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