Home | History | Annotate | Line # | Download | only in usb
ubsa_common.c revision 1.5.8.2
      1  1.5.8.2    yamt /*	$NetBSD: ubsa_common.c,v 1.5.8.2 2013/01/16 05:33:34 yamt Exp $	*/
      2      1.1  ichiro /*-
      3      1.1  ichiro  * Copyright (c) 2002, Alexander Kabaev <kan.FreeBSD.org>.
      4      1.1  ichiro  * All rights reserved.
      5      1.1  ichiro  *
      6      1.1  ichiro  * Redistribution and use in source and binary forms, with or without
      7      1.1  ichiro  * modification, are permitted provided that the following conditions
      8      1.1  ichiro  * are met:
      9      1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     10      1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     11      1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     13      1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     14      1.1  ichiro  *
     15      1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16      1.1  ichiro  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17      1.1  ichiro  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18      1.1  ichiro  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19      1.1  ichiro  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20      1.1  ichiro  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21      1.1  ichiro  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22      1.1  ichiro  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23      1.1  ichiro  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24      1.1  ichiro  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25      1.1  ichiro  * SUCH DAMAGE.
     26      1.1  ichiro  */
     27      1.1  ichiro /*
     28      1.1  ichiro  * Copyright (c) 2001 The NetBSD Foundation, Inc.
     29      1.1  ichiro  * All rights reserved.
     30      1.1  ichiro  *
     31      1.1  ichiro  * This code is derived from software contributed to The NetBSD Foundation
     32      1.1  ichiro  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
     33      1.1  ichiro  *
     34      1.1  ichiro  * Redistribution and use in source and binary forms, with or without
     35      1.1  ichiro  * modification, are permitted provided that the following conditions
     36      1.1  ichiro  * are met:
     37      1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     38      1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     39      1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     40      1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     41      1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     42      1.1  ichiro  *
     43      1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     44      1.1  ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     45      1.1  ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     46      1.1  ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     47      1.1  ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     48      1.1  ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     49      1.1  ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     50      1.1  ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     51      1.1  ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     52      1.1  ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     53      1.1  ichiro  * POSSIBILITY OF SUCH DAMAGE.
     54      1.1  ichiro  */
     55      1.1  ichiro 
     56      1.1  ichiro #include <sys/cdefs.h>
     57  1.5.8.2    yamt __KERNEL_RCSID(0, "$NetBSD: ubsa_common.c,v 1.5.8.2 2013/01/16 05:33:34 yamt Exp $");
     58      1.1  ichiro 
     59      1.1  ichiro #include <sys/param.h>
     60      1.1  ichiro #include <sys/systm.h>
     61      1.1  ichiro #include <sys/kernel.h>
     62      1.1  ichiro #include <sys/malloc.h>
     63      1.1  ichiro #include <sys/ioccom.h>
     64      1.1  ichiro #include <sys/fcntl.h>
     65      1.1  ichiro #include <sys/conf.h>
     66      1.1  ichiro #include <sys/tty.h>
     67      1.1  ichiro #include <sys/file.h>
     68      1.1  ichiro #include <sys/select.h>
     69      1.1  ichiro #include <sys/proc.h>
     70      1.1  ichiro #include <sys/device.h>
     71      1.1  ichiro #include <sys/poll.h>
     72      1.1  ichiro #include <sys/sysctl.h>
     73      1.1  ichiro #include <sys/bus.h>
     74      1.1  ichiro 
     75      1.1  ichiro #include <dev/usb/usb.h>
     76      1.1  ichiro #include <dev/usb/usbdi.h>
     77      1.1  ichiro #include <dev/usb/usbdi_util.h>
     78      1.1  ichiro #include <dev/usb/usbdivar.h>
     79      1.1  ichiro 
     80      1.1  ichiro #include <dev/usb/usbcdc.h>
     81      1.1  ichiro #include <dev/usb/usbdevs.h>
     82      1.1  ichiro #include <dev/usb/usb_quirks.h>
     83      1.1  ichiro #include <dev/usb/ucomvar.h>
     84      1.1  ichiro #include <dev/usb/ubsavar.h>
     85      1.1  ichiro 
     86      1.1  ichiro #ifdef UBSA_DEBUG
     87      1.1  ichiro extern	int	ubsadebug;
     88      1.1  ichiro #define	DPRINTFN(n, x)	do { \
     89      1.1  ichiro 				if (ubsadebug > (n)) \
     90      1.5  dyoung 					printf x; \
     91      1.1  ichiro 			} while (0)
     92      1.1  ichiro #else
     93      1.1  ichiro #define	DPRINTFN(n, x)
     94      1.1  ichiro #endif
     95      1.1  ichiro #define	DPRINTF(x) DPRINTFN(0, x)
     96      1.1  ichiro 
     97      1.2  ichiro int
     98      1.1  ichiro ubsa_request(struct ubsa_softc *sc, int portno, u_int8_t request, u_int16_t value)
     99      1.1  ichiro {
    100      1.1  ichiro 	usb_device_request_t req;
    101      1.1  ichiro 	usbd_status err;
    102      1.1  ichiro 
    103      1.1  ichiro 	if (sc->sc_quadumts)
    104      1.1  ichiro 		req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
    105      1.1  ichiro 	else
    106      1.1  ichiro 		req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
    107      1.1  ichiro 
    108  1.5.8.2    yamt 	if (portno >= UBSA_MAXCONN) {
    109      1.1  ichiro 		printf("%s: ubsa_request: invalid port(%d)#\n",
    110      1.5  dyoung 			device_xname(sc->sc_dev), portno);
    111      1.1  ichiro 		return USBD_INVAL;
    112      1.1  ichiro 	}
    113      1.1  ichiro 
    114      1.1  ichiro 	req.bRequest = request;
    115      1.1  ichiro 	USETW(req.wValue, value);
    116      1.1  ichiro 	USETW(req.wIndex, sc->sc_iface_number[portno]);
    117      1.1  ichiro 	USETW(req.wLength, 0);
    118      1.1  ichiro 
    119      1.1  ichiro 	err = usbd_do_request(sc->sc_udev, &req, 0);
    120      1.1  ichiro 	if (err)
    121      1.1  ichiro 		printf("%s: ubsa_request: %s\n",
    122      1.5  dyoung 		    device_xname(sc->sc_dev), usbd_errstr(err));
    123      1.1  ichiro 	return (err);
    124      1.1  ichiro }
    125      1.1  ichiro 
    126      1.2  ichiro void
    127      1.1  ichiro ubsa_dtr(struct ubsa_softc *sc, int portno, int onoff)
    128      1.1  ichiro {
    129      1.1  ichiro 
    130      1.1  ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    131      1.1  ichiro 
    132      1.1  ichiro 	if (sc->sc_dtr == onoff)
    133      1.1  ichiro 		return;
    134      1.1  ichiro 	sc->sc_dtr = onoff;
    135      1.1  ichiro 
    136      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_DTR, onoff ? 1 : 0);
    137      1.1  ichiro }
    138      1.1  ichiro 
    139      1.2  ichiro void
    140      1.1  ichiro ubsa_rts(struct ubsa_softc *sc, int portno, int onoff)
    141      1.1  ichiro {
    142      1.1  ichiro 
    143      1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    144      1.1  ichiro 
    145      1.1  ichiro 	if (sc->sc_rts == onoff)
    146      1.1  ichiro 		return;
    147      1.1  ichiro 	sc->sc_rts = onoff;
    148      1.1  ichiro 
    149      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_RTS, onoff ? 1 : 0);
    150      1.1  ichiro }
    151      1.1  ichiro 
    152      1.2  ichiro void
    153      1.1  ichiro ubsa_quadumts_dtr(struct ubsa_softc *sc, int portno, int onoff)
    154      1.1  ichiro {
    155      1.1  ichiro 
    156      1.1  ichiro 	DPRINTF(("ubsa_dtr: onoff = %d\n", onoff));
    157      1.1  ichiro 
    158      1.1  ichiro 	if (sc->sc_dtr == onoff)
    159      1.1  ichiro 		return;
    160      1.1  ichiro 	sc->sc_dtr = onoff;
    161      1.1  ichiro 
    162      1.1  ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    163      1.1  ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    164      1.1  ichiro }
    165      1.1  ichiro 
    166      1.2  ichiro void
    167      1.1  ichiro ubsa_quadumts_rts(struct ubsa_softc *sc, int portno, int onoff)
    168      1.1  ichiro {
    169      1.1  ichiro 
    170      1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    171      1.1  ichiro 
    172      1.1  ichiro 	if (sc->sc_rts == onoff)
    173      1.1  ichiro 		return;
    174      1.1  ichiro 	sc->sc_rts = onoff;
    175      1.1  ichiro 
    176      1.1  ichiro 	ubsa_request(sc, portno, UBSA_QUADUMTS_SET_PIN,
    177      1.1  ichiro 		 (sc->sc_rts ? 2 : 0)+(sc->sc_dtr ? 1 : 0));
    178      1.1  ichiro }
    179      1.1  ichiro 
    180      1.2  ichiro void
    181      1.1  ichiro ubsa_break(struct ubsa_softc *sc, int portno, int onoff)
    182      1.1  ichiro {
    183      1.1  ichiro 	DPRINTF(("ubsa_rts: onoff = %d\n", onoff));
    184      1.1  ichiro 
    185      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_BREAK, onoff ? 1 : 0);
    186      1.1  ichiro }
    187      1.1  ichiro 
    188      1.2  ichiro void
    189      1.1  ichiro ubsa_set(void *addr, int portno, int reg, int onoff)
    190      1.1  ichiro {
    191      1.1  ichiro 	struct ubsa_softc *sc;
    192      1.1  ichiro 
    193      1.1  ichiro 	sc = addr;
    194      1.1  ichiro 	switch (reg) {
    195      1.1  ichiro 	case UCOM_SET_DTR:
    196      1.1  ichiro 		if (sc->sc_quadumts)
    197      1.1  ichiro 			ubsa_quadumts_dtr(sc, portno, onoff);
    198      1.1  ichiro 		else
    199      1.1  ichiro 			ubsa_dtr(sc, portno, onoff);
    200      1.1  ichiro 		break;
    201      1.1  ichiro 	case UCOM_SET_RTS:
    202      1.1  ichiro 		if (sc->sc_quadumts)
    203      1.1  ichiro 			ubsa_quadumts_rts(sc, portno, onoff);
    204      1.1  ichiro 		else
    205      1.1  ichiro 			ubsa_rts(sc, portno, onoff);
    206      1.1  ichiro 		break;
    207      1.1  ichiro 	case UCOM_SET_BREAK:
    208      1.1  ichiro 		if (!sc->sc_quadumts)
    209      1.1  ichiro 			ubsa_break(sc, portno, onoff);
    210      1.1  ichiro 		break;
    211      1.1  ichiro 	default:
    212      1.1  ichiro 		break;
    213      1.1  ichiro 	}
    214      1.1  ichiro }
    215      1.1  ichiro 
    216      1.2  ichiro void
    217      1.1  ichiro ubsa_baudrate(struct ubsa_softc *sc, int portno, speed_t speed)
    218      1.1  ichiro {
    219      1.1  ichiro 	u_int16_t value = 0;
    220      1.1  ichiro 
    221      1.1  ichiro 	DPRINTF(("ubsa_baudrate: speed = %d\n", speed));
    222      1.1  ichiro 
    223      1.1  ichiro 	switch(speed) {
    224      1.1  ichiro 	case B0:
    225      1.1  ichiro 		break;
    226      1.1  ichiro 	case B300:
    227      1.1  ichiro 	case B600:
    228      1.1  ichiro 	case B1200:
    229      1.1  ichiro 	case B2400:
    230      1.1  ichiro 	case B4800:
    231      1.1  ichiro 	case B9600:
    232      1.1  ichiro 	case B19200:
    233      1.1  ichiro 	case B38400:
    234      1.1  ichiro 	case B57600:
    235      1.1  ichiro 	case B115200:
    236      1.1  ichiro 	case B230400:
    237      1.1  ichiro 		value = B230400 / speed;
    238      1.1  ichiro 		break;
    239      1.1  ichiro 	default:
    240      1.1  ichiro 		printf("%s: ubsa_param: unsupported baudrate, "
    241      1.1  ichiro 		    "forcing default of 9600\n",
    242      1.5  dyoung 		    device_xname(sc->sc_dev));
    243      1.1  ichiro 		value = B230400 / B9600;
    244      1.1  ichiro 		break;
    245      1.1  ichiro 	};
    246      1.1  ichiro 
    247      1.1  ichiro 	if (speed == B0) {
    248      1.1  ichiro 		ubsa_flow(sc, portno, 0, 0);
    249      1.1  ichiro 		ubsa_dtr(sc, portno, 0);
    250      1.1  ichiro 		ubsa_rts(sc, portno, 0);
    251      1.1  ichiro 	} else
    252      1.1  ichiro 		ubsa_request(sc, portno, UBSA_SET_BAUDRATE, value);
    253      1.1  ichiro }
    254      1.1  ichiro 
    255      1.2  ichiro void
    256      1.1  ichiro ubsa_parity(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    257      1.1  ichiro {
    258      1.1  ichiro 	int value;
    259      1.1  ichiro 
    260      1.1  ichiro 	DPRINTF(("ubsa_parity: cflag = 0x%x\n", cflag));
    261      1.1  ichiro 
    262      1.1  ichiro 	if (cflag & PARENB)
    263      1.1  ichiro 		value = (cflag & PARODD) ? UBSA_PARITY_ODD : UBSA_PARITY_EVEN;
    264      1.1  ichiro 	else
    265      1.1  ichiro 		value = UBSA_PARITY_NONE;
    266      1.1  ichiro 
    267      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_PARITY, value);
    268      1.1  ichiro }
    269      1.1  ichiro 
    270      1.2  ichiro void
    271      1.1  ichiro ubsa_databits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    272      1.1  ichiro {
    273      1.1  ichiro 	int value;
    274      1.1  ichiro 
    275      1.1  ichiro 	DPRINTF(("ubsa_databits: cflag = 0x%x\n", cflag));
    276      1.1  ichiro 
    277      1.1  ichiro 	switch (cflag & CSIZE) {
    278      1.1  ichiro 	case CS5: value = 0; break;
    279      1.1  ichiro 	case CS6: value = 1; break;
    280      1.1  ichiro 	case CS7: value = 2; break;
    281      1.1  ichiro 	case CS8: value = 3; break;
    282      1.1  ichiro 	default:
    283      1.1  ichiro 		printf("%s: ubsa_param: unsupported databits requested, "
    284      1.1  ichiro 		    "forcing default of 8\n",
    285      1.5  dyoung 		    device_xname(sc->sc_dev));
    286      1.1  ichiro 		value = 3;
    287      1.1  ichiro 	}
    288      1.1  ichiro 
    289      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_DATA_BITS, value);
    290      1.1  ichiro }
    291      1.1  ichiro 
    292      1.2  ichiro void
    293      1.1  ichiro ubsa_stopbits(struct ubsa_softc *sc, int portno, tcflag_t cflag)
    294      1.1  ichiro {
    295      1.1  ichiro 	int value;
    296      1.1  ichiro 
    297      1.1  ichiro 	DPRINTF(("ubsa_stopbits: cflag = 0x%x\n", cflag));
    298      1.1  ichiro 
    299      1.1  ichiro 	value = (cflag & CSTOPB) ? 1 : 0;
    300      1.1  ichiro 
    301      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_STOP_BITS, value);
    302      1.1  ichiro }
    303      1.1  ichiro 
    304      1.2  ichiro void
    305      1.1  ichiro ubsa_flow(struct ubsa_softc *sc, int portno, tcflag_t cflag, tcflag_t iflag)
    306      1.1  ichiro {
    307      1.1  ichiro 	int value;
    308      1.1  ichiro 
    309      1.1  ichiro 	DPRINTF(("ubsa_flow: cflag = 0x%x, iflag = 0x%x\n", cflag, iflag));
    310      1.1  ichiro 
    311      1.1  ichiro 	value = 0;
    312      1.1  ichiro 	if (cflag & CRTSCTS)
    313      1.1  ichiro 		value |= UBSA_FLOW_OCTS | UBSA_FLOW_IRTS;
    314      1.1  ichiro 	if (iflag & (IXON|IXOFF))
    315      1.1  ichiro 		value |= UBSA_FLOW_OXON | UBSA_FLOW_IXON;
    316      1.1  ichiro 
    317      1.1  ichiro 	ubsa_request(sc, portno, UBSA_SET_FLOW_CTRL, value);
    318      1.1  ichiro }
    319      1.1  ichiro 
    320      1.2  ichiro int
    321      1.1  ichiro ubsa_param(void *addr, int portno, struct termios *ti)
    322      1.1  ichiro {
    323      1.1  ichiro 	struct ubsa_softc *sc = addr;
    324      1.1  ichiro 
    325      1.1  ichiro 	DPRINTF(("ubsa_param: sc = %p\n", sc));
    326      1.1  ichiro 
    327      1.1  ichiro 	if (!sc->sc_quadumts) {
    328      1.1  ichiro 		ubsa_baudrate(sc, portno, ti->c_ospeed);
    329      1.1  ichiro 		ubsa_parity(sc, portno, ti->c_cflag);
    330      1.1  ichiro 		ubsa_databits(sc, portno, ti->c_cflag);
    331      1.1  ichiro 		ubsa_stopbits(sc, portno, ti->c_cflag);
    332      1.1  ichiro 		ubsa_flow(sc, portno, ti->c_cflag, ti->c_iflag);
    333      1.1  ichiro 	}
    334      1.1  ichiro 
    335      1.1  ichiro 	return (0);
    336      1.1  ichiro }
    337      1.1  ichiro 
    338      1.2  ichiro int
    339      1.1  ichiro ubsa_open(void *addr, int portno)
    340      1.1  ichiro {
    341      1.1  ichiro 	struct ubsa_softc *sc = addr;
    342      1.1  ichiro 	int err;
    343      1.1  ichiro 
    344      1.1  ichiro 	if (sc->sc_dying)
    345      1.1  ichiro 		return (ENXIO);
    346      1.1  ichiro 
    347      1.1  ichiro 	if (sc->sc_intr_number != -1 && sc->sc_intr_pipe == NULL) {
    348      1.1  ichiro 		sc->sc_intr_buf = malloc(sc->sc_isize, M_USBDEV, M_WAITOK);
    349      1.1  ichiro 		/* XXX only iface# = 0 has intr line */
    350      1.1  ichiro 		/* XXX E220 specific? need to check */
    351      1.1  ichiro 		err = usbd_open_pipe_intr(sc->sc_iface[0],
    352      1.1  ichiro 		    sc->sc_intr_number,
    353      1.1  ichiro 		    USBD_SHORT_XFER_OK,
    354      1.1  ichiro 		    &sc->sc_intr_pipe,
    355      1.1  ichiro 		    sc,
    356      1.1  ichiro 		    sc->sc_intr_buf,
    357      1.1  ichiro 		    sc->sc_isize,
    358      1.1  ichiro 		    ubsa_intr,
    359      1.1  ichiro 		    UBSA_INTR_INTERVAL);
    360      1.1  ichiro 		if (err) {
    361      1.1  ichiro 			printf("%s: cannot open interrupt pipe (addr %d)\n",
    362      1.5  dyoung 			    device_xname(sc->sc_dev),
    363      1.1  ichiro 			    sc->sc_intr_number);
    364      1.1  ichiro 			return (EIO);
    365      1.1  ichiro 		}
    366      1.1  ichiro 	}
    367      1.1  ichiro 
    368      1.1  ichiro 	return (0);
    369      1.1  ichiro }
    370      1.1  ichiro 
    371      1.2  ichiro void
    372      1.1  ichiro ubsa_close(void *addr, int portno)
    373      1.1  ichiro {
    374      1.1  ichiro 	struct ubsa_softc *sc = addr;
    375      1.1  ichiro 	int err;
    376      1.1  ichiro 
    377      1.1  ichiro 	if (sc->sc_dying)
    378      1.1  ichiro 		return;
    379      1.1  ichiro 
    380      1.1  ichiro 	DPRINTF(("ubsa_close: close\n"));
    381      1.1  ichiro 
    382      1.1  ichiro 	if (sc->sc_intr_pipe != NULL) {
    383      1.1  ichiro 		err = usbd_abort_pipe(sc->sc_intr_pipe);
    384      1.1  ichiro 		if (err)
    385      1.1  ichiro 			printf("%s: abort interrupt pipe failed: %s\n",
    386      1.5  dyoung 			    device_xname(sc->sc_dev),
    387      1.1  ichiro 			    usbd_errstr(err));
    388      1.1  ichiro 		err = usbd_close_pipe(sc->sc_intr_pipe);
    389      1.1  ichiro 		if (err)
    390      1.1  ichiro 			printf("%s: close interrupt pipe failed: %s\n",
    391      1.5  dyoung 			    device_xname(sc->sc_dev),
    392      1.1  ichiro 			    usbd_errstr(err));
    393      1.1  ichiro 		free(sc->sc_intr_buf, M_USBDEV);
    394      1.1  ichiro 		sc->sc_intr_pipe = NULL;
    395      1.1  ichiro 	}
    396      1.1  ichiro }
    397      1.1  ichiro 
    398      1.2  ichiro void
    399      1.1  ichiro ubsa_intr(usbd_xfer_handle xfer, usbd_private_handle priv,
    400      1.1  ichiro     usbd_status status)
    401      1.1  ichiro {
    402      1.1  ichiro 	struct ubsa_softc *sc = priv;
    403      1.1  ichiro 	u_char *buf;
    404      1.1  ichiro 	int i;
    405      1.1  ichiro 
    406      1.1  ichiro 	buf = sc->sc_intr_buf;
    407      1.1  ichiro 	if (sc->sc_dying)
    408      1.1  ichiro 		return;
    409      1.1  ichiro 
    410      1.1  ichiro 	if (status != USBD_NORMAL_COMPLETION) {
    411      1.1  ichiro 		if (status == USBD_NOT_STARTED || status == USBD_CANCELLED)
    412      1.1  ichiro 			return;
    413      1.1  ichiro 
    414      1.1  ichiro 		DPRINTF(("%s: ubsa_intr: abnormal status: %s\n",
    415      1.5  dyoung 		    device_xname(sc->sc_dev), usbd_errstr(status)));
    416      1.1  ichiro 		usbd_clear_endpoint_stall_async(sc->sc_intr_pipe);
    417      1.1  ichiro 		return;
    418      1.1  ichiro 	}
    419      1.1  ichiro 
    420      1.1  ichiro 	/* incidentally, Belkin adapter status bits match UART 16550 bits */
    421      1.1  ichiro 	sc->sc_lsr = buf[2];
    422      1.1  ichiro 	sc->sc_msr = buf[3];
    423      1.1  ichiro 
    424      1.1  ichiro 	DPRINTF(("%s: ubsa lsr = 0x%02x, msr = 0x%02x\n",
    425      1.5  dyoung 	    device_xname(sc->sc_dev), sc->sc_lsr, sc->sc_msr));
    426      1.1  ichiro 
    427      1.1  ichiro 	for (i = 0; i < sc->sc_numif; i++) {
    428      1.4    cube 		ucom_status_change(device_private(sc->sc_subdevs[i]));
    429      1.1  ichiro 	}
    430      1.1  ichiro }
    431      1.1  ichiro 
    432      1.2  ichiro void
    433      1.1  ichiro ubsa_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
    434      1.1  ichiro {
    435      1.1  ichiro 	struct ubsa_softc *sc = addr;
    436      1.1  ichiro 
    437      1.1  ichiro 	DPRINTF(("ubsa_get_status\n"));
    438      1.1  ichiro 
    439      1.1  ichiro 	if (lsr != NULL)
    440      1.1  ichiro 		*lsr = sc->sc_lsr;
    441      1.1  ichiro 	if (msr != NULL)
    442      1.1  ichiro 		*msr = sc->sc_msr;
    443      1.1  ichiro }
    444      1.1  ichiro 
    445