1 /* $FreeBSD$ */ 2 /*- 3 * SPDX-License-Identifier: BSD-2-Clause-NetBSD 4 * 5 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 6 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 7 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #include <sys/stdint.h> 32 #include <sys/stddef.h> 33 #include <sys/param.h> 34 #include <sys/queue.h> 35 #include <sys/types.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/bus.h> 39 #include <sys/module.h> 40 #include <sys/lock.h> 41 #include <sys/mutex.h> 42 #include <sys/condvar.h> 43 #include <sys/sysctl.h> 44 #include <sys/sx.h> 45 #include <sys/unistd.h> 46 #include <sys/callout.h> 47 #include <sys/malloc.h> 48 #include <sys/priv.h> 49 50 #include <dev/usb/usb.h> 51 #include <dev/usb/usb_ioctl.h> 52 #include <dev/usb/usbdi.h> 53 #include "usbdevs.h" 54 55 #define USB_DEBUG_VAR usb_debug 56 #include <dev/usb/usb_debug.h> 57 #include <dev/usb/usb_dynamic.h> 58 59 #include <dev/usb/quirk/usb_quirk.h> 60 61 MODULE_DEPEND(usb_quirk, usb, 1, 1, 1); 62 MODULE_VERSION(usb_quirk, 1); 63 64 #define USB_DEV_QUIRKS_MAX 384 65 #define USB_SUB_QUIRKS_MAX 8 66 #define USB_QUIRK_ENVROOT "hw.usb.quirk." 67 68 struct usb_quirk_entry { 69 uint16_t vid; 70 uint16_t pid; 71 uint16_t lo_rev; 72 uint16_t hi_rev; 73 uint16_t quirks[USB_SUB_QUIRKS_MAX]; 74 }; 75 76 static struct mtx usb_quirk_mtx; 77 78 #define USB_QUIRK_VP(v,p,l,h,...) \ 79 { .vid = (v), .pid = (p), .lo_rev = (l), .hi_rev = (h), \ 80 .quirks = { __VA_ARGS__ } } 81 #define USB_QUIRK(v,p,l,h,...) \ 82 USB_QUIRK_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, l, h, __VA_ARGS__) 83 84 static struct usb_quirk_entry usb_quirks[USB_DEV_QUIRKS_MAX] = { 85 USB_QUIRK(ASUS, LCM, 0x0000, 0xffff, UQ_HID_IGNORE), 86 USB_QUIRK(INSIDEOUT, EDGEPORT4, 0x094, 0x094, UQ_SWAP_UNICODE), 87 USB_QUIRK(DALLAS, J6502, 0x0a2, 0x0a2, UQ_BAD_ADC), 88 USB_QUIRK(DALLAS, J6502, 0x0a2, 0x0a2, UQ_AU_NO_XU), 89 USB_QUIRK(ALTEC, ADA70, 0x103, 0x103, UQ_BAD_ADC), 90 USB_QUIRK(ALTEC, ASC495, 0x000, 0x000, UQ_BAD_AUDIO), 91 USB_QUIRK(QTRONIX, 980N, 0x110, 0x110, UQ_SPUR_BUT_UP), 92 USB_QUIRK(ALCOR2, KBD_HUB, 0x001, 0x001, UQ_SPUR_BUT_UP), 93 USB_QUIRK(MCT, HUB0100, 0x102, 0x102, UQ_BUS_POWERED), 94 USB_QUIRK(MCT, USB232, 0x102, 0x102, UQ_BUS_POWERED), 95 USB_QUIRK(TI, UTUSB41, 0x110, 0x110, UQ_POWER_CLAIM), 96 USB_QUIRK(TELEX, MIC1, 0x009, 0x009, UQ_AU_NO_FRAC), 97 USB_QUIRK(SILICONPORTALS, YAPPHONE, 0x100, 0x100, UQ_AU_INP_ASYNC), 98 USB_QUIRK(LOGITECH, UN53B, 0x0000, 0xffff, UQ_NO_STRINGS), 99 USB_QUIRK(REALTEK, RTL8196EU, 0x0000, 0xffff, UQ_CFG_INDEX_1), 100 USB_QUIRK(ELSA, MODEM1, 0x0000, 0xffff, UQ_CFG_INDEX_1), 101 USB_QUIRK(PLANEX2, MZKUE150N, 0x0000, 0xffff, UQ_CFG_INDEX_1), 102 USB_QUIRK(CISCOLINKSYS, USB3GIGV1, 0x0000, 0xffff, UQ_CFG_INDEX_1), 103 /* Quirks for printer devices */ 104 USB_QUIRK(HP, 895C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 105 USB_QUIRK(HP, 880C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 106 USB_QUIRK(HP, 815C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 107 USB_QUIRK(HP, 810C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 108 USB_QUIRK(HP, 830C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 109 USB_QUIRK(HP, 1220C, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 110 USB_QUIRK(XEROX, WCM15, 0x0000, 0xffff, UQ_BROKEN_BIDIR), 111 /* Devices which should be ignored by uhid */ 112 USB_QUIRK(APC, UPS, 0x0000, 0xffff, UQ_HID_IGNORE), 113 USB_QUIRK(BELKIN, F6C550AVR, 0x0000, 0xffff, UQ_HID_IGNORE), 114 USB_QUIRK(CYBERPOWER, 1500CAVRLCD, 0x0000, 0xffff, UQ_HID_IGNORE), 115 USB_QUIRK(CYPRESS, SILVERSHIELD, 0x0000, 0xffff, UQ_HID_IGNORE), 116 USB_QUIRK(DELORME, EARTHMATE, 0x0000, 0xffff, UQ_HID_IGNORE), 117 USB_QUIRK(DREAMLINK, DL100B, 0x0000, 0xffff, UQ_HID_IGNORE), 118 USB_QUIRK(ITUNERNET, USBLCD2X20, 0x0000, 0xffff, UQ_HID_IGNORE), 119 USB_QUIRK(ITUNERNET, USBLCD4X20, 0x0000, 0xffff, UQ_HID_IGNORE), 120 USB_QUIRK(LIEBERT, POWERSURE_PXT, 0x0000, 0xffff, UQ_HID_IGNORE), 121 USB_QUIRK(LIEBERT2, PSI1000, 0x0000, 0xffff, UQ_HID_IGNORE), 122 USB_QUIRK(MGE, UPS1, 0x0000, 0xffff, UQ_HID_IGNORE), 123 USB_QUIRK(MGE, UPS2, 0x0000, 0xffff, UQ_HID_IGNORE), 124 USB_QUIRK(APPLE, IPHONE, 0x0000, 0xffff, UQ_HID_IGNORE), 125 USB_QUIRK(APPLE, IPHONE_3G, 0x0000, 0xffff, UQ_HID_IGNORE), 126 USB_QUIRK(MEGATEC, UPS, 0x0000, 0xffff, UQ_HID_IGNORE), 127 /* Devices which should be ignored by both ukbd and uhid */ 128 USB_QUIRK(CYPRESS, WISPY1A, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE), 129 USB_QUIRK(METAGEEK, WISPY1B, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE), 130 USB_QUIRK(METAGEEK, WISPY24X, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE), 131 USB_QUIRK(METAGEEK2, WISPYDBX, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE), 132 USB_QUIRK(TENX, UAUDIO0, 0x0101, 0x0101, UQ_AUDIO_SWAP_LR), 133 /* MS keyboards do weird things */ 134 USB_QUIRK(MICROSOFT, NATURAL4000, 0x0000, 0xFFFF, UQ_KBD_BOOTPROTO), 135 USB_QUIRK(MICROSOFT, WLINTELLIMOUSE, 0x0000, 0xffff, UQ_MS_LEADING_BYTE), 136 /* Quirk for Corsair Vengeance K60 keyboard */ 137 USB_QUIRK(CORSAIR, K60, 0x0000, 0xffff, UQ_KBD_BOOTPROTO), 138 /* Quirk for Corsair Vengeance K70 keyboard */ 139 USB_QUIRK(CORSAIR, K70, 0x0000, 0xffff, UQ_KBD_BOOTPROTO), 140 /* Quirk for Corsair STRAFE Gaming keyboard */ 141 USB_QUIRK(CORSAIR, STRAFE, 0x0000, 0xffff, UQ_KBD_BOOTPROTO), 142 /* umodem(4) device quirks */ 143 USB_QUIRK(METRICOM, RICOCHET_GS, 0x100, 0x100, UQ_ASSUME_CM_OVER_DATA), 144 USB_QUIRK(SANYO, SCP4900, 0x000, 0x000, UQ_ASSUME_CM_OVER_DATA), 145 USB_QUIRK(MOTOROLA2, T720C, 0x001, 0x001, UQ_ASSUME_CM_OVER_DATA), 146 USB_QUIRK(EICON, DIVA852, 0x100, 0x100, UQ_ASSUME_CM_OVER_DATA), 147 USB_QUIRK(SIEMENS2, ES75, 0x000, 0x000, UQ_ASSUME_CM_OVER_DATA), 148 USB_QUIRK(QUALCOMM, CDMA_MSM, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA), 149 USB_QUIRK(QUALCOMM2, CDMA_MSM, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA), 150 USB_QUIRK(CURITEL, UM150, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA), 151 USB_QUIRK(CURITEL, UM175, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA), 152 USB_QUIRK(VERTEX, VW110L, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA), 153 154 /* USB Mass Storage Class Quirks */ 155 USB_QUIRK_VP(USB_VENDOR_ASAHIOPTICAL, 0, UQ_MSC_NO_RS_CLEAR_UA, 156 UQ_MATCH_VENDOR_ONLY), 157 USB_QUIRK(ADDON, ATTACHE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 158 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 159 USB_QUIRK(ADDON, A256MB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 160 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 161 USB_QUIRK(ADDON, DISKPRO512, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 162 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 163 USB_QUIRK(ADDONICS2, CABLE_205, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 164 UQ_MSC_FORCE_PROTO_SCSI), 165 USB_QUIRK(AIPTEK, POCKETCAM3M, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 166 UQ_MSC_FORCE_PROTO_SCSI), 167 USB_QUIRK(ALCOR, UMCR_9361, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 168 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 169 USB_QUIRK(ALCOR, TRANSCEND, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN, 170 UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_TEST_UNIT_READY), 171 USB_QUIRK(APACER, HT202, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY, 172 UQ_MSC_NO_SYNC_CACHE), 173 USB_QUIRK(ASAHIOPTICAL, OPTIO230, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 174 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 175 USB_QUIRK(ASAHIOPTICAL, OPTIO330, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 176 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 177 USB_QUIRK(ATP, EUSB, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 178 USB_QUIRK(BELKIN, USB2SCSI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 179 UQ_MSC_FORCE_PROTO_SCSI), 180 USB_QUIRK(CASIO, QV_DIGICAM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 181 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 182 USB_QUIRK(CCYU, ED1064, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 183 UQ_MSC_FORCE_PROTO_SCSI), 184 USB_QUIRK(CENTURY, EX35QUAT, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 185 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 186 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 187 USB_QUIRK(CYPRESS, XX6830XX, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN, 188 UQ_MSC_NO_SYNC_CACHE), 189 USB_QUIRK(DESKNOTE, UCR_61S2B, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 190 UQ_MSC_FORCE_PROTO_SCSI), 191 USB_QUIRK(DMI, CFSM_RW, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI, 192 UQ_MSC_NO_GETMAXLUN), 193 USB_QUIRK(EMTEC, RUF2PS, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 194 USB_QUIRK(EPSON, STYLUS_875DC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 195 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 196 USB_QUIRK(EPSON, STYLUS_895, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 197 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 198 USB_QUIRK(FEIYA, 5IN1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 199 UQ_MSC_FORCE_PROTO_SCSI), 200 USB_QUIRK(FEIYA, ELANGO, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 201 USB_QUIRK(FREECOM, DVD, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 202 USB_QUIRK(FUJIPHOTO, MASS0100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I, 203 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_NO_SYNC_CACHE), 204 USB_QUIRK(GARMIN, FORERUNNER230, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY), 205 USB_QUIRK(GENESYS, GL641USB2IDE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 206 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 207 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE, UQ_MSC_NO_SYNC_CACHE), 208 USB_QUIRK(GENESYS, GL641USB2IDE_2, 0x0000, 0xffff, 209 UQ_MSC_FORCE_WIRE_BBB, UQ_MSC_FORCE_PROTO_ATAPI, 210 UQ_MSC_FORCE_SHORT_INQ, UQ_MSC_NO_START_STOP, 211 UQ_MSC_IGNORE_RESIDUE), 212 USB_QUIRK(GENESYS, GL641USB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 213 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 214 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 215 USB_QUIRK(GENESYS, GL641USB_2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 216 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG), 217 USB_QUIRK(HAGIWARA, FG, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 218 UQ_MSC_FORCE_PROTO_SCSI), 219 USB_QUIRK(HAGIWARA, FGSM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 220 UQ_MSC_FORCE_PROTO_SCSI), 221 USB_QUIRK(HITACHI, DVDCAM_DZ_MV100A, 0x0000, 0xffff, 222 UQ_MSC_FORCE_WIRE_CBI, UQ_MSC_FORCE_PROTO_SCSI, 223 UQ_MSC_NO_GETMAXLUN), 224 USB_QUIRK(HITACHI, DVDCAM_USB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I, 225 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY), 226 USB_QUIRK(HP, CDW4E, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_ATAPI), 227 USB_QUIRK(HP, CDW8200, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I, 228 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY, 229 UQ_MSC_NO_START_STOP), 230 USB_QUIRK(IMAGINATION, DBX1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 231 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG), 232 USB_QUIRK(INSYSTEM, USBCABLE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 233 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY, 234 UQ_MSC_NO_START_STOP, UQ_MSC_ALT_IFACE_1), 235 USB_QUIRK(INSYSTEM, ATAPI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 236 UQ_MSC_FORCE_PROTO_RBC), 237 USB_QUIRK(INSYSTEM, STORAGE_V2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 238 UQ_MSC_FORCE_PROTO_RBC), 239 USB_QUIRK(INTENSO, MEMORY_BOX, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY), 240 USB_QUIRK(IODATA, IU_CD2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 241 UQ_MSC_FORCE_PROTO_SCSI), 242 USB_QUIRK(IODATA, DVR_UEH8, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 243 UQ_MSC_FORCE_PROTO_SCSI), 244 USB_QUIRK(IOMEGA, ZIP100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 245 UQ_MSC_FORCE_PROTO_SCSI, 246 UQ_MSC_NO_TEST_UNIT_READY), /* XXX ZIP drives can also use ATAPI */ 247 USB_QUIRK(JMICRON, JMS567, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN), 248 USB_QUIRK(JMICRON, JM20337, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 249 UQ_MSC_FORCE_PROTO_SCSI, 250 UQ_MSC_NO_SYNC_CACHE), 251 USB_QUIRK(KINGSTON, HYPERX3_0, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY), 252 USB_QUIRK(KYOCERA, FINECAM_L3, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 253 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 254 USB_QUIRK(KYOCERA, FINECAM_S3X, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 255 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY), 256 USB_QUIRK(KYOCERA, FINECAM_S4, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 257 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY), 258 USB_QUIRK(KYOCERA, FINECAM_S5, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 259 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 260 USB_QUIRK(LACIE, HD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 261 UQ_MSC_FORCE_PROTO_RBC), 262 USB_QUIRK(LEXAR, CF_READER, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 263 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 264 USB_QUIRK(LEXAR, JUMPSHOT, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 265 USB_QUIRK(LEXAR, JUMPDRIVE, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY), 266 USB_QUIRK(LOGITEC, LDR_H443SU2, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 267 USB_QUIRK(LOGITEC, LDR_H443U2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 268 UQ_MSC_FORCE_PROTO_SCSI,), 269 USB_QUIRK(MELCO, DUBPXXG, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 270 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 271 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 272 USB_QUIRK(MICROTECH, DPCM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 273 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_TEST_UNIT_READY, 274 UQ_MSC_NO_START_STOP), 275 USB_QUIRK(MICRON, REALSSD, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 276 USB_QUIRK(MICROTECH, SCSIDB25, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 277 UQ_MSC_FORCE_PROTO_SCSI), 278 USB_QUIRK(MICROTECH, SCSIHD50, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 279 UQ_MSC_FORCE_PROTO_SCSI), 280 USB_QUIRK(MINOLTA, E223, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 281 USB_QUIRK(MINOLTA, F300, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 282 UQ_MSC_FORCE_PROTO_SCSI), 283 USB_QUIRK(MITSUMI, CDRRW, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI | 284 UQ_MSC_FORCE_PROTO_ATAPI), 285 USB_QUIRK(MOTOROLA2, E398, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 286 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 287 UQ_MSC_NO_INQUIRY_EVPD, UQ_MSC_NO_GETMAXLUN), 288 USB_QUIRK_VP(USB_VENDOR_MPMAN, 0, UQ_MSC_NO_SYNC_CACHE, 289 UQ_MATCH_VENDOR_ONLY), 290 USB_QUIRK(MSYSTEMS, DISKONKEY, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 291 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE, UQ_MSC_NO_GETMAXLUN, 292 UQ_MSC_NO_RS_CLEAR_UA), 293 USB_QUIRK(MSYSTEMS, DISKONKEY2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 294 UQ_MSC_FORCE_PROTO_ATAPI), 295 USB_QUIRK(MYSON, HEDEN, 0x0000, 0xffff, UQ_MSC_IGNORE_RESIDUE, 296 UQ_MSC_NO_SYNC_CACHE), 297 USB_QUIRK(NEODIO, ND3260, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 298 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ), 299 USB_QUIRK(NETAC, CF_CARD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 300 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 301 USB_QUIRK(NETAC, ONLYDISK, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 302 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 303 USB_QUIRK(NETCHIP, CLIK_40, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_ATAPI, 304 UQ_MSC_NO_INQUIRY), 305 USB_QUIRK(NETCHIP, POCKETBOOK, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 306 USB_QUIRK(NIKON, D300, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 307 UQ_MSC_FORCE_PROTO_SCSI), 308 USB_QUIRK(OLYMPUS, C1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 309 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG), 310 USB_QUIRK(OLYMPUS, C700, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN), 311 USB_QUIRK(ONSPEC, SDS_HOTFIND_D, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 312 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN, UQ_MSC_NO_SYNC_CACHE), 313 USB_QUIRK(ONSPEC, CFMS_RW, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 314 USB_QUIRK(ONSPEC, CFSM_COMBO, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 315 USB_QUIRK(ONSPEC, CFSM_READER, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 316 USB_QUIRK(ONSPEC, CFSM_READER2, 0x0000, 0xffff, 317 UQ_MSC_FORCE_PROTO_SCSI), 318 USB_QUIRK(ONSPEC, MDCFE_B_CF_READER, 0x0000, 0xffff, 319 UQ_MSC_FORCE_PROTO_SCSI), 320 USB_QUIRK(ONSPEC, MDSM_B_READER, 0x0000, 0xffff, 321 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 322 USB_QUIRK(ONSPEC, READER, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 323 USB_QUIRK(ONSPEC, UCF100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 324 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY, UQ_MSC_NO_GETMAXLUN), 325 USB_QUIRK(ONSPEC2, IMAGEMATE_SDDR55, 0x0000, 0xffff, 326 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 327 USB_QUIRK(PANASONIC, KXL840AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 328 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_GETMAXLUN), 329 USB_QUIRK(PANASONIC, KXLCB20AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 330 UQ_MSC_FORCE_PROTO_SCSI), 331 USB_QUIRK(PANASONIC, KXLCB35AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 332 UQ_MSC_FORCE_PROTO_SCSI), 333 USB_QUIRK(PANASONIC, LS120CAM, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_UFI), 334 USB_QUIRK(PLEXTOR, 40_12_40U, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 335 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_TEST_UNIT_READY), 336 USB_QUIRK(PNY, ATTACHE2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 337 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE, 338 UQ_MSC_NO_START_STOP), 339 USB_QUIRK(PROLIFIC, PL2506, 0x0000, 0xffff, 340 UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_PREVENT_ALLOW), 341 USB_QUIRK_VP(USB_VENDOR_SAMSUNG_TECHWIN, 342 USB_PRODUCT_SAMSUNG_TECHWIN_DIGIMAX_410, UQ_MSC_FORCE_WIRE_BBB, 343 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 344 USB_QUIRK(SANDISK, SDDR05A, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 345 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1, 346 UQ_MSC_NO_GETMAXLUN), 347 USB_QUIRK(SANDISK, SDDR09, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI, 348 UQ_MSC_READ_CAP_OFFBY1, UQ_MSC_NO_GETMAXLUN), 349 USB_QUIRK(SANDISK, SDDR12, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 350 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1, 351 UQ_MSC_NO_GETMAXLUN), 352 USB_QUIRK(SANDISK, SDCZ2_128, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 353 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE, 354 UQ_MSC_NO_SYNC_CACHE), 355 USB_QUIRK(SANDISK, SDCZ2_256, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 356 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 357 USB_QUIRK(SANDISK, SDCZ4_128, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 358 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 359 USB_QUIRK(SANDISK, SDCZ4_256, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 360 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 361 USB_QUIRK(SANDISK, SDDR31, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 362 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1), 363 USB_QUIRK(SANDISK, IMAGEMATE_SDDR289, 0x0000, 0xffff, 364 UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_GETMAXLUN), 365 USB_QUIRK(SCANLOGIC, SL11R, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 366 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY), 367 USB_QUIRK(SHUTTLE, EUSB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I, 368 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY, 369 UQ_MSC_NO_START_STOP, UQ_MSC_SHUTTLE_INIT), 370 USB_QUIRK(SHUTTLE, CDRW, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 371 UQ_MSC_FORCE_PROTO_ATAPI), 372 USB_QUIRK(SHUTTLE, CF, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 373 UQ_MSC_FORCE_PROTO_ATAPI), 374 USB_QUIRK(SHUTTLE, EUSBATAPI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 375 UQ_MSC_FORCE_PROTO_ATAPI), 376 USB_QUIRK(SHUTTLE, EUSBCFSM, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 377 USB_QUIRK(SHUTTLE, EUSCSI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 378 UQ_MSC_FORCE_PROTO_SCSI), 379 USB_QUIRK(SHUTTLE, HIFD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 380 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 381 USB_QUIRK(SHUTTLE, SDDR09, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI, 382 UQ_MSC_NO_GETMAXLUN), 383 USB_QUIRK(SHUTTLE, ZIOMMC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 384 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 385 USB_QUIRK(SIGMATEL, I_BEAD100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 386 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_SHUTTLE_INIT), 387 USB_QUIRK(SIIG, WINTERREADER, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 388 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE), 389 USB_QUIRK(SKANHEX, MD_7425, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 390 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 391 USB_QUIRK(SKANHEX, SX_520Z, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 392 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 393 USB_QUIRK(SONY, HANDYCAM, 0x0500, 0x0500, UQ_MSC_FORCE_WIRE_CBI, 394 UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12), 395 USB_QUIRK(SONY, CLIE_40_MS, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 396 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 397 USB_QUIRK(SONY, DSC, 0x0500, 0x0500, UQ_MSC_FORCE_WIRE_CBI, 398 UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12), 399 USB_QUIRK(SONY, DSC, 0x0600, 0x0600, UQ_MSC_FORCE_WIRE_CBI, 400 UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12), 401 USB_QUIRK(SONY, DSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 402 UQ_MSC_FORCE_PROTO_RBC), 403 USB_QUIRK(SONY, HANDYCAM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 404 UQ_MSC_FORCE_PROTO_RBC), 405 USB_QUIRK(SONY, MSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 406 UQ_MSC_FORCE_PROTO_RBC), 407 USB_QUIRK(SONY, MS_MSC_U03, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 408 UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_GETMAXLUN), 409 USB_QUIRK(SONY, MS_NW_MS7, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 410 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 411 USB_QUIRK(SONY, MS_PEG_N760C, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 412 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 413 USB_QUIRK(SONY, MSACUS1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 414 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN), 415 USB_QUIRK(SONY, PORTABLE_HDD_V2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 416 UQ_MSC_FORCE_PROTO_SCSI), 417 USB_QUIRK(STMICRO, ST72682, 0x0000, 0xffff, UQ_MSC_NO_PREVENT_ALLOW), 418 USB_QUIRK(SUPERTOP, IDE, 0x0000, 0xffff, UQ_MSC_IGNORE_RESIDUE, 419 UQ_MSC_NO_SYNC_CACHE), 420 USB_QUIRK(SUPERTOP, FLASHDRIVE, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY, 421 UQ_MSC_NO_SYNC_CACHE), 422 USB_QUIRK(TAUGA, CAMERAMATE, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 423 USB_QUIRK(TEAC, FD05PUB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 424 UQ_MSC_FORCE_PROTO_UFI), 425 USB_QUIRK(TECLAST, TLC300, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY, 426 UQ_MSC_NO_SYNC_CACHE), 427 USB_QUIRK(TREK, MEMKEY, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 428 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 429 USB_QUIRK(TREK, THUMBDRIVE_8MB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 430 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_IGNORE_RESIDUE), 431 USB_QUIRK(TRUMPION, C3310, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 432 UQ_MSC_FORCE_PROTO_UFI), 433 USB_QUIRK(TRUMPION, MP3, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_RBC), 434 USB_QUIRK(TRUMPION, T33520, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI), 435 USB_QUIRK(TWINMOS, MDIV, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 436 UQ_MSC_FORCE_PROTO_SCSI), 437 USB_QUIRK(VIA, USB2IDEBRIDGE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 438 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_SYNC_CACHE), 439 USB_QUIRK(VIVITAR, 35XX, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 440 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 441 USB_QUIRK(WESTERN, COMBO, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 442 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 443 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 444 USB_QUIRK(WESTERN, EXTHDD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 445 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 446 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 447 USB_QUIRK(WESTERN, MYBOOK, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 448 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY_EVPD, 449 UQ_MSC_NO_SYNC_CACHE), 450 USB_QUIRK(WESTERN, MYPASSPORT_00, 0x0000, 0xffff, UQ_MSC_FORCE_SHORT_INQ), 451 USB_QUIRK(WESTERN, MYPASSPORT_01, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 452 USB_QUIRK(WESTERN, MYPASSPORT_02, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 453 USB_QUIRK(WESTERN, MYPASSPORT_03, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 454 USB_QUIRK(WESTERN, MYPASSPORT_04, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 455 USB_QUIRK(WESTERN, MYPASSPORT_05, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 456 USB_QUIRK(WESTERN, MYPASSPORT_06, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 457 USB_QUIRK(WESTERN, MYPASSPORT_07, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 458 USB_QUIRK(WESTERN, MYPASSPORT_08, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 459 USB_QUIRK(WESTERN, MYPASSPORT_09, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 460 USB_QUIRK(WESTERN, MYPASSPORT_10, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 461 USB_QUIRK(WESTERN, MYPASSPORT_11, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 462 USB_QUIRK(WESTERN, MYPASSPORTES_00, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 463 USB_QUIRK(WESTERN, MYPASSPORTES_01, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 464 USB_QUIRK(WESTERN, MYPASSPORTES_02, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 465 USB_QUIRK(WESTERN, MYPASSPORTES_03, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 466 USB_QUIRK(WESTERN, MYPASSPORTES_04, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 467 USB_QUIRK(WESTERN, MYPASSPORTES_05, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 468 USB_QUIRK(WESTERN, MYPASSPORTES_06, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 469 USB_QUIRK(WESTERN, MYPASSPORTES_07, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 470 USB_QUIRK(WESTERN, MYPASSPORTES_08, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 471 USB_QUIRK(WESTERN, MYPASSPORTES_09, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 472 USB_QUIRK(WINMAXGROUP, FLASH64MC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 473 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY), 474 USB_QUIRK(YANO, FW800HD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 475 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ, 476 UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE), 477 USB_QUIRK(YANO, U640MO, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I, 478 UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_FORCE_SHORT_INQ), 479 USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0000, 0x007F, UQ_MSC_FORCE_WIRE_CBI, 480 UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED, 481 UQ_MSC_NO_TEST_UNIT_READY, UQ_MSC_NO_GETMAXLUN), 482 USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0080, 0x0080, UQ_MSC_FORCE_WIRE_CBI_I, 483 UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED, 484 UQ_MSC_NO_TEST_UNIT_READY, UQ_MSC_NO_GETMAXLUN), 485 USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0081, 0xFFFF, UQ_MSC_FORCE_WIRE_CBI_I, 486 UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED, 487 UQ_MSC_NO_GETMAXLUN), 488 USB_QUIRK(ZORAN, EX20DSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI, 489 UQ_MSC_FORCE_PROTO_ATAPI), 490 USB_QUIRK(MEIZU, M6_SL, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB, 491 UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY, UQ_MSC_NO_SYNC_CACHE), 492 USB_QUIRK(TOSHIBA, TRANSMEMORY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, 493 UQ_MSC_NO_PREVENT_ALLOW), 494 USB_QUIRK(VIALABS, USB30SATABRIDGE, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE), 495 USB_QUIRK(QUALCOMMINC, ZTE_MF730M, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN, 496 UQ_MSC_NO_INQUIRY, UQ_CFG_INDEX_0), 497 /* Non-standard USB MIDI devices */ 498 USB_QUIRK(ROLAND, UM1, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 499 USB_QUIRK(ROLAND, SC8850, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 500 USB_QUIRK(ROLAND, SD90, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 501 USB_QUIRK(ROLAND, UM880N, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 502 USB_QUIRK(ROLAND, UA100, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 503 USB_QUIRK(ROLAND, UM4, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 504 USB_QUIRK(ROLAND, U8, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 505 USB_QUIRK(ROLAND, UM2, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 506 USB_QUIRK(ROLAND, SC8820, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 507 USB_QUIRK(ROLAND, PC300, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 508 USB_QUIRK(ROLAND, SK500, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 509 USB_QUIRK(ROLAND, SCD70, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 510 USB_QUIRK(ROLAND, UM550, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 511 USB_QUIRK(ROLAND, SD20, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 512 USB_QUIRK(ROLAND, SD80, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 513 USB_QUIRK(ROLAND, UA700, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 514 USB_QUIRK(ROLAND, PCR300, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 515 USB_QUIRK(EGO, M4U, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 516 USB_QUIRK(LOGILINK, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 517 USB_QUIRK(MEDELI, DD305, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI, UQ_MATCH_VENDOR_ONLY), 518 USB_QUIRK(REDOCTANE, GHMIDI, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 519 USB_QUIRK(TEXTECH, U2M_1, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 520 USB_QUIRK(TEXTECH, U2M_2, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 521 USB_QUIRK(WCH2, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI), 522 523 /* Non-standard USB AUDIO devices */ 524 USB_QUIRK(MAUDIO, FASTTRACKULTRA, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 525 USB_QUIRK(MAUDIO, FASTTRACKULTRA8R, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS), 526 USB_QUIRK(CMEDIA, CM6206, 0x0000, 0xffff, UQ_AU_SET_SPDIF_CM6206), 527 528 /* 529 * Quirks for manufacturers which USB devices does not respond 530 * after issuing non-supported commands: 531 */ 532 USB_QUIRK(ALCOR, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_TEST_UNIT_READY, UQ_MATCH_VENDOR_ONLY), 533 USB_QUIRK(APPLE, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY), 534 USB_QUIRK(FEIYA, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY), 535 USB_QUIRK(REALTEK, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY), 536 USB_QUIRK(INITIO, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY), 537 538 /* DYMO LabelManager Pnp */ 539 USB_QUIRK(DYMO, LABELMANAGERPNP, 0x0000, 0xffff, UQ_MSC_DYMO_EJECT), 540 541 /* Holtek USB gaming keyboard */ 542 USB_QUIRK(HOLTEK, F85, 0x0000, 0xffff, UQ_KBD_BOOTPROTO), 543 }; 544 #undef USB_QUIRK_VP 545 #undef USB_QUIRK 546 547 static const char *usb_quirk_str[USB_QUIRK_MAX] = { 548 [UQ_NONE] = "UQ_NONE", 549 [UQ_MATCH_VENDOR_ONLY] = "UQ_MATCH_VENDOR_ONLY", 550 [UQ_AUDIO_SWAP_LR] = "UQ_AUDIO_SWAP_LR", 551 [UQ_AU_INP_ASYNC] = "UQ_AU_INP_ASYNC", 552 [UQ_AU_NO_FRAC] = "UQ_AU_NO_FRAC", 553 [UQ_AU_NO_XU] = "UQ_AU_NO_XU", 554 [UQ_BAD_ADC] = "UQ_BAD_ADC", 555 [UQ_BAD_AUDIO] = "UQ_BAD_AUDIO", 556 [UQ_BROKEN_BIDIR] = "UQ_BROKEN_BIDIR", 557 [UQ_BUS_POWERED] = "UQ_BUS_POWERED", 558 [UQ_HID_IGNORE] = "UQ_HID_IGNORE", 559 [UQ_KBD_IGNORE] = "UQ_KBD_IGNORE", 560 [UQ_KBD_BOOTPROTO] = "UQ_KBD_BOOTPROTO", 561 [UQ_UMS_IGNORE] = "UQ_UMS_IGNORE", 562 [UQ_MS_BAD_CLASS] = "UQ_MS_BAD_CLASS", 563 [UQ_MS_LEADING_BYTE] = "UQ_MS_LEADING_BYTE", 564 [UQ_MS_REVZ] = "UQ_MS_REVZ", 565 [UQ_NO_STRINGS] = "UQ_NO_STRINGS", 566 [UQ_POWER_CLAIM] = "UQ_POWER_CLAIM", 567 [UQ_SPUR_BUT_UP] = "UQ_SPUR_BUT_UP", 568 [UQ_SWAP_UNICODE] = "UQ_SWAP_UNICODE", 569 [UQ_CFG_INDEX_1] = "UQ_CFG_INDEX_1", 570 [UQ_CFG_INDEX_2] = "UQ_CFG_INDEX_2", 571 [UQ_CFG_INDEX_3] = "UQ_CFG_INDEX_3", 572 [UQ_CFG_INDEX_4] = "UQ_CFG_INDEX_4", 573 [UQ_CFG_INDEX_0] = "UQ_CFG_INDEX_0", 574 [UQ_ASSUME_CM_OVER_DATA] = "UQ_ASSUME_CM_OVER_DATA", 575 [UQ_MSC_NO_TEST_UNIT_READY] = "UQ_MSC_NO_TEST_UNIT_READY", 576 [UQ_MSC_NO_RS_CLEAR_UA] = "UQ_MSC_NO_RS_CLEAR_UA", 577 [UQ_MSC_NO_START_STOP] = "UQ_MSC_NO_START_STOP", 578 [UQ_MSC_NO_GETMAXLUN] = "UQ_MSC_NO_GETMAXLUN", 579 [UQ_MSC_NO_INQUIRY] = "UQ_MSC_NO_INQUIRY", 580 [UQ_MSC_NO_INQUIRY_EVPD] = "UQ_MSC_NO_INQUIRY_EVPD", 581 [UQ_MSC_NO_PREVENT_ALLOW] = "UQ_MSC_NO_PREVENT_ALLOW", 582 [UQ_MSC_NO_SYNC_CACHE] = "UQ_MSC_NO_SYNC_CACHE", 583 [UQ_MSC_SHUTTLE_INIT] = "UQ_MSC_SHUTTLE_INIT", 584 [UQ_MSC_ALT_IFACE_1] = "UQ_MSC_ALT_IFACE_1", 585 [UQ_MSC_FLOPPY_SPEED] = "UQ_MSC_FLOPPY_SPEED", 586 [UQ_MSC_IGNORE_RESIDUE] = "UQ_MSC_IGNORE_RESIDUE", 587 [UQ_MSC_WRONG_CSWSIG] = "UQ_MSC_WRONG_CSWSIG", 588 [UQ_MSC_RBC_PAD_TO_12] = "UQ_MSC_RBC_PAD_TO_12", 589 [UQ_MSC_READ_CAP_OFFBY1] = "UQ_MSC_READ_CAP_OFFBY1", 590 [UQ_MSC_FORCE_SHORT_INQ] = "UQ_MSC_FORCE_SHORT_INQ", 591 [UQ_MSC_FORCE_WIRE_BBB] = "UQ_MSC_FORCE_WIRE_BBB", 592 [UQ_MSC_FORCE_WIRE_CBI] = "UQ_MSC_FORCE_WIRE_CBI", 593 [UQ_MSC_FORCE_WIRE_CBI_I] = "UQ_MSC_FORCE_WIRE_CBI_I", 594 [UQ_MSC_FORCE_PROTO_SCSI] = "UQ_MSC_FORCE_PROTO_SCSI", 595 [UQ_MSC_FORCE_PROTO_ATAPI] = "UQ_MSC_FORCE_PROTO_ATAPI", 596 [UQ_MSC_FORCE_PROTO_UFI] = "UQ_MSC_FORCE_PROTO_UFI", 597 [UQ_MSC_FORCE_PROTO_RBC] = "UQ_MSC_FORCE_PROTO_RBC", 598 [UQ_MSC_EJECT_HUAWEI] = "UQ_MSC_EJECT_HUAWEI", 599 [UQ_MSC_EJECT_SIERRA] = "UQ_MSC_EJECT_SIERRA", 600 [UQ_MSC_EJECT_SCSIEJECT] = "UQ_MSC_EJECT_SCSIEJECT", 601 [UQ_MSC_EJECT_REZERO] = "UQ_MSC_EJECT_REZERO", 602 [UQ_MSC_EJECT_ZTESTOR] = "UQ_MSC_EJECT_ZTESTOR", 603 [UQ_MSC_EJECT_CMOTECH] = "UQ_MSC_EJECT_CMOTECH", 604 [UQ_MSC_EJECT_WAIT] = "UQ_MSC_EJECT_WAIT", 605 [UQ_MSC_EJECT_SAEL_M460] = "UQ_MSC_EJECT_SAEL_M460", 606 [UQ_MSC_EJECT_HUAWEISCSI] = "UQ_MSC_EJECT_HUAWEISCSI", 607 [UQ_MSC_EJECT_HUAWEISCSI2] = "UQ_MSC_EJECT_HUAWEISCSI2", 608 [UQ_MSC_EJECT_TCT] = "UQ_MSC_EJECT_TCT", 609 [UQ_BAD_MIDI] = "UQ_BAD_MIDI", 610 [UQ_AU_VENDOR_CLASS] = "UQ_AU_VENDOR_CLASS", 611 [UQ_SINGLE_CMD_MIDI] = "UQ_SINGLE_CMD_MIDI", 612 [UQ_MSC_DYMO_EJECT] = "UQ_MSC_DYMO_EJECT", 613 [UQ_AU_SET_SPDIF_CM6206] = "UQ_AU_SET_SPDIF_CM6206", 614 [UQ_WMT_IGNORE] = "UQ_WMT_IGNORE", 615 }; 616 617 /*------------------------------------------------------------------------* 618 * usb_quirkstr 619 * 620 * This function converts an USB quirk code into a string. 621 *------------------------------------------------------------------------*/ 622 static const char * 623 usb_quirkstr(uint16_t quirk) 624 { 625 return ((quirk < USB_QUIRK_MAX && usb_quirk_str[quirk] != NULL) ? 626 usb_quirk_str[quirk] : "UQ_UNKNOWN"); 627 } 628 629 /*------------------------------------------------------------------------* 630 * usb_strquirk 631 * 632 * This function converts a string into a USB quirk code. 633 * 634 * Returns: 635 * Less than USB_QUIRK_MAX: Quirk code 636 * Else: Quirk code not found 637 *------------------------------------------------------------------------*/ 638 static uint16_t 639 usb_strquirk(const char *str, size_t len) 640 { 641 const char *quirk; 642 uint16_t x; 643 644 for (x = 0; x != USB_QUIRK_MAX; x++) { 645 quirk = usb_quirkstr(x); 646 if (strncmp(str, quirk, len) == 0 && 647 quirk[len] == 0) 648 break; 649 } 650 return (x); 651 } 652 653 /*------------------------------------------------------------------------* 654 * usb_test_quirk_by_info 655 * 656 * Returns: 657 * 0: Quirk not found 658 * Else: Quirk found 659 *------------------------------------------------------------------------*/ 660 static uint8_t 661 usb_test_quirk_by_info(const struct usbd_lookup_info *info, uint16_t quirk) 662 { 663 uint16_t x; 664 uint16_t y; 665 666 if (quirk == UQ_NONE) 667 goto done; 668 669 USB_MTX_LOCK(&usb_quirk_mtx); 670 671 for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) { 672 /* see if quirk information does not match */ 673 if ((usb_quirks[x].vid != info->idVendor) || 674 (usb_quirks[x].lo_rev > info->bcdDevice) || 675 (usb_quirks[x].hi_rev < info->bcdDevice)) { 676 continue; 677 } 678 /* see if quirk only should match vendor ID */ 679 if (usb_quirks[x].pid != info->idProduct) { 680 if (usb_quirks[x].pid != 0) 681 continue; 682 683 for (y = 0; y != USB_SUB_QUIRKS_MAX; y++) { 684 if (usb_quirks[x].quirks[y] == UQ_MATCH_VENDOR_ONLY) 685 break; 686 } 687 if (y == USB_SUB_QUIRKS_MAX) 688 continue; 689 } 690 /* lookup quirk */ 691 for (y = 0; y != USB_SUB_QUIRKS_MAX; y++) { 692 if (usb_quirks[x].quirks[y] == quirk) { 693 USB_MTX_UNLOCK(&usb_quirk_mtx); 694 DPRINTF("Found quirk '%s'.\n", usb_quirkstr(quirk)); 695 return (1); 696 } 697 } 698 } 699 USB_MTX_UNLOCK(&usb_quirk_mtx); 700 done: 701 return (0); /* no quirk match */ 702 } 703 704 static struct usb_quirk_entry * 705 usb_quirk_get_entry(uint16_t vid, uint16_t pid, 706 uint16_t lo_rev, uint16_t hi_rev, uint8_t do_alloc) 707 { 708 uint16_t x; 709 710 USB_MTX_ASSERT(&usb_quirk_mtx, MA_OWNED); 711 712 if ((vid | pid | lo_rev | hi_rev) == 0) { 713 /* all zero - special case */ 714 return (usb_quirks + USB_DEV_QUIRKS_MAX - 1); 715 } 716 /* search for an existing entry */ 717 for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) { 718 /* see if quirk information does not match */ 719 if ((usb_quirks[x].vid != vid) || 720 (usb_quirks[x].pid != pid) || 721 (usb_quirks[x].lo_rev != lo_rev) || 722 (usb_quirks[x].hi_rev != hi_rev)) { 723 continue; 724 } 725 return (usb_quirks + x); 726 } 727 728 if (do_alloc == 0) { 729 /* no match */ 730 return (NULL); 731 } 732 /* search for a free entry */ 733 for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) { 734 /* see if quirk information does not match */ 735 if ((usb_quirks[x].vid | 736 usb_quirks[x].pid | 737 usb_quirks[x].lo_rev | 738 usb_quirks[x].hi_rev) != 0) { 739 continue; 740 } 741 usb_quirks[x].vid = vid; 742 usb_quirks[x].pid = pid; 743 usb_quirks[x].lo_rev = lo_rev; 744 usb_quirks[x].hi_rev = hi_rev; 745 746 return (usb_quirks + x); 747 } 748 749 /* no entry found */ 750 return (NULL); 751 } 752 753 /*------------------------------------------------------------------------* 754 * usb_quirk_ioctl - handle quirk IOCTLs 755 * 756 * Returns: 757 * 0: Success 758 * Else: Failure 759 *------------------------------------------------------------------------*/ 760 static int 761 usb_quirk_ioctl(unsigned long cmd, caddr_t data, 762 int fflag, struct thread *td) 763 { 764 struct usb_gen_quirk *pgq; 765 struct usb_quirk_entry *pqe; 766 uint32_t x; 767 uint32_t y; 768 int err; 769 770 switch (cmd) { 771 case USB_DEV_QUIRK_GET: 772 pgq = (void *)data; 773 x = pgq->index % USB_SUB_QUIRKS_MAX; 774 y = pgq->index / USB_SUB_QUIRKS_MAX; 775 if (y >= USB_DEV_QUIRKS_MAX) { 776 return (EINVAL); 777 } 778 USB_MTX_LOCK(&usb_quirk_mtx); 779 /* copy out data */ 780 pgq->vid = usb_quirks[y].vid; 781 pgq->pid = usb_quirks[y].pid; 782 pgq->bcdDeviceLow = usb_quirks[y].lo_rev; 783 pgq->bcdDeviceHigh = usb_quirks[y].hi_rev; 784 strlcpy(pgq->quirkname, 785 usb_quirkstr(usb_quirks[y].quirks[x]), 786 sizeof(pgq->quirkname)); 787 USB_MTX_UNLOCK(&usb_quirk_mtx); 788 return (0); /* success */ 789 790 case USB_QUIRK_NAME_GET: 791 pgq = (void *)data; 792 x = pgq->index; 793 if (x >= USB_QUIRK_MAX) { 794 return (EINVAL); 795 } 796 strlcpy(pgq->quirkname, 797 usb_quirkstr(x), sizeof(pgq->quirkname)); 798 return (0); /* success */ 799 800 case USB_DEV_QUIRK_ADD: 801 pgq = (void *)data; 802 803 /* check privileges */ 804 err = priv_check(curthread, PRIV_DRIVER); 805 if (err) { 806 return (err); 807 } 808 /* convert quirk string into numerical */ 809 for (y = 0; y != USB_DEV_QUIRKS_MAX; y++) { 810 if (strcmp(pgq->quirkname, usb_quirkstr(y)) == 0) { 811 break; 812 } 813 } 814 if (y == USB_DEV_QUIRKS_MAX) { 815 return (EINVAL); 816 } 817 if (y == UQ_NONE) { 818 return (EINVAL); 819 } 820 USB_MTX_LOCK(&usb_quirk_mtx); 821 pqe = usb_quirk_get_entry(pgq->vid, pgq->pid, 822 pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 1); 823 if (pqe == NULL) { 824 USB_MTX_UNLOCK(&usb_quirk_mtx); 825 return (EINVAL); 826 } 827 for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) { 828 if (pqe->quirks[x] == UQ_NONE) { 829 pqe->quirks[x] = y; 830 break; 831 } 832 } 833 USB_MTX_UNLOCK(&usb_quirk_mtx); 834 if (x == USB_SUB_QUIRKS_MAX) { 835 return (ENOMEM); 836 } 837 return (0); /* success */ 838 839 case USB_DEV_QUIRK_REMOVE: 840 pgq = (void *)data; 841 /* check privileges */ 842 err = priv_check(curthread, PRIV_DRIVER); 843 if (err) { 844 return (err); 845 } 846 /* convert quirk string into numerical */ 847 for (y = 0; y != USB_DEV_QUIRKS_MAX; y++) { 848 if (strcmp(pgq->quirkname, usb_quirkstr(y)) == 0) { 849 break; 850 } 851 } 852 if (y == USB_DEV_QUIRKS_MAX) { 853 return (EINVAL); 854 } 855 if (y == UQ_NONE) { 856 return (EINVAL); 857 } 858 USB_MTX_LOCK(&usb_quirk_mtx); 859 pqe = usb_quirk_get_entry(pgq->vid, pgq->pid, 860 pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 0); 861 if (pqe == NULL) { 862 USB_MTX_UNLOCK(&usb_quirk_mtx); 863 return (EINVAL); 864 } 865 for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) { 866 if (pqe->quirks[x] == y) { 867 pqe->quirks[x] = UQ_NONE; 868 break; 869 } 870 } 871 if (x == USB_SUB_QUIRKS_MAX) { 872 USB_MTX_UNLOCK(&usb_quirk_mtx); 873 return (ENOMEM); 874 } 875 for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) { 876 if (pqe->quirks[x] != UQ_NONE) { 877 break; 878 } 879 } 880 if (x == USB_SUB_QUIRKS_MAX) { 881 /* all quirk entries are unused - release */ 882 memset(pqe, 0, sizeof(*pqe)); 883 } 884 USB_MTX_UNLOCK(&usb_quirk_mtx); 885 return (0); /* success */ 886 887 default: 888 break; 889 } 890 return (ENOIOCTL); 891 } 892 893 /*------------------------------------------------------------------------* 894 * usb_quirk_strtou16 895 * 896 * Helper function to scan a 16-bit integer. 897 *------------------------------------------------------------------------*/ 898 static uint16_t 899 usb_quirk_strtou16(const char **pptr, const char *name, const char *what) 900 { 901 unsigned long value; 902 char *end; 903 904 value = strtoul(*pptr, &end, 0); 905 if (value > 65535 || *pptr == end || (*end != ' ' && *end != '\t')) { 906 printf("%s: %s 16-bit %s value set to zero\n", 907 name, what, *end == 0 ? "incomplete" : "invalid"); 908 return (0); 909 } 910 *pptr = end + 1; 911 return ((uint16_t)value); 912 } 913 914 /*------------------------------------------------------------------------* 915 * usb_quirk_add_entry_from_str 916 * 917 * Add a USB quirk entry from string. 918 * "VENDOR PRODUCT LO_REV HI_REV QUIRK[,QUIRK[,...]]" 919 *------------------------------------------------------------------------*/ 920 static void 921 usb_quirk_add_entry_from_str(const char *name, const char *env) 922 { 923 struct usb_quirk_entry entry = { }; 924 struct usb_quirk_entry *new; 925 uint16_t quirk_idx; 926 uint16_t quirk; 927 const char *end; 928 929 /* check for invalid environment variable */ 930 if (name == NULL || env == NULL) 931 return; 932 933 if (bootverbose) 934 printf("Adding USB QUIRK '%s' = '%s'\n", name, env); 935 936 /* parse device information */ 937 entry.vid = usb_quirk_strtou16(&env, name, "Vendor ID"); 938 entry.pid = usb_quirk_strtou16(&env, name, "Product ID"); 939 entry.lo_rev = usb_quirk_strtou16(&env, name, "Low revision"); 940 entry.hi_rev = usb_quirk_strtou16(&env, name, "High revision"); 941 942 /* parse quirk information */ 943 quirk_idx = 0; 944 while (*env != 0 && quirk_idx != USB_SUB_QUIRKS_MAX) { 945 /* skip whitespace before quirks */ 946 while (*env == ' ' || *env == '\t') 947 env++; 948 949 /* look for quirk separation character */ 950 end = strchr(env, ','); 951 if (end == NULL) 952 end = env + strlen(env); 953 954 /* lookup quirk in string table */ 955 quirk = usb_strquirk(env, end - env); 956 if (quirk < USB_QUIRK_MAX) { 957 entry.quirks[quirk_idx++] = quirk; 958 } else { 959 printf("%s: unknown USB quirk '%.*s' (skipped)\n", 960 name, (int)(end - env), env); 961 } 962 env = end; 963 964 /* skip quirk delimiter, if any */ 965 if (*env != 0) 966 env++; 967 } 968 969 /* register quirk */ 970 if (quirk_idx != 0) { 971 if (*env != 0) { 972 printf("%s: Too many USB quirks, only %d allowed!\n", 973 name, USB_SUB_QUIRKS_MAX); 974 } 975 USB_MTX_LOCK(&usb_quirk_mtx); 976 new = usb_quirk_get_entry(entry.vid, entry.pid, 977 entry.lo_rev, entry.hi_rev, 1); 978 if (new == NULL) 979 printf("%s: USB quirks table is full!\n", name); 980 else 981 memcpy(new->quirks, entry.quirks, sizeof(entry.quirks)); 982 USB_MTX_UNLOCK(&usb_quirk_mtx); 983 } else { 984 printf("%s: No USB quirks found!\n", name); 985 } 986 } 987 988 static void 989 usb_quirk_init(void *arg) 990 { 991 char envkey[sizeof(USB_QUIRK_ENVROOT) + 2]; /* 2 digits max, 0 to 99 */ 992 int i; 993 994 /* initialize mutex */ 995 mtx_init(&usb_quirk_mtx, "USB quirk", NULL, MTX_DEF); 996 997 /* look for quirks defined by the environment variable */ 998 for (i = 0; i != 100; i++) { 999 snprintf(envkey, sizeof(envkey), USB_QUIRK_ENVROOT "%d", i); 1000 1001 /* Stop at first undefined var */ 1002 if (!testenv(envkey)) 1003 break; 1004 1005 /* parse environment variable */ 1006 usb_quirk_add_entry_from_str(envkey, kern_getenv(envkey)); 1007 } 1008 1009 /* register our function */ 1010 usb_test_quirk_p = &usb_test_quirk_by_info; 1011 usb_quirk_ioctl_p = &usb_quirk_ioctl; 1012 } 1013 1014 static void 1015 usb_quirk_uninit(void *arg) 1016 { 1017 usb_quirk_unload(arg); 1018 1019 /* destroy mutex */ 1020 mtx_destroy(&usb_quirk_mtx); 1021 } 1022 1023 SYSINIT(usb_quirk_init, SI_SUB_LOCK, SI_ORDER_FIRST, usb_quirk_init, NULL); 1024 SYSUNINIT(usb_quirk_uninit, SI_SUB_LOCK, SI_ORDER_ANY, usb_quirk_uninit, NULL); 1025