[1/2] net/mlx5: support maximum id in id allocate
Checks
Commit Message
The id allocated is for the register unique id match. Some registers may
not use the full 32 bits. Add the maximum id to avoid allocate id over
the register restriction.
Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
drivers/net/mlx5/mlx5.c | 12 ++++++++----
drivers/net/mlx5/mlx5.h | 1 +
drivers/net/mlx5/mlx5_flow.h | 2 +-
3 files changed, 10 insertions(+), 5 deletions(-)
Comments
Hi,
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Suanming Mou
> Sent: Thursday, January 23, 2020 8:01 AM
> To: Matan Azrad <matan@mellanox.com>; Shahaf Shuler
> <shahafs@mellanox.com>; Slava Ovsiienko <viacheslavo@mellanox.com>
> Cc: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH 1/2] net/mlx5: support maximum id in id allocate
>
> The id allocated is for the register unique id match. Some registers may not
> use the full 32 bits. Add the maximum id to avoid allocate id over the register
> restriction.
>
> Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
> ---
> drivers/net/mlx5/mlx5.c | 12 ++++++++----
> drivers/net/mlx5/mlx5.h | 1 +
> drivers/net/mlx5/mlx5_flow.h | 2 +-
> 3 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index
> ffee39c..2c9f705 100644
> --- a/drivers/net/mlx5/mlx5.c
> +++ b/drivers/net/mlx5/mlx5.c
> @@ -196,11 +196,14 @@ struct mlx5_dev_spawn_data {
> /**
> * Allocate ID pool structure.
> *
> + * @param[in] max_id
> + * The maximum id can be allocated from the pool.
> + *
> * @return
> * Pointer to pool object, NULL value otherwise.
> */
> struct mlx5_flow_id_pool *
> -mlx5_flow_id_pool_alloc(void)
> +mlx5_flow_id_pool_alloc(uint32_t max_id)
> {
> struct mlx5_flow_id_pool *pool;
> void *mem;
> @@ -223,6 +226,7 @@ struct mlx5_flow_id_pool *
> pool->curr = pool->free_arr;
> pool->last = pool->free_arr + MLX5_FLOW_MIN_ID_POOL_SIZE;
> pool->base_index = 0;
> + pool->max_id = max_id;
> return pool;
> error:
> rte_free(pool);
> @@ -257,7 +261,7 @@ struct mlx5_flow_id_pool * mlx5_flow_id_get(struct
> mlx5_flow_id_pool *pool, uint32_t *id) {
> if (pool->curr == pool->free_arr) {
> - if (pool->base_index == UINT32_MAX) {
> + if (pool->base_index == pool->max_id) {
> rte_errno = ENOMEM;
> DRV_LOG(ERR, "no free id");
> return -rte_errno;
> @@ -590,7 +594,7 @@ struct mlx5_flow_id_pool *
> goto error;
> }
> }
> - sh->flow_id_pool = mlx5_flow_id_pool_alloc();
> + sh->flow_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX);
> if (!sh->flow_id_pool) {
> DRV_LOG(ERR, "can't create flow id pool");
> err = ENOMEM;
> @@ -2680,7 +2684,7 @@ struct mlx5_flow_id_pool *
> err = mlx5_alloc_shared_dr(priv);
> if (err)
> goto error;
> - priv->qrss_id_pool = mlx5_flow_id_pool_alloc();
> + priv->qrss_id_pool =
> mlx5_flow_id_pool_alloc(UINT32_MAX);
> if (!priv->qrss_id_pool) {
> DRV_LOG(ERR, "can't create flow id pool");
> err = ENOMEM;
> diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index
> 01542e7..ac86c19 100644
> --- a/drivers/net/mlx5/mlx5.h
> +++ b/drivers/net/mlx5/mlx5.h
> @@ -630,6 +630,7 @@ struct mlx5_flow_id_pool {
> /**< The next index that can be used without any free elements. */
> uint32_t *curr; /**< Pointer to the index to pop. */
> uint32_t *last; /**< Pointer to the last element in the empty arrray.
> */
> + uint32_t max_id; /**< Maximum id can be allocated from the pool.
> */
> };
>
> /*
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index 9832542..d9f1761 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -749,7 +749,7 @@ struct mlx5_flow_driver_ops {
>
> /* mlx5_flow.c */
>
> -struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(void);
> +struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(uint32_t max_id);
> void mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool); uint32_t
> mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id); uint32_t
> mlx5_flow_id_release(struct mlx5_flow_id_pool *pool,
> --
> 1.8.3.1
Series applied to next-net-mlx,
Kindest regards,
Raslan Darawsheh
@@ -196,11 +196,14 @@ struct mlx5_dev_spawn_data {
/**
* Allocate ID pool structure.
*
+ * @param[in] max_id
+ * The maximum id can be allocated from the pool.
+ *
* @return
* Pointer to pool object, NULL value otherwise.
*/
struct mlx5_flow_id_pool *
-mlx5_flow_id_pool_alloc(void)
+mlx5_flow_id_pool_alloc(uint32_t max_id)
{
struct mlx5_flow_id_pool *pool;
void *mem;
@@ -223,6 +226,7 @@ struct mlx5_flow_id_pool *
pool->curr = pool->free_arr;
pool->last = pool->free_arr + MLX5_FLOW_MIN_ID_POOL_SIZE;
pool->base_index = 0;
+ pool->max_id = max_id;
return pool;
error:
rte_free(pool);
@@ -257,7 +261,7 @@ struct mlx5_flow_id_pool *
mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id)
{
if (pool->curr == pool->free_arr) {
- if (pool->base_index == UINT32_MAX) {
+ if (pool->base_index == pool->max_id) {
rte_errno = ENOMEM;
DRV_LOG(ERR, "no free id");
return -rte_errno;
@@ -590,7 +594,7 @@ struct mlx5_flow_id_pool *
goto error;
}
}
- sh->flow_id_pool = mlx5_flow_id_pool_alloc();
+ sh->flow_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX);
if (!sh->flow_id_pool) {
DRV_LOG(ERR, "can't create flow id pool");
err = ENOMEM;
@@ -2680,7 +2684,7 @@ struct mlx5_flow_id_pool *
err = mlx5_alloc_shared_dr(priv);
if (err)
goto error;
- priv->qrss_id_pool = mlx5_flow_id_pool_alloc();
+ priv->qrss_id_pool = mlx5_flow_id_pool_alloc(UINT32_MAX);
if (!priv->qrss_id_pool) {
DRV_LOG(ERR, "can't create flow id pool");
err = ENOMEM;
@@ -630,6 +630,7 @@ struct mlx5_flow_id_pool {
/**< The next index that can be used without any free elements. */
uint32_t *curr; /**< Pointer to the index to pop. */
uint32_t *last; /**< Pointer to the last element in the empty arrray. */
+ uint32_t max_id; /**< Maximum id can be allocated from the pool. */
};
/*
@@ -749,7 +749,7 @@ struct mlx5_flow_driver_ops {
/* mlx5_flow.c */
-struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(void);
+struct mlx5_flow_id_pool *mlx5_flow_id_pool_alloc(uint32_t max_id);
void mlx5_flow_id_pool_release(struct mlx5_flow_id_pool *pool);
uint32_t mlx5_flow_id_get(struct mlx5_flow_id_pool *pool, uint32_t *id);
uint32_t mlx5_flow_id_release(struct mlx5_flow_id_pool *pool,