1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2021 Broadcom 3 * All rights reserved. 4 */ 5 6 #include "bnxt.h" 7 #include "bnxt_tf_common.h" 8 #include "ulp_rte_parser.h" 9 #include "ulp_matcher.h" 10 #include "ulp_flow_db.h" 11 #include "ulp_mapper.h" 12 #include "ulp_fc_mgr.h" 13 #include "ulp_port_db.h" 14 #include "ulp_ha_mgr.h" 15 #include "ulp_tun.h" 16 #include <rte_malloc.h> 17 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG 18 #include "ulp_template_debug_proto.h" 19 #endif 20 21 static int32_t 22 bnxt_ulp_flow_validate_args(const struct rte_flow_attr *attr, 23 const struct rte_flow_item pattern[], 24 const struct rte_flow_action actions[], 25 struct rte_flow_error *error) 26 { 27 /* Perform the validation of the arguments for null */ 28 if (!error) 29 return BNXT_TF_RC_ERROR; 30 31 if (!pattern) { 32 rte_flow_error_set(error, 33 EINVAL, 34 RTE_FLOW_ERROR_TYPE_ITEM_NUM, 35 NULL, 36 "NULL pattern."); 37 return BNXT_TF_RC_ERROR; 38 } 39 40 if (!actions) { 41 rte_flow_error_set(error, 42 EINVAL, 43 RTE_FLOW_ERROR_TYPE_ACTION_NUM, 44 NULL, 45 "NULL action."); 46 return BNXT_TF_RC_ERROR; 47 } 48 49 if (!attr) { 50 rte_flow_error_set(error, 51 EINVAL, 52 RTE_FLOW_ERROR_TYPE_ATTR, 53 NULL, 54 "NULL attribute."); 55 return BNXT_TF_RC_ERROR; 56 } 57 58 if (attr->egress && attr->ingress) { 59 rte_flow_error_set(error, 60 EINVAL, 61 RTE_FLOW_ERROR_TYPE_ATTR, 62 attr, 63 "EGRESS AND INGRESS UNSUPPORTED"); 64 return BNXT_TF_RC_ERROR; 65 } 66 return BNXT_TF_RC_SUCCESS; 67 } 68 69 static inline void 70 bnxt_ulp_set_dir_attributes(struct ulp_rte_parser_params *params, 71 const struct rte_flow_attr *attr) 72 { 73 /* Set the flow attributes */ 74 if (attr->egress) 75 params->dir_attr |= BNXT_ULP_FLOW_ATTR_EGRESS; 76 if (attr->ingress) 77 params->dir_attr |= BNXT_ULP_FLOW_ATTR_INGRESS; 78 #if RTE_VERSION_NUM(17, 11, 10, 16) < RTE_VERSION 79 if (attr->transfer) 80 params->dir_attr |= BNXT_ULP_FLOW_ATTR_TRANSFER; 81 #endif 82 } 83 84 void 85 bnxt_ulp_init_mapper_params(struct bnxt_ulp_mapper_create_parms *mapper_cparms, 86 struct ulp_rte_parser_params *params, 87 enum bnxt_ulp_fdb_type flow_type) 88 { 89 uint32_t ulp_flags = 0; 90 91 memset(mapper_cparms, 0, sizeof(*mapper_cparms)); 92 mapper_cparms->flow_type = flow_type; 93 mapper_cparms->app_priority = params->priority; 94 mapper_cparms->dir_attr = params->dir_attr; 95 mapper_cparms->class_tid = params->class_id; 96 mapper_cparms->act_tid = params->act_tmpl; 97 mapper_cparms->func_id = params->func_id; 98 mapper_cparms->hdr_bitmap = ¶ms->hdr_bitmap; 99 mapper_cparms->enc_hdr_bitmap = ¶ms->enc_hdr_bitmap; 100 mapper_cparms->hdr_field = params->hdr_field; 101 mapper_cparms->enc_field = params->enc_field; 102 mapper_cparms->comp_fld = params->comp_fld; 103 mapper_cparms->act = ¶ms->act_bitmap; 104 mapper_cparms->act_prop = ¶ms->act_prop; 105 mapper_cparms->flow_id = params->fid; 106 mapper_cparms->parent_flow = params->parent_flow; 107 mapper_cparms->child_flow = params->child_flow; 108 mapper_cparms->fld_bitmap = ¶ms->fld_bitmap; 109 mapper_cparms->flow_pattern_id = params->flow_pattern_id; 110 mapper_cparms->act_pattern_id = params->act_pattern_id; 111 mapper_cparms->app_id = params->app_id; 112 mapper_cparms->port_id = params->port_id; 113 mapper_cparms->tun_idx = params->tun_idx; 114 115 /* update the signature fields into the computed field list */ 116 ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_HDR_SIG_ID, 117 params->hdr_sig_id); 118 ULP_COMP_FLD_IDX_WR(params, BNXT_ULP_CF_IDX_FLOW_SIG_ID, 119 params->flow_sig_id); 120 121 /* update the WC Priority flag */ 122 if (!bnxt_ulp_cntxt_ptr2_ulp_flags_get(params->ulp_ctx, &ulp_flags) && 123 ULP_HIGH_AVAIL_IS_ENABLED(ulp_flags)) { 124 enum ulp_ha_mgr_region region = ULP_HA_REGION_LOW; 125 int32_t rc; 126 127 rc = ulp_ha_mgr_region_get(params->ulp_ctx, ®ion); 128 if (rc) 129 BNXT_TF_DBG(ERR, "Unable to get WC region\n"); 130 if (region == ULP_HA_REGION_HI) 131 ULP_COMP_FLD_IDX_WR(params, 132 BNXT_ULP_CF_IDX_WC_IS_HA_HIGH_REG, 133 1); 134 } 135 } 136 137 /* Function to create the rte flow. */ 138 static struct rte_flow * 139 bnxt_ulp_flow_create(struct rte_eth_dev *dev, 140 const struct rte_flow_attr *attr, 141 const struct rte_flow_item pattern[], 142 const struct rte_flow_action actions[], 143 struct rte_flow_error *error) 144 { 145 struct bnxt_ulp_mapper_create_parms mapper_cparms = { 0 }; 146 struct ulp_rte_parser_params params; 147 struct bnxt_ulp_context *ulp_ctx; 148 int rc, ret = BNXT_TF_RC_ERROR; 149 struct rte_flow *flow_id; 150 uint16_t func_id; 151 uint32_t fid; 152 153 if (bnxt_ulp_flow_validate_args(attr, 154 pattern, actions, 155 error) == BNXT_TF_RC_ERROR) { 156 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n"); 157 goto flow_error; 158 } 159 160 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev); 161 if (!ulp_ctx) { 162 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 163 goto flow_error; 164 } 165 166 /* Initialize the parser params */ 167 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params)); 168 params.ulp_ctx = ulp_ctx; 169 170 if (bnxt_ulp_cntxt_app_id_get(params.ulp_ctx, ¶ms.app_id)) { 171 BNXT_TF_DBG(ERR, "failed to get the app id\n"); 172 goto flow_error; 173 } 174 175 /* Set the flow attributes */ 176 bnxt_ulp_set_dir_attributes(¶ms, attr); 177 178 /* copy the device port id and direction for further processing */ 179 ULP_COMP_FLD_IDX_WR(¶ms, BNXT_ULP_CF_IDX_INCOMING_IF, 180 dev->data->port_id); 181 ULP_COMP_FLD_IDX_WR(¶ms, BNXT_ULP_CF_IDX_DEV_PORT_ID, 182 dev->data->port_id); 183 ULP_COMP_FLD_IDX_WR(¶ms, BNXT_ULP_CF_IDX_SVIF_FLAG, 184 BNXT_ULP_INVALID_SVIF_VAL); 185 186 /* Get the function id */ 187 if (ulp_port_db_port_func_id_get(ulp_ctx, 188 dev->data->port_id, 189 &func_id)) { 190 BNXT_TF_DBG(ERR, "conversion of port to func id failed\n"); 191 goto flow_error; 192 } 193 194 /* Protect flow creation */ 195 if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) { 196 BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n"); 197 goto flow_error; 198 } 199 200 /* Allocate a Flow ID for attaching all resources for the flow to. 201 * Once allocated, all errors have to walk the list of resources and 202 * free each of them. 203 */ 204 rc = ulp_flow_db_fid_alloc(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR, 205 func_id, &fid); 206 if (rc) { 207 BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n"); 208 goto release_lock; 209 } 210 211 /* Parse the rte flow pattern */ 212 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms); 213 if (ret != BNXT_TF_RC_SUCCESS) 214 goto free_fid; 215 216 /* Parse the rte flow action */ 217 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms); 218 if (ret != BNXT_TF_RC_SUCCESS) 219 goto free_fid; 220 221 params.fid = fid; 222 params.func_id = func_id; 223 params.priority = attr->priority; 224 params.port_id = dev->data->port_id; 225 226 /* Perform the rte flow post process */ 227 bnxt_ulp_rte_parser_post_process(¶ms); 228 229 /* do the tunnel offload process if any */ 230 ret = ulp_tunnel_offload_process(¶ms); 231 if (ret == BNXT_TF_RC_ERROR) 232 goto free_fid; 233 234 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG 235 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_PARSER 236 /* Dump the rte flow pattern */ 237 ulp_parser_hdr_info_dump(¶ms); 238 /* Dump the rte flow action */ 239 ulp_parser_act_info_dump(¶ms); 240 #endif 241 #endif 242 243 ret = ulp_matcher_pattern_match(¶ms, ¶ms.class_id); 244 if (ret != BNXT_TF_RC_SUCCESS) 245 goto free_fid; 246 247 ret = ulp_matcher_action_match(¶ms, ¶ms.act_tmpl); 248 if (ret != BNXT_TF_RC_SUCCESS) 249 goto free_fid; 250 251 bnxt_ulp_init_mapper_params(&mapper_cparms, ¶ms, 252 BNXT_ULP_FDB_TYPE_REGULAR); 253 /* Call the ulp mapper to create the flow in the hardware. */ 254 ret = ulp_mapper_flow_create(ulp_ctx, &mapper_cparms); 255 if (ret) 256 goto free_fid; 257 258 bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); 259 260 flow_id = (struct rte_flow *)((uintptr_t)fid); 261 return flow_id; 262 263 free_fid: 264 ulp_flow_db_fid_free(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR, fid); 265 release_lock: 266 bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); 267 flow_error: 268 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 269 "Failed to create flow."); 270 return NULL; 271 } 272 273 /* Function to validate the rte flow. */ 274 static int 275 bnxt_ulp_flow_validate(struct rte_eth_dev *dev, 276 const struct rte_flow_attr *attr, 277 const struct rte_flow_item pattern[], 278 const struct rte_flow_action actions[], 279 struct rte_flow_error *error) 280 { 281 struct ulp_rte_parser_params params; 282 struct bnxt_ulp_context *ulp_ctx; 283 uint32_t class_id, act_tmpl; 284 int ret = BNXT_TF_RC_ERROR; 285 286 if (bnxt_ulp_flow_validate_args(attr, 287 pattern, actions, 288 error) == BNXT_TF_RC_ERROR) { 289 BNXT_TF_DBG(ERR, "Invalid arguments being passed\n"); 290 goto parse_error; 291 } 292 293 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev); 294 if (!ulp_ctx) { 295 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 296 goto parse_error; 297 } 298 299 /* Initialize the parser params */ 300 memset(¶ms, 0, sizeof(struct ulp_rte_parser_params)); 301 params.ulp_ctx = ulp_ctx; 302 303 if (bnxt_ulp_cntxt_app_id_get(params.ulp_ctx, ¶ms.app_id)) { 304 BNXT_TF_DBG(ERR, "failed to get the app id\n"); 305 goto parse_error; 306 } 307 308 /* Set the flow attributes */ 309 bnxt_ulp_set_dir_attributes(¶ms, attr); 310 311 /* Parse the rte flow pattern */ 312 ret = bnxt_ulp_rte_parser_hdr_parse(pattern, ¶ms); 313 if (ret != BNXT_TF_RC_SUCCESS) 314 goto parse_error; 315 316 /* Parse the rte flow action */ 317 ret = bnxt_ulp_rte_parser_act_parse(actions, ¶ms); 318 if (ret != BNXT_TF_RC_SUCCESS) 319 goto parse_error; 320 321 /* Perform the rte flow post process */ 322 bnxt_ulp_rte_parser_post_process(¶ms); 323 324 /* do the tunnel offload process if any */ 325 ret = ulp_tunnel_offload_process(¶ms); 326 if (ret == BNXT_TF_RC_ERROR) 327 goto parse_error; 328 329 ret = ulp_matcher_pattern_match(¶ms, &class_id); 330 331 if (ret != BNXT_TF_RC_SUCCESS) 332 goto parse_error; 333 334 ret = ulp_matcher_action_match(¶ms, &act_tmpl); 335 if (ret != BNXT_TF_RC_SUCCESS) 336 goto parse_error; 337 338 /* all good return success */ 339 return ret; 340 341 parse_error: 342 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 343 "Failed to validate flow."); 344 return -EINVAL; 345 } 346 347 /* Function to destroy the rte flow. */ 348 int 349 bnxt_ulp_flow_destroy(struct rte_eth_dev *dev, 350 struct rte_flow *flow, 351 struct rte_flow_error *error) 352 { 353 struct bnxt_ulp_context *ulp_ctx; 354 uint32_t flow_id; 355 uint16_t func_id; 356 int ret; 357 358 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(dev); 359 if (!ulp_ctx) { 360 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 361 if (error) 362 rte_flow_error_set(error, EINVAL, 363 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 364 "Failed to destroy flow."); 365 return -EINVAL; 366 } 367 368 flow_id = (uint32_t)(uintptr_t)flow; 369 370 if (ulp_port_db_port_func_id_get(ulp_ctx, 371 dev->data->port_id, 372 &func_id)) { 373 BNXT_TF_DBG(ERR, "conversion of port to func id failed\n"); 374 if (error) 375 rte_flow_error_set(error, EINVAL, 376 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 377 "Failed to destroy flow."); 378 return -EINVAL; 379 } 380 381 if (ulp_flow_db_validate_flow_func(ulp_ctx, flow_id, func_id) == 382 false) { 383 BNXT_TF_DBG(ERR, "Incorrect device params\n"); 384 if (error) 385 rte_flow_error_set(error, EINVAL, 386 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 387 "Failed to destroy flow."); 388 return -EINVAL; 389 } 390 391 if (bnxt_ulp_cntxt_acquire_fdb_lock(ulp_ctx)) { 392 BNXT_TF_DBG(ERR, "Flow db lock acquire failed\n"); 393 return -EINVAL; 394 } 395 ret = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR, 396 flow_id); 397 if (ret) { 398 BNXT_TF_DBG(ERR, "Failed to destroy flow.\n"); 399 if (error) 400 rte_flow_error_set(error, -ret, 401 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 402 "Failed to destroy flow."); 403 } 404 bnxt_ulp_cntxt_release_fdb_lock(ulp_ctx); 405 406 return ret; 407 } 408 409 /* Function to destroy the rte flows. */ 410 static int32_t 411 bnxt_ulp_flow_flush(struct rte_eth_dev *eth_dev, 412 struct rte_flow_error *error) 413 { 414 struct bnxt_ulp_context *ulp_ctx; 415 int32_t ret = 0; 416 uint16_t func_id; 417 418 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 419 if (!ulp_ctx) { 420 return ret; 421 } 422 423 /* Free the resources for the last device */ 424 if (ulp_ctx_deinit_allowed(ulp_ctx)) { 425 ret = ulp_flow_db_session_flow_flush(ulp_ctx); 426 } else if (bnxt_ulp_cntxt_ptr2_flow_db_get(ulp_ctx)) { 427 ret = ulp_port_db_port_func_id_get(ulp_ctx, 428 eth_dev->data->port_id, 429 &func_id); 430 if (!ret) 431 ret = ulp_flow_db_function_flow_flush(ulp_ctx, func_id); 432 else 433 BNXT_TF_DBG(ERR, "convert port to func id failed\n"); 434 } 435 if (ret) 436 rte_flow_error_set(error, ret, 437 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 438 "Failed to flush flow."); 439 return ret; 440 } 441 442 /* Function to query the rte flows. */ 443 static int32_t 444 bnxt_ulp_flow_query(struct rte_eth_dev *eth_dev, 445 struct rte_flow *flow, 446 const struct rte_flow_action *action, 447 void *data, 448 struct rte_flow_error *error) 449 { 450 int rc = 0; 451 struct bnxt_ulp_context *ulp_ctx; 452 struct rte_flow_query_count *count; 453 uint32_t flow_id; 454 455 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 456 if (!ulp_ctx) { 457 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 458 rte_flow_error_set(error, EINVAL, 459 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 460 "Failed to query flow."); 461 return -EINVAL; 462 } 463 464 flow_id = (uint32_t)(uintptr_t)flow; 465 466 switch (action->type) { 467 case RTE_FLOW_ACTION_TYPE_COUNT: 468 count = data; 469 rc = ulp_fc_mgr_query_count_get(ulp_ctx, flow_id, count); 470 if (rc) { 471 rte_flow_error_set(error, EINVAL, 472 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 473 "Failed to query flow."); 474 } 475 break; 476 default: 477 rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM, 478 NULL, "Unsupported action item"); 479 } 480 481 return rc; 482 } 483 484 /* Tunnel offload Apis */ 485 #define BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS 1 486 487 static int 488 bnxt_ulp_tunnel_decap_set(struct rte_eth_dev *eth_dev, 489 struct rte_flow_tunnel *tunnel, 490 struct rte_flow_action **pmd_actions, 491 uint32_t *num_of_actions, 492 struct rte_flow_error *error) 493 { 494 struct bnxt_ulp_context *ulp_ctx; 495 struct bnxt_flow_app_tun_ent *tun_entry; 496 int32_t rc = 0; 497 498 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 499 if (ulp_ctx == NULL) { 500 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 501 rte_flow_error_set(error, EINVAL, 502 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 503 "ULP context uninitialized"); 504 return -EINVAL; 505 } 506 507 if (tunnel == NULL) { 508 BNXT_TF_DBG(ERR, "No tunnel specified\n"); 509 rte_flow_error_set(error, EINVAL, 510 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 511 "no tunnel specified"); 512 return -EINVAL; 513 } 514 515 if (tunnel->type != RTE_FLOW_ITEM_TYPE_VXLAN) { 516 BNXT_TF_DBG(ERR, "Tunnel type unsupported\n"); 517 rte_flow_error_set(error, EINVAL, 518 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 519 "tunnel type unsupported"); 520 return -EINVAL; 521 } 522 523 rc = ulp_app_tun_search_entry(ulp_ctx, tunnel, &tun_entry); 524 if (rc < 0) { 525 rte_flow_error_set(error, EINVAL, 526 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 527 "tunnel decap set failed"); 528 return -EINVAL; 529 } 530 531 rc = ulp_app_tun_entry_set_decap_action(tun_entry); 532 if (rc < 0) { 533 rte_flow_error_set(error, EINVAL, 534 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 535 "tunnel decap set failed"); 536 return -EINVAL; 537 } 538 539 *pmd_actions = &tun_entry->action; 540 *num_of_actions = BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS; 541 return 0; 542 } 543 544 static int 545 bnxt_ulp_tunnel_match(struct rte_eth_dev *eth_dev, 546 struct rte_flow_tunnel *tunnel, 547 struct rte_flow_item **pmd_items, 548 uint32_t *num_of_items, 549 struct rte_flow_error *error) 550 { 551 struct bnxt_ulp_context *ulp_ctx; 552 struct bnxt_flow_app_tun_ent *tun_entry; 553 int32_t rc = 0; 554 555 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 556 if (ulp_ctx == NULL) { 557 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 558 rte_flow_error_set(error, EINVAL, 559 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 560 "ULP context uninitialized"); 561 return -EINVAL; 562 } 563 564 if (tunnel == NULL) { 565 BNXT_TF_DBG(ERR, "No tunnel specified\n"); 566 rte_flow_error_set(error, EINVAL, 567 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 568 "no tunnel specified"); 569 return -EINVAL; 570 } 571 572 if (tunnel->type != RTE_FLOW_ITEM_TYPE_VXLAN) { 573 BNXT_TF_DBG(ERR, "Tunnel type unsupported\n"); 574 rte_flow_error_set(error, EINVAL, 575 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 576 "tunnel type unsupported"); 577 return -EINVAL; 578 } 579 580 rc = ulp_app_tun_search_entry(ulp_ctx, tunnel, &tun_entry); 581 if (rc < 0) { 582 rte_flow_error_set(error, EINVAL, 583 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 584 "tunnel match set failed"); 585 return -EINVAL; 586 } 587 588 rc = ulp_app_tun_entry_set_decap_item(tun_entry); 589 if (rc < 0) { 590 rte_flow_error_set(error, EINVAL, 591 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 592 "tunnel match set failed"); 593 return -EINVAL; 594 } 595 596 *pmd_items = &tun_entry->item; 597 *num_of_items = BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS; 598 return 0; 599 } 600 601 static int 602 bnxt_ulp_tunnel_decap_release(struct rte_eth_dev *eth_dev, 603 struct rte_flow_action *pmd_actions, 604 uint32_t num_actions, 605 struct rte_flow_error *error) 606 { 607 struct bnxt_ulp_context *ulp_ctx; 608 struct bnxt_flow_app_tun_ent *tun_entry; 609 const struct rte_flow_action *action_item = pmd_actions; 610 611 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 612 if (ulp_ctx == NULL) { 613 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 614 rte_flow_error_set(error, EINVAL, 615 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 616 "ULP context uninitialized"); 617 return -EINVAL; 618 } 619 if (num_actions != BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS) { 620 BNXT_TF_DBG(ERR, "num actions is invalid\n"); 621 rte_flow_error_set(error, EINVAL, 622 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 623 "num actions is invalid"); 624 return -EINVAL; 625 } 626 while (action_item && action_item->type != RTE_FLOW_ACTION_TYPE_END) { 627 if (action_item->type == (typeof(tun_entry->action.type)) 628 BNXT_RTE_FLOW_ACTION_TYPE_VXLAN_DECAP) { 629 tun_entry = ulp_app_tun_match_entry(ulp_ctx, 630 action_item->conf); 631 ulp_app_tun_entry_delete(tun_entry); 632 } 633 action_item++; 634 } 635 return 0; 636 } 637 638 static int 639 bnxt_ulp_tunnel_item_release(struct rte_eth_dev *eth_dev, 640 struct rte_flow_item *pmd_items, 641 uint32_t num_items, 642 struct rte_flow_error *error) 643 { 644 struct bnxt_ulp_context *ulp_ctx; 645 struct bnxt_flow_app_tun_ent *tun_entry; 646 647 ulp_ctx = bnxt_ulp_eth_dev_ptr2_cntxt_get(eth_dev); 648 if (ulp_ctx == NULL) { 649 BNXT_TF_DBG(ERR, "ULP context is not initialized\n"); 650 rte_flow_error_set(error, EINVAL, 651 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, 652 "ULP context uninitialized"); 653 return -EINVAL; 654 } 655 if (num_items != BNXT_ULP_TUNNEL_OFFLOAD_NUM_ITEMS) { 656 BNXT_TF_DBG(ERR, "num items is invalid\n"); 657 rte_flow_error_set(error, EINVAL, 658 RTE_FLOW_ERROR_TYPE_ATTR, NULL, 659 "num items is invalid"); 660 return -EINVAL; 661 } 662 663 tun_entry = ulp_app_tun_match_entry(ulp_ctx, pmd_items->spec); 664 ulp_app_tun_entry_delete(tun_entry); 665 return 0; 666 } 667 668 const struct rte_flow_ops bnxt_ulp_rte_flow_ops = { 669 .validate = bnxt_ulp_flow_validate, 670 .create = bnxt_ulp_flow_create, 671 .destroy = bnxt_ulp_flow_destroy, 672 .flush = bnxt_ulp_flow_flush, 673 .query = bnxt_ulp_flow_query, 674 .isolate = NULL, 675 /* Tunnel offload callbacks */ 676 .tunnel_decap_set = bnxt_ulp_tunnel_decap_set, 677 .tunnel_match = bnxt_ulp_tunnel_match, 678 .tunnel_action_decap_release = bnxt_ulp_tunnel_decap_release, 679 .tunnel_item_release = bnxt_ulp_tunnel_item_release, 680 .get_restore_info = NULL 681 }; 682