Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vdpa: support packed virtqueue for set/get_vq_state()

This patch extends the vdpa_vq_state to support packed virtqueue
state which is basically the device/driver ring wrap counters and the
avail and used index. This will be used for the virito-vdpa support
for the packed virtqueue and the future vhost/vhost-vdpa support for
the packed virtqueue.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Link: https://lore.kernel.org/r/20210602021536.39525-2-jasowang@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eli Cohen <elic@nvidia.com>

authored by

Jason Wang and committed by
Michael S. Tsirkin
530a5678 72b5e895

+33 -12
+2 -2
drivers/vdpa/ifcvf/ifcvf_main.c
··· 264 264 { 265 265 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 266 266 267 - state->avail_index = ifcvf_get_vq_state(vf, qid); 267 + state->split.avail_index = ifcvf_get_vq_state(vf, qid); 268 268 return 0; 269 269 } 270 270 ··· 273 273 { 274 274 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 275 275 276 - return ifcvf_set_vq_state(vf, qid, state->avail_index); 276 + return ifcvf_set_vq_state(vf, qid, state->split.avail_index); 277 277 } 278 278 279 279 static void ifcvf_vdpa_set_vq_cb(struct vdpa_device *vdpa_dev, u16 qid,
+4 -4
drivers/vdpa/mlx5/net/mlx5_vnet.c
··· 1423 1423 return -EINVAL; 1424 1424 } 1425 1425 1426 - mvq->used_idx = state->avail_index; 1427 - mvq->avail_idx = state->avail_index; 1426 + mvq->used_idx = state->split.avail_index; 1427 + mvq->avail_idx = state->split.avail_index; 1428 1428 return 0; 1429 1429 } 1430 1430 ··· 1445 1445 * Since both values should be identical, we take the value of 1446 1446 * used_idx which is reported correctly. 1447 1447 */ 1448 - state->avail_index = mvq->used_idx; 1448 + state->split.avail_index = mvq->used_idx; 1449 1449 return 0; 1450 1450 } 1451 1451 ··· 1454 1454 mlx5_vdpa_warn(mvdev, "failed to query virtqueue\n"); 1455 1455 return err; 1456 1456 } 1457 - state->avail_index = attr.used_index; 1457 + state->split.avail_index = attr.used_index; 1458 1458 return 0; 1459 1459 } 1460 1460
+2 -2
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 374 374 struct vringh *vrh = &vq->vring; 375 375 376 376 spin_lock(&vdpasim->lock); 377 - vrh->last_avail_idx = state->avail_index; 377 + vrh->last_avail_idx = state->split.avail_index; 378 378 spin_unlock(&vdpasim->lock); 379 379 380 380 return 0; ··· 387 387 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx]; 388 388 struct vringh *vrh = &vq->vring; 389 389 390 - state->avail_index = vrh->last_avail_idx; 390 + state->split.avail_index = vrh->last_avail_idx; 391 391 return 0; 392 392 } 393 393
+2 -2
drivers/vhost/vdpa.c
··· 383 383 if (r) 384 384 return r; 385 385 386 - vq->last_avail_idx = vq_state.avail_index; 386 + vq->last_avail_idx = vq_state.split.avail_index; 387 387 break; 388 388 } 389 389 ··· 401 401 break; 402 402 403 403 case VHOST_SET_VRING_BASE: 404 - vq_state.avail_index = vq->last_avail_idx; 404 + vq_state.split.avail_index = vq->last_avail_idx; 405 405 if (ops->set_vq_state(vdpa, idx, &vq_state)) 406 406 r = -EINVAL; 407 407 break;
+23 -2
include/linux/vdpa.h
··· 28 28 }; 29 29 30 30 /** 31 - * struct vdpa_vq_state - vDPA vq_state definition 31 + * struct vdpa_vq_state_split - vDPA split virtqueue state 32 32 * @avail_index: available index 33 33 */ 34 - struct vdpa_vq_state { 34 + struct vdpa_vq_state_split { 35 35 u16 avail_index; 36 + }; 37 + 38 + /** 39 + * struct vdpa_vq_state_packed - vDPA packed virtqueue state 40 + * @last_avail_counter: last driver ring wrap counter observed by device 41 + * @last_avail_idx: device available index 42 + * @last_used_counter: device ring wrap counter 43 + * @last_used_idx: used index 44 + */ 45 + struct vdpa_vq_state_packed { 46 + u16 last_avail_counter:1; 47 + u16 last_avail_idx:15; 48 + u16 last_used_counter:1; 49 + u16 last_used_idx:15; 50 + }; 51 + 52 + struct vdpa_vq_state { 53 + union { 54 + struct vdpa_vq_state_split split; 55 + struct vdpa_vq_state_packed packed; 56 + }; 36 57 }; 37 58 38 59 struct vdpa_mgmt_dev;