net: add virtio network driver
Subsystems (4)
PATCH 1/1 net: add virtio network driver
This gives virtio-enabled boards an easy route to network connectivity:
qemu-system-aarch64 -M virt -serial mon:stdio -trace file=/dev/null \ -kernel images/barebox-dt-2nd.img -cpu cortex-a57 -nographic \ -device virtio-net-device,netdev=network0 -netdev tap,id=network0,ifname=tap0
The tap0 interface created by QEMU can then be bridged/listened on.
Signed-off-by Ahmad Fatoum <[email protected]>
--- Documentation/user/virtio.rst | 2 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/virtio.c | 236 +++++++++++++++++++++ include/linux/virtio_config.h | 7 +- include/uapi/linux/virtio_net.h | 358 ++++++++++++++++++++++++++++++++ 6 files changed, 608 insertions(+), 3 deletions(-) create mode 100644 drivers/net/virtio.c create mode 100644 include/uapi/linux/virtio_net.h
Documentation/user/virtio.rst +1 -1
@@ -35,7 +35,7 @@ queues configuration and buffer transfers are nearly identical. Both MMIO and non-legacy PCI are supported in barebox. The VirtIO spec defines a lots of VirtIO device types, however at present only -block, console, input and RNG devices are supported. +block, network, console, input and RNG devices are supported. Build Instructions ------------------
drivers/net/Kconfig +7 -0
@@ -258,6 +258,13 @@ config DRIVER_NET_EFI_SNP bool "EFI SNP ethernet driver" depends on EFI_BOOTUP +config DRIVER_NET_VIRTIO + bool "virtio net driver" + depends on VIRTIO + help + This is the virtual net driver for virtio. It can be used with + QEMU based targets. + config DRIVER_NET_AG71XX bool "Atheros AG71xx ethernet driver" depends on MACH_MIPS_ATH79
drivers/net/Makefile +1 -0
@@ -36,4 +36,5 @@ obj-$(CONFIG_DRIVER_NET_SMC91111) += smc91111.o obj-$(CONFIG_DRIVER_NET_TAP) += tap.o obj-$(CONFIG_DRIVER_NET_TSE) += altera_tse.o obj-$(CONFIG_DRIVER_NET_EFI_SNP) += efi-snp.o +obj-$(CONFIG_DRIVER_NET_VIRTIO) += virtio.o obj-$(CONFIG_DRIVER_NET_AG71XX) += ag71xx.o
drivers/net/virtio.c new file +236 -0
236 lines not on this page · raw message
include/linux/virtio_config.h +5 -2
@@ -232,8 +232,11 @@ static inline int virtio_get_config(struct virtio_device *vdev, unsigned int off* @len: the length of the buffer * @return 0 if OK, -ve on error */ -int virtio_set_config (struct virtio_device *vdev,unsigned int offset, -void *buf,unsigned int len); +static inline int virtio_set_config (struct virtio_device *vdev,unsigned int offset, +void *buf,unsigned int len) +{ +return vdev->config->set_config (vdev, offset, buf, len); +}/** * virtio_find_vqs() - find virtqueues and instantiate them
include/uapi/linux/virtio_net.h new file +358 -0
358 lines not on this page · raw message
Signature · 7 lines
2.33.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/1 fixup! net: add virtio network driver
We already stop the virtio device. Let's clean up the rest too and unregister the network interface and free the private data.
Signed-off-by Ahmad Fatoum <[email protected]>
--- drivers/net/virtio.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/net/virtio.c +7 -0
@@ -171,6 +171,8 @@ static int virtio_net_probe(struct virtio_device *vdev) priv =xzalloc (sizeof (*priv)); + vdev->priv = priv; +/* * For v1.0 compliant device, it always assumes the member * 'num_buffers' exists in the struct virtio_net_hdr while
@@ -205,8 +207,13 @@ static int virtio_net_probe(struct virtio_device *vdev)static void virtio_net_remove (struct virtio_device *vdev) { +struct virtio_net_priv *priv = vdev->priv; + vdev->config->reset (vdev); +eth_unregister (&priv->edev); vdev->config->del_vqs (vdev); + +free (priv); }/*
Signature · 7 lines
2.30.2 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Sascha Hauer
AppliedQuoted 9 lines · Ahmad Fatoum
This gives virtio-enabled boards an easy route to network connectivity:
qemu-system-aarch64 -M virt -serial mon:stdio -trace file=/dev/null \ -kernel images/barebox-dt-2nd.img -cpu cortex-a57 -nographic \ -device virtio-net-device,netdev=network0 -netdev tap,id=network0,ifname=tap0The tap0 interface created by QEMU can then be bridged/listened on.
Signed-off-by Ahmad Fatoum <[email protected]>
Quoted 10 lines
--- Documentation/user/virtio.rst | 2 +- drivers/net/Kconfig | 7 + drivers/net/Makefile | 1 + drivers/net/virtio.c | 236 +++++++++++++++++++++ include/linux/virtio_config.h | 7 +- include/uapi/linux/virtio_net.h | 358 ++++++++++++++++++++++++++++++++ 6 files changed, 608 insertions(+), 3 deletions(-) create mode 100644 drivers/net/virtio.c create mode 100644 include/uapi/linux/virtio_net.h
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox