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