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