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;
364 ulp_data->ulp_flags |= BNXT_ULP_VF_REP_ENABLED;
366 /* Open the ulp session. */
367 rc = ulp_ctx_session_open(bp, session);
369 (void)ulp_ctx_deinit(bp, session);
372 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
376 /* The function to initialize ulp dparms with devargs */
378 ulp_dparms_init(struct bnxt *bp,
379 struct bnxt_ulp_context *ulp_ctx)
381 struct bnxt_ulp_device_params *dparms;
384 if (!bp->max_num_kflows)
387 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
388 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
392 dparms = bnxt_ulp_device_params_get(dev_id);
394 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
398 /* num_flows = max_num_kflows * 1024 */
399 dparms->flow_db_num_entries = bp->max_num_kflows * 1024;
400 /* GFID = 2 * num_flows */
401 dparms->mark_db_gfid_entries = dparms->flow_db_num_entries * 2;
402 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
403 dparms->flow_db_num_entries);
408 /* The function to initialize bp flags with truflow features */
410 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
411 struct bnxt_ulp_context *ulp_ctx)
413 struct bnxt_ulp_device_params *dparms;
416 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
417 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
421 dparms = bnxt_ulp_device_params_get(dev_id);
423 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
427 /* Update the bp flag with gfid flag */
428 if (dparms->flow_mem_type == BNXT_ULP_FLOW_MEM_TYPE_EXT)
429 bp->flags |= BNXT_FLAG_GFID_ENABLE;
435 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
436 struct bnxt_ulp_session_state *session)
438 if (!ulp_ctx || !session) {
439 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
443 /* Increment the ulp context data reference count usage. */
444 ulp_ctx->cfg_data = session->cfg_data;
445 ulp_ctx->cfg_data->ref_cnt++;
447 /* TBD call TF_session_attach. */
448 ulp_ctx->g_tfp = session->g_tfp;
453 ulp_ctx_detach(struct bnxt *bp,
454 struct bnxt_ulp_session_state *session)
456 struct bnxt_ulp_context *ulp_ctx;
458 if (!bp || !session) {
459 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
462 ulp_ctx = bp->ulp_ctx;
464 if (!ulp_ctx->cfg_data)
467 /* TBD call TF_session_detach */
469 /* Increment the ulp context data reference count usage. */
470 if (ulp_ctx->cfg_data->ref_cnt >= 1) {
471 ulp_ctx->cfg_data->ref_cnt--;
472 if (ulp_ctx_deinit_allowed(bp))
473 ulp_ctx_deinit(bp, session);
474 ulp_ctx->cfg_data = NULL;
475 ulp_ctx->g_tfp = NULL;
478 BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
483 * Initialize the state of an ULP session.
484 * If the state of an ULP session is not initialized, set it's state to
485 * initialized. If the state is already initialized, do nothing.
488 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
490 pthread_mutex_lock(&session->bnxt_ulp_mutex);
492 if (!session->bnxt_ulp_init) {
493 session->bnxt_ulp_init = true;
499 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
503 * Check if an ULP session is already allocated for a specific PCI
504 * domain & bus. If it is already allocated simply return the session
505 * pointer, otherwise allocate a new session.
507 static struct bnxt_ulp_session_state *
508 ulp_get_session(struct rte_pci_addr *pci_addr)
510 struct bnxt_ulp_session_state *session;
512 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
513 if (session->pci_info.domain == pci_addr->domain &&
514 session->pci_info.bus == pci_addr->bus) {
522 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
523 * If it's already initialized simply return the already existing session.
525 static struct bnxt_ulp_session_state *
526 ulp_session_init(struct bnxt *bp,
529 struct rte_pci_device *pci_dev;
530 struct rte_pci_addr *pci_addr;
531 struct bnxt_ulp_session_state *session;
536 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
537 pci_addr = &pci_dev->addr;
539 pthread_mutex_lock(&bnxt_ulp_global_mutex);
541 session = ulp_get_session(pci_addr);
543 /* Not Found the session Allocate a new one */
544 session = rte_zmalloc("bnxt_ulp_session",
545 sizeof(struct bnxt_ulp_session_state),
549 "Allocation failed for bnxt_ulp_session\n");
550 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
554 /* Add it to the queue */
555 session->pci_info.domain = pci_addr->domain;
556 session->pci_info.bus = pci_addr->bus;
557 pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
558 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
562 ulp_context_initialized(session, init);
563 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
568 * When a device is closed, remove it's associated session from the global
572 ulp_session_deinit(struct bnxt_ulp_session_state *session)
577 if (!session->cfg_data) {
578 pthread_mutex_lock(&bnxt_ulp_global_mutex);
579 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
580 bnxt_ulp_session_state, next);
581 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
583 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
588 * When a port is initialized by dpdk. This functions is called
589 * and this function initializes the ULP context and rest of the
590 * infrastructure associated with it.
593 bnxt_ulp_init(struct bnxt *bp)
595 struct bnxt_ulp_session_state *session;
600 BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
605 * Multiple uplink ports can be associated with a single vswitch.
606 * Make sure only the port that is started first will initialize
609 session = ulp_session_init(bp, &init);
611 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
615 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
616 sizeof(struct bnxt_ulp_context), 0);
618 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
619 ulp_session_deinit(session);
624 * If ULP is already initialized for a specific domain then simply
625 * assign the ulp context to this rte_eth_dev.
628 rc = ulp_ctx_attach(bp->ulp_ctx, session);
631 "Failed to attach the ulp context\n");
632 ulp_session_deinit(session);
633 rte_free(bp->ulp_ctx);
637 /* Update bnxt driver flags */
638 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
640 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
641 ulp_ctx_detach(bp, session);
642 ulp_session_deinit(session);
643 rte_free(bp->ulp_ctx);
647 /* update the port database */
648 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
651 "Failed to update port database\n");
652 ulp_ctx_detach(bp, session);
653 ulp_session_deinit(session);
654 rte_free(bp->ulp_ctx);
659 /* Allocate and Initialize the ulp context. */
660 rc = ulp_ctx_init(bp, session);
662 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
666 /* Initialize ulp dparms with values devargs passed */
667 rc = ulp_dparms_init(bp, bp->ulp_ctx);
669 /* create the port database */
670 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
672 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
676 /* Update bnxt driver flags */
677 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
679 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
683 /* update the port database */
684 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
686 BNXT_TF_DBG(ERR, "Failed to update port database\n");
690 /* Create the Mark database. */
691 rc = ulp_mark_db_init(bp->ulp_ctx);
693 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
697 /* Create the flow database. */
698 rc = ulp_flow_db_init(bp->ulp_ctx);
700 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
704 /* Create the eem table scope. */
705 rc = ulp_eem_tbl_scope_init(bp);
707 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
711 rc = ulp_mapper_init(bp->ulp_ctx);
713 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
717 rc = ulp_fc_mgr_init(bp->ulp_ctx);
719 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
730 /* Below are the access functions to access internal data of ulp context. */
733 * When a port is deinit'ed by dpdk. This function is called
734 * and this function clears the ULP context and rest of the
735 * infrastructure associated with it.
738 bnxt_ulp_deinit(struct bnxt *bp)
740 struct bnxt_ulp_session_state *session;
741 struct rte_pci_device *pci_dev;
742 struct rte_pci_addr *pci_addr;
744 /* Get the session first */
745 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
746 pci_addr = &pci_dev->addr;
747 pthread_mutex_lock(&bnxt_ulp_global_mutex);
748 session = ulp_get_session(pci_addr);
749 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
751 /* session not found then just exit */
755 /* clean up regular flows */
756 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
758 /* cleanup the eem table scope */
759 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
761 /* cleanup the flow database */
762 ulp_flow_db_deinit(bp->ulp_ctx);
764 /* Delete the Mark database */
765 ulp_mark_db_deinit(bp->ulp_ctx);
767 /* cleanup the ulp mapper */
768 ulp_mapper_deinit(bp->ulp_ctx);
770 /* Delete the Flow Counter Manager */
771 ulp_fc_mgr_deinit(bp->ulp_ctx);
773 /* Delete the Port database */
774 ulp_port_db_deinit(bp->ulp_ctx);
776 /* Delete the ulp context and tf session */
777 ulp_ctx_detach(bp, session);
779 /* Finally delete the bnxt session*/
780 ulp_session_deinit(session);
782 rte_free(bp->ulp_ctx);
785 /* Function to set the Mark DB into the context */
787 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
788 struct bnxt_ulp_mark_tbl *mark_tbl)
790 if (!ulp_ctx || !ulp_ctx->cfg_data) {
791 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
795 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
800 /* Function to retrieve the Mark DB from the context. */
801 struct bnxt_ulp_mark_tbl *
802 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
804 if (!ulp_ctx || !ulp_ctx->cfg_data)
807 return ulp_ctx->cfg_data->mark_tbl;
810 /* Function to set the device id of the hardware. */
812 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
815 if (ulp_ctx && ulp_ctx->cfg_data) {
816 ulp_ctx->cfg_data->dev_id = dev_id;
823 /* Function to get the device id of the hardware. */
825 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
828 if (ulp_ctx && ulp_ctx->cfg_data) {
829 *dev_id = ulp_ctx->cfg_data->dev_id;
836 /* Function to get the table scope id of the EEM table. */
838 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
839 uint32_t *tbl_scope_id)
841 if (ulp_ctx && ulp_ctx->cfg_data) {
842 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
849 /* Function to set the table scope id of the EEM table. */
851 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
852 uint32_t tbl_scope_id)
854 if (ulp_ctx && ulp_ctx->cfg_data) {
855 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
862 /* Function to set the tfp session details from the ulp context. */
864 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
867 BNXT_TF_DBG(ERR, "Invalid arguments\n");
871 /* TBD The tfp should be removed once tf_attach is implemented. */
876 /* Function to get the tfp session details from the ulp context. */
878 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
881 BNXT_TF_DBG(ERR, "Invalid arguments\n");
884 /* TBD The tfp should be removed once tf_attach is implemented. */
889 * Get the device table entry based on the device id.
891 * dev_id [in] The device id of the hardware
893 * Returns the pointer to the device parameters.
895 struct bnxt_ulp_device_params *
896 bnxt_ulp_device_params_get(uint32_t dev_id)
898 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
899 return &ulp_device_params[dev_id];
903 /* Function to set the flow database to the ulp context. */
905 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
906 struct bnxt_ulp_flow_db *flow_db)
908 if (!ulp_ctx || !ulp_ctx->cfg_data)
911 ulp_ctx->cfg_data->flow_db = flow_db;
915 /* Function to get the flow database from the ulp context. */
916 struct bnxt_ulp_flow_db *
917 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
919 if (!ulp_ctx || !ulp_ctx->cfg_data)
922 return ulp_ctx->cfg_data->flow_db;
925 /* Function to get the ulp context from eth device. */
926 struct bnxt_ulp_context *
927 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
929 struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
931 if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
932 struct bnxt_vf_representor *vfr = dev->data->dev_private;
933 bp = vfr->parent_dev->data->dev_private;
937 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
944 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
947 if (!ulp_ctx || !ulp_ctx->cfg_data) {
948 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
952 ulp_ctx->cfg_data->mapper_data = mapper_data;
957 bnxt_ulp_cntxt_ptr2_mapper_data_get(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 return ulp_ctx->cfg_data->mapper_data;
967 /* Function to set the port database to the ulp context. */
969 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
970 struct bnxt_ulp_port_db *port_db)
972 if (!ulp_ctx || !ulp_ctx->cfg_data)
975 ulp_ctx->cfg_data->port_db = port_db;
979 /* Function to get the port database from the ulp context. */
980 struct bnxt_ulp_port_db *
981 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
983 if (!ulp_ctx || !ulp_ctx->cfg_data)
986 return ulp_ctx->cfg_data->port_db;
989 /* Function to set the flow counter info into the context */
991 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
992 struct bnxt_ulp_fc_info *ulp_fc_info)
994 if (!ulp_ctx || !ulp_ctx->cfg_data) {
995 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
999 ulp_ctx->cfg_data->fc_info = ulp_fc_info;
1004 /* Function to retrieve the flow counter info from the context. */
1005 struct bnxt_ulp_fc_info *
1006 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1008 if (!ulp_ctx || !ulp_ctx->cfg_data)
1011 return ulp_ctx->cfg_data->fc_info;
1014 /* Function to get the ulp flags from the ulp context. */
1016 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
1019 if (!ulp_ctx || !ulp_ctx->cfg_data)
1022 *flags = ulp_ctx->cfg_data->ulp_flags;