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: vdsk and ldc drivers - from OpenBSD, ...



details:   https://anonhg.NetBSD.org/src/rev/a3a026862aab
branches:  trunk
changeset: 347263:a3a026862aab
user:      palle <palle%NetBSD.org@localhost>
date:      Fri Aug 19 19:02:07 2016 +0000

description:
sun4v: vdsk and ldc drivers - from OpenBSD, but heavily adapted to NetBSD scsipi - access to a virtual disk served from a ldom primary domain now works

diffstat:

 sys/arch/sparc64/conf/GENERIC       |     5 +-
 sys/arch/sparc64/conf/files.sparc64 |    10 +-
 sys/arch/sparc64/dev/ldc.c          |   679 +++++++++++++++++
 sys/arch/sparc64/dev/ldcvar.h       |   169 ++++
 sys/arch/sparc64/dev/vdsk.c         |  1381 +++++++++++++++++++++++++++++++++++
 sys/arch/sparc64/doc/TODO           |     5 +-
 sys/arch/sparc64/sparc64/autoconf.c |    53 +-
 7 files changed, 2295 insertions(+), 7 deletions(-)

diffs (truncated from 2393 to 300 lines):

diff -r af72ee8e737f -r a3a026862aab sys/arch/sparc64/conf/GENERIC
--- a/sys/arch/sparc64/conf/GENERIC     Fri Aug 19 18:53:29 2016 +0000
+++ b/sys/arch/sparc64/conf/GENERIC     Fri Aug 19 19:02:07 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.191 2016/06/22 20:12:59 palle Exp $
+# $NetBSD: GENERIC,v 1.192 2016/08/19 19:02:07 palle Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident         "GENERIC-$Revision: 1.191 $"
+#ident         "GENERIC-$Revision: 1.192 $"
 
 maxusers       64
 
@@ -277,6 +277,7 @@
 
 # Virtual devices for sun4v systems.
 vrtc0  at vbus?
+vdsk*  at cbus?
 
 #### Serial port configuration
 
diff -r af72ee8e737f -r a3a026862aab sys/arch/sparc64/conf/files.sparc64
--- a/sys/arch/sparc64/conf/files.sparc64       Fri Aug 19 18:53:29 2016 +0000
+++ b/sys/arch/sparc64/conf/files.sparc64       Fri Aug 19 19:02:07 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc64,v 1.151 2016/06/22 20:12:59 palle Exp $
+#      $NetBSD: files.sparc64,v 1.152 2016/08/19 19:02:07 palle Exp $
 
 # @(#)files.sparc64    8.1 (Berkeley) 7/19/93
 # sparc64-specific configuration info
@@ -325,3 +325,11 @@
 device vrtc
 attach vrtc at vbus
 file   arch/sparc64/dev/vrtc.c                 vrtc
+
+define ldc
+file   arch/sparc64/dev/ldc.c                  ldc
+
+# Virtual disk
+device vdsk: ldc, scsi
+attach vdsk at cbus
+file   arch/sparc64/dev/vdsk.c                 vdsk
diff -r af72ee8e737f -r a3a026862aab sys/arch/sparc64/dev/ldc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sparc64/dev/ldc.c        Fri Aug 19 19:02:07 2016 +0000
@@ -0,0 +1,679 @@
+/*     $NetBSD: ldc.c,v 1.1 2016/08/19 19:02:07 palle Exp $    */
+/*     $OpenBSD: ldc.c,v 1.12 2015/03/21 18:02:58 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/kmem.h>
+#include <sys/malloc.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+
+#include <sys/bus.h>
+#include <machine/hypervisor.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <sparc64/dev/ldcvar.h>
+
+#ifdef LDC_DEBUG
+#define DPRINTF(x)     printf x
+#else
+#define DPRINTF(x)
+#endif
+
+void   ldc_rx_ctrl_vers(struct ldc_conn *, struct ldc_pkt *);
+void   ldc_rx_ctrl_rtr(struct ldc_conn *, struct ldc_pkt *);
+void   ldc_rx_ctrl_rts(struct ldc_conn *, struct ldc_pkt *);
+void   ldc_rx_ctrl_rdx(struct ldc_conn *, struct ldc_pkt *);
+
+void   ldc_send_ack(struct ldc_conn *);
+void   ldc_send_rtr(struct ldc_conn *);
+void   ldc_send_rts(struct ldc_conn *);
+void   ldc_send_rdx(struct ldc_conn *);
+
+void
+ldc_rx_ctrl(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       switch (lp->ctrl) {
+       case LDC_VERS:
+               ldc_rx_ctrl_vers(lc, lp);
+               break;
+
+       case LDC_RTS:
+               ldc_rx_ctrl_rts(lc, lp);
+               break;
+
+       case LDC_RTR:
+               ldc_rx_ctrl_rtr(lc, lp);
+               break;
+
+       case LDC_RDX:
+               ldc_rx_ctrl_rdx(lc, lp);
+               break;
+
+       default:
+               DPRINTF(("CTRL/0x%02x/0x%02x\n", lp->stype, lp->ctrl));
+               ldc_reset(lc);
+               break;
+       }
+}
+
+void
+ldc_rx_ctrl_vers(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       switch (lp->stype) {
+       case LDC_INFO:
+               DPRINTF(("CTRL/INFO/VERS\n"));
+               if (lp->major == LDC_VERSION_MAJOR &&
+                   lp->minor == LDC_VERSION_MINOR)
+                       ldc_send_ack(lc);
+               else {
+                       /* XXX do nothing for now. */
+               }
+               break;
+
+       case LDC_ACK:
+               if (lc->lc_state != LDC_SND_VERS) {
+                       DPRINTF(("Spurious CTRL/ACK/VERS: state %d\n",
+                           lc->lc_state));
+                       ldc_reset(lc);
+                       return;
+               }
+               DPRINTF(("CTRL/ACK/VERS\n"));
+               ldc_send_rts(lc);
+               break;
+
+       case LDC_NACK:
+               DPRINTF(("CTRL/NACK/VERS\n"));
+               ldc_reset(lc);
+               break;
+
+       default:
+               DPRINTF(("CTRL/0x%02x/VERS\n", lp->stype));
+               ldc_reset(lc);
+               break;
+       }
+}
+
+void
+ldc_rx_ctrl_rts(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       switch (lp->stype) {
+       case LDC_INFO:
+               if (lc->lc_state != LDC_RCV_VERS) {
+                       DPRINTF(("Spurious CTRL/INFO/RTS: state %d\n",
+                           lc->lc_state));
+                       ldc_reset(lc);
+                       return;
+               }
+               DPRINTF(("CTRL/INFO/RTS\n"));
+               ldc_send_rtr(lc);
+               break;
+
+       case LDC_ACK:
+               DPRINTF(("CTRL/ACK/RTS\n"));
+               ldc_reset(lc);
+               break;
+
+       case LDC_NACK:
+               DPRINTF(("CTRL/NACK/RTS\n"));
+               ldc_reset(lc);
+               break;
+
+       default:
+               DPRINTF(("CTRL/0x%02x/RTS\n", lp->stype));
+               ldc_reset(lc);
+               break;
+       }
+}
+
+void
+ldc_rx_ctrl_rtr(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       switch (lp->stype) {
+       case LDC_INFO:
+               if (lc->lc_state != LDC_SND_RTS) {
+                       DPRINTF(("Spurious CTRL/INFO/RTR: state %d\n",
+                           lc->lc_state));
+                       ldc_reset(lc);
+                       return;
+               }
+               DPRINTF(("CTRL/INFO/RTR\n"));
+               ldc_send_rdx(lc);
+               lc->lc_start(lc);
+               break;
+
+       case LDC_ACK:
+               DPRINTF(("CTRL/ACK/RTR\n"));
+               ldc_reset(lc);
+               break;
+
+       case LDC_NACK:
+               DPRINTF(("CTRL/NACK/RTR\n"));
+               ldc_reset(lc);
+               break;
+
+       default:
+               DPRINTF(("CTRL/0x%02x/RTR\n", lp->stype));
+               ldc_reset(lc);
+               break;
+       }
+}
+
+void
+ldc_rx_ctrl_rdx(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       switch (lp->stype) {
+       case LDC_INFO:
+               if (lc->lc_state != LDC_SND_RTR) {
+                       DPRINTF(("Spurious CTRL/INFO/RTR: state %d\n",
+                           lc->lc_state));
+                       ldc_reset(lc);
+                       return;
+               }
+               DPRINTF(("CTRL/INFO/RDX\n"));
+               lc->lc_start(lc);
+               break;
+
+       case LDC_ACK:
+               DPRINTF(("CTRL/ACK/RDX\n"));
+               ldc_reset(lc);
+               break;
+
+       case LDC_NACK:
+               DPRINTF(("CTRL/NACK/RDX\n"));
+               ldc_reset(lc);
+               break;
+
+       default:
+               DPRINTF(("CTRL/0x%02x/RDX\n", lp->stype));
+               ldc_reset(lc);
+               break;
+       }
+}
+
+void
+ldc_rx_data(struct ldc_conn *lc, struct ldc_pkt *lp)
+{
+       size_t len;
+
+       if (lp->stype != LDC_INFO) {
+               DPRINTF(("DATA/0x%02x\n", lp->stype));
+               ldc_reset(lc);
+               return;
+       }
+
+       if (lc->lc_state != LDC_SND_RTR &&
+           lc->lc_state != LDC_SND_RDX) {
+               DPRINTF(("Spurious DATA/INFO: state %d\n", lc->lc_state));
+               ldc_reset(lc);
+               return;
+       }
+
+       if (lp->env & LDC_FRAG_START) {
+               lc->lc_len = (lp->env & LDC_LEN_MASK) + 8;
+               KASSERT(lc->lc_len <= sizeof(lc->lc_msg));
+               memcpy((uint8_t *)lc->lc_msg, lp, lc->lc_len);
+       } else {
+               len = (lp->env & LDC_LEN_MASK);
+               if (lc->lc_len + len > sizeof(lc->lc_msg)) {
+                       DPRINTF(("Buffer overrun\n"));
+                       ldc_reset(lc);
+                       return;
+               }
+               memcpy(((uint8_t *)lc->lc_msg) + lc->lc_len, &lp->major, len);
+               lc->lc_len += len;
+       }
+
+       if (lp->env & LDC_FRAG_STOP)
+               lc->lc_rx_data(lc, (struct ldc_pkt *)lc->lc_msg);
+}
+
+void
+ldc_send_vers(struct ldc_conn *lc)
+{
+       struct ldc_pkt *lp;
+       uint64_t tx_head, tx_tail, tx_state;



Home | Main Index | Thread Index | Old Index