Skip to content

Commit db296d2

Browse files
elic307imstsirkin
authored andcommitted
vdpa/mlx5: Decouple virtqueue callback from struct mlx5_vdpa_virtqueue
Instead, define an array of struct vdpa_callback on struct mlx5_vdpa_net and use it to store callbacks for any virtqueue provided. This is required due to the fact that callback configurations arrive before feature negotiation. With control VQ and multiqueue introduced next we want to save the information until after feature negotiation where we know the CVQ index. Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent ae0428d commit db296d2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ struct mlx5_vq_restore_info {
9090
u16 avail_index;
9191
u16 used_index;
9292
bool ready;
93-
struct vdpa_callback cb;
9493
bool restore;
9594
};
9695

@@ -100,7 +99,6 @@ struct mlx5_vdpa_virtqueue {
10099
u64 device_addr;
101100
u64 driver_addr;
102101
u32 num_ent;
103-
struct vdpa_callback event_cb;
104102

105103
/* Resources for implementing the notification channel from the device
106104
* to the driver. fwqp is the firmware end of an RC connection; the
@@ -140,6 +138,7 @@ struct mlx5_vdpa_net {
140138
struct mlx5_vdpa_net_resources res;
141139
struct virtio_net_config config;
142140
struct mlx5_vdpa_virtqueue vqs[MLX5_MAX_SUPPORTED_VQS];
141+
struct vdpa_callback event_cbs[MLX5_MAX_SUPPORTED_VQS + 1];
143142

144143
/* Serialize vq resources creation and destruction. This is required
145144
* since memory map might change and we need to destroy and create
@@ -481,15 +480,19 @@ static int mlx5_vdpa_poll_one(struct mlx5_vdpa_cq *vcq)
481480

482481
static void mlx5_vdpa_handle_completions(struct mlx5_vdpa_virtqueue *mvq, int num)
483482
{
483+
struct mlx5_vdpa_net *ndev = mvq->ndev;
484+
struct vdpa_callback *event_cb;
485+
486+
event_cb = &ndev->event_cbs[mvq->index];
484487
mlx5_cq_set_ci(&mvq->cq.mcq);
485488

486489
/* make sure CQ cosumer update is visible to the hardware before updating
487490
* RX doorbell record.
488491
*/
489492
dma_wmb();
490493
rx_post(&mvq->vqqp, num);
491-
if (mvq->event_cb.callback)
492-
mvq->event_cb.callback(mvq->event_cb.private);
494+
if (event_cb->callback)
495+
event_cb->callback(event_cb->private);
493496
}
494497

495498
static void mlx5_vdpa_cq_comp(struct mlx5_core_cq *mcq, struct mlx5_eqe *eqe)
@@ -1384,9 +1387,8 @@ static void mlx5_vdpa_set_vq_cb(struct vdpa_device *vdev, u16 idx, struct vdpa_c
13841387
{
13851388
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
13861389
struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
1387-
struct mlx5_vdpa_virtqueue *vq = &ndev->vqs[idx];
13881390

1389-
vq->event_cb = *cb;
1391+
ndev->event_cbs[idx] = *cb;
13901392
}
13911393

13921394
static void mlx5_vdpa_set_vq_ready(struct vdpa_device *vdev, u16 idx, bool ready)
@@ -1623,7 +1625,6 @@ static int save_channel_info(struct mlx5_vdpa_net *ndev, struct mlx5_vdpa_virtqu
16231625
ri->desc_addr = mvq->desc_addr;
16241626
ri->device_addr = mvq->device_addr;
16251627
ri->driver_addr = mvq->driver_addr;
1626-
ri->cb = mvq->event_cb;
16271628
ri->restore = true;
16281629
return 0;
16291630
}
@@ -1668,7 +1669,6 @@ static void restore_channels_info(struct mlx5_vdpa_net *ndev)
16681669
mvq->desc_addr = ri->desc_addr;
16691670
mvq->device_addr = ri->device_addr;
16701671
mvq->driver_addr = ri->driver_addr;
1671-
mvq->event_cb = ri->cb;
16721672
}
16731673
}
16741674

@@ -1791,6 +1791,7 @@ static void mlx5_vdpa_set_status(struct vdpa_device *vdev, u8 status)
17911791
mlx5_vdpa_destroy_mr(&ndev->mvdev);
17921792
ndev->mvdev.status = 0;
17931793
ndev->mvdev.mlx_features = 0;
1794+
memset(ndev->event_cbs, 0, sizeof(ndev->event_cbs));
17941795
++mvdev->generation;
17951796
if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
17961797
if (mlx5_vdpa_create_mr(mvdev, NULL))

0 commit comments

Comments
 (0)