29 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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>
42 #include <linux/slab.h>
49 #include <linux/virtio.h>
53 #define VIRTQUEUE_NUM 128
102 static struct list_head virtio_chan_list;
105 static unsigned int rest_of_page(
void *
data)
156 spin_unlock_irqrestore(&chan->
lock, flags);
160 spin_unlock_irqrestore(&chan->
lock, flags);
192 s = rest_of_page(data);
196 sg_set_buf(&sg[index++], data, s);
221 pack_sg_list_p(
struct scatterlist *sg,
int start,
int limit,
222 struct page **
pdata,
int nr_pages,
char *data,
int count)
228 BUG_ON(nr_pages > (limit - start));
235 s = rest_of_page(data);
238 sg_set_page(&sg[index++], pdata[i++], s, data_off);
244 return index -
start;
269 out = pack_sg_list(chan->
sg, 0,
272 in = pack_sg_list(chan->
sg, out,
280 spin_unlock_irqrestore(&chan->
lock, flags);
289 spin_unlock_irqrestore(&chan->
lock, flags);
291 "virtio rpc add_buf returned failure\n");
296 spin_unlock_irqrestore(&chan->
lock, flags);
302 static int p9_get_mapped_pages(
struct virtio_chan *chan,
304 int nr_pages,
int write,
int kern_buf)
325 int count = nr_pages;
327 s = rest_of_page(data);
350 char *uidata,
char *uodata,
int inlen,
351 int outlen,
int in_hdr_len,
int kern_buf)
355 int in_nr_pages = 0, out_nr_pages = 0;
363 out_pages =
kmalloc(
sizeof(
struct page *) * out_nr_pages,
369 out_nr_pages = p9_get_mapped_pages(chan, out_pages, uodata,
370 out_nr_pages, 0, kern_buf);
371 if (out_nr_pages < 0) {
380 in_pages =
kmalloc(
sizeof(
struct page *) * in_nr_pages,
386 in_nr_pages = p9_get_mapped_pages(chan, in_pages, uidata,
387 in_nr_pages, 1, kern_buf);
388 if (in_nr_pages < 0) {
399 out = pack_sg_list(chan->
sg, 0,
404 out_pages, out_nr_pages, uodata, outlen);
412 in = pack_sg_list(chan->
sg, out,
416 in_pages, in_nr_pages, uidata, inlen);
423 spin_unlock_irqrestore(&chan->
lock, flags);
430 goto req_retry_pinned;
432 spin_unlock_irqrestore(&chan->
lock, flags);
434 "virtio rpc add_buf returned failure\n");
440 spin_unlock_irqrestore(&chan->
lock, flags);
496 pr_err(
"Failed to allocate virtio 9P channel\n");
504 chan->
vq = virtio_find_single_vq(vdev, req_done,
"requests");
505 if (IS_ERR(chan->
vq)) {
506 err = PTR_ERR(chan->
vq);
509 chan->
vq->vdev->priv = chan;
518 &tag_len,
sizeof(tag_len));
554 vdev->
config->del_vqs(vdev);
576 p9_virtio_create(
struct p9_client *client,
const char *devname,
char *args)
597 pr_err(
"no channels available\n");
601 client->
trans = (
void *)chan;
619 p9_virtio_close(chan->
client);
620 vdev->
config->del_vqs(vdev);
645 .driver.name = KBUILD_MODNAME,
648 .probe = p9_virtio_probe,
649 .remove = p9_virtio_remove,
654 .create = p9_virtio_create,
655 .close = p9_virtio_close,
656 .request = p9_virtio_request,
657 .zc_request = p9_virtio_zc_request,
658 .cancel = p9_virtio_cancel,
671 static int __init p9_virtio_init(
void)
673 INIT_LIST_HEAD(&virtio_chan_list);
679 static void __exit p9_virtio_cleanup(
void)