xref: /freebsd/sys/dev/usb/serial/u3g.c (revision d840e1d24870f2aa5e16f826d03d86027ecd06fb)
102ac6454SAndrew Thompson /*
202ac6454SAndrew Thompson  * Copyright (c) 2008 AnyWi Technologies
302ac6454SAndrew Thompson  * Author: Andrea Guzzo <aguzzo@anywi.com>
402ac6454SAndrew Thompson  * * based on uark.c 1.1 2006/08/14 08:30:22 jsg *
502ac6454SAndrew Thompson  * * parts from ubsa.c 183348 2008-09-25 12:00:56Z phk *
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * Permission to use, copy, modify, and distribute this software for any
802ac6454SAndrew Thompson  * purpose with or without fee is hereby granted, provided that the above
902ac6454SAndrew Thompson  * copyright notice and this permission notice appear in all copies.
1002ac6454SAndrew Thompson  *
1102ac6454SAndrew Thompson  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1202ac6454SAndrew Thompson  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1302ac6454SAndrew Thompson  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1402ac6454SAndrew Thompson  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1502ac6454SAndrew Thompson  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1602ac6454SAndrew Thompson  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1702ac6454SAndrew Thompson  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1802ac6454SAndrew Thompson  *
1902ac6454SAndrew Thompson  * $FreeBSD$
2002ac6454SAndrew Thompson  */
2102ac6454SAndrew Thompson 
2202ac6454SAndrew Thompson /*
2302ac6454SAndrew Thompson  * NOTE:
2402ac6454SAndrew Thompson  *
2502ac6454SAndrew Thompson  * - The detour through the tty layer is ridiculously expensive wrt
2602ac6454SAndrew Thompson  *   buffering due to the high speeds.
2702ac6454SAndrew Thompson  *
2802ac6454SAndrew Thompson  *   We should consider adding a simple r/w device which allows
2902ac6454SAndrew Thompson  *   attaching of PPP in a more efficient way.
3002ac6454SAndrew Thompson  *
3102ac6454SAndrew Thompson  */
3202ac6454SAndrew Thompson 
33ed6d949aSAndrew Thompson 
34ed6d949aSAndrew Thompson #include <sys/stdint.h>
35ed6d949aSAndrew Thompson #include <sys/stddef.h>
36ed6d949aSAndrew Thompson #include <sys/param.h>
37ed6d949aSAndrew Thompson #include <sys/queue.h>
38ed6d949aSAndrew Thompson #include <sys/types.h>
39ed6d949aSAndrew Thompson #include <sys/systm.h>
40ed6d949aSAndrew Thompson #include <sys/kernel.h>
41ed6d949aSAndrew Thompson #include <sys/bus.h>
42ed6d949aSAndrew Thompson #include <sys/module.h>
43ed6d949aSAndrew Thompson #include <sys/lock.h>
44ed6d949aSAndrew Thompson #include <sys/mutex.h>
45ed6d949aSAndrew Thompson #include <sys/condvar.h>
46ed6d949aSAndrew Thompson #include <sys/sysctl.h>
47ed6d949aSAndrew Thompson #include <sys/sx.h>
48ed6d949aSAndrew Thompson #include <sys/unistd.h>
49ed6d949aSAndrew Thompson #include <sys/callout.h>
50ed6d949aSAndrew Thompson #include <sys/malloc.h>
51ed6d949aSAndrew Thompson #include <sys/priv.h>
52ed6d949aSAndrew Thompson 
5302ac6454SAndrew Thompson #include <dev/usb/usb.h>
54ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h>
55ed6d949aSAndrew Thompson #include <dev/usb/usbdi_util.h>
56ed6d949aSAndrew Thompson #include "usbdevs.h"
5702ac6454SAndrew Thompson 
5802ac6454SAndrew Thompson #define	USB_DEBUG_VAR u3g_debug
5902ac6454SAndrew Thompson #include <dev/usb/usb_debug.h>
6002ac6454SAndrew Thompson #include <dev/usb/usb_process.h>
61ed6d949aSAndrew Thompson #include <dev/usb/usb_msctest.h>
6202ac6454SAndrew Thompson 
6302ac6454SAndrew Thompson #include <dev/usb/serial/usb_serial.h>
64e7702e9eSNick Hibma #include <dev/usb/quirk/usb_quirk.h>
6502ac6454SAndrew Thompson 
66b850ecc1SAndrew Thompson #ifdef USB_DEBUG
6702ac6454SAndrew Thompson static int u3g_debug = 0;
6802ac6454SAndrew Thompson 
699360ae40SAndrew Thompson SYSCTL_NODE(_hw_usb, OID_AUTO, u3g, CTLFLAG_RW, 0, "USB 3g");
709360ae40SAndrew Thompson SYSCTL_INT(_hw_usb_u3g, OID_AUTO, debug, CTLFLAG_RW,
71750a2682SAndrew Thompson     &u3g_debug, 0, "Debug level");
7202ac6454SAndrew Thompson #endif
7302ac6454SAndrew Thompson 
746057aa35SAndrew Thompson #define	U3G_MAXPORTS		12
7502ac6454SAndrew Thompson #define	U3G_CONFIG_INDEX	0
7602ac6454SAndrew Thompson #define	U3G_BSIZE		2048
7702ac6454SAndrew Thompson 
7802ac6454SAndrew Thompson #define	U3GSP_GPRS		0
7902ac6454SAndrew Thompson #define	U3GSP_EDGE		1
8002ac6454SAndrew Thompson #define	U3GSP_CDMA		2
8102ac6454SAndrew Thompson #define	U3GSP_UMTS		3
8202ac6454SAndrew Thompson #define	U3GSP_HSDPA		4
8302ac6454SAndrew Thompson #define	U3GSP_HSUPA		5
8402ac6454SAndrew Thompson #define	U3GSP_HSPA		6
8502ac6454SAndrew Thompson #define	U3GSP_MAX		7
8602ac6454SAndrew Thompson 
87e7702e9eSNick Hibma /* Eject methods; See also usb_quirks.h:UQ_MSC_EJECT_* */
88d84a79e7SAndrew Thompson #define	U3GINIT_HUAWEI		1	/* Requires Huawei init command */
89d84a79e7SAndrew Thompson #define	U3GINIT_SIERRA		2	/* Requires Sierra init command */
90d84a79e7SAndrew Thompson #define	U3GINIT_SCSIEJECT	3	/* Requires SCSI eject command */
91d84a79e7SAndrew Thompson #define	U3GINIT_REZERO		4	/* Requires SCSI rezero command */
92d84a79e7SAndrew Thompson #define	U3GINIT_ZTESTOR		5	/* Requires ZTE SCSI command */
93d84a79e7SAndrew Thompson #define	U3GINIT_CMOTECH		6	/* Requires CMOTECH SCSI command */
94d84a79e7SAndrew Thompson #define	U3GINIT_WAIT		7	/* Device reappears after a delay */
95d84a79e7SAndrew Thompson #define	U3GINIT_SAEL_M460	8	/* Requires vendor init */
962386d714SAndrew Thompson #define	U3GINIT_HUAWEISCSI	9	/* Requires Huawei SCSI init command */
97fb7a4d49SGleb Smirnoff #define	U3GINIT_TCT		10	/* Requires TCT Mobile init command */
9802ac6454SAndrew Thompson 
9902ac6454SAndrew Thompson enum {
10002ac6454SAndrew Thompson 	U3G_BULK_WR,
10102ac6454SAndrew Thompson 	U3G_BULK_RD,
10202ac6454SAndrew Thompson 	U3G_N_TRANSFER,
10302ac6454SAndrew Thompson };
10402ac6454SAndrew Thompson 
10502ac6454SAndrew Thompson struct u3g_softc {
106760bc48eSAndrew Thompson 	struct ucom_super_softc sc_super_ucom;
107760bc48eSAndrew Thompson 	struct ucom_softc sc_ucom[U3G_MAXPORTS];
10802ac6454SAndrew Thompson 
109760bc48eSAndrew Thompson 	struct usb_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER];
110760bc48eSAndrew Thompson 	struct usb_device *sc_udev;
111deefe583SAndrew Thompson 	struct mtx sc_mtx;
11202ac6454SAndrew Thompson 
11302ac6454SAndrew Thompson 	uint8_t	sc_lsr;			/* local status register */
11402ac6454SAndrew Thompson 	uint8_t	sc_msr;			/* U3G status register */
11502ac6454SAndrew Thompson 	uint8_t	sc_numports;
11602ac6454SAndrew Thompson };
11702ac6454SAndrew Thompson 
11802ac6454SAndrew Thompson static device_probe_t u3g_probe;
11902ac6454SAndrew Thompson static device_attach_t u3g_attach;
12002ac6454SAndrew Thompson static device_detach_t u3g_detach;
12102ac6454SAndrew Thompson 
122e0a69b51SAndrew Thompson static usb_callback_t u3g_write_callback;
123e0a69b51SAndrew Thompson static usb_callback_t u3g_read_callback;
12402ac6454SAndrew Thompson 
125760bc48eSAndrew Thompson static void u3g_start_read(struct ucom_softc *ucom);
126760bc48eSAndrew Thompson static void u3g_stop_read(struct ucom_softc *ucom);
127760bc48eSAndrew Thompson static void u3g_start_write(struct ucom_softc *ucom);
128760bc48eSAndrew Thompson static void u3g_stop_write(struct ucom_softc *ucom);
12902ac6454SAndrew Thompson 
1302a4c6157SAndrew Thompson 
1312a4c6157SAndrew Thompson static void u3g_test_autoinst(void *, struct usb_device *,
1322a4c6157SAndrew Thompson 		struct usb_attach_arg *);
13302ac6454SAndrew Thompson static int u3g_driver_loaded(struct module *mod, int what, void *arg);
13402ac6454SAndrew Thompson 
1352a4c6157SAndrew Thompson static eventhandler_tag u3g_etag;
1362a4c6157SAndrew Thompson 
137760bc48eSAndrew Thompson static const struct usb_config u3g_config[U3G_N_TRANSFER] = {
13802ac6454SAndrew Thompson 
13902ac6454SAndrew Thompson 	[U3G_BULK_WR] = {
14002ac6454SAndrew Thompson 		.type = UE_BULK,
14102ac6454SAndrew Thompson 		.endpoint = UE_ADDR_ANY,
14202ac6454SAndrew Thompson 		.direction = UE_DIR_OUT,
1434eae601eSAndrew Thompson 		.bufsize = U3G_BSIZE,/* bytes */
1444eae601eSAndrew Thompson 		.flags = {.pipe_bof = 1,.force_short_xfer = 1,},
1454eae601eSAndrew Thompson 		.callback = &u3g_write_callback,
14602ac6454SAndrew Thompson 	},
14702ac6454SAndrew Thompson 
14802ac6454SAndrew Thompson 	[U3G_BULK_RD] = {
14902ac6454SAndrew Thompson 		.type = UE_BULK,
15002ac6454SAndrew Thompson 		.endpoint = UE_ADDR_ANY,
15102ac6454SAndrew Thompson 		.direction = UE_DIR_IN,
1524eae601eSAndrew Thompson 		.bufsize = U3G_BSIZE,/* bytes */
1534eae601eSAndrew Thompson 		.flags = {.pipe_bof = 1,.short_xfer_ok = 1,},
1544eae601eSAndrew Thompson 		.callback = &u3g_read_callback,
15502ac6454SAndrew Thompson 	},
15602ac6454SAndrew Thompson };
15702ac6454SAndrew Thompson 
158760bc48eSAndrew Thompson static const struct ucom_callback u3g_callback = {
159a593f6b8SAndrew Thompson 	.ucom_start_read = &u3g_start_read,
160a593f6b8SAndrew Thompson 	.ucom_stop_read = &u3g_stop_read,
161a593f6b8SAndrew Thompson 	.ucom_start_write = &u3g_start_write,
162a593f6b8SAndrew Thompson 	.ucom_stop_write = &u3g_stop_write,
16302ac6454SAndrew Thompson };
16402ac6454SAndrew Thompson 
16502ac6454SAndrew Thompson static device_method_t u3g_methods[] = {
16602ac6454SAndrew Thompson 	DEVMETHOD(device_probe, u3g_probe),
16702ac6454SAndrew Thompson 	DEVMETHOD(device_attach, u3g_attach),
16802ac6454SAndrew Thompson 	DEVMETHOD(device_detach, u3g_detach),
16902ac6454SAndrew Thompson 	{0, 0}
17002ac6454SAndrew Thompson };
17102ac6454SAndrew Thompson 
17202ac6454SAndrew Thompson static devclass_t u3g_devclass;
17302ac6454SAndrew Thompson 
17402ac6454SAndrew Thompson static driver_t u3g_driver = {
17502ac6454SAndrew Thompson 	.name = "u3g",
17602ac6454SAndrew Thompson 	.methods = u3g_methods,
17702ac6454SAndrew Thompson 	.size = sizeof(struct u3g_softc),
17802ac6454SAndrew Thompson };
17902ac6454SAndrew Thompson 
1809aef556dSAndrew Thompson DRIVER_MODULE(u3g, uhub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0);
18102ac6454SAndrew Thompson MODULE_DEPEND(u3g, ucom, 1, 1, 1);
18202ac6454SAndrew Thompson MODULE_DEPEND(u3g, usb, 1, 1, 1);
183910cb8feSAndrew Thompson MODULE_VERSION(u3g, 1);
18402ac6454SAndrew Thompson 
185f1a16106SHans Petter Selasky static const STRUCT_USB_HOST_ID u3g_devs[] = {
186a173706bSAndrew Thompson #define	U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) }
187c0e2c178SAndrew Thompson 	U3G_DEV(ACERP, H10, 0),
188c0e2c178SAndrew Thompson 	U3G_DEV(AIRPLUS, MCD650, 0),
189c0e2c178SAndrew Thompson 	U3G_DEV(AIRPRIME, PC5220, 0),
190c0e2c178SAndrew Thompson 	U3G_DEV(ALINK, 3G, 0),
191c0e2c178SAndrew Thompson 	U3G_DEV(ALINK, 3GU, 0),
192c0e2c178SAndrew Thompson 	U3G_DEV(ALINK, DWM652U5, 0),
193c0e2c178SAndrew Thompson 	U3G_DEV(AMOI, H01, 0),
194c0e2c178SAndrew Thompson 	U3G_DEV(AMOI, H01A, 0),
195c0e2c178SAndrew Thompson 	U3G_DEV(AMOI, H02, 0),
196c0e2c178SAndrew Thompson 	U3G_DEV(ANYDATA, ADU_500A, 0),
197b340b7beSAndrew Thompson 	U3G_DEV(ANYDATA, ADU_620UW, 0),
198c0e2c178SAndrew Thompson 	U3G_DEV(ANYDATA, ADU_E100X, 0),
199c0e2c178SAndrew Thompson 	U3G_DEV(AXESSTEL, DATAMODEM, 0),
200c0e2c178SAndrew Thompson 	U3G_DEV(CMOTECH, CDMA_MODEM1, 0),
201d84a79e7SAndrew Thompson 	U3G_DEV(CMOTECH, CGU628, U3GINIT_CMOTECH),
202c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5500, 0),
203c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5505, 0),
204c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5510, 0),
205c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5520, 0),
206c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5520_2, 0),
207c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5520_3, 0),
208c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5700, 0),
209c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5700_2, 0),
210c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5700_3, 0),
211c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5700_4, 0),
212c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5720, 0),
213c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5720_2, 0),
214c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5730, 0),
215c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5730_2, 0),
216c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U5730_3, 0),
217c0e2c178SAndrew Thompson 	U3G_DEV(DELL, U740, 0),
218c0e2c178SAndrew Thompson 	U3G_DEV(DLINK3, DWM652, 0),
219c0e2c178SAndrew Thompson 	U3G_DEV(HP, EV2200, 0),
220c0e2c178SAndrew Thompson 	U3G_DEV(HP, HS2300, 0),
221d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1401, U3GINIT_HUAWEI),
222d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1402, U3GINIT_HUAWEI),
223d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1403, U3GINIT_HUAWEI),
224d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1404, U3GINIT_HUAWEI),
225d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1405, U3GINIT_HUAWEI),
226d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1406, U3GINIT_HUAWEI),
227d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1407, U3GINIT_HUAWEI),
228d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1408, U3GINIT_HUAWEI),
229d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1409, U3GINIT_HUAWEI),
230d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E140A, U3GINIT_HUAWEI),
231d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E140B, U3GINIT_HUAWEI),
232d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E140D, U3GINIT_HUAWEI),
233d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E140E, U3GINIT_HUAWEI),
234d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E140F, U3GINIT_HUAWEI),
235d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1410, U3GINIT_HUAWEI),
236d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1411, U3GINIT_HUAWEI),
237d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1412, U3GINIT_HUAWEI),
238d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1413, U3GINIT_HUAWEI),
239d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1414, U3GINIT_HUAWEI),
240d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1415, U3GINIT_HUAWEI),
241d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1416, U3GINIT_HUAWEI),
242d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1417, U3GINIT_HUAWEI),
243d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1418, U3GINIT_HUAWEI),
244d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1419, U3GINIT_HUAWEI),
245d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141A, U3GINIT_HUAWEI),
246d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141B, U3GINIT_HUAWEI),
247d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141C, U3GINIT_HUAWEI),
248d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141D, U3GINIT_HUAWEI),
249d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141E, U3GINIT_HUAWEI),
250d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E141F, U3GINIT_HUAWEI),
251d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1420, U3GINIT_HUAWEI),
252d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1421, U3GINIT_HUAWEI),
253d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1422, U3GINIT_HUAWEI),
254d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1423, U3GINIT_HUAWEI),
255d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1424, U3GINIT_HUAWEI),
256d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1425, U3GINIT_HUAWEI),
257d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1426, U3GINIT_HUAWEI),
258d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1427, U3GINIT_HUAWEI),
259d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1428, U3GINIT_HUAWEI),
260d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1429, U3GINIT_HUAWEI),
261d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142A, U3GINIT_HUAWEI),
262d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142B, U3GINIT_HUAWEI),
263d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142C, U3GINIT_HUAWEI),
264d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142D, U3GINIT_HUAWEI),
265d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142E, U3GINIT_HUAWEI),
266d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E142F, U3GINIT_HUAWEI),
267d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1430, U3GINIT_HUAWEI),
268d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1431, U3GINIT_HUAWEI),
269d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1432, U3GINIT_HUAWEI),
270d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1433, U3GINIT_HUAWEI),
271d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1434, U3GINIT_HUAWEI),
272d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1435, U3GINIT_HUAWEI),
273d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1436, U3GINIT_HUAWEI),
274d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1437, U3GINIT_HUAWEI),
275d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1438, U3GINIT_HUAWEI),
276d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E1439, U3GINIT_HUAWEI),
277d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143A, U3GINIT_HUAWEI),
278d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143B, U3GINIT_HUAWEI),
279d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143C, U3GINIT_HUAWEI),
280d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143D, U3GINIT_HUAWEI),
281d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143E, U3GINIT_HUAWEI),
282d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E143F, U3GINIT_HUAWEI),
283*d840e1d2SHans Petter Selasky 	U3G_DEV(HUAWEI, E173, 0),
284*d840e1d2SHans Petter Selasky 	U3G_DEV(HUAWEI, E173_INIT, U3GINIT_HUAWEISCSI),
285d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E180V, U3GINIT_HUAWEI),
286d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E220, U3GINIT_HUAWEI),
287d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, E220BIS, U3GINIT_HUAWEI),
288d84a79e7SAndrew Thompson 	U3G_DEV(HUAWEI, MOBILE, U3GINIT_HUAWEI),
2892386d714SAndrew Thompson 	U3G_DEV(HUAWEI, E1752, U3GINIT_HUAWEISCSI),
290294fe04aSNick Hibma 	U3G_DEV(HUAWEI, E1820, U3GINIT_HUAWEISCSI),
291f3aa3ca3SHans Petter Selasky 	U3G_DEV(HUAWEI, K3765, U3GINIT_HUAWEI),
292b2e79269SDima Dorfman 	U3G_DEV(HUAWEI, K3765_INIT, U3GINIT_HUAWEISCSI),
293c0e2c178SAndrew Thompson 	U3G_DEV(KYOCERA2, CDMA_MSM_K, 0),
294b340b7beSAndrew Thompson 	U3G_DEV(KYOCERA2, KPC680, 0),
295627ab90bSGavin Atkinson 	U3G_DEV(LONGCHEER, WM66, U3GINIT_HUAWEI),
296c175c7deSNick Hibma 	U3G_DEV(LONGCHEER, DISK, U3GINIT_TCT),
297c175c7deSNick Hibma 	U3G_DEV(LONGCHEER, W14, 0),
29814bd1ee5SHans Petter Selasky 	U3G_DEV(LONGCHEER, XSSTICK, 0),
299185d20b5SAndrew Thompson 	U3G_DEV(MERLIN, V620, 0),
300f3aa3ca3SHans Petter Selasky 	U3G_DEV(NEOTEL, PRIME, 0),
301c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, E725, 0),
302a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, ES620, 0),
303c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, ES620_2, 0),
304c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, EU730, 0),
305c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, EU740, 0),
306c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, EU870D, 0),
307c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, MC760, 0),
308b531de0bSNick Hibma 	U3G_DEV(NOVATEL, MC547, 0),
309a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, MC950D, 0),
310a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, U720, 0),
311a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, U727, 0),
312c0e2c178SAndrew Thompson 	U3G_DEV(NOVATEL, U727_2, 0),
313a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, U740, 0),
314a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, U740_2, 0),
315d84a79e7SAndrew Thompson 	U3G_DEV(NOVATEL, U760, U3GINIT_SCSIEJECT),
316a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, U870, 0),
317a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, V620, 0),
318a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, V640, 0),
319a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, V720, 0),
320a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, V740, 0),
321a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, X950D, 0),
322a173706bSAndrew Thompson 	U3G_DEV(NOVATEL, XU870, 0),
323c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6500, 0),
324c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6501, 0),
325c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6601, 0),
326c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6721, 0),
327c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6741, 0),
328c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6761, 0),
329c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E6800, 0),
330c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E7021, 0),
331c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E7041, 0),
332c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E7061, 0),
333c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, E7100, 0),
334e191eb5aSAndrew Thompson 	U3G_DEV(OPTION, GE40X, 0),
335c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GT3G, 0),
336c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GT3GPLUS, 0),
337c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GT3GQUAD, 0),
338b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_1, 0),
339b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_2, 0),
340b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_3, 0),
341b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_4, 0),
342b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_5, 0),
343b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GT3G_6, 0),
344c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GTHSDPA, 0),
345b340b7beSAndrew Thompson 	U3G_DEV(OPTION, GTM380, 0),
346c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GTMAX36, 0),
347c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GTMAX380HSUPAE, 0),
348c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GTMAXHSUPA, 0),
349c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, GTMAXHSUPAE, 0),
350c0e2c178SAndrew Thompson 	U3G_DEV(OPTION, VODAFONEMC3G, 0),
351c0e2c178SAndrew Thompson 	U3G_DEV(QISDA, H20_1, 0),
352c0e2c178SAndrew Thompson 	U3G_DEV(QISDA, H20_2, 0),
353b340b7beSAndrew Thompson 	U3G_DEV(QISDA, H21_1, 0),
354b340b7beSAndrew Thompson 	U3G_DEV(QISDA, H21_2, 0),
355c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMM2, AC8700, 0),
356c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMM2, MF330, 0),
357b340b7beSAndrew Thompson 	U3G_DEV(QUALCOMMINC, AC2726, 0),
358b340b7beSAndrew Thompson 	U3G_DEV(QUALCOMMINC, AC8700, 0),
359b340b7beSAndrew Thompson 	U3G_DEV(QUALCOMMINC, AC8710, 0),
360d84a79e7SAndrew Thompson 	U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GINIT_SCSIEJECT),
361c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0002, 0),
362c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0003, 0),
363c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0004, 0),
364c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0005, 0),
365c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0006, 0),
366c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0007, 0),
367c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0008, 0),
368c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0009, 0),
369c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000A, 0),
370c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000B, 0),
371c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000C, 0),
372c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000D, 0),
373c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000E, 0),
374c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E000F, 0),
375c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0010, 0),
376c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0011, 0),
377c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0012, 0),
378c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0013, 0),
379c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0014, 0),
380c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0017, 0),
381c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0018, 0),
382c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0019, 0),
383c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0020, 0),
384c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0021, 0),
385c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0022, 0),
386c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0023, 0),
387c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0024, 0),
388c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0025, 0),
389c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0026, 0),
390c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0027, 0),
391c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0028, 0),
392c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0029, 0),
393c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0030, 0),
394c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0032, 0),
395c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0033, 0),
396c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0037, 0),
397c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0039, 0),
398c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0042, 0),
399c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0043, 0),
400c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0048, 0),
401c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0049, 0),
402c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0051, 0),
403c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0052, 0),
404c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0054, 0),
405c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0055, 0),
406c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0057, 0),
407c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0058, 0),
408c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0059, 0),
409c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0060, 0),
410c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0061, 0),
411c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0062, 0),
412c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0063, 0),
413c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0064, 0),
414c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0066, 0),
415c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0069, 0),
416c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0070, 0),
417c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0073, 0),
418c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0076, 0),
419c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0078, 0),
420c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0082, 0),
421c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E0086, 0),
4220223e98aSNick Hibma 	U3G_DEV(QUALCOMMINC, SURFSTICK, 0),
423c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E2002, 0),
424c0e2c178SAndrew Thompson 	U3G_DEV(QUALCOMMINC, E2003, 0),
425b340b7beSAndrew Thompson 	U3G_DEV(QUALCOMMINC, MF626, 0),
426b340b7beSAndrew Thompson 	U3G_DEV(QUALCOMMINC, MF628, 0),
42709882661SAndrew Thompson 	U3G_DEV(QUALCOMMINC, MF633R, 0),
428c0e2c178SAndrew Thompson 	U3G_DEV(QUANTA, GKE, 0),
429c0e2c178SAndrew Thompson 	U3G_DEV(QUANTA, GLE, 0),
430b340b7beSAndrew Thompson 	U3G_DEV(QUANTA, GLX, 0),
431b340b7beSAndrew Thompson 	U3G_DEV(QUANTA, Q101, 0),
432b340b7beSAndrew Thompson 	U3G_DEV(QUANTA, Q111, 0),
433c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC402, 0),
434a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC595U, 0),
435a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC597E, 0),
436c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC875E, 0),
437c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC875U, 0),
438c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC875U_2, 0),
439a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC880, 0),
440a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC880E, 0),
441a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC880U, 0),
442a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC881, 0),
443a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC881E, 0),
444a173706bSAndrew Thompson 	U3G_DEV(SIERRA, AC881U, 0),
445c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC885E, 0),
446c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AC885E_2, 0),
447426909d9SAndrew Thompson 	U3G_DEV(SIERRA, AC885U, 0),
448c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AIRCARD580, 0),
449c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AIRCARD595, 0),
450c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, AIRCARD875, 0),
451c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, C22, 0),
452c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, C597, 0),
453c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, C888, 0),
454c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, E0029, 0),
455c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, E6892, 0),
456c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, E6893, 0),
457a173706bSAndrew Thompson 	U3G_DEV(SIERRA, EM5625, 0),
458c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, EM5725, 0),
459a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC5720, 0),
460a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC5720_2, 0),
461a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC5725, 0),
462c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC5727, 0),
463c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC5727_2, 0),
464c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC5728, 0),
465fcc8d2e1SAndrew Thompson 	U3G_DEV(SIERRA, MC8700, 0),
466a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8755, 0),
467a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8755_2, 0),
468a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8755_3, 0),
469c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8755_4, 0),
470a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8765, 0),
471c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8765_2, 0),
472c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8765_3, 0),
473c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8775, 0),
474a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8775_2, 0),
475a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8780, 0),
476c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8780_2, 0),
477c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8780_3, 0),
478a173706bSAndrew Thompson 	U3G_DEV(SIERRA, MC8781, 0),
479c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8781_2, 0),
480c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8781_3, 0),
481c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8785, 0),
482c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8785_2, 0),
483c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8790, 0),
484c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8791, 0),
485c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MC8792, 0),
486c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, MINI5725, 0),
487c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, T11, 0),
488c0e2c178SAndrew Thompson 	U3G_DEV(SIERRA, T598, 0),
489d84a79e7SAndrew Thompson 	U3G_DEV(SILABS, SAEL, U3GINIT_SAEL_M460),
490c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, C105, 0),
491c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1003, 0),
492c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1004, 0),
493c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1005, 0),
494c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1006, 0),
495c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1007, 0),
496c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1008, 0),
497c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1009, 0),
498c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100A, 0),
499c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100B, 0),
500c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100C, 0),
501c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100D, 0),
502c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100E, 0),
503c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E100F, 0),
504c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1010, 0),
505c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1011, 0),
506c0e2c178SAndrew Thompson 	U3G_DEV(STELERA, E1012, 0),
507c0e2c178SAndrew Thompson 	U3G_DEV(TCTMOBILE, X060S, 0),
508fb7a4d49SGleb Smirnoff 	U3G_DEV(TCTMOBILE, X080S, U3GINIT_TCT),
509c0e2c178SAndrew Thompson 	U3G_DEV(TELIT, UC864E, 0),
510c0e2c178SAndrew Thompson 	U3G_DEV(TELIT, UC864G, 0),
511c0e2c178SAndrew Thompson 	U3G_DEV(TLAYTECH, TEU800, 0),
512c0e2c178SAndrew Thompson 	U3G_DEV(TOSHIBA, G450, 0),
513c0e2c178SAndrew Thompson 	U3G_DEV(TOSHIBA, HSDPA, 0),
514c0e2c178SAndrew Thompson 	U3G_DEV(YISO, C893, 0),
515c0e2c178SAndrew Thompson 	/* Autoinstallers */
516d84a79e7SAndrew Thompson 	U3G_DEV(NOVATEL, ZEROCD, U3GINIT_SCSIEJECT),
517d84a79e7SAndrew Thompson 	U3G_DEV(OPTION, GTICON322, U3GINIT_REZERO),
518d84a79e7SAndrew Thompson 	U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GINIT_ZTESTOR),
519504cfaf8SAndrew Thompson 	U3G_DEV(QUALCOMMINC, ZTE_STOR2, U3GINIT_SCSIEJECT),
520cc552e7eSKevin Lo 	U3G_DEV(QUANTA, Q101_STOR, U3GINIT_SCSIEJECT),
521d84a79e7SAndrew Thompson 	U3G_DEV(SIERRA, TRUINSTALL, U3GINIT_SIERRA),
522c0e2c178SAndrew Thompson #undef	U3G_DEV
52302ac6454SAndrew Thompson };
52402ac6454SAndrew Thompson 
525d84a79e7SAndrew Thompson static int
526760bc48eSAndrew Thompson u3g_sierra_init(struct usb_device *udev)
52702ac6454SAndrew Thompson {
528760bc48eSAndrew Thompson 	struct usb_device_request req;
52902ac6454SAndrew Thompson 
53002ac6454SAndrew Thompson 	req.bmRequestType = UT_VENDOR;
53102ac6454SAndrew Thompson 	req.bRequest = UR_SET_INTERFACE;
53202ac6454SAndrew Thompson 	USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
53302ac6454SAndrew Thompson 	USETW(req.wIndex, UHF_PORT_CONNECTION);
53402ac6454SAndrew Thompson 	USETW(req.wLength, 0);
53502ac6454SAndrew Thompson 
536a593f6b8SAndrew Thompson 	if (usbd_do_request_flags(udev, NULL, &req,
53702ac6454SAndrew Thompson 	    NULL, 0, NULL, USB_MS_HZ)) {
53802ac6454SAndrew Thompson 		/* ignore any errors */
53902ac6454SAndrew Thompson 	}
540d84a79e7SAndrew Thompson 	return (0);
54102ac6454SAndrew Thompson }
54202ac6454SAndrew Thompson 
543d84a79e7SAndrew Thompson static int
544760bc48eSAndrew Thompson u3g_huawei_init(struct usb_device *udev)
54502ac6454SAndrew Thompson {
546760bc48eSAndrew Thompson 	struct usb_device_request req;
54702ac6454SAndrew Thompson 
54802ac6454SAndrew Thompson 	req.bmRequestType = UT_WRITE_DEVICE;
54902ac6454SAndrew Thompson 	req.bRequest = UR_SET_FEATURE;
55002ac6454SAndrew Thompson 	USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP);
55102ac6454SAndrew Thompson 	USETW(req.wIndex, UHF_PORT_SUSPEND);
55202ac6454SAndrew Thompson 	USETW(req.wLength, 0);
55302ac6454SAndrew Thompson 
554a593f6b8SAndrew Thompson 	if (usbd_do_request_flags(udev, NULL, &req,
55502ac6454SAndrew Thompson 	    NULL, 0, NULL, USB_MS_HZ)) {
55602ac6454SAndrew Thompson 		/* ignore any errors */
55702ac6454SAndrew Thompson 	}
558d84a79e7SAndrew Thompson 	return (0);
55902ac6454SAndrew Thompson }
56002ac6454SAndrew Thompson 
561750a2682SAndrew Thompson static void
562760bc48eSAndrew Thompson u3g_sael_m460_init(struct usb_device *udev)
563750a2682SAndrew Thompson {
564750a2682SAndrew Thompson 	static const uint8_t setup[][24] = {
565750a2682SAndrew Thompson 	     { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
566750a2682SAndrew Thompson 	     { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },
567750a2682SAndrew Thompson 	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
568750a2682SAndrew Thompson 	       0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
569750a2682SAndrew Thompson 	       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
570750a2682SAndrew Thompson 	     { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 },
571750a2682SAndrew Thompson 	     { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },
572750a2682SAndrew Thompson 	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
573750a2682SAndrew Thompson 	     { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
574750a2682SAndrew Thompson 	     { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
575750a2682SAndrew Thompson 	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
576750a2682SAndrew Thompson 	     { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
577750a2682SAndrew Thompson 	     { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
578750a2682SAndrew Thompson 	       0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
579750a2682SAndrew Thompson 	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
580750a2682SAndrew Thompson 	       0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
581750a2682SAndrew Thompson 	       0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
582750a2682SAndrew Thompson 	     { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 },
583750a2682SAndrew Thompson 	     { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },
584750a2682SAndrew Thompson 	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
585750a2682SAndrew Thompson 	     { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },
586750a2682SAndrew Thompson 	     { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
587750a2682SAndrew Thompson 	       0x00, 0x00, 0x00, 0x00, 0x11, 0x13 },
588750a2682SAndrew Thompson 	     { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
589750a2682SAndrew Thompson 	       0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
590750a2682SAndrew Thompson 	       0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 },
591750a2682SAndrew Thompson 	     { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 },
592750a2682SAndrew Thompson 	};
593750a2682SAndrew Thompson 
594760bc48eSAndrew Thompson 	struct usb_device_request req;
595e0a69b51SAndrew Thompson 	usb_error_t err;
596750a2682SAndrew Thompson 	uint16_t len;
597750a2682SAndrew Thompson 	uint8_t buf[0x300];
598750a2682SAndrew Thompson 	uint8_t n;
599750a2682SAndrew Thompson 
600750a2682SAndrew Thompson 	DPRINTFN(1, "\n");
601750a2682SAndrew Thompson 
602a593f6b8SAndrew Thompson 	if (usbd_req_set_alt_interface_no(udev, NULL, 0, 0)) {
603750a2682SAndrew Thompson 		DPRINTFN(0, "Alt setting 0 failed\n");
604750a2682SAndrew Thompson 		return;
605750a2682SAndrew Thompson 	}
606750a2682SAndrew Thompson 
607750a2682SAndrew Thompson 	for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) {
608750a2682SAndrew Thompson 
609750a2682SAndrew Thompson 		memcpy(&req, setup[n], sizeof(req));
610750a2682SAndrew Thompson 
611750a2682SAndrew Thompson 		len = UGETW(req.wLength);
612750a2682SAndrew Thompson 		if (req.bmRequestType & UE_DIR_IN) {
613750a2682SAndrew Thompson 			if (len > sizeof(buf)) {
614750a2682SAndrew Thompson 				DPRINTFN(0, "too small buffer\n");
615750a2682SAndrew Thompson 				continue;
616750a2682SAndrew Thompson 			}
617a593f6b8SAndrew Thompson 			err = usbd_do_request(udev, NULL, &req, buf);
618750a2682SAndrew Thompson 		} else {
619750a2682SAndrew Thompson 			if (len > (sizeof(setup[0]) - 8)) {
620750a2682SAndrew Thompson 				DPRINTFN(0, "too small buffer\n");
621750a2682SAndrew Thompson 				continue;
622750a2682SAndrew Thompson 			}
623a593f6b8SAndrew Thompson 			err = usbd_do_request(udev, NULL, &req,
6244309a3fbSAndrew Thompson 			    __DECONST(uint8_t *, &setup[n][8]));
6254309a3fbSAndrew Thompson 		}
6264309a3fbSAndrew Thompson 		if (err) {
6274309a3fbSAndrew Thompson 			DPRINTFN(1, "request %u failed\n",
628750a2682SAndrew Thompson 			    (unsigned int)n);
6294309a3fbSAndrew Thompson 			/*
6304309a3fbSAndrew Thompson 			 * Some of the requests will fail. Stop doing
6314309a3fbSAndrew Thompson 			 * requests when we are getting timeouts so
6324309a3fbSAndrew Thompson 			 * that we don't block the explore/attach
6334309a3fbSAndrew Thompson 			 * thread forever.
6344309a3fbSAndrew Thompson 			 */
6354309a3fbSAndrew Thompson 			if (err == USB_ERR_TIMEOUT)
636750a2682SAndrew Thompson 				break;
637750a2682SAndrew Thompson 		}
638750a2682SAndrew Thompson 	}
639750a2682SAndrew Thompson }
640750a2682SAndrew Thompson 
64102ac6454SAndrew Thompson /*
64202ac6454SAndrew Thompson  * The following function handles 3G modem devices (E220, Mobile,
64302ac6454SAndrew Thompson  * etc.) with auto-install flash disks for Windows/MacOSX on the first
64402ac6454SAndrew Thompson  * interface.  After some command or some delay they change appearance
64502ac6454SAndrew Thompson  * to a modem.
64602ac6454SAndrew Thompson  */
6472a4c6157SAndrew Thompson static void
6482a4c6157SAndrew Thompson u3g_test_autoinst(void *arg, struct usb_device *udev,
649760bc48eSAndrew Thompson     struct usb_attach_arg *uaa)
65002ac6454SAndrew Thompson {
651760bc48eSAndrew Thompson 	struct usb_interface *iface;
652760bc48eSAndrew Thompson 	struct usb_interface_descriptor *id;
653d84a79e7SAndrew Thompson 	int error;
654e7702e9eSNick Hibma 	unsigned long method;
65502ac6454SAndrew Thompson 
6562a4c6157SAndrew Thompson 	if (uaa->dev_state != UAA_DEV_READY)
6572a4c6157SAndrew Thompson 		return;
6582a4c6157SAndrew Thompson 
659a593f6b8SAndrew Thompson 	iface = usbd_get_iface(udev, 0);
6602a4c6157SAndrew Thompson 	if (iface == NULL)
6612a4c6157SAndrew Thompson 		return;
66202ac6454SAndrew Thompson 	id = iface->idesc;
6632a4c6157SAndrew Thompson 	if (id == NULL || id->bInterfaceClass != UICLASS_MASS)
6642a4c6157SAndrew Thompson 		return;
665e7702e9eSNick Hibma 
666e7702e9eSNick Hibma 	if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEI))
667e7702e9eSNick Hibma 		method = U3GINIT_HUAWEI;
668e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_SIERRA))
669e7702e9eSNick Hibma 		method = U3GINIT_SIERRA;
670e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_SCSIEJECT))
671e7702e9eSNick Hibma 		method = U3GINIT_SCSIEJECT;
672e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_REZERO))
673e7702e9eSNick Hibma 		method = U3GINIT_REZERO;
674e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_ZTESTOR))
675e7702e9eSNick Hibma 		method = U3GINIT_ZTESTOR;
676e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_CMOTECH))
677e7702e9eSNick Hibma 		method = U3GINIT_CMOTECH;
678e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_WAIT))
679e7702e9eSNick Hibma 		method = U3GINIT_WAIT;
680e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_HUAWEISCSI))
681e7702e9eSNick Hibma 		method = U3GINIT_HUAWEISCSI;
682e7702e9eSNick Hibma 	else if (usb_test_quirk(uaa, UQ_MSC_EJECT_TCT))
683e7702e9eSNick Hibma 		method = U3GINIT_TCT;
684e7702e9eSNick Hibma 	else if (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa) == 0)
685e7702e9eSNick Hibma 		method = USB_GET_DRIVER_INFO(uaa);
686e7702e9eSNick Hibma 	else
687d84a79e7SAndrew Thompson 		return;		/* no device match */
68802ac6454SAndrew Thompson 
689b38fd2d9SNick Hibma 	if (bootverbose) {
690e7702e9eSNick Hibma 		printf("Ejecting %s %s using method %ld\n",
691e7702e9eSNick Hibma 		       usb_get_manufacturer(udev),
692e7702e9eSNick Hibma 		       usb_get_product(udev), method);
693b38fd2d9SNick Hibma 	}
694b38fd2d9SNick Hibma 
695e7702e9eSNick Hibma 	switch (method) {
696d84a79e7SAndrew Thompson 		case U3GINIT_HUAWEI:
697d84a79e7SAndrew Thompson 			error = u3g_huawei_init(udev);
698d84a79e7SAndrew Thompson 			break;
6992386d714SAndrew Thompson 		case U3GINIT_HUAWEISCSI:
7002386d714SAndrew Thompson 			error = usb_msc_eject(udev, 0, MSC_EJECT_HUAWEI);
7012386d714SAndrew Thompson 			break;
702d84a79e7SAndrew Thompson 		case U3GINIT_SCSIEJECT:
703d84a79e7SAndrew Thompson 			error = usb_msc_eject(udev, 0, MSC_EJECT_STOPUNIT);
704d84a79e7SAndrew Thompson 			break;
705d84a79e7SAndrew Thompson 		case U3GINIT_REZERO:
706d84a79e7SAndrew Thompson 			error = usb_msc_eject(udev, 0, MSC_EJECT_REZERO);
707d84a79e7SAndrew Thompson 			break;
708d84a79e7SAndrew Thompson 		case U3GINIT_ZTESTOR:
709b38fd2d9SNick Hibma 			error = usb_msc_eject(udev, 0, MSC_EJECT_STOPUNIT);
710b38fd2d9SNick Hibma 			error |= usb_msc_eject(udev, 0, MSC_EJECT_ZTESTOR);
711d84a79e7SAndrew Thompson 			break;
712d84a79e7SAndrew Thompson 		case U3GINIT_CMOTECH:
713d84a79e7SAndrew Thompson 			error = usb_msc_eject(udev, 0, MSC_EJECT_CMOTECH);
714d84a79e7SAndrew Thompson 			break;
715fb7a4d49SGleb Smirnoff 		case U3GINIT_TCT:
716fb7a4d49SGleb Smirnoff 			error = usb_msc_eject(udev, 0, MSC_EJECT_TCT);
717fb7a4d49SGleb Smirnoff 			break;
718d84a79e7SAndrew Thompson 		case U3GINIT_SIERRA:
719d84a79e7SAndrew Thompson 			error = u3g_sierra_init(udev);
720d84a79e7SAndrew Thompson 			break;
721d84a79e7SAndrew Thompson 		case U3GINIT_WAIT:
722d84a79e7SAndrew Thompson 			/* Just pretend we ejected, the card will timeout */
723d84a79e7SAndrew Thompson 			error = 0;
724d84a79e7SAndrew Thompson 			break;
725d84a79e7SAndrew Thompson 		default:
726d84a79e7SAndrew Thompson 			/* no 3G eject quirks */
727d84a79e7SAndrew Thompson 			error = EOPNOTSUPP;
728d84a79e7SAndrew Thompson 			break;
72902ac6454SAndrew Thompson 	}
730d84a79e7SAndrew Thompson 	if (error == 0) {
731d84a79e7SAndrew Thompson 		/* success, mark the udev as disappearing */
7322a4c6157SAndrew Thompson 		uaa->dev_state = UAA_DEV_EJECTING;
733d84a79e7SAndrew Thompson 	}
73402ac6454SAndrew Thompson }
73502ac6454SAndrew Thompson 
73602ac6454SAndrew Thompson static int
73702ac6454SAndrew Thompson u3g_driver_loaded(struct module *mod, int what, void *arg)
73802ac6454SAndrew Thompson {
73902ac6454SAndrew Thompson 	switch (what) {
74002ac6454SAndrew Thompson 	case MOD_LOAD:
74102ac6454SAndrew Thompson 		/* register our autoinstall handler */
7422a4c6157SAndrew Thompson 		u3g_etag = EVENTHANDLER_REGISTER(usb_dev_configured,
7432a4c6157SAndrew Thompson 		    u3g_test_autoinst, NULL, EVENTHANDLER_PRI_ANY);
74402ac6454SAndrew Thompson 		break;
74502ac6454SAndrew Thompson 	case MOD_UNLOAD:
7462a4c6157SAndrew Thompson 		EVENTHANDLER_DEREGISTER(usb_dev_configured, u3g_etag);
74702ac6454SAndrew Thompson 		break;
74802ac6454SAndrew Thompson 	default:
74902ac6454SAndrew Thompson 		return (EOPNOTSUPP);
75002ac6454SAndrew Thompson 	}
75102ac6454SAndrew Thompson  	return (0);
75202ac6454SAndrew Thompson }
75302ac6454SAndrew Thompson 
75402ac6454SAndrew Thompson static int
75502ac6454SAndrew Thompson u3g_probe(device_t self)
75602ac6454SAndrew Thompson {
757760bc48eSAndrew Thompson 	struct usb_attach_arg *uaa = device_get_ivars(self);
75802ac6454SAndrew Thompson 
759f29a0724SAndrew Thompson 	if (uaa->usb_mode != USB_MODE_HOST) {
76002ac6454SAndrew Thompson 		return (ENXIO);
76102ac6454SAndrew Thompson 	}
76202ac6454SAndrew Thompson 	if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) {
76302ac6454SAndrew Thompson 		return (ENXIO);
76402ac6454SAndrew Thompson 	}
76502ac6454SAndrew Thompson 	if (uaa->info.bInterfaceClass != UICLASS_VENDOR) {
76602ac6454SAndrew Thompson 		return (ENXIO);
76702ac6454SAndrew Thompson 	}
7682a4c6157SAndrew Thompson 	return (usbd_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa));
76902ac6454SAndrew Thompson }
77002ac6454SAndrew Thompson 
77102ac6454SAndrew Thompson static int
77202ac6454SAndrew Thompson u3g_attach(device_t dev)
77302ac6454SAndrew Thompson {
774760bc48eSAndrew Thompson 	struct usb_config u3g_config_tmp[U3G_N_TRANSFER];
775760bc48eSAndrew Thompson 	struct usb_attach_arg *uaa = device_get_ivars(dev);
77602ac6454SAndrew Thompson 	struct u3g_softc *sc = device_get_softc(dev);
777760bc48eSAndrew Thompson 	struct usb_interface *iface;
778760bc48eSAndrew Thompson 	struct usb_interface_descriptor *id;
779822e5d76SAndrew Thompson 	uint32_t iface_valid;
780d84a79e7SAndrew Thompson 	int error, type, nports;
781e92a4515SAndrew Thompson 	int ep, n;
78202ac6454SAndrew Thompson 	uint8_t i;
78302ac6454SAndrew Thompson 
78402ac6454SAndrew Thompson 	DPRINTF("sc=%p\n", sc);
78502ac6454SAndrew Thompson 
786d84a79e7SAndrew Thompson 	type = USB_GET_DRIVER_INFO(uaa);
787e7702e9eSNick Hibma 	if (type == U3GINIT_SAEL_M460
788e7702e9eSNick Hibma 	    || usb_test_quirk(uaa, UQ_MSC_EJECT_SAEL_M460)) {
789750a2682SAndrew Thompson 		u3g_sael_m460_init(uaa->device);
790e7702e9eSNick Hibma 	}
791750a2682SAndrew Thompson 
79202ac6454SAndrew Thompson 	/* copy in USB config */
79302ac6454SAndrew Thompson 	for (n = 0; n != U3G_N_TRANSFER; n++)
79402ac6454SAndrew Thompson 		u3g_config_tmp[n] = u3g_config[n];
79502ac6454SAndrew Thompson 
796a593f6b8SAndrew Thompson 	device_set_usb_desc(dev);
797deefe583SAndrew Thompson 	mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF);
79802ac6454SAndrew Thompson 
79902ac6454SAndrew Thompson 	sc->sc_udev = uaa->device;
80002ac6454SAndrew Thompson 
801e92a4515SAndrew Thompson 	/* Claim all interfaces on the device */
802e92a4515SAndrew Thompson 	iface_valid = 0;
803e92a4515SAndrew Thompson 	for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) {
804a593f6b8SAndrew Thompson 		iface = usbd_get_iface(uaa->device, i);
805e92a4515SAndrew Thompson 		if (iface == NULL)
806e92a4515SAndrew Thompson 			break;
807a593f6b8SAndrew Thompson 		id = usbd_get_interface_descriptor(iface);
808e92a4515SAndrew Thompson 		if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR)
809e92a4515SAndrew Thompson 			continue;
810a593f6b8SAndrew Thompson 		usbd_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex);
811e92a4515SAndrew Thompson 		iface_valid |= (1<<i);
812e92a4515SAndrew Thompson 	}
81302ac6454SAndrew Thompson 
814e92a4515SAndrew Thompson 	i = 0;		/* interface index */
815e92a4515SAndrew Thompson 	ep = 0;		/* endpoint index */
816e92a4515SAndrew Thompson 	nports = 0;	/* number of ports */
817e92a4515SAndrew Thompson 	while (i < USB_IFACE_MAX) {
818e92a4515SAndrew Thompson 		if ((iface_valid & (1<<i)) == 0) {
819e92a4515SAndrew Thompson 			i++;
820e92a4515SAndrew Thompson 			continue;
821e92a4515SAndrew Thompson 		}
82202ac6454SAndrew Thompson 
82302ac6454SAndrew Thompson 		/* update BULK endpoint index */
824e92a4515SAndrew Thompson 		for (n = 0; n < U3G_N_TRANSFER; n++)
825e92a4515SAndrew Thompson 			u3g_config_tmp[n].ep_index = ep;
82602ac6454SAndrew Thompson 
82702ac6454SAndrew Thompson 		/* try to allocate a set of BULK endpoints */
828a593f6b8SAndrew Thompson 		error = usbd_transfer_setup(uaa->device, &i,
829e92a4515SAndrew Thompson 		    sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER,
830e92a4515SAndrew Thompson 		    &sc->sc_ucom[nports], &sc->sc_mtx);
83102ac6454SAndrew Thompson 		if (error) {
83202ac6454SAndrew Thompson 			/* next interface */
833e92a4515SAndrew Thompson 			i++;
834e92a4515SAndrew Thompson 			ep = 0;
83502ac6454SAndrew Thompson 			continue;
83602ac6454SAndrew Thompson 		}
83702ac6454SAndrew Thompson 
83802ac6454SAndrew Thompson 		/* set stall by default */
839deefe583SAndrew Thompson 		mtx_lock(&sc->sc_mtx);
840ed6d949aSAndrew Thompson 		usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]);
841ed6d949aSAndrew Thompson 		usbd_xfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]);
842deefe583SAndrew Thompson 		mtx_unlock(&sc->sc_mtx);
84302ac6454SAndrew Thompson 
844e92a4515SAndrew Thompson 		nports++;	/* found one port */
845e92a4515SAndrew Thompson 		ep++;
846e92a4515SAndrew Thompson 		if (nports == U3G_MAXPORTS)
847e92a4515SAndrew Thompson 			break;
84802ac6454SAndrew Thompson 	}
849e92a4515SAndrew Thompson 	if (nports == 0) {
850e92a4515SAndrew Thompson 		device_printf(dev, "no ports found\n");
851e92a4515SAndrew Thompson 		goto detach;
852e92a4515SAndrew Thompson 	}
853e92a4515SAndrew Thompson 	sc->sc_numports = nports;
85402ac6454SAndrew Thompson 
855a593f6b8SAndrew Thompson 	error = ucom_attach(&sc->sc_super_ucom, sc->sc_ucom,
856deefe583SAndrew Thompson 	    sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx);
85702ac6454SAndrew Thompson 	if (error) {
858a593f6b8SAndrew Thompson 		DPRINTF("ucom_attach failed\n");
85902ac6454SAndrew Thompson 		goto detach;
86002ac6454SAndrew Thompson 	}
8616416c259SNick Hibma 	ucom_set_pnpinfo_usb(&sc->sc_super_ucom, dev);
862d84a79e7SAndrew Thompson 	device_printf(dev, "Found %u port%s.\n", sc->sc_numports,
863d84a79e7SAndrew Thompson 	    sc->sc_numports > 1 ? "s":"");
8646416c259SNick Hibma 
86502ac6454SAndrew Thompson 	return (0);
86602ac6454SAndrew Thompson 
86702ac6454SAndrew Thompson detach:
86802ac6454SAndrew Thompson 	u3g_detach(dev);
86902ac6454SAndrew Thompson 	return (ENXIO);
87002ac6454SAndrew Thompson }
87102ac6454SAndrew Thompson 
87202ac6454SAndrew Thompson static int
87302ac6454SAndrew Thompson u3g_detach(device_t dev)
87402ac6454SAndrew Thompson {
87502ac6454SAndrew Thompson 	struct u3g_softc *sc = device_get_softc(dev);
876015bb88fSNick Hibma 	uint8_t subunit;
87702ac6454SAndrew Thompson 
87802ac6454SAndrew Thompson 	DPRINTF("sc=%p\n", sc);
87902ac6454SAndrew Thompson 
88002ac6454SAndrew Thompson 	/* NOTE: It is not dangerous to detach more ports than attached! */
881015bb88fSNick Hibma 	ucom_detach(&sc->sc_super_ucom, sc->sc_ucom);
88202ac6454SAndrew Thompson 
883015bb88fSNick Hibma 	for (subunit = 0; subunit != U3G_MAXPORTS; subunit++)
884015bb88fSNick Hibma 		usbd_transfer_unsetup(sc->sc_xfer[subunit], U3G_N_TRANSFER);
885deefe583SAndrew Thompson 	mtx_destroy(&sc->sc_mtx);
88602ac6454SAndrew Thompson 
88702ac6454SAndrew Thompson 	return (0);
88802ac6454SAndrew Thompson }
88902ac6454SAndrew Thompson 
89002ac6454SAndrew Thompson static void
891760bc48eSAndrew Thompson u3g_start_read(struct ucom_softc *ucom)
89202ac6454SAndrew Thompson {
89302ac6454SAndrew Thompson 	struct u3g_softc *sc = ucom->sc_parent;
89402ac6454SAndrew Thompson 
89502ac6454SAndrew Thompson 	/* start read endpoint */
896015bb88fSNick Hibma 	usbd_transfer_start(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_RD]);
89702ac6454SAndrew Thompson 	return;
89802ac6454SAndrew Thompson }
89902ac6454SAndrew Thompson 
90002ac6454SAndrew Thompson static void
901760bc48eSAndrew Thompson u3g_stop_read(struct ucom_softc *ucom)
90202ac6454SAndrew Thompson {
90302ac6454SAndrew Thompson 	struct u3g_softc *sc = ucom->sc_parent;
90402ac6454SAndrew Thompson 
90502ac6454SAndrew Thompson 	/* stop read endpoint */
906015bb88fSNick Hibma 	usbd_transfer_stop(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_RD]);
90702ac6454SAndrew Thompson 	return;
90802ac6454SAndrew Thompson }
90902ac6454SAndrew Thompson 
91002ac6454SAndrew Thompson static void
911760bc48eSAndrew Thompson u3g_start_write(struct ucom_softc *ucom)
91202ac6454SAndrew Thompson {
91302ac6454SAndrew Thompson 	struct u3g_softc *sc = ucom->sc_parent;
91402ac6454SAndrew Thompson 
915015bb88fSNick Hibma 	usbd_transfer_start(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_WR]);
91602ac6454SAndrew Thompson 	return;
91702ac6454SAndrew Thompson }
91802ac6454SAndrew Thompson 
91902ac6454SAndrew Thompson static void
920760bc48eSAndrew Thompson u3g_stop_write(struct ucom_softc *ucom)
92102ac6454SAndrew Thompson {
92202ac6454SAndrew Thompson 	struct u3g_softc *sc = ucom->sc_parent;
92302ac6454SAndrew Thompson 
924015bb88fSNick Hibma 	usbd_transfer_stop(sc->sc_xfer[ucom->sc_subunit][U3G_BULK_WR]);
92502ac6454SAndrew Thompson 	return;
92602ac6454SAndrew Thompson }
92702ac6454SAndrew Thompson 
92802ac6454SAndrew Thompson static void
929ed6d949aSAndrew Thompson u3g_write_callback(struct usb_xfer *xfer, usb_error_t error)
93002ac6454SAndrew Thompson {
931ed6d949aSAndrew Thompson 	struct ucom_softc *ucom = usbd_xfer_softc(xfer);
932ed6d949aSAndrew Thompson 	struct usb_page_cache *pc;
93302ac6454SAndrew Thompson 	uint32_t actlen;
93402ac6454SAndrew Thompson 
93502ac6454SAndrew Thompson 	switch (USB_GET_STATE(xfer)) {
93602ac6454SAndrew Thompson 	case USB_ST_TRANSFERRED:
93702ac6454SAndrew Thompson 	case USB_ST_SETUP:
93802ac6454SAndrew Thompson tr_setup:
939ed6d949aSAndrew Thompson 		pc = usbd_xfer_get_frame(xfer, 0);
940ed6d949aSAndrew Thompson 		if (ucom_get_data(ucom, pc, 0, U3G_BSIZE, &actlen)) {
941ed6d949aSAndrew Thompson 			usbd_xfer_set_frame_len(xfer, 0, actlen);
942a593f6b8SAndrew Thompson 			usbd_transfer_submit(xfer);
94302ac6454SAndrew Thompson 		}
94402ac6454SAndrew Thompson 		break;
94502ac6454SAndrew Thompson 
94602ac6454SAndrew Thompson 	default:			/* Error */
947ed6d949aSAndrew Thompson 		if (error != USB_ERR_CANCELLED) {
94802ac6454SAndrew Thompson 			/* do a builtin clear-stall */
949ed6d949aSAndrew Thompson 			usbd_xfer_set_stall(xfer);
95002ac6454SAndrew Thompson 			goto tr_setup;
95102ac6454SAndrew Thompson 		}
95202ac6454SAndrew Thompson 		break;
95302ac6454SAndrew Thompson 	}
95402ac6454SAndrew Thompson 	return;
95502ac6454SAndrew Thompson }
95602ac6454SAndrew Thompson 
95702ac6454SAndrew Thompson static void
958ed6d949aSAndrew Thompson u3g_read_callback(struct usb_xfer *xfer, usb_error_t error)
95902ac6454SAndrew Thompson {
960ed6d949aSAndrew Thompson 	struct ucom_softc *ucom = usbd_xfer_softc(xfer);
961ed6d949aSAndrew Thompson 	struct usb_page_cache *pc;
962ed6d949aSAndrew Thompson 	int actlen;
963ed6d949aSAndrew Thompson 
964ed6d949aSAndrew Thompson 	usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
96502ac6454SAndrew Thompson 
96602ac6454SAndrew Thompson 	switch (USB_GET_STATE(xfer)) {
96702ac6454SAndrew Thompson 	case USB_ST_TRANSFERRED:
968ed6d949aSAndrew Thompson 		pc = usbd_xfer_get_frame(xfer, 0);
969ed6d949aSAndrew Thompson 		ucom_put_data(ucom, pc, 0, actlen);
97002ac6454SAndrew Thompson 
97102ac6454SAndrew Thompson 	case USB_ST_SETUP:
97202ac6454SAndrew Thompson tr_setup:
973ed6d949aSAndrew Thompson 		usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
974a593f6b8SAndrew Thompson 		usbd_transfer_submit(xfer);
97502ac6454SAndrew Thompson 		break;
97602ac6454SAndrew Thompson 
97702ac6454SAndrew Thompson 	default:			/* Error */
978ed6d949aSAndrew Thompson 		if (error != USB_ERR_CANCELLED) {
97902ac6454SAndrew Thompson 			/* do a builtin clear-stall */
980ed6d949aSAndrew Thompson 			usbd_xfer_set_stall(xfer);
98102ac6454SAndrew Thompson 			goto tr_setup;
98202ac6454SAndrew Thompson 		}
98302ac6454SAndrew Thompson 		break;
98402ac6454SAndrew Thompson 	}
98502ac6454SAndrew Thompson 	return;
98602ac6454SAndrew Thompson }
987