net/ixgbe/base: clean up X557 link status check
[dpdk.git] / lib / librte_lpm / rte_lpm6.c
index 9157103..32fdba0 100644 (file)
@@ -45,7 +45,6 @@
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_memcpy.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
 #include <rte_per_lcore.h>
@@ -79,6 +78,11 @@ enum valid_flag {
 
 TAILQ_HEAD(rte_lpm6_list, rte_tailq_entry);
 
+static struct rte_tailq_elem rte_lpm6_tailq = {
+       .name = "RTE_LPM6",
+};
+EAL_REGISTER_TAILQ(rte_lpm6_tailq)
+
 /** Tbl entry structure. It is the same for both tbl24 and tbl8 */
 struct rte_lpm6_tbl_entry {
        uint32_t next_hop:      21;  /**< Next hop / next table to be checked. */
@@ -151,12 +155,7 @@ rte_lpm6_create(const char *name, int socket_id,
        uint64_t mem_size, rules_size;
        struct rte_lpm6_list *lpm_list;
 
-       /* Check that we have an initialised tail queue */
-       if ((lpm_list =
-            RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM6, rte_lpm6_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return NULL;
-       }
+       lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list);
 
        RTE_BUILD_BUG_ON(sizeof(struct rte_lpm6_tbl_entry) != sizeof(uint32_t));
 
@@ -183,8 +182,11 @@ rte_lpm6_create(const char *name, int socket_id,
                if (strncmp(name, lpm->name, RTE_LPM6_NAMESIZE) == 0)
                        break;
        }
-       if (te != NULL)
+       lpm = NULL;
+       if (te != NULL) {
+               rte_errno = EEXIST;
                goto exit;
+       }
 
        /* allocate tailq entry */
        te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0);
@@ -195,7 +197,7 @@ rte_lpm6_create(const char *name, int socket_id,
 
        /* Allocate memory to store the LPM data structures. */
        lpm = (struct rte_lpm6 *)rte_zmalloc_socket(mem_name, (size_t)mem_size,
-                       CACHE_LINE_SIZE, socket_id);
+                       RTE_CACHE_LINE_SIZE, socket_id);
 
        if (lpm == NULL) {
                RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
@@ -204,11 +206,12 @@ rte_lpm6_create(const char *name, int socket_id,
        }
 
        lpm->rules_tbl = (struct rte_lpm6_rule *)rte_zmalloc_socket(NULL,
-                       (size_t)rules_size, CACHE_LINE_SIZE, socket_id);
+                       (size_t)rules_size, RTE_CACHE_LINE_SIZE, socket_id);
 
        if (lpm->rules_tbl == NULL) {
-               RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
+               RTE_LOG(ERR, LPM, "LPM rules_tbl allocation failed\n");
                rte_free(lpm);
+               lpm = NULL;
                rte_free(te);
                goto exit;
        }
@@ -238,12 +241,7 @@ rte_lpm6_find_existing(const char *name)
        struct rte_tailq_entry *te;
        struct rte_lpm6_list *lpm_list;
 
-       /* Check that we have an initialised tail queue */
-       if ((lpm_list = RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM6,
-                       rte_lpm6_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return NULL;
-       }
+       lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list);
 
        rte_rwlock_read_lock(RTE_EAL_TAILQ_RWLOCK);
        TAILQ_FOREACH(te, lpm_list, next) {
@@ -274,12 +272,7 @@ rte_lpm6_free(struct rte_lpm6 *lpm)
        if (lpm == NULL)
                return;
 
-       /* check that we have an initialised tail queue */
-       if ((lpm_list =
-            RTE_TAILQ_LOOKUP_BY_IDX(RTE_TAILQ_LPM, rte_lpm6_list)) == NULL) {
-               rte_errno = E_RTE_NO_TAILQ;
-               return;
-       }
+       lpm_list = RTE_TAILQ_CAST(rte_lpm6_tailq.head, rte_lpm6_list);
 
        rte_rwlock_write_lock(RTE_EAL_TAILQ_RWLOCK);
 
@@ -288,15 +281,13 @@ rte_lpm6_free(struct rte_lpm6 *lpm)
                if (te->data == (void *) lpm)
                        break;
        }
-       if (te == NULL) {
-               rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
-               return;
-       }
 
-       TAILQ_REMOVE(lpm_list, te, next);
+       if (te != NULL)
+               TAILQ_REMOVE(lpm_list, te, next);
 
        rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
 
+       rte_free(lpm->rules_tbl);
        rte_free(lpm);
        rte_free(te);
 }
@@ -610,7 +601,7 @@ int
 rte_lpm6_lookup(const struct rte_lpm6 *lpm, uint8_t *ip, uint8_t *next_hop)
 {
        const struct rte_lpm6_tbl_entry *tbl;
-       const struct rte_lpm6_tbl_entry *tbl_next;
+       const struct rte_lpm6_tbl_entry *tbl_next = NULL;
        int status;
        uint8_t first_byte;
        uint32_t tbl24_index;
@@ -645,7 +636,7 @@ rte_lpm6_lookup_bulk_func(const struct rte_lpm6 *lpm,
 {
        unsigned i;
        const struct rte_lpm6_tbl_entry *tbl;
-       const struct rte_lpm6_tbl_entry *tbl_next;
+       const struct rte_lpm6_tbl_entry *tbl_next = NULL;
        uint32_t tbl24_index;
        uint8_t first_byte, next_hop;
        int status;