net/mlx5: use indexed pool as id generator
[dpdk.git] / drivers / net / mlx5 / mlx5_utils.c
index 9a54fda..7a6b0c6 100644 (file)
@@ -230,7 +230,7 @@ mlx5_ipool_create(struct mlx5_indexed_pool_config *cfg)
        struct mlx5_indexed_pool *pool;
        uint32_t i;
 
-       if (!cfg || !cfg->size || (!cfg->malloc ^ !cfg->free) ||
+       if (!cfg || (!cfg->malloc ^ !cfg->free) ||
            (cfg->trunk_size && ((cfg->trunk_size & (cfg->trunk_size - 1)) ||
            ((__builtin_ffs(cfg->trunk_size) + TRUNK_IDX_BITS) > 32))))
                return NULL;
@@ -362,6 +362,11 @@ mlx5_ipool_malloc(struct mlx5_indexed_pool *pool, uint32_t *idx)
        MLX5_ASSERT(iidx < mlx5_trunk_size_get(pool, trunk->idx));
        rte_bitmap_clear(trunk->bmp, iidx);
        p = &trunk->data[iidx * pool->cfg.size];
+       /*
+        * The ipool index should grow continually from small to big,
+        * some features as metering only accept limited bits of index.
+        * Random index with MSB set may be rejected.
+        */
        iidx += mlx5_trunk_idx_offset_get(pool, trunk->idx);
        iidx += 1; /* non-zero index. */
        trunk->free--;
@@ -391,7 +396,7 @@ mlx5_ipool_zmalloc(struct mlx5_indexed_pool *pool, uint32_t *idx)
 {
        void *entry = mlx5_ipool_malloc(pool, idx);
 
-       if (entry)
+       if (entry && pool->cfg.size)
                memset(entry, 0, pool->cfg.size);
        return entry;
 }