1 /* $NetBSD: umass_quirks.c,v 1.74 2008/05/11 05:20:33 mlelstv 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@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.74 2008/05/11 05:20:33 mlelstv 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 Static usbd_status umass_init_e220(struct umass_softc *); 55 56 Static void umass_fixup_sony(struct umass_softc *); 57 58 /* 59 * XXX 60 * PLEASE NOTE that if you want quirk entries added to this table, you MUST 61 * compile a kernel with USB_DEBUG, and submit a full log of the output from 62 * whatever operation is "failing" with ?hcidebug=20 or higher and 63 * umassdebug=0xffffff. (It's usually helpful to also set MSGBUFSIZE to 64 * something "large" unless you're using a serial console.) Without this 65 * information, the source of the problem cannot be properly analyzed, and 66 * the quirk entry WILL NOT be accepted. 67 * Also, when an entry is committed to this table, a concise but clear 68 * description of the problem MUST accompany it. 69 * - mycroft 70 */ 71 Static const struct umass_quirk umass_quirks[] = { 72 /* 73 * The following 3 In-System Design adapters use a non-standard ATA 74 * over BBB protocol. Force this protocol by quirk entries. 75 */ 76 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 }, 77 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA, 78 0, 79 0, 80 UMATCH_VENDOR_PRODUCT, 81 NULL, NULL 82 }, 83 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI }, 84 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA, 85 0, 86 0, 87 UMATCH_VENDOR_PRODUCT, 88 NULL, NULL 89 }, 90 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 }, 91 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA, 92 0, 93 0, 94 UMATCH_VENDOR_PRODUCT, 95 NULL, NULL 96 }, 97 98 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE }, 99 UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI, 100 0, 101 0, 102 UMATCH_VENDOR_PRODUCT, 103 umass_init_insystem, NULL 104 }, 105 106 { { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB }, 107 UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI, 108 0, 109 0, 110 UMATCH_VENDOR_PRODUCT, 111 umass_init_shuttle, NULL 112 }, 113 114 /* 115 * These work around genuine device bugs -- returning the wrong info in 116 * the CSW block. 117 */ 118 { { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 }, 119 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 120 UMASS_QUIRK_WRONG_CSWSIG, 121 0, 122 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 123 NULL, NULL 124 }, 125 { { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R }, 126 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 127 UMASS_QUIRK_WRONG_CSWTAG, 128 0, 129 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 130 NULL, NULL 131 }, 132 { { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA }, 133 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 134 UMASS_QUIRK_WRONG_CSWTAG, 135 0, 136 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 137 NULL, NULL 138 }, 139 140 /* 141 * Some Sony cameras advertise a subclass code of 0xff, so we force it 142 * to the correct value iff necessary. 143 */ 144 { { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC }, 145 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 146 UMASS_QUIRK_RBC_PAD_TO_12, 147 0, 148 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 149 NULL, umass_fixup_sony 150 }, 151 152 /* 153 * Stupid device reports itself as SFF-8070, but actually returns a UFI 154 * interrupt descriptor. - mycroft, 2004/06/28 155 */ 156 { { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS }, 157 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI, 158 0, 159 0, 160 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 161 NULL, NULL 162 }, 163 164 /* 165 * The DiskOnKey does not reject commands it doesn't recognize in a 166 * sane way -- rather than STALLing the bulk pipe, it continually NAKs 167 * until we time out. To prevent being screwed by this, for now we 168 * disable 10-byte MODE SENSE the klugy way. - mycroft, 2003/10/16 169 */ 170 { { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY }, 171 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 172 0, 173 PQUIRK_NOBIGMODESENSE, 174 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 175 NULL, NULL 176 }, 177 { { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 }, 178 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 179 0, 180 PQUIRK_NOBIGMODESENSE, 181 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 182 NULL, NULL 183 }, 184 { { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY3 }, 185 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 186 0, 187 PQUIRK_NOBIGMODESENSE, 188 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO, 189 NULL, NULL 190 }, 191 { { USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 }, 192 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 193 0, 194 0, 195 UMASS_QUIRK_USE_DEFAULTMATCH, /* use default MATCH function */ 196 umass_init_e220, NULL 197 }, 198 /* IBEAD devices don't like all SCSI commands */ 199 { { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_MUSICSTICK }, 200 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 201 0, 202 PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE, 203 UMATCH_VENDOR_PRODUCT, 204 NULL, NULL 205 }, 206 { { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD100 }, 207 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 208 0, 209 PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE, 210 UMATCH_VENDOR_PRODUCT, 211 NULL, NULL 212 }, 213 { { USB_VENDOR_SIGMATEL, USB_PRODUCT_SIGMATEL_I_BEAD150 }, 214 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC, 215 0, 216 PQUIRK_NODOORLOCK | PQUIRK_NOSYNCCACHE, 217 UMATCH_VENDOR_PRODUCT, 218 NULL, NULL 219 }, 220 }; 221 222 const struct umass_quirk * 223 umass_lookup(u_int16_t vendor, u_int16_t product) 224 { 225 return ((const struct umass_quirk *) 226 usb_lookup(umass_quirks, vendor, product)); 227 } 228 229 Static usbd_status 230 umass_init_insystem(struct umass_softc *sc) 231 { 232 usbd_status err; 233 234 err = usbd_set_interface(sc->sc_iface, 1); 235 if (err) { 236 DPRINTF(UDMASS_USB, 237 ("%s: could not switch to Alt Interface 1\n", 238 USBDEVNAME(sc->sc_dev))); 239 return (err); 240 } 241 242 return (USBD_NORMAL_COMPLETION); 243 } 244 245 Static usbd_status 246 umass_init_shuttle(struct umass_softc *sc) 247 { 248 usb_device_request_t req; 249 u_int8_t status[2]; 250 251 /* The Linux driver does this */ 252 req.bmRequestType = UT_READ_VENDOR_DEVICE; 253 req.bRequest = 1; 254 USETW(req.wValue, 0); 255 USETW(req.wIndex, sc->sc_ifaceno); 256 USETW(req.wLength, sizeof(status)); 257 258 return (usbd_do_request(sc->sc_udev, &req, &status)); 259 } 260 261 Static void 262 umass_fixup_sony(struct umass_softc *sc) 263 { 264 usb_interface_descriptor_t *id; 265 266 id = usbd_get_interface_descriptor(sc->sc_iface); 267 if (id->bInterfaceSubClass == 0xff) 268 sc->sc_cmd = UMASS_CPROTO_RBC; 269 } 270 271 Static usbd_status 272 umass_init_e220(struct umass_softc *sc) 273 { 274 #define E220_UMASS_INTERFACE 2 275 usbd_status err; 276 277 if (sc->sc_ifaceno != E220_UMASS_INTERFACE) 278 return (USBD_NOT_CONFIGURED); 279 280 err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, &sc->sc_iface); 281 if (err) { 282 DPRINTF(UDMASS_USB, 283 ("%s: could not switch to Alt Interface %d\n", 284 USBDEVNAME(sc->sc_dev), sc->sc_ifaceno)); 285 return (err); 286 } 287 288 return (USBD_NORMAL_COMPLETION); 289 #undef E220_UMASS_INTERFACE 290 } 291