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