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] = 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] = 16;
100 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
101 resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 416;
104 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 2048;
107 resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
111 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT] = 8;
112 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
113 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
114 resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
117 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 16;
118 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 16;
121 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 16;
122 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 16;
125 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM] = 8;
126 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
127 resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
130 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 8;
133 resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
136 resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_SP_SMAC_IPV4] = 128;
138 rc = tf_open_session(&bp->tfp, ¶ms);
140 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
141 params.ctrl_chan_name, rc);
144 session->session_opened = 1;
145 session->g_tfp = &bp->tfp;
150 * Close the ULP session.
151 * It takes the ulp context pointer.
154 ulp_ctx_session_close(struct bnxt *bp,
155 struct bnxt_ulp_session_state *session)
157 /* close the session in the hardware */
158 if (session->session_opened)
159 tf_close_session(&bp->tfp);
160 session->session_opened = 0;
161 session->g_tfp = NULL;
162 bp->ulp_ctx->g_tfp = NULL;
166 bnxt_init_tbl_scope_parms(struct bnxt *bp,
167 struct tf_alloc_tbl_scope_parms *params)
169 struct bnxt_ulp_device_params *dparms;
173 rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
175 /* TBD: For now, just use default. */
178 dparms = bnxt_ulp_device_params_get(dev_id);
181 * Set the flush timer for EEM entries. The value is in 100ms intervals,
184 params->hw_flow_cache_flush_timer = 100;
187 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
188 params->rx_max_action_entry_sz_in_bits =
189 BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
190 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
191 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
192 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
194 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
195 params->tx_max_action_entry_sz_in_bits =
196 BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
197 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
198 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
199 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
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 = dparms->flow_db_num_entries / 1024;
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 = dparms->flow_db_num_entries / 1024;
213 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
217 /* Initialize Extended Exact Match host memory. */
219 ulp_eem_tbl_scope_init(struct bnxt *bp)
221 struct tf_alloc_tbl_scope_parms params = {0};
223 struct bnxt_ulp_device_params *dparms;
226 /* Get the dev specific number of flows that needed to be supported. */
227 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
228 BNXT_TF_DBG(ERR, "Invalid device id\n");
232 dparms = bnxt_ulp_device_params_get(dev_id);
234 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
238 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
239 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
243 bnxt_init_tbl_scope_parms(bp, ¶ms);
245 rc = tf_alloc_tbl_scope(&bp->tfp, ¶ms);
247 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
252 rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
254 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
261 /* Free Extended Exact Match host memory */
263 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
265 struct tf_free_tbl_scope_parms params = {0};
268 struct bnxt_ulp_device_params *dparms;
271 if (!ulp_ctx || !ulp_ctx->cfg_data)
274 /* Free the resources for the last device */
275 if (!ulp_ctx_deinit_allowed(bp))
278 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
280 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
284 /* Get the dev specific number of flows that needed to be supported. */
285 if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
286 BNXT_TF_DBG(ERR, "Invalid device id\n");
290 dparms = bnxt_ulp_device_params_get(dev_id);
292 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
296 if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
297 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
301 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, ¶ms.tbl_scope_id);
303 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
307 rc = tf_free_tbl_scope(tfp, ¶ms);
309 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
315 /* The function to free and deinit the ulp context data. */
317 ulp_ctx_deinit(struct bnxt *bp,
318 struct bnxt_ulp_session_state *session)
320 if (!session || !bp) {
321 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
325 /* close the tf session */
326 ulp_ctx_session_close(bp, session);
328 /* Free the contents */
329 if (session->cfg_data) {
330 rte_free(session->cfg_data);
331 bp->ulp_ctx->cfg_data = NULL;
332 session->cfg_data = NULL;
337 /* The function to allocate and initialize the ulp context data. */
339 ulp_ctx_init(struct bnxt *bp,
340 struct bnxt_ulp_session_state *session)
342 struct bnxt_ulp_data *ulp_data;
345 if (!session || !bp) {
346 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
350 /* Allocate memory to hold ulp context data. */
351 ulp_data = rte_zmalloc("bnxt_ulp_data",
352 sizeof(struct bnxt_ulp_data), 0);
354 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
358 /* Increment the ulp context data reference count usage. */
359 bp->ulp_ctx->cfg_data = ulp_data;
360 session->cfg_data = ulp_data;
363 /* Open the ulp session. */
364 rc = ulp_ctx_session_open(bp, session);
366 (void)ulp_ctx_deinit(bp, session);
369 bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, session->g_tfp);
373 /* The function to initialize ulp dparms with devargs */
375 ulp_dparms_init(struct bnxt *bp,
376 struct bnxt_ulp_context *ulp_ctx)
378 struct bnxt_ulp_device_params *dparms;
381 if (!bp->max_num_kflows)
384 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
385 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
389 dparms = bnxt_ulp_device_params_get(dev_id);
391 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
395 /* num_flows = max_num_kflows * 1024 */
396 dparms->flow_db_num_entries = bp->max_num_kflows * 1024;
397 /* GFID = 2 * num_flows */
398 dparms->mark_db_gfid_entries = dparms->flow_db_num_entries * 2;
399 BNXT_TF_DBG(DEBUG, "Set the number of flows = %"PRIu64"\n",
400 dparms->flow_db_num_entries);
405 /* The function to initialize bp flags with truflow features */
407 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
408 struct bnxt_ulp_context *ulp_ctx)
410 struct bnxt_ulp_device_params *dparms;
413 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
414 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
418 dparms = bnxt_ulp_device_params_get(dev_id);
420 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
424 /* Update the bp flag with gfid flag */
425 if (dparms->flow_mem_type == BNXT_ULP_FLOW_MEM_TYPE_EXT)
426 bp->flags |= BNXT_FLAG_GFID_ENABLE;
432 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
433 struct bnxt_ulp_session_state *session)
435 if (!ulp_ctx || !session) {
436 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
440 /* Increment the ulp context data reference count usage. */
441 ulp_ctx->cfg_data = session->cfg_data;
442 ulp_ctx->cfg_data->ref_cnt++;
444 /* TBD call TF_session_attach. */
445 ulp_ctx->g_tfp = session->g_tfp;
450 ulp_ctx_detach(struct bnxt *bp,
451 struct bnxt_ulp_session_state *session)
453 struct bnxt_ulp_context *ulp_ctx;
455 if (!bp || !session) {
456 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
459 ulp_ctx = bp->ulp_ctx;
461 if (!ulp_ctx->cfg_data)
464 /* TBD call TF_session_detach */
466 /* Increment the ulp context data reference count usage. */
467 if (ulp_ctx->cfg_data->ref_cnt >= 1) {
468 ulp_ctx->cfg_data->ref_cnt--;
469 if (ulp_ctx_deinit_allowed(bp))
470 ulp_ctx_deinit(bp, session);
471 ulp_ctx->cfg_data = NULL;
472 ulp_ctx->g_tfp = NULL;
475 BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
480 * Initialize the state of an ULP session.
481 * If the state of an ULP session is not initialized, set it's state to
482 * initialized. If the state is already initialized, do nothing.
485 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
487 pthread_mutex_lock(&session->bnxt_ulp_mutex);
489 if (!session->bnxt_ulp_init) {
490 session->bnxt_ulp_init = true;
496 pthread_mutex_unlock(&session->bnxt_ulp_mutex);
500 * Check if an ULP session is already allocated for a specific PCI
501 * domain & bus. If it is already allocated simply return the session
502 * pointer, otherwise allocate a new session.
504 static struct bnxt_ulp_session_state *
505 ulp_get_session(struct rte_pci_addr *pci_addr)
507 struct bnxt_ulp_session_state *session;
509 STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
510 if (session->pci_info.domain == pci_addr->domain &&
511 session->pci_info.bus == pci_addr->bus) {
519 * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
520 * If it's already initialized simply return the already existing session.
522 static struct bnxt_ulp_session_state *
523 ulp_session_init(struct bnxt *bp,
526 struct rte_pci_device *pci_dev;
527 struct rte_pci_addr *pci_addr;
528 struct bnxt_ulp_session_state *session;
533 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
534 pci_addr = &pci_dev->addr;
536 pthread_mutex_lock(&bnxt_ulp_global_mutex);
538 session = ulp_get_session(pci_addr);
540 /* Not Found the session Allocate a new one */
541 session = rte_zmalloc("bnxt_ulp_session",
542 sizeof(struct bnxt_ulp_session_state),
546 "Allocation failed for bnxt_ulp_session\n");
547 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
551 /* Add it to the queue */
552 session->pci_info.domain = pci_addr->domain;
553 session->pci_info.bus = pci_addr->bus;
554 pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
555 STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
559 ulp_context_initialized(session, init);
560 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
565 * When a device is closed, remove it's associated session from the global
569 ulp_session_deinit(struct bnxt_ulp_session_state *session)
574 if (!session->cfg_data) {
575 pthread_mutex_lock(&bnxt_ulp_global_mutex);
576 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
577 bnxt_ulp_session_state, next);
578 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
580 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
585 * When a port is initialized by dpdk. This functions is called
586 * and this function initializes the ULP context and rest of the
587 * infrastructure associated with it.
590 bnxt_ulp_init(struct bnxt *bp)
592 struct bnxt_ulp_session_state *session;
597 BNXT_TF_DBG(ERR, "ulp ctx already allocated\n");
602 * Multiple uplink ports can be associated with a single vswitch.
603 * Make sure only the port that is started first will initialize
606 session = ulp_session_init(bp, &init);
608 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
612 bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
613 sizeof(struct bnxt_ulp_context), 0);
615 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
616 ulp_session_deinit(session);
621 * If ULP is already initialized for a specific domain then simply
622 * assign the ulp context to this rte_eth_dev.
625 rc = ulp_ctx_attach(bp->ulp_ctx, session);
628 "Failed to attach the ulp context\n");
629 ulp_session_deinit(session);
630 rte_free(bp->ulp_ctx);
634 /* Update bnxt driver flags */
635 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
637 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
638 ulp_ctx_detach(bp, session);
639 ulp_session_deinit(session);
640 rte_free(bp->ulp_ctx);
644 /* update the port database */
645 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
648 "Failed to update port database\n");
649 ulp_ctx_detach(bp, session);
650 ulp_session_deinit(session);
651 rte_free(bp->ulp_ctx);
656 /* Allocate and Initialize the ulp context. */
657 rc = ulp_ctx_init(bp, session);
659 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
663 /* Initialize ulp dparms with values devargs passed */
664 rc = ulp_dparms_init(bp, bp->ulp_ctx);
666 /* create the port database */
667 rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
669 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
673 /* Update bnxt driver flags */
674 rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
676 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
680 /* update the port database */
681 rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
683 BNXT_TF_DBG(ERR, "Failed to update port database\n");
687 /* Create the Mark database. */
688 rc = ulp_mark_db_init(bp->ulp_ctx);
690 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
694 /* Create the flow database. */
695 rc = ulp_flow_db_init(bp->ulp_ctx);
697 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
701 /* Create the eem table scope. */
702 rc = ulp_eem_tbl_scope_init(bp);
704 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
708 rc = ulp_mapper_init(bp->ulp_ctx);
710 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
714 rc = ulp_fc_mgr_init(bp->ulp_ctx);
716 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
727 /* Below are the access functions to access internal data of ulp context. */
730 * When a port is deinit'ed by dpdk. This function is called
731 * and this function clears the ULP context and rest of the
732 * infrastructure associated with it.
735 bnxt_ulp_deinit(struct bnxt *bp)
737 struct bnxt_ulp_session_state *session;
738 struct rte_pci_device *pci_dev;
739 struct rte_pci_addr *pci_addr;
741 /* Get the session first */
742 pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
743 pci_addr = &pci_dev->addr;
744 pthread_mutex_lock(&bnxt_ulp_global_mutex);
745 session = ulp_get_session(pci_addr);
746 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
748 /* session not found then just exit */
752 /* clean up regular flows */
753 ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
755 /* cleanup the eem table scope */
756 ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
758 /* cleanup the flow database */
759 ulp_flow_db_deinit(bp->ulp_ctx);
761 /* Delete the Mark database */
762 ulp_mark_db_deinit(bp->ulp_ctx);
764 /* cleanup the ulp mapper */
765 ulp_mapper_deinit(bp->ulp_ctx);
767 /* Delete the Flow Counter Manager */
768 ulp_fc_mgr_deinit(bp->ulp_ctx);
770 /* Delete the Port database */
771 ulp_port_db_deinit(bp->ulp_ctx);
773 /* Delete the ulp context and tf session */
774 ulp_ctx_detach(bp, session);
776 /* Finally delete the bnxt session*/
777 ulp_session_deinit(session);
779 rte_free(bp->ulp_ctx);
782 /* Function to set the Mark DB into the context */
784 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
785 struct bnxt_ulp_mark_tbl *mark_tbl)
787 if (!ulp_ctx || !ulp_ctx->cfg_data) {
788 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
792 ulp_ctx->cfg_data->mark_tbl = mark_tbl;
797 /* Function to retrieve the Mark DB from the context. */
798 struct bnxt_ulp_mark_tbl *
799 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
801 if (!ulp_ctx || !ulp_ctx->cfg_data)
804 return ulp_ctx->cfg_data->mark_tbl;
807 /* Function to set the device id of the hardware. */
809 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
812 if (ulp_ctx && ulp_ctx->cfg_data) {
813 ulp_ctx->cfg_data->dev_id = dev_id;
820 /* Function to get the device id of the hardware. */
822 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
825 if (ulp_ctx && ulp_ctx->cfg_data) {
826 *dev_id = ulp_ctx->cfg_data->dev_id;
833 /* Function to get the table scope id of the EEM table. */
835 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
836 uint32_t *tbl_scope_id)
838 if (ulp_ctx && ulp_ctx->cfg_data) {
839 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
846 /* Function to set the table scope id of the EEM table. */
848 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
849 uint32_t tbl_scope_id)
851 if (ulp_ctx && ulp_ctx->cfg_data) {
852 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
859 /* Function to set the tfp session details from the ulp context. */
861 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
864 BNXT_TF_DBG(ERR, "Invalid arguments\n");
868 /* TBD The tfp should be removed once tf_attach is implemented. */
873 /* Function to get the tfp session details from the ulp context. */
875 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
878 BNXT_TF_DBG(ERR, "Invalid arguments\n");
881 /* TBD The tfp should be removed once tf_attach is implemented. */
886 * Get the device table entry based on the device id.
888 * dev_id [in] The device id of the hardware
890 * Returns the pointer to the device parameters.
892 struct bnxt_ulp_device_params *
893 bnxt_ulp_device_params_get(uint32_t dev_id)
895 if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
896 return &ulp_device_params[dev_id];
900 /* Function to set the flow database to the ulp context. */
902 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
903 struct bnxt_ulp_flow_db *flow_db)
905 if (!ulp_ctx || !ulp_ctx->cfg_data)
908 ulp_ctx->cfg_data->flow_db = flow_db;
912 /* Function to get the flow database from the ulp context. */
913 struct bnxt_ulp_flow_db *
914 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
916 if (!ulp_ctx || !ulp_ctx->cfg_data)
919 return ulp_ctx->cfg_data->flow_db;
922 /* Function to get the ulp context from eth device. */
923 struct bnxt_ulp_context *
924 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev *dev)
928 bp = (struct bnxt *)dev->data->dev_private;
930 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
937 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
940 if (!ulp_ctx || !ulp_ctx->cfg_data) {
941 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
945 ulp_ctx->cfg_data->mapper_data = mapper_data;
950 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
952 if (!ulp_ctx || !ulp_ctx->cfg_data) {
953 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
957 return ulp_ctx->cfg_data->mapper_data;
960 /* Function to set the port database to the ulp context. */
962 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
963 struct bnxt_ulp_port_db *port_db)
965 if (!ulp_ctx || !ulp_ctx->cfg_data)
968 ulp_ctx->cfg_data->port_db = port_db;
972 /* Function to get the port database from the ulp context. */
973 struct bnxt_ulp_port_db *
974 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
976 if (!ulp_ctx || !ulp_ctx->cfg_data)
979 return ulp_ctx->cfg_data->port_db;
982 /* Function to set the flow counter info into the context */
984 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
985 struct bnxt_ulp_fc_info *ulp_fc_info)
987 if (!ulp_ctx || !ulp_ctx->cfg_data) {
988 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
992 ulp_ctx->cfg_data->fc_info = ulp_fc_info;
997 /* Function to retrieve the flow counter info from the context. */
998 struct bnxt_ulp_fc_info *
999 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1001 if (!ulp_ctx || !ulp_ctx->cfg_data)
1004 return ulp_ctx->cfg_data->fc_info;