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