summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-05-16 10:53:07 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-05-16 10:53:07 +0000
commit96ecee597077d226df03d5f305c2d6666129283a (patch)
tree58d7338c56b3e62437f36db145d37e42552e05af
parenta906f4b468c0d927c9b71a676b121bce10c0d0e1 (diff)
Add vsw(4), a driver for the virtual network switch on sun4v. This is just
some simple glue to attach each port as a network interface.
-rw-r--r--sys/arch/sparc64/conf/files.sparc649
-rw-r--r--sys/arch/sparc64/dev/vsw.c137
2 files changed, 144 insertions, 2 deletions
diff --git a/sys/arch/sparc64/conf/files.sparc64 b/sys/arch/sparc64/conf/files.sparc64
index d1161da6b37..6d32e0c4bb4 100644
--- a/sys/arch/sparc64/conf/files.sparc64
+++ b/sys/arch/sparc64/conf/files.sparc64
@@ -1,4 +1,4 @@
-# $OpenBSD: files.sparc64,v 1.121 2009/05/10 12:24:04 kettenis Exp $
+# $OpenBSD: files.sparc64,v 1.122 2009/05/16 10:53:06 kettenis Exp $
# $NetBSD: files.sparc64,v 1.50 2001/08/10 20:53:50 eeh Exp $
# maxpartitions must be first item in files.${ARCH}
@@ -403,9 +403,14 @@ device vdsk: ldc, scsi
attach vdsk at cbus
file arch/sparc64/dev/vdsk.c vdsk
+# Virtual network switch
+device vsw {}
+attach vsw at cbus
+file arch/sparc64/dev/vsw.c vsw
+
# Virtual network
device vnet: ldc
-attach vnet at cbus
+attach vnet at cbus, vsw
file arch/sparc64/dev/vnet.c vnet
# Virtual console concentrator
diff --git a/sys/arch/sparc64/dev/vsw.c b/sys/arch/sparc64/dev/vsw.c
new file mode 100644
index 00000000000..6202230b2c3
--- /dev/null
+++ b/sys/arch/sparc64/dev/vsw.c
@@ -0,0 +1,137 @@
+/* $OpenBSD: vsw.c,v 1.1 2009/05/16 10:53:06 kettenis Exp $ */
+/*
+ * Copyright (c) 2009 Mark Kettenis
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <machine/autoconf.h>
+#include <machine/hypervisor.h>
+#include <machine/mdesc.h>
+
+#include <sparc64/dev/cbusvar.h>
+
+#ifdef VSW_DEBUG
+#define DPRINTF(x) printf x
+#else
+#define DPRINTF(x)
+#endif
+
+struct vsw_softc {
+ struct device sc_dv;
+ bus_space_tag_t sc_bustag;
+ bus_dma_tag_t sc_dmatag;
+};
+
+int vsw_match(struct device *, void *, void *);
+void vsw_attach(struct device *, struct device *, void *);
+
+struct cfattach vsw_ca = {
+ sizeof(struct vsw_softc), vsw_match, vsw_attach
+};
+
+struct cfdriver vsw_cd = {
+ NULL, "vsw", DV_DULL
+};
+
+void vsw_get_channel_endpoint(int, struct cbus_attach_args *);
+
+int
+vsw_match(struct device *parent, void *match, void *aux)
+{
+ struct cbus_attach_args *ca = aux;
+
+ if (strcmp(ca->ca_name, "virtual-network-switch") == 0)
+ return (1);
+
+ return (0);
+}
+
+void
+vsw_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct cbus_attach_args *ca = aux;
+ struct cbus_attach_args nca;
+ struct md_header *hdr;
+ struct md_element *elem;
+ const char *name_blk;
+ const char *str;
+ int idx;
+ int arc;
+
+ printf("\n");
+
+ hdr = (struct md_header *)mdesc;
+ elem = (struct md_element *)(mdesc + sizeof(struct md_header));
+ name_blk = mdesc + sizeof(struct md_header) + hdr->node_blk_sz;
+
+ idx = ca->ca_idx;
+ for (; elem[idx].tag != 'E'; idx++) {
+ str = name_blk + elem[idx].name_offset;
+ if (elem[idx].tag != 'a' || strcmp(str, "fwd") != 0)
+ continue;
+
+ arc = elem[idx].d.val;
+ str = name_blk + elem[arc].name_offset;
+ if (strcmp(str, "virtual-device-port") == 0) {
+ bzero(&nca, sizeof(nca));
+ nca.ca_name = "network";
+ nca.ca_node = ca->ca_node;
+ nca.ca_bustag = ca->ca_bustag;
+ nca.ca_dmatag = ca->ca_dmatag;
+ vsw_get_channel_endpoint(arc, &nca);
+ config_found(self, &nca, cbus_print);
+ }
+ }
+}
+
+void
+vsw_get_channel_endpoint(int idx, struct cbus_attach_args *ca)
+{
+ struct md_header *hdr;
+ struct md_element *elem;
+ const char *name_blk;
+ const char *str;
+ int arc;
+
+ hdr = (struct md_header *)mdesc;
+ elem = (struct md_element *)(mdesc + sizeof(struct md_header));
+ name_blk = mdesc + sizeof(struct md_header) + hdr->node_blk_sz;
+
+ ca->ca_idx = idx;
+
+ ca->ca_id = -1;
+ ca->ca_tx_ino = -1;
+ ca->ca_rx_ino = -1;
+
+ for (; elem[idx].tag != 'E'; idx++) {
+ str = name_blk + elem[idx].name_offset;
+ if (elem[idx].tag != 'a' || strcmp(str, "fwd") != 0)
+ continue;
+
+ arc = elem[idx].d.val;
+ str = name_blk + elem[arc].name_offset;
+ if (strcmp(str, "channel-endpoint") == 0) {
+ ca->ca_id = mdesc_get_prop_val(arc, "id");
+ ca->ca_tx_ino = mdesc_get_prop_val(arc, "tx-ino");
+ ca->ca_rx_ino = mdesc_get_prop_val(arc, "rx-ino");
+ return;
+ }
+ }
+}