net/bnxt: update copyright year
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 #include <stdio.h>
7
8 #include "tf_core.h"
9 #include "tf_util.h"
10 #include "tf_session.h"
11 #include "tf_tbl.h"
12 #include "tf_em.h"
13 #include "tf_rm.h"
14 #include "tf_global_cfg.h"
15 #include "tf_msg.h"
16 #include "tfp.h"
17 #include "bitalloc.h"
18 #include "bnxt.h"
19 #include "rand.h"
20 #include "tf_common.h"
21 #include "hwrm_tf.h"
22
23 int
24 tf_open_session(struct tf *tfp,
25                 struct tf_open_session_parms *parms)
26 {
27         int rc;
28         unsigned int domain, bus, slot, device;
29         struct tf_session_open_session_parms oparms;
30
31         TF_CHECK_PARMS2(tfp, parms);
32
33         /* Filter out any non-supported device types on the Core
34          * side. It is assumed that the Firmware will be supported if
35          * firmware open session succeeds.
36          */
37         if (parms->device_type != TF_DEVICE_TYPE_WH &&
38             parms->device_type != TF_DEVICE_TYPE_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.%u",
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.%u",
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:%u\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.%u",
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.%u",
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
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         rc = dev->ops->tf_dev_get_global_cfg(tfp, parms);
345         if (rc) {
346                 TFP_DRV_LOG(ERR,
347                             "%s: Global Cfg get failed, rc:%s\n",
348                             tf_dir_2_str(parms->dir),
349                             strerror(-rc));
350                 return rc;
351         }
352
353         return rc;
354 }
355
356 /** Set global configuration API
357  *
358  *    returns:
359  *    0       - Success
360  *    -EINVAL - Error
361  */
362 int tf_set_global_cfg(struct tf *tfp,
363                       struct tf_global_cfg_parms *parms)
364 {
365         int rc = 0;
366         struct tf_session *tfs;
367         struct tf_dev_info *dev;
368
369         TF_CHECK_PARMS2(tfp, parms);
370
371         /* Retrieve the session information */
372         rc = tf_session_get_session(tfp, &tfs);
373         if (rc) {
374                 TFP_DRV_LOG(ERR,
375                             "%s: Failed to lookup session, rc:%s\n",
376                             tf_dir_2_str(parms->dir),
377                             strerror(-rc));
378                 return rc;
379         }
380
381         /* Retrieve the device information */
382         rc = tf_session_get_device(tfs, &dev);
383         if (rc) {
384                 TFP_DRV_LOG(ERR,
385                             "%s: Failed to lookup device, rc:%s\n",
386                             tf_dir_2_str(parms->dir),
387                             strerror(-rc));
388                 return rc;
389         }
390
391         if (parms->config == NULL ||
392            parms->config_sz_in_bytes == 0) {
393                 TFP_DRV_LOG(ERR, "Invalid Argument(s)\n");
394                 return -EINVAL;
395         }
396
397         if (dev->ops->tf_dev_set_global_cfg == NULL) {
398                 rc = -EOPNOTSUPP;
399                 TFP_DRV_LOG(ERR,
400                             "%s: Operation not supported, rc:%s\n",
401                             tf_dir_2_str(parms->dir),
402                             strerror(-rc));
403                 return -EOPNOTSUPP;
404         }
405
406         rc = dev->ops->tf_dev_set_global_cfg(tfp, parms);
407         if (rc) {
408                 TFP_DRV_LOG(ERR,
409                             "%s: Global Cfg set failed, rc:%s\n",
410                             tf_dir_2_str(parms->dir),
411                             strerror(-rc));
412                 return rc;
413         }
414
415         return rc;
416 }
417
418 int
419 tf_alloc_identifier(struct tf *tfp,
420                     struct tf_alloc_identifier_parms *parms)
421 {
422         int rc;
423         struct tf_session *tfs;
424         struct tf_dev_info *dev;
425         struct tf_ident_alloc_parms aparms;
426         uint16_t id;
427
428         TF_CHECK_PARMS2(tfp, parms);
429
430         /* Can't do static initialization due to UT enum check */
431         memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
432
433         /* Retrieve the session information */
434         rc = tf_session_get_session(tfp, &tfs);
435         if (rc) {
436                 TFP_DRV_LOG(ERR,
437                             "%s: Failed to lookup session, rc:%s\n",
438                             tf_dir_2_str(parms->dir),
439                             strerror(-rc));
440                 return rc;
441         }
442
443         /* Retrieve the device information */
444         rc = tf_session_get_device(tfs, &dev);
445         if (rc) {
446                 TFP_DRV_LOG(ERR,
447                             "%s: Failed to lookup device, rc:%s\n",
448                             tf_dir_2_str(parms->dir),
449                             strerror(-rc));
450                 return rc;
451         }
452
453         if (dev->ops->tf_dev_alloc_ident == NULL) {
454                 rc = -EOPNOTSUPP;
455                 TFP_DRV_LOG(ERR,
456                             "%s: Operation not supported, rc:%s\n",
457                             tf_dir_2_str(parms->dir),
458                             strerror(-rc));
459                 return -EOPNOTSUPP;
460         }
461
462         aparms.dir = parms->dir;
463         aparms.type = parms->ident_type;
464         aparms.id = &id;
465         rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
466         if (rc) {
467                 TFP_DRV_LOG(ERR,
468                             "%s: Identifier allocation failed, rc:%s\n",
469                             tf_dir_2_str(parms->dir),
470                             strerror(-rc));
471                 return rc;
472         }
473
474         parms->id = id;
475
476         return 0;
477 }
478
479 int
480 tf_free_identifier(struct tf *tfp,
481                    struct tf_free_identifier_parms *parms)
482 {
483         int rc;
484         struct tf_session *tfs;
485         struct tf_dev_info *dev;
486         struct tf_ident_free_parms fparms;
487
488         TF_CHECK_PARMS2(tfp, parms);
489
490         /* Can't do static initialization due to UT enum check */
491         memset(&fparms, 0, sizeof(struct tf_ident_free_parms));
492
493         /* Retrieve the session information */
494         rc = tf_session_get_session(tfp, &tfs);
495         if (rc) {
496                 TFP_DRV_LOG(ERR,
497                             "%s: Failed to lookup session, rc:%s\n",
498                             tf_dir_2_str(parms->dir),
499                             strerror(-rc));
500                 return rc;
501         }
502
503         /* Retrieve the device information */
504         rc = tf_session_get_device(tfs, &dev);
505         if (rc) {
506                 TFP_DRV_LOG(ERR,
507                             "%s: Failed to lookup device, rc:%s\n",
508                             tf_dir_2_str(parms->dir),
509                             strerror(-rc));
510                 return rc;
511         }
512
513         if (dev->ops->tf_dev_free_ident == NULL) {
514                 rc = -EOPNOTSUPP;
515                 TFP_DRV_LOG(ERR,
516                             "%s: Operation not supported, rc:%s\n",
517                             tf_dir_2_str(parms->dir),
518                             strerror(-rc));
519                 return -EOPNOTSUPP;
520         }
521
522         fparms.dir = parms->dir;
523         fparms.type = parms->ident_type;
524         fparms.id = parms->id;
525         fparms.ref_cnt = &parms->ref_cnt;
526         rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
527         if (rc) {
528                 TFP_DRV_LOG(ERR,
529                             "%s: Identifier free failed, rc:%s\n",
530                             tf_dir_2_str(parms->dir),
531                             strerror(-rc));
532                 return rc;
533         }
534
535         return 0;
536 }
537
538 int
539 tf_search_identifier(struct tf *tfp,
540                      struct tf_search_identifier_parms *parms)
541 {
542         int rc;
543         struct tf_session *tfs;
544         struct tf_dev_info *dev;
545         struct tf_ident_search_parms sparms;
546
547         TF_CHECK_PARMS2(tfp, parms);
548
549         /* Can't do static initialization due to UT enum check */
550         memset(&sparms, 0, sizeof(struct tf_ident_search_parms));
551
552         /* Retrieve the session information */
553         rc = tf_session_get_session(tfp, &tfs);
554         if (rc) {
555                 TFP_DRV_LOG(ERR,
556                             "%s: Failed to lookup session, rc:%s\n",
557                             tf_dir_2_str(parms->dir),
558                             strerror(-rc));
559                 return rc;
560         }
561
562         /* Retrieve the device information */
563         rc = tf_session_get_device(tfs, &dev);
564         if (rc) {
565                 TFP_DRV_LOG(ERR,
566                             "%s: Failed to lookup device, rc:%s\n",
567                             tf_dir_2_str(parms->dir),
568                             strerror(-rc));
569                 return rc;
570         }
571
572         if (dev->ops->tf_dev_search_ident == NULL) {
573                 rc = -EOPNOTSUPP;
574                 TFP_DRV_LOG(ERR,
575                             "%s: Operation not supported, rc:%s\n",
576                             tf_dir_2_str(parms->dir),
577                             strerror(-rc));
578                 return rc;
579         }
580
581         sparms.dir = parms->dir;
582         sparms.type = parms->ident_type;
583         sparms.search_id = parms->search_id;
584         sparms.hit = &parms->hit;
585         sparms.ref_cnt = &parms->ref_cnt;
586         rc = dev->ops->tf_dev_search_ident(tfp, &sparms);
587         if (rc) {
588                 TFP_DRV_LOG(ERR,
589                             "%s: Identifier search failed, rc:%s\n",
590                             tf_dir_2_str(parms->dir),
591                             strerror(-rc));
592                 return rc;
593         }
594
595         return 0;
596 }
597
598 int
599 tf_search_tcam_entry(struct tf *tfp,
600                      struct tf_search_tcam_entry_parms *parms)
601 {
602         int rc;
603         struct tf_session *tfs;
604         struct tf_dev_info *dev;
605         struct tf_tcam_alloc_search_parms sparms;
606
607         TF_CHECK_PARMS2(tfp, parms);
608
609         memset(&sparms, 0, sizeof(struct tf_tcam_alloc_search_parms));
610
611         /* Retrieve the session information */
612         rc = tf_session_get_session(tfp, &tfs);
613         if (rc) {
614                 TFP_DRV_LOG(ERR,
615                             "%s: Failed to lookup session, rc:%s\n",
616                             tf_dir_2_str(parms->dir),
617                             strerror(-rc));
618                 return rc;
619         }
620
621         /* Retrieve the device information */
622         rc = tf_session_get_device(tfs, &dev);
623         if (rc) {
624                 TFP_DRV_LOG(ERR,
625                             "%s: Failed to lookup device, rc:%s\n",
626                             tf_dir_2_str(parms->dir),
627                             strerror(-rc));
628                 return rc;
629         }
630
631         if (dev->ops->tf_dev_alloc_search_tcam == NULL) {
632                 rc = -EOPNOTSUPP;
633                 TFP_DRV_LOG(ERR,
634                             "%s: Operation not supported, rc:%s\n",
635                             tf_dir_2_str(parms->dir),
636                             strerror(-rc));
637                 return rc;
638         }
639
640         sparms.dir = parms->dir;
641         sparms.type = parms->tcam_tbl_type;
642         sparms.key = parms->key;
643         sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
644         sparms.mask = parms->mask;
645         sparms.priority = parms->priority;
646         sparms.alloc = parms->alloc;
647
648         /* Result is an in/out and so no need to copy during outputs */
649         sparms.result = parms->result;
650         sparms.result_size =
651                 TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
652
653         rc = dev->ops->tf_dev_alloc_search_tcam(tfp, &sparms);
654         if (rc) {
655                 TFP_DRV_LOG(ERR,
656                             "%s: TCAM allocation failed, rc:%s\n",
657                             tf_dir_2_str(parms->dir),
658                             strerror(-rc));
659                 return rc;
660         }
661
662         /* Copy the outputs */
663         parms->hit = sparms.hit;
664         parms->search_status = sparms.search_status;
665         parms->ref_cnt = sparms.ref_cnt;
666         parms->idx = sparms.idx;
667
668         return 0;
669 }
670
671 int
672 tf_alloc_tcam_entry(struct tf *tfp,
673                     struct tf_alloc_tcam_entry_parms *parms)
674 {
675         int rc;
676         struct tf_session *tfs;
677         struct tf_dev_info *dev;
678         struct tf_tcam_alloc_parms aparms;
679
680         TF_CHECK_PARMS2(tfp, parms);
681
682         memset(&aparms, 0, sizeof(struct tf_tcam_alloc_parms));
683
684         /* Retrieve the session information */
685         rc = tf_session_get_session(tfp, &tfs);
686         if (rc) {
687                 TFP_DRV_LOG(ERR,
688                             "%s: Failed to lookup session, rc:%s\n",
689                             tf_dir_2_str(parms->dir),
690                             strerror(-rc));
691                 return rc;
692         }
693
694         /* Retrieve the device information */
695         rc = tf_session_get_device(tfs, &dev);
696         if (rc) {
697                 TFP_DRV_LOG(ERR,
698                             "%s: Failed to lookup device, rc:%s\n",
699                             tf_dir_2_str(parms->dir),
700                             strerror(-rc));
701                 return rc;
702         }
703
704         if (dev->ops->tf_dev_alloc_tcam == NULL) {
705                 rc = -EOPNOTSUPP;
706                 TFP_DRV_LOG(ERR,
707                             "%s: Operation not supported, rc:%s\n",
708                             tf_dir_2_str(parms->dir),
709                             strerror(-rc));
710                 return rc;
711         }
712
713         aparms.dir = parms->dir;
714         aparms.type = parms->tcam_tbl_type;
715         aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
716         aparms.priority = parms->priority;
717         rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
718         if (rc) {
719                 TFP_DRV_LOG(ERR,
720                             "%s: TCAM allocation failed, rc:%s\n",
721                             tf_dir_2_str(parms->dir),
722                             strerror(-rc));
723                 return rc;
724         }
725
726         parms->idx = aparms.idx;
727
728         return 0;
729 }
730
731 int
732 tf_set_tcam_entry(struct tf *tfp,
733                   struct tf_set_tcam_entry_parms *parms)
734 {
735         int rc;
736         struct tf_session *tfs;
737         struct tf_dev_info *dev;
738         struct tf_tcam_set_parms sparms;
739
740         TF_CHECK_PARMS2(tfp, parms);
741
742         memset(&sparms, 0, sizeof(struct tf_tcam_set_parms));
743
744
745         /* Retrieve the session information */
746         rc = tf_session_get_session(tfp, &tfs);
747         if (rc) {
748                 TFP_DRV_LOG(ERR,
749                             "%s: Failed to lookup session, rc:%s\n",
750                             tf_dir_2_str(parms->dir),
751                             strerror(-rc));
752                 return rc;
753         }
754
755         /* Retrieve the device information */
756         rc = tf_session_get_device(tfs, &dev);
757         if (rc) {
758                 TFP_DRV_LOG(ERR,
759                             "%s: Failed to lookup device, rc:%s\n",
760                             tf_dir_2_str(parms->dir),
761                             strerror(-rc));
762                 return rc;
763         }
764
765         if (dev->ops->tf_dev_set_tcam == NULL) {
766                 rc = -EOPNOTSUPP;
767                 TFP_DRV_LOG(ERR,
768                             "%s: Operation not supported, rc:%s\n",
769                             tf_dir_2_str(parms->dir),
770                             strerror(-rc));
771                 return rc;
772         }
773
774         sparms.dir = parms->dir;
775         sparms.type = parms->tcam_tbl_type;
776         sparms.idx = parms->idx;
777         sparms.key = parms->key;
778         sparms.mask = parms->mask;
779         sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
780         sparms.result = parms->result;
781         sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
782
783         rc = dev->ops->tf_dev_set_tcam(tfp, &sparms);
784         if (rc) {
785                 TFP_DRV_LOG(ERR,
786                             "%s: TCAM set failed, rc:%s\n",
787                             tf_dir_2_str(parms->dir),
788                             strerror(-rc));
789                 return rc;
790         }
791
792         return 0;
793 }
794
795 int
796 tf_get_tcam_entry(struct tf *tfp __rte_unused,
797                   struct tf_get_tcam_entry_parms *parms __rte_unused)
798 {
799         TF_CHECK_PARMS2(tfp, parms);
800         return -EOPNOTSUPP;
801 }
802
803 int
804 tf_free_tcam_entry(struct tf *tfp,
805                    struct tf_free_tcam_entry_parms *parms)
806 {
807         int rc;
808         struct tf_session *tfs;
809         struct tf_dev_info *dev;
810         struct tf_tcam_free_parms fparms;
811
812         TF_CHECK_PARMS2(tfp, parms);
813
814         memset(&fparms, 0, sizeof(struct tf_tcam_free_parms));
815
816         /* Retrieve the session information */
817         rc = tf_session_get_session(tfp, &tfs);
818         if (rc) {
819                 TFP_DRV_LOG(ERR,
820                             "%s: Failed to lookup session, rc:%s\n",
821                             tf_dir_2_str(parms->dir),
822                             strerror(-rc));
823                 return rc;
824         }
825
826         /* Retrieve the device information */
827         rc = tf_session_get_device(tfs, &dev);
828         if (rc) {
829                 TFP_DRV_LOG(ERR,
830                             "%s: Failed to lookup device, rc:%s\n",
831                             tf_dir_2_str(parms->dir),
832                             strerror(-rc));
833                 return rc;
834         }
835
836         if (dev->ops->tf_dev_free_tcam == NULL) {
837                 rc = -EOPNOTSUPP;
838                 TFP_DRV_LOG(ERR,
839                             "%s: Operation not supported, rc:%s\n",
840                             tf_dir_2_str(parms->dir),
841                             strerror(-rc));
842                 return rc;
843         }
844
845         fparms.dir = parms->dir;
846         fparms.type = parms->tcam_tbl_type;
847         fparms.idx = parms->idx;
848         rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
849         if (rc) {
850                 TFP_DRV_LOG(ERR,
851                             "%s: TCAM free failed, rc:%s\n",
852                             tf_dir_2_str(parms->dir),
853                             strerror(-rc));
854                 return rc;
855         }
856
857         return 0;
858 }
859
860 int
861 tf_alloc_tbl_entry(struct tf *tfp,
862                    struct tf_alloc_tbl_entry_parms *parms)
863 {
864         int rc;
865         struct tf_session *tfs;
866         struct tf_dev_info *dev;
867         struct tf_tbl_alloc_parms aparms;
868         uint32_t idx;
869
870         TF_CHECK_PARMS2(tfp, parms);
871
872         /* Can't do static initialization due to UT enum check */
873         memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
874
875         /* Retrieve the session information */
876         rc = tf_session_get_session(tfp, &tfs);
877         if (rc) {
878                 TFP_DRV_LOG(ERR,
879                             "%s: Failed to lookup session, rc:%s\n",
880                             tf_dir_2_str(parms->dir),
881                             strerror(-rc));
882                 return rc;
883         }
884
885         /* Retrieve the device information */
886         rc = tf_session_get_device(tfs, &dev);
887         if (rc) {
888                 TFP_DRV_LOG(ERR,
889                             "%s: Failed to lookup device, rc:%s\n",
890                             tf_dir_2_str(parms->dir),
891                             strerror(-rc));
892                 return rc;
893         }
894
895         aparms.dir = parms->dir;
896         aparms.type = parms->type;
897         aparms.idx = &idx;
898         aparms.tbl_scope_id = parms->tbl_scope_id;
899
900         if (parms->type == TF_TBL_TYPE_EXT) {
901                 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) {
902                         rc = -EOPNOTSUPP;
903                         TFP_DRV_LOG(ERR,
904                                     "%s: Operation not supported, rc:%s\n",
905                                     tf_dir_2_str(parms->dir),
906                                     strerror(-rc));
907                         return -EOPNOTSUPP;
908                 }
909
910                 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
911                 if (rc) {
912                         TFP_DRV_LOG(ERR,
913                                     "%s: External table allocation failed, rc:%s\n",
914                                     tf_dir_2_str(parms->dir),
915                                     strerror(-rc));
916                         return rc;
917                 }
918
919         } else {
920                 if (dev->ops->tf_dev_alloc_tbl == NULL) {
921                         rc = -EOPNOTSUPP;
922                         TFP_DRV_LOG(ERR,
923                                     "%s: Operation not supported, rc:%s\n",
924                                     tf_dir_2_str(parms->dir),
925                                     strerror(-rc));
926                         return -EOPNOTSUPP;
927                 }
928
929                 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
930                 if (rc) {
931                         TFP_DRV_LOG(ERR,
932                                     "%s: Table allocation failed, rc:%s\n",
933                                     tf_dir_2_str(parms->dir),
934                                     strerror(-rc));
935                         return rc;
936                 }
937         }
938
939         parms->idx = idx;
940
941         return 0;
942 }
943
944 int
945 tf_search_tbl_entry(struct tf *tfp,
946                     struct tf_search_tbl_entry_parms *parms)
947 {
948         int rc;
949         struct tf_session *tfs;
950         struct tf_dev_info *dev;
951         struct tf_tbl_alloc_search_parms sparms;
952
953         TF_CHECK_PARMS2(tfp, parms);
954
955         /* Retrieve the session information */
956         rc = tf_session_get_session(tfp, &tfs);
957         if (rc) {
958                 TFP_DRV_LOG(ERR,
959                             "%s: Failed to lookup session, rc:%s\n",
960                             tf_dir_2_str(parms->dir),
961                             strerror(-rc));
962                 return rc;
963         }
964
965         /* Retrieve the device information */
966         rc = tf_session_get_device(tfs, &dev);
967         if (rc) {
968                 TFP_DRV_LOG(ERR,
969                             "%s: Failed to lookup device, rc:%s\n",
970                             tf_dir_2_str(parms->dir),
971                             strerror(-rc));
972                 return rc;
973         }
974
975         if (dev->ops->tf_dev_alloc_search_tbl == NULL) {
976                 rc = -EOPNOTSUPP;
977                 TFP_DRV_LOG(ERR,
978                             "%s: Operation not supported, rc:%s\n",
979                             tf_dir_2_str(parms->dir),
980                             strerror(-rc));
981                 return rc;
982         }
983
984         memset(&sparms, 0, sizeof(struct tf_tbl_alloc_search_parms));
985         sparms.dir = parms->dir;
986         sparms.type = parms->type;
987         sparms.result = parms->result;
988         sparms.result_sz_in_bytes = parms->result_sz_in_bytes;
989         sparms.alloc = parms->alloc;
990         sparms.tbl_scope_id = parms->tbl_scope_id;
991         rc = dev->ops->tf_dev_alloc_search_tbl(tfp, &sparms);
992         if (rc) {
993                 TFP_DRV_LOG(ERR,
994                             "%s: TBL allocation failed, rc:%s\n",
995                             tf_dir_2_str(parms->dir),
996                             strerror(-rc));
997                 return rc;
998         }
999
1000         /* Return the outputs from the search */
1001         parms->hit = sparms.hit;
1002         parms->search_status = sparms.search_status;
1003         parms->ref_cnt = sparms.ref_cnt;
1004         parms->idx = sparms.idx;
1005
1006         return 0;
1007 }
1008
1009 int
1010 tf_free_tbl_entry(struct tf *tfp,
1011                   struct tf_free_tbl_entry_parms *parms)
1012 {
1013         int rc;
1014         struct tf_session *tfs;
1015         struct tf_dev_info *dev;
1016         struct tf_tbl_free_parms fparms;
1017
1018         TF_CHECK_PARMS2(tfp, parms);
1019
1020         /* Can't do static initialization due to UT enum check */
1021         memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
1022
1023         /* Retrieve the session information */
1024         rc = tf_session_get_session(tfp, &tfs);
1025         if (rc) {
1026                 TFP_DRV_LOG(ERR,
1027                             "%s: Failed to lookup session, rc:%s\n",
1028                             tf_dir_2_str(parms->dir),
1029                             strerror(-rc));
1030                 return rc;
1031         }
1032
1033         /* Retrieve the device information */
1034         rc = tf_session_get_device(tfs, &dev);
1035         if (rc) {
1036                 TFP_DRV_LOG(ERR,
1037                             "%s: Failed to lookup device, rc:%s\n",
1038                             tf_dir_2_str(parms->dir),
1039                             strerror(-rc));
1040                 return rc;
1041         }
1042
1043         fparms.dir = parms->dir;
1044         fparms.type = parms->type;
1045         fparms.idx = parms->idx;
1046         fparms.tbl_scope_id = parms->tbl_scope_id;
1047
1048         if (parms->type == TF_TBL_TYPE_EXT) {
1049                 if (dev->ops->tf_dev_free_ext_tbl == NULL) {
1050                         rc = -EOPNOTSUPP;
1051                         TFP_DRV_LOG(ERR,
1052                                     "%s: Operation not supported, rc:%s\n",
1053                                     tf_dir_2_str(parms->dir),
1054                                     strerror(-rc));
1055                         return -EOPNOTSUPP;
1056                 }
1057
1058                 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms);
1059                 if (rc) {
1060                         TFP_DRV_LOG(ERR,
1061                                     "%s: Table free failed, rc:%s\n",
1062                                     tf_dir_2_str(parms->dir),
1063                                     strerror(-rc));
1064                         return rc;
1065                 }
1066         } else {
1067                 if (dev->ops->tf_dev_free_tbl == NULL) {
1068                         rc = -EOPNOTSUPP;
1069                         TFP_DRV_LOG(ERR,
1070                                     "%s: Operation not supported, rc:%s\n",
1071                                     tf_dir_2_str(parms->dir),
1072                                     strerror(-rc));
1073                         return -EOPNOTSUPP;
1074                 }
1075
1076                 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
1077                 if (rc) {
1078                         TFP_DRV_LOG(ERR,
1079                                     "%s: Table free failed, rc:%s\n",
1080                                     tf_dir_2_str(parms->dir),
1081                                     strerror(-rc));
1082                         return rc;
1083                 }
1084         }
1085
1086         return 0;
1087 }
1088
1089 int
1090 tf_set_tbl_entry(struct tf *tfp,
1091                  struct tf_set_tbl_entry_parms *parms)
1092 {
1093         int rc = 0;
1094         struct tf_session *tfs;
1095         struct tf_dev_info *dev;
1096         struct tf_tbl_set_parms sparms;
1097
1098         TF_CHECK_PARMS3(tfp, parms, parms->data);
1099
1100         /* Can't do static initialization due to UT enum check */
1101         memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
1102
1103         /* Retrieve the session information */
1104         rc = tf_session_get_session(tfp, &tfs);
1105         if (rc) {
1106                 TFP_DRV_LOG(ERR,
1107                             "%s: Failed to lookup session, rc:%s\n",
1108                             tf_dir_2_str(parms->dir),
1109                             strerror(-rc));
1110                 return rc;
1111         }
1112
1113         /* Retrieve the device information */
1114         rc = tf_session_get_device(tfs, &dev);
1115         if (rc) {
1116                 TFP_DRV_LOG(ERR,
1117                             "%s: Failed to lookup device, rc:%s\n",
1118                             tf_dir_2_str(parms->dir),
1119                             strerror(-rc));
1120                 return rc;
1121         }
1122
1123         sparms.dir = parms->dir;
1124         sparms.type = parms->type;
1125         sparms.data = parms->data;
1126         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1127         sparms.idx = parms->idx;
1128         sparms.tbl_scope_id = parms->tbl_scope_id;
1129
1130         if (parms->type == TF_TBL_TYPE_EXT) {
1131                 if (dev->ops->tf_dev_set_ext_tbl == NULL) {
1132                         rc = -EOPNOTSUPP;
1133                         TFP_DRV_LOG(ERR,
1134                                     "%s: Operation not supported, rc:%s\n",
1135                                     tf_dir_2_str(parms->dir),
1136                                     strerror(-rc));
1137                         return -EOPNOTSUPP;
1138                 }
1139
1140                 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms);
1141                 if (rc) {
1142                         TFP_DRV_LOG(ERR,
1143                                     "%s: Table set failed, rc:%s\n",
1144                                     tf_dir_2_str(parms->dir),
1145                                     strerror(-rc));
1146                         return rc;
1147                 }
1148         } else {
1149                 if (dev->ops->tf_dev_set_tbl == NULL) {
1150                         rc = -EOPNOTSUPP;
1151                         TFP_DRV_LOG(ERR,
1152                                     "%s: Operation not supported, rc:%s\n",
1153                                     tf_dir_2_str(parms->dir),
1154                                     strerror(-rc));
1155                         return -EOPNOTSUPP;
1156                 }
1157
1158                 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
1159                 if (rc) {
1160                         TFP_DRV_LOG(ERR,
1161                                     "%s: Table set failed, rc:%s\n",
1162                                     tf_dir_2_str(parms->dir),
1163                                     strerror(-rc));
1164                         return rc;
1165                 }
1166         }
1167
1168         return rc;
1169 }
1170
1171 int
1172 tf_get_tbl_entry(struct tf *tfp,
1173                  struct tf_get_tbl_entry_parms *parms)
1174 {
1175         int rc = 0;
1176         struct tf_session *tfs;
1177         struct tf_dev_info *dev;
1178         struct tf_tbl_get_parms gparms;
1179
1180         TF_CHECK_PARMS3(tfp, parms, parms->data);
1181
1182         /* Can't do static initialization due to UT enum check */
1183         memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
1184
1185         /* Retrieve the session information */
1186         rc = tf_session_get_session(tfp, &tfs);
1187         if (rc) {
1188                 TFP_DRV_LOG(ERR,
1189                             "%s: Failed to lookup session, rc:%s\n",
1190                             tf_dir_2_str(parms->dir),
1191                             strerror(-rc));
1192                 return rc;
1193         }
1194
1195         /* Retrieve the device information */
1196         rc = tf_session_get_device(tfs, &dev);
1197         if (rc) {
1198                 TFP_DRV_LOG(ERR,
1199                             "%s: Failed to lookup device, rc:%s\n",
1200                             tf_dir_2_str(parms->dir),
1201                             strerror(-rc));
1202                 return rc;
1203         }
1204
1205         if (dev->ops->tf_dev_get_tbl == NULL) {
1206                 rc = -EOPNOTSUPP;
1207                 TFP_DRV_LOG(ERR,
1208                             "%s: Operation not supported, rc:%s\n",
1209                             tf_dir_2_str(parms->dir),
1210                             strerror(-rc));
1211                 return -EOPNOTSUPP;
1212         }
1213
1214         gparms.dir = parms->dir;
1215         gparms.type = parms->type;
1216         gparms.data = parms->data;
1217         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1218         gparms.idx = parms->idx;
1219         rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
1220         if (rc) {
1221                 TFP_DRV_LOG(ERR,
1222                             "%s: Table get failed, rc:%s\n",
1223                             tf_dir_2_str(parms->dir),
1224                             strerror(-rc));
1225                 return rc;
1226         }
1227
1228         return rc;
1229 }
1230
1231 int
1232 tf_bulk_get_tbl_entry(struct tf *tfp,
1233                  struct tf_bulk_get_tbl_entry_parms *parms)
1234 {
1235         int rc = 0;
1236         struct tf_session *tfs;
1237         struct tf_dev_info *dev;
1238         struct tf_tbl_get_bulk_parms bparms;
1239
1240         TF_CHECK_PARMS2(tfp, parms);
1241
1242         /* Can't do static initialization due to UT enum check */
1243         memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
1244
1245         /* Retrieve the session information */
1246         rc = tf_session_get_session(tfp, &tfs);
1247         if (rc) {
1248                 TFP_DRV_LOG(ERR,
1249                             "%s: Failed to lookup session, rc:%s\n",
1250                             tf_dir_2_str(parms->dir),
1251                             strerror(-rc));
1252                 return rc;
1253         }
1254
1255         /* Retrieve the device information */
1256         rc = tf_session_get_device(tfs, &dev);
1257         if (rc) {
1258                 TFP_DRV_LOG(ERR,
1259                             "%s: Failed to lookup device, rc:%s\n",
1260                             tf_dir_2_str(parms->dir),
1261                             strerror(-rc));
1262                 return rc;
1263         }
1264
1265         if (parms->type == TF_TBL_TYPE_EXT) {
1266                 /* Not supported, yet */
1267                 rc = -EOPNOTSUPP;
1268                 TFP_DRV_LOG(ERR,
1269                             "%s, External table type not supported, rc:%s\n",
1270                             tf_dir_2_str(parms->dir),
1271                             strerror(-rc));
1272
1273                 return rc;
1274         }
1275
1276         /* Internal table type processing */
1277
1278         if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
1279                 rc = -EOPNOTSUPP;
1280                 TFP_DRV_LOG(ERR,
1281                             "%s: Operation not supported, rc:%s\n",
1282                             tf_dir_2_str(parms->dir),
1283                             strerror(-rc));
1284                 return -EOPNOTSUPP;
1285         }
1286
1287         bparms.dir = parms->dir;
1288         bparms.type = parms->type;
1289         bparms.starting_idx = parms->starting_idx;
1290         bparms.num_entries = parms->num_entries;
1291         bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
1292         bparms.physical_mem_addr = parms->physical_mem_addr;
1293         rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
1294         if (rc) {
1295                 TFP_DRV_LOG(ERR,
1296                             "%s: Table get bulk failed, rc:%s\n",
1297                             tf_dir_2_str(parms->dir),
1298                             strerror(-rc));
1299                 return rc;
1300         }
1301
1302         return rc;
1303 }
1304
1305 int
1306 tf_alloc_tbl_scope(struct tf *tfp,
1307                    struct tf_alloc_tbl_scope_parms *parms)
1308 {
1309         struct tf_session *tfs;
1310         struct tf_dev_info *dev;
1311         int rc;
1312
1313         TF_CHECK_PARMS2(tfp, parms);
1314
1315         /* Retrieve the session information */
1316         rc = tf_session_get_session(tfp, &tfs);
1317         if (rc) {
1318                 TFP_DRV_LOG(ERR,
1319                             "Failed to lookup session, rc:%s\n",
1320                             strerror(-rc));
1321                 return rc;
1322         }
1323
1324         /* Retrieve the device information */
1325         rc = tf_session_get_device(tfs, &dev);
1326         if (rc) {
1327                 TFP_DRV_LOG(ERR,
1328                             "Failed to lookup device, rc:%s\n",
1329                             strerror(-rc));
1330                 return rc;
1331         }
1332
1333         if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
1334                 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
1335         } else {
1336                 TFP_DRV_LOG(ERR,
1337                             "Alloc table scope not supported by device\n");
1338                 return -EINVAL;
1339         }
1340
1341         return rc;
1342 }
1343 int
1344 tf_map_tbl_scope(struct tf *tfp,
1345                    struct tf_map_tbl_scope_parms *parms)
1346 {
1347         struct tf_session *tfs;
1348         struct tf_dev_info *dev;
1349         int rc;
1350
1351         TF_CHECK_PARMS2(tfp, parms);
1352
1353         /* Retrieve the session information */
1354         rc = tf_session_get_session(tfp, &tfs);
1355         if (rc) {
1356                 TFP_DRV_LOG(ERR,
1357                             "Failed to lookup session, rc:%s\n",
1358                             strerror(-rc));
1359                 return rc;
1360         }
1361
1362         /* Retrieve the device information */
1363         rc = tf_session_get_device(tfs, &dev);
1364         if (rc) {
1365                 TFP_DRV_LOG(ERR,
1366                             "Failed to lookup device, rc:%s\n",
1367                             strerror(-rc));
1368                 return rc;
1369         }
1370
1371         if (dev->ops->tf_dev_map_tbl_scope != NULL) {
1372                 rc = dev->ops->tf_dev_map_tbl_scope(tfp, parms);
1373         } else {
1374                 TFP_DRV_LOG(ERR,
1375                             "Map table scope not supported by device\n");
1376                 return -EINVAL;
1377         }
1378
1379         return rc;
1380 }
1381
1382 int
1383 tf_free_tbl_scope(struct tf *tfp,
1384                   struct tf_free_tbl_scope_parms *parms)
1385 {
1386         struct tf_session *tfs;
1387         struct tf_dev_info *dev;
1388         int rc;
1389
1390         TF_CHECK_PARMS2(tfp, parms);
1391
1392         /* Retrieve the session information */
1393         rc = tf_session_get_session(tfp, &tfs);
1394         if (rc) {
1395                 TFP_DRV_LOG(ERR,
1396                             "Failed to lookup session, rc:%s\n",
1397                             strerror(-rc));
1398                 return rc;
1399         }
1400
1401         /* Retrieve the device information */
1402         rc = tf_session_get_device(tfs, &dev);
1403         if (rc) {
1404                 TFP_DRV_LOG(ERR,
1405                             "Failed to lookup device, rc:%s\n",
1406                             strerror(-rc));
1407                 return rc;
1408         }
1409
1410         if (dev->ops->tf_dev_free_tbl_scope) {
1411                 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
1412         } else {
1413                 TFP_DRV_LOG(ERR,
1414                             "Free table scope not supported by device\n");
1415                 return -EINVAL;
1416         }
1417
1418         return rc;
1419 }
1420
1421 int
1422 tf_set_if_tbl_entry(struct tf *tfp,
1423                     struct tf_set_if_tbl_entry_parms *parms)
1424 {
1425         int rc;
1426         struct tf_session *tfs;
1427         struct tf_dev_info *dev;
1428         struct tf_if_tbl_set_parms sparms = { 0 };
1429
1430         TF_CHECK_PARMS2(tfp, parms);
1431
1432         /* Retrieve the session information */
1433         rc = tf_session_get_session(tfp, &tfs);
1434         if (rc) {
1435                 TFP_DRV_LOG(ERR,
1436                             "%s: Failed to lookup session, rc:%s\n",
1437                             tf_dir_2_str(parms->dir),
1438                             strerror(-rc));
1439                 return rc;
1440         }
1441
1442         /* Retrieve the device information */
1443         rc = tf_session_get_device(tfs, &dev);
1444         if (rc) {
1445                 TFP_DRV_LOG(ERR,
1446                             "%s: Failed to lookup device, rc:%s\n",
1447                             tf_dir_2_str(parms->dir),
1448                             strerror(-rc));
1449                 return rc;
1450         }
1451
1452         if (dev->ops->tf_dev_set_if_tbl == NULL) {
1453                 rc = -EOPNOTSUPP;
1454                 TFP_DRV_LOG(ERR,
1455                             "%s: Operation not supported, rc:%s\n",
1456                             tf_dir_2_str(parms->dir),
1457                             strerror(-rc));
1458                 return rc;
1459         }
1460
1461         sparms.dir = parms->dir;
1462         sparms.type = parms->type;
1463         sparms.idx = parms->idx;
1464         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1465         sparms.data = parms->data;
1466
1467         rc = dev->ops->tf_dev_set_if_tbl(tfp, &sparms);
1468         if (rc) {
1469                 TFP_DRV_LOG(ERR,
1470                             "%s: If_tbl set failed, rc:%s\n",
1471                             tf_dir_2_str(parms->dir),
1472                             strerror(-rc));
1473                 return rc;
1474         }
1475
1476         return 0;
1477 }
1478
1479 int
1480 tf_get_if_tbl_entry(struct tf *tfp,
1481                     struct tf_get_if_tbl_entry_parms *parms)
1482 {
1483         int rc;
1484         struct tf_session *tfs;
1485         struct tf_dev_info *dev;
1486         struct tf_if_tbl_get_parms gparms = { 0 };
1487
1488         TF_CHECK_PARMS2(tfp, parms);
1489
1490         /* Retrieve the session information */
1491         rc = tf_session_get_session(tfp, &tfs);
1492         if (rc) {
1493                 TFP_DRV_LOG(ERR,
1494                             "%s: Failed to lookup session, rc:%s\n",
1495                             tf_dir_2_str(parms->dir),
1496                             strerror(-rc));
1497                 return rc;
1498         }
1499
1500         /* Retrieve the device information */
1501         rc = tf_session_get_device(tfs, &dev);
1502         if (rc) {
1503                 TFP_DRV_LOG(ERR,
1504                             "%s: Failed to lookup device, rc:%s\n",
1505                             tf_dir_2_str(parms->dir),
1506                             strerror(-rc));
1507                 return rc;
1508         }
1509
1510         if (dev->ops->tf_dev_get_if_tbl == NULL) {
1511                 rc = -EOPNOTSUPP;
1512                 TFP_DRV_LOG(ERR,
1513                             "%s: Operation not supported, rc:%s\n",
1514                             tf_dir_2_str(parms->dir),
1515                             strerror(-rc));
1516                 return rc;
1517         }
1518
1519         gparms.dir = parms->dir;
1520         gparms.type = parms->type;
1521         gparms.idx = parms->idx;
1522         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
1523         gparms.data = parms->data;
1524
1525         rc = dev->ops->tf_dev_get_if_tbl(tfp, &gparms);
1526         if (rc) {
1527                 TFP_DRV_LOG(ERR,
1528                             "%s: If_tbl get failed, rc:%s\n",
1529                             tf_dir_2_str(parms->dir),
1530                             strerror(-rc));
1531                 return rc;
1532         }
1533
1534         return 0;
1535 }