net/tap: fix to populate FDs in secondary process
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl_sram.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 Broadcom
3  * All rights reserved.
4  */
5
6 /* Truflow Table APIs and supporting code */
7
8 #include <rte_common.h>
9
10 #include "tf_tbl.h"
11 #include "tf_tbl_sram.h"
12 #include "tf_sram_mgr.h"
13 #include "tf_common.h"
14 #include "tf_rm.h"
15 #include "tf_util.h"
16 #include "tf_msg.h"
17 #include "tfp.h"
18 #include "tf_session.h"
19 #include "tf_device.h"
20 #include "cfa_resource_types.h"
21
22 #define DBG_SRAM 0
23
24 #define TF_TBL_PTR_TO_RM(new_idx, idx, base, shift) {           \
25                 *(new_idx) = (((idx) >> (shift)) - (base));     \
26 }
27
28 /**
29  * tf_sram_tbl_get_info_parms parameter definition
30  */
31 struct tf_tbl_sram_get_info_parms {
32         /**
33          * [in] table RM database
34          */
35         void *rm_db;
36         /**
37          * [in] Receive or transmit direction
38          */
39         enum tf_dir dir;
40         /**
41          * [in] table_type
42          *
43          *  the TF index table type
44          */
45         enum tf_tbl_type tbl_type;
46         /**
47          * [out] bank
48          *
49          *  The SRAM bank associated with the type
50          */
51         enum tf_sram_bank_id bank_id;
52         /**
53          * [out] slice_size
54          *
55          *  the slice size for the indicated table type
56          */
57         enum tf_sram_slice_size slice_size;
58 };
59
60 /**
61  * Translate HCAPI type to SRAM Manager bank
62  */
63 const uint16_t tf_tbl_sram_hcapi_2_bank[CFA_RESOURCE_TYPE_P58_LAST] = {
64         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_0] = TF_SRAM_BANK_ID_0,
65         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_1] = TF_SRAM_BANK_ID_1,
66         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_2] = TF_SRAM_BANK_ID_2,
67         [CFA_RESOURCE_TYPE_P58_SRAM_BANK_3] = TF_SRAM_BANK_ID_3
68 };
69
70 #define TF_TBL_SRAM_SLICES_MAX  \
71         (TF_SRAM_MGR_BLOCK_SZ_BYTES / TF_SRAM_MGR_MIN_SLICE_BYTES)
72 /**
73  * Translate HCAPI type to SRAM Manager bank
74  */
75 const uint8_t tf_tbl_sram_slices_2_size[TF_TBL_SRAM_SLICES_MAX + 1] = {
76         [0] = TF_SRAM_SLICE_SIZE_64B, /* if 0 slices assume 1 64B block */
77         [1] = TF_SRAM_SLICE_SIZE_64B, /* 1 slice  per 64B block */
78         [2] = TF_SRAM_SLICE_SIZE_32B, /* 2 slices per 64B block */
79         [4] = TF_SRAM_SLICE_SIZE_16B, /* 4 slices per 64B block */
80         [8] = TF_SRAM_SLICE_SIZE_8B   /* 8 slices per 64B block */
81 };
82
83 /**
84  * Get SRAM Table Information for a given index table type
85  *
86  *
87  * [in] sram_handle
88  *   Pointer to SRAM handle
89  *
90  * [in] parms
91  *   Pointer to the SRAM get info parameters
92  *
93  * Returns
94  *   - (0) if successful
95  *   - (-EINVAL) on failure
96  *
97  */
98 static int tf_tbl_sram_get_info(struct tf_tbl_sram_get_info_parms *parms)
99 {
100         int rc = 0;
101         uint16_t hcapi_type;
102         uint16_t slices;
103         struct tf_rm_get_hcapi_parms hparms;
104         struct tf_rm_get_slices_parms sparms;
105
106         hparms.rm_db = parms->rm_db;
107         hparms.subtype = parms->tbl_type;
108         hparms.hcapi_type = &hcapi_type;
109
110         rc = tf_rm_get_hcapi_type(&hparms);
111         if (rc) {
112                 TFP_DRV_LOG(ERR,
113                             "%s: Failed to get hcapi_type %s, rc:%s\n",
114                             tf_dir_2_str(parms->dir),
115                             tf_tbl_type_2_str(parms->tbl_type),
116                             strerror(-rc));
117                 return rc;
118         }
119         parms->bank_id = tf_tbl_sram_hcapi_2_bank[hcapi_type];
120
121         sparms.rm_db = parms->rm_db;
122         sparms.subtype = parms->tbl_type;
123         sparms.slices = &slices;
124
125         rc = tf_rm_get_slices(&sparms);
126         if (rc) {
127                 TFP_DRV_LOG(ERR,
128                             "%s: Failed to get slice cnt %s, rc:%s\n",
129                             tf_dir_2_str(parms->dir),
130                             tf_tbl_type_2_str(parms->tbl_type),
131                             strerror(-rc));
132                 return rc;
133         }
134         if (slices)
135                 parms->slice_size = tf_tbl_sram_slices_2_size[slices];
136
137         return rc;
138 }
139
140 int
141 tf_tbl_sram_bind(struct tf *tfp __rte_unused)
142 {
143         int rc = 0;
144         void *sram_handle = NULL;
145
146         TF_CHECK_PARMS1(tfp);
147
148         rc = tf_sram_mgr_bind(&sram_handle);
149
150         tf_session_set_sram_db(tfp, sram_handle);
151
152         TFP_DRV_LOG(INFO,
153                     "SRAM Table - initialized\n");
154
155         return rc;
156 }
157
158 int
159 tf_tbl_sram_unbind(struct tf *tfp __rte_unused)
160 {
161         int rc = 0;
162         void *sram_handle = NULL;
163
164         TF_CHECK_PARMS1(tfp);
165
166         rc = tf_session_get_sram_db(tfp, &sram_handle);
167         if (rc) {
168                 TFP_DRV_LOG(ERR,
169                             "Failed to get sram_handle from session, rc:%s\n",
170                             strerror(-rc));
171                 return rc;
172         }
173         if (sram_handle)
174                 rc = tf_sram_mgr_unbind(sram_handle);
175
176         TFP_DRV_LOG(INFO,
177                     "SRAM Table - deinitialized\n");
178         return rc;
179 }
180
181 int
182 tf_tbl_sram_alloc(struct tf *tfp,
183                   struct tf_tbl_alloc_parms *parms)
184 {
185         int rc;
186         uint16_t idx;
187         struct tf_session *tfs;
188         struct tf_dev_info *dev;
189         struct tf_tbl_sram_get_info_parms iparms = { 0 };
190         struct tf_sram_mgr_alloc_parms aparms = { 0 };
191         struct tbl_rm_db *tbl_db;
192         void *tbl_db_ptr = NULL;
193         void *sram_handle = NULL;
194
195         TF_CHECK_PARMS2(tfp, parms);
196
197         /* Retrieve the session information */
198         rc = tf_session_get(tfp, &tfs, &dev);
199         if (rc)
200                 return rc;
201
202         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
203         if (rc) {
204                 TFP_DRV_LOG(ERR,
205                             "Failed to get tbl_db from session, rc:%s\n",
206                             strerror(-rc));
207                 return rc;
208         }
209
210         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
211
212         rc = tf_session_get_sram_db(tfp, &sram_handle);
213         if (rc) {
214                 TFP_DRV_LOG(ERR,
215                             "Failed to get sram_handle from session, rc:%s\n",
216                             strerror(-rc));
217                 return rc;
218         }
219
220         iparms.rm_db = tbl_db->tbl_db[parms->dir];
221         iparms.dir = parms->dir;
222         iparms.tbl_type = parms->type;
223
224         rc = tf_tbl_sram_get_info(&iparms);
225
226         if (rc) {
227                 TFP_DRV_LOG(ERR,
228                             "%s: Failed to get SRAM info %s\n",
229                             tf_dir_2_str(parms->dir),
230                             tf_tbl_type_2_str(parms->type));
231                 return rc;
232         }
233
234         aparms.dir = parms->dir;
235         aparms.bank_id = iparms.bank_id;
236         aparms.slice_size = iparms.slice_size;
237         aparms.sram_offset = &idx;
238         aparms.tbl_type = parms->type;
239         aparms.rm_db = tbl_db->tbl_db[parms->dir];
240
241         rc = tf_sram_mgr_alloc(sram_handle, &aparms);
242         if (rc) {
243                 TFP_DRV_LOG(ERR,
244                             "%s: Failed to allocate SRAM table:%s\n",
245                             tf_dir_2_str(parms->dir),
246                             tf_tbl_type_2_str(parms->type));
247                 return rc;
248         }
249         *parms->idx = idx;
250
251 #if (DBG_SRAM == 1)
252         {
253                 struct tf_sram_mgr_dump_parms dparms;
254
255                 dparms.dir = parms->dir;
256                 dparms.bank_id = iparms.bank_id;
257                 dparms.slice_size = iparms.slice_size;
258
259                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
260         }
261 #endif
262
263         return rc;
264 }
265
266 int
267 tf_tbl_sram_free(struct tf *tfp __rte_unused,
268                  struct tf_tbl_free_parms *parms)
269 {
270         int rc;
271         struct tf_session *tfs;
272         struct tf_dev_info *dev;
273         struct tbl_rm_db *tbl_db;
274         void *tbl_db_ptr = NULL;
275         struct tf_tbl_sram_get_info_parms iparms = { 0 };
276         struct tf_sram_mgr_free_parms fparms = { 0 };
277         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
278         bool allocated = false;
279         void *sram_handle = NULL;
280
281         TF_CHECK_PARMS2(tfp, parms);
282
283         /* Retrieve the session information */
284         rc = tf_session_get(tfp, &tfs, &dev);
285         if (rc)
286                 return rc;
287
288         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
289         if (rc) {
290                 TFP_DRV_LOG(ERR,
291                             "Failed to get em_ext_db from session, rc:%s\n",
292                             strerror(-rc));
293                 return rc;
294         }
295         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
296
297         rc = tf_session_get_sram_db(tfp, &sram_handle);
298         if (rc) {
299                 TFP_DRV_LOG(ERR,
300                             "Failed to get sram_handle from session, rc:%s\n",
301                             strerror(-rc));
302                 return rc;
303         }
304
305         iparms.rm_db = tbl_db->tbl_db[parms->dir];
306         iparms.dir = parms->dir;
307         iparms.tbl_type = parms->type;
308
309         rc = tf_tbl_sram_get_info(&iparms);
310         if (rc) {
311                 TFP_DRV_LOG(ERR,
312                             "%s: Failed to get table info:%s\n",
313                             tf_dir_2_str(parms->dir),
314                             tf_tbl_type_2_str(parms->type));
315                 return rc;
316         }
317
318 #if (DBG_SRAM == 1)
319         {
320                 struct tf_sram_mgr_dump_parms dparms;
321
322                 printf("%s: %s: %s\n", tf_dir_2_str(parms->dir),
323                        tf_sram_slice_2_str(iparms.slice_size),
324                        tf_sram_bank_2_str(iparms.bank_id));
325
326                 dparms.dir = parms->dir;
327                 dparms.bank_id = iparms.bank_id;
328                 dparms.slice_size = iparms.slice_size;
329
330                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
331         }
332 #endif
333
334         aparms.sram_offset = parms->idx;
335         aparms.slice_size = iparms.slice_size;
336         aparms.bank_id = iparms.bank_id;
337         aparms.dir = parms->dir;
338         aparms.is_allocated = &allocated;
339
340         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
341         if (rc || !allocated) {
342                 TFP_DRV_LOG(ERR,
343                             "%s: Free of invalid entry:%s idx(%d):(%s)\n",
344                             tf_dir_2_str(parms->dir),
345                             tf_tbl_type_2_str(parms->type),
346                             parms->idx,
347                             strerror(-rc));
348                 rc = -ENOMEM;
349                 return rc;
350         }
351
352         fparms.rm_db = tbl_db->tbl_db[parms->dir];
353         fparms.tbl_type = parms->type;
354         fparms.sram_offset = parms->idx;
355         fparms.slice_size = iparms.slice_size;
356         fparms.bank_id = iparms.bank_id;
357         fparms.dir = parms->dir;
358 #if (STATS_CLEAR_ON_READ_SUPPORT == 0)
359         fparms.tfp = tfp;
360 #endif
361         rc = tf_sram_mgr_free(sram_handle, &fparms);
362         if (rc) {
363                 TFP_DRV_LOG(ERR,
364                             "%s: Failed to free entry:%s idx(%d)\n",
365                             tf_dir_2_str(parms->dir),
366                             tf_tbl_type_2_str(parms->type),
367                             parms->idx);
368                 return rc;
369         }
370
371 #if (DBG_SRAM == 1)
372         {
373                 struct tf_sram_mgr_dump_parms dparms;
374
375                 printf("%s: %s: %s\n", tf_dir_2_str(parms->dir),
376                        tf_sram_slice_2_str(iparms.slice_size),
377                        tf_sram_bank_2_str(iparms.bank_id));
378
379                 dparms.dir = parms->dir;
380                 dparms.bank_id = iparms.bank_id;
381                 dparms.slice_size = iparms.slice_size;
382
383                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
384         }
385 #endif
386         return rc;
387 }
388
389 int
390 tf_tbl_sram_set(struct tf *tfp,
391                 struct tf_tbl_set_parms *parms)
392 {
393         int rc;
394         bool allocated = 0;
395         int rallocated = 0;
396         uint16_t hcapi_type;
397         struct tf_rm_get_hcapi_parms hparms = { 0 };
398         struct tf_session *tfs;
399         struct tf_dev_info *dev;
400         struct tbl_rm_db *tbl_db;
401         void *tbl_db_ptr = NULL;
402         struct tf_tbl_sram_get_info_parms iparms = { 0 };
403         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
404         struct tf_rm_is_allocated_parms raparms = { 0 };
405         void *sram_handle = NULL;
406         uint16_t base = 0, shift = 0;
407
408         TF_CHECK_PARMS3(tfp, parms, parms->data);
409
410         /* Retrieve the session information */
411         rc = tf_session_get(tfp, &tfs, &dev);
412         if (rc)
413                 return rc;
414
415         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
416         if (rc) {
417                 TFP_DRV_LOG(ERR,
418                             "Failed to get em_ext_db from session, rc:%s\n",
419                             strerror(-rc));
420                 return rc;
421         }
422         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
423
424         rc = tf_session_get_sram_db(tfp, &sram_handle);
425         if (rc) {
426                 TFP_DRV_LOG(ERR,
427                             "Failed to get sram_handle from session, rc:%s\n",
428                             strerror(-rc));
429                 return rc;
430         }
431
432         iparms.rm_db = tbl_db->tbl_db[parms->dir];
433         iparms.dir = parms->dir;
434         iparms.tbl_type = parms->type;
435
436         rc = tf_tbl_sram_get_info(&iparms);
437         if (rc) {
438                 TFP_DRV_LOG(ERR,
439                             "%s: Failed to get table info:%s\n",
440                             tf_dir_2_str(parms->dir),
441                             tf_tbl_type_2_str(parms->type));
442                 return rc;
443         }
444
445         if (tf_session_is_shared_session(tfs)) {
446                 /* Only get table info if required for the device */
447                 if (dev->ops->tf_dev_get_tbl_info) {
448                         rc = dev->ops->tf_dev_get_tbl_info(tfp,
449                                                            tbl_db->tbl_db[parms->dir],
450                                                            parms->type,
451                                                            &base,
452                                                            &shift);
453                         if (rc) {
454                                 TFP_DRV_LOG(ERR,
455                                             "%s: Failed to get table info:%d\n",
456                                             tf_dir_2_str(parms->dir),
457                                             parms->type);
458                                 return rc;
459                         }
460                 }
461                 TF_TBL_PTR_TO_RM(&raparms.index, parms->idx, base, shift);
462
463                 raparms.rm_db = tbl_db->tbl_db[parms->dir];
464                 raparms.subtype = parms->type;
465                 raparms.allocated = &rallocated;
466                 rc = tf_rm_is_allocated(&raparms);
467                 if (rc)
468                         return rc;
469
470                 if (rallocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
471                         TFP_DRV_LOG(ERR,
472                            "%s, Invalid or not allocated index, type:%s, idx:%d\n",
473                            tf_dir_2_str(parms->dir),
474                            tf_tbl_type_2_str(parms->type),
475                            parms->idx);
476                         return -EINVAL;
477                 }
478         } else {
479                 aparms.sram_offset = parms->idx;
480                 aparms.slice_size = iparms.slice_size;
481                 aparms.bank_id = iparms.bank_id;
482                 aparms.dir = parms->dir;
483                 aparms.is_allocated = &allocated;
484                 rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
485                 if (rc || !allocated) {
486                         TFP_DRV_LOG(ERR,
487                                     "%s: Entry not allocated:%s idx(%d):(%s)\n",
488                                     tf_dir_2_str(parms->dir),
489                                     tf_tbl_type_2_str(parms->type),
490                                     parms->idx,
491                                     strerror(-rc));
492                         rc = -ENOMEM;
493                         return rc;
494                 }
495         }
496         /* Set the entry */
497         hparms.rm_db = tbl_db->tbl_db[parms->dir];
498         hparms.subtype = parms->type;
499         hparms.hcapi_type = &hcapi_type;
500         rc = tf_rm_get_hcapi_type(&hparms);
501         if (rc) {
502                 TFP_DRV_LOG(ERR,
503                             "%s, Failed type lookup, type:%s, rc:%s\n",
504                             tf_dir_2_str(parms->dir),
505                             tf_tbl_type_2_str(parms->type),
506                             strerror(-rc));
507                 return rc;
508         }
509
510         rc = tf_msg_set_tbl_entry(tfp,
511                                   parms->dir,
512                                   hcapi_type,
513                                   parms->data_sz_in_bytes,
514                                   parms->data,
515                                   parms->idx);
516         if (rc) {
517                 TFP_DRV_LOG(ERR,
518                             "%s, Set failed, type:%s, rc:%s\n",
519                             tf_dir_2_str(parms->dir),
520                             tf_tbl_type_2_str(parms->type),
521                             strerror(-rc));
522                 return rc;
523         }
524         return rc;
525 }
526
527 int
528 tf_tbl_sram_get(struct tf *tfp,
529                 struct tf_tbl_get_parms *parms)
530 {
531         int rc;
532         uint16_t hcapi_type;
533         bool allocated = 0;
534         struct tf_rm_get_hcapi_parms hparms = { 0 };
535         struct tf_session *tfs;
536         struct tf_dev_info *dev;
537         struct tbl_rm_db *tbl_db;
538         void *tbl_db_ptr = NULL;
539         struct tf_tbl_sram_get_info_parms iparms = { 0 };
540         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
541         void *sram_handle = NULL;
542         bool clear_on_read = false;
543
544         TF_CHECK_PARMS3(tfp, parms, parms->data);
545
546         /* Retrieve the session information */
547         rc = tf_session_get(tfp, &tfs, &dev);
548         if (rc)
549                 return rc;
550
551         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
552         if (rc) {
553                 TFP_DRV_LOG(ERR,
554                             "Failed to get em_ext_db from session, rc:%s\n",
555                             strerror(-rc));
556                 return rc;
557         }
558         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
559
560         rc = tf_session_get_sram_db(tfp, &sram_handle);
561         if (rc) {
562                 TFP_DRV_LOG(ERR,
563                             "Failed to get sram_handle from session, rc:%s\n",
564                             strerror(-rc));
565                 return rc;
566         }
567
568         iparms.rm_db = tbl_db->tbl_db[parms->dir];
569         iparms.dir = parms->dir;
570         iparms.tbl_type = parms->type;
571
572         rc = tf_tbl_sram_get_info(&iparms);
573         if (rc) {
574                 TFP_DRV_LOG(ERR,
575                             "%s: Failed to get table info:%s\n",
576                             tf_dir_2_str(parms->dir),
577                             tf_tbl_type_2_str(parms->type));
578                 return rc;
579         }
580
581         aparms.sram_offset = parms->idx;
582         aparms.slice_size = iparms.slice_size;
583         aparms.bank_id = iparms.bank_id;
584         aparms.dir = parms->dir;
585         aparms.is_allocated = &allocated;
586
587         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
588         if (rc || !allocated) {
589                 TFP_DRV_LOG(ERR,
590                             "%s: Entry not allocated:%s idx(%d):(%s)\n",
591                             tf_dir_2_str(parms->dir),
592                             tf_tbl_type_2_str(parms->type),
593                             parms->idx,
594                             strerror(-rc));
595                 rc = -ENOMEM;
596                 return rc;
597         }
598
599         /* Get the entry */
600         hparms.rm_db = tbl_db->tbl_db[parms->dir];
601         hparms.subtype = parms->type;
602         hparms.hcapi_type = &hcapi_type;
603         rc = tf_rm_get_hcapi_type(&hparms);
604         if (rc) {
605                 TFP_DRV_LOG(ERR,
606                             "%s, Failed type lookup, type:%s, rc:%s\n",
607                             tf_dir_2_str(parms->dir),
608                             tf_tbl_type_2_str(parms->type),
609                             strerror(-rc));
610                 return rc;
611         }
612         if (parms->type == TF_TBL_TYPE_ACT_STATS_64)
613                 clear_on_read = true;
614
615         /* Get the entry */
616         rc = tf_msg_get_tbl_entry(tfp,
617                                   parms->dir,
618                                   hcapi_type,
619                                   parms->data_sz_in_bytes,
620                                   parms->data,
621                                   parms->idx,
622                                   clear_on_read);
623         if (rc) {
624                 TFP_DRV_LOG(ERR,
625                             "%s, Get failed, type:%s, rc:%s\n",
626                             tf_dir_2_str(parms->dir),
627                             tf_tbl_type_2_str(parms->type),
628                             strerror(-rc));
629                 return rc;
630         }
631         return rc;
632 }
633
634 int
635 tf_tbl_sram_bulk_get(struct tf *tfp,
636                      struct tf_tbl_get_bulk_parms *parms)
637 {
638         int rc;
639         uint16_t hcapi_type;
640         struct tf_rm_get_hcapi_parms hparms = { 0 };
641         struct tf_tbl_sram_get_info_parms iparms = { 0 };
642         struct tf_session *tfs;
643         struct tf_dev_info *dev;
644         struct tbl_rm_db *tbl_db;
645         void *tbl_db_ptr = NULL;
646         uint16_t idx;
647         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
648         bool allocated = false;
649         void *sram_handle = NULL;
650         bool clear_on_read = false;
651
652         TF_CHECK_PARMS2(tfp, parms);
653
654         /* Retrieve the session information */
655         rc = tf_session_get(tfp, &tfs, &dev);
656         if (rc)
657                 return rc;
658
659         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
660         if (rc) {
661                 TFP_DRV_LOG(ERR,
662                             "Failed to get em_ext_db from session, rc:%s\n",
663                             strerror(-rc));
664                 return rc;
665         }
666         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
667
668         rc = tf_session_get_sram_db(tfp, &sram_handle);
669         if (rc) {
670                 TFP_DRV_LOG(ERR,
671                             "Failed to get sram_handle from session, rc:%s\n",
672                             strerror(-rc));
673                 return rc;
674         }
675
676         iparms.rm_db = tbl_db->tbl_db[parms->dir];
677         iparms.dir = parms->dir;
678         iparms.tbl_type = parms->type;
679
680         rc = tf_tbl_sram_get_info(&iparms);
681         if (rc) {
682                 TFP_DRV_LOG(ERR,
683                             "%s: Failed to get table info:%s\n",
684                             tf_dir_2_str(parms->dir),
685                             tf_tbl_type_2_str(parms->type));
686                 return rc;
687         }
688
689         /* Validate the start offset and the end offset is allocated
690          * This API is only used for statistics.  8 Byte entry allocation
691          * is used to verify
692          */
693         aparms.sram_offset = parms->starting_idx;
694         aparms.slice_size = iparms.slice_size;
695         aparms.bank_id = iparms.bank_id;
696         aparms.dir = parms->dir;
697         aparms.is_allocated = &allocated;
698         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
699         if (rc || !allocated) {
700                 TFP_DRV_LOG(ERR,
701                             "%s: Entry not allocated:%s starting_idx(%d):(%s)\n",
702                             tf_dir_2_str(parms->dir),
703                             tf_tbl_type_2_str(parms->type),
704                             parms->starting_idx,
705                             strerror(-rc));
706                 rc = -ENOMEM;
707                 return rc;
708         }
709         idx = parms->starting_idx + parms->num_entries - 1;
710         aparms.sram_offset = idx;
711         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
712         if (rc || !allocated) {
713                 TFP_DRV_LOG(ERR,
714                             "%s: Entry not allocated:%s last_idx(%d):(%s)\n",
715                             tf_dir_2_str(parms->dir),
716                             tf_tbl_type_2_str(parms->type),
717                             idx,
718                             strerror(-rc));
719                 rc = -ENOMEM;
720                 return rc;
721         }
722
723         hparms.rm_db = tbl_db->tbl_db[parms->dir];
724         hparms.subtype = parms->type;
725         hparms.hcapi_type = &hcapi_type;
726         rc = tf_rm_get_hcapi_type(&hparms);
727         if (rc) {
728                 TFP_DRV_LOG(ERR,
729                             "%s, Failed type lookup, type:%s, rc:%s\n",
730                             tf_dir_2_str(parms->dir),
731                             tf_tbl_type_2_str(parms->type),
732                             strerror(-rc));
733                 return rc;
734         }
735
736         if (parms->type == TF_TBL_TYPE_ACT_STATS_64)
737                 clear_on_read = true;
738
739         /* Get the entries */
740         rc = tf_msg_bulk_get_tbl_entry(tfp,
741                                        parms->dir,
742                                        hcapi_type,
743                                        parms->starting_idx,
744                                        parms->num_entries,
745                                        parms->entry_sz_in_bytes,
746                                        parms->physical_mem_addr,
747                                        clear_on_read);
748         if (rc) {
749                 TFP_DRV_LOG(ERR,
750                             "%s, Bulk get failed, type:%s, rc:%s\n",
751                             tf_dir_2_str(parms->dir),
752                             tf_tbl_type_2_str(parms->type),
753                             strerror(-rc));
754         }
755         return rc;
756 }