Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Port the FreeBSD `umass' driver to NetBSD. This...
details: https://anonhg.NetBSD.org/src/rev/f15bd42f7ddf
branches: trunk
changeset: 475879:f15bd42f7ddf
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Aug 29 00:30:08 1999 +0000
description:
Port the FreeBSD `umass' driver to NetBSD. This is still a work-in-progress
since a few things don't yet work properly:
- Sense data isn't reported properly (err, at all).
- It doesn't work with anything other than the Iomega USB Zip drive.
- Hot-unplug doesn't work yet.
...but this is enough to make my shiny new USB Zip drive go.
diffstat:
sys/dev/usb/umass.c | 687 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 687 insertions(+), 0 deletions(-)
diffs (truncated from 691 to 300 lines):
diff -r f1cc98bf769b -r f15bd42f7ddf sys/dev/usb/umass.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/umass.c Sun Aug 29 00:30:08 1999 +0000
@@ -0,0 +1,687 @@
+/* $NetBSD: umass.c,v 1.1 1999/08/29 00:30:08 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1999 MAEKAWA Masahide <bishop%rr.iij4u.or.jp@localhost>,
+ * Nick Hibma <hibma%skylink.it@localhost>
+ * 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 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 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.
+ *
+ * FreeBSD: src/sys/dev/usb/umass.c,v 1.8 1999/06/20 15:46:13 n_hibma Exp
+ */
+
+/*
+ * Universal Serial Bus Mass Storage Class Bulk-Only Transport
+ * http://www.usb.org/developers/usbmassbulk_09.pdf
+ *
+ * Relevant parts have been quoted in the source.
+ */
+
+/* To do:
+ * x The umass_usb_transfer routine uses synchroneous transfers. This
+ * should be changed to async and state handling.
+ *
+ * x Should handle more than just Iomega USB Zip drives. There are
+ * a fair number of USB->SCSI dongles out there.
+ */
+
+/* Authors: (with short acronyms for comments)
+ * NWH - Nick Hibma <hibma%skylink.it@localhost>
+ * JRT - Jason R. Thorpe <thorpej%shagadelic.org@localhost>
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/buf.h>
+#include <sys/proc.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+
+#include <dev/scsipi/scsi_all.h>
+#include <dev/scsipi/scsipi_all.h>
+#include <dev/scsipi/scsiconf.h>
+
+#ifdef UMASS_DEBUG
+#define DPRINTF(m, x) if (umassdebug & (m)) logprintf x
+#define UDMASS_SCSI 0x00020000
+#define UDMASS_USB 0x00040000
+#define UDMASS_BULK 0x00080000
+#define UDMASS_ALL 0xffff0000
+int umassdebug = /* UDMASS_SCSI|UDMASS_BULK|UDMASS_USB */ 0;
+#else
+#define DPRINTF(m, x)
+#endif
+
+typedef struct umass_softc {
+ bdevice sc_dev; /* base device */
+ usbd_interface_handle sc_iface; /* the interface we use */
+
+ u_int8_t sc_bulkout; /* bulk-out Endpoint Address */
+ usbd_pipe_handle sc_bulkout_pipe;
+ u_int8_t sc_bulkin; /* bulk-in Endpoint Address */
+ usbd_pipe_handle sc_bulkin_pipe;
+
+ struct scsipi_link sc_link; /* prototype for devs */
+ struct scsipi_adapter sc_adapter;
+} umass_softc_t;
+
+#define USBD_COMMAND_FAILED USBD_INVAL /* redefine some errors for */
+
+#define UPROTO_MASS_ZIP 0x50 /* letter 'P' for protoype */
+
+#define UMASS_SCSIID_HOST 0x00
+#define UMASS_SCSIID_DEVICE 0x01
+
+#define DIR_OUT 0
+#define DIR_IN 1
+#define DIR_NONE 2
+
+/* Bulk-Only specific request */
+#define UR_RESET 0xff
+
+/* Bulk-Only Mass Storage features */
+/* Command Block Wrapper */
+typedef struct {
+ uDWord dCBWSignature;
+#define CBWSIGNATURE 0x43425355
+ uDWord dCBWTag;
+ uDWord dCBWDataTransferLength;
+ uByte bCBWFlags;
+#define CBWFLAGS_OUT 0x00
+#define CBWFLAGS_IN 0x80
+ uByte bCBWLUN;
+ uByte bCDBLength;
+ uByte CBWCDB[16];
+} usb_bulk_cbw_t;
+#define USB_BULK_CBW_SIZE 31
+
+/* Command Status Wrapper */
+typedef struct {
+ uDWord dCSWSignature;
+#define CSWSIGNATURE 0x53425355
+ uDWord dCSWTag;
+ uDWord dCSWDataResidue;
+ uByte bCSWStatus;
+#define CSWSTATUS_GOOD 0x0
+#define CSWSTATUS_FAILED 0x1
+#define CSWSTATUS_PHASE 0x2
+} usb_bulk_csw_t;
+#define USB_BULK_CSW_SIZE 13
+
+
+USB_DECLARE_DRIVER(umass);
+
+/* USB related functions */
+usbd_status umass_usb_transfer __P((usbd_interface_handle iface,
+ usbd_pipe_handle pipe,
+ void *buf, int buflen,
+ int flags, int *xfer_size));
+
+/* Bulk-Only related functions */
+usbd_status umass_bulk_reset __P((umass_softc_t *sc));
+usbd_status umass_bulk_transfer __P((umass_softc_t *sc, int lun,
+ void *cmd, int cmdlen,
+ void *data, int datalen,
+ int dir, int *residue));
+
+/* SCSIPI related functions */
+struct scsipi_device umass_dev = {
+ NULL, /* Use default error handler */
+ NULL, /* have a queue, served by this */
+ NULL, /* have no async handler */
+ NULL, /* Use default `done' routine */
+};
+
+void umass_minphys __P((struct buf *));
+int umass_scsi_cmd __P((struct scsipi_xfer *));
+
+
+
+USB_MATCH(umass)
+{
+ USB_MATCH_START(umass, uaa);
+ usb_interface_descriptor_t *id;
+
+ if (!uaa->iface)
+ return(UMATCH_NONE);
+
+ id = usbd_get_interface_descriptor(uaa->iface);
+ if (id
+ && id->bInterfaceClass == UCLASS_MASS
+ && id->bInterfaceSubClass == USUBCLASS_SCSI
+ && id->bInterfaceProtocol == UPROTO_MASS_ZIP)
+ /* probe the Iomega USB Zip 100 drive */
+ return(UMATCH_VENDOR_IFACESUBCLASS_IFACEPROTO);
+
+ return(UMATCH_NONE);
+}
+
+USB_ATTACH(umass)
+{
+ USB_ATTACH_START(umass, sc, uaa);
+ usb_interface_descriptor_t *id;
+ usb_endpoint_descriptor_t *ed;
+ char devinfo[1024];
+ int i;
+ int err;
+
+ sc->sc_iface = uaa->iface;
+ sc->sc_bulkout_pipe = NULL;
+ sc->sc_bulkin_pipe = NULL;
+
+ usbd_devinfo(uaa->device, 0, devinfo);
+ USB_ATTACH_SETUP;
+
+ id = usbd_get_interface_descriptor(sc->sc_iface);
+ printf("%s: %s, iclass %d/%d/%d\n", USBDEVNAME(sc->sc_dev), devinfo,
+ id->bInterfaceClass, id->bInterfaceSubClass,
+ id->bInterfaceProtocol);
+
+ /*
+ * A Bulk-Only Mass Storage device supports the following endpoints,
+ * in addition to the Endpoint 0 for Control transfer that is required
+ * of all USB devices:
+ * (a) bulk-in endpoint.
+ * (b) bulk-out endpoint.
+ *
+ * The endpoint addresses are not fixed, so we have to read them
+ * from the device descriptors of the current interface.
+ */
+ for (i = 0 ; i < id->bNumEndpoints ; i++) {
+ ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
+ if (!ed) {
+ printf("%s: could not read endpoint descriptor\n",
+ USBDEVNAME(sc->sc_dev));
+ USB_ATTACH_ERROR_RETURN;
+ }
+ if (UE_GET_DIR(ed->bEndpointAddress) == UE_IN
+ && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
+ sc->sc_bulkin = ed->bEndpointAddress;
+ } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_OUT
+ && (ed->bmAttributes & UE_XFERTYPE) == UE_BULK) {
+ sc->sc_bulkout = ed->bEndpointAddress;
+ }
+ }
+
+ /* Open the bulk-in and -out pipe */
+ err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout,
+ USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
+ if (err) {
+ DPRINTF(UDMASS_USB, ("cannot open bulk out pipe (address %d)\n",
+ sc->sc_bulkout));
+ USB_ATTACH_ERROR_RETURN;
+ }
+ err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin,
+ USBD_EXCLUSIVE_USE, &sc->sc_bulkin_pipe);
+ if (err) {
+ DPRINTF(UDMASS_USB, ("cannot open bulk in pipe (address %d)\n",
+ sc->sc_bulkin));
+ usbd_close_pipe(sc->sc_bulkout_pipe);
+ USB_ATTACH_ERROR_RETURN;
+ }
+
+ /* attach the device to the SCSI layer */
+ sc->sc_adapter.scsipi_cmd = umass_scsi_cmd;
+ sc->sc_adapter.scsipi_minphys = umass_minphys;
+
+ sc->sc_link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
+ sc->sc_link.adapter_softc = sc;
+ sc->sc_link.scsipi_scsi.adapter_target = UMASS_SCSIID_HOST;
+ sc->sc_link.adapter = &sc->sc_adapter;
+ sc->sc_link.device = &umass_dev;
+ sc->sc_link.openings = 4; /* XXX */
+ sc->sc_link.scsipi_scsi.max_target = UMASS_SCSIID_DEVICE; /* XXX */
+ sc->sc_link.scsipi_scsi.max_lun = 0; /* XXX */
+ sc->sc_link.type = BUS_SCSI;
+
+ if (config_found(&sc->sc_dev, &sc->sc_link, scsiprint) == NULL) {
+ usbd_close_pipe(sc->sc_bulkout_pipe);
+ usbd_close_pipe(sc->sc_bulkin_pipe);
+ /* XXX Not really an error. */
+ USB_ATTACH_ERROR_RETURN;
+ }
+
+ USB_ATTACH_SUCCESS_RETURN;
+}
+
+int
+umass_activate(self, act)
+ struct device *self;
+ enum devact act;
+{
+
+ switch (act) {
+ case DVACT_ACTIVATE:
+ return (EOPNOTSUPP);
+ break;
+
+ case DVACT_DEACTIVATE:
+ /* XXX Not supported yet. */
+ return (EOPNOTSUPP);
+ break;
+ }
+ return (0);
+}
+
+int
+umass_detach(self, flags)
+ struct device *self;
+ int flags;
+{
+
+ /* XXX Not supported yet. */
Home |
Main Index |
Thread Index |
Old Index