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