167078a8c6e8215e6a6dbfbaf280acfedae8e27c
[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         TFP_DRV_LOG(DEBUG,
138                     "(%s) bank(%s) slice_size(%s)\n",
139                     tf_tbl_type_2_str(parms->tbl_type),
140                     tf_sram_bank_2_str(parms->bank_id),
141                     tf_sram_slice_2_str(parms->slice_size));
142         return rc;
143 }
144
145 int
146 tf_tbl_sram_bind(struct tf *tfp __rte_unused)
147 {
148         int rc = 0;
149         void *sram_handle = NULL;
150
151         TF_CHECK_PARMS1(tfp);
152
153         rc = tf_sram_mgr_bind(&sram_handle);
154
155         tf_session_set_sram_db(tfp, sram_handle);
156
157         TFP_DRV_LOG(INFO,
158                     "SRAM Table - initialized\n");
159
160         return rc;
161 }
162
163 int
164 tf_tbl_sram_unbind(struct tf *tfp __rte_unused)
165 {
166         int rc = 0;
167         void *sram_handle = NULL;
168
169         TF_CHECK_PARMS1(tfp);
170
171         rc = tf_session_get_sram_db(tfp, &sram_handle);
172         if (rc) {
173                 TFP_DRV_LOG(ERR,
174                             "Failed to get sram_handle from session, rc:%s\n",
175                             strerror(-rc));
176                 return rc;
177         }
178         if (sram_handle)
179                 rc = tf_sram_mgr_unbind(sram_handle);
180
181         TFP_DRV_LOG(INFO,
182                     "SRAM Table - deinitialized\n");
183         return rc;
184 }
185
186 int
187 tf_tbl_sram_alloc(struct tf *tfp,
188                   struct tf_tbl_alloc_parms *parms)
189 {
190         int rc;
191         uint16_t idx;
192         struct tf_session *tfs;
193         struct tf_dev_info *dev;
194         struct tf_tbl_sram_get_info_parms iparms = { 0 };
195         struct tf_sram_mgr_alloc_parms aparms = { 0 };
196         struct tbl_rm_db *tbl_db;
197         void *tbl_db_ptr = NULL;
198         void *sram_handle = NULL;
199
200         TF_CHECK_PARMS2(tfp, parms);
201
202         /* Retrieve the session information */
203         rc = tf_session_get(tfp, &tfs, &dev);
204         if (rc)
205                 return rc;
206
207         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
208         if (rc) {
209                 TFP_DRV_LOG(ERR,
210                             "Failed to get tbl_db from session, rc:%s\n",
211                             strerror(-rc));
212                 return rc;
213         }
214
215         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
216
217         rc = tf_session_get_sram_db(tfp, &sram_handle);
218         if (rc) {
219                 TFP_DRV_LOG(ERR,
220                             "Failed to get sram_handle from session, rc:%s\n",
221                             strerror(-rc));
222                 return rc;
223         }
224
225         iparms.rm_db = tbl_db->tbl_db[parms->dir];
226         iparms.dir = parms->dir;
227         iparms.tbl_type = parms->type;
228
229         rc = tf_tbl_sram_get_info(&iparms);
230
231         if (rc) {
232                 TFP_DRV_LOG(ERR,
233                             "%s: Failed to get SRAM info %s\n",
234                             tf_dir_2_str(parms->dir),
235                             tf_tbl_type_2_str(parms->type));
236                 return rc;
237         }
238
239         aparms.dir = parms->dir;
240         aparms.bank_id = iparms.bank_id;
241         aparms.slice_size = iparms.slice_size;
242         aparms.sram_offset = &idx;
243         aparms.tbl_type = parms->type;
244         aparms.rm_db = tbl_db->tbl_db[parms->dir];
245
246         rc = tf_sram_mgr_alloc(sram_handle, &aparms);
247         if (rc) {
248                 TFP_DRV_LOG(ERR,
249                             "%s: Failed to allocate SRAM table:%s\n",
250                             tf_dir_2_str(parms->dir),
251                             tf_tbl_type_2_str(parms->type));
252                 return rc;
253         }
254         *parms->idx = idx;
255
256 #if (DBG_SRAM == 1)
257         {
258                 struct tf_sram_mgr_dump_parms dparms;
259
260                 dparms.dir = parms->dir;
261                 dparms.bank_id = iparms.bank_id;
262                 dparms.slice_size = iparms.slice_size;
263
264                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
265         }
266 #endif
267
268         return rc;
269 }
270
271 int
272 tf_tbl_sram_free(struct tf *tfp __rte_unused,
273                  struct tf_tbl_free_parms *parms)
274 {
275         int rc;
276         struct tf_session *tfs;
277         struct tf_dev_info *dev;
278         struct tbl_rm_db *tbl_db;
279         void *tbl_db_ptr = NULL;
280         struct tf_tbl_sram_get_info_parms iparms = { 0 };
281         struct tf_sram_mgr_free_parms fparms = { 0 };
282         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
283         bool allocated = false;
284         void *sram_handle = NULL;
285
286         TF_CHECK_PARMS2(tfp, parms);
287
288         /* Retrieve the session information */
289         rc = tf_session_get(tfp, &tfs, &dev);
290         if (rc)
291                 return rc;
292
293         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
294         if (rc) {
295                 TFP_DRV_LOG(ERR,
296                             "Failed to get em_ext_db from session, rc:%s\n",
297                             strerror(-rc));
298                 return rc;
299         }
300         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
301
302         rc = tf_session_get_sram_db(tfp, &sram_handle);
303         if (rc) {
304                 TFP_DRV_LOG(ERR,
305                             "Failed to get sram_handle from session, rc:%s\n",
306                             strerror(-rc));
307                 return rc;
308         }
309
310         iparms.rm_db = tbl_db->tbl_db[parms->dir];
311         iparms.dir = parms->dir;
312         iparms.tbl_type = parms->type;
313
314         rc = tf_tbl_sram_get_info(&iparms);
315         if (rc) {
316                 TFP_DRV_LOG(ERR,
317                             "%s: Failed to get table info:%s\n",
318                             tf_dir_2_str(parms->dir),
319                             tf_tbl_type_2_str(parms->type));
320                 return rc;
321         }
322
323 #if (DBG_SRAM == 1)
324         {
325                 struct tf_sram_mgr_dump_parms dparms;
326
327                 printf("%s: %s: %s\n", tf_dir_2_str(parms->dir),
328                        tf_sram_slice_2_str(iparms.slice_size),
329                        tf_sram_bank_2_str(iparms.bank_id));
330
331                 dparms.dir = parms->dir;
332                 dparms.bank_id = iparms.bank_id;
333                 dparms.slice_size = iparms.slice_size;
334
335                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
336         }
337 #endif
338
339         aparms.sram_offset = parms->idx;
340         aparms.slice_size = iparms.slice_size;
341         aparms.bank_id = iparms.bank_id;
342         aparms.dir = parms->dir;
343         aparms.is_allocated = &allocated;
344
345         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
346         if (rc || !allocated) {
347                 TFP_DRV_LOG(ERR,
348                             "%s: Free of invalid entry:%s idx(%d):(%s)\n",
349                             tf_dir_2_str(parms->dir),
350                             tf_tbl_type_2_str(parms->type),
351                             parms->idx,
352                             strerror(-rc));
353                 rc = -ENOMEM;
354                 return rc;
355         }
356
357         fparms.rm_db = tbl_db->tbl_db[parms->dir];
358         fparms.tbl_type = parms->type;
359         fparms.sram_offset = parms->idx;
360         fparms.slice_size = iparms.slice_size;
361         fparms.bank_id = iparms.bank_id;
362         fparms.dir = parms->dir;
363 #if (STATS_CLEAR_ON_READ_SUPPORT == 0)
364         fparms.tfp = tfp;
365 #endif
366         rc = tf_sram_mgr_free(sram_handle, &fparms);
367         if (rc) {
368                 TFP_DRV_LOG(ERR,
369                             "%s: Failed to free entry:%s idx(%d)\n",
370                             tf_dir_2_str(parms->dir),
371                             tf_tbl_type_2_str(parms->type),
372                             parms->idx);
373                 return rc;
374         }
375
376
377 #if (DBG_SRAM == 1)
378         {
379                 struct tf_sram_mgr_dump_parms dparms;
380
381                 printf("%s: %s: %s\n", tf_dir_2_str(parms->dir),
382                        tf_sram_slice_2_str(iparms.slice_size),
383                        tf_sram_bank_2_str(iparms.bank_id));
384
385                 dparms.dir = parms->dir;
386                 dparms.bank_id = iparms.bank_id;
387                 dparms.slice_size = iparms.slice_size;
388
389                 rc = tf_sram_mgr_dump(sram_handle, &dparms);
390         }
391 #endif
392         return rc;
393 }
394
395 int
396 tf_tbl_sram_set(struct tf *tfp,
397                 struct tf_tbl_set_parms *parms)
398 {
399         int rc;
400         bool allocated = 0;
401         int rallocated = 0;
402         uint16_t hcapi_type;
403         struct tf_rm_get_hcapi_parms hparms = { 0 };
404         struct tf_session *tfs;
405         struct tf_dev_info *dev;
406         struct tbl_rm_db *tbl_db;
407         void *tbl_db_ptr = NULL;
408         struct tf_tbl_sram_get_info_parms iparms = { 0 };
409         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
410         struct tf_rm_is_allocated_parms raparms = { 0 };
411         void *sram_handle = NULL;
412         uint16_t base = 0, shift = 0;
413
414
415         TF_CHECK_PARMS3(tfp, parms, parms->data);
416
417         /* Retrieve the session information */
418         rc = tf_session_get(tfp, &tfs, &dev);
419         if (rc)
420                 return rc;
421
422         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
423         if (rc) {
424                 TFP_DRV_LOG(ERR,
425                             "Failed to get em_ext_db from session, rc:%s\n",
426                             strerror(-rc));
427                 return rc;
428         }
429         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
430
431         rc = tf_session_get_sram_db(tfp, &sram_handle);
432         if (rc) {
433                 TFP_DRV_LOG(ERR,
434                             "Failed to get sram_handle from session, rc:%s\n",
435                             strerror(-rc));
436                 return rc;
437         }
438
439         iparms.rm_db = tbl_db->tbl_db[parms->dir];
440         iparms.dir = parms->dir;
441         iparms.tbl_type = parms->type;
442
443         rc = tf_tbl_sram_get_info(&iparms);
444         if (rc) {
445                 TFP_DRV_LOG(ERR,
446                             "%s: Failed to get table info:%s\n",
447                             tf_dir_2_str(parms->dir),
448                             tf_tbl_type_2_str(parms->type));
449                 return rc;
450         }
451
452         if (tf_session_is_shared_session(tfs)) {
453                 /* Only get table info if required for the device */
454                 if (dev->ops->tf_dev_get_tbl_info) {
455                         rc = dev->ops->tf_dev_get_tbl_info(tfp,
456                                                            tbl_db->tbl_db[parms->dir],
457                                                            parms->type,
458                                                            &base,
459                                                            &shift);
460                         if (rc) {
461                                 TFP_DRV_LOG(ERR,
462                                             "%s: Failed to get table info:%d\n",
463                                             tf_dir_2_str(parms->dir),
464                                             parms->type);
465                                 return rc;
466                         }
467                 }
468                 TF_TBL_PTR_TO_RM(&raparms.index, parms->idx, base, shift);
469
470                 raparms.rm_db = tbl_db->tbl_db[parms->dir];
471                 raparms.subtype = parms->type;
472                 raparms.allocated = &rallocated;
473                 rc = tf_rm_is_allocated(&raparms);
474                 if (rc)
475                         return rc;
476
477                 if (rallocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
478                         TFP_DRV_LOG(ERR,
479                            "%s, Invalid or not allocated index, type:%s, idx:%d\n",
480                            tf_dir_2_str(parms->dir),
481                            tf_tbl_type_2_str(parms->type),
482                            parms->idx);
483                         return -EINVAL;
484                 }
485         } else {
486                 aparms.sram_offset = parms->idx;
487                 aparms.slice_size = iparms.slice_size;
488                 aparms.bank_id = iparms.bank_id;
489                 aparms.dir = parms->dir;
490                 aparms.is_allocated = &allocated;
491                 rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
492                 if (rc || !allocated) {
493                         TFP_DRV_LOG(ERR,
494                                     "%s: Entry not allocated:%s idx(%d):(%s)\n",
495                                     tf_dir_2_str(parms->dir),
496                                     tf_tbl_type_2_str(parms->type),
497                                     parms->idx,
498                                     strerror(-rc));
499                         rc = -ENOMEM;
500                         return rc;
501                 }
502         }
503         /* Set the entry */
504         hparms.rm_db = tbl_db->tbl_db[parms->dir];
505         hparms.subtype = parms->type;
506         hparms.hcapi_type = &hcapi_type;
507         rc = tf_rm_get_hcapi_type(&hparms);
508         if (rc) {
509                 TFP_DRV_LOG(ERR,
510                             "%s, Failed type lookup, type:%s, rc:%s\n",
511                             tf_dir_2_str(parms->dir),
512                             tf_tbl_type_2_str(parms->type),
513                             strerror(-rc));
514                 return rc;
515         }
516
517         rc = tf_msg_set_tbl_entry(tfp,
518                                   parms->dir,
519                                   hcapi_type,
520                                   parms->data_sz_in_bytes,
521                                   parms->data,
522                                   parms->idx);
523         if (rc) {
524                 TFP_DRV_LOG(ERR,
525                             "%s, Set failed, type:%s, rc:%s\n",
526                             tf_dir_2_str(parms->dir),
527                             tf_tbl_type_2_str(parms->type),
528                             strerror(-rc));
529                 return rc;
530         }
531         return rc;
532 }
533
534 int
535 tf_tbl_sram_get(struct tf *tfp,
536                 struct tf_tbl_get_parms *parms)
537 {
538         int rc;
539         uint16_t hcapi_type;
540         bool allocated = 0;
541         struct tf_rm_get_hcapi_parms hparms = { 0 };
542         struct tf_session *tfs;
543         struct tf_dev_info *dev;
544         struct tbl_rm_db *tbl_db;
545         void *tbl_db_ptr = NULL;
546         struct tf_tbl_sram_get_info_parms iparms = { 0 };
547         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
548         void *sram_handle = NULL;
549
550         TF_CHECK_PARMS3(tfp, parms, parms->data);
551
552         /* Retrieve the session information */
553         rc = tf_session_get(tfp, &tfs, &dev);
554         if (rc)
555                 return rc;
556
557         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
558         if (rc) {
559                 TFP_DRV_LOG(ERR,
560                             "Failed to get em_ext_db from session, rc:%s\n",
561                             strerror(-rc));
562                 return rc;
563         }
564         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
565
566         rc = tf_session_get_sram_db(tfp, &sram_handle);
567         if (rc) {
568                 TFP_DRV_LOG(ERR,
569                             "Failed to get sram_handle from session, rc:%s\n",
570                             strerror(-rc));
571                 return rc;
572         }
573
574         iparms.rm_db = tbl_db->tbl_db[parms->dir];
575         iparms.dir = parms->dir;
576         iparms.tbl_type = parms->type;
577
578         rc = tf_tbl_sram_get_info(&iparms);
579         if (rc) {
580                 TFP_DRV_LOG(ERR,
581                             "%s: Failed to get table info:%s\n",
582                             tf_dir_2_str(parms->dir),
583                             tf_tbl_type_2_str(parms->type));
584                 return rc;
585         }
586
587         aparms.sram_offset = parms->idx;
588         aparms.slice_size = iparms.slice_size;
589         aparms.bank_id = iparms.bank_id;
590         aparms.dir = parms->dir;
591         aparms.is_allocated = &allocated;
592
593         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
594         if (rc || !allocated) {
595                 TFP_DRV_LOG(ERR,
596                             "%s: Entry not allocated:%s idx(%d):(%s)\n",
597                             tf_dir_2_str(parms->dir),
598                             tf_tbl_type_2_str(parms->type),
599                             parms->idx,
600                             strerror(-rc));
601                 rc = -ENOMEM;
602                 return rc;
603         }
604
605         /* Get the entry */
606         hparms.rm_db = tbl_db->tbl_db[parms->dir];
607         hparms.subtype = parms->type;
608         hparms.hcapi_type = &hcapi_type;
609         rc = tf_rm_get_hcapi_type(&hparms);
610         if (rc) {
611                 TFP_DRV_LOG(ERR,
612                             "%s, Failed type lookup, type:%s, rc:%s\n",
613                             tf_dir_2_str(parms->dir),
614                             tf_tbl_type_2_str(parms->type),
615                             strerror(-rc));
616                 return rc;
617         }
618
619         /* Get the entry */
620         rc = tf_msg_get_tbl_entry(tfp,
621                                   parms->dir,
622                                   hcapi_type,
623                                   parms->data_sz_in_bytes,
624                                   parms->data,
625                                   parms->idx);
626         if (rc) {
627                 TFP_DRV_LOG(ERR,
628                             "%s, Get failed, type:%s, rc:%s\n",
629                             tf_dir_2_str(parms->dir),
630                             tf_tbl_type_2_str(parms->type),
631                             strerror(-rc));
632                 return rc;
633         }
634         return rc;
635 }
636
637 int
638 tf_tbl_sram_bulk_get(struct tf *tfp,
639                      struct tf_tbl_get_bulk_parms *parms)
640 {
641         int rc;
642         uint16_t hcapi_type;
643         struct tf_rm_get_hcapi_parms hparms = { 0 };
644         struct tf_tbl_sram_get_info_parms iparms = { 0 };
645         struct tf_session *tfs;
646         struct tf_dev_info *dev;
647         struct tbl_rm_db *tbl_db;
648         void *tbl_db_ptr = NULL;
649         uint16_t idx;
650         struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
651         bool allocated = false;
652         void *sram_handle = NULL;
653
654         TF_CHECK_PARMS2(tfp, parms);
655
656         /* Retrieve the session information */
657         rc = tf_session_get(tfp, &tfs, &dev);
658         if (rc)
659                 return rc;
660
661         rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
662         if (rc) {
663                 TFP_DRV_LOG(ERR,
664                             "Failed to get em_ext_db from session, rc:%s\n",
665                             strerror(-rc));
666                 return rc;
667         }
668         tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
669
670         rc = tf_session_get_sram_db(tfp, &sram_handle);
671         if (rc) {
672                 TFP_DRV_LOG(ERR,
673                             "Failed to get sram_handle from session, rc:%s\n",
674                             strerror(-rc));
675                 return rc;
676         }
677
678         iparms.rm_db = tbl_db->tbl_db[parms->dir];
679         iparms.dir = parms->dir;
680         iparms.tbl_type = parms->type;
681
682         rc = tf_tbl_sram_get_info(&iparms);
683         if (rc) {
684                 TFP_DRV_LOG(ERR,
685                             "%s: Failed to get table info:%s\n",
686                             tf_dir_2_str(parms->dir),
687                             tf_tbl_type_2_str(parms->type));
688                 return rc;
689         }
690
691         /* Validate the start offset and the end offset is allocated
692          * This API is only used for statistics.  8 Byte entry allocation
693          * is used to verify
694          */
695         aparms.sram_offset = parms->starting_idx;
696         aparms.slice_size = iparms.slice_size;
697         aparms.bank_id = iparms.bank_id;
698         aparms.dir = parms->dir;
699         aparms.is_allocated = &allocated;
700         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
701         if (rc || !allocated) {
702                 TFP_DRV_LOG(ERR,
703                             "%s: Entry not allocated:%s starting_idx(%d):(%s)\n",
704                             tf_dir_2_str(parms->dir),
705                             tf_tbl_type_2_str(parms->type),
706                             parms->starting_idx,
707                             strerror(-rc));
708                 rc = -ENOMEM;
709                 return rc;
710         }
711         idx = parms->starting_idx + parms->num_entries - 1;
712         aparms.sram_offset = idx;
713         rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
714         if (rc || !allocated) {
715                 TFP_DRV_LOG(ERR,
716                             "%s: Entry not allocated:%s last_idx(%d):(%s)\n",
717                             tf_dir_2_str(parms->dir),
718                             tf_tbl_type_2_str(parms->type),
719                             idx,
720                             strerror(-rc));
721                 rc = -ENOMEM;
722                 return rc;
723         }
724
725         hparms.rm_db = tbl_db->tbl_db[parms->dir];
726         hparms.subtype = parms->type;
727         hparms.hcapi_type = &hcapi_type;
728         rc = tf_rm_get_hcapi_type(&hparms);
729         if (rc) {
730                 TFP_DRV_LOG(ERR,
731                             "%s, Failed type lookup, type:%s, rc:%s\n",
732                             tf_dir_2_str(parms->dir),
733                             tf_tbl_type_2_str(parms->type),
734                             strerror(-rc));
735                 return rc;
736         }
737
738         /* Get the entries */
739         rc = tf_msg_bulk_get_tbl_entry(tfp,
740                                        parms->dir,
741                                        hcapi_type,
742                                        parms->starting_idx,
743                                        parms->num_entries,
744                                        parms->entry_sz_in_bytes,
745                                        parms->physical_mem_addr);
746         if (rc) {
747                 TFP_DRV_LOG(ERR,
748                             "%s, Bulk get failed, type:%s, rc:%s\n",
749                             tf_dir_2_str(parms->dir),
750                             tf_tbl_type_2_str(parms->type),
751                             strerror(-rc));
752         }
753         return rc;
754 }