eal: remove sys/queue.h from public headers
[dpdk.git] / drivers / net / bnxt / tf_core / tf_em_hash_internal.c
index f6c9772..60273a7 100644 (file)
@@ -22,7 +22,7 @@
 /**
  * EM Pool
  */
-extern struct stack em_pool[TF_DIR_MAX];
+#include "dpool.h"
 
 /**
  * Insert EM internal entry API
@@ -39,7 +39,7 @@ tf_em_hash_insert_int_entry(struct tf *tfp,
        uint16_t rptr_index = 0;
        uint8_t rptr_entry = 0;
        uint8_t num_of_entries = 0;
-       struct stack *pool = &em_pool[parms->dir];
+       struct dpool *pool;
        uint32_t index;
        uint32_t key0_hash;
        uint32_t key1_hash;
@@ -56,13 +56,16 @@ tf_em_hash_insert_int_entry(struct tf *tfp,
        rc = tf_session_get_device(tfs, &dev);
        if (rc)
                return rc;
+       pool = (struct dpool *)tfs->em_pool[parms->dir];
+       index = dpool_alloc(pool,
+                           parms->em_record_sz_in_bits / 128,
+                           DP_DEFRAG_TO_FIT);
 
-       rc = stack_pop(pool, &index);
-       if (rc) {
+       if (index == DP_INVALID_INDEX) {
                PMD_DRV_LOG(ERR,
                            "%s, EM entry index allocation failed\n",
                            tf_dir_2_str(parms->dir));
-               return rc;
+               return -1;
        }
 
        if (dev->ops->tf_dev_cfa_key_hash == NULL)
@@ -83,19 +86,10 @@ tf_em_hash_insert_int_entry(struct tf *tfp,
                                                  &num_of_entries);
        if (rc) {
                /* Free the allocated index before returning */
-               stack_push(pool, index);
+               dpool_free(pool, index);
                return -1;
        }
 
-       PMD_DRV_LOG
-                 (DEBUG,
-                  "%s, Internal entry @ Index:%d rptr_index:0x%x rptr_entry:0x%x num_of_entries:%d\n",
-                  tf_dir_2_str(parms->dir),
-                  index,
-                  rptr_index,
-                  rptr_entry,
-                  num_of_entries);
-
        TF_SET_GFID(gfid,
                    ((rptr_index << TF_EM_INTERNAL_INDEX_SHIFT) |
                     rptr_entry),
@@ -113,6 +107,7 @@ tf_em_hash_insert_int_entry(struct tf *tfp,
                                     rptr_index,
                                     rptr_entry,
                                     0);
+       dpool_set_entry_data(pool, index, parms->flow_handle);
        return 0;
 }
 
@@ -127,13 +122,60 @@ tf_em_hash_delete_int_entry(struct tf *tfp,
                            struct tf_delete_em_entry_parms *parms)
 {
        int rc = 0;
-       struct stack *pool = &em_pool[parms->dir];
+       struct tf_session *tfs;
+       struct dpool *pool;
+       /* 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_msg_delete_em_entry(tfp, parms);
 
        /* Return resource to pool */
-       if (rc == 0)
-               stack_push(pool, parms->index);
+       if (rc == 0) {
+               pool = (struct dpool *)tfs->em_pool[parms->dir];
+               dpool_free(pool, parms->index);
+       }
+
+       return rc;
+}
+
+/** Move EM internal entry API
+ *
+ * returns:
+ * 0
+ * -EINVAL
+ */
+int
+tf_em_move_int_entry(struct tf *tfp,
+                    struct tf_move_em_entry_parms *parms)
+{
+       int rc = 0;
+       struct dpool *pool;
+       struct tf_session *tfs;
+
+       /* 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_msg_move_em_entry(tfp, parms);
+
+       /* Return resource to pool */
+       if (rc == 0) {
+               pool = (struct dpool *)tfs->em_pool[parms->dir];
+               dpool_free(pool, parms->index);
+       }
 
        return rc;
 }