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