xref: /openbmc/linux/net/9p/trans_virtio.c (revision d2a7ddda9ffb1c8961abff6714b0f1eb925c120f)
1b530cc79SEric Van Hensbergen /*
2fea511a6SEric Van Hensbergen  * The Virtio 9p transport driver
3b530cc79SEric Van Hensbergen  *
4e2735b77SEric Van Hensbergen  * This is a block based transport driver based on the lguest block driver
5e2735b77SEric Van Hensbergen  * code.
6b530cc79SEric Van Hensbergen  *
7fea511a6SEric Van Hensbergen  *  Copyright (C) 2007, 2008 Eric Van Hensbergen, IBM Corporation
8b530cc79SEric Van Hensbergen  *
9b530cc79SEric Van Hensbergen  *  Based on virtio console driver
10b530cc79SEric Van Hensbergen  *  Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation
11b530cc79SEric Van Hensbergen  *
12b530cc79SEric Van Hensbergen  *  This program is free software; you can redistribute it and/or modify
13b530cc79SEric Van Hensbergen  *  it under the terms of the GNU General Public License version 2
14b530cc79SEric Van Hensbergen  *  as published by the Free Software Foundation.
15b530cc79SEric Van Hensbergen  *
16b530cc79SEric Van Hensbergen  *  This program is distributed in the hope that it will be useful,
17b530cc79SEric Van Hensbergen  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18b530cc79SEric Van Hensbergen  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19b530cc79SEric Van Hensbergen  *  GNU General Public License for more details.
20b530cc79SEric Van Hensbergen  *
21b530cc79SEric Van Hensbergen  *  You should have received a copy of the GNU General Public License
22b530cc79SEric Van Hensbergen  *  along with this program; if not, write to:
23b530cc79SEric Van Hensbergen  *  Free Software Foundation
24b530cc79SEric Van Hensbergen  *  51 Franklin Street, Fifth Floor
25b530cc79SEric Van Hensbergen  *  Boston, MA  02111-1301  USA
26b530cc79SEric Van Hensbergen  *
27b530cc79SEric Van Hensbergen  */
28b530cc79SEric Van Hensbergen 
29b530cc79SEric Van Hensbergen #include <linux/in.h>
30b530cc79SEric Van Hensbergen #include <linux/module.h>
31b530cc79SEric Van Hensbergen #include <linux/net.h>
32b530cc79SEric Van Hensbergen #include <linux/ipv6.h>
33b530cc79SEric Van Hensbergen #include <linux/errno.h>
34b530cc79SEric Van Hensbergen #include <linux/kernel.h>
35b530cc79SEric Van Hensbergen #include <linux/un.h>
36b530cc79SEric Van Hensbergen #include <linux/uaccess.h>
37b530cc79SEric Van Hensbergen #include <linux/inet.h>
38b530cc79SEric Van Hensbergen #include <linux/idr.h>
39b530cc79SEric Van Hensbergen #include <linux/file.h>
40b530cc79SEric Van Hensbergen #include <net/9p/9p.h>
41b530cc79SEric Van Hensbergen #include <linux/parser.h>
428b81ef58SEric Van Hensbergen #include <net/9p/client.h>
43b530cc79SEric Van Hensbergen #include <net/9p/transport.h>
44b530cc79SEric Van Hensbergen #include <linux/scatterlist.h>
45b530cc79SEric Van Hensbergen #include <linux/virtio.h>
46b530cc79SEric Van Hensbergen #include <linux/virtio_9p.h>
47b530cc79SEric Van Hensbergen 
48e2735b77SEric Van Hensbergen #define VIRTQUEUE_NUM	128
49e2735b77SEric Van Hensbergen 
50b530cc79SEric Van Hensbergen /* a single mutex to manage channel initialization and attachment */
51c1549497SJosef 'Jeff' Sipek static DEFINE_MUTEX(virtio_9p_lock);
52b530cc79SEric Van Hensbergen /* global which tracks highest initialized channel */
53b530cc79SEric Van Hensbergen static int chan_index;
54b530cc79SEric Van Hensbergen 
55ee443996SEric Van Hensbergen /**
56ee443996SEric Van Hensbergen  * struct virtio_chan - per-instance transport information
57ee443996SEric Van Hensbergen  * @initialized: whether the channel is initialized
58ee443996SEric Van Hensbergen  * @inuse: whether the channel is in use
59ee443996SEric Van Hensbergen  * @lock: protects multiple elements within this structure
60ee443996SEric Van Hensbergen  * @vdev: virtio dev associated with this channel
61ee443996SEric Van Hensbergen  * @vq: virtio queue associated with this channel
62ee443996SEric Van Hensbergen  * @tagpool: accounting for tag ids (and request slots)
63ee443996SEric Van Hensbergen  * @reqs: array of request slots
64ee443996SEric Van Hensbergen  * @max_tag: current number of request_slots allocated
65ee443996SEric Van Hensbergen  * @sg: scatter gather list which is used to pack a request (protected?)
66ee443996SEric Van Hensbergen  *
67ee443996SEric Van Hensbergen  * We keep all per-channel information in a structure.
68b530cc79SEric Van Hensbergen  * This structure is allocated within the devices dev->mem space.
69b530cc79SEric Van Hensbergen  * A pointer to the structure will get put in the transport private.
70ee443996SEric Van Hensbergen  *
71b530cc79SEric Van Hensbergen  */
72ee443996SEric Van Hensbergen 
73b530cc79SEric Van Hensbergen static struct virtio_chan {
74ee443996SEric Van Hensbergen 	bool initialized;
75ee443996SEric Van Hensbergen 	bool inuse;
76b530cc79SEric Van Hensbergen 
77e2735b77SEric Van Hensbergen 	spinlock_t lock;
78e2735b77SEric Van Hensbergen 
79fea511a6SEric Van Hensbergen 	struct p9_client *client;
80b530cc79SEric Van Hensbergen 	struct virtio_device *vdev;
81e2735b77SEric Van Hensbergen 	struct virtqueue *vq;
82b530cc79SEric Van Hensbergen 
83e2735b77SEric Van Hensbergen 	/* Scatterlist: can be too big for stack. */
84e2735b77SEric Van Hensbergen 	struct scatterlist sg[VIRTQUEUE_NUM];
85b530cc79SEric Van Hensbergen } channels[MAX_9P_CHAN];
86b530cc79SEric Van Hensbergen 
87b530cc79SEric Van Hensbergen /* How many bytes left in this page. */
88b530cc79SEric Van Hensbergen static unsigned int rest_of_page(void *data)
89b530cc79SEric Van Hensbergen {
90b530cc79SEric Van Hensbergen 	return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
91b530cc79SEric Van Hensbergen }
92b530cc79SEric Van Hensbergen 
93ee443996SEric Van Hensbergen /**
94ee443996SEric Van Hensbergen  * p9_virtio_close - reclaim resources of a channel
95ee443996SEric Van Hensbergen  * @trans: transport state
96ee443996SEric Van Hensbergen  *
97ee443996SEric Van Hensbergen  * This reclaims a channel by freeing its resources and
98ee443996SEric Van Hensbergen  * reseting its inuse flag.
99ee443996SEric Van Hensbergen  *
100ee443996SEric Van Hensbergen  */
101ee443996SEric Van Hensbergen 
1028b81ef58SEric Van Hensbergen static void p9_virtio_close(struct p9_client *client)
103b530cc79SEric Van Hensbergen {
1048b81ef58SEric Van Hensbergen 	struct virtio_chan *chan = client->trans;
105b530cc79SEric Van Hensbergen 
106c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
107b530cc79SEric Van Hensbergen 	chan->inuse = false;
108c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
109b530cc79SEric Van Hensbergen }
110b530cc79SEric Van Hensbergen 
111ee443996SEric Van Hensbergen /**
112ee443996SEric Van Hensbergen  * req_done - callback which signals activity from the server
113ee443996SEric Van Hensbergen  * @vq: virtio queue activity was received on
114ee443996SEric Van Hensbergen  *
115ee443996SEric Van Hensbergen  * This notifies us that the server has triggered some activity
116ee443996SEric Van Hensbergen  * on the virtio channel - most likely a response to request we
117ee443996SEric Van Hensbergen  * sent.  Figure out which requests now have responses and wake up
118ee443996SEric Van Hensbergen  * those threads.
119ee443996SEric Van Hensbergen  *
120ee443996SEric Van Hensbergen  * Bugs: could do with some additional sanity checking, but appears to work.
121ee443996SEric Van Hensbergen  *
122ee443996SEric Van Hensbergen  */
123ee443996SEric Van Hensbergen 
124e2735b77SEric Van Hensbergen static void req_done(struct virtqueue *vq)
125b530cc79SEric Van Hensbergen {
126e2735b77SEric Van Hensbergen 	struct virtio_chan *chan = vq->vdev->priv;
127e2735b77SEric Van Hensbergen 	struct p9_fcall *rc;
128e2735b77SEric Van Hensbergen 	unsigned int len;
129e2735b77SEric Van Hensbergen 	struct p9_req_t *req;
130b530cc79SEric Van Hensbergen 
13191b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, ": request done\n");
13291b8534fSEric Van Hensbergen 
133e2735b77SEric Van Hensbergen 	while ((rc = chan->vq->vq_ops->get_buf(chan->vq, &len)) != NULL) {
13491b8534fSEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS, ": rc %p\n", rc);
13591b8534fSEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS, ": lookup tag %d\n", rc->tag);
136fea511a6SEric Van Hensbergen 		req = p9_tag_lookup(chan->client, rc->tag);
1371bab88b2SLatchesar Ionkov 		req->status = REQ_STATUS_RCVD;
13891b8534fSEric Van Hensbergen 		p9_client_cb(chan->client, req);
139e2735b77SEric Van Hensbergen 	}
140b530cc79SEric Van Hensbergen }
141b530cc79SEric Van Hensbergen 
142ee443996SEric Van Hensbergen /**
143ee443996SEric Van Hensbergen  * pack_sg_list - pack a scatter gather list from a linear buffer
144ee443996SEric Van Hensbergen  * @sg: scatter/gather list to pack into
145ee443996SEric Van Hensbergen  * @start: which segment of the sg_list to start at
146ee443996SEric Van Hensbergen  * @limit: maximum segment to pack data to
147ee443996SEric Van Hensbergen  * @data: data to pack into scatter/gather list
148ee443996SEric Van Hensbergen  * @count: amount of data to pack into the scatter/gather list
149ee443996SEric Van Hensbergen  *
150ee443996SEric Van Hensbergen  * sg_lists have multiple segments of various sizes.  This will pack
151ee443996SEric Van Hensbergen  * arbitrary data into an existing scatter gather list, segmenting the
152ee443996SEric Van Hensbergen  * data as necessary within constraints.
153ee443996SEric Van Hensbergen  *
154ee443996SEric Van Hensbergen  */
155ee443996SEric Van Hensbergen 
156e2735b77SEric Van Hensbergen static int
157e2735b77SEric Van Hensbergen pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
158e2735b77SEric Van Hensbergen 								int count)
159e2735b77SEric Van Hensbergen {
160e2735b77SEric Van Hensbergen 	int s;
161e2735b77SEric Van Hensbergen 	int index = start;
162e2735b77SEric Van Hensbergen 
163e2735b77SEric Van Hensbergen 	while (count) {
164e2735b77SEric Van Hensbergen 		s = rest_of_page(data);
165e2735b77SEric Van Hensbergen 		if (s > count)
166e2735b77SEric Van Hensbergen 			s = count;
167e2735b77SEric Van Hensbergen 		sg_set_buf(&sg[index++], data, s);
168e2735b77SEric Van Hensbergen 		count -= s;
169e2735b77SEric Van Hensbergen 		data += s;
170d6584f3aSJulia Lawall 		BUG_ON(index > limit);
171e2735b77SEric Van Hensbergen 	}
172e2735b77SEric Van Hensbergen 
173e2735b77SEric Van Hensbergen 	return index-start;
174e2735b77SEric Van Hensbergen }
175e2735b77SEric Van Hensbergen 
17691b8534fSEric Van Hensbergen /* We don't currently allow canceling of virtio requests */
17791b8534fSEric Van Hensbergen static int p9_virtio_cancel(struct p9_client *client, struct p9_req_t *req)
17891b8534fSEric Van Hensbergen {
17991b8534fSEric Van Hensbergen 	return 1;
18091b8534fSEric Van Hensbergen }
18191b8534fSEric Van Hensbergen 
182ee443996SEric Van Hensbergen /**
18391b8534fSEric Van Hensbergen  * p9_virtio_request - issue a request
184ee443996SEric Van Hensbergen  * @t: transport state
185ee443996SEric Van Hensbergen  * @tc: &p9_fcall request to transmit
186ee443996SEric Van Hensbergen  * @rc: &p9_fcall to put reponse into
187ee443996SEric Van Hensbergen  *
188ee443996SEric Van Hensbergen  */
189ee443996SEric Van Hensbergen 
190e2735b77SEric Van Hensbergen static int
19191b8534fSEric Van Hensbergen p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
192e2735b77SEric Van Hensbergen {
193e2735b77SEric Van Hensbergen 	int in, out;
19491b8534fSEric Van Hensbergen 	struct virtio_chan *chan = client->trans;
19591b8534fSEric Van Hensbergen 	char *rdata = (char *)req->rc+sizeof(struct p9_fcall);
196e2735b77SEric Van Hensbergen 
19791b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request\n");
198e2735b77SEric Van Hensbergen 
19991b8534fSEric Van Hensbergen 	out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, req->tc->sdata,
20091b8534fSEric Van Hensbergen 								req->tc->size);
20191b8534fSEric Van Hensbergen 	in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata,
20291b8534fSEric Van Hensbergen 								client->msize);
203e2735b77SEric Van Hensbergen 
204e2735b77SEric Van Hensbergen 	req->status = REQ_STATUS_SENT;
205e2735b77SEric Van Hensbergen 
20691b8534fSEric Van Hensbergen 	if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, req->tc)) {
207e2735b77SEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS,
208e2735b77SEric Van Hensbergen 			"9p debug: virtio rpc add_buf returned failure");
209e2735b77SEric Van Hensbergen 		return -EIO;
210e2735b77SEric Van Hensbergen 	}
211e2735b77SEric Van Hensbergen 
212e2735b77SEric Van Hensbergen 	chan->vq->vq_ops->kick(chan->vq);
213e2735b77SEric Van Hensbergen 
21491b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request kicked\n");
215e2735b77SEric Van Hensbergen 	return 0;
216e2735b77SEric Van Hensbergen }
217e2735b77SEric Van Hensbergen 
218ee443996SEric Van Hensbergen /**
219ee443996SEric Van Hensbergen  * p9_virtio_probe - probe for existence of 9P virtio channels
220ee443996SEric Van Hensbergen  * @vdev: virtio device to probe
221ee443996SEric Van Hensbergen  *
222ee443996SEric Van Hensbergen  * This probes for existing virtio channels.  At present only
223ee443996SEric Van Hensbergen  * a single channel is in use, so in the future more work may need
224ee443996SEric Van Hensbergen  * to be done here.
225ee443996SEric Van Hensbergen  *
226ee443996SEric Van Hensbergen  */
227ee443996SEric Van Hensbergen 
228e2735b77SEric Van Hensbergen static int p9_virtio_probe(struct virtio_device *vdev)
229b530cc79SEric Van Hensbergen {
230b530cc79SEric Van Hensbergen 	int err;
231b530cc79SEric Van Hensbergen 	struct virtio_chan *chan;
232b530cc79SEric Van Hensbergen 	int index;
233b530cc79SEric Van Hensbergen 
234c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
235b530cc79SEric Van Hensbergen 	index = chan_index++;
236b530cc79SEric Van Hensbergen 	chan = &channels[index];
237c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
238b530cc79SEric Van Hensbergen 
239b530cc79SEric Van Hensbergen 	if (chan_index > MAX_9P_CHAN) {
240b530cc79SEric Van Hensbergen 		printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
241b530cc79SEric Van Hensbergen 		BUG();
242b530cc79SEric Van Hensbergen 		err = -ENOMEM;
243b530cc79SEric Van Hensbergen 		goto fail;
244b530cc79SEric Van Hensbergen 	}
245b530cc79SEric Van Hensbergen 
246e2735b77SEric Van Hensbergen 	chan->vdev = vdev;
247e2735b77SEric Van Hensbergen 
248e2735b77SEric Van Hensbergen 	/* We expect one virtqueue, for requests. */
249*d2a7dddaSMichael S. Tsirkin 	chan->vq = virtio_find_single_vq(vdev, req_done, "requests");
250e2735b77SEric Van Hensbergen 	if (IS_ERR(chan->vq)) {
251e2735b77SEric Van Hensbergen 		err = PTR_ERR(chan->vq);
252e2735b77SEric Van Hensbergen 		goto out_free_vq;
253b530cc79SEric Van Hensbergen 	}
254e2735b77SEric Van Hensbergen 	chan->vq->vdev->priv = chan;
255e2735b77SEric Van Hensbergen 	spin_lock_init(&chan->lock);
256b530cc79SEric Van Hensbergen 
257e2735b77SEric Van Hensbergen 	sg_init_table(chan->sg, VIRTQUEUE_NUM);
258b530cc79SEric Van Hensbergen 
259b530cc79SEric Van Hensbergen 	chan->inuse = false;
260b530cc79SEric Van Hensbergen 	chan->initialized = true;
261b530cc79SEric Van Hensbergen 	return 0;
262b530cc79SEric Van Hensbergen 
263e2735b77SEric Van Hensbergen out_free_vq:
264*d2a7dddaSMichael S. Tsirkin 	vdev->config->del_vqs(vdev);
265b530cc79SEric Van Hensbergen fail:
266c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
267b530cc79SEric Van Hensbergen 	chan_index--;
268c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
269b530cc79SEric Van Hensbergen 	return err;
270b530cc79SEric Van Hensbergen }
271b530cc79SEric Van Hensbergen 
272ee443996SEric Van Hensbergen 
273ee443996SEric Van Hensbergen /**
274ee443996SEric Van Hensbergen  * p9_virtio_create - allocate a new virtio channel
2758b81ef58SEric Van Hensbergen  * @client: client instance invoking this transport
276ee443996SEric Van Hensbergen  * @devname: string identifying the channel to connect to (unused)
277ee443996SEric Van Hensbergen  * @args: args passed from sys_mount() for per-transport options (unused)
278ee443996SEric Van Hensbergen  *
279ee443996SEric Van Hensbergen  * This sets up a transport channel for 9p communication.  Right now
280b530cc79SEric Van Hensbergen  * we only match the first available channel, but eventually we couldlook up
281b530cc79SEric Van Hensbergen  * alternate channels by matching devname versus a virtio_config entry.
282b530cc79SEric Van Hensbergen  * We use a simple reference count mechanism to ensure that only a single
283ee443996SEric Van Hensbergen  * mount has a channel open at a time.
284ee443996SEric Van Hensbergen  *
285ee443996SEric Van Hensbergen  * Bugs: doesn't allow identification of a specific channel
286ee443996SEric Van Hensbergen  * to allocate, channels are allocated sequentially. This was
287ee443996SEric Van Hensbergen  * a pragmatic decision to get things rolling, but ideally some
288ee443996SEric Van Hensbergen  * way of identifying the channel to attach to would be nice
289ee443996SEric Van Hensbergen  * if we are going to support multiple channels.
290ee443996SEric Van Hensbergen  *
291ee443996SEric Van Hensbergen  */
292ee443996SEric Van Hensbergen 
2938b81ef58SEric Van Hensbergen static int
2948b81ef58SEric Van Hensbergen p9_virtio_create(struct p9_client *client, const char *devname, char *args)
295b530cc79SEric Van Hensbergen {
296b530cc79SEric Van Hensbergen 	struct virtio_chan *chan = channels;
297e2735b77SEric Van Hensbergen 	int index = 0;
298b530cc79SEric Van Hensbergen 
299c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
300b530cc79SEric Van Hensbergen 	while (index < MAX_9P_CHAN) {
301b530cc79SEric Van Hensbergen 		if (chan->initialized && !chan->inuse) {
302b530cc79SEric Van Hensbergen 			chan->inuse = true;
303b530cc79SEric Van Hensbergen 			break;
304b530cc79SEric Van Hensbergen 		} else {
305b530cc79SEric Van Hensbergen 			index++;
306b530cc79SEric Van Hensbergen 			chan = &channels[index];
307b530cc79SEric Van Hensbergen 		}
308b530cc79SEric Van Hensbergen 	}
309c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
310b530cc79SEric Van Hensbergen 
311b530cc79SEric Van Hensbergen 	if (index >= MAX_9P_CHAN) {
312e2735b77SEric Van Hensbergen 		printk(KERN_ERR "9p: no channels available\n");
3138b81ef58SEric Van Hensbergen 		return -ENODEV;
314b530cc79SEric Van Hensbergen 	}
315b530cc79SEric Van Hensbergen 
3168b81ef58SEric Van Hensbergen 	client->trans = (void *)chan;
317fea511a6SEric Van Hensbergen 	chan->client = client;
318b530cc79SEric Van Hensbergen 
3198b81ef58SEric Van Hensbergen 	return 0;
320b530cc79SEric Van Hensbergen }
321b530cc79SEric Van Hensbergen 
322ee443996SEric Van Hensbergen /**
323ee443996SEric Van Hensbergen  * p9_virtio_remove - clean up resources associated with a virtio device
324ee443996SEric Van Hensbergen  * @vdev: virtio device to remove
325ee443996SEric Van Hensbergen  *
326ee443996SEric Van Hensbergen  */
327ee443996SEric Van Hensbergen 
328f3933545SEric Van Hensbergen static void p9_virtio_remove(struct virtio_device *vdev)
329f3933545SEric Van Hensbergen {
330f3933545SEric Van Hensbergen 	struct virtio_chan *chan = vdev->priv;
331f3933545SEric Van Hensbergen 
332f3933545SEric Van Hensbergen 	BUG_ON(chan->inuse);
333f3933545SEric Van Hensbergen 
334f3933545SEric Van Hensbergen 	if (chan->initialized) {
335*d2a7dddaSMichael S. Tsirkin 		vdev->config->del_vqs(vdev);
336f3933545SEric Van Hensbergen 		chan->initialized = false;
337f3933545SEric Van Hensbergen 	}
338f3933545SEric Van Hensbergen }
339f3933545SEric Van Hensbergen 
340b530cc79SEric Van Hensbergen #define VIRTIO_ID_9P 9
341b530cc79SEric Van Hensbergen 
342b530cc79SEric Van Hensbergen static struct virtio_device_id id_table[] = {
343b530cc79SEric Van Hensbergen 	{ VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID },
344b530cc79SEric Van Hensbergen 	{ 0 },
345b530cc79SEric Van Hensbergen };
346b530cc79SEric Van Hensbergen 
347b530cc79SEric Van Hensbergen /* The standard "struct lguest_driver": */
348b530cc79SEric Van Hensbergen static struct virtio_driver p9_virtio_drv = {
349b530cc79SEric Van Hensbergen 	.driver.name = 	KBUILD_MODNAME,
350b530cc79SEric Van Hensbergen 	.driver.owner = THIS_MODULE,
351b530cc79SEric Van Hensbergen 	.id_table =	id_table,
352b530cc79SEric Van Hensbergen 	.probe = 	p9_virtio_probe,
353f3933545SEric Van Hensbergen 	.remove =	p9_virtio_remove,
354b530cc79SEric Van Hensbergen };
355b530cc79SEric Van Hensbergen 
356b530cc79SEric Van Hensbergen static struct p9_trans_module p9_virtio_trans = {
357b530cc79SEric Van Hensbergen 	.name = "virtio",
358b530cc79SEric Van Hensbergen 	.create = p9_virtio_create,
3598b81ef58SEric Van Hensbergen 	.close = p9_virtio_close,
36091b8534fSEric Van Hensbergen 	.request = p9_virtio_request,
36191b8534fSEric Van Hensbergen 	.cancel = p9_virtio_cancel,
362e2735b77SEric Van Hensbergen 	.maxsize = PAGE_SIZE*16,
363b530cc79SEric Van Hensbergen 	.def = 0,
36472029fe8STejun Heo 	.owner = THIS_MODULE,
365b530cc79SEric Van Hensbergen };
366b530cc79SEric Van Hensbergen 
367b530cc79SEric Van Hensbergen /* The standard init function */
368b530cc79SEric Van Hensbergen static int __init p9_virtio_init(void)
369b530cc79SEric Van Hensbergen {
370b530cc79SEric Van Hensbergen 	int count;
371b530cc79SEric Van Hensbergen 
372b530cc79SEric Van Hensbergen 	for (count = 0; count < MAX_9P_CHAN; count++)
373b530cc79SEric Van Hensbergen 		channels[count].initialized = false;
374b530cc79SEric Van Hensbergen 
375b530cc79SEric Van Hensbergen 	v9fs_register_trans(&p9_virtio_trans);
376b530cc79SEric Van Hensbergen 	return register_virtio_driver(&p9_virtio_drv);
377b530cc79SEric Van Hensbergen }
378b530cc79SEric Van Hensbergen 
379f3933545SEric Van Hensbergen static void __exit p9_virtio_cleanup(void)
380f3933545SEric Van Hensbergen {
381f3933545SEric Van Hensbergen 	unregister_virtio_driver(&p9_virtio_drv);
38272029fe8STejun Heo 	v9fs_unregister_trans(&p9_virtio_trans);
383f3933545SEric Van Hensbergen }
384f3933545SEric Van Hensbergen 
385b530cc79SEric Van Hensbergen module_init(p9_virtio_init);
386f3933545SEric Van Hensbergen module_exit(p9_virtio_cleanup);
387b530cc79SEric Van Hensbergen 
388b530cc79SEric Van Hensbergen MODULE_DEVICE_TABLE(virtio, id_table);
389b530cc79SEric Van Hensbergen MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
390b530cc79SEric Van Hensbergen MODULE_DESCRIPTION("Virtio 9p Transport");
391b530cc79SEric Van Hensbergen MODULE_LICENSE("GPL");
392