1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _BNXT_ULP_UTILS_H_ 7 #define _BNXT_ULP_UTILS_H_ 8 9 #include <rte_log.h> 10 #include <rte_malloc.h> 11 #include <rte_flow.h> 12 #include <rte_flow_driver.h> 13 #include <rte_tailq.h> 14 #include <rte_spinlock.h> 15 16 #include "bnxt.h" 17 #include "bnxt_ulp.h" 18 #include "bnxt_tf_common.h" 19 #include "bnxt_hwrm.h" 20 #include "hsi_struct_def_dpdk.h" 21 #include "tf_core.h" 22 #include "tf_ext_flow_handle.h" 23 24 #include "ulp_template_db_enum.h" 25 #include "ulp_template_struct.h" 26 #include "ulp_mark_mgr.h" 27 #include "ulp_fc_mgr.h" 28 #include "ulp_sc_mgr.h" 29 #include "ulp_flow_db.h" 30 #include "ulp_mapper.h" 31 #include "ulp_matcher.h" 32 #include "ulp_port_db.h" 33 #include "ulp_tun.h" 34 #include "ulp_ha_mgr.h" 35 #include "bnxt_tf_pmd_shim.h" 36 #include "ulp_template_db_tbl.h" 37 38 static inline int32_t 39 bnxt_ulp_devid_get(struct bnxt *bp, 40 enum bnxt_ulp_device_id *ulp_dev_id) 41 { 42 if (BNXT_CHIP_P7(bp)) { 43 *ulp_dev_id = BNXT_ULP_DEVICE_ID_THOR2; 44 return 0; 45 } 46 47 if (BNXT_CHIP_P5(bp)) { 48 *ulp_dev_id = BNXT_ULP_DEVICE_ID_THOR; 49 return 0; 50 } 51 52 if (BNXT_STINGRAY(bp)) 53 *ulp_dev_id = BNXT_ULP_DEVICE_ID_STINGRAY; 54 else 55 /* Assuming Whitney */ 56 *ulp_dev_id = BNXT_ULP_DEVICE_ID_WH_PLUS; 57 58 return 0; 59 } 60 61 static inline struct bnxt_ulp_app_capabilities_info * 62 bnxt_ulp_app_cap_list_get(uint32_t *num_entries) 63 { 64 if (unlikely(!num_entries)) 65 return NULL; 66 *num_entries = BNXT_ULP_APP_CAP_TBL_MAX_SZ; 67 return ulp_app_cap_info_list; 68 } 69 70 static inline struct bnxt_ulp_shared_act_info * 71 bnxt_ulp_shared_act_info_get(uint32_t *num_entries) 72 { 73 if (unlikely(!num_entries)) 74 return NULL; 75 76 *num_entries = BNXT_ULP_GEN_TBL_MAX_SZ; 77 78 return ulp_shared_act_info; 79 } 80 81 static inline struct bnxt_ulp_resource_resv_info * 82 bnxt_ulp_app_resource_resv_list_get(uint32_t *num_entries) 83 { 84 if (unlikely(num_entries == NULL)) 85 return NULL; 86 *num_entries = BNXT_ULP_APP_RESOURCE_RESV_LIST_MAX_SZ; 87 return ulp_app_resource_resv_list; 88 } 89 90 static inline struct bnxt_ulp_resource_resv_info * 91 bnxt_ulp_resource_resv_list_get(uint32_t *num_entries) 92 { 93 if (unlikely(!num_entries)) 94 return NULL; 95 *num_entries = BNXT_ULP_RESOURCE_RESV_LIST_MAX_SZ; 96 return ulp_resource_resv_list; 97 } 98 99 static inline struct bnxt_ulp_glb_resource_info * 100 bnxt_ulp_app_glb_resource_info_list_get(uint32_t *num_entries) 101 { 102 if (unlikely(!num_entries)) 103 return NULL; 104 *num_entries = BNXT_ULP_APP_GLB_RESOURCE_TBL_MAX_SZ; 105 return ulp_app_glb_resource_tbl; 106 } 107 108 /* Function to set the number for vxlan_ip (custom vxlan) port into the context */ 109 static inline int 110 bnxt_ulp_cntxt_ecpri_udp_port_set(struct bnxt_ulp_context *ulp_ctx, 111 uint32_t ecpri_udp_port) 112 { 113 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 114 return -EINVAL; 115 116 ulp_ctx->cfg_data->ecpri_udp_port = ecpri_udp_port; 117 118 return 0; 119 } 120 121 /* Function to retrieve the vxlan_ip (custom vxlan) port from the context. */ 122 static inline unsigned int 123 bnxt_ulp_cntxt_ecpri_udp_port_get(struct bnxt_ulp_context *ulp_ctx) 124 { 125 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 126 return 0; 127 128 return (unsigned int)ulp_ctx->cfg_data->ecpri_udp_port; 129 } 130 131 /* Function to set the number for vxlan_ip (custom vxlan) port into the context */ 132 static inline int 133 bnxt_ulp_cntxt_vxlan_ip_port_set(struct bnxt_ulp_context *ulp_ctx, 134 uint32_t vxlan_ip_port) 135 { 136 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 137 return -EINVAL; 138 139 ulp_ctx->cfg_data->vxlan_ip_port = vxlan_ip_port; 140 if (vxlan_ip_port) 141 ulp_ctx->cfg_data->ulp_flags |= BNXT_ULP_STATIC_VXLAN_SUPPORT; 142 return 0; 143 } 144 145 /* Function to retrieve the vxlan_ip (custom vxlan) port from the context. */ 146 static inline unsigned int 147 bnxt_ulp_cntxt_vxlan_ip_port_get(struct bnxt_ulp_context *ulp_ctx) 148 { 149 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 150 return 0; 151 152 return (unsigned int)ulp_ctx->cfg_data->vxlan_ip_port; 153 } 154 155 /* Function to set the number for vxlan_gpe next_proto into the context */ 156 static inline uint32_t 157 bnxt_ulp_vxlan_gpe_next_proto_set(struct bnxt_ulp_context *ulp_ctx, 158 uint8_t tunnel_next_proto) 159 { 160 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 161 return -EINVAL; 162 163 ulp_ctx->cfg_data->tunnel_next_proto = tunnel_next_proto; 164 165 return 0; 166 } 167 168 /* Function to retrieve the vxlan_gpe next_proto from the context. */ 169 static inline uint8_t 170 bnxt_ulp_vxlan_gpe_next_proto_get(struct bnxt_ulp_context *ulp_ctx) 171 { 172 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 173 return 0; 174 175 return ulp_ctx->cfg_data->tunnel_next_proto; 176 } 177 178 /* Function to set the number for vxlan port into the context */ 179 static inline int 180 bnxt_ulp_cntxt_vxlan_port_set(struct bnxt_ulp_context *ulp_ctx, 181 uint32_t vxlan_port) 182 { 183 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 184 return -EINVAL; 185 186 ulp_ctx->cfg_data->vxlan_port = vxlan_port; 187 if (vxlan_port) 188 ulp_ctx->cfg_data->ulp_flags |= BNXT_ULP_STATIC_VXLAN_SUPPORT; 189 190 return 0; 191 } 192 193 /* Function to retrieve the vxlan port from the context. */ 194 static inline unsigned int 195 bnxt_ulp_cntxt_vxlan_port_get(struct bnxt_ulp_context *ulp_ctx) 196 { 197 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 198 return 0; 199 200 return (unsigned int)ulp_ctx->cfg_data->vxlan_port; 201 } 202 203 static inline int 204 bnxt_ulp_default_app_priority_set(struct bnxt_ulp_context *ulp_ctx, 205 uint32_t prio) 206 { 207 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 208 return -EINVAL; 209 210 ulp_ctx->cfg_data->default_priority = prio; 211 return 0; 212 } 213 214 static inline unsigned int 215 bnxt_ulp_default_app_priority_get(struct bnxt_ulp_context *ulp_ctx) 216 { 217 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 218 return 0; 219 220 return (unsigned int)ulp_ctx->cfg_data->default_priority; 221 } 222 223 static inline int 224 bnxt_ulp_max_def_priority_set(struct bnxt_ulp_context *ulp_ctx, 225 uint32_t prio) 226 { 227 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 228 return -EINVAL; 229 230 ulp_ctx->cfg_data->max_def_priority = prio; 231 return 0; 232 } 233 234 static inline unsigned int 235 bnxt_ulp_max_def_priority_get(struct bnxt_ulp_context *ulp_ctx) 236 { 237 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 238 return 0; 239 240 return (unsigned int)ulp_ctx->cfg_data->max_def_priority; 241 } 242 243 static inline int 244 bnxt_ulp_min_flow_priority_set(struct bnxt_ulp_context *ulp_ctx, uint32_t prio) 245 { 246 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 247 return -EINVAL; 248 249 ulp_ctx->cfg_data->min_flow_priority = prio; 250 return 0; 251 } 252 253 static inline unsigned int 254 bnxt_ulp_min_flow_priority_get(struct bnxt_ulp_context *ulp_ctx) 255 { 256 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 257 return 0; 258 259 return ulp_ctx->cfg_data->min_flow_priority; 260 } 261 262 static inline int 263 bnxt_ulp_max_flow_priority_set(struct bnxt_ulp_context *ulp_ctx, uint32_t prio) 264 { 265 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 266 return -EINVAL; 267 268 ulp_ctx->cfg_data->max_flow_priority = prio; 269 return 0; 270 } 271 272 static inline unsigned int 273 bnxt_ulp_max_flow_priority_get(struct bnxt_ulp_context *ulp_ctx) 274 { 275 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 276 return 0; 277 278 return ulp_ctx->cfg_data->max_flow_priority; 279 } 280 281 /* Below are the access functions to access internal data of ulp context. */ 282 /* Function to set the Mark DB into the context */ 283 static inline int32_t 284 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx, 285 struct bnxt_ulp_mark_tbl *mark_tbl) 286 { 287 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 288 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 289 return -EINVAL; 290 } 291 292 ulp_ctx->cfg_data->mark_tbl = mark_tbl; 293 294 return 0; 295 } 296 297 /* Function to retrieve the Mark DB from the context. */ 298 static inline struct bnxt_ulp_mark_tbl * 299 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx) 300 { 301 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 302 return NULL; 303 304 return ulp_ctx->cfg_data->mark_tbl; 305 } 306 307 static inline bool 308 bnxt_ulp_cntxt_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx) 309 { 310 return ULP_SHARED_SESSION_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags); 311 } 312 313 static inline bool 314 bnxt_ulp_cntxt_multi_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx) 315 { 316 return ULP_MULTI_SHARED_IS_SUPPORTED(ulp_ctx); 317 } 318 319 static inline int32_t 320 bnxt_ulp_cntxt_app_id_set(struct bnxt_ulp_context *ulp_ctx, uint8_t app_id) 321 { 322 if (unlikely(!ulp_ctx)) 323 return -EINVAL; 324 ulp_ctx->cfg_data->app_id = app_id; 325 return 0; 326 } 327 328 static inline int32_t 329 bnxt_ulp_cntxt_app_id_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *app_id) 330 { 331 /* Default APP id is zero */ 332 if (unlikely(!ulp_ctx || !app_id)) 333 return -EINVAL; 334 *app_id = ulp_ctx->cfg_data->app_id; 335 return 0; 336 } 337 338 /* Function to set the device id of the hardware. */ 339 static inline int32_t 340 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx, 341 uint32_t dev_id) 342 { 343 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 344 ulp_ctx->cfg_data->dev_id = dev_id; 345 return 0; 346 } 347 348 return -EINVAL; 349 } 350 351 /* Function to get the device id of the hardware. */ 352 static inline int32_t 353 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx, 354 uint32_t *dev_id) 355 { 356 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 357 *dev_id = ulp_ctx->cfg_data->dev_id; 358 return 0; 359 } 360 *dev_id = BNXT_ULP_DEVICE_ID_LAST; 361 BNXT_DRV_DBG(ERR, "Failed to read dev_id from ulp ctxt\n"); 362 return -EINVAL; 363 } 364 365 static inline int32_t 366 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx, 367 enum bnxt_ulp_flow_mem_type mem_type) 368 { 369 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 370 ulp_ctx->cfg_data->mem_type = mem_type; 371 return 0; 372 } 373 BNXT_DRV_DBG(ERR, "Failed to write mem_type in ulp ctxt\n"); 374 return -EINVAL; 375 } 376 377 static inline int32_t 378 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx, 379 enum bnxt_ulp_flow_mem_type *mem_type) 380 { 381 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 382 *mem_type = ulp_ctx->cfg_data->mem_type; 383 return 0; 384 } 385 *mem_type = BNXT_ULP_FLOW_MEM_TYPE_LAST; 386 BNXT_DRV_DBG(ERR, "Failed to read mem_type in ulp ctxt\n"); 387 return -EINVAL; 388 } 389 390 /* Function to get the table scope id of the EEM table. */ 391 static inline int32_t 392 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx, 393 uint32_t *tbl_scope_id) 394 { 395 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 396 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id; 397 return 0; 398 } 399 400 return -EINVAL; 401 } 402 403 /* Function to set the table scope id of the EEM table. */ 404 static inline int32_t 405 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx, 406 uint32_t tbl_scope_id) 407 { 408 if (likely(ulp_ctx && ulp_ctx->cfg_data)) { 409 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id; 410 return 0; 411 } 412 413 return -EINVAL; 414 } 415 416 /* Function to set the v3 table scope id, only works for tfc objects */ 417 static inline int32_t 418 bnxt_ulp_cntxt_tsid_set(struct bnxt_ulp_context *ulp_ctx, uint8_t tsid) 419 { 420 if (likely(ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC)) { 421 ulp_ctx->tsid = tsid; 422 ULP_BITMAP_SET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG); 423 return 0; 424 } 425 return -EINVAL; 426 } 427 428 /* Function to reset the v3 table scope id, only works for tfc objects */ 429 static inline void 430 bnxt_ulp_cntxt_tsid_reset(struct bnxt_ulp_context *ulp_ctx) 431 { 432 if (ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC) 433 ULP_BITMAP_RESET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG); 434 } 435 436 /* Function to set the v3 table scope id, only works for tfc objects */ 437 static inline int32_t 438 bnxt_ulp_cntxt_tsid_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *tsid) 439 { 440 if (likely(ulp_ctx && tsid && 441 ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC && 442 ULP_BITMAP_ISSET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_TSID_FLAG))) { 443 *tsid = ulp_ctx->tsid; 444 return 0; 445 } 446 return -EINVAL; 447 } 448 449 /* Function to set the v3 session id, only works for tfc objects */ 450 static inline int32_t 451 bnxt_ulp_cntxt_sid_set(struct bnxt_ulp_context *ulp_ctx, 452 uint16_t sid) 453 { 454 if (likely(ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC)) { 455 ulp_ctx->sid = sid; 456 ULP_BITMAP_SET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG); 457 return 0; 458 } 459 return -EINVAL; 460 } 461 462 /* 463 * Function to reset the v3 session id, only works for tfc objects 464 * There isn't a known invalid value for sid, so this is necessary 465 */ 466 static inline void 467 bnxt_ulp_cntxt_sid_reset(struct bnxt_ulp_context *ulp_ctx) 468 { 469 if (ulp_ctx && ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC) 470 ULP_BITMAP_RESET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG); 471 } 472 473 /* Function to get the v3 session id, only works for tfc objects */ 474 static inline int32_t 475 bnxt_ulp_cntxt_sid_get(struct bnxt_ulp_context *ulp_ctx, 476 uint16_t *sid) 477 { 478 if (likely(ulp_ctx && sid && 479 ulp_ctx->tfo_type == BNXT_ULP_TFO_TYPE_TFC && 480 ULP_BITMAP_ISSET(ulp_ctx->tfo_flags, BNXT_ULP_TFO_SID_FLAG))) { 481 *sid = ulp_ctx->sid; 482 return 0; 483 } 484 return -EINVAL; 485 } 486 487 /* Function to get the number of shared clients attached */ 488 static inline uint8_t 489 bnxt_ulp_cntxt_num_shared_clients_get(struct bnxt_ulp_context *ulp) 490 { 491 if (likely(ulp == NULL || ulp->cfg_data == NULL)) { 492 BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 493 return 0; 494 } 495 return ulp->cfg_data->num_shared_clients; 496 } 497 498 /* Function to set the number of shared clients */ 499 static inline int 500 bnxt_ulp_cntxt_num_shared_clients_set(struct bnxt_ulp_context *ulp, bool incr) 501 { 502 if (unlikely(ulp == NULL || ulp->cfg_data == NULL)) { 503 BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 504 return 0; 505 } 506 if (incr) 507 ulp->cfg_data->num_shared_clients++; 508 else if (ulp->cfg_data->num_shared_clients) 509 ulp->cfg_data->num_shared_clients--; 510 511 BNXT_DRV_DBG(DEBUG, "%d:clients(%d)\n", incr, 512 ulp->cfg_data->num_shared_clients); 513 514 return 0; 515 } 516 517 static inline int32_t 518 bnxt_ulp_cntxt_bp_set(struct bnxt_ulp_context *ulp, struct bnxt *bp) 519 { 520 if (unlikely(ulp == NULL)) { 521 BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 522 return -EINVAL; 523 } 524 ulp->bp = bp; 525 return 0; 526 } 527 528 static inline struct bnxt* 529 bnxt_ulp_cntxt_bp_get(struct bnxt_ulp_context *ulp) 530 { 531 if (unlikely(ulp == NULL)) { 532 BNXT_DRV_DBG(ERR, "Invalid arguments\n"); 533 return NULL; 534 } 535 return ulp->bp; 536 } 537 538 static inline int32_t 539 bnxt_ulp_cntxt_fid_get(struct bnxt_ulp_context *ulp, uint16_t *fid) 540 { 541 if (unlikely(ulp == NULL || fid == NULL)) 542 return -EINVAL; 543 544 *fid = ulp->bp->fw_fid; 545 return 0; 546 } 547 548 static inline void 549 bnxt_ulp_cntxt_ptr2_default_class_bits_set(struct bnxt_ulp_context *ulp_ctx, 550 uint64_t bits) 551 { 552 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 553 return; 554 ulp_ctx->cfg_data->default_class_bits = bits; 555 } 556 557 static inline uint64_t 558 bnxt_ulp_cntxt_ptr2_default_class_bits_get(struct bnxt_ulp_context *ulp_ctx) 559 { 560 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 561 return 0; 562 return ulp_ctx->cfg_data->default_class_bits; 563 } 564 565 static inline void 566 bnxt_ulp_cntxt_ptr2_default_act_bits_set(struct bnxt_ulp_context *ulp_ctx, 567 uint64_t bits) 568 { 569 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 570 return; 571 ulp_ctx->cfg_data->default_act_bits = bits; 572 } 573 574 static inline uint64_t 575 bnxt_ulp_cntxt_ptr2_default_act_bits_get(struct bnxt_ulp_context *ulp_ctx) 576 { 577 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 578 return 0; 579 return ulp_ctx->cfg_data->default_act_bits; 580 } 581 582 /* 583 * Get the device table entry based on the device id. 584 * 585 * dev_id [in] The device id of the hardware 586 * 587 * Returns the pointer to the device parameters. 588 */ 589 static inline struct bnxt_ulp_device_params * 590 bnxt_ulp_device_params_get(uint32_t dev_id) 591 { 592 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES) 593 return &ulp_device_params[dev_id]; 594 return NULL; 595 } 596 597 /* Function to set the flow database to the ulp context. */ 598 static inline int32_t 599 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx, 600 struct bnxt_ulp_flow_db *flow_db) 601 { 602 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 603 return -EINVAL; 604 605 ulp_ctx->cfg_data->flow_db = flow_db; 606 return 0; 607 } 608 609 /* Function to get the flow database from the ulp context. */ 610 static inline struct bnxt_ulp_flow_db * 611 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx) 612 { 613 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 614 return NULL; 615 616 return ulp_ctx->cfg_data->flow_db; 617 } 618 619 /* Function to get the tunnel cache table info from the ulp context. */ 620 static inline struct bnxt_tun_cache_entry * 621 bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx) 622 { 623 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 624 return NULL; 625 626 return ulp_ctx->cfg_data->tun_tbl; 627 } 628 629 /* Function to get the ulp context from eth device. */ 630 static inline struct bnxt_ulp_context * 631 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev) 632 { 633 struct bnxt *bp = (struct bnxt *)dev->data->dev_private; 634 635 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) { 636 struct bnxt_representor *vfr = dev->data->dev_private; 637 638 bp = vfr->parent_dev->data->dev_private; 639 } 640 641 if (unlikely(!bp)) { 642 BNXT_DRV_DBG(ERR, "Bnxt private data is not initialized\n"); 643 return NULL; 644 } 645 return bp->ulp_ctx; 646 } 647 648 static inline int32_t 649 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx, 650 void *mapper_data) 651 { 652 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 653 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 654 return -EINVAL; 655 } 656 657 ulp_ctx->cfg_data->mapper_data = mapper_data; 658 return 0; 659 } 660 661 static inline void * 662 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx) 663 { 664 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 665 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 666 return NULL; 667 } 668 669 return ulp_ctx->cfg_data->mapper_data; 670 } 671 672 static inline int32_t 673 bnxt_ulp_cntxt_ptr2_matcher_data_set(struct bnxt_ulp_context *ulp_ctx, 674 void *matcher_data) 675 { 676 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 677 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 678 return -EINVAL; 679 } 680 681 ulp_ctx->cfg_data->matcher_data = matcher_data; 682 return 0; 683 } 684 685 static inline void * 686 bnxt_ulp_cntxt_ptr2_matcher_data_get(struct bnxt_ulp_context *ulp_ctx) 687 { 688 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 689 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 690 return NULL; 691 } 692 693 return ulp_ctx->cfg_data->matcher_data; 694 } 695 696 /* Function to set the port database to the ulp context. */ 697 static inline int32_t 698 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx, 699 struct bnxt_ulp_port_db *port_db) 700 { 701 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 702 return -EINVAL; 703 704 ulp_ctx->cfg_data->port_db = port_db; 705 return 0; 706 } 707 708 /* Function to get the port database from the ulp context. */ 709 static inline struct bnxt_ulp_port_db * 710 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx) 711 { 712 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 713 return NULL; 714 715 return ulp_ctx->cfg_data->port_db; 716 } 717 718 /* Function to set the flow counter info into the context */ 719 static inline int32_t 720 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx, 721 struct bnxt_ulp_fc_info *ulp_fc_info) 722 { 723 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 724 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 725 return -EINVAL; 726 } 727 728 ulp_ctx->cfg_data->fc_info = ulp_fc_info; 729 730 return 0; 731 } 732 733 /* Function to retrieve the flow counter info from the context. */ 734 static inline struct bnxt_ulp_fc_info * 735 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx) 736 { 737 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 738 return NULL; 739 740 return ulp_ctx->cfg_data->fc_info; 741 } 742 743 /* Function to set the flow counter info into the context */ 744 static inline int32_t 745 bnxt_ulp_cntxt_ptr2_sc_info_set(struct bnxt_ulp_context *ulp_ctx, 746 struct bnxt_ulp_sc_info *ulp_sc_info) 747 { 748 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) { 749 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 750 return -EINVAL; 751 } 752 753 ulp_ctx->cfg_data->sc_info = ulp_sc_info; 754 755 return 0; 756 } 757 758 /* Function to retrieve the flow counter info from the context. */ 759 static inline struct bnxt_ulp_sc_info * 760 bnxt_ulp_cntxt_ptr2_sc_info_get(struct bnxt_ulp_context *ulp_ctx) 761 { 762 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 763 return NULL; 764 765 return ulp_ctx->cfg_data->sc_info; 766 } 767 768 /* Function to get the ulp flags from the ulp context. */ 769 static inline int32_t 770 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx, 771 uint32_t *flags) 772 { 773 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 774 return -1; 775 776 *flags = ulp_ctx->cfg_data->ulp_flags; 777 return 0; 778 } 779 780 /* Function to get the ulp vfr info from the ulp context. */ 781 static inline struct bnxt_ulp_vfr_rule_info* 782 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx, 783 uint32_t port_id) 784 { 785 if (unlikely(!ulp_ctx || 786 !ulp_ctx->cfg_data || 787 port_id >= RTE_MAX_ETHPORTS)) 788 return NULL; 789 790 return &ulp_ctx->cfg_data->vfr_rule_info[port_id]; 791 } 792 793 /* Function to acquire the flow database lock from the ulp context. */ 794 static inline int32_t 795 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx) 796 { 797 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 798 return -1; 799 800 if (pthread_mutex_lock(&ulp_ctx->cfg_data->flow_db_lock)) { 801 BNXT_DRV_DBG(ERR, "unable to acquire fdb lock\n"); 802 return -1; 803 } 804 return 0; 805 } 806 807 /* Function to release the flow database lock from the ulp context. */ 808 static inline void 809 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx) 810 { 811 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 812 return; 813 814 pthread_mutex_unlock(&ulp_ctx->cfg_data->flow_db_lock); 815 } 816 817 #if (RTE_VERSION_NUM(21, 05, 0, 0) > RTE_VERSION) 818 819 /* Function to extract the action type from the shared action handle. */ 820 static inline uint32_t 821 bnxt_get_shared_action_type(const struct rte_flow_shared_action *handle) 822 { 823 return (uint32_t)(((uint64_t)handle >> 32) & 0xffffffff); 824 } 825 826 /* Function to extract the direction from the shared action handle. */ 827 static inline uint32_t 828 bnxt_get_shared_action_direction(const struct rte_flow_shared_action *handle) 829 { 830 uint32_t shared_type; 831 832 shared_type = bnxt_get_shared_action_type(handle); 833 return shared_type & 0x1 ? BNXT_ULP_FLOW_ATTR_EGRESS : 834 BNXT_ULP_FLOW_ATTR_INGRESS; 835 } 836 837 /* Function to extract the action index from the shared action handle. */ 838 static inline uint32_t 839 bnxt_get_shared_action_index(const struct rte_flow_shared_action *handle) 840 { 841 return (uint32_t)((uint64_t)handle & 0xffffffff); 842 } 843 844 #else /* (RTE_VERSION >= RTE_VERSION_NUM(21,05,0,0)) */ 845 846 /* Function to extract the action type from the shared action handle. */ 847 static inline int32_t 848 bnxt_get_action_handle_type(const struct rte_flow_action_handle *handle, 849 uint32_t *action_handle_type) 850 { 851 if (unlikely(!action_handle_type)) 852 return -EINVAL; 853 854 *action_handle_type = (uint32_t)(((uint64_t)handle >> 32) & 0xffffffff); 855 if (*action_handle_type >= BNXT_ULP_GEN_TBL_MAX_SZ) 856 return -EINVAL; 857 858 return 0; 859 } 860 861 /* Function to extract the direction from the shared action handle. */ 862 static inline int32_t 863 bnxt_get_action_handle_direction(const struct rte_flow_action_handle *handle, 864 uint32_t *dir) 865 { 866 uint32_t shared_type; 867 int32_t ret = 0; 868 869 ret = bnxt_get_action_handle_type(handle, &shared_type); 870 if (unlikely(ret)) 871 return ret; 872 873 *dir = shared_type & 0x1 ? BNXT_ULP_DIR_EGRESS : BNXT_ULP_DIR_INGRESS; 874 875 return ret; 876 } 877 878 /* Function to extract the action index from the shared action handle. */ 879 static inline uint32_t 880 bnxt_get_action_handle_index(const struct rte_flow_action_handle *handle) 881 { 882 return (uint32_t)((uint64_t)handle & 0xffffffff); 883 } 884 885 #endif /* RTE_VERSION < RTE_VERSION_NUM(21,05,0,0) */ 886 887 /* Function to set the ha info into the context */ 888 static inline int32_t 889 bnxt_ulp_cntxt_ptr2_ha_info_set(struct bnxt_ulp_context *ulp_ctx, 890 struct bnxt_ulp_ha_mgr_info *ulp_ha_info) 891 { 892 if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) { 893 BNXT_DRV_DBG(ERR, "Invalid ulp context data\n"); 894 return -EINVAL; 895 } 896 ulp_ctx->cfg_data->ha_info = ulp_ha_info; 897 return 0; 898 } 899 900 /* Function to retrieve the ha info from the context. */ 901 static inline struct bnxt_ulp_ha_mgr_info * 902 bnxt_ulp_cntxt_ptr2_ha_info_get(struct bnxt_ulp_context *ulp_ctx) 903 { 904 if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) 905 return NULL; 906 return ulp_ctx->cfg_data->ha_info; 907 } 908 909 static inline bool 910 bnxt_ulp_cntxt_ha_enabled(struct bnxt_ulp_context *ulp_ctx) 911 { 912 if (unlikely(ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)) 913 return false; 914 return !!ULP_HIGH_AVAIL_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags); 915 } 916 917 /* Function to get the app tunnel details from the ulp context. */ 918 static inline struct bnxt_flow_app_tun_ent * 919 bnxt_ulp_cntxt_ptr2_app_tun_list_get(struct bnxt_ulp_context *ulp) 920 { 921 if (unlikely(!ulp || !ulp->cfg_data)) 922 return NULL; 923 924 return ulp->cfg_data->app_tun; 925 } 926 927 /* Function to get the truflow app id. This defined in the build file */ 928 static inline uint32_t 929 bnxt_ulp_default_app_id_get(void) 930 { 931 return BNXT_TF_APP_ID; 932 } 933 934 /* Function to convert ulp dev id to regular dev id. */ 935 static inline uint32_t 936 bnxt_ulp_cntxt_convert_dev_id(uint32_t ulp_dev_id) 937 { 938 enum tf_device_type type = 0; 939 940 switch (ulp_dev_id) { 941 case BNXT_ULP_DEVICE_ID_WH_PLUS: 942 type = TF_DEVICE_TYPE_P4; 943 break; 944 case BNXT_ULP_DEVICE_ID_STINGRAY: 945 type = TF_DEVICE_TYPE_SR; 946 break; 947 case BNXT_ULP_DEVICE_ID_THOR: 948 type = TF_DEVICE_TYPE_P5; 949 break; 950 default: 951 BNXT_DRV_DBG(ERR, "Invalid device id\n"); 952 break; 953 } 954 return type; 955 } 956 957 /* This function sets the IF table index for the 958 * Application to poll to get the hot upgrade state and count details from 959 * the firmware. 960 */ 961 static inline int32_t 962 bnxt_ulp_cntxt_ha_reg_set(struct bnxt_ulp_context *ulp_ctx, 963 uint8_t state, uint8_t cnt) 964 { 965 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 966 return -EINVAL; 967 968 if (ULP_MULTI_SHARED_IS_SUPPORTED(ulp_ctx)) { 969 ulp_ctx->cfg_data->hu_reg_state = state; 970 ulp_ctx->cfg_data->hu_reg_cnt = cnt; 971 } else { 972 ulp_ctx->cfg_data->hu_reg_state = ULP_HA_IF_TBL_IDX; 973 ulp_ctx->cfg_data->hu_reg_cnt = ULP_HA_CLIENT_CNT_IF_TBL_IDX; 974 } 975 return 0; 976 } 977 978 /* This function gets the IF table index for the 979 * Application to poll to get the application hot upgrade state from 980 * the firmware. 981 */ 982 static inline uint32_t 983 bnxt_ulp_cntxt_ha_reg_state_get(struct bnxt_ulp_context *ulp_ctx) 984 { 985 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 986 return 0; 987 988 return (uint32_t)ulp_ctx->cfg_data->hu_reg_state; 989 } 990 991 /* This function gets the IF table index for the 992 * Application to poll to get the application count from 993 * the firmware. 994 */ 995 static inline uint32_t 996 bnxt_ulp_cntxt_ha_reg_cnt_get(struct bnxt_ulp_context *ulp_ctx) 997 { 998 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 999 return 0; 1000 1001 return (uint32_t)ulp_ctx->cfg_data->hu_reg_cnt; 1002 } 1003 1004 /* This function sets the number of key recipes supported 1005 * Generally, this should be set to the number of flexible keys 1006 * supported 1007 */ 1008 static inline void 1009 bnxt_ulp_num_key_recipes_set(struct bnxt_ulp_context *ulp_ctx, 1010 uint16_t num_recipes) 1011 { 1012 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1013 return; 1014 ulp_ctx->cfg_data->num_key_recipes_per_dir = num_recipes; 1015 } 1016 1017 /* This function gets the number of key recipes supported */ 1018 static inline int32_t 1019 bnxt_ulp_num_key_recipes_get(struct bnxt_ulp_context *ulp_ctx) 1020 { 1021 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1022 return 0; 1023 return ulp_ctx->cfg_data->num_key_recipes_per_dir; 1024 } 1025 1026 /* This function gets the feature bits */ 1027 static inline uint64_t 1028 bnxt_ulp_feature_bits_get(struct bnxt_ulp_context *ulp_ctx) 1029 { 1030 if (unlikely(!ulp_ctx || !ulp_ctx->cfg_data)) 1031 return 0; 1032 return ulp_ctx->cfg_data->feature_bits; 1033 } 1034 1035 /* Add the VF Rep endpoint to the session */ 1036 static inline int32_t 1037 bnxt_ulp_vfr_session_fid_add(struct bnxt_ulp_context *ulp_ctx, 1038 uint16_t vfr_fid) 1039 { 1040 int32_t rc = 0; 1041 1042 if (unlikely(ulp_ctx == NULL || ulp_ctx->ops == NULL)) 1043 return -EINVAL; 1044 if (ulp_ctx->ops->ulp_vfr_session_fid_add) 1045 rc = ulp_ctx->ops->ulp_vfr_session_fid_add(ulp_ctx, vfr_fid); 1046 1047 return rc; 1048 } 1049 1050 /* Remove the VF Rep endpoint from the session */ 1051 static inline int32_t 1052 bnxt_ulp_vfr_session_fid_rem(struct bnxt_ulp_context *ulp_ctx, 1053 uint16_t vfr_fid) 1054 { 1055 int32_t rc = 0; 1056 1057 if (unlikely(ulp_ctx == NULL || ulp_ctx->ops == NULL)) 1058 return -EINVAL; 1059 if (ulp_ctx->ops->ulp_vfr_session_fid_rem) 1060 rc = ulp_ctx->ops->ulp_vfr_session_fid_rem(ulp_ctx, vfr_fid); 1061 return rc; 1062 } 1063 1064 static inline int32_t 1065 bnxt_ulp_cap_feat_process(uint64_t feat_bits, uint64_t *out_bits) 1066 { 1067 #ifdef RTE_BNXT_TF_FEAT_BITS 1068 uint64_t bit = RTE_BNXT_TF_FEAT_BITS; 1069 #else 1070 uint64_t bit = 0; 1071 #endif 1072 1073 *out_bits = 0; 1074 if ((feat_bits | bit) != feat_bits) { 1075 BNXT_DRV_DBG(ERR, "Invalid TF feature bit is set %" PRIu64 "\n", 1076 bit); 1077 return -EINVAL; 1078 } 1079 if ((bit & BNXT_ULP_FEATURE_BIT_PARENT_DMAC) && 1080 (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC)) { 1081 BNXT_DRV_DBG(ERR, "Invalid both Port and Parent Mac set\n"); 1082 return -EINVAL; 1083 } 1084 1085 if (bit & BNXT_ULP_FEATURE_BIT_PARENT_DMAC) 1086 BNXT_DRV_DBG(ERR, "Parent Mac Address Feature is enabled\n"); 1087 if (bit & BNXT_ULP_FEATURE_BIT_PORT_DMAC) 1088 BNXT_DRV_DBG(ERR, "Port Mac Address Feature is enabled\n"); 1089 if (bit & BNXT_ULP_FEATURE_BIT_MULTI_TUNNEL_FLOW) 1090 BNXT_DRV_DBG(ERR, "Multi Tunnel Flow Feature is enabled\n"); 1091 1092 *out_bits = bit; 1093 return 0; 1094 } 1095 1096 #endif /* _BNXT_ULP_UTILS_H_ */ 1097