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] = 16;
90 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
91 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
92 resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
95 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 720;
96 resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 720;
99 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
101 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
102 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 416;
105 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
108 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
112 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 8;
113 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
114 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
115 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
118 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 16;
119 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 16;
122 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 16;
123 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
126 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
128 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
129 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
132 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
135 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
138 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_SP_SMAC_IPV4] = 128;
140 rc = tf_open_session(&bp->tfp, ¶ms);
142 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
143 params.ctrl_chan_name, rc);
146 session->session_opened = 1;
147 session->g_tfp = &bp->tfp;
152 * Close the ULP session.
153 * It takes the ulp context pointer.
156 ulp_ctx_session_close(struct bnxt *bp,
157 struct bnxt_ulp_session_state *session)
159 /* close the session in the hardware */
160 if (session->session_opened)
161 tf_close_session(&bp->tfp);
162 session->session_opened = 0;
163 session->g_tfp = NULL;
164 bp->ulp_ctx->g_tfp = NULL;
168 bnxt_init_tbl_scope_parms(struct bnxt *bp,
169 struct tf_alloc_tbl_scope_parms *params)
171 struct bnxt_ulp_device_params *dparms;
175 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
177 /* TBD: For now, just use default. */
180 dparms = bnxt_ulp_device_params_get(dev_id);
183 * Set the flush timer for EEM entries. The value is in 100ms intervals,
186 params->hw_flow_cache_flush_timer = 100;
189 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
190 params->rx_max_action_entry_sz_in_bits =
191 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
192 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
193 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
194 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
196 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
197 params->tx_max_action_entry_sz_in_bits =
198 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
199 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
200 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
201 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
203 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
204 params->rx_max_action_entry_sz_in_bits =
205 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
206 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
207 params->rx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
208 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
210 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
211 params->tx_max_action_entry_sz_in_bits =
212 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
213 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
214 params->tx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
215 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
219 /* Initialize Extended Exact Match host memory. */
221 ulp_eem_tbl_scope_init(struct bnxt *bp)
223 struct tf_alloc_tbl_scope_parms params = {0};
225 struct bnxt_ulp_device_params *dparms;
228 /* Get the dev specific number of flows that needed to be supported. */
229 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
230 BNXT_TF_DBG(ERR, "Invalid device id\n");
234 dparms = bnxt_ulp_device_params_get(dev_id);
236 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
240 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
241 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
245 bnxt_init_tbl_scope_parms(bp, ¶ms);
247 rc = tf_alloc_tbl_scope(&bp->tfp, ¶ms);
249 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
254 rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
256 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
263 /* Free Extended Exact Match host memory */
265 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
267 struct tf_free_tbl_scope_parms params = {0};
270 struct bnxt_ulp_device_params *dparms;
273 if (!ulp_ctx || !ulp_ctx->cfg_data)
276 /* Free the resources for the last device */
277 if (!ulp_ctx_deinit_allowed(bp))
280 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
282 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
286 /* Get the dev specific number of flows that needed to be supported. */
287 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
288 BNXT_TF_DBG(ERR, "Invalid device id\n");
292 dparms = bnxt_ulp_device_params_get(dev_id);
294 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
298 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
299 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
303 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, ¶ms.tbl_scope_id);
305 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
309 rc = tf_free_tbl_scope(tfp, ¶ms);
311 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
317 /* The function to free and deinit the ulp context data. */
319 ulp_ctx_deinit(struct bnxt *bp,
320 struct bnxt_ulp_session_state *session)
322 if (!session || !bp) {
323 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
327 /* close the tf session */
328 ulp_ctx_session_close(bp, session);
330 /* Free the contents */
331 if (session->cfg_data) {
332 rte_free(session->cfg_data);
333 bp->ulp_ctx->cfg_data = NULL;
334 session->cfg_data = NULL;
339 /* The function to allocate and initialize the ulp context data. */
341 ulp_ctx_init(struct bnxt *bp,
342 struct bnxt_ulp_session_state *session)
344 struct bnxt_ulp_data *ulp_data;
347 if (!session || !bp) {
348 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
352 /* Allocate memory to hold ulp context data. */
353 ulp_data = rte_zmalloc("bnxt_ulp_data",
354 sizeof(struct bnxt_ulp_data), 0);
356 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
360 /* Increment the ulp context data reference count usage. */
361 bp->ulp_ctx->cfg_data = ulp_data;
362 session->cfg_data = ulp_data;
365 /* Open the ulp session. */
366 rc = ulp_ctx_session_open(bp, session);
368 (void)ulp_ctx_deinit(bp, session);
371 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
375 /* The function to initialize ulp dparms with devargs */
377 ulp_dparms_init(struct bnxt *bp,
378 struct bnxt_ulp_context *ulp_ctx)
380 struct bnxt_ulp_device_params *dparms;
383 if (!bp->max_num_kflows)
386 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
387 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
391 dparms = bnxt_ulp_device_params_get(dev_id);
393 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
397 /* num_flows = max_num_kflows * 1024 */
398 dparms->flow_db_num_entries = bp->max_num_kflows * 1024;
399 /* GFID = 2 * num_flows */
400 dparms->mark_db_gfid_entries = dparms->flow_db_num_entries * 2;
401 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
402 dparms->flow_db_num_entries);
407 /* The function to initialize bp flags with truflow features */
409 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
410 struct bnxt_ulp_context *ulp_ctx)
412 struct bnxt_ulp_device_params *dparms;
415 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
416 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
420 dparms = bnxt_ulp_device_params_get(dev_id);
422 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
426 /* Update the bp flag with gfid flag */
427 if (dparms->flow_mem_type == BNXT_ULP_FLOW_MEM_TYPE_EXT)
428 bp->flags |= BNXT_FLAG_GFID_ENABLE;
434 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
435 struct bnxt_ulp_session_state *session)
437 if (!ulp_ctx || !session) {
438 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
442 /* Increment the ulp context data reference count usage. */
443 ulp_ctx->cfg_data = session->cfg_data;
444 ulp_ctx->cfg_data->ref_cnt++;
446 /* TBD call TF_session_attach. */
447 ulp_ctx->g_tfp = session->g_tfp;
452 ulp_ctx_detach(struct bnxt *bp,
453 struct bnxt_ulp_session_state *session)
455 struct bnxt_ulp_context *ulp_ctx;
457 if (!bp || !session) {
458 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
461 ulp_ctx = bp->ulp_ctx;
463 if (!ulp_ctx->cfg_data)
466 /* TBD call TF_session_detach */
468 /* Increment the ulp context data reference count usage. */
469 if (ulp_ctx->cfg_data->ref_cnt >= 1) {
470 ulp_ctx->cfg_data->ref_cnt--;
471 if (ulp_ctx_deinit_allowed(bp))
472 ulp_ctx_deinit(bp, session);
473 ulp_ctx->cfg_data = NULL;
474 ulp_ctx->g_tfp = NULL;
477 BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
482 * Initialize the state of an ULP session.
483 * If the state of an ULP session is not initialized, set it's state to
484 * initialized. If the state is already initialized, do nothing.
487 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
489 pthread_mutex_lock(&session->bnxt_ulp_mutex);
491 if (!session->bnxt_ulp_init) {
492 session->bnxt_ulp_init = true;
498 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
502 * Check if an ULP session is already allocated for a specific PCI
503 * domain & bus. If it is already allocated simply return the session
504 * pointer, otherwise allocate a new session.
506 static struct bnxt_ulp_session_state *
507 ulp_get_session(struct rte_pci_addr *pci_addr)
509 struct bnxt_ulp_session_state *session;
511 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
512 if (session->pci_info.domain == pci_addr->domain &&
513 session->pci_info.bus == pci_addr->bus) {
521 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
522 * If it's already initialized simply return the already existing session.
524 static struct bnxt_ulp_session_state *
525 ulp_session_init(struct bnxt *bp,
528 struct rte_pci_device *pci_dev;
529 struct rte_pci_addr *pci_addr;
530 struct bnxt_ulp_session_state *session;
535 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
536 pci_addr = &pci_dev->addr;
538 pthread_mutex_lock(&bnxt_ulp_global_mutex);
540 session = ulp_get_session(pci_addr);
542 /* Not Found the session Allocate a new one */
543 session = rte_zmalloc("bnxt_ulp_session",
544 sizeof(struct bnxt_ulp_session_state),
548 "Allocation failed for bnxt_ulp_session\n");
549 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
553 /* Add it to the queue */
554 session->pci_info.domain = pci_addr->domain;
555 session->pci_info.bus = pci_addr->bus;
556 pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
557 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
561 ulp_context_initialized(session, init);
562 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
567 * When a device is closed, remove it's associated session from the global
571 ulp_session_deinit(struct bnxt_ulp_session_state *session)
576 if (!session->cfg_data) {
577 pthread_mutex_lock(&bnxt_ulp_global_mutex);
578 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
579 bnxt_ulp_session_state, next);
580 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
582 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
587 * When a port is initialized by dpdk. This functions is called
588 * and this function initializes the ULP context and rest of the
589 * infrastructure associated with it.
592 bnxt_ulp_init(struct bnxt *bp)
594 struct bnxt_ulp_session_state *session;
599 BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
604 * Multiple uplink ports can be associated with a single vswitch.
605 * Make sure only the port that is started first will initialize
608 session = ulp_session_init(bp, &init);
610 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
614 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
615 sizeof(struct bnxt_ulp_context), 0);
617 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
618 ulp_session_deinit(session);
623 * If ULP is already initialized for a specific domain then simply
624 * assign the ulp context to this rte_eth_dev.
627 rc = ulp_ctx_attach(bp->ulp_ctx, session);
630 "Failed to attach the ulp context\n");
631 ulp_session_deinit(session);
632 rte_free(bp->ulp_ctx);
636 /* Update bnxt driver flags */
637 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
639 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
640 ulp_ctx_detach(bp, session);
641 ulp_session_deinit(session);
642 rte_free(bp->ulp_ctx);
646 /* update the port database */
647 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
650 "Failed to update port database\n");
651 ulp_ctx_detach(bp, session);
652 ulp_session_deinit(session);
653 rte_free(bp->ulp_ctx);
658 /* Allocate and Initialize the ulp context. */
659 rc = ulp_ctx_init(bp, session);
661 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
665 /* Initialize ulp dparms with values devargs passed */
666 rc = ulp_dparms_init(bp, bp->ulp_ctx);
668 /* create the port database */
669 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
671 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
675 /* Update bnxt driver flags */
676 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
678 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
682 /* update the port database */
683 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
685 BNXT_TF_DBG(ERR, "Failed to update port database\n");
689 /* Create the Mark database. */
690 rc = ulp_mark_db_init(bp->ulp_ctx);
692 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
696 /* Create the flow database. */
697 rc = ulp_flow_db_init(bp->ulp_ctx);
699 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
703 /* Create the eem table scope. */
704 rc = ulp_eem_tbl_scope_init(bp);
706 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
710 rc = ulp_mapper_init(bp->ulp_ctx);
712 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
716 rc = ulp_fc_mgr_init(bp->ulp_ctx);
718 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
729 /* Below are the access functions to access internal data of ulp context. */
732 * When a port is deinit'ed by dpdk. This function is called
733 * and this function clears the ULP context and rest of the
734 * infrastructure associated with it.
737 bnxt_ulp_deinit(struct bnxt *bp)
739 struct bnxt_ulp_session_state *session;
740 struct rte_pci_device *pci_dev;
741 struct rte_pci_addr *pci_addr;
743 /* Get the session first */
744 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
745 pci_addr = &pci_dev->addr;
746 pthread_mutex_lock(&bnxt_ulp_global_mutex);
747 session = ulp_get_session(pci_addr);
748 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
750 /* session not found then just exit */
754 /* clean up regular flows */
755 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
757 /* cleanup the eem table scope */
758 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
760 /* cleanup the flow database */
761 ulp_flow_db_deinit(bp->ulp_ctx);
763 /* Delete the Mark database */
764 ulp_mark_db_deinit(bp->ulp_ctx);
766 /* cleanup the ulp mapper */
767 ulp_mapper_deinit(bp->ulp_ctx);
769 /* Delete the Flow Counter Manager */
770 ulp_fc_mgr_deinit(bp->ulp_ctx);
772 /* Delete the Port database */
773 ulp_port_db_deinit(bp->ulp_ctx);
775 /* Delete the ulp context and tf session */
776 ulp_ctx_detach(bp, session);
778 /* Finally delete the bnxt session*/
779 ulp_session_deinit(session);
781 rte_free(bp->ulp_ctx);
784 /* Function to set the Mark DB into the context */
786 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
787 struct bnxt_ulp_mark_tbl *mark_tbl)
789 if (!ulp_ctx || !ulp_ctx->cfg_data) {
790 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
794 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
799 /* Function to retrieve the Mark DB from the context. */
800 struct bnxt_ulp_mark_tbl *
801 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
803 if (!ulp_ctx || !ulp_ctx->cfg_data)
806 return ulp_ctx->cfg_data->mark_tbl;
809 /* Function to set the device id of the hardware. */
811 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
814 if (ulp_ctx && ulp_ctx->cfg_data) {
815 ulp_ctx->cfg_data->dev_id = dev_id;
822 /* Function to get the device id of the hardware. */
824 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
827 if (ulp_ctx && ulp_ctx->cfg_data) {
828 *dev_id = ulp_ctx->cfg_data->dev_id;
835 /* Function to get the table scope id of the EEM table. */
837 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
838 uint32_t *tbl_scope_id)
840 if (ulp_ctx && ulp_ctx->cfg_data) {
841 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
848 /* Function to set the table scope id of the EEM table. */
850 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
851 uint32_t tbl_scope_id)
853 if (ulp_ctx && ulp_ctx->cfg_data) {
854 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
861 /* Function to set the tfp session details from the ulp context. */
863 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
866 BNXT_TF_DBG(ERR, "Invalid arguments\n");
870 /* TBD The tfp should be removed once tf_attach is implemented. */
875 /* Function to get the tfp session details from the ulp context. */
877 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
880 BNXT_TF_DBG(ERR, "Invalid arguments\n");
883 /* TBD The tfp should be removed once tf_attach is implemented. */
888 * Get the device table entry based on the device id.
890 * dev_id [in] The device id of the hardware
892 * Returns the pointer to the device parameters.
894 struct bnxt_ulp_device_params *
895 bnxt_ulp_device_params_get(uint32_t dev_id)
897 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
898 return &ulp_device_params[dev_id];
902 /* Function to set the flow database to the ulp context. */
904 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
905 struct bnxt_ulp_flow_db *flow_db)
907 if (!ulp_ctx || !ulp_ctx->cfg_data)
910 ulp_ctx->cfg_data->flow_db = flow_db;
914 /* Function to get the flow database from the ulp context. */
915 struct bnxt_ulp_flow_db *
916 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
918 if (!ulp_ctx || !ulp_ctx->cfg_data)
921 return ulp_ctx->cfg_data->flow_db;
924 /* Function to get the ulp context from eth device. */
925 struct bnxt_ulp_context *
926 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
928 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
930 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
931 struct bnxt_vf_representor *vfr = dev->data->dev_private;
932 bp = vfr->parent_dev->data->dev_private;
936 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
943 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
946 if (!ulp_ctx || !ulp_ctx->cfg_data) {
947 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
951 ulp_ctx->cfg_data->mapper_data = mapper_data;
956 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
958 if (!ulp_ctx || !ulp_ctx->cfg_data) {
959 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
963 return ulp_ctx->cfg_data->mapper_data;
966 /* Function to set the port database to the ulp context. */
968 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
969 struct bnxt_ulp_port_db *port_db)
971 if (!ulp_ctx || !ulp_ctx->cfg_data)
974 ulp_ctx->cfg_data->port_db = port_db;
978 /* Function to get the port database from the ulp context. */
979 struct bnxt_ulp_port_db *
980 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
982 if (!ulp_ctx || !ulp_ctx->cfg_data)
985 return ulp_ctx->cfg_data->port_db;
988 /* Function to set the flow counter info into the context */
990 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
991 struct bnxt_ulp_fc_info *ulp_fc_info)
993 if (!ulp_ctx || !ulp_ctx->cfg_data) {
994 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
998 ulp_ctx->cfg_data->fc_info = ulp_fc_info;
1003 /* Function to retrieve the flow counter info from the context. */
1004 struct bnxt_ulp_fc_info *
1005 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1007 if (!ulp_ctx || !ulp_ctx->cfg_data)
1010 return ulp_ctx->cfg_data->fc_info;