@@ -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.
@@ -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,
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@linux.alibaba.com> --- drivers/virtio/virtio_ring.c | 23 +++++++++++++++++++++++ include/linux/virtio.h | 4 ++++ 2 files changed, 27 insertions(+)