/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2019-2020 Broadcom
+ * Copyright(c) 2019-2021 Broadcom
* All rights reserved.
*/
#include "tf_tbl.h"
#include "tf_em.h"
#include "tf_rm.h"
+#include "tf_global_cfg.h"
#include "tf_msg.h"
#include "tfp.h"
#include "bitalloc.h"
#include "bnxt.h"
#include "rand.h"
-
-static inline uint32_t SWAP_WORDS32(uint32_t val32)
-{
- return (((val32 & 0x0000ffff) << 16) |
- ((val32 & 0xffff0000) >> 16));
-}
-
-static void tf_seeds_init(struct tf_session *session)
-{
- int i;
- uint32_t r;
-
- /* Initialize the lfsr */
- rand_init();
-
- /* RX and TX use the same seed values */
- session->lkup_lkup3_init_cfg[TF_DIR_RX] =
- session->lkup_lkup3_init_cfg[TF_DIR_TX] =
- SWAP_WORDS32(rand32());
-
- for (i = 0; i < TF_LKUP_SEED_MEM_SIZE / 2; i++) {
- r = SWAP_WORDS32(rand32());
- session->lkup_em_seed_mem[TF_DIR_RX][i * 2] = r;
- session->lkup_em_seed_mem[TF_DIR_TX][i * 2] = r;
- r = SWAP_WORDS32(rand32());
- session->lkup_em_seed_mem[TF_DIR_RX][i * 2 + 1] = (r & 0x1);
- session->lkup_em_seed_mem[TF_DIR_TX][i * 2 + 1] = (r & 0x1);
- }
-}
-
-/**
- * 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, 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);
-}
+#include "tf_common.h"
+#include "hwrm_tf.h"
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;
+ struct tf_session_open_session_parms oparms;
- if (tfp == NULL || parms == NULL)
- return -EINVAL;
+ 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
* firmware open session succeeds.
*/
- if (parms->device_type != TF_DEVICE_TYPE_WH)
+ if (parms->device_type != TF_DEVICE_TYPE_WH &&
+ parms->device_type != TF_DEVICE_TYPE_SR) {
+ TFP_DRV_LOG(ERR,
+ "Unsupported device type %d\n",
+ parms->device_type);
return -ENOTSUP;
+ }
- /* Build the beginning of session_id */
+ /* Verify control channel and build the beginning of session_id */
rc = sscanf(parms->ctrl_chan_name,
- "%x:%x:%x.%d",
+ "%x:%x:%x.%u",
&domain,
&bus,
&slot,
&device);
if (rc != 4) {
- PMD_DRV_LOG(ERR,
+ /* PCI Domain not provided (optional in DPDK), thus we
+ * force domain to 0 and recheck.
+ */
+ domain = 0;
+
+ /* Check parsing of bus/slot/device */
+ rc = sscanf(parms->ctrl_chan_name,
+ "%x:%x.%u",
+ &bus,
+ &slot,
+ &device);
+ if (rc != 3) {
+ TFP_DRV_LOG(ERR,
"Failed to scan device ctrl_chan_name\n");
- return -EINVAL;
+ 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)
- PMD_DRV_LOG(ERR,
- "Session is already open, rc:%d\n",
- rc);
- else
- PMD_DRV_LOG(ERR,
- "Open message send failed, rc:%d\n",
- rc);
+ parms->session_id.internal.domain = domain;
+ parms->session_id.internal.bus = bus;
+ parms->session_id.internal.device = device;
+ oparms.open_cfg = parms;
- parms->session_id.id = TF_FW_SESSION_ID_INVALID;
+ /* Session vs session client is decided in
+ * tf_session_open_session()
+ */
+ rc = tf_session_open_session(tfp, &oparms);
+ /* Logging handled by tf_session_open_session */
+ if (rc)
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 */
- PMD_DRV_LOG(ERR,
- "Failed to allocate session info, rc:%d\n",
- rc);
- goto cleanup;
- }
-
- tfp->session = 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 */
- PMD_DRV_LOG(ERR,
- "Failed to allocate session data, rc:%d\n",
- 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->device_type = parms->device_type;
- session->dev = NULL;
- tf_rm_init(tfp);
+ TFP_DRV_LOG(INFO,
+ "domain:%d, bus:%d, device:%u\n",
+ parms->session_id.internal.domain,
+ parms->session_id.internal.bus,
+ parms->session_id.internal.device);
- /* 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;
+ return 0;
+}
- rc = tf_msg_session_qcfg(tfp);
- if (rc) {
- /* Log error */
- PMD_DRV_LOG(ERR,
- "Query config message send failed, rc:%d\n",
- rc);
- goto cleanup_close;
- }
+int
+tf_attach_session(struct tf *tfp,
+ struct tf_attach_session_parms *parms)
+{
+ int rc;
+ unsigned int domain, bus, slot, device;
+ struct tf_session_attach_session_parms aparms;
- /* 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)
- PMD_DRV_LOG(ERR,
- "Shadow DB Initialization failed\n, rc:%d",
- rc);
- /* Add additional processing */
-#endif /* TF_SHADOW */
- }
+ TF_CHECK_PARMS2(tfp, parms);
- /* Adjust the Session with what firmware allowed us to get */
- rc = tf_rm_allocate_validate(tfp);
- if (rc) {
- /* Log error */
- goto cleanup_close;
+ /* Verify control channel */
+ rc = sscanf(parms->ctrl_chan_name,
+ "%x:%x:%x.%u",
+ &domain,
+ &bus,
+ &slot,
+ &device);
+ if (rc != 4) {
+ TFP_DRV_LOG(ERR,
+ "Failed to scan device ctrl_chan_name\n");
+ return -EINVAL;
}
- /* Setup hash seeds */
- tf_seeds_init(session);
-
- /* Initialize EM pool */
- for (dir = 0; dir < TF_DIR_MAX; dir++) {
- rc = tf_create_em_pool(session, dir, TF_SESSION_EM_POOL_SIZE);
- if (rc) {
- TFP_DRV_LOG(ERR,
- "EM Pool initialization failed\n");
- goto cleanup_close;
- }
+ /* Verify 'attach' channel */
+ rc = sscanf(parms->attach_chan_name,
+ "%x:%x:%x.%u",
+ &domain,
+ &bus,
+ &slot,
+ &device);
+ if (rc != 4) {
+ TFP_DRV_LOG(ERR,
+ "Failed to scan device attach_chan_name\n");
+ return -EINVAL;
}
- session->ref_count++;
-
- /* Return session ID */
- parms->session_id = session->session_id;
+ /* Prepare return value of session_id, using ctrl_chan_name
+ * device values as it becomes the session id.
+ */
+ parms->session_id.internal.domain = domain;
+ parms->session_id.internal.bus = bus;
+ parms->session_id.internal.device = device;
+ aparms.attach_cfg = parms;
+ rc = tf_session_attach_session(tfp,
+ &aparms);
+ /* Logging handled by dev_bind */
+ if (rc)
+ return rc;
- PMD_DRV_LOG(INFO,
- "Session created, session_id:%d\n",
+ TFP_DRV_LOG(INFO,
+ "Attached to session, session_id:%d\n",
parms->session_id.id);
- PMD_DRV_LOG(INFO,
+ 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_attach_session(struct tf *tfp __rte_unused,
- struct tf_attach_session_parms *parms __rte_unused)
-{
-#if (TF_SHARED == 1)
- int rc;
-
- if (tfp == NULL)
- return -EINVAL;
-
- /* - 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) {
- 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_close_session(struct tf *tfp)
{
int rc;
- int rc_close = 0;
- struct tf_session *tfs;
- union tf_session_id session_id;
- int dir;
-
- if (tfp == NULL || tfp->session == NULL)
- return -EINVAL;
-
- 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 */
- PMD_DRV_LOG(ERR,
- "Message send failed, rc:%d\n",
- rc);
- }
-
- /* Update the ref_count */
- tfs->ref_count--;
- }
-
- session_id = tfs->session_id;
+ struct tf_session_close_session_parms cparms = { 0 };
+ union tf_session_id session_id = { 0 };
+ uint8_t ref_count;
- /* 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, dir);
+ TF_CHECK_PARMS1(tfp);
- tfp_free(tfp->session->core_data);
- tfp_free(tfp->session);
- tfp->session = NULL;
- }
-
- PMD_DRV_LOG(INFO,
- "Session closed, session_id:%d\n",
- session_id.id);
+ cparms.ref_count = &ref_count;
+ cparms.session_id = &session_id;
+ /* Session vs session client is decided in
+ * tf_session_close_session()
+ */
+ rc = tf_session_close_session(tfp,
+ &cparms);
+ /* Logging handled by tf_session_close_session */
+ if (rc)
+ return rc;
- PMD_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);
+ TFP_DRV_LOG(INFO,
+ "domain:%d, bus:%d, device:%d\n",
+ cparms.session_id->internal.domain,
+ cparms.session_id->internal.bus,
+ cparms.session_id->internal.device);
- return rc_close;
+ return rc;
}
/** insert EM hash entry API
int tf_insert_em_entry(struct tf *tfp,
struct tf_insert_em_entry_parms *parms)
{
- struct tf_tbl_scope_cb *tbl_scope_cb;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ int rc;
- if (tfp == NULL || parms == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(tfp, 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;
+ }
- tbl_scope_cb = tbl_scope_cb_find((struct tf_session *)
- (tfp->session->core_data),
- parms->tbl_scope_id);
- if (tbl_scope_cb == NULL)
+ if (parms->mem == TF_MEM_EXTERNAL &&
+ dev->ops->tf_dev_insert_ext_em_entry != NULL)
+ rc = dev->ops->tf_dev_insert_ext_em_entry(tfp, parms);
+ else if (parms->mem == TF_MEM_INTERNAL &&
+ dev->ops->tf_dev_insert_int_em_entry != NULL)
+ rc = dev->ops->tf_dev_insert_int_em_entry(tfp, parms);
+ else
return -EINVAL;
- /* Process the EM entry per Table Scope type */
- if (parms->mem == TF_MEM_EXTERNAL) {
- /* External EEM */
- return tf_insert_eem_entry((struct tf_session *)
- (tfp->session->core_data),
- tbl_scope_cb,
- parms);
- } else if (parms->mem == TF_MEM_INTERNAL) {
- /* Internal EM */
- return tf_insert_em_internal_entry(tfp, parms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: EM insert failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
}
- return -EINVAL;
+ return 0;
}
/** Delete EM hash entry API
int tf_delete_em_entry(struct tf *tfp,
struct tf_delete_em_entry_parms *parms)
{
- struct tf_tbl_scope_cb *tbl_scope_cb;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ int rc;
- if (tfp == NULL || parms == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(tfp, parms);
- tbl_scope_cb = tbl_scope_cb_find((struct tf_session *)
- (tfp->session->core_data),
- parms->tbl_scope_id);
- if (tbl_scope_cb == NULL)
- return -EINVAL;
+ /* 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 (parms->mem == TF_MEM_EXTERNAL)
- return tf_delete_eem_entry(tfp, parms);
+ rc = dev->ops->tf_dev_delete_ext_em_entry(tfp, parms);
+ else if (parms->mem == TF_MEM_INTERNAL)
+ rc = dev->ops->tf_dev_delete_int_em_entry(tfp, parms);
else
- return tf_delete_em_internal_entry(tfp, parms);
+ return -EINVAL;
+
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: EM delete failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return rc;
}
-/** allocate identifier resource
+/** Get global configuration API
*
- * Returns success or failure code.
+ * returns:
+ * 0 - Success
+ * -EINVAL - Error
*/
-int tf_alloc_identifier(struct tf *tfp,
- struct tf_alloc_identifier_parms *parms)
+int tf_get_global_cfg(struct tf *tfp,
+ struct tf_global_cfg_parms *parms)
{
- struct bitalloc *session_pool;
+ int rc = 0;
struct tf_session *tfs;
- int id;
- int rc;
+ struct tf_dev_info *dev;
- if (parms == NULL || tfp == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(tfp, 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 (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR, "%s: session error\n",
- tf_dir_2_str(parms->dir));
+ if (parms->config == NULL ||
+ parms->config_sz_in_bytes == 0) {
+ TFP_DRV_LOG(ERR, "Invalid Argument(s)\n");
return -EINVAL;
}
- 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:
- PMD_DRV_LOG(ERR, "%s: unsupported %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
+ if (dev->ops->tf_dev_get_global_cfg == NULL) {
rc = -EOPNOTSUPP;
- break;
- default:
- PMD_DRV_LOG(ERR, "%s: %s\n",
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EINVAL;
- break;
+ strerror(-rc));
+ return -EOPNOTSUPP;
}
+ rc = dev->ops->tf_dev_get_global_cfg(tfp, parms);
if (rc) {
- PMD_DRV_LOG(ERR, "%s: identifier pool %s failure\n",
+ TFP_DRV_LOG(ERR,
+ "%s: Global Cfg get failed, 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) {
- PMD_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;
+ return rc;
}
-/** free identifier resource
+/** Set global configuration API
*
- * Returns success or failure code.
+ * returns:
+ * 0 - Success
+ * -EINVAL - Error
*/
-int tf_free_identifier(struct tf *tfp,
- struct tf_free_identifier_parms *parms)
+int tf_set_global_cfg(struct tf *tfp,
+ struct tf_global_cfg_parms *parms)
{
- struct bitalloc *session_pool;
- int rc;
- int ba_rc;
+ int rc = 0;
struct tf_session *tfs;
+ struct tf_dev_info *dev;
- if (parms == NULL || tfp == NULL)
- return -EINVAL;
-
- if (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR, "%s: Session error\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
+ TF_CHECK_PARMS2(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:
- PMD_DRV_LOG(ERR, "%s: unsupported %s\n",
- tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type));
- rc = -EOPNOTSUPP;
- break;
- default:
- PMD_DRV_LOG(ERR, "%s: invalid %s\n",
+ /* 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),
- tf_ident_2_str(parms->ident_type));
- rc = -EINVAL;
- break;
+ strerror(-rc));
+ return rc;
}
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
if (rc) {
- PMD_DRV_LOG(ERR, "%s: %s Identifier pool access failed\n",
+ TFP_DRV_LOG(ERR,
+ "%s: Failed to lookup device, 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 (parms->config == NULL ||
+ parms->config_sz_in_bytes == 0) {
+ TFP_DRV_LOG(ERR, "Invalid Argument(s)\n");
+ return -EINVAL;
+ }
- if (ba_rc == BA_FAIL || ba_rc == BA_ENTRY_FREE) {
- PMD_DRV_LOG(ERR, "%s: %s: Entry %d already free",
+ if (dev->ops->tf_dev_set_global_cfg == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
tf_dir_2_str(parms->dir),
- tf_ident_2_str(parms->ident_type),
- parms->id);
- return -EINVAL;
+ strerror(-rc));
+ return -EOPNOTSUPP;
}
- ba_free(session_pool, (int)parms->id);
+ rc = dev->ops->tf_dev_set_global_cfg(tfp, parms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Global Cfg set failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
- return 0;
+ return rc;
}
int
-tf_alloc_tcam_entry(struct tf *tfp,
- struct tf_alloc_tcam_entry_parms *parms)
+tf_alloc_identifier(struct tf *tfp,
+ struct tf_alloc_identifier_parms *parms)
{
int rc;
- int index;
struct tf_session *tfs;
- struct bitalloc *session_pool;
+ struct tf_dev_info *dev;
+ struct tf_ident_alloc_parms aparms;
+ uint16_t id;
- if (parms == NULL || tfp == NULL)
- return -EINVAL;
+ TF_CHECK_PARMS2(tfp, parms);
- if (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR, "%s: session error\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
- }
+ /* Can't do static initialization due to UT enum check */
+ memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
- tfs = (struct tf_session *)(tfp->session->core_data);
+ /* 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;
+ }
- rc = tf_rm_lookup_tcam_type_pool(tfs,
- parms->dir,
- parms->tcam_tbl_type,
- &session_pool);
- /* Error logging handled by tf_rm_lookup_tcam_type_pool */
- if (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_ident == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return -EOPNOTSUPP;
+ }
- index = ba_alloc(session_pool);
- if (index == BA_FAIL) {
- PMD_DRV_LOG(ERR, "%s: %s: No resource available\n",
+ aparms.dir = parms->dir;
+ aparms.type = parms->ident_type;
+ aparms.id = &id;
+ rc = dev->ops->tf_dev_alloc_ident(tfp, &aparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Identifier allocation failed, rc:%s\n",
tf_dir_2_str(parms->dir),
- tf_tcam_tbl_2_str(parms->tcam_tbl_type));
- return -ENOMEM;
+ strerror(-rc));
+ return rc;
}
- parms->idx = index;
+ parms->id = id;
+
return 0;
}
int
-tf_set_tcam_entry(struct tf *tfp,
- struct tf_set_tcam_entry_parms *parms)
+tf_free_identifier(struct tf *tfp,
+ struct tf_free_identifier_parms *parms)
{
int rc;
- int id;
struct tf_session *tfs;
- struct bitalloc *session_pool;
+ struct tf_dev_info *dev;
+ struct tf_ident_free_parms fparms;
- if (tfp == NULL || parms == NULL) {
- PMD_DRV_LOG(ERR, "Invalid parameters\n");
- return -EINVAL;
- }
+ TF_CHECK_PARMS2(tfp, parms);
- if (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR,
- "%s, Session info invalid\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
+ /* Can't do static initialization due to UT enum check */
+ memset(&fparms, 0, sizeof(struct tf_ident_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_ident == 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->ident_type;
+ fparms.id = parms->id;
+ fparms.ref_cnt = &parms->ref_cnt;
+ rc = dev->ops->tf_dev_free_ident(tfp, &fparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Identifier free failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+tf_search_identifier(struct tf *tfp,
+ struct tf_search_identifier_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_ident_search_parms sparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&sparms, 0, sizeof(struct tf_ident_search_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_search_ident == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ sparms.dir = parms->dir;
+ sparms.type = parms->ident_type;
+ sparms.search_id = parms->search_id;
+ sparms.hit = &parms->hit;
+ sparms.ref_cnt = &parms->ref_cnt;
+ rc = dev->ops->tf_dev_search_ident(tfp, &sparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Identifier search failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+tf_search_tcam_entry(struct tf *tfp,
+ struct tf_search_tcam_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tcam_alloc_search_parms sparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ memset(&sparms, 0, sizeof(struct tf_tcam_alloc_search_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_search_tcam == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ sparms.dir = parms->dir;
+ sparms.type = parms->tcam_tbl_type;
+ sparms.key = parms->key;
+ sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
+ sparms.mask = parms->mask;
+ sparms.priority = parms->priority;
+ sparms.alloc = parms->alloc;
+
+ /* Result is an in/out and so no need to copy during outputs */
+ sparms.result = parms->result;
+ sparms.result_size =
+ TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
+
+ rc = dev->ops->tf_dev_alloc_search_tcam(tfp, &sparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: TCAM allocation failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Copy the outputs */
+ parms->hit = sparms.hit;
+ parms->search_status = sparms.search_status;
+ parms->ref_cnt = sparms.ref_cnt;
+ parms->idx = sparms.idx;
+
+ return 0;
+}
+
+int
+tf_alloc_tcam_entry(struct tf *tfp,
+ struct tf_alloc_tcam_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tcam_alloc_parms aparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ memset(&aparms, 0, sizeof(struct tf_tcam_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_tcam == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ aparms.dir = parms->dir;
+ aparms.type = parms->tcam_tbl_type;
+ aparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
+ aparms.priority = parms->priority;
+ rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: TCAM allocation failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ parms->idx = aparms.idx;
+
+ return 0;
+}
+
+int
+tf_set_tcam_entry(struct tf *tfp,
+ struct tf_set_tcam_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tcam_set_parms sparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ memset(&sparms, 0, sizeof(struct tf_tcam_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_tcam == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ sparms.dir = parms->dir;
+ sparms.type = parms->tcam_tbl_type;
+ sparms.idx = parms->idx;
+ sparms.key = parms->key;
+ sparms.mask = parms->mask;
+ sparms.key_size = TF_BITS2BYTES_WORD_ALIGN(parms->key_sz_in_bits);
+ sparms.result = parms->result;
+ sparms.result_size = TF_BITS2BYTES_WORD_ALIGN(parms->result_sz_in_bits);
+
+ rc = dev->ops->tf_dev_set_tcam(tfp, &sparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: TCAM set failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return 0;
+}
+
+int
+tf_get_tcam_entry(struct tf *tfp __rte_unused,
+ struct tf_get_tcam_entry_parms *parms __rte_unused)
+{
+ TF_CHECK_PARMS2(tfp, parms);
+ return -EOPNOTSUPP;
+}
+
+int
+tf_free_tcam_entry(struct tf *tfp,
+ struct tf_free_tcam_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tcam_free_parms fparms;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ memset(&fparms, 0, sizeof(struct tf_tcam_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_tcam == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ fparms.dir = parms->dir;
+ fparms.type = parms->tcam_tbl_type;
+ fparms.idx = parms->idx;
+ rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: TCAM 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;
+ }
+
+ aparms.dir = parms->dir;
+ aparms.type = parms->type;
+ aparms.idx = &idx;
+ aparms.tbl_scope_id = parms->tbl_scope_id;
+
+ if (parms->type == TF_TBL_TYPE_EXT) {
+ if (dev->ops->tf_dev_alloc_ext_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;
+ }
+
+ rc = dev->ops->tf_dev_alloc_ext_tbl(tfp, &aparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: External table allocation failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ } else {
+ 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;
+ }
+
+ 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_search_tbl_entry(struct tf *tfp,
+ struct tf_search_tbl_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_alloc_search_parms sparms;
+
+ TF_CHECK_PARMS2(tfp, 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_search_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ memset(&sparms, 0, sizeof(struct tf_tbl_alloc_search_parms));
+ sparms.dir = parms->dir;
+ sparms.type = parms->type;
+ sparms.result = parms->result;
+ sparms.result_sz_in_bytes = parms->result_sz_in_bytes;
+ sparms.alloc = parms->alloc;
+ sparms.tbl_scope_id = parms->tbl_scope_id;
+ rc = dev->ops->tf_dev_alloc_search_tbl(tfp, &sparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: TBL allocation failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Return the outputs from the search */
+ parms->hit = sparms.hit;
+ parms->search_status = sparms.search_status;
+ parms->ref_cnt = sparms.ref_cnt;
+ parms->idx = sparms.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;
}
- tfs = (struct tf_session *)(tfp->session->core_data);
+ fparms.dir = parms->dir;
+ fparms.type = parms->type;
+ fparms.idx = parms->idx;
+ fparms.tbl_scope_id = parms->tbl_scope_id;
- /*
- * Each tcam send msg function should check for key sizes range
- */
+ if (parms->type == TF_TBL_TYPE_EXT) {
+ if (dev->ops->tf_dev_free_ext_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;
+ }
- rc = tf_rm_lookup_tcam_type_pool(tfs,
- parms->dir,
- parms->tcam_tbl_type,
- &session_pool);
- /* Error logging handled by tf_rm_lookup_tcam_type_pool */
- if (rc)
+ rc = dev->ops->tf_dev_free_ext_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;
+ }
+ } else {
+ 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;
+ }
+
+ 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;
+ }
+ 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;
+ sparms.tbl_scope_id = parms->tbl_scope_id;
- /* Verify that the entry has been previously allocated */
- id = ba_inuse(session_pool, parms->idx);
- if (id != 1) {
- PMD_DRV_LOG(ERR,
- "%s: %s: Invalid or not allocated index, idx:%d\n",
- tf_dir_2_str(parms->dir),
- tf_tcam_tbl_2_str(parms->tcam_tbl_type),
- parms->idx);
- return -EINVAL;
+ if (parms->type == TF_TBL_TYPE_EXT) {
+ if (dev->ops->tf_dev_set_ext_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;
+ }
+
+ rc = dev->ops->tf_dev_set_ext_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;
+ }
+ } else {
+ 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;
+ }
+
+ 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;
}
- rc = tf_msg_tcam_entry_set(tfp, parms);
+ 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;
}
int
-tf_get_tcam_entry(struct tf *tfp __rte_unused,
- struct tf_get_tcam_entry_parms *parms __rte_unused)
+tf_bulk_get_tbl_entry(struct tf *tfp,
+ struct tf_bulk_get_tbl_entry_parms *parms)
{
- int rc = -EOPNOTSUPP;
+ int rc = 0;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_tbl_get_bulk_parms bparms;
- if (tfp == NULL || parms == NULL) {
- PMD_DRV_LOG(ERR, "Invalid parameters\n");
- return -EINVAL;
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Can't do static initialization due to UT enum check */
+ memset(&bparms, 0, sizeof(struct tf_tbl_get_bulk_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;
}
- if (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR,
- "%s, Session info invalid\n",
- tf_dir_2_str(parms->dir));
- return -EINVAL;
+ /* 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 (parms->type == TF_TBL_TYPE_EXT) {
+ /* Not supported, yet */
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s, External table type not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+
+ return rc;
+ }
+
+ /* Internal table type processing */
+
+ if (dev->ops->tf_dev_get_bulk_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;
+ }
+
+ bparms.dir = parms->dir;
+ bparms.type = parms->type;
+ bparms.starting_idx = parms->starting_idx;
+ bparms.num_entries = parms->num_entries;
+ bparms.entry_sz_in_bytes = parms->entry_sz_in_bytes;
+ bparms.physical_mem_addr = parms->physical_mem_addr;
+ rc = dev->ops->tf_dev_get_bulk_tbl(tfp, &bparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Table get bulk failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
}
return rc;
}
int
-tf_free_tcam_entry(struct tf *tfp,
- struct tf_free_tcam_entry_parms *parms)
+tf_alloc_tbl_scope(struct tf *tfp,
+ struct tf_alloc_tbl_scope_parms *parms)
{
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
int rc;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ if (dev->ops->tf_dev_alloc_tbl_scope != NULL) {
+ rc = dev->ops->tf_dev_alloc_tbl_scope(tfp, parms);
+ } else {
+ TFP_DRV_LOG(ERR,
+ "Alloc table scope not supported by device\n");
+ return -EINVAL;
+ }
+
+ return rc;
+}
+int
+tf_map_tbl_scope(struct tf *tfp,
+ struct tf_map_tbl_scope_parms *parms)
+{
struct tf_session *tfs;
- struct bitalloc *session_pool;
+ struct tf_dev_info *dev;
+ int rc;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
- if (parms == NULL || tfp == NULL)
+ if (dev->ops->tf_dev_map_tbl_scope != NULL) {
+ rc = dev->ops->tf_dev_map_tbl_scope(tfp, parms);
+ } else {
+ TFP_DRV_LOG(ERR,
+ "Map table scope not supported by device\n");
return -EINVAL;
+ }
+
+ return rc;
+}
+
+int
+tf_free_tbl_scope(struct tf *tfp,
+ struct tf_free_tbl_scope_parms *parms)
+{
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ int rc;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session(tfp, &tfs);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup session, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
+
+ /* Retrieve the device information */
+ rc = tf_session_get_device(tfs, &dev);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "Failed to lookup device, rc:%s\n",
+ strerror(-rc));
+ return rc;
+ }
- if (tfp->session == NULL || tfp->session->core_data == NULL) {
- PMD_DRV_LOG(ERR, "%s: Session error\n",
- tf_dir_2_str(parms->dir));
+ if (dev->ops->tf_dev_free_tbl_scope) {
+ rc = dev->ops->tf_dev_free_tbl_scope(tfp, parms);
+ } else {
+ TFP_DRV_LOG(ERR,
+ "Free table scope not supported by device\n");
return -EINVAL;
}
- tfs = (struct tf_session *)(tfp->session->core_data);
+ return rc;
+}
- rc = tf_rm_lookup_tcam_type_pool(tfs,
- parms->dir,
- parms->tcam_tbl_type,
- &session_pool);
- /* Error logging handled by tf_rm_lookup_tcam_type_pool */
- if (rc)
+int
+tf_set_if_tbl_entry(struct tf *tfp,
+ struct tf_set_if_tbl_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_if_tbl_set_parms sparms = { 0 };
+
+ TF_CHECK_PARMS2(tfp, 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;
+ }
- rc = ba_inuse(session_pool, (int)parms->idx);
- if (rc == BA_FAIL || rc == BA_ENTRY_FREE) {
- PMD_DRV_LOG(ERR, "%s: %s: Entry %d already free",
+ if (dev->ops->tf_dev_set_if_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
tf_dir_2_str(parms->dir),
- tf_tcam_tbl_2_str(parms->tcam_tbl_type),
- parms->idx);
- return -EINVAL;
+ strerror(-rc));
+ return rc;
}
- ba_free(session_pool, (int)parms->idx);
+ sparms.dir = parms->dir;
+ sparms.type = parms->type;
+ sparms.idx = parms->idx;
+ sparms.data_sz_in_bytes = parms->data_sz_in_bytes;
+ sparms.data = parms->data;
- rc = tf_msg_tcam_entry_free(tfp, parms);
+ rc = dev->ops->tf_dev_set_if_tbl(tfp, &sparms);
if (rc) {
- /* Log error */
- PMD_DRV_LOG(ERR, "%s: %s: Entry %d free failed",
+ TFP_DRV_LOG(ERR,
+ "%s: If_tbl set failed, rc:%s\n",
tf_dir_2_str(parms->dir),
- tf_tcam_tbl_2_str(parms->tcam_tbl_type),
- parms->idx);
+ strerror(-rc));
+ return rc;
}
- return rc;
+ return 0;
+}
+
+int
+tf_get_if_tbl_entry(struct tf *tfp,
+ struct tf_get_if_tbl_entry_parms *parms)
+{
+ int rc;
+ struct tf_session *tfs;
+ struct tf_dev_info *dev;
+ struct tf_if_tbl_get_parms gparms = { 0 };
+
+ TF_CHECK_PARMS2(tfp, 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_if_tbl == NULL) {
+ rc = -EOPNOTSUPP;
+ TFP_DRV_LOG(ERR,
+ "%s: Operation not supported, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ gparms.dir = parms->dir;
+ gparms.type = parms->type;
+ gparms.idx = parms->idx;
+ gparms.data_sz_in_bytes = parms->data_sz_in_bytes;
+ gparms.data = parms->data;
+
+ rc = dev->ops->tf_dev_get_if_tbl(tfp, &gparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: If_tbl get failed, rc:%s\n",
+ tf_dir_2_str(parms->dir),
+ strerror(-rc));
+ return rc;
+ }
+
+ return 0;
}