1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
7 #include <rte_malloc.h>
9 #include <rte_flow_driver.h>
10 #include <rte_tailq.h>
13 #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_flow_db.h"
22 #include "ulp_mapper.h"
23 #include "ulp_port_db.h"
25 /* Linked list of all TF sessions. */
26 STAILQ_HEAD(, bnxt_ulp_session_state) bnxt_ulp_session_list =
27 STAILQ_HEAD_INITIALIZER(bnxt_ulp_session_list);
29 /* Mutex to synchronize bnxt_ulp_session_list operations. */
30 static pthread_mutex_t bnxt_ulp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
33 * Allow the deletion of context only for the bnxt device that
35 * TBD - The implementation of the function should change to
36 * using the reference count once tf_session_attach functionality
40 ulp_ctx_deinit_allowed(void *ptr)
42 struct bnxt *bp = (struct bnxt *)ptr;
47 if (&bp->tfp == bp->ulp_ctx->g_tfp)
54 * Initialize an ULP session.
55 * An ULP session will contain all the resources needed to support rte flow
56 * offloads. A session is initialized as part of rte_eth_device start.
57 * A single vswitch instance can have multiple uplinks which means
58 * rte_eth_device start will be called for each of these devices.
59 * ULP session manager will make sure that a single ULP session is only
60 * initialized once. Apart from this, it also initializes MARK database,
61 * EEM table & flow database. ULP session manager also manages a list of
62 * all opened ULP sessions.
65 ulp_ctx_session_open(struct bnxt *bp,
66 struct bnxt_ulp_session_state *session)
68 struct rte_eth_dev *ethdev = bp->eth_dev;
70 struct tf_open_session_parms params;
71 struct tf_session_resources *resources;
73 memset(¶ms, 0, sizeof(params));
75 rc = rte_eth_dev_get_name_by_port(ethdev->data->port_id,
76 params.ctrl_chan_name);
78 BNXT_TF_DBG(ERR, "Invalid port %d, rc = %d\n",
79 ethdev->data->port_id, rc);
83 params.shadow_copy = false;
84 params.device_type = TF_DEVICE_TYPE_WH;
85 resources = ¶ms.resources;
88 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT] = 16;
89 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
90 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
91 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
94 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 720;
95 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 720;
98 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM] = 16;
99 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
100 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 416;
103 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
107 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT] = 8;
108 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
109 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
110 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
113 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 16;
114 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 16;
117 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 16;
118 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
121 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM] = 8;
122 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
123 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
126 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 8;
129 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
130 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
132 rc = tf_open_session(&bp->tfp, ¶ms);
134 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
135 params.ctrl_chan_name, rc);
138 session->session_opened = 1;
139 session->g_tfp = &bp->tfp;
144 * Close the ULP session.
145 * It takes the ulp context pointer.
148 ulp_ctx_session_close(struct bnxt *bp,
149 struct bnxt_ulp_session_state *session)
151 /* close the session in the hardware */
152 if (session->session_opened)
153 tf_close_session(&bp->tfp);
154 session->session_opened = 0;
155 session->g_tfp = NULL;
156 bp->ulp_ctx->g_tfp = NULL;
160 bnxt_init_tbl_scope_parms(struct bnxt *bp,
161 struct tf_alloc_tbl_scope_parms *params)
163 struct bnxt_ulp_device_params *dparms;
167 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
169 /* TBD: For now, just use default. */
172 dparms = bnxt_ulp_device_params_get(dev_id);
175 * Set the flush timer for EEM entries. The value is in 100ms intervals,
178 params->hw_flow_cache_flush_timer = 100;
181 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
182 params->rx_max_action_entry_sz_in_bits =
183 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
184 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
185 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
186 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
188 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
189 params->tx_max_action_entry_sz_in_bits =
190 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
191 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
192 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
193 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
195 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
196 params->rx_max_action_entry_sz_in_bits =
197 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
198 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
199 params->rx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
200 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
202 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
203 params->tx_max_action_entry_sz_in_bits =
204 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
205 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
206 params->tx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
207 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
211 /* Initialize Extended Exact Match host memory. */
213 ulp_eem_tbl_scope_init(struct bnxt *bp)
215 struct tf_alloc_tbl_scope_parms params = {0};
217 struct bnxt_ulp_device_params *dparms;
220 /* Get the dev specific number of flows that needed to be supported. */
221 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
222 BNXT_TF_DBG(ERR, "Invalid device id\n");
226 dparms = bnxt_ulp_device_params_get(dev_id);
228 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
232 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
233 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
237 bnxt_init_tbl_scope_parms(bp, ¶ms);
239 rc = tf_alloc_tbl_scope(&bp->tfp, ¶ms);
241 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
246 rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
248 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
255 /* Free Extended Exact Match host memory */
257 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
259 struct tf_free_tbl_scope_parms params = {0};
262 struct bnxt_ulp_device_params *dparms;
265 if (!ulp_ctx || !ulp_ctx->cfg_data)
268 /* Free the resources for the last device */
269 if (!ulp_ctx_deinit_allowed(bp))
272 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
274 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
278 /* Get the dev specific number of flows that needed to be supported. */
279 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
280 BNXT_TF_DBG(ERR, "Invalid device id\n");
284 dparms = bnxt_ulp_device_params_get(dev_id);
286 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
290 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
291 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
295 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, ¶ms.tbl_scope_id);
297 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
301 rc = tf_free_tbl_scope(tfp, ¶ms);
303 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
309 /* The function to free and deinit the ulp context data. */
311 ulp_ctx_deinit(struct bnxt *bp,
312 struct bnxt_ulp_session_state *session)
314 if (!session || !bp) {
315 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
319 /* close the tf session */
320 ulp_ctx_session_close(bp, session);
322 /* Free the contents */
323 if (session->cfg_data) {
324 rte_free(session->cfg_data);
325 bp->ulp_ctx->cfg_data = NULL;
326 session->cfg_data = NULL;
331 /* The function to allocate and initialize the ulp context data. */
333 ulp_ctx_init(struct bnxt *bp,
334 struct bnxt_ulp_session_state *session)
336 struct bnxt_ulp_data *ulp_data;
339 if (!session || !bp) {
340 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
344 /* Allocate memory to hold ulp context data. */
345 ulp_data = rte_zmalloc("bnxt_ulp_data",
346 sizeof(struct bnxt_ulp_data), 0);
348 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
352 /* Increment the ulp context data reference count usage. */
353 bp->ulp_ctx->cfg_data = ulp_data;
354 session->cfg_data = ulp_data;
357 /* Open the ulp session. */
358 rc = ulp_ctx_session_open(bp, session);
360 (void)ulp_ctx_deinit(bp, session);
363 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
367 /* The function to initialize ulp dparms with devargs */
369 ulp_dparms_init(struct bnxt *bp,
370 struct bnxt_ulp_context *ulp_ctx)
372 struct bnxt_ulp_device_params *dparms;
375 if (!bp->max_num_kflows)
378 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
379 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
383 dparms = bnxt_ulp_device_params_get(dev_id);
385 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
389 /* num_flows = max_num_kflows * 1024 */
390 dparms->flow_db_num_entries = bp->max_num_kflows * 1024;
391 /* GFID = 2 * num_flows */
392 dparms->mark_db_gfid_entries = dparms->flow_db_num_entries * 2;
393 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
394 dparms->flow_db_num_entries);
399 /* The function to initialize bp flags with truflow features */
401 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
402 struct bnxt_ulp_context *ulp_ctx)
404 struct bnxt_ulp_device_params *dparms;
407 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
408 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
412 dparms = bnxt_ulp_device_params_get(dev_id);
414 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
418 /* Update the bp flag with gfid flag */
419 if (dparms->flow_mem_type == BNXT_ULP_FLOW_MEM_TYPE_EXT)
420 bp->flags |= BNXT_FLAG_GFID_ENABLE;
426 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
427 struct bnxt_ulp_session_state *session)
429 if (!ulp_ctx || !session) {
430 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
434 /* Increment the ulp context data reference count usage. */
435 ulp_ctx->cfg_data = session->cfg_data;
436 ulp_ctx->cfg_data->ref_cnt++;
438 /* TBD call TF_session_attach. */
439 ulp_ctx->g_tfp = session->g_tfp;
444 ulp_ctx_detach(struct bnxt *bp,
445 struct bnxt_ulp_session_state *session)
447 struct bnxt_ulp_context *ulp_ctx;
449 if (!bp || !session) {
450 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
453 ulp_ctx = bp->ulp_ctx;
455 if (!ulp_ctx->cfg_data)
458 /* TBD call TF_session_detach */
460 /* Increment the ulp context data reference count usage. */
461 if (ulp_ctx->cfg_data->ref_cnt >= 1) {
462 ulp_ctx->cfg_data->ref_cnt--;
463 if (ulp_ctx_deinit_allowed(bp))
464 ulp_ctx_deinit(bp, session);
465 ulp_ctx->cfg_data = NULL;
466 ulp_ctx->g_tfp = NULL;
469 BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
474 * Initialize the state of an ULP session.
475 * If the state of an ULP session is not initialized, set it's state to
476 * initialized. If the state is already initialized, do nothing.
479 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
481 pthread_mutex_lock(&session->bnxt_ulp_mutex);
483 if (!session->bnxt_ulp_init) {
484 session->bnxt_ulp_init = true;
490 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
494 * Check if an ULP session is already allocated for a specific PCI
495 * domain & bus. If it is already allocated simply return the session
496 * pointer, otherwise allocate a new session.
498 static struct bnxt_ulp_session_state *
499 ulp_get_session(struct rte_pci_addr *pci_addr)
501 struct bnxt_ulp_session_state *session;
503 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
504 if (session->pci_info.domain == pci_addr->domain &&
505 session->pci_info.bus == pci_addr->bus) {
513 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
514 * If it's already initialized simply return the already existing session.
516 static struct bnxt_ulp_session_state *
517 ulp_session_init(struct bnxt *bp,
520 struct rte_pci_device *pci_dev;
521 struct rte_pci_addr *pci_addr;
522 struct bnxt_ulp_session_state *session;
527 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
528 pci_addr = &pci_dev->addr;
530 pthread_mutex_lock(&bnxt_ulp_global_mutex);
532 session = ulp_get_session(pci_addr);
534 /* Not Found the session Allocate a new one */
535 session = rte_zmalloc("bnxt_ulp_session",
536 sizeof(struct bnxt_ulp_session_state),
540 "Allocation failed for bnxt_ulp_session\n");
541 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
545 /* Add it to the queue */
546 session->pci_info.domain = pci_addr->domain;
547 session->pci_info.bus = pci_addr->bus;
548 pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
549 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
553 ulp_context_initialized(session, init);
554 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
559 * When a device is closed, remove it's associated session from the global
563 ulp_session_deinit(struct bnxt_ulp_session_state *session)
568 if (!session->cfg_data) {
569 pthread_mutex_lock(&bnxt_ulp_global_mutex);
570 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
571 bnxt_ulp_session_state, next);
572 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
574 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
579 * When a port is initialized by dpdk. This functions is called
580 * and this function initializes the ULP context and rest of the
581 * infrastructure associated with it.
584 bnxt_ulp_init(struct bnxt *bp)
586 struct bnxt_ulp_session_state *session;
591 BNXT_TF_DBG(ERR, "ulp ctx already allocated\n");
596 * Multiple uplink ports can be associated with a single vswitch.
597 * Make sure only the port that is started first will initialize
600 session = ulp_session_init(bp, &init);
602 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
606 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
607 sizeof(struct bnxt_ulp_context), 0);
609 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
610 ulp_session_deinit(session);
615 * If ULP is already initialized for a specific domain then simply
616 * assign the ulp context to this rte_eth_dev.
619 rc = ulp_ctx_attach(bp->ulp_ctx, session);
622 "Failed to attach the ulp context\n");
623 ulp_session_deinit(session);
624 rte_free(bp->ulp_ctx);
628 /* Update bnxt driver flags */
629 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
631 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
632 ulp_ctx_detach(bp, session);
633 ulp_session_deinit(session);
634 rte_free(bp->ulp_ctx);
638 /* update the port database */
639 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
642 "Failed to update port database\n");
643 ulp_ctx_detach(bp, session);
644 ulp_session_deinit(session);
645 rte_free(bp->ulp_ctx);
650 /* Allocate and Initialize the ulp context. */
651 rc = ulp_ctx_init(bp, session);
653 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
657 /* Initialize ulp dparms with values devargs passed */
658 rc = ulp_dparms_init(bp, bp->ulp_ctx);
660 /* create the port database */
661 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
663 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
667 /* Update bnxt driver flags */
668 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
670 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
674 /* update the port database */
675 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
677 BNXT_TF_DBG(ERR, "Failed to update port database\n");
681 /* Create the Mark database. */
682 rc = ulp_mark_db_init(bp->ulp_ctx);
684 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
688 /* Create the flow database. */
689 rc = ulp_flow_db_init(bp->ulp_ctx);
691 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
695 /* Create the eem table scope. */
696 rc = ulp_eem_tbl_scope_init(bp);
698 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
702 rc = ulp_mapper_init(bp->ulp_ctx);
704 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
715 /* Below are the access functions to access internal data of ulp context. */
718 * When a port is deinit'ed by dpdk. This function is called
719 * and this function clears the ULP context and rest of the
720 * infrastructure associated with it.
723 bnxt_ulp_deinit(struct bnxt *bp)
725 struct bnxt_ulp_session_state *session;
726 struct rte_pci_device *pci_dev;
727 struct rte_pci_addr *pci_addr;
729 /* Get the session first */
730 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
731 pci_addr = &pci_dev->addr;
732 pthread_mutex_lock(&bnxt_ulp_global_mutex);
733 session = ulp_get_session(pci_addr);
734 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
736 /* session not found then just exit */
740 /* clean up regular flows */
741 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
743 /* cleanup the eem table scope */
744 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
746 /* cleanup the flow database */
747 ulp_flow_db_deinit(bp->ulp_ctx);
749 /* Delete the Mark database */
750 ulp_mark_db_deinit(bp->ulp_ctx);
752 /* cleanup the ulp mapper */
753 ulp_mapper_deinit(bp->ulp_ctx);
755 /* Delete the Port database */
756 ulp_port_db_deinit(bp->ulp_ctx);
758 /* Delete the ulp context and tf session */
759 ulp_ctx_detach(bp, session);
761 /* Finally delete the bnxt session*/
762 ulp_session_deinit(session);
764 rte_free(bp->ulp_ctx);
767 /* Function to set the Mark DB into the context */
769 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
770 struct bnxt_ulp_mark_tbl *mark_tbl)
772 if (!ulp_ctx || !ulp_ctx->cfg_data) {
773 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
777 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
782 /* Function to retrieve the Mark DB from the context. */
783 struct bnxt_ulp_mark_tbl *
784 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
786 if (!ulp_ctx || !ulp_ctx->cfg_data)
789 return ulp_ctx->cfg_data->mark_tbl;
792 /* Function to set the device id of the hardware. */
794 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
797 if (ulp_ctx && ulp_ctx->cfg_data) {
798 ulp_ctx->cfg_data->dev_id = dev_id;
805 /* Function to get the device id of the hardware. */
807 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
810 if (ulp_ctx && ulp_ctx->cfg_data) {
811 *dev_id = ulp_ctx->cfg_data->dev_id;
818 /* Function to get the table scope id of the EEM table. */
820 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
821 uint32_t *tbl_scope_id)
823 if (ulp_ctx && ulp_ctx->cfg_data) {
824 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
831 /* Function to set the table scope id of the EEM table. */
833 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
834 uint32_t tbl_scope_id)
836 if (ulp_ctx && ulp_ctx->cfg_data) {
837 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
844 /* Function to set the tfp session details from the ulp context. */
846 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
849 BNXT_TF_DBG(ERR, "Invalid arguments\n");
853 /* TBD The tfp should be removed once tf_attach is implemented. */
858 /* Function to get the tfp session details from the ulp context. */
860 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
863 BNXT_TF_DBG(ERR, "Invalid arguments\n");
866 /* TBD The tfp should be removed once tf_attach is implemented. */
871 * Get the device table entry based on the device id.
873 * dev_id [in] The device id of the hardware
875 * Returns the pointer to the device parameters.
877 struct bnxt_ulp_device_params *
878 bnxt_ulp_device_params_get(uint32_t dev_id)
880 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
881 return &ulp_device_params[dev_id];
885 /* Function to set the flow database to the ulp context. */
887 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
888 struct bnxt_ulp_flow_db *flow_db)
890 if (!ulp_ctx || !ulp_ctx->cfg_data)
893 ulp_ctx->cfg_data->flow_db = flow_db;
897 /* Function to get the flow database from the ulp context. */
898 struct bnxt_ulp_flow_db *
899 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
901 if (!ulp_ctx || !ulp_ctx->cfg_data)
904 return ulp_ctx->cfg_data->flow_db;
907 /* Function to get the ulp context from eth device. */
908 struct bnxt_ulp_context *
909 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
913 bp = (struct bnxt *)dev->data->dev_private;
915 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
922 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
925 if (!ulp_ctx || !ulp_ctx->cfg_data) {
926 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
930 ulp_ctx->cfg_data->mapper_data = mapper_data;
935 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
937 if (!ulp_ctx || !ulp_ctx->cfg_data) {
938 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
942 return ulp_ctx->cfg_data->mapper_data;
945 /* Function to set the port database to the ulp context. */
947 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
948 struct bnxt_ulp_port_db *port_db)
950 if (!ulp_ctx || !ulp_ctx->cfg_data)
953 ulp_ctx->cfg_data->port_db = port_db;
957 /* Function to get the port database from the ulp context. */
958 struct bnxt_ulp_port_db *
959 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
961 if (!ulp_ctx || !ulp_ctx->cfg_data)
964 return ulp_ctx->cfg_data->port_db;