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