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 * NOTE: 3202ac6454SAndrew Thompson * 3302ac6454SAndrew Thompson * - The device ID's are stored in "core/usb2_msctest.c" 3402ac6454SAndrew Thompson */ 3502ac6454SAndrew Thompson 3602ac6454SAndrew Thompson #include "usbdevs.h" 3702ac6454SAndrew Thompson #include <dev/usb/usb.h> 3802ac6454SAndrew Thompson #include <dev/usb/usb_mfunc.h> 3902ac6454SAndrew Thompson #include <dev/usb/usb_error.h> 4002ac6454SAndrew Thompson #include <dev/usb/usb_defs.h> 4102ac6454SAndrew Thompson 4202ac6454SAndrew Thompson #define USB_DEBUG_VAR u3g_debug 4302ac6454SAndrew Thompson 4402ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 4502ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 4602ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 4702ac6454SAndrew Thompson #include <dev/usb/usb_request.h> 4802ac6454SAndrew Thompson #include <dev/usb/usb_lookup.h> 4902ac6454SAndrew Thompson #include <dev/usb/usb_util.h> 5002ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h> 5102ac6454SAndrew Thompson #include <dev/usb/usb_msctest.h> 5202ac6454SAndrew Thompson #include <dev/usb/usb_dynamic.h> 5302ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 5402ac6454SAndrew Thompson 5502ac6454SAndrew Thompson #include <dev/usb/serial/usb_serial.h> 5602ac6454SAndrew Thompson 5702ac6454SAndrew Thompson #if USB_DEBUG 5802ac6454SAndrew Thompson static int u3g_debug = 0; 5902ac6454SAndrew Thompson 6002ac6454SAndrew Thompson SYSCTL_NODE(_hw_usb2, OID_AUTO, u3g, CTLFLAG_RW, 0, "USB u3g"); 6102ac6454SAndrew Thompson SYSCTL_INT(_hw_usb2_u3g, OID_AUTO, debug, CTLFLAG_RW, 6202ac6454SAndrew Thompson &u3g_debug, 0, "u3g debug level"); 6302ac6454SAndrew Thompson #endif 6402ac6454SAndrew Thompson 6502ac6454SAndrew Thompson #define U3G_MAXPORTS 4 6602ac6454SAndrew Thompson #define U3G_CONFIG_INDEX 0 6702ac6454SAndrew Thompson #define U3G_BSIZE 2048 6802ac6454SAndrew Thompson 6902ac6454SAndrew Thompson #define U3GSP_GPRS 0 7002ac6454SAndrew Thompson #define U3GSP_EDGE 1 7102ac6454SAndrew Thompson #define U3GSP_CDMA 2 7202ac6454SAndrew Thompson #define U3GSP_UMTS 3 7302ac6454SAndrew Thompson #define U3GSP_HSDPA 4 7402ac6454SAndrew Thompson #define U3GSP_HSUPA 5 7502ac6454SAndrew Thompson #define U3GSP_HSPA 6 7602ac6454SAndrew Thompson #define U3GSP_MAX 7 7702ac6454SAndrew Thompson 7802ac6454SAndrew Thompson #define U3GFL_NONE 0x00 /* No flags */ 7902ac6454SAndrew Thompson #define U3GFL_HUAWEI_INIT 0x01 /* Init command required */ 8002ac6454SAndrew Thompson #define U3GFL_SCSI_EJECT 0x02 /* SCSI eject command required */ 8102ac6454SAndrew Thompson #define U3GFL_SIERRA_INIT 0x04 /* Init command required */ 8202ac6454SAndrew Thompson 8302ac6454SAndrew Thompson struct u3g_speeds_s { 8402ac6454SAndrew Thompson uint32_t ispeed; 8502ac6454SAndrew Thompson uint32_t ospeed; 8602ac6454SAndrew Thompson }; 8702ac6454SAndrew Thompson 8802ac6454SAndrew Thompson enum { 8902ac6454SAndrew Thompson U3G_BULK_WR, 9002ac6454SAndrew Thompson U3G_BULK_RD, 9102ac6454SAndrew Thompson U3G_N_TRANSFER, 9202ac6454SAndrew Thompson }; 9302ac6454SAndrew Thompson 9402ac6454SAndrew Thompson struct u3g_softc { 9502ac6454SAndrew Thompson struct usb2_com_super_softc sc_super_ucom; 9602ac6454SAndrew Thompson struct usb2_com_softc sc_ucom[U3G_MAXPORTS]; 9702ac6454SAndrew Thompson 9802ac6454SAndrew Thompson struct usb2_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER]; 9902ac6454SAndrew Thompson struct usb2_device *sc_udev; 10002ac6454SAndrew Thompson 10102ac6454SAndrew Thompson uint8_t sc_lsr; /* local status register */ 10202ac6454SAndrew Thompson uint8_t sc_msr; /* U3G status register */ 10302ac6454SAndrew Thompson uint8_t sc_numports; 10402ac6454SAndrew Thompson }; 10502ac6454SAndrew Thompson 10602ac6454SAndrew Thompson static device_probe_t u3g_probe; 10702ac6454SAndrew Thompson static device_attach_t u3g_attach; 10802ac6454SAndrew Thompson static device_detach_t u3g_detach; 10902ac6454SAndrew Thompson 11002ac6454SAndrew Thompson static usb2_callback_t u3g_write_callback; 11102ac6454SAndrew Thompson static usb2_callback_t u3g_read_callback; 11202ac6454SAndrew Thompson 11302ac6454SAndrew Thompson static void u3g_start_read(struct usb2_com_softc *ucom); 11402ac6454SAndrew Thompson static void u3g_stop_read(struct usb2_com_softc *ucom); 11502ac6454SAndrew Thompson static void u3g_start_write(struct usb2_com_softc *ucom); 11602ac6454SAndrew Thompson static void u3g_stop_write(struct usb2_com_softc *ucom); 11702ac6454SAndrew Thompson 11802ac6454SAndrew Thompson static int u3g_driver_loaded(struct module *mod, int what, void *arg); 11902ac6454SAndrew Thompson 12002ac6454SAndrew Thompson static const struct usb2_config u3g_config[U3G_N_TRANSFER] = { 12102ac6454SAndrew Thompson 12202ac6454SAndrew Thompson [U3G_BULK_WR] = { 12302ac6454SAndrew Thompson .type = UE_BULK, 12402ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 12502ac6454SAndrew Thompson .direction = UE_DIR_OUT, 12602ac6454SAndrew Thompson .mh.bufsize = U3G_BSIZE,/* bytes */ 12702ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 12802ac6454SAndrew Thompson .mh.callback = &u3g_write_callback, 12902ac6454SAndrew Thompson }, 13002ac6454SAndrew Thompson 13102ac6454SAndrew Thompson [U3G_BULK_RD] = { 13202ac6454SAndrew Thompson .type = UE_BULK, 13302ac6454SAndrew Thompson .endpoint = UE_ADDR_ANY, 13402ac6454SAndrew Thompson .direction = UE_DIR_IN, 13502ac6454SAndrew Thompson .mh.bufsize = U3G_BSIZE,/* bytes */ 13602ac6454SAndrew Thompson .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 13702ac6454SAndrew Thompson .mh.callback = &u3g_read_callback, 13802ac6454SAndrew Thompson }, 13902ac6454SAndrew Thompson }; 14002ac6454SAndrew Thompson 14102ac6454SAndrew Thompson static const struct usb2_com_callback u3g_callback = { 14202ac6454SAndrew Thompson .usb2_com_start_read = &u3g_start_read, 14302ac6454SAndrew Thompson .usb2_com_stop_read = &u3g_stop_read, 14402ac6454SAndrew Thompson .usb2_com_start_write = &u3g_start_write, 14502ac6454SAndrew Thompson .usb2_com_stop_write = &u3g_stop_write, 14602ac6454SAndrew Thompson }; 14702ac6454SAndrew Thompson 14802ac6454SAndrew Thompson #if 0 14902ac6454SAndrew Thompson static const struct u3g_speeds_s u3g_speeds[U3GSP_MAX] = { 15002ac6454SAndrew Thompson [U3GSP_GPRS] = {64000, 64000}, 15102ac6454SAndrew Thompson [U3GSP_EDGE] = {384000, 64000}, 15202ac6454SAndrew Thompson [U3GSP_CDMA] = {384000, 64000}, 15302ac6454SAndrew Thompson [U3GSP_UMTS] = {384000, 64000}, 15402ac6454SAndrew Thompson [U3GSP_HSDPA] = {1200000, 384000}, 15502ac6454SAndrew Thompson [U3GSP_HSUPA] = {1200000, 384000}, 15602ac6454SAndrew Thompson [U3GSP_HSPA] = {7200000, 384000}, 15702ac6454SAndrew Thompson }; 15802ac6454SAndrew Thompson #endif 15902ac6454SAndrew Thompson 16002ac6454SAndrew Thompson static device_method_t u3g_methods[] = { 16102ac6454SAndrew Thompson DEVMETHOD(device_probe, u3g_probe), 16202ac6454SAndrew Thompson DEVMETHOD(device_attach, u3g_attach), 16302ac6454SAndrew Thompson DEVMETHOD(device_detach, u3g_detach), 16402ac6454SAndrew Thompson {0, 0} 16502ac6454SAndrew Thompson }; 16602ac6454SAndrew Thompson 16702ac6454SAndrew Thompson static devclass_t u3g_devclass; 16802ac6454SAndrew Thompson 16902ac6454SAndrew Thompson static driver_t u3g_driver = { 17002ac6454SAndrew Thompson .name = "u3g", 17102ac6454SAndrew Thompson .methods = u3g_methods, 17202ac6454SAndrew Thompson .size = sizeof(struct u3g_softc), 17302ac6454SAndrew Thompson }; 17402ac6454SAndrew Thompson 17502ac6454SAndrew Thompson DRIVER_MODULE(u3g, ushub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0); 17602ac6454SAndrew Thompson MODULE_DEPEND(u3g, ucom, 1, 1, 1); 17702ac6454SAndrew Thompson MODULE_DEPEND(u3g, usb, 1, 1, 1); 17802ac6454SAndrew Thompson 17902ac6454SAndrew Thompson /* Huawei specific defines */ 18002ac6454SAndrew Thompson 18102ac6454SAndrew Thompson #define U3GINFO(flag,speed) ((flag)|((speed) * 256)) 18202ac6454SAndrew Thompson #define U3G_GET_SPEED(uaa) (USB_GET_DRIVER_INFO(uaa) / 256) 18302ac6454SAndrew Thompson 18402ac6454SAndrew Thompson /* 18502ac6454SAndrew Thompson * NOTE: The entries marked with XXX should be checked for the correct 18602ac6454SAndrew Thompson * speed indication to set the buffer sizes. 18702ac6454SAndrew Thompson */ 18802ac6454SAndrew Thompson static const struct usb2_device_id u3g_devs[] = { 18902ac6454SAndrew Thompson /* OEM: Option */ 19002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3G, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, 19102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GQUAD, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, 19202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GT3GPLUS, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, 19302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTMAX36, U3GINFO(U3GSP_HSDPA, U3GFL_NONE))}, 19402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_GTMAXHSUPA, U3GINFO(U3GSP_HSDPA, U3GFL_NONE))}, 19502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_OPTION, USB_PRODUCT_OPTION_VODAFONEMC3G, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, 19602ac6454SAndrew Thompson /* OEM: Qualcomm, Inc. */ 19702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_ZTE_STOR, U3GINFO(U3GSP_CDMA, U3GFL_SCSI_EJECT))}, 19802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_QUALCOMMINC, USB_PRODUCT_QUALCOMMINC_CDMA_MSM, U3GINFO(U3GSP_CDMA, U3GFL_SCSI_EJECT))}, 19902ac6454SAndrew Thompson /* OEM: Huawei */ 20002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_MOBILE, U3GINFO(U3GSP_HSDPA, U3GFL_HUAWEI_INIT))}, 20102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220, U3GINFO(U3GSP_HSPA, U3GFL_HUAWEI_INIT))}, 20202ac6454SAndrew Thompson /* OEM: Novatel */ 20302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_CDMA_MODEM, U3GINFO(U3GSP_CDMA, U3GFL_SCSI_EJECT))}, 20402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ES620, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 20502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_MC950D, U3GINFO(U3GSP_HSUPA, U3GFL_SCSI_EJECT))}, 20602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U720, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 20702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U727, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 20802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U740, U3GINFO(U3GSP_HSDPA, U3GFL_SCSI_EJECT))}, 20902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U740_2, U3GINFO(U3GSP_HSDPA, U3GFL_SCSI_EJECT))}, 21002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_U870, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 21102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V620, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 21202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V640, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 21302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V720, U3GINFO(U3GSP_UMTS, U3GFL_SCSI_EJECT))}, /* XXX */ 21402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_V740, U3GINFO(U3GSP_HSDPA, U3GFL_SCSI_EJECT))}, 21502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_X950D, U3GINFO(U3GSP_HSUPA, U3GFL_SCSI_EJECT))}, 21602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_XU870, U3GINFO(U3GSP_HSDPA, U3GFL_SCSI_EJECT))}, 21702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_NOVATEL, USB_PRODUCT_NOVATEL_ZEROCD, U3GINFO(U3GSP_HSUPA, U3GFL_SCSI_EJECT))}, 21802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_DELL, USB_PRODUCT_DELL_U740, U3GINFO(U3GSP_HSDPA, U3GFL_SCSI_EJECT))}, 21902ac6454SAndrew Thompson /* OEM: Merlin */ 22002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_MERLIN, USB_PRODUCT_MERLIN_V620, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22102ac6454SAndrew Thompson /* OEM: Sierra Wireless: */ 22202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD580, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD595, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC595U, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC597E, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_C597, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880E, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 22902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC880U, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881E, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC881U, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_EM5625, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5720_2, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC5725, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MINI5725, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AIRCARD875, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 23902ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_2, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24102ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8755_3, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24202ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8765, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24302ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_AC875U, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24402ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8775_2, U3GINFO(U3GSP_HSDPA, U3GFL_NONE))}, /* XXX */ 24502ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HS2300, U3GINFO(U3GSP_HSDPA, U3GFL_NONE))}, 24602ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8780, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24702ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_MC8781, U3GINFO(U3GSP_UMTS, U3GFL_NONE))}, /* XXX */ 24802ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_HP, USB_PRODUCT_HP_HS2300, U3GINFO(U3GSP_HSPA, U3GFL_NONE))}, /* XXX */ 24902ac6454SAndrew Thompson /* Sierra TruInstaller device ID */ 25002ac6454SAndrew Thompson {USB_VPI(USB_VENDOR_SIERRA, USB_PRODUCT_SIERRA_TRUINSTALL, U3GINFO(U3GSP_UMTS, U3GFL_SIERRA_INIT))}, 25102ac6454SAndrew Thompson }; 25202ac6454SAndrew Thompson 25302ac6454SAndrew Thompson static void 25402ac6454SAndrew Thompson u3g_sierra_init(struct usb2_device *udev) 25502ac6454SAndrew Thompson { 25602ac6454SAndrew Thompson struct usb2_device_request req; 25702ac6454SAndrew Thompson 25802ac6454SAndrew Thompson DPRINTFN(0, "\n"); 25902ac6454SAndrew Thompson 26002ac6454SAndrew Thompson req.bmRequestType = UT_VENDOR; 26102ac6454SAndrew Thompson req.bRequest = UR_SET_INTERFACE; 26202ac6454SAndrew Thompson USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 26302ac6454SAndrew Thompson USETW(req.wIndex, UHF_PORT_CONNECTION); 26402ac6454SAndrew Thompson USETW(req.wLength, 0); 26502ac6454SAndrew Thompson 26602ac6454SAndrew Thompson if (usb2_do_request_flags(udev, NULL, &req, 26702ac6454SAndrew Thompson NULL, 0, NULL, USB_MS_HZ)) { 26802ac6454SAndrew Thompson /* ignore any errors */ 26902ac6454SAndrew Thompson } 27002ac6454SAndrew Thompson return; 27102ac6454SAndrew Thompson } 27202ac6454SAndrew Thompson 27302ac6454SAndrew Thompson static void 27402ac6454SAndrew Thompson u3g_huawei_init(struct usb2_device *udev) 27502ac6454SAndrew Thompson { 27602ac6454SAndrew Thompson struct usb2_device_request req; 27702ac6454SAndrew Thompson 27802ac6454SAndrew Thompson DPRINTFN(0, "\n"); 27902ac6454SAndrew Thompson 28002ac6454SAndrew Thompson req.bmRequestType = UT_WRITE_DEVICE; 28102ac6454SAndrew Thompson req.bRequest = UR_SET_FEATURE; 28202ac6454SAndrew Thompson USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 28302ac6454SAndrew Thompson USETW(req.wIndex, UHF_PORT_SUSPEND); 28402ac6454SAndrew Thompson USETW(req.wLength, 0); 28502ac6454SAndrew Thompson 28602ac6454SAndrew Thompson if (usb2_do_request_flags(udev, NULL, &req, 28702ac6454SAndrew Thompson NULL, 0, NULL, USB_MS_HZ)) { 28802ac6454SAndrew Thompson /* ignore any errors */ 28902ac6454SAndrew Thompson } 29002ac6454SAndrew Thompson return; 29102ac6454SAndrew Thompson } 29202ac6454SAndrew Thompson 29302ac6454SAndrew Thompson static int 29402ac6454SAndrew Thompson u3g_lookup_huawei(struct usb2_attach_arg *uaa) 29502ac6454SAndrew Thompson { 29602ac6454SAndrew Thompson /* Calling the lookup function will also set the driver info! */ 29702ac6454SAndrew Thompson return (usb2_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)); 29802ac6454SAndrew Thompson } 29902ac6454SAndrew Thompson 30002ac6454SAndrew Thompson /* 30102ac6454SAndrew Thompson * The following function handles 3G modem devices (E220, Mobile, 30202ac6454SAndrew Thompson * etc.) with auto-install flash disks for Windows/MacOSX on the first 30302ac6454SAndrew Thompson * interface. After some command or some delay they change appearance 30402ac6454SAndrew Thompson * to a modem. 30502ac6454SAndrew Thompson */ 30602ac6454SAndrew Thompson static usb2_error_t 30702ac6454SAndrew Thompson u3g_test_huawei_autoinst(struct usb2_device *udev, 30802ac6454SAndrew Thompson struct usb2_attach_arg *uaa) 30902ac6454SAndrew Thompson { 31002ac6454SAndrew Thompson struct usb2_interface *iface; 31102ac6454SAndrew Thompson struct usb2_interface_descriptor *id; 31202ac6454SAndrew Thompson uint32_t flags; 31302ac6454SAndrew Thompson 31402ac6454SAndrew Thompson if (udev == NULL) { 31502ac6454SAndrew Thompson return (USB_ERR_INVAL); 31602ac6454SAndrew Thompson } 31702ac6454SAndrew Thompson iface = usb2_get_iface(udev, 0); 31802ac6454SAndrew Thompson if (iface == NULL) { 31902ac6454SAndrew Thompson return (USB_ERR_INVAL); 32002ac6454SAndrew Thompson } 32102ac6454SAndrew Thompson id = iface->idesc; 32202ac6454SAndrew Thompson if (id == NULL) { 32302ac6454SAndrew Thompson return (USB_ERR_INVAL); 32402ac6454SAndrew Thompson } 32502ac6454SAndrew Thompson if (id->bInterfaceClass != UICLASS_MASS) { 32602ac6454SAndrew Thompson return (USB_ERR_INVAL); 32702ac6454SAndrew Thompson } 32802ac6454SAndrew Thompson if (u3g_lookup_huawei(uaa)) { 32902ac6454SAndrew Thompson /* no device match */ 33002ac6454SAndrew Thompson return (USB_ERR_INVAL); 33102ac6454SAndrew Thompson } 33202ac6454SAndrew Thompson flags = USB_GET_DRIVER_INFO(uaa); 33302ac6454SAndrew Thompson 33402ac6454SAndrew Thompson if (flags & U3GFL_HUAWEI_INIT) { 33502ac6454SAndrew Thompson u3g_huawei_init(udev); 33602ac6454SAndrew Thompson } else if (flags & U3GFL_SCSI_EJECT) { 33702ac6454SAndrew Thompson return (usb2_test_autoinstall(udev, 0, 1)); 33802ac6454SAndrew Thompson } else if (flags & U3GFL_SIERRA_INIT) { 33902ac6454SAndrew Thompson u3g_sierra_init(udev); 34002ac6454SAndrew Thompson } else { 34102ac6454SAndrew Thompson /* no quirks */ 34202ac6454SAndrew Thompson return (USB_ERR_INVAL); 34302ac6454SAndrew Thompson } 34402ac6454SAndrew Thompson return (0); /* success */ 34502ac6454SAndrew Thompson } 34602ac6454SAndrew Thompson 34702ac6454SAndrew Thompson static int 34802ac6454SAndrew Thompson u3g_driver_loaded(struct module *mod, int what, void *arg) 34902ac6454SAndrew Thompson { 35002ac6454SAndrew Thompson switch (what) { 35102ac6454SAndrew Thompson case MOD_LOAD: 35202ac6454SAndrew Thompson /* register our autoinstall handler */ 35302ac6454SAndrew Thompson usb2_test_huawei_autoinst_p = &u3g_test_huawei_autoinst; 35402ac6454SAndrew Thompson break; 35502ac6454SAndrew Thompson case MOD_UNLOAD: 35602ac6454SAndrew Thompson usb2_test_huawei_unload(NULL); 35702ac6454SAndrew Thompson break; 35802ac6454SAndrew Thompson default: 35902ac6454SAndrew Thompson return (EOPNOTSUPP); 36002ac6454SAndrew Thompson } 36102ac6454SAndrew Thompson return (0); 36202ac6454SAndrew Thompson } 36302ac6454SAndrew Thompson 36402ac6454SAndrew Thompson static int 36502ac6454SAndrew Thompson u3g_probe(device_t self) 36602ac6454SAndrew Thompson { 36702ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(self); 36802ac6454SAndrew Thompson 36902ac6454SAndrew Thompson if (uaa->usb2_mode != USB_MODE_HOST) { 37002ac6454SAndrew Thompson return (ENXIO); 37102ac6454SAndrew Thompson } 37202ac6454SAndrew Thompson if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) { 37302ac6454SAndrew Thompson return (ENXIO); 37402ac6454SAndrew Thompson } 37502ac6454SAndrew Thompson if (uaa->info.bInterfaceClass != UICLASS_VENDOR) { 37602ac6454SAndrew Thompson return (ENXIO); 37702ac6454SAndrew Thompson } 37802ac6454SAndrew Thompson return (u3g_lookup_huawei(uaa)); 37902ac6454SAndrew Thompson } 38002ac6454SAndrew Thompson 38102ac6454SAndrew Thompson static int 38202ac6454SAndrew Thompson u3g_attach(device_t dev) 38302ac6454SAndrew Thompson { 38402ac6454SAndrew Thompson struct usb2_config u3g_config_tmp[U3G_N_TRANSFER]; 38502ac6454SAndrew Thompson struct usb2_attach_arg *uaa = device_get_ivars(dev); 38602ac6454SAndrew Thompson struct u3g_softc *sc = device_get_softc(dev); 38702ac6454SAndrew Thompson struct usb2_interface *iface; 38802ac6454SAndrew Thompson struct usb2_interface_descriptor *id; 38902ac6454SAndrew Thompson uint8_t m; 39002ac6454SAndrew Thompson uint8_t n; 39102ac6454SAndrew Thompson uint8_t i; 39202ac6454SAndrew Thompson uint8_t x; 39302ac6454SAndrew Thompson int error; 39402ac6454SAndrew Thompson 39502ac6454SAndrew Thompson DPRINTF("sc=%p\n", sc); 39602ac6454SAndrew Thompson 39702ac6454SAndrew Thompson /* copy in USB config */ 39802ac6454SAndrew Thompson for (n = 0; n != U3G_N_TRANSFER; n++) 39902ac6454SAndrew Thompson u3g_config_tmp[n] = u3g_config[n]; 40002ac6454SAndrew Thompson 40102ac6454SAndrew Thompson device_set_usb2_desc(dev); 40202ac6454SAndrew Thompson 40302ac6454SAndrew Thompson sc->sc_udev = uaa->device; 40402ac6454SAndrew Thompson 40502ac6454SAndrew Thompson x = 0; /* interface index */ 40602ac6454SAndrew Thompson i = 0; /* endpoint index */ 40702ac6454SAndrew Thompson m = 0; /* number of ports */ 40802ac6454SAndrew Thompson 40902ac6454SAndrew Thompson while (m != U3G_MAXPORTS) { 41002ac6454SAndrew Thompson 41102ac6454SAndrew Thompson /* update BULK endpoint index */ 41202ac6454SAndrew Thompson for (n = 0; n != U3G_N_TRANSFER; n++) 41302ac6454SAndrew Thompson u3g_config_tmp[n].ep_index = i; 41402ac6454SAndrew Thompson 41502ac6454SAndrew Thompson iface = usb2_get_iface(uaa->device, x); 41602ac6454SAndrew Thompson if (iface == NULL) { 41702ac6454SAndrew Thompson if (m != 0) 41802ac6454SAndrew Thompson break; /* end of interfaces */ 41902ac6454SAndrew Thompson DPRINTF("did not find any modem endpoints\n"); 42002ac6454SAndrew Thompson goto detach; 42102ac6454SAndrew Thompson } 42202ac6454SAndrew Thompson 42302ac6454SAndrew Thompson id = usb2_get_interface_descriptor(iface); 42402ac6454SAndrew Thompson if ((id == NULL) || 42502ac6454SAndrew Thompson (id->bInterfaceClass != UICLASS_VENDOR)) { 42602ac6454SAndrew Thompson /* next interface */ 42702ac6454SAndrew Thompson x++; 42802ac6454SAndrew Thompson i = 0; 42902ac6454SAndrew Thompson continue; 43002ac6454SAndrew Thompson } 43102ac6454SAndrew Thompson 43202ac6454SAndrew Thompson /* try to allocate a set of BULK endpoints */ 43302ac6454SAndrew Thompson error = usb2_transfer_setup(uaa->device, &x, 43402ac6454SAndrew Thompson sc->sc_xfer[m], u3g_config_tmp, U3G_N_TRANSFER, 43502ac6454SAndrew Thompson &sc->sc_ucom[m], &Giant); 43602ac6454SAndrew Thompson if (error) { 43702ac6454SAndrew Thompson /* next interface */ 43802ac6454SAndrew Thompson x++; 43902ac6454SAndrew Thompson i = 0; 44002ac6454SAndrew Thompson continue; 44102ac6454SAndrew Thompson } 44202ac6454SAndrew Thompson 44302ac6454SAndrew Thompson /* grab other interface, if any */ 44402ac6454SAndrew Thompson if (x != uaa->info.bIfaceIndex) 44502ac6454SAndrew Thompson usb2_set_parent_iface(uaa->device, x, 44602ac6454SAndrew Thompson uaa->info.bIfaceIndex); 44702ac6454SAndrew Thompson 44802ac6454SAndrew Thompson /* set stall by default */ 44902ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_WR]); 45002ac6454SAndrew Thompson usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_RD]); 45102ac6454SAndrew Thompson 45202ac6454SAndrew Thompson m++; /* found one port */ 45302ac6454SAndrew Thompson i++; /* next endpoint index */ 45402ac6454SAndrew Thompson } 45502ac6454SAndrew Thompson 45602ac6454SAndrew Thompson sc->sc_numports = m; 45702ac6454SAndrew Thompson 45802ac6454SAndrew Thompson error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, 45902ac6454SAndrew Thompson sc->sc_numports, sc, &u3g_callback, &Giant); 46002ac6454SAndrew Thompson if (error) { 46102ac6454SAndrew Thompson DPRINTF("usb2_com_attach failed\n"); 46202ac6454SAndrew Thompson goto detach; 46302ac6454SAndrew Thompson } 46402ac6454SAndrew Thompson if (sc->sc_numports != 1) { 46502ac6454SAndrew Thompson /* be verbose */ 46602ac6454SAndrew Thompson device_printf(dev, "Found %u ports.\n", 46702ac6454SAndrew Thompson (unsigned int)sc->sc_numports); 46802ac6454SAndrew Thompson } 46902ac6454SAndrew Thompson return (0); 47002ac6454SAndrew Thompson 47102ac6454SAndrew Thompson detach: 47202ac6454SAndrew Thompson u3g_detach(dev); 47302ac6454SAndrew Thompson return (ENXIO); 47402ac6454SAndrew Thompson } 47502ac6454SAndrew Thompson 47602ac6454SAndrew Thompson static int 47702ac6454SAndrew Thompson u3g_detach(device_t dev) 47802ac6454SAndrew Thompson { 47902ac6454SAndrew Thompson struct u3g_softc *sc = device_get_softc(dev); 48002ac6454SAndrew Thompson uint8_t m; 48102ac6454SAndrew Thompson 48202ac6454SAndrew Thompson DPRINTF("sc=%p\n", sc); 48302ac6454SAndrew Thompson 48402ac6454SAndrew Thompson /* NOTE: It is not dangerous to detach more ports than attached! */ 48502ac6454SAndrew Thompson usb2_com_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS); 48602ac6454SAndrew Thompson 48702ac6454SAndrew Thompson for (m = 0; m != U3G_MAXPORTS; m++) 48802ac6454SAndrew Thompson usb2_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER); 48902ac6454SAndrew Thompson 49002ac6454SAndrew Thompson return (0); 49102ac6454SAndrew Thompson } 49202ac6454SAndrew Thompson 49302ac6454SAndrew Thompson static void 49402ac6454SAndrew Thompson u3g_start_read(struct usb2_com_softc *ucom) 49502ac6454SAndrew Thompson { 49602ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 49702ac6454SAndrew Thompson 49802ac6454SAndrew Thompson /* start read endpoint */ 49902ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 50002ac6454SAndrew Thompson return; 50102ac6454SAndrew Thompson } 50202ac6454SAndrew Thompson 50302ac6454SAndrew Thompson static void 50402ac6454SAndrew Thompson u3g_stop_read(struct usb2_com_softc *ucom) 50502ac6454SAndrew Thompson { 50602ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 50702ac6454SAndrew Thompson 50802ac6454SAndrew Thompson /* stop read endpoint */ 50902ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 51002ac6454SAndrew Thompson return; 51102ac6454SAndrew Thompson } 51202ac6454SAndrew Thompson 51302ac6454SAndrew Thompson static void 51402ac6454SAndrew Thompson u3g_start_write(struct usb2_com_softc *ucom) 51502ac6454SAndrew Thompson { 51602ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 51702ac6454SAndrew Thompson 51802ac6454SAndrew Thompson usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 51902ac6454SAndrew Thompson return; 52002ac6454SAndrew Thompson } 52102ac6454SAndrew Thompson 52202ac6454SAndrew Thompson static void 52302ac6454SAndrew Thompson u3g_stop_write(struct usb2_com_softc *ucom) 52402ac6454SAndrew Thompson { 52502ac6454SAndrew Thompson struct u3g_softc *sc = ucom->sc_parent; 52602ac6454SAndrew Thompson 52702ac6454SAndrew Thompson usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 52802ac6454SAndrew Thompson return; 52902ac6454SAndrew Thompson } 53002ac6454SAndrew Thompson 53102ac6454SAndrew Thompson static void 53202ac6454SAndrew Thompson u3g_write_callback(struct usb2_xfer *xfer) 53302ac6454SAndrew Thompson { 53402ac6454SAndrew Thompson struct usb2_com_softc *ucom = xfer->priv_sc; 53502ac6454SAndrew Thompson uint32_t actlen; 53602ac6454SAndrew Thompson 53702ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 53802ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 53902ac6454SAndrew Thompson case USB_ST_SETUP: 54002ac6454SAndrew Thompson tr_setup: 54102ac6454SAndrew Thompson if (usb2_com_get_data(ucom, xfer->frbuffers, 0, 54202ac6454SAndrew Thompson U3G_BSIZE, &actlen)) { 54302ac6454SAndrew Thompson xfer->frlengths[0] = actlen; 54402ac6454SAndrew Thompson usb2_start_hardware(xfer); 54502ac6454SAndrew Thompson } 54602ac6454SAndrew Thompson break; 54702ac6454SAndrew Thompson 54802ac6454SAndrew Thompson default: /* Error */ 54902ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 55002ac6454SAndrew Thompson /* do a builtin clear-stall */ 55102ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 55202ac6454SAndrew Thompson goto tr_setup; 55302ac6454SAndrew Thompson } 55402ac6454SAndrew Thompson break; 55502ac6454SAndrew Thompson } 55602ac6454SAndrew Thompson return; 55702ac6454SAndrew Thompson } 55802ac6454SAndrew Thompson 55902ac6454SAndrew Thompson static void 56002ac6454SAndrew Thompson u3g_read_callback(struct usb2_xfer *xfer) 56102ac6454SAndrew Thompson { 56202ac6454SAndrew Thompson struct usb2_com_softc *ucom = xfer->priv_sc; 56302ac6454SAndrew Thompson 56402ac6454SAndrew Thompson switch (USB_GET_STATE(xfer)) { 56502ac6454SAndrew Thompson case USB_ST_TRANSFERRED: 56602ac6454SAndrew Thompson usb2_com_put_data(ucom, xfer->frbuffers, 0, xfer->actlen); 56702ac6454SAndrew Thompson 56802ac6454SAndrew Thompson case USB_ST_SETUP: 56902ac6454SAndrew Thompson tr_setup: 57002ac6454SAndrew Thompson xfer->frlengths[0] = xfer->max_data_length; 57102ac6454SAndrew Thompson usb2_start_hardware(xfer); 57202ac6454SAndrew Thompson break; 57302ac6454SAndrew Thompson 57402ac6454SAndrew Thompson default: /* Error */ 57502ac6454SAndrew Thompson if (xfer->error != USB_ERR_CANCELLED) { 57602ac6454SAndrew Thompson /* do a builtin clear-stall */ 57702ac6454SAndrew Thompson xfer->flags.stall_pipe = 1; 57802ac6454SAndrew Thompson goto tr_setup; 57902ac6454SAndrew Thompson } 58002ac6454SAndrew Thompson break; 58102ac6454SAndrew Thompson } 58202ac6454SAndrew Thompson return; 58302ac6454SAndrew Thompson } 584