1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
7 #include <rte_malloc.h>
9 #include <rte_flow_driver.h>
10 #include <rte_tailq.h>
14 #include "bnxt_tf_common.h"
16 #include "tf_ext_flow_handle.h"
18 #include "ulp_template_db_enum.h"
19 #include "ulp_template_struct.h"
20 #include "ulp_mark_mgr.h"
21 #include "ulp_fc_mgr.h"
22 #include "ulp_flow_db.h"
23 #include "ulp_mapper.h"
24 #include "ulp_port_db.h"
26 #include "ulp_ha_mgr.h"
28 /* Linked list of all TF sessions. */
29 STAILQ_HEAD(, bnxt_ulp_session_state) bnxt_ulp_session_list =
30 STAILQ_HEAD_INITIALIZER(bnxt_ulp_session_list);
32 /* Mutex to synchronize bnxt_ulp_session_list operations. */
33 static pthread_mutex_t bnxt_ulp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
36 * Allow the deletion of context only for the bnxt device that
37 * created the session.
40 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx)
42 if (!ulp_ctx || !ulp_ctx->cfg_data)
45 if (!ulp_ctx->cfg_data->ref_cnt) {
46 BNXT_TF_DBG(DEBUG, "ulp ctx shall initiate deinit\n");
54 bnxt_ulp_devid_get(struct bnxt *bp,
55 enum bnxt_ulp_device_id *ulp_dev_id)
57 if (BNXT_CHIP_P5(bp)) {
58 /* TBD: needs to accommodate even SR2 */
59 *ulp_dev_id = BNXT_ULP_DEVICE_ID_THOR;
63 if (BNXT_STINGRAY(bp))
64 *ulp_dev_id = BNXT_ULP_DEVICE_ID_STINGRAY;
66 /* Assuming Whitney */
67 *ulp_dev_id = BNXT_ULP_DEVICE_ID_WH_PLUS;
72 struct bnxt_ulp_app_capabilities_info *
73 bnxt_ulp_app_cap_list_get(uint32_t *num_entries)
77 *num_entries = BNXT_ULP_APP_CAP_TBL_MAX_SZ;
78 return ulp_app_cap_info_list;
81 static struct bnxt_ulp_resource_resv_info *
82 bnxt_ulp_app_resource_resv_list_get(uint32_t *num_entries)
84 if (num_entries == NULL)
86 *num_entries = BNXT_ULP_APP_RESOURCE_RESV_LIST_MAX_SZ;
87 return ulp_app_resource_resv_list;
90 struct bnxt_ulp_resource_resv_info *
91 bnxt_ulp_resource_resv_list_get(uint32_t *num_entries)
95 *num_entries = BNXT_ULP_RESOURCE_RESV_LIST_MAX_SZ;
96 return ulp_resource_resv_list;
99 struct bnxt_ulp_glb_resource_info *
100 bnxt_ulp_app_glb_resource_info_list_get(uint32_t *num_entries)
104 *num_entries = BNXT_ULP_APP_GLB_RESOURCE_TBL_MAX_SZ;
105 return ulp_app_glb_resource_tbl;
109 bnxt_ulp_named_resources_calc(struct bnxt_ulp_context *ulp_ctx,
110 struct bnxt_ulp_glb_resource_info *info,
112 struct tf_session_resources *res)
114 uint32_t dev_id, res_type, i;
119 if (ulp_ctx == NULL || info == NULL || res == NULL || num == 0) {
120 BNXT_TF_DBG(ERR, "Invalid parms to named resources calc.\n");
124 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
126 BNXT_TF_DBG(ERR, "Unable to get the app id from ulp.\n");
130 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
132 BNXT_TF_DBG(ERR, "Unable to get the dev id from ulp.\n");
136 for (i = 0; i < num; i++) {
137 if (dev_id != info[i].device_id || app_id != info[i].app_id)
139 dir = info[i].direction;
140 res_type = info[i].resource_type;
142 switch (info[i].resource_func) {
143 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
144 res->ident_cnt[dir].cnt[res_type]++;
146 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
147 res->tbl_cnt[dir].cnt[res_type]++;
149 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
150 res->tcam_cnt[dir].cnt[res_type]++;
152 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
153 res->em_cnt[dir].cnt[res_type]++;
156 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n,",
157 info[i].resource_func);
166 bnxt_ulp_unnamed_resources_calc(struct bnxt_ulp_context *ulp_ctx,
167 struct bnxt_ulp_resource_resv_info *info,
169 struct tf_session_resources *res)
171 uint32_t dev_id, res_type, i;
176 if (ulp_ctx == NULL || res == NULL || info == NULL || num == 0) {
177 BNXT_TF_DBG(ERR, "Invalid arguments to get resources.\n");
181 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
183 BNXT_TF_DBG(ERR, "Unable to get the app id from ulp.\n");
187 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
189 BNXT_TF_DBG(ERR, "Unable to get the dev id from ulp.\n");
193 for (i = 0; i < num; i++) {
194 if (app_id != info[i].app_id || dev_id != info[i].device_id)
196 dir = info[i].direction;
197 res_type = info[i].resource_type;
199 switch (info[i].resource_func) {
200 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
201 res->ident_cnt[dir].cnt[res_type] = info[i].count;
203 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
204 res->tbl_cnt[dir].cnt[res_type] = info[i].count;
206 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
207 res->tcam_cnt[dir].cnt[res_type] = info[i].count;
209 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
210 res->em_cnt[dir].cnt[res_type] = info[i].count;
220 bnxt_ulp_tf_resources_get(struct bnxt_ulp_context *ulp_ctx,
221 struct tf_session_resources *res)
223 struct bnxt_ulp_resource_resv_info *unnamed = NULL;
227 if (ulp_ctx == NULL || res == NULL) {
228 BNXT_TF_DBG(ERR, "Invalid arguments to get resources.\n");
232 unnamed = bnxt_ulp_resource_resv_list_get(&unum);
233 if (unnamed == NULL) {
234 BNXT_TF_DBG(ERR, "Unable to get resource resv list.\n");
238 rc = bnxt_ulp_unnamed_resources_calc(ulp_ctx, unnamed, unum, res);
240 BNXT_TF_DBG(ERR, "Unable to calc resources for session.\n");
246 bnxt_ulp_tf_shared_session_resources_get(struct bnxt_ulp_context *ulp_ctx,
247 struct tf_session_resources *res)
249 struct bnxt_ulp_resource_resv_info *unnamed;
250 struct bnxt_ulp_glb_resource_info *named;
254 if (ulp_ctx == NULL || res == NULL) {
255 BNXT_TF_DBG(ERR, "Invalid arguments to get resources.\n");
259 /* Make sure the resources are zero before accumulating. */
260 memset(res, 0, sizeof(struct tf_session_resources));
263 * Shared resources are comprised of both named and unnamed resources.
264 * First get the unnamed counts, and then add the named to the result.
266 /* Get the baseline counts */
267 unnamed = bnxt_ulp_app_resource_resv_list_get(&unum);
268 if (unnamed == NULL) {
269 BNXT_TF_DBG(ERR, "Unable to get shared resource resv list.\n");
272 rc = bnxt_ulp_unnamed_resources_calc(ulp_ctx, unnamed, unum, res);
274 BNXT_TF_DBG(ERR, "Unable to calc resources for shared session.\n");
278 /* Get the named list and add the totals */
279 named = bnxt_ulp_app_glb_resource_info_list_get(&nnum);
281 BNXT_TF_DBG(ERR, "Unable to get app global resource list\n");
284 rc = bnxt_ulp_named_resources_calc(ulp_ctx, named, nnum, res);
286 BNXT_TF_DBG(ERR, "Unable to calc named resources\n");
292 bnxt_ulp_cntxt_app_caps_init(struct bnxt_ulp_context *ulp_ctx,
293 uint8_t app_id, uint32_t dev_id)
295 struct bnxt_ulp_app_capabilities_info *info;
300 if (ULP_APP_DEV_UNSUPPORTED_ENABLED(ulp_ctx->cfg_data->ulp_flags)) {
301 BNXT_TF_DBG(ERR, "APP ID %d, Device ID: 0x%x not supported.\n",
306 info = bnxt_ulp_app_cap_list_get(&num);
308 BNXT_TF_DBG(ERR, "Failed to get app capabilities.\n");
312 for (i = 0; i < num; i++) {
313 if (info[i].app_id != app_id || info[i].device_id != dev_id)
316 if (info[i].flags & BNXT_ULP_APP_CAP_SHARED_EN)
317 ulp_ctx->cfg_data->ulp_flags |=
318 BNXT_ULP_SHARED_SESSION_ENABLED;
319 if (info[i].flags & BNXT_ULP_APP_CAP_HOT_UPGRADE_EN)
320 ulp_ctx->cfg_data->ulp_flags |=
321 BNXT_ULP_HIGH_AVAIL_ENABLED;
324 BNXT_TF_DBG(ERR, "APP ID %d, Device ID: 0x%x not supported.\n",
326 ulp_ctx->cfg_data->ulp_flags |= BNXT_ULP_APP_DEV_UNSUPPORTED;
334 ulp_ctx_shared_session_close(struct bnxt *bp,
335 struct bnxt_ulp_session_state *session)
340 if (!bnxt_ulp_cntxt_shared_session_enabled(bp->ulp_ctx))
343 tfp = bnxt_ulp_cntxt_shared_tfp_get(bp->ulp_ctx);
346 * Log it under debug since this is likely a case of the
347 * shared session not being created. For example, a failed
350 BNXT_TF_DBG(DEBUG, "Failed to get shared tfp on close.\n");
353 rc = tf_close_session(tfp);
355 BNXT_TF_DBG(ERR, "Failed to close the shared session rc=%d.\n",
357 (void)bnxt_ulp_cntxt_shared_tfp_set(bp->ulp_ctx, NULL);
359 session->g_shared_tfp.session = NULL;
363 ulp_ctx_shared_session_open(struct bnxt *bp,
364 struct bnxt_ulp_session_state *session)
366 struct rte_eth_dev *ethdev = bp->eth_dev;
367 struct tf_session_resources *resources;
368 struct tf_open_session_parms parms;
369 size_t copy_num_bytes;
373 /* only perform this if shared session is enabled. */
374 if (!bnxt_ulp_cntxt_shared_session_enabled(bp->ulp_ctx))
377 memset(&parms, 0, sizeof(parms));
379 rc = rte_eth_dev_get_name_by_port(ethdev->data->port_id,
380 parms.ctrl_chan_name);
382 BNXT_TF_DBG(ERR, "Invalid port %d, rc = %d\n",
383 ethdev->data->port_id, rc);
386 resources = &parms.resources;
389 * Need to account for size of ctrl_chan_name and 1 extra for Null
392 copy_num_bytes = sizeof(parms.ctrl_chan_name) -
393 strlen(parms.ctrl_chan_name) - 1;
395 /* Build the ctrl_chan_name with shared token */
396 strncat(parms.ctrl_chan_name, "-tf_shared", copy_num_bytes);
398 rc = bnxt_ulp_tf_shared_session_resources_get(bp->ulp_ctx, resources);
402 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &ulp_dev_id);
404 BNXT_TF_DBG(ERR, "Unable to get device id from ulp.\n");
408 switch (ulp_dev_id) {
409 case BNXT_ULP_DEVICE_ID_WH_PLUS:
410 parms.device_type = TF_DEVICE_TYPE_WH;
412 case BNXT_ULP_DEVICE_ID_STINGRAY:
413 parms.device_type = TF_DEVICE_TYPE_SR;
415 case BNXT_ULP_DEVICE_ID_THOR:
416 parms.device_type = TF_DEVICE_TYPE_THOR;
419 BNXT_TF_DBG(ERR, "Unable to determine dev for opening session.\n");
423 parms.shadow_copy = true;
427 * Open the session here, but the collect the resources during the
428 * mapper initialization.
430 rc = tf_open_session(&bp->tfp_shared, &parms);
434 if (parms.shared_session_creator)
435 BNXT_TF_DBG(DEBUG, "Shared session creator.\n");
437 BNXT_TF_DBG(DEBUG, "Shared session attached.\n");
439 /* Save the shared session in global data */
440 if (!session->g_shared_tfp.session)
441 session->g_shared_tfp.session = bp->tfp_shared.session;
443 rc = bnxt_ulp_cntxt_shared_tfp_set(bp->ulp_ctx, &bp->tfp_shared);
445 BNXT_TF_DBG(ERR, "Failed to add shared tfp to ulp (%d)\n", rc);
451 ulp_ctx_shared_session_attach(struct bnxt *bp,
452 struct bnxt_ulp_session_state *session)
456 /* Simply return success if shared session not enabled */
457 if (bnxt_ulp_cntxt_shared_session_enabled(bp->ulp_ctx)) {
458 bp->tfp_shared.session = session->g_shared_tfp.session;
459 rc = ulp_ctx_shared_session_open(bp, session);
466 ulp_ctx_shared_session_detach(struct bnxt *bp)
468 if (bnxt_ulp_cntxt_shared_session_enabled(bp->ulp_ctx)) {
469 if (bp->tfp_shared.session) {
470 tf_close_session(&bp->tfp_shared);
471 bp->tfp_shared.session = NULL;
477 * Initialize an ULP session.
478 * An ULP session will contain all the resources needed to support rte flow
479 * offloads. A session is initialized as part of rte_eth_device start.
480 * A single vswitch instance can have multiple uplinks which means
481 * rte_eth_device start will be called for each of these devices.
482 * ULP session manager will make sure that a single ULP session is only
483 * initialized once. Apart from this, it also initializes MARK database,
484 * EEM table & flow database. ULP session manager also manages a list of
485 * all opened ULP sessions.
488 ulp_ctx_session_open(struct bnxt *bp,
489 struct bnxt_ulp_session_state *session)
491 struct rte_eth_dev *ethdev = bp->eth_dev;
493 struct tf_open_session_parms params;
494 struct tf_session_resources *resources;
497 memset(¶ms, 0, sizeof(params));
499 rc = rte_eth_dev_get_name_by_port(ethdev->data->port_id,
500 params.ctrl_chan_name);
502 BNXT_TF_DBG(ERR, "Invalid port %d, rc = %d\n",
503 ethdev->data->port_id, rc);
507 params.shadow_copy = true;
509 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &ulp_dev_id);
511 BNXT_TF_DBG(ERR, "Unable to get device id from ulp.\n");
515 switch (ulp_dev_id) {
516 case BNXT_ULP_DEVICE_ID_WH_PLUS:
517 params.device_type = TF_DEVICE_TYPE_WH;
519 case BNXT_ULP_DEVICE_ID_STINGRAY:
520 params.device_type = TF_DEVICE_TYPE_SR;
522 case BNXT_ULP_DEVICE_ID_THOR:
523 params.device_type = TF_DEVICE_TYPE_THOR;
526 BNXT_TF_DBG(ERR, "Unable to determine device for opening session.\n");
530 resources = ¶ms.resources;
531 rc = bnxt_ulp_tf_resources_get(bp->ulp_ctx, resources);
536 rc = tf_open_session(&bp->tfp, ¶ms);
538 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
539 params.ctrl_chan_name, rc);
542 if (!session->session_opened) {
543 session->session_opened = 1;
544 session->g_tfp = rte_zmalloc("bnxt_ulp_session_tfp",
545 sizeof(struct tf), 0);
546 session->g_tfp->session = bp->tfp.session;
552 * Close the ULP session.
553 * It takes the ulp context pointer.
556 ulp_ctx_session_close(struct bnxt *bp,
557 struct bnxt_ulp_session_state *session)
559 /* close the session in the hardware */
560 if (session->session_opened)
561 tf_close_session(&bp->tfp);
562 session->session_opened = 0;
563 rte_free(session->g_tfp);
564 session->g_tfp = NULL;
568 bnxt_init_tbl_scope_parms(struct bnxt *bp,
569 struct tf_alloc_tbl_scope_parms *params)
571 struct bnxt_ulp_device_params *dparms;
575 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
577 /* TBD: For now, just use default. */
580 dparms = bnxt_ulp_device_params_get(dev_id);
583 * Set the flush timer for EEM entries. The value is in 100ms intervals,
586 params->hw_flow_cache_flush_timer = 100;
589 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
590 params->rx_max_action_entry_sz_in_bits =
591 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
592 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
593 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
595 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
596 params->tx_max_action_entry_sz_in_bits =
597 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
598 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
599 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
601 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
602 params->rx_max_action_entry_sz_in_bits =
603 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
604 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
605 params->rx_num_flows_in_k =
606 dparms->ext_flow_db_num_entries / 1024;
608 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
609 params->tx_max_action_entry_sz_in_bits =
610 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
611 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
612 params->tx_num_flows_in_k =
613 dparms->ext_flow_db_num_entries / 1024;
615 BNXT_TF_DBG(INFO, "Table Scope initialized with %uK flows.\n",
616 params->rx_num_flows_in_k);
619 /* Initialize Extended Exact Match host memory. */
621 ulp_eem_tbl_scope_init(struct bnxt *bp)
623 struct tf_alloc_tbl_scope_parms params = {0};
624 struct bnxt_ulp_device_params *dparms;
625 enum bnxt_ulp_flow_mem_type mtype;
629 /* Get the dev specific number of flows that needed to be supported. */
630 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
631 BNXT_TF_DBG(ERR, "Invalid device id\n");
635 dparms = bnxt_ulp_device_params_get(dev_id);
637 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
641 if (bnxt_ulp_cntxt_mem_type_get(bp->ulp_ctx, &mtype))
643 if (mtype != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
644 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
648 bnxt_init_tbl_scope_parms(bp, ¶ms);
649 rc = tf_alloc_tbl_scope(&bp->tfp, ¶ms);
651 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
655 rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
657 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
664 /* Free Extended Exact Match host memory */
666 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
668 struct tf_free_tbl_scope_parms params = {0};
671 struct bnxt_ulp_device_params *dparms;
672 enum bnxt_ulp_flow_mem_type mtype;
675 if (!ulp_ctx || !ulp_ctx->cfg_data)
678 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
680 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
684 /* Get the dev specific number of flows that needed to be supported. */
685 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
686 BNXT_TF_DBG(ERR, "Invalid device id\n");
690 dparms = bnxt_ulp_device_params_get(dev_id);
692 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
696 if (bnxt_ulp_cntxt_mem_type_get(ulp_ctx, &mtype))
698 if (mtype != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
699 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
703 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, ¶ms.tbl_scope_id);
705 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
709 rc = tf_free_tbl_scope(tfp, ¶ms);
711 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
717 /* The function to free and deinit the ulp context data. */
719 ulp_ctx_deinit(struct bnxt *bp,
720 struct bnxt_ulp_session_state *session)
722 /* close the tf session */
723 ulp_ctx_session_close(bp, session);
725 /* The shared session must be closed last. */
726 ulp_ctx_shared_session_close(bp, session);
728 /* Free the contents */
729 if (session->cfg_data) {
730 rte_free(session->cfg_data);
731 bp->ulp_ctx->cfg_data = NULL;
732 session->cfg_data = NULL;
737 /* The function to allocate and initialize the ulp context data. */
739 ulp_ctx_init(struct bnxt *bp,
740 struct bnxt_ulp_session_state *session)
742 struct bnxt_ulp_data *ulp_data;
744 enum bnxt_ulp_device_id devid;
746 /* Allocate memory to hold ulp context data. */
747 ulp_data = rte_zmalloc("bnxt_ulp_data",
748 sizeof(struct bnxt_ulp_data), 0);
750 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
754 /* Increment the ulp context data reference count usage. */
755 bp->ulp_ctx->cfg_data = ulp_data;
756 session->cfg_data = ulp_data;
758 ulp_data->ulp_flags |= BNXT_ULP_VF_REP_ENABLED;
760 rc = bnxt_ulp_devid_get(bp, &devid);
762 BNXT_TF_DBG(ERR, "Unable to determine device for ULP init.\n");
766 rc = bnxt_ulp_cntxt_dev_id_set(bp->ulp_ctx, devid);
768 BNXT_TF_DBG(ERR, "Unable to set device for ULP init.\n");
772 rc = bnxt_ulp_cntxt_app_id_set(bp->ulp_ctx, bp->app_id);
774 BNXT_TF_DBG(ERR, "Unable to set app_id for ULP init.\n");
778 rc = bnxt_ulp_cntxt_app_caps_init(bp->ulp_ctx, bp->app_id, devid);
780 BNXT_TF_DBG(ERR, "Unable to set caps for app(%x)/dev(%x)\n",
786 * Shared session must be created before first regular session but after
787 * the ulp_ctx is valid.
789 rc = ulp_ctx_shared_session_open(bp, session);
791 BNXT_TF_DBG(ERR, "Unable to open shared session (%d)\n", rc);
795 /* Open the ulp session. */
796 rc = ulp_ctx_session_open(bp, session);
800 ulp_tun_tbl_init(ulp_data->tun_tbl);
802 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, &bp->tfp);
806 session->session_opened = 1;
807 (void)ulp_ctx_deinit(bp, session);
811 /* The function to initialize ulp dparms with devargs */
813 ulp_dparms_init(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
815 struct bnxt_ulp_device_params *dparms;
818 if (!bp->max_num_kflows) {
819 /* Defaults to Internal */
820 bnxt_ulp_cntxt_mem_type_set(ulp_ctx,
821 BNXT_ULP_FLOW_MEM_TYPE_INT);
825 /* The max_num_kflows were set, so move to external */
826 if (bnxt_ulp_cntxt_mem_type_set(ulp_ctx, BNXT_ULP_FLOW_MEM_TYPE_EXT))
829 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
830 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
834 dparms = bnxt_ulp_device_params_get(dev_id);
836 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
840 /* num_flows = max_num_kflows * 1024 */
841 dparms->ext_flow_db_num_entries = bp->max_num_kflows * 1024;
842 /* GFID = 2 * num_flows */
843 dparms->mark_db_gfid_entries = dparms->ext_flow_db_num_entries * 2;
844 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
845 dparms->ext_flow_db_num_entries);
850 /* The function to initialize bp flags with truflow features */
852 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
853 struct bnxt_ulp_context *ulp_ctx)
855 enum bnxt_ulp_flow_mem_type mtype;
857 if (bnxt_ulp_cntxt_mem_type_get(ulp_ctx, &mtype))
859 /* Update the bp flag with gfid flag */
860 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT)
861 bp->flags |= BNXT_FLAG_GFID_ENABLE;
867 ulp_ctx_attach(struct bnxt *bp,
868 struct bnxt_ulp_session_state *session)
871 uint32_t flags, dev_id;
874 /* Increment the ulp context data reference count usage. */
875 bp->ulp_ctx->cfg_data = session->cfg_data;
876 bp->ulp_ctx->cfg_data->ref_cnt++;
878 /* update the session details in bnxt tfp */
879 bp->tfp.session = session->g_tfp->session;
882 * The supported flag will be set during the init. Use it now to
883 * know if we should go through the attach.
885 rc = bnxt_ulp_cntxt_app_id_get(bp->ulp_ctx, &app_id);
887 BNXT_TF_DBG(ERR, "Unable to get the app id from ulp.\n");
891 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
893 BNXT_TF_DBG(ERR, "Unable do get the dev_id.\n");
897 flags = bp->ulp_ctx->cfg_data->ulp_flags;
898 if (ULP_APP_DEV_UNSUPPORTED_ENABLED(flags)) {
899 BNXT_TF_DBG(ERR, "APP ID %d, Device ID: 0x%x not supported.\n",
904 /* Create a TF Client */
905 rc = ulp_ctx_session_open(bp, session);
907 PMD_DRV_LOG(ERR, "Failed to open ctxt session, rc:%d\n", rc);
908 bp->tfp.session = NULL;
912 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, &bp->tfp);
917 ulp_ctx_detach(struct bnxt *bp)
919 if (bp->tfp.session) {
920 tf_close_session(&bp->tfp);
921 bp->tfp.session = NULL;
926 * Initialize the state of an ULP session.
927 * If the state of an ULP session is not initialized, set it's state to
928 * initialized. If the state is already initialized, do nothing.
931 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
933 pthread_mutex_lock(&session->bnxt_ulp_mutex);
935 if (!session->bnxt_ulp_init) {
936 session->bnxt_ulp_init = true;
942 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
946 * Check if an ULP session is already allocated for a specific PCI
947 * domain & bus. If it is already allocated simply return the session
948 * pointer, otherwise allocate a new session.
950 static struct bnxt_ulp_session_state *
951 ulp_get_session(struct rte_pci_addr *pci_addr)
953 struct bnxt_ulp_session_state *session;
955 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
956 if (session->pci_info.domain == pci_addr->domain &&
957 session->pci_info.bus == pci_addr->bus) {
965 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
966 * If it's already initialized simply return the already existing session.
968 static struct bnxt_ulp_session_state *
969 ulp_session_init(struct bnxt *bp,
972 struct rte_pci_device *pci_dev;
973 struct rte_pci_addr *pci_addr;
974 struct bnxt_ulp_session_state *session;
980 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
981 pci_addr = &pci_dev->addr;
983 pthread_mutex_lock(&bnxt_ulp_global_mutex);
985 session = ulp_get_session(pci_addr);
987 /* Not Found the session Allocate a new one */
988 session = rte_zmalloc("bnxt_ulp_session",
989 sizeof(struct bnxt_ulp_session_state),
993 "Allocation failed for bnxt_ulp_session\n");
994 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
998 /* Add it to the queue */
999 session->pci_info.domain = pci_addr->domain;
1000 session->pci_info.bus = pci_addr->bus;
1001 rc = pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
1003 BNXT_TF_DBG(ERR, "mutex create failed\n");
1004 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
1007 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
1011 ulp_context_initialized(session, init);
1012 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
1017 * When a device is closed, remove it's associated session from the global
1021 ulp_session_deinit(struct bnxt_ulp_session_state *session)
1026 if (!session->cfg_data) {
1027 pthread_mutex_lock(&bnxt_ulp_global_mutex);
1028 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
1029 bnxt_ulp_session_state, next);
1030 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
1032 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
1037 * Internal api to enable NAT feature.
1038 * Set set_flag to 1 to set the value or zero to reset the value.
1039 * returns 0 on success.
1042 bnxt_ulp_global_cfg_update(struct bnxt *bp,
1044 enum tf_global_config_type type,
1049 uint32_t global_cfg = 0;
1051 struct tf_global_cfg_parms parms = { 0 };
1053 /* Initialize the params */
1056 parms.offset = offset,
1057 parms.config = (uint8_t *)&global_cfg,
1058 parms.config_sz_in_bytes = sizeof(global_cfg);
1060 rc = tf_get_global_cfg(&bp->tfp, &parms);
1062 BNXT_TF_DBG(ERR, "Failed to get global cfg 0x%x rc:%d\n",
1068 global_cfg |= value;
1070 global_cfg &= ~value;
1072 /* SET the register RE_CFA_REG_ACT_TECT */
1073 rc = tf_set_global_cfg(&bp->tfp, &parms);
1075 BNXT_TF_DBG(ERR, "Failed to set global cfg 0x%x rc:%d\n",
1082 /* Internal function to delete all the flows belonging to the given port */
1084 bnxt_ulp_flush_port_flows(struct bnxt *bp)
1088 /* it is assumed that port is either TVF or PF */
1089 if (ulp_port_db_port_func_id_get(bp->ulp_ctx,
1090 bp->eth_dev->data->port_id,
1092 BNXT_TF_DBG(ERR, "Invalid argument\n");
1095 (void)ulp_flow_db_function_flow_flush(bp->ulp_ctx, func_id);
1098 /* Internal function to delete the VFR default flows */
1100 bnxt_ulp_destroy_vfr_default_rules(struct bnxt *bp, bool global)
1102 struct bnxt_ulp_vfr_rule_info *info;
1104 struct rte_eth_dev *vfr_eth_dev;
1105 struct bnxt_representor *vfr_bp;
1107 if (!BNXT_TRUFLOW_EN(bp) || BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev))
1110 if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
1113 /* Delete default rules for all ports */
1114 for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
1115 info = &bp->ulp_ctx->cfg_data->vfr_rule_info[port_id];
1119 if (!global && info->parent_port_id !=
1120 bp->eth_dev->data->port_id)
1123 /* Destroy the flows */
1124 ulp_default_flow_destroy(bp->eth_dev, info->vfr_flow_id);
1125 /* Clean up the tx action pointer */
1126 vfr_eth_dev = &rte_eth_devices[port_id];
1128 vfr_bp = vfr_eth_dev->data->dev_private;
1129 vfr_bp->vfr_tx_cfa_action = 0;
1131 memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
1136 * When a port is deinit'ed by dpdk. This function is called
1137 * and this function clears the ULP context and rest of the
1138 * infrastructure associated with it.
1141 bnxt_ulp_deinit(struct bnxt *bp,
1142 struct bnxt_ulp_session_state *session)
1146 if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
1149 ha_enabled = bnxt_ulp_cntxt_ha_enabled(bp->ulp_ctx);
1150 if (ha_enabled && session->session_opened) {
1151 int32_t rc = ulp_ha_mgr_close(bp->ulp_ctx);
1153 BNXT_TF_DBG(ERR, "Failed to close HA (%d)\n", rc);
1156 /* clean up default flows */
1157 bnxt_ulp_destroy_df_rules(bp, true);
1159 /* clean up default VFR flows */
1160 bnxt_ulp_destroy_vfr_default_rules(bp, true);
1162 /* clean up regular flows */
1163 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR);
1165 /* cleanup the eem table scope */
1166 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
1168 /* cleanup the flow database */
1169 ulp_flow_db_deinit(bp->ulp_ctx);
1171 /* Delete the Mark database */
1172 ulp_mark_db_deinit(bp->ulp_ctx);
1174 /* cleanup the ulp mapper */
1175 ulp_mapper_deinit(bp->ulp_ctx);
1177 /* Delete the Flow Counter Manager */
1178 ulp_fc_mgr_deinit(bp->ulp_ctx);
1180 /* Delete the Port database */
1181 ulp_port_db_deinit(bp->ulp_ctx);
1183 /* Disable NAT feature */
1184 (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
1185 TF_TUNNEL_ENCAP_NAT,
1186 BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
1188 (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
1189 TF_TUNNEL_ENCAP_NAT,
1190 BNXT_ULP_NAT_OUTER_MOST_FLAGS, 0);
1192 /* free the flow db lock */
1193 pthread_mutex_destroy(&bp->ulp_ctx->cfg_data->flow_db_lock);
1196 ulp_ha_mgr_deinit(bp->ulp_ctx);
1198 /* Delete the ulp context and tf session and free the ulp context */
1199 ulp_ctx_deinit(bp, session);
1200 BNXT_TF_DBG(DEBUG, "ulp ctx has been deinitialized\n");
1204 * When a port is initialized by dpdk. This functions is called
1205 * and this function initializes the ULP context and rest of the
1206 * infrastructure associated with it.
1209 bnxt_ulp_init(struct bnxt *bp,
1210 struct bnxt_ulp_session_state *session)
1214 /* Allocate and Initialize the ulp context. */
1215 rc = ulp_ctx_init(bp, session);
1217 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
1221 rc = pthread_mutex_init(&bp->ulp_ctx->cfg_data->flow_db_lock, NULL);
1223 BNXT_TF_DBG(ERR, "Unable to initialize flow db lock\n");
1227 /* Initialize ulp dparms with values devargs passed */
1228 rc = ulp_dparms_init(bp, bp->ulp_ctx);
1230 BNXT_TF_DBG(ERR, "Failed to initialize the dparms\n");
1234 /* create the port database */
1235 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
1237 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
1241 /* Create the Mark database. */
1242 rc = ulp_mark_db_init(bp->ulp_ctx);
1244 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
1248 /* Create the flow database. */
1249 rc = ulp_flow_db_init(bp->ulp_ctx);
1251 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
1255 /* Create the eem table scope. */
1256 rc = ulp_eem_tbl_scope_init(bp);
1258 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
1262 rc = ulp_mapper_init(bp->ulp_ctx);
1264 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
1268 rc = ulp_fc_mgr_init(bp->ulp_ctx);
1270 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
1275 * Enable NAT feature. Set the global configuration register
1276 * Tunnel encap to enable NAT with the reuse of existing inner
1277 * L2 header smac and dmac
1279 rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
1280 TF_TUNNEL_ENCAP_NAT,
1281 BNXT_ULP_NAT_OUTER_MOST_FLAGS, 1);
1283 BNXT_TF_DBG(ERR, "Failed to set rx global configuration\n");
1287 rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
1288 TF_TUNNEL_ENCAP_NAT,
1289 BNXT_ULP_NAT_OUTER_MOST_FLAGS, 1);
1291 BNXT_TF_DBG(ERR, "Failed to set tx global configuration\n");
1295 if (bnxt_ulp_cntxt_ha_enabled(bp->ulp_ctx)) {
1296 rc = ulp_ha_mgr_init(bp->ulp_ctx);
1298 BNXT_TF_DBG(ERR, "Failed to initialize HA %d\n", rc);
1301 rc = ulp_ha_mgr_open(bp->ulp_ctx);
1303 BNXT_TF_DBG(ERR, "Failed to Process HA Open %d\n", rc);
1307 BNXT_TF_DBG(DEBUG, "ulp ctx has been initialized\n");
1311 bnxt_ulp_deinit(bp, session);
1316 * When a port is initialized by dpdk. This functions sets up
1317 * the port specific details.
1320 bnxt_ulp_port_init(struct bnxt *bp)
1322 struct bnxt_ulp_session_state *session;
1326 if (!bp || !BNXT_TRUFLOW_EN(bp))
1329 if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
1331 "Skip ulp init for port: %d, not a TVF or PF\n",
1332 bp->eth_dev->data->port_id);
1337 BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
1341 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
1342 sizeof(struct bnxt_ulp_context), 0);
1344 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
1349 * Multiple uplink ports can be associated with a single vswitch.
1350 * Make sure only the port that is started first will initialize
1353 session = ulp_session_init(bp, &initialized);
1355 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
1362 * If ULP is already initialized for a specific domain then
1363 * simply assign the ulp context to this rte_eth_dev.
1365 rc = ulp_ctx_attach(bp, session);
1367 BNXT_TF_DBG(ERR, "Failed to attach the ulp context\n");
1372 * Attach to the shared session, must be called after the
1373 * ulp_ctx_attach in order to ensure that ulp data is available
1376 rc = ulp_ctx_shared_session_attach(bp, session);
1379 "Failed attach to shared session (%d)", rc);
1383 rc = bnxt_ulp_init(bp, session);
1385 BNXT_TF_DBG(ERR, "Failed to initialize the ulp init\n");
1390 /* Update bnxt driver flags */
1391 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
1393 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
1397 /* update the port database for the given interface */
1398 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
1400 BNXT_TF_DBG(ERR, "Failed to update port database\n");
1403 /* create the default rules */
1404 rc = bnxt_ulp_create_df_rules(bp);
1406 BNXT_TF_DBG(ERR, "Failed to create default flow\n");
1410 if (BNXT_ACCUM_STATS_EN(bp))
1411 bp->ulp_ctx->cfg_data->accum_stats = true;
1413 BNXT_TF_DBG(DEBUG, "BNXT Port:%d ULP port init\n",
1414 bp->eth_dev->data->port_id);
1418 bnxt_ulp_port_deinit(bp);
1423 * When a port is de-initialized by dpdk. This functions clears up
1424 * the port specific details.
1427 bnxt_ulp_port_deinit(struct bnxt *bp)
1429 struct bnxt_ulp_session_state *session;
1430 struct rte_pci_device *pci_dev;
1431 struct rte_pci_addr *pci_addr;
1433 if (!BNXT_TRUFLOW_EN(bp))
1436 if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
1438 "Skip ULP deinit port:%d, not a TVF or PF\n",
1439 bp->eth_dev->data->port_id);
1444 BNXT_TF_DBG(DEBUG, "ulp ctx already de-allocated\n");
1448 BNXT_TF_DBG(DEBUG, "BNXT Port:%d ULP port deinit\n",
1449 bp->eth_dev->data->port_id);
1451 /* Get the session details */
1452 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
1453 pci_addr = &pci_dev->addr;
1454 pthread_mutex_lock(&bnxt_ulp_global_mutex);
1455 session = ulp_get_session(pci_addr);
1456 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
1458 /* session not found then just exit */
1460 /* Free the ulp context */
1461 rte_free(bp->ulp_ctx);
1466 /* Check the reference count to deinit or deattach*/
1467 if (bp->ulp_ctx->cfg_data && bp->ulp_ctx->cfg_data->ref_cnt) {
1468 bp->ulp_ctx->cfg_data->ref_cnt--;
1469 if (bp->ulp_ctx->cfg_data->ref_cnt) {
1470 /* free the port details */
1471 /* Free the default flow rule associated to this port */
1472 bnxt_ulp_destroy_df_rules(bp, false);
1473 bnxt_ulp_destroy_vfr_default_rules(bp, false);
1475 /* free flows associated with this port */
1476 bnxt_ulp_flush_port_flows(bp);
1478 /* close the session associated with this port */
1481 /* always detach/close shared after the session. */
1482 ulp_ctx_shared_session_detach(bp);
1484 /* Perform ulp ctx deinit */
1485 bnxt_ulp_deinit(bp, session);
1489 /* clean up the session */
1490 ulp_session_deinit(session);
1492 /* Free the ulp context */
1493 rte_free(bp->ulp_ctx);
1497 /* Below are the access functions to access internal data of ulp context. */
1498 /* Function to set the Mark DB into the context */
1500 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
1501 struct bnxt_ulp_mark_tbl *mark_tbl)
1503 if (!ulp_ctx || !ulp_ctx->cfg_data) {
1504 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1508 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
1513 /* Function to retrieve the Mark DB from the context. */
1514 struct bnxt_ulp_mark_tbl *
1515 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
1517 if (!ulp_ctx || !ulp_ctx->cfg_data)
1520 return ulp_ctx->cfg_data->mark_tbl;
1524 bnxt_ulp_cntxt_shared_session_enabled(struct bnxt_ulp_context *ulp_ctx)
1526 return ULP_SHARED_SESSION_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags);
1530 bnxt_ulp_cntxt_app_id_set(struct bnxt_ulp_context *ulp_ctx, uint8_t app_id)
1534 ulp_ctx->cfg_data->app_id = app_id;
1539 bnxt_ulp_cntxt_app_id_get(struct bnxt_ulp_context *ulp_ctx, uint8_t *app_id)
1541 /* Default APP id is zero */
1542 if (!ulp_ctx || !app_id)
1544 *app_id = ulp_ctx->cfg_data->app_id;
1548 /* Function to set the device id of the hardware. */
1550 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
1553 if (ulp_ctx && ulp_ctx->cfg_data) {
1554 ulp_ctx->cfg_data->dev_id = dev_id;
1561 /* Function to get the device id of the hardware. */
1563 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
1566 if (ulp_ctx && ulp_ctx->cfg_data) {
1567 *dev_id = ulp_ctx->cfg_data->dev_id;
1571 BNXT_TF_DBG(ERR, "Failed to read dev_id from ulp ctxt\n");
1576 bnxt_ulp_cntxt_mem_type_set(struct bnxt_ulp_context *ulp_ctx,
1577 enum bnxt_ulp_flow_mem_type mem_type)
1579 if (ulp_ctx && ulp_ctx->cfg_data) {
1580 ulp_ctx->cfg_data->mem_type = mem_type;
1583 BNXT_TF_DBG(ERR, "Failed to write mem_type in ulp ctxt\n");
1588 bnxt_ulp_cntxt_mem_type_get(struct bnxt_ulp_context *ulp_ctx,
1589 enum bnxt_ulp_flow_mem_type *mem_type)
1591 if (ulp_ctx && ulp_ctx->cfg_data) {
1592 *mem_type = ulp_ctx->cfg_data->mem_type;
1595 BNXT_TF_DBG(ERR, "Failed to read mem_type in ulp ctxt\n");
1599 /* Function to get the table scope id of the EEM table. */
1601 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
1602 uint32_t *tbl_scope_id)
1604 if (ulp_ctx && ulp_ctx->cfg_data) {
1605 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
1612 /* Function to set the table scope id of the EEM table. */
1614 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
1615 uint32_t tbl_scope_id)
1617 if (ulp_ctx && ulp_ctx->cfg_data) {
1618 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
1625 /* Function to set the shared tfp session details from the ulp context. */
1627 bnxt_ulp_cntxt_shared_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
1630 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1634 ulp->g_shared_tfp = tfp;
1638 /* Function to get the shared tfp session details from the ulp context. */
1640 bnxt_ulp_cntxt_shared_tfp_get(struct bnxt_ulp_context *ulp)
1643 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1646 return ulp->g_shared_tfp;
1649 /* Function to set the tfp session details from the ulp context. */
1651 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
1654 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1662 /* Function to get the tfp session details from the ulp context. */
1664 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp,
1665 enum bnxt_ulp_shared_session shared)
1668 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1672 return ulp->g_shared_tfp;
1678 * Get the device table entry based on the device id.
1680 * dev_id [in] The device id of the hardware
1682 * Returns the pointer to the device parameters.
1684 struct bnxt_ulp_device_params *
1685 bnxt_ulp_device_params_get(uint32_t dev_id)
1687 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
1688 return &ulp_device_params[dev_id];
1692 /* Function to set the flow database to the ulp context. */
1694 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
1695 struct bnxt_ulp_flow_db *flow_db)
1697 if (!ulp_ctx || !ulp_ctx->cfg_data)
1700 ulp_ctx->cfg_data->flow_db = flow_db;
1704 /* Function to get the flow database from the ulp context. */
1705 struct bnxt_ulp_flow_db *
1706 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
1708 if (!ulp_ctx || !ulp_ctx->cfg_data)
1711 return ulp_ctx->cfg_data->flow_db;
1714 /* Function to get the tunnel cache table info from the ulp context. */
1715 struct bnxt_tun_cache_entry *
1716 bnxt_ulp_cntxt_ptr2_tun_tbl_get(struct bnxt_ulp_context *ulp_ctx)
1718 if (!ulp_ctx || !ulp_ctx->cfg_data)
1721 return ulp_ctx->cfg_data->tun_tbl;
1724 /* Function to get the ulp context from eth device. */
1725 struct bnxt_ulp_context *
1726 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
1728 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1730 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
1731 struct bnxt_representor *vfr = dev->data->dev_private;
1733 bp = vfr->parent_dev->data->dev_private;
1737 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
1744 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
1747 if (!ulp_ctx || !ulp_ctx->cfg_data) {
1748 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1752 ulp_ctx->cfg_data->mapper_data = mapper_data;
1757 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
1759 if (!ulp_ctx || !ulp_ctx->cfg_data) {
1760 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1764 return ulp_ctx->cfg_data->mapper_data;
1767 /* Function to set the port database to the ulp context. */
1769 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
1770 struct bnxt_ulp_port_db *port_db)
1772 if (!ulp_ctx || !ulp_ctx->cfg_data)
1775 ulp_ctx->cfg_data->port_db = port_db;
1779 /* Function to get the port database from the ulp context. */
1780 struct bnxt_ulp_port_db *
1781 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
1783 if (!ulp_ctx || !ulp_ctx->cfg_data)
1786 return ulp_ctx->cfg_data->port_db;
1789 /* Function to set the flow counter info into the context */
1791 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
1792 struct bnxt_ulp_fc_info *ulp_fc_info)
1794 if (!ulp_ctx || !ulp_ctx->cfg_data) {
1795 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1799 ulp_ctx->cfg_data->fc_info = ulp_fc_info;
1804 /* Function to retrieve the flow counter info from the context. */
1805 struct bnxt_ulp_fc_info *
1806 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1808 if (!ulp_ctx || !ulp_ctx->cfg_data)
1811 return ulp_ctx->cfg_data->fc_info;
1814 /* Function to get the ulp flags from the ulp context. */
1816 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
1819 if (!ulp_ctx || !ulp_ctx->cfg_data)
1822 *flags = ulp_ctx->cfg_data->ulp_flags;
1826 /* Function to get the ulp vfr info from the ulp context. */
1827 struct bnxt_ulp_vfr_rule_info*
1828 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
1831 if (!ulp_ctx || !ulp_ctx->cfg_data || port_id >= RTE_MAX_ETHPORTS)
1834 return &ulp_ctx->cfg_data->vfr_rule_info[port_id];
1837 /* Function to acquire the flow database lock from the ulp context. */
1839 bnxt_ulp_cntxt_acquire_fdb_lock(struct bnxt_ulp_context *ulp_ctx)
1841 if (!ulp_ctx || !ulp_ctx->cfg_data)
1844 if (pthread_mutex_lock(&ulp_ctx->cfg_data->flow_db_lock)) {
1845 BNXT_TF_DBG(ERR, "unable to acquire fdb lock\n");
1851 /* Function to release the flow database lock from the ulp context. */
1853 bnxt_ulp_cntxt_release_fdb_lock(struct bnxt_ulp_context *ulp_ctx)
1855 if (!ulp_ctx || !ulp_ctx->cfg_data)
1858 pthread_mutex_unlock(&ulp_ctx->cfg_data->flow_db_lock);
1861 /* Function to set the ha info into the context */
1863 bnxt_ulp_cntxt_ptr2_ha_info_set(struct bnxt_ulp_context *ulp_ctx,
1864 struct bnxt_ulp_ha_mgr_info *ulp_ha_info)
1866 if (ulp_ctx == NULL || ulp_ctx->cfg_data == NULL) {
1867 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1870 ulp_ctx->cfg_data->ha_info = ulp_ha_info;
1874 /* Function to retrieve the ha info from the context. */
1875 struct bnxt_ulp_ha_mgr_info *
1876 bnxt_ulp_cntxt_ptr2_ha_info_get(struct bnxt_ulp_context *ulp_ctx)
1878 if (ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)
1880 return ulp_ctx->cfg_data->ha_info;
1884 bnxt_ulp_cntxt_ha_enabled(struct bnxt_ulp_context *ulp_ctx)
1886 if (ulp_ctx == NULL || ulp_ctx->cfg_data == NULL)
1888 return !!ULP_HIGH_AVAIL_IS_ENABLED(ulp_ctx->cfg_data->ulp_flags);