[2/5] net/mlx5: add resize function to ipool

Message ID 20240202115611.288892-3-getelson@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: add support for flow table resizing |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Gregory Etelson Feb. 2, 2024, 11:56 a.m. UTC
  From: Maayan Kashani <mkashani@nvidia.com>

Before this patch, ipool size could be fixed by
setting max_idx in mlx5_indexed_pool_config upon
ipool creation. Or it can be auto resized to the
maximum limit by setting max_idx to zero upon
ipool creation and the saved value is the maximum
index possible.
This patch adds ipool_resize API that enables to
update the value of max_idx in case it is not set to
maximum, meaning not in auto resize mode. It
enables the allocation of new trunk when using
malloc/zmalloc up to the max_idx limit. Please
notice the resize number of entries should be divisible by trunk_size.

Signed-off-by: Maayan Kashani <mkashani@nvidia.com>
---
 drivers/net/mlx5/mlx5_utils.c | 29 +++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_utils.h | 16 ++++++++++++++++
 2 files changed, 45 insertions(+)
  

Patch

diff --git a/drivers/net/mlx5/mlx5_utils.c b/drivers/net/mlx5/mlx5_utils.c
index 4db738785f..e28db2ec43 100644
--- a/drivers/net/mlx5/mlx5_utils.c
+++ b/drivers/net/mlx5/mlx5_utils.c
@@ -809,6 +809,35 @@  mlx5_ipool_get_next(struct mlx5_indexed_pool *pool, uint32_t *pos)
 	return NULL;
 }
 
+int
+mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries)
+{
+	uint32_t cur_max_idx;
+	uint32_t max_index = mlx5_trunk_idx_offset_get(pool, TRUNK_MAX_IDX + 1);
+
+	if (num_entries % pool->cfg.trunk_size) {
+		DRV_LOG(ERR, "num_entries param should be trunk_size(=%u) multiplication\n",
+			pool->cfg.trunk_size);
+		return -EINVAL;
+	}
+
+	mlx5_ipool_lock(pool);
+	cur_max_idx = pool->cfg.max_idx + num_entries;
+	/* If the ipool max idx is above maximum or uint overflow occurred. */
+	if (cur_max_idx > max_index || cur_max_idx < num_entries) {
+		DRV_LOG(ERR, "Ipool resize failed\n");
+		DRV_LOG(ERR, "Adding %u entries to existing %u entries, will cross max limit(=%u)\n",
+		num_entries, cur_max_idx, max_index);
+		mlx5_ipool_unlock(pool);
+		return -EINVAL;
+	}
+
+	/* Update maximum entries number. */
+	pool->cfg.max_idx = cur_max_idx;
+	mlx5_ipool_unlock(pool);
+	return 0;
+}
+
 void
 mlx5_ipool_dump(struct mlx5_indexed_pool *pool)
 {
diff --git a/drivers/net/mlx5/mlx5_utils.h b/drivers/net/mlx5/mlx5_utils.h
index 82e8298781..f3c0d76a6d 100644
--- a/drivers/net/mlx5/mlx5_utils.h
+++ b/drivers/net/mlx5/mlx5_utils.h
@@ -427,6 +427,22 @@  void mlx5_ipool_flush_cache(struct mlx5_indexed_pool *pool);
  */
 void *mlx5_ipool_get_next(struct mlx5_indexed_pool *pool, uint32_t *pos);
 
+/**
+ * This function resize the ipool.
+ *
+ * @param pool
+ *   Pointer to the index memory pool handler.
+ * @param num_entries
+ *   Number of entries to be added to the pool.
+ *   This number should be divisible by trunk_size.
+ *
+ * @return
+ *   - non-zero value on error.
+ *   - 0 on success.
+ *
+ */
+int mlx5_ipool_resize(struct mlx5_indexed_pool *pool, uint32_t num_entries);
+
 /**
  * This function allocates new empty Three-level table.
  *