Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Make the separation between wire protocol (umass...



details:   https://anonhg.NetBSD.org/src/rev/0c9862d7074b
branches:  trunk
changeset: 519691:0c9862d7074b
user:      augustss <augustss%NetBSD.org@localhost>
date:      Mon Dec 24 13:25:52 2001 +0000

description:
Make the separation between wire protocol (umass.c) and command protocol
(umass_scsipi.c) more distinct.
It is now possible to add new command protocols with a minimum of change.
The umassbus.[ch] files have been renamed umass_scsipi.[ch] since this
reflects their purpose better.

diffstat:

 sys/dev/usb/files.usb      |    4 +-
 sys/dev/usb/umass.c        |   81 +++++-
 sys/dev/usb/umass_quirks.c |    4 +-
 sys/dev/usb/umass_scsipi.c |  635 +++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/umass_scsipi.h |   41 ++
 sys/dev/usb/umassvar.h     |    9 +-
 6 files changed, 758 insertions(+), 16 deletions(-)

diffs (truncated from 901 to 300 lines):

diff -r 8a3697e970ea -r 0c9862d7074b sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb     Mon Dec 24 12:39:55 2001 +0000
+++ b/sys/dev/usb/files.usb     Mon Dec 24 13:25:52 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.usb,v 1.33 2001/12/17 12:16:14 gehenna Exp $
+#      $NetBSD: files.usb,v 1.34 2001/12/24 13:25:53 augustss Exp $
 #
 # Config file and device description for machine-independent USB code.
 # Included by ports that need it.  Ports that use it must provide
@@ -82,8 +82,8 @@
 device umass: scsi, atapi
 attach umass at uhub
 file   dev/usb/umass.c                 umass
-file   dev/usb/umassbus.c              umass
 file   dev/usb/umass_quirks.c          umass
+file   dev/usb/umass_scsipi.c          umass & (scsibus | atapibus)
 
 
 # IrDA bridges
diff -r 8a3697e970ea -r 0c9862d7074b sys/dev/usb/umass.c
--- a/sys/dev/usb/umass.c       Mon Dec 24 12:39:55 2001 +0000
+++ b/sys/dev/usb/umass.c       Mon Dec 24 13:25:52 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umass.c,v 1.78 2001/12/17 12:16:14 gehenna Exp $       */
+/*     $NetBSD: umass.c,v 1.79 2001/12/24 13:25:52 augustss Exp $      */
 /*-
  * Copyright (c) 1999 MAEKAWA Masahide <bishop%rr.iij4u.or.jp@localhost>,
  *                   Nick Hibma <n_hibma%freebsd.org@localhost>
@@ -94,9 +94,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.78 2001/12/17 12:16:14 gehenna Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass.c,v 1.79 2001/12/24 13:25:52 augustss Exp $");
 
 #include "atapibus.h"
+#include "scsibus.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -120,10 +121,9 @@
 #include <dev/usb/usbdi_util.h>
 #include <dev/usb/usbdevs.h>
 
-#include <dev/usb/umassbus.h>
 #include <dev/usb/umassvar.h>
 #include <dev/usb/umass_quirks.h>
-
+#include <dev/usb/umass_scsipi.h>
 
 
 #ifdef UMASS_DEBUG
@@ -266,7 +266,7 @@
        const char *sWire, *sCommand;
        char devinfo[1024];
        usbd_status err;
-       int i, bno;
+       int i, bno, error;
 
        usbd_devinfo(uaa->device, 0, devinfo);
        USB_ATTACH_SETUP;
@@ -558,12 +558,40 @@
                }
        }
 
-       if (umass_attach_bus(sc)) {
-               DPRINTF(UDMASS_GEN, ("%s: bus attach failed\n",
-                                    USBDEVNAME(sc->sc_dev)));
+       error = 0;
+       switch (sc->sc_cmd) {
+       case UMASS_CPROTO_RBC:
+       case UMASS_CPROTO_SCSI:
+#if NSCSIBUS > 0
+               error = umass_scsi_attach(sc);
+#else
+               printf("%s: atapibus not configured\n", USBDEVNAME(sc->sc_dev));
+#endif
+               break;
+
+       case UMASS_CPROTO_UFI:
+       case UMASS_CPROTO_ATAPI:
+#if NATAPIBUS > 0
+               error = umass_atapi_attach(sc);
+#else
+               printf("%s: scsibus not configured\n", USBDEVNAME(sc->sc_dev));
+#endif
+               break;
+
+       default:
+               printf("%s: command protocol=0x%x not supported\n",
+                      USBDEVNAME(sc->sc_dev), sc->sc_cmd);
                umass_disco(sc);
                USB_ATTACH_ERROR_RETURN;
        }
+       if (error) {
+               printf("%s: bus attach failed\n", USBDEVNAME(sc->sc_dev));
+               umass_disco(sc);
+               USB_ATTACH_ERROR_RETURN;
+       }
+
+       usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev,
+                          USBDEV(sc->sc_dev));
 
        DPRINTF(UDMASS_GEN, ("%s: Attach finished\n", USBDEVNAME(sc->sc_dev)));
 
@@ -573,6 +601,7 @@
 USB_DETACH(umass)
 {
        USB_DETACH_START(umass, sc);
+       struct umassbus_softc *scbus = sc->bus;
        int rv = 0, i;
 
        DPRINTF(UDMASS_USB, ("%s: detached\n", USBDEVNAME(sc->sc_dev)));
@@ -593,7 +622,12 @@
        splx(s);
 #endif
 
-       rv = umass_detach_bus(sc, flags);
+       if (scbus != NULL) {
+               if (scbus->sc_child != NULL)
+                       rv = config_detach(scbus->sc_child, flags);
+               free(scbus, M_DEVBUF);
+               sc->bus = NULL;
+       }
 
        if (rv != 0)
                return (rv);
@@ -603,7 +637,34 @@
        usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev,
                           USBDEV(sc->sc_dev));
 
-       return (0);
+       return (rv);
+}
+
+int
+umass_activate(struct device *dev, enum devact act)
+{
+       struct umass_softc *sc = (struct umass_softc *)dev;
+       struct umassbus_softc *scbus = sc->bus;
+       int rv = 0;
+
+       DPRINTF(UDMASS_USB, ("%s: umass_activate: %d\n",
+           USBDEVNAME(sc->sc_dev), act));
+
+       switch (act) {
+       case DVACT_ACTIVATE:
+               rv = EOPNOTSUPP;
+               break;
+
+       case DVACT_DEACTIVATE:
+               sc->sc_dying = 1;
+               if (scbus->sc_child == NULL)
+                       break;
+               rv = config_deactivate(scbus->sc_child);
+               DPRINTF(UDMASS_USB, ("%s: umass_activate: child "
+                   "returned %d\n", USBDEVNAME(sc->sc_dev), rv));
+               break;
+       }
+       return (rv);
 }
 
 Static void
diff -r 8a3697e970ea -r 0c9862d7074b sys/dev/usb/umass_quirks.c
--- a/sys/dev/usb/umass_quirks.c        Mon Dec 24 12:39:55 2001 +0000
+++ b/sys/dev/usb/umass_quirks.c        Mon Dec 24 13:25:52 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umass_quirks.c,v 1.2 2001/12/22 13:21:59 gehenna Exp $ */
+/*     $NetBSD: umass_quirks.c,v 1.3 2001/12/24 13:25:52 augustss Exp $        */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -45,7 +45,6 @@
 #include <dev/usb/usbdi.h>
 #include <dev/usb/usbdevs.h>
 
-#include <dev/usb/umassbus.h>
 #include <dev/usb/umassvar.h>
 #include <dev/usb/umass_quirks.h>
 
@@ -149,6 +148,7 @@
          UMATCH_VENDOR_PRODUCT_REV,
          NULL, umass_fixup_yedata
        },
+
 };
 
 const struct umass_quirk *
diff -r 8a3697e970ea -r 0c9862d7074b sys/dev/usb/umass_scsipi.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/umass_scsipi.c        Mon Dec 24 13:25:52 2001 +0000
@@ -0,0 +1,635 @@
+/*     $NetBSD: umass_scsipi.c,v 1.1 2001/12/24 13:25:52 augustss Exp $        */
+
+/*
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Lennart Augustsson (lennart%augustsson.net@localhost) at
+ * Carlstedt Research & Technology.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION 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: umass_scsipi.c,v 1.1 2001/12/24 13:25:52 augustss Exp $");
+
+#include "atapibus.h"
+#include "scsibus.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/conf.h>
+#include <sys/buf.h>
+#include <sys/device.h>
+#include <sys/ioctl.h>
+#include <sys/malloc.h>
+
+/* SCSI & ATAPI */
+#include <sys/scsiio.h>
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+#include <dev/scsipi/atapiconf.h>
+
+#include <dev/scsipi/scsipi_disk.h>
+#include <dev/scsipi/scsi_disk.h>
+#include <dev/scsipi/scsi_changer.h>
+
+#include <dev/scsipi/atapi_disk.h>
+
+#include <sys/disk.h>          /* XXX */
+#include <dev/scsipi/sdvar.h>  /* XXX */
+
+/* USB */
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdevs.h>
+
+#include <dev/usb/umassvar.h>
+#include <dev/usb/umass_scsipi.h>
+
+struct umass_scsipi_softc {
+       struct umassbus_softc   base;
+
+       struct atapi_adapter    sc_atapi_adapter;
+#define sc_adapter sc_atapi_adapter._generic
+       struct scsipi_channel sc_channel;
+       usbd_status             sc_sync_status;
+       struct scsipi_sense     sc_sense_cmd;
+};
+
+
+#define SHORT_INQUIRY_LENGTH    36 /* XXX */
+
+#define UMASS_SCSIID_HOST      0x00
+#define UMASS_SCSIID_DEVICE    0x01
+
+#define UMASS_ATAPI_DRIVE      0
+
+Static void umass_scsipi_request(struct scsipi_channel *,
+                                scsipi_adapter_req_t, void *);
+Static void umass_scsipi_minphys(struct buf *bp);
+Static int umass_scsipi_ioctl(struct scsipi_channel *, u_long,
+                             caddr_t, int, struct proc *);
+Static int umass_scsipi_getgeom(struct scsipi_periph *periph,
+                               struct disk_parms *, u_long sectors);
+
+Static void umass_scsipi_cb(struct umass_softc *sc, void *priv,
+                           int residue, int status);



Home | Main Index | Thread Index | Old Index