net/bnxt: fix link status when port is stopped
[dpdk.git] / drivers / net / mlx5 / mlx5_utils.c
index 4536ca8..4115a2a 100644 (file)
@@ -8,167 +8,6 @@
 
 #include "mlx5_utils.h"
 
-
-/********************* MLX5 list ************************/
-
-static struct mlx5_list_entry *
-mlx5_list_default_create_cb(struct mlx5_list *list,
-                            struct mlx5_list_entry *entry __rte_unused,
-                            void *ctx __rte_unused)
-{
-       return mlx5_malloc(MLX5_MEM_ZERO, list->entry_sz, 0, SOCKET_ID_ANY);
-}
-
-static void
-mlx5_list_default_remove_cb(struct mlx5_list *list __rte_unused,
-                            struct mlx5_list_entry *entry)
-{
-       mlx5_free(entry);
-}
-
-int
-mlx5_list_create(struct mlx5_list *list, const char *name,
-                    uint32_t entry_size, void *ctx,
-                    mlx5_list_create_cb cb_create,
-                    mlx5_list_match_cb cb_match,
-                    mlx5_list_remove_cb cb_remove)
-{
-       MLX5_ASSERT(list);
-       if (!cb_match || (!cb_create ^ !cb_remove))
-               return -1;
-       if (name)
-               snprintf(list->name, sizeof(list->name), "%s", name);
-       list->entry_sz = entry_size;
-       list->ctx = ctx;
-       list->cb_create = cb_create ? cb_create : mlx5_list_default_create_cb;
-       list->cb_match = cb_match;
-       list->cb_remove = cb_remove ? cb_remove : mlx5_list_default_remove_cb;
-       rte_rwlock_init(&list->lock);
-       DRV_LOG(DEBUG, "mlx5 list %s initialized.", list->name);
-       LIST_INIT(&list->head);
-       return 0;
-}
-
-static struct mlx5_list_entry *
-__list_lookup(struct mlx5_list *list, void *ctx, bool reuse)
-{
-       struct mlx5_list_entry *entry;
-
-       LIST_FOREACH(entry, &list->head, next) {
-               if (list->cb_match(list, entry, ctx))
-                       continue;
-               if (reuse) {
-                       __atomic_add_fetch(&entry->ref_cnt, 1,
-                                          __ATOMIC_RELAXED);
-                       DRV_LOG(DEBUG, "mlx5 list %s entry %p ref++: %u.",
-                               list->name, (void *)entry, entry->ref_cnt);
-               }
-               break;
-       }
-       return entry;
-}
-
-static struct mlx5_list_entry *
-list_lookup(struct mlx5_list *list, void *ctx, bool reuse)
-{
-       struct mlx5_list_entry *entry;
-
-       rte_rwlock_read_lock(&list->lock);
-       entry = __list_lookup(list, ctx, reuse);
-       rte_rwlock_read_unlock(&list->lock);
-       return entry;
-}
-
-struct mlx5_list_entry *
-mlx5_list_lookup(struct mlx5_list *list, void *ctx)
-{
-       return list_lookup(list, ctx, false);
-}
-
-struct mlx5_list_entry *
-mlx5_list_register(struct mlx5_list *list, void *ctx)
-{
-       struct mlx5_list_entry *entry;
-       uint32_t prev_gen_cnt = 0;
-
-       MLX5_ASSERT(list);
-       prev_gen_cnt = __atomic_load_n(&list->gen_cnt, __ATOMIC_ACQUIRE);
-       /* Lookup with read lock, reuse if found. */
-       entry = list_lookup(list, ctx, true);
-       if (entry)
-               return entry;
-       /* Not found, append with write lock - block read from other threads. */
-       rte_rwlock_write_lock(&list->lock);
-       /* If list changed by other threads before lock, search again. */
-       if (prev_gen_cnt != __atomic_load_n(&list->gen_cnt, __ATOMIC_ACQUIRE)) {
-               /* Lookup and reuse w/o read lock. */
-               entry = __list_lookup(list, ctx, true);
-               if (entry)
-                       goto done;
-       }
-       entry = list->cb_create(list, entry, ctx);
-       if (!entry) {
-               DRV_LOG(ERR, "Failed to init mlx5 list %s entry %p.",
-                       list->name, (void *)entry);
-               goto done;
-       }
-       entry->ref_cnt = 1;
-       LIST_INSERT_HEAD(&list->head, entry, next);
-       __atomic_add_fetch(&list->gen_cnt, 1, __ATOMIC_RELEASE);
-       __atomic_add_fetch(&list->count, 1, __ATOMIC_ACQUIRE);
-       DRV_LOG(DEBUG, "mlx5 list %s entry %p new: %u.",
-               list->name, (void *)entry, entry->ref_cnt);
-done:
-       rte_rwlock_write_unlock(&list->lock);
-       return entry;
-}
-
-int
-mlx5_list_unregister(struct mlx5_list *list,
-                     struct mlx5_list_entry *entry)
-{
-       rte_rwlock_write_lock(&list->lock);
-       MLX5_ASSERT(entry && entry->next.le_prev);
-       DRV_LOG(DEBUG, "mlx5 list %s entry %p ref--: %u.",
-               list->name, (void *)entry, entry->ref_cnt);
-       if (--entry->ref_cnt) {
-               rte_rwlock_write_unlock(&list->lock);
-               return 1;
-       }
-       __atomic_add_fetch(&list->gen_cnt, 1, __ATOMIC_ACQUIRE);
-       __atomic_sub_fetch(&list->count, 1, __ATOMIC_ACQUIRE);
-       LIST_REMOVE(entry, next);
-       list->cb_remove(list, entry);
-       rte_rwlock_write_unlock(&list->lock);
-       DRV_LOG(DEBUG, "mlx5 list %s entry %p removed.",
-               list->name, (void *)entry);
-       return 0;
-}
-
-void
-mlx5_list_destroy(struct mlx5_list *list)
-{
-       struct mlx5_list_entry *entry;
-
-       MLX5_ASSERT(list);
-       /* no LIST_FOREACH_SAFE, using while instead */
-       while (!LIST_EMPTY(&list->head)) {
-               entry = LIST_FIRST(&list->head);
-               LIST_REMOVE(entry, next);
-               list->cb_remove(list, entry);
-               DRV_LOG(DEBUG, "mlx5 list %s entry %p destroyed.",
-                       list->name, (void *)entry);
-       }
-       memset(list, 0, sizeof(*list));
-}
-
-uint32_t
-mlx5_list_get_entry_num(struct mlx5_list *list)
-{
-       MLX5_ASSERT(list);
-       return __atomic_load_n(&list->count, __ATOMIC_RELAXED);
-}
-
 /********************* Indexed pool **********************/
 
 static inline void
@@ -501,6 +340,8 @@ check_again:
        /* Enqueue half of the index to global. */
        ts_idx = mlx5_trunk_idx_offset_get(pool, trunk_idx) + 1;
        fetch_size = trunk->free >> 1;
+       if (fetch_size > pool->cfg.per_core_cache)
+               fetch_size = trunk->free - pool->cfg.per_core_cache;
        for (i = 0; i < fetch_size; i++)
                lc->idx[i] = ts_idx + i;
        lc->len = fetch_size;
@@ -1345,44 +1186,3 @@ mlx5_l3t_set_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
        rte_spinlock_unlock(&tbl->sl);
        return ret;
 }
-
-int32_t
-mlx5_l3t_prepare_entry(struct mlx5_l3t_tbl *tbl, uint32_t idx,
-                      union mlx5_l3t_data *data,
-                      mlx5_l3t_alloc_callback_fn cb, void *ctx)
-{
-       int32_t ret;
-
-       rte_spinlock_lock(&tbl->sl);
-       /* Check if entry data is ready. */
-       ret = __l3t_get_entry(tbl, idx, data);
-       if (!ret) {
-               switch (tbl->type) {
-               case MLX5_L3T_TYPE_WORD:
-                       if (data->word)
-                               goto out;
-                       break;
-               case MLX5_L3T_TYPE_DWORD:
-                       if (data->dword)
-                               goto out;
-                       break;
-               case MLX5_L3T_TYPE_QWORD:
-                       if (data->qword)
-                               goto out;
-                       break;
-               default:
-                       if (data->ptr)
-                               goto out;
-                       break;
-               }
-       }
-       /* Entry data is not ready, use user callback to create it. */
-       ret = cb(ctx, data);
-       if (ret)
-               goto out;
-       /* Save the new allocated data to entry. */
-       ret = __l3t_set_entry(tbl, idx, data);
-out:
-       rte_spinlock_unlock(&tbl->sl);
-       return ret;
-}