]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
virtio_ring: introduce add api for premapped
authorXuan Zhuo <xuanzhuo@linux.alibaba.com>
Tue, 12 Nov 2024 01:29:20 +0000 (09:29 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 16 Nov 2024 02:46:55 +0000 (18:46 -0800)
Two APIs are introduced to submit premapped per-buffers.

int virtqueue_add_inbuf_premapped(struct virtqueue *vq,
                                 struct scatterlist *sg, unsigned int num,
                                 void *data,
                                 void *ctx,
                                 gfp_t gfp);

int virtqueue_add_outbuf_premapped(struct virtqueue *vq,
                                  struct scatterlist *sg, unsigned int num,
                                  void *data,
                                  gfp_t gfp);

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Link: https://patch.msgid.link/20241112012928.102478-6-xuanzhuo@linux.alibaba.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/virtio/virtio_ring.c
include/linux/virtio.h

index fefa85a5e6b6546f65bd1cdba0726c91482bd3ed..0842d27886e5b5ac38de0fc0c2439f95c2801627 100644 (file)
@@ -2276,6 +2276,29 @@ int virtqueue_add_outbuf(struct virtqueue *vq,
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_outbuf);
 
+/**
+ * virtqueue_add_outbuf_premapped - expose output buffers to other end
+ * @vq: the struct virtqueue we're talking about.
+ * @sg: scatterlist (must be well-formed and terminated!)
+ * @num: the number of entries in @sg readable by other side
+ * @data: the token identifying the buffer.
+ * @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).
+ *
+ * Return:
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
+ */
+int virtqueue_add_outbuf_premapped(struct virtqueue *vq,
+                                  struct scatterlist *sg, unsigned int num,
+                                  void *data,
+                                  gfp_t gfp)
+{
+       return virtqueue_add(vq, &sg, num, 1, 0, data, NULL, true, gfp);
+}
+EXPORT_SYMBOL_GPL(virtqueue_add_outbuf_premapped);
+
 /**
  * virtqueue_add_inbuf - expose input buffers to other end
  * @vq: the struct virtqueue we're talking about.
@@ -2322,6 +2345,31 @@ int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
 }
 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx);
 
+/**
+ * virtqueue_add_inbuf_premapped - expose input buffers to other end
+ * @vq: the struct virtqueue we're talking about.
+ * @sg: scatterlist (must be well-formed and terminated!)
+ * @num: the number of entries in @sg writable 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).
+ *
+ * Return:
+ * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO).
+ */
+int virtqueue_add_inbuf_premapped(struct virtqueue *vq,
+                                 struct scatterlist *sg, unsigned int num,
+                                 void *data,
+                                 void *ctx,
+                                 gfp_t gfp)
+{
+       return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, true, gfp);
+}
+EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_premapped);
+
 /**
  * virtqueue_dma_dev - get the dma dev
  * @_vq: the struct virtqueue we're talking about.
index 306137a15d0753c2f5527cfe79053a1082fffba1..13b3f55abca31a02b05f047e71f15a1c9d94b221 100644 (file)
@@ -56,6 +56,17 @@ int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
                            void *ctx,
                            gfp_t gfp);
 
+int virtqueue_add_inbuf_premapped(struct virtqueue *vq,
+                                 struct scatterlist *sg, unsigned int num,
+                                 void *data,
+                                 void *ctx,
+                                 gfp_t gfp);
+
+int virtqueue_add_outbuf_premapped(struct virtqueue *vq,
+                                  struct scatterlist *sg, unsigned int num,
+                                  void *data,
+                                  gfp_t gfp);
+
 int virtqueue_add_sgs(struct virtqueue *vq,
                      struct scatterlist *sgs[],
                      unsigned int out_sgs,