Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sys Pull up following revision(s) (requested by bsiegert ...
details: https://anonhg.NetBSD.org/src/rev/31faaccef754
branches: netbsd-7
changeset: 800090:31faaccef754
user: snj <snj%NetBSD.org@localhost>
date: Fri Dec 23 06:33:56 2016 +0000
description:
Pull up following revision(s) (requested by bsiegert in ticket #1338):
sys/arch/amd64/conf/GENERIC: revision 1.418
sys/dev/pci/files.pci: revision 1.379
sys/dev/pci/vioscsi.c: revisions 1.1-1.8
sys/dev/pci/vioscsireg.h: revision 1.1
sys/dev/pci/virtioreg.h: revisions 1.5, 1.6
add the common flag bits
--
Add vioscsi, compile tested only (toxic)
--
this is working now, remove debugging.
--
add vioscsi
--
kill some more debugging.
--
Fake mode sense data for illegal targets. qemu reports 256 targets...
--
fix the status return.
--
Use SCSIPI_CHAN_NOSETTLE.
--
vioscsi_req_get()/virtio_enqueue_prep() failing is actually perfectly
normal - observed failures included 10, 27, 61 in-flight commands,
so probably depends on particular command mix; return with
XS_RESOURCE_SHORTAGE rather then panic
do vioscsi_req_put() when initial bus_dmamap_load() fails, as suggested
by the XXX; the vq_done hook is called by virtio, but in that case we
never get to commit the request to it
--
react on ADAPTER_REQ_SET_XFER_MODE so that we set tagged queuing
pass tag type and set id
diffstat:
sys/arch/amd64/conf/GENERIC | 6 +-
sys/dev/pci/files.pci | 8 +-
sys/dev/pci/vioscsi.c | 559 ++++++++++++++++++++++++++++++++++++++++++++
sys/dev/pci/vioscsireg.h | 72 +++++
sys/dev/pci/virtioreg.h | 13 +-
5 files changed, 652 insertions(+), 6 deletions(-)
diffs (truncated from 723 to 300 lines):
diff -r 74f63c6663f1 -r 31faaccef754 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC Fri Dec 23 05:57:40 2016 +0000
+++ b/sys/arch/amd64/conf/GENERIC Fri Dec 23 06:33:56 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.392.2.8 2016/12/09 05:10:45 snj Exp $
+# $NetBSD: GENERIC,v 1.392.2.9 2016/12/23 06:33:56 snj Exp $
#
# GENERIC machine description file
#
@@ -22,7 +22,7 @@
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "GENERIC-$Revision: 1.392.2.8 $"
+#ident "GENERIC-$Revision: 1.392.2.9 $"
maxusers 64 # estimated number of users
@@ -1188,7 +1188,7 @@
ld* at virtio? # Virtio disk device
vioif* at virtio? # Virtio network device
viornd* at virtio? # Virtio entropy device
-
+vioscsi* at virtio? # Virtio SCSI device
# Pull in optional local configuration
cinclude "arch/amd64/conf/GENERIC.local"
diff -r 74f63c6663f1 -r 31faaccef754 sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci Fri Dec 23 05:57:40 2016 +0000
+++ b/sys/dev/pci/files.pci Fri Dec 23 06:33:56 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.pci,v 1.371.4.3 2015/04/19 06:45:17 riz Exp $
+# $NetBSD: files.pci,v 1.371.4.4 2016/12/23 06:33:56 snj Exp $
#
# Config file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
@@ -1131,7 +1131,11 @@
device viornd
attach viornd at virtio
-file dev/pci/viornd.c viornd
+file dev/pci/viornd.c viornd
+
+device vioscsi: scsi
+attach vioscsi at virtio
+file dev/pci/vioscsi.c vioscsi
# Silicon Motion SM712(LynxEM+) frame buffer
device lynxfb: wsemuldisplaydev, rasops16
diff -r 74f63c6663f1 -r 31faaccef754 sys/dev/pci/vioscsi.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/vioscsi.c Fri Dec 23 06:33:56 2016 +0000
@@ -0,0 +1,559 @@
+/* $NetBSD: vioscsi.c,v 1.8.2.2 2016/12/23 06:33:56 snj Exp $ */
+/* $OpenBSD: vioscsi.c,v 1.3 2015/03/14 03:38:49 jsg Exp $ */
+
+/*
+ * Copyright (c) 2013 Google Inc.
+ *
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: vioscsi.c,v 1.8.2.2 2016/12/23 06:33:56 snj Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/bus.h>
+#include <sys/buf.h>
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <dev/pci/vioscsireg.h>
+#include <dev/pci/virtiovar.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+#ifdef VIOSCSI_DEBUG
+static int vioscsi_debug = 1;
+#define DPRINTF(f) do { if (vioscsi_debug) printf f; } while (/*CONSTCOND*/0)
+#else
+#define DPRINTF(f) ((void)0)
+#endif
+
+struct vioscsi_req {
+ struct virtio_scsi_req_hdr vr_req;
+ struct virtio_scsi_res_hdr vr_res;
+ struct scsipi_xfer *vr_xs;
+ bus_dmamap_t vr_control;
+ bus_dmamap_t vr_data;
+};
+
+struct vioscsi_softc {
+ device_t sc_dev;
+ struct scsipi_adapter sc_adapter;
+ struct scsipi_channel sc_channel;
+
+ struct virtqueue sc_vqs[3];
+ struct vioscsi_req *sc_reqs;
+ bus_dma_segment_t sc_reqs_segs[1];
+
+ u_int32_t sc_seg_max;
+};
+
+/*
+ * Each block request uses at least two segments - one for the header
+ * and one for the status.
+*/
+#define VIRTIO_SCSI_MIN_SEGMENTS 2
+
+static int vioscsi_match(device_t, cfdata_t, void *);
+static void vioscsi_attach(device_t, device_t, void *);
+
+static int vioscsi_alloc_reqs(struct vioscsi_softc *,
+ struct virtio_softc *, int, uint32_t);
+static void vioscsi_scsipi_request(struct scsipi_channel *,
+ scsipi_adapter_req_t, void *);
+static int vioscsi_vq_done(struct virtqueue *);
+static void vioscsi_req_done(struct vioscsi_softc *, struct virtio_softc *,
+ struct vioscsi_req *);
+static struct vioscsi_req *vioscsi_req_get(struct vioscsi_softc *);
+static void vioscsi_req_put(struct vioscsi_softc *, struct vioscsi_req *);
+
+static const char *const vioscsi_vq_names[] = {
+ "control",
+ "event",
+ "request",
+};
+
+CFATTACH_DECL_NEW(vioscsi, sizeof(struct vioscsi_softc),
+ vioscsi_match, vioscsi_attach, NULL, NULL);
+
+static int
+vioscsi_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct virtio_softc *va = aux;
+
+ if (va->sc_childdevid == PCI_PRODUCT_VIRTIO_SCSI)
+ return 1;
+ return 0;
+}
+
+static void
+vioscsi_attach(device_t parent, device_t self, void *aux)
+{
+ struct vioscsi_softc *sc = device_private(self);
+ struct virtio_softc *vsc = device_private(parent);
+ struct scsipi_adapter *adapt = &sc->sc_adapter;
+ struct scsipi_channel *chan = &sc->sc_channel;
+ uint32_t features;
+ char buf[256];
+ int rv;
+
+ if (vsc->sc_child != NULL) {
+ aprint_error(": parent %s already has a child\n",
+ device_xname(parent));
+ return;
+ }
+
+ sc->sc_dev = self;
+
+ vsc->sc_child = self;
+ vsc->sc_ipl = IPL_BIO;
+ vsc->sc_vqs = sc->sc_vqs;
+ vsc->sc_nvqs = __arraycount(sc->sc_vqs);
+ vsc->sc_config_change = NULL;
+ vsc->sc_intrhand = virtio_vq_intr;
+ vsc->sc_flags = 0;
+
+ features = virtio_negotiate_features(vsc, 0);
+ snprintb(buf, sizeof(buf), VIRTIO_COMMON_FLAG_BITS, features);
+ aprint_normal(": Features: %s\n", buf);
+ aprint_naive("\n");
+
+ uint32_t cmd_per_lun = virtio_read_device_config_4(vsc,
+ VIRTIO_SCSI_CONFIG_CMD_PER_LUN);
+
+ uint32_t seg_max = virtio_read_device_config_4(vsc,
+ VIRTIO_SCSI_CONFIG_SEG_MAX);
+
+ uint16_t max_target = virtio_read_device_config_2(vsc,
+ VIRTIO_SCSI_CONFIG_MAX_TARGET);
+
+ uint16_t max_channel = virtio_read_device_config_2(vsc,
+ VIRTIO_SCSI_CONFIG_MAX_CHANNEL);
+
+ uint32_t max_lun = virtio_read_device_config_4(vsc,
+ VIRTIO_SCSI_CONFIG_MAX_LUN);
+
+ sc->sc_seg_max = seg_max;
+
+ for (size_t i = 0; i < __arraycount(sc->sc_vqs); i++) {
+ rv = virtio_alloc_vq(vsc, &sc->sc_vqs[i], i, MAXPHYS,
+ 1 + howmany(MAXPHYS, NBPG), vioscsi_vq_names[i]);
+ if (rv) {
+ aprint_error_dev(sc->sc_dev,
+ "failed to allocate virtqueue %zu\n", i);
+ return;
+ }
+ sc->sc_vqs[i].vq_done = vioscsi_vq_done;
+ }
+
+ int qsize = sc->sc_vqs[2].vq_num;
+ aprint_normal_dev(sc->sc_dev, "qsize %d\n", qsize);
+ if (vioscsi_alloc_reqs(sc, vsc, qsize, seg_max))
+ return;
+
+ /*
+ * Fill in the scsipi_adapter.
+ */
+ memset(adapt, 0, sizeof(*adapt));
+ adapt->adapt_dev = sc->sc_dev;
+ adapt->adapt_nchannels = max_channel;
+ adapt->adapt_openings = cmd_per_lun;
+ adapt->adapt_max_periph = adapt->adapt_openings;
+ adapt->adapt_request = vioscsi_scsipi_request;
+ adapt->adapt_minphys = minphys;
+
+ /*
+ * Fill in the scsipi_channel.
+ */
+ memset(chan, 0, sizeof(*chan));
+ chan->chan_adapter = adapt;
+ chan->chan_bustype = &scsi_bustype;
+ chan->chan_channel = 0;
+ chan->chan_ntargets = max_target;
+ chan->chan_nluns = max_lun;
+ chan->chan_id = 0;
+ chan->chan_flags = SCSIPI_CHAN_NOSETTLE;
+
+ config_found(sc->sc_dev, &sc->sc_channel, scsiprint);
+}
+
+#define XS2DMA(xs) \
+ ((((xs)->xs_control & XS_CTL_DATA_IN) ? BUS_DMA_READ : BUS_DMA_WRITE) | \
+ (((xs)->xs_control & XS_CTL_NOSLEEP) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK) | \
+ BUS_DMA_STREAMING)
+
+#define XS2DMAPRE(xs) (((xs)->xs_control & XS_CTL_DATA_IN) ? \
+ BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE)
+
+#define XS2DMAPOST(xs) (((xs)->xs_control & XS_CTL_DATA_IN) ? \
+ BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE)
+
+static void
+vioscsi_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t
+ request, void *arg)
+{
+ struct vioscsi_softc *sc =
+ device_private(chan->chan_adapter->adapt_dev);
+ struct virtio_softc *vsc = device_private(device_parent(sc->sc_dev));
+ struct scsipi_xfer *xs;
+ struct scsipi_periph *periph;
+ struct vioscsi_req *vr;
+ struct virtio_scsi_req_hdr *req;
+ struct virtqueue *vq = &sc->sc_vqs[2];
+ int slot, error;
+
+ DPRINTF(("%s: enter\n", __func__));
+
+ switch (request) {
+ case ADAPTER_REQ_RUN_XFER:
+ break;
+ case ADAPTER_REQ_SET_XFER_MODE:
+ {
+ struct scsipi_xfer_mode *xm = arg;
+ xm->xm_mode = PERIPH_CAP_TQING;
+ xm->xm_period = 0;
+ xm->xm_offset = 0;
+ scsipi_async_event(chan, ASYNC_EVENT_XFER_MODE, xm);
+ return;
+ }
+ default:
+ DPRINTF(("%s: unhandled %d\n", __func__, request));
+ return;
+ }
+
+ xs = arg;
+ periph = xs->xs_periph;
+
+ vr = vioscsi_req_get(sc);
+ /*
+ * This can happen when we run out of queue slots.
+ */
+ if (vr == NULL) {
+ xs->error = XS_RESOURCE_SHORTAGE;
Home |
Main Index |
Thread Index |
Old Index