#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;
-/**
- * Table Shadow DBs
- */
-static void *shadow_tbl_db[TF_DIR_MAX];
-
-/**
- * Shadow init flag, set on bind and cleared on unbind
- */
-static uint8_t shadow_init;
+#define TF_TBL_RM_TO_PTR(new_idx, idx, base, shift) { \
+ *(new_idx) = (((idx) + (base)) << (shift)); \
+}
int
tf_tbl_bind(struct tf *tfp,
db_rc[d] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
else
db_rc[d] = tf_rm_create_db(tfp, &db_cfg);
- if (db_rc[d]) {
- TFP_DRV_LOG(ERR,
- "%s: No Table DB creation required\n",
- tf_dir_2_str(d));
-
- }
}
/* No db created */
- if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX])
+ 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");
TF_CHECK_PARMS1(tfp);
rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
- if (rc) {
- TFP_DRV_LOG(INFO,
- "Tbl_db is not initialized, rc:%s\n",
- strerror(-rc));
+ if (rc)
return 0;
- }
tbl_db = (struct tbl_rm_db *)tbl_db_ptr;
for (i = 0; i < TF_DIR_MAX; i++) {
tbl_db->tbl_db[i] = NULL;
}
- shadow_init = 0;
-
return 0;
}
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;
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",
+ "Failed to get tbl_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;
rc = tf_rm_allocate(&aparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s: Failed allocate, type:%d\n",
+ "%s: Failed allocate, type:%s\n",
tf_dir_2_str(parms->dir),
- parms->type);
+ tf_tbl_type_2_str(parms->type));
return rc;
}
- TF_TBL_RM_TO_PTR(&idx, idx, base, shift);
*parms->idx = idx;
return 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;
}
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.index = parms->idx;
aparms.allocated = &allocated;
rc = tf_rm_is_allocated(&aparms);
if (rc)
if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
TFP_DRV_LOG(ERR,
- "%s: Entry already free, type:%d, index:%d\n",
+ "%s: Entry already free, type:%s, index:%d\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
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:%s, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ tf_tbl_type_2_str(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:%s, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ tf_tbl_type_2_str(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);
-
+ fparms.index = parms->idx;
rc = tf_rm_free(&fparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s: Free failed, type:%d, index:%d\n",
+ "%s: Free failed, type:%s, index:%d\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(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)
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;
}
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;
+ /* Do not check meter drop counter because it is not allocated
+ * resources
+ */
+ if (parms->type != TF_TBL_TYPE_METER_DROP_CNT) {
+ /* Verify that the entry has been previously allocated */
+ aparms.rm_db = tbl_db->tbl_db[parms->dir];
+ aparms.subtype = parms->type;
+ aparms.allocated = &allocated;
+ aparms.index = parms->idx;
+ 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;
+ if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
+ TFP_DRV_LOG(ERR,
+ "%s, Invalid or not allocated, type:%s, idx:%d\n",
+ tf_dir_2_str(parms->dir),
+ tf_tbl_type_2_str(parms->type),
+ parms->idx);
+ return -EINVAL;
+ }
}
/* Set the entry */
rc = tf_rm_get_hcapi_type(&hparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Failed type lookup, type:%d, rc:%s\n",
+ "%s, Failed type lookup, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
return rc;
}
parms->idx);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Set failed, type:%d, rc:%s\n",
+ "%s, Set failed, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
return rc;
}
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;
}
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);
+ /* Do not check meter drop counter because it is not allocated
+ * resources.
+ */
+ if (parms->type != TF_TBL_TYPE_METER_DROP_CNT) {
+ /* Verify that the entry has been previously allocated */
+ aparms.rm_db = tbl_db->tbl_db[parms->dir];
+ aparms.subtype = parms->type;
+ aparms.index = parms->idx;
+ aparms.allocated = &allocated;
+ rc = tf_rm_is_allocated(&aparms);
+ if (rc)
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;
+ if (allocated != 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;
+ }
}
/* Set the entry */
rc = tf_rm_get_hcapi_type(&hparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Failed type lookup, type:%d, rc:%s\n",
+ "%s, Failed type lookup, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
return rc;
}
parms->idx);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Get failed, type:%d, rc:%s\n",
+ "%s, Get failed, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
return rc;
}
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;
}
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 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;
+ cparms.starting_index = parms->starting_idx;
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",
+ " not in range, type:%s",
tf_dir_2_str(parms->dir),
parms->starting_idx,
parms->num_entries,
- parms->type);
+ tf_tbl_type_2_str(parms->type));
return rc;
}
rc = tf_rm_get_hcapi_type(&hparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Failed type lookup, type:%d, rc:%s\n",
+ "%s, Failed type lookup, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
return rc;
}
parms->physical_mem_addr);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s, Bulk get failed, type:%d, rc:%s\n",
+ "%s, Bulk get failed, type:%s, rc:%s\n",
tf_dir_2_str(parms->dir),
- parms->type,
+ tf_tbl_type_2_str(parms->type),
strerror(-rc));
}
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;
+ uint16_t base = 0, shift = 0;
TF_CHECK_PARMS2(tfp, tbl);
return rc;
rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TABLE, &tbl_db_ptr);
- if (rc) {
- TFP_DRV_LOG(INFO,
- "No resource allocated for table from session\n");
- return 0;
- }
+ 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);