8b3e15c8ab2deaec00163576754a3236985a4b80
[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_PARMS_SESSION(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_PARMS_SESSION(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_PARMS_SESSION(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 allocation 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         if (dev->ops->tf_dev_alloc_tbl == NULL) {
621                 rc = -EOPNOTSUPP;
622                 TFP_DRV_LOG(ERR,
623                             "%s: Operation not supported, rc:%s\n",
624                             tf_dir_2_str(parms->dir),
625                             strerror(-rc));
626                 return -EOPNOTSUPP;
627         }
628
629         aparms.dir = parms->dir;
630         aparms.type = parms->type;
631         aparms.idx = &idx;
632         rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
633         if (rc) {
634                 TFP_DRV_LOG(ERR,
635                             "%s: Table allocation failed, rc:%s\n",
636                             tf_dir_2_str(parms->dir),
637                             strerror(-rc));
638                 return rc;
639         }
640
641         parms->idx = idx;
642
643         return 0;
644 }
645
646 int
647 tf_free_tbl_entry(struct tf *tfp,
648                   struct tf_free_tbl_entry_parms *parms)
649 {
650         int rc;
651         struct tf_session *tfs;
652         struct tf_dev_info *dev;
653         struct tf_tbl_free_parms fparms;
654
655         TF_CHECK_PARMS2(tfp, parms);
656
657         /* Can't do static initialization due to UT enum check */
658         memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
659
660         /* Retrieve the session information */
661         rc = tf_session_get_session(tfp, &tfs);
662         if (rc) {
663                 TFP_DRV_LOG(ERR,
664                             "%s: Failed to lookup session, rc:%s\n",
665                             tf_dir_2_str(parms->dir),
666                             strerror(-rc));
667                 return rc;
668         }
669
670         /* Retrieve the device information */
671         rc = tf_session_get_device(tfs, &dev);
672         if (rc) {
673                 TFP_DRV_LOG(ERR,
674                             "%s: Failed to lookup device, rc:%s\n",
675                             tf_dir_2_str(parms->dir),
676                             strerror(-rc));
677                 return rc;
678         }
679
680         if (dev->ops->tf_dev_free_tbl == NULL) {
681                 rc = -EOPNOTSUPP;
682                 TFP_DRV_LOG(ERR,
683                             "%s: Operation not supported, rc:%s\n",
684                             tf_dir_2_str(parms->dir),
685                             strerror(-rc));
686                 return -EOPNOTSUPP;
687         }
688
689         fparms.dir = parms->dir;
690         fparms.type = parms->type;
691         fparms.idx = parms->idx;
692         rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
693         if (rc) {
694                 TFP_DRV_LOG(ERR,
695                             "%s: Table free failed, rc:%s\n",
696                             tf_dir_2_str(parms->dir),
697                             strerror(-rc));
698                 return rc;
699         }
700
701         return 0;
702 }
703
704 int
705 tf_set_tbl_entry(struct tf *tfp,
706                  struct tf_set_tbl_entry_parms *parms)
707 {
708         int rc = 0;
709         struct tf_session *tfs;
710         struct tf_dev_info *dev;
711         struct tf_tbl_set_parms sparms;
712
713         TF_CHECK_PARMS3(tfp, parms, parms->data);
714
715         /* Can't do static initialization due to UT enum check */
716         memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
717
718         /* Retrieve the session information */
719         rc = tf_session_get_session(tfp, &tfs);
720         if (rc) {
721                 TFP_DRV_LOG(ERR,
722                             "%s: Failed to lookup session, rc:%s\n",
723                             tf_dir_2_str(parms->dir),
724                             strerror(-rc));
725                 return rc;
726         }
727
728         /* Retrieve the device information */
729         rc = tf_session_get_device(tfs, &dev);
730         if (rc) {
731                 TFP_DRV_LOG(ERR,
732                             "%s: Failed to lookup device, rc:%s\n",
733                             tf_dir_2_str(parms->dir),
734                             strerror(-rc));
735                 return rc;
736         }
737
738         if (dev->ops->tf_dev_set_tbl == NULL) {
739                 rc = -EOPNOTSUPP;
740                 TFP_DRV_LOG(ERR,
741                             "%s: Operation not supported, rc:%s\n",
742                             tf_dir_2_str(parms->dir),
743                             strerror(-rc));
744                 return -EOPNOTSUPP;
745         }
746
747         sparms.dir = parms->dir;
748         sparms.type = parms->type;
749         sparms.data = parms->data;
750         sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
751         sparms.idx = parms->idx;
752         rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
753         if (rc) {
754                 TFP_DRV_LOG(ERR,
755                             "%s: Table set failed, rc:%s\n",
756                             tf_dir_2_str(parms->dir),
757                             strerror(-rc));
758                 return rc;
759         }
760
761         return rc;
762 }
763
764 int
765 tf_get_tbl_entry(struct tf *tfp,
766                  struct tf_get_tbl_entry_parms *parms)
767 {
768         int rc = 0;
769         struct tf_session *tfs;
770         struct tf_dev_info *dev;
771         struct tf_tbl_get_parms gparms;
772
773         TF_CHECK_PARMS3(tfp, parms, parms->data);
774
775         /* Can't do static initialization due to UT enum check */
776         memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
777
778         /* Retrieve the session information */
779         rc = tf_session_get_session(tfp, &tfs);
780         if (rc) {
781                 TFP_DRV_LOG(ERR,
782                             "%s: Failed to lookup session, rc:%s\n",
783                             tf_dir_2_str(parms->dir),
784                             strerror(-rc));
785                 return rc;
786         }
787
788         /* Retrieve the device information */
789         rc = tf_session_get_device(tfs, &dev);
790         if (rc) {
791                 TFP_DRV_LOG(ERR,
792                             "%s: Failed to lookup device, rc:%s\n",
793                             tf_dir_2_str(parms->dir),
794                             strerror(-rc));
795                 return rc;
796         }
797
798         if (dev->ops->tf_dev_get_tbl == NULL) {
799                 rc = -EOPNOTSUPP;
800                 TFP_DRV_LOG(ERR,
801                             "%s: Operation not supported, rc:%s\n",
802                             tf_dir_2_str(parms->dir),
803                             strerror(-rc));
804                 return -EOPNOTSUPP;
805         }
806
807         gparms.dir = parms->dir;
808         gparms.type = parms->type;
809         gparms.data = parms->data;
810         gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
811         gparms.idx = parms->idx;
812         rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
813         if (rc) {
814                 TFP_DRV_LOG(ERR,
815                             "%s: Table get failed, rc:%s\n",
816                             tf_dir_2_str(parms->dir),
817                             strerror(-rc));
818                 return rc;
819         }
820
821         return rc;
822 }
823
824 /* API defined in tf_core.h */
825 int
826 tf_alloc_tbl_scope(struct tf *tfp,
827                    struct tf_alloc_tbl_scope_parms *parms)
828 {
829         struct tf_session *tfs;
830         struct tf_dev_info *dev;
831         int rc;
832
833         TF_CHECK_PARMS_SESSION_NO_DIR(tfp, parms);
834
835         /* Retrieve the session information */
836         rc = tf_session_get_session(tfp, &tfs);
837         if (rc) {
838                 TFP_DRV_LOG(ERR,
839                             "Failed to lookup session, rc:%s\n",
840                             strerror(-rc));
841                 return rc;
842         }
843
844         /* Retrieve the device information */
845         rc = tf_session_get_device(tfs, &dev);
846         if (rc) {
847                 TFP_DRV_LOG(ERR,
848                             "Failed to lookup device, rc:%s\n",
849                             strerror(-rc));
850                 return rc;
851         }
852
853         if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
854                 rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
855         } else {
856                 TFP_DRV_LOG(ERR,
857                             "Alloc table scope not supported by device\n");
858                 return -EINVAL;
859         }
860
861         return rc;
862 }
863
864 /* API defined in tf_core.h */
865 int
866 tf_free_tbl_scope(struct tf *tfp,
867                   struct tf_free_tbl_scope_parms *parms)
868 {
869         struct tf_session *tfs;
870         struct tf_dev_info *dev;
871         int rc;
872
873         TF_CHECK_PARMS_SESSION_NO_DIR(tfp, parms);
874
875         /* Retrieve the session information */
876         rc = tf_session_get_session(tfp, &tfs);
877         if (rc) {
878                 TFP_DRV_LOG(ERR,
879                             "Failed to lookup session, rc:%s\n",
880                             strerror(-rc));
881                 return rc;
882         }
883
884         /* Retrieve the device information */
885         rc = tf_session_get_device(tfs, &dev);
886         if (rc) {
887                 TFP_DRV_LOG(ERR,
888                             "Failed to lookup device, rc:%s\n",
889                             strerror(-rc));
890                 return rc;
891         }
892
893         if (dev->ops->tf_dev_free_tbl_scope) {
894                 rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
895         } else {
896                 TFP_DRV_LOG(ERR,
897                             "Free table scope not supported by device\n");
898                 return -EINVAL;
899         }
900
901         return rc;
902 }