#include "tf_common.h"
#include "hwrm_tf.h"
-/**
- * Create EM Tbl pool of memory indexes.
- *
- * [in] session
- * Pointer to session
- * [in] dir
- * direction
- * [in] num_entries
- * number of entries to write
- *
- * Return:
- * 0 - Success, entry allocated - no search support
- * -ENOMEM -EINVAL -EOPNOTSUPP
- * - Failure, entry not allocated, out of resources
- */
-static int
-tf_create_em_pool(struct tf_session *session,
- enum tf_dir dir,
- uint32_t num_entries)
-{
- struct tfp_calloc_parms parms;
- uint32_t i, j;
- int rc = 0;
- struct stack *pool = &session->em_pool[dir];
-
- parms.nitems = num_entries;
- parms.size = sizeof(uint32_t);
- parms.alignment = 0;
-
- if (tfp_calloc(&parms) != 0) {
- TFP_DRV_LOG(ERR, "EM pool allocation failure %s\n",
- strerror(-ENOMEM));
- return -ENOMEM;
- }
-
- /* Create empty stack
- */
- rc = stack_init(num_entries, (uint32_t *)parms.mem_va, pool);
-
- if (rc != 0) {
- TFP_DRV_LOG(ERR, "EM pool stack init failure %s\n",
- strerror(-rc));
- goto cleanup;
- }
-
- /* Fill pool with indexes
- */
- j = num_entries - 1;
-
- for (i = 0; i < num_entries; i++) {
- rc = stack_push(pool, j);
- if (rc != 0) {
- TFP_DRV_LOG(ERR, "EM pool stack push failure %s\n",
- strerror(-rc));
- goto cleanup;
- }
- j--;
- }
-
- if (!stack_is_full(pool)) {
- rc = -EINVAL;
- TFP_DRV_LOG(ERR, "EM pool stack failure %s\n",
- strerror(-rc));
- goto cleanup;
- }
-
- return 0;
-cleanup:
- tfp_free((void *)parms.mem_va);
- return rc;
-}
-
-/**
- * Create EM Tbl pool of memory indexes.
- *
- * [in] session
- * Pointer to session
- * [in] dir
- * direction
- *
- * Return:
- */
-static void
-tf_free_em_pool(struct tf_session *session,
- enum tf_dir dir)
-{
- struct stack *pool = &session->em_pool[dir];
- uint32_t *ptr;
-
- ptr = stack_items(pool);
-
- tfp_free(ptr);
-}
-
int
-tf_open_session(struct tf *tfp,
+tf_open_session(struct tf *tfp,
struct tf_open_session_parms *parms)
-{
- int rc;
- struct tf_session *session;
- struct tfp_calloc_parms alloc_parms;
- unsigned int domain, bus, slot, device;
- uint8_t fw_session_id;
- int dir;
-
- TF_CHECK_PARMS(tfp, parms);
-
- /* Filter out any non-supported device types on the Core
- * side. It is assumed that the Firmware will be supported if
- * firmware open session succeeds.
- */
- if (parms->device_type != TF_DEVICE_TYPE_WH) {
- TFP_DRV_LOG(ERR,
- "Unsupported device type %d\n",
- parms->device_type);
- return -ENOTSUP;
- }
-
- /* Build the beginning of session_id */
- rc = sscanf(parms->ctrl_chan_name,
- "%x:%x:%x.%d",
- &domain,
- &bus,
- &slot,
- &device);
- if (rc != 4) {
- TFP_DRV_LOG(ERR,
- "Failed to scan device ctrl_chan_name\n");
- return -EINVAL;
- }
-
- /* open FW session and get a new session_id */
- rc = tf_msg_session_open(tfp,
- parms->ctrl_chan_name,
- &fw_session_id);
- if (rc) {
- /* Log error */
- if (rc == -EEXIST)
- TFP_DRV_LOG(ERR,
- "Session is already open, rc:%s\n",
- strerror(-rc));
- else
- TFP_DRV_LOG(ERR,
- "Open message send failed, rc:%s\n",
- strerror(-rc));
-
- parms->session_id.id = TF_FW_SESSION_ID_INVALID;
- return rc;
- }
-
- /* Allocate session */
- alloc_parms.nitems = 1;
- alloc_parms.size = sizeof(struct tf_session_info);
- alloc_parms.alignment = 0;
- rc = tfp_calloc(&alloc_parms);
- if (rc) {
- /* Log error */
- TFP_DRV_LOG(ERR,
- "Failed to allocate session info, rc:%s\n",
- strerror(-rc));
- goto cleanup;
- }
-
- tfp->session = (struct tf_session_info *)alloc_parms.mem_va;
-
- /* Allocate core data for the session */
- alloc_parms.nitems = 1;
- alloc_parms.size = sizeof(struct tf_session);
- alloc_parms.alignment = 0;
- rc = tfp_calloc(&alloc_parms);
- if (rc) {
- /* Log error */
- TFP_DRV_LOG(ERR,
- "Failed to allocate session data, rc:%s\n",
- strerror(-rc));
- goto cleanup;
- }
-
- tfp->session->core_data = alloc_parms.mem_va;
-
- session = (struct tf_session *)tfp->session->core_data;
- tfp_memcpy(session->ctrl_chan_name,
- parms->ctrl_chan_name,
- TF_SESSION_NAME_MAX);
-
- /* Initialize Session */
- session->dev = NULL;
- tf_rm_init(tfp);
-
- /* Construct the Session ID */
- session->session_id.internal.domain = domain;
- session->session_id.internal.bus = bus;
- session->session_id.internal.device = device;
- session->session_id.internal.fw_session_id = fw_session_id;
-
- /* Query for Session Config
- */
- rc = tf_msg_session_qcfg(tfp);
- if (rc) {
- TFP_DRV_LOG(ERR,
- "Query config message send failed, rc:%s\n",
- strerror(-rc));
- goto cleanup_close;
- }
-
- /* Shadow DB configuration */
- if (parms->shadow_copy) {
- /* Ignore shadow_copy setting */
- session->shadow_copy = 0;/* parms->shadow_copy; */
-#if (TF_SHADOW == 1)
- rc = tf_rm_shadow_db_init(tfs);
- if (rc)
- TFP_DRV_LOG(ERR,
- "Shadow DB Initialization failed\n, rc:%s",
- strerror(-rc));
- /* Add additional processing */
-#endif /* TF_SHADOW */
- }
-
- /* Adjust the Session with what firmware allowed us to get */
- rc = tf_rm_allocate_validate(tfp);
- if (rc) {
- TFP_DRV_LOG(ERR,
- "Rm allocate validate failed, rc:%s\n",
- strerror(-rc));
- goto cleanup_close;
- }
-
- /* Initialize EM pool */
- for (dir = 0; dir < TF_DIR_MAX; dir++) {
- rc = tf_create_em_pool(session,
- (enum tf_dir)dir,
- TF_SESSION_EM_POOL_SIZE);
- if (rc) {
- TFP_DRV_LOG(ERR,
- "EM Pool initialization failed\n");
- goto cleanup_close;
- }
- }
-
- session->ref_count++;
-
- /* Return session ID */
- parms->session_id = session->session_id;
-
- TFP_DRV_LOG(INFO,
- "Session created, session_id:%d\n",
- parms->session_id.id);
-
- TFP_DRV_LOG(INFO,
- "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
- parms->session_id.internal.domain,
- parms->session_id.internal.bus,
- parms->session_id.internal.device,
- parms->session_id.internal.fw_session_id);
-
- return 0;
-
- cleanup:
- tfp_free(tfp->session->core_data);
- tfp_free(tfp->session);
- tfp->session = NULL;
- return rc;
-
- cleanup_close:
- tf_close_session(tfp);
- return -EINVAL;
-}
-
-int
-tf_open_session_new(struct tf *tfp,
- struct tf_open_session_parms *parms)
{
int rc;
unsigned int domain, bus, slot, device;
struct tf_session_open_session_parms oparms;
- TF_CHECK_PARMS(tfp, parms);
+ TF_CHECK_PARMS2(tfp, parms);
/* Filter out any non-supported device types on the Core
* side. It is assumed that the Firmware will be supported if
}
int
-tf_attach_session(struct tf *tfp __rte_unused,
- struct tf_attach_session_parms *parms __rte_unused)
-{
-#if (TF_SHARED == 1)
- int rc;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- /* - Open the shared memory for the attach_chan_name
- * - Point to the shared session for this Device instance
- * - Check that session is valid
- * - Attach to the firmware so it can record there is more
- * than one client of the session.
- */
-
- if (tfp->session->session_id.id != TF_SESSION_ID_INVALID) {
- rc = tf_msg_session_attach(tfp,
- parms->ctrl_chan_name,
- parms->session_id);
- }
-#endif /* TF_SHARED */
- return -1;
-}
-
-int
-tf_attach_session_new(struct tf *tfp,
- struct tf_attach_session_parms *parms)
+tf_attach_session(struct tf *tfp,
+ struct tf_attach_session_parms *parms)
{
int rc;
unsigned int domain, bus, slot, device;
int
tf_close_session(struct tf *tfp)
-{
- int rc;
- int rc_close = 0;
- struct tf_session *tfs;
- union tf_session_id session_id;
- int dir;
-
- TF_CHECK_TFP_SESSION(tfp);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* Cleanup if we're last user of the session */
- if (tfs->ref_count == 1) {
- /* Cleanup any outstanding resources */
- rc_close = tf_rm_close(tfp);
- }
-
- if (tfs->session_id.id != TF_SESSION_ID_INVALID) {
- rc = tf_msg_session_close(tfp);
- if (rc) {
- /* Log error */
- TFP_DRV_LOG(ERR,
- "Message send failed, rc:%s\n",
- strerror(-rc));
- }
-
- /* Update the ref_count */
- tfs->ref_count--;
- }
-
- session_id = tfs->session_id;
-
- /* Final cleanup as we're last user of the session */
- if (tfs->ref_count == 0) {
- /* Free EM pool */
- for (dir = 0; dir < TF_DIR_MAX; dir++)
- tf_free_em_pool(tfs, (enum tf_dir)dir);
-
- tfp_free(tfp->session->core_data);
- tfp_free(tfp->session);
- tfp->session = NULL;
- }
-
- TFP_DRV_LOG(INFO,
- "Session closed, session_id:%d\n",
- session_id.id);
-
- TFP_DRV_LOG(INFO,
- "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
- session_id.internal.domain,
- session_id.internal.bus,
- session_id.internal.device,
- session_id.internal.fw_session_id);
-
- return rc_close;
-}
-
-int
-tf_close_session_new(struct tf *tfp)
{
int rc;
struct tf_session_close_session_parms cparms = { 0 };
return rc;
}
-int tf_alloc_identifier(struct tf *tfp,
- struct tf_alloc_identifier_parms *parms)
-{
- struct bitalloc *session_pool;
- struct tf_session *tfs;
- int id;
- int rc;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- switch (parms->ident_type) {
- case TF_IDENT_TYPE_L2_CTXT:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_L2_CTXT_REMAP_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_PROF_FUNC:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_PROF_FUNC_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_EM_PROF:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_EM_PROF_ID_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_WC_PROF:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_WC_TCAM_PROF_ID_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_L2_FUNC:
- TFP_DRV_LOG(ERR, "%s: unsupported %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EOPNOTSUPP;
- break;
- default:
- TFP_DRV_LOG(ERR, "%s: %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EOPNOTSUPP;
- break;
- }
-
- if (rc) {
- TFP_DRV_LOG(ERR, "%s: identifier pool %s failure, rc:%s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type),
- strerror(-rc));
- return rc;
- }
-
- id = ba_alloc(session_pool);
-
- if (id == BA_FAIL) {
- TFP_DRV_LOG(ERR, "%s: %s: No resource available\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- return -ENOMEM;
- }
- parms->id = id;
- return 0;
-}
-
int
-tf_alloc_identifier_new(struct tf *tfp,
- struct tf_alloc_identifier_parms *parms)
+tf_alloc_identifier(struct tf *tfp,
+ struct tf_alloc_identifier_parms *parms)
{
int rc;
struct tf_session *tfs;
}
aparms.dir = parms->dir;
- aparms.ident_type = parms->ident_type;
+ aparms.type = parms->ident_type;
aparms.id = &id;
rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
if (rc) {
return 0;
}
-int tf_free_identifier(struct tf *tfp,
- struct tf_free_identifier_parms *parms)
-{
- struct bitalloc *session_pool;
- int rc;
- int ba_rc;
- struct tf_session *tfs;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- switch (parms->ident_type) {
- case TF_IDENT_TYPE_L2_CTXT:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_L2_CTXT_REMAP_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_PROF_FUNC:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_PROF_FUNC_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_EM_PROF:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_EM_PROF_ID_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_WC_PROF:
- TF_RM_GET_POOLS(tfs, parms->dir, &session_pool,
- TF_WC_TCAM_PROF_ID_POOL_NAME,
- rc);
- break;
- case TF_IDENT_TYPE_L2_FUNC:
- TFP_DRV_LOG(ERR, "%s: unsupported %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EOPNOTSUPP;
- break;
- default:
- TFP_DRV_LOG(ERR, "%s: invalid %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EOPNOTSUPP;
- break;
- }
- if (rc) {
- TFP_DRV_LOG(ERR,
- "%s: %s Identifier pool access failed, rc:%s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type),
- strerror(-rc));
- return rc;
- }
-
- ba_rc = ba_inuse(session_pool, (int)parms->id);
-
- if (ba_rc == BA_FAIL || ba_rc == BA_ENTRY_FREE) {
- TFP_DRV_LOG(ERR, "%s: %s: Entry %d already free",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type),
- parms->id);
- return -EINVAL;
- }
-
- ba_free(session_pool, (int)parms->id);
-
- return 0;
-}
-
int
-tf_free_identifier_new(struct tf *tfp,
- struct tf_free_identifier_parms *parms)
+tf_free_identifier(struct tf *tfp,
+ struct tf_free_identifier_parms *parms)
{
int rc;
struct tf_session *tfs;
}
fparms.dir = parms->dir;
- fparms.ident_type = parms->ident_type;
+ fparms.type = parms->ident_type;
fparms.id = parms->id;
rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
if (rc) {
TFP_DRV_LOG(ERR,
- "%s: Identifier allocation failed, rc:%s\n",
+ "%s: Identifier free failed, rc:%s\n",
tf_dir_2_str(parms->dir),
strerror(-rc));
return rc;
return 0;
}
+
+int
+tf_alloc_tbl_entry(struct tf *tfp,
+ struct tf_alloc_tbl_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_alloc_parms aparms;
+ uint32_t idx;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&aparms, 0, sizeof(struct tf_tbl_alloc_parms));
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ if (dev->ops->tf_dev_alloc_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return -EOPNOTSUPP;
+ }
+
+ aparms.dir = parms->dir;
+ aparms.type = parms->type;
+ aparms.idx = &idx;
+ rc = dev->ops->tf_dev_alloc_tbl(tfp, &aparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table allocation failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ parms->idx = idx;
+
+ return 0;
+}
+
+int
+tf_free_tbl_entry(struct tf *tfp,
+ struct tf_free_tbl_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_free_parms fparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&fparms, 0, sizeof(struct tf_tbl_free_parms));
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ if (dev->ops->tf_dev_free_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return -EOPNOTSUPP;
+ }
+
+ fparms.dir = parms->dir;
+ fparms.type = parms->type;
+ fparms.idx = parms->idx;
+ rc = dev->ops->tf_dev_free_tbl(tfp, &fparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table free failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+tf_set_tbl_entry(struct tf *tfp,
+ struct tf_set_tbl_entry_parms *parms)
+{
+ int rc = 0;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_set_parms sparms;
+
+ TF_CHECK_PARMS3(tfp, parms, parms->data);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&sparms, 0, sizeof(struct tf_tbl_set_parms));
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ if (dev->ops->tf_dev_set_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return -EOPNOTSUPP;
+ }
+
+ sparms.dir = parms->dir;
+ sparms.type = parms->type;
+ sparms.data = parms->data;
+ sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
+ sparms.idx = parms->idx;
+ rc = dev->ops->tf_dev_set_tbl(tfp, &sparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table set failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return rc;
+}
+
+int
+tf_get_tbl_entry(struct tf *tfp,
+ struct tf_get_tbl_entry_parms *parms)
+{
+ int rc = 0;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_get_parms gparms;
+
+ TF_CHECK_PARMS3(tfp, parms, parms->data);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&gparms, 0, sizeof(struct tf_tbl_get_parms));
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup session, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ if (dev->ops->tf_dev_get_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return -EOPNOTSUPP;
+ }
+
+ gparms.dir = parms->dir;
+ gparms.type = parms->type;
+ gparms.data = parms->data;
+ gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
+ gparms.idx = parms->idx;
+ rc = dev->ops->tf_dev_get_tbl(tfp, &gparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table get failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return rc;
+}
struct tf_session_info *session;
};
+/**
+ * Identifier resource definition
+ */
+struct tf_identifier_resources {
+ /**
+ * Array of TF Identifiers where each entry is expected to be
+ * set to the requested resource number of that specific type.
+ * The index used is tf_identifier_type.
+ */
+ uint16_t cnt[TF_IDENT_TYPE_MAX];
+};
+
+/**
+ * Table type resource definition
+ */
+struct tf_tbl_resources {
+ /**
+ * Array of TF Table types where each entry is expected to be
+ * set to the requeste resource number of that specific
+ * type. The index used is tf_tbl_type.
+ */
+ uint16_t cnt[TF_TBL_TYPE_MAX];
+};
+
+/**
+ * TCAM type resource definition
+ */
+struct tf_tcam_resources {
+ /**
+ * Array of TF TCAM types where each entry is expected to be
+ * set to the requested resource number of that specific
+ * type. The index used is tf_tcam_tbl_type.
+ */
+ uint16_t cnt[TF_TCAM_TBL_TYPE_MAX];
+};
+
+/**
+ * EM type resource definition
+ */
+struct tf_em_resources {
+ /**
+ * Array of TF EM table types where each entry is expected to
+ * be set to the requested resource number of that specific
+ * type. The index used is tf_em_tbl_type.
+ */
+ uint16_t cnt[TF_EM_TBL_TYPE_MAX];
+};
+
/**
* tf_session_resources parameter definition.
*/
struct tf_session_resources {
- /** [in] Requested Identifier Resources
+ /**
+ * [in] Requested Identifier Resources
*
- * The number of identifier resources requested for the session.
- * The index used is tf_identifier_type.
+ * Number of identifier resources requested for the
+ * session.
*/
- uint16_t identifier_cnt[TF_IDENT_TYPE_MAX][TF_DIR_MAX];
- /** [in] Requested Index Table resource counts
+ struct tf_identifier_resources ident_cnt[TF_DIR_MAX];
+ /**
+ * [in] Requested Index Table resource counts
*
- * The number of index table resources requested for the session.
- * The index used is tf_tbl_type.
+ * The number of index table resources requested for the
+ * session.
*/
- uint16_t tbl_cnt[TF_TBL_TYPE_MAX][TF_DIR_MAX];
- /** [in] Requested TCAM Table resource counts
+ struct tf_tbl_resources tbl_cnt[TF_DIR_MAX];
+ /**
+ * [in] Requested TCAM Table resource counts
*
- * The number of TCAM table resources requested for the session.
- * The index used is tf_tcam_tbl_type.
+ * The number of TCAM table resources requested for the
+ * session.
*/
- uint16_t tcam_tbl_cnt[TF_TCAM_TBL_TYPE_MAX][TF_DIR_MAX];
- /** [in] Requested EM resource counts
+
+ struct tf_tcam_resources tcam_cnt[TF_DIR_MAX];
+ /**
+ * [in] Requested EM resource counts
*
- * The number of internal EM table resources requested for the session
- * The index used is tf_em_tbl_type.
+ * The number of internal EM table resources requested for the
+ * session.
*/
- uint16_t em_tbl_cnt[TF_EM_TBL_TYPE_MAX][TF_DIR_MAX];
+ struct tf_em_resources em_cnt[TF_DIR_MAX];
};
/**
int tf_open_session(struct tf *tfp,
struct tf_open_session_parms *parms);
-int tf_open_session_new(struct tf *tfp,
- struct tf_open_session_parms *parms);
-
struct tf_attach_session_parms {
/**
* [in] ctrl_chan_name
*/
int tf_attach_session(struct tf *tfp,
struct tf_attach_session_parms *parms);
-int tf_attach_session_new(struct tf *tfp,
- struct tf_attach_session_parms *parms);
/**
* Closes an existing session. Cleans up all hardware and firmware
* Returns success or failure code.
*/
int tf_close_session(struct tf *tfp);
-int tf_close_session_new(struct tf *tfp);
/**
* @page ident Identity Management
*/
int tf_alloc_identifier(struct tf *tfp,
struct tf_alloc_identifier_parms *parms);
-int tf_alloc_identifier_new(struct tf *tfp,
- struct tf_alloc_identifier_parms *parms);
/**
* free identifier resource
*/
int tf_free_identifier(struct tf *tfp,
struct tf_free_identifier_parms *parms);
-int tf_free_identifier_new(struct tf *tfp,
- struct tf_free_identifier_parms *parms);
/**
* @page dram_table DRAM Table Scope Interface
* provided data buffer is too small for the data type requested.
*/
int tf_bulk_get_tbl_entry(struct tf *tfp,
- struct tf_bulk_get_tbl_entry_parms *parms);
+ struct tf_bulk_get_tbl_entry_parms *parms);
/**
* @page exact_match Exact Match Table
struct tf_tbl_cfg_parms tbl_cfg;
struct tf_tcam_cfg_parms tcam_cfg;
+ dev_handle->type = TF_DEVICE_TYPE_WH;
+ /* Initial function initialization */
+ dev_handle->ops = &tf_dev_ops_p4_init;
+
+ dev_handle->type = TF_DEVICE_TYPE_WH;
+ /* Initial function initialization */
+ dev_handle->ops = &tf_dev_ops_p4_init;
+
/* Initialize the modules */
ident_cfg.num_elements = TF_IDENT_TYPE_MAX;
goto fail;
}
- dev_handle->type = TF_DEVICE_TYPE_WH;
+ /* Final function initialization */
dev_handle->ops = &tf_dev_ops_p4;
return 0;
/**
* Supported device operation structures
*/
+extern const struct tf_dev_ops tf_dev_ops_p4_init;
extern const struct tf_dev_ops tf_dev_ops_p4;
#endif /* _TF_DEVICE_H_ */
return 0;
}
+/**
+ * Truflow P4 device specific functions
+ */
+const struct tf_dev_ops tf_dev_ops_p4_init = {
+ .tf_dev_get_max_types = tf_dev_p4_get_max_types,
+ .tf_dev_get_tcam_slice_info = tf_dev_p4_get_tcam_slice_info,
+ .tf_dev_alloc_ident = NULL,
+ .tf_dev_free_ident = NULL,
+ .tf_dev_alloc_tbl = NULL,
+ .tf_dev_free_tbl = NULL,
+ .tf_dev_alloc_search_tbl = NULL,
+ .tf_dev_set_tbl = NULL,
+ .tf_dev_get_tbl = NULL,
+ .tf_dev_alloc_tcam = NULL,
+ .tf_dev_free_tcam = NULL,
+ .tf_dev_alloc_search_tcam = NULL,
+ .tf_dev_set_tcam = NULL,
+ .tf_dev_get_tcam = NULL,
+};
+
/**
* Truflow P4 device specific functions
*/
.tf_dev_free_ident = tf_ident_free,
.tf_dev_alloc_tbl = tf_tbl_alloc,
.tf_dev_free_tbl = tf_tbl_free,
- .tf_dev_alloc_search_tbl = tf_tbl_alloc_search,
+ .tf_dev_alloc_search_tbl = NULL,
.tf_dev_set_tbl = tf_tbl_set,
.tf_dev_get_tbl = tf_tbl_get,
.tf_dev_alloc_tcam = tf_tcam_alloc,
.tf_dev_free_tcam = tf_tcam_free,
- .tf_dev_alloc_search_tcam = tf_tcam_alloc_search,
+ .tf_dev_alloc_search_tcam = NULL,
.tf_dev_set_tcam = tf_tcam_set,
- .tf_dev_get_tcam = tf_tcam_get,
+ .tf_dev_get_tcam = NULL,
.tf_dev_insert_em_entry = tf_em_insert_entry,
.tf_dev_delete_em_entry = tf_em_delete_entry,
};
db_cfg.dir = i;
db_cfg.num_elements = parms->num_elements;
db_cfg.cfg = parms->cfg;
- db_cfg.alloc_num = parms->resources->identifier_cnt[i];
- db_cfg.rm_db = ident_db[i];
+ db_cfg.alloc_cnt = parms->resources->ident_cnt[i].cnt;
+ db_cfg.rm_db = &ident_db[i];
rc = tf_rm_create_db(tfp, &db_cfg);
if (rc) {
TFP_DRV_LOG(ERR,
"%s: Identifier DB creation failed\n",
tf_dir_2_str(i));
+
return rc;
}
}
init = 1;
+ printf("Identifier - initialized\n");
+
return 0;
}
/* Bail if nothing has been initialized done silent as to
* allow for creation cleanup.
*/
- if (!init)
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "No Identifier DBs created\n");
return -EINVAL;
+ }
for (i = 0; i < TF_DIR_MAX; i++) {
fparms.dir = i;
struct tf_ident_alloc_parms *parms)
{
int rc;
+ uint32_t id;
struct tf_rm_allocate_parms aparms = { 0 };
TF_CHECK_PARMS2(tfp, parms);
/* Allocate requested element */
aparms.rm_db = ident_db[parms->dir];
- aparms.db_index = parms->ident_type;
- aparms.index = (uint32_t *)&parms->id;
+ aparms.db_index = parms->type;
+ aparms.index = &id;
rc = tf_rm_allocate(&aparms);
if (rc) {
TFP_DRV_LOG(ERR,
"%s: Failed allocate, type:%d\n",
tf_dir_2_str(parms->dir),
- parms->ident_type);
+ parms->type);
return rc;
}
+ *parms->id = id;
+
return 0;
}
/* Check if element is in use */
aparms.rm_db = ident_db[parms->dir];
- aparms.db_index = parms->ident_type;
+ aparms.db_index = parms->type;
aparms.index = parms->id;
aparms.allocated = &allocated;
rc = tf_rm_is_allocated(&aparms);
TFP_DRV_LOG(ERR,
"%s: Entry already free, type:%d, index:%d\n",
tf_dir_2_str(parms->dir),
- parms->ident_type,
+ parms->type,
parms->id);
return rc;
}
/* Free requested element */
fparms.rm_db = ident_db[parms->dir];
- fparms.db_index = parms->ident_type;
+ fparms.db_index = parms->type;
fparms.index = parms->id;
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->ident_type,
+ parms->type,
parms->id);
return rc;
}
/**
* [in] Identifier type
*/
- enum tf_identifier_type ident_type;
+ enum tf_identifier_type type;
/**
* [out] Identifier allocated
*/
/**
* [in] Identifier type
*/
- enum tf_identifier_type ident_type;
+ enum tf_identifier_type type;
/**
* [in] ID to free
*/
#include "tf_device.h"
#include "tf_msg.h"
#include "tf_util.h"
+#include "tf_common.h"
#include "tf_session.h"
#include "tfp.h"
#include "hwrm_tf.h"
struct tf_rm_resc_req_entry *data;
int dma_size;
- if (size == 0 || query == NULL || resv_strategy == NULL) {
- TFP_DRV_LOG(ERR,
- "%s: Resource QCAPS parameter error, rc:%s\n",
- tf_dir_2_str(dir),
- strerror(-EINVAL));
- return -EINVAL;
- }
+ TF_CHECK_PARMS3(tfp, query, resv_strategy);
rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
if (rc) {
req.fw_session_id = tfp_cpu_to_le_32(fw_session_id);
req.flags = tfp_cpu_to_le_16(dir);
req.qcaps_size = size;
- req.qcaps_addr = qcaps_buf.pa_addr;
+ req.qcaps_addr = tfp_cpu_to_le_64(qcaps_buf.pa_addr);
parms.tf_type = HWRM_TF_SESSION_RESC_QCAPS;
parms.req_data = (uint32_t *)&req;
*/
if (resp.size != size) {
TFP_DRV_LOG(ERR,
- "%s: QCAPS message error, rc:%s\n",
+ "%s: QCAPS message size error, rc:%s\n",
tf_dir_2_str(dir),
strerror(-EINVAL));
return -EINVAL;
}
+ printf("size: %d\n", resp.size);
+
/* Post process the response */
data = (struct tf_rm_resc_req_entry *)qcaps_buf.va_addr;
+
+ printf("\nQCAPS\n");
for (i = 0; i < size; i++) {
query[i].type = tfp_cpu_to_le_32(data[i].type);
query[i].min = tfp_le_to_cpu_16(data[i].min);
query[i].max = tfp_le_to_cpu_16(data[i].max);
+
+ printf("type: %d(0x%x) %d %d\n",
+ query[i].type,
+ query[i].type,
+ query[i].min,
+ query[i].max);
+
}
*resv_strategy = resp.flags &
struct tf_rm_resc_entry *resv_data;
int dma_size;
+ TF_CHECK_PARMS3(tfp, request, resv);
+
rc = tf_session_get_fw_session_id(tfp, &fw_session_id);
if (rc) {
TFP_DRV_LOG(ERR,
req_data[i].max = tfp_cpu_to_le_16(request[i].max);
}
- req.req_addr = req_buf.pa_addr;
- req.resp_addr = resv_buf.pa_addr;
+ req.req_addr = tfp_cpu_to_le_64(req_buf.pa_addr);
+ req.resc_addr = tfp_cpu_to_le_64(resv_buf.pa_addr);
parms.tf_type = HWRM_TF_SESSION_RESC_ALLOC;
parms.req_data = (uint32_t *)&req;
*/
if (resp.size != size) {
TFP_DRV_LOG(ERR,
- "%s: Alloc message error, rc:%s\n",
+ "%s: Alloc message size error, rc:%s\n",
tf_dir_2_str(dir),
strerror(-EINVAL));
return -EINVAL;
}
+ printf("\nRESV\n");
+ printf("size: %d\n", resp.size);
+
/* Post process the response */
resv_data = (struct tf_rm_resc_entry *)resv_buf.va_addr;
for (i = 0; i < size; i++) {
resv[i].type = tfp_cpu_to_le_32(resv_data[i].type);
resv[i].start = tfp_cpu_to_le_16(resv_data[i].start);
resv[i].stride = tfp_cpu_to_le_16(resv_data[i].stride);
+
+ printf("%d type: %d(0x%x) %d %d\n",
+ i,
+ resv[i].type,
+ resv[i].type,
+ resv[i].start,
+ resv[i].stride);
}
tf_msg_free_dma_buf(&req_buf);
req.start_index = tfp_cpu_to_le_32(params->starting_idx);
req.num_entries = tfp_cpu_to_le_32(params->num_entries);
- data_size = (params->num_entries * params->entry_sz_in_bytes);
+ data_size = params->num_entries * params->entry_sz_in_bytes;
+
req.host_addr = tfp_cpu_to_le_64(params->physical_mem_addr);
MSG_PREP(parms,
#include "tf_tbl.h"
#include "tf_rm.h"
#include "tf_rm_new.h"
+#include "tf_tcam.h"
struct tf;
#include <cfa_resource_types.h>
#include "tf_rm_new.h"
+#include "tf_common.h"
#include "tf_util.h"
#include "tf_session.h"
#include "tf_device.h"
struct tf_rm_element *db;
};
+/**
+ * Adjust an index according to the allocation information.
+ *
+ * All resources are controlled in a 0 based pool. Some resources, by
+ * design, are not 0 based, i.e. Full Action Records (SRAM) thus they
+ * need to be adjusted before they are handed out.
+ *
+ * [in] cfg
+ * Pointer to the DB configuration
+ *
+ * [in] reservations
+ * Pointer to the allocation values associated with the module
+ *
+ * [in] count
+ * Number of DB configuration elements
+ *
+ * [out] valid_count
+ * Number of HCAPI entries with a reservation value greater than 0
+ *
+ * Returns:
+ * 0 - Success
+ * - EOPNOTSUPP - Operation not supported
+ */
+static void
+tf_rm_count_hcapi_reservations(struct tf_rm_element_cfg *cfg,
+ uint16_t *reservations,
+ uint16_t count,
+ uint16_t *valid_count)
+{
+ int i;
+ uint16_t cnt = 0;
+
+ for (i = 0; i < count; i++) {
+ if (cfg[i].cfg_type == TF_RM_ELEM_CFG_HCAPI &&
+ reservations[i] > 0)
+ cnt++;
+ }
+
+ *valid_count = cnt;
+}
/**
* Resource Manager Adjust of base index definitions.
{
int rc;
int i;
+ int j;
struct tf_session *tfs;
struct tf_dev_info *dev;
uint16_t max_types;
struct tf_rm_new_db *rm_db;
struct tf_rm_element *db;
uint32_t pool_size;
+ uint16_t hcapi_items;
+
+ TF_CHECK_PARMS2(tfp, parms);
/* Retrieve the session information */
rc = tf_session_get_session(tfp, &tfs);
if (rc)
return rc;
- /* Process capabilities against db requirements */
+ /* Process capabilities against DB requirements. However, as a
+ * DB can hold elements that are not HCAPI we can reduce the
+ * req msg content by removing those out of the request yet
+ * the DB holds them all as to give a fast lookup. We can also
+ * remove entries where there are no request for elements.
+ */
+ tf_rm_count_hcapi_reservations(parms->cfg,
+ parms->alloc_cnt,
+ parms->num_elements,
+ &hcapi_items);
/* Alloc request, alignment already set */
- cparms.nitems = parms->num_elements;
+ cparms.nitems = (size_t)hcapi_items;
cparms.size = sizeof(struct tf_rm_resc_req_entry);
rc = tfp_calloc(&cparms);
if (rc)
resv = (struct tf_rm_resc_entry *)cparms.mem_va;
/* Build the request */
- for (i = 0; i < parms->num_elements; i++) {
+ for (i = 0, j = 0; i < parms->num_elements; i++) {
/* Skip any non HCAPI cfg elements */
if (parms->cfg[i].cfg_type == TF_RM_ELEM_CFG_HCAPI) {
- req[i].type = parms->cfg[i].hcapi_type;
- /* Check that we can get the full amount allocated */
- if (parms->alloc_num[i] <=
+ /* Only perform reservation for entries that
+ * has been requested
+ */
+ if (parms->alloc_cnt[i] == 0)
+ continue;
+
+ /* Verify that we can get the full amount
+ * allocated per the qcaps availability.
+ */
+ if (parms->alloc_cnt[i] <=
query[parms->cfg[i].hcapi_type].max) {
- req[i].min = parms->alloc_num[i];
- req[i].max = parms->alloc_num[i];
+ req[j].type = parms->cfg[i].hcapi_type;
+ req[j].min = parms->alloc_cnt[i];
+ req[j].max = parms->alloc_cnt[i];
+ j++;
} else {
TFP_DRV_LOG(ERR,
"%s: Resource failure, type:%d\n",
parms->cfg[i].hcapi_type);
TFP_DRV_LOG(ERR,
"req:%d, avail:%d\n",
- parms->alloc_num[i],
+ parms->alloc_cnt[i],
query[parms->cfg[i].hcapi_type].max);
return -EINVAL;
}
- } else {
- /* Skip the element */
- req[i].type = CFA_RESOURCE_TYPE_INVALID;
}
}
rc = tf_msg_session_resc_alloc(tfp,
parms->dir,
- parms->num_elements,
+ hcapi_items,
req,
resv);
if (rc)
rm_db->db = (struct tf_rm_element *)cparms.mem_va;
db = rm_db->db;
- for (i = 0; i < parms->num_elements; i++) {
- /* If allocation failed for a single entry the DB
- * creation is considered a failure.
+ for (i = 0, j = 0; i < parms->num_elements; i++) {
+ db[i].cfg_type = parms->cfg[i].cfg_type;
+ db[i].hcapi_type = parms->cfg[i].hcapi_type;
+
+ /* Skip any non HCAPI types as we didn't include them
+ * in the reservation request.
+ */
+ if (parms->cfg[i].cfg_type != TF_RM_ELEM_CFG_HCAPI)
+ continue;
+
+ /* If the element didn't request an allocation no need
+ * to create a pool nor verify if we got a reservation.
*/
- if (parms->alloc_num[i] != resv[i].stride) {
+ if (parms->alloc_cnt[i] == 0)
+ continue;
+
+ /* If the element had requested an allocation and that
+ * allocation was a success (full amount) then
+ * allocate the pool.
+ */
+ if (parms->alloc_cnt[i] == resv[j].stride) {
+ db[i].alloc.entry.start = resv[j].start;
+ db[i].alloc.entry.stride = resv[j].stride;
+
+ /* Create pool */
+ pool_size = (BITALLOC_SIZEOF(resv[j].stride) /
+ sizeof(struct bitalloc));
+ /* Alloc request, alignment already set */
+ cparms.nitems = pool_size;
+ cparms.size = sizeof(struct bitalloc);
+ rc = tfp_calloc(&cparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Pool alloc failed, type:%d\n",
+ tf_dir_2_str(parms->dir),
+ db[i].cfg_type);
+ goto fail;
+ }
+ db[i].pool = (struct bitalloc *)cparms.mem_va;
+
+ rc = ba_init(db[i].pool, resv[j].stride);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Pool init failed, type:%d\n",
+ tf_dir_2_str(parms->dir),
+ db[i].cfg_type);
+ goto fail;
+ }
+ j++;
+ } else {
+ /* Bail out as we want what we requested for
+ * all elements, not any less.
+ */
TFP_DRV_LOG(ERR,
"%s: Alloc failed, type:%d\n",
tf_dir_2_str(parms->dir),
- i);
+ db[i].cfg_type);
TFP_DRV_LOG(ERR,
"req:%d, alloc:%d\n",
- parms->alloc_num[i],
- resv[i].stride);
+ parms->alloc_cnt[i],
+ resv[j].stride);
goto fail;
}
-
- db[i].cfg_type = parms->cfg[i].cfg_type;
- db[i].hcapi_type = parms->cfg[i].hcapi_type;
- db[i].alloc.entry.start = resv[i].start;
- db[i].alloc.entry.stride = resv[i].stride;
-
- /* Create pool */
- pool_size = (BITALLOC_SIZEOF(resv[i].stride) /
- sizeof(struct bitalloc));
- /* Alloc request, alignment already set */
- cparms.nitems = pool_size;
- cparms.size = sizeof(struct bitalloc);
- rc = tfp_calloc(&cparms);
- if (rc)
- return rc;
- db[i].pool = (struct bitalloc *)cparms.mem_va;
}
rm_db->num_entries = i;
rm_db->dir = parms->dir;
- parms->rm_db = (void *)rm_db;
+ *parms->rm_db = (void *)rm_db;
tfp_free((void *)req);
tfp_free((void *)resv);
int i;
struct tf_rm_new_db *rm_db;
+ TF_CHECK_PARMS1(parms);
+
/* Traverse the DB and clear each pool.
* NOTE:
* Firmware is not cleared. It will be cleared on close only.
*/
rm_db = (struct tf_rm_new_db *)parms->rm_db;
for (i = 0; i < rm_db->num_entries; i++)
- tfp_free((void *)rm_db->db->pool);
+ tfp_free((void *)rm_db->db[i].pool);
tfp_free((void *)parms->rm_db);
{
int rc = 0;
int id;
+ uint32_t index;
struct tf_rm_new_db *rm_db;
enum tf_rm_elem_cfg_type cfg_type;
- if (parms == NULL || parms->rm_db == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(parms, parms->rm_db);
rm_db = (struct tf_rm_new_db *)parms->rm_db;
cfg_type = rm_db->db[parms->db_index].cfg_type;
cfg_type != TF_RM_ELEM_CFG_PRIVATE)
return -ENOTSUP;
+ /* Bail out if the pool is not valid, should never happen */
+ if (rm_db->db[parms->db_index].pool == NULL) {
+ rc = -ENOTSUP;
+ TFP_DRV_LOG(ERR,
+ "%s: Invalid pool for this type:%d, rc:%s\n",
+ tf_dir_2_str(rm_db->dir),
+ parms->db_index,
+ strerror(-rc));
+ return rc;
+ }
+
id = ba_alloc(rm_db->db[parms->db_index].pool);
if (id == BA_FAIL) {
TFP_DRV_LOG(ERR,
TF_RM_ADJUST_ADD_BASE,
parms->db_index,
id,
- parms->index);
+ &index);
if (rc) {
TFP_DRV_LOG(ERR,
"%s: Alloc adjust of base index failed, rc:%s\n",
tf_dir_2_str(rm_db->dir),
strerror(-rc));
- return -1;
+ return -EINVAL;
}
+ *parms->index = index;
+
return rc;
}
struct tf_rm_new_db *rm_db;
enum tf_rm_elem_cfg_type cfg_type;
- if (parms == NULL || parms->rm_db == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(parms, parms->rm_db);
rm_db = (struct tf_rm_new_db *)parms->rm_db;
cfg_type = rm_db->db[parms->db_index].cfg_type;
cfg_type != TF_RM_ELEM_CFG_PRIVATE)
return -ENOTSUP;
+ /* Bail out if the pool is not valid, should never happen */
+ if (rm_db->db[parms->db_index].pool == NULL) {
+ rc = -ENOTSUP;
+ TFP_DRV_LOG(ERR,
+ "%s: Invalid pool for this type:%d, rc:%s\n",
+ tf_dir_2_str(rm_db->dir),
+ parms->db_index,
+ strerror(-rc));
+ return rc;
+ }
+
/* Adjust for any non zero start value */
rc = tf_rm_adjust_index(rm_db->db,
TF_RM_ADJUST_RM_BASE,
struct tf_rm_new_db *rm_db;
enum tf_rm_elem_cfg_type cfg_type;
- if (parms == NULL || parms->rm_db == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(parms, parms->rm_db);
rm_db = (struct tf_rm_new_db *)parms->rm_db;
cfg_type = rm_db->db[parms->db_index].cfg_type;
cfg_type != TF_RM_ELEM_CFG_PRIVATE)
return -ENOTSUP;
+ /* Bail out if the pool is not valid, should never happen */
+ if (rm_db->db[parms->db_index].pool == NULL) {
+ rc = -ENOTSUP;
+ TFP_DRV_LOG(ERR,
+ "%s: Invalid pool for this type:%d, rc:%s\n",
+ tf_dir_2_str(rm_db->dir),
+ parms->db_index,
+ strerror(-rc));
+ return rc;
+ }
+
/* Adjust for any non zero start value */
rc = tf_rm_adjust_index(rm_db->db,
TF_RM_ADJUST_RM_BASE,
struct tf_rm_new_db *rm_db;
enum tf_rm_elem_cfg_type cfg_type;
- if (parms == NULL || parms->rm_db == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(parms, parms->rm_db);
rm_db = (struct tf_rm_new_db *)parms->rm_db;
cfg_type = rm_db->db[parms->db_index].cfg_type;
struct tf_rm_new_db *rm_db;
enum tf_rm_elem_cfg_type cfg_type;
- if (parms == NULL || parms->rm_db == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(parms, parms->rm_db);
rm_db = (struct tf_rm_new_db *)parms->rm_db;
cfg_type = rm_db->db[parms->db_index].cfg_type;
*/
struct tf_rm_element_cfg *cfg;
/**
- * Allocation number array. Array size is num_elements.
+ * Resource allocation count array. This array content
+ * originates from the tf_session_resources that is passed in
+ * on session open.
+ * Array size is num_elements.
*/
- uint16_t *alloc_num;
+ uint16_t *alloc_cnt;
/**
* [out] RM DB Handle
*/
- void *rm_db;
+ void **rm_db;
};
/**
/**
* Performs a lookup in the Resource Manager DB and retrieves the
- * requested HCAPI type.
+ * requested HCAPI RM type.
*
* [in] parms
* Pointer to get hcapi parameters
parms->open_cfg->device_type,
session->shadow_copy,
&parms->open_cfg->resources,
- session->dev);
+ &session->dev);
/* Logging handled by dev_bind */
if (rc)
return rc;
- /* Query for Session Config
- */
- rc = tf_msg_session_qcfg(tfp);
- if (rc) {
- TFP_DRV_LOG(ERR,
- "Query config message send failed, rc:%s\n",
- strerror(-rc));
- goto cleanup_close;
- }
-
session->ref_count++;
return 0;
tfp_free(tfp->session);
tfp->session = NULL;
return rc;
-
- cleanup_close:
- tf_close_session(tfp);
- return -EINVAL;
}
int
tf_session_get_device(struct tf_session *tfs,
struct tf_dev_info **tfd)
{
- int rc;
-
- if (tfs->dev == NULL) {
- rc = -EINVAL;
- TFP_DRV_LOG(ERR,
- "Device not created, rc:%s\n",
- strerror(-rc));
- return rc;
- }
-
- *tfd = tfs->dev;
+ *tfd = &tfs->dev;
return 0;
}
uint8_t ref_count;
/** Device handle */
- struct tf_dev_info *dev;
+ struct tf_dev_info dev;
/** Session HW and SRAM resources */
struct tf_rm_db resc;
return 0;
}
-/**
- * Internal function to set a Table Entry. Supports all internal Table Types
- *
- * [in] tfp
- * Pointer to TruFlow handle
- *
- * [in] parms
- * Pointer to input parameters
- *
- * Returns:
- * 0 - Success
- * -EINVAL - Parameter error
- */
-static int
-tf_set_tbl_entry_internal(struct tf *tfp,
- struct tf_set_tbl_entry_parms *parms)
-{
- int rc;
- int id;
- uint32_t index;
- struct bitalloc *session_pool;
- struct tf_session *tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* 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 */
- if (rc)
- return rc;
-
- index = parms->idx;
-
- if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD &&
- parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 &&
- parms->type != TF_TBL_TYPE_ACT_STATS_64) {
- TFP_DRV_LOG(ERR,
- "%s, Type not supported, type:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type);
- return -EOPNOTSUPP;
- }
-
- /* 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,
- parms->type,
- TF_RM_CONVERT_RM_BASE,
- parms->idx,
- &index);
-
- /* Verify that the entry has been previously allocated */
- id = ba_inuse(session_pool, index);
- if (id != 1) {
- TFP_DRV_LOG(ERR,
- "%s, Invalid or not allocated index, type:%d, idx:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type,
- index);
- return -EINVAL;
- }
-
- /* Set the entry */
- rc = tf_msg_set_tbl_entry(tfp,
- parms->dir,
- parms->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;
-}
-
-/**
- * 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
- */
-static int
-tf_get_tbl_entry_internal(struct tf *tfp,
- struct tf_get_tbl_entry_parms *parms)
-{
- int rc;
- int id;
- uint32_t index;
- struct bitalloc *session_pool;
- struct tf_session *tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* 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 */
- if (rc)
- return rc;
-
- index = parms->idx;
-
- /* 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,
- parms->type,
- TF_RM_CONVERT_RM_BASE,
- parms->idx,
- &index);
-
- /* Verify that the entry has been previously allocated */
- id = ba_inuse(session_pool, index);
- if (id != 1) {
- TFP_DRV_LOG(ERR,
- "%s, Invalid or not allocated index, type:%d, idx:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type,
- index);
- return -EINVAL;
- }
-
- /* Get the entry */
- rc = tf_msg_get_tbl_entry(tfp,
- parms->dir,
- parms->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;
-}
-
/**
* 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.
tfp_free(ext_act_pool_mem);
}
-/**
- * Allocate External Tbl entry from the Session Pool.
- *
- * [in] tfp
- * Pointer to Truflow Handle
- * [in] parms
- * Allocation parameters
- *
- * Return:
- * 0 - Success, entry allocated - no search support
- * -ENOMEM -EINVAL -EOPNOTSUPP
- * - Failure, entry not allocated, out of resources
- */
-static int
-tf_alloc_tbl_entry_pool_external(struct tf *tfp,
- struct tf_alloc_tbl_entry_parms *parms)
-{
- int rc;
- uint32_t index;
- struct tf_session *tfs;
- struct tf_tbl_scope_cb *tbl_scope_cb;
- struct stack *pool;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* Get the pool info from the table scope
- */
- tbl_scope_cb = tbl_scope_cb_find(tfs, parms->tbl_scope_id);
-
- if (tbl_scope_cb == NULL) {
- TFP_DRV_LOG(ERR,
- "%s, table scope not allocated\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
- pool = &tbl_scope_cb->ext_act_pool[parms->dir];
-
- /* Allocate an element
- */
- rc = stack_pop(pool, &index);
-
- if (rc != 0) {
- TFP_DRV_LOG(ERR,
- "%s, Allocation failed, type:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type);
- return rc;
- }
- parms->idx = index;
- return rc;
-}
-
-/**
- * Allocate Internal Tbl entry from the Session Pool.
- *
- * [in] tfp
- * Pointer to Truflow Handle
- * [in] parms
- * Allocation parameters
- *
- * Return:
- * 0 - Success, entry found and ref count decremented
- * -ENOMEM - Failure, entry not allocated, out of resources
- */
-static int
-tf_alloc_tbl_entry_pool_internal(struct tf *tfp,
- struct tf_alloc_tbl_entry_parms *parms)
-{
- int rc;
- int id;
- int free_cnt;
- uint32_t index;
- struct bitalloc *session_pool;
- struct tf_session *tfs;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD &&
- parms->type != TF_TBL_TYPE_ACT_SP_SMAC &&
- parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_8B &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_16B &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_64B &&
- parms->type != TF_TBL_TYPE_ACT_STATS_64) {
- TFP_DRV_LOG(ERR,
- "%s, Type not supported, type:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type);
- return -EOPNOTSUPP;
- }
-
- /* 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 */
- if (rc)
- return rc;
-
- id = ba_alloc(session_pool);
- if (id == -1) {
- free_cnt = ba_free_count(session_pool);
-
- TFP_DRV_LOG(ERR,
- "%s, Allocation failed, type:%d, free:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type,
- free_cnt);
- return -ENOMEM;
- }
-
- /* 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,
- parms->type,
- TF_RM_CONVERT_ADD_BASE,
- id,
- &index);
- parms->idx = index;
- return rc;
-}
-
-/**
- * Free External Tbl entry to the session pool.
- *
- * [in] tfp
- * Pointer to Truflow Handle
- * [in] parms
- * Allocation parameters
- *
- * Return:
- * 0 - Success, entry freed
- *
- * - Failure, entry not successfully freed for these reasons
- * -ENOMEM
- * -EOPNOTSUPP
- * -EINVAL
- */
-static int
-tf_free_tbl_entry_pool_external(struct tf *tfp,
- struct tf_free_tbl_entry_parms *parms)
-{
- int rc = 0;
- struct tf_session *tfs;
- uint32_t index;
- struct tf_tbl_scope_cb *tbl_scope_cb;
- struct stack *pool;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* Get the pool info from the table scope
- */
- tbl_scope_cb = tbl_scope_cb_find(tfs, parms->tbl_scope_id);
-
- if (tbl_scope_cb == NULL) {
- TFP_DRV_LOG(ERR,
- "%s, table scope error\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
- pool = &tbl_scope_cb->ext_act_pool[parms->dir];
-
- index = parms->idx;
-
- rc = stack_push(pool, index);
-
- if (rc != 0) {
- TFP_DRV_LOG(ERR,
- "%s, consistency error, stack full, type:%d, idx:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type,
- index);
- }
- return rc;
-}
-
-/**
- * Free Internal Tbl entry from the Session Pool.
- *
- * [in] tfp
- * Pointer to Truflow Handle
- * [in] parms
- * Allocation parameters
- *
- * Return:
- * 0 - Success, entry found and ref count decremented
- * -ENOMEM - Failure, entry not allocated, out of resources
- */
-static int
-tf_free_tbl_entry_pool_internal(struct tf *tfp,
- struct tf_free_tbl_entry_parms *parms)
-{
- int rc = 0;
- int id;
- struct bitalloc *session_pool;
- struct tf_session *tfs;
- uint32_t index;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- if (parms->type != TF_TBL_TYPE_FULL_ACT_RECORD &&
- parms->type != TF_TBL_TYPE_ACT_SP_SMAC &&
- parms->type != TF_TBL_TYPE_ACT_SP_SMAC_IPV4 &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_8B &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_16B &&
- parms->type != TF_TBL_TYPE_ACT_ENCAP_64B &&
- parms->type != TF_TBL_TYPE_ACT_STATS_64) {
- TFP_DRV_LOG(ERR,
- "%s, Type not supported, type:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type);
- return -EOPNOTSUPP;
- }
-
- /* 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 */
- if (rc)
- return rc;
-
- index = parms->idx;
-
- /* 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,
- parms->type,
- TF_RM_CONVERT_RM_BASE,
- parms->idx,
- &index);
-
- /* Check if element was indeed allocated */
- id = ba_inuse_free(session_pool, index);
- if (id == -1) {
- TFP_DRV_LOG(ERR,
- "%s, Element not previously alloc'ed, type:%d, idx:%d\n",
- tf_dir_2_str(parms->dir),
- parms->type,
- index);
- return -ENOMEM;
- }
-
- return rc;
-}
-
/* API defined in tf_em.h */
struct tf_tbl_scope_cb *
tbl_scope_cb_find(struct tf_session *session,
return -EINVAL;
}
-/* API defined in tf_core.h */
-int
-tf_set_tbl_entry(struct tf *tfp,
- struct tf_set_tbl_entry_parms *parms)
-{
- int rc = 0;
- struct tf_tbl_scope_cb *tbl_scope_cb;
- struct tf_session *session;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- if (parms->data == NULL) {
- TFP_DRV_LOG(ERR,
- "%s, invalid parms->data\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
-
- if (parms->type == TF_TBL_TYPE_EXT) {
- void *base_addr;
- uint32_t offset = parms->idx;
- uint32_t tbl_scope_id;
-
- session = (struct tf_session *)(tfp->session->core_data);
-
- tbl_scope_id = parms->tbl_scope_id;
-
- if (tbl_scope_id == TF_TBL_SCOPE_INVALID) {
- TFP_DRV_LOG(ERR,
- "%s, Table scope not allocated\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
-
- /* Get the table scope control block associated with the
- * external pool
- */
- tbl_scope_cb = tbl_scope_cb_find(session, tbl_scope_id);
-
- if (tbl_scope_cb == NULL) {
- TFP_DRV_LOG(ERR,
- "%s, table scope error\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
-
- /* External table, implicitly the Action table */
- base_addr = (void *)(uintptr_t)
- hcapi_get_table_page(&tbl_scope_cb->em_ctx_info[parms->dir].em_tables[TF_RECORD_TABLE], offset);
-
- if (base_addr == NULL) {
- TFP_DRV_LOG(ERR,
- "%s, Base address lookup failed\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
-
- offset %= TF_EM_PAGE_SIZE;
- rte_memcpy((char *)base_addr + offset,
- parms->data,
- parms->data_sz_in_bytes);
- } else {
- /* Internal table type processing */
- rc = tf_set_tbl_entry_internal(tfp, parms);
- 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;
-}
-
-/* API defined in tf_core.h */
-int
-tf_get_tbl_entry(struct tf *tfp,
- struct tf_get_tbl_entry_parms *parms)
-{
- int rc = 0;
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- if (parms->type == TF_TBL_TYPE_EXT) {
- /* Not supported, yet */
- TFP_DRV_LOG(ERR,
- "%s, External table type not supported\n",
- tf_dir_2_str(parms->dir));
-
- rc = -EOPNOTSUPP;
- } else {
- /* Internal table type processing */
- rc = tf_get_tbl_entry_internal(tfp, parms);
- 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;
-}
-
-/* API defined in tf_core.h */
+ /* API defined in tf_core.h */
int
tf_bulk_get_tbl_entry(struct tf *tfp,
struct tf_bulk_get_tbl_entry_parms *parms)
return rc;
}
-/* API defined in tf_core.h */
-int
-tf_alloc_tbl_entry(struct tf *tfp,
- struct tf_alloc_tbl_entry_parms *parms)
-{
- int rc;
-#if (TF_SHADOW == 1)
- struct tf_session *tfs;
-#endif /* TF_SHADOW */
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
- /*
- * No shadow copy support for external tables, allocate and return
- */
- if (parms->type == TF_TBL_TYPE_EXT) {
- rc = tf_alloc_tbl_entry_pool_external(tfp, parms);
- return rc;
- }
-
-#if (TF_SHADOW == 1)
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* Search the Shadow DB for requested element. If not found go
- * allocate one from the Session Pool
- */
- if (parms->search_enable && tfs->shadow_copy) {
- rc = tf_alloc_tbl_entry_shadow(tfs, parms);
- /* Entry found and parms populated with return data */
- if (rc == 0)
- return rc;
- }
-#endif /* TF_SHADOW */
-
- rc = tf_alloc_tbl_entry_pool_internal(tfp, parms);
- if (rc)
- TFP_DRV_LOG(ERR, "%s, Alloc failed, rc:%s\n",
- tf_dir_2_str(parms->dir),
- strerror(-rc));
-
- return rc;
-}
-
-/* API defined in tf_core.h */
-int
-tf_free_tbl_entry(struct tf *tfp,
- struct tf_free_tbl_entry_parms *parms)
-{
- int rc;
-#if (TF_SHADOW == 1)
- struct tf_session *tfs;
-#endif /* TF_SHADOW */
-
- TF_CHECK_PARMS_SESSION(tfp, parms);
-
- /*
- * No shadow of external tables so just free the entry
- */
- if (parms->type == TF_TBL_TYPE_EXT) {
- rc = tf_free_tbl_entry_pool_external(tfp, parms);
- return rc;
- }
-
-#if (TF_SHADOW == 1)
- tfs = (struct tf_session *)(tfp->session->core_data);
-
- /* Search the Shadow DB for requested element. If not found go
- * allocate one from the Session Pool
- */
- if (parms->search_enable && tfs->shadow_copy) {
- rc = tf_free_tbl_entry_shadow(tfs, parms);
- /* Entry free'ed and parms populated with return data */
- if (rc == 0)
- return rc;
- }
-#endif /* TF_SHADOW */
-
- rc = tf_free_tbl_entry_pool_internal(tfp, parms);
-
- if (rc)
- TFP_DRV_LOG(ERR, "%s, Alloc failed, rc:%s\n",
- tf_dir_2_str(parms->dir),
- strerror(-rc));
- return rc;
-}
-
-
static void
tf_dump_link_page_table(struct hcapi_cfa_em_page_tbl *tp,
struct hcapi_cfa_em_page_tbl *tp_next)
#include <rte_common.h>
#include "tf_tbl_type.h"
+#include "tf_common.h"
+#include "tf_rm_new.h"
+#include "tf_util.h"
+#include "tf_msg.h"
+#include "tfp.h"
struct tf;
/**
* Table DBs.
*/
-/* static void *tbl_db[TF_DIR_MAX]; */
+static void *tbl_db[TF_DIR_MAX];
/**
* Table Shadow DBs
/**
* Init flag, set on bind and cleared on unbind
*/
-/* static uint8_t init; */
+static uint8_t init;
/**
* Shadow init flag, set on bind and cleared on unbind
/* static uint8_t shadow_init; */
int
-tf_tbl_bind(struct tf *tfp __rte_unused,
- struct tf_tbl_cfg_parms *parms __rte_unused)
+tf_tbl_bind(struct tf *tfp,
+ struct tf_tbl_cfg_parms *parms)
{
+ int rc;
+ int i;
+ struct tf_rm_create_db_parms db_cfg = { 0 };
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (init) {
+ TFP_DRV_LOG(ERR,
+ "Table already initialized\n");
+ return -EINVAL;
+ }
+
+ db_cfg.num_elements = parms->num_elements;
+
+ for (i = 0; i < TF_DIR_MAX; i++) {
+ db_cfg.dir = i;
+ db_cfg.num_elements = parms->num_elements;
+ db_cfg.cfg = parms->cfg;
+ db_cfg.alloc_cnt = parms->resources->tbl_cnt[i].cnt;
+ db_cfg.rm_db = &tbl_db[i];
+ rc = tf_rm_create_db(tfp, &db_cfg);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table DB creation failed\n",
+ tf_dir_2_str(i));
+
+ return rc;
+ }
+ }
+
+ init = 1;
+
+ printf("Table Type - initialized\n");
+
return 0;
}
int
tf_tbl_unbind(struct tf *tfp __rte_unused)
{
+ int rc;
+ int i;
+ struct tf_rm_free_db_parms fparms = { 0 };
+
+ TF_CHECK_PARMS1(tfp);
+
+ /* Bail if nothing has been initialized done silent as to
+ * allow for creation cleanup.
+ */
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "No Table DBs created\n");
+ return -EINVAL;
+ }
+
+ for (i = 0; i < TF_DIR_MAX; i++) {
+ fparms.dir = i;
+ fparms.rm_db = tbl_db[i];
+ rc = tf_rm_free_db(tfp, &fparms);
+ if (rc)
+ return rc;
+
+ tbl_db[i] = NULL;
+ }
+
+ init = 0;
+
return 0;
}
int
tf_tbl_alloc(struct tf *tfp __rte_unused,
- struct tf_tbl_alloc_parms *parms __rte_unused)
+ struct tf_tbl_alloc_parms *parms)
{
+ int rc;
+ uint32_t idx;
+ struct tf_rm_allocate_parms aparms = { 0 };
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Table DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Allocate requested element */
+ aparms.rm_db = tbl_db[parms->dir];
+ aparms.db_index = 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;
+ }
+
+ *parms->idx = idx;
+
return 0;
}
int
tf_tbl_free(struct tf *tfp __rte_unused,
- struct tf_tbl_free_parms *parms __rte_unused)
+ struct tf_tbl_free_parms *parms)
{
+ int rc;
+ struct tf_rm_is_allocated_parms aparms = { 0 };
+ struct tf_rm_free_parms fparms = { 0 };
+ int allocated = 0;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Table DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Check if element is in use */
+ aparms.rm_db = tbl_db[parms->dir];
+ aparms.db_index = parms->type;
+ aparms.index = parms->idx;
+ aparms.allocated = &allocated;
+ rc = tf_rm_is_allocated(&aparms);
+ if (rc)
+ return rc;
+
+ if (!allocated) {
+ TFP_DRV_LOG(ERR,
+ "%s: Entry already free, type:%d, index:%d\n",
+ tf_dir_2_str(parms->dir),
+ parms->type,
+ parms->idx);
+ return rc;
+ }
+
+ /* Free requested element */
+ fparms.rm_db = tbl_db[parms->dir];
+ fparms.db_index = parms->type;
+ fparms.index = parms->idx;
+ 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_set(struct tf *tfp __rte_unused,
- struct tf_tbl_set_parms *parms __rte_unused)
+tf_tbl_set(struct tf *tfp,
+ struct tf_tbl_set_parms *parms)
{
+ int rc;
+ struct tf_rm_is_allocated_parms aparms;
+ int allocated = 0;
+
+ TF_CHECK_PARMS3(tfp, parms, parms->data);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Table DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Verify that the entry has been previously allocated */
+ aparms.rm_db = tbl_db[parms->dir];
+ aparms.db_index = parms->type;
+ aparms.index = parms->idx;
+ aparms.allocated = &allocated;
+ rc = tf_rm_is_allocated(&aparms);
+ if (rc)
+ return rc;
+
+ if (!allocated) {
+ 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 */
+ rc = tf_msg_set_tbl_entry(tfp,
+ parms->dir,
+ parms->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 0;
}
int
-tf_tbl_get(struct tf *tfp __rte_unused,
- struct tf_tbl_get_parms *parms __rte_unused)
+tf_tbl_get(struct tf *tfp,
+ struct tf_tbl_get_parms *parms)
{
+ int rc;
+ struct tf_rm_is_allocated_parms aparms;
+ int allocated = 0;
+
+ TF_CHECK_PARMS3(tfp, parms, parms->data);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Table DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Verify that the entry has been previously allocated */
+ aparms.rm_db = tbl_db[parms->dir];
+ aparms.db_index = parms->type;
+ aparms.index = parms->idx;
+ aparms.allocated = &allocated;
+ rc = tf_rm_is_allocated(&aparms);
+ if (rc)
+ return rc;
+
+ if (!allocated) {
+ 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;
+ }
+
+ /* Get the entry */
+ rc = tf_msg_get_tbl_entry(tfp,
+ parms->dir,
+ parms->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 0;
}
/**
* [out] Idx of allocated entry or found entry (if search_enable)
*/
- uint32_t idx;
+ uint32_t *idx;
};
/**
/* static uint8_t shadow_init; */
int
-tf_tcam_bind(struct tf *tfp __rte_unused,
- struct tf_tcam_cfg_parms *parms __rte_unused)
+tf_tcam_bind(struct tf *tfp,
+ struct tf_tcam_cfg_parms *parms)
{
int rc;
int i;
db_cfg.dir = i;
db_cfg.num_elements = parms->num_elements;
db_cfg.cfg = parms->cfg;
- db_cfg.alloc_num = parms->resources->tcam_tbl_cnt[i];
- db_cfg.rm_db = tcam_db[i];
+ db_cfg.alloc_cnt = parms->resources->tcam_cnt[i].cnt;
+ db_cfg.rm_db = &tcam_db[i];
rc = tf_rm_create_db(tfp, &db_cfg);
if (rc) {
TFP_DRV_LOG(ERR,
init = 1;
+ printf("TCAM - initialized\n");
+
return 0;
}
int
-tf_tcam_unbind(struct tf *tfp __rte_unused)
+tf_tcam_unbind(struct tf *tfp)
{
int rc;
int i;
/**
* Helper function converting direction to text string
+ *
+ * [in] dir
+ * Receive or transmit direction identifier
+ *
+ * Returns:
+ * Pointer to a char string holding the string for the direction
*/
-const char
-*tf_dir_2_str(enum tf_dir dir);
+const char *tf_dir_2_str(enum tf_dir dir);
/**
* Helper function converting identifier to text string
+ *
+ * [in] id_type
+ * Identifier type
+ *
+ * Returns:
+ * Pointer to a char string holding the string for the identifier
*/
-const char
-*tf_ident_2_str(enum tf_identifier_type id_type);
+const char *tf_ident_2_str(enum tf_identifier_type id_type);
/**
* Helper function converting tcam type to text string
+ *
+ * [in] tcam_type
+ * TCAM type
+ *
+ * Returns:
+ * Pointer to a char string holding the string for the tcam
*/
-const char
-*tf_tcam_tbl_2_str(enum tf_tcam_tbl_type tcam_type);
+const char *tf_tcam_tbl_2_str(enum tf_tcam_tbl_type tcam_type);
/**
* Helper function converting tbl type to text string
+ *
+ * [in] tbl_type
+ * Table type
+ *
+ * Returns:
+ * Pointer to a char string holding the string for the table type
*/
-const char
-*tf_tbl_type_2_str(enum tf_tbl_type tbl_type);
+const char *tf_tbl_type_2_str(enum tf_tbl_type tbl_type);
/**
* Helper function converting em tbl type to text string
+ *
+ * [in] em_type
+ * EM type
+ *
+ * Returns:
+ * Pointer to a char string holding the string for the EM type
*/
-const char
-*tf_em_tbl_type_2_str(enum tf_em_tbl_type em_type);
+const char *tf_em_tbl_type_2_str(enum tf_em_tbl_type em_type);
#endif /* _TF_UTIL_H_ */
(parms->nitems * parms->size),
parms->alignment);
if (parms->mem_va == NULL) {
- PMD_DRV_LOG(ERR, "Allocate failed mem_va\n");
+ TFP_DRV_LOG(ERR, "Allocate failed mem_va\n");
return -ENOMEM;
}
parms->mem_pa = (void *)((uintptr_t)rte_mem_virt2iova(parms->mem_va));
if (parms->mem_pa == (void *)((uintptr_t)RTE_BAD_IOVA)) {
- PMD_DRV_LOG(ERR, "Allocate failed mem_pa\n");
+ TFP_DRV_LOG(ERR, "Allocate failed mem_pa\n");
return -ENOMEM;
}