Commit 74c89072 authored by Dragos Tatulea's avatar Dragos Tatulea Committed by Michael S. Tsirkin

vdpa/mlx5: Small improvement for change_num_qps()

change_num_qps() has a lot of multiplications by 2 to convert
the number of VQ pairs to number of VQs. This patch simplifies
the code by doing the VQP -> VQ count conversion at the beginning
in a variable.
Signed-off-by: default avatarDragos Tatulea <dtatulea@nvidia.com>
Reviewed-by: default avatarTariq Toukan <tariqt@nvidia.com>
Message-Id: <20240816090159.1967650-10-dtatulea@nvidia.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Acked-by: default avatarEugenio Pérez <eperezma@redhat.com>
Tested-by: default avatarLei Yang <leiyang@redhat.com>
parent 55a7cb05
...@@ -2219,16 +2219,17 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd) ...@@ -2219,16 +2219,17 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps) static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
{ {
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
int cur_qps = ndev->cur_num_vqs / 2; int cur_vqs = ndev->cur_num_vqs;
int new_vqs = newqps * 2;
int err; int err;
int i; int i;
if (cur_qps > newqps) { if (cur_vqs > new_vqs) {
err = modify_rqt(ndev, 2 * newqps); err = modify_rqt(ndev, new_vqs);
if (err) if (err)
return err; return err;
for (i = ndev->cur_num_vqs - 1; i >= 2 * newqps; i--) { for (i = cur_vqs - 1; i >= new_vqs; i--) {
struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
if (is_resumable(ndev)) if (is_resumable(ndev))
...@@ -2237,27 +2238,27 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps) ...@@ -2237,27 +2238,27 @@ static int change_num_qps(struct mlx5_vdpa_dev *mvdev, int newqps)
teardown_vq(ndev, mvq); teardown_vq(ndev, mvq);
} }
ndev->cur_num_vqs = 2 * newqps; ndev->cur_num_vqs = new_vqs;
} else { } else {
ndev->cur_num_vqs = 2 * newqps; ndev->cur_num_vqs = new_vqs;
for (i = cur_qps * 2; i < 2 * newqps; i++) { for (i = cur_vqs; i < new_vqs; i++) {
struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i]; struct mlx5_vdpa_virtqueue *mvq = &ndev->vqs[i];
err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true); err = mvq->initialized ? resume_vq(ndev, mvq) : setup_vq(ndev, mvq, true);
if (err) if (err)
goto clean_added; goto clean_added;
} }
err = modify_rqt(ndev, 2 * newqps); err = modify_rqt(ndev, new_vqs);
if (err) if (err)
goto clean_added; goto clean_added;
} }
return 0; return 0;
clean_added: clean_added:
for (--i; i >= 2 * cur_qps; --i) for (--i; i >= cur_vqs; --i)
teardown_vq(ndev, &ndev->vqs[i]); teardown_vq(ndev, &ndev->vqs[i]);
ndev->cur_num_vqs = 2 * cur_qps; ndev->cur_num_vqs = cur_vqs;
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment