blob: 42adc052b149251a46e3ac8a1bf039c91f00417f [file] [log] [blame]
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -05001/*
2 * The Guest 9p transport driver
3 *
Eric Van Hensbergene2735b72008-02-06 19:25:58 -06004 * This is a block based transport driver based on the lguest block driver
5 * code.
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -05006 *
7 */
8/*
9 * Copyright (C) 2007 Eric Van Hensbergen, IBM Corporation
10 *
11 * Based on virtio console driver
12 * Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to:
25 * Free Software Foundation
26 * 51 Franklin Street, Fifth Floor
27 * Boston, MA 02111-1301 USA
28 *
29 */
30
31#include <linux/in.h>
32#include <linux/module.h>
33#include <linux/net.h>
34#include <linux/ipv6.h>
35#include <linux/errno.h>
36#include <linux/kernel.h>
37#include <linux/un.h>
38#include <linux/uaccess.h>
39#include <linux/inet.h>
40#include <linux/idr.h>
41#include <linux/file.h>
42#include <net/9p/9p.h>
43#include <linux/parser.h>
44#include <net/9p/transport.h>
45#include <linux/scatterlist.h>
46#include <linux/virtio.h>
47#include <linux/virtio_9p.h>
48
Eric Van Hensbergene2735b72008-02-06 19:25:58 -060049#define VIRTQUEUE_NUM 128
50
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -050051/* a single mutex to manage channel initialization and attachment */
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -060052static DEFINE_MUTEX(virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -050053/* global which tracks highest initialized channel */
54static int chan_index;
55
Eric Van Hensbergene2735b72008-02-06 19:25:58 -060056#define P9_INIT_MAXTAG 16
57
Eric Van Hensbergenee443992008-03-05 07:08:09 -060058
59/**
60 * enum p9_req_status_t - virtio request status
61 * @REQ_STATUS_IDLE: request slot unused
62 * @REQ_STATUS_SENT: request sent to server
63 * @REQ_STATUS_RCVD: response received from server
64 * @REQ_STATUS_FLSH: request has been flushed
65 *
66 * The @REQ_STATUS_IDLE state is used to mark a request slot as unused
67 * but use is actually tracked by the idpool structure which handles tag
68 * id allocation.
69 *
70 */
71
72enum p9_req_status_t {
73 REQ_STATUS_IDLE,
74 REQ_STATUS_SENT,
75 REQ_STATUS_RCVD,
76 REQ_STATUS_FLSH,
77};
78
79/**
80 * struct p9_req_t - virtio request slots
81 * @status: status of this request slot
82 * @wq: wait_queue for the client to block on for this request
83 *
84 * The virtio transport uses an array to track outstanding requests
85 * instead of a list. While this may incurr overhead during initial
86 * allocation or expansion, it makes request lookup much easier as the
87 * tag id is a index into an array. (We use tag+1 so that we can accomodate
88 * the -1 tag for the T_VERSION request).
89 * This also has the nice effect of only having to allocate wait_queues
90 * once, instead of constantly allocating and freeing them. Its possible
91 * other resources could benefit from this scheme as well.
92 *
93 */
Eric Van Hensbergene2735b72008-02-06 19:25:58 -060094
95struct p9_req_t {
96 int status;
97 wait_queue_head_t *wq;
98};
99
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600100/**
101 * struct virtio_chan - per-instance transport information
102 * @initialized: whether the channel is initialized
103 * @inuse: whether the channel is in use
104 * @lock: protects multiple elements within this structure
105 * @vdev: virtio dev associated with this channel
106 * @vq: virtio queue associated with this channel
107 * @tagpool: accounting for tag ids (and request slots)
108 * @reqs: array of request slots
109 * @max_tag: current number of request_slots allocated
110 * @sg: scatter gather list which is used to pack a request (protected?)
111 *
112 * We keep all per-channel information in a structure.
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500113 * This structure is allocated within the devices dev->mem space.
114 * A pointer to the structure will get put in the transport private.
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600115 *
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500116 */
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600117
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500118static struct virtio_chan {
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600119 bool initialized;
120 bool inuse;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500121
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600122 spinlock_t lock;
123
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500124 struct virtio_device *vdev;
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600125 struct virtqueue *vq;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500126
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600127 struct p9_idpool *tagpool;
128 struct p9_req_t *reqs;
129 int max_tag;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500130
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600131 /* Scatterlist: can be too big for stack. */
132 struct scatterlist sg[VIRTQUEUE_NUM];
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500133} channels[MAX_9P_CHAN];
134
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600135/**
136 * p9_lookup_tag - Lookup requests by tag
137 * @c: virtio channel to lookup tag within
138 * @tag: numeric id for transaction
139 *
140 * this is a simple array lookup, but will grow the
141 * request_slots as necessary to accomodate transaction
142 * ids which did not previously have a slot.
143 *
144 * Bugs: there is currently no upper limit on request slots set
145 * here, but that should be constrained by the id accounting.
146 */
147
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600148static struct p9_req_t *p9_lookup_tag(struct virtio_chan *c, u16 tag)
149{
150 /* This looks up the original request by tag so we know which
151 * buffer to read the data into */
152 tag++;
153
154 while (tag >= c->max_tag) {
155 int old_max = c->max_tag;
156 int count;
157
158 if (c->max_tag)
159 c->max_tag *= 2;
160 else
161 c->max_tag = P9_INIT_MAXTAG;
162
163 c->reqs = krealloc(c->reqs, sizeof(struct p9_req_t)*c->max_tag,
164 GFP_ATOMIC);
165 if (!c->reqs) {
166 printk(KERN_ERR "Couldn't grow tag array\n");
167 BUG();
168 }
169 for (count = old_max; count < c->max_tag; count++) {
170 c->reqs[count].status = REQ_STATUS_IDLE;
Adrian Bunk15e29b8b2008-02-19 16:25:30 -0800171 c->reqs[count].wq = kmalloc(sizeof(wait_queue_head_t),
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600172 GFP_ATOMIC);
173 if (!c->reqs[count].wq) {
174 printk(KERN_ERR "Couldn't grow tag array\n");
175 BUG();
176 }
177 init_waitqueue_head(c->reqs[count].wq);
178 }
179 }
180
181 return &c->reqs[tag];
182}
183
184
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500185/* How many bytes left in this page. */
186static unsigned int rest_of_page(void *data)
187{
188 return PAGE_SIZE - ((unsigned long)data % PAGE_SIZE);
189}
190
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600191/**
192 * p9_virtio_close - reclaim resources of a channel
193 * @trans: transport state
194 *
195 * This reclaims a channel by freeing its resources and
196 * reseting its inuse flag.
197 *
198 */
199
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500200static void p9_virtio_close(struct p9_trans *trans)
201{
202 struct virtio_chan *chan = trans->priv;
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600203 int count;
Steven Rostedtd0c44712008-05-03 17:29:50 -0500204 unsigned long flags;
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600205
206 spin_lock_irqsave(&chan->lock, flags);
207 p9_idpool_destroy(chan->tagpool);
208 for (count = 0; count < chan->max_tag; count++)
209 kfree(chan->reqs[count].wq);
210 kfree(chan->reqs);
211 chan->max_tag = 0;
212 spin_unlock_irqrestore(&chan->lock, flags);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500213
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600214 mutex_lock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500215 chan->inuse = false;
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600216 mutex_unlock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500217
218 kfree(trans);
219}
220
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600221/**
222 * req_done - callback which signals activity from the server
223 * @vq: virtio queue activity was received on
224 *
225 * This notifies us that the server has triggered some activity
226 * on the virtio channel - most likely a response to request we
227 * sent. Figure out which requests now have responses and wake up
228 * those threads.
229 *
230 * Bugs: could do with some additional sanity checking, but appears to work.
231 *
232 */
233
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600234static void req_done(struct virtqueue *vq)
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500235{
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600236 struct virtio_chan *chan = vq->vdev->priv;
237 struct p9_fcall *rc;
238 unsigned int len;
239 unsigned long flags;
240 struct p9_req_t *req;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500241
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600242 spin_lock_irqsave(&chan->lock, flags);
243 while ((rc = chan->vq->vq_ops->get_buf(chan->vq, &len)) != NULL) {
244 req = p9_lookup_tag(chan, rc->tag);
245 req->status = REQ_STATUS_RCVD;
246 wake_up(req->wq);
247 }
248 /* In case queue is stopped waiting for more buffers. */
249 spin_unlock_irqrestore(&chan->lock, flags);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500250}
251
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600252/**
253 * pack_sg_list - pack a scatter gather list from a linear buffer
254 * @sg: scatter/gather list to pack into
255 * @start: which segment of the sg_list to start at
256 * @limit: maximum segment to pack data to
257 * @data: data to pack into scatter/gather list
258 * @count: amount of data to pack into the scatter/gather list
259 *
260 * sg_lists have multiple segments of various sizes. This will pack
261 * arbitrary data into an existing scatter gather list, segmenting the
262 * data as necessary within constraints.
263 *
264 */
265
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600266static int
267pack_sg_list(struct scatterlist *sg, int start, int limit, char *data,
268 int count)
269{
270 int s;
271 int index = start;
272
273 while (count) {
274 s = rest_of_page(data);
275 if (s > count)
276 s = count;
277 sg_set_buf(&sg[index++], data, s);
278 count -= s;
279 data += s;
Julia Lawalld6584f32008-02-17 18:42:53 -0800280 BUG_ON(index > limit);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600281 }
282
283 return index-start;
284}
285
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600286/**
287 * p9_virtio_rpc - issue a request and wait for a response
288 * @t: transport state
289 * @tc: &p9_fcall request to transmit
290 * @rc: &p9_fcall to put reponse into
291 *
292 */
293
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600294static int
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600295p9_virtio_rpc(struct p9_trans *t, struct p9_fcall *tc, struct p9_fcall **rc)
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600296{
297 int in, out;
298 int n, err, size;
299 struct virtio_chan *chan = t->priv;
300 char *rdata;
301 struct p9_req_t *req;
302 unsigned long flags;
303
304 if (*rc == NULL) {
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600305 *rc = kmalloc(sizeof(struct p9_fcall) + t->msize, GFP_KERNEL);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600306 if (!*rc)
307 return -ENOMEM;
308 }
309
310 rdata = (char *)*rc+sizeof(struct p9_fcall);
311
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600312 n = P9_NOTAG;
313 if (tc->id != P9_TVERSION) {
314 n = p9_idpool_get(chan->tagpool);
315 if (n < 0)
316 return -ENOMEM;
317 }
318
Eric Van Hensbergen7c7d90f2008-02-06 19:25:07 -0600319 spin_lock_irqsave(&chan->lock, flags);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600320 req = p9_lookup_tag(chan, n);
321 spin_unlock_irqrestore(&chan->lock, flags);
322
323 p9_set_tag(tc, n);
324
325 P9_DPRINTK(P9_DEBUG_TRANS, "9p debug: virtio rpc tag %d\n", n);
326
327 out = pack_sg_list(chan->sg, 0, VIRTQUEUE_NUM, tc->sdata, tc->size);
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600328 in = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM-out, rdata, t->msize);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600329
330 req->status = REQ_STATUS_SENT;
331
332 if (chan->vq->vq_ops->add_buf(chan->vq, chan->sg, out, in, tc)) {
333 P9_DPRINTK(P9_DEBUG_TRANS,
334 "9p debug: virtio rpc add_buf returned failure");
335 return -EIO;
336 }
337
338 chan->vq->vq_ops->kick(chan->vq);
339
340 wait_event(*req->wq, req->status == REQ_STATUS_RCVD);
341
342 size = le32_to_cpu(*(__le32 *) rdata);
343
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600344 err = p9_deserialize_fcall(rdata, size, *rc, t->extended);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600345 if (err < 0) {
346 P9_DPRINTK(P9_DEBUG_TRANS,
347 "9p debug: virtio rpc deserialize returned %d\n", err);
348 return err;
349 }
350
351#ifdef CONFIG_NET_9P_DEBUG
352 if ((p9_debug_level&P9_DEBUG_FCALL) == P9_DEBUG_FCALL) {
353 char buf[150];
354
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600355 p9_printfcall(buf, sizeof(buf), *rc, t->extended);
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600356 printk(KERN_NOTICE ">>> %p %s\n", t, buf);
357 }
358#endif
359
360 if (n != P9_NOTAG && p9_idpool_check(n, chan->tagpool))
361 p9_idpool_put(n, chan->tagpool);
362
363 req->status = REQ_STATUS_IDLE;
364
365 return 0;
366}
367
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600368/**
369 * p9_virtio_probe - probe for existence of 9P virtio channels
370 * @vdev: virtio device to probe
371 *
372 * This probes for existing virtio channels. At present only
373 * a single channel is in use, so in the future more work may need
374 * to be done here.
375 *
376 */
377
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600378static int p9_virtio_probe(struct virtio_device *vdev)
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500379{
380 int err;
381 struct virtio_chan *chan;
382 int index;
383
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600384 mutex_lock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500385 index = chan_index++;
386 chan = &channels[index];
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600387 mutex_unlock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500388
389 if (chan_index > MAX_9P_CHAN) {
390 printk(KERN_ERR "9p: virtio: Maximum channels exceeded\n");
391 BUG();
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500392 err = -ENOMEM;
393 goto fail;
394 }
395
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600396 chan->vdev = vdev;
397
398 /* We expect one virtqueue, for requests. */
399 chan->vq = vdev->config->find_vq(vdev, 0, req_done);
400 if (IS_ERR(chan->vq)) {
401 err = PTR_ERR(chan->vq);
402 goto out_free_vq;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500403 }
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600404 chan->vq->vdev->priv = chan;
405 spin_lock_init(&chan->lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500406
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600407 sg_init_table(chan->sg, VIRTQUEUE_NUM);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500408
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500409 chan->inuse = false;
410 chan->initialized = true;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500411 return 0;
412
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600413out_free_vq:
414 vdev->config->del_vq(chan->vq);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500415fail:
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600416 mutex_lock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500417 chan_index--;
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600418 mutex_unlock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500419 return err;
420}
421
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600422
423/**
424 * p9_virtio_create - allocate a new virtio channel
425 * @devname: string identifying the channel to connect to (unused)
426 * @args: args passed from sys_mount() for per-transport options (unused)
427 * @msize: requested maximum packet size
428 * @extended: 9p2000.u enabled flag
429 *
430 * This sets up a transport channel for 9p communication. Right now
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500431 * we only match the first available channel, but eventually we couldlook up
432 * alternate channels by matching devname versus a virtio_config entry.
433 * We use a simple reference count mechanism to ensure that only a single
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600434 * mount has a channel open at a time.
435 *
436 * Bugs: doesn't allow identification of a specific channel
437 * to allocate, channels are allocated sequentially. This was
438 * a pragmatic decision to get things rolling, but ideally some
439 * way of identifying the channel to attach to would be nice
440 * if we are going to support multiple channels.
441 *
442 */
443
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600444static struct p9_trans *
445p9_virtio_create(const char *devname, char *args, int msize,
446 unsigned char extended)
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500447{
448 struct p9_trans *trans;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500449 struct virtio_chan *chan = channels;
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600450 int index = 0;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500451
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600452 mutex_lock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500453 while (index < MAX_9P_CHAN) {
454 if (chan->initialized && !chan->inuse) {
455 chan->inuse = true;
456 break;
457 } else {
458 index++;
459 chan = &channels[index];
460 }
461 }
Josef 'Jeff' Sipekc1549492008-03-07 11:39:13 -0600462 mutex_unlock(&virtio_9p_lock);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500463
464 if (index >= MAX_9P_CHAN) {
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600465 printk(KERN_ERR "9p: no channels available\n");
466 return ERR_PTR(-ENODEV);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500467 }
468
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600469 chan->tagpool = p9_idpool_create();
470 if (IS_ERR(chan->tagpool)) {
471 printk(KERN_ERR "9p: couldn't allocate tagpool\n");
472 return ERR_PTR(-ENOMEM);
473 }
474 p9_idpool_get(chan->tagpool); /* reserve tag 0 */
475 chan->max_tag = 0;
476 chan->reqs = NULL;
477
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500478 trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL);
479 if (!trans) {
480 printk(KERN_ERR "9p: couldn't allocate transport\n");
481 return ERR_PTR(-ENOMEM);
482 }
Eric Van Hensbergen8a0dc952008-02-06 19:25:03 -0600483 trans->extended = extended;
484 trans->msize = msize;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500485 trans->close = p9_virtio_close;
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600486 trans->rpc = p9_virtio_rpc;
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500487 trans->priv = chan;
488
489 return trans;
490}
491
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600492/**
493 * p9_virtio_remove - clean up resources associated with a virtio device
494 * @vdev: virtio device to remove
495 *
496 */
497
Eric Van Hensbergenf3933542008-02-06 19:25:04 -0600498static void p9_virtio_remove(struct virtio_device *vdev)
499{
500 struct virtio_chan *chan = vdev->priv;
501
502 BUG_ON(chan->inuse);
503
504 if (chan->initialized) {
505 vdev->config->del_vq(chan->vq);
506 chan->initialized = false;
507 }
508}
509
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500510#define VIRTIO_ID_9P 9
511
512static struct virtio_device_id id_table[] = {
513 { VIRTIO_ID_9P, VIRTIO_DEV_ANY_ID },
514 { 0 },
515};
516
517/* The standard "struct lguest_driver": */
518static struct virtio_driver p9_virtio_drv = {
519 .driver.name = KBUILD_MODNAME,
520 .driver.owner = THIS_MODULE,
521 .id_table = id_table,
522 .probe = p9_virtio_probe,
Eric Van Hensbergenf3933542008-02-06 19:25:04 -0600523 .remove = p9_virtio_remove,
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500524};
525
526static struct p9_trans_module p9_virtio_trans = {
527 .name = "virtio",
528 .create = p9_virtio_create,
Eric Van Hensbergene2735b72008-02-06 19:25:58 -0600529 .maxsize = PAGE_SIZE*16,
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500530 .def = 0,
531};
532
533/* The standard init function */
534static int __init p9_virtio_init(void)
535{
536 int count;
537
538 for (count = 0; count < MAX_9P_CHAN; count++)
539 channels[count].initialized = false;
540
541 v9fs_register_trans(&p9_virtio_trans);
542 return register_virtio_driver(&p9_virtio_drv);
543}
544
Eric Van Hensbergenf3933542008-02-06 19:25:04 -0600545static void __exit p9_virtio_cleanup(void)
546{
547 unregister_virtio_driver(&p9_virtio_drv);
548}
549
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500550module_init(p9_virtio_init);
Eric Van Hensbergenf3933542008-02-06 19:25:04 -0600551module_exit(p9_virtio_cleanup);
Eric Van Hensbergenb530cc72007-10-23 13:47:31 -0500552
553MODULE_DEVICE_TABLE(virtio, id_table);
554MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
555MODULE_DESCRIPTION("Virtio 9p Transport");
556MODULE_LICENSE("GPL");