#include <rte_common.h>
#include "tf_identifier.h"
+#include "tf_common.h"
+#include "tf_rm_new.h"
+#include "tf_util.h"
+#include "tfp.h"
struct tf;
/**
* Identifier DBs.
*/
-/* static void *ident_db[TF_DIR_MAX]; */
+static void *ident_db[TF_DIR_MAX];
/**
* Init flag, set on bind and cleared on unbind
*/
-/* static uint8_t init; */
+static uint8_t init;
int
-tf_ident_bind(struct tf *tfp __rte_unused,
- struct tf_ident_cfg *parms __rte_unused)
+tf_ident_bind(struct tf *tfp,
+ struct tf_ident_cfg_parms *parms)
{
+ int rc;
+ int i;
+ struct tf_rm_create_db_parms db_cfg = { 0 };
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (init) {
+ TFP_DRV_LOG(ERR,
+ "Identifier already initialized\n");
+ return -EINVAL;
+ }
+
+ db_cfg.num_elements = parms->num_elements;
+
+ for (i = 0; i < TF_DIR_MAX; i++) {
+ db_cfg.dir = i;
+ db_cfg.num_elements = parms->num_elements;
+ db_cfg.cfg = parms->cfg;
+ db_cfg.alloc_num = parms->resources->identifier_cnt[i];
+ db_cfg.rm_db = ident_db[i];
+ rc = tf_rm_create_db(tfp, &db_cfg);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Identifier DB creation failed\n",
+ tf_dir_2_str(i));
+ return rc;
+ }
+ }
+
+ init = 1;
+
return 0;
}
int
tf_ident_unbind(struct tf *tfp __rte_unused)
{
+ int rc;
+ int i;
+ struct tf_rm_free_db_parms fparms = { 0 };
+
+ TF_CHECK_PARMS1(tfp);
+
+ /* Bail if nothing has been initialized done silent as to
+ * allow for creation cleanup.
+ */
+ if (!init)
+ return -EINVAL;
+
+ for (i = 0; i < TF_DIR_MAX; i++) {
+ fparms.dir = i;
+ fparms.rm_db = ident_db[i];
+ rc = tf_rm_free_db(tfp, &fparms);
+ if (rc)
+ return rc;
+
+ ident_db[i] = NULL;
+ }
+
+ init = 0;
+
return 0;
}
int
tf_ident_alloc(struct tf *tfp __rte_unused,
- struct tf_ident_alloc_parms *parms __rte_unused)
+ struct tf_ident_alloc_parms *parms)
{
+ int rc;
+ struct tf_rm_allocate_parms aparms = { 0 };
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Identifier DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Allocate requested element */
+ aparms.rm_db = ident_db[parms->dir];
+ aparms.db_index = parms->ident_type;
+ aparms.index = (uint32_t *)&parms->id;
+ rc = tf_rm_allocate(&aparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Failed allocate, type:%d\n",
+ tf_dir_2_str(parms->dir),
+ parms->ident_type);
+ return rc;
+ }
+
return 0;
}
int
tf_ident_free(struct tf *tfp __rte_unused,
- struct tf_ident_free_parms *parms __rte_unused)
+ struct tf_ident_free_parms *parms)
{
+ int rc;
+ struct tf_rm_is_allocated_parms aparms = { 0 };
+ struct tf_rm_free_parms fparms = { 0 };
+ int allocated = 0;
+
+ TF_CHECK_PARMS2(tfp, parms);
+
+ if (!init) {
+ TFP_DRV_LOG(ERR,
+ "%s: No Identifier DBs created\n",
+ tf_dir_2_str(parms->dir));
+ return -EINVAL;
+ }
+
+ /* Check if element is in use */
+ aparms.rm_db = ident_db[parms->dir];
+ aparms.db_index = parms->ident_type;
+ aparms.index = parms->id;
+ aparms.allocated = &allocated;
+ rc = tf_rm_is_allocated(&aparms);
+ if (rc)
+ return rc;
+
+ if (!allocated) {
+ TFP_DRV_LOG(ERR,
+ "%s: Entry already free, type:%d, index:%d\n",
+ tf_dir_2_str(parms->dir),
+ parms->ident_type,
+ parms->id);
+ return rc;
+ }
+
+ /* Free requested element */
+ fparms.rm_db = ident_db[parms->dir];
+ fparms.db_index = parms->ident_type;
+ fparms.index = parms->id;
+ rc = tf_rm_free(&fparms);
+ if (rc) {
+ TFP_DRV_LOG(ERR,
+ "%s: Free failed, type:%d, index:%d\n",
+ tf_dir_2_str(parms->dir),
+ parms->ident_type,
+ parms->id);
+ return rc;
+ }
+
return 0;
}