Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/dev Implement enough of a SCSI target to be able to...



details:   https://anonhg.NetBSD.org/src/rev/96d0b7f6e683
branches:  trunk
changeset: 757296:96d0b7f6e683
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Aug 24 11:23:35 2010 +0000

description:
Implement enough of a SCSI target to be able to perform tests on
our SCSIPI driver stack.  Currently we pretend to be a single CD
controller with an optional host file as the image, but I guess
the sky's the limit.

dmesg porn:
NetBSD 5.99.39 (RUMP-ROAST) #0: Mon Aug 23 11:38:16 CEST 2010
        pooka@pain-rustique.localhost:/usr/allsrc/src/sys/rump/librump/rumpkern
total memory = unlimited (host limit)
timecounter: Timecounters tick every 10.000 msec
timecounter: Timecounter "rumpclk" frequency 100 Hz quality 0
root file system type: rumpfs
mainbus0 (root)
scsitest0 at mainbus0
scsibus0 at scsitest0: 2 targets, 1 lun per target
cd0 at scsibus0 target 1 lun 0: <RUMPHOBO, It's a LIE, 0.00> cdrom removable

diffstat:

 sys/rump/dev/Makefile.rumpdev                |    4 +-
 sys/rump/dev/files.rump                      |    5 +-
 sys/rump/dev/lib/libscsitest/Makefile        |   11 +
 sys/rump/dev/lib/libscsitest/SCSITEST.ioconf |   12 +
 sys/rump/dev/lib/libscsitest/component.c     |   46 ++++
 sys/rump/dev/lib/libscsitest/scsitest.c      |  255 +++++++++++++++++++++++++++
 sys/rump/dev/lib/libscsitest/shlib_version   |    4 +
 7 files changed, 334 insertions(+), 3 deletions(-)

diffs (truncated from 378 to 300 lines):

diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/Makefile.rumpdev
--- a/sys/rump/dev/Makefile.rumpdev     Tue Aug 24 10:29:53 2010 +0000
+++ b/sys/rump/dev/Makefile.rumpdev     Tue Aug 24 11:23:35 2010 +0000
@@ -1,8 +1,8 @@
-#      $NetBSD: Makefile.rumpdev,v 1.15 2010/08/23 20:49:53 pooka Exp $
+#      $NetBSD: Makefile.rumpdev,v 1.16 2010/08/24 11:23:35 pooka Exp $
 #
 
 RUMPDEVLIST=   audio bpf cgd disk dm fss netsmb pad putter raidframe   \
-               rnd scsipi sysmon ubt ucom ugenhc ulpt umass usb wscons
+               rnd scsipi scsitest sysmon ubt ucom ugenhc ulpt umass usb wscons
 
 .for var in ${RUMPDEVLIST}
 RUMPDEVLIBS+=lib${var}
diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/files.rump
--- a/sys/rump/dev/files.rump   Tue Aug 24 10:29:53 2010 +0000
+++ b/sys/rump/dev/files.rump   Tue Aug 24 11:23:35 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.rump,v 1.2 2010/03/08 10:24:37 pooka Exp $
+#      $NetBSD: files.rump,v 1.3 2010/08/24 11:23:35 pooka Exp $
 #
 
 device mainbus { }
@@ -6,3 +6,6 @@
 
 device ugenhc: usbus, usbroothub
 attach ugenhc at mainbus
+
+device scsitest: scsi
+attach scsitest at mainbus
diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/lib/libscsitest/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libscsitest/Makefile     Tue Aug 24 11:23:35 2010 +0000
@@ -0,0 +1,11 @@
+#      $NetBSD: Makefile,v 1.1 2010/08/24 11:23:35 pooka Exp $
+#
+
+LIB=   rumpdev_scsitest
+IOCONF=        SCSITEST.ioconf
+
+SRCS=  scsitest.c
+SRCS+= component.c
+
+.include <bsd.lib.mk>
+.include <bsd.klinks.mk>
diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/lib/libscsitest/SCSITEST.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libscsitest/SCSITEST.ioconf      Tue Aug 24 11:23:35 2010 +0000
@@ -0,0 +1,12 @@
+#      $NetBSD: SCSITEST.ioconf,v 1.1 2010/08/24 11:23:35 pooka Exp $
+#
+
+ioconf scsitest
+
+include "conf/files"
+include "dev/scsipi/files.scsipi"
+include "rump/dev/files.rump"
+
+pseudo-root mainbus*
+
+scsitest0 at mainbus?
diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/lib/libscsitest/component.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libscsitest/component.c  Tue Aug 24 11:23:35 2010 +0000
@@ -0,0 +1,46 @@
+/*     $NetBSD: component.c,v 1.1 2010/08/24 11:23:35 pooka Exp $      */
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  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 OR CONTRIBUTORS 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: component.c,v 1.1 2010/08/24 11:23:35 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/mbuf.h>
+#include <sys/stat.h>
+
+#include "ioconf.c"
+
+#include "rump_private.h"
+
+RUMP_COMPONENT(RUMP_COMPONENT_DEV)
+{
+
+       config_init_component(cfdriver_ioconf_scsitest,
+           cfattach_ioconf_scsitest, cfdata_ioconf_scsitest);
+}
diff -r e213e638291b -r 96d0b7f6e683 sys/rump/dev/lib/libscsitest/scsitest.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libscsitest/scsitest.c   Tue Aug 24 11:23:35 2010 +0000
@@ -0,0 +1,255 @@
+/*     $NetBSD: scsitest.c,v 1.1 2010/08/24 11:23:35 pooka Exp $       */
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  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 OR CONTRIBUTORS 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.
+ */
+
+/*
+ * A SCSI target which is useful for debugging our scsipi driver stack.
+ * Currently it pretends to be a single CD.
+ *
+ * Freely add the necessary features for your tests.  Just remember to
+ * run the atf test suite to make sure you didn't cause regressions to
+ * other tests.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: scsitest.c,v 1.1 2010/08/24 11:23:35 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/atomic.h>
+#include <sys/buf.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/fcntl.h>
+
+#include <dev/scsipi/scsiconf.h>
+#include <dev/scsipi/scsipiconf.h>
+#include <dev/scsipi/scsi_disk.h>
+#include <dev/scsipi/scsipi_cd.h>
+#include <dev/scsipi/scsipi_all.h>
+
+#include <rump/rumpuser.h>
+#include <rump/scsitest.h>
+
+int    scsitest_match(struct device *, struct cfdata *, void *);
+void   scsitest_attach(struct device *, struct device *, void *);
+
+struct scsitest {
+       struct scsipi_channel sc_channel;
+       struct scsipi_adapter sc_adapter;
+};
+
+CFATTACH_DECL_NEW(scsitest, sizeof(struct scsitest), scsitest_match,
+       scsitest_attach, NULL, NULL);
+
+/*
+ * tosi.iso can be used to deliver CD requests to a host file with the
+ * name in USE_TOSI_ISO (yes, it's extrasimplistic).
+ */
+//#define USE_TOSI_ISO
+
+#define CDBLOCKSIZE 2048
+static uint32_t mycdsize = 2048;
+static int isofd;
+
+#define MYCDISO "tosi.iso"
+
+unsigned rump_scsitest_err[RUMP_SCSITEST_MAXERROR];
+
+static void
+sense_notready(struct scsipi_xfer *xs)
+{
+       struct scsi_sense_data *sense = &xs->sense.scsi_sense;
+
+       xs->error = XS_SENSE;
+
+       sense->response_code = 0x70;
+       sense->flags = SKEY_NOT_READY;
+       sense->asc = 0x3A;
+       sense->ascq = 0x00;
+       sense->extra_len = 6;
+}
+
+/*
+ * This is pretty much a CD target for now
+ */
+static void
+scsitest_request(struct scsipi_channel *chan,
+       scsipi_adapter_req_t req, void *arg)
+{
+       struct scsipi_xfer *xs = arg;
+       struct scsipi_generic *cmd = xs->cmd;
+#ifdef USE_TOSI_ISO
+       int error;
+#endif
+
+       if (req != ADAPTER_REQ_RUN_XFER)
+               return;
+
+       //show_scsipi_xs(xs);
+
+       switch (cmd->opcode) {
+       case SCSI_TEST_UNIT_READY:
+               if (isofd == -1)
+                       sense_notready(xs);
+
+               break;
+       case INQUIRY: {
+               struct scsipi_inquiry_data *inqbuf = (void *)xs->data;
+
+               memset(inqbuf, 0, sizeof(*inqbuf));
+               inqbuf->device = T_CDROM;
+               inqbuf->dev_qual2 = SID_REMOVABLE;
+               strcpy(inqbuf->vendor, "RUMPHOBO");
+               strcpy(inqbuf->product, "It's a LIE");
+               strcpy(inqbuf->revision, "0.00");
+               break;
+       }
+       case READ_CD_CAPACITY: {
+               struct scsipi_read_cd_cap_data *ret = (void *)xs->data;
+
+               _lto4b(CDBLOCKSIZE, ret->length);
+               _lto4b(mycdsize, ret->addr);
+
+               break;
+       }
+       case READ_DISCINFO: {
+               struct scsipi_read_discinfo_data *ret = (void *)xs->data;
+
+               memset(ret, 0, sizeof(*ret));
+               break;
+       }
+       case READ_TRACKINFO: {
+               struct scsipi_read_trackinfo_data *ret = (void *)xs->data;
+
+               _lto4b(mycdsize, ret->track_size);
+               break;
+       }
+       case READ_TOC: {
+               struct scsipi_toc_header *ret = (void *)xs->data;
+
+               memset(ret, 0, sizeof(*ret));
+               break;
+       }
+       case START_STOP: {
+               struct scsipi_start_stop *param = (void *)cmd;
+
+               if (param->how & SSS_LOEJ) {
+#ifdef USE_TOSI_ISO
+                       rumpuser_close(isofd, &error);
+#endif
+                       isofd = -1;
+               }
+               break;
+       }
+       case SCSI_SYNCHRONIZE_CACHE_10: {
+               if (isofd == -1) {
+                       if ((xs->xs_control & XS_CTL_SILENT) == 0)
+                               atomic_inc_uint(&rump_scsitest_err
+                                   [RUMP_SCSITEST_NOISYSYNC]);
+                       
+                       sense_notready(xs);
+               }
+
+               break;
+       }
+       case GET_CONFIGURATION: {
+
+               break;
+       }
+       case SCSI_READ_6_COMMAND: {
+#ifdef USE_TOSI_ISO
+               struct scsi_rw_6 *param = (void *)cmd;
+



Home | Main Index | Thread Index | Old Index