eal: remove sys/queue.h from public headers
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tbl_sram.c
index ea10afe..636811b 100644 (file)
 
 #define DBG_SRAM 0
 
+#define TF_TBL_PTR_TO_RM(new_idx, idx, base, shift) {          \
+               *(new_idx) = (((idx) >> (shift)) - (base));     \
+}
+
 /**
  * tf_sram_tbl_get_info_parms parameter definition
  */
@@ -130,11 +134,6 @@ static int tf_tbl_sram_get_info(struct tf_tbl_sram_get_info_parms *parms)
        if (slices)
                parms->slice_size = tf_tbl_sram_slices_2_size[slices];
 
-       TFP_DRV_LOG(INFO,
-                   "(%s) bank(%s) slice_size(%s)\n",
-                   tf_tbl_type_2_str(parms->tbl_type),
-                   tf_sram_bank_2_str(parms->bank_id),
-                   tf_sram_slice_2_str(parms->slice_size));
        return rc;
 }
 
@@ -369,7 +368,6 @@ tf_tbl_sram_free(struct tf *tfp __rte_unused,
                return rc;
        }
 
-
 #if (DBG_SRAM == 1)
        {
                struct tf_sram_mgr_dump_parms dparms;
@@ -394,6 +392,7 @@ tf_tbl_sram_set(struct tf *tfp,
 {
        int rc;
        bool allocated = 0;
+       int rallocated = 0;
        uint16_t hcapi_type;
        struct tf_rm_get_hcapi_parms hparms = { 0 };
        struct tf_session *tfs;
@@ -402,8 +401,9 @@ tf_tbl_sram_set(struct tf *tfp,
        void *tbl_db_ptr = NULL;
        struct tf_tbl_sram_get_info_parms iparms = { 0 };
        struct tf_sram_mgr_is_allocated_parms aparms = { 0 };
+       struct tf_rm_is_allocated_parms raparms = { 0 };
        void *sram_handle = NULL;
-
+       uint16_t base = 0, shift = 0;
 
        TF_CHECK_PARMS3(tfp, parms, parms->data);
 
@@ -442,23 +442,57 @@ tf_tbl_sram_set(struct tf *tfp,
                return rc;
        }
 
-       aparms.sram_offset = parms->idx;
-       aparms.slice_size = iparms.slice_size;
-       aparms.bank_id = iparms.bank_id;
-       aparms.dir = parms->dir;
-       aparms.is_allocated = &allocated;
-       rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
-       if (rc || !allocated) {
-               TFP_DRV_LOG(ERR,
-                           "%s: Entry not allocated:%s idx(%d):(%s)\n",
-                           tf_dir_2_str(parms->dir),
-                           tf_tbl_type_2_str(parms->type),
-                           parms->idx,
-                           strerror(-rc));
-               rc = -ENOMEM;
-               return rc;
+       if (tf_session_is_shared_session(tfs)) {
+               /* 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;
+                       }
+               }
+               TF_TBL_PTR_TO_RM(&raparms.index, parms->idx, base, shift);
+
+               raparms.rm_db = tbl_db->tbl_db[parms->dir];
+               raparms.subtype = parms->type;
+               raparms.allocated = &rallocated;
+               rc = tf_rm_is_allocated(&raparms);
+               if (rc)
+                       return rc;
+
+               if (rallocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+                       TFP_DRV_LOG(ERR,
+                          "%s, Invalid or not allocated index, type:%s, idx:%d\n",
+                          tf_dir_2_str(parms->dir),
+                          tf_tbl_type_2_str(parms->type),
+                          parms->idx);
+                       return -EINVAL;
+               }
+       } else {
+               aparms.sram_offset = parms->idx;
+               aparms.slice_size = iparms.slice_size;
+               aparms.bank_id = iparms.bank_id;
+               aparms.dir = parms->dir;
+               aparms.is_allocated = &allocated;
+               rc = tf_sram_mgr_is_allocated(sram_handle, &aparms);
+               if (rc || !allocated) {
+                       TFP_DRV_LOG(ERR,
+                                   "%s: Entry not allocated:%s idx(%d):(%s)\n",
+                                   tf_dir_2_str(parms->dir),
+                                   tf_tbl_type_2_str(parms->type),
+                                   parms->idx,
+                                   strerror(-rc));
+                       rc = -ENOMEM;
+                       return rc;
+               }
        }
-
        /* Set the entry */
        hparms.rm_db = tbl_db->tbl_db[parms->dir];
        hparms.subtype = parms->type;