Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.71.28.1
      1  1.71.28.1       mjf /*	$NetBSD: umass_quirks.c,v 1.71.28.1 2008/02/18 21:06:26 mjf Exp $	*/
      2        1.1   gehenna 
      3        1.1   gehenna /*
      4       1.68   mycroft  * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
      5        1.1   gehenna  * All rights reserved.
      6        1.1   gehenna  *
      7        1.1   gehenna  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1   gehenna  * by MAEKAWA Masahide (gehenna (at) NetBSD.org).
      9       1.68   mycroft  * This code is derived from software contributed to The NetBSD Foundation
     10       1.68   mycroft  * by Charles M. Hannum.
     11        1.1   gehenna  *
     12        1.1   gehenna  * Redistribution and use in source and binary forms, with or without
     13        1.1   gehenna  * modification, are permitted provided that the following conditions
     14        1.1   gehenna  * are met:
     15        1.1   gehenna  * 1. Redistributions of source code must retain the above copyright
     16        1.1   gehenna  *    notice, this list of conditions and the following disclaimer.
     17        1.1   gehenna  * 2. Redistributions in binary form must reproduce the above copyright
     18        1.1   gehenna  *    notice, this list of conditions and the following disclaimer in the
     19        1.1   gehenna  *    documentation and/or other materials provided with the distribution.
     20        1.1   gehenna  * 3. All advertising materials mentioning features or use of this software
     21        1.1   gehenna  *    must display the following acknowledgement:
     22        1.1   gehenna  *	  This product includes software developed by the NetBSD
     23        1.1   gehenna  *	  Foundation, Inc. and its contributors.
     24        1.1   gehenna  * 4. Neither the name of The NetBSD Foundation nor the names of its
     25        1.1   gehenna  *    contributors may be used to endorse or promote products derived
     26        1.1   gehenna  *    from this software without specific prior written permission.
     27        1.1   gehenna  *
     28        1.1   gehenna  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     29        1.1   gehenna  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     30        1.1   gehenna  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     31        1.1   gehenna  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     32        1.1   gehenna  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     33        1.1   gehenna  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     34        1.1   gehenna  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     35        1.1   gehenna  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     36        1.1   gehenna  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     37        1.1   gehenna  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38        1.1   gehenna  * POSSIBILITY OF SUCH DAMAGE.
     39        1.1   gehenna  */
     40       1.44     lukem 
     41       1.44     lukem #include <sys/cdefs.h>
     42  1.71.28.1       mjf __KERNEL_RCSID(0, "$NetBSD: umass_quirks.c,v 1.71.28.1 2008/02/18 21:06:26 mjf Exp $");
     43        1.1   gehenna 
     44        1.1   gehenna #include <sys/param.h>
     45        1.1   gehenna #include <sys/systm.h>
     46        1.1   gehenna #include <sys/device.h>
     47        1.1   gehenna #include <sys/buf.h>
     48        1.1   gehenna 
     49        1.7  augustss #include <dev/scsipi/scsipi_all.h> /* for scsiconf.h below */
     50        1.7  augustss #include <dev/scsipi/scsiconf.h> /* for quirks defines */
     51        1.7  augustss 
     52        1.1   gehenna #include <dev/usb/usb.h>
     53        1.1   gehenna #include <dev/usb/usbdi.h>
     54        1.1   gehenna #include <dev/usb/usbdevs.h>
     55        1.1   gehenna 
     56        1.1   gehenna #include <dev/usb/umassvar.h>
     57        1.1   gehenna #include <dev/usb/umass_quirks.h>
     58        1.1   gehenna 
     59        1.1   gehenna Static usbd_status umass_init_insystem(struct umass_softc *);
     60        1.1   gehenna Static usbd_status umass_init_shuttle(struct umass_softc *);
     61  1.71.28.1       mjf Static usbd_status umass_init_e220(struct umass_softc *);
     62        1.1   gehenna 
     63       1.25       cjs Static void umass_fixup_sony(struct umass_softc *);
     64        1.1   gehenna 
     65       1.65   mycroft /*
     66       1.65   mycroft  * XXX
     67       1.65   mycroft  * PLEASE NOTE that if you want quirk entries added to this table, you MUST
     68       1.65   mycroft  * compile a kernel with USB_DEBUG, and submit a full log of the output from
     69       1.65   mycroft  * whatever operation is "failing" with ?hcidebug=20 or higher and
     70       1.65   mycroft  * umassdebug=0xffffff.  (It's usually helpful to also set MSGBUFSIZE to
     71       1.65   mycroft  * something "large" unless you're using a serial console.)  Without this
     72       1.65   mycroft  * information, the source of the problem cannot be properly analyzed, and
     73       1.65   mycroft  * the quirk entry WILL NOT be accepted.
     74       1.65   mycroft  * Also, when an entry is committed to this table, a concise but clear
     75       1.65   mycroft  * description of the problem MUST accompany it.
     76       1.65   mycroft  * - mycroft
     77       1.65   mycroft  */
     78        1.1   gehenna Static const struct umass_quirk umass_quirks[] = {
     79       1.63  augustss 	/*
     80       1.63  augustss 	 * The following 3 In-System Design adapters use a non-standard ATA
     81       1.63  augustss 	 * over BBB protocol.  Force this protocol by quirk entries.
     82       1.63  augustss 	 */
     83       1.63  augustss 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
     84       1.63  augustss 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     85       1.63  augustss 	  0,
     86       1.63  augustss 	  0,
     87       1.63  augustss 	  UMATCH_VENDOR_PRODUCT,
     88       1.63  augustss 	  NULL, NULL
     89       1.63  augustss 	},
     90       1.63  augustss 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
     91       1.63  augustss 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     92       1.63  augustss 	  0,
     93       1.63  augustss 	  0,
     94       1.63  augustss 	  UMATCH_VENDOR_PRODUCT,
     95       1.63  augustss 	  NULL, NULL
     96       1.63  augustss 	},
     97       1.63  augustss 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
     98       1.63  augustss 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     99       1.63  augustss 	  0,
    100       1.63  augustss 	  0,
    101       1.63  augustss 	  UMATCH_VENDOR_PRODUCT,
    102       1.63  augustss 	  NULL, NULL
    103       1.63  augustss 	},
    104       1.63  augustss 
    105        1.1   gehenna 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
    106        1.1   gehenna 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
    107       1.49   mycroft 	  0,
    108       1.56   mycroft 	  0,
    109        1.1   gehenna 	  UMATCH_VENDOR_PRODUCT,
    110        1.1   gehenna 	  umass_init_insystem, NULL
    111       1.32  augustss 	},
    112       1.32  augustss 
    113       1.58   mycroft 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    114       1.58   mycroft 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    115       1.58   mycroft 	  0,
    116       1.58   mycroft 	  0,
    117       1.58   mycroft 	  UMATCH_VENDOR_PRODUCT,
    118       1.58   mycroft 	  umass_init_shuttle, NULL
    119       1.58   mycroft 	},
    120       1.58   mycroft 
    121       1.58   mycroft 	/*
    122       1.62       wiz 	 * These work around genuine device bugs -- returning the wrong info in
    123       1.58   mycroft 	 * the CSW block.
    124       1.58   mycroft 	 */
    125        1.1   gehenna 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
    126        1.1   gehenna 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    127        1.1   gehenna 	  UMASS_QUIRK_WRONG_CSWSIG,
    128        1.7  augustss 	  0,
    129       1.59   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    130       1.23   gehenna 	  NULL, NULL
    131       1.23   gehenna 	},
    132        1.1   gehenna 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    133       1.58   mycroft 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    134       1.28       erh 	  UMASS_QUIRK_WRONG_CSWTAG,
    135        1.7  augustss 	  0,
    136       1.59   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    137       1.64   kivinen 	  NULL, NULL
    138       1.64   kivinen 	},
    139       1.64   kivinen 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA },
    140       1.64   kivinen 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    141       1.64   kivinen 	  UMASS_QUIRK_WRONG_CSWTAG,
    142       1.64   kivinen 	  0,
    143       1.67   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    144        1.1   gehenna 	  NULL, NULL
    145        1.1   gehenna 	},
    146        1.1   gehenna 
    147       1.58   mycroft 	/*
    148       1.58   mycroft 	 * Some Sony cameras advertise a subclass code of 0xff, so we force it
    149       1.58   mycroft 	 * to the correct value iff necessary.
    150       1.58   mycroft 	 */
    151       1.26       cjs 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC },
    152       1.25       cjs 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    153       1.71  christos 	  UMASS_QUIRK_RBC_PAD_TO_12,
    154       1.43    martin 	  0,
    155       1.43    martin 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    156       1.43    martin 	  NULL, umass_fixup_sony
    157       1.57   mycroft 	},
    158       1.57   mycroft 
    159       1.57   mycroft 	/*
    160       1.66   mycroft 	 * Stupid device reports itself as SFF-8070, but actually returns a UFI
    161       1.66   mycroft 	 * interrupt descriptor.  - mycroft, 2004/06/28
    162       1.66   mycroft 	 */
    163       1.66   mycroft 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS },
    164       1.66   mycroft 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    165       1.66   mycroft 	  0,
    166       1.66   mycroft 	  0,
    167       1.67   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    168       1.66   mycroft 	  NULL, NULL
    169       1.66   mycroft 	},
    170       1.66   mycroft 
    171       1.66   mycroft 	/*
    172       1.57   mycroft 	 * The DiskOnKey does not reject commands it doesn't recognize in a
    173       1.57   mycroft 	 * sane way -- rather than STALLing the bulk pipe, it continually NAKs
    174       1.57   mycroft 	 * until we time out.  To prevent being screwed by this, for now we
    175       1.57   mycroft 	 * disable 10-byte MODE SENSE the klugy way.  - mycroft, 2003/10/16
    176       1.57   mycroft 	 */
    177       1.57   mycroft 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY },
    178       1.57   mycroft 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    179       1.57   mycroft 	  0,
    180       1.57   mycroft 	  PQUIRK_NOBIGMODESENSE,
    181       1.59   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    182       1.57   mycroft 	  NULL, NULL
    183       1.57   mycroft 	},
    184       1.57   mycroft 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 },
    185       1.57   mycroft 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    186       1.57   mycroft 	  0,
    187       1.57   mycroft 	  PQUIRK_NOBIGMODESENSE,
    188       1.59   mycroft 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    189       1.36  augustss 	  NULL, NULL
    190        1.4  augustss 	},
    191       1.69      cube 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY3 },
    192       1.69      cube 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    193       1.69      cube 	  0,
    194       1.69      cube 	  PQUIRK_NOBIGMODESENSE,
    195       1.69      cube 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    196       1.69      cube 	  NULL, NULL
    197       1.69      cube 	},
    198  1.71.28.1       mjf 	{ { USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 },
    199  1.71.28.1       mjf 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    200  1.71.28.1       mjf 	  0,
    201  1.71.28.1       mjf 	  0,
    202  1.71.28.1       mjf 	  UMASS_QUIRK_USE_DEFAULTMATCH, /* use default MATCH function */
    203  1.71.28.1       mjf 	  umass_init_e220, NULL
    204  1.71.28.1       mjf 	},
    205        1.1   gehenna };
    206        1.1   gehenna 
    207        1.1   gehenna const struct umass_quirk *
    208        1.1   gehenna umass_lookup(u_int16_t vendor, u_int16_t product)
    209        1.1   gehenna {
    210        1.6  augustss 	return ((const struct umass_quirk *)
    211        1.6  augustss 		usb_lookup(umass_quirks, vendor, product));
    212        1.1   gehenna }
    213        1.1   gehenna 
    214        1.1   gehenna Static usbd_status
    215        1.1   gehenna umass_init_insystem(struct umass_softc *sc)
    216        1.1   gehenna {
    217        1.1   gehenna 	usbd_status err;
    218        1.1   gehenna 
    219        1.1   gehenna 	err = usbd_set_interface(sc->sc_iface, 1);
    220        1.1   gehenna 	if (err) {
    221        1.1   gehenna 		DPRINTF(UDMASS_USB,
    222        1.1   gehenna 			("%s: could not switch to Alt Interface 1\n",
    223        1.1   gehenna 			USBDEVNAME(sc->sc_dev)));
    224        1.1   gehenna 		return (err);
    225        1.1   gehenna 	}
    226        1.1   gehenna 
    227        1.1   gehenna 	return (USBD_NORMAL_COMPLETION);
    228        1.1   gehenna }
    229        1.1   gehenna 
    230        1.1   gehenna Static usbd_status
    231        1.1   gehenna umass_init_shuttle(struct umass_softc *sc)
    232        1.1   gehenna {
    233        1.1   gehenna 	usb_device_request_t req;
    234        1.1   gehenna 	u_int8_t status[2];
    235        1.1   gehenna 
    236        1.1   gehenna 	/* The Linux driver does this */
    237        1.1   gehenna 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    238        1.1   gehenna 	req.bRequest = 1;
    239        1.1   gehenna 	USETW(req.wValue, 0);
    240        1.1   gehenna 	USETW(req.wIndex, sc->sc_ifaceno);
    241        1.1   gehenna 	USETW(req.wLength, sizeof(status));
    242        1.1   gehenna 
    243        1.1   gehenna 	return (usbd_do_request(sc->sc_udev, &req, &status));
    244       1.25       cjs }
    245       1.25       cjs 
    246       1.25       cjs Static void
    247       1.25       cjs umass_fixup_sony(struct umass_softc *sc)
    248       1.25       cjs {
    249       1.25       cjs 	usb_interface_descriptor_t *id;
    250       1.25       cjs 
    251       1.25       cjs 	id = usbd_get_interface_descriptor(sc->sc_iface);
    252       1.53   mycroft 	if (id->bInterfaceSubClass == 0xff)
    253       1.71  christos 		sc->sc_cmd = UMASS_CPROTO_RBC;
    254        1.1   gehenna }
    255  1.71.28.1       mjf 
    256  1.71.28.1       mjf Static usbd_status
    257  1.71.28.1       mjf umass_init_e220(struct umass_softc *sc)
    258  1.71.28.1       mjf {
    259  1.71.28.1       mjf #define E220_UMASS_INTERFACE 2
    260  1.71.28.1       mjf 	usbd_status err;
    261  1.71.28.1       mjf 
    262  1.71.28.1       mjf 	if (sc->sc_ifaceno != E220_UMASS_INTERFACE)
    263  1.71.28.1       mjf 		return (USBD_NOT_CONFIGURED);
    264  1.71.28.1       mjf 
    265  1.71.28.1       mjf 	err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, &sc->sc_iface);
    266  1.71.28.1       mjf 	if (err) {
    267  1.71.28.1       mjf 		DPRINTF(UDMASS_USB,
    268  1.71.28.1       mjf 			("%s: could not switch to Alt Interface %d\n",
    269  1.71.28.1       mjf 			USBDEVNAME(sc->sc_dev), sc->sc_ifaceno));
    270  1.71.28.1       mjf 		return (err);
    271  1.71.28.1       mjf 	}
    272  1.71.28.1       mjf 
    273  1.71.28.1       mjf 	return (USBD_NORMAL_COMPLETION);
    274  1.71.28.1       mjf #undef E220_UMASS_INTERFACE
    275  1.71.28.1       mjf }
    276