Home | History | Annotate | Line # | Download | only in usb
umass_quirks.c revision 1.100
      1 /*	$NetBSD: umass_quirks.c,v 1.100 2017/10/28 00:37:12 pgoyette 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.100 2017/10/28 00:37:12 pgoyette Exp $");
     36 
     37 #ifdef _KERNEL_OPT
     38 #include "opt_usb.h"
     39 #endif
     40 
     41 #include <sys/param.h>
     42 #include <sys/systm.h>
     43 #include <sys/device.h>
     44 #include <sys/buf.h>
     45 
     46 #include <dev/scsipi/scsipi_all.h> /* for scsiconf.h below */
     47 #include <dev/scsipi/scsiconf.h> /* for quirks defines */
     48 
     49 #include <dev/usb/usb.h>
     50 #include <dev/usb/usbdi.h>
     51 #include <dev/usb/usbdevs.h>
     52 #include <dev/usb/usbhist.h>
     53 
     54 #include <dev/usb/umassvar.h>
     55 #include <dev/usb/umass_quirks.h>
     56 
     57 Static usbd_status umass_init_insystem(struct umass_softc *);
     58 Static usbd_status umass_init_shuttle(struct umass_softc *);
     59 
     60 Static void umass_fixup_sony(struct umass_softc *);
     61 
     62 /*
     63  * XXX
     64  * PLEASE NOTE that if you want quirk entries added to this table, you MUST
     65  * compile a kernel with USB_DEBUG, and submit a full log of the output from
     66  * whatever operation is "failing" with ?hcidebug=20 or higher and
     67  * umassdebug=0xffffff.  (It's usually helpful to also set MSGBUFSIZE to
     68  * something "large" unless you're using a serial console.)  Without this
     69  * information, the source of the problem cannot be properly analyzed, and
     70  * the quirk entry WILL NOT be accepted.
     71  * Also, when an entry is committed to this table, a concise but clear
     72  * description of the problem MUST accompany it.
     73  * - mycroft
     74  */
     75 Static const struct umass_quirk umass_quirks[] = {
     76 	/*
     77 	 * The following 3 In-System Design adapters use a non-standard ATA
     78 	 * over BBB protocol.  Force this protocol by quirk entries.
     79 	 */
     80 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
     81 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     82 	  0,
     83 	  0,
     84 	  UMATCH_VENDOR_PRODUCT,
     85 	  NULL, NULL
     86 	},
     87 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
     88 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     89 	  0,
     90 	  0,
     91 	  UMATCH_VENDOR_PRODUCT,
     92 	  NULL, NULL
     93 	},
     94 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
     95 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
     96 	  0,
     97 	  0,
     98 	  UMATCH_VENDOR_PRODUCT,
     99 	  NULL, NULL
    100 	},
    101 
    102 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
    103 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
    104 	  0,
    105 	  0,
    106 	  UMATCH_VENDOR_PRODUCT,
    107 	  umass_init_insystem, NULL
    108 	},
    109 
    110 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
    111 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
    112 	  0,
    113 	  0,
    114 	  UMATCH_VENDOR_PRODUCT,
    115 	  umass_init_shuttle, NULL
    116 	},
    117 
    118 	/*
    119 	 * These work around genuine device bugs -- returning the wrong info in
    120 	 * the CSW block.
    121 	 */
    122 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
    123 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    124 	  UMASS_QUIRK_WRONG_CSWSIG,
    125 	  0,
    126 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    127 	  NULL, NULL
    128 	},
    129 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
    130 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    131 	  UMASS_QUIRK_WRONG_CSWTAG,
    132 	  0,
    133 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    134 	  NULL, NULL
    135 	},
    136 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA },
    137 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    138 	  UMASS_QUIRK_WRONG_CSWTAG,
    139 	  0,
    140 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    141 	  NULL, NULL
    142 	},
    143 
    144 	/*
    145 	 * Some Sony cameras advertise a subclass code of 0xff, so we force it
    146 	 * to the correct value iff necessary.
    147 	 */
    148 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC },
    149 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    150 	  UMASS_QUIRK_RBC_PAD_TO_12,
    151 	  0,
    152 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    153 	  NULL, umass_fixup_sony
    154 	},
    155 
    156 	/*
    157 	 * Stupid device reports itself as SFF-8070, but actually returns a UFI
    158 	 * interrupt descriptor.  - mycroft, 2004/06/28
    159 	 */
    160 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS },
    161 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
    162 	  0,
    163 	  0,
    164 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    165 	  NULL, NULL
    166 	},
    167 
    168 	/*
    169 	 * The SONY Portable GPS strage device almost hangs up when request
    170 	 * UR_BBB_GET_MAX_LUN - disable the query logic.
    171 	 */
    172 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_GPS_CS1 },
    173 	  UMASS_WPROTO_BBB, UMASS_CPROTO_UNSPEC,
    174 	  UMASS_QUIRK_NOGETMAXLUN,
    175 	  0,
    176 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    177 	  NULL, NULL
    178 	},
    179 
    180 	/*
    181 	 * The DiskOnKey does not reject commands it doesn't recognize in a
    182 	 * sane way -- rather than STALLing the bulk pipe, it continually NAKs
    183 	 * until we time out.  To prevent being screwed by this, for now we
    184 	 * disable 10-byte MODE SENSE the klugy way.  - mycroft, 2003/10/16
    185 	 */
    186 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY },
    187 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    188 	  0,
    189 	  PQUIRK_NOBIGMODESENSE,
    190 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    191 	  NULL, NULL
    192 	},
    193 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 },
    194 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    195 	  0,
    196 	  PQUIRK_NOBIGMODESENSE,
    197 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    198 	  NULL, NULL
    199 	},
    200 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY3 },
    201 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    202 	  0,
    203 	  PQUIRK_NOBIGMODESENSE,
    204 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
    205 	  NULL, NULL
    206 	},
    207 	/* Some Sigmatel-based devices don't like all SCSI commands */
    208 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_MUSICSTICK },
    209 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    210 	  0,
    211 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    212 	  UMATCH_VENDOR_PRODUCT,
    213 	  NULL, NULL
    214 	},
    215 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD100 },
    216 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    217 	  0,
    218 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    219 	  UMATCH_VENDOR_PRODUCT,
    220 	  NULL, NULL
    221 	},
    222 	{ { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD150 },
    223 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    224 	  0,
    225 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    226 	  UMATCH_VENDOR_PRODUCT,
    227 	  NULL, NULL
    228 	},
    229 	{ { USB_VENDOR_PHILIPS, USB_PRODUCT_PHILIPS_SA235 },
    230 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    231 	  0,
    232 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    233 	  UMATCH_VENDOR_PRODUCT,
    234 	  NULL, NULL
    235 	},
    236 	/* Creative Nomad MuVo, NetBSD PR 30389, FreeBSD PR 53094 */
    237 	{ { USB_VENDOR_CREATIVE, USB_PRODUCT_CREATIVE_NOMAD },
    238 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    239 	  0,
    240 	  PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE,
    241 	  UMATCH_VENDOR_PRODUCT,
    242 	  NULL, NULL
    243 	},
    244 
    245 	/* iRiver iFP-[135]xx players fail on PREVENT/ALLOW, see PR 25440 */
    246 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_1XX },
    247 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    248 	  0,
    249 	  PQUIRK_NODOORLOCK,
    250 	  UMATCH_VENDOR_PRODUCT,
    251 	  NULL, NULL
    252 	},
    253 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_3XX },
    254 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    255 	  0,
    256 	  PQUIRK_NODOORLOCK,
    257 	  UMATCH_VENDOR_PRODUCT,
    258 	  NULL, NULL
    259 	},
    260 	{ { USB_VENDOR_IRIVER, USB_PRODUCT_IRIVER_IFP_5XX },
    261 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    262 	  0,
    263 	  PQUIRK_NODOORLOCK,
    264 	  UMATCH_VENDOR_PRODUCT,
    265 	  NULL, NULL
    266 	},
    267 
    268 	/* Meizu M6 doesn't like synchronize-cache, see PR 40442 */
    269 	{ { USB_VENDOR_MEIZU, USB_PRODUCT_MEIZU_M6_SL },
    270 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    271 	  0,
    272 	  PQUIRK_NOSYNCCACHE,
    273 	  UMATCH_VENDOR_PRODUCT,
    274 	  NULL, NULL
    275 	},
    276 
    277 	/*
    278 	 * SanDisk Cruzer rejects cache sync.
    279 	 */
    280 	{ { USB_VENDOR_SANDISK, USB_PRODUCT_SANDISK_CRUZER },
    281 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    282 	  0,
    283 	  PQUIRK_NOSYNCCACHE,
    284 	  UMATCH_VENDOR_PRODUCT,
    285 	  NULL, NULL
    286 	},
    287 
    288 	/*
    289 	 * SanDisk Sansa Clip rejects cache sync in unconventional way.
    290 	 * However, unlike some other devices listed in this table,
    291 	 * this is does not cause the device firmware to stop responding.
    292 	 */
    293 	{ { USB_VENDOR_SANDISK, USB_PRODUCT_SANDISK_SANSA_CLIP },
    294 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    295 	  0,
    296 	  PQUIRK_NOSYNCCACHE,
    297 	  UMATCH_VENDOR_PRODUCT,
    298 	  NULL, NULL
    299 	},
    300 
    301 	/* Kingston USB pendrives don't like being told to lock the door */
    302 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DT101_II },
    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_DT101_G2 },
    311 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    312 	  0,
    313 	  PQUIRK_NODOORLOCK,
    314 	  UMATCH_VENDOR_PRODUCT,
    315 	  NULL, NULL
    316 	},
    317 
    318 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DT102_G2 },
    319 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    320 	  0,
    321 	  PQUIRK_NODOORLOCK,
    322 	  UMATCH_VENDOR_PRODUCT,
    323 	  NULL, NULL
    324 	},
    325 
    326 	{ { USB_VENDOR_KINGSTON, USB_PRODUCT_KINGSTON_DTMINI10 },
    327 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    328 	  0,
    329 	  PQUIRK_NODOORLOCK,
    330 	  UMATCH_VENDOR_PRODUCT,
    331 	  NULL, NULL
    332 	},
    333 
    334 	/* Also, some Kingston pendrives have Toshiba vendor ID */
    335 	{ { USB_VENDOR_TOSHIBA, USB_PRODUCT_KINGSTON_DT100_G2 },
    336 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    337 	  0,
    338 	  PQUIRK_NODOORLOCK,
    339 	  UMATCH_VENDOR_PRODUCT,
    340 	  NULL, NULL
    341 	},
    342 
    343 	/* HP USB pendrives don't like being told to lock the door */
    344 	{ { USB_VENDOR_HP, USB_PRODUCT_HP_V125W },
    345 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    346 	  0,
    347 	  PQUIRK_NODOORLOCK,
    348 	  UMATCH_VENDOR_PRODUCT,
    349 	  NULL, NULL
    350 	},
    351 
    352 	{ { USB_VENDOR_IODATA2, USB_PRODUCT_IODATA2_USB2SC },
    353 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
    354 	  0,
    355 	  0,
    356 	  UMATCH_VENDOR_PRODUCT,
    357 	  NULL, NULL
    358 	},
    359 };
    360 
    361 const struct umass_quirk *
    362 umass_lookup(uint16_t vendor, uint16_t product)
    363 {
    364 	return (const struct umass_quirk *)
    365 		usb_lookup(umass_quirks, vendor, product);
    366 }
    367 
    368 Static usbd_status
    369 umass_init_insystem(struct umass_softc *sc)
    370 {
    371 	UMASSHIST_FUNC(); UMASSHIST_CALLED();
    372 	usbd_status err;
    373 
    374 	err = usbd_set_interface(sc->sc_iface, 1);
    375 	if (err) {
    376 		DPRINTFM(UDMASS_USB, "sc %#jx: could not switch to Alt "
    377 		    "Interface 1", (uintptr_t)sc, 0, 0, 0);
    378 		return err;
    379 	}
    380 
    381 	return USBD_NORMAL_COMPLETION;
    382 }
    383 
    384 Static usbd_status
    385 umass_init_shuttle(struct umass_softc *sc)
    386 {
    387 	usb_device_request_t req;
    388 	uint8_t status[2];
    389 
    390 	/* The Linux driver does this */
    391 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
    392 	req.bRequest = 1;
    393 	USETW(req.wValue, 0);
    394 	USETW(req.wIndex, sc->sc_ifaceno);
    395 	USETW(req.wLength, sizeof(status));
    396 
    397 	return usbd_do_request(sc->sc_udev, &req, &status);
    398 }
    399 
    400 Static void
    401 umass_fixup_sony(struct umass_softc *sc)
    402 {
    403 	usb_interface_descriptor_t *id;
    404 
    405 	id = usbd_get_interface_descriptor(sc->sc_iface);
    406 	if (id->bInterfaceSubClass == 0xff)
    407 		sc->sc_cmd = UMASS_CPROTO_RBC;
    408 }
    409