aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio/virtio_ring.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-01-12 00:14:42 -0500
committerRusty Russell <rusty@rustcorp.com.au>2012-01-12 00:14:42 -0500
commit5dfc17628d57f9e62043ed0cba03a6e3eb019a78 (patch)
treea488dd3ea081166342904224db3cf039758f23d4 /drivers/virtio/virtio_ring.c
parent1e214a5c1a7e901fc8e98ad6ef84f11005f9ee9d (diff)
virtio: document functions better.
The old documentation is left over from when we used a structure with strategy pointers. And move the documentation to the C file as per kernel practice. Though I disagree... Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/virtio/virtio_ring.c')
-rw-r--r--drivers/virtio/virtio_ring.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 50da92046092..fe50486341a4 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -166,6 +166,23 @@ static int vring_add_indirect(struct vring_virtqueue *vq,
166 return head; 166 return head;
167} 167}
168 168
169/**
170 * virtqueue_add_buf_gfp - expose buffer to other end
171 * @vq: the struct virtqueue we're talking about.
172 * @sg: the description of the buffer(s).
173 * @out_num: the number of sg readable by other side
174 * @in_num: the number of sg which are writable (after readable ones)
175 * @data: the token identifying the buffer.
176 * @gfp: how to do memory allocations (if necessary).
177 *
178 * Caller must ensure we don't call this with other virtqueue operations
179 * at the same time (except where noted).
180 *
181 * Returns remaining capacity of queue or a negative error
182 * (ie. ENOSPC). Note that it only really makes sense to treat all
183 * positive return values as "available": indirect buffers mean that
184 * we can put an entire sg[] array inside a single queue entry.
185 */
169int virtqueue_add_buf_gfp(struct virtqueue *_vq, 186int virtqueue_add_buf_gfp(struct virtqueue *_vq,
170 struct scatterlist sg[], 187 struct scatterlist sg[],
171 unsigned int out, 188 unsigned int out,
@@ -244,6 +261,16 @@ add_head:
244} 261}
245EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp); 262EXPORT_SYMBOL_GPL(virtqueue_add_buf_gfp);
246 263
264/**
265 * virtqueue_kick - update after add_buf
266 * @vq: the struct virtqueue
267 *
268 * After one or more virtqueue_add_buf_gfp calls, invoke this to kick
269 * the other side.
270 *
271 * Caller must ensure we don't call this with other virtqueue
272 * operations at the same time (except where noted).
273 */
247void virtqueue_kick(struct virtqueue *_vq) 274void virtqueue_kick(struct virtqueue *_vq)
248{ 275{
249 struct vring_virtqueue *vq = to_vvq(_vq); 276 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -300,6 +327,22 @@ static inline bool more_used(const struct vring_virtqueue *vq)
300 return vq->last_used_idx != vq->vring.used->idx; 327 return vq->last_used_idx != vq->vring.used->idx;
301} 328}
302 329
330/**
331 * virtqueue_get_buf - get the next used buffer
332 * @vq: the struct virtqueue we're talking about.
333 * @len: the length written into the buffer
334 *
335 * If the driver wrote data into the buffer, @len will be set to the
336 * amount written. This means you don't need to clear the buffer
337 * beforehand to ensure there's no data leakage in the case of short
338 * writes.
339 *
340 * Caller must ensure we don't call this with other virtqueue
341 * operations at the same time (except where noted).
342 *
343 * Returns NULL if there are no used buffers, or the "data" token
344 * handed to virtqueue_add_buf_gfp().
345 */
303void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) 346void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
304{ 347{
305 struct vring_virtqueue *vq = to_vvq(_vq); 348 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -351,6 +394,15 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
351} 394}
352EXPORT_SYMBOL_GPL(virtqueue_get_buf); 395EXPORT_SYMBOL_GPL(virtqueue_get_buf);
353 396
397/**
398 * virtqueue_disable_cb - disable callbacks
399 * @vq: the struct virtqueue we're talking about.
400 *
401 * Note that this is not necessarily synchronous, hence unreliable and only
402 * useful as an optimization.
403 *
404 * Unlike other operations, this need not be serialized.
405 */
354void virtqueue_disable_cb(struct virtqueue *_vq) 406void virtqueue_disable_cb(struct virtqueue *_vq)
355{ 407{
356 struct vring_virtqueue *vq = to_vvq(_vq); 408 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -359,6 +411,17 @@ void virtqueue_disable_cb(struct virtqueue *_vq)
359} 411}
360EXPORT_SYMBOL_GPL(virtqueue_disable_cb); 412EXPORT_SYMBOL_GPL(virtqueue_disable_cb);
361 413
414/**
415 * virtqueue_enable_cb - restart callbacks after disable_cb.
416 * @vq: the struct virtqueue we're talking about.
417 *
418 * This re-enables callbacks; it returns "false" if there are pending
419 * buffers in the queue, to detect a possible race between the driver
420 * checking for more work, and enabling callbacks.
421 *
422 * Caller must ensure we don't call this with other virtqueue
423 * operations at the same time (except where noted).
424 */
362bool virtqueue_enable_cb(struct virtqueue *_vq) 425bool virtqueue_enable_cb(struct virtqueue *_vq)
363{ 426{
364 struct vring_virtqueue *vq = to_vvq(_vq); 427 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -383,6 +446,19 @@ bool virtqueue_enable_cb(struct virtqueue *_vq)
383} 446}
384EXPORT_SYMBOL_GPL(virtqueue_enable_cb); 447EXPORT_SYMBOL_GPL(virtqueue_enable_cb);
385 448
449/**
450 * virtqueue_enable_cb_delayed - restart callbacks after disable_cb.
451 * @vq: the struct virtqueue we're talking about.
452 *
453 * This re-enables callbacks but hints to the other side to delay
454 * interrupts until most of the available buffers have been processed;
455 * it returns "false" if there are many pending buffers in the queue,
456 * to detect a possible race between the driver checking for more work,
457 * and enabling callbacks.
458 *
459 * Caller must ensure we don't call this with other virtqueue
460 * operations at the same time (except where noted).
461 */
386bool virtqueue_enable_cb_delayed(struct virtqueue *_vq) 462bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
387{ 463{
388 struct vring_virtqueue *vq = to_vvq(_vq); 464 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -410,6 +486,14 @@ bool virtqueue_enable_cb_delayed(struct virtqueue *_vq)
410} 486}
411EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed); 487EXPORT_SYMBOL_GPL(virtqueue_enable_cb_delayed);
412 488
489/**
490 * virtqueue_detach_unused_buf - detach first unused buffer
491 * @vq: the struct virtqueue we're talking about.
492 *
493 * Returns NULL or the "data" token handed to virtqueue_add_buf_gfp().
494 * This is not valid on an active queue; it is useful only for device
495 * shutdown.
496 */
413void *virtqueue_detach_unused_buf(struct virtqueue *_vq) 497void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
414{ 498{
415 struct vring_virtqueue *vq = to_vvq(_vq); 499 struct vring_virtqueue *vq = to_vvq(_vq);
@@ -538,7 +622,13 @@ void vring_transport_features(struct virtio_device *vdev)
538} 622}
539EXPORT_SYMBOL_GPL(vring_transport_features); 623EXPORT_SYMBOL_GPL(vring_transport_features);
540 624
541/* return the size of the vring within the virtqueue */ 625/**
626 * virtqueue_get_vring_size - return the size of the virtqueue's vring
627 * @vq: the struct virtqueue containing the vring of interest.
628 *
629 * Returns the size of the vring. This is mainly used for boasting to
630 * userspace. Unlike other operations, this need not be serialized.
631 */
542unsigned int virtqueue_get_vring_size(struct virtqueue *_vq) 632unsigned int virtqueue_get_vring_size(struct virtqueue *_vq)
543{ 633{
544 634