net/bnxt: modify table processing
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl.c
index d7f5de4..ced5913 100644 (file)
 /* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019-2020 Broadcom
+ * Copyright(c) 2019-2021 Broadcom
  * All rights reserved.
  */
 
 /* Truflow Table APIs and supporting code */
 
-#include <stdio.h>
-#include <string.h>
-#include <stdbool.h>
-#include <math.h>
-#include <sys/param.h>
 #include <rte_common.h>
-#include <rte_errno.h>
-#include "hsi_struct_def_dpdk.h"
 
-#include "tf_core.h"
+#include "tf_tbl.h"
+#include "tf_common.h"
+#include "tf_rm.h"
 #include "tf_util.h"
-#include "tf_em.h"
 #include "tf_msg.h"
 #include "tfp.h"
-#include "hwrm_tf.h"
-#include "bnxt.h"
-#include "tf_resources.h"
-#include "tf_rm.h"
-#include "stack.h"
-#include "tf_common.h"
+#include "tf_session.h"
+#include "tf_device.h"
+
+#define TF_TBL_RM_TO_PTR(new_idx, idx, base, shift) {          \
+               *(new_idx) = (((idx) + (base)) << (shift));     \
+}
+
+#define TF_TBL_PTR_TO_RM(new_idx, idx, base, shift) {          \
+               *(new_idx) = (((idx) >> (shift)) - (base));     \
+}
+
+struct tf;
 
 /**
- * Internal function to get a Table Entry. Supports all Table Types
- * except the TF_TBL_TYPE_EXT as that is handled as a table scope.
- *
- * [in] tfp
- *   Pointer to TruFlow handle
- *
- * [in] parms
- *   Pointer to input parameters
- *
- * Returns:
- *   0       - Success
- *   -EINVAL - Parameter error
+ * Table Shadow DBs
  */
-static int
-tf_bulk_get_tbl_entry_internal(struct tf *tfp,
-                         struct tf_bulk_get_tbl_entry_parms *parms)
+static void *shadow_tbl_db[TF_DIR_MAX];
+
+/**
+ * Shadow init flag, set on bind and cleared on unbind
+ */
+static uint8_t shadow_init;
+
+int
+tf_tbl_bind(struct tf *tfp,
+           struct tf_tbl_cfg_parms *parms)
+{
+       int rc, d, i;
+       int db_rc[TF_DIR_MAX] = { 0 };
+       struct tf_rm_create_db_parms db_cfg = { 0 };
+       struct tbl_rm_db *tbl_db;
+       struct tfp_calloc_parms cparms;
+       struct tf_session *tfs;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       memset(&db_cfg, 0, sizeof(db_cfg));
+       cparms.nitems = 1;
+       cparms.size = sizeof(struct tbl_rm_db);
+       cparms.alignment = 0;
+       if (tfp_calloc(&cparms) != 0) {
+               TFP_DRV_LOG(ERR, "tbl_rm_db alloc error %s\n",
+                           strerror(ENOMEM));
+               return -ENOMEM;
+       }
+
+       tbl_db = cparms.mem_va;
+       for (i = 0; i < TF_DIR_MAX; i++)
+               tbl_db->tbl_db[i] = NULL;
+       tf_session_set_db(tfp, TF_MODULE_TYPE_TABLE, tbl_db);
+
+       db_cfg.num_elements = parms->num_elements;
+       db_cfg.module = TF_MODULE_TYPE_TABLE;
+       db_cfg.num_elements = parms->num_elements;
+       db_cfg.cfg = parms->cfg;
+
+       for (d = 0; d < TF_DIR_MAX; d++) {
+               db_cfg.dir = d;
+               db_cfg.alloc_cnt = parms->resources->tbl_cnt[d].cnt;
+               db_cfg.rm_db = (void *)&tbl_db->tbl_db[d];
+               if (tf_session_is_shared_session(tfs) &&
+                       (!tf_session_is_shared_session_creator(tfs)))
+                       db_rc[d] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
+               else
+                       db_rc[d] = tf_rm_create_db(tfp, &db_cfg);
+       }
+
+       /* No db created */
+       if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) {
+               TFP_DRV_LOG(ERR,
+                           "%s: No Table DB created\n",
+                           tf_dir_2_str(d));
+               return db_rc[TF_DIR_RX];
+       }
+
+       TFP_DRV_LOG(INFO,
+                   "Table Type - initialized\n");
+
+       return 0;
+}
+
+int
+tf_tbl_unbind(struct tf *tfp)
+{
+       int rc;
+       int i;
+       struct tf_rm_free_db_parms fparms = { 0 };
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
+       TF_CHECK_PARMS1(tfp);
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc)
+               return 0;
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       for (i = 0; i < TF_DIR_MAX; i++) {
+               if (tbl_db->tbl_db[i] == NULL)
+                       continue;
+               fparms.dir = i;
+               fparms.rm_db = tbl_db->tbl_db[i];
+               rc = tf_rm_free_db(tfp, &fparms);
+               if (rc)
+                       return rc;
+
+               tbl_db->tbl_db[i] = NULL;
+       }
+
+       shadow_init = 0;
+
+       return 0;
+}
+
+int
+tf_tbl_alloc(struct tf *tfp __rte_unused,
+            struct tf_tbl_alloc_parms *parms)
+{
+       int rc;
+       uint32_t idx;
+       struct tf_rm_allocate_parms aparms = { 0 };
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       /* Only get table info if required for the device */
+       if (dev->ops->tf_dev_get_tbl_info) {
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s: Failed to get table info:%d\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type);
+                       return rc;
+               }
+       }
+
+       /* Allocate requested element */
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
+       aparms.subtype = parms->type;
+       aparms.index = &idx;
+       rc = tf_rm_allocate(&aparms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed allocate, type:%d\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type);
+               return rc;
+       }
+
+       TF_TBL_RM_TO_PTR(&idx, idx, base, shift);
+       *parms->idx = idx;
+
+       return 0;
+}
+
+int
+tf_tbl_free(struct tf *tfp __rte_unused,
+           struct tf_tbl_free_parms *parms)
 {
        int rc;
-       int id;
-       uint32_t index;
-       struct bitalloc *session_pool;
-       struct tf_session *tfs = (struct tf_session *)(tfp->session->core_data);
+       struct tf_rm_is_allocated_parms aparms = { 0 };
+       struct tf_rm_free_parms fparms = { 0 };
+       int allocated = 0;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
-       /* Lookup the pool using the table type of the element */
-       rc = tf_rm_lookup_tbl_type_pool(tfs,
-                                       parms->dir,
-                                       parms->type,
-                                       &session_pool);
-       /* Error logging handled by tf_rm_lookup_tbl_type_pool */
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
        if (rc)
                return rc;
 
-       index = parms->starting_idx;
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       /* Only get table info if required for the device */
+       if (dev->ops->tf_dev_get_tbl_info) {
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s: Failed to get table info:%d\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type);
+                       return rc;
+               }
+       }
+
+       /* Check if element is in use */
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
+       aparms.subtype = parms->type;
+
+       TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
+
+       aparms.allocated = &allocated;
+       rc = tf_rm_is_allocated(&aparms);
+       if (rc)
+               return rc;
 
-       /*
-        * Adjust the returned index/offset as there is no guarantee
-        * that the start is 0 at time of RM allocation
-        */
-       tf_rm_convert_index(tfs,
-                           parms->dir,
+       if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+               TFP_DRV_LOG(ERR,
+                           "%s: Entry already free, type:%d, index:%d\n",
+                           tf_dir_2_str(parms->dir),
                            parms->type,
-                           TF_RM_CONVERT_RM_BASE,
-                           parms->starting_idx,
-                           &index);
+                           parms->idx);
+               return -EINVAL;
+       }
+
+       /* If this is counter table, clear the entry on free */
+       if (parms->type == TF_TBL_TYPE_ACT_STATS_64) {
+               uint8_t data[8] = { 0 };
+               uint16_t hcapi_type = 0;
+               struct tf_rm_get_hcapi_parms hparms = { 0 };
+
+               /* Get the hcapi type */
+               hparms.rm_db = tbl_db->tbl_db[parms->dir];
+               hparms.subtype = parms->type;
+               hparms.hcapi_type = &hcapi_type;
+               rc = tf_rm_get_hcapi_type(&hparms);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s, Failed type lookup, type:%d, rc:%s\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type,
+                                   strerror(-rc));
+                       return rc;
+               }
+               /* Clear the counter
+                */
+               rc = tf_msg_set_tbl_entry(tfp,
+                                         parms->dir,
+                                         hcapi_type,
+                                         sizeof(data),
+                                         data,
+                                         parms->idx);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s, Set failed, type:%d, rc:%s\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type,
+                                   strerror(-rc));
+                       return rc;
+               }
+       }
+
+       /* Free requested element */
+       fparms.rm_db = tbl_db->tbl_db[parms->dir];
+       fparms.subtype = parms->type;
+
+       TF_TBL_PTR_TO_RM(&fparms.index, parms->idx, base, shift);
+
+       rc = tf_rm_free(&fparms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s: Free failed, type:%d, index:%d\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           parms->idx);
+               return rc;
+       }
+
+       return 0;
+}
+
+int
+tf_tbl_alloc_search(struct tf *tfp,
+                   struct tf_tbl_alloc_search_parms *parms)
+{
+       int rc = 0;
+       TF_CHECK_PARMS2(tfp, parms);
+
+       if (!shadow_init || !shadow_tbl_db[parms->dir]) {
+               TFP_DRV_LOG(ERR, "%s: Shadow TBL not initialized.\n",
+                           tf_dir_2_str(parms->dir));
+               return -EINVAL;
+       }
+
+       return rc;
+}
+
+int
+tf_tbl_set(struct tf *tfp,
+          struct tf_tbl_set_parms *parms)
+{
+       int rc;
+       int allocated = 0;
+       uint16_t hcapi_type;
+       struct tf_rm_is_allocated_parms aparms = { 0 };
+       struct tf_rm_get_hcapi_parms hparms = { 0 };
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
+
+       TF_CHECK_PARMS3(tfp, parms, parms->data);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       /* Only get table info if required for the device */
+       if (dev->ops->tf_dev_get_tbl_info) {
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s: Failed to get table info:%d\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type);
+                       return rc;
+               }
+       }
 
        /* Verify that the entry has been previously allocated */
-       id = ba_inuse(session_pool, index);
-       if (id != 1) {
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
+       aparms.subtype = parms->type;
+       TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
+
+       aparms.allocated = &allocated;
+       rc = tf_rm_is_allocated(&aparms);
+       if (rc)
+               return rc;
+
+       if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
                TFP_DRV_LOG(ERR,
-                  "%s, Invalid or not allocated index, type:%d, starting_idx:%d\n",
+                  "%s, Invalid or not allocated index, type:%d, idx:%d\n",
                   tf_dir_2_str(parms->dir),
                   parms->type,
-                  index);
+                  parms->idx);
                return -EINVAL;
        }
 
-       /* Get the entry */
-       rc = tf_msg_bulk_get_tbl_entry(tfp, parms);
+       /* Set the entry */
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
+       hparms.subtype = parms->type;
+       hparms.hcapi_type = &hcapi_type;
+       rc = tf_rm_get_hcapi_type(&hparms);
        if (rc) {
                TFP_DRV_LOG(ERR,
-                           "%s, Bulk get failed, type:%d, rc:%s\n",
+                           "%s, Failed type lookup, type:%d, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           strerror(-rc));
+               return rc;
+       }
+
+       rc = tf_msg_set_tbl_entry(tfp,
+                                 parms->dir,
+                                 hcapi_type,
+                                 parms->data_sz_in_bytes,
+                                 parms->data,
+                                 parms->idx);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Set failed, type:%d, rc:%s\n",
                            tf_dir_2_str(parms->dir),
                            parms->type,
                            strerror(-rc));
+               return rc;
        }
 
-       return rc;
+       return 0;
 }
 
-#if (TF_SHADOW == 1)
-/**
- * Allocate Tbl entry from the Shadow DB. Shadow DB is searched for
- * the requested entry. If found the ref count is incremente and
- * returned.
- *
- * [in] tfs
- *   Pointer to session
- * [in] parms
- *   Allocation parameters
- *
- * Return:
- *  0       - Success, entry found and ref count incremented
- *  -ENOENT - Failure, entry not found
- */
-static int
-tf_alloc_tbl_entry_shadow(struct tf_session *tfs __rte_unused,
-                         struct tf_alloc_tbl_entry_parms *parms __rte_unused)
+int
+tf_tbl_get(struct tf *tfp,
+          struct tf_tbl_get_parms *parms)
 {
-       TFP_DRV_LOG(ERR,
-                   "%s, Entry Alloc with search not supported\n",
-                   tf_dir_2_str(parms->dir));
+       int rc;
+       uint16_t hcapi_type;
+       int allocated = 0;
+       struct tf_rm_is_allocated_parms aparms = { 0 };
+       struct tf_rm_get_hcapi_parms hparms = { 0 };
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
-       return -EOPNOTSUPP;
-}
+       TF_CHECK_PARMS3(tfp, parms, parms->data);
 
-/**
- * Free Tbl entry from the Shadow DB. Shadow DB is searched for
- * the requested entry. If found the ref count is decremente and
- * new ref_count returned.
- *
- * [in] tfs
- *   Pointer to session
- * [in] parms
- *   Allocation parameters
- *
- * Return:
- *  0       - Success, entry found and ref count decremented
- *  -ENOENT - Failure, entry not found
- */
-static int
-tf_free_tbl_entry_shadow(struct tf_session *tfs,
-                        struct tf_free_tbl_entry_parms *parms)
-{
-       TFP_DRV_LOG(ERR,
-                   "%s, Entry Free with search not supported\n",
-                   tf_dir_2_str(parms->dir));
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
 
-       return -EOPNOTSUPP;
-}
-#endif /* TF_SHADOW */
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       /* Only get table info if required for the device */
+       if (dev->ops->tf_dev_get_tbl_info) {
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
+               if (rc) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s: Failed to get table info:%d\n",
+                                   tf_dir_2_str(parms->dir),
+                                   parms->type);
+                       return rc;
+               }
+       }
+
+       /* Verify that the entry has been previously allocated */
+       aparms.rm_db = tbl_db->tbl_db[parms->dir];
+       aparms.subtype = parms->type;
+       TF_TBL_PTR_TO_RM(&aparms.index, parms->idx, base, shift);
+
+       aparms.allocated = &allocated;
+       rc = tf_rm_is_allocated(&aparms);
+       if (rc)
+               return rc;
+
+       if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+               TFP_DRV_LOG(ERR,
+                  "%s, Invalid or not allocated index, type:%d, idx:%d\n",
+                  tf_dir_2_str(parms->dir),
+                  parms->type,
+                  parms->idx);
+               return -EINVAL;
+       }
+
+       /* Set the entry */
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
+       hparms.subtype = parms->type;
+       hparms.hcapi_type = &hcapi_type;
+       rc = tf_rm_get_hcapi_type(&hparms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Failed type lookup, type:%d, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           strerror(-rc));
+               return rc;
+       }
+
+       /* Get the entry */
+       rc = tf_msg_get_tbl_entry(tfp,
+                                 parms->dir,
+                                 hcapi_type,
+                                 parms->data_sz_in_bytes,
+                                 parms->data,
+                                 parms->idx);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Get failed, type:%d, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           strerror(-rc));
+               return rc;
+       }
 
+       return 0;
+}
 
- /* API defined in tf_core.h */
 int
-tf_bulk_get_tbl_entry(struct tf *tfp,
-                struct tf_bulk_get_tbl_entry_parms *parms)
+tf_tbl_bulk_get(struct tf *tfp,
+               struct tf_tbl_get_bulk_parms *parms)
 {
-       int rc = 0;
+       int rc;
+       uint16_t hcapi_type;
+       struct tf_rm_get_hcapi_parms hparms = { 0 };
+       struct tf_rm_check_indexes_in_range_parms cparms = { 0 };
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       uint16_t base = 0, shift = 0;
+       struct tbl_rm_db *tbl_db;
+       void *tbl_db_ptr = NULL;
 
-       TF_CHECK_PARMS_SESSION(tfp, parms);
+       TF_CHECK_PARMS2(tfp, parms);
 
-       if (parms->type == TF_TBL_TYPE_EXT) {
-               /* Not supported, yet */
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc) {
                TFP_DRV_LOG(ERR,
-                           "%s, External table type not supported\n",
-                           tf_dir_2_str(parms->dir));
+                           "Failed to get em_ext_db from session, rc:%s\n",
+                           strerror(-rc));
+               return rc;
+       }
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
 
-               rc = -EOPNOTSUPP;
-       } else {
-               /* Internal table type processing */
-               rc = tf_bulk_get_tbl_entry_internal(tfp, parms);
-               if (rc)
+       /* Only get table info if required for the device */
+       if (dev->ops->tf_dev_get_tbl_info) {
+               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                  tbl_db->tbl_db[parms->dir],
+                                                  parms->type,
+                                                  &base,
+                                                  &shift);
+               if (rc) {
                        TFP_DRV_LOG(ERR,
-                                   "%s, Bulk get failed, type:%d, rc:%s\n",
+                                   "%s: Failed to get table info:%d\n",
                                    tf_dir_2_str(parms->dir),
-                                   parms->type,
-                                   strerror(-rc));
+                                   parms->type);
+                       return rc;
+               }
+       }
+
+       /* Verify that the entries are in the range of reserved resources. */
+       cparms.rm_db = tbl_db->tbl_db[parms->dir];
+       cparms.subtype = parms->type;
+
+       TF_TBL_PTR_TO_RM(&cparms.starting_index, parms->starting_idx,
+                        base, shift);
+
+       cparms.num_entries = parms->num_entries;
+
+       rc = tf_rm_check_indexes_in_range(&cparms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Invalid or %d index starting from %d"
+                           " not in range, type:%d",
+                           tf_dir_2_str(parms->dir),
+                           parms->starting_idx,
+                           parms->num_entries,
+                           parms->type);
+               return rc;
+       }
+
+       hparms.rm_db = tbl_db->tbl_db[parms->dir];
+       hparms.subtype = parms->type;
+       hparms.hcapi_type = &hcapi_type;
+       rc = tf_rm_get_hcapi_type(&hparms);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Failed type lookup, type:%d, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           strerror(-rc));
+               return rc;
+       }
+
+       /* Get the entries */
+       rc = tf_msg_bulk_get_tbl_entry(tfp,
+                                      parms->dir,
+                                      hcapi_type,
+                                      parms->starting_idx,
+                                      parms->num_entries,
+                                      parms->entry_sz_in_bytes,
+                                      parms->physical_mem_addr);
+       if (rc) {
+               TFP_DRV_LOG(ERR,
+                           "%s, Bulk get failed, type:%d, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           parms->type,
+                           strerror(-rc));
        }
 
        return rc;
 }
+
+int
+tf_tbl_get_resc_info(struct tf *tfp,
+                    struct tf_tbl_resource_info *tbl)
+{
+       int rc;
+       int d, i;
+       struct tf_resource_info *dinfo;
+       struct tf_rm_get_alloc_info_parms ainfo;
+       void *tbl_db_ptr = NULL;
+       struct tbl_rm_db *tbl_db;
+       uint16_t base = 0, shift = 0;
+       struct tf_dev_info *dev;
+       struct tf_session *tfs;
+
+       TF_CHECK_PARMS2(tfp, tbl);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session_internal(tfp, &tfs);
+       if (rc)
+               return rc;
+
+       /* Retrieve the device information */
+       rc = tf_session_get_device(tfs, &dev);
+       if (rc)
+               return rc;
+
+       rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
+       if (rc == -ENOMEM)
+               return 0; /* db doesn't exist */
+       else if (rc)
+               return rc; /* error getting db */
+
+       tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
+
+       /* check if reserved resource for WC is multiple of num_slices */
+       for (d = 0; d < TF_DIR_MAX; d++) {
+               ainfo.rm_db = tbl_db->tbl_db[d];
+               dinfo = tbl[d].info;
+
+               if (!ainfo.rm_db)
+                       continue;
+
+               ainfo.info = (struct tf_rm_alloc_info *)dinfo;
+               ainfo.subtype = 0;
+               rc = tf_rm_get_all_info(&ainfo, TF_TBL_TYPE_MAX);
+               if (rc)
+                       return rc;
+
+               if (dev->ops->tf_dev_get_tbl_info) {
+                       /* Adjust all */
+                       for (i = 0; i < TF_TBL_TYPE_MAX; i++) {
+                               /* Only get table info if required for the device */
+                               rc = dev->ops->tf_dev_get_tbl_info(tfp,
+                                                                  tbl_db->tbl_db[d],
+                                                                  i,
+                                                                  &base,
+                                                                  &shift);
+                               if (rc) {
+                                       TFP_DRV_LOG(ERR,
+                                                   "%s: Failed to get table info:%d\n",
+                                                   tf_dir_2_str(d),
+                                                   i);
+                                       return rc;
+                               }
+                               if (dinfo[i].stride)
+                                       TF_TBL_RM_TO_PTR(&dinfo[i].start,
+                                                        dinfo[i].start,
+                                                        base,
+                                                        shift);
+                       }
+               }
+       }
+
+       return 0;
+}