xref: /openbmc/linux/net/9p/trans_virtio.c (revision f75580c4afb72c156746b3fc1ec977b1a85d3dee)
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
600e15597eSAbhishek Kulkarni  * @client: client instance
61ee443996SEric Van Hensbergen  * @vdev: virtio dev associated with this channel
62ee443996SEric Van Hensbergen  * @vq: virtio queue associated with this channel
63ee443996SEric Van Hensbergen  * @sg: scatter gather list which is used to pack a request (protected?)
64ee443996SEric Van Hensbergen  *
65ee443996SEric Van Hensbergen  * We keep all per-channel information in a structure.
66b530cc79SEric Van Hensbergen  * This structure is allocated within the devices dev->mem space.
67b530cc79SEric Van Hensbergen  * A pointer to the structure will get put in the transport private.
68ee443996SEric Van Hensbergen  *
69b530cc79SEric Van Hensbergen  */
70ee443996SEric Van Hensbergen 
71b530cc79SEric Van Hensbergen static struct virtio_chan {
72ee443996SEric Van Hensbergen 	bool initialized;
73ee443996SEric Van Hensbergen 	bool inuse;
74b530cc79SEric Van Hensbergen 
75e2735b77SEric Van Hensbergen 	spinlock_t lock;
76e2735b77SEric Van Hensbergen 
77fea511a6SEric Van Hensbergen 	struct p9_client *client;
78b530cc79SEric Van Hensbergen 	struct virtio_device *vdev;
79e2735b77SEric Van Hensbergen 	struct virtqueue *vq;
80b530cc79SEric Van Hensbergen 
81e2735b77SEric Van Hensbergen 	/* Scatterlist: can be too big for stack. */
82e2735b77SEric Van Hensbergen 	struct scatterlist sg[VIRTQUEUE_NUM];
83b530cc79SEric Van Hensbergen } channels[MAX_9P_CHAN];
84b530cc79SEric Van Hensbergen 
85b530cc79SEric Van Hensbergen /* How many bytes left in this page. */
86b530cc79SEric Van Hensbergen static unsigned int rest_of_page(void *data)
87b530cc79SEric Van Hensbergen {
88b530cc79SEric Van Hensbergen 	return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
89b530cc79SEric Van Hensbergen }
90b530cc79SEric Van Hensbergen 
91ee443996SEric Van Hensbergen /**
92ee443996SEric Van Hensbergen  * p9_virtio_close - reclaim resources of a channel
930e15597eSAbhishek Kulkarni  * @client: client instance
94ee443996SEric Van Hensbergen  *
95ee443996SEric Van Hensbergen  * This reclaims a channel by freeing its resources and
96ee443996SEric Van Hensbergen  * reseting its inuse flag.
97ee443996SEric Van Hensbergen  *
98ee443996SEric Van Hensbergen  */
99ee443996SEric Van Hensbergen 
1008b81ef58SEric Van Hensbergen static void p9_virtio_close(struct p9_client *client)
101b530cc79SEric Van Hensbergen {
1028b81ef58SEric Van Hensbergen 	struct virtio_chan *chan = client->trans;
103b530cc79SEric Van Hensbergen 
104c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
105fb786100SAneesh Kumar K.V 	if (chan)
106b530cc79SEric Van Hensbergen 		chan->inuse = false;
107c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
108b530cc79SEric Van Hensbergen }
109b530cc79SEric Van Hensbergen 
110ee443996SEric Van Hensbergen /**
111ee443996SEric Van Hensbergen  * req_done - callback which signals activity from the server
112ee443996SEric Van Hensbergen  * @vq: virtio queue activity was received on
113ee443996SEric Van Hensbergen  *
114ee443996SEric Van Hensbergen  * This notifies us that the server has triggered some activity
115ee443996SEric Van Hensbergen  * on the virtio channel - most likely a response to request we
116ee443996SEric Van Hensbergen  * sent.  Figure out which requests now have responses and wake up
117ee443996SEric Van Hensbergen  * those threads.
118ee443996SEric Van Hensbergen  *
119ee443996SEric Van Hensbergen  * Bugs: could do with some additional sanity checking, but appears to work.
120ee443996SEric Van Hensbergen  *
121ee443996SEric Van Hensbergen  */
122ee443996SEric Van Hensbergen 
123e2735b77SEric Van Hensbergen static void req_done(struct virtqueue *vq)
124b530cc79SEric Van Hensbergen {
125e2735b77SEric Van Hensbergen 	struct virtio_chan *chan = vq->vdev->priv;
126e2735b77SEric Van Hensbergen 	struct p9_fcall *rc;
127e2735b77SEric Van Hensbergen 	unsigned int len;
128e2735b77SEric Van Hensbergen 	struct p9_req_t *req;
129b530cc79SEric Van Hensbergen 
13091b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, ": request done\n");
13191b8534fSEric Van Hensbergen 
132e2735b77SEric Van Hensbergen 	while ((rc = chan->vq->vq_ops->get_buf(chan->vq, &len)) != NULL) {
13391b8534fSEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS, ": rc %p\n", rc);
13491b8534fSEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS, ": lookup tag %d\n", rc->tag);
135fea511a6SEric Van Hensbergen 		req = p9_tag_lookup(chan->client, rc->tag);
1361bab88b2SLatchesar Ionkov 		req->status = REQ_STATUS_RCVD;
13791b8534fSEric Van Hensbergen 		p9_client_cb(chan->client, req);
138e2735b77SEric Van Hensbergen 	}
139b530cc79SEric Van Hensbergen }
140b530cc79SEric Van Hensbergen 
141ee443996SEric Van Hensbergen /**
142ee443996SEric Van Hensbergen  * pack_sg_list - pack a scatter gather list from a linear buffer
143ee443996SEric Van Hensbergen  * @sg: scatter/gather list to pack into
144ee443996SEric Van Hensbergen  * @start: which segment of the sg_list to start at
145ee443996SEric Van Hensbergen  * @limit: maximum segment to pack data to
146ee443996SEric Van Hensbergen  * @data: data to pack into scatter/gather list
147ee443996SEric Van Hensbergen  * @count: amount of data to pack into the scatter/gather list
148ee443996SEric Van Hensbergen  *
149ee443996SEric Van Hensbergen  * sg_lists have multiple segments of various sizes.  This will pack
150ee443996SEric Van Hensbergen  * arbitrary data into an existing scatter gather list, segmenting the
151ee443996SEric Van Hensbergen  * data as necessary within constraints.
152ee443996SEric Van Hensbergen  *
153ee443996SEric Van Hensbergen  */
154ee443996SEric Van Hensbergen 
155e2735b77SEric Van Hensbergen static int
156e2735b77SEric Van Hensbergen pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
157e2735b77SEric Van Hensbergen 								int count)
158e2735b77SEric Van Hensbergen {
159e2735b77SEric Van Hensbergen 	int s;
160e2735b77SEric Van Hensbergen 	int index = start;
161e2735b77SEric Van Hensbergen 
162e2735b77SEric Van Hensbergen 	while (count) {
163e2735b77SEric Van Hensbergen 		s = rest_of_page(data);
164e2735b77SEric Van Hensbergen 		if (s > count)
165e2735b77SEric Van Hensbergen 			s = count;
166e2735b77SEric Van Hensbergen 		sg_set_buf(&sg[index++], data, s);
167e2735b77SEric Van Hensbergen 		count -= s;
168e2735b77SEric Van Hensbergen 		data += s;
169d6584f3aSJulia Lawall 		BUG_ON(index > limit);
170e2735b77SEric Van Hensbergen 	}
171e2735b77SEric Van Hensbergen 
172e2735b77SEric Van Hensbergen 	return index-start;
173e2735b77SEric Van Hensbergen }
174e2735b77SEric Van Hensbergen 
17591b8534fSEric Van Hensbergen /* We don't currently allow canceling of virtio requests */
17691b8534fSEric Van Hensbergen static int p9_virtio_cancel(struct p9_client *client, struct p9_req_t *req)
17791b8534fSEric Van Hensbergen {
17891b8534fSEric Van Hensbergen 	return 1;
17991b8534fSEric Van Hensbergen }
18091b8534fSEric Van Hensbergen 
181ee443996SEric Van Hensbergen /**
18291b8534fSEric Van Hensbergen  * p9_virtio_request - issue a request
1830e15597eSAbhishek Kulkarni  * @client: client instance issuing the request
1840e15597eSAbhishek Kulkarni  * @req: request to be issued
185ee443996SEric Van Hensbergen  *
186ee443996SEric Van Hensbergen  */
187ee443996SEric Van Hensbergen 
188e2735b77SEric Van Hensbergen static int
18991b8534fSEric Van Hensbergen p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
190e2735b77SEric Van Hensbergen {
191e2735b77SEric Van Hensbergen 	int in, out;
19291b8534fSEric Van Hensbergen 	struct virtio_chan *chan = client->trans;
19391b8534fSEric Van Hensbergen 	char *rdata = (char *)req->rc+sizeof(struct p9_fcall);
194e2735b77SEric Van Hensbergen 
19591b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request\n");
196e2735b77SEric Van Hensbergen 
19791b8534fSEric Van Hensbergen 	out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, req->tc->sdata,
19891b8534fSEric Van Hensbergen 								req->tc->size);
19991b8534fSEric Van Hensbergen 	in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata,
20091b8534fSEric Van Hensbergen 								client->msize);
201e2735b77SEric Van Hensbergen 
202e2735b77SEric Van Hensbergen 	req->status = REQ_STATUS_SENT;
203e2735b77SEric Van Hensbergen 
2043c1b27d5SRusty Russell 	if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, req->tc) < 0) {
205e2735b77SEric Van Hensbergen 		P9_DPRINTK(P9_DEBUG_TRANS,
206e2735b77SEric Van Hensbergen 			"9p debug: virtio rpc add_buf returned failure");
207e2735b77SEric Van Hensbergen 		return -EIO;
208e2735b77SEric Van Hensbergen 	}
209e2735b77SEric Van Hensbergen 
210e2735b77SEric Van Hensbergen 	chan->vq->vq_ops->kick(chan->vq);
211e2735b77SEric Van Hensbergen 
21291b8534fSEric Van Hensbergen 	P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio request kicked\n");
213e2735b77SEric Van Hensbergen 	return 0;
214e2735b77SEric Van Hensbergen }
215e2735b77SEric Van Hensbergen 
216ee443996SEric Van Hensbergen /**
217ee443996SEric Van Hensbergen  * p9_virtio_probe - probe for existence of 9P virtio channels
218ee443996SEric Van Hensbergen  * @vdev: virtio device to probe
219ee443996SEric Van Hensbergen  *
220ee443996SEric Van Hensbergen  * This probes for existing virtio channels.  At present only
221ee443996SEric Van Hensbergen  * a single channel is in use, so in the future more work may need
222ee443996SEric Van Hensbergen  * to be done here.
223ee443996SEric Van Hensbergen  *
224ee443996SEric Van Hensbergen  */
225ee443996SEric Van Hensbergen 
226e2735b77SEric Van Hensbergen static int p9_virtio_probe(struct virtio_device *vdev)
227b530cc79SEric Van Hensbergen {
228b530cc79SEric Van Hensbergen 	int err;
229b530cc79SEric Van Hensbergen 	struct virtio_chan *chan;
230b530cc79SEric Van Hensbergen 	int index;
231b530cc79SEric Van Hensbergen 
232c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
233b530cc79SEric Van Hensbergen 	index = chan_index++;
234b530cc79SEric Van Hensbergen 	chan = &channels[index];
235c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
236b530cc79SEric Van Hensbergen 
237b530cc79SEric Van Hensbergen 	if (chan_index > MAX_9P_CHAN) {
238b530cc79SEric Van Hensbergen 		printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
239b530cc79SEric Van Hensbergen 		BUG();
240b530cc79SEric Van Hensbergen 		err = -ENOMEM;
241b530cc79SEric Van Hensbergen 		goto fail;
242b530cc79SEric Van Hensbergen 	}
243b530cc79SEric Van Hensbergen 
244e2735b77SEric Van Hensbergen 	chan->vdev = vdev;
245e2735b77SEric Van Hensbergen 
246e2735b77SEric Van Hensbergen 	/* We expect one virtqueue, for requests. */
247d2a7dddaSMichael S. Tsirkin 	chan->vq = virtio_find_single_vq(vdev, req_done, "requests");
248e2735b77SEric Van Hensbergen 	if (IS_ERR(chan->vq)) {
249e2735b77SEric Van Hensbergen 		err = PTR_ERR(chan->vq);
250e2735b77SEric Van Hensbergen 		goto out_free_vq;
251b530cc79SEric Van Hensbergen 	}
252e2735b77SEric Van Hensbergen 	chan->vq->vdev->priv = chan;
253e2735b77SEric Van Hensbergen 	spin_lock_init(&chan->lock);
254b530cc79SEric Van Hensbergen 
255e2735b77SEric Van Hensbergen 	sg_init_table(chan->sg, VIRTQUEUE_NUM);
256b530cc79SEric Van Hensbergen 
257b530cc79SEric Van Hensbergen 	chan->inuse = false;
258b530cc79SEric Van Hensbergen 	chan->initialized = true;
259b530cc79SEric Van Hensbergen 	return 0;
260b530cc79SEric Van Hensbergen 
261e2735b77SEric Van Hensbergen out_free_vq:
262d2a7dddaSMichael S. Tsirkin 	vdev->config->del_vqs(vdev);
263b530cc79SEric Van Hensbergen fail:
264c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
265b530cc79SEric Van Hensbergen 	chan_index--;
266c1549497SJosef 'Jeff' Sipek 	mutex_unlock(&virtio_9p_lock);
267b530cc79SEric Van Hensbergen 	return err;
268b530cc79SEric Van Hensbergen }
269b530cc79SEric Van Hensbergen 
270ee443996SEric Van Hensbergen 
271ee443996SEric Van Hensbergen /**
272ee443996SEric Van Hensbergen  * p9_virtio_create - allocate a new virtio channel
2738b81ef58SEric Van Hensbergen  * @client: client instance invoking this transport
274ee443996SEric Van Hensbergen  * @devname: string identifying the channel to connect to (unused)
275ee443996SEric Van Hensbergen  * @args: args passed from sys_mount() for per-transport options (unused)
276ee443996SEric Van Hensbergen  *
277ee443996SEric Van Hensbergen  * This sets up a transport channel for 9p communication.  Right now
278b530cc79SEric Van Hensbergen  * we only match the first available channel, but eventually we couldlook up
279b530cc79SEric Van Hensbergen  * alternate channels by matching devname versus a virtio_config entry.
280b530cc79SEric Van Hensbergen  * We use a simple reference count mechanism to ensure that only a single
281ee443996SEric Van Hensbergen  * mount has a channel open at a time.
282ee443996SEric Van Hensbergen  *
283ee443996SEric Van Hensbergen  * Bugs: doesn't allow identification of a specific channel
284ee443996SEric Van Hensbergen  * to allocate, channels are allocated sequentially. This was
285ee443996SEric Van Hensbergen  * a pragmatic decision to get things rolling, but ideally some
286ee443996SEric Van Hensbergen  * way of identifying the channel to attach to would be nice
287ee443996SEric Van Hensbergen  * if we are going to support multiple channels.
288ee443996SEric Van Hensbergen  *
289ee443996SEric Van Hensbergen  */
290ee443996SEric Van Hensbergen 
2918b81ef58SEric Van Hensbergen static int
2928b81ef58SEric Van Hensbergen p9_virtio_create(struct p9_client *client, const char *devname, char *args)
293b530cc79SEric Van Hensbergen {
294b530cc79SEric Van Hensbergen 	struct virtio_chan *chan = channels;
295e2735b77SEric Van Hensbergen 	int index = 0;
296b530cc79SEric Van Hensbergen 
297c1549497SJosef 'Jeff' Sipek 	mutex_lock(&virtio_9p_lock);
298b530cc79SEric Van Hensbergen 	while (index < MAX_9P_CHAN) {
299*f75580c4SAneesh Kumar K.V 		if (chan->initialized &&
300*f75580c4SAneesh Kumar K.V 			!strcmp(devname, dev_name(&chan->vdev->dev))) {
301*f75580c4SAneesh Kumar K.V 			if (!chan->inuse) {
302b530cc79SEric Van Hensbergen 				chan->inuse = true;
303b530cc79SEric Van Hensbergen 				break;
304*f75580c4SAneesh Kumar K.V 			}
305*f75580c4SAneesh Kumar K.V 		}
306b530cc79SEric Van Hensbergen 		index++;
307b530cc79SEric Van Hensbergen 		chan = &channels[index];
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;
317562ada61SEric Van Hensbergen 	client->status = Connected;
318fea511a6SEric Van Hensbergen 	chan->client = client;
319b530cc79SEric Van Hensbergen 
3208b81ef58SEric Van Hensbergen 	return 0;
321b530cc79SEric Van Hensbergen }
322b530cc79SEric Van Hensbergen 
323ee443996SEric Van Hensbergen /**
324ee443996SEric Van Hensbergen  * p9_virtio_remove - clean up resources associated with a virtio device
325ee443996SEric Van Hensbergen  * @vdev: virtio device to remove
326ee443996SEric Van Hensbergen  *
327ee443996SEric Van Hensbergen  */
328ee443996SEric Van Hensbergen 
329f3933545SEric Van Hensbergen static void p9_virtio_remove(struct virtio_device *vdev)
330f3933545SEric Van Hensbergen {
331f3933545SEric Van Hensbergen 	struct virtio_chan *chan = vdev->priv;
332f3933545SEric Van Hensbergen 
333f3933545SEric Van Hensbergen 	BUG_ON(chan->inuse);
334f3933545SEric Van Hensbergen 
335f3933545SEric Van Hensbergen 	if (chan->initialized) {
336d2a7dddaSMichael S. Tsirkin 		vdev->config->del_vqs(vdev);
337f3933545SEric Van Hensbergen 		chan->initialized = false;
338f3933545SEric Van Hensbergen 	}
339f3933545SEric Van Hensbergen }
340f3933545SEric Van Hensbergen 
341b530cc79SEric Van Hensbergen static struct virtio_device_id id_table[] = {
342b530cc79SEric Van Hensbergen 	{ VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID },
343b530cc79SEric Van Hensbergen 	{ 0 },
344b530cc79SEric Van Hensbergen };
345b530cc79SEric Van Hensbergen 
346b530cc79SEric Van Hensbergen /* The standard "struct lguest_driver": */
347b530cc79SEric Van Hensbergen static struct virtio_driver p9_virtio_drv = {
348b530cc79SEric Van Hensbergen 	.driver.name = 	KBUILD_MODNAME,
349b530cc79SEric Van Hensbergen 	.driver.owner = THIS_MODULE,
350b530cc79SEric Van Hensbergen 	.id_table =	id_table,
351b530cc79SEric Van Hensbergen 	.probe = 	p9_virtio_probe,
352f3933545SEric Van Hensbergen 	.remove =	p9_virtio_remove,
353b530cc79SEric Van Hensbergen };
354b530cc79SEric Van Hensbergen 
355b530cc79SEric Van Hensbergen static struct p9_trans_module p9_virtio_trans = {
356b530cc79SEric Van Hensbergen 	.name = "virtio",
357b530cc79SEric Van Hensbergen 	.create = p9_virtio_create,
3588b81ef58SEric Van Hensbergen 	.close = p9_virtio_close,
35991b8534fSEric Van Hensbergen 	.request = p9_virtio_request,
36091b8534fSEric Van Hensbergen 	.cancel = p9_virtio_cancel,
361e2735b77SEric Van Hensbergen 	.maxsize = PAGE_SIZE*16,
362b530cc79SEric Van Hensbergen 	.def = 0,
36372029fe8STejun Heo 	.owner = THIS_MODULE,
364b530cc79SEric Van Hensbergen };
365b530cc79SEric Van Hensbergen 
366b530cc79SEric Van Hensbergen /* The standard init function */
367b530cc79SEric Van Hensbergen static int __init p9_virtio_init(void)
368b530cc79SEric Van Hensbergen {
369b530cc79SEric Van Hensbergen 	int count;
370b530cc79SEric Van Hensbergen 
371b530cc79SEric Van Hensbergen 	for (count = 0; count < MAX_9P_CHAN; count++)
372b530cc79SEric Van Hensbergen 		channels[count].initialized = false;
373b530cc79SEric Van Hensbergen 
374b530cc79SEric Van Hensbergen 	v9fs_register_trans(&p9_virtio_trans);
375b530cc79SEric Van Hensbergen 	return register_virtio_driver(&p9_virtio_drv);
376b530cc79SEric Van Hensbergen }
377b530cc79SEric Van Hensbergen 
378f3933545SEric Van Hensbergen static void __exit p9_virtio_cleanup(void)
379f3933545SEric Van Hensbergen {
380f3933545SEric Van Hensbergen 	unregister_virtio_driver(&p9_virtio_drv);
38172029fe8STejun Heo 	v9fs_unregister_trans(&p9_virtio_trans);
382f3933545SEric Van Hensbergen }
383f3933545SEric Van Hensbergen 
384b530cc79SEric Van Hensbergen module_init(p9_virtio_init);
385f3933545SEric Van Hensbergen module_exit(p9_virtio_cleanup);
386b530cc79SEric Van Hensbergen 
387b530cc79SEric Van Hensbergen MODULE_DEVICE_TABLE(virtio, id_table);
388b530cc79SEric Van Hensbergen MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
389b530cc79SEric Van Hensbergen MODULE_DESCRIPTION("Virtio 9p Transport");
390b530cc79SEric Van Hensbergen MODULE_LICENSE("GPL");
391