Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Import of the virtio driver written by MINOURA Makoto <m...
details: https://anonhg.NetBSD.org/src/rev/f3da2849a27c
branches: trunk
changeset: 770717:f3da2849a27c
user: hannken <hannken%NetBSD.org@localhost>
date: Sun Oct 30 12:12:21 2011 +0000
description:
Import of the virtio driver written by MINOURA Makoto <minoura%netbsd.org@localhost>
with minor changes to make it compile an run on -current. This driver
speeds up disk and network access in virtual environments like KVM.
Enabled on i386 and amd64. Tested with a CentOS 5.7 x86_64 host.
See http://ozlabs.org/~rusty/virtio-spec/virtio.pdf for the specification.
diffstat:
sys/arch/amd64/conf/GENERIC | 10 +-
sys/arch/i386/conf/ALL | 10 +-
sys/arch/i386/conf/GENERIC | 10 +-
sys/dev/pci/files.pci | 18 +-
sys/dev/pci/if_vioif.c | 1307 +++++++++++++++++++++++++++++++++++++++++++
sys/dev/pci/ld_virtio.c | 557 ++++++++++++++++++
sys/dev/pci/viomb.c | 515 ++++++++++++++++
sys/dev/pci/virtio.c | 1014 +++++++++++++++++++++++++++++++++
sys/dev/pci/virtioreg.h | 152 +++++
sys/dev/pci/virtiovar.h | 207 ++++++
10 files changed, 3793 insertions(+), 7 deletions(-)
diffs (truncated from 3898 to 300 lines):
diff -r ac6b8837846a -r f3da2849a27c sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC Sun Oct 30 12:00:27 2011 +0000
+++ b/sys/arch/amd64/conf/GENERIC Sun Oct 30 12:12:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.337 2011/08/30 13:07:30 mbalmer Exp $
+# $NetBSD: GENERIC,v 1.338 2011/10/30 12:12:21 hannken Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.337 $"
+#ident "GENERIC-$Revision: 1.338 $"
maxusers 64 # estimated number of users
@@ -1109,6 +1109,12 @@
# devices (watchdog timer, etc.)
weasel* at pci?
+# Virtio devices
+virtio* at pci? dev ? function ? # Virtio PCI device
+viomb* at virtio? # Virtio memory balloon device
+ld* at virtio? # Virtio disk device
+vioif* at virtio? # Virtio network device
+
# Pull in optional local configuration
cinclude "arch/amd64/conf/GENERIC.local"
diff -r ac6b8837846a -r f3da2849a27c sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL Sun Oct 30 12:00:27 2011 +0000
+++ b/sys/arch/i386/conf/ALL Sun Oct 30 12:12:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.324 2011/10/17 22:40:31 jmcneill Exp $
+# $NetBSD: ALL,v 1.325 2011/10/30 12:12:21 hannken Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.324 $"
+#ident "ALL-$Revision: 1.325 $"
maxusers 64 # estimated number of users
@@ -1596,6 +1596,12 @@
# devices (watchdog timer, etc.)
weasel* at pci?
+# Virtio devices
+virtio* at pci? dev ? function ? # Virtio PCI device
+viomb* at virtio? # Virtio memory balloon device
+ld* at virtio? # Virtio disk device
+vioif* at virtio? # Virtio network device
+
# Flash subsystem
flash* at flashbus?
diff -r ac6b8837846a -r f3da2849a27c sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC Sun Oct 30 12:00:27 2011 +0000
+++ b/sys/arch/i386/conf/GENERIC Sun Oct 30 12:12:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1054 2011/10/02 12:19:17 mbalmer Exp $
+# $NetBSD: GENERIC,v 1.1055 2011/10/30 12:12:21 hannken Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.1054 $"
+#ident "GENERIC-$Revision: 1.1055 $"
maxusers 64 # estimated number of users
@@ -1525,6 +1525,12 @@
# devices (watchdog timer, etc.)
weasel* at pci?
+# Virtio devices
+virtio* at pci? dev ? function ? # Virtio PCI device
+viomb* at virtio? # Virtio memory balloon device
+ld* at virtio? # Virtio disk device
+vioif* at virtio? # Virtio network device
+
# Pull in optional local configuration
cinclude "arch/i386/conf/GENERIC.local"
diff -r ac6b8837846a -r f3da2849a27c sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci Sun Oct 30 12:00:27 2011 +0000
+++ b/sys/dev/pci/files.pci Sun Oct 30 12:12:21 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.349 2011/10/08 00:19:14 kiyohara Exp $
+# $NetBSD: files.pci,v 1.350 2011/10/30 12:12:21 hannken Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -1085,3 +1085,19 @@
device sisfb: wsemuldisplaydev, rasops8, rasops15, rasops16, rasops32, vcons
attach sisfb at pci
file dev/pci/sisfb.c sisfb needs-flag
+
+# VirtIO
+device virtio {}
+attach virtio at pci
+file dev/pci/virtio.c virtio
+
+attach ld at virtio with ld_virtio
+file dev/pci/ld_virtio.c ld_virtio
+
+device viomb
+attach viomb at virtio
+file dev/pci/viomb.c viomb
+
+device vioif
+attach vioif at virtio
+file dev/pci/if_vioif.c vioif
diff -r ac6b8837846a -r f3da2849a27c sys/dev/pci/if_vioif.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/if_vioif.c Sun Oct 30 12:12:21 2011 +0000
@@ -0,0 +1,1307 @@
+/* $NetBSD: if_vioif.c,v 1.1 2011/10/30 12:12:21 hannken Exp $ */
+
+/*
+ * Copyright (c) 2010 Minoura Makoto.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_vioif.c,v 1.1 2011/10/30 12:12:21 hannken Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/device.h>
+#include <sys/intr.h>
+#include <sys/kmem.h>
+#include <sys/mbuf.h>
+#include <sys/mutex.h>
+#include <sys/sockio.h>
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/virtioreg.h>
+#include <dev/pci/virtiovar.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_ether.h>
+
+#include <net/bpf.h>
+
+
+/*
+ * if_vioifreg.h:
+ */
+/* Configuration registers */
+#define VIRTIO_NET_CONFIG_MAC 0 /* 8bit x 6byte */
+#define VIRTIO_NET_CONFIG_STATUS 6 /* 16bit */
+
+/* Feature bits */
+#define VIRTIO_NET_F_CSUM (1<<0)
+#define VIRTIO_NET_F_GUEST_CSUM (1<<1)
+#define VIRTIO_NET_F_MAC (1<<5)
+#define VIRTIO_NET_F_GSO (1<<6)
+#define VIRTIO_NET_F_GUEST_TSO4 (1<<7)
+#define VIRTIO_NET_F_GUEST_TSO6 (1<<8)
+#define VIRTIO_NET_F_GUEST_ECN (1<<9)
+#define VIRTIO_NET_F_GUEST_UFO (1<<10)
+#define VIRTIO_NET_F_HOST_TSO4 (1<<11)
+#define VIRTIO_NET_F_HOST_TSO6 (1<<12)
+#define VIRTIO_NET_F_HOST_ECN (1<<13)
+#define VIRTIO_NET_F_HOST_UFO (1<<14)
+#define VIRTIO_NET_F_MRG_RXBUF (1<<15)
+#define VIRTIO_NET_F_STATUS (1<<16)
+#define VIRTIO_NET_F_CTRL_VQ (1<<17)
+#define VIRTIO_NET_F_CTRL_RX (1<<18)
+#define VIRTIO_NET_F_CTRL_VLAN (1<<19)
+
+/* Status */
+#define VIRTIO_NET_S_LINK_UP 1
+
+/* Packet header structure */
+struct virtio_net_hdr {
+ uint8_t flags;
+ uint8_t gso_type;
+ uint16_t hdr_len;
+ uint16_t gso_size;
+ uint16_t csum_start;
+ uint16_t csum_offset;
+#if 0
+ uint16_t num_buffers; /* if VIRTIO_NET_F_MRG_RXBUF enabled */
+#endif
+} __packed;
+
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* flags */
+#define VIRTIO_NET_HDR_GSO_NONE 0 /* gso_type */
+#define VIRTIO_NET_HDR_GSO_TCPV4 1 /* gso_type */
+#define VIRTIO_NET_HDR_GSO_UDP 3 /* gso_type */
+#define VIRTIO_NET_HDR_GSO_TCPV6 4 /* gso_type */
+#define VIRTIO_NET_HDR_GSO_ECN 0x80 /* gso_type, |'ed */
+
+#define VIRTIO_NET_MAX_GSO_LEN (65536+ETHER_HDR_LEN)
+
+/* Control virtqueue */
+struct virtio_net_ctrl_cmd {
+ uint8_t class;
+ uint8_t command;
+} __packed;
+#define VIRTIO_NET_CTRL_RX 0
+# define VIRTIO_NET_CTRL_RX_PROMISC 0
+# define VIRTIO_NET_CTRL_RX_ALLMULTI 1
+
+#define VIRTIO_NET_CTRL_MAC 1
+# define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
+
+#define VIRTIO_NET_CTRL_VLAN 2
+# define VIRTIO_NET_CTRL_VLAN_ADD 0
+# define VIRTIO_NET_CTRL_VLAN_DEL 1
+
+struct virtio_net_ctrl_status {
+ uint8_t ack;
+} __packed;
+#define VIRTIO_NET_OK 0
+#define VIRTIO_NET_ERR 1
+
+struct virtio_net_ctrl_rx {
+ uint8_t onoff;
+} __packed;
+
+struct virtio_net_ctrl_mac_tbl {
+ uint32_t nentries;
+ uint8_t macs[][ETHER_ADDR_LEN];
+} __packed;
+
+struct virtio_net_ctrl_vlan {
+ uint16_t id;
+} __packed;
+
+
+/*
+ * if_vioifvar.h:
+ */
+struct vioif_softc {
+ device_t sc_dev;
+
+ struct virtio_softc *sc_virtio;
+ struct virtqueue sc_vq[3];
+
+ uint8_t sc_mac[ETHER_ADDR_LEN];
+ struct ethercom sc_ethercom;
+ uint32_t sc_features;
+ short sc_ifflags;
+
+ /* bus_dmamem */
+ bus_dma_segment_t sc_hdr_segs[1];
+ struct virtio_net_hdr *sc_hdrs;
+#define sc_rx_hdrs sc_hdrs
+ struct virtio_net_hdr *sc_tx_hdrs;
+ struct virtio_net_ctrl_cmd *sc_ctrl_cmd;
+ struct virtio_net_ctrl_status *sc_ctrl_status;
+ struct virtio_net_ctrl_rx *sc_ctrl_rx;
+ struct virtio_net_ctrl_mac_tbl *sc_ctrl_mac_tbl_uc;
+ struct virtio_net_ctrl_mac_tbl *sc_ctrl_mac_tbl_mc;
+
+ /* kmem */
+ bus_dmamap_t *sc_arrays;
+#define sc_rxhdr_dmamaps sc_arrays
+ bus_dmamap_t *sc_txhdr_dmamaps;
+ bus_dmamap_t *sc_rx_dmamaps;
+ bus_dmamap_t *sc_tx_dmamaps;
+ struct mbuf **sc_rx_mbufs;
Home |
Main Index |
Thread Index |
Old Index