Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/sparc64 sun4v: add vnet driver from openbsd - compi...



details:   https://anonhg.NetBSD.org/src/rev/8428a3cf257b
branches:  trunk
changeset: 981221:8428a3cf257b
user:      palle <palle%NetBSD.org@localhost>
date:      Thu Mar 04 20:17:00 2021 +0000

description:
sun4v: add vnet driver from openbsd - compiles but probably does not work yet - still WIP

diffstat:

 sys/arch/sparc64/conf/GENERIC       |     5 +-
 sys/arch/sparc64/conf/files.sparc64 |     7 +-
 sys/arch/sparc64/dev/vnet.c         |  1889 +++++++++++++++++++++++++++++++++++
 3 files changed, 1898 insertions(+), 3 deletions(-)

diffs (truncated from 1937 to 300 lines):

diff -r e630b002dcd2 -r 8428a3cf257b sys/arch/sparc64/conf/GENERIC
--- a/sys/arch/sparc64/conf/GENERIC     Thu Mar 04 20:00:51 2021 +0000
+++ b/sys/arch/sparc64/conf/GENERIC     Thu Mar 04 20:17:00 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.234 2021/01/31 08:07:25 martin Exp $
+# $NetBSD: GENERIC,v 1.235 2021/03/04 20:17:00 palle Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident         "GENERIC-$Revision: 1.234 $"
+#ident         "GENERIC-$Revision: 1.235 $"
 
 maxusers       64
 
@@ -248,6 +248,7 @@
 # Virtual devices for sun4v systems.
 vrtc0  at vbus?
 vdsk*  at cbus?
+vnet*  at cbus?
 
 #### Serial port configuration
 
diff -r e630b002dcd2 -r 8428a3cf257b sys/arch/sparc64/conf/files.sparc64
--- a/sys/arch/sparc64/conf/files.sparc64       Thu Mar 04 20:00:51 2021 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64       Thu Mar 04 20:17:00 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc64,v 1.163 2020/10/21 13:31:52 christos Exp $
+#      $NetBSD: files.sparc64,v 1.164 2021/03/04 20:17:00 palle Exp $
 
 # @(#)files.sparc64    8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -332,3 +332,8 @@
 device vdsk: ldc, scsi
 attach vdsk at cbus
 file   arch/sparc64/dev/vdsk.c                 vdsk
+
+# Virtual network
+device vnet: ldc
+attach vnet at cbus
+file   arch/sparc64/dev/vnet.c                 vnet
diff -r e630b002dcd2 -r 8428a3cf257b sys/arch/sparc64/dev/vnet.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/vnet.c       Thu Mar 04 20:17:00 2021 +0000
@@ -0,0 +1,1889 @@
+/*     $OpenBSD: vnet.c,v 1.62 2020/07/10 13:26:36 patrick Exp $       */
+/*
+ * Copyright (c) 2009, 2015 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.
+ */
+
+#if 0
+FIXME openbsd
+#include "bpfilter.h"
+#endif
+
+#include <sys/kmem.h>
+#include <sys/param.h>
+#include <sys/atomic.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/pool.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/systm.h>
+#if 0
+FIXME openbsd
+#include <sys/timeout.h>
+#endif
+
+#include <machine/autoconf.h>
+#include <machine/hypervisor.h>
+#include <machine/openfirm.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <netinet/in.h>
+#include <net/if_ether.h>
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+
+#include <uvm/uvm_extern.h>
+
+#include <sparc64/dev/cbusvar.h>
+#include <sparc64/dev/ldcvar.h>
+#include <sparc64/dev/viovar.h>
+
+#ifdef VNET_DEBUG
+#define DPRINTF(x)     printf x
+#else
+#define DPRINTF(x)
+#endif
+
+#define VNET_TX_ENTRIES                32
+#define VNET_RX_ENTRIES                32
+
+struct vnet_attr_info {
+       struct vio_msg_tag      tag;
+       uint8_t                 xfer_mode;
+       uint8_t                 addr_type;
+       uint16_t                ack_freq;
+       uint32_t                _reserved1;
+       uint64_t                addr;
+       uint64_t                mtu;
+       uint64_t                _reserved2[3];
+};
+
+/* Address types. */
+#define VNET_ADDR_ETHERMAC     0x01
+
+/* Sub-Type envelopes. */
+#define VNET_MCAST_INFO                0x0101
+
+#define VNET_NUM_MCAST         7
+
+struct vnet_mcast_info {
+       struct vio_msg_tag      tag;
+       uint8_t                 set;
+       uint8_t                 count;
+       uint8_t                 mcast_addr[VNET_NUM_MCAST][ETHER_ADDR_LEN];
+       uint32_t                _reserved;
+};
+
+struct vnet_desc {
+       struct vio_dring_hdr    hdr;
+       uint32_t                nbytes;
+       uint32_t                ncookies;
+       struct ldc_cookie       cookie[2];
+};
+
+struct vnet_desc_msg {
+       struct vio_msg_tag      tag;
+       uint64_t                seq_no;
+       uint64_t                desc_handle;
+       uint32_t                nbytes;
+       uint32_t                ncookies;
+       struct ldc_cookie       cookie[1];
+};
+
+struct vnet_dring {
+       bus_dmamap_t            vd_map;
+       bus_dma_segment_t       vd_seg;
+       struct vnet_desc        *vd_desc;
+       int                     vd_nentries;
+};
+
+struct vnet_dring *vnet_dring_alloc(bus_dma_tag_t, int);
+void   vnet_dring_free(bus_dma_tag_t, struct vnet_dring *);
+
+/*
+ * For now, we only support vNet 1.0.
+ */
+#define VNET_MAJOR     1
+#define VNET_MINOR     0
+
+/*
+ * The vNet protocol wants the IP header to be 64-bit aligned, so
+ * define out own variant of ETHER_ALIGN.
+ */
+#define VNET_ETHER_ALIGN       6
+
+struct vnet_soft_desc {
+       int             vsd_map_idx;
+#if 0
+FIXME openbsd          
+       caddr_t         vsd_buf;
+#else          
+       unsigned char *vsd_buf;
+#endif         
+};
+
+struct vnet_softc {
+       struct device   sc_dv;
+       bus_space_tag_t sc_bustag;
+       bus_dma_tag_t   sc_dmatag;
+
+       uint64_t        sc_tx_ino;
+       uint64_t        sc_rx_ino;
+       void            *sc_tx_ih;
+       void            *sc_rx_ih;
+
+       struct ldc_conn sc_lc;
+
+       uint16_t        sc_vio_state;
+#define VIO_SND_VER_INFO       0x0001
+#define VIO_ACK_VER_INFO       0x0002
+#define VIO_RCV_VER_INFO       0x0004
+#define VIO_SND_ATTR_INFO      0x0008
+#define VIO_ACK_ATTR_INFO      0x0010
+#define VIO_RCV_ATTR_INFO      0x0020
+#define VIO_SND_DRING_REG      0x0040
+#define VIO_ACK_DRING_REG      0x0080
+#define VIO_RCV_DRING_REG      0x0100
+#define VIO_SND_RDX            0x0200
+#define VIO_ACK_RDX            0x0400
+#define VIO_RCV_RDX            0x0800
+
+#if 0
+FIXME openbsd          
+       struct timeout  sc_handshake_to;
+#endif         
+
+       uint8_t         sc_xfer_mode;
+
+       uint32_t        sc_local_sid;
+       uint64_t        sc_dring_ident;
+       uint64_t        sc_seq_no;
+
+       u_int           sc_tx_prod;
+       u_int           sc_tx_cons;
+
+       u_int           sc_peer_state;
+
+       struct ldc_map  *sc_lm;
+       struct vnet_dring *sc_vd;
+       struct vnet_soft_desc *sc_vsd;
+#define VNET_NUM_SOFT_DESC     128
+
+       size_t          sc_peer_desc_size;
+       struct ldc_cookie sc_peer_dring_cookie;
+       int             sc_peer_dring_nentries;
+
+       struct pool     sc_pool;
+
+       struct ethercom sc_ethercom;
+       struct ifmedia  sc_media;
+       u_int8_t sc_macaddr[ETHER_ADDR_LEN];
+};
+
+int vnet_match (device_t, cfdata_t, void *);
+void vnet_attach (device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(vnet, sizeof(struct vnet_softc),
+    vnet_match, vnet_attach, NULL, NULL);
+
+int    vnet_tx_intr(void *);
+int    vnet_rx_intr(void *);
+void   vnet_handshake(void *);
+
+void   vio_rx_data(struct ldc_conn *, struct ldc_pkt *);
+void   vnet_rx_vio_ctrl(struct vnet_softc *, struct vio_msg *);
+void   vnet_rx_vio_ver_info(struct vnet_softc *, struct vio_msg_tag *);
+void   vnet_rx_vio_attr_info(struct vnet_softc *, struct vio_msg_tag *);
+void   vnet_rx_vio_dring_reg(struct vnet_softc *, struct vio_msg_tag *);
+void   vnet_rx_vio_rdx(struct vnet_softc *sc, struct vio_msg_tag *);
+void   vnet_rx_vio_data(struct vnet_softc *sc, struct vio_msg *);
+void   vnet_rx_vio_desc_data(struct vnet_softc *sc, struct vio_msg_tag *);
+void   vnet_rx_vio_dring_data(struct vnet_softc *sc, struct vio_msg_tag *);
+
+void   vnet_ldc_reset(struct ldc_conn *);
+void   vnet_ldc_start(struct ldc_conn *);
+
+void   vnet_sendmsg(struct vnet_softc *, void *, size_t);
+void   vnet_send_ver_info(struct vnet_softc *, uint16_t, uint16_t);
+void   vnet_send_attr_info(struct vnet_softc *);
+void   vnet_send_dring_reg(struct vnet_softc *);
+void   vio_send_rdx(struct vnet_softc *);
+void   vnet_send_dring_data(struct vnet_softc *, uint32_t);
+
+void   vnet_start(struct ifnet *);
+void   vnet_start_desc(struct ifnet *);
+int            vnet_ioctl (struct ifnet *, u_long, void *);
+void   vnet_watchdog(struct ifnet *);
+
+int            vnet_media_change(struct ifnet *);
+void   vnet_media_status(struct ifnet *, struct ifmediareq *);
+
+void   vnet_link_state(struct vnet_softc *sc);
+
+void   vnet_setmulti(struct vnet_softc *, int);
+
+void   vnet_init(struct ifnet *);
+void   vnet_stop(struct ifnet *);
+
+int vnet_match(device_t parent, cfdata_t match, void *aux)
+{
+
+       struct cbus_attach_args *ca = aux;
+       if (strcmp(ca->ca_name, "network") == 0)
+               return (1);
+
+       return (0);



Home | Main Index | Thread Index | Old Index