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