202b4a529b88c865956c5aaa22076f4b95b155ba
[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_ulp.h"
13 #include "bnxt_tf_common.h"
14 #include "bnxt.h"
15 #include "tf_core.h"
16 #include "tf_ext_flow_handle.h"
17
18 #include "ulp_template_db.h"
19 #include "ulp_template_struct.h"
20 #include "ulp_mark_mgr.h"
21 #include "ulp_flow_db.h"
22 #include "ulp_mapper.h"
23
24 /* Linked list of all TF sessions. */
25 STAILQ_HEAD(, bnxt_ulp_session_state) bnxt_ulp_session_list =
26                         STAILQ_HEAD_INITIALIZER(bnxt_ulp_session_list);
27
28 /* Mutex to synchronize bnxt_ulp_session_list operations. */
29 static pthread_mutex_t bnxt_ulp_global_mutex = PTHREAD_MUTEX_INITIALIZER;
30
31 /*
32  * Allow the deletion of context only for the bnxt device that
33  * created the session
34  * TBD - The implementation of the function should change to
35  * using the reference count once tf_session_attach functionality
36  * is fixed.
37  */
38 bool
39 ulp_ctx_deinit_allowed(void *ptr)
40 {
41         struct bnxt *bp = (struct bnxt *)ptr;
42
43         if (!bp)
44                 return 0;
45
46         if (&bp->tfp == bp->ulp_ctx.g_tfp)
47                 return 1;
48
49         return 0;
50 }
51
52 /*
53  * Initialize an ULP session.
54  * An ULP session will contain all the resources needed to support rte flow
55  * offloads. A session is initialized as part of rte_eth_device start.
56  * A single vswitch instance can have multiple uplinks which means
57  * rte_eth_device start will be called for each of these devices.
58  * ULP session manager will make sure that a single ULP session is only
59  * initialized once. Apart from this, it also initializes MARK database,
60  * EEM table & flow database. ULP session manager also manages a list of
61  * all opened ULP sessions.
62  */
63 static int32_t
64 ulp_ctx_session_open(struct bnxt *bp,
65                      struct bnxt_ulp_session_state *session)
66 {
67         struct rte_eth_dev              *ethdev = bp->eth_dev;
68         int32_t                         rc = 0;
69         struct tf_open_session_parms    params;
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         rc = tf_open_session(&bp->tfp, &params);
82         if (rc) {
83                 BNXT_TF_DBG(ERR, "Failed to open TF session - %s, rc = %d\n",
84                             params.ctrl_chan_name, rc);
85                 return -EINVAL;
86         }
87         session->session_opened = 1;
88         session->g_tfp = &bp->tfp;
89         return rc;
90 }
91
92 /*
93  * Close the ULP session.
94  * It takes the ulp context pointer.
95  */
96 static void
97 ulp_ctx_session_close(struct bnxt *bp,
98                       struct bnxt_ulp_session_state *session)
99 {
100         /* close the session in the hardware */
101         if (session->session_opened)
102                 tf_close_session(&bp->tfp);
103         session->session_opened = 0;
104         session->g_tfp = NULL;
105         bp->ulp_ctx.g_tfp = NULL;
106 }
107
108 static void
109 bnxt_init_tbl_scope_parms(struct bnxt *bp,
110                           struct tf_alloc_tbl_scope_parms *params)
111 {
112         struct bnxt_ulp_device_params   *dparms;
113         uint32_t dev_id;
114         int rc;
115
116         rc = bnxt_ulp_cntxt_dev_id_get(&bp->ulp_ctx, &dev_id);
117         if (rc)
118                 /* TBD: For now, just use default. */
119                 dparms = 0;
120         else
121                 dparms = bnxt_ulp_device_params_get(dev_id);
122
123         if (!dparms) {
124                 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
125                 params->rx_max_action_entry_sz_in_bits =
126                         BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
127                 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
128                 params->rx_num_flows_in_k = BNXT_ULP_RX_NUM_FLOWS;
129                 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
130
131                 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
132                 params->tx_max_action_entry_sz_in_bits =
133                         BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
134                 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
135                 params->tx_num_flows_in_k = BNXT_ULP_TX_NUM_FLOWS;
136                 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
137         } else {
138                 params->rx_max_key_sz_in_bits = BNXT_ULP_DFLT_RX_MAX_KEY;
139                 params->rx_max_action_entry_sz_in_bits =
140                         BNXT_ULP_DFLT_RX_MAX_ACTN_ENTRY;
141                 params->rx_mem_size_in_mb = BNXT_ULP_DFLT_RX_MEM;
142                 params->rx_num_flows_in_k = dparms->num_flows / (1024);
143                 params->rx_tbl_if_id = BNXT_ULP_RX_TBL_IF_ID;
144
145                 params->tx_max_key_sz_in_bits = BNXT_ULP_DFLT_TX_MAX_KEY;
146                 params->tx_max_action_entry_sz_in_bits =
147                         BNXT_ULP_DFLT_TX_MAX_ACTN_ENTRY;
148                 params->tx_mem_size_in_mb = BNXT_ULP_DFLT_TX_MEM;
149                 params->tx_num_flows_in_k = dparms->num_flows / (1024);
150                 params->tx_tbl_if_id = BNXT_ULP_TX_TBL_IF_ID;
151         }
152 }
153
154 /* Initialize Extended Exact Match host memory. */
155 static int32_t
156 ulp_eem_tbl_scope_init(struct bnxt *bp)
157 {
158         struct tf_alloc_tbl_scope_parms params = {0};
159         int rc;
160
161         bnxt_init_tbl_scope_parms(bp, &params);
162
163         rc = tf_alloc_tbl_scope(&bp->tfp, &params);
164         if (rc) {
165                 BNXT_TF_DBG(ERR, "Unable to allocate eem table scope rc = %d\n",
166                             rc);
167                 return rc;
168         }
169
170         rc = bnxt_ulp_cntxt_tbl_scope_id_set(&bp->ulp_ctx, params.tbl_scope_id);
171         if (rc) {
172                 BNXT_TF_DBG(ERR, "Unable to set table scope id\n");
173                 return rc;
174         }
175
176         return 0;
177 }
178
179 /* Free Extended Exact Match host memory */
180 static int32_t
181 ulp_eem_tbl_scope_deinit(struct bnxt *bp, struct bnxt_ulp_context *ulp_ctx)
182 {
183         struct tf_free_tbl_scope_parms  params = {0};
184         struct tf                       *tfp;
185         int32_t                         rc = 0;
186
187         if (!ulp_ctx || !ulp_ctx->cfg_data)
188                 return -EINVAL;
189
190         /* Free the resources for the last device */
191         if (!ulp_ctx_deinit_allowed(bp))
192                 return rc;
193
194         tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
195         if (!tfp) {
196                 BNXT_TF_DBG(ERR, "Failed to get the truflow pointer\n");
197                 return -EINVAL;
198         }
199
200         rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &params.tbl_scope_id);
201         if (rc) {
202                 BNXT_TF_DBG(ERR, "Failed to get the table scope id\n");
203                 return -EINVAL;
204         }
205
206         rc = tf_free_tbl_scope(tfp, &params);
207         if (rc) {
208                 BNXT_TF_DBG(ERR, "Unable to free table scope\n");
209                 return -EINVAL;
210         }
211         return rc;
212 }
213
214 /* The function to free and deinit the ulp context data. */
215 static int32_t
216 ulp_ctx_deinit(struct bnxt *bp,
217                struct bnxt_ulp_session_state *session)
218 {
219         if (!session || !bp) {
220                 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
221                 return -EINVAL;
222         }
223
224         /* close the tf session */
225         ulp_ctx_session_close(bp, session);
226
227         /* Free the contents */
228         if (session->cfg_data) {
229                 rte_free(session->cfg_data);
230                 bp->ulp_ctx.cfg_data = NULL;
231                 session->cfg_data = NULL;
232         }
233         return 0;
234 }
235
236 /* The function to allocate and initialize the ulp context data. */
237 static int32_t
238 ulp_ctx_init(struct bnxt *bp,
239              struct bnxt_ulp_session_state *session)
240 {
241         struct bnxt_ulp_data    *ulp_data;
242         int32_t                 rc = 0;
243
244         if (!session || !bp) {
245                 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
246                 return -EINVAL;
247         }
248
249         /* Allocate memory to hold ulp context data. */
250         ulp_data = rte_zmalloc("bnxt_ulp_data",
251                                sizeof(struct bnxt_ulp_data), 0);
252         if (!ulp_data) {
253                 BNXT_TF_DBG(ERR, "Failed to allocate memory for ulp data\n");
254                 return -ENOMEM;
255         }
256
257         /* Increment the ulp context data reference count usage. */
258         bp->ulp_ctx.cfg_data = ulp_data;
259         session->cfg_data = ulp_data;
260         ulp_data->ref_cnt++;
261
262         /* Open the ulp session. */
263         rc = ulp_ctx_session_open(bp, session);
264         if (rc) {
265                 (void)ulp_ctx_deinit(bp, session);
266                 return rc;
267         }
268         bnxt_ulp_cntxt_tfp_set(&bp->ulp_ctx, session->g_tfp);
269         return rc;
270 }
271
272 static int32_t
273 ulp_ctx_attach(struct bnxt_ulp_context *ulp_ctx,
274                struct bnxt_ulp_session_state *session)
275 {
276         if (!ulp_ctx || !session) {
277                 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
278                 return -EINVAL;
279         }
280
281         /* Increment the ulp context data reference count usage. */
282         ulp_ctx->cfg_data = session->cfg_data;
283         ulp_ctx->cfg_data->ref_cnt++;
284
285         /* TBD call TF_session_attach. */
286         ulp_ctx->g_tfp = session->g_tfp;
287         return 0;
288 }
289
290 static int32_t
291 ulp_ctx_detach(struct bnxt *bp,
292                struct bnxt_ulp_session_state *session)
293 {
294         struct bnxt_ulp_context *ulp_ctx;
295
296         if (!bp || !session) {
297                 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
298                 return -EINVAL;
299         }
300         ulp_ctx = &bp->ulp_ctx;
301
302         if (!ulp_ctx->cfg_data)
303                 return 0;
304
305         /* TBD call TF_session_detach */
306
307         /* Increment the ulp context data reference count usage. */
308         if (ulp_ctx->cfg_data->ref_cnt >= 1) {
309                 ulp_ctx->cfg_data->ref_cnt--;
310                 if (ulp_ctx_deinit_allowed(bp))
311                         ulp_ctx_deinit(bp, session);
312                 ulp_ctx->cfg_data = NULL;
313                 ulp_ctx->g_tfp = NULL;
314                 return 0;
315         }
316         BNXT_TF_DBG(ERR, "context deatach on invalid data\n");
317         return 0;
318 }
319
320 /*
321  * Initialize the state of an ULP session.
322  * If the state of an ULP session is not initialized, set it's state to
323  * initialized. If the state is already initialized, do nothing.
324  */
325 static void
326 ulp_context_initialized(struct bnxt_ulp_session_state *session, bool *init)
327 {
328         pthread_mutex_lock(&session->bnxt_ulp_mutex);
329
330         if (!session->bnxt_ulp_init) {
331                 session->bnxt_ulp_init = true;
332                 *init = false;
333         } else {
334                 *init = true;
335         }
336
337         pthread_mutex_unlock(&session->bnxt_ulp_mutex);
338 }
339
340 /*
341  * Check if an ULP session is already allocated for a specific PCI
342  * domain & bus. If it is already allocated simply return the session
343  * pointer, otherwise allocate a new session.
344  */
345 static struct bnxt_ulp_session_state *
346 ulp_get_session(struct rte_pci_addr *pci_addr)
347 {
348         struct bnxt_ulp_session_state *session;
349
350         STAILQ_FOREACH(session, &bnxt_ulp_session_list, next) {
351                 if (session->pci_info.domain == pci_addr->domain &&
352                     session->pci_info.bus == pci_addr->bus) {
353                         return session;
354                 }
355         }
356         return NULL;
357 }
358
359 /*
360  * Allocate and Initialize an ULP session and set it's state to INITIALIZED.
361  * If it's already initialized simply return the already existing session.
362  */
363 static struct bnxt_ulp_session_state *
364 ulp_session_init(struct bnxt *bp,
365                  bool *init)
366 {
367         struct rte_pci_device           *pci_dev;
368         struct rte_pci_addr             *pci_addr;
369         struct bnxt_ulp_session_state   *session;
370
371         if (!bp)
372                 return NULL;
373
374         pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
375         pci_addr = &pci_dev->addr;
376
377         pthread_mutex_lock(&bnxt_ulp_global_mutex);
378
379         session = ulp_get_session(pci_addr);
380         if (!session) {
381                 /* Not Found the session  Allocate a new one */
382                 session = rte_zmalloc("bnxt_ulp_session",
383                                       sizeof(struct bnxt_ulp_session_state),
384                                       0);
385                 if (!session) {
386                         BNXT_TF_DBG(ERR,
387                                     "Allocation failed for bnxt_ulp_session\n");
388                         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
389                         return NULL;
390
391                 } else {
392                         /* Add it to the queue */
393                         session->pci_info.domain = pci_addr->domain;
394                         session->pci_info.bus = pci_addr->bus;
395                         pthread_mutex_init(&session->bnxt_ulp_mutex, NULL);
396                         STAILQ_INSERT_TAIL(&bnxt_ulp_session_list,
397                                            session, next);
398                 }
399         }
400         ulp_context_initialized(session, init);
401         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
402         return session;
403 }
404
405 /*
406  * When a device is closed, remove it's associated session from the global
407  * session list.
408  */
409 static void
410 ulp_session_deinit(struct bnxt_ulp_session_state *session)
411 {
412         if (!session)
413                 return;
414
415         if (!session->cfg_data) {
416                 pthread_mutex_lock(&bnxt_ulp_global_mutex);
417                 STAILQ_REMOVE(&bnxt_ulp_session_list, session,
418                               bnxt_ulp_session_state, next);
419                 pthread_mutex_destroy(&session->bnxt_ulp_mutex);
420                 rte_free(session);
421                 pthread_mutex_unlock(&bnxt_ulp_global_mutex);
422         }
423 }
424
425 /*
426  * When a port is initialized by dpdk. This functions is called
427  * and this function initializes the ULP context and rest of the
428  * infrastructure associated with it.
429  */
430 int32_t
431 bnxt_ulp_init(struct bnxt *bp)
432 {
433         struct bnxt_ulp_session_state *session;
434         bool init;
435         int rc;
436
437         /*
438          * Multiple uplink ports can be associated with a single vswitch.
439          * Make sure only the port that is started first will initialize
440          * the TF session.
441          */
442         session = ulp_session_init(bp, &init);
443         if (!session) {
444                 BNXT_TF_DBG(ERR, "Failed to initialize the tf session\n");
445                 return -EINVAL;
446         }
447
448         /*
449          * If ULP is already initialized for a specific domain then simply
450          * assign the ulp context to this rte_eth_dev.
451          */
452         if (init) {
453                 rc = ulp_ctx_attach(&bp->ulp_ctx, session);
454                 if (rc) {
455                         BNXT_TF_DBG(ERR,
456                                     "Failed to attach the ulp context\n");
457                 }
458                 return rc;
459         }
460
461         /* Allocate and Initialize the ulp context. */
462         rc = ulp_ctx_init(bp, session);
463         if (rc) {
464                 BNXT_TF_DBG(ERR, "Failed to create the ulp context\n");
465                 goto jump_to_error;
466         }
467
468         /* Create the Mark database. */
469         rc = ulp_mark_db_init(&bp->ulp_ctx);
470         if (rc) {
471                 BNXT_TF_DBG(ERR, "Failed to create the mark database\n");
472                 goto jump_to_error;
473         }
474
475         /* Create the flow database. */
476         rc = ulp_flow_db_init(&bp->ulp_ctx);
477         if (rc) {
478                 BNXT_TF_DBG(ERR, "Failed to create the flow database\n");
479                 goto jump_to_error;
480         }
481
482         /* Create the eem table scope. */
483         rc = ulp_eem_tbl_scope_init(bp);
484         if (rc) {
485                 BNXT_TF_DBG(ERR, "Failed to create the eem scope table\n");
486                 goto jump_to_error;
487         }
488
489         rc = ulp_mapper_init(&bp->ulp_ctx);
490         if (rc) {
491                 BNXT_TF_DBG(ERR, "Failed to initialize ulp mapper\n");
492                 goto jump_to_error;
493         }
494
495         return rc;
496
497 jump_to_error:
498         bnxt_ulp_deinit(bp);
499         return -ENOMEM;
500 }
501
502 /* Below are the access functions to access internal data of ulp context. */
503
504 /*
505  * When a port is deinit'ed by dpdk. This function is called
506  * and this function clears the ULP context and rest of the
507  * infrastructure associated with it.
508  */
509 void
510 bnxt_ulp_deinit(struct bnxt *bp)
511 {
512         struct bnxt_ulp_session_state   *session;
513         struct rte_pci_device           *pci_dev;
514         struct rte_pci_addr             *pci_addr;
515
516         /* Get the session first */
517         pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
518         pci_addr = &pci_dev->addr;
519         pthread_mutex_lock(&bnxt_ulp_global_mutex);
520         session = ulp_get_session(pci_addr);
521         pthread_mutex_unlock(&bnxt_ulp_global_mutex);
522
523         /* session not found then just exit */
524         if (!session)
525                 return;
526
527         /* clean up regular flows */
528         ulp_flow_db_flush_flows(&bp->ulp_ctx, BNXT_ULP_REGULAR_FLOW_TABLE);
529
530         /* cleanup the eem table scope */
531         ulp_eem_tbl_scope_deinit(bp, &bp->ulp_ctx);
532
533         /* cleanup the flow database */
534         ulp_flow_db_deinit(&bp->ulp_ctx);
535
536         /* Delete the Mark database */
537         ulp_mark_db_deinit(&bp->ulp_ctx);
538
539         /* cleanup the ulp mapper */
540         ulp_mapper_deinit(&bp->ulp_ctx);
541
542         /* Delete the ulp context and tf session */
543         ulp_ctx_detach(bp, session);
544
545         /* Finally delete the bnxt session*/
546         ulp_session_deinit(session);
547 }
548
549 /* Function to set the Mark DB into the context */
550 int32_t
551 bnxt_ulp_cntxt_ptr2_mark_db_set(struct bnxt_ulp_context *ulp_ctx,
552                                 struct bnxt_ulp_mark_tbl *mark_tbl)
553 {
554         if (!ulp_ctx || !ulp_ctx->cfg_data) {
555                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
556                 return -EINVAL;
557         }
558
559         ulp_ctx->cfg_data->mark_tbl = mark_tbl;
560
561         return 0;
562 }
563
564 /* Function to retrieve the Mark DB from the context. */
565 struct bnxt_ulp_mark_tbl *
566 bnxt_ulp_cntxt_ptr2_mark_db_get(struct bnxt_ulp_context *ulp_ctx)
567 {
568         if (!ulp_ctx || !ulp_ctx->cfg_data)
569                 return NULL;
570
571         return ulp_ctx->cfg_data->mark_tbl;
572 }
573
574 /* Function to set the device id of the hardware. */
575 int32_t
576 bnxt_ulp_cntxt_dev_id_set(struct bnxt_ulp_context *ulp_ctx,
577                           uint32_t dev_id)
578 {
579         if (ulp_ctx && ulp_ctx->cfg_data) {
580                 ulp_ctx->cfg_data->dev_id = dev_id;
581                 return 0;
582         }
583
584         return -EINVAL;
585 }
586
587 /* Function to get the device id of the hardware. */
588 int32_t
589 bnxt_ulp_cntxt_dev_id_get(struct bnxt_ulp_context *ulp_ctx,
590                           uint32_t *dev_id)
591 {
592         if (ulp_ctx && ulp_ctx->cfg_data) {
593                 *dev_id = ulp_ctx->cfg_data->dev_id;
594                 return 0;
595         }
596
597         return -EINVAL;
598 }
599
600 /* Function to get the table scope id of the EEM table. */
601 int32_t
602 bnxt_ulp_cntxt_tbl_scope_id_get(struct bnxt_ulp_context *ulp_ctx,
603                                 uint32_t *tbl_scope_id)
604 {
605         if (ulp_ctx && ulp_ctx->cfg_data) {
606                 *tbl_scope_id = ulp_ctx->cfg_data->tbl_scope_id;
607                 return 0;
608         }
609
610         return -EINVAL;
611 }
612
613 /* Function to set the table scope id of the EEM table. */
614 int32_t
615 bnxt_ulp_cntxt_tbl_scope_id_set(struct bnxt_ulp_context *ulp_ctx,
616                                 uint32_t tbl_scope_id)
617 {
618         if (ulp_ctx && ulp_ctx->cfg_data) {
619                 ulp_ctx->cfg_data->tbl_scope_id = tbl_scope_id;
620                 return 0;
621         }
622
623         return -EINVAL;
624 }
625
626 /* Function to set the tfp session details from the ulp context. */
627 int32_t
628 bnxt_ulp_cntxt_tfp_set(struct bnxt_ulp_context *ulp, struct tf *tfp)
629 {
630         if (!ulp) {
631                 BNXT_TF_DBG(ERR, "Invalid arguments\n");
632                 return -EINVAL;
633         }
634
635         /* TBD The tfp should be removed once tf_attach is implemented. */
636         ulp->g_tfp = tfp;
637         return 0;
638 }
639
640 /* Function to get the tfp session details from the ulp context. */
641 struct tf *
642 bnxt_ulp_cntxt_tfp_get(struct bnxt_ulp_context *ulp)
643 {
644         if (!ulp) {
645                 BNXT_TF_DBG(ERR, "Invalid arguments\n");
646                 return NULL;
647         }
648         /* TBD The tfp should be removed once tf_attach is implemented. */
649         return ulp->g_tfp;
650 }
651
652 /*
653  * Get the device table entry based on the device id.
654  *
655  * dev_id [in] The device id of the hardware
656  *
657  * Returns the pointer to the device parameters.
658  */
659 struct bnxt_ulp_device_params *
660 bnxt_ulp_device_params_get(uint32_t dev_id)
661 {
662         if (dev_id < BNXT_ULP_MAX_NUM_DEVICES)
663                 return &ulp_device_params[dev_id];
664         return NULL;
665 }
666
667 /* Function to set the flow database to the ulp context. */
668 int32_t
669 bnxt_ulp_cntxt_ptr2_flow_db_set(struct bnxt_ulp_context *ulp_ctx,
670                                 struct bnxt_ulp_flow_db *flow_db)
671 {
672         if (!ulp_ctx || !ulp_ctx->cfg_data)
673                 return -EINVAL;
674
675         ulp_ctx->cfg_data->flow_db = flow_db;
676         return 0;
677 }
678
679 /* Function to get the flow database from the ulp context. */
680 struct bnxt_ulp_flow_db *
681 bnxt_ulp_cntxt_ptr2_flow_db_get(struct bnxt_ulp_context *ulp_ctx)
682 {
683         if (!ulp_ctx || !ulp_ctx->cfg_data)
684                 return NULL;
685
686         return ulp_ctx->cfg_data->flow_db;
687 }
688
689 /* Function to get the ulp context from eth device. */
690 struct bnxt_ulp_context *
691 bnxt_ulp_eth_dev_ptr2_cntxt_get(struct rte_eth_dev      *dev)
692 {
693         struct bnxt     *bp;
694
695         bp = (struct bnxt *)dev->data->dev_private;
696         if (!bp) {
697                 BNXT_TF_DBG(ERR, "Bnxt private data is not initialized\n");
698                 return NULL;
699         }
700         return &bp->ulp_ctx;
701 }
702
703 int32_t
704 bnxt_ulp_cntxt_ptr2_mapper_data_set(struct bnxt_ulp_context *ulp_ctx,
705                                     void *mapper_data)
706 {
707         if (!ulp_ctx || !ulp_ctx->cfg_data) {
708                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
709                 return -EINVAL;
710         }
711
712         ulp_ctx->cfg_data->mapper_data = mapper_data;
713         return 0;
714 }
715
716 void *
717 bnxt_ulp_cntxt_ptr2_mapper_data_get(struct bnxt_ulp_context *ulp_ctx)
718 {
719         if (!ulp_ctx || !ulp_ctx->cfg_data) {
720                 BNXT_TF_DBG(ERR, "Invalid ulp context data\n");
721                 return NULL;
722         }
723
724         return ulp_ctx->cfg_data->mapper_data;
725 }