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