1 /* $NetBSD: ucom.c,v 1.40 2001/11/13 06:24:54 lukem Exp $ */
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
6 * Copyright (c) 2001-2003, 2005, 2008
7 * Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
36 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
37 * All rights reserved.
39 * This code is derived from software contributed to The NetBSD Foundation
40 * by Lennart Augustsson (lennart@augustsson.net) at
41 * Carlstedt Research & Technology.
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.
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.
65 #include <sys/stdint.h>
66 #include <sys/stddef.h>
67 #include <sys/param.h>
68 #include <sys/queue.h>
69 #include <sys/types.h>
70 #include <sys/systm.h>
71 #include <sys/kernel.h>
73 #include <sys/module.h>
75 #include <sys/mutex.h>
76 #include <sys/condvar.h>
77 #include <sys/sysctl.h>
79 #include <sys/unistd.h>
80 #include <sys/callout.h>
81 #include <sys/malloc.h>
85 #include <dev/uart/uart_ppstypes.h>
87 #include <dev/usb/usb.h>
88 #include <dev/usb/usbdi.h>
89 #include <dev/usb/usbdi_util.h>
91 #define USB_DEBUG_VAR ucom_debug
92 #include <dev/usb/usb_debug.h>
93 #include <dev/usb/usb_busdma.h>
94 #include <dev/usb/usb_process.h>
96 #include <dev/usb/serial/usb_serial.h>
100 static SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom");
102 static int ucom_pps_mode;
104 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, pps_mode, CTLFLAG_RWTUN,
106 "pulse capture mode: 0/1/2=disabled/CTS/DCD; add 0x10 to invert");
108 static int ucom_device_mode_console = 1;
110 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, device_mode_console, CTLFLAG_RW,
111 &ucom_device_mode_console, 0,
112 "set to 1 to mark terminals as consoles when in device mode");
115 static int ucom_debug = 0;
117 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, debug, CTLFLAG_RWTUN,
118 &ucom_debug, 0, "ucom debug level");
121 #define UCOM_CONS_BUFSIZE 1024
123 static uint8_t ucom_cons_rx_buf[UCOM_CONS_BUFSIZE];
124 static uint8_t ucom_cons_tx_buf[UCOM_CONS_BUFSIZE];
126 static unsigned int ucom_cons_rx_low = 0;
127 static unsigned int ucom_cons_rx_high = 0;
129 static unsigned int ucom_cons_tx_low = 0;
130 static unsigned int ucom_cons_tx_high = 0;
132 static int ucom_cons_unit = -1;
133 static int ucom_cons_subunit = 0;
134 static int ucom_cons_baud = 9600;
135 static struct ucom_softc *ucom_cons_softc = NULL;
137 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, cons_unit, CTLFLAG_RWTUN,
138 &ucom_cons_unit, 0, "console unit number");
139 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, cons_subunit, CTLFLAG_RWTUN,
140 &ucom_cons_subunit, 0, "console subunit number");
141 SYSCTL_INT(_hw_usb_ucom, OID_AUTO, cons_baud, CTLFLAG_RWTUN,
142 &ucom_cons_baud, 0, "console baud rate");
144 static usb_proc_callback_t ucom_cfg_start_transfers;
145 static usb_proc_callback_t ucom_cfg_open;
146 static usb_proc_callback_t ucom_cfg_close;
147 static usb_proc_callback_t ucom_cfg_line_state;
148 static usb_proc_callback_t ucom_cfg_status_change;
149 static usb_proc_callback_t ucom_cfg_param;
151 static int ucom_unit_alloc(void);
152 static void ucom_unit_free(int);
153 static int ucom_attach_tty(struct ucom_super_softc *, struct ucom_softc *);
154 static void ucom_detach_tty(struct ucom_super_softc *, struct ucom_softc *);
155 static void ucom_queue_command(struct ucom_softc *,
156 usb_proc_callback_t *, struct termios *pt,
157 struct usb_proc_msg *t0, struct usb_proc_msg *t1);
158 static void ucom_shutdown(struct ucom_softc *);
159 static void ucom_ring(struct ucom_softc *, uint8_t);
160 static void ucom_break(struct ucom_softc *, uint8_t);
161 static void ucom_dtr(struct ucom_softc *, uint8_t);
162 static void ucom_rts(struct ucom_softc *, uint8_t);
164 static tsw_open_t ucom_open;
165 static tsw_close_t ucom_close;
166 static tsw_ioctl_t ucom_ioctl;
167 static tsw_modem_t ucom_modem;
168 static tsw_param_t ucom_param;
169 static tsw_outwakeup_t ucom_outwakeup;
170 static tsw_inwakeup_t ucom_inwakeup;
171 static tsw_free_t ucom_free;
172 static tsw_busy_t ucom_busy;
174 static struct ttydevsw ucom_class = {
175 .tsw_flags = TF_INITLOCK | TF_CALLOUT,
176 .tsw_open = ucom_open,
177 .tsw_close = ucom_close,
178 .tsw_outwakeup = ucom_outwakeup,
179 .tsw_inwakeup = ucom_inwakeup,
180 .tsw_ioctl = ucom_ioctl,
181 .tsw_param = ucom_param,
182 .tsw_modem = ucom_modem,
183 .tsw_free = ucom_free,
184 .tsw_busy = ucom_busy,
187 MODULE_DEPEND(ucom, usb, 1, 1, 1);
188 MODULE_VERSION(ucom, 1);
190 #define UCOM_UNIT_MAX 128 /* maximum number of units */
191 #define UCOM_TTY_PREFIX "U"
193 static struct unrhdr *ucom_unrhdr;
194 static struct mtx ucom_mtx;
195 static int ucom_close_refs;
201 ucom_unrhdr = new_unrhdr(0, UCOM_UNIT_MAX - 1, NULL);
202 mtx_init(&ucom_mtx, "UCOM MTX", NULL, MTX_DEF);
204 SYSINIT(ucom_init, SI_SUB_KLD - 1, SI_ORDER_ANY, ucom_init, NULL);
207 ucom_uninit(void *arg)
218 mtx_destroy(&ucom_mtx);
220 SYSUNINIT(ucom_uninit, SI_SUB_KLD - 3, SI_ORDER_ANY, ucom_uninit, NULL);
223 * Mark a unit number (the X in cuaUX) as in use.
225 * Note that devices using a different naming scheme (see ucom_tty_name()
226 * callback) still use this unit allocation.
229 ucom_unit_alloc(void)
234 if (ucom_unrhdr == NULL) {
235 DPRINTF("ucom_unrhdr is NULL\n");
238 unit = alloc_unr(ucom_unrhdr);
239 DPRINTF("unit %d is allocated\n", unit);
244 * Mark the unit number as not in use.
247 ucom_unit_free(int unit)
250 if (unit < 0 || unit >= UCOM_UNIT_MAX || ucom_unrhdr == NULL) {
251 DPRINTF("cannot free unit number\n");
254 DPRINTF("unit %d is freed\n", unit);
255 free_unr(ucom_unrhdr, unit);
259 * Setup a group of one or more serial ports.
261 * The mutex pointed to by "mtx" is applied before all
262 * callbacks are called back. Also "mtx" must be applied
263 * before calling into the ucom-layer!
266 ucom_attach(struct ucom_super_softc *ssc, struct ucom_softc *sc,
267 int subunits, void *parent,
268 const struct ucom_callback *callback, struct mtx *mtx)
275 (callback == NULL) ||
280 /* allocate a uniq unit number */
281 ssc->sc_unit = ucom_unit_alloc();
282 if (ssc->sc_unit == -1)
285 /* generate TTY name string */
286 snprintf(ssc->sc_ttyname, sizeof(ssc->sc_ttyname),
287 UCOM_TTY_PREFIX "%d", ssc->sc_unit);
289 /* create USB request handling process */
290 error = usb_proc_create(&ssc->sc_tq, mtx, "ucom", USB_PRI_MED);
292 ucom_unit_free(ssc->sc_unit);
295 ssc->sc_subunits = subunits;
296 ssc->sc_flag = UCOM_FLAG_ATTACHED |
297 UCOM_FLAG_FREE_UNIT | (ssc->sc_flag & UCOM_FLAG_DEVICE_MODE);
299 if (callback->ucom_free == NULL)
300 ssc->sc_flag |= UCOM_FLAG_WAIT_REFS;
302 /* increment reference count */
305 for (subunit = 0; subunit < ssc->sc_subunits; subunit++) {
306 sc[subunit].sc_subunit = subunit;
307 sc[subunit].sc_super = ssc;
308 sc[subunit].sc_mtx = mtx;
309 sc[subunit].sc_parent = parent;
310 sc[subunit].sc_callback = callback;
312 error = ucom_attach_tty(ssc, &sc[subunit]);
314 ucom_detach(ssc, &sc[0]);
317 /* increment reference count */
320 /* set subunit attached */
321 sc[subunit].sc_flag |= UCOM_FLAG_ATTACHED;
324 DPRINTF("tp = %p, unit = %d, subunits = %d\n",
325 sc->sc_tty, ssc->sc_unit, ssc->sc_subunits);
331 * The following function will do nothing if the structure pointed to
332 * by "ssc" and "sc" is zero or has already been detached.
335 ucom_detach(struct ucom_super_softc *ssc, struct ucom_softc *sc)
339 if (!(ssc->sc_flag & UCOM_FLAG_ATTACHED))
340 return; /* not initialized */
342 if (ssc->sc_sysctl_ttyname != NULL) {
343 sysctl_remove_oid(ssc->sc_sysctl_ttyname, 1, 0);
344 ssc->sc_sysctl_ttyname = NULL;
347 if (ssc->sc_sysctl_ttyports != NULL) {
348 sysctl_remove_oid(ssc->sc_sysctl_ttyports, 1, 0);
349 ssc->sc_sysctl_ttyports = NULL;
352 usb_proc_drain(&ssc->sc_tq);
354 for (subunit = 0; subunit < ssc->sc_subunits; subunit++) {
355 if (sc[subunit].sc_flag & UCOM_FLAG_ATTACHED) {
357 ucom_detach_tty(ssc, &sc[subunit]);
359 /* avoid duplicate detach */
360 sc[subunit].sc_flag &= ~UCOM_FLAG_ATTACHED;
363 usb_proc_free(&ssc->sc_tq);
367 if (ssc->sc_flag & UCOM_FLAG_WAIT_REFS)
370 /* make sure we don't detach twice */
371 ssc->sc_flag &= ~UCOM_FLAG_ATTACHED;
375 ucom_drain(struct ucom_super_softc *ssc)
378 while (ssc->sc_refs > 0) {
379 printf("ucom: Waiting for a TTY device to close.\n");
380 usb_pause_mtx(&ucom_mtx, hz);
382 mtx_unlock(&ucom_mtx);
386 ucom_drain_all(void *arg)
389 while (ucom_close_refs > 0) {
390 printf("ucom: Waiting for all detached TTY "
391 "devices to have open fds closed.\n");
392 usb_pause_mtx(&ucom_mtx, hz);
394 mtx_unlock(&ucom_mtx);
397 static cn_probe_t ucom_cnprobe;
398 static cn_init_t ucom_cninit;
399 static cn_term_t ucom_cnterm;
400 static cn_getc_t ucom_cngetc;
401 static cn_putc_t ucom_cnputc;
402 static cn_grab_t ucom_cngrab;
403 static cn_ungrab_t ucom_cnungrab;
405 const struct consdev_ops ucom_cnops = {
406 .cn_probe = ucom_cnprobe,
407 .cn_init = ucom_cninit,
408 .cn_term = ucom_cnterm,
409 .cn_getc = ucom_cngetc,
410 .cn_putc = ucom_cnputc,
411 .cn_grab = ucom_cngrab,
412 .cn_ungrab = ucom_cnungrab,
416 ucom_attach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc)
419 char buf[32]; /* temporary TTY device name buffer */
421 tp = tty_alloc_mutex(&ucom_class, sc, sc->sc_mtx);
425 /* Check if the client has a custom TTY name */
427 if (sc->sc_callback->ucom_tty_name) {
428 sc->sc_callback->ucom_tty_name(sc, buf,
429 sizeof(buf), ssc->sc_unit, sc->sc_subunit);
432 /* Use default TTY name */
433 if (ssc->sc_subunits > 1) {
434 /* multiple modems in one */
435 snprintf(buf, sizeof(buf), UCOM_TTY_PREFIX "%u.%u",
436 ssc->sc_unit, sc->sc_subunit);
439 snprintf(buf, sizeof(buf), UCOM_TTY_PREFIX "%u",
443 tty_makedev(tp, NULL, "%s", buf);
447 sc->sc_pps.ppscap = PPS_CAPTUREBOTH;
448 sc->sc_pps.driver_abi = PPS_ABI_VERSION;
449 sc->sc_pps.driver_mtx = sc->sc_mtx;
450 pps_init_abi(&sc->sc_pps);
452 DPRINTF("ttycreate: %s\n", buf);
454 /* Check if this device should be a console */
455 if ((ucom_cons_softc == NULL) &&
456 (ssc->sc_unit == ucom_cons_unit) &&
457 (sc->sc_subunit == ucom_cons_subunit)) {
459 DPRINTF("unit %d subunit %d is console",
460 ssc->sc_unit, sc->sc_subunit);
462 ucom_cons_softc = sc;
464 tty_init_console(tp, ucom_cons_baud);
466 UCOM_MTX_LOCK(ucom_cons_softc);
467 ucom_cons_rx_low = 0;
468 ucom_cons_rx_high = 0;
469 ucom_cons_tx_low = 0;
470 ucom_cons_tx_high = 0;
471 sc->sc_flag |= UCOM_FLAG_CONSOLE;
472 ucom_open(ucom_cons_softc->sc_tty);
473 ucom_param(ucom_cons_softc->sc_tty, &tp->t_termios_init_in);
474 UCOM_MTX_UNLOCK(ucom_cons_softc);
477 if ((ssc->sc_flag & UCOM_FLAG_DEVICE_MODE) != 0 &&
478 ucom_device_mode_console > 0 &&
479 ucom_cons_softc == NULL) {
482 cp = malloc(sizeof(struct consdev), M_USBDEV,
484 cp->cn_ops = &ucom_cnops;
486 cp->cn_pri = CN_NORMAL;
487 strlcpy(cp->cn_name, "tty", sizeof(cp->cn_name));
488 strlcat(cp->cn_name, buf, sizeof(cp->cn_name));
499 ucom_detach_tty(struct ucom_super_softc *ssc, struct ucom_softc *sc)
501 struct tty *tp = sc->sc_tty;
503 DPRINTF("sc = %p, tp = %p\n", sc, sc->sc_tty);
505 if (sc->sc_consdev != NULL) {
506 cnremove(sc->sc_consdev);
507 free(sc->sc_consdev, M_USBDEV);
508 sc->sc_consdev = NULL;
511 if (sc->sc_flag & UCOM_FLAG_CONSOLE) {
512 UCOM_MTX_LOCK(ucom_cons_softc);
513 ucom_close(ucom_cons_softc->sc_tty);
514 sc->sc_flag &= ~UCOM_FLAG_CONSOLE;
515 UCOM_MTX_UNLOCK(ucom_cons_softc);
516 ucom_cons_softc = NULL;
519 /* the config thread has been stopped when we get here */
522 sc->sc_flag |= UCOM_FLAG_GONE;
523 sc->sc_flag &= ~(UCOM_FLAG_HL_READY | UCOM_FLAG_LL_READY);
529 mtx_unlock(&ucom_mtx);
533 ucom_close(tp); /* close, if any */
539 * make sure that read and write transfers are stopped
541 if (sc->sc_callback->ucom_stop_read)
542 (sc->sc_callback->ucom_stop_read) (sc);
543 if (sc->sc_callback->ucom_stop_write)
544 (sc->sc_callback->ucom_stop_write) (sc);
550 ucom_set_pnpinfo_usb(struct ucom_super_softc *ssc, device_t dev)
554 struct usb_attach_arg *uaa;
556 snprintf(buf, sizeof(buf), "ttyname=" UCOM_TTY_PREFIX
557 "%d ttyports=%d", ssc->sc_unit, ssc->sc_subunits);
559 /* Store the PNP info in the first interface for the device */
560 uaa = device_get_ivars(dev);
561 iface_index = uaa->info.bIfaceIndex;
563 if (usbd_set_pnpinfo(uaa->device, iface_index, buf) != 0)
564 device_printf(dev, "Could not set PNP info\n");
567 * The following information is also replicated in the PNP-info
568 * string which is registered above:
570 if (ssc->sc_sysctl_ttyname == NULL) {
571 ssc->sc_sysctl_ttyname = SYSCTL_ADD_STRING(NULL,
572 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
573 OID_AUTO, "ttyname", CTLFLAG_RD, ssc->sc_ttyname, 0,
574 "TTY device basename");
576 if (ssc->sc_sysctl_ttyports == NULL) {
577 ssc->sc_sysctl_ttyports = SYSCTL_ADD_INT(NULL,
578 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
579 OID_AUTO, "ttyports", CTLFLAG_RD,
580 NULL, ssc->sc_subunits, "Number of ports");
585 ucom_set_usb_mode(struct ucom_super_softc *ssc, enum usb_hc_mode usb_mode)
589 case USB_MODE_DEVICE:
590 ssc->sc_flag |= UCOM_FLAG_DEVICE_MODE;
593 ssc->sc_flag &= ~UCOM_FLAG_DEVICE_MODE;
599 ucom_queue_command(struct ucom_softc *sc,
600 usb_proc_callback_t *fn, struct termios *pt,
601 struct usb_proc_msg *t0, struct usb_proc_msg *t1)
603 struct ucom_super_softc *ssc = sc->sc_super;
604 struct ucom_param_task *task;
606 UCOM_MTX_ASSERT(sc, MA_OWNED);
608 if (usb_proc_is_gone(&ssc->sc_tq)) {
609 DPRINTF("proc is gone\n");
610 return; /* nothing to do */
613 * NOTE: The task cannot get executed before we drop the
614 * "sc_mtx" mutex. It is safe to update fields in the message
615 * structure after that the message got queued.
617 task = (struct ucom_param_task *)
618 usb_proc_msignal(&ssc->sc_tq, t0, t1);
620 /* Setup callback and softc pointers */
621 task->hdr.pm_callback = fn;
625 * Make a copy of the termios. This field is only present if
626 * the "pt" field is not NULL.
629 task->termios_copy = *pt;
632 * Closing the device should be synchronous.
634 if (fn == ucom_cfg_close)
635 usb_proc_mwait(&ssc->sc_tq, t0, t1);
638 * In case of multiple configure requests,
639 * keep track of the last one!
641 if (fn == ucom_cfg_start_transfers)
642 sc->sc_last_start_xfer = &task->hdr;
646 ucom_shutdown(struct ucom_softc *sc)
648 struct tty *tp = sc->sc_tty;
650 UCOM_MTX_ASSERT(sc, MA_OWNED);
655 * Hang up if necessary:
657 if (tp->t_termios.c_cflag & HUPCL) {
658 ucom_modem(tp, 0, SER_DTR);
665 * else: taskqueue is draining or gone
668 ucom_cfg_is_gone(struct ucom_softc *sc)
670 struct ucom_super_softc *ssc = sc->sc_super;
672 return (usb_proc_is_gone(&ssc->sc_tq));
676 ucom_cfg_start_transfers(struct usb_proc_msg *_task)
678 struct ucom_cfg_task *task =
679 (struct ucom_cfg_task *)_task;
680 struct ucom_softc *sc = task->sc;
682 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
685 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
686 /* TTY device closed */
690 if (_task == sc->sc_last_start_xfer)
691 sc->sc_flag |= UCOM_FLAG_GP_DATA;
693 if (sc->sc_callback->ucom_start_read) {
694 (sc->sc_callback->ucom_start_read) (sc);
696 if (sc->sc_callback->ucom_start_write) {
697 (sc->sc_callback->ucom_start_write) (sc);
702 ucom_start_transfers(struct ucom_softc *sc)
704 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
708 * Make sure that data transfers are started in both
711 if (sc->sc_callback->ucom_start_read) {
712 (sc->sc_callback->ucom_start_read) (sc);
714 if (sc->sc_callback->ucom_start_write) {
715 (sc->sc_callback->ucom_start_write) (sc);
720 ucom_cfg_open(struct usb_proc_msg *_task)
722 struct ucom_cfg_task *task =
723 (struct ucom_cfg_task *)_task;
724 struct ucom_softc *sc = task->sc;
728 if (sc->sc_flag & UCOM_FLAG_LL_READY) {
734 sc->sc_flag |= UCOM_FLAG_LL_READY;
736 if (sc->sc_callback->ucom_cfg_open) {
737 (sc->sc_callback->ucom_cfg_open) (sc);
740 usb_pause_mtx(sc->sc_mtx, hz / 10);
746 ucom_open(struct tty *tp)
748 struct ucom_softc *sc = tty_softc(tp);
751 UCOM_MTX_ASSERT(sc, MA_OWNED);
753 if (sc->sc_flag & UCOM_FLAG_GONE) {
756 if (sc->sc_flag & UCOM_FLAG_HL_READY) {
760 DPRINTF("tp = %p\n", tp);
762 if (sc->sc_callback->ucom_pre_open) {
764 * give the lower layer a chance to disallow TTY open, for
765 * example if the device is not present:
767 error = (sc->sc_callback->ucom_pre_open) (sc);
772 sc->sc_flag |= UCOM_FLAG_HL_READY;
774 /* Disable transfers */
775 sc->sc_flag &= ~UCOM_FLAG_GP_DATA;
781 /* reset programmed line state */
786 /* reset jitter buffer */
787 sc->sc_jitterbuf_in = 0;
788 sc->sc_jitterbuf_out = 0;
790 ucom_queue_command(sc, ucom_cfg_open, NULL,
791 &sc->sc_open_task[0].hdr,
792 &sc->sc_open_task[1].hdr);
794 /* Queue transfer enable command last */
795 ucom_queue_command(sc, ucom_cfg_start_transfers, NULL,
796 &sc->sc_start_task[0].hdr,
797 &sc->sc_start_task[1].hdr);
799 if (sc->sc_tty == NULL || (sc->sc_tty->t_termios.c_cflag & CNO_RTSDTR) == 0)
800 ucom_modem(tp, SER_DTR | SER_RTS, 0);
806 ucom_status_change(sc);
812 ucom_cfg_close(struct usb_proc_msg *_task)
814 struct ucom_cfg_task *task =
815 (struct ucom_cfg_task *)_task;
816 struct ucom_softc *sc = task->sc;
820 if (sc->sc_flag & UCOM_FLAG_LL_READY) {
821 sc->sc_flag &= ~UCOM_FLAG_LL_READY;
822 if (sc->sc_callback->ucom_cfg_close)
823 (sc->sc_callback->ucom_cfg_close) (sc);
830 ucom_close(struct tty *tp)
832 struct ucom_softc *sc = tty_softc(tp);
834 UCOM_MTX_ASSERT(sc, MA_OWNED);
836 DPRINTF("tp=%p\n", tp);
838 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
839 DPRINTF("tp=%p already closed\n", tp);
844 ucom_queue_command(sc, ucom_cfg_close, NULL,
845 &sc->sc_close_task[0].hdr,
846 &sc->sc_close_task[1].hdr);
848 sc->sc_flag &= ~(UCOM_FLAG_HL_READY | UCOM_FLAG_RTS_IFLOW);
850 if (sc->sc_callback->ucom_stop_read) {
851 (sc->sc_callback->ucom_stop_read) (sc);
856 ucom_inwakeup(struct tty *tp)
858 struct ucom_softc *sc = tty_softc(tp);
864 UCOM_MTX_ASSERT(sc, MA_OWNED);
866 DPRINTF("tp=%p\n", tp);
868 if (ttydisc_can_bypass(tp) != 0 ||
869 (sc->sc_flag & UCOM_FLAG_HL_READY) == 0 ||
870 (sc->sc_flag & UCOM_FLAG_INWAKEUP) != 0) {
874 /* prevent recursion */
875 sc->sc_flag |= UCOM_FLAG_INWAKEUP;
877 pos = sc->sc_jitterbuf_out;
879 while (sc->sc_jitterbuf_in != pos) {
882 c = (char)sc->sc_jitterbuf[pos];
884 if (ttydisc_rint(tp, c, 0) == -1)
887 if (pos >= UCOM_JITTERBUF_SIZE)
888 pos -= UCOM_JITTERBUF_SIZE;
891 sc->sc_jitterbuf_out = pos;
893 /* clear RTS in async fashion */
894 if ((sc->sc_jitterbuf_in == pos) &&
895 (sc->sc_flag & UCOM_FLAG_RTS_IFLOW))
898 sc->sc_flag &= ~UCOM_FLAG_INWAKEUP;
902 ucom_ioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
904 struct ucom_softc *sc = tty_softc(tp);
907 UCOM_MTX_ASSERT(sc, MA_OWNED);
909 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
912 DPRINTF("cmd = 0x%08lx\n", cmd);
934 if (sc->sc_callback->ucom_ioctl) {
935 error = (sc->sc_callback->ucom_ioctl)
936 (sc, cmd, data, 0, td);
940 if (error == ENOIOCTL)
941 error = pps_ioctl(cmd, data, &sc->sc_pps);
948 ucom_modem(struct tty *tp, int sigon, int sigoff)
950 struct ucom_softc *sc = tty_softc(tp);
953 UCOM_MTX_ASSERT(sc, MA_OWNED);
955 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
958 if ((sigon == 0) && (sigoff == 0)) {
960 if (sc->sc_mcr & SER_DTR) {
963 if (sc->sc_mcr & SER_RTS) {
966 if (sc->sc_msr & SER_CTS) {
969 if (sc->sc_msr & SER_DCD) {
972 if (sc->sc_msr & SER_DSR) {
975 if (sc->sc_msr & SER_RI) {
980 if (sigon & SER_DTR) {
981 sc->sc_mcr |= SER_DTR;
983 if (sigoff & SER_DTR) {
984 sc->sc_mcr &= ~SER_DTR;
986 if (sigon & SER_RTS) {
987 sc->sc_mcr |= SER_RTS;
989 if (sigoff & SER_RTS) {
990 sc->sc_mcr &= ~SER_RTS;
992 onoff = (sc->sc_mcr & SER_DTR) ? 1 : 0;
995 onoff = (sc->sc_mcr & SER_RTS) ? 1 : 0;
1002 ucom_cfg_line_state(struct usb_proc_msg *_task)
1004 struct ucom_cfg_task *task =
1005 (struct ucom_cfg_task *)_task;
1006 struct ucom_softc *sc = task->sc;
1013 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
1018 /* compute callback mask */
1019 if (sc->sc_callback->ucom_cfg_set_dtr)
1020 mask |= UCOM_LS_DTR;
1021 if (sc->sc_callback->ucom_cfg_set_rts)
1022 mask |= UCOM_LS_RTS;
1023 if (sc->sc_callback->ucom_cfg_set_break)
1024 mask |= UCOM_LS_BREAK;
1025 if (sc->sc_callback->ucom_cfg_set_ring)
1026 mask |= UCOM_LS_RING;
1028 /* compute the bits we are to program */
1029 notch_bits = (sc->sc_pls_set & sc->sc_pls_clr) & mask;
1030 any_bits = (sc->sc_pls_set | sc->sc_pls_clr) & mask;
1031 prev_value = sc->sc_pls_curr ^ notch_bits;
1032 last_value = sc->sc_pls_curr;
1034 /* reset programmed line state */
1035 sc->sc_pls_curr = 0;
1039 /* ensure that we don't lose any levels */
1040 if (notch_bits & UCOM_LS_DTR)
1041 sc->sc_callback->ucom_cfg_set_dtr(sc,
1042 (prev_value & UCOM_LS_DTR) ? 1 : 0);
1043 if (notch_bits & UCOM_LS_RTS)
1044 sc->sc_callback->ucom_cfg_set_rts(sc,
1045 (prev_value & UCOM_LS_RTS) ? 1 : 0);
1046 if (notch_bits & UCOM_LS_BREAK)
1047 sc->sc_callback->ucom_cfg_set_break(sc,
1048 (prev_value & UCOM_LS_BREAK) ? 1 : 0);
1049 if (notch_bits & UCOM_LS_RING)
1050 sc->sc_callback->ucom_cfg_set_ring(sc,
1051 (prev_value & UCOM_LS_RING) ? 1 : 0);
1053 /* set last value */
1054 if (any_bits & UCOM_LS_DTR)
1055 sc->sc_callback->ucom_cfg_set_dtr(sc,
1056 (last_value & UCOM_LS_DTR) ? 1 : 0);
1057 if (any_bits & UCOM_LS_RTS)
1058 sc->sc_callback->ucom_cfg_set_rts(sc,
1059 (last_value & UCOM_LS_RTS) ? 1 : 0);
1060 if (any_bits & UCOM_LS_BREAK)
1061 sc->sc_callback->ucom_cfg_set_break(sc,
1062 (last_value & UCOM_LS_BREAK) ? 1 : 0);
1063 if (any_bits & UCOM_LS_RING)
1064 sc->sc_callback->ucom_cfg_set_ring(sc,
1065 (last_value & UCOM_LS_RING) ? 1 : 0);
1069 ucom_line_state(struct ucom_softc *sc,
1070 uint8_t set_bits, uint8_t clear_bits)
1072 UCOM_MTX_ASSERT(sc, MA_OWNED);
1074 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
1078 DPRINTF("on=0x%02x, off=0x%02x\n", set_bits, clear_bits);
1080 /* update current programmed line state */
1081 sc->sc_pls_curr |= set_bits;
1082 sc->sc_pls_curr &= ~clear_bits;
1083 sc->sc_pls_set |= set_bits;
1084 sc->sc_pls_clr |= clear_bits;
1086 /* defer driver programming */
1087 ucom_queue_command(sc, ucom_cfg_line_state, NULL,
1088 &sc->sc_line_state_task[0].hdr,
1089 &sc->sc_line_state_task[1].hdr);
1093 ucom_ring(struct ucom_softc *sc, uint8_t onoff)
1095 DPRINTF("onoff = %d\n", onoff);
1098 ucom_line_state(sc, UCOM_LS_RING, 0);
1100 ucom_line_state(sc, 0, UCOM_LS_RING);
1104 ucom_break(struct ucom_softc *sc, uint8_t onoff)
1106 DPRINTF("onoff = %d\n", onoff);
1109 ucom_line_state(sc, UCOM_LS_BREAK, 0);
1111 ucom_line_state(sc, 0, UCOM_LS_BREAK);
1115 ucom_dtr(struct ucom_softc *sc, uint8_t onoff)
1117 DPRINTF("onoff = %d\n", onoff);
1120 ucom_line_state(sc, UCOM_LS_DTR, 0);
1122 ucom_line_state(sc, 0, UCOM_LS_DTR);
1126 ucom_rts(struct ucom_softc *sc, uint8_t onoff)
1128 DPRINTF("onoff = %d\n", onoff);
1131 ucom_line_state(sc, UCOM_LS_RTS, 0);
1133 ucom_line_state(sc, 0, UCOM_LS_RTS);
1137 ucom_cfg_status_change(struct usb_proc_msg *_task)
1139 struct ucom_cfg_task *task =
1140 (struct ucom_cfg_task *)_task;
1141 struct ucom_softc *sc = task->sc;
1152 UCOM_MTX_ASSERT(sc, MA_OWNED);
1154 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
1157 if (sc->sc_callback->ucom_cfg_get_status == NULL) {
1165 (sc->sc_callback->ucom_cfg_get_status) (sc, &new_lsr, &new_msr);
1167 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
1168 /* TTY device closed */
1171 msr_delta = (sc->sc_msr ^ new_msr);
1172 lsr_delta = (sc->sc_lsr ^ new_lsr);
1174 sc->sc_msr = new_msr;
1175 sc->sc_lsr = new_lsr;
1178 * Time pulse counting support.
1180 switch(ucom_pps_mode & UART_PPS_SIGNAL_MASK) {
1182 pps_signal = SER_CTS;
1185 pps_signal = SER_DCD;
1192 if ((sc->sc_pps.ppsparam.mode & PPS_CAPTUREBOTH) &&
1193 (msr_delta & pps_signal)) {
1194 pps_capture(&sc->sc_pps);
1195 onoff = (sc->sc_msr & pps_signal) ? 1 : 0;
1196 if (ucom_pps_mode & UART_PPS_INVERT_PULSE)
1198 pps_event(&sc->sc_pps, onoff ? PPS_CAPTUREASSERT :
1202 if (msr_delta & SER_DCD) {
1204 onoff = (sc->sc_msr & SER_DCD) ? 1 : 0;
1206 DPRINTF("DCD changed to %d\n", onoff);
1208 ttydisc_modem(tp, onoff);
1211 if ((lsr_delta & ULSR_BI) && (sc->sc_lsr & ULSR_BI)) {
1213 DPRINTF("BREAK detected\n");
1215 ttydisc_rint(tp, 0, TRE_BREAK);
1216 ttydisc_rint_done(tp);
1219 if ((lsr_delta & ULSR_FE) && (sc->sc_lsr & ULSR_FE)) {
1221 DPRINTF("Frame error detected\n");
1223 ttydisc_rint(tp, 0, TRE_FRAMING);
1224 ttydisc_rint_done(tp);
1227 if ((lsr_delta & ULSR_PE) && (sc->sc_lsr & ULSR_PE)) {
1229 DPRINTF("Parity error detected\n");
1231 ttydisc_rint(tp, 0, TRE_PARITY);
1232 ttydisc_rint_done(tp);
1237 ucom_status_change(struct ucom_softc *sc)
1239 UCOM_MTX_ASSERT(sc, MA_OWNED);
1241 if (sc->sc_flag & UCOM_FLAG_CONSOLE)
1242 return; /* not supported */
1244 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
1249 ucom_queue_command(sc, ucom_cfg_status_change, NULL,
1250 &sc->sc_status_task[0].hdr,
1251 &sc->sc_status_task[1].hdr);
1255 ucom_cfg_param(struct usb_proc_msg *_task)
1257 struct ucom_param_task *task =
1258 (struct ucom_param_task *)_task;
1259 struct ucom_softc *sc = task->sc;
1261 if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) {
1264 if (sc->sc_callback->ucom_cfg_param == NULL) {
1268 (sc->sc_callback->ucom_cfg_param) (sc, &task->termios_copy);
1271 usb_pause_mtx(sc->sc_mtx, hz / 10);
1275 ucom_param(struct tty *tp, struct termios *t)
1277 struct ucom_softc *sc = tty_softc(tp);
1281 UCOM_MTX_ASSERT(sc, MA_OWNED);
1286 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
1288 /* XXX the TTY layer should call "open()" first! */
1290 * Not quite: Its ordering is partly backwards, but
1291 * some parameters must be set early in ttydev_open(),
1292 * possibly before calling ttydevsw_open().
1294 error = ucom_open(tp);
1300 DPRINTF("sc = %p\n", sc);
1302 /* Check requested parameters. */
1303 if (t->c_ispeed && (t->c_ispeed != t->c_ospeed)) {
1304 /* XXX c_ospeed == 0 is perfectly valid. */
1305 DPRINTF("mismatch ispeed and ospeed\n");
1309 t->c_ispeed = t->c_ospeed;
1311 if (sc->sc_callback->ucom_pre_param) {
1312 /* Let the lower layer verify the parameters */
1313 error = (sc->sc_callback->ucom_pre_param) (sc, t);
1315 DPRINTF("callback error = %d\n", error);
1320 /* Disable transfers */
1321 sc->sc_flag &= ~UCOM_FLAG_GP_DATA;
1323 /* Queue baud rate programming command first */
1324 ucom_queue_command(sc, ucom_cfg_param, t,
1325 &sc->sc_param_task[0].hdr,
1326 &sc->sc_param_task[1].hdr);
1328 /* Queue transfer enable command last */
1329 ucom_queue_command(sc, ucom_cfg_start_transfers, NULL,
1330 &sc->sc_start_task[0].hdr,
1331 &sc->sc_start_task[1].hdr);
1333 if (t->c_cflag & CRTS_IFLOW) {
1334 sc->sc_flag |= UCOM_FLAG_RTS_IFLOW;
1335 } else if (sc->sc_flag & UCOM_FLAG_RTS_IFLOW) {
1336 sc->sc_flag &= ~UCOM_FLAG_RTS_IFLOW;
1337 ucom_modem(tp, SER_RTS, 0);
1349 ucom_outwakeup(struct tty *tp)
1351 struct ucom_softc *sc = tty_softc(tp);
1353 UCOM_MTX_ASSERT(sc, MA_OWNED);
1355 DPRINTF("sc = %p\n", sc);
1357 if (!(sc->sc_flag & UCOM_FLAG_HL_READY)) {
1358 /* The higher layer is not ready */
1361 ucom_start_transfers(sc);
1365 ucom_busy(struct tty *tp)
1367 struct ucom_softc *sc = tty_softc(tp);
1368 const uint8_t txidle = ULSR_TXRDY | ULSR_TSRE;
1370 UCOM_MTX_ASSERT(sc, MA_OWNED);
1372 DPRINTFN(3, "sc = %p lsr 0x%02x\n", sc, sc->sc_lsr);
1375 * If the driver maintains the txidle bits in LSR, we can use them to
1376 * determine whether the transmitter is busy or idle. Otherwise we have
1377 * to assume it is idle to avoid hanging forever on tcdrain(3).
1379 if (sc->sc_flag & UCOM_FLAG_LSRTXIDLE)
1380 return ((sc->sc_lsr & txidle) != txidle);
1385 /*------------------------------------------------------------------------*
1389 * 0: No data is available.
1390 * Else: Data is available.
1391 *------------------------------------------------------------------------*/
1393 ucom_get_data(struct ucom_softc *sc, struct usb_page_cache *pc,
1394 uint32_t offset, uint32_t len, uint32_t *actlen)
1396 struct usb_page_search res;
1397 struct tty *tp = sc->sc_tty;
1399 uint32_t offset_orig;
1401 UCOM_MTX_ASSERT(sc, MA_OWNED);
1403 if (sc->sc_flag & UCOM_FLAG_CONSOLE) {
1406 /* get total TX length */
1408 temp = ucom_cons_tx_high - ucom_cons_tx_low;
1409 temp %= UCOM_CONS_BUFSIZE;
1411 /* limit TX length */
1413 if (temp > (UCOM_CONS_BUFSIZE - ucom_cons_tx_low))
1414 temp = (UCOM_CONS_BUFSIZE - ucom_cons_tx_low);
1421 usbd_copy_in(pc, offset, ucom_cons_tx_buf + ucom_cons_tx_low, temp);
1423 /* update counters */
1425 ucom_cons_tx_low += temp;
1426 ucom_cons_tx_low %= UCOM_CONS_BUFSIZE;
1428 /* store actual length */
1432 return (temp ? 1 : 0);
1436 !(sc->sc_flag & UCOM_FLAG_GP_DATA)) {
1438 return (0); /* multiport device polling */
1440 offset_orig = offset;
1444 usbd_get_page(pc, offset, &res);
1446 if (res.length > len) {
1449 /* copy data directly into USB buffer */
1450 cnt = ttydisc_getc(tp, res.buffer, res.length);
1455 if (cnt < res.length) {
1461 actlen[0] = offset - offset_orig;
1463 DPRINTF("cnt=%d\n", actlen[0]);
1465 if (actlen[0] == 0) {
1472 ucom_put_data(struct ucom_softc *sc, struct usb_page_cache *pc,
1473 uint32_t offset, uint32_t len)
1475 struct usb_page_search res;
1476 struct tty *tp = sc->sc_tty;
1480 UCOM_MTX_ASSERT(sc, MA_OWNED);
1482 if (sc->sc_flag & UCOM_FLAG_CONSOLE) {
1485 /* get maximum RX length */
1487 temp = (UCOM_CONS_BUFSIZE - 1) - ucom_cons_rx_high + ucom_cons_rx_low;
1488 temp %= UCOM_CONS_BUFSIZE;
1490 /* limit RX length */
1492 if (temp > (UCOM_CONS_BUFSIZE - ucom_cons_rx_high))
1493 temp = (UCOM_CONS_BUFSIZE - ucom_cons_rx_high);
1500 usbd_copy_out(pc, offset, ucom_cons_rx_buf + ucom_cons_rx_high, temp);
1502 /* update counters */
1504 ucom_cons_rx_high += temp;
1505 ucom_cons_rx_high %= UCOM_CONS_BUFSIZE;
1511 return; /* multiport device polling */
1514 return; /* no data */
1516 /* set a flag to prevent recursation ? */
1520 usbd_get_page(pc, offset, &res);
1522 if (res.length > len) {
1526 offset += res.length;
1528 /* pass characters to tty layer */
1533 /* first check if we can pass the buffer directly */
1535 if (ttydisc_can_bypass(tp)) {
1537 /* clear any jitter buffer */
1538 sc->sc_jitterbuf_in = 0;
1539 sc->sc_jitterbuf_out = 0;
1541 if (ttydisc_rint_bypass(tp, buf, cnt) != cnt) {
1542 DPRINTF("tp=%p, data lost\n", tp);
1548 for (cnt = 0; cnt != res.length; cnt++) {
1549 if (sc->sc_jitterbuf_in != sc->sc_jitterbuf_out ||
1550 ttydisc_rint(tp, buf[cnt], 0) == -1) {
1554 pos = sc->sc_jitterbuf_in;
1555 end = sc->sc_jitterbuf_out +
1556 UCOM_JITTERBUF_SIZE - 1;
1557 if (end >= UCOM_JITTERBUF_SIZE)
1558 end -= UCOM_JITTERBUF_SIZE;
1560 for (; cnt != res.length; cnt++) {
1563 sc->sc_jitterbuf[pos] = buf[cnt];
1565 if (pos >= UCOM_JITTERBUF_SIZE)
1566 pos -= UCOM_JITTERBUF_SIZE;
1569 sc->sc_jitterbuf_in = pos;
1571 /* set RTS in async fashion */
1572 if (sc->sc_flag & UCOM_FLAG_RTS_IFLOW)
1575 DPRINTF("tp=%p, lost %d "
1576 "chars\n", tp, res.length - cnt);
1581 ttydisc_rint_done(tp);
1585 ucom_free(void *xsc)
1587 struct ucom_softc *sc = xsc;
1589 if (sc->sc_callback->ucom_free != NULL)
1590 sc->sc_callback->ucom_free(sc);
1592 ucom_unref(sc->sc_super);
1594 mtx_lock(&ucom_mtx);
1596 mtx_unlock(&ucom_mtx);
1599 CONSOLE_DRIVER(ucom);
1602 ucom_cnprobe(struct consdev *cp)
1604 if (ucom_cons_unit != -1)
1605 cp->cn_pri = CN_NORMAL;
1607 cp->cn_pri = CN_DEAD;
1609 strlcpy(cp->cn_name, "ucom", sizeof(cp->cn_name));
1613 ucom_cninit(struct consdev *cp)
1618 ucom_cnterm(struct consdev *cp)
1623 ucom_cngrab(struct consdev *cp)
1628 ucom_cnungrab(struct consdev *cp)
1633 ucom_cngetc(struct consdev *cd)
1635 struct ucom_softc *sc = ucom_cons_softc;
1643 if (ucom_cons_rx_low != ucom_cons_rx_high) {
1644 c = ucom_cons_rx_buf[ucom_cons_rx_low];
1645 ucom_cons_rx_low ++;
1646 ucom_cons_rx_low %= UCOM_CONS_BUFSIZE;
1651 /* start USB transfers */
1652 ucom_outwakeup(sc->sc_tty);
1654 UCOM_MTX_UNLOCK(sc);
1656 /* poll if necessary */
1657 if (USB_IN_POLLING_MODE_FUNC() && sc->sc_callback->ucom_poll)
1658 (sc->sc_callback->ucom_poll) (sc);
1664 ucom_cnputc(struct consdev *cd, int c)
1666 struct ucom_softc *sc = ucom_cons_softc;
1676 /* compute maximum TX length */
1678 temp = (UCOM_CONS_BUFSIZE - 1) - ucom_cons_tx_high + ucom_cons_tx_low;
1679 temp %= UCOM_CONS_BUFSIZE;
1682 ucom_cons_tx_buf[ucom_cons_tx_high] = c;
1683 ucom_cons_tx_high ++;
1684 ucom_cons_tx_high %= UCOM_CONS_BUFSIZE;
1687 /* start USB transfers */
1688 ucom_outwakeup(sc->sc_tty);
1690 UCOM_MTX_UNLOCK(sc);
1692 /* poll if necessary */
1693 if (USB_IN_POLLING_MODE_FUNC() && sc->sc_callback->ucom_poll) {
1694 (sc->sc_callback->ucom_poll) (sc);
1695 /* simple flow control */
1701 /*------------------------------------------------------------------------*
1704 * This function will increment the super UCOM reference count.
1705 *------------------------------------------------------------------------*/
1707 ucom_ref(struct ucom_super_softc *ssc)
1709 mtx_lock(&ucom_mtx);
1711 mtx_unlock(&ucom_mtx);
1714 /*------------------------------------------------------------------------*
1717 * This function will free the super UCOM's allocated unit
1718 * number. This function can be called on a zero-initialized
1719 * structure. This function can be called multiple times.
1720 *------------------------------------------------------------------------*/
1722 ucom_free_unit(struct ucom_super_softc *ssc)
1724 if (!(ssc->sc_flag & UCOM_FLAG_FREE_UNIT))
1727 ucom_unit_free(ssc->sc_unit);
1729 ssc->sc_flag &= ~UCOM_FLAG_FREE_UNIT;
1732 /*------------------------------------------------------------------------*
1735 * This function will decrement the super UCOM reference count.
1738 * 0: UCOM structures are still referenced.
1739 * Else: UCOM structures are no longer referenced.
1740 *------------------------------------------------------------------------*/
1742 ucom_unref(struct ucom_super_softc *ssc)
1746 mtx_lock(&ucom_mtx);
1747 retval = (ssc->sc_refs < 2);
1749 mtx_unlock(&ucom_mtx);
1752 ucom_free_unit(ssc);
1759 #include <gdb/gdb.h>
1761 static gdb_probe_f ucom_gdbprobe;
1762 static gdb_init_f ucom_gdbinit;
1763 static gdb_term_f ucom_gdbterm;
1764 static gdb_getc_f ucom_gdbgetc;
1765 static gdb_putc_f ucom_gdbputc;
1767 GDB_DBGPORT(sio, ucom_gdbprobe, ucom_gdbinit, ucom_gdbterm, ucom_gdbgetc, ucom_gdbputc);
1772 return ((ucom_cons_softc != NULL) ? 0 : -1);
1788 ucom_cnputc(NULL, c);
1794 return (ucom_cngetc(NULL));