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