@@ -16,9 +16,6 @@
struct tf;
-/* Number of slices per row for WC TCAM */
-uint16_t g_wc_num_slices_per_row = TF_WC_TCAM_1_SLICE_PER_ROW;
-
/* Forward declarations */
static int tf_dev_unbind_p4(struct tf *tfp);
static int tf_dev_unbind_p58(struct tf *tfp);
@@ -239,14 +239,22 @@ tf_dev_p4_get_resource_str(struct tf *tfp __rte_unused,
* - (-EINVAL) on failure.
*/
static int
-tf_dev_p4_set_tcam_slice_info(struct tf *tfp __rte_unused,
+tf_dev_p4_set_tcam_slice_info(struct tf *tfp,
enum tf_wc_num_slice num_slices_per_row)
{
+ int rc;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
switch (num_slices_per_row) {
case TF_WC_TCAM_1_SLICE_PER_ROW:
case TF_WC_TCAM_2_SLICE_PER_ROW:
case TF_WC_TCAM_4_SLICE_PER_ROW:
- g_wc_num_slices_per_row = num_slices_per_row;
+ tfs->wc_num_slices_per_row = num_slices_per_row;
break;
default:
return -EINVAL;
@@ -276,16 +284,24 @@ tf_dev_p4_set_tcam_slice_info(struct tf *tfp __rte_unused,
* - (-EINVAL) on failure.
*/
static int
-tf_dev_p4_get_tcam_slice_info(struct tf *tfp __rte_unused,
+tf_dev_p4_get_tcam_slice_info(struct tf *tfp,
enum tf_tcam_tbl_type type,
uint16_t key_sz,
uint16_t *num_slices_per_row)
{
+ int rc;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
/* Single slice support */
#define CFA_P4_WC_TCAM_SLICE_SIZE 12
if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
- *num_slices_per_row = g_wc_num_slices_per_row;
+ *num_slices_per_row = tfs->wc_num_slices_per_row;
if (key_sz > *num_slices_per_row * CFA_P4_WC_TCAM_SLICE_SIZE)
return -ENOTSUP;
} else { /* for other type of tcam */
@@ -350,14 +350,22 @@ tf_dev_p58_get_resource_str(struct tf *tfp __rte_unused,
* - (-EINVAL) on failure.
*/
static int
-tf_dev_p58_set_tcam_slice_info(struct tf *tfp __rte_unused,
+tf_dev_p58_set_tcam_slice_info(struct tf *tfp,
enum tf_wc_num_slice num_slices_per_row)
{
+ int rc;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
switch (num_slices_per_row) {
case TF_WC_TCAM_1_SLICE_PER_ROW:
case TF_WC_TCAM_2_SLICE_PER_ROW:
case TF_WC_TCAM_4_SLICE_PER_ROW:
- g_wc_num_slices_per_row = num_slices_per_row;
+ tfs->wc_num_slices_per_row = num_slices_per_row;
break;
default:
return -EINVAL;
@@ -387,14 +395,22 @@ tf_dev_p58_set_tcam_slice_info(struct tf *tfp __rte_unused,
* - (-EINVAL) on failure.
*/
static int
-tf_dev_p58_get_tcam_slice_info(struct tf *tfp __rte_unused,
+tf_dev_p58_get_tcam_slice_info(struct tf *tfp,
enum tf_tcam_tbl_type type,
uint16_t key_sz,
uint16_t *num_slices_per_row)
{
+ int rc;
+ struct tf_session *tfs;
+
+ /* Retrieve the session information */
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
#define CFA_P58_WC_TCAM_SLICE_SIZE 24
if (type == TF_TCAM_TBL_TYPE_WC_TCAM) {
- *num_slices_per_row = g_wc_num_slices_per_row;
+ *num_slices_per_row = tfs->wc_num_slices_per_row;
if (key_sz > *num_slices_per_row * CFA_P58_WC_TCAM_SLICE_SIZE)
return -ENOTSUP;
} else { /* for other type of tcam */
@@ -12,10 +12,13 @@
#include "tfp.h"
struct tf;
+
/**
- * Global Cfg DBs.
+ * Global cfg database
*/
-static void *global_cfg_db[TF_DIR_MAX];
+struct tf_global_cfg_db {
+ struct tf_global_cfg_cfg *global_cfg_db[TF_DIR_MAX];
+};
/**
* Init flag, set on bind and cleared on unbind
@@ -72,40 +75,62 @@ tf_global_cfg_get_hcapi_type(struct tf_global_cfg_get_hcapi_parms *parms)
}
int
-tf_global_cfg_bind(struct tf *tfp __rte_unused,
+tf_global_cfg_bind(struct tf *tfp,
struct tf_global_cfg_cfg_parms *parms)
{
+ struct tfp_calloc_parms cparms;
+ struct tf_global_cfg_db *global_cfg_db;
+
TF_CHECK_PARMS2(tfp, parms);
if (init) {
- TFP_DRV_LOG(ERR,
- "Global Cfg DB already initialized\n");
+ TFP_DRV_LOG(ERR, "Global Cfg DB already initialized\n");
return -EINVAL;
}
- global_cfg_db[TF_DIR_RX] = parms->cfg;
- global_cfg_db[TF_DIR_TX] = parms->cfg;
+ cparms.nitems = 1;
+ cparms.size = sizeof(struct tf_global_cfg_db);
+ cparms.alignment = 0;
+ if (tfp_calloc(&cparms) != 0) {
+ TFP_DRV_LOG(ERR, "global_rm_db alloc error %s\n",
+ strerror(ENOMEM));
+ return -ENOMEM;
+ }
+
+ global_cfg_db = cparms.mem_va;
+ global_cfg_db->global_cfg_db[TF_DIR_RX] = parms->cfg;
+ global_cfg_db->global_cfg_db[TF_DIR_TX] = parms->cfg;
+
+ tf_session_set_global_db(tfp, (void *)global_cfg_db);
init = 1;
- TFP_DRV_LOG(INFO,
- "Global Cfg - initialized\n");
+ TFP_DRV_LOG(INFO, "Global Cfg - initialized\n");
return 0;
}
int
-tf_global_cfg_unbind(struct tf *tfp __rte_unused)
+tf_global_cfg_unbind(struct tf *tfp)
{
+ int rc;
+ struct tf_global_cfg_db *global_cfg_db_ptr;
+
+ TF_CHECK_PARMS1(tfp);
+
/* Bail if nothing has been initialized */
if (!init) {
- TFP_DRV_LOG(INFO,
- "No Global Cfg DBs created\n");
+ TFP_DRV_LOG(INFO, "No Global Cfg DBs created\n");
return 0;
}
- global_cfg_db[TF_DIR_RX] = NULL;
- global_cfg_db[TF_DIR_TX] = NULL;
+ rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "global_cfg_db is not initialized\n");
+ return 0;
+ }
+
+ tfp_free((void *)global_cfg_db_ptr);
init = 0;
return 0;
@@ -117,19 +142,25 @@ tf_global_cfg_set(struct tf *tfp,
{
int rc;
struct tf_global_cfg_get_hcapi_parms hparms;
+ struct tf_global_cfg_db *global_cfg_db_ptr;
uint16_t hcapi_type;
TF_CHECK_PARMS3(tfp, parms, parms->config);
if (!init) {
- TFP_DRV_LOG(ERR,
- "%s: No Global Cfg DBs created\n",
+ TFP_DRV_LOG(ERR, "%s: No Global Cfg DBs created\n",
tf_dir_2_str(parms->dir));
return -EINVAL;
}
+ rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "No global cfg DBs initialized\n");
+ return 0;
+ }
+
/* Convert TF type to HCAPI type */
- hparms.global_cfg_db = global_cfg_db[parms->dir];
+ hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
hparms.db_index = parms->type;
hparms.hcapi_type = &hcapi_type;
rc = tf_global_cfg_get_hcapi_type(&hparms);
@@ -161,6 +192,7 @@ tf_global_cfg_get(struct tf *tfp,
{
int rc;
struct tf_global_cfg_get_hcapi_parms hparms;
+ struct tf_global_cfg_db *global_cfg_db_ptr;
uint16_t hcapi_type;
TF_CHECK_PARMS3(tfp, parms, parms->config);
@@ -172,7 +204,14 @@ tf_global_cfg_get(struct tf *tfp,
return -EINVAL;
}
- hparms.global_cfg_db = global_cfg_db[parms->dir];
+ rc = tf_session_get_global_db(tfp, (void **)&global_cfg_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "No Global cfg DBs initialized\n");
+ return 0;
+ }
+
+ /* Convert TF type to HCAPI type */
+ hparms.global_cfg_db = global_cfg_db_ptr->global_cfg_db[parms->dir];
hparms.db_index = parms->type;
hparms.hcapi_type = &hcapi_type;
rc = tf_global_cfg_get_hcapi_type(&hparms);
@@ -15,10 +15,11 @@
struct tf;
/**
- * IF Table DBs.
- * TODO: Store this data in session db
+ * IF Table database
*/
-static void *if_tbl_db[TF_DIR_MAX];
+struct tf_if_tbl_db {
+ struct tf_if_tbl_cfg *if_tbl_cfg_db[TF_DIR_MAX];
+};
/**
* Init flag, set on bind and cleared on unbind
@@ -57,13 +58,27 @@ tf_if_tbl_get_hcapi_type(struct tf_if_tbl_get_hcapi_parms *parms)
}
int
-tf_if_tbl_bind(struct tf *tfp __rte_unused,
+tf_if_tbl_bind(struct tf *tfp,
struct tf_if_tbl_cfg_parms *parms)
{
+ struct tfp_calloc_parms cparms;
+ struct tf_if_tbl_db *if_tbl_db;
+
TF_CHECK_PARMS2(tfp, parms);
- if_tbl_db[TF_DIR_RX] = parms->cfg;
- if_tbl_db[TF_DIR_TX] = parms->cfg;
+ cparms.nitems = 1;
+ cparms.size = sizeof(struct tf_if_tbl_db);
+ cparms.alignment = 0;
+ if (tfp_calloc(&cparms) != 0) {
+ TFP_DRV_LOG(ERR, "if_tbl_rm_db alloc error %s\n",
+ strerror(ENOMEM));
+ return -ENOMEM;
+ }
+
+ if_tbl_db = cparms.mem_va;
+ if_tbl_db->if_tbl_cfg_db[TF_DIR_RX] = parms->cfg;
+ if_tbl_db->if_tbl_cfg_db[TF_DIR_TX] = parms->cfg;
+ tf_session_set_if_tbl_db(tfp, (void *)if_tbl_db);
init = 1;
@@ -74,8 +89,11 @@ tf_if_tbl_bind(struct tf *tfp __rte_unused,
}
int
-tf_if_tbl_unbind(struct tf *tfp __rte_unused)
+tf_if_tbl_unbind(struct tf *tfp)
{
+ int rc;
+ struct tf_if_tbl_db *if_tbl_db_ptr;
+
/* Bail if nothing has been initialized */
if (!init) {
TFP_DRV_LOG(INFO,
@@ -83,8 +101,15 @@ tf_if_tbl_unbind(struct tf *tfp __rte_unused)
return 0;
}
- if_tbl_db[TF_DIR_RX] = NULL;
- if_tbl_db[TF_DIR_TX] = NULL;
+ TF_CHECK_PARMS1(tfp);
+
+ rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
+ return 0;
+ }
+
+ tfp_free((void *)if_tbl_db_ptr);
init = 0;
return 0;
@@ -95,6 +120,7 @@ tf_if_tbl_set(struct tf *tfp,
struct tf_if_tbl_set_parms *parms)
{
int rc;
+ struct tf_if_tbl_db *if_tbl_db_ptr;
struct tf_if_tbl_get_hcapi_parms hparms;
TF_CHECK_PARMS3(tfp, parms, parms->data);
@@ -106,8 +132,14 @@ tf_if_tbl_set(struct tf *tfp,
return -EINVAL;
}
+ rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
+ return 0;
+ }
+
/* Convert TF type to HCAPI type */
- hparms.tbl_db = if_tbl_db[parms->dir];
+ hparms.tbl_db = if_tbl_db_ptr->if_tbl_cfg_db[parms->dir];
hparms.db_index = parms->type;
hparms.hcapi_type = &parms->hcapi_type;
rc = tf_if_tbl_get_hcapi_type(&hparms);
@@ -131,6 +163,7 @@ tf_if_tbl_get(struct tf *tfp,
struct tf_if_tbl_get_parms *parms)
{
int rc = 0;
+ struct tf_if_tbl_db *if_tbl_db_ptr;
struct tf_if_tbl_get_hcapi_parms hparms;
TF_CHECK_PARMS3(tfp, parms, parms->data);
@@ -142,8 +175,14 @@ tf_if_tbl_get(struct tf *tfp,
return -EINVAL;
}
+ rc = tf_session_get_if_tbl_db(tfp, (void **)&if_tbl_db_ptr);
+ if (rc) {
+ TFP_DRV_LOG(INFO, "No IF Table DBs initialized\n");
+ return 0;
+ }
+
/* Convert TF type to HCAPI type */
- hparms.tbl_db = if_tbl_db[parms->dir];
+ hparms.tbl_db = if_tbl_db_ptr->if_tbl_cfg_db[parms->dir];
hparms.db_index = parms->type;
hparms.hcapi_type = &parms->hcapi_type;
rc = tf_if_tbl_get_hcapi_type(&hparms);
@@ -1069,3 +1069,79 @@ tf_session_set_sram_db(struct tf *tfp,
}
#endif /* TF_TCAM_SHARED */
+
+int
+tf_session_get_global_db(struct tf *tfp,
+ void **global_handle)
+{
+ struct tf_session *tfs = NULL;
+ int rc = 0;
+
+ *global_handle = NULL;
+
+ if (tfp == NULL)
+ return (-EINVAL);
+
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
+ *global_handle = tfs->global_db_handle;
+ return rc;
+}
+
+int
+tf_session_set_global_db(struct tf *tfp,
+ void *global_handle)
+{
+ struct tf_session *tfs = NULL;
+ int rc = 0;
+
+ if (tfp == NULL)
+ return (-EINVAL);
+
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
+ tfs->global_db_handle = global_handle;
+ return rc;
+}
+
+int
+tf_session_get_if_tbl_db(struct tf *tfp,
+ void **if_tbl_handle)
+{
+ struct tf_session *tfs = NULL;
+ int rc = 0;
+
+ *if_tbl_handle = NULL;
+
+ if (tfp == NULL)
+ return (-EINVAL);
+
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
+ *if_tbl_handle = tfs->if_tbl_db_handle;
+ return rc;
+}
+
+int
+tf_session_set_if_tbl_db(struct tf *tfp,
+ void *if_tbl_handle)
+{
+ struct tf_session *tfs = NULL;
+ int rc = 0;
+
+ if (tfp == NULL)
+ return (-EINVAL);
+
+ rc = tf_session_get_session_internal(tfp, &tfs);
+ if (rc)
+ return rc;
+
+ tfs->if_tbl_db_handle = if_tbl_handle;
+ return rc;
+}
@@ -13,7 +13,6 @@
#include "tf_core.h"
#include "tf_device.h"
#include "tf_rm.h"
-#include "tf_tbl.h"
#include "tf_resources.h"
#include "stack.h"
#include "ll.h"
@@ -166,10 +165,26 @@ struct tf_session {
*/
void *tcam_shared_db_handle;
#endif /* TF_TCAM_SHARED */
+
/**
* SRAM db reference for the session
*/
void *sram_handle;
+
+ /**
+ * if table db reference for the session
+ */
+ void *if_tbl_db_handle;
+
+ /**
+ * global db reference for the session
+ */
+ void *global_db_handle;
+
+ /**
+ * Number of slices per row for WC TCAM
+ */
+ uint16_t wc_num_slices_per_row;
};
/**
@@ -666,4 +681,56 @@ int
tf_session_get_sram_db(struct tf *tfp,
void **sram_handle);
+/**
+ * Set the pointer to the global cfg database
+ *
+ * [in] session, pointer to the session
+ *
+ * Returns:
+ * - (0) if successful.
+ * - (-EINVAL) on failure.
+ */
+int
+tf_session_set_global_db(struct tf *tfp,
+ void *global_handle);
+
+/**
+ * Get the pointer to the global cfg database
+ *
+ * [in] session, pointer to the session
+ *
+ * Returns:
+ * - (0) if successful.
+ * - (-EINVAL) on failure.
+ */
+int
+tf_session_get_global_db(struct tf *tfp,
+ void **global_handle);
+
+/**
+ * Set the pointer to the if table cfg database
+ *
+ * [in] session, pointer to the session
+ *
+ * Returns:
+ * - (0) if successful.
+ * - (-EINVAL) on failure.
+ */
+int
+tf_session_set_if_tbl_db(struct tf *tfp,
+ void *if_tbl_handle);
+
+/**
+ * Get the pointer to the if table cfg database
+ *
+ * [in] session, pointer to the session
+ *
+ * Returns:
+ * - (0) if successful.
+ * - (-EINVAL) on failure.
+ */
+int
+tf_session_get_if_tbl_db(struct tf *tfp,
+ void **if_tbl_handle);
+
#endif /* _TF_SESSION_H_ */