Skip to content

Commit a43ae80

Browse files
elic307imstsirkin
authored andcommitted
vdpa/mlx5: Fix MQ to support non power of two num queues
RQT objects require that a power of two value be configured for both rqt_max_size and rqt_actual size. For create_rqt, make sure to round up to the power of two the value of given by the user who created the vdpa device and given by ndev->rqt_size. The actual size is also rounded up to the power of two using the current number of VQs given by ndev->cur_num_vqs. Same goes with modify_rqt where we need to make sure act size is power of two based on the new number of QPs. Without this patch, attempt to create a device with non power of two QPs would result in error from firmware. Fixes: 5289373 ("vdpa/mlx5: Add multiqueue support") Signed-off-by: Eli Cohen <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 46f8a29 commit a43ae80

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,14 +1320,16 @@ static void teardown_vq(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqueue *
13201320

13211321
static int create_rqt(struct mlx5_vdpa_net *ndev)
13221322
{
1323+
int rqt_table_size = roundup_pow_of_two(ndev->rqt_size);
1324+
int act_sz = roundup_pow_of_two(ndev->cur_num_vqs / 2);
13231325
__be32 *list;
13241326
void *rqtc;
13251327
int inlen;
13261328
void *in;
13271329
int i, j;
13281330
int err;
13291331

1330-
inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + ndev->rqt_size * MLX5_ST_SZ_BYTES(rq_num);
1332+
inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + rqt_table_size * MLX5_ST_SZ_BYTES(rq_num);
13311333
in = kzalloc(inlen, GFP_KERNEL);
13321334
if (!in)
13331335
return -ENOMEM;
@@ -1336,12 +1338,12 @@ static int create_rqt(struct mlx5_vdpa_net *ndev)
13361338
rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
13371339

13381340
MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q);
1339-
MLX5_SET(rqtc, rqtc, rqt_max_size, ndev->rqt_size);
1341+
MLX5_SET(rqtc, rqtc, rqt_max_size, rqt_table_size);
13401342
list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]);
1341-
for (i = 0, j = 0; i < ndev->rqt_size; i++, j += 2)
1343+
for (i = 0, j = 0; i < act_sz; i++, j += 2)
13421344
list[i] = cpu_to_be32(ndev->vqs[j % ndev->cur_num_vqs].virtq_id);
13431345

1344-
MLX5_SET(rqtc, rqtc, rqt_actual_size, ndev->rqt_size);
1346+
MLX5_SET(rqtc, rqtc, rqt_actual_size, act_sz);
13451347
err = mlx5_vdpa_create_rqt(&ndev->mvdev, in, inlen, &ndev->res.rqtn);
13461348
kfree(in);
13471349
if (err)
@@ -1354,14 +1356,15 @@ static int create_rqt(struct mlx5_vdpa_net *ndev)
13541356

13551357
static int modify_rqt(struct mlx5_vdpa_net *ndev, int num)
13561358
{
1359+
int act_sz = roundup_pow_of_two(num / 2);
13571360
__be32 *list;
13581361
void *rqtc;
13591362
int inlen;
13601363
void *in;
13611364
int i, j;
13621365
int err;
13631366

1364-
inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + ndev->rqt_size * MLX5_ST_SZ_BYTES(rq_num);
1367+
inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) + act_sz * MLX5_ST_SZ_BYTES(rq_num);
13651368
in = kzalloc(inlen, GFP_KERNEL);
13661369
if (!in)
13671370
return -ENOMEM;
@@ -1372,10 +1375,10 @@ static int modify_rqt(struct mlx5_vdpa_net *ndev, int num)
13721375
MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q);
13731376

13741377
list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]);
1375-
for (i = 0, j = 0; i < ndev->rqt_size; i++, j += 2)
1378+
for (i = 0, j = 0; i < act_sz; i++, j = j + 2)
13761379
list[i] = cpu_to_be32(ndev->vqs[j % num].virtq_id);
13771380

1378-
MLX5_SET(rqtc, rqtc, rqt_actual_size, ndev->rqt_size);
1381+
MLX5_SET(rqtc, rqtc, rqt_actual_size, act_sz);
13791382
err = mlx5_vdpa_modify_rqt(&ndev->mvdev, in, inlen, ndev->res.rqtn);
13801383
kfree(in);
13811384
if (err)

0 commit comments

Comments
 (0)