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