Introduce virtqueueu_add_sg(), so that in virtio-net we can create an unify api for rq and sq. Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> --- drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++ include/linux/virtio.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 56444f872967..a00f049ea442 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -2356,6 +2356,29 @@ static inline int virtqueue_add(struct virtqueue *_vq, out_sgs, in_sgs, data, ctx, gfp); } +/** + * virtqueue_add_sg - expose buffers to other end + * @vq: the struct virtqueue we're talking about. + * @sg: a scatterlist + * @num: the number of entries in @sg + * @out: whether the sg is readable by other side + * @data: the token identifying the buffer. + * @ctx: extra context for the token + * @gfp: how to do memory allocations (if necessary). + * + * Caller must ensure we don't call this with other virtqueue operations + * at the same time (except where noted). + * + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). + */ +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp) +{ + return virtqueue_add(vq, &sg, num, (int)out, (int)!out, data, ctx, gfp); +} +EXPORT_SYMBOL_GPL(virtqueue_add_sg); + /** * virtqueue_add_sgs - expose buffers to other end * @_vq: the struct virtqueue we're talking about. diff --git a/include/linux/virtio.h b/include/linux/virtio.h index b24f0a665390..1a4aa4382c53 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -55,6 +55,10 @@ struct virtqueue_detach_cursor { unsigned pos:16; }; +int virtqueue_add_sg(struct virtqueue *vq, struct scatterlist *sg, + unsigned int num, bool out, void *data, + void *ctx, gfp_t gfp); + int virtqueue_add_outbuf(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, -- 2.32.0.3.g01195cf9f