Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.97
      1 /*	$NetBSD: umass_quirks.c,v 1.97 2016/04/23 10:15:32 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by MAEKAWA Masahide (gehenna (at) NetBSD.org).
      9  * This code is derived from software contributed to The NetBSD Foundation
     10  * by Charles M. Hannum.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31  * POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: umass_quirks.c,v 1.97 2016/04/23 10:15:32 skrll Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/buf.h>
     41 
     42 #include <dev/scsipi/scsipi_all.h> /* for scsiconf.h below */
     43 #include <dev/scsipi/scsiconf.h> /* for quirks defines */
     44 
     45 #include <dev/usb/usb.h>
     46 #include <dev/usb/usbdi.h>
     47 #include <dev/usb/usbdevs.h>
     48 
     49 #include <dev/usb/umassvar.h>
     50 #include <dev/usb/umass_quirks.h>
     51 
     52 Static usbd_status umass_init_insystem(struct umass_softc *);
     53 Static usbd_status umass_init_shuttle(struct umass_softc *);
     54 
     55 Static void umass_fixup_sony(struct umass_softc *);
     56 
     57 /*
     58  * XXX
     59  * PLEASE NOTE that if you want quirk entries added to this table, you MUST
     60  * compile a kernel with USB_DEBUG, and submit a full log of the output from
     61  * whatever operation is "failing" with ?hcidebug=20 or higher and
     62  * umassdebug=0xffffff.  (It's usually helpful to also set MSGBUFSIZE to
     63  * something "large" unless you're using a serial console.)  Without this
     64  * information, the source of the problem cannot be properly analyzed, and
     65  * the quirk entry WILL NOT be accepted.
     66  * Also, when an entry is committed to this table, a concise but clear
     67  * description of the problem MUST accompany it.
     68  * - mycroft
     69  */
     70 Static const struct umass_quirk umass_quirks[] = {
     71 	/*
     72 	 * The following 3 In-System Design adapters use a non-standard ATA
     73 	 * over BBB protocol.  Force this protocol by quirk entries.
     74 	 */
     75 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
     76 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     77 	  0,
     78 	  0,
     79 	  UMATCH_VENDOR_PRODUCT,
     80 	  NULL, NULL
     81 	},
     82 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
     83 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     84 	  0,
     85 	  0,
     86 	  UMATCH_VENDOR_PRODUCT,
     87 	  NULL, NULL
     88 	},
     89 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
     90 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     91 	  0,
     92 	  0,
     93 	  UMATCH_VENDOR_PRODUCT,
     94 	  NULL, NULL
     95 	},
     96 
     97 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
     98 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
     99 	  0,
    100 	  0,
    101 	  UMATCH_VENDOR_PRODUCT,
    102 	  umass_init_insystem, NULL
    103 	},
    104 
    105 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    106 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    107 	  0,
    108 	  0,
    109 	  UMATCH_VENDOR_PRODUCT,
    110 	  umass_init_shuttle, NULL
    111 	},
    112 
    113 	/*
    114 	 * These work around genuine device bugs -- returning the wrong info in
    115 	 * the CSW block.
    116 	 */
    117 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
    118 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    119 	  UMASS_QUIRK_WRONG_CSWSIG,
    120 	  0,
    121 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    122 	  NULL, NULL
    123 	},
    124 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    125 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    126 	  UMASS_QUIRK_WRONG_CSWTAG,
    127 	  0,
    128 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    129 	  NULL, NULL
    130 	},
    131 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA },
    132 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    133 	  UMASS_QUIRK_WRONG_CSWTAG,
    134 	  0,
    135 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    136 	  NULL, NULL
    137 	},
    138 
    139 	/*
    140 	 * Some Sony cameras advertise a subclass code of 0xff, so we force it
    141 	 * to the correct value iff necessary.
    142 	 */
    143 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC },
    144 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    145 	  UMASS_QUIRK_RBC_PAD_TO_12,
    146 	  0,
    147 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    148 	  NULL, umass_fixup_sony
    149 	},
    150 
    151 	/*
    152 	 * Stupid device reports itself as SFF-8070, but actually returns a UFI
    153 	 * interrupt descriptor.  - mycroft, 2004/06/28
    154 	 */
    155 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS },
    156 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    157 	  0,
    158 	  0,
    159 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    160 	  NULL, NULL
    161 	},
    162 
    163 	/*
    164 	 * The SONY Portable GPS strage device almost hangs up when request
    165 	 * UR_BBB_GET_MAX_LUN - disable the query logic.
    166 	 */
    167 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_GPS_CS1 },
    168 	  UMASS_WPROTO_BBB, UMASS_CPROTO_UNSPEC,
    169 	  UMASS_QUIRK_NOGETMAXLUN,
    170 	  0,
    171 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    172 	  NULL, NULL
    173 	},
    174 
    175 	/*
    176 	 * The DiskOnKey does not reject commands it doesn't recognize in a
    177 	 * sane way -- rather than STALLing the bulk pipe, it continually NAKs
    178 	 * until we time out.  To prevent being screwed by this, for now we
    179 	 * disable 10-byte MODE SENSE the klugy way.  - mycroft, 2003/10/16
    180 	 */
    181 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY },
    182 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    183 	  0,
    184 	  PQUIRK_NOBIGMODESENSE,
    185 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    186 	  NULL, NULL
    187 	},
    188 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 },
    189 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    190 	  0,
    191 	  PQUIRK_NOBIGMODESENSE,
    192 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    193 	  NULL, NULL
    194 	},
    195 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY3 },
    196 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    197 	  0,
    198 	  PQUIRK_NOBIGMODESENSE,
    199 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    200 	  NULL, NULL
    201 	},
    202 	/* Some Sigmatel-based devices don't like all SCSI commands */
    203 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_MUSICSTICK },
    204 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    205 	  0,
    206 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    207 	  UMATCH_VENDOR_PRODUCT,
    208 	  NULL, NULL
    209 	},
    210 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD100 },
    211 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    212 	  0,
    213 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    214 	  UMATCH_VENDOR_PRODUCT,
    215 	  NULL, NULL
    216 	},
    217 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD150 },
    218 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    219 	  0,
    220 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    221 	  UMATCH_VENDOR_PRODUCT,
    222 	  NULL, NULL
    223 	},
    224 	{ { USB_VENDOR_PHILIPS, USB_PRODUCT_PHILIPS_SA235 },
    225 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    226 	  0,
    227 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    228 	  UMATCH_VENDOR_PRODUCT,
    229 	  NULL, NULL
    230 	},
    231 	/* Creative Nomad MuVo, NetBSD PR 30389, FreeBSD PR 53094 */
    232 	{ { USB_VENDOR_CREATIVE, USB_PRODUCT_CREATIVE_NOMAD },
    233 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    234 	  0,
    235 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    236 	  UMATCH_VENDOR_PRODUCT,
    237 	  NULL, NULL
    238 	},
    239 
    240 	/* iRiver iFP-[135]xx players fail on PREVENT/ALLOW, see PR 25440 */
    241 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_1XX },
    242 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    243 	  0,
    244 	  PQUIRK_NODOORLOCK,
    245 	  UMATCH_VENDOR_PRODUCT,
    246 	  NULL, NULL
    247 	},
    248 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_3XX },
    249 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    250 	  0,
    251 	  PQUIRK_NODOORLOCK,
    252 	  UMATCH_VENDOR_PRODUCT,
    253 	  NULL, NULL
    254 	},
    255 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_5XX },
    256 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    257 	  0,
    258 	  PQUIRK_NODOORLOCK,
    259 	  UMATCH_VENDOR_PRODUCT,
    260 	  NULL, NULL
    261 	},
    262 
    263 	/* Meizu M6 doesn't like synchronize-cache, see PR 40442 */
    264 	{ { USB_VENDOR_MEIZU, USB_PRODUCT_MEIZU_M6_SL },
    265 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    266 	  0,
    267 	  PQUIRK_NOSYNCCACHE,
    268 	  UMATCH_VENDOR_PRODUCT,
    269 	  NULL, NULL
    270 	},
    271 
    272 	/*
    273 	 * SanDisk Sansa Clip rejects cache sync in unconventional way.
    274 	 * However, unlike some other devices listed in this table,
    275 	 * this is does not cause the device firmware to stop responding.
    276 	 */
    277 	{ { USB_VENDOR_SANDISK, USB_PRODUCT_SANDISK_SANSA_CLIP },
    278 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    279 	  0,
    280 	  PQUIRK_NOSYNCCACHE,
    281 	  UMATCH_VENDOR_PRODUCT,
    282 	  NULL, NULL
    283 	},
    284 
    285 	/* Kingston USB pendrives don't like being told to lock the door */
    286 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DT101_II },
    287 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    288 	  0,
    289 	  PQUIRK_NODOORLOCK,
    290 	  UMATCH_VENDOR_PRODUCT,
    291 	  NULL, NULL
    292 	},
    293 
    294 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DT101_G2 },
    295 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    296 	  0,
    297 	  PQUIRK_NODOORLOCK,
    298 	  UMATCH_VENDOR_PRODUCT,
    299 	  NULL, NULL
    300 	},
    301 
    302 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DT102_G2 },
    303 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    304 	  0,
    305 	  PQUIRK_NODOORLOCK,
    306 	  UMATCH_VENDOR_PRODUCT,
    307 	  NULL, NULL
    308 	},
    309 
    310 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DTMINI10 },
    311 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    312 	  0,
    313 	  PQUIRK_NODOORLOCK,
    314 	  UMATCH_VENDOR_PRODUCT,
    315 	  NULL, NULL
    316 	},
    317 
    318 	/* Also, some Kingston pendrives have Toshiba vendor ID */
    319 	{ { USB_VENDOR_TOSHIBA, USB_PRODUCT_KINGSTON_DT100_G2 },
    320 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    321 	  0,
    322 	  PQUIRK_NODOORLOCK,
    323 	  UMATCH_VENDOR_PRODUCT,
    324 	  NULL, NULL
    325 	},
    326 
    327 	/* HP USB pendrives don't like being told to lock the door */
    328 	{ { USB_VENDOR_HP, USB_PRODUCT_HP_V125W },
    329 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    330 	  0,
    331 	  PQUIRK_NODOORLOCK,
    332 	  UMATCH_VENDOR_PRODUCT,
    333 	  NULL, NULL
    334 	},
    335 
    336 	{ { USB_VENDOR_IODATA2, USB_PRODUCT_IODATA2_USB2SC },
    337 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    338 	  0,
    339 	  0,
    340 	  UMATCH_VENDOR_PRODUCT,
    341 	  NULL, NULL
    342 	},
    343 };
    344 
    345 const struct umass_quirk *
    346 umass_lookup(uint16_t vendor, uint16_t product)
    347 {
    348 	return (const struct umass_quirk *)
    349 		usb_lookup(umass_quirks, vendor, product);
    350 }
    351 
    352 Static usbd_status
    353 umass_init_insystem(struct umass_softc *sc)
    354 {
    355 	usbd_status err;
    356 
    357 	err = usbd_set_interface(sc->sc_iface, 1);
    358 	if (err) {
    359 		DPRINTF(UDMASS_USB,
    360 			("%s: could not switch to Alt Interface 1\n",
    361 			device_xname(sc->sc_dev)));
    362 		return err;
    363 	}
    364 
    365 	return USBD_NORMAL_COMPLETION;
    366 }
    367 
    368 Static usbd_status
    369 umass_init_shuttle(struct umass_softc *sc)
    370 {
    371 	usb_device_request_t req;
    372 	uint8_t status[2];
    373 
    374 	/* The Linux driver does this */
    375 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    376 	req.bRequest = 1;
    377 	USETW(req.wValue, 0);
    378 	USETW(req.wIndex, sc->sc_ifaceno);
    379 	USETW(req.wLength, sizeof(status));
    380 
    381 	return usbd_do_request(sc->sc_udev, &req, &status);
    382 }
    383 
    384 Static void
    385 umass_fixup_sony(struct umass_softc *sc)
    386 {
    387 	usb_interface_descriptor_t *id;
    388 
    389 	id = usbd_get_interface_descriptor(sc->sc_iface);
    390 	if (id->bInterfaceSubClass == 0xff)
    391 		sc->sc_cmd = UMASS_CPROTO_RBC;
    392 }
    393