From: arnd@arndb.de
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: virtualization@lists.linux-foundation.org
Subject: [RFC 2/4] Convert virtio_net to new virtio bus
Date: Fri, 06 Jul 2007 14:42:02 +0200 [thread overview]
Message-ID: <20070706125717.630165348@arndb.de> (raw)
In-Reply-To: 20070706124200.988637662@arndb.de
[-- Attachment #1: virtnet-iobus.diff --]
[-- Type: text/plain, Size: 3876 bytes --]
This converts the virtio_net driver from Rusty's
draft III implementation to use the generic bus.
Since every device needs to get its MAC address from
somewhere, we read it from the virtio configuration
space. It's up to the virtio host to fill in valid
data here.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Index: linux-2.6/drivers/net/virtio_net.c
===================================================================
--- linux-2.6.orig/drivers/net/virtio_net.c
+++ linux-2.6/drivers/net/virtio_net.c
@@ -43,7 +43,7 @@ struct virtnet_info
static bool skb_xmit_done(struct virtio_device *vdev)
{
- struct virtnet_info *vi = vdev->priv;
+ struct virtnet_info *vi = vdev->dev.driver_data;
/* In case we were waiting for output buffers. */
netif_wake_queue(vi->ndev);
@@ -100,7 +100,7 @@ static void try_fill_recv(struct virtnet
static bool skb_recv_done(struct virtio_device *vdev)
{
- struct virtnet_info *vi = vdev->priv;
+ struct virtnet_info *vi = vdev->dev.driver_data;
netif_rx_schedule(vi->ndev);
/* Suppress further interrupts. */
@@ -217,21 +217,17 @@ static int virtnet_close(struct net_devi
return 0;
}
-static struct virtio_driver_ops virtnet_ops = {
- .in = skb_recv_done,
- .out = skb_xmit_done,
-};
-
-struct net_device *virtnet_probe(struct virtio_device *vdev,
- const u8 mac[ETH_ALEN])
+static int virtnet_probe(struct device *self)
{
+ struct virtio_device *vdev = to_virtio_dev(self);
+ const u8 *mac = (void *)&vdev->config.driver;
int err;
struct net_device *dev;
struct virtnet_info *vi;
dev = alloc_etherdev(sizeof(struct virtnet_info));
if (!dev)
- return ERR_PTR(-ENOMEM);
+ return -ENOMEM;
SET_MODULE_OWNER(dev);
@@ -242,13 +238,12 @@ struct net_device *virtnet_probe(struct
dev->poll = virtnet_poll;
dev->hard_start_xmit = start_xmit;
dev->weight = 16;
- SET_NETDEV_DEV(dev, vdev->dev);
+ SET_NETDEV_DEV(dev, &vdev->dev);
vi = netdev_priv(dev);
vi->vdev = vdev;
vi->ndev = dev;
- vdev->priv = vi;
- vdev->driver_ops = &virtnet_ops;
+ vdev->dev.driver_data = vi;
skb_queue_head_init(&vi->recv);
skb_queue_head_init(&vi->send);
@@ -258,20 +253,49 @@ struct net_device *virtnet_probe(struct
goto free;
}
pr_debug("virtnet: registered device %s\n", dev->name);
- return dev;
+ return 0;
free:
free_netdev(dev);
- return ERR_PTR(err);
+ return err;
}
-EXPORT_SYMBOL_GPL(virtnet_probe);
-void virtnet_remove(struct net_device *dev)
+int virtnet_remove(struct device *dev)
{
- unregister_netdev(dev);
- free_netdev(dev);
+ struct virtnet_info *vi = dev->driver_data;
+ unregister_netdev(vi->ndev);
+ free_netdev(vi->ndev);
+ return 0;
+}
+
+static struct virtio_device_id virtnet_device_ids[] = {
+ { .device_type = "virtnet" },
+ { },
+};
+
+static struct virtio_driver virtio_net = {
+ .ids = virtnet_device_ids,
+ .drv = {
+ .name = "virtnet",
+ .owner = THIS_MODULE,
+ .probe = virtnet_probe,
+ .remove = virtnet_remove,
+ },
+ .in = skb_recv_done,
+ .out = skb_xmit_done,
+};
+
+static int __init virtnet_init(void)
+{
+ return virtio_driver_register(&virtio_net);
+}
+module_init(virtnet_init);
+
+static void __exit virtnet_exit(void)
+{
+ return virtio_driver_unregister(&virtio_net);
}
-EXPORT_SYMBOL_GPL(virtnet_remove);
+module_exit(virtnet_exit);
MODULE_DESCRIPTION("Virtio network driver");
MODULE_LICENSE("GPL");
Index: linux-2.6/include/linux/virtio_net.h
===================================================================
--- linux-2.6.orig/include/linux/virtio_net.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _LINUX_VIRTIO_NET_H
-#define _LINUX_VIRTIO_NET_H
-#include <linux/types.h>
-#include <linux/etherdevice.h>
-struct net_device;
-struct virtio_device;
-
-struct net_device *virtnet_probe(struct virtio_device *vdev,
- const u8 mac[ETH_ALEN]);
-void virtnet_remove(struct net_device *dev);
-
-#endif /* _LINUX_VIRTIO_NET_H */
--
next prev parent reply other threads:[~2007-07-06 12:42 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-06 12:42 [RFC 0/4] Using a generic bus_type for virtio arnd
2007-07-06 12:42 ` [RFC 1/4] New virtio bus driver arnd
2007-07-08 9:59 ` Avi Kivity
2007-07-08 15:29 ` Arnd Bergmann
2007-07-08 15:48 ` Avi Kivity
2007-07-08 20:29 ` Arnd Bergmann
2007-07-08 23:42 ` Rusty Russell
2007-07-09 6:49 ` Avi Kivity
2007-07-09 11:18 ` Arnd Bergmann
2007-07-09 11:41 ` Avi Kivity
2007-07-09 11:38 ` Arnd Bergmann
2007-07-09 12:09 ` Avi Kivity
2007-07-09 14:24 ` Arnd Bergmann
2007-07-09 14:56 ` Avi Kivity
2007-07-09 16:33 ` Arnd Bergmann
2007-07-10 1:53 ` Rusty Russell
2007-07-10 7:56 ` Avi Kivity
2007-07-10 1:17 ` Rusty Russell
2007-07-10 6:06 ` Avi Kivity
2007-07-06 12:42 ` arnd [this message]
2007-07-06 12:42 ` [RFC 3/4] Convert virtio_blk to new virtio bus arnd
2007-07-06 12:42 ` [RFC 4/4] Example virtio host implementation, using chardev arnd
2007-07-08 2:15 ` [RFC 0/4] Using a generic bus_type for virtio Rusty Russell
2007-07-08 9:45 ` Avi Kivity
2007-07-08 15:55 ` Arnd Bergmann
2007-07-08 9:42 ` Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070706125717.630165348@arndb.de \
--to=arnd@arndb.de \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).