u3g.c (187970) | u3g.c (188413) |
---|---|
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 * | 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/usb2/serial/u3g2.c 187970 2009-02-01 00:51:25Z thompsa $ | 19 * $FreeBSD: head/sys/dev/usb2/serial/u3g2.c 188413 2009-02-09 22:05:25Z 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 * --- 55 unchanged lines hidden (view full) --- 83struct u3g_speeds_s { 84 uint32_t ispeed; 85 uint32_t ospeed; 86}; 87 88enum { 89 U3G_BULK_WR, 90 U3G_BULK_RD, | 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 * --- 55 unchanged lines hidden (view full) --- 83struct u3g_speeds_s { 84 uint32_t ispeed; 85 uint32_t ospeed; 86}; 87 88enum { 89 U3G_BULK_WR, 90 U3G_BULK_RD, |
91 U3G_N_TRANSFER = 2, | 91 U3G_N_TRANSFER, |
92}; 93 94struct u3g_softc { 95 struct usb2_com_super_softc sc_super_ucom; 96 struct usb2_com_softc sc_ucom[U3G_MAXPORTS]; 97 98 struct usb2_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER]; 99 struct usb2_device *sc_udev; 100 | 92}; 93 94struct u3g_softc { 95 struct usb2_com_super_softc sc_super_ucom; 96 struct usb2_com_softc sc_ucom[U3G_MAXPORTS]; 97 98 struct usb2_xfer *sc_xfer[U3G_MAXPORTS][U3G_N_TRANSFER]; 99 struct usb2_device *sc_udev; 100 |
101 uint8_t sc_iface_no; /* interface number */ 102 uint8_t sc_iface_index; /* interface index */ | |
103 uint8_t sc_lsr; /* local status register */ 104 uint8_t sc_msr; /* U3G status register */ | 101 uint8_t sc_lsr; /* local status register */ 102 uint8_t sc_msr; /* U3G status register */ |
105 struct u3g_speeds_s sc_speed; | |
106 uint8_t sc_numports; 107}; 108 109static device_probe_t u3g_probe; 110static device_attach_t u3g_attach; 111static device_detach_t u3g_detach; 112 113static usb2_callback_t u3g_write_callback; --- 29 unchanged lines hidden (view full) --- 143 144static const struct usb2_com_callback u3g_callback = { 145 .usb2_com_start_read = &u3g_start_read, 146 .usb2_com_stop_read = &u3g_stop_read, 147 .usb2_com_start_write = &u3g_start_write, 148 .usb2_com_stop_write = &u3g_stop_write, 149}; 150 | 103 uint8_t sc_numports; 104}; 105 106static device_probe_t u3g_probe; 107static device_attach_t u3g_attach; 108static device_detach_t u3g_detach; 109 110static usb2_callback_t u3g_write_callback; --- 29 unchanged lines hidden (view full) --- 140 141static const struct usb2_com_callback u3g_callback = { 142 .usb2_com_start_read = &u3g_start_read, 143 .usb2_com_stop_read = &u3g_stop_read, 144 .usb2_com_start_write = &u3g_start_write, 145 .usb2_com_stop_write = &u3g_stop_write, 146}; 147 |
148#if 0 |
|
151static const struct u3g_speeds_s u3g_speeds[U3GSP_MAX] = { 152 [U3GSP_GPRS] = {64000, 64000}, 153 [U3GSP_EDGE] = {384000, 64000}, 154 [U3GSP_CDMA] = {384000, 64000}, 155 [U3GSP_UMTS] = {384000, 64000}, 156 [U3GSP_HSDPA] = {1200000, 384000}, 157 [U3GSP_HSUPA] = {1200000, 384000}, 158 [U3GSP_HSPA] = {7200000, 384000}, 159}; | 149static const struct u3g_speeds_s u3g_speeds[U3GSP_MAX] = { 150 [U3GSP_GPRS] = {64000, 64000}, 151 [U3GSP_EDGE] = {384000, 64000}, 152 [U3GSP_CDMA] = {384000, 64000}, 153 [U3GSP_UMTS] = {384000, 64000}, 154 [U3GSP_HSDPA] = {1200000, 384000}, 155 [U3GSP_HSUPA] = {1200000, 384000}, 156 [U3GSP_HSPA] = {7200000, 384000}, 157}; |
158#endif |
|
160 161static device_method_t u3g_methods[] = { 162 DEVMETHOD(device_probe, u3g_probe), 163 DEVMETHOD(device_attach, u3g_attach), 164 DEVMETHOD(device_detach, u3g_detach), 165 {0, 0} 166}; 167 --- 212 unchanged lines hidden (view full) --- 380} 381 382static int 383u3g_attach(device_t dev) 384{ 385 struct usb2_config u3g_config_tmp[U3G_N_TRANSFER]; 386 struct usb2_attach_arg *uaa = device_get_ivars(dev); 387 struct u3g_softc *sc = device_get_softc(dev); | 159 160static device_method_t u3g_methods[] = { 161 DEVMETHOD(device_probe, u3g_probe), 162 DEVMETHOD(device_attach, u3g_attach), 163 DEVMETHOD(device_detach, u3g_detach), 164 {0, 0} 165}; 166 --- 212 unchanged lines hidden (view full) --- 379} 380 381static int 382u3g_attach(device_t dev) 383{ 384 struct usb2_config u3g_config_tmp[U3G_N_TRANSFER]; 385 struct usb2_attach_arg *uaa = device_get_ivars(dev); 386 struct u3g_softc *sc = device_get_softc(dev); |
388 uint8_t n; | 387 struct usb2_interface *iface; 388 struct usb2_interface_descriptor *id; |
389 uint8_t m; | 389 uint8_t m; |
390 uint8_t n; 391 uint8_t i; 392 uint8_t x; |
|
390 int error; 391 392 DPRINTF("sc=%p\n", sc); 393 394 /* copy in USB config */ 395 for (n = 0; n != U3G_N_TRANSFER; n++) 396 u3g_config_tmp[n] = u3g_config[n]; 397 398 device_set_usb2_desc(dev); 399 400 sc->sc_udev = uaa->device; | 393 int error; 394 395 DPRINTF("sc=%p\n", sc); 396 397 /* copy in USB config */ 398 for (n = 0; n != U3G_N_TRANSFER; n++) 399 u3g_config_tmp[n] = u3g_config[n]; 400 401 device_set_usb2_desc(dev); 402 403 sc->sc_udev = uaa->device; |
401 sc->sc_iface_no = uaa->info.bIfaceNum; 402 sc->sc_iface_index = uaa->info.bIfaceIndex; 403 sc->sc_speed = u3g_speeds[U3G_GET_SPEED(uaa)]; | |
404 | 404 |
405 for (m = 0; m != U3G_MAXPORTS; m++) { | 405 x = 0; /* interface index */ 406 i = 0; /* endpoint index */ 407 m = 0; /* number of ports */ |
406 | 408 |
409 while (m != U3G_MAXPORTS) { 410 |
|
407 /* update BULK endpoint index */ 408 for (n = 0; n != U3G_N_TRANSFER; n++) | 411 /* update BULK endpoint index */ 412 for (n = 0; n != U3G_N_TRANSFER; n++) |
409 u3g_config_tmp[n].ep_index = m; | 413 u3g_config_tmp[n].ep_index = i; |
410 | 414 |
415 iface = usb2_get_iface(uaa->device, x); 416 if (iface == NULL) { 417 if (m != 0) 418 break; /* end of interfaces */ 419 DPRINTF("did not find any modem endpoints\n"); 420 goto detach; 421 } 422 423 id = usb2_get_interface_descriptor(iface); 424 if ((id == NULL) || 425 (id->bInterfaceClass != UICLASS_VENDOR)) { 426 /* next interface */ 427 x++; 428 i = 0; 429 continue; 430 } 431 |
|
411 /* try to allocate a set of BULK endpoints */ | 432 /* try to allocate a set of BULK endpoints */ |
412 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index, | 433 error = usb2_transfer_setup(uaa->device, &x, |
413 sc->sc_xfer[m], u3g_config_tmp, U3G_N_TRANSFER, 414 &sc->sc_ucom[m], &Giant); | 434 sc->sc_xfer[m], u3g_config_tmp, U3G_N_TRANSFER, 435 &sc->sc_ucom[m], &Giant); |
415 | |
416 if (error) { | 436 if (error) { |
417 if (m != 0) 418 break; /* end of endpoints */ 419 DPRINTF("could not allocate all pipes\n"); 420 goto detach; | 437 /* next interface */ 438 x++; 439 i = 0; 440 continue; |
421 } | 441 } |
442 443 /* grab other interface, if any */ 444 if (x != uaa->info.bIfaceIndex) 445 usb2_set_parent_iface(uaa->device, x, 446 uaa->info.bIfaceIndex); 447 |
|
422 /* set stall by default */ 423 usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_WR]); 424 usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_RD]); | 448 /* set stall by default */ 449 usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_WR]); 450 usb2_transfer_set_stall(sc->sc_xfer[m][U3G_BULK_RD]); |
451 452 m++; /* found one port */ 453 i++; /* next endpoint index */ |
|
425 } 426 427 sc->sc_numports = m; 428 429 error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, 430 sc->sc_numports, sc, &u3g_callback, &Giant); 431 if (error) { 432 DPRINTF("usb2_com_attach failed\n"); --- 122 unchanged lines hidden --- | 454 } 455 456 sc->sc_numports = m; 457 458 error = usb2_com_attach(&sc->sc_super_ucom, sc->sc_ucom, 459 sc->sc_numports, sc, &u3g_callback, &Giant); 460 if (error) { 461 DPRINTF("usb2_com_attach failed\n"); --- 122 unchanged lines hidden --- |