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_fc_mgr.h"
22 #include "ulp_flow_db.h"
23 #include "ulp_mapper.h"
24 #include "ulp_port_db.h"
26 /* Linked list of all TF sessions. */
27 STAILQ_HEAD(, bnxt_ulp_session_state) bnxt_ulp_session_list =
28 STAILQ_HEAD_INITIALIZER(bnxt_ulp_session_list);
30 /* Mutex to synchronize bnxt_ulp_session_list operations. */
31 static pthread_mutex_t bnxt_ulp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
34 * Allow the deletion of context only for the bnxt device that
36 * TBD - The implementation of the function should change to
37 * using the reference count once tf_session_attach functionality
41 ulp_ctx_deinit_allowed(void *ptr)
43 struct bnxt *bp = (struct bnxt *)ptr;
48 if (&bp->tfp == bp->ulp_ctx->g_tfp)
55 * Initialize an ULP session.
56 * An ULP session will contain all the resources needed to support rte flow
57 * offloads. A session is initialized as part of rte_eth_device start.
58 * A single vswitch instance can have multiple uplinks which means
59 * rte_eth_device start will be called for each of these devices.
60 * ULP session manager will make sure that a single ULP session is only
61 * initialized once. Apart from this, it also initializes MARK database,
62 * EEM table & flow database. ULP session manager also manages a list of
63 * all opened ULP sessions.
66 ulp_ctx_session_open(struct bnxt *bp,
67 struct bnxt_ulp_session_state *session)
69 struct rte_eth_dev *ethdev = bp->eth_dev;
71 struct tf_open_session_parms params;
72 struct tf_session_resources *resources;
74 memset(¶ms, 0, sizeof(params));
76 rc = rte_eth_dev_get_name_by_port(ethdev->data->port_id,
77 params.ctrl_chan_name);
79 BNXT_TF_DBG(ERR, "Invalid port %d, rc = %d\n",
80 ethdev->data->port_id, rc);
84 params.shadow_copy = false;
85 params.device_type = TF_DEVICE_TYPE_WH;
86 resources = ¶ms.resources;
89 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 200;
90 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 20;
91 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
92 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
93 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
96 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 720;
97 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 720;
98 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 8;
101 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_8B] = 16;
102 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
105 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
107 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
109 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
110 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 416;
113 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
116 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
120 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 200;
121 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 20;
122 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
123 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
124 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
127 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 16;
128 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 16;
129 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 8;
132 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 16;
133 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
136 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
138 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
140 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
141 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
144 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
147 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
150 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_SP_SMAC_IPV4] = 128;
152 rc = tf_open_session(&bp->tfp, ¶ms);
154 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
155 params.ctrl_chan_name, rc);
158 session->session_opened = 1;
159 session->g_tfp = &bp->tfp;
164 * Close the ULP session.
165 * It takes the ulp context pointer.
168 ulp_ctx_session_close(struct bnxt *bp,
169 struct bnxt_ulp_session_state *session)
171 /* close the session in the hardware */
172 if (session->session_opened)
173 tf_close_session(&bp->tfp);
174 session->session_opened = 0;
175 session->g_tfp = NULL;
176 bp->ulp_ctx->g_tfp = NULL;
180 bnxt_init_tbl_scope_parms(struct bnxt *bp,
181 struct tf_alloc_tbl_scope_parms *params)
183 struct bnxt_ulp_device_params *dparms;
187 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
189 /* TBD: For now, just use default. */
192 dparms = bnxt_ulp_device_params_get(dev_id);
195 * Set the flush timer for EEM entries. The value is in 100ms intervals,
198 params->hw_flow_cache_flush_timer = 100;
201 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
202 params->rx_max_action_entry_sz_in_bits =
203 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
204 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
205 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
206 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
208 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
209 params->tx_max_action_entry_sz_in_bits =
210 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
211 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
212 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
213 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
215 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
216 params->rx_max_action_entry_sz_in_bits =
217 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
218 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
219 params->rx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
220 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
222 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
223 params->tx_max_action_entry_sz_in_bits =
224 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
225 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
226 params->tx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
227 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
231 /* Initialize Extended Exact Match host memory. */
233 ulp_eem_tbl_scope_init(struct bnxt *bp)
235 struct tf_alloc_tbl_scope_parms params = {0};
237 struct bnxt_ulp_device_params *dparms;
240 /* Get the dev specific number of flows that needed to be supported. */
241 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
242 BNXT_TF_DBG(ERR, "Invalid device id\n");
246 dparms = bnxt_ulp_device_params_get(dev_id);
248 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
252 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
253 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
257 bnxt_init_tbl_scope_parms(bp, ¶ms);
259 rc = tf_alloc_tbl_scope(&bp->tfp, ¶ms);
261 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
266 rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
268 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
275 /* Free Extended Exact Match host memory */
277 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
279 struct tf_free_tbl_scope_parms params = {0};
282 struct bnxt_ulp_device_params *dparms;
285 if (!ulp_ctx || !ulp_ctx->cfg_data)
288 /* Free the resources for the last device */
289 if (!ulp_ctx_deinit_allowed(bp))
292 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
294 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
298 /* Get the dev specific number of flows that needed to be supported. */
299 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
300 BNXT_TF_DBG(ERR, "Invalid device id\n");
304 dparms = bnxt_ulp_device_params_get(dev_id);
306 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
310 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
311 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
315 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, ¶ms.tbl_scope_id);
317 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
321 rc = tf_free_tbl_scope(tfp, ¶ms);
323 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
329 /* The function to free and deinit the ulp context data. */
331 ulp_ctx_deinit(struct bnxt *bp,
332 struct bnxt_ulp_session_state *session)
334 if (!session || !bp) {
335 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
339 /* close the tf session */
340 ulp_ctx_session_close(bp, session);
342 /* Free the contents */
343 if (session->cfg_data) {
344 rte_free(session->cfg_data);
345 bp->ulp_ctx->cfg_data = NULL;
346 session->cfg_data = NULL;
351 /* The function to allocate and initialize the ulp context data. */
353 ulp_ctx_init(struct bnxt *bp,
354 struct bnxt_ulp_session_state *session)
356 struct bnxt_ulp_data *ulp_data;
359 if (!session || !bp) {
360 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
364 /* Allocate memory to hold ulp context data. */
365 ulp_data = rte_zmalloc("bnxt_ulp_data",
366 sizeof(struct bnxt_ulp_data), 0);
368 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
372 /* Increment the ulp context data reference count usage. */
373 bp->ulp_ctx->cfg_data = ulp_data;
374 session->cfg_data = ulp_data;
376 ulp_data->ulp_flags |= BNXT_ULP_VF_REP_ENABLED;
378 /* Open the ulp session. */
379 rc = ulp_ctx_session_open(bp, session);
381 (void)ulp_ctx_deinit(bp, session);
384 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
388 /* The function to initialize ulp dparms with devargs */
390 ulp_dparms_init(struct bnxt *bp,
391 struct bnxt_ulp_context *ulp_ctx)
393 struct bnxt_ulp_device_params *dparms;
396 if (!bp->max_num_kflows)
399 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
400 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
404 dparms = bnxt_ulp_device_params_get(dev_id);
406 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
410 /* num_flows = max_num_kflows * 1024 */
411 dparms->flow_db_num_entries = bp->max_num_kflows * 1024;
412 /* GFID = 2 * num_flows */
413 dparms->mark_db_gfid_entries = dparms->flow_db_num_entries * 2;
414 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
415 dparms->flow_db_num_entries);
420 /* The function to initialize bp flags with truflow features */
422 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
423 struct bnxt_ulp_context *ulp_ctx)
425 struct bnxt_ulp_device_params *dparms;
428 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
429 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
433 dparms = bnxt_ulp_device_params_get(dev_id);
435 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
439 /* Update the bp flag with gfid flag */
440 if (dparms->flow_mem_type == BNXT_ULP_FLOW_MEM_TYPE_EXT)
441 bp->flags |= BNXT_FLAG_GFID_ENABLE;
447 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
448 struct bnxt_ulp_session_state *session)
450 if (!ulp_ctx || !session) {
451 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
455 /* Increment the ulp context data reference count usage. */
456 ulp_ctx->cfg_data = session->cfg_data;
457 ulp_ctx->cfg_data->ref_cnt++;
459 /* TBD call TF_session_attach. */
460 ulp_ctx->g_tfp = session->g_tfp;
465 ulp_ctx_detach(struct bnxt *bp,
466 struct bnxt_ulp_session_state *session)
468 struct bnxt_ulp_context *ulp_ctx;
470 if (!bp || !session) {
471 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
474 ulp_ctx = bp->ulp_ctx;
476 if (!ulp_ctx->cfg_data)
479 /* TBD call TF_session_detach */
481 /* Increment the ulp context data reference count usage. */
482 if (ulp_ctx->cfg_data->ref_cnt >= 1) {
483 ulp_ctx->cfg_data->ref_cnt--;
484 if (ulp_ctx_deinit_allowed(bp))
485 ulp_ctx_deinit(bp, session);
486 ulp_ctx->cfg_data = NULL;
487 ulp_ctx->g_tfp = NULL;
490 BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
495 * Initialize the state of an ULP session.
496 * If the state of an ULP session is not initialized, set it's state to
497 * initialized. If the state is already initialized, do nothing.
500 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
502 pthread_mutex_lock(&session->bnxt_ulp_mutex);
504 if (!session->bnxt_ulp_init) {
505 session->bnxt_ulp_init = true;
511 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
515 * Check if an ULP session is already allocated for a specific PCI
516 * domain & bus. If it is already allocated simply return the session
517 * pointer, otherwise allocate a new session.
519 static struct bnxt_ulp_session_state *
520 ulp_get_session(struct rte_pci_addr *pci_addr)
522 struct bnxt_ulp_session_state *session;
524 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
525 if (session->pci_info.domain == pci_addr->domain &&
526 session->pci_info.bus == pci_addr->bus) {
534 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
535 * If it's already initialized simply return the already existing session.
537 static struct bnxt_ulp_session_state *
538 ulp_session_init(struct bnxt *bp,
541 struct rte_pci_device *pci_dev;
542 struct rte_pci_addr *pci_addr;
543 struct bnxt_ulp_session_state *session;
548 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
549 pci_addr = &pci_dev->addr;
551 pthread_mutex_lock(&bnxt_ulp_global_mutex);
553 session = ulp_get_session(pci_addr);
555 /* Not Found the session Allocate a new one */
556 session = rte_zmalloc("bnxt_ulp_session",
557 sizeof(struct bnxt_ulp_session_state),
561 "Allocation failed for bnxt_ulp_session\n");
562 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
566 /* Add it to the queue */
567 session->pci_info.domain = pci_addr->domain;
568 session->pci_info.bus = pci_addr->bus;
569 pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
570 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
574 ulp_context_initialized(session, init);
575 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
580 * When a device is closed, remove it's associated session from the global
584 ulp_session_deinit(struct bnxt_ulp_session_state *session)
589 if (!session->cfg_data) {
590 pthread_mutex_lock(&bnxt_ulp_global_mutex);
591 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
592 bnxt_ulp_session_state, next);
593 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
595 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
600 * When a port is initialized by dpdk. This functions is called
601 * and this function initializes the ULP context and rest of the
602 * infrastructure associated with it.
605 bnxt_ulp_init(struct bnxt *bp)
607 struct bnxt_ulp_session_state *session;
612 BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
617 * Multiple uplink ports can be associated with a single vswitch.
618 * Make sure only the port that is started first will initialize
621 session = ulp_session_init(bp, &init);
623 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
627 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
628 sizeof(struct bnxt_ulp_context), 0);
630 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
631 ulp_session_deinit(session);
636 * If ULP is already initialized for a specific domain then simply
637 * assign the ulp context to this rte_eth_dev.
640 rc = ulp_ctx_attach(bp->ulp_ctx, session);
643 "Failed to attach the ulp context\n");
644 ulp_session_deinit(session);
645 rte_free(bp->ulp_ctx);
649 /* Update bnxt driver flags */
650 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
652 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
653 ulp_ctx_detach(bp, session);
654 ulp_session_deinit(session);
655 rte_free(bp->ulp_ctx);
659 /* update the port database */
660 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
663 "Failed to update port database\n");
664 ulp_ctx_detach(bp, session);
665 ulp_session_deinit(session);
666 rte_free(bp->ulp_ctx);
671 /* Allocate and Initialize the ulp context. */
672 rc = ulp_ctx_init(bp, session);
674 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
678 /* Initialize ulp dparms with values devargs passed */
679 rc = ulp_dparms_init(bp, bp->ulp_ctx);
681 /* create the port database */
682 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
684 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
688 /* Update bnxt driver flags */
689 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
691 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
695 /* update the port database */
696 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
698 BNXT_TF_DBG(ERR, "Failed to update port database\n");
702 /* Create the Mark database. */
703 rc = ulp_mark_db_init(bp->ulp_ctx);
705 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
709 /* Create the flow database. */
710 rc = ulp_flow_db_init(bp->ulp_ctx);
712 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
716 /* Create the eem table scope. */
717 rc = ulp_eem_tbl_scope_init(bp);
719 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
723 rc = ulp_mapper_init(bp->ulp_ctx);
725 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
729 rc = ulp_fc_mgr_init(bp->ulp_ctx);
731 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
742 /* Below are the access functions to access internal data of ulp context. */
745 * When a port is deinit'ed by dpdk. This function is called
746 * and this function clears the ULP context and rest of the
747 * infrastructure associated with it.
750 bnxt_ulp_deinit(struct bnxt *bp)
752 struct bnxt_ulp_session_state *session;
753 struct rte_pci_device *pci_dev;
754 struct rte_pci_addr *pci_addr;
756 /* Get the session first */
757 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
758 pci_addr = &pci_dev->addr;
759 pthread_mutex_lock(&bnxt_ulp_global_mutex);
760 session = ulp_get_session(pci_addr);
761 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
763 /* session not found then just exit */
767 /* clean up regular flows */
768 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
770 /* cleanup the eem table scope */
771 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
773 /* cleanup the flow database */
774 ulp_flow_db_deinit(bp->ulp_ctx);
776 /* Delete the Mark database */
777 ulp_mark_db_deinit(bp->ulp_ctx);
779 /* cleanup the ulp mapper */
780 ulp_mapper_deinit(bp->ulp_ctx);
782 /* Delete the Flow Counter Manager */
783 ulp_fc_mgr_deinit(bp->ulp_ctx);
785 /* Delete the Port database */
786 ulp_port_db_deinit(bp->ulp_ctx);
788 /* Delete the ulp context and tf session */
789 ulp_ctx_detach(bp, session);
791 /* Finally delete the bnxt session*/
792 ulp_session_deinit(session);
794 rte_free(bp->ulp_ctx);
797 /* Function to set the Mark DB into the context */
799 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
800 struct bnxt_ulp_mark_tbl *mark_tbl)
802 if (!ulp_ctx || !ulp_ctx->cfg_data) {
803 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
807 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
812 /* Function to retrieve the Mark DB from the context. */
813 struct bnxt_ulp_mark_tbl *
814 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
816 if (!ulp_ctx || !ulp_ctx->cfg_data)
819 return ulp_ctx->cfg_data->mark_tbl;
822 /* Function to set the device id of the hardware. */
824 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
827 if (ulp_ctx && ulp_ctx->cfg_data) {
828 ulp_ctx->cfg_data->dev_id = dev_id;
835 /* Function to get the device id of the hardware. */
837 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
840 if (ulp_ctx && ulp_ctx->cfg_data) {
841 *dev_id = ulp_ctx->cfg_data->dev_id;
848 /* Function to get the table scope id of the EEM table. */
850 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
851 uint32_t *tbl_scope_id)
853 if (ulp_ctx && ulp_ctx->cfg_data) {
854 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
861 /* Function to set the table scope id of the EEM table. */
863 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
864 uint32_t tbl_scope_id)
866 if (ulp_ctx && ulp_ctx->cfg_data) {
867 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
874 /* Function to set the tfp session details from the ulp context. */
876 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
879 BNXT_TF_DBG(ERR, "Invalid arguments\n");
883 /* TBD The tfp should be removed once tf_attach is implemented. */
888 /* Function to get the tfp session details from the ulp context. */
890 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
893 BNXT_TF_DBG(ERR, "Invalid arguments\n");
896 /* TBD The tfp should be removed once tf_attach is implemented. */
901 * Get the device table entry based on the device id.
903 * dev_id [in] The device id of the hardware
905 * Returns the pointer to the device parameters.
907 struct bnxt_ulp_device_params *
908 bnxt_ulp_device_params_get(uint32_t dev_id)
910 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
911 return &ulp_device_params[dev_id];
915 /* Function to set the flow database to the ulp context. */
917 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
918 struct bnxt_ulp_flow_db *flow_db)
920 if (!ulp_ctx || !ulp_ctx->cfg_data)
923 ulp_ctx->cfg_data->flow_db = flow_db;
927 /* Function to get the flow database from the ulp context. */
928 struct bnxt_ulp_flow_db *
929 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
931 if (!ulp_ctx || !ulp_ctx->cfg_data)
934 return ulp_ctx->cfg_data->flow_db;
937 /* Function to get the ulp context from eth device. */
938 struct bnxt_ulp_context *
939 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
941 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
943 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
944 struct bnxt_vf_representor *vfr = dev->data->dev_private;
945 bp = vfr->parent_dev->data->dev_private;
949 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
956 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
959 if (!ulp_ctx || !ulp_ctx->cfg_data) {
960 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
964 ulp_ctx->cfg_data->mapper_data = mapper_data;
969 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
971 if (!ulp_ctx || !ulp_ctx->cfg_data) {
972 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
976 return ulp_ctx->cfg_data->mapper_data;
979 /* Function to set the port database to the ulp context. */
981 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
982 struct bnxt_ulp_port_db *port_db)
984 if (!ulp_ctx || !ulp_ctx->cfg_data)
987 ulp_ctx->cfg_data->port_db = port_db;
991 /* Function to get the port database from the ulp context. */
992 struct bnxt_ulp_port_db *
993 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
995 if (!ulp_ctx || !ulp_ctx->cfg_data)
998 return ulp_ctx->cfg_data->port_db;
1001 /* Function to set the flow counter info into the context */
1003 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
1004 struct bnxt_ulp_fc_info *ulp_fc_info)
1006 if (!ulp_ctx || !ulp_ctx->cfg_data) {
1007 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1011 ulp_ctx->cfg_data->fc_info = ulp_fc_info;
1016 /* Function to retrieve the flow counter info from the context. */
1017 struct bnxt_ulp_fc_info *
1018 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1020 if (!ulp_ctx || !ulp_ctx->cfg_data)
1023 return ulp_ctx->cfg_data->fc_info;
1026 /* Function to get the ulp flags from the ulp context. */
1028 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
1031 if (!ulp_ctx || !ulp_ctx->cfg_data)
1034 *flags = ulp_ctx->cfg_data->ulp_flags;