• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "implementation/global_implementation.h"
32 #include "implementation/usbdevs.h"
33 
34 MODULE_DEPEND(usb_quirk, usb, 1, 1, 1);
35 
36 #define	USB_DEV_QUIRKS_MAX 384
37 #define	USB_SUB_QUIRKS_MAX 8
38 
39 struct usb_quirk_entry {
40 	uint16_t vid;
41 	uint16_t pid;
42 	uint16_t lo_rev;
43 	uint16_t hi_rev;
44 	uint16_t quirks[USB_SUB_QUIRKS_MAX];
45 };
46 
47 static struct mtx usb_quirk_mtx;
48 
49 #define	USB_QUIRK_VP(v,p,l,h,...) \
50   { .vid = (v), .pid = (p), .lo_rev = (l), .hi_rev = (h), \
51     .quirks = { __VA_ARGS__ } }
52 #define	USB_QUIRK(v,p,l,h,...) \
53   USB_QUIRK_VP(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, l, h, __VA_ARGS__)
54 
55 static struct usb_quirk_entry usb_quirks[USB_DEV_QUIRKS_MAX] = {
56 	USB_QUIRK(HUAWEI, ME909S, 0x0000, 0xffff, UQ_CFG_INDEX_1),
57 	USB_QUIRK(ASUS, LCM, 0x0000, 0xffff, UQ_HID_IGNORE),
58 	USB_QUIRK(INSIDEOUT, EDGEPORT4, 0x094, 0x094, UQ_SWAP_UNICODE),
59 	USB_QUIRK(DALLAS, J6502, 0x0a2, 0x0a2, UQ_BAD_ADC),
60 	USB_QUIRK(DALLAS, J6502, 0x0a2, 0x0a2, UQ_AU_NO_XU),
61 	USB_QUIRK(ALTEC, ADA70, 0x103, 0x103, UQ_BAD_ADC),
62 	USB_QUIRK(ALTEC, ASC495, 0x000, 0x000, UQ_BAD_AUDIO),
63 	USB_QUIRK(QTRONIX, 980N, 0x110, 0x110, UQ_SPUR_BUT_UP),
64 	USB_QUIRK(ALCOR2, KBD_HUB, 0x001, 0x001, UQ_SPUR_BUT_UP),
65 	USB_QUIRK(MCT, HUB0100, 0x102, 0x102, UQ_BUS_POWERED),
66 	USB_QUIRK(MCT, USB232, 0x102, 0x102, UQ_BUS_POWERED),
67 	USB_QUIRK(TI, UTUSB41, 0x110, 0x110, UQ_POWER_CLAIM),
68 	USB_QUIRK(TELEX, MIC1, 0x009, 0x009, UQ_AU_NO_FRAC),
69 	USB_QUIRK(SILICONPORTALS, YAPPHONE, 0x100, 0x100, UQ_AU_INP_ASYNC),
70 	USB_QUIRK(LOGITECH, UN53B, 0x0000, 0xffff, UQ_NO_STRINGS),
71 	USB_QUIRK(LOGITECH, G510S, 0x0000, 0xFFFF, UQ_KBD_BOOTPROTO),
72 	USB_QUIRK(REALTEK, RTL8196EU, 0x0000, 0xffff, UQ_CFG_INDEX_1),
73 	USB_QUIRK(REALTEK, RTL8153, 0x0000, 0xffff, UQ_CFG_INDEX_1),
74 	USB_QUIRK(ELSA, MODEM1, 0x0000, 0xffff, UQ_CFG_INDEX_1),
75 	USB_QUIRK(PLANEX2, MZKUE150N, 0x0000, 0xffff, UQ_CFG_INDEX_1),
76 	USB_QUIRK(CISCOLINKSYS, USB3GIGV1, 0x0000, 0xffff, UQ_CFG_INDEX_1),
77 	/* Quirks for printer devices */
78 	USB_QUIRK(HP, 895C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
79 	USB_QUIRK(HP, 880C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
80 	USB_QUIRK(HP, 815C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
81 	USB_QUIRK(HP, 810C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
82 	USB_QUIRK(HP, 830C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
83 	USB_QUIRK(HP, 1220C, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
84 	USB_QUIRK(XEROX, WCM15, 0x0000, 0xffff, UQ_BROKEN_BIDIR),
85 	/* Devices which should be ignored by uhid */
86 	USB_QUIRK(APC, UPS, 0x0000, 0xffff, UQ_HID_IGNORE),
87 	USB_QUIRK(BELKIN, F6C550AVR, 0x0000, 0xffff, UQ_HID_IGNORE),
88 	USB_QUIRK(CYBERPOWER, 1500CAVRLCD, 0x0000, 0xffff, UQ_HID_IGNORE),
89 	USB_QUIRK(CYPRESS, SILVERSHIELD, 0x0000, 0xffff, UQ_HID_IGNORE),
90 	USB_QUIRK(DELORME, EARTHMATE, 0x0000, 0xffff, UQ_HID_IGNORE),
91 	USB_QUIRK(DREAMLINK, DL100B, 0x0000, 0xffff, UQ_HID_IGNORE),
92 	USB_QUIRK(ITUNERNET, USBLCD2X20, 0x0000, 0xffff, UQ_HID_IGNORE),
93 	USB_QUIRK(ITUNERNET, USBLCD4X20, 0x0000, 0xffff, UQ_HID_IGNORE),
94 	USB_QUIRK(LIEBERT, POWERSURE_PXT, 0x0000, 0xffff, UQ_HID_IGNORE),
95 	USB_QUIRK(LIEBERT2, PSI1000, 0x0000, 0xffff, UQ_HID_IGNORE),
96 	USB_QUIRK(MGE, UPS1, 0x0000, 0xffff, UQ_HID_IGNORE),
97 	USB_QUIRK(MGE, UPS2, 0x0000, 0xffff, UQ_HID_IGNORE),
98 	USB_QUIRK(APPLE, IPHONE, 0x0000, 0xffff, UQ_HID_IGNORE),
99 	USB_QUIRK(APPLE, IPHONE_3G, 0x0000, 0xffff, UQ_HID_IGNORE),
100 	USB_QUIRK(MEGATEC, UPS, 0x0000, 0xffff, UQ_HID_IGNORE),
101 	/* Devices which should be ignored by both ukbd and uhid */
102 	USB_QUIRK(CYPRESS, WISPY1A, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE),
103 	USB_QUIRK(METAGEEK, WISPY1B, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE),
104 	USB_QUIRK(METAGEEK, WISPY24X, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE),
105 	USB_QUIRK(METAGEEK2, WISPYDBX, 0x0000, 0xffff, UQ_KBD_IGNORE, UQ_HID_IGNORE),
106 	USB_QUIRK(TENX, UAUDIO0, 0x0101, 0x0101, UQ_AUDIO_SWAP_LR),
107 	/* MS keyboards do weird things */
108 	USB_QUIRK(MICROSOFT, NATURAL4000, 0x0000, 0xFFFF, UQ_KBD_BOOTPROTO),
109 	USB_QUIRK(MICROSOFT, WLINTELLIMOUSE, 0x0000, 0xffff, UQ_MS_LEADING_BYTE),
110 	/* Quirk for Corsair Vengeance K60 keyboard */
111 	USB_QUIRK(CORSAIR, K60, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
112 	/* Quirk for Corsair Gaming K68 keyboard */
113 	USB_QUIRK(CORSAIR, K68, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
114 	/* Quirk for Corsair Vengeance K70 keyboard */
115 	USB_QUIRK(CORSAIR, K70, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
116 	/* Quirk for Corsair K70 RGB keyboard */
117 	USB_QUIRK(CORSAIR, K70_RGB, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
118 	/* Quirk for Corsair STRAFE Gaming keyboard */
119 	USB_QUIRK(CORSAIR, STRAFE, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
120 	USB_QUIRK(CORSAIR, STRAFE2, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
121 	/* umodem(4) device quirks */
122 	USB_QUIRK(METRICOM, RICOCHET_GS, 0x100, 0x100, UQ_ASSUME_CM_OVER_DATA),
123 	USB_QUIRK(SANYO, SCP4900, 0x000, 0x000, UQ_ASSUME_CM_OVER_DATA),
124 	USB_QUIRK(MOTOROLA2, T720C, 0x001, 0x001, UQ_ASSUME_CM_OVER_DATA),
125 	USB_QUIRK(EICON, DIVA852, 0x100, 0x100, UQ_ASSUME_CM_OVER_DATA),
126 	USB_QUIRK(SIEMENS2, ES75, 0x000, 0x000, UQ_ASSUME_CM_OVER_DATA),
127 	USB_QUIRK(QUALCOMM, CDMA_MSM, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA),
128 	USB_QUIRK(QUALCOMM2, CDMA_MSM, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA),
129 	USB_QUIRK(CURITEL, UM150, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA),
130 	USB_QUIRK(CURITEL, UM175, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA),
131 	USB_QUIRK(VERTEX, VW110L, 0x0000, 0xffff, UQ_ASSUME_CM_OVER_DATA),
132 
133 	/* USB Mass Storage Class Quirks */
134 	USB_QUIRK_VP(USB_VENDOR_ASAHIOPTICAL, 0, UQ_MSC_NO_RS_CLEAR_UA,
135 	    UQ_MATCH_VENDOR_ONLY),
136 	USB_QUIRK(ADDON, ATTACHE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
137 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
138 	USB_QUIRK(ADDON, A256MB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
139 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
140 	USB_QUIRK(ADDON, DISKPRO512, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
141 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
142 	USB_QUIRK(ADDONICS2, CABLE_205, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
143 	    UQ_MSC_FORCE_PROTO_SCSI),
144 	USB_QUIRK(AIPTEK, POCKETCAM3M, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
145 	    UQ_MSC_FORCE_PROTO_SCSI),
146 	USB_QUIRK(ALCOR, UMCR_9361, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
147 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
148 	USB_QUIRK(ALCOR, TRANSCEND, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN,
149 	    UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_TEST_UNIT_READY),
150 	USB_QUIRK(APACER, HT202, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY,
151 	    UQ_MSC_NO_SYNC_CACHE),
152 	USB_QUIRK(ASAHIOPTICAL, OPTIO230, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
153 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
154 	USB_QUIRK(ASAHIOPTICAL, OPTIO330, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
155 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
156 	USB_QUIRK(ATP, EUSB, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
157 	USB_QUIRK(BELKIN, USB2SCSI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
158 	    UQ_MSC_FORCE_PROTO_SCSI),
159 	USB_QUIRK(CASIO, QV_DIGICAM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
160 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
161 	USB_QUIRK(CCYU, ED1064, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
162 	    UQ_MSC_FORCE_PROTO_SCSI),
163 	USB_QUIRK(CENTURY, EX35QUAT, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
164 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
165 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
166 	USB_QUIRK(CYPRESS, XX6830XX, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN,
167 	    UQ_MSC_NO_SYNC_CACHE),
168 	USB_QUIRK(DESKNOTE, UCR_61S2B, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
169 	    UQ_MSC_FORCE_PROTO_SCSI),
170 	USB_QUIRK(DMI, CFSM_RW, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI,
171 	    UQ_MSC_NO_GETMAXLUN),
172 	USB_QUIRK(EMTEC, RUF2PS, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
173 	USB_QUIRK(EPSON, STYLUS_875DC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
174 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
175 	USB_QUIRK(EPSON, STYLUS_895, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
176 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
177 	USB_QUIRK(FEIYA, ELANGO, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
178 	USB_QUIRK(FREECOM, DVD, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
179 	USB_QUIRK(FUJIPHOTO, MASS0100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I,
180 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_NO_SYNC_CACHE),
181 	USB_QUIRK(GARMIN, FORERUNNER230, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY),
182 	USB_QUIRK(GENESYS, GL641USB2IDE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
183 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
184 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE, UQ_MSC_NO_SYNC_CACHE),
185 	USB_QUIRK(GENESYS, GL641USB2IDE_2, 0x0000, 0xffff,
186 	    UQ_MSC_FORCE_WIRE_BBB, UQ_MSC_FORCE_PROTO_ATAPI,
187 	    UQ_MSC_FORCE_SHORT_INQ, UQ_MSC_NO_START_STOP,
188 	    UQ_MSC_IGNORE_RESIDUE),
189 	USB_QUIRK(GENESYS, GL641USB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
190 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
191 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
192 	USB_QUIRK(GENESYS, GL641USB_2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
193 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG),
194 	USB_QUIRK(HAGIWARA, FG, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
195 	    UQ_MSC_FORCE_PROTO_SCSI),
196 	USB_QUIRK(HAGIWARA, FGSM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
197 	    UQ_MSC_FORCE_PROTO_SCSI),
198 	USB_QUIRK(HITACHI, DVDCAM_DZ_MV100A, 0x0000, 0xffff,
199 	    UQ_MSC_FORCE_WIRE_CBI, UQ_MSC_FORCE_PROTO_SCSI,
200 	    UQ_MSC_NO_GETMAXLUN),
201 	USB_QUIRK(HITACHI, DVDCAM_USB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I,
202 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY),
203 	USB_QUIRK(HP, CDW4E, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_ATAPI),
204 	USB_QUIRK(HP, CDW8200, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I,
205 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY,
206 	    UQ_MSC_NO_START_STOP),
207 	USB_QUIRK(IMAGINATION, DBX1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
208 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG),
209 	USB_QUIRK(INSYSTEM, USBCABLE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
210 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY,
211 	    UQ_MSC_NO_START_STOP, UQ_MSC_ALT_IFACE_1),
212 	USB_QUIRK(INSYSTEM, ATAPI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
213 	    UQ_MSC_FORCE_PROTO_RBC),
214 	USB_QUIRK(INSYSTEM, STORAGE_V2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
215 	    UQ_MSC_FORCE_PROTO_RBC),
216 	USB_QUIRK(INTENSO, MEMORY_BOX, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY),
217 	USB_QUIRK(IODATA, IU_CD2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
218 	    UQ_MSC_FORCE_PROTO_SCSI),
219 	USB_QUIRK(IODATA, DVR_UEH8, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
220 	    UQ_MSC_FORCE_PROTO_SCSI),
221 	USB_QUIRK(IOMEGA, ZIP100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
222 	    UQ_MSC_FORCE_PROTO_SCSI,
223 	    UQ_MSC_NO_TEST_UNIT_READY), /* XXX ZIP drives can also use ATAPI */
224 	USB_QUIRK(JMICRON, JMS566, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN),
225 	USB_QUIRK(JMICRON, JMS567, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN),
226 	USB_QUIRK(JMICRON, JM20337, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
227 	    UQ_MSC_FORCE_PROTO_SCSI,
228 	    UQ_MSC_NO_SYNC_CACHE),
229 	USB_QUIRK(KINGSTON, HYPERX3_0, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY),
230 	USB_QUIRK(KYOCERA, FINECAM_L3, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
231 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
232 	USB_QUIRK(KYOCERA, FINECAM_S3X, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
233 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY),
234 	USB_QUIRK(KYOCERA, FINECAM_S4, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
235 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY),
236 	USB_QUIRK(KYOCERA, FINECAM_S5, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
237 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
238 	USB_QUIRK(LACIE, HD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
239 	    UQ_MSC_FORCE_PROTO_RBC),
240 	USB_QUIRK(LEXAR, CF_READER, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
241 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
242 	USB_QUIRK(LEXAR, JUMPSHOT, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
243 	USB_QUIRK(LEXAR, JUMPDRIVE, 0x0000, 0xffff, UQ_MSC_NO_INQUIRY),
244 	USB_QUIRK(LOGITEC, LDR_H443SU2, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
245 	USB_QUIRK(LOGITEC, LDR_H443U2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
246 	    UQ_MSC_FORCE_PROTO_SCSI,),
247 	USB_QUIRK(MELCO, DUBPXXG, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
248 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
249 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
250 	USB_QUIRK(MICROTECH, DPCM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
251 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_TEST_UNIT_READY,
252 	    UQ_MSC_NO_START_STOP),
253 	USB_QUIRK(MICRON, REALSSD, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
254 	USB_QUIRK(MICROTECH, SCSIDB25, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
255 	    UQ_MSC_FORCE_PROTO_SCSI),
256 	USB_QUIRK(MICROTECH, SCSIHD50, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
257 	    UQ_MSC_FORCE_PROTO_SCSI),
258 	USB_QUIRK(MINOLTA, E223, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
259 	USB_QUIRK(MINOLTA, F300, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
260 	    UQ_MSC_FORCE_PROTO_SCSI),
261 	USB_QUIRK(MITSUMI, CDRRW, 0x0000, 0xffff, (UQ_MSC_FORCE_WIRE_CBI |
262 	UQ_MSC_FORCE_PROTO_ATAPI)),
263 	USB_QUIRK(MOTOROLA2, E398, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
264 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
265 	    UQ_MSC_NO_INQUIRY_EVPD, UQ_MSC_NO_GETMAXLUN),
266 	USB_QUIRK_VP(USB_VENDOR_MPMAN, 0, UQ_MSC_NO_SYNC_CACHE,
267 	    UQ_MATCH_VENDOR_ONLY),
268 	USB_QUIRK(MSYSTEMS, DISKONKEY, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
269 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE, UQ_MSC_NO_GETMAXLUN,
270 	    UQ_MSC_NO_RS_CLEAR_UA),
271 	USB_QUIRK(MSYSTEMS, DISKONKEY2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
272 	    UQ_MSC_FORCE_PROTO_ATAPI),
273 	USB_QUIRK(MYSON, HEDEN, 0x0000, 0xffff, UQ_MSC_IGNORE_RESIDUE,
274 	    UQ_MSC_NO_SYNC_CACHE),
275 	USB_QUIRK(NEODIO, ND3260, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
276 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ),
277 	USB_QUIRK(NETAC, CF_CARD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
278 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
279 	USB_QUIRK(NETAC, ONLYDISK, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
280 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
281 	USB_QUIRK(NETCHIP, CLIK_40, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_ATAPI,
282 	    UQ_MSC_NO_INQUIRY),
283 	USB_QUIRK(NETCHIP, POCKETBOOK, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
284 	USB_QUIRK(NIKON, D300, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
285 	    UQ_MSC_FORCE_PROTO_SCSI),
286 	USB_QUIRK(OLYMPUS, C1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
287 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_WRONG_CSWSIG),
288 	USB_QUIRK(OLYMPUS, C700, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN),
289 	USB_QUIRK(ONSPEC, SDS_HOTFIND_D, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
290 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN, UQ_MSC_NO_SYNC_CACHE),
291 	USB_QUIRK(ONSPEC, CFMS_RW, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
292 	USB_QUIRK(ONSPEC, CFSM_COMBO, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
293 	USB_QUIRK(ONSPEC, CFSM_READER, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
294 	USB_QUIRK(ONSPEC, CFSM_READER2, 0x0000, 0xffff,
295 	    UQ_MSC_FORCE_PROTO_SCSI),
296 	USB_QUIRK(ONSPEC, MDCFE_B_CF_READER, 0x0000, 0xffff,
297 	    UQ_MSC_FORCE_PROTO_SCSI),
298 	USB_QUIRK(ONSPEC, MDSM_B_READER, 0x0000, 0xffff,
299 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
300 	USB_QUIRK(ONSPEC, READER, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
301 	USB_QUIRK(ONSPEC, UCF100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
302 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY, UQ_MSC_NO_GETMAXLUN),
303 	USB_QUIRK(ONSPEC2, IMAGEMATE_SDDR55, 0x0000, 0xffff,
304 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
305 	USB_QUIRK(PANASONIC, KXL840AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
306 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_GETMAXLUN),
307 	USB_QUIRK(PANASONIC, KXLCB20AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
308 	    UQ_MSC_FORCE_PROTO_SCSI),
309 	USB_QUIRK(PANASONIC, KXLCB35AN, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
310 	    UQ_MSC_FORCE_PROTO_SCSI),
311 	USB_QUIRK(PANASONIC, LS120CAM, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_UFI),
312 	USB_QUIRK(PLEXTOR, 40_12_40U, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
313 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_TEST_UNIT_READY),
314 	USB_QUIRK(PNY, ATTACHE2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
315 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE,
316 	    UQ_MSC_NO_START_STOP),
317 	USB_QUIRK(PROLIFIC, PL2506, 0x0000, 0xffff,
318 	    UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_PREVENT_ALLOW),
319 	USB_QUIRK_VP(USB_VENDOR_SAMSUNG_TECHWIN,
320 	    USB_PRODUCT_SAMSUNG_TECHWIN_DIGIMAX_410, UQ_MSC_FORCE_WIRE_BBB,
321 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
322 	USB_QUIRK(SANDISK, SDDR05A, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
323 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1,
324 	    UQ_MSC_NO_GETMAXLUN),
325 	USB_QUIRK(SANDISK, SDDR09, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI,
326 	    UQ_MSC_READ_CAP_OFFBY1, UQ_MSC_NO_GETMAXLUN),
327 	USB_QUIRK(SANDISK, SDDR12, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
328 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1,
329 	    UQ_MSC_NO_GETMAXLUN),
330 	USB_QUIRK(SANDISK, SDCZ2_128, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
331 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE,
332 	    UQ_MSC_NO_SYNC_CACHE),
333 	USB_QUIRK(SANDISK, SDCZ2_256, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
334 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
335 	USB_QUIRK(SANDISK, SDCZ4_128, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
336 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
337 	USB_QUIRK(SANDISK, SDCZ4_256, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
338 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
339 	USB_QUIRK(SANDISK, SDCZ48_32, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE,
340 	    UQ_MSC_NO_TEST_UNIT_READY),
341 	USB_QUIRK(SANDISK, SDDR31, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
342 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_READ_CAP_OFFBY1),
343 	USB_QUIRK(SANDISK, IMAGEMATE_SDDR289, 0x0000, 0xffff,
344 	    UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_GETMAXLUN),
345 	USB_QUIRK(SCANLOGIC, SL11R, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
346 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_INQUIRY),
347 	USB_QUIRK(SHUTTLE, EUSB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I,
348 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_NO_TEST_UNIT_READY,
349 	    UQ_MSC_NO_START_STOP, UQ_MSC_SHUTTLE_INIT),
350 	USB_QUIRK(SHUTTLE, CDRW, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
351 	    UQ_MSC_FORCE_PROTO_ATAPI),
352 	USB_QUIRK(SHUTTLE, CF, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
353 	    UQ_MSC_FORCE_PROTO_ATAPI),
354 	USB_QUIRK(SHUTTLE, EUSBATAPI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
355 	    UQ_MSC_FORCE_PROTO_ATAPI),
356 	USB_QUIRK(SHUTTLE, EUSBCFSM, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
357 	USB_QUIRK(SHUTTLE, EUSCSI, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
358 	    UQ_MSC_FORCE_PROTO_SCSI),
359 	USB_QUIRK(SHUTTLE, HIFD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
360 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
361 	USB_QUIRK(SHUTTLE, SDDR09, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI,
362 	    UQ_MSC_NO_GETMAXLUN),
363 	USB_QUIRK(SHUTTLE, ZIOMMC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
364 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
365 	USB_QUIRK(SIGMATEL, I_BEAD100, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
366 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_SHUTTLE_INIT),
367 	USB_QUIRK(SIIG, WINTERREADER, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
368 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_IGNORE_RESIDUE),
369 	USB_QUIRK(SKANHEX, MD_7425, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
370 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
371 	USB_QUIRK(SKANHEX, SX_520Z, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
372 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
373 	USB_QUIRK(SONY, HANDYCAM, 0x0500, 0x0500, UQ_MSC_FORCE_WIRE_CBI,
374 	    UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12),
375 	USB_QUIRK(SONY, CLIE_40_MS, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
376 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
377 	USB_QUIRK(SONY, DSC, 0x0500, 0x0500, UQ_MSC_FORCE_WIRE_CBI,
378 	    UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12),
379 	USB_QUIRK(SONY, DSC, 0x0600, 0x0600, UQ_MSC_FORCE_WIRE_CBI,
380 	    UQ_MSC_FORCE_PROTO_RBC, UQ_MSC_RBC_PAD_TO_12),
381 	USB_QUIRK(SONY, DSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
382 	    UQ_MSC_FORCE_PROTO_RBC),
383 	USB_QUIRK(SONY, HANDYCAM, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
384 	    UQ_MSC_FORCE_PROTO_RBC),
385 	USB_QUIRK(SONY, MSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
386 	    UQ_MSC_FORCE_PROTO_RBC),
387 	USB_QUIRK(SONY, MS_MSC_U03, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
388 	    UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_GETMAXLUN),
389 	USB_QUIRK(SONY, MS_NW_MS7, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
390 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
391 	USB_QUIRK(SONY, MS_PEG_N760C, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
392 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
393 	USB_QUIRK(SONY, MSACUS1, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
394 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_GETMAXLUN),
395 	USB_QUIRK(SONY, PORTABLE_HDD_V2, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
396 	    UQ_MSC_FORCE_PROTO_SCSI),
397 	USB_QUIRK(STMICRO, ST72682, 0x0000, 0xffff, UQ_MSC_NO_PREVENT_ALLOW),
398 	USB_QUIRK(SUPERTOP, IDE, 0x0000, 0xffff, UQ_MSC_IGNORE_RESIDUE,
399 	    UQ_MSC_NO_SYNC_CACHE),
400 	USB_QUIRK(SUPERTOP, FLASHDRIVE, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY,
401 	    UQ_MSC_NO_SYNC_CACHE),
402 	USB_QUIRK(TAUGA, CAMERAMATE, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
403 	USB_QUIRK(TEAC, FD05PUB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
404 	    UQ_MSC_FORCE_PROTO_UFI),
405 	USB_QUIRK(TECLAST, TLC300, 0x0000, 0xffff, UQ_MSC_NO_TEST_UNIT_READY,
406 	    UQ_MSC_NO_SYNC_CACHE),
407 	USB_QUIRK(TREK, MEMKEY, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
408 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
409 	USB_QUIRK(TREK, THUMBDRIVE_8MB, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
410 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_IGNORE_RESIDUE),
411 	USB_QUIRK(TRUMPION, C3310, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
412 	    UQ_MSC_FORCE_PROTO_UFI),
413 	USB_QUIRK(TRUMPION, MP3, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_RBC),
414 	USB_QUIRK(TRUMPION, T33520, 0x0000, 0xffff, UQ_MSC_FORCE_PROTO_SCSI),
415 	USB_QUIRK(TWINMOS, MDIV, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
416 	    UQ_MSC_FORCE_PROTO_SCSI),
417 	USB_QUIRK(VIA, USB2IDEBRIDGE, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
418 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_SYNC_CACHE),
419 	USB_QUIRK(VIVITAR, 35XX, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
420 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
421 	USB_QUIRK(WESTERN, COMBO, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
422 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
423 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
424 	USB_QUIRK(WESTERN, EXTHDD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
425 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
426 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
427 	USB_QUIRK(WESTERN, MYBOOK, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
428 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY_EVPD,
429 	    UQ_MSC_NO_SYNC_CACHE),
430 	USB_QUIRK(WESTERN, MYPASSPORT_00, 0x0000, 0xffff, UQ_MSC_FORCE_SHORT_INQ),
431 	USB_QUIRK(WESTERN, MYPASSPORT_01, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
432 	USB_QUIRK(WESTERN, MYPASSPORT_02, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
433 	USB_QUIRK(WESTERN, MYPASSPORT_03, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
434 	USB_QUIRK(WESTERN, MYPASSPORT_04, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
435 	USB_QUIRK(WESTERN, MYPASSPORT_05, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
436 	USB_QUIRK(WESTERN, MYPASSPORT_06, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
437 	USB_QUIRK(WESTERN, MYPASSPORT_07, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
438 	USB_QUIRK(WESTERN, MYPASSPORT_08, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
439 	USB_QUIRK(WESTERN, MYPASSPORT_09, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
440 	USB_QUIRK(WESTERN, MYPASSPORT_10, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
441 	USB_QUIRK(WESTERN, MYPASSPORT_11, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
442 	USB_QUIRK(WESTERN, MYPASSPORTES_00, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
443 	USB_QUIRK(WESTERN, MYPASSPORTES_01, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
444 	USB_QUIRK(WESTERN, MYPASSPORTES_02, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
445 	USB_QUIRK(WESTERN, MYPASSPORTES_03, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
446 	USB_QUIRK(WESTERN, MYPASSPORTES_04, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
447 	USB_QUIRK(WESTERN, MYPASSPORTES_05, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
448 	USB_QUIRK(WESTERN, MYPASSPORTES_06, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
449 	USB_QUIRK(WESTERN, MYPASSPORTES_07, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
450 	USB_QUIRK(WESTERN, MYPASSPORTES_08, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
451 	USB_QUIRK(WESTERN, MYPASSPORTES_09, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
452 	USB_QUIRK(WINMAXGROUP, FLASH64MC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
453 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY),
454 	USB_QUIRK(YANO, FW800HD, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
455 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_FORCE_SHORT_INQ,
456 	    UQ_MSC_NO_START_STOP, UQ_MSC_IGNORE_RESIDUE),
457 	USB_QUIRK(YANO, U640MO, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI_I,
458 	    UQ_MSC_FORCE_PROTO_ATAPI, UQ_MSC_FORCE_SHORT_INQ),
459 	USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0000, 0x007F, UQ_MSC_FORCE_WIRE_CBI,
460 	    UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED,
461 	    UQ_MSC_NO_TEST_UNIT_READY, UQ_MSC_NO_GETMAXLUN),
462 	USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0080, 0x0080, UQ_MSC_FORCE_WIRE_CBI_I,
463 	    UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED,
464 	    UQ_MSC_NO_TEST_UNIT_READY, UQ_MSC_NO_GETMAXLUN),
465 	USB_QUIRK(YEDATA, FLASHBUSTERU, 0x0081, 0xFFFF, UQ_MSC_FORCE_WIRE_CBI_I,
466 	    UQ_MSC_FORCE_PROTO_UFI, UQ_MSC_NO_RS_CLEAR_UA, UQ_MSC_FLOPPY_SPEED,
467 	    UQ_MSC_NO_GETMAXLUN),
468 	USB_QUIRK(ZORAN, EX20DSC, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_CBI,
469 	    UQ_MSC_FORCE_PROTO_ATAPI),
470 	USB_QUIRK(MEIZU, M6_SL, 0x0000, 0xffff, UQ_MSC_FORCE_WIRE_BBB,
471 	    UQ_MSC_FORCE_PROTO_SCSI, UQ_MSC_NO_INQUIRY, UQ_MSC_NO_SYNC_CACHE),
472 	USB_QUIRK(TOSHIBA, TRANSMEMORY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE,
473 	    UQ_MSC_NO_PREVENT_ALLOW),
474 	USB_QUIRK(VIALABS, USB30SATABRIDGE, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE),
475 	USB_QUIRK(QUALCOMMINC, ZTE_MF730M, 0x0000, 0xffff, UQ_MSC_NO_GETMAXLUN,
476 	    UQ_MSC_NO_INQUIRY, UQ_CFG_INDEX_0),
477 	/* Non-standard USB MIDI devices */
478 	USB_QUIRK(ROLAND, UM1, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
479 	USB_QUIRK(ROLAND, SC8850, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
480 	USB_QUIRK(ROLAND, SD90, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
481 	USB_QUIRK(ROLAND, UM880N, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
482 	USB_QUIRK(ROLAND, UA100, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
483 	USB_QUIRK(ROLAND, UM4, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
484 	USB_QUIRK(ROLAND, U8, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
485 	USB_QUIRK(ROLAND, UM2, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
486 	USB_QUIRK(ROLAND, SC8820, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
487 	USB_QUIRK(ROLAND, PC300, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
488 	USB_QUIRK(ROLAND, SK500, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
489 	USB_QUIRK(ROLAND, SCD70, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
490 	USB_QUIRK(ROLAND, UM550, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
491 	USB_QUIRK(ROLAND, SD20, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
492 	USB_QUIRK(ROLAND, SD80, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
493 	USB_QUIRK(ROLAND, UA700, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
494 	USB_QUIRK(ROLAND, PCR300, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
495 	USB_QUIRK(EGO, M4U, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
496 	USB_QUIRK(LOGILINK, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
497 	USB_QUIRK(MEDELI, DD305, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI, UQ_MATCH_VENDOR_ONLY),
498 	USB_QUIRK(REDOCTANE, GHMIDI, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
499 	USB_QUIRK(TEXTECH, U2M_1, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
500 	USB_QUIRK(TEXTECH, U2M_2, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
501 	USB_QUIRK(WCH2, U2M, 0x0000, 0xffff, UQ_SINGLE_CMD_MIDI),
502 
503 	/* Non-standard USB AUDIO devices */
504 	USB_QUIRK(MAUDIO, FASTTRACKULTRA, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
505 	USB_QUIRK(MAUDIO, FASTTRACKULTRA8R, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
506 	USB_QUIRK(CMEDIA, CM6206, 0x0000, 0xffff, UQ_AU_SET_SPDIF_CM6206),
507 	USB_QUIRK(PLOYTEC, SPL_CRIMSON_1, 0x0000, 0xffff, UQ_CFG_INDEX_1),
508 	USB_QUIRK(ROLAND, UA25EX_AD, 0x0000, 0xffff, UQ_AU_VENDOR_CLASS),
509 
510 	/*
511 	 * Quirks for manufacturers which USB devices does not respond
512 	 * after issuing non-supported commands:
513 	 */
514 	USB_QUIRK(ALCOR, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MSC_NO_TEST_UNIT_READY, UQ_MATCH_VENDOR_ONLY),
515 	USB_QUIRK(APPLE, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY),
516 	USB_QUIRK(FEIYA, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY),
517 	USB_QUIRK(REALTEK, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY),
518 	USB_QUIRK(INITIO, DUMMY, 0x0000, 0xffff, UQ_MSC_NO_SYNC_CACHE, UQ_MATCH_VENDOR_ONLY),
519 
520 	/* DYMO LabelManager Pnp */
521 	USB_QUIRK(DYMO, LABELMANAGERPNP, 0x0000, 0xffff, UQ_MSC_DYMO_EJECT),
522 
523 	/* Holtek USB gaming keyboard */
524 	USB_QUIRK(HOLTEK, F85, 0x0000, 0xffff, UQ_KBD_BOOTPROTO),
525 };
526 #undef USB_QUIRK_VP
527 #undef USB_QUIRK
528 
529 static const char *usb_quirk_str[USB_QUIRK_MAX] = {
530 	[UQ_NONE]		= "UQ_NONE",
531 	[UQ_MATCH_VENDOR_ONLY]	= "UQ_MATCH_VENDOR_ONLY",
532 	[UQ_AUDIO_SWAP_LR]	= "UQ_AUDIO_SWAP_LR",
533 	[UQ_AU_INP_ASYNC]	= "UQ_AU_INP_ASYNC",
534 	[UQ_AU_NO_FRAC]		= "UQ_AU_NO_FRAC",
535 	[UQ_AU_NO_XU]		= "UQ_AU_NO_XU",
536 	[UQ_BAD_ADC]		= "UQ_BAD_ADC",
537 	[UQ_BAD_AUDIO]		= "UQ_BAD_AUDIO",
538 	[UQ_BROKEN_BIDIR]	= "UQ_BROKEN_BIDIR",
539 	[UQ_BUS_POWERED]	= "UQ_BUS_POWERED",
540 	[UQ_HID_IGNORE]		= "UQ_HID_IGNORE",
541 	[UQ_KBD_IGNORE]		= "UQ_KBD_IGNORE",
542 	[UQ_KBD_BOOTPROTO]	= "UQ_KBD_BOOTPROTO",
543 	[UQ_UMS_IGNORE]		= "UQ_UMS_IGNORE",
544 	[UQ_MS_BAD_CLASS]	= "UQ_MS_BAD_CLASS",
545 	[UQ_MS_LEADING_BYTE]	= "UQ_MS_LEADING_BYTE",
546 	[UQ_MS_REVZ]		= "UQ_MS_REVZ",
547 	[UQ_NO_STRINGS]		= "UQ_NO_STRINGS",
548 	[UQ_POWER_CLAIM]	= "UQ_POWER_CLAIM",
549 	[UQ_SPUR_BUT_UP]	= "UQ_SPUR_BUT_UP",
550 	[UQ_SWAP_UNICODE]	= "UQ_SWAP_UNICODE",
551 	[UQ_CFG_INDEX_1]	= "UQ_CFG_INDEX_1",
552 	[UQ_CFG_INDEX_2]	= "UQ_CFG_INDEX_2",
553 	[UQ_CFG_INDEX_3]	= "UQ_CFG_INDEX_3",
554 	[UQ_CFG_INDEX_4]	= "UQ_CFG_INDEX_4",
555 	[UQ_CFG_INDEX_0]	= "UQ_CFG_INDEX_0",
556 	[UQ_ASSUME_CM_OVER_DATA]	= "UQ_ASSUME_CM_OVER_DATA",
557 	[UQ_MSC_NO_TEST_UNIT_READY]	= "UQ_MSC_NO_TEST_UNIT_READY",
558 	[UQ_MSC_NO_RS_CLEAR_UA]		= "UQ_MSC_NO_RS_CLEAR_UA",
559 	[UQ_MSC_NO_START_STOP]		= "UQ_MSC_NO_START_STOP",
560 	[UQ_MSC_NO_GETMAXLUN]		= "UQ_MSC_NO_GETMAXLUN",
561 	[UQ_MSC_NO_INQUIRY]		= "UQ_MSC_NO_INQUIRY",
562 	[UQ_MSC_NO_INQUIRY_EVPD]	= "UQ_MSC_NO_INQUIRY_EVPD",
563 	[UQ_MSC_NO_PREVENT_ALLOW]	= "UQ_MSC_NO_PREVENT_ALLOW",
564 	[UQ_MSC_NO_SYNC_CACHE]		= "UQ_MSC_NO_SYNC_CACHE",
565 	[UQ_MSC_SHUTTLE_INIT]		= "UQ_MSC_SHUTTLE_INIT",
566 	[UQ_MSC_ALT_IFACE_1]		= "UQ_MSC_ALT_IFACE_1",
567 	[UQ_MSC_FLOPPY_SPEED]		= "UQ_MSC_FLOPPY_SPEED",
568 	[UQ_MSC_IGNORE_RESIDUE]		= "UQ_MSC_IGNORE_RESIDUE",
569 	[UQ_MSC_WRONG_CSWSIG]		= "UQ_MSC_WRONG_CSWSIG",
570 	[UQ_MSC_RBC_PAD_TO_12]		= "UQ_MSC_RBC_PAD_TO_12",
571 	[UQ_MSC_READ_CAP_OFFBY1]	= "UQ_MSC_READ_CAP_OFFBY1",
572 	[UQ_MSC_FORCE_SHORT_INQ]	= "UQ_MSC_FORCE_SHORT_INQ",
573 	[UQ_MSC_FORCE_WIRE_BBB]		= "UQ_MSC_FORCE_WIRE_BBB",
574 	[UQ_MSC_FORCE_WIRE_CBI]		= "UQ_MSC_FORCE_WIRE_CBI",
575 	[UQ_MSC_FORCE_WIRE_CBI_I]	= "UQ_MSC_FORCE_WIRE_CBI_I",
576 	[UQ_MSC_FORCE_PROTO_SCSI]	= "UQ_MSC_FORCE_PROTO_SCSI",
577 	[UQ_MSC_FORCE_PROTO_ATAPI]	= "UQ_MSC_FORCE_PROTO_ATAPI",
578 	[UQ_MSC_FORCE_PROTO_UFI]	= "UQ_MSC_FORCE_PROTO_UFI",
579 	[UQ_MSC_FORCE_PROTO_RBC]	= "UQ_MSC_FORCE_PROTO_RBC",
580 	[UQ_MSC_EJECT_HUAWEI]		= "UQ_MSC_EJECT_HUAWEI",
581 	[UQ_MSC_EJECT_SIERRA]		= "UQ_MSC_EJECT_SIERRA",
582 	[UQ_MSC_EJECT_SCSIEJECT]	= "UQ_MSC_EJECT_SCSIEJECT",
583 	[UQ_MSC_EJECT_REZERO]		= "UQ_MSC_EJECT_REZERO",
584 	[UQ_MSC_EJECT_ZTESTOR]		= "UQ_MSC_EJECT_ZTESTOR",
585 	[UQ_MSC_EJECT_CMOTECH]		= "UQ_MSC_EJECT_CMOTECH",
586 	[UQ_MSC_EJECT_WAIT]		= "UQ_MSC_EJECT_WAIT",
587 	[UQ_MSC_EJECT_SAEL_M460]	= "UQ_MSC_EJECT_SAEL_M460",
588 	[UQ_MSC_EJECT_HUAWEISCSI]	= "UQ_MSC_EJECT_HUAWEISCSI",
589 	[UQ_MSC_EJECT_HUAWEISCSI2]	= "UQ_MSC_EJECT_HUAWEISCSI2",
590 	[UQ_MSC_EJECT_HUAWEISCSI3]	= "UQ_MSC_EJECT_HUAWEISCSI3",
591 	[UQ_MSC_EJECT_TCT]		= "UQ_MSC_EJECT_TCT",
592 	[UQ_BAD_MIDI]			= "UQ_BAD_MIDI",
593 	[UQ_AU_VENDOR_CLASS]		= "UQ_AU_VENDOR_CLASS",
594 	[UQ_SINGLE_CMD_MIDI]		= "UQ_SINGLE_CMD_MIDI",
595 };
596 
597 /*------------------------------------------------------------------------*
598  *	usb_quirkstr
599  *
600  * This function converts an USB quirk code into a string.
601  *------------------------------------------------------------------------*/
602 static const char *
usb_quirkstr(uint16_t quirk)603 usb_quirkstr(uint16_t quirk)
604 {
605 	return ((quirk < USB_QUIRK_MAX) ?
606 		usb_quirk_str[quirk] : "USB_QUIRK_UNKNOWN");
607 }
608 
609 /*------------------------------------------------------------------------*
610  *	usb_test_quirk_by_info
611  *
612  * Returns:
613  * 0: Quirk not found
614  * Else: Quirk found
615  *------------------------------------------------------------------------*/
616 static uint8_t
usb_test_quirk_by_info(const struct usbd_lookup_info * info,uint16_t quirk)617 usb_test_quirk_by_info(const struct usbd_lookup_info *info, uint16_t quirk)
618 {
619 	uint16_t x;
620 	uint16_t y;
621 
622 	if (quirk == UQ_NONE)
623 		goto done;
624 
625 	mtx_lock(&usb_quirk_mtx);
626 
627 	for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
628 		/* see if quirk information does not match */
629 		if ((usb_quirks[x].vid != info->idVendor) ||
630 		    (usb_quirks[x].lo_rev > info->bcdDevice) ||
631 		    (usb_quirks[x].hi_rev < info->bcdDevice)) {
632 			continue;
633 		}
634 		/* see if quirk only should match vendor ID */
635 		if (usb_quirks[x].pid != info->idProduct) {
636 			if (usb_quirks[x].pid != 0)
637 				continue;
638 
639 			for (y = 0; y != USB_SUB_QUIRKS_MAX; y++) {
640 				if (usb_quirks[x].quirks[y] == UQ_MATCH_VENDOR_ONLY)
641 					break;
642 			}
643 			if (y == USB_SUB_QUIRKS_MAX)
644 				continue;
645 		}
646 		/* lookup quirk */
647 		for (y = 0; y != USB_SUB_QUIRKS_MAX; y++) {
648 			if (usb_quirks[x].quirks[y] == quirk) {
649 				mtx_unlock(&usb_quirk_mtx);
650 				DPRINTF("Found quirk '%s'.\n", usb_quirkstr(quirk));
651 				return (1);
652 			}
653 		}
654 		/* no quirk found */
655 		break;
656 	}
657 	mtx_unlock(&usb_quirk_mtx);
658 done:
659 	return (0);			/* no quirk match */
660 }
661 
662 static struct usb_quirk_entry *
usb_quirk_get_entry(uint16_t vid,uint16_t pid,uint16_t lo_rev,uint16_t hi_rev,uint8_t do_alloc)663 usb_quirk_get_entry(uint16_t vid, uint16_t pid,
664     uint16_t lo_rev, uint16_t hi_rev, uint8_t do_alloc)
665 {
666 	uint16_t x;
667 
668 	mtx_assert(&usb_quirk_mtx, MA_OWNED);
669 
670 	if ((vid | pid | lo_rev | hi_rev) == 0) {
671 		/* all zero - special case */
672 		return (usb_quirks + USB_DEV_QUIRKS_MAX - 1);
673 	}
674 	/* search for an existing entry */
675 	for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
676 		/* see if quirk information does not match */
677 		if ((usb_quirks[x].vid != vid) ||
678 		    (usb_quirks[x].pid != pid) ||
679 		    (usb_quirks[x].lo_rev != lo_rev) ||
680 		    (usb_quirks[x].hi_rev != hi_rev)) {
681 			continue;
682 		}
683 		return (usb_quirks + x);
684 	}
685 
686 	if (do_alloc == 0) {
687 		/* no match */
688 		return (NULL);
689 	}
690 	/* search for a free entry */
691 	for (x = 0; x != USB_DEV_QUIRKS_MAX; x++) {
692 		/* see if quirk information does not match */
693 		if ((usb_quirks[x].vid |
694 		    usb_quirks[x].pid |
695 		    usb_quirks[x].lo_rev |
696 		    usb_quirks[x].hi_rev) != 0) {
697 			continue;
698 		}
699 		usb_quirks[x].vid = vid;
700 		usb_quirks[x].pid = pid;
701 		usb_quirks[x].lo_rev = lo_rev;
702 		usb_quirks[x].hi_rev = hi_rev;
703 
704 		return (usb_quirks + x);
705 	}
706 
707 	/* no entry found */
708 	return (NULL);
709 }
710 
711 /*------------------------------------------------------------------------*
712  *	usb_quirk_ioctl - handle quirk IOCTLs
713  *
714  * Returns:
715  * 0: Success
716  * Else: Failure
717  *------------------------------------------------------------------------*/
718 static int
usb_quirk_ioctl(unsigned long cmd,caddr_t data,int fflag,struct thread * td)719 usb_quirk_ioctl(unsigned long cmd, caddr_t data,
720     int fflag, struct thread *td)
721 {
722 	struct usb_gen_quirk *pgq;
723 	struct usb_quirk_entry *pqe;
724 	uint32_t x;
725 	uint32_t y;
726 	int err;
727 
728 	(void)td;
729 
730 	switch (cmd) {
731 	case USB_DEV_QUIRK_GET:
732 		pgq = (void *)data;
733 		x = pgq->index % USB_SUB_QUIRKS_MAX;
734 		y = pgq->index / USB_SUB_QUIRKS_MAX;
735 		if (y >= USB_DEV_QUIRKS_MAX) {
736 			return (EINVAL);
737 		}
738 		mtx_lock(&usb_quirk_mtx);
739 		/* copy out data */
740 		pgq->vid = usb_quirks[y].vid;
741 		pgq->pid = usb_quirks[y].pid;
742 		pgq->bcdDeviceLow = usb_quirks[y].lo_rev;
743 		pgq->bcdDeviceHigh = usb_quirks[y].hi_rev;
744 		(void)strlcpy(pgq->quirkname,
745 		    usb_quirkstr(usb_quirks[y].quirks[x]),
746 		    sizeof(pgq->quirkname));
747 		mtx_unlock(&usb_quirk_mtx);
748 		return (0);		/* success */
749 
750 	case USB_QUIRK_NAME_GET:
751 		pgq = (void *)data;
752 		x = pgq->index;
753 		if (x >= USB_QUIRK_MAX) {
754 			return (EINVAL);
755 		}
756 		(void)strlcpy(pgq->quirkname,
757 		    usb_quirkstr(x), sizeof(pgq->quirkname));
758 		return (0);		/* success */
759 
760 	case USB_DEV_QUIRK_ADD:
761 		pgq = (void *)data;
762 
763 		/* check privileges */
764 		err = priv_check(curthread, PRIV_DRIVER);
765 		if (err) {
766 			return (err);
767 		}
768 		/* convert quirk string into numerical */
769 		for (y = 0; y != USB_DEV_QUIRKS_MAX; y++) {
770 			if (strcmp(pgq->quirkname, usb_quirkstr(y)) == 0) {
771 				break;
772 			}
773 		}
774 		if (y == USB_DEV_QUIRKS_MAX) {
775 			return (EINVAL);
776 		}
777 		if (y == UQ_NONE) {
778 			return (EINVAL);
779 		}
780 		mtx_lock(&usb_quirk_mtx);
781 		pqe = usb_quirk_get_entry(pgq->vid, pgq->pid,
782 		    pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 1);
783 		if (pqe == NULL) {
784 			mtx_unlock(&usb_quirk_mtx);
785 			return (EINVAL);
786 		}
787 		for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
788 			if (pqe->quirks[x] == UQ_NONE) {
789 				pqe->quirks[x] = y;
790 				break;
791 			}
792 		}
793 		mtx_unlock(&usb_quirk_mtx);
794 		if (x == USB_SUB_QUIRKS_MAX) {
795 			return (ENOMEM);
796 		}
797 		return (0);		/* success */
798 
799 	case USB_DEV_QUIRK_REMOVE:
800 		pgq = (void *)data;
801 		/* check privileges */
802 		err = priv_check(curthread, PRIV_DRIVER);
803 		if (err) {
804 			return (err);
805 		}
806 		/* convert quirk string into numerical */
807 		for (y = 0; y != USB_DEV_QUIRKS_MAX; y++) {
808 			if (strcmp(pgq->quirkname, usb_quirkstr(y)) == 0) {
809 				break;
810 			}
811 		}
812 		if (y == USB_DEV_QUIRKS_MAX) {
813 			return (EINVAL);
814 		}
815 		if (y == UQ_NONE) {
816 			return (EINVAL);
817 		}
818 		mtx_lock(&usb_quirk_mtx);
819 		pqe = usb_quirk_get_entry(pgq->vid, pgq->pid,
820 		    pgq->bcdDeviceLow, pgq->bcdDeviceHigh, 0);
821 		if (pqe == NULL) {
822 			mtx_unlock(&usb_quirk_mtx);
823 			return (EINVAL);
824 		}
825 		for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
826 			if (pqe->quirks[x] == y) {
827 				pqe->quirks[x] = UQ_NONE;
828 				break;
829 			}
830 		}
831 		if (x == USB_SUB_QUIRKS_MAX) {
832 			mtx_unlock(&usb_quirk_mtx);
833 			return (ENOMEM);
834 		}
835 		for (x = 0; x != USB_SUB_QUIRKS_MAX; x++) {
836 			if (pqe->quirks[x] != UQ_NONE) {
837 				break;
838 			}
839 		}
840 		if (x == USB_SUB_QUIRKS_MAX) {
841 			/* all quirk entries are unused - release */
842 			(void)memset_s(pqe, sizeof(*pqe), 0, sizeof(*pqe));
843 		}
844 		mtx_unlock(&usb_quirk_mtx);
845 		return (0);		/* success */
846 
847 	default:
848 		break;
849 	}
850 	return (ENOIOCTL);
851 }
852 
853 void
usb_quirk_init(void * arg)854 usb_quirk_init(void *arg)
855 {
856 	/* initialize mutex */
857 	mtx_init(&usb_quirk_mtx, "USB quirk", NULL, MTX_DEF);
858 
859 	/* register our function */
860 	usb_test_quirk_p = &usb_test_quirk_by_info;
861 	usb_quirk_ioctl_p = &usb_quirk_ioctl;
862 }
863 
864