aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/block/virtio_blk.c2
-rw-r--r--drivers/char/hw_random/virtio-rng.c2
-rw-r--r--drivers/char/virtio_console.c4
-rw-r--r--drivers/lguest/lguest_device.c5
-rw-r--r--drivers/net/virtio_net.c6
-rw-r--r--drivers/s390/kvm/kvm_virtio.c7
-rw-r--r--drivers/virtio/virtio.c2
-rw-r--r--drivers/virtio/virtio_balloon.c4
-rw-r--r--drivers/virtio/virtio_pci.c5
-rw-r--r--drivers/virtio/virtio_ring.c27
-rw-r--r--include/linux/virtio.h12
-rw-r--r--include/linux/virtio_config.h6
-rw-r--r--include/linux/virtio_ring.h3
-rw-r--r--net/9p/trans_virtio.c2
14 files changed, 56 insertions, 31 deletions
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c0facaa55cf4..db55a50d9f6a 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -288,7 +288,7 @@ static int virtblk_probe(struct virtio_device *vdev)
288 sg_init_table(vblk->sg, vblk->sg_elems); 288 sg_init_table(vblk->sg, vblk->sg_elems);
289 289
290 /* We expect one virtqueue, for output. */ 290 /* We expect one virtqueue, for output. */
291 vblk->vq = vdev->config->find_vq(vdev, 0, blk_done); 291 vblk->vq = vdev->config->find_vq(vdev, 0, blk_done, "requests");
292 if (IS_ERR(vblk->vq)) { 292 if (IS_ERR(vblk->vq)) {
293 err = PTR_ERR(vblk->vq); 293 err = PTR_ERR(vblk->vq);
294 goto out_free_vblk; 294 goto out_free_vblk;
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 86e83f883139..2aeafcea95fe 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -94,7 +94,7 @@ static int virtrng_probe(struct virtio_device *vdev)
94 int err; 94 int err;
95 95
96 /* We expect a single virtqueue. */ 96 /* We expect a single virtqueue. */
97 vq = vdev->config->find_vq(vdev, 0, random_recv_done); 97 vq = vdev->config->find_vq(vdev, 0, random_recv_done, "input");
98 if (IS_ERR(vq)) 98 if (IS_ERR(vq))
99 return PTR_ERR(vq); 99 return PTR_ERR(vq);
100 100
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index ff6f5a4b58fb..58684e4a0814 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -202,13 +202,13 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
202 /* Find the input queue. */ 202 /* Find the input queue. */
203 /* FIXME: This is why we want to wean off hvc: we do nothing 203 /* FIXME: This is why we want to wean off hvc: we do nothing
204 * when input comes in. */ 204 * when input comes in. */
205 in_vq = vdev->config->find_vq(vdev, 0, hvc_handle_input); 205 in_vq = vdev->config->find_vq(vdev, 0, hvc_handle_input, "input");
206 if (IS_ERR(in_vq)) { 206 if (IS_ERR(in_vq)) {
207 err = PTR_ERR(in_vq); 207 err = PTR_ERR(in_vq);
208 goto free; 208 goto free;
209 } 209 }
210 210
211 out_vq = vdev->config->find_vq(vdev, 1, NULL); 211 out_vq = vdev->config->find_vq(vdev, 1, NULL, "output");
212 if (IS_ERR(out_vq)) { 212 if (IS_ERR(out_vq)) {
213 err = PTR_ERR(out_vq); 213 err = PTR_ERR(out_vq);
214 goto free_in_vq; 214 goto free_in_vq;
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index df44d962626d..4babed899d59 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -228,7 +228,8 @@ extern void lguest_setup_irq(unsigned int irq);
228 * function. */ 228 * function. */
229static struct virtqueue *lg_find_vq(struct virtio_device *vdev, 229static struct virtqueue *lg_find_vq(struct virtio_device *vdev,
230 unsigned index, 230 unsigned index,
231 void (*callback)(struct virtqueue *vq)) 231 void (*callback)(struct virtqueue *vq),
232 const char *name)
232{ 233{
233 struct lguest_device *ldev = to_lgdev(vdev); 234 struct lguest_device *ldev = to_lgdev(vdev);
234 struct lguest_vq_info *lvq; 235 struct lguest_vq_info *lvq;
@@ -263,7 +264,7 @@ static struct virtqueue *lg_find_vq(struct virtio_device *vdev,
263 /* OK, tell virtio_ring.c to set up a virtqueue now we know its size 264 /* OK, tell virtio_ring.c to set up a virtqueue now we know its size
264 * and we've got a pointer to its pages. */ 265 * and we've got a pointer to its pages. */
265 vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN, 266 vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN,
266 vdev, lvq->pages, lg_notify, callback); 267 vdev, lvq->pages, lg_notify, callback, name);
267 if (!vq) { 268 if (!vq) {
268 err = -ENOMEM; 269 err = -ENOMEM;
269 goto unmap; 270 goto unmap;
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 4d1d47953fc6..be3b734ff5a1 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -906,20 +906,20 @@ static int virtnet_probe(struct virtio_device *vdev)
906 vi->mergeable_rx_bufs = true; 906 vi->mergeable_rx_bufs = true;
907 907
908 /* We expect two virtqueues, receive then send. */ 908 /* We expect two virtqueues, receive then send. */
909 vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done); 909 vi->rvq = vdev->config->find_vq(vdev, 0, skb_recv_done, "input");
910 if (IS_ERR(vi->rvq)) { 910 if (IS_ERR(vi->rvq)) {
911 err = PTR_ERR(vi->rvq); 911 err = PTR_ERR(vi->rvq);
912 goto free; 912 goto free;
913 } 913 }
914 914
915 vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done); 915 vi->svq = vdev->config->find_vq(vdev, 1, skb_xmit_done, "output");
916 if (IS_ERR(vi->svq)) { 916 if (IS_ERR(vi->svq)) {
917 err = PTR_ERR(vi->svq); 917 err = PTR_ERR(vi->svq);
918 goto free_recv; 918 goto free_recv;
919 } 919 }
920 920
921 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) { 921 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_VQ)) {
922 vi->cvq = vdev->config->find_vq(vdev, 2, NULL); 922 vi->cvq = vdev->config->find_vq(vdev, 2, NULL, "control");
923 if (IS_ERR(vi->cvq)) { 923 if (IS_ERR(vi->cvq)) {
924 err = PTR_ERR(vi->svq); 924 err = PTR_ERR(vi->svq);
925 goto free_send; 925 goto free_send;
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index cbc8566fab70..ba8995fbf041 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -173,8 +173,9 @@ static void kvm_notify(struct virtqueue *vq)
173 * this device and sets it up. 173 * this device and sets it up.
174 */ 174 */
175static struct virtqueue *kvm_find_vq(struct virtio_device *vdev, 175static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
176 unsigned index, 176 unsigned index,
177 void (*callback)(struct virtqueue *vq)) 177 void (*callback)(struct virtqueue *vq),
178 const char *name)
178{ 179{
179 struct kvm_device *kdev = to_kvmdev(vdev); 180 struct kvm_device *kdev = to_kvmdev(vdev);
180 struct kvm_vqconfig *config; 181 struct kvm_vqconfig *config;
@@ -194,7 +195,7 @@ static struct virtqueue *kvm_find_vq(struct virtio_device *vdev,
194 195
195 vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN, 196 vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN,
196 vdev, (void *) config->address, 197 vdev, (void *) config->address,
197 kvm_notify, callback); 198 kvm_notify, callback, name);
198 if (!vq) { 199 if (!vq) {
199 err = -ENOMEM; 200 err = -ENOMEM;
200 goto unmap; 201 goto unmap;
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 6b6810364860..3f52c767dfe9 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -186,6 +186,8 @@ int register_virtio_device(struct virtio_device *dev)
186 /* Acknowledge that we've seen the device. */ 186 /* Acknowledge that we've seen the device. */
187 add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE); 187 add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE);
188 188
189 INIT_LIST_HEAD(&dev->vqs);
190
189 /* device_register() causes the bus infrastructure to look for a 191 /* device_register() causes the bus infrastructure to look for a
190 * matching driver. */ 192 * matching driver. */
191 err = device_register(&dev->dev); 193 err = device_register(&dev->dev);
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 9c76a061a04d..0fa73b4d18b0 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -218,13 +218,13 @@ static int virtballoon_probe(struct virtio_device *vdev)
218 vb->vdev = vdev; 218 vb->vdev = vdev;
219 219
220 /* We expect two virtqueues. */ 220 /* We expect two virtqueues. */
221 vb->inflate_vq = vdev->config->find_vq(vdev, 0, balloon_ack); 221 vb->inflate_vq = vdev->config->find_vq(vdev, 0, balloon_ack, "inflate");
222 if (IS_ERR(vb->inflate_vq)) { 222 if (IS_ERR(vb->inflate_vq)) {
223 err = PTR_ERR(vb->inflate_vq); 223 err = PTR_ERR(vb->inflate_vq);
224 goto out_free_vb; 224 goto out_free_vb;
225 } 225 }
226 226
227 vb->deflate_vq = vdev->config->find_vq(vdev, 1, balloon_ack); 227 vb->deflate_vq = vdev->config->find_vq(vdev, 1, balloon_ack, "deflate");
228 if (IS_ERR(vb->deflate_vq)) { 228 if (IS_ERR(vb->deflate_vq)) {
229 err = PTR_ERR(vb->deflate_vq); 229 err = PTR_ERR(vb->deflate_vq);
230 goto out_del_inflate_vq; 230 goto out_del_inflate_vq;
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 330aacbdec1f..be4047abd5ba 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -208,7 +208,8 @@ static irqreturn_t vp_interrupt(int irq, void *opaque)
208 208
209/* the config->find_vq() implementation */ 209/* the config->find_vq() implementation */
210static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index, 210static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
211 void (*callback)(struct virtqueue *vq)) 211 void (*callback)(struct virtqueue *vq),
212 const char *name)
212{ 213{
213 struct virtio_pci_device *vp_dev = to_vp_device(vdev); 214 struct virtio_pci_device *vp_dev = to_vp_device(vdev);
214 struct virtio_pci_vq_info *info; 215 struct virtio_pci_vq_info *info;
@@ -247,7 +248,7 @@ static struct virtqueue *vp_find_vq(struct virtio_device *vdev, unsigned index,
247 248
248 /* create the vring */ 249 /* create the vring */
249 vq = vring_new_virtqueue(info->num, VIRTIO_PCI_VRING_ALIGN, 250 vq = vring_new_virtqueue(info->num, VIRTIO_PCI_VRING_ALIGN,
250 vdev, info->queue, vp_notify, callback); 251 vdev, info->queue, vp_notify, callback, name);
251 if (!vq) { 252 if (!vq) {
252 err = -ENOMEM; 253 err = -ENOMEM;
253 goto out_activate_queue; 254 goto out_activate_queue;
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 5c52369ab9bb..579fa693d5d0 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -23,21 +23,30 @@
23 23
24#ifdef DEBUG 24#ifdef DEBUG
25/* For development, we want to crash whenever the ring is screwed. */ 25/* For development, we want to crash whenever the ring is screwed. */
26#define BAD_RING(_vq, fmt...) \ 26#define BAD_RING(_vq, fmt, args...) \
27 do { dev_err(&(_vq)->vq.vdev->dev, fmt); BUG(); } while(0) 27 do { \
28 dev_err(&(_vq)->vq.vdev->dev, \
29 "%s:"fmt, (_vq)->vq.name, ##args); \
30 BUG(); \
31 } while (0)
28/* Caller is supposed to guarantee no reentry. */ 32/* Caller is supposed to guarantee no reentry. */
29#define START_USE(_vq) \ 33#define START_USE(_vq) \
30 do { \ 34 do { \
31 if ((_vq)->in_use) \ 35 if ((_vq)->in_use) \
32 panic("in_use = %i\n", (_vq)->in_use); \ 36 panic("%s:in_use = %i\n", \
37 (_vq)->vq.name, (_vq)->in_use); \
33 (_vq)->in_use = __LINE__; \ 38 (_vq)->in_use = __LINE__; \
34 mb(); \ 39 mb(); \
35 } while(0) 40 } while (0)
36#define END_USE(_vq) \ 41#define END_USE(_vq) \
37 do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; mb(); } while(0) 42 do { BUG_ON(!(_vq)->in_use); (_vq)->in_use = 0; mb(); } while(0)
38#else 43#else
39#define BAD_RING(_vq, fmt...) \ 44#define BAD_RING(_vq, fmt, args...) \
40 do { dev_err(&_vq->vq.vdev->dev, fmt); (_vq)->broken = true; } while(0) 45 do { \
46 dev_err(&_vq->vq.vdev->dev, \
47 "%s:"fmt, (_vq)->vq.name, ##args); \
48 (_vq)->broken = true; \
49 } while (0)
41#define START_USE(vq) 50#define START_USE(vq)
42#define END_USE(vq) 51#define END_USE(vq)
43#endif 52#endif
@@ -284,7 +293,8 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
284 struct virtio_device *vdev, 293 struct virtio_device *vdev,
285 void *pages, 294 void *pages,
286 void (*notify)(struct virtqueue *), 295 void (*notify)(struct virtqueue *),
287 void (*callback)(struct virtqueue *)) 296 void (*callback)(struct virtqueue *),
297 const char *name)
288{ 298{
289 struct vring_virtqueue *vq; 299 struct vring_virtqueue *vq;
290 unsigned int i; 300 unsigned int i;
@@ -303,10 +313,12 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
303 vq->vq.callback = callback; 313 vq->vq.callback = callback;
304 vq->vq.vdev = vdev; 314 vq->vq.vdev = vdev;
305 vq->vq.vq_ops = &vring_vq_ops; 315 vq->vq.vq_ops = &vring_vq_ops;
316 vq->vq.name = name;
306 vq->notify = notify; 317 vq->notify = notify;
307 vq->broken = false; 318 vq->broken = false;
308 vq->last_used_idx = 0; 319 vq->last_used_idx = 0;
309 vq->num_added = 0; 320 vq->num_added = 0;
321 list_add_tail(&vq->vq.list, &vdev->vqs);
310#ifdef DEBUG 322#ifdef DEBUG
311 vq->in_use = false; 323 vq->in_use = false;
312#endif 324#endif
@@ -327,6 +339,7 @@ EXPORT_SYMBOL_GPL(vring_new_virtqueue);
327 339
328void vring_del_virtqueue(struct virtqueue *vq) 340void vring_del_virtqueue(struct virtqueue *vq)
329{ 341{
342 list_del(&vq->list);
330 kfree(to_vvq(vq)); 343 kfree(to_vvq(vq));
331} 344}
332EXPORT_SYMBOL_GPL(vring_del_virtqueue); 345EXPORT_SYMBOL_GPL(vring_del_virtqueue);
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 9410394bbf96..4fca4f5440ba 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -10,14 +10,17 @@
10 10
11/** 11/**
12 * virtqueue - a queue to register buffers for sending or receiving. 12 * virtqueue - a queue to register buffers for sending or receiving.
13 * @list: the chain of virtqueues for this device
13 * @callback: the function to call when buffers are consumed (can be NULL). 14 * @callback: the function to call when buffers are consumed (can be NULL).
15 * @name: the name of this virtqueue (mainly for debugging)
14 * @vdev: the virtio device this queue was created for. 16 * @vdev: the virtio device this queue was created for.
15 * @vq_ops: the operations for this virtqueue (see below). 17 * @vq_ops: the operations for this virtqueue (see below).
16 * @priv: a pointer for the virtqueue implementation to use. 18 * @priv: a pointer for the virtqueue implementation to use.
17 */ 19 */
18struct virtqueue 20struct virtqueue {
19{ 21 struct list_head list;
20 void (*callback)(struct virtqueue *vq); 22 void (*callback)(struct virtqueue *vq);
23 const char *name;
21 struct virtio_device *vdev; 24 struct virtio_device *vdev;
22 struct virtqueue_ops *vq_ops; 25 struct virtqueue_ops *vq_ops;
23 void *priv; 26 void *priv;
@@ -76,15 +79,16 @@ struct virtqueue_ops {
76 * @dev: underlying device. 79 * @dev: underlying device.
77 * @id: the device type identification (used to match it with a driver). 80 * @id: the device type identification (used to match it with a driver).
78 * @config: the configuration ops for this device. 81 * @config: the configuration ops for this device.
82 * @vqs: the list of virtqueues for this device.
79 * @features: the features supported by both driver and device. 83 * @features: the features supported by both driver and device.
80 * @priv: private pointer for the driver's use. 84 * @priv: private pointer for the driver's use.
81 */ 85 */
82struct virtio_device 86struct virtio_device {
83{
84 int index; 87 int index;
85 struct device dev; 88 struct device dev;
86 struct virtio_device_id id; 89 struct virtio_device_id id;
87 struct virtio_config_ops *config; 90 struct virtio_config_ops *config;
91 struct list_head vqs;
88 /* Note that this is a Linux set_bit-style bitmap. */ 92 /* Note that this is a Linux set_bit-style bitmap. */
89 unsigned long features[1]; 93 unsigned long features[1];
90 void *priv; 94 void *priv;
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index bf8ec283b232..9fae274751e0 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -55,7 +55,8 @@
55 * @find_vq: find a virtqueue and instantiate it. 55 * @find_vq: find a virtqueue and instantiate it.
56 * vdev: the virtio_device 56 * vdev: the virtio_device
57 * index: the 0-based virtqueue number in case there's more than one. 57 * index: the 0-based virtqueue number in case there's more than one.
58 * callback: the virqtueue callback 58 * callback: the virtqueue callback
59 * name: the virtqueue name (mainly for debugging)
59 * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT). 60 * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT).
60 * @del_vq: free a virtqueue found by find_vq(). 61 * @del_vq: free a virtqueue found by find_vq().
61 * @get_features: get the array of feature bits for this device. 62 * @get_features: get the array of feature bits for this device.
@@ -77,7 +78,8 @@ struct virtio_config_ops
77 void (*reset)(struct virtio_device *vdev); 78 void (*reset)(struct virtio_device *vdev);
78 struct virtqueue *(*find_vq)(struct virtio_device *vdev, 79 struct virtqueue *(*find_vq)(struct virtio_device *vdev,
79 unsigned index, 80 unsigned index,
80 void (*callback)(struct virtqueue *)); 81 void (*callback)(struct virtqueue *),
82 const char *name);
81 void (*del_vq)(struct virtqueue *vq); 83 void (*del_vq)(struct virtqueue *vq);
82 u32 (*get_features)(struct virtio_device *vdev); 84 u32 (*get_features)(struct virtio_device *vdev);
83 void (*finalize_features)(struct virtio_device *vdev); 85 void (*finalize_features)(struct virtio_device *vdev);
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
index 71e03722fb59..166c519689de 100644
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -119,7 +119,8 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
119 struct virtio_device *vdev, 119 struct virtio_device *vdev,
120 void *pages, 120 void *pages,
121 void (*notify)(struct virtqueue *vq), 121 void (*notify)(struct virtqueue *vq),
122 void (*callback)(struct virtqueue *vq)); 122 void (*callback)(struct virtqueue *vq),
123 const char *name);
123void vring_del_virtqueue(struct virtqueue *vq); 124void vring_del_virtqueue(struct virtqueue *vq);
124/* Filter out transport-specific feature bits. */ 125/* Filter out transport-specific feature bits. */
125void vring_transport_features(struct virtio_device *vdev); 126void vring_transport_features(struct virtio_device *vdev);
diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
index bb8579a141a8..ab8791f9aba8 100644
--- a/net/9p/trans_virtio.c
+++ b/net/9p/trans_virtio.c
@@ -246,7 +246,7 @@ static int p9_virtio_probe(struct virtio_device *vdev)
246 chan->vdev = vdev; 246 chan->vdev = vdev;
247 247
248 /* We expect one virtqueue, for requests. */ 248 /* We expect one virtqueue, for requests. */
249 chan->vq = vdev->config->find_vq(vdev, 0, req_done); 249 chan->vq = vdev->config->find_vq(vdev, 0, req_done, "requests");
250 if (IS_ERR(chan->vq)) { 250 if (IS_ERR(chan->vq)) {
251 err = PTR_ERR(chan->vq); 251 err = PTR_ERR(chan->vq);
252 goto out_free_vq; 252 goto out_free_vq;