97e6165e92fe6e39bf9354200a9f79b155c8cc2a
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #include <stdio.h>
7
8 #include "tf_core.h"
9 #include "tf_util.h"
10 #include "tf_session.h"
11 #include "tf_tbl.h"
12 #include "tf_em.h"
13 #include "tf_rm.h"
14 #include "tf_global_cfg.h"
15 #include "tf_msg.h"
16 #include "tfp.h"
17 #include "bitalloc.h"
18 #include "bnxt.h"
19 #include "rand.h"
20 #include "tf_common.h"
21 #include "tf_ext_flow_handle.h"
22
23 int
24 tf_open_session(struct tf *tfp,
25                 struct tf_open_session_parms *parms)
26 {
27         int rc;
28         unsigned int domain, bus, slot, device;
29         struct tf_session_open_session_parms oparms;
30
31         TF_CHECK_PARMS2(tfp, parms);
32
33         /* Filter out any non-supported device types on the Core
34          * side. It is assumed that the Firmware will be supported if
35          * firmware open session succeeds.
36          */
37         if (parms->device_type != TF_DEVICE_TYPE_WH &&
38             parms->device_type != TF_DEVICE_TYPE_THOR &&
39             parms->device_type != TF_DEVICE_TYPE_SR) {
40                 TFP_DRV_LOG(ERR,
41                             "Unsupported device type %d\n",
42                             parms->device_type);
43                 return -ENOTSUP;
44         }
45
46         /* Verify control channel and build the beginning of session_id */
47         rc = sscanf(parms->ctrl_chan_name,
48                     "%x:%x:%x.%u",
49                     &domain,
50                     &bus,
51                     &slot,
52                     &device);
53         if (rc != 4) {
54                 /* PCI Domain not provided (optional in DPDK), thus we
55                  * force domain to 0 and recheck.
56                  */
57                 domain = 0;
58
59                 /* Check parsing of bus/slot/device */
60                 rc = sscanf(parms->ctrl_chan_name,
61                             "%x:%x.%u",
62                             &bus,
63                             &slot,
64                             &device);
65                 if (rc != 3) {
66                         TFP_DRV_LOG(ERR,
67                             "Failed to scan device ctrl_chan_name\n");
68                         return -EINVAL;
69                 }
70         }
71
72         parms->session_id.internal.domain = domain;
73         parms->session_id.internal.bus = bus;
74         parms->session_id.internal.device = device;
75         oparms.open_cfg = parms;
76
77         /* Session vs session client is decided in
78          * tf_session_open_session()
79          */
80         rc = tf_session_open_session(tfp, &oparms);
81         /* Logging handled by tf_session_open_session */
82         if (rc)
83                 return rc;
84
85         TFP_DRV_LOG(INFO,
86                     "domain:%d, bus:%d, device:%u\n",
87                     parms->session_id.internal.domain,
88                     parms->session_id.internal.bus,
89                     parms->session_id.internal.device);
90
91         return 0;
92 }
93
94 int
95 tf_attach_session(struct tf *tfp,
96                   struct tf_attach_session_parms *parms)
97 {
98         int rc;
99         unsigned int domain, bus, slot, device;
100         struct tf_session_attach_session_parms aparms;
101
102         TF_CHECK_PARMS2(tfp, parms);
103
104         /* Verify control channel */
105         rc = sscanf(parms->ctrl_chan_name,
106                     "%x:%x:%x.%u",
107                     &domain,
108                     &bus,
109                     &slot,
110                     &device);
111         if (rc != 4) {
112                 TFP_DRV_LOG(ERR,
113                             "Failed to scan device ctrl_chan_name\n");
114                 return -EINVAL;
115         }
116
117         /* Verify 'attach' channel */
118         rc = sscanf(parms->attach_chan_name,
119                     "%x:%x:%x.%u",
120                     &domain,
121                     &bus,
122                     &slot,
123                     &device);
124         if (rc != 4) {
125                 TFP_DRV_LOG(ERR,
126                             "Failed to scan device attach_chan_name\n");
127                 return -EINVAL;
128         }
129
130         /* Prepare return value of session_id, using ctrl_chan_name
131          * device values as it becomes the session id.
132          */
133         parms->session_id.internal.domain = domain;
134         parms->session_id.internal.bus = bus;
135         parms->session_id.internal.device = device;
136         aparms.attach_cfg = parms;
137         rc = tf_session_attach_session(tfp,
138                                        &aparms);
139         /* Logging handled by dev_bind */
140         if (rc)
141                 return rc;
142
143         TFP_DRV_LOG(INFO,
144                     "Attached to session, session_id:%d\n",
145                     parms->session_id.id);
146
147         TFP_DRV_LOG(INFO,
148                     "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
149                     parms->session_id.internal.domain,
150                     parms->session_id.internal.bus,
151                     parms->session_id.internal.device,
152                     parms->session_id.internal.fw_session_id);
153
154         return rc;
155 }
156
157 int
158 tf_close_session(struct tf *tfp)
159 {
160         int rc;
161         struct tf_session_close_session_parms cparms = { 0 };
162         union tf_session_id session_id = { 0 };
163         uint8_t ref_count;
164
165         TF_CHECK_PARMS1(tfp);
166
167         cparms.ref_count = &ref_count;
168         cparms.session_id = &session_id;
169         /* Session vs session client is decided in
170          * tf_session_close_session()
171          */
172         rc = tf_session_close_session(tfp,
173                                       &cparms);
174         /* Logging handled by tf_session_close_session */
175         if (rc)
176                 return rc;
177
178         TFP_DRV_LOG(INFO,
179                     "domain:%d, bus:%d, device:%d\n",
180                     cparms.session_id->internal.domain,
181                     cparms.session_id->internal.bus,
182                     cparms.session_id->internal.device);
183
184         return rc;
185 }
186
187 /** insert EM hash entry API
188  *
189  *    returns:
190  *    0       - Success
191  *    -EINVAL - Error
192  */
193 int tf_insert_em_entry(struct tf *tfp,
194                        struct tf_insert_em_entry_parms *parms)
195 {
196         struct tf_session      *tfs;
197         struct tf_dev_info     *dev;
198         int rc;
199
200         TF_CHECK_PARMS2(tfp, parms);
201
202         /* Retrieve the session information */
203         rc = tf_session_get_session(tfp, &tfs);
204         if (rc) {
205                 TFP_DRV_LOG(ERR,
206                             "%s: Failed to lookup session, rc:%s\n",
207                             tf_dir_2_str(parms->dir),
208                             strerror(-rc));
209                 return rc;
210         }
211
212         /* Retrieve the device information */
213         rc = tf_session_get_device(tfs, &dev);
214         if (rc) {
215                 TFP_DRV_LOG(ERR,
216                             "%s: Failed to lookup device, rc:%s\n",
217                             tf_dir_2_str(parms->dir),
218                             strerror(-rc));
219                 return rc;
220         }
221
222         if (parms->mem == TF_MEM_EXTERNAL &&
223                 dev->ops->tf_dev_insert_ext_em_entry != NULL)
224                 rc = dev->ops->tf_dev_insert_ext_em_entry(tfp, parms);
225         else if (parms->mem == TF_MEM_INTERNAL &&
226                 dev->ops->tf_dev_insert_int_em_entry != NULL)
227                 rc = dev->ops->tf_dev_insert_int_em_entry(tfp, parms);
228         else
229                 return -EINVAL;
230
231         if (rc) {
232                 TFP_DRV_LOG(ERR,
233                             "%s: EM insert failed, rc:%s\n",
234                             tf_dir_2_str(parms->dir),
235                             strerror(-rc));
236                 return rc;
237         }
238
239         return 0;
240 }
241
242 /** Delete EM hash entry API
243  *
244  *    returns:
245  *    0       - Success
246  *    -EINVAL - Error
247  */
248 int tf_delete_em_entry(struct tf *tfp,
249                        struct tf_delete_em_entry_parms *parms)
250 {
251         struct tf_session      *tfs;
252         struct tf_dev_info     *dev;
253         int rc;
254         unsigned int flag = 0;
255
256         TF_CHECK_PARMS2(tfp, parms);
257
258         /* Retrieve the session information */
259         rc = tf_session_get_session(tfp, &tfs);
260         if (rc) {
261                 TFP_DRV_LOG(ERR,
262                             "%s: Failed to lookup session, rc:%s\n",
263                             tf_dir_2_str(parms->dir),
264                             strerror(-rc));
265                 return rc;
266         }
267
268         /* Retrieve the device information */
269         rc = tf_session_get_device(tfs, &dev);
270         if (rc) {
271                 TFP_DRV_LOG(ERR,
272                             "%s: Failed to lookup device, rc:%s\n",
273                             tf_dir_2_str(parms->dir),
274                             strerror(-rc));
275                 return rc;
276         }
277
278         TF_GET_FLAG_FROM_FLOW_HANDLE(parms->flow_handle, flag);
279         if ((flag & TF_FLAGS_FLOW_HANDLE_INTERNAL))
280                 rc = dev->ops->tf_dev_delete_int_em_entry(tfp, parms);
281         else
282                 rc = dev->ops->tf_dev_delete_ext_em_entry(tfp, parms);
283
284         if (rc) {
285                 TFP_DRV_LOG(ERR,
286                             "%s: EM delete failed, rc:%s\n",
287                             tf_dir_2_str(parms->dir),
288                             strerror(-rc));
289                 return rc;
290         }
291
292         return rc;
293 }
294
295 /** Get global configuration API
296  *
297  *    returns:
298  *    0       - Success
299  *    -EINVAL - Error
300  */
301 int tf_get_global_cfg(struct tf *tfp,
302                       struct tf_global_cfg_parms *parms)
303 {
304         int rc = 0;
305         struct tf_session *tfs;
306         struct tf_dev_info *dev;
307
308         TF_CHECK_PARMS2(tfp, parms);
309
310         /* Retrieve the session information */
311         rc = tf_session_get_session(tfp, &tfs);
312         if (rc) {
313                 TFP_DRV_LOG(ERR,
314                             "%s: Failed to lookup session, rc:%s\n",
315                             tf_dir_2_str(parms->dir),
316                             strerror(-rc));
317                 return rc;
318         }
319
320         /* Retrieve the device information */
321         rc = tf_session_get_device(tfs, &dev);
322         if (rc) {
323                 TFP_DRV_LOG(ERR,
324                             "%s: Failed to lookup device, rc:%s\n",
325                             tf_dir_2_str(parms->dir),
326                             strerror(-rc));
327                 return rc;
328         }
329
330         if (parms->config == NULL ||
331            parms->config_sz_in_bytes == 0) {
332                 TFP_DRV_LOG(ERR, "Invalid Argument(s)\n");
333                 return -EINVAL;
334         }
335
336         if (dev->ops->tf_dev_get_global_cfg == NULL) {
337                 rc = -EOPNOTSUPP;
338                 TFP_DRV_LOG(ERR,
339                             "%s: Operation not supported, rc:%s\n",
340                             tf_dir_2_str(parms->dir),
341                             strerror(-rc));
342                 return -EOPNOTSUPP;
343         }
344
345         rc = dev->ops->tf_dev_get_global_cfg(tfp, parms);
346         if (rc) {
347                 TFP_DRV_LOG(ERR,
348                             "%s: Global Cfg get failed, rc:%s\n",
349                             tf_dir_2_str(parms->dir),
350                             strerror(-rc));
351                 return rc;
352         }
353
354         return rc;
355 }
356
357 /** Set global configuration API
358  *
359  *    returns:
360  *    0       - Success
361  *    -EINVAL - Error
362  */
363 int tf_set_global_cfg(struct tf *tfp,
364                       struct tf_global_cfg_parms *parms)
365 {
366         int rc = 0;
367         struct tf_session *tfs;
368         struct tf_dev_info *dev;
369
370         TF_CHECK_PARMS2(tfp, parms);
371
372         /* Retrieve the session information */
373         rc = tf_session_get_session(tfp, &tfs);
374         if (rc) {
375                 TFP_DRV_LOG(ERR,
376                             "%s: Failed to lookup session, rc:%s\n",
377                             tf_dir_2_str(parms->dir),
378                             strerror(-rc));
379                 return rc;
380         }
381
382         /* Retrieve the device information */
383         rc = tf_session_get_device(tfs, &dev);
384         if (rc) {
385                 TFP_DRV_LOG(ERR,
386                             "%s: Failed to lookup device, rc:%s\n",
387                             tf_dir_2_str(parms->dir),
388                             strerror(-rc));
389                 return rc;
390         }
391
392         if (parms->config == NULL ||
393            parms->config_sz_in_bytes == 0) {
394                 TFP_DRV_LOG(ERR, "Invalid Argument(s)\n");
395                 return -EINVAL;
396         }
397
398         if (dev->ops->tf_dev_set_global_cfg == NULL) {
399                 rc = -EOPNOTSUPP;
400                 TFP_DRV_LOG(ERR,
401                             "%s: Operation not supported, rc:%s\n",
402                             tf_dir_2_str(parms->dir),
403                             strerror(-rc));
404                 return -EOPNOTSUPP;
405         }
406
407         rc = dev->ops->tf_dev_set_global_cfg(tfp, parms);
408         if (rc) {
409                 TFP_DRV_LOG(ERR,
410                             "%s: Global Cfg set failed, rc:%s\n",
411                             tf_dir_2_str(parms->dir),
412                             strerror(-rc));
413                 return rc;
414         }
415
416         return rc;
417 }
418
419 int
420 tf_alloc_identifier(struct tf *tfp,
421                     struct tf_alloc_identifier_parms *parms)
422 {
423         int rc;
424         struct tf_session *tfs;
425         struct tf_dev_info *dev;
426         struct tf_ident_alloc_parms aparms;
427         uint16_t id;
428
429         TF_CHECK_PARMS2(tfp, parms);
430
431         /* Can't do static initialization due to UT enum check */
432         memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
433
434         /* Retrieve the session information */
435         rc = tf_session_get_session(tfp, &tfs);
436         if (rc) {
437                 TFP_DRV_LOG(ERR,
438                             "%s: Failed to lookup session, rc:%s\n",
439                             tf_dir_2_str(parms->dir),
440                             strerror(-rc));
441                 return rc;
442         }
443
444         /* Retrieve the device information */
445         rc = tf_session_get_device(tfs, &dev);
446         if (rc) {
447                 TFP_DRV_LOG(ERR,
448                             "%s: Failed to lookup device, rc:%s\n",
449                             tf_dir_2_str(parms->dir),
450                             strerror(-rc));
451                 return rc;
452         }
453
454         if (dev->ops->tf_dev_alloc_ident == NULL) {
455                 rc = -EOPNOTSUPP;
456                 TFP_DRV_LOG(ERR,
457                             "%s: Operation not supported, rc:%s\n",
458                             tf_dir_2_str(parms->dir),
459                             strerror(-rc));
460                 return -EOPNOTSUPP;
461         }
462
463         aparms.dir = parms->dir;
464         aparms.type = parms->ident_type;
465         aparms.id = &id;
466         rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
467         if (rc) {
468                 TFP_DRV_LOG(ERR,
469                             "%s: Identifier allocation failed, rc:%s\n",
470                             tf_dir_2_str(parms->dir),
471                             strerror(-rc));
472                 return rc;
473         }
474
475         parms->id = id;
476
477         return 0;
478 }
479
480 int
481 tf_free_identifier(struct tf *tfp,
482                    struct tf_free_identifier_parms *parms)
483 {
484         int rc;
485         struct tf_session *tfs;
486         struct tf_dev_info *dev;
487         struct tf_ident_free_parms fparms;
488
489         TF_CHECK_PARMS2(tfp, parms);
490
491         /* Can't do static initialization due to UT enum check */
492         memset(&fparms, 0, sizeof(struct tf_ident_free_parms));
493
494         /* Retrieve the session information */
495         rc = tf_session_get_session(tfp, &tfs);
496         if (rc) {
497                 TFP_DRV_LOG(ERR,
498                             "%s: Failed to lookup session, rc:%s\n",
499                             tf_dir_2_str(parms->dir),
500                             strerror(-rc));
501                 return rc;
502         }
503
504         /* Retrieve the device information */
505         rc = tf_session_get_device(tfs, &dev);
506         if (rc) {
507                 TFP_DRV_LOG(ERR,
508                             "%s: Failed to lookup device, rc:%s\n",
509                             tf_dir_2_str(parms->dir),
510                             strerror(-rc));
511                 return rc;
512         }
513
514         if (dev->ops->tf_dev_free_ident == NULL) {
515                 rc = -EOPNOTSUPP;
516                 TFP_DRV_LOG(ERR,
517                             "%s: Operation not supported, rc:%s\n",
518                             tf_dir_2_str(parms->dir),
519                             strerror(-rc));
520                 return -EOPNOTSUPP;
521         }
522
523         fparms.dir = parms->dir;
524         fparms.type = parms->ident_type;
525         fparms.id = parms->id;
526         fparms.ref_cnt = &parms->ref_cnt;
527         rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
528         if (rc) {
529                 TFP_DRV_LOG(ERR,
530                             "%s: Identifier free failed, rc:%s\n",
531                             tf_dir_2_str(parms->dir),
532                             strerror(-rc));
533                 return rc;
534         }
535
536         return 0;
537 }
538
539 int
540 tf_search_identifier(struct tf *tfp,
541                      struct tf_search_identifier_parms *parms)
542 {
543         int rc;
544         struct tf_session *tfs;
545         struct tf_dev_info *dev;
546         struct tf_ident_search_parms sparms;
547
548         TF_CHECK_PARMS2(tfp, parms);
549
550         /* Can't do static initialization due to UT enum check */
551         memset(&sparms, 0, sizeof(struct tf_ident_search_parms));
552
553         /* Retrieve the session information */
554         rc = tf_session_get_session(tfp, &tfs);
555         if (rc) {
556                 TFP_DRV_LOG(ERR,
557                             "%s: Failed to lookup session, rc:%s\n",
558                             tf_dir_2_str(parms->dir),
559                             strerror(-rc));
560                 return rc;
561         }
562
563         /* Retrieve the device information */
564         rc = tf_session_get_device(tfs, &dev);
565         if (rc) {
566                 TFP_DRV_LOG(ERR,
567                             "%s: Failed to lookup device, rc:%s\n",
568                             tf_dir_2_str(parms->dir),
569                             strerror(-rc));
570                 return rc;
571         }
572
573         if (dev->ops->tf_dev_search_ident == NULL) {
574                 rc = -EOPNOTSUPP;
575                 TFP_DRV_LOG(ERR,
576                             "%s: Operation not supported, rc:%s\n",
577                             tf_dir_2_str(parms->dir),
578                             strerror(-rc));
579                 return rc;
580         }
581
582         sparms.dir = parms->dir;
583         sparms.type = parms->ident_type;
584         sparms.search_id = parms->search_id;
585         sparms.hit = &parms->hit;
586         sparms.ref_cnt = &parms->ref_cnt;
587         rc = dev->ops->tf_dev_search_ident(tfp, &sparms);
588         if (rc) {
589                 TFP_DRV_LOG(ERR,
590                             "%s: Identifier search failed, rc:%s\n",
591                             tf_dir_2_str(parms->dir),
592                             strerror(-rc));
593                 return rc;
594         }
595
596         return 0;
597 }
598
599 int
600 tf_search_tcam_entry(struct tf *tfp,
601                      struct tf_search_tcam_entry_parms *parms)
602 {
603         int rc;
604         struct tf_session *tfs;
605         struct tf_dev_info *dev;
606         struct tf_tcam_alloc_search_parms sparms;
607
608         TF_CHECK_PARMS2(tfp, parms);
609
610         memset(&sparms, 0, sizeof(struct tf_tcam_alloc_search_parms));
611
612         /* Retrieve the session information */
613         rc = tf_session_get_session(tfp, &tfs);
614         if (rc) {
615                 TFP_DRV_LOG(ERR,
616                             "%s: Failed to lookup session, rc:%s\n",
617                             tf_dir_2_str(parms->dir),
618                             strerror(-rc));
619                 return rc;
620         }
621
622         /* Retrieve the device information */
623         rc = tf_session_get_device(tfs, &dev);
624         if (rc) {
625                 TFP_DRV_LOG(ERR,
626                             "%s: Failed to lookup device, rc:%s\n",
627                             tf_dir_2_str(parms->dir),
628                             strerror(-rc));
629                 return rc;
630         }
631
632         if (dev->ops->tf_dev_alloc_search_tcam == NULL) {
633                 rc = -EOPNOTSUPP;
634                 TFP_DRV_LOG(ERR,
635                             "%s: Operation not supported, rc:%s\n",
636                             tf_dir_2_str(parms->dir),
637                             strerror(-rc));
638                 return rc;
639         }
640
641         sparms.dir = parms->dir;
642         sparms.type = parms->tcam_tbl_type;
643         sparms.key = parms->key;
644         sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
645         sparms.mask = parms->mask;
646         sparms.priority = parms->priority;
647         sparms.alloc = parms->alloc;
648
649         /* Result is an in/out and so no need to copy during outputs */
650         sparms.result = parms->result;
651         sparms.result_size =
652                 TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
653
654         rc = dev->ops->tf_dev_alloc_search_tcam(tfp, &sparms);
655         if (rc) {
656                 TFP_DRV_LOG(ERR,
657                             "%s: TCAM allocation failed, rc:%s\n",
658                             tf_dir_2_str(parms->dir),
659                             strerror(-rc));
660                 return rc;
661         }
662
663         /* Copy the outputs */
664         parms->hit = sparms.hit;
665         parms->search_status = sparms.search_status;
666         parms->ref_cnt = sparms.ref_cnt;
667         parms->idx = sparms.idx;
668
669         return 0;
670 }
671
672 int
673 tf_alloc_tcam_entry(struct tf *tfp,
674                     struct tf_alloc_tcam_entry_parms *parms)
675 {
676         int rc;
677         struct tf_session *tfs;
678         struct tf_dev_info *dev;
679         struct tf_tcam_alloc_parms aparms;
680
681         TF_CHECK_PARMS2(tfp, parms);
682
683         memset(&aparms, 0, sizeof(struct tf_tcam_alloc_parms));
684
685         /* Retrieve the session information */
686         rc = tf_session_get_session(tfp, &tfs);
687         if (rc) {
688                 TFP_DRV_LOG(ERR,
689                             "%s: Failed to lookup session, rc:%s\n",
690                             tf_dir_2_str(parms->dir),
691                             strerror(-rc));
692                 return rc;
693         }
694
695         /* Retrieve the device information */
696         rc = tf_session_get_device(tfs, &dev);
697         if (rc) {
698                 TFP_DRV_LOG(ERR,
699                             "%s: Failed to lookup device, rc:%s\n",
700                             tf_dir_2_str(parms->dir),
701                             strerror(-rc));
702                 return rc;
703         }
704
705         if (dev->ops->tf_dev_alloc_tcam == NULL) {
706                 rc = -EOPNOTSUPP;
707                 TFP_DRV_LOG(ERR,
708                             "%s: Operation not supported, rc:%s\n",
709                             tf_dir_2_str(parms->dir),
710                             strerror(-rc));
711                 return rc;
712         }
713
714         aparms.dir = parms->dir;
715         aparms.type = parms->tcam_tbl_type;
716         aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
717         aparms.priority = parms->priority;
718         rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
719         if (rc) {
720                 TFP_DRV_LOG(ERR,
721                             "%s: TCAM allocation failed, rc:%s\n",
722                             tf_dir_2_str(parms->dir),
723                             strerror(-rc));
724                 return rc;
725         }
726
727         parms->idx = aparms.idx;
728
729         return 0;
730 }
731
732 int
733 tf_set_tcam_entry(struct tf *tfp,
734                   struct tf_set_tcam_entry_parms *parms)
735 {
736         int rc;
737         struct tf_session *tfs;
738         struct tf_dev_info *dev;
739         struct tf_tcam_set_parms sparms;
740
741         TF_CHECK_PARMS2(tfp, parms);
742
743         memset(&sparms, 0, sizeof(struct tf_tcam_set_parms));
744
745
746         /* Retrieve the session information */
747         rc = tf_session_get_session(tfp, &tfs);
748         if (rc) {
749                 TFP_DRV_LOG(ERR,
750                             "%s: Failed to lookup session, rc:%s\n",
751                             tf_dir_2_str(parms->dir),
752                             strerror(-rc));
753                 return rc;
754         }
755
756         /* Retrieve the device information */
757         rc = tf_session_get_device(tfs, &dev);
758         if (rc) {
759                 TFP_DRV_LOG(ERR,
760                             "%s: Failed to lookup device, rc:%s\n",
761                             tf_dir_2_str(parms->dir),
762                             strerror(-rc));
763                 return rc;
764         }
765
766         if (dev->ops->tf_dev_set_tcam == NULL ||
767             dev->ops->tf_dev_word_align == NULL) {
768                 rc = -EOPNOTSUPP;
769                 TFP_DRV_LOG(ERR,
770                             "%s: Operation not supported, rc:%s\n",
771                             tf_dir_2_str(parms->dir),
772                             strerror(-rc));
773                 return rc;
774         }
775
776         sparms.dir = parms->dir;
777         sparms.type = parms->tcam_tbl_type;
778         sparms.idx = parms->idx;
779         sparms.key = parms->key;
780         sparms.mask = parms->mask;
781         sparms.key_size = dev->ops->tf_dev_word_align(parms->key_sz_in_bits);
782         sparms.result = parms->result;
783         sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
784
785         rc = dev->ops->tf_dev_set_tcam(tfp, &sparms);
786         if (rc) {
787                 TFP_DRV_LOG(ERR,
788                             "%s: TCAM set failed, rc:%s\n",
789                             tf_dir_2_str(parms->dir),
790                             strerror(-rc));
791                 return rc;
792         }
793
794         return 0;
795 }
796
797 int
798 tf_get_tcam_entry(struct tf *tfp __rte_unused,
799                   struct tf_get_tcam_entry_parms *parms)
800 {
801         int rc;
802         struct tf_session *tfs;
803         struct tf_dev_info *dev;
804         struct tf_tcam_get_parms gparms;
805
806         TF_CHECK_PARMS2(tfp, parms);
807
808         memset(&gparms, 0, sizeof(struct tf_tcam_get_parms));
809
810
811         /* Retrieve the session information */
812         rc = tf_session_get_session(tfp, &tfs);
813         if (rc) {
814                 TFP_DRV_LOG(ERR,
815                             "%s: Failed to lookup session, rc:%s\n",
816                             tf_dir_2_str(parms->dir),
817                             strerror(-rc));
818                 return rc;
819         }
820
821         /* Retrieve the device information */
822         rc = tf_session_get_device(tfs, &dev);
823         if (rc) {
824                 TFP_DRV_LOG(ERR,
825                             "%s: Failed to lookup device, rc:%s\n",
826                             tf_dir_2_str(parms->dir),
827                             strerror(-rc));
828                 return rc;
829         }
830
831         if (dev->ops->tf_dev_get_tcam == NULL) {
832                 rc = -EOPNOTSUPP;
833                 TFP_DRV_LOG(ERR,
834                             "%s: Operation not supported, rc:%s\n",
835                             tf_dir_2_str(parms->dir),
836                             strerror(-rc));
837                 return rc;
838         }
839
840         gparms.dir = parms->dir;
841         gparms.type = parms->tcam_tbl_type;
842         gparms.idx = parms->idx;
843         gparms.key = parms->key;
844         gparms.key_size = dev->ops->tf_dev_word_align(parms->key_sz_in_bits);
845         gparms.mask = parms->mask;
846         gparms.result = parms->result;
847         gparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
848
849         rc = dev->ops->tf_dev_get_tcam(tfp, &gparms);
850         if (rc) {
851                 TFP_DRV_LOG(ERR,
852                             "%s: TCAM get failed, rc:%s\n",
853                             tf_dir_2_str(parms->dir),
854                             strerror(-rc));
855                 return rc;
856         }
857         parms->key_sz_in_bits = gparms.key_size * 8;
858         parms->result_sz_in_bits = gparms.result_size * 8;
859
860         return 0;
861 }
862
863 int
864 tf_free_tcam_entry(struct tf *tfp,
865                    struct tf_free_tcam_entry_parms *parms)
866 {
867         int rc;
868         struct tf_session *tfs;
869         struct tf_dev_info *dev;
870         struct tf_tcam_free_parms fparms;
871
872         TF_CHECK_PARMS2(tfp, parms);
873
874         memset(&fparms, 0, sizeof(struct tf_tcam_free_parms));
875
876         /* Retrieve the session information */
877         rc = tf_session_get_session(tfp, &tfs);
878         if (rc) {
879                 TFP_DRV_LOG(ERR,
880                             "%s: Failed to lookup session, rc:%s\n",
881                             tf_dir_2_str(parms->dir),
882                             strerror(-rc));
883                 return rc;
884         }
885
886         /* Retrieve the device information */
887         rc = tf_session_get_device(tfs, &dev);
888         if (rc) {
889                 TFP_DRV_LOG(ERR,
890                             "%s: Failed to lookup device, rc:%s\n",
891                             tf_dir_2_str(parms->dir),
892                             strerror(-rc));
893                 return rc;
894         }
895
896         if (dev->ops->tf_dev_free_tcam == NULL) {
897                 rc = -EOPNOTSUPP;
898                 TFP_DRV_LOG(ERR,
899                             "%s: Operation not supported, rc:%s\n",
900                             tf_dir_2_str(parms->dir),
901                             strerror(-rc));
902                 return rc;
903         }
904
905         fparms.dir = parms->dir;
906         fparms.type = parms->tcam_tbl_type;
907         fparms.idx = parms->idx;
908         rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
909         if (rc) {
910                 TFP_DRV_LOG(ERR,
911                             "%s: TCAM free failed, rc:%s\n",
912                             tf_dir_2_str(parms->dir),
913                             strerror(-rc));
914                 return rc;
915         }
916
917         return 0;
918 }
919
920 #ifdef TF_TCAM_SHARED
921 int
922 tf_move_tcam_shared_entries(struct tf *tfp,
923                             struct tf_move_tcam_shared_entries_parms *parms)
924 {
925         int rc;
926         struct tf_session *tfs;
927         struct tf_dev_info *dev;
928
929         TF_CHECK_PARMS2(tfp, parms);
930
931         /* Retrieve the session information */
932         rc = tf_session_get_session(tfp, &tfs);
933         if (rc) {
934                 TFP_DRV_LOG(ERR,
935                             "%s: Failed to lookup session, rc:%s\n",
936                             tf_dir_2_str(parms->dir),
937                             strerror(-rc));
938                 return rc;
939         }
940
941         /* Retrieve the device information */
942         rc = tf_session_get_device(tfs, &dev);
943         if (rc) {
944                 TFP_DRV_LOG(ERR,
945                             "%s: Failed to lookup device, rc:%s\n",
946                             tf_dir_2_str(parms->dir),
947                             strerror(-rc));
948                 return rc;
949         }
950
951         if (dev->ops->tf_dev_move_tcam == NULL) {
952                 rc = -EOPNOTSUPP;
953                 TFP_DRV_LOG(ERR,
954                             "%s: Operation not supported, rc:%s\n",
955                             tf_dir_2_str(parms->dir),
956                             strerror(-rc));
957                 return rc;
958         }
959
960         rc = dev->ops->tf_dev_move_tcam(tfp, parms);
961         if (rc) {
962                 TFP_DRV_LOG(ERR,
963                             "%s: TCAM shared entries move failed, rc:%s\n",
964                             tf_dir_2_str(parms->dir),
965                             strerror(-rc));
966                 return rc;
967         }
968
969         return 0;
970 }
971
972 int
973 tf_clear_tcam_shared_entries(struct tf *tfp,
974                              struct tf_clear_tcam_shared_entries_parms *parms)
975 {
976         int rc;
977         struct tf_session *tfs;
978         struct tf_dev_info *dev;
979
980         TF_CHECK_PARMS2(tfp, parms);
981
982         /* Retrieve the session information */
983         rc = tf_session_get_session(tfp, &tfs);
984         if (rc) {
985                 TFP_DRV_LOG(ERR,
986                             "%s: Failed to lookup session, rc:%s\n",
987                             tf_dir_2_str(parms->dir),
988                             strerror(-rc));
989                 return rc;
990         }
991
992         /* Retrieve the device information */
993         rc = tf_session_get_device(tfs, &dev);
994         if (rc) {
995                 TFP_DRV_LOG(ERR,
996                             "%s: Failed to lookup device, rc:%s\n",
997                             tf_dir_2_str(parms->dir),
998                             strerror(-rc));
999                 return rc;
1000         }
1001
1002         if (dev->ops->tf_dev_clear_tcam == NULL) {
1003                 rc = -EOPNOTSUPP;
1004                 TFP_DRV_LOG(ERR,
1005                             "%s: Operation not supported, rc:%s\n",
1006                             tf_dir_2_str(parms->dir),
1007                             strerror(-rc));
1008                 return rc;
1009         }
1010
1011         rc = dev->ops->tf_dev_clear_tcam(tfp, parms);
1012         if (rc) {
1013                 TFP_DRV_LOG(ERR,
1014                             "%s: TCAM shared entries clear failed, rc:%s\n",
1015                             tf_dir_2_str(parms->dir),
1016                             strerror(-rc));
1017                 return rc;
1018         }
1019
1020         return 0;
1021 }
1022 #endif /* TF_TCAM_SHARED */
1023
1024 int
1025 tf_alloc_tbl_entry(struct tf *tfp,
1026                    struct tf_alloc_tbl_entry_parms *parms)
1027 {
1028         int rc;
1029         struct tf_session *tfs;
1030         struct tf_dev_info *dev;
1031         struct tf_tbl_alloc_parms aparms;
1032         uint32_t idx;
1033
1034         TF_CHECK_PARMS2(tfp, parms);
1035
1036         /* Can't do static initialization due to UT enum check */
1037         memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
1038
1039         /* Retrieve the session information */
1040         rc = tf_session_get_session(tfp, &tfs);
1041         if (rc) {
1042                 TFP_DRV_LOG(ERR,
1043                             "%s: Failed to lookup session, rc:%s\n",
1044                             tf_dir_2_str(parms->dir),
1045                             strerror(-rc));
1046                 return rc;
1047         }
1048
1049         /* Retrieve the device information */
1050         rc = tf_session_get_device(tfs, &dev);
1051         if (rc) {
1052                 TFP_DRV_LOG(ERR,
1053                             "%s: Failed to lookup device, rc:%s\n",
1054                             tf_dir_2_str(parms->dir),
1055                             strerror(-rc));
1056                 return rc;
1057         }
1058
1059         aparms.dir = parms->dir;
1060         aparms.type = parms->type;
1061         aparms.idx = &idx;
1062         aparms.tbl_scope_id = parms->tbl_scope_id;
1063
1064         if (parms->type == TF_TBL_TYPE_EXT) {
1065                 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) {
1066                         rc = -EOPNOTSUPP;
1067                         TFP_DRV_LOG(ERR,
1068                                     "%s: Operation not supported, rc:%s\n",
1069                                     tf_dir_2_str(parms->dir),
1070                                     strerror(-rc));
1071                         return -EOPNOTSUPP;
1072                 }
1073
1074                 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
1075                 if (rc) {
1076                         TFP_DRV_LOG(ERR,
1077                                     "%s: External table allocation failed, rc:%s\n",
1078                                     tf_dir_2_str(parms->dir),
1079                                     strerror(-rc));
1080                         return rc;
1081                 }
1082
1083         } else {
1084                 if (dev->ops->tf_dev_alloc_tbl == NULL) {
1085                         rc = -EOPNOTSUPP;
1086                         TFP_DRV_LOG(ERR,
1087                                     "%s: Operation not supported, rc:%s\n",
1088                                     tf_dir_2_str(parms->dir),
1089                                     strerror(-rc));
1090                         return -EOPNOTSUPP;
1091                 }
1092
1093                 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
1094                 if (rc) {
1095                         TFP_DRV_LOG(ERR,
1096                                     "%s: Table allocation failed, rc:%s\n",
1097                                     tf_dir_2_str(parms->dir),
1098                                     strerror(-rc));
1099                         return rc;
1100                 }
1101         }
1102
1103         parms->idx = idx;
1104
1105         return 0;
1106 }
1107
1108 int
1109 tf_search_tbl_entry(struct tf *tfp,
1110                     struct tf_search_tbl_entry_parms *parms)
1111 {
1112         int rc;
1113         struct tf_session *tfs;
1114         struct tf_dev_info *dev;
1115         struct tf_tbl_alloc_search_parms sparms;
1116
1117         TF_CHECK_PARMS2(tfp, parms);
1118
1119         /* Retrieve the session information */
1120         rc = tf_session_get_session(tfp, &tfs);
1121         if (rc) {
1122                 TFP_DRV_LOG(ERR,
1123                             "%s: Failed to lookup session, rc:%s\n",
1124                             tf_dir_2_str(parms->dir),
1125                             strerror(-rc));
1126                 return rc;
1127         }
1128
1129         /* Retrieve the device information */
1130         rc = tf_session_get_device(tfs, &dev);
1131         if (rc) {
1132                 TFP_DRV_LOG(ERR,
1133                             "%s: Failed to lookup device, rc:%s\n",
1134                             tf_dir_2_str(parms->dir),
1135                             strerror(-rc));
1136                 return rc;
1137         }
1138
1139         if (dev->ops->tf_dev_alloc_search_tbl == NULL) {
1140                 rc = -EOPNOTSUPP;
1141                 TFP_DRV_LOG(ERR,
1142                             "%s: Operation not supported, rc:%s\n",
1143                             tf_dir_2_str(parms->dir),
1144                             strerror(-rc));
1145                 return rc;
1146         }
1147
1148         memset(&sparms, 0, sizeof(struct tf_tbl_alloc_search_parms));
1149         sparms.dir = parms->dir;
1150         sparms.type = parms->type;
1151         sparms.result = parms->result;
1152         sparms.result_sz_in_bytes = parms->result_sz_in_bytes;
1153         sparms.alloc = parms->alloc;
1154         sparms.tbl_scope_id = parms->tbl_scope_id;
1155         rc = dev->ops->tf_dev_alloc_search_tbl(tfp, &sparms);
1156         if (rc) {
1157                 TFP_DRV_LOG(ERR,
1158                             "%s: TBL allocation failed, rc:%s\n",
1159                             tf_dir_2_str(parms->dir),
1160                             strerror(-rc));
1161                 return rc;
1162         }
1163
1164         /* Return the outputs from the search */
1165         parms->hit = sparms.hit;
1166         parms->search_status = sparms.search_status;
1167         parms->ref_cnt = sparms.ref_cnt;
1168         parms->idx = sparms.idx;
1169
1170         return 0;
1171 }
1172
1173 int
1174 tf_free_tbl_entry(struct tf *tfp,
1175                   struct tf_free_tbl_entry_parms *parms)
1176 {
1177         int rc;
1178         struct tf_session *tfs;
1179         struct tf_dev_info *dev;
1180         struct tf_tbl_free_parms fparms;
1181
1182         TF_CHECK_PARMS2(tfp, parms);
1183
1184         /* Can't do static initialization due to UT enum check */
1185         memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
1186
1187         /* Retrieve the session information */
1188         rc = tf_session_get_session(tfp, &tfs);
1189         if (rc) {
1190                 TFP_DRV_LOG(ERR,
1191                             "%s: Failed to lookup session, rc:%s\n",
1192                             tf_dir_2_str(parms->dir),
1193                             strerror(-rc));
1194                 return rc;
1195         }
1196
1197         /* Retrieve the device information */
1198         rc = tf_session_get_device(tfs, &dev);
1199         if (rc) {
1200                 TFP_DRV_LOG(ERR,
1201                             "%s: Failed to lookup device, rc:%s\n",
1202                             tf_dir_2_str(parms->dir),
1203                             strerror(-rc));
1204                 return rc;
1205         }
1206
1207         fparms.dir = parms->dir;
1208         fparms.type = parms->type;
1209         fparms.idx = parms->idx;
1210         fparms.tbl_scope_id = parms->tbl_scope_id;
1211
1212         if (parms->type == TF_TBL_TYPE_EXT) {
1213                 if (dev->ops->tf_dev_free_ext_tbl == NULL) {
1214                         rc = -EOPNOTSUPP;
1215                         TFP_DRV_LOG(ERR,
1216                                     "%s: Operation not supported, rc:%s\n",
1217                                     tf_dir_2_str(parms->dir),
1218                                     strerror(-rc));
1219                         return -EOPNOTSUPP;
1220                 }
1221
1222                 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms);
1223                 if (rc) {
1224                         TFP_DRV_LOG(ERR,
1225                                     "%s: Table free failed, rc:%s\n",
1226                                     tf_dir_2_str(parms->dir),
1227                                     strerror(-rc));
1228                         return rc;
1229                 }
1230         } else {
1231                 if (dev->ops->tf_dev_free_tbl == NULL) {
1232                         rc = -EOPNOTSUPP;
1233                         TFP_DRV_LOG(ERR,
1234                                     "%s: Operation not supported, rc:%s\n",
1235                                     tf_dir_2_str(parms->dir),
1236                                     strerror(-rc));
1237                         return -EOPNOTSUPP;
1238                 }
1239
1240                 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
1241                 if (rc) {
1242                         TFP_DRV_LOG(ERR,
1243                                     "%s: Table free failed, rc:%s\n",
1244                                     tf_dir_2_str(parms->dir),
1245                                     strerror(-rc));
1246                         return rc;
1247                 }
1248         }
1249
1250         return 0;
1251 }
1252
1253 int
1254 tf_set_tbl_entry(struct tf *tfp,
1255                  struct tf_set_tbl_entry_parms *parms)
1256 {
1257         int rc = 0;
1258         struct tf_session *tfs;
1259         struct tf_dev_info *dev;
1260         struct tf_tbl_set_parms sparms;
1261
1262         TF_CHECK_PARMS3(tfp, parms, parms->data);
1263
1264         /* Can't do static initialization due to UT enum check */
1265         memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
1266
1267         /* Retrieve the session information */
1268         rc = tf_session_get_session(tfp, &tfs);
1269         if (rc) {
1270                 TFP_DRV_LOG(ERR,
1271                             "%s: Failed to lookup session, rc:%s\n",
1272                             tf_dir_2_str(parms->dir),
1273                             strerror(-rc));
1274                 return rc;
1275         }
1276
1277         /* Retrieve the device information */
1278         rc = tf_session_get_device(tfs, &dev);
1279         if (rc) {
1280                 TFP_DRV_LOG(ERR,
1281                             "%s: Failed to lookup device, rc:%s\n",
1282                             tf_dir_2_str(parms->dir),
1283                             strerror(-rc));
1284                 return rc;
1285         }
1286
1287         sparms.dir = parms->dir;
1288         sparms.type = parms->type;
1289         sparms.data = parms->data;
1290         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1291         sparms.idx = parms->idx;
1292         sparms.tbl_scope_id = parms->tbl_scope_id;
1293
1294         if (parms->type == TF_TBL_TYPE_EXT) {
1295                 if (dev->ops->tf_dev_set_ext_tbl == NULL) {
1296                         rc = -EOPNOTSUPP;
1297                         TFP_DRV_LOG(ERR,
1298                                     "%s: Operation not supported, rc:%s\n",
1299                                     tf_dir_2_str(parms->dir),
1300                                     strerror(-rc));
1301                         return -EOPNOTSUPP;
1302                 }
1303
1304                 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms);
1305                 if (rc) {
1306                         TFP_DRV_LOG(ERR,
1307                                     "%s: Table set failed, rc:%s\n",
1308                                     tf_dir_2_str(parms->dir),
1309                                     strerror(-rc));
1310                         return rc;
1311                 }
1312         } else {
1313                 if (dev->ops->tf_dev_set_tbl == NULL) {
1314                         rc = -EOPNOTSUPP;
1315                         TFP_DRV_LOG(ERR,
1316                                     "%s: Operation not supported, rc:%s\n",
1317                                     tf_dir_2_str(parms->dir),
1318                                     strerror(-rc));
1319                         return -EOPNOTSUPP;
1320                 }
1321
1322                 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
1323                 if (rc) {
1324                         TFP_DRV_LOG(ERR,
1325                                     "%s: Table set failed, rc:%s\n",
1326                                     tf_dir_2_str(parms->dir),
1327                                     strerror(-rc));
1328                         return rc;
1329                 }
1330         }
1331
1332         return rc;
1333 }
1334
1335 int
1336 tf_get_tbl_entry(struct tf *tfp,
1337                  struct tf_get_tbl_entry_parms *parms)
1338 {
1339         int rc = 0;
1340         struct tf_session *tfs;
1341         struct tf_dev_info *dev;
1342         struct tf_tbl_get_parms gparms;
1343
1344         TF_CHECK_PARMS3(tfp, parms, parms->data);
1345
1346         /* Can't do static initialization due to UT enum check */
1347         memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
1348
1349         /* Retrieve the session information */
1350         rc = tf_session_get_session(tfp, &tfs);
1351         if (rc) {
1352                 TFP_DRV_LOG(ERR,
1353                             "%s: Failed to lookup session, rc:%s\n",
1354                             tf_dir_2_str(parms->dir),
1355                             strerror(-rc));
1356                 return rc;
1357         }
1358
1359         /* Retrieve the device information */
1360         rc = tf_session_get_device(tfs, &dev);
1361         if (rc) {
1362                 TFP_DRV_LOG(ERR,
1363                             "%s: Failed to lookup device, rc:%s\n",
1364                             tf_dir_2_str(parms->dir),
1365                             strerror(-rc));
1366                 return rc;
1367         }
1368
1369         if (dev->ops->tf_dev_get_tbl == NULL) {
1370                 rc = -EOPNOTSUPP;
1371                 TFP_DRV_LOG(ERR,
1372                             "%s: Operation not supported, rc:%s\n",
1373                             tf_dir_2_str(parms->dir),
1374                             strerror(-rc));
1375                 return -EOPNOTSUPP;
1376         }
1377
1378         gparms.dir = parms->dir;
1379         gparms.type = parms->type;
1380         gparms.data = parms->data;
1381         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1382         gparms.idx = parms->idx;
1383         rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
1384         if (rc) {
1385                 TFP_DRV_LOG(ERR,
1386                             "%s: Table get failed, rc:%s\n",
1387                             tf_dir_2_str(parms->dir),
1388                             strerror(-rc));
1389                 return rc;
1390         }
1391
1392         return rc;
1393 }
1394
1395 int
1396 tf_bulk_get_tbl_entry(struct tf *tfp,
1397                  struct tf_bulk_get_tbl_entry_parms *parms)
1398 {
1399         int rc = 0;
1400         struct tf_session *tfs;
1401         struct tf_dev_info *dev;
1402         struct tf_tbl_get_bulk_parms bparms;
1403
1404         TF_CHECK_PARMS2(tfp, parms);
1405
1406         /* Can't do static initialization due to UT enum check */
1407         memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
1408
1409         /* Retrieve the session information */
1410         rc = tf_session_get_session(tfp, &tfs);
1411         if (rc) {
1412                 TFP_DRV_LOG(ERR,
1413                             "%s: Failed to lookup session, rc:%s\n",
1414                             tf_dir_2_str(parms->dir),
1415                             strerror(-rc));
1416                 return rc;
1417         }
1418
1419         /* Retrieve the device information */
1420         rc = tf_session_get_device(tfs, &dev);
1421         if (rc) {
1422                 TFP_DRV_LOG(ERR,
1423                             "%s: Failed to lookup device, rc:%s\n",
1424                             tf_dir_2_str(parms->dir),
1425                             strerror(-rc));
1426                 return rc;
1427         }
1428
1429         if (parms->type == TF_TBL_TYPE_EXT) {
1430                 /* Not supported, yet */
1431                 rc = -EOPNOTSUPP;
1432                 TFP_DRV_LOG(ERR,
1433                             "%s, External table type not supported, rc:%s\n",
1434                             tf_dir_2_str(parms->dir),
1435                             strerror(-rc));
1436
1437                 return rc;
1438         }
1439
1440         /* Internal table type processing */
1441
1442         if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
1443                 rc = -EOPNOTSUPP;
1444                 TFP_DRV_LOG(ERR,
1445                             "%s: Operation not supported, rc:%s\n",
1446                             tf_dir_2_str(parms->dir),
1447                             strerror(-rc));
1448                 return -EOPNOTSUPP;
1449         }
1450
1451         bparms.dir = parms->dir;
1452         bparms.type = parms->type;
1453         bparms.starting_idx = parms->starting_idx;
1454         bparms.num_entries = parms->num_entries;
1455         bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
1456         bparms.physical_mem_addr = parms->physical_mem_addr;
1457         rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
1458         if (rc) {
1459                 TFP_DRV_LOG(ERR,
1460                             "%s: Table get bulk failed, rc:%s\n",
1461                             tf_dir_2_str(parms->dir),
1462                             strerror(-rc));
1463                 return rc;
1464         }
1465
1466         return rc;
1467 }
1468
1469 int tf_get_shared_tbl_increment(struct tf *tfp,
1470                                 struct tf_get_shared_tbl_increment_parms *parms)
1471 {
1472         int rc = 0;
1473         struct tf_session *tfs;
1474         struct tf_dev_info *dev;
1475
1476         TF_CHECK_PARMS2(tfp, parms);
1477
1478         /* Retrieve the session information */
1479         rc = tf_session_get_session(tfp, &tfs);
1480         if (rc) {
1481                 TFP_DRV_LOG(ERR,
1482                             "%s: Failed to lookup session, rc:%s\n",
1483                             tf_dir_2_str(parms->dir),
1484                             strerror(-rc));
1485                 return rc;
1486         }
1487
1488         /* Retrieve the device information */
1489         rc = tf_session_get_device(tfs, &dev);
1490         if (rc) {
1491                 TFP_DRV_LOG(ERR,
1492                             "%s: Failed to lookup device, rc:%s\n",
1493                             tf_dir_2_str(parms->dir),
1494                             strerror(-rc));
1495                 return rc;
1496         }
1497
1498         /* Internal table type processing */
1499
1500         if (dev->ops->tf_dev_get_shared_tbl_increment == NULL) {
1501                 rc = -EOPNOTSUPP;
1502                 TFP_DRV_LOG(ERR,
1503                             "%s: Operation not supported, rc:%s\n",
1504                             tf_dir_2_str(parms->dir),
1505                             strerror(-rc));
1506                 return -EOPNOTSUPP;
1507         }
1508
1509         rc = dev->ops->tf_dev_get_shared_tbl_increment(tfp, parms);
1510         if (rc) {
1511                 TFP_DRV_LOG(ERR,
1512                             "%s: Get table increment not supported, rc:%s\n",
1513                             tf_dir_2_str(parms->dir),
1514                             strerror(-rc));
1515                 return rc;
1516         }
1517
1518         return rc;
1519 }
1520
1521 int
1522 tf_alloc_tbl_scope(struct tf *tfp,
1523                    struct tf_alloc_tbl_scope_parms *parms)
1524 {
1525         struct tf_session *tfs;
1526         struct tf_dev_info *dev;
1527         int rc;
1528
1529         TF_CHECK_PARMS2(tfp, parms);
1530
1531         /* Retrieve the session information */
1532         rc = tf_session_get_session(tfp, &tfs);
1533         if (rc) {
1534                 TFP_DRV_LOG(ERR,
1535                             "Failed to lookup session, rc:%s\n",
1536                             strerror(-rc));
1537                 return rc;
1538         }
1539
1540         /* Retrieve the device information */
1541         rc = tf_session_get_device(tfs, &dev);
1542         if (rc) {
1543                 TFP_DRV_LOG(ERR,
1544                             "Failed to lookup device, rc:%s\n",
1545                             strerror(-rc));
1546                 return rc;
1547         }
1548
1549         if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
1550                 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
1551         } else {
1552                 TFP_DRV_LOG(ERR,
1553                             "Alloc table scope not supported by device\n");
1554                 return -EINVAL;
1555         }
1556
1557         return rc;
1558 }
1559 int
1560 tf_map_tbl_scope(struct tf *tfp,
1561                    struct tf_map_tbl_scope_parms *parms)
1562 {
1563         struct tf_session *tfs;
1564         struct tf_dev_info *dev;
1565         int rc;
1566
1567         TF_CHECK_PARMS2(tfp, parms);
1568
1569         /* Retrieve the session information */
1570         rc = tf_session_get_session(tfp, &tfs);
1571         if (rc) {
1572                 TFP_DRV_LOG(ERR,
1573                             "Failed to lookup session, rc:%s\n",
1574                             strerror(-rc));
1575                 return rc;
1576         }
1577
1578         /* Retrieve the device information */
1579         rc = tf_session_get_device(tfs, &dev);
1580         if (rc) {
1581                 TFP_DRV_LOG(ERR,
1582                             "Failed to lookup device, rc:%s\n",
1583                             strerror(-rc));
1584                 return rc;
1585         }
1586
1587         if (dev->ops->tf_dev_map_tbl_scope != NULL) {
1588                 rc = dev->ops->tf_dev_map_tbl_scope(tfp, parms);
1589         } else {
1590                 TFP_DRV_LOG(ERR,
1591                             "Map table scope not supported by device\n");
1592                 return -EINVAL;
1593         }
1594
1595         return rc;
1596 }
1597
1598 int
1599 tf_free_tbl_scope(struct tf *tfp,
1600                   struct tf_free_tbl_scope_parms *parms)
1601 {
1602         struct tf_session *tfs;
1603         struct tf_dev_info *dev;
1604         int rc;
1605
1606         TF_CHECK_PARMS2(tfp, parms);
1607
1608         /* Retrieve the session information */
1609         rc = tf_session_get_session(tfp, &tfs);
1610         if (rc) {
1611                 TFP_DRV_LOG(ERR,
1612                             "Failed to lookup session, rc:%s\n",
1613                             strerror(-rc));
1614                 return rc;
1615         }
1616
1617         /* Retrieve the device information */
1618         rc = tf_session_get_device(tfs, &dev);
1619         if (rc) {
1620                 TFP_DRV_LOG(ERR,
1621                             "Failed to lookup device, rc:%s\n",
1622                             strerror(-rc));
1623                 return rc;
1624         }
1625
1626         if (dev->ops->tf_dev_free_tbl_scope) {
1627                 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
1628         } else {
1629                 TFP_DRV_LOG(ERR,
1630                             "Free table scope not supported by device\n");
1631                 return -EINVAL;
1632         }
1633
1634         return rc;
1635 }
1636
1637 int
1638 tf_set_if_tbl_entry(struct tf *tfp,
1639                     struct tf_set_if_tbl_entry_parms *parms)
1640 {
1641         int rc;
1642         struct tf_session *tfs;
1643         struct tf_dev_info *dev;
1644         struct tf_if_tbl_set_parms sparms = { 0 };
1645
1646         TF_CHECK_PARMS2(tfp, parms);
1647
1648         /* Retrieve the session information */
1649         rc = tf_session_get_session(tfp, &tfs);
1650         if (rc) {
1651                 TFP_DRV_LOG(ERR,
1652                             "%s: Failed to lookup session, rc:%s\n",
1653                             tf_dir_2_str(parms->dir),
1654                             strerror(-rc));
1655                 return rc;
1656         }
1657
1658         /* Retrieve the device information */
1659         rc = tf_session_get_device(tfs, &dev);
1660         if (rc) {
1661                 TFP_DRV_LOG(ERR,
1662                             "%s: Failed to lookup device, rc:%s\n",
1663                             tf_dir_2_str(parms->dir),
1664                             strerror(-rc));
1665                 return rc;
1666         }
1667
1668         if (dev->ops->tf_dev_set_if_tbl == NULL) {
1669                 rc = -EOPNOTSUPP;
1670                 TFP_DRV_LOG(ERR,
1671                             "%s: Operation not supported, rc:%s\n",
1672                             tf_dir_2_str(parms->dir),
1673                             strerror(-rc));
1674                 return rc;
1675         }
1676
1677         sparms.dir = parms->dir;
1678         sparms.type = parms->type;
1679         sparms.idx = parms->idx;
1680         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1681         sparms.data = parms->data;
1682
1683         rc = dev->ops->tf_dev_set_if_tbl(tfp, &sparms);
1684         if (rc) {
1685                 TFP_DRV_LOG(ERR,
1686                             "%s: If_tbl set failed, rc:%s\n",
1687                             tf_dir_2_str(parms->dir),
1688                             strerror(-rc));
1689                 return rc;
1690         }
1691
1692         return 0;
1693 }
1694
1695 int
1696 tf_get_if_tbl_entry(struct tf *tfp,
1697                     struct tf_get_if_tbl_entry_parms *parms)
1698 {
1699         int rc;
1700         struct tf_session *tfs;
1701         struct tf_dev_info *dev;
1702         struct tf_if_tbl_get_parms gparms = { 0 };
1703
1704         TF_CHECK_PARMS2(tfp, parms);
1705
1706         /* Retrieve the session information */
1707         rc = tf_session_get_session(tfp, &tfs);
1708         if (rc) {
1709                 TFP_DRV_LOG(ERR,
1710                             "%s: Failed to lookup session, rc:%s\n",
1711                             tf_dir_2_str(parms->dir),
1712                             strerror(-rc));
1713                 return rc;
1714         }
1715
1716         /* Retrieve the device information */
1717         rc = tf_session_get_device(tfs, &dev);
1718         if (rc) {
1719                 TFP_DRV_LOG(ERR,
1720                             "%s: Failed to lookup device, rc:%s\n",
1721                             tf_dir_2_str(parms->dir),
1722                             strerror(-rc));
1723                 return rc;
1724         }
1725
1726         if (dev->ops->tf_dev_get_if_tbl == NULL) {
1727                 rc = -EOPNOTSUPP;
1728                 TFP_DRV_LOG(ERR,
1729                             "%s: Operation not supported, rc:%s\n",
1730                             tf_dir_2_str(parms->dir),
1731                             strerror(-rc));
1732                 return rc;
1733         }
1734
1735         gparms.dir = parms->dir;
1736         gparms.type = parms->type;
1737         gparms.idx = parms->idx;
1738         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1739         gparms.data = parms->data;
1740
1741         rc = dev->ops->tf_dev_get_if_tbl(tfp, &gparms);
1742         if (rc) {
1743                 TFP_DRV_LOG(ERR,
1744                             "%s: If_tbl get failed, rc:%s\n",
1745                             tf_dir_2_str(parms->dir),
1746                             strerror(-rc));
1747                 return rc;
1748         }
1749
1750         return 0;
1751 }
1752
1753 int tf_get_session_info(struct tf *tfp,
1754                         struct tf_get_session_info_parms *parms)
1755 {
1756         int rc;
1757         struct tf_session      *tfs;
1758         struct tf_dev_info     *dev;
1759
1760         TF_CHECK_PARMS2(tfp, parms);
1761
1762         /* Retrieve the session information */
1763         rc = tf_session_get_session(tfp, &tfs);
1764         if (rc) {
1765                 TFP_DRV_LOG(ERR,
1766                             "Failed to lookup session, rc:%s\n",
1767                             strerror(-rc));
1768                 return rc;
1769         }
1770
1771         /* Retrieve the device information */
1772         rc = tf_session_get_device(tfs, &dev);
1773         if (rc) {
1774                 TFP_DRV_LOG(ERR,
1775                             "Failed to lookup device, rc:%s\n",
1776                             strerror(-rc));
1777                 return rc;
1778         }
1779
1780         TF_CHECK_PARMS2(tfp, parms);
1781
1782         if (dev->ops->tf_dev_get_ident_resc_info == NULL) {
1783                 rc = -EOPNOTSUPP;
1784                 TFP_DRV_LOG(ERR,
1785                             "Operation not supported, rc:%s\n",
1786                             strerror(-rc));
1787                 return rc;
1788         }
1789
1790         rc = dev->ops->tf_dev_get_ident_resc_info(tfp, parms->session_info.ident);
1791         if (rc) {
1792                 TFP_DRV_LOG(ERR,
1793                             "Ident get resc info failed, rc:%s\n",
1794                             strerror(-rc));
1795         }
1796
1797         if (dev->ops->tf_dev_get_tbl_resc_info == NULL) {
1798                 rc = -EOPNOTSUPP;
1799                 TFP_DRV_LOG(ERR,
1800                             "Operation not supported, rc:%s\n",
1801                             strerror(-rc));
1802                 return rc;
1803         }
1804
1805         rc = dev->ops->tf_dev_get_tbl_resc_info(tfp, parms->session_info.tbl);
1806         if (rc) {
1807                 TFP_DRV_LOG(ERR,
1808                             "Tbl get resc info failed, rc:%s\n",
1809                             strerror(-rc));
1810         }
1811
1812         if (dev->ops->tf_dev_get_tcam_resc_info == NULL) {
1813                 rc = -EOPNOTSUPP;
1814                 TFP_DRV_LOG(ERR,
1815                             "Operation not supported, rc:%s\n",
1816                             strerror(-rc));
1817                 return rc;
1818         }
1819
1820         rc = dev->ops->tf_dev_get_tcam_resc_info(tfp, parms->session_info.tcam);
1821         if (rc) {
1822                 TFP_DRV_LOG(ERR,
1823                             "TCAM get resc info failed, rc:%s\n",
1824                             strerror(-rc));
1825         }
1826
1827         if (dev->ops->tf_dev_get_em_resc_info == NULL) {
1828                 rc = -EOPNOTSUPP;
1829                 TFP_DRV_LOG(ERR,
1830                             "Operation not supported, rc:%s\n",
1831                             strerror(-rc));
1832                 return rc;
1833         }
1834
1835         rc = dev->ops->tf_dev_get_em_resc_info(tfp, parms->session_info.em);
1836         if (rc) {
1837                 TFP_DRV_LOG(ERR,
1838                             "EM get resc info failed, rc:%s\n",
1839                             strerror(-rc));
1840         }
1841
1842         return 0;
1843 }