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 3302ac6454SAndrew Thompson #include "usbdevs.h" 3402ac6454SAndrew Thompson #include <dev/usb/usb.h> 3502ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h> 3602ac6454SAndrew Thompson #include <dev/usb/usb_error.h> 3702ac6454SAndrew Thompson #include <dev/usb/usb_defs.h> 3802ac6454SAndrew Thompson 3902ac6454SAndrew Thompson #define USB_DEBUG_VAR u3g_debug 4002ac6454SAndrew Thompson 4102ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 4202ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 4302ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 4402ac6454SAndrew Thompson #include <dev/usb/usb_request.h> 4502ac6454SAndrew Thompson #include <dev/usb/usb_lookup.h> 4602ac6454SAndrew Thompson #include <dev/usb/usb_util.h> 4702ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h> 4802ac6454SAndrew Thompson #include <dev/usb/usb_msctest.h> 4902ac6454SAndrew Thompson #include <dev/usb/usb_dynamic.h> 5002ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 5102ac6454SAndrew Thompson 5202ac6454SAndrew Thompson #include <dev/usb/serial/usb_serial.h> 5302ac6454SAndrew Thompson 5402ac6454SAndrew Thompson #if USB_DEBUG 5502ac6454SAndrew Thompson static int u3g_debug = 0; 5602ac6454SAndrew Thompson 57750a2682SAndrew Thompson SYSCTL_NODE(_hw_usb2, OID_AUTO, u3g, CTLFLAG_RW, 0, "USB 3g"); 5802ac6454SAndrew Thompson SYSCTL_INT(_hw_usb2_u3g, OID_AUTO, debug, CTLFLAG_RW, 59750a2682SAndrew Thompson &u3g_debug, 0, "Debug level"); 6002ac6454SAndrew Thompson #endif 6102ac6454SAndrew Thompson 6202ac6454SAndrew Thompson #define U3G_MAXPORTS 4 6302ac6454SAndrew Thompson #define U3G_CONFIG_INDEX 0 6402ac6454SAndrew Thompson #define U3G_BSIZE 2048 6502ac6454SAndrew Thompson 6602ac6454SAndrew Thompson #define U3GSP_GPRS 0 6702ac6454SAndrew Thompson #define U3GSP_EDGE 1 6802ac6454SAndrew Thompson #define U3GSP_CDMA 2 6902ac6454SAndrew Thompson #define U3GSP_UMTS 3 7002ac6454SAndrew Thompson #define U3GSP_HSDPA 4 7102ac6454SAndrew Thompson #define U3GSP_HSUPA 5 7202ac6454SAndrew Thompson #define U3GSP_HSPA 6 7302ac6454SAndrew Thompson #define U3GSP_MAX 7 7402ac6454SAndrew Thompson 75750a2682SAndrew Thompson #define U3GFL_NONE 0x0000 /* No flags */ 76750a2682SAndrew Thompson #define U3GFL_HUAWEI_INIT 0x0001 /* Init command required */ 77750a2682SAndrew Thompson #define U3GFL_SCSI_EJECT 0x0002 /* SCSI eject command required */ 78750a2682SAndrew Thompson #define U3GFL_SIERRA_INIT 0x0004 /* Init command required */ 79750a2682SAndrew Thompson #define U3GFL_SAEL_M460_INIT 0x0008 /* Init device */ 8002ac6454SAndrew Thompson 8102ac6454SAndrew Thompson enum { 8202ac6454SAndrew Thompson U3G_BULK_WR, 8302ac6454SAndrew Thompson U3G_BULK_RD, 8402ac6454SAndrew Thompson U3G_N_TRANSFER, 8502ac6454SAndrew Thompson }; 8602ac6454SAndrew Thompson 8702ac6454SAndrew Thompson struct u3g_softc { 8802ac6454SAndrew Thompson struct usb2_com_super_softc sc_super_ucom; 8902ac6454SAndrew Thompson struct usb2_com_softc sc_ucom[U3G_MAXPORTS]; 9002ac6454SAndrew Thompson 9102ac6454SAndrew Thompson struct usb2_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER]; 9202ac6454SAndrew Thompson struct usb2_device *sc_udev; 93deefe583SAndrew Thompson struct mtx sc_mtx; 9402ac6454SAndrew Thompson 9502ac6454SAndrew Thompson uint8_t sc_lsr; /* local status register */ 9602ac6454SAndrew Thompson uint8_t sc_msr; /* U3G status register */ 9702ac6454SAndrew Thompson uint8_t sc_numports; 9802ac6454SAndrew Thompson }; 9902ac6454SAndrew Thompson 10002ac6454SAndrew Thompson static device_probe_t u3g_probe; 10102ac6454SAndrew Thompson static device_attach_t u3g_attach; 10202ac6454SAndrew Thompson static device_detach_t u3g_detach; 10302ac6454SAndrew Thompson 10402ac6454SAndrew Thompson static usb2_callback_t u3g_write_callback; 10502ac6454SAndrew Thompson static usb2_callback_t u3g_read_callback; 10602ac6454SAndrew Thompson 10702ac6454SAndrew Thompson static void u3g_start_read(struct usb2_com_softc *ucom); 10802ac6454SAndrew Thompson static void u3g_stop_read(struct usb2_com_softc *ucom); 10902ac6454SAndrew Thompson static void u3g_start_write(struct usb2_com_softc *ucom); 11002ac6454SAndrew Thompson static void u3g_stop_write(struct usb2_com_softc *ucom); 11102ac6454SAndrew Thompson 11202ac6454SAndrew Thompson static int u3g_driver_loaded(struct module *mod, int what, void *arg); 11302ac6454SAndrew Thompson 11402ac6454SAndrew Thompson static const struct usb2_config u3g_config[U3G_N_TRANSFER] = { 11502ac6454SAndrew Thompson 11602ac6454SAndrew Thompson [U3G_BULK_WR] = { 11702ac6454SAndrew Thompson .type = UE_BULK, 11802ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 11902ac6454SAndrew Thompson .direction = UE_DIR_OUT, 12002ac6454SAndrew Thompson .mh.bufsize = U3G_BSIZE,/* bytes */ 12102ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 12202ac6454SAndrew Thompson .mh.callback = &u3g_write_callback, 12302ac6454SAndrew Thompson }, 12402ac6454SAndrew Thompson 12502ac6454SAndrew Thompson [U3G_BULK_RD] = { 12602ac6454SAndrew Thompson .type = UE_BULK, 12702ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 12802ac6454SAndrew Thompson .direction = UE_DIR_IN, 12902ac6454SAndrew Thompson .mh.bufsize = U3G_BSIZE,/* bytes */ 13002ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 13102ac6454SAndrew Thompson .mh.callback = &u3g_read_callback, 13202ac6454SAndrew Thompson }, 13302ac6454SAndrew Thompson }; 13402ac6454SAndrew Thompson 13502ac6454SAndrew Thompson static const struct usb2_com_callback u3g_callback = { 13602ac6454SAndrew Thompson .usb2_com_start_read = &u3g_start_read, 13702ac6454SAndrew Thompson .usb2_com_stop_read = &u3g_stop_read, 13802ac6454SAndrew Thompson .usb2_com_start_write = &u3g_start_write, 13902ac6454SAndrew Thompson .usb2_com_stop_write = &u3g_stop_write, 14002ac6454SAndrew Thompson }; 14102ac6454SAndrew Thompson 14202ac6454SAndrew Thompson static device_method_t u3g_methods[] = { 14302ac6454SAndrew Thompson DEVMETHOD(device_probe, u3g_probe), 14402ac6454SAndrew Thompson DEVMETHOD(device_attach, u3g_attach), 14502ac6454SAndrew Thompson DEVMETHOD(device_detach, u3g_detach), 14602ac6454SAndrew Thompson {0, 0} 14702ac6454SAndrew Thompson }; 14802ac6454SAndrew Thompson 14902ac6454SAndrew Thompson static devclass_t u3g_devclass; 15002ac6454SAndrew Thompson 15102ac6454SAndrew Thompson static driver_t u3g_driver = { 15202ac6454SAndrew Thompson .name = "u3g", 15302ac6454SAndrew Thompson .methods = u3g_methods, 15402ac6454SAndrew Thompson .size = sizeof(struct u3g_softc), 15502ac6454SAndrew Thompson }; 15602ac6454SAndrew Thompson 1579aef556dSAndrew Thompson DRIVER_MODULE(u3g, uhub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0); 15802ac6454SAndrew Thompson MODULE_DEPEND(u3g, ucom, 1, 1, 1); 15902ac6454SAndrew Thompson MODULE_DEPEND(u3g, usb, 1, 1, 1); 16002ac6454SAndrew Thompson 16102ac6454SAndrew Thompson static const struct usb2_device_id u3g_devs[] = { 16202ac6454SAndrew Thompson /* OEM: Option */ 163750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3G, U3GFL_NONE)}, 164750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GQUAD, U3GFL_NONE)}, 165750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GPLUS, U3GFL_NONE)}, 166750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTMAX36, U3GFL_NONE)}, 167750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTMAXHSUPA, U3GFL_NONE)}, 168750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_VODAFONEMC3G, U3GFL_NONE)}, 16902ac6454SAndrew Thompson /* OEM: Qualcomm, Inc. */ 170750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_ZTE_STOR, U3GFL_SCSI_EJECT)}, 171750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_CDMA_MSM, U3GFL_SCSI_EJECT)}, 17202ac6454SAndrew Thompson /* OEM: Huawei */ 173750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_MOBILE, U3GFL_HUAWEI_INIT)}, 174750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220, U3GFL_HUAWEI_INIT)}, 17502ac6454SAndrew Thompson /* OEM: Novatel */ 176750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_CDMA_MODEM, U3GFL_SCSI_EJECT)}, 177750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ES620, U3GFL_SCSI_EJECT)}, 178750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MC950D, U3GFL_SCSI_EJECT)}, 179750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U720, U3GFL_SCSI_EJECT)}, 180750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U727, U3GFL_SCSI_EJECT)}, 181750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U740, U3GFL_SCSI_EJECT)}, 182750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U740_2, U3GFL_SCSI_EJECT)}, 183750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U870, U3GFL_SCSI_EJECT)}, 184750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V620, U3GFL_SCSI_EJECT)}, 185750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V640, U3GFL_SCSI_EJECT)}, 186750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V720, U3GFL_SCSI_EJECT)}, 187750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V740, U3GFL_SCSI_EJECT)}, 188750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_X950D, U3GFL_SCSI_EJECT)}, 189750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_XU870, U3GFL_SCSI_EJECT)}, 190750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ZEROCD, U3GFL_SCSI_EJECT)}, 191750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_DELL, USB_PRODUCT_DELL_U740, U3GFL_SCSI_EJECT)}, 19202ac6454SAndrew Thompson /* OEM: Merlin */ 193750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_MERLIN, USB_PRODUCT_MERLIN_V620, U3GFL_NONE)}, 19402ac6454SAndrew Thompson /* OEM: Sierra Wireless: */ 195750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD580, U3GFL_NONE)}, 196750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD595, U3GFL_NONE)}, 197750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC595U, U3GFL_NONE)}, 198750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC597E, U3GFL_NONE)}, 199750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_C597, U3GFL_NONE)}, 200750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880, U3GFL_NONE)}, 201750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880E, U3GFL_NONE)}, 202750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880U, U3GFL_NONE)}, 203750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881, U3GFL_NONE)}, 204750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881E, U3GFL_NONE)}, 205750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881U, U3GFL_NONE)}, 206750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_EM5625, U3GFL_NONE)}, 207750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720, U3GFL_NONE)}, 208750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720_2, U3GFL_NONE)}, 209750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5725, U3GFL_NONE)}, 210750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MINI5725, U3GFL_NONE)}, 211750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD875, U3GFL_NONE)}, 212750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755, U3GFL_NONE)}, 213750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_2, U3GFL_NONE)}, 214750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_3, U3GFL_NONE)}, 215750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8765, U3GFL_NONE)}, 216750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC875U, U3GFL_NONE)}, 217750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8775_2, U3GFL_NONE)}, 218750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HS2300, U3GFL_NONE)}, 219750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8780, U3GFL_NONE)}, 220750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8781, U3GFL_NONE)}, 221750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HS2300, U3GFL_NONE)}, 22202ac6454SAndrew Thompson /* Sierra TruInstaller device ID */ 223750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_TRUINSTALL, U3GFL_SIERRA_INIT)}, 224750a2682SAndrew Thompson /* PRUEBA SILABS */ 225750a2682SAndrew Thompson {USB_VPI(USB_VENDOR_SILABS, USB_PRODUCT_SILABS_SAEL, U3GFL_SAEL_M460_INIT)}, 22602ac6454SAndrew Thompson }; 22702ac6454SAndrew Thompson 22802ac6454SAndrew Thompson static void 22902ac6454SAndrew Thompson u3g_sierra_init(struct usb2_device *udev) 23002ac6454SAndrew Thompson { 23102ac6454SAndrew Thompson struct usb2_device_request req; 23202ac6454SAndrew Thompson 23302ac6454SAndrew Thompson DPRINTFN(0, "\n"); 23402ac6454SAndrew Thompson 23502ac6454SAndrew Thompson req.bmRequestType = UT_VENDOR; 23602ac6454SAndrew Thompson req.bRequest = UR_SET_INTERFACE; 23702ac6454SAndrew Thompson USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 23802ac6454SAndrew Thompson USETW(req.wIndex, UHF_PORT_CONNECTION); 23902ac6454SAndrew Thompson USETW(req.wLength, 0); 24002ac6454SAndrew Thompson 24102ac6454SAndrew Thompson if (usb2_do_request_flags(udev, NULL, &req, 24202ac6454SAndrew Thompson NULL, 0, NULL, USB_MS_HZ)) { 24302ac6454SAndrew Thompson /* ignore any errors */ 24402ac6454SAndrew Thompson } 24502ac6454SAndrew Thompson return; 24602ac6454SAndrew Thompson } 24702ac6454SAndrew Thompson 24802ac6454SAndrew Thompson static void 24902ac6454SAndrew Thompson u3g_huawei_init(struct usb2_device *udev) 25002ac6454SAndrew Thompson { 25102ac6454SAndrew Thompson struct usb2_device_request req; 25202ac6454SAndrew Thompson 25302ac6454SAndrew Thompson DPRINTFN(0, "\n"); 25402ac6454SAndrew Thompson 25502ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_DEVICE; 25602ac6454SAndrew Thompson req.bRequest = UR_SET_FEATURE; 25702ac6454SAndrew Thompson USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 25802ac6454SAndrew Thompson USETW(req.wIndex, UHF_PORT_SUSPEND); 25902ac6454SAndrew Thompson USETW(req.wLength, 0); 26002ac6454SAndrew Thompson 26102ac6454SAndrew Thompson if (usb2_do_request_flags(udev, NULL, &req, 26202ac6454SAndrew Thompson NULL, 0, NULL, USB_MS_HZ)) { 26302ac6454SAndrew Thompson /* ignore any errors */ 26402ac6454SAndrew Thompson } 26502ac6454SAndrew Thompson return; 26602ac6454SAndrew Thompson } 26702ac6454SAndrew Thompson 268750a2682SAndrew Thompson static void 269750a2682SAndrew Thompson u3g_sael_m460_init(struct usb2_device *udev) 270750a2682SAndrew Thompson { 271750a2682SAndrew Thompson static const uint8_t setup[][24] = { 272750a2682SAndrew Thompson { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 273750a2682SAndrew Thompson { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, 274750a2682SAndrew Thompson { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 275750a2682SAndrew Thompson 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 276750a2682SAndrew Thompson 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 277750a2682SAndrew Thompson { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 }, 278750a2682SAndrew Thompson { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }, 279750a2682SAndrew Thompson { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 280750a2682SAndrew Thompson { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, 281750a2682SAndrew Thompson { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 282750a2682SAndrew Thompson { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 283750a2682SAndrew Thompson { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 284750a2682SAndrew Thompson { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 285750a2682SAndrew Thompson 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 286750a2682SAndrew Thompson { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 287750a2682SAndrew Thompson 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 288750a2682SAndrew Thompson 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 289750a2682SAndrew Thompson { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, 290750a2682SAndrew Thompson { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 291750a2682SAndrew Thompson { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 292750a2682SAndrew Thompson { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 293750a2682SAndrew Thompson { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 294750a2682SAndrew Thompson 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 295750a2682SAndrew Thompson { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 296750a2682SAndrew Thompson 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 297750a2682SAndrew Thompson 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 298750a2682SAndrew Thompson { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 299750a2682SAndrew Thompson }; 300750a2682SAndrew Thompson 301750a2682SAndrew Thompson struct usb2_device_request req; 3024309a3fbSAndrew Thompson usb2_error_t err; 303750a2682SAndrew Thompson uint16_t len; 304750a2682SAndrew Thompson uint8_t buf[0x300]; 305750a2682SAndrew Thompson uint8_t n; 306750a2682SAndrew Thompson 307750a2682SAndrew Thompson DPRINTFN(1, "\n"); 308750a2682SAndrew Thompson 309750a2682SAndrew Thompson if (usb2_req_set_alt_interface_no(udev, NULL, 0, 0)) { 310750a2682SAndrew Thompson DPRINTFN(0, "Alt setting 0 failed\n"); 311750a2682SAndrew Thompson return; 312750a2682SAndrew Thompson } 313750a2682SAndrew Thompson 314750a2682SAndrew Thompson for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) { 315750a2682SAndrew Thompson 316750a2682SAndrew Thompson memcpy(&req, setup[n], sizeof(req)); 317750a2682SAndrew Thompson 318750a2682SAndrew Thompson len = UGETW(req.wLength); 319750a2682SAndrew Thompson if (req.bmRequestType & UE_DIR_IN) { 320750a2682SAndrew Thompson if (len > sizeof(buf)) { 321750a2682SAndrew Thompson DPRINTFN(0, "too small buffer\n"); 322750a2682SAndrew Thompson continue; 323750a2682SAndrew Thompson } 3244309a3fbSAndrew Thompson err = usb2_do_request(udev, NULL, &req, buf); 325750a2682SAndrew Thompson } else { 326750a2682SAndrew Thompson if (len > (sizeof(setup[0]) - 8)) { 327750a2682SAndrew Thompson DPRINTFN(0, "too small buffer\n"); 328750a2682SAndrew Thompson continue; 329750a2682SAndrew Thompson } 3304309a3fbSAndrew Thompson err = usb2_do_request(udev, NULL, &req, 3314309a3fbSAndrew Thompson __DECONST(uint8_t *, &setup[n][8])); 3324309a3fbSAndrew Thompson } 3334309a3fbSAndrew Thompson if (err) { 3344309a3fbSAndrew Thompson DPRINTFN(1, "request %u failed\n", 335750a2682SAndrew Thompson (unsigned int)n); 3364309a3fbSAndrew Thompson /* 3374309a3fbSAndrew Thompson * Some of the requests will fail. Stop doing 3384309a3fbSAndrew Thompson * requests when we are getting timeouts so 3394309a3fbSAndrew Thompson * that we don't block the explore/attach 3404309a3fbSAndrew Thompson * thread forever. 3414309a3fbSAndrew Thompson */ 3424309a3fbSAndrew Thompson if (err == USB_ERR_TIMEOUT) 343750a2682SAndrew Thompson break; 344750a2682SAndrew Thompson } 345750a2682SAndrew Thompson } 346750a2682SAndrew Thompson } 347750a2682SAndrew Thompson 34802ac6454SAndrew Thompson static int 34902ac6454SAndrew Thompson u3g_lookup_huawei(struct usb2_attach_arg *uaa) 35002ac6454SAndrew Thompson { 35102ac6454SAndrew Thompson /* Calling the lookup function will also set the driver info! */ 35202ac6454SAndrew Thompson return (usb2_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)); 35302ac6454SAndrew Thompson } 35402ac6454SAndrew Thompson 35502ac6454SAndrew Thompson /* 35602ac6454SAndrew Thompson * The following function handles 3G modem devices (E220, Mobile, 35702ac6454SAndrew Thompson * etc.) with auto-install flash disks for Windows/MacOSX on the first 35802ac6454SAndrew Thompson * interface. After some command or some delay they change appearance 35902ac6454SAndrew Thompson * to a modem. 36002ac6454SAndrew Thompson */ 36102ac6454SAndrew Thompson static usb2_error_t 36202ac6454SAndrew Thompson u3g_test_huawei_autoinst(struct usb2_device *udev, 36302ac6454SAndrew Thompson struct usb2_attach_arg *uaa) 36402ac6454SAndrew Thompson { 36502ac6454SAndrew Thompson struct usb2_interface *iface; 36602ac6454SAndrew Thompson struct usb2_interface_descriptor *id; 36702ac6454SAndrew Thompson uint32_t flags; 36802ac6454SAndrew Thompson 36902ac6454SAndrew Thompson if (udev == NULL) { 37002ac6454SAndrew Thompson return (USB_ERR_INVAL); 37102ac6454SAndrew Thompson } 37202ac6454SAndrew Thompson iface = usb2_get_iface(udev, 0); 37302ac6454SAndrew Thompson if (iface == NULL) { 37402ac6454SAndrew Thompson return (USB_ERR_INVAL); 37502ac6454SAndrew Thompson } 37602ac6454SAndrew Thompson id = iface->idesc; 37702ac6454SAndrew Thompson if (id == NULL) { 37802ac6454SAndrew Thompson return (USB_ERR_INVAL); 37902ac6454SAndrew Thompson } 38002ac6454SAndrew Thompson if (id->bInterfaceClass != UICLASS_MASS) { 38102ac6454SAndrew Thompson return (USB_ERR_INVAL); 38202ac6454SAndrew Thompson } 38302ac6454SAndrew Thompson if (u3g_lookup_huawei(uaa)) { 38402ac6454SAndrew Thompson /* no device match */ 38502ac6454SAndrew Thompson return (USB_ERR_INVAL); 38602ac6454SAndrew Thompson } 38702ac6454SAndrew Thompson flags = USB_GET_DRIVER_INFO(uaa); 38802ac6454SAndrew Thompson 38902ac6454SAndrew Thompson if (flags & U3GFL_HUAWEI_INIT) { 39002ac6454SAndrew Thompson u3g_huawei_init(udev); 39102ac6454SAndrew Thompson } else if (flags & U3GFL_SCSI_EJECT) { 39202ac6454SAndrew Thompson return (usb2_test_autoinstall(udev, 0, 1)); 39302ac6454SAndrew Thompson } else if (flags & U3GFL_SIERRA_INIT) { 39402ac6454SAndrew Thompson u3g_sierra_init(udev); 39502ac6454SAndrew Thompson } else { 39602ac6454SAndrew Thompson /* no quirks */ 39702ac6454SAndrew Thompson return (USB_ERR_INVAL); 39802ac6454SAndrew Thompson } 39902ac6454SAndrew Thompson return (0); /* success */ 40002ac6454SAndrew Thompson } 40102ac6454SAndrew Thompson 40202ac6454SAndrew Thompson static int 40302ac6454SAndrew Thompson u3g_driver_loaded(struct module *mod, int what, void *arg) 40402ac6454SAndrew Thompson { 40502ac6454SAndrew Thompson switch (what) { 40602ac6454SAndrew Thompson case MOD_LOAD: 40702ac6454SAndrew Thompson /* register our autoinstall handler */ 40802ac6454SAndrew Thompson usb2_test_huawei_autoinst_p = &u3g_test_huawei_autoinst; 40902ac6454SAndrew Thompson break; 41002ac6454SAndrew Thompson case MOD_UNLOAD: 41102ac6454SAndrew Thompson usb2_test_huawei_unload(NULL); 41202ac6454SAndrew Thompson break; 41302ac6454SAndrew Thompson default: 41402ac6454SAndrew Thompson return (EOPNOTSUPP); 41502ac6454SAndrew Thompson } 41602ac6454SAndrew Thompson return (0); 41702ac6454SAndrew Thompson } 41802ac6454SAndrew Thompson 41902ac6454SAndrew Thompson static int 42002ac6454SAndrew Thompson u3g_probe(device_t self) 42102ac6454SAndrew Thompson { 42202ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(self); 42302ac6454SAndrew Thompson 42402ac6454SAndrew Thompson if (uaa->usb2_mode != USB_MODE_HOST) { 42502ac6454SAndrew Thompson return (ENXIO); 42602ac6454SAndrew Thompson } 42702ac6454SAndrew Thompson if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) { 42802ac6454SAndrew Thompson return (ENXIO); 42902ac6454SAndrew Thompson } 43002ac6454SAndrew Thompson if (uaa->info.bInterfaceClass != UICLASS_VENDOR) { 43102ac6454SAndrew Thompson return (ENXIO); 43202ac6454SAndrew Thompson } 43302ac6454SAndrew Thompson return (u3g_lookup_huawei(uaa)); 43402ac6454SAndrew Thompson } 43502ac6454SAndrew Thompson 43602ac6454SAndrew Thompson static int 43702ac6454SAndrew Thompson u3g_attach(device_t dev) 43802ac6454SAndrew Thompson { 43902ac6454SAndrew Thompson struct usb2_config u3g_config_tmp[U3G_N_TRANSFER]; 44002ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 44102ac6454SAndrew Thompson struct u3g_softc *sc = device_get_softc(dev); 44202ac6454SAndrew Thompson struct usb2_interface *iface; 44302ac6454SAndrew Thompson struct usb2_interface_descriptor *id; 444750a2682SAndrew Thompson uint32_t flags; 44502ac6454SAndrew Thompson uint8_t m; 44602ac6454SAndrew Thompson uint8_t n; 44702ac6454SAndrew Thompson uint8_t i; 44802ac6454SAndrew Thompson uint8_t x; 44902ac6454SAndrew Thompson int error; 45002ac6454SAndrew Thompson 45102ac6454SAndrew Thompson DPRINTF("sc=%p\n", sc); 45202ac6454SAndrew Thompson 453750a2682SAndrew Thompson flags = USB_GET_DRIVER_INFO(uaa); 454750a2682SAndrew Thompson 455750a2682SAndrew Thompson if (flags & U3GFL_SAEL_M460_INIT) 456750a2682SAndrew Thompson u3g_sael_m460_init(uaa->device); 457750a2682SAndrew Thompson 45802ac6454SAndrew Thompson /* copy in USB config */ 45902ac6454SAndrew Thompson for (n = 0; n != U3G_N_TRANSFER; n++) 46002ac6454SAndrew Thompson u3g_config_tmp[n] = u3g_config[n]; 46102ac6454SAndrew Thompson 46202ac6454SAndrew Thompson device_set_usb2_desc(dev); 463deefe583SAndrew Thompson mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF); 46402ac6454SAndrew Thompson 46502ac6454SAndrew Thompson sc->sc_udev = uaa->device; 46602ac6454SAndrew Thompson 46702ac6454SAndrew Thompson x = 0; /* interface index */ 46802ac6454SAndrew Thompson i = 0; /* endpoint index */ 46902ac6454SAndrew Thompson m = 0; /* number of ports */ 47002ac6454SAndrew Thompson 47102ac6454SAndrew Thompson while (m != U3G_MAXPORTS) { 47202ac6454SAndrew Thompson 47302ac6454SAndrew Thompson /* update BULK endpoint index */ 47402ac6454SAndrew Thompson for (n = 0; n != U3G_N_TRANSFER; n++) 47502ac6454SAndrew Thompson u3g_config_tmp[n].ep_index = i; 47602ac6454SAndrew Thompson 47702ac6454SAndrew Thompson iface = usb2_get_iface(uaa->device, x); 47802ac6454SAndrew Thompson if (iface == NULL) { 47902ac6454SAndrew Thompson if (m != 0) 48002ac6454SAndrew Thompson break; /* end of interfaces */ 48102ac6454SAndrew Thompson DPRINTF("did not find any modem endpoints\n"); 48202ac6454SAndrew Thompson goto detach; 48302ac6454SAndrew Thompson } 48402ac6454SAndrew Thompson 48502ac6454SAndrew Thompson id = usb2_get_interface_descriptor(iface); 48602ac6454SAndrew Thompson if ((id == NULL) || 48702ac6454SAndrew Thompson (id->bInterfaceClass != UICLASS_VENDOR)) { 48802ac6454SAndrew Thompson /* next interface */ 48902ac6454SAndrew Thompson x++; 49002ac6454SAndrew Thompson i = 0; 49102ac6454SAndrew Thompson continue; 49202ac6454SAndrew Thompson } 49302ac6454SAndrew Thompson 49402ac6454SAndrew Thompson /* try to allocate a set of BULK endpoints */ 49502ac6454SAndrew Thompson error = usb2_transfer_setup(uaa->device, &x, 49602ac6454SAndrew Thompson sc->sc_xfer[m], u3g_config_tmp, U3G_N_TRANSFER, 497deefe583SAndrew Thompson &sc->sc_ucom[m], &sc->sc_mtx); 49802ac6454SAndrew Thompson if (error) { 49902ac6454SAndrew Thompson /* next interface */ 50002ac6454SAndrew Thompson x++; 50102ac6454SAndrew Thompson i = 0; 50202ac6454SAndrew Thompson continue; 50302ac6454SAndrew Thompson } 50402ac6454SAndrew Thompson 50502ac6454SAndrew Thompson /* grab other interface, if any */ 50602ac6454SAndrew Thompson if (x != uaa->info.bIfaceIndex) 50702ac6454SAndrew Thompson usb2_set_parent_iface(uaa->device, x, 50802ac6454SAndrew Thompson uaa->info.bIfaceIndex); 50902ac6454SAndrew Thompson 51002ac6454SAndrew Thompson /* set stall by default */ 511deefe583SAndrew Thompson mtx_lock(&sc->sc_mtx); 51202ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_WR]); 51302ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_RD]); 514deefe583SAndrew Thompson mtx_unlock(&sc->sc_mtx); 51502ac6454SAndrew Thompson 51602ac6454SAndrew Thompson m++; /* found one port */ 51702ac6454SAndrew Thompson i++; /* next endpoint index */ 51802ac6454SAndrew Thompson } 51902ac6454SAndrew Thompson 52002ac6454SAndrew Thompson sc->sc_numports = m; 52102ac6454SAndrew Thompson 52202ac6454SAndrew Thompson error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, 523deefe583SAndrew Thompson sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx); 52402ac6454SAndrew Thompson if (error) { 52502ac6454SAndrew Thompson DPRINTF("usb2_com_attach failed\n"); 52602ac6454SAndrew Thompson goto detach; 52702ac6454SAndrew Thompson } 52802ac6454SAndrew Thompson if (sc->sc_numports != 1) { 52902ac6454SAndrew Thompson /* be verbose */ 53002ac6454SAndrew Thompson device_printf(dev, "Found %u ports.\n", 53102ac6454SAndrew Thompson (unsigned int)sc->sc_numports); 53202ac6454SAndrew Thompson } 53302ac6454SAndrew Thompson return (0); 53402ac6454SAndrew Thompson 53502ac6454SAndrew Thompson detach: 53602ac6454SAndrew Thompson u3g_detach(dev); 53702ac6454SAndrew Thompson return (ENXIO); 53802ac6454SAndrew Thompson } 53902ac6454SAndrew Thompson 54002ac6454SAndrew Thompson static int 54102ac6454SAndrew Thompson u3g_detach(device_t dev) 54202ac6454SAndrew Thompson { 54302ac6454SAndrew Thompson struct u3g_softc *sc = device_get_softc(dev); 54402ac6454SAndrew Thompson uint8_t m; 54502ac6454SAndrew Thompson 54602ac6454SAndrew Thompson DPRINTF("sc=%p\n", sc); 54702ac6454SAndrew Thompson 54802ac6454SAndrew Thompson /* NOTE: It is not dangerous to detach more ports than attached! */ 54902ac6454SAndrew Thompson usb2_com_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS); 55002ac6454SAndrew Thompson 55102ac6454SAndrew Thompson for (m = 0; m != U3G_MAXPORTS; m++) 55202ac6454SAndrew Thompson usb2_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER); 553deefe583SAndrew Thompson mtx_destroy(&sc->sc_mtx); 55402ac6454SAndrew Thompson 55502ac6454SAndrew Thompson return (0); 55602ac6454SAndrew Thompson } 55702ac6454SAndrew Thompson 55802ac6454SAndrew Thompson static void 55902ac6454SAndrew Thompson u3g_start_read(struct usb2_com_softc *ucom) 56002ac6454SAndrew Thompson { 56102ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 56202ac6454SAndrew Thompson 56302ac6454SAndrew Thompson /* start read endpoint */ 56402ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 56502ac6454SAndrew Thompson return; 56602ac6454SAndrew Thompson } 56702ac6454SAndrew Thompson 56802ac6454SAndrew Thompson static void 56902ac6454SAndrew Thompson u3g_stop_read(struct usb2_com_softc *ucom) 57002ac6454SAndrew Thompson { 57102ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 57202ac6454SAndrew Thompson 57302ac6454SAndrew Thompson /* stop read endpoint */ 57402ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 57502ac6454SAndrew Thompson return; 57602ac6454SAndrew Thompson } 57702ac6454SAndrew Thompson 57802ac6454SAndrew Thompson static void 57902ac6454SAndrew Thompson u3g_start_write(struct usb2_com_softc *ucom) 58002ac6454SAndrew Thompson { 58102ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 58202ac6454SAndrew Thompson 58302ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 58402ac6454SAndrew Thompson return; 58502ac6454SAndrew Thompson } 58602ac6454SAndrew Thompson 58702ac6454SAndrew Thompson static void 58802ac6454SAndrew Thompson u3g_stop_write(struct usb2_com_softc *ucom) 58902ac6454SAndrew Thompson { 59002ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 59102ac6454SAndrew Thompson 59202ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 59302ac6454SAndrew Thompson return; 59402ac6454SAndrew Thompson } 59502ac6454SAndrew Thompson 59602ac6454SAndrew Thompson static void 59702ac6454SAndrew Thompson u3g_write_callback(struct usb2_xfer *xfer) 59802ac6454SAndrew Thompson { 59902ac6454SAndrew Thompson struct usb2_com_softc *ucom = xfer->priv_sc; 60002ac6454SAndrew Thompson uint32_t actlen; 60102ac6454SAndrew Thompson 60202ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 60302ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 60402ac6454SAndrew Thompson case USB_ST_SETUP: 60502ac6454SAndrew Thompson tr_setup: 60602ac6454SAndrew Thompson if (usb2_com_get_data(ucom, xfer->frbuffers, 0, 60702ac6454SAndrew Thompson U3G_BSIZE, &actlen)) { 60802ac6454SAndrew Thompson xfer->frlengths[0] = actlen; 60902ac6454SAndrew Thompson usb2_start_hardware(xfer); 61002ac6454SAndrew Thompson } 61102ac6454SAndrew Thompson break; 61202ac6454SAndrew Thompson 61302ac6454SAndrew Thompson default: /* Error */ 61402ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 61502ac6454SAndrew Thompson /* do a builtin clear-stall */ 61602ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 61702ac6454SAndrew Thompson goto tr_setup; 61802ac6454SAndrew Thompson } 61902ac6454SAndrew Thompson break; 62002ac6454SAndrew Thompson } 62102ac6454SAndrew Thompson return; 62202ac6454SAndrew Thompson } 62302ac6454SAndrew Thompson 62402ac6454SAndrew Thompson static void 62502ac6454SAndrew Thompson u3g_read_callback(struct usb2_xfer *xfer) 62602ac6454SAndrew Thompson { 62702ac6454SAndrew Thompson struct usb2_com_softc *ucom = xfer->priv_sc; 62802ac6454SAndrew Thompson 62902ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 63002ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 63102ac6454SAndrew Thompson usb2_com_put_data(ucom, xfer->frbuffers, 0, xfer->actlen); 63202ac6454SAndrew Thompson 63302ac6454SAndrew Thompson case USB_ST_SETUP: 63402ac6454SAndrew Thompson tr_setup: 63502ac6454SAndrew Thompson xfer->frlengths[0] = xfer->max_data_length; 63602ac6454SAndrew Thompson usb2_start_hardware(xfer); 63702ac6454SAndrew Thompson break; 63802ac6454SAndrew Thompson 63902ac6454SAndrew Thompson default: /* Error */ 64002ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 64102ac6454SAndrew Thompson /* do a builtin clear-stall */ 64202ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 64302ac6454SAndrew Thompson goto tr_setup; 64402ac6454SAndrew Thompson } 64502ac6454SAndrew Thompson break; 64602ac6454SAndrew Thompson } 64702ac6454SAndrew Thompson return; 64802ac6454SAndrew Thompson } 649