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$"); 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 84 static int ubsa_debug = 0; 85 86 SYSCTL_NODE(_hw_usb2, OID_AUTO, ubsa, CTLFLAG_RW, 0, "USB ubsa"); 87 SYSCTL_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 143 enum { 144 UBSA_BULK_DT_WR, 145 UBSA_BULK_DT_RD, 146 UBSA_INTR_DT_RD, 147 UBSA_N_TRANSFER, 148 }; 149 150 struct 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 157 uint8_t sc_iface_no; /* interface number */ 158 uint8_t sc_iface_index; /* interface index */ 159 uint8_t sc_lsr; /* local status register */ 160 uint8_t sc_msr; /* UBSA status register */ 161 }; 162 163 static device_probe_t ubsa_probe; 164 static device_attach_t ubsa_attach; 165 static device_detach_t ubsa_detach; 166 167 static usb2_callback_t ubsa_write_callback; 168 static usb2_callback_t ubsa_read_callback; 169 static usb2_callback_t ubsa_intr_callback; 170 171 static void ubsa_cfg_request(struct ubsa_softc *, uint8_t, uint16_t); 172 static void ubsa_cfg_set_dtr(struct usb2_com_softc *, uint8_t); 173 static void ubsa_cfg_set_rts(struct usb2_com_softc *, uint8_t); 174 static void ubsa_cfg_set_break(struct usb2_com_softc *, uint8_t); 175 static int ubsa_pre_param(struct usb2_com_softc *, struct termios *); 176 static void ubsa_cfg_param(struct usb2_com_softc *, struct termios *); 177 static void ubsa_start_read(struct usb2_com_softc *); 178 static void ubsa_stop_read(struct usb2_com_softc *); 179 static void ubsa_start_write(struct usb2_com_softc *); 180 static void ubsa_stop_write(struct usb2_com_softc *); 181 static void ubsa_cfg_get_status(struct usb2_com_softc *, uint8_t *, 182 uint8_t *); 183 184 static const struct usb2_config ubsa_config[UBSA_N_TRANSFER] = { 185 186 [UBSA_BULK_DT_WR] = { 187 .type = UE_BULK, 188 .endpoint = UE_ADDR_ANY, 189 .direction = UE_DIR_OUT, 190 .mh.bufsize = UBSA_BSIZE, /* bytes */ 191 .mh.flags = {.pipe_bof = 1,.force_short_xfer = 1,}, 192 .mh.callback = &ubsa_write_callback, 193 }, 194 195 [UBSA_BULK_DT_RD] = { 196 .type = UE_BULK, 197 .endpoint = UE_ADDR_ANY, 198 .direction = UE_DIR_IN, 199 .mh.bufsize = UBSA_BSIZE, /* bytes */ 200 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 201 .mh.callback = &ubsa_read_callback, 202 }, 203 204 [UBSA_INTR_DT_RD] = { 205 .type = UE_INTERRUPT, 206 .endpoint = UE_ADDR_ANY, 207 .direction = UE_DIR_IN, 208 .mh.flags = {.pipe_bof = 1,.short_xfer_ok = 1,}, 209 .mh.bufsize = 0, /* use wMaxPacketSize */ 210 .mh.callback = &ubsa_intr_callback, 211 }, 212 }; 213 214 static const struct usb2_com_callback ubsa_callback = { 215 .usb2_com_cfg_get_status = &ubsa_cfg_get_status, 216 .usb2_com_cfg_set_dtr = &ubsa_cfg_set_dtr, 217 .usb2_com_cfg_set_rts = &ubsa_cfg_set_rts, 218 .usb2_com_cfg_set_break = &ubsa_cfg_set_break, 219 .usb2_com_cfg_param = &ubsa_cfg_param, 220 .usb2_com_pre_param = &ubsa_pre_param, 221 .usb2_com_start_read = &ubsa_start_read, 222 .usb2_com_stop_read = &ubsa_stop_read, 223 .usb2_com_start_write = &ubsa_start_write, 224 .usb2_com_stop_write = &ubsa_stop_write, 225 }; 226 227 static const struct usb2_device_id ubsa_devs[] = { 228 /* AnyData ADU-500A */ 229 {USB_VPI(USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_500A, 0)}, 230 /* AnyData ADU-E100A/H */ 231 {USB_VPI(USB_VENDOR_ANYDATA, USB_PRODUCT_ANYDATA_ADU_E100X, 0)}, 232 /* Axesstel MV100H */ 233 {USB_VPI(USB_VENDOR_AXESSTEL, USB_PRODUCT_AXESSTEL_DATAMODEM, 0)}, 234 /* BELKIN F5U103 */ 235 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U103, 0)}, 236 /* BELKIN F5U120 */ 237 {USB_VPI(USB_VENDOR_BELKIN, USB_PRODUCT_BELKIN_F5U120, 0)}, 238 /* GoHubs GO-COM232 */ 239 {USB_VPI(USB_VENDOR_ETEK, USB_PRODUCT_ETEK_1COM, 0)}, 240 /* GoHubs GO-COM232 */ 241 {USB_VPI(USB_VENDOR_GOHUBS, USB_PRODUCT_GOHUBS_GOCOM232, 0)}, 242 /* Peracom */ 243 {USB_VPI(USB_VENDOR_PERACOM, USB_PRODUCT_PERACOM_SERIAL1, 0)}, 244 }; 245 246 static device_method_t ubsa_methods[] = { 247 DEVMETHOD(device_probe, ubsa_probe), 248 DEVMETHOD(device_attach, ubsa_attach), 249 DEVMETHOD(device_detach, ubsa_detach), 250 {0, 0} 251 }; 252 253 static devclass_t ubsa_devclass; 254 255 static driver_t ubsa_driver = { 256 .name = "ubsa", 257 .methods = ubsa_methods, 258 .size = sizeof(struct ubsa_softc), 259 }; 260 261 DRIVER_MODULE(ubsa, ushub, ubsa_driver, ubsa_devclass, NULL, 0); 262 MODULE_DEPEND(ubsa, ucom, 1, 1, 1); 263 MODULE_DEPEND(ubsa, usb, 1, 1, 1); 264 265 static int 266 ubsa_probe(device_t dev) 267 { 268 struct usb2_attach_arg *uaa = device_get_ivars(dev); 269 270 if (uaa->usb2_mode != USB_MODE_HOST) { 271 return (ENXIO); 272 } 273 if (uaa->info.bConfigIndex != UBSA_CONFIG_INDEX) { 274 return (ENXIO); 275 } 276 if (uaa->info.bIfaceIndex != UBSA_IFACE_INDEX) { 277 return (ENXIO); 278 } 279 return (usb2_lookup_id_by_uaa(ubsa_devs, sizeof(ubsa_devs), uaa)); 280 } 281 282 static int 283 ubsa_attach(device_t dev) 284 { 285 struct usb2_attach_arg *uaa = device_get_ivars(dev); 286 struct ubsa_softc *sc = device_get_softc(dev); 287 int error; 288 289 DPRINTF("sc=%p\n", sc); 290 291 device_set_usb2_desc(dev); 292 293 sc->sc_udev = uaa->device; 294 sc->sc_iface_no = uaa->info.bIfaceNum; 295 sc->sc_iface_index = UBSA_IFACE_INDEX; 296 297 error = usb2_transfer_setup(uaa->device, &sc->sc_iface_index, 298 sc->sc_xfer, ubsa_config, UBSA_N_TRANSFER, sc, &Giant); 299 300 if (error) { 301 DPRINTF("could not allocate all pipes\n"); 302 goto detach; 303 } 304 /* clear stall at first run */ 305 usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_WR]); 306 usb2_transfer_set_stall(sc->sc_xfer[UBSA_BULK_DT_RD]); 307 308 error = usb2_com_attach(&sc->sc_super_ucom, &sc->sc_ucom, 1, sc, 309 &ubsa_callback, &Giant); 310 if (error) { 311 DPRINTF("usb2_com_attach failed\n"); 312 goto detach; 313 } 314 return (0); 315 316 detach: 317 ubsa_detach(dev); 318 return (ENXIO); 319 } 320 321 static int 322 ubsa_detach(device_t dev) 323 { 324 struct ubsa_softc *sc = device_get_softc(dev); 325 326 DPRINTF("sc=%p\n", sc); 327 328 usb2_com_detach(&sc->sc_super_ucom, &sc->sc_ucom, 1); 329 330 usb2_transfer_unsetup(sc->sc_xfer, UBSA_N_TRANSFER); 331 332 return (0); 333 } 334 335 static void 336 ubsa_cfg_request(struct ubsa_softc *sc, uint8_t index, uint16_t value) 337 { 338 struct usb2_device_request req; 339 usb2_error_t err; 340 341 req.bmRequestType = UT_WRITE_VENDOR_DEVICE; 342 req.bRequest = index; 343 USETW(req.wValue, value); 344 req.wIndex[0] = sc->sc_iface_no; 345 req.wIndex[1] = 0; 346 USETW(req.wLength, 0); 347 348 err = usb2_com_cfg_do_request(sc->sc_udev, &sc->sc_ucom, 349 &req, NULL, 0, 1000); 350 if (err) { 351 DPRINTFN(0, "device request failed, err=%s " 352 "(ignored)\n", usb2_errstr(err)); 353 } 354 } 355 356 static void 357 ubsa_cfg_set_dtr(struct usb2_com_softc *ucom, uint8_t onoff) 358 { 359 struct ubsa_softc *sc = ucom->sc_parent; 360 361 DPRINTF("onoff = %d\n", onoff); 362 363 ubsa_cfg_request(sc, UBSA_REG_DTR, onoff ? 1 : 0); 364 } 365 366 static void 367 ubsa_cfg_set_rts(struct usb2_com_softc *ucom, uint8_t onoff) 368 { 369 struct ubsa_softc *sc = ucom->sc_parent; 370 371 DPRINTF("onoff = %d\n", onoff); 372 373 ubsa_cfg_request(sc, UBSA_REG_RTS, onoff ? 1 : 0); 374 } 375 376 static void 377 ubsa_cfg_set_break(struct usb2_com_softc *ucom, uint8_t onoff) 378 { 379 struct ubsa_softc *sc = ucom->sc_parent; 380 381 DPRINTF("onoff = %d\n", onoff); 382 383 ubsa_cfg_request(sc, UBSA_REG_BREAK, onoff ? 1 : 0); 384 } 385 386 static int 387 ubsa_pre_param(struct usb2_com_softc *ucom, struct termios *t) 388 { 389 struct ubsa_softc *sc = ucom->sc_parent; 390 391 DPRINTF("sc = %p\n", sc); 392 393 switch (t->c_ospeed) { 394 case B0: 395 case B300: 396 case B600: 397 case B1200: 398 case B2400: 399 case B4800: 400 case B9600: 401 case B19200: 402 case B38400: 403 case B57600: 404 case B115200: 405 case B230400: 406 break; 407 default: 408 return (EINVAL); 409 } 410 return (0); 411 } 412 413 static void 414 ubsa_cfg_param(struct usb2_com_softc *ucom, struct termios *t) 415 { 416 struct ubsa_softc *sc = ucom->sc_parent; 417 uint16_t value = 0; 418 419 DPRINTF("sc = %p\n", sc); 420 421 switch (t->c_ospeed) { 422 case B0: 423 ubsa_cfg_request(sc, UBSA_REG_FLOW_CTRL, 0); 424 ubsa_cfg_set_dtr(&sc->sc_ucom, 0); 425 ubsa_cfg_set_rts(&sc->sc_ucom, 0); 426 break; 427 case B300: 428 case B600: 429 case B1200: 430 case B2400: 431 case B4800: 432 case B9600: 433 case B19200: 434 case B38400: 435 case B57600: 436 case B115200: 437 case B230400: 438 value = B230400 / t->c_ospeed; 439 ubsa_cfg_request(sc, UBSA_REG_BAUDRATE, value); 440 break; 441 default: 442 return; 443 } 444 445 if (t->c_cflag & PARENB) 446 value = (t->c_cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN; 447 else 448 value = UBSA_PARITY_NONE; 449 450 ubsa_cfg_request(sc, UBSA_REG_PARITY, value); 451 452 switch (t->c_cflag & CSIZE) { 453 case CS5: 454 value = 0; 455 break; 456 case CS6: 457 value = 1; 458 break; 459 case CS7: 460 value = 2; 461 break; 462 default: 463 case CS8: 464 value = 3; 465 break; 466 } 467 468 ubsa_cfg_request(sc, UBSA_REG_DATA_BITS, value); 469 470 value = (t->c_cflag & CSTOPB) ? 1 : 0; 471 472 ubsa_cfg_request(sc, UBSA_REG_STOP_BITS, value); 473 474 value = 0; 475 if (t->c_cflag & CRTSCTS) 476 value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS; 477 478 if (t->c_iflag & (IXON | IXOFF)) 479 value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON; 480 481 ubsa_cfg_request(sc, UBSA_REG_FLOW_CTRL, value); 482 } 483 484 static void 485 ubsa_start_read(struct usb2_com_softc *ucom) 486 { 487 struct ubsa_softc *sc = ucom->sc_parent; 488 489 /* start interrupt endpoint */ 490 usb2_transfer_start(sc->sc_xfer[UBSA_INTR_DT_RD]); 491 492 /* start read endpoint */ 493 usb2_transfer_start(sc->sc_xfer[UBSA_BULK_DT_RD]); 494 } 495 496 static void 497 ubsa_stop_read(struct usb2_com_softc *ucom) 498 { 499 struct ubsa_softc *sc = ucom->sc_parent; 500 501 /* stop interrupt endpoint */ 502 usb2_transfer_stop(sc->sc_xfer[UBSA_INTR_DT_RD]); 503 504 /* stop read endpoint */ 505 usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_RD]); 506 } 507 508 static void 509 ubsa_start_write(struct usb2_com_softc *ucom) 510 { 511 struct ubsa_softc *sc = ucom->sc_parent; 512 513 usb2_transfer_start(sc->sc_xfer[UBSA_BULK_DT_WR]); 514 } 515 516 static void 517 ubsa_stop_write(struct usb2_com_softc *ucom) 518 { 519 struct ubsa_softc *sc = ucom->sc_parent; 520 521 usb2_transfer_stop(sc->sc_xfer[UBSA_BULK_DT_WR]); 522 } 523 524 static void 525 ubsa_cfg_get_status(struct usb2_com_softc *ucom, uint8_t *lsr, uint8_t *msr) 526 { 527 struct ubsa_softc *sc = ucom->sc_parent; 528 529 DPRINTF("\n"); 530 531 *lsr = sc->sc_lsr; 532 *msr = sc->sc_msr; 533 } 534 535 static void 536 ubsa_write_callback(struct usb2_xfer *xfer) 537 { 538 struct ubsa_softc *sc = xfer->priv_sc; 539 uint32_t actlen; 540 541 switch (USB_GET_STATE(xfer)) { 542 case USB_ST_SETUP: 543 case USB_ST_TRANSFERRED: 544 tr_setup: 545 if (usb2_com_get_data(&sc->sc_ucom, xfer->frbuffers, 0, 546 UBSA_BSIZE, &actlen)) { 547 548 xfer->frlengths[0] = actlen; 549 usb2_start_hardware(xfer); 550 } 551 return; 552 553 default: /* Error */ 554 if (xfer->error != USB_ERR_CANCELLED) { 555 /* try to clear stall first */ 556 xfer->flags.stall_pipe = 1; 557 goto tr_setup; 558 } 559 return; 560 561 } 562 } 563 564 static void 565 ubsa_read_callback(struct usb2_xfer *xfer) 566 { 567 struct ubsa_softc *sc = xfer->priv_sc; 568 569 switch (USB_GET_STATE(xfer)) { 570 case USB_ST_TRANSFERRED: 571 usb2_com_put_data(&sc->sc_ucom, xfer->frbuffers, 0, xfer->actlen); 572 573 case USB_ST_SETUP: 574 tr_setup: 575 xfer->frlengths[0] = xfer->max_data_length; 576 usb2_start_hardware(xfer); 577 return; 578 579 default: /* Error */ 580 if (xfer->error != USB_ERR_CANCELLED) { 581 /* try to clear stall first */ 582 xfer->flags.stall_pipe = 1; 583 goto tr_setup; 584 } 585 return; 586 587 } 588 } 589 590 static void 591 ubsa_intr_callback(struct usb2_xfer *xfer) 592 { 593 struct ubsa_softc *sc = xfer->priv_sc; 594 uint8_t buf[4]; 595 596 switch (USB_GET_STATE(xfer)) { 597 case USB_ST_TRANSFERRED: 598 599 if (xfer->actlen >= sizeof(buf)) { 600 601 usb2_copy_out(xfer->frbuffers, 0, buf, sizeof(buf)); 602 603 /* 604 * incidentally, Belkin adapter status bits match 605 * UART 16550 bits 606 */ 607 sc->sc_lsr = buf[2]; 608 sc->sc_msr = buf[3]; 609 610 DPRINTF("lsr = 0x%02x, msr = 0x%02x\n", 611 sc->sc_lsr, sc->sc_msr); 612 613 usb2_com_status_change(&sc->sc_ucom); 614 } else { 615 DPRINTF("ignoring short packet, %d bytes\n", 616 xfer->actlen); 617 } 618 619 case USB_ST_SETUP: 620 tr_setup: 621 xfer->frlengths[0] = xfer->max_data_length; 622 usb2_start_hardware(xfer); 623 return; 624 625 default: /* Error */ 626 if (xfer->error != USB_ERR_CANCELLED) { 627 /* try to clear stall first */ 628 xfer->flags.stall_pipe = 1; 629 goto tr_setup; 630 } 631 return; 632 633 } 634 } 635