eal: remove sys/queue.h from public headers
[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
543         TF_CHECK_PARMS3(tfp, parms, parms->data);
544
545         /* Retrieve the session information */
546         rc = tf_session_get(tfp, &tfs, &dev);
547         if (rc)
548                 return rc;
549
550         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
551         if (rc) {
552                 TFP_DRV_LOG(ERR,
553                             "Failed to get em_ext_db from session, rc:%s\n",
554                             strerror(-rc));
555                 return rc;
556         }
557         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
558
559         rc = tf_session_get_sram_db(tfp, &sram_handle);
560         if (rc) {
561                 TFP_DRV_LOG(ERR,
562                             "Failed to get sram_handle from session, rc:%s\n",
563                             strerror(-rc));
564                 return rc;
565         }
566
567         iparms.rm_db = tbl_db->tbl_db[parms->dir];
568         iparms.dir = parms->dir;
569         iparms.tbl_type = parms->type;
570
571         rc = tf_tbl_sram_get_info(&iparms);
572         if (rc) {
573                 TFP_DRV_LOG(ERR,
574                             "%s: Failed to get table info:%s\n",
575                             tf_dir_2_str(parms->dir),
576                             tf_tbl_type_2_str(parms->type));
577                 return rc;
578         }
579
580         aparms.sram_offset = parms->idx;
581         aparms.slice_size = iparms.slice_size;
582         aparms.bank_id = iparms.bank_id;
583         aparms.dir = parms->dir;
584         aparms.is_allocated = &allocated;
585
586         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
587         if (rc || !allocated) {
588                 TFP_DRV_LOG(ERR,
589                             "%s: Entry not allocated:%s idx(%d):(%s)\n",
590                             tf_dir_2_str(parms->dir),
591                             tf_tbl_type_2_str(parms->type),
592                             parms->idx,
593                             strerror(-rc));
594                 rc = -ENOMEM;
595                 return rc;
596         }
597
598         /* Get the entry */
599         hparms.rm_db = tbl_db->tbl_db[parms->dir];
600         hparms.subtype = parms->type;
601         hparms.hcapi_type = &hcapi_type;
602         rc = tf_rm_get_hcapi_type(&hparms);
603         if (rc) {
604                 TFP_DRV_LOG(ERR,
605                             "%s, Failed type lookup, type:%s, rc:%s\n",
606                             tf_dir_2_str(parms->dir),
607                             tf_tbl_type_2_str(parms->type),
608                             strerror(-rc));
609                 return rc;
610         }
611
612         /* Get the entry */
613         rc = tf_msg_get_tbl_entry(tfp,
614                                   parms->dir,
615                                   hcapi_type,
616                                   parms->data_sz_in_bytes,
617                                   parms->data,
618                                   parms->idx);
619         if (rc) {
620                 TFP_DRV_LOG(ERR,
621                             "%s, Get failed, type:%s, rc:%s\n",
622                             tf_dir_2_str(parms->dir),
623                             tf_tbl_type_2_str(parms->type),
624                             strerror(-rc));
625                 return rc;
626         }
627         return rc;
628 }
629
630 int
631 tf_tbl_sram_bulk_get(struct tf *tfp,
632                      struct tf_tbl_get_bulk_parms *parms)
633 {
634         int rc;
635         uint16_t hcapi_type;
636         struct tf_rm_get_hcapi_parms hparms = { 0 };
637         struct tf_tbl_sram_get_info_parms iparms = { 0 };
638         struct tf_session *tfs;
639         struct tf_dev_info *dev;
640         struct tbl_rm_db *tbl_db;
641         void *tbl_db_ptr = NULL;
642         uint16_t idx;
643         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
644         bool allocated = false;
645         void *sram_handle = NULL;
646
647         TF_CHECK_PARMS2(tfp, parms);
648
649         /* Retrieve the session information */
650         rc = tf_session_get(tfp, &tfs, &dev);
651         if (rc)
652                 return rc;
653
654         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
655         if (rc) {
656                 TFP_DRV_LOG(ERR,
657                             "Failed to get em_ext_db from session, rc:%s\n",
658                             strerror(-rc));
659                 return rc;
660         }
661         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
662
663         rc = tf_session_get_sram_db(tfp, &sram_handle);
664         if (rc) {
665                 TFP_DRV_LOG(ERR,
666                             "Failed to get sram_handle from session, rc:%s\n",
667                             strerror(-rc));
668                 return rc;
669         }
670
671         iparms.rm_db = tbl_db->tbl_db[parms->dir];
672         iparms.dir = parms->dir;
673         iparms.tbl_type = parms->type;
674
675         rc = tf_tbl_sram_get_info(&iparms);
676         if (rc) {
677                 TFP_DRV_LOG(ERR,
678                             "%s: Failed to get table info:%s\n",
679                             tf_dir_2_str(parms->dir),
680                             tf_tbl_type_2_str(parms->type));
681                 return rc;
682         }
683
684         /* Validate the start offset and the end offset is allocated
685          * This API is only used for statistics.  8 Byte entry allocation
686          * is used to verify
687          */
688         aparms.sram_offset = parms->starting_idx;
689         aparms.slice_size = iparms.slice_size;
690         aparms.bank_id = iparms.bank_id;
691         aparms.dir = parms->dir;
692         aparms.is_allocated = &allocated;
693         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
694         if (rc || !allocated) {
695                 TFP_DRV_LOG(ERR,
696                             "%s: Entry not allocated:%s starting_idx(%d):(%s)\n",
697                             tf_dir_2_str(parms->dir),
698                             tf_tbl_type_2_str(parms->type),
699                             parms->starting_idx,
700                             strerror(-rc));
701                 rc = -ENOMEM;
702                 return rc;
703         }
704         idx = parms->starting_idx + parms->num_entries - 1;
705         aparms.sram_offset = idx;
706         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
707         if (rc || !allocated) {
708                 TFP_DRV_LOG(ERR,
709                             "%s: Entry not allocated:%s last_idx(%d):(%s)\n",
710                             tf_dir_2_str(parms->dir),
711                             tf_tbl_type_2_str(parms->type),
712                             idx,
713                             strerror(-rc));
714                 rc = -ENOMEM;
715                 return rc;
716         }
717
718         hparms.rm_db = tbl_db->tbl_db[parms->dir];
719         hparms.subtype = parms->type;
720         hparms.hcapi_type = &hcapi_type;
721         rc = tf_rm_get_hcapi_type(&hparms);
722         if (rc) {
723                 TFP_DRV_LOG(ERR,
724                             "%s, Failed type lookup, type:%s, rc:%s\n",
725                             tf_dir_2_str(parms->dir),
726                             tf_tbl_type_2_str(parms->type),
727                             strerror(-rc));
728                 return rc;
729         }
730
731         /* Get the entries */
732         rc = tf_msg_bulk_get_tbl_entry(tfp,
733                                        parms->dir,
734                                        hcapi_type,
735                                        parms->starting_idx,
736                                        parms->num_entries,
737                                        parms->entry_sz_in_bytes,
738                                        parms->physical_mem_addr);
739         if (rc) {
740                 TFP_DRV_LOG(ERR,
741                             "%s, Bulk get failed, type:%s, rc:%s\n",
742                             tf_dir_2_str(parms->dir),
743                             tf_tbl_type_2_str(parms->type),
744                             strerror(-rc));
745         }
746         return rc;
747 }