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