u3g.c revision 193045
1/* 2 * Copyright (c) 2008 AnyWi Technologies 3 * Author: Andrea Guzzo <aguzzo@anywi.com> 4 * * based on uark.c 1.1 2006/08/14 08:30:22 jsg * 5 * * parts from ubsa.c 183348 2008-09-25 12:00:56Z phk * 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 * 19 * $FreeBSD: head/sys/dev/usb/serial/u3g.c 193045 2009-05-29 18:46:57Z thompsa $ 20 */ 21 22/* 23 * NOTE: 24 * 25 * - The detour through the tty layer is ridiculously expensive wrt 26 * buffering due to the high speeds. 27 * 28 * We should consider adding a simple r/w device which allows 29 * attaching of PPP in a more efficient way. 30 * 31 */ 32 33#include "usbdevs.h" 34#include <dev/usb/usb.h> 35#include <dev/usb/usb_mfunc.h> 36#include <dev/usb/usb_error.h> 37 38#define USB_DEBUG_VAR u3g_debug 39 40#include <dev/usb/usb_core.h> 41#include <dev/usb/usb_debug.h> 42#include <dev/usb/usb_process.h> 43#include <dev/usb/usb_request.h> 44#include <dev/usb/usb_lookup.h> 45#include <dev/usb/usb_util.h> 46#include <dev/usb/usb_busdma.h> 47#include <dev/usb/usb_msctest.h> 48#include <dev/usb/usb_dynamic.h> 49#include <dev/usb/usb_device.h> 50 51#include <dev/usb/serial/usb_serial.h> 52 53#if USB_DEBUG 54static int u3g_debug = 0; 55 56SYSCTL_NODE(_hw_usb, OID_AUTO, u3g, CTLFLAG_RW, 0, "USB 3g"); 57SYSCTL_INT(_hw_usb_u3g, OID_AUTO, debug, CTLFLAG_RW, 58 &u3g_debug, 0, "Debug level"); 59#endif 60 61#define U3G_MAXPORTS 8 62#define U3G_CONFIG_INDEX 0 63#define U3G_BSIZE 2048 64 65#define U3GSP_GPRS 0 66#define U3GSP_EDGE 1 67#define U3GSP_CDMA 2 68#define U3GSP_UMTS 3 69#define U3GSP_HSDPA 4 70#define U3GSP_HSUPA 5 71#define U3GSP_HSPA 6 72#define U3GSP_MAX 7 73 74#define U3GFL_HUAWEI_INIT 0x0001 /* Init command required */ 75#define U3GFL_SCSI_EJECT 0x0002 /* SCSI eject command required */ 76#define U3GFL_SIERRA_INIT 0x0004 /* Init command required */ 77#define U3GFL_SAEL_M460_INIT 0x0008 /* Init device */ 78 79enum { 80 U3G_BULK_WR, 81 U3G_BULK_RD, 82 U3G_N_TRANSFER, 83}; 84 85struct u3g_softc { 86 struct ucom_super_softc sc_super_ucom; 87 struct ucom_softc sc_ucom[U3G_MAXPORTS]; 88 89 struct usb_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER]; 90 struct usb_device *sc_udev; 91 struct mtx sc_mtx; 92 93 uint8_t sc_lsr; /* local status register */ 94 uint8_t sc_msr; /* U3G status register */ 95 uint8_t sc_numports; 96}; 97 98static device_probe_t u3g_probe; 99static device_attach_t u3g_attach; 100static device_detach_t u3g_detach; 101 102static usb_callback_t u3g_write_callback; 103static usb_callback_t u3g_read_callback; 104 105static void u3g_start_read(struct ucom_softc *ucom); 106static void u3g_stop_read(struct ucom_softc *ucom); 107static void u3g_start_write(struct ucom_softc *ucom); 108static void u3g_stop_write(struct ucom_softc *ucom); 109 110static int u3g_driver_loaded(struct module *mod, int what, void *arg); 111 112static const struct usb_config u3g_config[U3G_N_TRANSFER] = { 113 114 [U3G_BULK_WR] = { 115 .type = UE_BULK, 116 .endpoint = UE_ADDR_ANY, 117 .direction = UE_DIR_OUT, 118 .bufsize = U3G_BSIZE,/* bytes */ 119 .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 120 .callback = &u3g_write_callback, 121 }, 122 123 [U3G_BULK_RD] = { 124 .type = UE_BULK, 125 .endpoint = UE_ADDR_ANY, 126 .direction = UE_DIR_IN, 127 .bufsize = U3G_BSIZE,/* bytes */ 128 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 129 .callback = &u3g_read_callback, 130 }, 131}; 132 133static const struct ucom_callback u3g_callback = { 134 .usb2_com_start_read = &u3g_start_read, 135 .usb2_com_stop_read = &u3g_stop_read, 136 .usb2_com_start_write = &u3g_start_write, 137 .usb2_com_stop_write = &u3g_stop_write, 138}; 139 140static device_method_t u3g_methods[] = { 141 DEVMETHOD(device_probe, u3g_probe), 142 DEVMETHOD(device_attach, u3g_attach), 143 DEVMETHOD(device_detach, u3g_detach), 144 {0, 0} 145}; 146 147static devclass_t u3g_devclass; 148 149static driver_t u3g_driver = { 150 .name = "u3g", 151 .methods = u3g_methods, 152 .size = sizeof(struct u3g_softc), 153}; 154 155DRIVER_MODULE(u3g, uhub, u3g_driver, u3g_devclass, u3g_driver_loaded, 0); 156MODULE_DEPEND(u3g, ucom, 1, 1, 1); 157MODULE_DEPEND(u3g, usb, 1, 1, 1); 158 159static const struct usb_device_id u3g_devs[] = { 160#define U3G_DEV(v,p,i) { USB_VPI(USB_VENDOR_##v, USB_PRODUCT_##v##_##p, i) } 161 /* OEM: Option */ 162 U3G_DEV(OPTION, GT3G, 0), 163 U3G_DEV(OPTION, GT3GQUAD, 0), 164 U3G_DEV(OPTION, GT3GPLUS, 0), 165 U3G_DEV(OPTION, GTMAX36, 0), 166 U3G_DEV(OPTION, GTHSDPA, 0), 167 U3G_DEV(OPTION, GTMAXHSUPA, 0), 168 U3G_DEV(OPTION, VODAFONEMC3G, 0), 169 /* OEM: Qualcomm, Inc. */ 170 U3G_DEV(QUALCOMMINC, ZTE_STOR, U3GFL_SCSI_EJECT), 171 U3G_DEV(QUALCOMMINC, CDMA_MSM, U3GFL_SCSI_EJECT), 172 /* OEM: Huawei */ 173 U3G_DEV(HUAWEI, MOBILE, U3GFL_HUAWEI_INIT), 174 U3G_DEV(HUAWEI, E220, U3GFL_HUAWEI_INIT), 175 /* OEM: Novatel */ 176 U3G_DEV(NOVATEL, CDMA_MODEM, 0), 177 U3G_DEV(NOVATEL, ES620, 0), 178 U3G_DEV(NOVATEL, MC950D, 0), 179 U3G_DEV(NOVATEL, U720, 0), 180 U3G_DEV(NOVATEL, U727, 0), 181 U3G_DEV(NOVATEL, U740, 0), 182 U3G_DEV(NOVATEL, U740_2, 0), 183 U3G_DEV(NOVATEL, U870, 0), 184 U3G_DEV(NOVATEL, V620, 0), 185 U3G_DEV(NOVATEL, V640, 0), 186 U3G_DEV(NOVATEL, V720, 0), 187 U3G_DEV(NOVATEL, V740, 0), 188 U3G_DEV(NOVATEL, X950D, 0), 189 U3G_DEV(NOVATEL, XU870, 0), 190 U3G_DEV(NOVATEL, ZEROCD, U3GFL_SCSI_EJECT), 191 U3G_DEV(DELL, U740, 0), 192 /* OEM: Merlin */ 193 U3G_DEV(MERLIN, V620, 0), 194 /* OEM: Sierra Wireless: */ 195 U3G_DEV(SIERRA, AIRCARD580, 0), 196 U3G_DEV(SIERRA, AIRCARD595, 0), 197 U3G_DEV(SIERRA, AC595U, 0), 198 U3G_DEV(SIERRA, AC597E, 0), 199 U3G_DEV(SIERRA, C597, 0), 200 U3G_DEV(SIERRA, AC880, 0), 201 U3G_DEV(SIERRA, AC880E, 0), 202 U3G_DEV(SIERRA, AC880U, 0), 203 U3G_DEV(SIERRA, AC881, 0), 204 U3G_DEV(SIERRA, AC881E, 0), 205 U3G_DEV(SIERRA, AC881U, 0), 206 U3G_DEV(SIERRA, AC885U, 0), 207 U3G_DEV(SIERRA, EM5625, 0), 208 U3G_DEV(SIERRA, MC5720, 0), 209 U3G_DEV(SIERRA, MC5720_2, 0), 210 U3G_DEV(SIERRA, MC5725, 0), 211 U3G_DEV(SIERRA, MINI5725, 0), 212 U3G_DEV(SIERRA, AIRCARD875, 0), 213 U3G_DEV(SIERRA, MC8755, 0), 214 U3G_DEV(SIERRA, MC8755_2, 0), 215 U3G_DEV(SIERRA, MC8755_3, 0), 216 U3G_DEV(SIERRA, MC8765, 0), 217 U3G_DEV(SIERRA, AC875U, 0), 218 U3G_DEV(SIERRA, MC8775_2, 0), 219 U3G_DEV(SIERRA, MC8780, 0), 220 U3G_DEV(SIERRA, MC8781, 0), 221 U3G_DEV(HP, HS2300, 0), 222 /* Sierra TruInstaller device ID */ 223 U3G_DEV(SIERRA, TRUINSTALL, U3GFL_SIERRA_INIT), 224 /* PRUEBA SILABS */ 225 U3G_DEV(SILABS, SAEL, U3GFL_SAEL_M460_INIT), 226}; 227 228static void 229u3g_sierra_init(struct usb_device *udev) 230{ 231 struct usb_device_request req; 232 233 DPRINTFN(0, "\n"); 234 235 req.bmRequestType = UT_VENDOR; 236 req.bRequest = UR_SET_INTERFACE; 237 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 238 USETW(req.wIndex, UHF_PORT_CONNECTION); 239 USETW(req.wLength, 0); 240 241 if (usb2_do_request_flags(udev, NULL, &req, 242 NULL, 0, NULL, USB_MS_HZ)) { 243 /* ignore any errors */ 244 } 245 return; 246} 247 248static void 249u3g_huawei_init(struct usb_device *udev) 250{ 251 struct usb_device_request req; 252 253 DPRINTFN(0, "\n"); 254 255 req.bmRequestType = UT_WRITE_DEVICE; 256 req.bRequest = UR_SET_FEATURE; 257 USETW(req.wValue, UF_DEVICE_REMOTE_WAKEUP); 258 USETW(req.wIndex, UHF_PORT_SUSPEND); 259 USETW(req.wLength, 0); 260 261 if (usb2_do_request_flags(udev, NULL, &req, 262 NULL, 0, NULL, USB_MS_HZ)) { 263 /* ignore any errors */ 264 } 265 return; 266} 267 268static void 269u3g_sael_m460_init(struct usb_device *udev) 270{ 271 static const uint8_t setup[][24] = { 272 { 0x41, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 273 { 0x41, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 }, 274 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 275 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, 277 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02 }, 278 { 0xc1, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 }, 279 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 280 { 0xc1, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, 281 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 282 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 283 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 284 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 285 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 286 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 287 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 288 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 289 { 0x41, 0x12, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, 290 { 0x41, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 }, 291 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 292 { 0x41, 0x03, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, 293 { 0x41, 0x19, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 294 0x00, 0x00, 0x00, 0x00, 0x11, 0x13 }, 295 { 0x41, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 296 0x09, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 297 0x0a, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00 }, 298 { 0x41, 0x07, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }, 299 }; 300 301 struct usb_device_request req; 302 usb_error_t err; 303 uint16_t len; 304 uint8_t buf[0x300]; 305 uint8_t n; 306 307 DPRINTFN(1, "\n"); 308 309 if (usb2_req_set_alt_interface_no(udev, NULL, 0, 0)) { 310 DPRINTFN(0, "Alt setting 0 failed\n"); 311 return; 312 } 313 314 for (n = 0; n != (sizeof(setup)/sizeof(setup[0])); n++) { 315 316 memcpy(&req, setup[n], sizeof(req)); 317 318 len = UGETW(req.wLength); 319 if (req.bmRequestType & UE_DIR_IN) { 320 if (len > sizeof(buf)) { 321 DPRINTFN(0, "too small buffer\n"); 322 continue; 323 } 324 err = usb2_do_request(udev, NULL, &req, buf); 325 } else { 326 if (len > (sizeof(setup[0]) - 8)) { 327 DPRINTFN(0, "too small buffer\n"); 328 continue; 329 } 330 err = usb2_do_request(udev, NULL, &req, 331 __DECONST(uint8_t *, &setup[n][8])); 332 } 333 if (err) { 334 DPRINTFN(1, "request %u failed\n", 335 (unsigned int)n); 336 /* 337 * Some of the requests will fail. Stop doing 338 * requests when we are getting timeouts so 339 * that we don't block the explore/attach 340 * thread forever. 341 */ 342 if (err == USB_ERR_TIMEOUT) 343 break; 344 } 345 } 346} 347 348static int 349u3g_lookup_huawei(struct usb_attach_arg *uaa) 350{ 351 /* Calling the lookup function will also set the driver info! */ 352 return (usb2_lookup_id_by_uaa(u3g_devs, sizeof(u3g_devs), uaa)); 353} 354 355/* 356 * The following function handles 3G modem devices (E220, Mobile, 357 * etc.) with auto-install flash disks for Windows/MacOSX on the first 358 * interface. After some command or some delay they change appearance 359 * to a modem. 360 */ 361static usb_error_t 362u3g_test_huawei_autoinst(struct usb_device *udev, 363 struct usb_attach_arg *uaa) 364{ 365 struct usb_interface *iface; 366 struct usb_interface_descriptor *id; 367 uint32_t flags; 368 369 if (udev == NULL) { 370 return (USB_ERR_INVAL); 371 } 372 iface = usb2_get_iface(udev, 0); 373 if (iface == NULL) { 374 return (USB_ERR_INVAL); 375 } 376 id = iface->idesc; 377 if (id == NULL) { 378 return (USB_ERR_INVAL); 379 } 380 if (id->bInterfaceClass != UICLASS_MASS) { 381 return (USB_ERR_INVAL); 382 } 383 if (u3g_lookup_huawei(uaa)) { 384 /* no device match */ 385 return (USB_ERR_INVAL); 386 } 387 flags = USB_GET_DRIVER_INFO(uaa); 388 389 if (flags & U3GFL_HUAWEI_INIT) { 390 u3g_huawei_init(udev); 391 } else if (flags & U3GFL_SCSI_EJECT) { 392 return (usb2_test_autoinstall(udev, 0, 1)); 393 } else if (flags & U3GFL_SIERRA_INIT) { 394 u3g_sierra_init(udev); 395 } else { 396 /* no quirks */ 397 return (USB_ERR_INVAL); 398 } 399 return (0); /* success */ 400} 401 402static int 403u3g_driver_loaded(struct module *mod, int what, void *arg) 404{ 405 switch (what) { 406 case MOD_LOAD: 407 /* register our autoinstall handler */ 408 usb2_test_huawei_autoinst_p = &u3g_test_huawei_autoinst; 409 break; 410 case MOD_UNLOAD: 411 usb2_test_huawei_unload(NULL); 412 break; 413 default: 414 return (EOPNOTSUPP); 415 } 416 return (0); 417} 418 419static int 420u3g_probe(device_t self) 421{ 422 struct usb_attach_arg *uaa = device_get_ivars(self); 423 424 if (uaa->usb_mode != USB_MODE_HOST) { 425 return (ENXIO); 426 } 427 if (uaa->info.bConfigIndex != U3G_CONFIG_INDEX) { 428 return (ENXIO); 429 } 430 if (uaa->info.bInterfaceClass != UICLASS_VENDOR) { 431 return (ENXIO); 432 } 433 return (u3g_lookup_huawei(uaa)); 434} 435 436static int 437u3g_attach(device_t dev) 438{ 439 struct usb_config u3g_config_tmp[U3G_N_TRANSFER]; 440 struct usb_attach_arg *uaa = device_get_ivars(dev); 441 struct u3g_softc *sc = device_get_softc(dev); 442 struct usb_interface *iface; 443 struct usb_interface_descriptor *id; 444 uint32_t iface_valid; 445 int error, flags, nports; 446 int ep, n; 447 uint8_t i; 448 449 DPRINTF("sc=%p\n", sc); 450 451 flags = USB_GET_DRIVER_INFO(uaa); 452 453 if (flags & U3GFL_SAEL_M460_INIT) 454 u3g_sael_m460_init(uaa->device); 455 456 /* copy in USB config */ 457 for (n = 0; n != U3G_N_TRANSFER; n++) 458 u3g_config_tmp[n] = u3g_config[n]; 459 460 device_set_usb2_desc(dev); 461 mtx_init(&sc->sc_mtx, "u3g", NULL, MTX_DEF); 462 463 sc->sc_udev = uaa->device; 464 465 /* Claim all interfaces on the device */ 466 iface_valid = 0; 467 for (i = uaa->info.bIfaceIndex; i < USB_IFACE_MAX; i++) { 468 iface = usb2_get_iface(uaa->device, i); 469 if (iface == NULL) 470 break; 471 id = usb2_get_interface_descriptor(iface); 472 if (id == NULL || id->bInterfaceClass != UICLASS_VENDOR) 473 continue; 474 usb2_set_parent_iface(uaa->device, i, uaa->info.bIfaceIndex); 475 iface_valid |= (1<<i); 476 } 477 478 i = 0; /* interface index */ 479 ep = 0; /* endpoint index */ 480 nports = 0; /* number of ports */ 481 while (i < USB_IFACE_MAX) { 482 if ((iface_valid & (1<<i)) == 0) { 483 i++; 484 continue; 485 } 486 487 /* update BULK endpoint index */ 488 for (n = 0; n < U3G_N_TRANSFER; n++) 489 u3g_config_tmp[n].ep_index = ep; 490 491 /* try to allocate a set of BULK endpoints */ 492 error = usb2_transfer_setup(uaa->device, &i, 493 sc->sc_xfer[nports], u3g_config_tmp, U3G_N_TRANSFER, 494 &sc->sc_ucom[nports], &sc->sc_mtx); 495 if (error) { 496 /* next interface */ 497 i++; 498 ep = 0; 499 continue; 500 } 501 502 /* set stall by default */ 503 mtx_lock(&sc->sc_mtx); 504 usb2_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_WR]); 505 usb2_transfer_set_stall(sc->sc_xfer[nports][U3G_BULK_RD]); 506 mtx_unlock(&sc->sc_mtx); 507 508 nports++; /* found one port */ 509 ep++; 510 if (nports == U3G_MAXPORTS) 511 break; 512 } 513 if (nports == 0) { 514 device_printf(dev, "no ports found\n"); 515 goto detach; 516 } 517 sc->sc_numports = nports; 518 519 error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, 520 sc->sc_numports, sc, &u3g_callback, &sc->sc_mtx); 521 if (error) { 522 DPRINTF("usb2_com_attach failed\n"); 523 goto detach; 524 } 525 if (sc->sc_numports > 1) 526 device_printf(dev, "Found %u ports.\n", sc->sc_numports); 527 return (0); 528 529detach: 530 u3g_detach(dev); 531 return (ENXIO); 532} 533 534static int 535u3g_detach(device_t dev) 536{ 537 struct u3g_softc *sc = device_get_softc(dev); 538 uint8_t m; 539 540 DPRINTF("sc=%p\n", sc); 541 542 /* NOTE: It is not dangerous to detach more ports than attached! */ 543 usb2_com_detach(&sc->sc_super_ucom, sc->sc_ucom, U3G_MAXPORTS); 544 545 for (m = 0; m != U3G_MAXPORTS; m++) 546 usb2_transfer_unsetup(sc->sc_xfer[m], U3G_N_TRANSFER); 547 mtx_destroy(&sc->sc_mtx); 548 549 return (0); 550} 551 552static void 553u3g_start_read(struct ucom_softc *ucom) 554{ 555 struct u3g_softc *sc = ucom->sc_parent; 556 557 /* start read endpoint */ 558 usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 559 return; 560} 561 562static void 563u3g_stop_read(struct ucom_softc *ucom) 564{ 565 struct u3g_softc *sc = ucom->sc_parent; 566 567 /* stop read endpoint */ 568 usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_RD]); 569 return; 570} 571 572static void 573u3g_start_write(struct ucom_softc *ucom) 574{ 575 struct u3g_softc *sc = ucom->sc_parent; 576 577 usb2_transfer_start(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 578 return; 579} 580 581static void 582u3g_stop_write(struct ucom_softc *ucom) 583{ 584 struct u3g_softc *sc = ucom->sc_parent; 585 586 usb2_transfer_stop(sc->sc_xfer[ucom->sc_local_unit][U3G_BULK_WR]); 587 return; 588} 589 590static void 591u3g_write_callback(struct usb_xfer *xfer) 592{ 593 struct ucom_softc *ucom = xfer->priv_sc; 594 uint32_t actlen; 595 596 switch (USB_GET_STATE(xfer)) { 597 case USB_ST_TRANSFERRED: 598 case USB_ST_SETUP: 599tr_setup: 600 if (usb2_com_get_data(ucom, xfer->frbuffers, 0, 601 U3G_BSIZE, &actlen)) { 602 xfer->frlengths[0] = actlen; 603 usb2_start_hardware(xfer); 604 } 605 break; 606 607 default: /* Error */ 608 if (xfer->error != USB_ERR_CANCELLED) { 609 /* do a builtin clear-stall */ 610 xfer->flags.stall_pipe = 1; 611 goto tr_setup; 612 } 613 break; 614 } 615 return; 616} 617 618static void 619u3g_read_callback(struct usb_xfer *xfer) 620{ 621 struct ucom_softc *ucom = xfer->priv_sc; 622 623 switch (USB_GET_STATE(xfer)) { 624 case USB_ST_TRANSFERRED: 625 usb2_com_put_data(ucom, xfer->frbuffers, 0, xfer->actlen); 626 627 case USB_ST_SETUP: 628tr_setup: 629 xfer->frlengths[0] = xfer->max_data_length; 630 usb2_start_hardware(xfer); 631 break; 632 633 default: /* Error */ 634 if (xfer->error != USB_ERR_CANCELLED) { 635 /* do a builtin clear-stall */ 636 xfer->flags.stall_pipe = 1; 637 goto tr_setup; 638 } 639 break; 640 } 641 return; 642} 643