xref: /netbsd-src/sys/dev/usb/umass_quirks.c (revision 8ac07aec990b9d2e483062509d0a9fa5b4f57cf2)
1 /*	$NetBSD: umass_quirks.c,v 1.72 2008/01/21 11:36:47 ichiro Exp $	*/
2 
3 /*
4  * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by MAEKAWA Masahide (gehenna@NetBSD.org).
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Charles M. Hannum.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	  This product includes software developed by the NetBSD
23  *	  Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: umass_quirks.c,v 1.72 2008/01/21 11:36:47 ichiro Exp $");
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <sys/buf.h>
48 
49 #include <dev/scsipi/scsipi_all.h> /* for scsiconf.h below */
50 #include <dev/scsipi/scsiconf.h> /* for quirks defines */
51 
52 #include <dev/usb/usb.h>
53 #include <dev/usb/usbdi.h>
54 #include <dev/usb/usbdevs.h>
55 
56 #include <dev/usb/umassvar.h>
57 #include <dev/usb/umass_quirks.h>
58 
59 Static usbd_status umass_init_insystem(struct umass_softc *);
60 Static usbd_status umass_init_shuttle(struct umass_softc *);
61 Static usbd_status umass_init_e220(struct umass_softc *);
62 
63 Static void umass_fixup_sony(struct umass_softc *);
64 
65 /*
66  * XXX
67  * PLEASE NOTE that if you want quirk entries added to this table, you MUST
68  * compile a kernel with USB_DEBUG, and submit a full log of the output from
69  * whatever operation is "failing" with ?hcidebug=20 or higher and
70  * umassdebug=0xffffff.  (It's usually helpful to also set MSGBUFSIZE to
71  * something "large" unless you're using a serial console.)  Without this
72  * information, the source of the problem cannot be properly analyzed, and
73  * the quirk entry WILL NOT be accepted.
74  * Also, when an entry is committed to this table, a concise but clear
75  * description of the problem MUST accompany it.
76  * - mycroft
77  */
78 Static const struct umass_quirk umass_quirks[] = {
79 	/*
80 	 * The following 3 In-System Design adapters use a non-standard ATA
81 	 * over BBB protocol.  Force this protocol by quirk entries.
82 	 */
83 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
84 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
85 	  0,
86 	  0,
87 	  UMATCH_VENDOR_PRODUCT,
88 	  NULL, NULL
89 	},
90 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
91 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
92 	  0,
93 	  0,
94 	  UMATCH_VENDOR_PRODUCT,
95 	  NULL, NULL
96 	},
97 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
98 	  UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
99 	  0,
100 	  0,
101 	  UMATCH_VENDOR_PRODUCT,
102 	  NULL, NULL
103 	},
104 
105 	{ { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
106 	  UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
107 	  0,
108 	  0,
109 	  UMATCH_VENDOR_PRODUCT,
110 	  umass_init_insystem, NULL
111 	},
112 
113 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
114 	  UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
115 	  0,
116 	  0,
117 	  UMATCH_VENDOR_PRODUCT,
118 	  umass_init_shuttle, NULL
119 	},
120 
121 	/*
122 	 * These work around genuine device bugs -- returning the wrong info in
123 	 * the CSW block.
124 	 */
125 	{ { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
126 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
127 	  UMASS_QUIRK_WRONG_CSWSIG,
128 	  0,
129 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
130 	  NULL, NULL
131 	},
132 	{ { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
133 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
134 	  UMASS_QUIRK_WRONG_CSWTAG,
135 	  0,
136 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
137 	  NULL, NULL
138 	},
139 	{ { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA },
140 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
141 	  UMASS_QUIRK_WRONG_CSWTAG,
142 	  0,
143 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
144 	  NULL, NULL
145 	},
146 
147 	/*
148 	 * Some Sony cameras advertise a subclass code of 0xff, so we force it
149 	 * to the correct value iff necessary.
150 	 */
151 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC },
152 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
153 	  UMASS_QUIRK_RBC_PAD_TO_12,
154 	  0,
155 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
156 	  NULL, umass_fixup_sony
157 	},
158 
159 	/*
160 	 * Stupid device reports itself as SFF-8070, but actually returns a UFI
161 	 * interrupt descriptor.  - mycroft, 2004/06/28
162 	 */
163 	{ { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS },
164 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
165 	  0,
166 	  0,
167 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
168 	  NULL, NULL
169 	},
170 
171 	/*
172 	 * The DiskOnKey does not reject commands it doesn't recognize in a
173 	 * sane way -- rather than STALLing the bulk pipe, it continually NAKs
174 	 * until we time out.  To prevent being screwed by this, for now we
175 	 * disable 10-byte MODE SENSE the klugy way.  - mycroft, 2003/10/16
176 	 */
177 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY },
178 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
179 	  0,
180 	  PQUIRK_NOBIGMODESENSE,
181 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
182 	  NULL, NULL
183 	},
184 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 },
185 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
186 	  0,
187 	  PQUIRK_NOBIGMODESENSE,
188 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
189 	  NULL, NULL
190 	},
191 	{ { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY3 },
192 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
193 	  0,
194 	  PQUIRK_NOBIGMODESENSE,
195 	  UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
196 	  NULL, NULL
197 	},
198 	{ { USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 },
199 	  UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
200 	  0,
201 	  0,
202 	  UMASS_QUIRK_USE_DEFAULTMATCH, /* use default MATCH function */
203 	  umass_init_e220, NULL
204 	},
205 };
206 
207 const struct umass_quirk *
208 umass_lookup(u_int16_t vendor, u_int16_t product)
209 {
210 	return ((const struct umass_quirk *)
211 		usb_lookup(umass_quirks, vendor, product));
212 }
213 
214 Static usbd_status
215 umass_init_insystem(struct umass_softc *sc)
216 {
217 	usbd_status err;
218 
219 	err = usbd_set_interface(sc->sc_iface, 1);
220 	if (err) {
221 		DPRINTF(UDMASS_USB,
222 			("%s: could not switch to Alt Interface 1\n",
223 			USBDEVNAME(sc->sc_dev)));
224 		return (err);
225 	}
226 
227 	return (USBD_NORMAL_COMPLETION);
228 }
229 
230 Static usbd_status
231 umass_init_shuttle(struct umass_softc *sc)
232 {
233 	usb_device_request_t req;
234 	u_int8_t status[2];
235 
236 	/* The Linux driver does this */
237 	req.bmRequestType = UT_READ_VENDOR_DEVICE;
238 	req.bRequest = 1;
239 	USETW(req.wValue, 0);
240 	USETW(req.wIndex, sc->sc_ifaceno);
241 	USETW(req.wLength, sizeof(status));
242 
243 	return (usbd_do_request(sc->sc_udev, &req, &status));
244 }
245 
246 Static void
247 umass_fixup_sony(struct umass_softc *sc)
248 {
249 	usb_interface_descriptor_t *id;
250 
251 	id = usbd_get_interface_descriptor(sc->sc_iface);
252 	if (id->bInterfaceSubClass == 0xff)
253 		sc->sc_cmd = UMASS_CPROTO_RBC;
254 }
255 
256 Static usbd_status
257 umass_init_e220(struct umass_softc *sc)
258 {
259 #define E220_UMASS_INTERFACE 2
260 	usbd_status err;
261 
262 	if (sc->sc_ifaceno != E220_UMASS_INTERFACE)
263 		return (USBD_NOT_CONFIGURED);
264 
265 	err = usbd_device2interface_handle(sc->sc_udev, sc->sc_ifaceno, &sc->sc_iface);
266 	if (err) {
267 		DPRINTF(UDMASS_USB,
268 			("%s: could not switch to Alt Interface %d\n",
269 			USBDEVNAME(sc->sc_dev), sc->sc_ifaceno));
270 		return (err);
271 	}
272 
273 	return (USBD_NORMAL_COMPLETION);
274 #undef E220_UMASS_INTERFACE
275 }
276