net/bnxt: fix function id used in flow flush
[dpdk.git] / drivers / net / bnxt / tf_ulp / bnxt_ulp.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #include <rte_log.h>
7 #include <rte_malloc.h>
8 #include <rte_flow.h>
9 #include <rte_flow_driver.h>
10 #include <rte_tailq.h>
11
12 #include "bnxt.h"
13 #include "bnxt_ulp.h"
14 #include "bnxt_tf_common.h"
15 #include "tf_core.h"
16 #include "tf_ext_flow_handle.h"
17
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"
25
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);
29
30 /* Mutex to synchronize bnxt_ulp_session_list operations. */
31 static pthread_mutex_t bnxt_ulp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
32
33 /*
34  * Allow the deletion of context only for the bnxt device that
35  * created the session.
36  */
37 bool
38 ulp_ctx_deinit_allowed(struct bnxt_ulp_context *ulp_ctx)
39 {
40         if (!ulp_ctx || !ulp_ctx->cfg_data)
41                 return false;
42
43         if (!ulp_ctx->cfg_data->ref_cnt) {
44                 BNXT_TF_DBG(DEBUG, "ulp ctx shall initiate deinit\n");
45                 return true;
46         }
47
48         return false;
49 }
50
51 /*
52  * Initialize an ULP session.
53  * An ULP session will contain all the resources needed to support rte flow
54  * offloads. A session is initialized as part of rte_eth_device start.
55  * A single vswitch instance can have multiple uplinks which means
56  * rte_eth_device start will be called for each of these devices.
57  * ULP session manager will make sure that a single ULP session is only
58  * initialized once. Apart from this, it also initializes MARK database,
59  * EEM table & flow database. ULP session manager also manages a list of
60  * all opened ULP sessions.
61  */
62 static int32_t
63 ulp_ctx_session_open(struct bnxt *bp,
64                      struct bnxt_ulp_session_state *session)
65 {
66         struct rte_eth_dev              *ethdev = bp->eth_dev;
67         int32_t                         rc = 0;
68         struct tf_open_session_parms    params;
69         struct tf_session_resources     *resources;
70
71         memset(&params, 0, sizeof(params));
72
73         rc = rte_eth_dev_get_name_by_port(ethdev->data->port_id,
74                                           params.ctrl_chan_name);
75         if (rc) {
76                 BNXT_TF_DBG(ERR, "Invalid port %d, rc = %d\n",
77                             ethdev->data->port_id, rc);
78                 return rc;
79         }
80
81         params.shadow_copy = true;
82         params.device_type = TF_DEVICE_TYPE_WH;
83         resources = &params.resources;
84         /** RX **/
85         /* Identifiers */
86         resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 422;
87         resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 6;
88         resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
89         resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
90         resources->ident_cnt[TF_DIR_RX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
91
92         /* Table Types */
93         resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 8192;
94         resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 8192;
95         resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 1023;
96
97         /* ENCAP */
98         resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_8B] = 255;
99         resources->tbl_cnt[TF_DIR_RX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 63;
100
101         /* TCAMs */
102         resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
103                 422;
104         resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
105                 6;
106         resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
107         resources->tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 88;
108
109         /* EM */
110         resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 13176;
111
112         /* EEM */
113         resources->em_cnt[TF_DIR_RX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
114
115         /** TX **/
116         /* Identifiers */
117         resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_HIGH] = 292;
118         resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_L2_CTXT_LOW] = 144;
119         resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_WC_PROF] = 8;
120         resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_PROF_FUNC] = 8;
121         resources->ident_cnt[TF_DIR_TX].cnt[TF_IDENT_TYPE_EM_PROF] = 8;
122
123         /* Table Types */
124         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_FULL_ACT_RECORD] = 8192;
125         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_STATS_64] = 8192;
126         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_MODIFY_IPV4] = 1023;
127
128         /* ENCAP */
129         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_64B] = 511;
130         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_16B] = 200;
131         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_ENCAP_8B] = 255;
132
133         /* TCAMs */
134         resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_HIGH] =
135                 292;
136         resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_L2_CTXT_TCAM_LOW] =
137                 144;
138         resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_PROF_TCAM] = 8;
139         resources->tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] = 8;
140
141         /* EM */
142         resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_EM_RECORD] = 15232;
143
144         /* EEM */
145         resources->em_cnt[TF_DIR_TX].cnt[TF_EM_TBL_TYPE_TBL_SCOPE] = 1;
146
147         /* SP */
148         resources->tbl_cnt[TF_DIR_TX].cnt[TF_TBL_TYPE_ACT_SP_SMAC_IPV4] = 488;
149
150         rc = tf_open_session(&bp->tfp, &params);
151         if (rc) {
152                 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
153                             params.ctrl_chan_name, rc);
154                 return -EINVAL;
155         }
156         if (!session->session_opened) {
157                 session->session_opened = 1;
158                 session->g_tfp = &bp->tfp;
159         }
160         return rc;
161 }
162
163 /*
164  * Close the ULP session.
165  * It takes the ulp context pointer.
166  */
167 static void
168 ulp_ctx_session_close(struct bnxt *bp,
169                       struct bnxt_ulp_session_state *session)
170 {
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 }
177
178 static void
179 bnxt_init_tbl_scope_parms(struct bnxt *bp,
180                           struct tf_alloc_tbl_scope_parms *params)
181 {
182         struct bnxt_ulp_device_params   *dparms;
183         uint32_t dev_id;
184         int rc;
185
186         rc = bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id);
187         if (rc)
188                 /* TBD: For now, just use default. */
189                 dparms = 0;
190         else
191                 dparms = bnxt_ulp_device_params_get(dev_id);
192
193         /*
194          * Set the flush timer for EEM entries. The value is in 100ms intervals,
195          * so 100 is 10s.
196          */
197         params->hw_flow_cache_flush_timer = 100;
198
199         if (!dparms) {
200                 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
201                 params->rx_max_action_entry_sz_in_bits =
202                         BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
203                 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
204                 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
205                 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
206
207                 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
208                 params->tx_max_action_entry_sz_in_bits =
209                         BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
210                 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
211                 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
212                 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
213         } else {
214                 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
215                 params->rx_max_action_entry_sz_in_bits =
216                         BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
217                 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
218                 params->rx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
219                 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
220
221                 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
222                 params->tx_max_action_entry_sz_in_bits =
223                         BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
224                 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
225                 params->tx_num_flows_in_k = dparms->flow_db_num_entries / 1024;
226                 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
227         }
228 }
229
230 /* Initialize Extended Exact Match host memory. */
231 static int32_t
232 ulp_eem_tbl_scope_init(struct bnxt *bp)
233 {
234         struct tf_alloc_tbl_scope_parms params = {0};
235         uint32_t dev_id;
236         struct bnxt_ulp_device_params *dparms;
237         int rc;
238
239         /* Get the dev specific number of flows that needed to be supported. */
240         if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
241                 BNXT_TF_DBG(ERR, "Invalid device id\n");
242                 return -EINVAL;
243         }
244
245         dparms = bnxt_ulp_device_params_get(dev_id);
246         if (!dparms) {
247                 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
248                 return -ENODEV;
249         }
250
251         if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
252                 BNXT_TF_DBG(INFO, "Table Scope alloc is not required\n");
253                 return 0;
254         }
255
256         bnxt_init_tbl_scope_parms(bp, &params);
257
258         rc = tf_alloc_tbl_scope(&bp->tfp, &params);
259         if (rc) {
260                 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
261                             rc);
262                 return rc;
263         }
264
265         rc = bnxt_ulp_cntxt_tbl_scope_id_set(bp->ulp_ctx, params.tbl_scope_id);
266         if (rc) {
267                 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
268                 return rc;
269         }
270
271         return 0;
272 }
273
274 /* Free Extended Exact Match host memory */
275 static int32_t
276 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
277 {
278         struct tf_free_tbl_scope_parms  params = {0};
279         struct tf                       *tfp;
280         int32_t                         rc = 0;
281         struct bnxt_ulp_device_params *dparms;
282         uint32_t dev_id;
283
284         if (!ulp_ctx || !ulp_ctx->cfg_data)
285                 return -EINVAL;
286
287         tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
288         if (!tfp) {
289                 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
290                 return -EINVAL;
291         }
292
293         /* Get the dev specific number of flows that needed to be supported. */
294         if (bnxt_ulp_cntxt_dev_id_get(bp->ulp_ctx, &dev_id)) {
295                 BNXT_TF_DBG(ERR, "Invalid device id\n");
296                 return -EINVAL;
297         }
298
299         dparms = bnxt_ulp_device_params_get(dev_id);
300         if (!dparms) {
301                 BNXT_TF_DBG(ERR, "could not fetch the device params\n");
302                 return -ENODEV;
303         }
304
305         if (dparms->flow_mem_type != BNXT_ULP_FLOW_MEM_TYPE_EXT) {
306                 BNXT_TF_DBG(INFO, "Table Scope free is not required\n");
307                 return 0;
308         }
309
310         rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &params.tbl_scope_id);
311         if (rc) {
312                 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
313                 return -EINVAL;
314         }
315
316         rc = tf_free_tbl_scope(tfp, &params);
317         if (rc) {
318                 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
319                 return -EINVAL;
320         }
321         return rc;
322 }
323
324 /* The function to free and deinit the ulp context data. */
325 static int32_t
326 ulp_ctx_deinit(struct bnxt *bp,
327                struct bnxt_ulp_session_state *session)
328 {
329         /* close the tf session */
330         ulp_ctx_session_close(bp, session);
331
332         /* Free the contents */
333         if (session->cfg_data) {
334                 rte_free(session->cfg_data);
335                 bp->ulp_ctx->cfg_data = NULL;
336                 session->cfg_data = NULL;
337         }
338         return 0;
339 }
340
341 /* The function to allocate and initialize the ulp context data. */
342 static int32_t
343 ulp_ctx_init(struct bnxt *bp,
344              struct bnxt_ulp_session_state *session)
345 {
346         struct bnxt_ulp_data    *ulp_data;
347         int32_t                 rc = 0;
348
349         /* Allocate memory to hold ulp context data. */
350         ulp_data = rte_zmalloc("bnxt_ulp_data",
351                                sizeof(struct bnxt_ulp_data), 0);
352         if (!ulp_data) {
353                 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
354                 return -ENOMEM;
355         }
356
357         /* Increment the ulp context data reference count usage. */
358         bp->ulp_ctx->cfg_data = ulp_data;
359         session->cfg_data = ulp_data;
360         ulp_data->ref_cnt++;
361         ulp_data->ulp_flags |= BNXT_ULP_VF_REP_ENABLED;
362
363         /* Open the ulp session. */
364         rc = ulp_ctx_session_open(bp, session);
365         if (rc) {
366                 session->session_opened = 1;
367                 (void)ulp_ctx_deinit(bp, session);
368                 return rc;
369         }
370
371         bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, &bp->tfp);
372         return rc;
373 }
374
375 /* The function to initialize ulp dparms with devargs */
376 static int32_t
377 ulp_dparms_init(struct bnxt *bp,
378                 struct bnxt_ulp_context *ulp_ctx)
379 {
380         struct bnxt_ulp_device_params *dparms;
381         uint32_t dev_id;
382
383         if (!bp->max_num_kflows)
384                 return 0;
385
386         if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
387                 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
388                 return -EINVAL;
389         }
390
391         dparms = bnxt_ulp_device_params_get(dev_id);
392         if (!dparms) {
393                 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
394                 return -EINVAL;
395         }
396
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);
403
404         return 0;
405 }
406
407 /* The function to initialize bp flags with truflow features */
408 static int32_t
409 ulp_dparms_dev_port_intf_update(struct bnxt *bp,
410                                 struct bnxt_ulp_context *ulp_ctx)
411 {
412         struct bnxt_ulp_device_params *dparms;
413         uint32_t dev_id;
414
415         if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
416                 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
417                 return -EINVAL;
418         }
419
420         dparms = bnxt_ulp_device_params_get(dev_id);
421         if (!dparms) {
422                 BNXT_TF_DBG(DEBUG, "Failed to get device parms\n");
423                 return -EINVAL;
424         }
425
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;
429
430         return 0;
431 }
432
433 static int32_t
434 ulp_ctx_attach(struct bnxt *bp,
435                struct bnxt_ulp_session_state *session)
436 {
437         int32_t rc = 0;
438
439         /* Increment the ulp context data reference count usage. */
440         bp->ulp_ctx->cfg_data = session->cfg_data;
441         bp->ulp_ctx->cfg_data->ref_cnt++;
442
443         /* update the session details in bnxt tfp */
444         bp->tfp.session = session->g_tfp->session;
445
446         /* Create a TF Client */
447         rc = ulp_ctx_session_open(bp, session);
448         if (rc) {
449                 PMD_DRV_LOG(ERR, "Failed to open ctxt session, rc:%d\n", rc);
450                 bp->tfp.session = NULL;
451                 return rc;
452         }
453
454         bnxt_ulp_cntxt_tfp_set(bp->ulp_ctx, &bp->tfp);
455         return rc;
456 }
457
458 static void
459 ulp_ctx_detach(struct bnxt *bp)
460 {
461         if (bp->tfp.session) {
462                 tf_close_session(&bp->tfp);
463                 bp->tfp.session = NULL;
464         }
465 }
466
467 /*
468  * Initialize the state of an ULP session.
469  * If the state of an ULP session is not initialized, set it's state to
470  * initialized. If the state is already initialized, do nothing.
471  */
472 static void
473 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
474 {
475         pthread_mutex_lock(&session->bnxt_ulp_mutex);
476
477         if (!session->bnxt_ulp_init) {
478                 session->bnxt_ulp_init = true;
479                 *init = false;
480         } else {
481                 *init = true;
482         }
483
484         pthread_mutex_unlock(&session->bnxt_ulp_mutex);
485 }
486
487 /*
488  * Check if an ULP session is already allocated for a specific PCI
489  * domain & bus. If it is already allocated simply return the session
490  * pointer, otherwise allocate a new session.
491  */
492 static struct bnxt_ulp_session_state *
493 ulp_get_session(struct rte_pci_addr *pci_addr)
494 {
495         struct bnxt_ulp_session_state *session;
496
497         STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
498                 if (session->pci_info.domain == pci_addr->domain &&
499                     session->pci_info.bus == pci_addr->bus) {
500                         return session;
501                 }
502         }
503         return NULL;
504 }
505
506 /*
507  * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
508  * If it's already initialized simply return the already existing session.
509  */
510 static struct bnxt_ulp_session_state *
511 ulp_session_init(struct bnxt *bp,
512                  bool *init)
513 {
514         struct rte_pci_device           *pci_dev;
515         struct rte_pci_addr             *pci_addr;
516         struct bnxt_ulp_session_state   *session;
517         int rc = 0;
518
519         if (!bp)
520                 return NULL;
521
522         pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
523         pci_addr = &pci_dev->addr;
524
525         pthread_mutex_lock(&bnxt_ulp_global_mutex);
526
527         session = ulp_get_session(pci_addr);
528         if (!session) {
529                 /* Not Found the session  Allocate a new one */
530                 session = rte_zmalloc("bnxt_ulp_session",
531                                       sizeof(struct bnxt_ulp_session_state),
532                                       0);
533                 if (!session) {
534                         BNXT_TF_DBG(ERR,
535                                     "Allocation failed for bnxt_ulp_session\n");
536                         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
537                         return NULL;
538
539                 } else {
540                         /* Add it to the queue */
541                         session->pci_info.domain = pci_addr->domain;
542                         session->pci_info.bus = pci_addr->bus;
543                         rc = pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
544                         if (rc) {
545                                 BNXT_TF_DBG(ERR, "mutex create failed\n");
546                                 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
547                                 return NULL;
548                         }
549                         STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
550                                            session, next);
551                 }
552         }
553         ulp_context_initialized(session, init);
554         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
555         return session;
556 }
557
558 /*
559  * When a device is closed, remove it's associated session from the global
560  * session list.
561  */
562 static void
563 ulp_session_deinit(struct bnxt_ulp_session_state *session)
564 {
565         if (!session)
566                 return;
567
568         if (!session->cfg_data) {
569                 pthread_mutex_lock(&bnxt_ulp_global_mutex);
570                 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
571                               bnxt_ulp_session_state, next);
572                 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
573                 rte_free(session);
574                 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
575         }
576 }
577
578 /*
579  * Internal api to enable NAT feature.
580  * Set set_flag to 1 to set the value or zero to reset the value.
581  * returns 0 on success.
582  */
583 static int32_t
584 bnxt_ulp_global_cfg_update(struct bnxt *bp,
585                            enum tf_dir dir,
586                            enum tf_global_config_type type,
587                            uint32_t offset,
588                            uint32_t value,
589                            uint32_t set_flag)
590 {
591         uint32_t global_cfg = 0;
592         int rc;
593         struct tf_global_cfg_parms parms;
594
595         /* Initialize the params */
596         parms.dir = dir,
597         parms.type = type,
598         parms.offset = offset,
599         parms.config = (uint8_t *)&global_cfg,
600         parms.config_sz_in_bytes = sizeof(global_cfg);
601
602         rc = tf_get_global_cfg(&bp->tfp, &parms);
603         if (rc) {
604                 BNXT_TF_DBG(ERR, "Failed to get global cfg 0x%x rc:%d\n",
605                             type, rc);
606                 return rc;
607         }
608
609         if (set_flag)
610                 global_cfg |= value;
611         else
612                 global_cfg &= ~value;
613
614         /* SET the register RE_CFA_REG_ACT_TECT */
615         rc = tf_set_global_cfg(&bp->tfp, &parms);
616         if (rc) {
617                 BNXT_TF_DBG(ERR, "Failed to set global cfg 0x%x rc:%d\n",
618                             type, rc);
619                 return rc;
620         }
621         return rc;
622 }
623
624 /* Internal function to delete all the flows belonging to the given port */
625 static void
626 bnxt_ulp_flush_port_flows(struct bnxt *bp)
627 {
628         uint16_t func_id;
629
630         /* it is assumed that port is either TVF or PF */
631         if (ulp_port_db_port_func_id_get(bp->ulp_ctx,
632                                          bp->eth_dev->data->port_id,
633                                          &func_id)) {
634                 BNXT_TF_DBG(ERR, "Invalid argument\n");
635                 return;
636         }
637         (void)ulp_flow_db_function_flow_flush(bp->ulp_ctx, func_id);
638 }
639
640 /* Internal function to delete the VFR default flows */
641 static void
642 bnxt_ulp_destroy_vfr_default_rules(struct bnxt *bp, bool global)
643 {
644         struct bnxt_ulp_vfr_rule_info *info;
645         uint8_t port_id;
646         struct rte_eth_dev *vfr_eth_dev;
647         struct bnxt_vf_representor *vfr_bp;
648
649         if (!BNXT_TRUFLOW_EN(bp) || BNXT_ETH_DEV_IS_REPRESENTOR(bp->eth_dev))
650                 return;
651
652         if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
653                 return;
654
655         /* Delete default rules for all ports */
656         for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
657                 info = &bp->ulp_ctx->cfg_data->vfr_rule_info[port_id];
658                 if (!info->valid)
659                         continue;
660
661                 if (!global && info->parent_port_id !=
662                     bp->eth_dev->data->port_id)
663                         continue;
664
665                 /* Destroy the flows */
666                 ulp_default_flow_destroy(bp->eth_dev, info->rep2vf_flow_id);
667                 ulp_default_flow_destroy(bp->eth_dev, info->vf2rep_flow_id);
668                 /* Clean up the tx action pointer */
669                 vfr_eth_dev = &rte_eth_devices[port_id];
670                 if (vfr_eth_dev) {
671                         vfr_bp = vfr_eth_dev->data->dev_private;
672                         vfr_bp->vfr_tx_cfa_action = 0;
673                 }
674                 memset(info, 0, sizeof(struct bnxt_ulp_vfr_rule_info));
675         }
676 }
677
678 /*
679  * When a port is deinit'ed by dpdk. This function is called
680  * and this function clears the ULP context and rest of the
681  * infrastructure associated with it.
682  */
683 static void
684 bnxt_ulp_deinit(struct bnxt *bp,
685                 struct bnxt_ulp_session_state *session)
686 {
687         if (!bp->ulp_ctx || !bp->ulp_ctx->cfg_data)
688                 return;
689
690         /* clean up default flows */
691         bnxt_ulp_destroy_df_rules(bp, true);
692
693         /* clean up default VFR flows */
694         bnxt_ulp_destroy_vfr_default_rules(bp, true);
695
696         /* clean up regular flows */
697         ulp_flow_db_flush_flows(bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
698
699         /* cleanup the eem table scope */
700         ulp_eem_tbl_scope_deinit(bp, bp->ulp_ctx);
701
702         /* cleanup the flow database */
703         ulp_flow_db_deinit(bp->ulp_ctx);
704
705         /* Delete the Mark database */
706         ulp_mark_db_deinit(bp->ulp_ctx);
707
708         /* cleanup the ulp mapper */
709         ulp_mapper_deinit(bp->ulp_ctx);
710
711         /* Delete the Flow Counter Manager */
712         ulp_fc_mgr_deinit(bp->ulp_ctx);
713
714         /* Delete the Port database */
715         ulp_port_db_deinit(bp->ulp_ctx);
716
717         /* Disable NAT feature */
718         (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
719                                          TF_TUNNEL_ENCAP_NAT,
720                                          (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
721                                           BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
722                                          0);
723
724         (void)bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
725                                          TF_TUNNEL_ENCAP_NAT,
726                                          (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
727                                           BNXT_ULP_NAT_INNER_L2_HEADER_DMAC),
728                                          0);
729
730         /* Delete the ulp context and tf session and free the ulp context */
731         ulp_ctx_deinit(bp, session);
732         BNXT_TF_DBG(DEBUG, "ulp ctx has been deinitialized\n");
733 }
734
735 /*
736  * When a port is initialized by dpdk. This functions is called
737  * and this function initializes the ULP context and rest of the
738  * infrastructure associated with it.
739  */
740 static int32_t
741 bnxt_ulp_init(struct bnxt *bp,
742               struct bnxt_ulp_session_state *session)
743 {
744         int rc;
745
746         /* Allocate and Initialize the ulp context. */
747         rc = ulp_ctx_init(bp, session);
748         if (rc) {
749                 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
750                 goto jump_to_error;
751         }
752
753         /* Initialize ulp dparms with values devargs passed */
754         rc = ulp_dparms_init(bp, bp->ulp_ctx);
755         if (rc) {
756                 BNXT_TF_DBG(ERR, "Failed to initialize the dparms\n");
757                 goto jump_to_error;
758         }
759
760         /* create the port database */
761         rc = ulp_port_db_init(bp->ulp_ctx, bp->port_cnt);
762         if (rc) {
763                 BNXT_TF_DBG(ERR, "Failed to create the port database\n");
764                 goto jump_to_error;
765         }
766
767         /* Create the Mark database. */
768         rc = ulp_mark_db_init(bp->ulp_ctx);
769         if (rc) {
770                 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
771                 goto jump_to_error;
772         }
773
774         /* Create the flow database. */
775         rc = ulp_flow_db_init(bp->ulp_ctx);
776         if (rc) {
777                 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
778                 goto jump_to_error;
779         }
780
781         /* Create the eem table scope. */
782         rc = ulp_eem_tbl_scope_init(bp);
783         if (rc) {
784                 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
785                 goto jump_to_error;
786         }
787
788         rc = ulp_mapper_init(bp->ulp_ctx);
789         if (rc) {
790                 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
791                 goto jump_to_error;
792         }
793
794         rc = ulp_fc_mgr_init(bp->ulp_ctx);
795         if (rc) {
796                 BNXT_TF_DBG(ERR, "Failed to initialize ulp flow counter mgr\n");
797                 goto jump_to_error;
798         }
799
800         /*
801          * Enable NAT feature. Set the global configuration register
802          * Tunnel encap to enable NAT with the reuse of existing inner
803          * L2 header smac and dmac
804          */
805         rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_RX, TF_TUNNEL_ENCAP,
806                                         TF_TUNNEL_ENCAP_NAT,
807                                         (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
808                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
809         if (rc) {
810                 BNXT_TF_DBG(ERR, "Failed to set rx global configuration\n");
811                 goto jump_to_error;
812         }
813
814         rc = bnxt_ulp_global_cfg_update(bp, TF_DIR_TX, TF_TUNNEL_ENCAP,
815                                         TF_TUNNEL_ENCAP_NAT,
816                                         (BNXT_ULP_NAT_INNER_L2_HEADER_SMAC |
817                                         BNXT_ULP_NAT_INNER_L2_HEADER_DMAC), 1);
818         if (rc) {
819                 BNXT_TF_DBG(ERR, "Failed to set tx global configuration\n");
820                 goto jump_to_error;
821         }
822         BNXT_TF_DBG(DEBUG, "ulp ctx has been initialized\n");
823         return rc;
824
825 jump_to_error:
826         bnxt_ulp_deinit(bp, session);
827         return rc;
828 }
829
830 /*
831  * When a port is initialized by dpdk. This functions sets up
832  * the port specific details.
833  */
834 int32_t
835 bnxt_ulp_port_init(struct bnxt *bp)
836 {
837         struct bnxt_ulp_session_state *session;
838         bool initialized;
839         int32_t rc = 0;
840
841         if (!bp || !BNXT_TRUFLOW_EN(bp))
842                 return rc;
843
844         if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
845                 BNXT_TF_DBG(ERR,
846                             "Skip ulp init for port: %d, not a TVF or PF\n",
847                         bp->eth_dev->data->port_id);
848                 return rc;
849         }
850
851         if (bp->ulp_ctx) {
852                 BNXT_TF_DBG(DEBUG, "ulp ctx already allocated\n");
853                 return rc;
854         }
855
856         bp->ulp_ctx = rte_zmalloc("bnxt_ulp_ctx",
857                                   sizeof(struct bnxt_ulp_context), 0);
858         if (!bp->ulp_ctx) {
859                 BNXT_TF_DBG(ERR, "Failed to allocate ulp ctx\n");
860                 return -ENOMEM;
861         }
862
863         /*
864          * Multiple uplink ports can be associated with a single vswitch.
865          * Make sure only the port that is started first will initialize
866          * the TF session.
867          */
868         session = ulp_session_init(bp, &initialized);
869         if (!session) {
870                 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
871                 rc = -EIO;
872                 goto jump_to_error;
873         }
874
875         if (initialized) {
876                 /*
877                  * If ULP is already initialized for a specific domain then
878                  * simply assign the ulp context to this rte_eth_dev.
879                  */
880                 rc = ulp_ctx_attach(bp, session);
881                 if (rc) {
882                         BNXT_TF_DBG(ERR, "Failed to attach the ulp context\n");
883                         goto jump_to_error;
884                 }
885         } else {
886                 rc = bnxt_ulp_init(bp, session);
887                 if (rc) {
888                         BNXT_TF_DBG(ERR, "Failed to initialize the ulp init\n");
889                         goto jump_to_error;
890                 }
891         }
892
893         /* Update bnxt driver flags */
894         rc = ulp_dparms_dev_port_intf_update(bp, bp->ulp_ctx);
895         if (rc) {
896                 BNXT_TF_DBG(ERR, "Failed to update driver flags\n");
897                 goto jump_to_error;
898         }
899
900         /* update the port database for the given interface */
901         rc = ulp_port_db_dev_port_intf_update(bp->ulp_ctx, bp->eth_dev);
902         if (rc) {
903                 BNXT_TF_DBG(ERR, "Failed to update port database\n");
904                 goto jump_to_error;
905         }
906         /* create the default rules */
907         bnxt_ulp_create_df_rules(bp);
908         BNXT_TF_DBG(DEBUG, "ULP Port:%d created and initialized\n",
909                     bp->eth_dev->data->port_id);
910         return rc;
911
912 jump_to_error:
913         bnxt_ulp_port_deinit(bp);
914         return rc;
915 }
916
917 /*
918  * When a port is de-initialized by dpdk. This functions clears up
919  * the port specific details.
920  */
921 void
922 bnxt_ulp_port_deinit(struct bnxt *bp)
923 {
924         struct bnxt_ulp_session_state *session;
925         struct rte_pci_device *pci_dev;
926         struct rte_pci_addr *pci_addr;
927
928         if (!BNXT_TRUFLOW_EN(bp))
929                 return;
930
931         if (!BNXT_PF(bp) && !BNXT_VF_IS_TRUSTED(bp)) {
932                 BNXT_TF_DBG(ERR,
933                             "Skip ULP deinit port:%d, not a TVF or PF\n",
934                             bp->eth_dev->data->port_id);
935                 return;
936         }
937
938         if (!bp->ulp_ctx) {
939                 BNXT_TF_DBG(DEBUG, "ulp ctx already de-allocated\n");
940                 return;
941         }
942
943         BNXT_TF_DBG(DEBUG, "ULP Port:%d destroyed\n",
944                     bp->eth_dev->data->port_id);
945
946         /* Get the session details  */
947         pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
948         pci_addr = &pci_dev->addr;
949         pthread_mutex_lock(&bnxt_ulp_global_mutex);
950         session = ulp_get_session(pci_addr);
951         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
952
953         /* session not found then just exit */
954         if (!session) {
955                 /* Free the ulp context */
956                 rte_free(bp->ulp_ctx);
957                 bp->ulp_ctx = NULL;
958                 return;
959         }
960
961         /* Check the reference count to deinit or deattach*/
962         if (bp->ulp_ctx->cfg_data && bp->ulp_ctx->cfg_data->ref_cnt) {
963                 bp->ulp_ctx->cfg_data->ref_cnt--;
964                 if (bp->ulp_ctx->cfg_data->ref_cnt) {
965                         /* free the port details */
966                         /* Free the default flow rule associated to this port */
967                         bnxt_ulp_destroy_df_rules(bp, false);
968                         bnxt_ulp_destroy_vfr_default_rules(bp, false);
969
970                         /* free flows associated with this port */
971                         bnxt_ulp_flush_port_flows(bp);
972
973                         /* close the session associated with this port */
974                         ulp_ctx_detach(bp);
975                 } else {
976                         /* Perform ulp ctx deinit */
977                         bnxt_ulp_deinit(bp, session);
978                 }
979         }
980
981         /* clean up the session */
982         ulp_session_deinit(session);
983
984         /* Free the ulp context */
985         rte_free(bp->ulp_ctx);
986         bp->ulp_ctx = NULL;
987 }
988
989 /* Below are the access functions to access internal data of ulp context. */
990 /* Function to set the Mark DB into the context */
991 int32_t
992 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
993                                 struct bnxt_ulp_mark_tbl *mark_tbl)
994 {
995         if (!ulp_ctx || !ulp_ctx->cfg_data) {
996                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
997                 return -EINVAL;
998         }
999
1000         ulp_ctx->cfg_data->mark_tbl = mark_tbl;
1001
1002         return 0;
1003 }
1004
1005 /* Function to retrieve the Mark DB from the context. */
1006 struct bnxt_ulp_mark_tbl *
1007 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
1008 {
1009         if (!ulp_ctx || !ulp_ctx->cfg_data)
1010                 return NULL;
1011
1012         return ulp_ctx->cfg_data->mark_tbl;
1013 }
1014
1015 /* Function to set the device id of the hardware. */
1016 int32_t
1017 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
1018                           uint32_t dev_id)
1019 {
1020         if (ulp_ctx && ulp_ctx->cfg_data) {
1021                 ulp_ctx->cfg_data->dev_id = dev_id;
1022                 return 0;
1023         }
1024
1025         return -EINVAL;
1026 }
1027
1028 /* Function to get the device id of the hardware. */
1029 int32_t
1030 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
1031                           uint32_t *dev_id)
1032 {
1033         if (ulp_ctx && ulp_ctx->cfg_data) {
1034                 *dev_id = ulp_ctx->cfg_data->dev_id;
1035                 return 0;
1036         }
1037
1038         return -EINVAL;
1039 }
1040
1041 /* Function to get the table scope id of the EEM table. */
1042 int32_t
1043 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
1044                                 uint32_t *tbl_scope_id)
1045 {
1046         if (ulp_ctx && ulp_ctx->cfg_data) {
1047                 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
1048                 return 0;
1049         }
1050
1051         return -EINVAL;
1052 }
1053
1054 /* Function to set the table scope id of the EEM table. */
1055 int32_t
1056 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
1057                                 uint32_t tbl_scope_id)
1058 {
1059         if (ulp_ctx && ulp_ctx->cfg_data) {
1060                 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
1061                 return 0;
1062         }
1063
1064         return -EINVAL;
1065 }
1066
1067 /* Function to set the tfp session details from the ulp context. */
1068 int32_t
1069 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
1070 {
1071         if (!ulp) {
1072                 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1073                 return -EINVAL;
1074         }
1075
1076         ulp->g_tfp = tfp;
1077         return 0;
1078 }
1079
1080 /* Function to get the tfp session details from the ulp context. */
1081 struct tf *
1082 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
1083 {
1084         if (!ulp) {
1085                 BNXT_TF_DBG(ERR, "Invalid arguments\n");
1086                 return NULL;
1087         }
1088         return ulp->g_tfp;
1089 }
1090
1091 /*
1092  * Get the device table entry based on the device id.
1093  *
1094  * dev_id [in] The device id of the hardware
1095  *
1096  * Returns the pointer to the device parameters.
1097  */
1098 struct bnxt_ulp_device_params *
1099 bnxt_ulp_device_params_get(uint32_t dev_id)
1100 {
1101         if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
1102                 return &ulp_device_params[dev_id];
1103         return NULL;
1104 }
1105
1106 /* Function to set the flow database to the ulp context. */
1107 int32_t
1108 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
1109                                 struct bnxt_ulp_flow_db *flow_db)
1110 {
1111         if (!ulp_ctx || !ulp_ctx->cfg_data)
1112                 return -EINVAL;
1113
1114         ulp_ctx->cfg_data->flow_db = flow_db;
1115         return 0;
1116 }
1117
1118 /* Function to get the flow database from the ulp context. */
1119 struct bnxt_ulp_flow_db *
1120 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
1121 {
1122         if (!ulp_ctx || !ulp_ctx->cfg_data)
1123                 return NULL;
1124
1125         return ulp_ctx->cfg_data->flow_db;
1126 }
1127
1128 /* Function to get the ulp context from eth device. */
1129 struct bnxt_ulp_context *
1130 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev      *dev)
1131 {
1132         struct bnxt *bp = (struct bnxt *)dev->data->dev_private;
1133
1134         if (BNXT_ETH_DEV_IS_REPRESENTOR(dev)) {
1135                 struct bnxt_vf_representor *vfr = dev->data->dev_private;
1136
1137                 bp = vfr->parent_dev->data->dev_private;
1138         }
1139
1140         if (!bp) {
1141                 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
1142                 return NULL;
1143         }
1144         return bp->ulp_ctx;
1145 }
1146
1147 int32_t
1148 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
1149                                     void *mapper_data)
1150 {
1151         if (!ulp_ctx || !ulp_ctx->cfg_data) {
1152                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1153                 return -EINVAL;
1154         }
1155
1156         ulp_ctx->cfg_data->mapper_data = mapper_data;
1157         return 0;
1158 }
1159
1160 void *
1161 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
1162 {
1163         if (!ulp_ctx || !ulp_ctx->cfg_data) {
1164                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1165                 return NULL;
1166         }
1167
1168         return ulp_ctx->cfg_data->mapper_data;
1169 }
1170
1171 /* Function to set the port database to the ulp context. */
1172 int32_t
1173 bnxt_ulp_cntxt_ptr2_port_db_set(struct bnxt_ulp_context *ulp_ctx,
1174                                 struct bnxt_ulp_port_db *port_db)
1175 {
1176         if (!ulp_ctx || !ulp_ctx->cfg_data)
1177                 return -EINVAL;
1178
1179         ulp_ctx->cfg_data->port_db = port_db;
1180         return 0;
1181 }
1182
1183 /* Function to get the port database from the ulp context. */
1184 struct bnxt_ulp_port_db *
1185 bnxt_ulp_cntxt_ptr2_port_db_get(struct bnxt_ulp_context *ulp_ctx)
1186 {
1187         if (!ulp_ctx || !ulp_ctx->cfg_data)
1188                 return NULL;
1189
1190         return ulp_ctx->cfg_data->port_db;
1191 }
1192
1193 /* Function to set the flow counter info into the context */
1194 int32_t
1195 bnxt_ulp_cntxt_ptr2_fc_info_set(struct bnxt_ulp_context *ulp_ctx,
1196                                 struct bnxt_ulp_fc_info *ulp_fc_info)
1197 {
1198         if (!ulp_ctx || !ulp_ctx->cfg_data) {
1199                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
1200                 return -EINVAL;
1201         }
1202
1203         ulp_ctx->cfg_data->fc_info = ulp_fc_info;
1204
1205         return 0;
1206 }
1207
1208 /* Function to retrieve the flow counter info from the context. */
1209 struct bnxt_ulp_fc_info *
1210 bnxt_ulp_cntxt_ptr2_fc_info_get(struct bnxt_ulp_context *ulp_ctx)
1211 {
1212         if (!ulp_ctx || !ulp_ctx->cfg_data)
1213                 return NULL;
1214
1215         return ulp_ctx->cfg_data->fc_info;
1216 }
1217
1218 /* Function to get the ulp flags from the ulp context. */
1219 int32_t
1220 bnxt_ulp_cntxt_ptr2_ulp_flags_get(struct bnxt_ulp_context *ulp_ctx,
1221                                   uint32_t *flags)
1222 {
1223         if (!ulp_ctx || !ulp_ctx->cfg_data)
1224                 return -1;
1225
1226         *flags =  ulp_ctx->cfg_data->ulp_flags;
1227         return 0;
1228 }
1229
1230 /* Function to get the ulp vfr info from the ulp context. */
1231 struct bnxt_ulp_vfr_rule_info*
1232 bnxt_ulp_cntxt_ptr2_ulp_vfr_info_get(struct bnxt_ulp_context *ulp_ctx,
1233                                      uint32_t port_id)
1234 {
1235         if (!ulp_ctx || !ulp_ctx->cfg_data || port_id >= RTE_MAX_ETHPORTS)
1236                 return NULL;
1237
1238         return &ulp_ctx->cfg_data->vfr_rule_info[port_id];
1239 }