net/bnxt: add external action allocate and free
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #include <stdio.h>
7
8 #include "tf_core.h"
9 #include "tf_util.h"
10 #include "tf_session.h"
11 #include "tf_tbl.h"
12 #include "tf_em.h"
13 #include "tf_rm.h"
14 #include "tf_msg.h"
15 #include "tfp.h"
16 #include "bitalloc.h"
17 #include "bnxt.h"
18 #include "rand.h"
19 #include "tf_common.h"
20 #include "hwrm_tf.h"
21
22 int
23 tf_open_session(struct tf *tfp,
24                 struct tf_open_session_parms *parms)
25 {
26         int rc;
27         unsigned int domain, bus, slot, device;
28         struct tf_session_open_session_parms oparms;
29
30         TF_CHECK_PARMS2(tfp, parms);
31
32         /* Filter out any non-supported device types on the Core
33          * side. It is assumed that the Firmware will be supported if
34          * firmware open session succeeds.
35          */
36         if (parms->device_type != TF_DEVICE_TYPE_WH) {
37                 TFP_DRV_LOG(ERR,
38                             "Unsupported device type %d\n",
39                             parms->device_type);
40                 return -ENOTSUP;
41         }
42
43         /* Verify control channel and build the beginning of session_id */
44         rc = sscanf(parms->ctrl_chan_name,
45                     "%x:%x:%x.%d",
46                     &domain,
47                     &bus,
48                     &slot,
49                     &device);
50         if (rc != 4) {
51                 TFP_DRV_LOG(ERR,
52                             "Failed to scan device ctrl_chan_name\n");
53                 return -EINVAL;
54         }
55
56         parms->session_id.internal.domain = domain;
57         parms->session_id.internal.bus = bus;
58         parms->session_id.internal.device = device;
59         oparms.open_cfg = parms;
60
61         rc = tf_session_open_session(tfp, &oparms);
62         /* Logging handled by tf_session_open_session */
63         if (rc)
64                 return rc;
65
66         TFP_DRV_LOG(INFO,
67                     "Session created, session_id:%d\n",
68                     parms->session_id.id);
69
70         TFP_DRV_LOG(INFO,
71                     "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
72                     parms->session_id.internal.domain,
73                     parms->session_id.internal.bus,
74                     parms->session_id.internal.device,
75                     parms->session_id.internal.fw_session_id);
76
77         return 0;
78 }
79
80 int
81 tf_attach_session(struct tf *tfp,
82                   struct tf_attach_session_parms *parms)
83 {
84         int rc;
85         unsigned int domain, bus, slot, device;
86         struct tf_session_attach_session_parms aparms;
87
88         TF_CHECK_PARMS2(tfp, parms);
89
90         /* Verify control channel */
91         rc = sscanf(parms->ctrl_chan_name,
92                     "%x:%x:%x.%d",
93                     &domain,
94                     &bus,
95                     &slot,
96                     &device);
97         if (rc != 4) {
98                 TFP_DRV_LOG(ERR,
99                             "Failed to scan device ctrl_chan_name\n");
100                 return -EINVAL;
101         }
102
103         /* Verify 'attach' channel */
104         rc = sscanf(parms->attach_chan_name,
105                     "%x:%x:%x.%d",
106                     &domain,
107                     &bus,
108                     &slot,
109                     &device);
110         if (rc != 4) {
111                 TFP_DRV_LOG(ERR,
112                             "Failed to scan device attach_chan_name\n");
113                 return -EINVAL;
114         }
115
116         /* Prepare return value of session_id, using ctrl_chan_name
117          * device values as it becomes the session id.
118          */
119         parms->session_id.internal.domain = domain;
120         parms->session_id.internal.bus = bus;
121         parms->session_id.internal.device = device;
122         aparms.attach_cfg = parms;
123         rc = tf_session_attach_session(tfp,
124                                        &aparms);
125         /* Logging handled by dev_bind */
126         if (rc)
127                 return rc;
128
129         TFP_DRV_LOG(INFO,
130                     "Attached to session, session_id:%d\n",
131                     parms->session_id.id);
132
133         TFP_DRV_LOG(INFO,
134                     "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
135                     parms->session_id.internal.domain,
136                     parms->session_id.internal.bus,
137                     parms->session_id.internal.device,
138                     parms->session_id.internal.fw_session_id);
139
140         return rc;
141 }
142
143 int
144 tf_close_session(struct tf *tfp)
145 {
146         int rc;
147         struct tf_session_close_session_parms cparms = { 0 };
148         union tf_session_id session_id = { 0 };
149         uint8_t ref_count;
150
151         TF_CHECK_PARMS1(tfp);
152
153         cparms.ref_count = &ref_count;
154         cparms.session_id = &session_id;
155         rc = tf_session_close_session(tfp,
156                                       &cparms);
157         /* Logging handled by tf_session_close_session */
158         if (rc)
159                 return rc;
160
161         TFP_DRV_LOG(INFO,
162                     "Closed session, session_id:%d, ref_count:%d\n",
163                     cparms.session_id->id,
164                     *cparms.ref_count);
165
166         TFP_DRV_LOG(INFO,
167                     "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
168                     cparms.session_id->internal.domain,
169                     cparms.session_id->internal.bus,
170                     cparms.session_id->internal.device,
171                     cparms.session_id->internal.fw_session_id);
172
173         return rc;
174 }
175
176 /** insert EM hash entry API
177  *
178  *    returns:
179  *    0       - Success
180  *    -EINVAL - Error
181  */
182 int tf_insert_em_entry(struct tf *tfp,
183                        struct tf_insert_em_entry_parms *parms)
184 {
185         struct tf_session      *tfs;
186         struct tf_dev_info     *dev;
187         int rc;
188
189         TF_CHECK_PARMS2(tfp, parms);
190
191         /* Retrieve the session information */
192         rc = tf_session_get_session(tfp, &tfs);
193         if (rc) {
194                 TFP_DRV_LOG(ERR,
195                             "%s: Failed to lookup session, rc:%s\n",
196                             tf_dir_2_str(parms->dir),
197                             strerror(-rc));
198                 return rc;
199         }
200
201         /* Retrieve the device information */
202         rc = tf_session_get_device(tfs, &dev);
203         if (rc) {
204                 TFP_DRV_LOG(ERR,
205                             "%s: Failed to lookup device, rc:%s\n",
206                             tf_dir_2_str(parms->dir),
207                             strerror(-rc));
208                 return rc;
209         }
210
211         if (parms->mem == TF_MEM_EXTERNAL &&
212                 dev->ops->tf_dev_insert_ext_em_entry != NULL)
213                 rc = dev->ops->tf_dev_insert_ext_em_entry(tfp, parms);
214         else if (parms->mem == TF_MEM_INTERNAL &&
215                 dev->ops->tf_dev_insert_int_em_entry != NULL)
216                 rc = dev->ops->tf_dev_insert_int_em_entry(tfp, parms);
217         else
218                 return -EINVAL;
219
220         if (rc) {
221                 TFP_DRV_LOG(ERR,
222                             "%s: EM insert failed, rc:%s\n",
223                             tf_dir_2_str(parms->dir),
224                             strerror(-rc));
225                 return rc;
226         }
227
228         return 0;
229 }
230
231 /** Delete EM hash entry API
232  *
233  *    returns:
234  *    0       - Success
235  *    -EINVAL - Error
236  */
237 int tf_delete_em_entry(struct tf *tfp,
238                        struct tf_delete_em_entry_parms *parms)
239 {
240         struct tf_session      *tfs;
241         struct tf_dev_info     *dev;
242         int rc;
243
244         TF_CHECK_PARMS2(tfp, parms);
245
246         /* Retrieve the session information */
247         rc = tf_session_get_session(tfp, &tfs);
248         if (rc) {
249                 TFP_DRV_LOG(ERR,
250                             "%s: Failed to lookup session, rc:%s\n",
251                             tf_dir_2_str(parms->dir),
252                             strerror(-rc));
253                 return rc;
254         }
255
256         /* Retrieve the device information */
257         rc = tf_session_get_device(tfs, &dev);
258         if (rc) {
259                 TFP_DRV_LOG(ERR,
260                             "%s: Failed to lookup device, rc:%s\n",
261                             tf_dir_2_str(parms->dir),
262                             strerror(-rc));
263                 return rc;
264         }
265
266         if (parms->mem == TF_MEM_EXTERNAL)
267                 rc = dev->ops->tf_dev_delete_ext_em_entry(tfp, parms);
268         else if (parms->mem == TF_MEM_INTERNAL)
269                 rc = dev->ops->tf_dev_delete_int_em_entry(tfp, parms);
270         else
271                 return -EINVAL;
272
273         if (rc) {
274                 TFP_DRV_LOG(ERR,
275                             "%s: EM delete failed, rc:%s\n",
276                             tf_dir_2_str(parms->dir),
277                             strerror(-rc));
278                 return rc;
279         }
280
281         return rc;
282 }
283
284 int
285 tf_alloc_identifier(struct tf *tfp,
286                     struct tf_alloc_identifier_parms *parms)
287 {
288         int rc;
289         struct tf_session *tfs;
290         struct tf_dev_info *dev;
291         struct tf_ident_alloc_parms aparms;
292         uint16_t id;
293
294         TF_CHECK_PARMS2(tfp, parms);
295
296         /* Can't do static initialization due to UT enum check */
297         memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
298
299         /* Retrieve the session information */
300         rc = tf_session_get_session(tfp, &tfs);
301         if (rc) {
302                 TFP_DRV_LOG(ERR,
303                             "%s: Failed to lookup session, rc:%s\n",
304                             tf_dir_2_str(parms->dir),
305                             strerror(-rc));
306                 return rc;
307         }
308
309         /* Retrieve the device information */
310         rc = tf_session_get_device(tfs, &dev);
311         if (rc) {
312                 TFP_DRV_LOG(ERR,
313                             "%s: Failed to lookup device, rc:%s\n",
314                             tf_dir_2_str(parms->dir),
315                             strerror(-rc));
316                 return rc;
317         }
318
319         if (dev->ops->tf_dev_alloc_ident == NULL) {
320                 rc = -EOPNOTSUPP;
321                 TFP_DRV_LOG(ERR,
322                             "%s: Operation not supported, rc:%s\n",
323                             tf_dir_2_str(parms->dir),
324                             strerror(-rc));
325                 return -EOPNOTSUPP;
326         }
327
328         aparms.dir = parms->dir;
329         aparms.type = parms->ident_type;
330         aparms.id = &id;
331         rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
332         if (rc) {
333                 TFP_DRV_LOG(ERR,
334                             "%s: Identifier allocation failed, rc:%s\n",
335                             tf_dir_2_str(parms->dir),
336                             strerror(-rc));
337                 return rc;
338         }
339
340         parms->id = id;
341
342         return 0;
343 }
344
345 int
346 tf_free_identifier(struct tf *tfp,
347                    struct tf_free_identifier_parms *parms)
348 {
349         int rc;
350         struct tf_session *tfs;
351         struct tf_dev_info *dev;
352         struct tf_ident_free_parms fparms;
353
354         TF_CHECK_PARMS2(tfp, parms);
355
356         /* Can't do static initialization due to UT enum check */
357         memset(&fparms, 0, sizeof(struct tf_ident_free_parms));
358
359         /* Retrieve the session information */
360         rc = tf_session_get_session(tfp, &tfs);
361         if (rc) {
362                 TFP_DRV_LOG(ERR,
363                             "%s: Failed to lookup session, rc:%s\n",
364                             tf_dir_2_str(parms->dir),
365                             strerror(-rc));
366                 return rc;
367         }
368
369         /* Retrieve the device information */
370         rc = tf_session_get_device(tfs, &dev);
371         if (rc) {
372                 TFP_DRV_LOG(ERR,
373                             "%s: Failed to lookup device, rc:%s\n",
374                             tf_dir_2_str(parms->dir),
375                             strerror(-rc));
376                 return rc;
377         }
378
379         if (dev->ops->tf_dev_free_ident == NULL) {
380                 rc = -EOPNOTSUPP;
381                 TFP_DRV_LOG(ERR,
382                             "%s: Operation not supported, rc:%s\n",
383                             tf_dir_2_str(parms->dir),
384                             strerror(-rc));
385                 return -EOPNOTSUPP;
386         }
387
388         fparms.dir = parms->dir;
389         fparms.type = parms->ident_type;
390         fparms.id = parms->id;
391         rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
392         if (rc) {
393                 TFP_DRV_LOG(ERR,
394                             "%s: Identifier free failed, rc:%s\n",
395                             tf_dir_2_str(parms->dir),
396                             strerror(-rc));
397                 return rc;
398         }
399
400         return 0;
401 }
402
403 int
404 tf_alloc_tcam_entry(struct tf *tfp,
405                     struct tf_alloc_tcam_entry_parms *parms)
406 {
407         int rc;
408         struct tf_session *tfs;
409         struct tf_dev_info *dev;
410         struct tf_tcam_alloc_parms aparms = { 0 };
411
412         TF_CHECK_PARMS2(tfp, parms);
413
414         /* Retrieve the session information */
415         rc = tf_session_get_session(tfp, &tfs);
416         if (rc) {
417                 TFP_DRV_LOG(ERR,
418                             "%s: Failed to lookup session, rc:%s\n",
419                             tf_dir_2_str(parms->dir),
420                             strerror(-rc));
421                 return rc;
422         }
423
424         /* Retrieve the device information */
425         rc = tf_session_get_device(tfs, &dev);
426         if (rc) {
427                 TFP_DRV_LOG(ERR,
428                             "%s: Failed to lookup device, rc:%s\n",
429                             tf_dir_2_str(parms->dir),
430                             strerror(-rc));
431                 return rc;
432         }
433
434         if (dev->ops->tf_dev_alloc_tcam == NULL) {
435                 rc = -EOPNOTSUPP;
436                 TFP_DRV_LOG(ERR,
437                             "%s: Operation not supported, rc:%s\n",
438                             tf_dir_2_str(parms->dir),
439                             strerror(-rc));
440                 return rc;
441         }
442
443         aparms.dir = parms->dir;
444         aparms.type = parms->tcam_tbl_type;
445         aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
446         aparms.priority = parms->priority;
447         rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
448         if (rc) {
449                 TFP_DRV_LOG(ERR,
450                             "%s: TCAM allocation failed, rc:%s\n",
451                             tf_dir_2_str(parms->dir),
452                             strerror(-rc));
453                 return rc;
454         }
455
456         parms->idx = aparms.idx;
457
458         return 0;
459 }
460
461 int
462 tf_set_tcam_entry(struct tf *tfp,
463                   struct tf_set_tcam_entry_parms *parms)
464 {
465         int rc;
466         struct tf_session *tfs;
467         struct tf_dev_info *dev;
468         struct tf_tcam_set_parms sparms = { 0 };
469
470         TF_CHECK_PARMS2(tfp, parms);
471
472         /* Retrieve the session information */
473         rc = tf_session_get_session(tfp, &tfs);
474         if (rc) {
475                 TFP_DRV_LOG(ERR,
476                             "%s: Failed to lookup session, rc:%s\n",
477                             tf_dir_2_str(parms->dir),
478                             strerror(-rc));
479                 return rc;
480         }
481
482         /* Retrieve the device information */
483         rc = tf_session_get_device(tfs, &dev);
484         if (rc) {
485                 TFP_DRV_LOG(ERR,
486                             "%s: Failed to lookup device, rc:%s\n",
487                             tf_dir_2_str(parms->dir),
488                             strerror(-rc));
489                 return rc;
490         }
491
492         if (dev->ops->tf_dev_set_tcam == NULL) {
493                 rc = -EOPNOTSUPP;
494                 TFP_DRV_LOG(ERR,
495                             "%s: Operation not supported, rc:%s\n",
496                             tf_dir_2_str(parms->dir),
497                             strerror(-rc));
498                 return rc;
499         }
500
501         sparms.dir = parms->dir;
502         sparms.type = parms->tcam_tbl_type;
503         sparms.idx = parms->idx;
504         sparms.key = parms->key;
505         sparms.mask = parms->mask;
506         sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
507         sparms.result = parms->result;
508         sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
509
510         rc = dev->ops->tf_dev_set_tcam(tfp, &sparms);
511         if (rc) {
512                 TFP_DRV_LOG(ERR,
513                             "%s: TCAM set failed, rc:%s\n",
514                             tf_dir_2_str(parms->dir),
515                             strerror(-rc));
516                 return rc;
517         }
518
519         return 0;
520 }
521
522 int
523 tf_get_tcam_entry(struct tf *tfp __rte_unused,
524                   struct tf_get_tcam_entry_parms *parms __rte_unused)
525 {
526         TF_CHECK_PARMS2(tfp, parms);
527         return -EOPNOTSUPP;
528 }
529
530 int
531 tf_free_tcam_entry(struct tf *tfp,
532                    struct tf_free_tcam_entry_parms *parms)
533 {
534         int rc;
535         struct tf_session *tfs;
536         struct tf_dev_info *dev;
537         struct tf_tcam_free_parms fparms = { 0 };
538
539         TF_CHECK_PARMS2(tfp, parms);
540
541         /* Retrieve the session information */
542         rc = tf_session_get_session(tfp, &tfs);
543         if (rc) {
544                 TFP_DRV_LOG(ERR,
545                             "%s: Failed to lookup session, rc:%s\n",
546                             tf_dir_2_str(parms->dir),
547                             strerror(-rc));
548                 return rc;
549         }
550
551         /* Retrieve the device information */
552         rc = tf_session_get_device(tfs, &dev);
553         if (rc) {
554                 TFP_DRV_LOG(ERR,
555                             "%s: Failed to lookup device, rc:%s\n",
556                             tf_dir_2_str(parms->dir),
557                             strerror(-rc));
558                 return rc;
559         }
560
561         if (dev->ops->tf_dev_free_tcam == NULL) {
562                 rc = -EOPNOTSUPP;
563                 TFP_DRV_LOG(ERR,
564                             "%s: Operation not supported, rc:%s\n",
565                             tf_dir_2_str(parms->dir),
566                             strerror(-rc));
567                 return rc;
568         }
569
570         fparms.dir = parms->dir;
571         fparms.type = parms->tcam_tbl_type;
572         fparms.idx = parms->idx;
573         rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
574         if (rc) {
575                 TFP_DRV_LOG(ERR,
576                             "%s: TCAM free failed, rc:%s\n",
577                             tf_dir_2_str(parms->dir),
578                             strerror(-rc));
579                 return rc;
580         }
581
582         return 0;
583 }
584
585 int
586 tf_alloc_tbl_entry(struct tf *tfp,
587                    struct tf_alloc_tbl_entry_parms *parms)
588 {
589         int rc;
590         struct tf_session *tfs;
591         struct tf_dev_info *dev;
592         struct tf_tbl_alloc_parms aparms;
593         uint32_t idx;
594
595         TF_CHECK_PARMS2(tfp, parms);
596
597         /* Can't do static initialization due to UT enum check */
598         memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
599
600         /* Retrieve the session information */
601         rc = tf_session_get_session(tfp, &tfs);
602         if (rc) {
603                 TFP_DRV_LOG(ERR,
604                             "%s: Failed to lookup session, rc:%s\n",
605                             tf_dir_2_str(parms->dir),
606                             strerror(-rc));
607                 return rc;
608         }
609
610         /* Retrieve the device information */
611         rc = tf_session_get_device(tfs, &dev);
612         if (rc) {
613                 TFP_DRV_LOG(ERR,
614                             "%s: Failed to lookup device, rc:%s\n",
615                             tf_dir_2_str(parms->dir),
616                             strerror(-rc));
617                 return rc;
618         }
619
620         aparms.dir = parms->dir;
621         aparms.type = parms->type;
622         aparms.idx = &idx;
623         aparms.tbl_scope_id = parms->tbl_scope_id;
624
625         if (parms->type == TF_TBL_TYPE_EXT) {
626                 if (dev->ops->tf_dev_alloc_ext_tbl == NULL) {
627                         rc = -EOPNOTSUPP;
628                         TFP_DRV_LOG(ERR,
629                                     "%s: Operation not supported, rc:%s\n",
630                                     tf_dir_2_str(parms->dir),
631                                     strerror(-rc));
632                         return -EOPNOTSUPP;
633                 }
634
635                 rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
636                 if (rc) {
637                         TFP_DRV_LOG(ERR,
638                                     "%s: External table allocation failed, rc:%s\n",
639                                     tf_dir_2_str(parms->dir),
640                                     strerror(-rc));
641                         return rc;
642                 }
643
644         } else {
645                 if (dev->ops->tf_dev_alloc_tbl == NULL) {
646                         rc = -EOPNOTSUPP;
647                         TFP_DRV_LOG(ERR,
648                                     "%s: Operation not supported, rc:%s\n",
649                                     tf_dir_2_str(parms->dir),
650                                     strerror(-rc));
651                         return -EOPNOTSUPP;
652                 }
653
654                 rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
655                 if (rc) {
656                         TFP_DRV_LOG(ERR,
657                                     "%s: Table allocation failed, rc:%s\n",
658                                     tf_dir_2_str(parms->dir),
659                                     strerror(-rc));
660                         return rc;
661                 }
662         }
663
664         parms->idx = idx;
665
666         return 0;
667 }
668
669 int
670 tf_free_tbl_entry(struct tf *tfp,
671                   struct tf_free_tbl_entry_parms *parms)
672 {
673         int rc;
674         struct tf_session *tfs;
675         struct tf_dev_info *dev;
676         struct tf_tbl_free_parms fparms;
677
678         TF_CHECK_PARMS2(tfp, parms);
679
680         /* Can't do static initialization due to UT enum check */
681         memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
682
683         /* Retrieve the session information */
684         rc = tf_session_get_session(tfp, &tfs);
685         if (rc) {
686                 TFP_DRV_LOG(ERR,
687                             "%s: Failed to lookup session, rc:%s\n",
688                             tf_dir_2_str(parms->dir),
689                             strerror(-rc));
690                 return rc;
691         }
692
693         /* Retrieve the device information */
694         rc = tf_session_get_device(tfs, &dev);
695         if (rc) {
696                 TFP_DRV_LOG(ERR,
697                             "%s: Failed to lookup device, rc:%s\n",
698                             tf_dir_2_str(parms->dir),
699                             strerror(-rc));
700                 return rc;
701         }
702
703         fparms.dir = parms->dir;
704         fparms.type = parms->type;
705         fparms.idx = parms->idx;
706         fparms.tbl_scope_id = parms->tbl_scope_id;
707
708         if (parms->type == TF_TBL_TYPE_EXT) {
709                 if (dev->ops->tf_dev_free_ext_tbl == NULL) {
710                         rc = -EOPNOTSUPP;
711                         TFP_DRV_LOG(ERR,
712                                     "%s: Operation not supported, rc:%s\n",
713                                     tf_dir_2_str(parms->dir),
714                                     strerror(-rc));
715                         return -EOPNOTSUPP;
716                 }
717
718                 rc = dev->ops->tf_dev_free_ext_tbl(tfp, &fparms);
719                 if (rc) {
720                         TFP_DRV_LOG(ERR,
721                                     "%s: Table free failed, rc:%s\n",
722                                     tf_dir_2_str(parms->dir),
723                                     strerror(-rc));
724                         return rc;
725                 }
726         } else {
727                 if (dev->ops->tf_dev_free_tbl == NULL) {
728                         rc = -EOPNOTSUPP;
729                         TFP_DRV_LOG(ERR,
730                                     "%s: Operation not supported, rc:%s\n",
731                                     tf_dir_2_str(parms->dir),
732                                     strerror(-rc));
733                         return -EOPNOTSUPP;
734                 }
735
736                 rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
737                 if (rc) {
738                         TFP_DRV_LOG(ERR,
739                                     "%s: Table free failed, rc:%s\n",
740                                     tf_dir_2_str(parms->dir),
741                                     strerror(-rc));
742                         return rc;
743                 }
744         }
745
746         return 0;
747 }
748
749 int
750 tf_set_tbl_entry(struct tf *tfp,
751                  struct tf_set_tbl_entry_parms *parms)
752 {
753         int rc = 0;
754         struct tf_session *tfs;
755         struct tf_dev_info *dev;
756         struct tf_tbl_set_parms sparms;
757
758         TF_CHECK_PARMS3(tfp, parms, parms->data);
759
760         /* Can't do static initialization due to UT enum check */
761         memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
762
763         /* Retrieve the session information */
764         rc = tf_session_get_session(tfp, &tfs);
765         if (rc) {
766                 TFP_DRV_LOG(ERR,
767                             "%s: Failed to lookup session, rc:%s\n",
768                             tf_dir_2_str(parms->dir),
769                             strerror(-rc));
770                 return rc;
771         }
772
773         /* Retrieve the device information */
774         rc = tf_session_get_device(tfs, &dev);
775         if (rc) {
776                 TFP_DRV_LOG(ERR,
777                             "%s: Failed to lookup device, rc:%s\n",
778                             tf_dir_2_str(parms->dir),
779                             strerror(-rc));
780                 return rc;
781         }
782
783         sparms.dir = parms->dir;
784         sparms.type = parms->type;
785         sparms.data = parms->data;
786         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
787         sparms.idx = parms->idx;
788         sparms.tbl_scope_id = parms->tbl_scope_id;
789
790         if (parms->type == TF_TBL_TYPE_EXT) {
791                 if (dev->ops->tf_dev_set_ext_tbl == NULL) {
792                         rc = -EOPNOTSUPP;
793                         TFP_DRV_LOG(ERR,
794                                     "%s: Operation not supported, rc:%s\n",
795                                     tf_dir_2_str(parms->dir),
796                                     strerror(-rc));
797                         return -EOPNOTSUPP;
798                 }
799
800                 rc = dev->ops->tf_dev_set_ext_tbl(tfp, &sparms);
801                 if (rc) {
802                         TFP_DRV_LOG(ERR,
803                                     "%s: Table set failed, rc:%s\n",
804                                     tf_dir_2_str(parms->dir),
805                                     strerror(-rc));
806                         return rc;
807                 }
808         } else {
809                 if (dev->ops->tf_dev_set_tbl == NULL) {
810                         rc = -EOPNOTSUPP;
811                         TFP_DRV_LOG(ERR,
812                                     "%s: Operation not supported, rc:%s\n",
813                                     tf_dir_2_str(parms->dir),
814                                     strerror(-rc));
815                         return -EOPNOTSUPP;
816                 }
817
818                 rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
819                 if (rc) {
820                         TFP_DRV_LOG(ERR,
821                                     "%s: Table set failed, rc:%s\n",
822                                     tf_dir_2_str(parms->dir),
823                                     strerror(-rc));
824                         return rc;
825                 }
826         }
827
828         return rc;
829 }
830
831 int
832 tf_get_tbl_entry(struct tf *tfp,
833                  struct tf_get_tbl_entry_parms *parms)
834 {
835         int rc = 0;
836         struct tf_session *tfs;
837         struct tf_dev_info *dev;
838         struct tf_tbl_get_parms gparms;
839
840         TF_CHECK_PARMS3(tfp, parms, parms->data);
841
842         /* Can't do static initialization due to UT enum check */
843         memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
844
845         /* Retrieve the session information */
846         rc = tf_session_get_session(tfp, &tfs);
847         if (rc) {
848                 TFP_DRV_LOG(ERR,
849                             "%s: Failed to lookup session, rc:%s\n",
850                             tf_dir_2_str(parms->dir),
851                             strerror(-rc));
852                 return rc;
853         }
854
855         /* Retrieve the device information */
856         rc = tf_session_get_device(tfs, &dev);
857         if (rc) {
858                 TFP_DRV_LOG(ERR,
859                             "%s: Failed to lookup device, rc:%s\n",
860                             tf_dir_2_str(parms->dir),
861                             strerror(-rc));
862                 return rc;
863         }
864
865         if (dev->ops->tf_dev_get_tbl == NULL) {
866                 rc = -EOPNOTSUPP;
867                 TFP_DRV_LOG(ERR,
868                             "%s: Operation not supported, rc:%s\n",
869                             tf_dir_2_str(parms->dir),
870                             strerror(-rc));
871                 return -EOPNOTSUPP;
872         }
873
874         gparms.dir = parms->dir;
875         gparms.type = parms->type;
876         gparms.data = parms->data;
877         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
878         gparms.idx = parms->idx;
879         rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
880         if (rc) {
881                 TFP_DRV_LOG(ERR,
882                             "%s: Table get failed, rc:%s\n",
883                             tf_dir_2_str(parms->dir),
884                             strerror(-rc));
885                 return rc;
886         }
887
888         return rc;
889 }
890
891 int
892 tf_bulk_get_tbl_entry(struct tf *tfp,
893                  struct tf_bulk_get_tbl_entry_parms *parms)
894 {
895         int rc = 0;
896         struct tf_session *tfs;
897         struct tf_dev_info *dev;
898         struct tf_tbl_get_bulk_parms bparms;
899
900         TF_CHECK_PARMS2(tfp, parms);
901
902         /* Can't do static initialization due to UT enum check */
903         memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_parms));
904
905         /* Retrieve the session information */
906         rc = tf_session_get_session(tfp, &tfs);
907         if (rc) {
908                 TFP_DRV_LOG(ERR,
909                             "%s: Failed to lookup session, rc:%s\n",
910                             tf_dir_2_str(parms->dir),
911                             strerror(-rc));
912                 return rc;
913         }
914
915         /* Retrieve the device information */
916         rc = tf_session_get_device(tfs, &dev);
917         if (rc) {
918                 TFP_DRV_LOG(ERR,
919                             "%s: Failed to lookup device, rc:%s\n",
920                             tf_dir_2_str(parms->dir),
921                             strerror(-rc));
922                 return rc;
923         }
924
925         if (parms->type == TF_TBL_TYPE_EXT) {
926                 /* Not supported, yet */
927                 rc = -EOPNOTSUPP;
928                 TFP_DRV_LOG(ERR,
929                             "%s, External table type not supported, rc:%s\n",
930                             tf_dir_2_str(parms->dir),
931                             strerror(-rc));
932
933                 return rc;
934         }
935
936         /* Internal table type processing */
937
938         if (dev->ops->tf_dev_get_bulk_tbl == NULL) {
939                 rc = -EOPNOTSUPP;
940                 TFP_DRV_LOG(ERR,
941                             "%s: Operation not supported, rc:%s\n",
942                             tf_dir_2_str(parms->dir),
943                             strerror(-rc));
944                 return -EOPNOTSUPP;
945         }
946
947         bparms.dir = parms->dir;
948         bparms.type = parms->type;
949         bparms.starting_idx = parms->starting_idx;
950         bparms.num_entries = parms->num_entries;
951         bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
952         bparms.physical_mem_addr = parms->physical_mem_addr;
953         rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
954         if (rc) {
955                 TFP_DRV_LOG(ERR,
956                             "%s: Table get bulk failed, rc:%s\n",
957                             tf_dir_2_str(parms->dir),
958                             strerror(-rc));
959                 return rc;
960         }
961
962         return rc;
963 }
964
965 int
966 tf_alloc_tbl_scope(struct tf *tfp,
967                    struct tf_alloc_tbl_scope_parms *parms)
968 {
969         struct tf_session *tfs;
970         struct tf_dev_info *dev;
971         int rc;
972
973         TF_CHECK_PARMS2(tfp, parms);
974
975         /* Retrieve the session information */
976         rc = tf_session_get_session(tfp, &tfs);
977         if (rc) {
978                 TFP_DRV_LOG(ERR,
979                             "Failed to lookup session, rc:%s\n",
980                             strerror(-rc));
981                 return rc;
982         }
983
984         /* Retrieve the device information */
985         rc = tf_session_get_device(tfs, &dev);
986         if (rc) {
987                 TFP_DRV_LOG(ERR,
988                             "Failed to lookup device, rc:%s\n",
989                             strerror(-rc));
990                 return rc;
991         }
992
993         if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
994                 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
995         } else {
996                 TFP_DRV_LOG(ERR,
997                             "Alloc table scope not supported by device\n");
998                 return -EINVAL;
999         }
1000
1001         return rc;
1002 }
1003
1004 int
1005 tf_free_tbl_scope(struct tf *tfp,
1006                   struct tf_free_tbl_scope_parms *parms)
1007 {
1008         struct tf_session *tfs;
1009         struct tf_dev_info *dev;
1010         int rc;
1011
1012         TF_CHECK_PARMS2(tfp, parms);
1013
1014         /* Retrieve the session information */
1015         rc = tf_session_get_session(tfp, &tfs);
1016         if (rc) {
1017                 TFP_DRV_LOG(ERR,
1018                             "Failed to lookup session, rc:%s\n",
1019                             strerror(-rc));
1020                 return rc;
1021         }
1022
1023         /* Retrieve the device information */
1024         rc = tf_session_get_device(tfs, &dev);
1025         if (rc) {
1026                 TFP_DRV_LOG(ERR,
1027                             "Failed to lookup device, rc:%s\n",
1028                             strerror(-rc));
1029                 return rc;
1030         }
1031
1032         if (dev->ops->tf_dev_free_tbl_scope) {
1033                 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
1034         } else {
1035                 TFP_DRV_LOG(ERR,
1036                             "Free table scope not supported by device\n");
1037                 return -EINVAL;
1038         }
1039
1040         return rc;
1041 }