net/bnxt: support Thor WC TCAM
[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.key_size = dev->ops->tf_dev_word_align(parms->key_sz_in_bits);
846         gparms.mask = parms->mask;
847         gparms.result = parms->result;
848         gparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
849
850         rc = dev->ops->tf_dev_get_tcam(tfp, &gparms);
851         if (rc) {
852                 TFP_DRV_LOG(ERR,
853                             "%s: TCAM get failed, rc:%s\n",
854                             tf_dir_2_str(parms->dir),
855                             strerror(-rc));
856                 return rc;
857         }
858         parms->key_sz_in_bits = gparms.key_size * 8;
859         parms->result_sz_in_bits = gparms.result_size * 8;
860
861         return 0;
862 }
863
864 int
865 tf_free_tcam_entry(struct tf *tfp,
866                    struct tf_free_tcam_entry_parms *parms)
867 {
868         int rc;
869         struct tf_session *tfs;
870         struct tf_dev_info *dev;
871         struct tf_tcam_free_parms fparms;
872
873         TF_CHECK_PARMS2(tfp, parms);
874
875         memset(&fparms, 0, sizeof(struct tf_tcam_free_parms));
876
877         /* Retrieve the session information */
878         rc = tf_session_get_session(tfp, &tfs);
879         if (rc) {
880                 TFP_DRV_LOG(ERR,
881                             "%s: Failed to lookup session, rc:%s\n",
882                             tf_dir_2_str(parms->dir),
883                             strerror(-rc));
884                 return rc;
885         }
886
887         /* Retrieve the device information */
888         rc = tf_session_get_device(tfs, &dev);
889         if (rc) {
890                 TFP_DRV_LOG(ERR,
891                             "%s: Failed to lookup device, rc:%s\n",
892                             tf_dir_2_str(parms->dir),
893                             strerror(-rc));
894                 return rc;
895         }
896
897         if (dev->ops->tf_dev_free_tcam == NULL) {
898                 rc = -EOPNOTSUPP;
899                 TFP_DRV_LOG(ERR,
900                             "%s: Operation not supported, rc:%s\n",
901                             tf_dir_2_str(parms->dir),
902                             strerror(-rc));
903                 return rc;
904         }
905
906         fparms.dir = parms->dir;
907         fparms.type = parms->tcam_tbl_type;
908         fparms.idx = parms->idx;
909         rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
910         if (rc) {
911                 TFP_DRV_LOG(ERR,
912                             "%s: TCAM free failed, rc:%s\n",
913                             tf_dir_2_str(parms->dir),
914                             strerror(-rc));
915                 return rc;
916         }
917
918         return 0;
919 }
920
921 int
922 tf_alloc_tbl_entry(struct tf *tfp,
923                    struct tf_alloc_tbl_entry_parms *parms)
924 {
925         int rc;
926         struct tf_session *tfs;
927         struct tf_dev_info *dev;
928         struct tf_tbl_alloc_parms aparms;
929         uint32_t idx;
930
931         TF_CHECK_PARMS2(tfp, parms);
932
933         /* Can't do static initialization due to UT enum check */
934         memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
935
936         /* Retrieve the session information */
937         rc = tf_session_get_session(tfp, &tfs);
938         if (rc) {
939                 TFP_DRV_LOG(ERR,
940                             "%s: Failed to lookup session, rc:%s\n",
941                             tf_dir_2_str(parms->dir),
942                             strerror(-rc));
943                 return rc;
944         }
945
946         /* Retrieve the device information */
947         rc = tf_session_get_device(tfs, &dev);
948         if (rc) {
949                 TFP_DRV_LOG(ERR,
950                             "%s: Failed to lookup device, rc:%s\n",
951                             tf_dir_2_str(parms->dir),
952                             strerror(-rc));
953                 return rc;
954         }
955
956         aparms.dir = parms->dir;
957         aparms.type = parms->type;
958         aparms.idx = &idx;
959         aparms.tbl_scope_id = parms->tbl_scope_id;
960
961         if (parms->type == TF_TBL_TYPE_EXT) {
962                 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) {
963                         rc = -EOPNOTSUPP;
964                         TFP_DRV_LOG(ERR,
965                                     "%s: Operation not supported, rc:%s\n",
966                                     tf_dir_2_str(parms->dir),
967                                     strerror(-rc));
968                         return -EOPNOTSUPP;
969                 }
970
971                 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
972                 if (rc) {
973                         TFP_DRV_LOG(ERR,
974                                     "%s: External table allocation failed, rc:%s\n",
975                                     tf_dir_2_str(parms->dir),
976                                     strerror(-rc));
977                         return rc;
978                 }
979
980         } else {
981                 if (dev->ops->tf_dev_alloc_tbl == NULL) {
982                         rc = -EOPNOTSUPP;
983                         TFP_DRV_LOG(ERR,
984                                     "%s: Operation not supported, rc:%s\n",
985                                     tf_dir_2_str(parms->dir),
986                                     strerror(-rc));
987                         return -EOPNOTSUPP;
988                 }
989
990                 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
991                 if (rc) {
992                         TFP_DRV_LOG(ERR,
993                                     "%s: Table allocation failed, rc:%s\n",
994                                     tf_dir_2_str(parms->dir),
995                                     strerror(-rc));
996                         return rc;
997                 }
998         }
999
1000         parms->idx = idx;
1001
1002         return 0;
1003 }
1004
1005 int
1006 tf_search_tbl_entry(struct tf *tfp,
1007                     struct tf_search_tbl_entry_parms *parms)
1008 {
1009         int rc;
1010         struct tf_session *tfs;
1011         struct tf_dev_info *dev;
1012         struct tf_tbl_alloc_search_parms sparms;
1013
1014         TF_CHECK_PARMS2(tfp, parms);
1015
1016         /* Retrieve the session information */
1017         rc = tf_session_get_session(tfp, &tfs);
1018         if (rc) {
1019                 TFP_DRV_LOG(ERR,
1020                             "%s: Failed to lookup session, rc:%s\n",
1021                             tf_dir_2_str(parms->dir),
1022                             strerror(-rc));
1023                 return rc;
1024         }
1025
1026         /* Retrieve the device information */
1027         rc = tf_session_get_device(tfs, &dev);
1028         if (rc) {
1029                 TFP_DRV_LOG(ERR,
1030                             "%s: Failed to lookup device, rc:%s\n",
1031                             tf_dir_2_str(parms->dir),
1032                             strerror(-rc));
1033                 return rc;
1034         }
1035
1036         if (dev->ops->tf_dev_alloc_search_tbl == NULL) {
1037                 rc = -EOPNOTSUPP;
1038                 TFP_DRV_LOG(ERR,
1039                             "%s: Operation not supported, rc:%s\n",
1040                             tf_dir_2_str(parms->dir),
1041                             strerror(-rc));
1042                 return rc;
1043         }
1044
1045         memset(&sparms, 0, sizeof(struct tf_tbl_alloc_search_parms));
1046         sparms.dir = parms->dir;
1047         sparms.type = parms->type;
1048         sparms.result = parms->result;
1049         sparms.result_sz_in_bytes = parms->result_sz_in_bytes;
1050         sparms.alloc = parms->alloc;
1051         sparms.tbl_scope_id = parms->tbl_scope_id;
1052         rc = dev->ops->tf_dev_alloc_search_tbl(tfp, &sparms);
1053         if (rc) {
1054                 TFP_DRV_LOG(ERR,
1055                             "%s: TBL allocation failed, rc:%s\n",
1056                             tf_dir_2_str(parms->dir),
1057                             strerror(-rc));
1058                 return rc;
1059         }
1060
1061         /* Return the outputs from the search */
1062         parms->hit = sparms.hit;
1063         parms->search_status = sparms.search_status;
1064         parms->ref_cnt = sparms.ref_cnt;
1065         parms->idx = sparms.idx;
1066
1067         return 0;
1068 }
1069
1070 int
1071 tf_free_tbl_entry(struct tf *tfp,
1072                   struct tf_free_tbl_entry_parms *parms)
1073 {
1074         int rc;
1075         struct tf_session *tfs;
1076         struct tf_dev_info *dev;
1077         struct tf_tbl_free_parms fparms;
1078
1079         TF_CHECK_PARMS2(tfp, parms);
1080
1081         /* Can't do static initialization due to UT enum check */
1082         memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
1083
1084         /* Retrieve the session information */
1085         rc = tf_session_get_session(tfp, &tfs);
1086         if (rc) {
1087                 TFP_DRV_LOG(ERR,
1088                             "%s: Failed to lookup session, rc:%s\n",
1089                             tf_dir_2_str(parms->dir),
1090                             strerror(-rc));
1091                 return rc;
1092         }
1093
1094         /* Retrieve the device information */
1095         rc = tf_session_get_device(tfs, &dev);
1096         if (rc) {
1097                 TFP_DRV_LOG(ERR,
1098                             "%s: Failed to lookup device, rc:%s\n",
1099                             tf_dir_2_str(parms->dir),
1100                             strerror(-rc));
1101                 return rc;
1102         }
1103
1104         fparms.dir = parms->dir;
1105         fparms.type = parms->type;
1106         fparms.idx = parms->idx;
1107         fparms.tbl_scope_id = parms->tbl_scope_id;
1108
1109         if (parms->type == TF_TBL_TYPE_EXT) {
1110                 if (dev->ops->tf_dev_free_ext_tbl == NULL) {
1111                         rc = -EOPNOTSUPP;
1112                         TFP_DRV_LOG(ERR,
1113                                     "%s: Operation not supported, rc:%s\n",
1114                                     tf_dir_2_str(parms->dir),
1115                                     strerror(-rc));
1116                         return -EOPNOTSUPP;
1117                 }
1118
1119                 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms);
1120                 if (rc) {
1121                         TFP_DRV_LOG(ERR,
1122                                     "%s: Table free failed, rc:%s\n",
1123                                     tf_dir_2_str(parms->dir),
1124                                     strerror(-rc));
1125                         return rc;
1126                 }
1127         } else {
1128                 if (dev->ops->tf_dev_free_tbl == NULL) {
1129                         rc = -EOPNOTSUPP;
1130                         TFP_DRV_LOG(ERR,
1131                                     "%s: Operation not supported, rc:%s\n",
1132                                     tf_dir_2_str(parms->dir),
1133                                     strerror(-rc));
1134                         return -EOPNOTSUPP;
1135                 }
1136
1137                 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
1138                 if (rc) {
1139                         TFP_DRV_LOG(ERR,
1140                                     "%s: Table free failed, rc:%s\n",
1141                                     tf_dir_2_str(parms->dir),
1142                                     strerror(-rc));
1143                         return rc;
1144                 }
1145         }
1146
1147         return 0;
1148 }
1149
1150 int
1151 tf_set_tbl_entry(struct tf *tfp,
1152                  struct tf_set_tbl_entry_parms *parms)
1153 {
1154         int rc = 0;
1155         struct tf_session *tfs;
1156         struct tf_dev_info *dev;
1157         struct tf_tbl_set_parms sparms;
1158
1159         TF_CHECK_PARMS3(tfp, parms, parms->data);
1160
1161         /* Can't do static initialization due to UT enum check */
1162         memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
1163
1164         /* Retrieve the session information */
1165         rc = tf_session_get_session(tfp, &tfs);
1166         if (rc) {
1167                 TFP_DRV_LOG(ERR,
1168                             "%s: Failed to lookup session, rc:%s\n",
1169                             tf_dir_2_str(parms->dir),
1170                             strerror(-rc));
1171                 return rc;
1172         }
1173
1174         /* Retrieve the device information */
1175         rc = tf_session_get_device(tfs, &dev);
1176         if (rc) {
1177                 TFP_DRV_LOG(ERR,
1178                             "%s: Failed to lookup device, rc:%s\n",
1179                             tf_dir_2_str(parms->dir),
1180                             strerror(-rc));
1181                 return rc;
1182         }
1183
1184         sparms.dir = parms->dir;
1185         sparms.type = parms->type;
1186         sparms.data = parms->data;
1187         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1188         sparms.idx = parms->idx;
1189         sparms.tbl_scope_id = parms->tbl_scope_id;
1190
1191         if (parms->type == TF_TBL_TYPE_EXT) {
1192                 if (dev->ops->tf_dev_set_ext_tbl == NULL) {
1193                         rc = -EOPNOTSUPP;
1194                         TFP_DRV_LOG(ERR,
1195                                     "%s: Operation not supported, rc:%s\n",
1196                                     tf_dir_2_str(parms->dir),
1197                                     strerror(-rc));
1198                         return -EOPNOTSUPP;
1199                 }
1200
1201                 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms);
1202                 if (rc) {
1203                         TFP_DRV_LOG(ERR,
1204                                     "%s: Table set failed, rc:%s\n",
1205                                     tf_dir_2_str(parms->dir),
1206                                     strerror(-rc));
1207                         return rc;
1208                 }
1209         } else {
1210                 if (dev->ops->tf_dev_set_tbl == NULL) {
1211                         rc = -EOPNOTSUPP;
1212                         TFP_DRV_LOG(ERR,
1213                                     "%s: Operation not supported, rc:%s\n",
1214                                     tf_dir_2_str(parms->dir),
1215                                     strerror(-rc));
1216                         return -EOPNOTSUPP;
1217                 }
1218
1219                 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
1220                 if (rc) {
1221                         TFP_DRV_LOG(ERR,
1222                                     "%s: Table set failed, rc:%s\n",
1223                                     tf_dir_2_str(parms->dir),
1224                                     strerror(-rc));
1225                         return rc;
1226                 }
1227         }
1228
1229         return rc;
1230 }
1231
1232 int
1233 tf_get_tbl_entry(struct tf *tfp,
1234                  struct tf_get_tbl_entry_parms *parms)
1235 {
1236         int rc = 0;
1237         struct tf_session *tfs;
1238         struct tf_dev_info *dev;
1239         struct tf_tbl_get_parms gparms;
1240
1241         TF_CHECK_PARMS3(tfp, parms, parms->data);
1242
1243         /* Can't do static initialization due to UT enum check */
1244         memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
1245
1246         /* Retrieve the session information */
1247         rc = tf_session_get_session(tfp, &tfs);
1248         if (rc) {
1249                 TFP_DRV_LOG(ERR,
1250                             "%s: Failed to lookup session, rc:%s\n",
1251                             tf_dir_2_str(parms->dir),
1252                             strerror(-rc));
1253                 return rc;
1254         }
1255
1256         /* Retrieve the device information */
1257         rc = tf_session_get_device(tfs, &dev);
1258         if (rc) {
1259                 TFP_DRV_LOG(ERR,
1260                             "%s: Failed to lookup device, rc:%s\n",
1261                             tf_dir_2_str(parms->dir),
1262                             strerror(-rc));
1263                 return rc;
1264         }
1265
1266         if (dev->ops->tf_dev_get_tbl == NULL) {
1267                 rc = -EOPNOTSUPP;
1268                 TFP_DRV_LOG(ERR,
1269                             "%s: Operation not supported, rc:%s\n",
1270                             tf_dir_2_str(parms->dir),
1271                             strerror(-rc));
1272                 return -EOPNOTSUPP;
1273         }
1274
1275         gparms.dir = parms->dir;
1276         gparms.type = parms->type;
1277         gparms.data = parms->data;
1278         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1279         gparms.idx = parms->idx;
1280         rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
1281         if (rc) {
1282                 TFP_DRV_LOG(ERR,
1283                             "%s: Table get failed, rc:%s\n",
1284                             tf_dir_2_str(parms->dir),
1285                             strerror(-rc));
1286                 return rc;
1287         }
1288
1289         return rc;
1290 }
1291
1292 int
1293 tf_bulk_get_tbl_entry(struct tf *tfp,
1294                  struct tf_bulk_get_tbl_entry_parms *parms)
1295 {
1296         int rc = 0;
1297         struct tf_session *tfs;
1298         struct tf_dev_info *dev;
1299         struct tf_tbl_get_bulk_parms bparms;
1300
1301         TF_CHECK_PARMS2(tfp, parms);
1302
1303         /* Can't do static initialization due to UT enum check */
1304         memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
1305
1306         /* Retrieve the session information */
1307         rc = tf_session_get_session(tfp, &tfs);
1308         if (rc) {
1309                 TFP_DRV_LOG(ERR,
1310                             "%s: Failed to lookup session, rc:%s\n",
1311                             tf_dir_2_str(parms->dir),
1312                             strerror(-rc));
1313                 return rc;
1314         }
1315
1316         /* Retrieve the device information */
1317         rc = tf_session_get_device(tfs, &dev);
1318         if (rc) {
1319                 TFP_DRV_LOG(ERR,
1320                             "%s: Failed to lookup device, rc:%s\n",
1321                             tf_dir_2_str(parms->dir),
1322                             strerror(-rc));
1323                 return rc;
1324         }
1325
1326         if (parms->type == TF_TBL_TYPE_EXT) {
1327                 /* Not supported, yet */
1328                 rc = -EOPNOTSUPP;
1329                 TFP_DRV_LOG(ERR,
1330                             "%s, External table type not supported, rc:%s\n",
1331                             tf_dir_2_str(parms->dir),
1332                             strerror(-rc));
1333
1334                 return rc;
1335         }
1336
1337         /* Internal table type processing */
1338
1339         if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
1340                 rc = -EOPNOTSUPP;
1341                 TFP_DRV_LOG(ERR,
1342                             "%s: Operation not supported, rc:%s\n",
1343                             tf_dir_2_str(parms->dir),
1344                             strerror(-rc));
1345                 return -EOPNOTSUPP;
1346         }
1347
1348         bparms.dir = parms->dir;
1349         bparms.type = parms->type;
1350         bparms.starting_idx = parms->starting_idx;
1351         bparms.num_entries = parms->num_entries;
1352         bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
1353         bparms.physical_mem_addr = parms->physical_mem_addr;
1354         rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
1355         if (rc) {
1356                 TFP_DRV_LOG(ERR,
1357                             "%s: Table get bulk failed, rc:%s\n",
1358                             tf_dir_2_str(parms->dir),
1359                             strerror(-rc));
1360                 return rc;
1361         }
1362
1363         return rc;
1364 }
1365
1366 int
1367 tf_alloc_tbl_scope(struct tf *tfp,
1368                    struct tf_alloc_tbl_scope_parms *parms)
1369 {
1370         struct tf_session *tfs;
1371         struct tf_dev_info *dev;
1372         int rc;
1373
1374         TF_CHECK_PARMS2(tfp, parms);
1375
1376         /* Retrieve the session information */
1377         rc = tf_session_get_session(tfp, &tfs);
1378         if (rc) {
1379                 TFP_DRV_LOG(ERR,
1380                             "Failed to lookup session, rc:%s\n",
1381                             strerror(-rc));
1382                 return rc;
1383         }
1384
1385         /* Retrieve the device information */
1386         rc = tf_session_get_device(tfs, &dev);
1387         if (rc) {
1388                 TFP_DRV_LOG(ERR,
1389                             "Failed to lookup device, rc:%s\n",
1390                             strerror(-rc));
1391                 return rc;
1392         }
1393
1394         if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
1395                 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
1396         } else {
1397                 TFP_DRV_LOG(ERR,
1398                             "Alloc table scope not supported by device\n");
1399                 return -EINVAL;
1400         }
1401
1402         return rc;
1403 }
1404 int
1405 tf_map_tbl_scope(struct tf *tfp,
1406                    struct tf_map_tbl_scope_parms *parms)
1407 {
1408         struct tf_session *tfs;
1409         struct tf_dev_info *dev;
1410         int rc;
1411
1412         TF_CHECK_PARMS2(tfp, parms);
1413
1414         /* Retrieve the session information */
1415         rc = tf_session_get_session(tfp, &tfs);
1416         if (rc) {
1417                 TFP_DRV_LOG(ERR,
1418                             "Failed to lookup session, rc:%s\n",
1419                             strerror(-rc));
1420                 return rc;
1421         }
1422
1423         /* Retrieve the device information */
1424         rc = tf_session_get_device(tfs, &dev);
1425         if (rc) {
1426                 TFP_DRV_LOG(ERR,
1427                             "Failed to lookup device, rc:%s\n",
1428                             strerror(-rc));
1429                 return rc;
1430         }
1431
1432         if (dev->ops->tf_dev_map_tbl_scope != NULL) {
1433                 rc = dev->ops->tf_dev_map_tbl_scope(tfp, parms);
1434         } else {
1435                 TFP_DRV_LOG(ERR,
1436                             "Map table scope not supported by device\n");
1437                 return -EINVAL;
1438         }
1439
1440         return rc;
1441 }
1442
1443 int
1444 tf_free_tbl_scope(struct tf *tfp,
1445                   struct tf_free_tbl_scope_parms *parms)
1446 {
1447         struct tf_session *tfs;
1448         struct tf_dev_info *dev;
1449         int rc;
1450
1451         TF_CHECK_PARMS2(tfp, parms);
1452
1453         /* Retrieve the session information */
1454         rc = tf_session_get_session(tfp, &tfs);
1455         if (rc) {
1456                 TFP_DRV_LOG(ERR,
1457                             "Failed to lookup session, rc:%s\n",
1458                             strerror(-rc));
1459                 return rc;
1460         }
1461
1462         /* Retrieve the device information */
1463         rc = tf_session_get_device(tfs, &dev);
1464         if (rc) {
1465                 TFP_DRV_LOG(ERR,
1466                             "Failed to lookup device, rc:%s\n",
1467                             strerror(-rc));
1468                 return rc;
1469         }
1470
1471         if (dev->ops->tf_dev_free_tbl_scope) {
1472                 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
1473         } else {
1474                 TFP_DRV_LOG(ERR,
1475                             "Free table scope not supported by device\n");
1476                 return -EINVAL;
1477         }
1478
1479         return rc;
1480 }
1481
1482 int
1483 tf_set_if_tbl_entry(struct tf *tfp,
1484                     struct tf_set_if_tbl_entry_parms *parms)
1485 {
1486         int rc;
1487         struct tf_session *tfs;
1488         struct tf_dev_info *dev;
1489         struct tf_if_tbl_set_parms sparms = { 0 };
1490
1491         TF_CHECK_PARMS2(tfp, parms);
1492
1493         /* Retrieve the session information */
1494         rc = tf_session_get_session(tfp, &tfs);
1495         if (rc) {
1496                 TFP_DRV_LOG(ERR,
1497                             "%s: Failed to lookup session, rc:%s\n",
1498                             tf_dir_2_str(parms->dir),
1499                             strerror(-rc));
1500                 return rc;
1501         }
1502
1503         /* Retrieve the device information */
1504         rc = tf_session_get_device(tfs, &dev);
1505         if (rc) {
1506                 TFP_DRV_LOG(ERR,
1507                             "%s: Failed to lookup device, rc:%s\n",
1508                             tf_dir_2_str(parms->dir),
1509                             strerror(-rc));
1510                 return rc;
1511         }
1512
1513         if (dev->ops->tf_dev_set_if_tbl == NULL) {
1514                 rc = -EOPNOTSUPP;
1515                 TFP_DRV_LOG(ERR,
1516                             "%s: Operation not supported, rc:%s\n",
1517                             tf_dir_2_str(parms->dir),
1518                             strerror(-rc));
1519                 return rc;
1520         }
1521
1522         sparms.dir = parms->dir;
1523         sparms.type = parms->type;
1524         sparms.idx = parms->idx;
1525         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1526         sparms.data = parms->data;
1527
1528         rc = dev->ops->tf_dev_set_if_tbl(tfp, &sparms);
1529         if (rc) {
1530                 TFP_DRV_LOG(ERR,
1531                             "%s: If_tbl set failed, rc:%s\n",
1532                             tf_dir_2_str(parms->dir),
1533                             strerror(-rc));
1534                 return rc;
1535         }
1536
1537         return 0;
1538 }
1539
1540 int
1541 tf_get_if_tbl_entry(struct tf *tfp,
1542                     struct tf_get_if_tbl_entry_parms *parms)
1543 {
1544         int rc;
1545         struct tf_session *tfs;
1546         struct tf_dev_info *dev;
1547         struct tf_if_tbl_get_parms gparms = { 0 };
1548
1549         TF_CHECK_PARMS2(tfp, parms);
1550
1551         /* Retrieve the session information */
1552         rc = tf_session_get_session(tfp, &tfs);
1553         if (rc) {
1554                 TFP_DRV_LOG(ERR,
1555                             "%s: Failed to lookup session, rc:%s\n",
1556                             tf_dir_2_str(parms->dir),
1557                             strerror(-rc));
1558                 return rc;
1559         }
1560
1561         /* Retrieve the device information */
1562         rc = tf_session_get_device(tfs, &dev);
1563         if (rc) {
1564                 TFP_DRV_LOG(ERR,
1565                             "%s: Failed to lookup device, rc:%s\n",
1566                             tf_dir_2_str(parms->dir),
1567                             strerror(-rc));
1568                 return rc;
1569         }
1570
1571         if (dev->ops->tf_dev_get_if_tbl == NULL) {
1572                 rc = -EOPNOTSUPP;
1573                 TFP_DRV_LOG(ERR,
1574                             "%s: Operation not supported, rc:%s\n",
1575                             tf_dir_2_str(parms->dir),
1576                             strerror(-rc));
1577                 return rc;
1578         }
1579
1580         gparms.dir = parms->dir;
1581         gparms.type = parms->type;
1582         gparms.idx = parms->idx;
1583         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1584         gparms.data = parms->data;
1585
1586         rc = dev->ops->tf_dev_get_if_tbl(tfp, &gparms);
1587         if (rc) {
1588                 TFP_DRV_LOG(ERR,
1589                             "%s: If_tbl get failed, rc:%s\n",
1590                             tf_dir_2_str(parms->dir),
1591                             strerror(-rc));
1592                 return rc;
1593         }
1594
1595         return 0;
1596 }