net/bnxt: update RM to support HCAPI only
[dpdk.git] / drivers / net / bnxt / tf_core / tf_core.c
index f26bf28..8727900 100644 (file)
@@ -6,35 +6,88 @@
 #include <stdio.h>
 
 #include "tf_core.h"
+#include "tf_util.h"
 #include "tf_session.h"
+#include "tf_tbl.h"
+#include "tf_em.h"
 #include "tf_rm.h"
 #include "tf_msg.h"
 #include "tfp.h"
 #include "bitalloc.h"
 #include "bnxt.h"
 #include "rand.h"
+#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;
+       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) {
+               TFP_DRV_LOG(ERR,
+                           "Unsupported device type %d\n",
+                           parms->device_type);
                return -ENOTSUP;
+       }
+
+       /* Verify control channel and 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;
+       }
+
+       parms->session_id.internal.domain = domain;
+       parms->session_id.internal.bus = bus;
+       parms->session_id.internal.device = device;
+       oparms.open_cfg = parms;
+
+       rc = tf_session_open_session(tfp, &oparms);
+       /* Logging handled by tf_session_open_session */
+       if (rc)
+               return rc;
+
+       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;
+}
+
+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;
+
+       TF_CHECK_PARMS2(tfp, parms);
 
-       /* Build the beginning of session_id */
+       /* Verify control channel */
        rc = sscanf(parms->ctrl_chan_name,
                    "%x:%x:%x.%d",
                    &domain,
@@ -42,185 +95,880 @@ tf_open_session(struct tf                    *tfp,
                    &slot,
                    &device);
        if (rc != 4) {
-               PMD_DRV_LOG(ERR,
+               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);
+       /* Verify 'attach' channel */
+       rc = sscanf(parms->attach_chan_name,
+                   "%x:%x:%x.%d",
+                   &domain,
+                   &bus,
+                   &slot,
+                   &device);
+       if (rc != 4) {
+               TFP_DRV_LOG(ERR,
+                           "Failed to scan device attach_chan_name\n");
+               return -EINVAL;
+       }
+
+       /* 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;
+
+       TFP_DRV_LOG(INFO,
+                   "Attached to session, 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 rc;
+}
+
+int
+tf_close_session(struct tf *tfp)
+{
+       int rc;
+       struct tf_session_close_session_parms cparms = { 0 };
+       union tf_session_id session_id = { 0 };
+       uint8_t ref_count;
+
+       TF_CHECK_PARMS1(tfp);
+
+       cparms.ref_count = &ref_count;
+       cparms.session_id = &session_id;
+       rc = tf_session_close_session(tfp,
+                                     &cparms);
+       /* Logging handled by tf_session_close_session */
+       if (rc)
+               return rc;
+
+       TFP_DRV_LOG(INFO,
+                   "Closed session, session_id:%d, ref_count:%d\n",
+                   cparms.session_id->id,
+                   *cparms.ref_count);
+
+       TFP_DRV_LOG(INFO,
+                   "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
+                   cparms.session_id->internal.domain,
+                   cparms.session_id->internal.bus,
+                   cparms.session_id->internal.device,
+                   cparms.session_id->internal.fw_session_id);
+
+       return rc;
+}
+
+/** insert EM hash entry API
+ *
+ *    returns:
+ *    0       - Success
+ *    -EINVAL - Error
+ */
+int tf_insert_em_entry(struct tf *tfp,
+                      struct tf_insert_em_entry_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) {
-               /* 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);
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed to lookup session, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
+       }
 
-               parms->session_id.id = TF_FW_SESSION_ID_INVALID;
+       /* 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;
        }
 
-       /* Allocate session */
-       alloc_parms.nitems = 1;
-       alloc_parms.size = sizeof(struct tf_session_info);
-       alloc_parms.alignment = 0;
-       rc = tfp_calloc(&alloc_parms);
+       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;
+
        if (rc) {
-               /* Log error */
-               PMD_DRV_LOG(ERR,
-                           "Failed to allocate session info, rc:%d\n",
-                           rc);
-               goto cleanup;
+               TFP_DRV_LOG(ERR,
+                           "%s: EM insert failed, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
        }
 
-       tfp->session = (struct tf_session_info *)alloc_parms.mem_va;
+       return 0;
+}
+
+/** Delete EM hash entry API
+ *
+ *    returns:
+ *    0       - Success
+ *    -EINVAL - Error
+ */
+int tf_delete_em_entry(struct tf *tfp,
+                      struct tf_delete_em_entry_parms *parms)
+{
+       struct tf_session      *tfs;
+       struct tf_dev_info     *dev;
+       int rc;
 
-       /* 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);
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session(tfp, &tfs);
        if (rc) {
-               /* Log error */
-               PMD_DRV_LOG(ERR,
-                           "Failed to allocate session data, rc:%d\n",
-                           rc);
-               goto cleanup;
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed to lookup session, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
        }
 
-       tfp->session->core_data = alloc_parms.mem_va;
+       /* 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;
+       }
 
-       session = (struct tf_session *)tfp->session->core_data;
-       tfp_memcpy(session->ctrl_chan_name,
-                  parms->ctrl_chan_name,
-                  TF_SESSION_NAME_MAX);
+       if (parms->mem == TF_MEM_EXTERNAL)
+               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 -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;
+}
 
-       /* Initialize Session */
-       session->device_type = parms->device_type;
+int
+tf_alloc_identifier(struct tf *tfp,
+                   struct tf_alloc_identifier_parms *parms)
+{
+       int rc;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       struct tf_ident_alloc_parms aparms;
+       uint16_t id;
 
-       /* 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;
+       TF_CHECK_PARMS2(tfp, parms);
 
-       rc = tf_msg_session_qcfg(tfp);
+       /* Can't do static initialization due to UT enum check */
+       memset(&aparms, 0, sizeof(struct tf_ident_alloc_parms));
+
+       /* Retrieve the session information */
+       rc = tf_session_get_session(tfp, &tfs);
        if (rc) {
-               /* Log error */
-               PMD_DRV_LOG(ERR,
-                           "Query config message send failed, rc:%d\n",
-                           rc);
-               goto cleanup_close;
+               TFP_DRV_LOG(ERR,
+                           "%s: Failed to lookup session, rc:%s\n",
+                           tf_dir_2_str(parms->dir),
+                           strerror(-rc));
+               return rc;
        }
 
-       session->ref_count++;
+       /* 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;
+       }
 
-       /* Return session ID */
-       parms->session_id = session->session_id;
+       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;
+       }
 
-       PMD_DRV_LOG(INFO,
-                   "Session created, session_id:%d\n",
-                   parms->session_id.id);
+       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),
+                           strerror(-rc));
+               return rc;
+       }
 
-       PMD_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);
+       parms->id = id;
 
        return 0;
+}
 
- cleanup:
-       tfp_free(tfp->session->core_data);
-       tfp_free(tfp->session);
-       tfp->session = NULL;
-       return rc;
+int
+tf_free_identifier(struct tf *tfp,
+                  struct tf_free_identifier_parms *parms)
+{
+       int rc;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       struct tf_ident_free_parms fparms;
+
+       TF_CHECK_PARMS2(tfp, parms);
+
+       /* 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;
+       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;
+       }
 
- cleanup_close:
-       tf_close_session(tfp);
-       return -EINVAL;
+       return 0;
 }
 
 int
-tf_attach_session(struct tf *tfp __rte_unused,
-                 struct tf_attach_session_parms *parms __rte_unused)
+tf_alloc_tcam_entry(struct tf *tfp,
+                   struct tf_alloc_tcam_entry_parms *parms)
 {
-#if (TF_SHARED == 1)
        int rc;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       struct tf_tcam_alloc_parms aparms = { 0 };
 
-       if (tfp == NULL)
-               return -EINVAL;
+       TF_CHECK_PARMS2(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.
-        */
+       /* 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) {
-               if (tfp->session->session_id.id != TF_SESSION_ID_INVALID) {
-                       rc = tf_msg_session_attach(tfp,
-                                                  parms->ctrl_chan_name,
-                                                  parms->session_id);
-               }
+       /* 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;
        }
-#endif /* TF_SHARED */
-       return -1;
+
+       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_close_session(struct tf *tfp)
+tf_set_tcam_entry(struct tf *tfp,
+                 struct tf_set_tcam_entry_parms *parms)
 {
        int rc;
-       int rc_close = 0;
        struct tf_session *tfs;
-       union tf_session_id session_id;
+       struct tf_dev_info *dev;
+       struct tf_tcam_set_parms sparms = { 0 };
 
-       if (tfp == NULL || tfp->session == NULL)
-               return -EINVAL;
+       TF_CHECK_PARMS2(tfp, 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;
+       }
 
-       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);
-               }
+       /* 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;
+       }
 
-               /* Update the ref_count */
-               tfs->ref_count--;
+       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;
        }
 
-       session_id = tfs->session_id;
+       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);
 
-       /* Final cleanup as we're last user of the session */
-       if (tfs->ref_count == 0) {
-               tfp_free(tfp->session->core_data);
-               tfp_free(tfp->session);
-               tfp->session = NULL;
+       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;
        }
 
-       PMD_DRV_LOG(INFO,
-                   "Session closed, session_id:%d\n",
-                   session_id.id);
+       return 0;
+}
 
-       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);
+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 = { 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_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 allocation 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;
+       }
 
-       return rc_close;
+       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;
+}
+
+int
+tf_bulk_get_tbl_entry(struct tf *tfp,
+                struct tf_bulk_get_tbl_entry_parms *parms)
+{
+       int rc = 0;
+       struct tf_session *tfs;
+       struct tf_dev_info *dev;
+       struct tf_tbl_get_bulk_parms bparms;
+
+       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;
+       }
+
+       /* 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_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_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 (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;
+       }
+
+       return rc;
 }