2 * Copyright (c) 2004 Bernd Walter <ticso@freebsd.org>
4 * $URL: https://devel.bwct.de/svn/projects/ubser/ubser.c $
5 * $Date: 2004-02-29 01:53:10 +0100 (Sun, 29 Feb 2004) $
11 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * Copyright (c) 2000 The NetBSD Foundation, Inc.
38 * All rights reserved.
40 * This code is derived from software contributed to The NetBSD Foundation
41 * by Lennart Augustsson (lennart@augustsson.net).
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the NetBSD
54 * Foundation, Inc. and its contributors.
55 * 4. Neither the name of The NetBSD Foundation nor the names of its
56 * contributors may be used to endorse or promote products derived
57 * from this software without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
60 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
61 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
63 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
64 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
65 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
66 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
67 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
68 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
69 * POSSIBILITY OF SUCH DAMAGE.
72 #include <sys/cdefs.h>
73 __FBSDID("$FreeBSD$");
76 * BWCT serial adapter driver
79 #include <sys/cdefs.h>
81 #include <sys/param.h>
82 #include <sys/systm.h>
83 #include <sys/kernel.h>
84 #include <sys/module.h>
85 #include <sys/malloc.h>
87 #include <sys/ioccom.h>
88 #include <sys/fcntl.h>
90 #include <sys/serial.h>
92 #include <sys/clist.h>
95 #include <sys/selinfo.h>
97 #include <sys/sysctl.h>
99 #include <dev/usb/usb.h>
100 #include <dev/usb/usbhid.h>
102 #include <dev/usb/usbdi.h>
103 #include <dev/usb/usbdi_util.h>
106 #include <dev/usb/ubser.h>
109 static int ubserdebug = 0;
110 SYSCTL_NODE(_hw_usb, OID_AUTO, ubser, CTLFLAG_RW, 0, "USB ubser");
111 SYSCTL_INT(_hw_usb_ubser, OID_AUTO, debug, CTLFLAG_RW,
112 &ubserdebug, 0, "ubser debug level");
113 #define DPRINTF(x) do { \
118 #define DPRINTFN(n, x) do { \
119 if (ubserdebug > (n)) \
124 #define DPRINTFN(n,x)
127 #define ISSET(t, f) ((t) & (f))
128 #define SET(t, f) (t) |= (f)
129 #define CLR(t, f) (t) &= ~((unsigned)(f))
133 struct ubser_softc *p_sc;
134 usbd_xfer_handle p_oxfer; /* write request */
135 u_char *p_obuf; /* write buffer */
140 USBBASEDEVICE sc_dev;
141 usbd_device_handle sc_udev;
142 usbd_interface_handle sc_iface; /* data interface */
151 int sc_bulkin_no; /* bulk in endpoint address */
152 usbd_pipe_handle sc_bulkin_pipe; /* bulk in pipe */
153 usbd_xfer_handle sc_ixfer; /* read request */
154 u_char *sc_ibuf; /* read buffer */
155 u_int sc_ibufsize; /* read buffer size */
156 u_int sc_ibufsizepad; /* read buffer size padded */
158 int sc_bulkout_no; /* bulk out endpoint address */
159 usbd_pipe_handle sc_bulkout_pipe;/* bulk out pipe */
160 u_int sc_obufsize; /* write buffer size */
161 u_int sc_opkthdrlen; /* header length of
164 struct ubser_port *sc_port;
167 Static int ubserparam(struct tty *, struct termios *);
168 Static void ubserstart(struct tty *);
169 Static void ubserstop(struct tty *, int);
170 Static usbd_status ubserstartread(struct ubser_softc *);
171 Static void ubserreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
172 Static void ubserwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
173 Static void ubser_cleanup(struct ubser_softc *sc);
175 Static t_break_t ubserbreak;
176 Static t_open_t ubseropen;
177 Static t_close_t ubserclose;
178 Static t_modem_t ubsermodem;
180 USB_DECLARE_DRIVER(ubser);
184 USB_MATCH_START(ubser, uaa);
185 usb_string_descriptor_t us;
186 usb_interface_descriptor_t *id;
187 usb_device_descriptor_t *dd;
190 if (uaa->iface == NULL)
191 return (UMATCH_NONE);
193 DPRINTFN(20,("ubser: vendor=0x%x, product=0x%x\n",
194 uaa->vendor, uaa->product));
196 dd = usbd_get_device_descriptor(uaa->device);
198 printf("ubser: failed to get device descriptor\n");
199 return (UMATCH_NONE);
202 id = usbd_get_interface_descriptor(uaa->iface);
204 printf("ubser: failed to get interface descriptor\n");
205 return (UMATCH_NONE);
208 err = usbd_get_string_desc(uaa->device, dd->iManufacturer, 0, &us,
211 return (UMATCH_NONE);
213 /* check if this is a BWCT vendor specific ubser interface */
214 if (strcmp((char*)us.bString, "B\0W\0C\0T\0") == 0 &&
215 id->bInterfaceClass == 0xff && id->bInterfaceSubClass == 0x00)
216 return (UMATCH_VENDOR_IFACESUBCLASS);
218 return (UMATCH_NONE);
223 USB_ATTACH_START(ubser, sc, uaa);
224 usbd_device_handle udev = uaa->device;
225 usb_endpoint_descriptor_t *ed;
226 usb_interface_descriptor_t *id;
227 usb_device_request_t req;
234 struct ubser_port *pp;
236 devinfo = malloc(1024, M_USBDEV, M_WAITOK);
237 usbd_devinfo(udev, 0, devinfo);
240 DPRINTFN(10,("\nubser_attach: sc=%p\n", sc));
242 sc->sc_udev = udev = uaa->device;
243 sc->sc_iface = uaa->iface;
247 /* get interface index */
248 id = usbd_get_interface_descriptor(uaa->iface);
250 printf("ubser: failed to get interface descriptor\n");
251 return (UMATCH_NONE);
253 sc->sc_ifaceno = id->bInterfaceNumber;
255 /* get number of serials */
256 req.bmRequestType = UT_READ_VENDOR_INTERFACE;
257 req.bRequest = VENDOR_GET_NUMSER;
258 USETW(req.wValue, 0);
259 USETW(req.wIndex, sc->sc_ifaceno);
260 USETW(req.wLength, 1);
261 err = usbd_do_request_flags(udev, &req, &sc->sc_numser,
262 USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
264 printf("%s: failed to get number of serials\n",
265 USBDEVNAME(sc->sc_dev));
267 } else if (alen != 1) {
268 printf("%s: bogus answer on get_numser\n",
269 USBDEVNAME(sc->sc_dev));
272 if (sc->sc_numser > MAX_SER)
273 sc->sc_numser = MAX_SER;
274 printf("%s: found %i serials\n", USBDEVNAME(sc->sc_dev), sc->sc_numser);
276 sc->sc_port = malloc(sizeof(*sc->sc_port) * sc->sc_numser,
279 /* find our bulk endpoints */
281 usbd_endpoint_count(sc->sc_iface, &epcount);
282 sc->sc_bulkin_no = -1;
283 sc->sc_bulkout_no = -1;
284 for (i = 0; i < epcount; i++) {
285 ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i);
287 printf("%s: couldn't get ep %d\n",
288 USBDEVNAME(sc->sc_dev), i);
289 USB_ATTACH_ERROR_RETURN;
291 if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
292 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
293 sc->sc_bulkin_no = ed->bEndpointAddress;
294 sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize);
295 sc->sc_ibufsizepad = UGETW(ed->wMaxPacketSize) - 1;
296 } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT &&
297 UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
298 sc->sc_bulkout_no = ed->bEndpointAddress;
299 sc->sc_obufsize = UGETW(ed->wMaxPacketSize) - 1;
300 sc->sc_opkthdrlen = 1;
303 if (sc->sc_bulkin_no == -1 || sc->sc_bulkout_no == -1) {
304 printf("%s: could not find bulk in/out endpoint\n",
305 USBDEVNAME(sc->sc_dev));
310 /* Open the bulk pipes */
312 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no, 0,
313 &sc->sc_bulkin_pipe);
315 printf("%s: open bulk in error (addr %d): %s\n",
316 USBDEVNAME(sc->sc_dev), sc->sc_bulkin_no,
321 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
322 USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
324 printf("%s: open bulk out error (addr %d): %s\n",
325 USBDEVNAME(sc->sc_dev), sc->sc_bulkout_no,
330 /* Allocate a request and an input buffer */
331 sc->sc_ixfer = usbd_alloc_xfer(sc->sc_udev);
332 if (sc->sc_ixfer == NULL) {
336 sc->sc_ibuf = usbd_alloc_buffer(sc->sc_ixfer,
338 if (sc->sc_ibuf == NULL) {
342 for (i = 0; i < sc->sc_numser; i++) {
343 pp = &sc->sc_port[i];
346 tp = pp->p_tty = ttyalloc();
348 DPRINTF(("ubser_attach: tty_attach tp = %p\n", tp));
349 tp->t_oproc = ubserstart;
350 tp->t_param = ubserparam;
351 tp->t_stop = ubserstop;
352 tp->t_break = ubserbreak;
353 tp->t_open = ubseropen;
354 tp->t_close = ubserclose;
355 tp->t_modem = ubsermodem;
356 ttycreate(tp, NULL, 0, 0, "y%r%r", USBDEVUNIT(sc->sc_dev), i);
360 for (i = 0; i < sc->sc_numser; i++) {
361 sc->sc_port[i].p_oxfer = NULL;
362 sc->sc_port[i].p_obuf = NULL;
364 for (i = 0; i < sc->sc_numser; i++) {
365 sc->sc_port[i].p_oxfer = usbd_alloc_xfer(sc->sc_udev);
366 if (sc->sc_port[i].p_oxfer == NULL) {
370 sc->sc_port[i].p_obuf = usbd_alloc_buffer(sc->sc_port[i].p_oxfer,
373 if (sc->sc_port[i].p_obuf == NULL) {
380 free(devinfo, M_USBDEV);
381 USB_ATTACH_SUCCESS_RETURN;
384 for (i = 0; i < sc->sc_numser; i++) {
385 if (sc->sc_port[i].p_oxfer != NULL) {
386 usbd_free_xfer(sc->sc_port[i].p_oxfer);
387 sc->sc_port[i].p_oxfer = NULL;
391 usbd_free_xfer(sc->sc_ixfer);
394 usbd_close_pipe(sc->sc_bulkout_pipe);
395 sc->sc_bulkout_pipe = NULL;
397 usbd_close_pipe(sc->sc_bulkin_pipe);
398 sc->sc_bulkin_pipe = NULL;
401 wakeup(&sc->sc_opening);
405 if (sc->sc_port != NULL) {
406 for (i = 0; i < sc->sc_numser; i++) {
407 pp = &sc->sc_port[i];
408 if (pp->p_tty != NULL)
411 free(sc->sc_port, M_USBDEV);
415 DPRINTF(("ubser_attach: ATTACH ERROR\n"));
416 free(devinfo, M_USBDEV);
418 USB_ATTACH_ERROR_RETURN;
423 USB_DETACH_START(ubser, sc);
425 struct ubser_port *pp;
427 DPRINTF(("ubser_detach: sc=%p\n", sc));
430 for (i = 0; i < sc->sc_numser; i++) {
431 pp = &sc->sc_port[i];
432 if (pp->p_tty != NULL)
436 if (sc->sc_bulkin_pipe != NULL)
437 usbd_abort_pipe(sc->sc_bulkin_pipe);
438 if (sc->sc_bulkout_pipe != NULL)
439 usbd_abort_pipe(sc->sc_bulkout_pipe);
441 if (sc->sc_port != NULL) {
442 for (i = 0; i < sc->sc_numser; i++) {
443 pp = &sc->sc_port[i];
444 if (pp->p_tty != NULL)
447 free(sc->sc_port, M_USBDEV);
451 if (--sc->sc_refcnt >= 0) {
452 /* Wait for processes to go away. */
453 usb_detach_wait(USBDEV(sc->sc_dev));
460 ubserparam(struct tty *tp, struct termios *t)
462 struct ubser_softc *sc;
463 struct ubser_port *pp;
471 DPRINTF(("ubserparam: sc = %p\n", sc));
474 * The firmware on our devices can only do 8n1@9600bps
476 * We refuse to accept other configurations.
479 /* enshure 9600bps */
480 switch (t->c_ospeed) {
487 /* 2 stop bits not possible */
488 if (ISSET(t->c_cflag, CSTOPB))
491 /* XXX parity handling not possible with current firmware */
492 if (ISSET(t->c_cflag, PARENB))
495 /* we can only do 8 data bits */
496 switch (ISSET(t->c_cflag, CSIZE)) {
503 /* we can't do any kind of hardware handshaking */
505 (CRTS_IFLOW | CDTR_IFLOW |CDSR_OFLOW |CCAR_OFLOW)) != 0)
509 * XXX xon/xoff not supported by the firmware!
510 * This is handled within FreeBSD only and may overflow buffers
511 * because of delayed reaction due to device buffering.
520 ubserstart(struct tty *tp)
522 struct ubser_softc *sc;
523 struct ubser_port *pp;
533 DPRINTF(("ubserstart: sc = %p, tp = %p\n", sc, tp));
538 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
540 DPRINTF(("ubserstart: stopped\n"));
544 if (tp->t_outq.c_cc <= tp->t_olowat) {
545 if (ISSET(tp->t_state, TS_SO_OLOWAT)) {
546 CLR(tp->t_state, TS_SO_OLOWAT);
547 wakeup(TSA_OLOWAT(tp));
549 selwakeuppri(&tp->t_wsel, TTIPRI);
550 if (tp->t_outq.c_cc == 0) {
551 if (ISSET(tp->t_state, TS_BUSY | TS_SO_OCOMPLETE) ==
552 TS_SO_OCOMPLETE && tp->t_outq.c_cc == 0) {
553 CLR(tp->t_state, TS_SO_OCOMPLETE);
554 wakeup(TSA_OCOMPLETE(tp));
560 /* Grab the first contiguous region of buffer space. */
561 data = tp->t_outq.c_cf;
562 cbp = (struct cblock *) ((intptr_t) tp->t_outq.c_cf & ~CROUND);
563 cnt = min((char *) (cbp+1) - tp->t_outq.c_cf, tp->t_outq.c_cc);
566 DPRINTF(("ubserstart: cnt == 0\n"));
570 SET(tp->t_state, TS_BUSY);
572 if (cnt + sc->sc_opkthdrlen > sc->sc_obufsize) {
573 DPRINTF(("ubserstart: big buffer %d chars\n", cnt));
574 cnt = sc->sc_obufsize;
576 sc->sc_port[serial].p_obuf[0] = serial;
577 memcpy(sc->sc_port[serial].p_obuf + sc->sc_opkthdrlen, data, cnt);
580 DPRINTF(("ubserstart: %d chars\n", cnt));
581 usbd_setup_xfer(sc->sc_port[serial].p_oxfer, sc->sc_bulkout_pipe,
582 (usbd_private_handle)tp, sc->sc_port[serial].p_obuf,
583 cnt + sc->sc_opkthdrlen,
584 USBD_NO_COPY, USBD_NO_TIMEOUT, ubserwritecb);
585 /* What can we do on error? */
586 err = usbd_transfer(sc->sc_port[serial].p_oxfer);
587 if (err != USBD_IN_PROGRESS)
588 printf("ubserstart: err=%s\n", usbd_errstr(err));
594 ubserstop(struct tty *tp, int flag)
596 struct ubser_softc *sc;
600 DPRINTF(("ubserstop: %d\n", flag));
603 DPRINTF(("ubserstop: write\n"));
604 if (ISSET(tp->t_state, TS_BUSY)) {
606 if (!ISSET(tp->t_state, TS_TTSTOP))
607 SET(tp->t_state, TS_FLUSH);
611 DPRINTF(("ubserstop: done\n"));
615 ubserwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
618 struct ubser_softc *sc;
619 struct ubser_port *pp;
622 tp = (struct tty *)p;
626 DPRINTF(("ubserwritecb: status = %d\n", status));
628 if (status == USBD_CANCELLED || sc->sc_dying)
631 if (status != USBD_NORMAL_COMPLETION) {
632 printf("%s: ubserwritecb: %s\n",
633 USBDEVNAME(sc->sc_dev), usbd_errstr(status));
634 if (status == USBD_STALLED)
635 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
636 /* XXX we should restart after some delay. */
640 usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
641 DPRINTF(("ubserwritecb: cc = %d\n", cc));
642 if (cc <= sc->sc_opkthdrlen) {
643 printf("%s: sent size too small, cc = %d\n",
644 USBDEVNAME(sc->sc_dev), cc);
648 /* convert from USB bytes to tty bytes */
649 cc -= sc->sc_opkthdrlen;
651 CLR(tp->t_state, TS_BUSY);
652 if (ISSET(tp->t_state, TS_FLUSH))
653 CLR(tp->t_state, TS_FLUSH);
655 ndflush(&tp->t_outq, cc);
661 CLR(tp->t_state, TS_BUSY);
666 ubserstartread(struct ubser_softc *sc)
670 DPRINTF(("ubserstartread: start\n"));
672 if (sc->sc_bulkin_pipe == NULL)
673 return (USBD_NORMAL_COMPLETION);
675 usbd_setup_xfer(sc->sc_ixfer, sc->sc_bulkin_pipe,
676 (usbd_private_handle)sc,
677 sc->sc_ibuf, sc->sc_ibufsizepad,
678 USBD_SHORT_XFER_OK | USBD_NO_COPY,
679 USBD_NO_TIMEOUT, ubserreadcb);
681 err = usbd_transfer(sc->sc_ixfer);
682 if (err != USBD_IN_PROGRESS) {
683 DPRINTF(("ubserstartread: err = %s\n", usbd_errstr(err)));
687 return (USBD_NORMAL_COMPLETION);
691 ubserreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
693 struct ubser_softc *sc = (struct ubser_softc *)p;
700 if (status == USBD_IOERROR) {
701 printf("%s: ubserreadcb: %s - restarting\n",
702 USBDEVNAME(sc->sc_dev), usbd_errstr(status));
706 DPRINTF(("ubserreadcb: status = %d\n", status));
708 if (status != USBD_NORMAL_COMPLETION) {
709 if (status != USBD_CANCELLED) {
710 printf("%s: ubserreadcb: %s\n",
711 USBDEVNAME(sc->sc_dev), usbd_errstr(status));
713 if (status == USBD_STALLED)
714 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
718 usbd_get_xfer_status(xfer, NULL, (void **)&cp, &cc, NULL);
720 DPRINTF(("ubserreadcb: got %d bytes from device\n", cc));
724 if (cc > sc->sc_ibufsizepad) {
725 printf("%s: invalid receive data size, %d chars\n",
726 USBDEVNAME(sc->sc_dev), cc);
733 DPRINTF(("ubserreadcb: got %d chars for serial %d\n", cc - 1, *cp));
734 tp = sc->sc_port[*cp].p_tty;
741 if (!(tp->t_state & TS_ISOPEN)) /* drop data for unused serials */
744 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
745 if (tp->t_rawq.c_cc + cc > tp->t_ihiwat
746 && (tp->t_iflag & IXOFF)
747 && !(tp->t_state & TS_TBLOCK))
749 lostcc = b_to_q((char *)cp, cc, &tp->t_rawq);
752 if (tp->t_state & TS_TTSTOP
753 && (tp->t_iflag & IXANY
754 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
755 tp->t_state &= ~TS_TTSTOP;
756 tp->t_lflag &= ~FLUSHO;
760 printf("%s: lost %d chars\n", USBDEVNAME(sc->sc_dev),
763 /* Give characters to tty layer. */
765 DPRINTFN(7, ("ubserreadcb: char = 0x%02x\n", *cp));
766 if (ttyld_rint(tp, *cp) == -1) {
767 /* XXX what should we do? */
768 printf("%s: lost %d chars\n",
769 USBDEVNAME(sc->sc_dev), cc);
778 err = ubserstartread(sc);
780 printf("%s: read start failed\n", USBDEVNAME(sc->sc_dev));
781 /* XXX what should we do now? */
787 ubser_cleanup(struct ubser_softc *sc)
790 struct ubser_port *pp;
792 DPRINTF(("ubser_cleanup: closing pipes\n"));
794 if (sc->sc_bulkin_pipe != NULL) {
795 usbd_abort_pipe(sc->sc_bulkin_pipe);
796 usbd_close_pipe(sc->sc_bulkin_pipe);
797 sc->sc_bulkin_pipe = NULL;
799 if (sc->sc_bulkout_pipe != NULL) {
800 usbd_abort_pipe(sc->sc_bulkout_pipe);
801 usbd_close_pipe(sc->sc_bulkout_pipe);
802 sc->sc_bulkout_pipe = NULL;
804 if (sc->sc_ixfer != NULL) {
805 usbd_free_xfer(sc->sc_ixfer);
808 for (i = 0; i < sc->sc_numser; i++) {
809 pp = &sc->sc_port[i];
810 if (pp->p_oxfer != NULL) {
811 usbd_free_xfer(pp->p_oxfer);
818 ubseropen(struct tty *tp, struct cdev *dev)
820 struct ubser_softc *sc;
821 struct ubser_port *pp;
826 sc->sc_refcnt++; /* XXX: wrong refcnt on error later on */
831 ubserclose(struct tty *tp)
833 struct ubser_softc *sc;
834 struct ubser_port *pp;
838 if (--sc->sc_refcnt < 0)
839 usb_detach_wakeup(USBDEV(sc->sc_dev));
843 ubserbreak(struct tty *tp, int sig)
845 usb_device_request_t req;
846 struct ubser_softc *sc;
847 struct ubser_port *pp;
854 DPRINTF(("ubser_break: TIOCSBRK\n"));
855 req.bmRequestType = UT_READ_VENDOR_INTERFACE;
856 req.bRequest = VENDOR_SET_BREAK;
857 USETW(req.wValue, pp->p_port);
858 USETW(req.wIndex, sc->sc_ifaceno);
859 USETW(req.wLength, 0);
860 error = usbd_do_request_flags(sc->sc_udev, &req, &sc->sc_numser,
861 USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT);
866 ubsermodem(struct tty *tp, int sigon, int sigoff)
869 return (SER_DTR | SER_RTS | SER_DCD);
872 DRIVER_MODULE(ubser, uhub, ubser_driver, ubser_devclass, usbd_driver_load, 0);