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