umass_quirks.c revision 1.64.2.1 1 /* $NetBSD: umass_quirks.c,v 1.64.2.1 2004/06/30 20:15:00 jdc Exp $ */
2
3 /*
4 * Copyright (c) 2001 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 (at) NetBSD.org).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: umass_quirks.c,v 1.64.2.1 2004/06/30 20:15:00 jdc Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/buf.h>
46
47 #include <dev/scsipi/scsipi_all.h> /* for scsiconf.h below */
48 #include <dev/scsipi/scsiconf.h> /* for quirks defines */
49
50 #include <dev/usb/usb.h>
51 #include <dev/usb/usbdi.h>
52 #include <dev/usb/usbdevs.h>
53
54 #include <dev/usb/umassvar.h>
55 #include <dev/usb/umass_quirks.h>
56
57 Static usbd_status umass_init_insystem(struct umass_softc *);
58 Static usbd_status umass_init_shuttle(struct umass_softc *);
59
60 Static void umass_fixup_sony(struct umass_softc *);
61
62 Static const struct umass_quirk umass_quirks[] = {
63 /*
64 * The following 3 In-System Design adapters use a non-standard ATA
65 * over BBB protocol. Force this protocol by quirk entries.
66 */
67 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ADAPTERV2 },
68 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
69 0,
70 0,
71 UMATCH_VENDOR_PRODUCT,
72 NULL, NULL
73 },
74 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_ATAPI },
75 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
76 0,
77 0,
78 UMATCH_VENDOR_PRODUCT,
79 NULL, NULL
80 },
81 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_DRIVEV2_5 },
82 UMASS_WPROTO_BBB, UMASS_CPROTO_ISD_ATA,
83 0,
84 0,
85 UMATCH_VENDOR_PRODUCT,
86 NULL, NULL
87 },
88
89 { { USB_VENDOR_INSYSTEM, USB_PRODUCT_INSYSTEM_USBCABLE },
90 UMASS_WPROTO_CBI, UMASS_CPROTO_ATAPI,
91 0,
92 0,
93 UMATCH_VENDOR_PRODUCT,
94 umass_init_insystem, NULL
95 },
96
97 { { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_EUSB },
98 UMASS_WPROTO_CBI_I, UMASS_CPROTO_ATAPI,
99 0,
100 0,
101 UMATCH_VENDOR_PRODUCT,
102 umass_init_shuttle, NULL
103 },
104
105 /*
106 * These work around genuine device bugs -- returning the wrong info in
107 * the CSW block.
108 */
109 { { USB_VENDOR_OLYMPUS, USB_PRODUCT_OLYMPUS_C1 },
110 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
111 UMASS_QUIRK_WRONG_CSWSIG,
112 0,
113 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
114 NULL, NULL
115 },
116 { { USB_VENDOR_SCANLOGIC, USB_PRODUCT_SCANLOGIC_SL11R },
117 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
118 UMASS_QUIRK_WRONG_CSWTAG,
119 0,
120 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
121 NULL, NULL
122 },
123 { { USB_VENDOR_SHUTTLE, USB_PRODUCT_SHUTTLE_ORCA },
124 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
125 UMASS_QUIRK_WRONG_CSWTAG,
126 0,
127 UMATCH_VENDOR_PRODUCT,
128 NULL, NULL
129 },
130
131 /*
132 * Some Sony cameras advertise a subclass code of 0xff, so we force it
133 * to the correct value iff necessary.
134 */
135 { { USB_VENDOR_SONY, USB_PRODUCT_SONY_DSC },
136 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
137 0,
138 0,
139 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
140 NULL, umass_fixup_sony
141 },
142
143 /*
144 * Stupid device reports itself as SFF-8070, but actually returns a UFI
145 * interrupt descriptor. - mycroft, 2004/06/28
146 */
147 { { USB_VENDOR_SONY, USB_PRODUCT_SONY_CLIE_40_MS },
148 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UFI,
149 0,
150 0,
151 UMATCH_VENDOR_PRODUCT,
152 NULL, NULL
153 },
154
155 /*
156 * The DiskOnKey does not reject commands it doesn't recognize in a
157 * sane way -- rather than STALLing the bulk pipe, it continually NAKs
158 * until we time out. To prevent being screwed by this, for now we
159 * disable 10-byte MODE SENSE the klugy way. - mycroft, 2003/10/16
160 */
161 { { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY },
162 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
163 0,
164 PQUIRK_NOBIGMODESENSE,
165 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
166 NULL, NULL
167 },
168 { { USB_VENDOR_MSYSTEMS, USB_PRODUCT_MSYSTEMS_DISKONKEY2 },
169 UMASS_WPROTO_UNSPEC, UMASS_CPROTO_UNSPEC,
170 0,
171 PQUIRK_NOBIGMODESENSE,
172 UMATCH_DEVCLASS_DEVSUBCLASS_DEVPROTO,
173 NULL, NULL
174 },
175 };
176
177 const struct umass_quirk *
178 umass_lookup(u_int16_t vendor, u_int16_t product)
179 {
180 return ((const struct umass_quirk *)
181 usb_lookup(umass_quirks, vendor, product));
182 }
183
184 Static usbd_status
185 umass_init_insystem(struct umass_softc *sc)
186 {
187 usbd_status err;
188
189 err = usbd_set_interface(sc->sc_iface, 1);
190 if (err) {
191 DPRINTF(UDMASS_USB,
192 ("%s: could not switch to Alt Interface 1\n",
193 USBDEVNAME(sc->sc_dev)));
194 return (err);
195 }
196
197 return (USBD_NORMAL_COMPLETION);
198 }
199
200 Static usbd_status
201 umass_init_shuttle(struct umass_softc *sc)
202 {
203 usb_device_request_t req;
204 u_int8_t status[2];
205
206 /* The Linux driver does this */
207 req.bmRequestType = UT_READ_VENDOR_DEVICE;
208 req.bRequest = 1;
209 USETW(req.wValue, 0);
210 USETW(req.wIndex, sc->sc_ifaceno);
211 USETW(req.wLength, sizeof(status));
212
213 return (usbd_do_request(sc->sc_udev, &req, &status));
214 }
215
216 Static void
217 umass_fixup_sony(struct umass_softc *sc)
218 {
219 usb_interface_descriptor_t *id;
220
221 id = usbd_get_interface_descriptor(sc->sc_iface);
222 if (id->bInterfaceSubClass == 0xff)
223 sc->sc_cmd = UMASS_CPROTO_SCSI;
224 }
225