ubsa.c revision 190749
1/*- 2 * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> 28__FBSDID("$FreeBSD: head/sys/dev/usb/serial/ubsa.c 190749 2009-04-05 21:24:15Z piso $"); 29/*- 30 * Copyright (c) 2001 The NetBSD Foundation, Inc. 31 * All rights reserved. 32 * 33 * This code is derived from software contributed to The NetBSD Foundation 34 * by Ichiro FUKUHARA (ichiro@ichiro.org). 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. All advertising materials mentioning features or use of this software 45 * must display the following acknowledgement: 46 * This product includes software developed by the NetBSD 47 * Foundation, Inc. and its contributors. 48 * 4. Neither the name of The NetBSD Foundation nor the names of its 49 * contributors may be used to endorse or promote products derived 50 * from this software without specific prior written permission. 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 53 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 54 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 55 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 56 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 57 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 58 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 59 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 60 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 61 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 62 * POSSIBILITY OF SUCH DAMAGE. 63 */ 64 65#include "usbdevs.h" 66#include <dev/usb/usb.h> 67#include <dev/usb/usb_mfunc.h> 68#include <dev/usb/usb_error.h> 69#include <dev/usb/usb_cdc.h> 70 71#define USB_DEBUG_VAR ubsa_debug 72 73#include <dev/usb/usb_core.h> 74#include <dev/usb/usb_debug.h> 75#include <dev/usb/usb_process.h> 76#include <dev/usb/usb_request.h> 77#include <dev/usb/usb_lookup.h> 78#include <dev/usb/usb_util.h> 79#include <dev/usb/usb_busdma.h> 80 81#include <dev/usb/serial/usb_serial.h> 82 83#if USB_DEBUG 84static int ubsa_debug = 0; 85 86SYSCTL_NODE(_hw_usb2, OID_AUTO, ubsa, CTLFLAG_RW, 0, "USB ubsa"); 87SYSCTL_INT(_hw_usb2_ubsa, OID_AUTO, debug, CTLFLAG_RW, 88 &ubsa_debug, 0, "ubsa debug level"); 89#endif 90 91#define UBSA_BSIZE 1024 /* bytes */ 92 93#define UBSA_CONFIG_INDEX 0 94#define UBSA_IFACE_INDEX 0 95 96#define UBSA_REG_BAUDRATE 0x00 97#define UBSA_REG_STOP_BITS 0x01 98#define UBSA_REG_DATA_BITS 0x02 99#define UBSA_REG_PARITY 0x03 100#define UBSA_REG_DTR 0x0A 101#define UBSA_REG_RTS 0x0B 102#define UBSA_REG_BREAK 0x0C 103#define UBSA_REG_FLOW_CTRL 0x10 104 105#define UBSA_PARITY_NONE 0x00 106#define UBSA_PARITY_EVEN 0x01 107#define UBSA_PARITY_ODD 0x02 108#define UBSA_PARITY_MARK 0x03 109#define UBSA_PARITY_SPACE 0x04 110 111#define UBSA_FLOW_NONE 0x0000 112#define UBSA_FLOW_OCTS 0x0001 113#define UBSA_FLOW_ODSR 0x0002 114#define UBSA_FLOW_IDSR 0x0004 115#define UBSA_FLOW_IDTR 0x0008 116#define UBSA_FLOW_IRTS 0x0010 117#define UBSA_FLOW_ORTS 0x0020 118#define UBSA_FLOW_UNKNOWN 0x0040 119#define UBSA_FLOW_OXON 0x0080 120#define UBSA_FLOW_IXON 0x0100 121 122/* line status register */ 123#define UBSA_LSR_TSRE 0x40 /* Transmitter empty: byte sent */ 124#define UBSA_LSR_TXRDY 0x20 /* Transmitter buffer empty */ 125#define UBSA_LSR_BI 0x10 /* Break detected */ 126#define UBSA_LSR_FE 0x08 /* Framing error: bad stop bit */ 127#define UBSA_LSR_PE 0x04 /* Parity error */ 128#define UBSA_LSR_OE 0x02 /* Overrun, lost incoming byte */ 129#define UBSA_LSR_RXRDY 0x01 /* Byte ready in Receive Buffer */ 130#define UBSA_LSR_RCV_MASK 0x1f /* Mask for incoming data or error */ 131 132/* modem status register */ 133/* All deltas are from the last read of the MSR. */ 134#define UBSA_MSR_DCD 0x80 /* Current Data Carrier Detect */ 135#define UBSA_MSR_RI 0x40 /* Current Ring Indicator */ 136#define UBSA_MSR_DSR 0x20 /* Current Data Set Ready */ 137#define UBSA_MSR_CTS 0x10 /* Current Clear to Send */ 138#define UBSA_MSR_DDCD 0x08 /* DCD has changed state */ 139#define UBSA_MSR_TERI 0x04 /* RI has toggled low to high */ 140#define UBSA_MSR_DDSR 0x02 /* DSR has changed state */ 141#define UBSA_MSR_DCTS 0x01 /* CTS has changed state */ 142 143enum { 144 UBSA_BULK_DT_WR, 145 UBSA_BULK_DT_RD, 146 UBSA_INTR_DT_RD, 147 UBSA_N_TRANSFER, 148}; 149 150struct ubsa_softc { 151 struct usb2_com_super_softc sc_super_ucom; 152 struct usb2_com_softc sc_ucom; 153 154 struct usb2_xfer *sc_xfer[UBSA_N_TRANSFER]; 155 struct usb2_device *sc_udev; 156 struct mtx sc_mtx; 157 158 uint8_t sc_iface_no; /* interface number */ 159 uint8_t sc_iface_index; /* interface index */ 160 uint8_t sc_lsr; /* local status register */ 161 uint8_t sc_msr; /* UBSA status register */ 162}; 163 164static device_probe_t ubsa_probe; 165static device_attach_t ubsa_attach; 166static device_detach_t ubsa_detach; 167 168static usb2_callback_t ubsa_write_callback; 169static usb2_callback_t ubsa_read_callback; 170static usb2_callback_t ubsa_intr_callback; 171 172static void ubsa_cfg_request(struct ubsa_softc *, uint8_t, uint16_t); 173static void ubsa_cfg_set_dtr(struct usb2_com_softc *, uint8_t); 174static void ubsa_cfg_set_rts(struct usb2_com_softc *, uint8_t); 175static void ubsa_cfg_set_break(struct usb2_com_softc *, uint8_t); 176static int ubsa_pre_param(struct usb2_com_softc *, struct termios *); 177static void ubsa_cfg_param(struct usb2_com_softc *, struct termios *); 178static void ubsa_start_read(struct usb2_com_softc *); 179static void ubsa_stop_read(struct usb2_com_softc *); 180static void ubsa_start_write(struct usb2_com_softc *); 181static void ubsa_stop_write(struct usb2_com_softc *); 182static void ubsa_cfg_get_status(struct usb2_com_softc *, uint8_t *, 183 uint8_t *); 184 185static const struct usb2_config ubsa_config[UBSA_N_TRANSFER] = { 186 187 [UBSA_BULK_DT_WR] = { 188 .type = UE_BULK, 189 .endpoint = UE_ADDR_ANY, 190 .direction = UE_DIR_OUT, 191 .bufsize = UBSA_BSIZE, /* bytes */ 192 .flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 193 .callback = &ubsa_write_callback, 194 }, 195 196 [UBSA_BULK_DT_RD] = { 197 .type = UE_BULK, 198 .endpoint = UE_ADDR_ANY, 199 .direction = UE_DIR_IN, 200 .bufsize = UBSA_BSIZE, /* bytes */ 201 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 202 .callback = &ubsa_read_callback, 203 }, 204 205 [UBSA_INTR_DT_RD] = { 206 .type = UE_INTERRUPT, 207 .endpoint = UE_ADDR_ANY, 208 .direction = UE_DIR_IN, 209 .flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 210 .bufsize = 0, /* use wMaxPacketSize */ 211 .callback = &ubsa_intr_callback, 212 }, 213}; 214 215static const struct usb2_com_callback ubsa_callback = { 216 .usb2_com_cfg_get_status = &ubsa_cfg_get_status, 217 .usb2_com_cfg_set_dtr = &ubsa_cfg_set_dtr, 218 .usb2_com_cfg_set_rts = &ubsa_cfg_set_rts, 219 .usb2_com_cfg_set_break = &ubsa_cfg_set_break, 220 .usb2_com_cfg_param = &ubsa_cfg_param, 221 .usb2_com_pre_param = &ubsa_pre_param, 222 .usb2_com_start_read = &ubsa_start_read, 223 .usb2_com_stop_read = &ubsa_stop_read, 224 .usb2_com_start_write = &ubsa_start_write, 225 .usb2_com_stop_write = &ubsa_stop_write, 226}; 227 228static const struct usb2_device_id ubsa_devs[] = { 229 /* AnyData ADU-500A */ 230 {USB_VPI(USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_500A, 0)}, 231 /* AnyData ADU-E100A/H */ 232 {USB_VPI(USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_E100X, 0)}, 233 /* Axesstel MV100H */ 234 {USB_VPI(USB_VENDOR_AXESSTEL, USB_PRODUCT_AXESSTEL_DATAMODEM, 0)}, 235 /* BELKIN F5U103 */ 236 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U103, 0)}, 237 /* BELKIN F5U120 */ 238 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U120, 0)}, 239 /* GoHubs GO-COM232 */ 240 {USB_VPI(USB_VENDOR_ETEK, USB_PRODUCT_ETEK_1COM, 0)}, 241 /* GoHubs GO-COM232 */ 242 {USB_VPI(USB_VENDOR_GOHUBS, USB_PRODUCT_GOHUBS_GOCOM232, 0)}, 243 /* Peracom */ 244 {USB_VPI(USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_SERIAL1, 0)}, 245}; 246 247static device_method_t ubsa_methods[] = { 248 DEVMETHOD(device_probe, ubsa_probe), 249 DEVMETHOD(device_attach, ubsa_attach), 250 DEVMETHOD(device_detach, ubsa_detach), 251 {0, 0} 252}; 253 254static devclass_t ubsa_devclass; 255 256static driver_t ubsa_driver = { 257 .name = "ubsa", 258 .methods = ubsa_methods, 259 .size = sizeof(struct ubsa_softc), 260}; 261 262DRIVER_MODULE(ubsa, uhub, ubsa_driver, ubsa_devclass, NULL, 0); 263MODULE_DEPEND(ubsa, ucom, 1, 1, 1); 264MODULE_DEPEND(ubsa, usb, 1, 1, 1); 265 266static int 267ubsa_probe(device_t dev) 268{ 269 struct usb2_attach_arg *uaa = device_get_ivars(dev); 270 271 if (uaa->usb2_mode != USB_MODE_HOST) { 272 return (ENXIO); 273 } 274 if (uaa->info.bConfigIndex != UBSA_CONFIG_INDEX) { 275 return (ENXIO); 276 } 277 if (uaa->info.bIfaceIndex != UBSA_IFACE_INDEX) { 278 return (ENXIO); 279 } 280 return (usb2_lookup_id_by_uaa(ubsa_devs, sizeof(ubsa_devs), uaa)); 281} 282 283static int 284ubsa_attach(device_t dev) 285{ 286 struct usb2_attach_arg *uaa = device_get_ivars(dev); 287 struct ubsa_softc *sc = device_get_softc(dev); 288 int error; 289 290 DPRINTF("sc=%p\n", sc); 291 292 device_set_usb2_desc(dev); 293 mtx_init(&sc->sc_mtx, "ubsa", NULL, MTX_DEF); 294 295 sc->sc_udev = uaa->device; 296 sc->sc_iface_no = uaa->info.bIfaceNum; 297 sc->sc_iface_index = UBSA_IFACE_INDEX; 298 299 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index, 300 sc->sc_xfer, ubsa_config, UBSA_N_TRANSFER, sc, &sc->sc_mtx); 301 302 if (error) { 303 DPRINTF("could not allocate all pipes\n"); 304 goto detach; 305 } 306 /* clear stall at first run */ 307 mtx_lock(&sc->sc_mtx); 308 usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]); 309 usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]); 310 mtx_unlock(&sc->sc_mtx); 311 312 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 313 &ubsa_callback, &sc->sc_mtx); 314 if (error) { 315 DPRINTF("usb2_com_attach failed\n"); 316 goto detach; 317 } 318 return (0); 319 320detach: 321 ubsa_detach(dev); 322 return (ENXIO); 323} 324 325static int 326ubsa_detach(device_t dev) 327{ 328 struct ubsa_softc *sc = device_get_softc(dev); 329 330 DPRINTF("sc=%p\n", sc); 331 332 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1); 333 usb2_transfer_unsetup(sc->sc_xfer, UBSA_N_TRANSFER); 334 mtx_destroy(&sc->sc_mtx); 335 336 return (0); 337} 338 339static void 340ubsa_cfg_request(struct ubsa_softc *sc, uint8_t index, uint16_t value) 341{ 342 struct usb2_device_request req; 343 usb2_error_t err; 344 345 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 346 req.bRequest = index; 347 USETW(req.wValue, value); 348 req.wIndex[0] = sc->sc_iface_no; 349 req.wIndex[1] = 0; 350 USETW(req.wLength, 0); 351 352 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 353 &req, NULL, 0, 1000); 354 if (err) { 355 DPRINTFN(0, "device request failed, err=%s " 356 "(ignored)\n", usb2_errstr(err)); 357 } 358} 359 360static void 361ubsa_cfg_set_dtr(struct usb2_com_softc *ucom, uint8_t onoff) 362{ 363 struct ubsa_softc *sc = ucom->sc_parent; 364 365 DPRINTF("onoff = %d\n", onoff); 366 367 ubsa_cfg_request(sc, UBSA_REG_DTR, onoff ? 1 : 0); 368} 369 370static void 371ubsa_cfg_set_rts(struct usb2_com_softc *ucom, uint8_t onoff) 372{ 373 struct ubsa_softc *sc = ucom->sc_parent; 374 375 DPRINTF("onoff = %d\n", onoff); 376 377 ubsa_cfg_request(sc, UBSA_REG_RTS, onoff ? 1 : 0); 378} 379 380static void 381ubsa_cfg_set_break(struct usb2_com_softc *ucom, uint8_t onoff) 382{ 383 struct ubsa_softc *sc = ucom->sc_parent; 384 385 DPRINTF("onoff = %d\n", onoff); 386 387 ubsa_cfg_request(sc, UBSA_REG_BREAK, onoff ? 1 : 0); 388} 389 390static int 391ubsa_pre_param(struct usb2_com_softc *ucom, struct termios *t) 392{ 393 struct ubsa_softc *sc = ucom->sc_parent; 394 395 DPRINTF("sc = %p\n", sc); 396 397 switch (t->c_ospeed) { 398 case B0: 399 case B300: 400 case B600: 401 case B1200: 402 case B2400: 403 case B4800: 404 case B9600: 405 case B19200: 406 case B38400: 407 case B57600: 408 case B115200: 409 case B230400: 410 break; 411 default: 412 return (EINVAL); 413 } 414 return (0); 415} 416 417static void 418ubsa_cfg_param(struct usb2_com_softc *ucom, struct termios *t) 419{ 420 struct ubsa_softc *sc = ucom->sc_parent; 421 uint16_t value = 0; 422 423 DPRINTF("sc = %p\n", sc); 424 425 switch (t->c_ospeed) { 426 case B0: 427 ubsa_cfg_request(sc, UBSA_REG_FLOW_CTRL, 0); 428 ubsa_cfg_set_dtr(&sc->sc_ucom, 0); 429 ubsa_cfg_set_rts(&sc->sc_ucom, 0); 430 break; 431 case B300: 432 case B600: 433 case B1200: 434 case B2400: 435 case B4800: 436 case B9600: 437 case B19200: 438 case B38400: 439 case B57600: 440 case B115200: 441 case B230400: 442 value = B230400 / t->c_ospeed; 443 ubsa_cfg_request(sc, UBSA_REG_BAUDRATE, value); 444 break; 445 default: 446 return; 447 } 448 449 if (t->c_cflag & PARENB) 450 value = (t->c_cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN; 451 else 452 value = UBSA_PARITY_NONE; 453 454 ubsa_cfg_request(sc, UBSA_REG_PARITY, value); 455 456 switch (t->c_cflag & CSIZE) { 457 case CS5: 458 value = 0; 459 break; 460 case CS6: 461 value = 1; 462 break; 463 case CS7: 464 value = 2; 465 break; 466 default: 467 case CS8: 468 value = 3; 469 break; 470 } 471 472 ubsa_cfg_request(sc, UBSA_REG_DATA_BITS, value); 473 474 value = (t->c_cflag & CSTOPB) ? 1 : 0; 475 476 ubsa_cfg_request(sc, UBSA_REG_STOP_BITS, value); 477 478 value = 0; 479 if (t->c_cflag & CRTSCTS) 480 value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS; 481 482 if (t->c_iflag & (IXON | IXOFF)) 483 value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON; 484 485 ubsa_cfg_request(sc, UBSA_REG_FLOW_CTRL, value); 486} 487 488static void 489ubsa_start_read(struct usb2_com_softc *ucom) 490{ 491 struct ubsa_softc *sc = ucom->sc_parent; 492 493 /* start interrupt endpoint */ 494 usb2_transfer_start(sc->sc_xfer[UBSA_INTR_DT_RD]); 495 496 /* start read endpoint */ 497 usb2_transfer_start(sc->sc_xfer[UBSA_BULK_DT_RD]); 498} 499 500static void 501ubsa_stop_read(struct usb2_com_softc *ucom) 502{ 503 struct ubsa_softc *sc = ucom->sc_parent; 504 505 /* stop interrupt endpoint */ 506 usb2_transfer_stop(sc->sc_xfer[UBSA_INTR_DT_RD]); 507 508 /* stop read endpoint */ 509 usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_RD]); 510} 511 512static void 513ubsa_start_write(struct usb2_com_softc *ucom) 514{ 515 struct ubsa_softc *sc = ucom->sc_parent; 516 517 usb2_transfer_start(sc->sc_xfer[UBSA_BULK_DT_WR]); 518} 519 520static void 521ubsa_stop_write(struct usb2_com_softc *ucom) 522{ 523 struct ubsa_softc *sc = ucom->sc_parent; 524 525 usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_WR]); 526} 527 528static void 529ubsa_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr) 530{ 531 struct ubsa_softc *sc = ucom->sc_parent; 532 533 DPRINTF("\n"); 534 535 *lsr = sc->sc_lsr; 536 *msr = sc->sc_msr; 537} 538 539static void 540ubsa_write_callback(struct usb2_xfer *xfer) 541{ 542 struct ubsa_softc *sc = xfer->priv_sc; 543 uint32_t actlen; 544 545 switch (USB_GET_STATE(xfer)) { 546 case USB_ST_SETUP: 547 case USB_ST_TRANSFERRED: 548tr_setup: 549 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 550 UBSA_BSIZE, &actlen)) { 551 552 xfer->frlengths[0] = actlen; 553 usb2_start_hardware(xfer); 554 } 555 return; 556 557 default: /* Error */ 558 if (xfer->error != USB_ERR_CANCELLED) { 559 /* try to clear stall first */ 560 xfer->flags.stall_pipe = 1; 561 goto tr_setup; 562 } 563 return; 564 565 } 566} 567 568static void 569ubsa_read_callback(struct usb2_xfer *xfer) 570{ 571 struct ubsa_softc *sc = xfer->priv_sc; 572 573 switch (USB_GET_STATE(xfer)) { 574 case USB_ST_TRANSFERRED: 575 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen); 576 577 case USB_ST_SETUP: 578tr_setup: 579 xfer->frlengths[0] = xfer->max_data_length; 580 usb2_start_hardware(xfer); 581 return; 582 583 default: /* Error */ 584 if (xfer->error != USB_ERR_CANCELLED) { 585 /* try to clear stall first */ 586 xfer->flags.stall_pipe = 1; 587 goto tr_setup; 588 } 589 return; 590 591 } 592} 593 594static void 595ubsa_intr_callback(struct usb2_xfer *xfer) 596{ 597 struct ubsa_softc *sc = xfer->priv_sc; 598 uint8_t buf[4]; 599 600 switch (USB_GET_STATE(xfer)) { 601 case USB_ST_TRANSFERRED: 602 603 if (xfer->actlen >= sizeof(buf)) { 604 605 usb2_copy_out(xfer->frbuffers, 0, buf, sizeof(buf)); 606 607 /* 608 * incidentally, Belkin adapter status bits match 609 * UART 16550 bits 610 */ 611 sc->sc_lsr = buf[2]; 612 sc->sc_msr = buf[3]; 613 614 DPRINTF("lsr = 0x%02x, msr = 0x%02x\n", 615 sc->sc_lsr, sc->sc_msr); 616 617 usb2_com_status_change(&sc->sc_ucom); 618 } else { 619 DPRINTF("ignoring short packet, %d bytes\n", 620 xfer->actlen); 621 } 622 623 case USB_ST_SETUP: 624tr_setup: 625 xfer->frlengths[0] = xfer->max_data_length; 626 usb2_start_hardware(xfer); 627 return; 628 629 default: /* Error */ 630 if (xfer->error != USB_ERR_CANCELLED) { 631 /* try to clear stall first */ 632 xfer->flags.stall_pipe = 1; 633 goto tr_setup; 634 } 635 return; 636 637 } 638} 639