introduce virtqueue_detach_unused_buf_premapped() to collect the dma info when get buf from virtio core for premapped mode. If the virtio queue is premapped mode, the virtio-net send buf may have many desc. Every desc dma address need to be unmap. So here we introduce a new helper to collect the dma address of the buffer from the virtio core. Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> --- drivers/virtio/virtio_ring.c | 33 +++++++++++++++++++++++++-------- include/linux/virtio.h | 1 + 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index a30f7f8298cb..de70ead51135 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -991,7 +991,7 @@ static bool virtqueue_enable_cb_delayed_split(struct virtqueue *_vq) return true; } -static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) +static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq, struct virtio_dma_head *dma) { struct vring_virtqueue *vq = to_vvq(_vq); unsigned int i; @@ -1004,7 +1004,7 @@ static void *virtqueue_detach_unused_buf_split(struct virtqueue *_vq) continue; /* detach_buf_split clears data, so grab it now. */ buf = vq->split.desc_state[i].data; - detach_buf_split(vq, i, NULL, NULL); + detach_buf_split(vq, i, dma, NULL); vq->split.avail_idx_shadow--; vq->split.vring.avail->idx = cpu_to_virtio16(_vq->vdev, vq->split.avail_idx_shadow); @@ -1884,7 +1884,7 @@ static bool virtqueue_enable_cb_delayed_packed(struct virtqueue *_vq) return true; } -static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq) +static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq, struct virtio_dma_head *dma) { struct vring_virtqueue *vq = to_vvq(_vq); unsigned int i; @@ -1897,7 +1897,7 @@ static void *virtqueue_detach_unused_buf_packed(struct virtqueue *_vq) continue; /* detach_buf clears data, so grab it now. */ buf = vq->packed.desc_state[i].data; - detach_buf_packed(vq, i, NULL, NULL); + detach_buf_packed(vq, i, dma, NULL); END_USE(vq); return buf; } @@ -2589,19 +2589,36 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq) EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed); /** - * virtqueue_detach_unused_buf - detach first unused buffer + * virtqueue_detach_unused_buf_premapped - detach first unused buffer * @_vq: the struct virtqueue we're talking about. + * @sg: scatterlist array to store the dma info + * + * more see virtqueue_get_buf_ctx_dma() * * Returns NULL or the "data" token handed to virtqueue_add_*(). * This is not valid on an active queue; it is useful for device * shutdown or the reset queue. */ -void *virtqueue_detach_unused_buf(struct virtqueue *_vq) +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, struct virtio_dma_head *dma) { struct vring_virtqueue *vq = to_vvq(_vq); - return vq->packed_ring ? virtqueue_detach_unused_buf_packed(_vq) : - virtqueue_detach_unused_buf_split(_vq); + return vq->packed_ring ? virtqueue_detach_unused_buf_packed(_vq, dma) : + virtqueue_detach_unused_buf_split(_vq, dma); +} +EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf_premapped); + +/** + * virtqueue_detach_unused_buf - detach first unused buffer + * @_vq: the struct virtqueue we're talking about. + * + * Returns NULL or the "data" token handed to virtqueue_add_*(). + * This is not valid on an active queue; it is useful for device + * shutdown or the reset queue. + */ +void *virtqueue_detach_unused_buf(struct virtqueue *_vq) +{ + return virtqueue_detach_unused_buf_premapped(_vq, NULL); } EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf); diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 7a5e9ea7d420..15de031b907f 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -104,6 +104,7 @@ bool virtqueue_poll(struct virtqueue *vq, unsigned); bool virtqueue_enable_cb_delayed(struct virtqueue *vq); void *virtqueue_detach_unused_buf(struct virtqueue *vq); +void *virtqueue_detach_unused_buf_premapped(struct virtqueue *_vq, struct virtio_dma_head *dma); unsigned int virtqueue_get_vring_size(const struct virtqueue *vq); -- 2.32.0.3.g01195cf9f