kernel - Remove D_KQFILTER flag
[dragonfly.git] / sys / dev / usbmisc / ucom / ucom.c
CommitLineData
7e74f00e
MD
1/*
2 * $NetBSD: ucom.c,v 1.39 2001/08/16 22:31:24 augustss Exp $
1550dfd9
MD
3 * $NetBSD: ucom.c,v 1.40 2001/11/13 06:24:54 lukem Exp $
4 * $FreeBSD: src/sys/dev/usb/ucom.c,v 1.35 2003/11/16 11:58:21 akiyama Exp $
3e997bb7 5 * $DragonFly: src/sys/dev/usbmisc/ucom/ucom.c,v 1.32 2007/11/05 19:09:43 hasso Exp $
7e74f00e 6 */
984263bc
MD
7/*-
8 * Copyright (c) 2001-2002, Shunsuke Akiyama <akiyama@jp.FreeBSD.org>.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/*
34 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
35 * All rights reserved.
36 *
37 * This code is derived from software contributed to The NetBSD Foundation
38 * by Lennart Augustsson (lennart@augustsson.net) at
39 * Carlstedt Research & Technology.
40 *
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
43 * are met:
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. All advertising materials mentioning features or use of this software
50 * must display the following acknowledgement:
51 * This product includes software developed by the NetBSD
52 * Foundation, Inc. and its contributors.
53 * 4. Neither the name of The NetBSD Foundation nor the names of its
54 * contributors may be used to endorse or promote products derived
55 * from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
58 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
59 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
61 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
62 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
63 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
64 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
65 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
66 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
67 * POSSIBILITY OF SUCH DAMAGE.
68 */
69
984263bc
MD
70#include <sys/param.h>
71#include <sys/systm.h>
72#include <sys/kernel.h>
73#include <sys/malloc.h>
74#include <sys/bus.h>
984263bc
MD
75#include <sys/fcntl.h>
76#include <sys/conf.h>
77#include <sys/tty.h>
78#include <sys/clist.h>
79#include <sys/file.h>
984263bc 80#include <sys/proc.h>
895c1f85 81#include <sys/priv.h>
984263bc 82#include <sys/sysctl.h>
4e01b467 83#include <sys/thread2.h>
984263bc 84
1f2de5d4
MD
85#include <bus/usb/usb.h>
86#include <bus/usb/usbcdc.h>
984263bc 87
1f2de5d4
MD
88#include <bus/usb/usbdi.h>
89#include <bus/usb/usbdi_util.h>
1f2de5d4 90#include <bus/usb/usb_quirks.h>
984263bc 91
1f2de5d4 92#include "ucomvar.h"
984263bc
MD
93
94#ifdef USB_DEBUG
95static int ucomdebug = 0;
96SYSCTL_NODE(_hw_usb, OID_AUTO, ucom, CTLFLAG_RW, 0, "USB ucom");
97SYSCTL_INT(_hw_usb_ucom, OID_AUTO, debug, CTLFLAG_RW,
98 &ucomdebug, 0, "ucom debug level");
99#define DPRINTF(x) do { \
100 if (ucomdebug) \
fc1ef497 101 kprintf x; \
984263bc
MD
102 } while (0)
103
104#define DPRINTFN(n, x) do { \
105 if (ucomdebug > (n)) \
fc1ef497 106 kprintf x; \
984263bc
MD
107 } while (0)
108#else
109#define DPRINTF(x)
110#define DPRINTFN(n, x)
111#endif
112
6ed427ca
HT
113static d_open_t ucomopen;
114static d_close_t ucomclose;
115static d_read_t ucomread;
116static d_write_t ucomwrite;
117static d_ioctl_t ucomioctl;
984263bc
MD
118
119#define UCOM_CDEV_MAJOR 138
120
fef8985e 121static struct dev_ops ucom_ops = {
d4b8aec4 122 { "ucom", UCOM_CDEV_MAJOR, D_TTY },
fef8985e
MD
123 .d_open = ucomopen,
124 .d_close = ucomclose,
125 .d_read = ucomread,
126 .d_write = ucomwrite,
127 .d_ioctl = ucomioctl,
a32446b7
MD
128 .d_kqfilter = ttykqfilter,
129 .d_revoke = ttyrevoke
984263bc
MD
130};
131
6ed427ca
HT
132static void ucom_cleanup(struct ucom_softc *);
133static int ucomctl(struct ucom_softc *, int, int);
134static int ucomparam(struct tty *, struct termios *);
135static void ucomstart(struct tty *);
136static void ucomstop(struct tty *, int);
137static void ucom_shutdown(struct ucom_softc *);
138static void ucom_dtr(struct ucom_softc *, int);
139static void ucom_rts(struct ucom_softc *, int);
140static void ucom_break(struct ucom_softc *, int);
141static usbd_status ucomstartread(struct ucom_softc *);
142static void ucomreadcb(usbd_xfer_handle, usbd_private_handle, usbd_status);
143static void ucomwritecb(usbd_xfer_handle, usbd_private_handle, usbd_status);
144static void ucomstopread(struct ucom_softc *);
984263bc
MD
145static void disc_optim(struct tty *, struct termios *, struct ucom_softc *);
146
147devclass_t ucom_devclass;
148
149static moduledata_t ucom_mod = {
150 "ucom",
151 NULL,
152 NULL
153};
154
155DECLARE_MODULE(ucom, ucom_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
156MODULE_DEPEND(ucom, usb, 1, 1, 1);
157MODULE_VERSION(ucom, UCOM_MODVER);
158
159int
160ucom_attach(struct ucom_softc *sc)
161{
162 struct tty *tp;
163 int unit;
b13267a5 164 cdev_t dev;
984263bc
MD
165
166 unit = device_get_unit(sc->sc_dev);
167
168 sc->sc_tty = tp = ttymalloc(sc->sc_tty);
169 tp->t_oproc = ucomstart;
170 tp->t_param = ucomparam;
171 tp->t_stop = ucomstop;
172
173 DPRINTF(("ucom_attach: tty_attach tp = %p\n", tp));
174
175 DPRINTF(("ucom_attach: make_dev: ucom%d\n", unit));
176
fef8985e 177 dev = make_dev(&ucom_ops, unit | UCOM_CALLOUT_MASK,
984263bc
MD
178 UID_UUCP, GID_DIALER, 0660,
179 "ucom%d", unit);
e4c9c0c8 180 dev->si_tty = tp;
984263bc
MD
181
182 return (0);
183}
184
185int
186ucom_detach(struct ucom_softc *sc)
187{
188 struct tty *tp = sc->sc_tty;
e4c9c0c8 189 int unit;
984263bc
MD
190
191 DPRINTF(("ucom_detach: sc = %p, tp = %p\n", sc, sc->sc_tty));
192
193 sc->sc_dying = 1;
194
195 if (sc->sc_bulkin_pipe != NULL)
196 usbd_abort_pipe(sc->sc_bulkin_pipe);
197 if (sc->sc_bulkout_pipe != NULL)
198 usbd_abort_pipe(sc->sc_bulkout_pipe);
199
200 if (tp != NULL) {
201 if (tp->t_state & TS_ISOPEN) {
202 device_printf(sc->sc_dev,
203 "still open, forcing close\n");
204 (*linesw[tp->t_line].l_close)(tp, 0);
984263bc 205 ttyclose(tp);
984263bc
MD
206 }
207 } else {
208 DPRINTF(("ucom_detach: no tty\n"));
209 return (0);
210 }
211
4e01b467 212 crit_enter();
984263bc
MD
213 if (--sc->sc_refcnt >= 0) {
214 /* Wait for processes to go away. */
2939c544 215 usb_detach_wait(sc->sc_dev);
984263bc 216 }
4e01b467 217 crit_exit();
984263bc 218
e4c9c0c8 219 unit = device_get_unit(sc->sc_dev);
cd29885a 220 dev_ops_remove_minor(&ucom_ops, /*UCOMUNIT_MASK, */unit);
984263bc
MD
221
222 return (0);
223}
224
6ed427ca 225static void
984263bc
MD
226ucom_shutdown(struct ucom_softc *sc)
227{
228 struct tty *tp = sc->sc_tty;
229
230 DPRINTF(("ucom_shutdown\n"));
231 /*
232 * Hang up if necessary. Wait a bit, so the other side has time to
233 * notice even if we immediately open the port again.
234 */
235 if (ISSET(tp->t_cflag, HUPCL)) {
236 (void)ucomctl(sc, TIOCM_DTR, DMBIC);
377d4740 237 (void)tsleep(sc, 0, "ucomsd", hz);
984263bc
MD
238 }
239}
240
6ed427ca 241static int
fef8985e 242ucomopen(struct dev_open_args *ap)
984263bc 243{
b13267a5 244 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
245 int unit = UCOMUNIT(dev);
246 struct ucom_softc *sc;
247 usbd_status err;
248 struct tty *tp;
984263bc 249 int error;
41c20dac 250
1e089e7e
HT
251 sc = devclass_get_softc(ucom_devclass, unit);
252 if (sc == NULL)
253 return (ENXIO);
984263bc
MD
254
255 if (sc->sc_dying)
256 return (ENXIO);
257
258 tp = sc->sc_tty;
259
6ed427ca 260 DPRINTF(("%s: ucomopen: tp = %p\n", device_get_nameunit(sc->sc_dev), tp));
984263bc
MD
261
262 if (ISSET(tp->t_state, TS_ISOPEN) &&
263 ISSET(tp->t_state, TS_XCLUDE) &&
895c1f85 264 priv_check_cred(ap->a_cred, PRIV_ROOT, 0)
dadab5e9 265 ) {
984263bc 266 return (EBUSY);
dadab5e9 267 }
984263bc
MD
268
269 /*
270 * Do the following iff this is a first open.
271 */
a5950399 272 crit_enter();
984263bc 273 while (sc->sc_opening)
377d4740 274 tsleep(&sc->sc_opening, 0, "ucomop", 0);
984263bc
MD
275 sc->sc_opening = 1;
276
277 if (!ISSET(tp->t_state, TS_ISOPEN)) {
278 struct termios t;
279
280 sc->sc_poll = 0;
281 sc->sc_lsr = sc->sc_msr = sc->sc_mcr = 0;
282
e4c9c0c8 283 tp->t_dev = reference_dev(dev);
984263bc
MD
284
285 /*
286 * Initialize the termios status to the defaults. Add in the
287 * sticky bits from TIOCSFLAGS.
288 */
289 t.c_ispeed = 0;
290 t.c_ospeed = TTYDEF_SPEED;
291 t.c_cflag = TTYDEF_CFLAG;
292 /* Make sure ucomparam() will do something. */
293 tp->t_ospeed = 0;
294 (void)ucomparam(tp, &t);
295 tp->t_iflag = TTYDEF_IFLAG;
296 tp->t_oflag = TTYDEF_OFLAG;
297 tp->t_lflag = TTYDEF_LFLAG;
298 ttychars(tp);
299 ttsetwater(tp);
300
301 /*
302 * Turn on DTR. We must always do this, even if carrier is not
303 * present, because otherwise we'd have to use TIOCSDTR
304 * immediately after setting CLOCAL, which applications do not
305 * expect. We always assert DTR while the device is open
306 * unless explicitly requested to deassert it.
307 */
308 (void)ucomctl(sc, TIOCM_DTR | TIOCM_RTS, DMBIS);
309
310 /* Device specific open */
311 if (sc->sc_callback->ucom_open != NULL) {
312 error = sc->sc_callback->ucom_open(sc->sc_parent,
313 sc->sc_portno);
314 if (error) {
315 ucom_cleanup(sc);
316 sc->sc_opening = 0;
317 wakeup(&sc->sc_opening);
a5950399 318 crit_exit();
984263bc
MD
319 return (error);
320 }
321 }
322
323 DPRINTF(("ucomopen: open pipes in = %d out = %d\n",
324 sc->sc_bulkin_no, sc->sc_bulkout_no));
325
326 /* Open the bulk pipes */
327 /* Bulk-in pipe */
328 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkin_no, 0,
329 &sc->sc_bulkin_pipe);
330 if (err) {
e3869ec7 331 kprintf("%s: open bulk in error (addr %d): %s\n",
6ed427ca 332 device_get_nameunit(sc->sc_dev), sc->sc_bulkin_no,
984263bc
MD
333 usbd_errstr(err));
334 error = EIO;
335 goto fail_0;
336 }
337 /* Bulk-out pipe */
338 err = usbd_open_pipe(sc->sc_iface, sc->sc_bulkout_no,
339 USBD_EXCLUSIVE_USE, &sc->sc_bulkout_pipe);
340 if (err) {
e3869ec7 341 kprintf("%s: open bulk out error (addr %d): %s\n",
6ed427ca 342 device_get_nameunit(sc->sc_dev), sc->sc_bulkout_no,
984263bc
MD
343 usbd_errstr(err));
344 error = EIO;
345 goto fail_1;
346 }
347
348 /* Allocate a request and an input buffer and start reading. */
349 sc->sc_ixfer = usbd_alloc_xfer(sc->sc_udev);
350 if (sc->sc_ixfer == NULL) {
351 error = ENOMEM;
352 goto fail_2;
353 }
354
355 sc->sc_ibuf = usbd_alloc_buffer(sc->sc_ixfer,
356 sc->sc_ibufsizepad);
357 if (sc->sc_ibuf == NULL) {
358 error = ENOMEM;
359 goto fail_3;
360 }
361
362 sc->sc_oxfer = usbd_alloc_xfer(sc->sc_udev);
363 if (sc->sc_oxfer == NULL) {
364 error = ENOMEM;
365 goto fail_3;
366 }
367
368 sc->sc_obuf = usbd_alloc_buffer(sc->sc_oxfer,
369 sc->sc_obufsize +
370 sc->sc_opkthdrlen);
371 if (sc->sc_obuf == NULL) {
372 error = ENOMEM;
373 goto fail_4;
374 }
375
376 /*
377 * Handle initial DCD.
378 */
379 if (ISSET(sc->sc_msr, UMSR_DCD) ||
380 (minor(dev) & UCOM_CALLOUT_MASK))
381 (*linesw[tp->t_line].l_modem)(tp, 1);
382
383 ucomstartread(sc);
384 }
385
386 sc->sc_opening = 0;
387 wakeup(&sc->sc_opening);
a5950399 388 crit_exit();
984263bc
MD
389
390 error = ttyopen(dev, tp);
391 if (error)
392 goto bad;
393
394 error = (*linesw[tp->t_line].l_open)(dev, tp);
395 if (error)
396 goto bad;
397
398 disc_optim(tp, &tp->t_termios, sc);
399
6ed427ca 400 DPRINTF(("%s: ucomopen: success\n", device_get_nameunit(sc->sc_dev)));
984263bc
MD
401
402 sc->sc_poll = 1;
403 sc->sc_refcnt++;
404
405 return (0);
406
407fail_4:
408 usbd_free_xfer(sc->sc_oxfer);
409 sc->sc_oxfer = NULL;
410fail_3:
411 usbd_free_xfer(sc->sc_ixfer);
412 sc->sc_ixfer = NULL;
413fail_2:
414 usbd_close_pipe(sc->sc_bulkout_pipe);
415 sc->sc_bulkout_pipe = NULL;
416fail_1:
417 usbd_close_pipe(sc->sc_bulkin_pipe);
418 sc->sc_bulkin_pipe = NULL;
419fail_0:
420 sc->sc_opening = 0;
421 wakeup(&sc->sc_opening);
a5950399 422 crit_exit();
984263bc
MD
423 return (error);
424
425bad:
426 if (!ISSET(tp->t_state, TS_ISOPEN)) {
427 /*
428 * We failed to open the device, and nobody else had it opened.
429 * Clean up the state as appropriate.
430 */
431 ucom_cleanup(sc);
432 }
433
6ed427ca 434 DPRINTF(("%s: ucomopen: failed\n", device_get_nameunit(sc->sc_dev)));
984263bc
MD
435
436 return (error);
437}
438
439static int
fef8985e 440ucomclose(struct dev_close_args *ap)
984263bc 441{
b13267a5 442 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
443 struct ucom_softc *sc;
444 struct tty *tp;
984263bc 445
1e089e7e 446 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(dev));
984263bc
MD
447
448 tp = sc->sc_tty;
449
450 DPRINTF(("%s: ucomclose: unit = %d\n",
6ed427ca 451 device_get_nameunit(sc->sc_dev), UCOMUNIT(dev)));
984263bc
MD
452
453 if (!ISSET(tp->t_state, TS_ISOPEN))
454 goto quit;
455
a5950399 456 crit_enter();
fef8985e 457 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
984263bc
MD
458 disc_optim(tp, &tp->t_termios, sc);
459 ttyclose(tp);
a5950399 460 crit_exit();
984263bc
MD
461
462 if (sc->sc_dying)
463 goto quit;
464
465 if (!ISSET(tp->t_state, TS_ISOPEN)) {
466 /*
467 * Although we got a last close, the device may still be in
468 * use; e.g. if this was the dialout node, and there are still
469 * processes waiting for carrier on the non-dialout node.
470 */
471 ucom_cleanup(sc);
472 }
473
474 if (sc->sc_callback->ucom_close != NULL)
475 sc->sc_callback->ucom_close(sc->sc_parent, sc->sc_portno);
476
77ab1ae2
MD
477quit:
478 if (tp->t_dev) {
479 release_dev(tp->t_dev);
480 tp->t_dev = NULL;
481 }
482
984263bc 483 if (--sc->sc_refcnt < 0)
2939c544 484 usb_detach_wakeup(sc->sc_dev);
984263bc
MD
485
486 return (0);
487}
488
489static int
fef8985e 490ucomread(struct dev_read_args *ap)
984263bc 491{
b13267a5 492 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
493 struct ucom_softc *sc;
494 struct tty *tp;
495 int error;
496
1e089e7e 497 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(dev));
984263bc
MD
498 tp = sc->sc_tty;
499
fef8985e 500 DPRINTF(("ucomread: tp = %p, flag = 0x%x\n", tp, ap->a_ioflag));
984263bc
MD
501
502 if (sc->sc_dying)
503 return (EIO);
504
fef8985e 505 error = (*linesw[tp->t_line].l_read)(tp, ap->a_uio, ap->a_ioflag);
984263bc
MD
506
507 DPRINTF(("ucomread: error = %d\n", error));
508
509 return (error);
510}
511
512static int
fef8985e 513ucomwrite(struct dev_write_args *ap)
984263bc 514{
b13267a5 515 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
516 struct ucom_softc *sc;
517 struct tty *tp;
518 int error;
519
1e089e7e 520 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(dev));
984263bc
MD
521 tp = sc->sc_tty;
522
fef8985e 523 DPRINTF(("ucomwrite: tp = %p, flag = 0x%x\n", tp, ap->a_ioflag));
984263bc
MD
524
525 if (sc->sc_dying)
526 return (EIO);
527
fef8985e 528 error = (*linesw[tp->t_line].l_write)(tp, ap->a_uio, ap->a_ioflag);
984263bc
MD
529
530 DPRINTF(("ucomwrite: error = %d\n", error));
531
532 return (error);
533}
534
535static int
fef8985e 536ucomioctl(struct dev_ioctl_args *ap)
984263bc 537{
b13267a5 538 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
539 struct ucom_softc *sc;
540 struct tty *tp;
541 int error;
984263bc
MD
542 int d;
543
1e089e7e 544 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(dev));
984263bc
MD
545 tp = sc->sc_tty;
546
547 if (sc->sc_dying)
548 return (EIO);
549
fef8985e 550 DPRINTF(("ucomioctl: cmd = 0x%08lx\n", ap->a_cmd));
984263bc 551
fef8985e
MD
552 error = (*linesw[tp->t_line].l_ioctl)(tp, ap->a_cmd, ap->a_data,
553 ap->a_fflag, ap->a_cred);
62ade751 554 if (error != ENOIOCTL) {
984263bc
MD
555 DPRINTF(("ucomioctl: l_ioctl: error = %d\n", error));
556 return (error);
557 }
558
a5950399 559 crit_enter();
62ade751 560
fef8985e 561 error = ttioctl(tp, ap->a_cmd, ap->a_data, ap->a_fflag);
984263bc 562 disc_optim(tp, &tp->t_termios, sc);
62ade751 563 if (error != ENOIOCTL) {
a5950399 564 crit_exit();
984263bc
MD
565 DPRINTF(("ucomioctl: ttioctl: error = %d\n", error));
566 return (error);
567 }
568
569 if (sc->sc_callback->ucom_ioctl != NULL) {
570 error = sc->sc_callback->ucom_ioctl(sc->sc_parent,
571 sc->sc_portno,
fef8985e
MD
572 ap->a_cmd, ap->a_data,
573 ap->a_fflag, curthread);
a5950399
MD
574 if (error >= 0) {
575 crit_exit();
984263bc 576 return (error);
a5950399 577 }
984263bc
MD
578 }
579
580 error = 0;
581
fef8985e 582 DPRINTF(("ucomioctl: our cmd = 0x%08lx\n", ap->a_cmd));
984263bc 583
fef8985e 584 switch (ap->a_cmd) {
984263bc
MD
585 case TIOCSBRK:
586 DPRINTF(("ucomioctl: TIOCSBRK\n"));
587 ucom_break(sc, 1);
588 break;
589 case TIOCCBRK:
590 DPRINTF(("ucomioctl: TIOCCBRK\n"));
591 ucom_break(sc, 0);
592 break;
593
594 case TIOCSDTR:
595 DPRINTF(("ucomioctl: TIOCSDTR\n"));
596 (void)ucomctl(sc, TIOCM_DTR, DMBIS);
597 break;
598 case TIOCCDTR:
599 DPRINTF(("ucomioctl: TIOCCDTR\n"));
600 (void)ucomctl(sc, TIOCM_DTR, DMBIC);
601 break;
602
603 case TIOCMSET:
fef8985e 604 d = *(int *)ap->a_data;
984263bc
MD
605 DPRINTF(("ucomioctl: TIOCMSET, 0x%x\n", d));
606 (void)ucomctl(sc, d, DMSET);
607 break;
608 case TIOCMBIS:
fef8985e 609 d = *(int *)ap->a_data;
984263bc
MD
610 DPRINTF(("ucomioctl: TIOCMBIS, 0x%x\n", d));
611 (void)ucomctl(sc, d, DMBIS);
612 break;
613 case TIOCMBIC:
fef8985e 614 d = *(int *)ap->a_data;
984263bc
MD
615 DPRINTF(("ucomioctl: TIOCMBIC, 0x%x\n", d));
616 (void)ucomctl(sc, d, DMBIC);
617 break;
618 case TIOCMGET:
619 d = ucomctl(sc, 0, DMGET);
620 DPRINTF(("ucomioctl: TIOCMGET, 0x%x\n", d));
fef8985e 621 *(int *)ap->a_data = d;
984263bc
MD
622 break;
623
624 default:
fef8985e 625 DPRINTF(("ucomioctl: error: our cmd = 0x%08lx\n", ap->a_cmd));
984263bc
MD
626 error = ENOTTY;
627 break;
628 }
629
a5950399 630 crit_exit();
984263bc
MD
631
632 return (error);
633}
634
6ed427ca 635static int
984263bc
MD
636ucomctl(struct ucom_softc *sc, int bits, int how)
637{
638 int mcr;
639 int msr;
640 int onoff;
641
642 DPRINTF(("ucomctl: bits = 0x%x, how = %d\n", bits, how));
643
644 if (how == DMGET) {
645 SET(bits, TIOCM_LE); /* always set TIOCM_LE bit */
646 DPRINTF(("ucomctl: DMGET: LE"));
647
648 mcr = sc->sc_mcr;
649 if (ISSET(mcr, UMCR_DTR)) {
650 SET(bits, TIOCM_DTR);
651 DPRINTF((" DTR"));
652 }
653 if (ISSET(mcr, UMCR_RTS)) {
654 SET(bits, TIOCM_RTS);
655 DPRINTF((" RTS"));
656 }
657
658 msr = sc->sc_msr;
659 if (ISSET(msr, UMSR_CTS)) {
660 SET(bits, TIOCM_CTS);
661 DPRINTF((" CTS"));
662 }
663 if (ISSET(msr, UMSR_DCD)) {
664 SET(bits, TIOCM_CD);
665 DPRINTF((" CD"));
666 }
667 if (ISSET(msr, UMSR_DSR)) {
668 SET(bits, TIOCM_DSR);
669 DPRINTF((" DSR"));
670 }
671 if (ISSET(msr, UMSR_RI)) {
672 SET(bits, TIOCM_RI);
673 DPRINTF((" RI"));
674 }
675
676 DPRINTF(("\n"));
677
678 return (bits);
679 }
680
681 mcr = 0;
682 if (ISSET(bits, TIOCM_DTR))
683 SET(mcr, UMCR_DTR);
684 if (ISSET(bits, TIOCM_RTS))
685 SET(mcr, UMCR_RTS);
686
687 switch (how) {
688 case DMSET:
689 sc->sc_mcr = mcr;
690 break;
691 case DMBIS:
692 sc->sc_mcr |= mcr;
693 break;
694 case DMBIC:
695 sc->sc_mcr &= ~mcr;
696 break;
697 }
698
699 onoff = ISSET(sc->sc_mcr, UMCR_DTR) ? 1 : 0;
700 ucom_dtr(sc, onoff);
701
702 onoff = ISSET(sc->sc_mcr, UMCR_RTS) ? 1 : 0;
703 ucom_rts(sc, onoff);
704
705 return (0);
706}
707
6ed427ca 708static void
984263bc
MD
709ucom_break(struct ucom_softc *sc, int onoff)
710{
711 DPRINTF(("ucom_break: onoff = %d\n", onoff));
712
713 if (sc->sc_callback->ucom_set == NULL)
714 return;
715 sc->sc_callback->ucom_set(sc->sc_parent, sc->sc_portno,
716 UCOM_SET_BREAK, onoff);
717}
718
6ed427ca 719static void
984263bc
MD
720ucom_dtr(struct ucom_softc *sc, int onoff)
721{
722 DPRINTF(("ucom_dtr: onoff = %d\n", onoff));
723
724 if (sc->sc_callback->ucom_set == NULL)
725 return;
1550dfd9 726 sc->sc_callback->ucom_set(sc->sc_parent, sc->sc_portno,
984263bc
MD
727 UCOM_SET_DTR, onoff);
728}
729
6ed427ca 730static void
984263bc
MD
731ucom_rts(struct ucom_softc *sc, int onoff)
732{
733 DPRINTF(("ucom_rts: onoff = %d\n", onoff));
734
735 if (sc->sc_callback->ucom_set == NULL)
736 return;
1550dfd9 737 sc->sc_callback->ucom_set(sc->sc_parent, sc->sc_portno,
984263bc
MD
738 UCOM_SET_RTS, onoff);
739}
740
741void
742ucom_status_change(struct ucom_softc *sc)
743{
744 struct tty *tp = sc->sc_tty;
745 u_char old_msr;
746 int onoff;
747
748 if (sc->sc_callback->ucom_get_status == NULL) {
749 sc->sc_lsr = 0;
750 sc->sc_msr = 0;
751 return;
752 }
753
754 old_msr = sc->sc_msr;
755 sc->sc_callback->ucom_get_status(sc->sc_parent, sc->sc_portno,
756 &sc->sc_lsr, &sc->sc_msr);
757 if (ISSET((sc->sc_msr ^ old_msr), UMSR_DCD)) {
758 if (sc->sc_poll == 0)
759 return;
760 onoff = ISSET(sc->sc_msr, UMSR_DCD) ? 1 : 0;
761 DPRINTF(("ucom_status_change: DCD changed to %d\n", onoff));
762 (*linesw[tp->t_line].l_modem)(tp, onoff);
763 }
764}
765
6ed427ca 766static int
984263bc
MD
767ucomparam(struct tty *tp, struct termios *t)
768{
769 struct ucom_softc *sc;
770 int error;
771 usbd_status uerr;
772
1e089e7e 773 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(tp->t_dev));
984263bc
MD
774
775 if (sc->sc_dying)
776 return (EIO);
777
778 DPRINTF(("ucomparam: sc = %p\n", sc));
779
780 /* Check requested parameters. */
781 if (t->c_ospeed < 0) {
782 DPRINTF(("ucomparam: negative ospeed\n"));
783 return (EINVAL);
784 }
785 if (t->c_ispeed && t->c_ispeed != t->c_ospeed) {
786 DPRINTF(("ucomparam: mismatch ispeed and ospeed\n"));
787 return (EINVAL);
788 }
789
790 /*
791 * If there were no changes, don't do anything. This avoids dropping
792 * input and improves performance when all we did was frob things like
793 * VMIN and VTIME.
794 */
795 if (tp->t_ospeed == t->c_ospeed &&
796 tp->t_cflag == t->c_cflag)
797 return (0);
798
799 /* And copy to tty. */
800 tp->t_ispeed = 0;
801 tp->t_ospeed = t->c_ospeed;
802 tp->t_cflag = t->c_cflag;
803
804 if (sc->sc_callback->ucom_param == NULL)
805 return (0);
806
807 ucomstopread(sc);
808
809 error = sc->sc_callback->ucom_param(sc->sc_parent, sc->sc_portno, t);
810 if (error) {
811 DPRINTF(("ucomparam: callback: error = %d\n", error));
812 return (error);
813 }
814
815 ttsetwater(tp);
816
817 if (t->c_cflag & CRTS_IFLOW) {
818 sc->sc_state |= UCS_RTS_IFLOW;
819 } else if (sc->sc_state & UCS_RTS_IFLOW) {
820 sc->sc_state &= ~UCS_RTS_IFLOW;
821 (void)ucomctl(sc, UMCR_RTS, DMBIS);
822 }
823
824 disc_optim(tp, t, sc);
825
826 uerr = ucomstartread(sc);
827 if (uerr != USBD_NORMAL_COMPLETION)
828 return (EIO);
829
830 return (0);
831}
832
6ed427ca 833static void
984263bc
MD
834ucomstart(struct tty *tp)
835{
836 struct ucom_softc *sc;
837 struct cblock *cbp;
838 usbd_status err;
984263bc
MD
839 u_char *data;
840 int cnt;
841
1e089e7e 842 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(tp->t_dev));
984263bc
MD
843 DPRINTF(("ucomstart: sc = %p\n", sc));
844
845 if (sc->sc_dying)
846 return;
847
a5950399 848 crit_enter();
984263bc
MD
849
850 if (tp->t_state & TS_TBLOCK) {
851 if (ISSET(sc->sc_mcr, UMCR_RTS) &&
852 ISSET(sc->sc_state, UCS_RTS_IFLOW)) {
853 DPRINTF(("ucomstart: clear RTS\n"));
854 (void)ucomctl(sc, UMCR_RTS, DMBIC);
855 }
856 } else {
857 if (!ISSET(sc->sc_mcr, UMCR_RTS) &&
858 tp->t_rawq.c_cc <= tp->t_ilowat &&
859 ISSET(sc->sc_state, UCS_RTS_IFLOW)) {
860 DPRINTF(("ucomstart: set RTS\n"));
861 (void)ucomctl(sc, UMCR_RTS, DMBIS);
862 }
863 }
864
865 if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
866 ttwwakeup(tp);
867 DPRINTF(("ucomstart: stopped\n"));
868 goto out;
869 }
870
871 if (tp->t_outq.c_cc <= tp->t_olowat) {
872 if (ISSET(tp->t_state, TS_SO_OLOWAT)) {
873 CLR(tp->t_state, TS_SO_OLOWAT);
874 wakeup(TSA_OLOWAT(tp));
875 }
5b22f1a7 876 KNOTE(&tp->t_wkq.ki_note, 0);
984263bc
MD
877 if (tp->t_outq.c_cc == 0) {
878 if (ISSET(tp->t_state, TS_BUSY | TS_SO_OCOMPLETE) ==
879 TS_SO_OCOMPLETE && tp->t_outq.c_cc == 0) {
880 CLR(tp->t_state, TS_SO_OCOMPLETE);
881 wakeup(TSA_OCOMPLETE(tp));
882 }
883 goto out;
884 }
885 }
886
887 /* Grab the first contiguous region of buffer space. */
888 data = tp->t_outq.c_cf;
889 cbp = (struct cblock *) ((intptr_t) tp->t_outq.c_cf & ~CROUND);
890 cnt = min((char *) (cbp+1) - tp->t_outq.c_cf, tp->t_outq.c_cc);
891
892 if (cnt == 0) {
893 DPRINTF(("ucomstart: cnt == 0\n"));
894 goto out;
895 }
896
897 SET(tp->t_state, TS_BUSY);
898
899 if (cnt > sc->sc_obufsize) {
900 DPRINTF(("ucomstart: big buffer %d chars\n", cnt));
901 cnt = sc->sc_obufsize;
902 }
903 if (sc->sc_callback->ucom_write != NULL)
904 sc->sc_callback->ucom_write(sc->sc_parent, sc->sc_portno,
905 sc->sc_obuf, data, &cnt);
906 else
907 memcpy(sc->sc_obuf, data, cnt);
908
909 DPRINTF(("ucomstart: %d chars\n", cnt));
1550dfd9 910 usbd_setup_xfer(sc->sc_oxfer, sc->sc_bulkout_pipe,
984263bc
MD
911 (usbd_private_handle)sc, sc->sc_obuf, cnt,
912 USBD_NO_COPY, USBD_NO_TIMEOUT, ucomwritecb);
913 /* What can we do on error? */
914 err = usbd_transfer(sc->sc_oxfer);
915 if (err != USBD_IN_PROGRESS)
e3869ec7 916 kprintf("ucomstart: err=%s\n", usbd_errstr(err));
984263bc
MD
917
918 ttwwakeup(tp);
919
920 out:
a5950399 921 crit_exit();
984263bc
MD
922}
923
6ed427ca 924static void
984263bc
MD
925ucomstop(struct tty *tp, int flag)
926{
927 struct ucom_softc *sc;
984263bc 928
1e089e7e 929 sc = devclass_get_softc(ucom_devclass, UCOMUNIT(tp->t_dev));
984263bc
MD
930
931 DPRINTF(("ucomstop: %d\n", flag));
932
933 if (flag & FREAD) {
6a76f45a
MD
934 /*
935 * This is just supposed to flush pending receive data,
936 * not stop the reception of data entirely!
937 */
984263bc
MD
938 DPRINTF(("ucomstop: read\n"));
939 ucomstopread(sc);
6a76f45a 940 ucomstartread(sc);
984263bc
MD
941 }
942
943 if (flag & FWRITE) {
944 DPRINTF(("ucomstop: write\n"));
a5950399 945 crit_enter();
984263bc
MD
946 if (ISSET(tp->t_state, TS_BUSY)) {
947 /* XXX do what? */
948 if (!ISSET(tp->t_state, TS_TTSTOP))
949 SET(tp->t_state, TS_FLUSH);
950 }
a5950399 951 crit_exit();
984263bc
MD
952 }
953
954 DPRINTF(("ucomstop: done\n"));
955}
956
6ed427ca 957static void
984263bc
MD
958ucomwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
959{
960 struct ucom_softc *sc = (struct ucom_softc *)p;
961 struct tty *tp = sc->sc_tty;
962 u_int32_t cc;
984263bc
MD
963
964 DPRINTF(("ucomwritecb: status = %d\n", status));
965
966 if (status == USBD_CANCELLED || sc->sc_dying)
967 goto error;
968
969 if (status != USBD_NORMAL_COMPLETION) {
e3869ec7 970 kprintf("%s: ucomwritecb: %s\n",
6ed427ca 971 device_get_nameunit(sc->sc_dev), usbd_errstr(status));
984263bc
MD
972 if (status == USBD_STALLED)
973 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
6a76f45a
MD
974 /*
975 * XXX. We may need a flag to sequence ucomstopread() and
976 * ucomstartread() to handle the case where ucomstartread()
977 * is called after ucomstopread() but before the request has
978 * been properly canceled?
979 */
984263bc
MD
980 goto error;
981 }
982
983 usbd_get_xfer_status(xfer, NULL, NULL, &cc, NULL);
984 DPRINTF(("ucomwritecb: cc = %d\n", cc));
62ade751 985 if (cc <= sc->sc_opkthdrlen) {
e3869ec7 986 kprintf("%s: sent size too small, cc = %d\n",
6ed427ca 987 device_get_nameunit(sc->sc_dev), cc);
62ade751
MD
988 goto error;
989 }
984263bc
MD
990
991 /* convert from USB bytes to tty bytes */
992 cc -= sc->sc_opkthdrlen;
993
a5950399 994 crit_enter();
984263bc
MD
995 CLR(tp->t_state, TS_BUSY);
996 if (ISSET(tp->t_state, TS_FLUSH))
997 CLR(tp->t_state, TS_FLUSH);
998 else
999 ndflush(&tp->t_outq, cc);
1000 (*linesw[tp->t_line].l_start)(tp);
a5950399 1001 crit_exit();
984263bc
MD
1002
1003 return;
1004
1005 error:
a5950399 1006 crit_enter();
984263bc 1007 CLR(tp->t_state, TS_BUSY);
a5950399 1008 crit_exit();
984263bc
MD
1009 return;
1010}
1011
6ed427ca 1012static usbd_status
984263bc
MD
1013ucomstartread(struct ucom_softc *sc)
1014{
1015 usbd_status err;
1016
1017 DPRINTF(("ucomstartread: start\n"));
1018
1019 sc->sc_state &= ~UCS_RXSTOP;
1020
1021 if (sc->sc_bulkin_pipe == NULL)
1022 return (USBD_NORMAL_COMPLETION);
1023
1550dfd9
MD
1024 usbd_setup_xfer(sc->sc_ixfer, sc->sc_bulkin_pipe,
1025 (usbd_private_handle)sc,
984263bc
MD
1026 sc->sc_ibuf, sc->sc_ibufsize,
1027 USBD_SHORT_XFER_OK | USBD_NO_COPY,
1028 USBD_NO_TIMEOUT, ucomreadcb);
1029
1030 err = usbd_transfer(sc->sc_ixfer);
1031 if (err != USBD_IN_PROGRESS) {
1032 DPRINTF(("ucomstartread: err = %s\n", usbd_errstr(err)));
1033 return (err);
1034 }
1035
1036 return (USBD_NORMAL_COMPLETION);
1037}
1038
6ed427ca 1039static void
984263bc
MD
1040ucomreadcb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
1041{
1042 struct ucom_softc *sc = (struct ucom_softc *)p;
1043 struct tty *tp = sc->sc_tty;
1044 int (*rint) (int c, struct tty *tp) = linesw[tp->t_line].l_rint;
1045 usbd_status err;
1046 u_int32_t cc;
1047 u_char *cp;
1048 int lostcc;
984263bc
MD
1049
1050 DPRINTF(("ucomreadcb: status = %d\n", status));
1051
1052 if (status != USBD_NORMAL_COMPLETION) {
1053 if (!(sc->sc_state & UCS_RXSTOP))
e3869ec7 1054 kprintf("%s: ucomreadcb: %s\n",
6ed427ca 1055 device_get_nameunit(sc->sc_dev), usbd_errstr(status));
984263bc
MD
1056 if (status == USBD_STALLED)
1057 usbd_clear_endpoint_stall_async(sc->sc_bulkin_pipe);
1058 /* XXX we should restart after some delay. */
1059 return;
1060 }
1061
1062 usbd_get_xfer_status(xfer, NULL, (void **)&cp, &cc, NULL);
1063 DPRINTF(("ucomreadcb: got %d chars, tp = %p\n", cc, tp));
62ade751
MD
1064 if (cc == 0)
1065 goto resubmit;
1066
1067 if (sc->sc_callback->ucom_read != NULL) {
984263bc
MD
1068 sc->sc_callback->ucom_read(sc->sc_parent, sc->sc_portno,
1069 &cp, &cc);
62ade751
MD
1070 }
1071
1072 if (cc > sc->sc_ibufsize) {
e3869ec7 1073 kprintf("%s: invalid receive data size, %d chars\n",
6ed427ca 1074 device_get_nameunit(sc->sc_dev), cc);
62ade751
MD
1075 goto resubmit;
1076 }
1077 if (cc < 1)
1078 goto resubmit;
984263bc 1079
a5950399 1080 crit_enter();
984263bc
MD
1081 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1082 if (tp->t_rawq.c_cc + cc > tp->t_ihiwat
1083 && (sc->sc_state & UCS_RTS_IFLOW
1084 || tp->t_iflag & IXOFF)
1085 && !(tp->t_state & TS_TBLOCK))
1086 ttyblock(tp);
1087 lostcc = b_to_q((char *)cp, cc, &tp->t_rawq);
1088 tp->t_rawcc += cc;
6a76f45a
MD
1089 if (sc->hotchar) {
1090 while (cc) {
1091 if (*cp == sc->hotchar)
1092 break;
1093 --cc;
1094 ++cp;
1095 }
1096 if (cc)
1097 setsofttty();
1098 }
984263bc
MD
1099 ttwakeup(tp);
1100 if (tp->t_state & TS_TTSTOP
1101 && (tp->t_iflag & IXANY
1102 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1103 tp->t_state &= ~TS_TTSTOP;
1104 tp->t_lflag &= ~FLUSHO;
1105 ucomstart(tp);
1106 }
1107 if (lostcc > 0)
6ed427ca 1108 kprintf("%s: lost %d chars\n", device_get_nameunit(sc->sc_dev),
984263bc
MD
1109 lostcc);
1110 } else {
1111 /* Give characters to tty layer. */
62ade751
MD
1112 while (cc > 0) {
1113 DPRINTFN(7, ("ucomreadcb: char = 0x%02x\n", *cp));
1114 if ((*rint)(*cp, tp) == -1) {
984263bc 1115 /* XXX what should we do? */
e3869ec7 1116 kprintf("%s: lost %d chars\n",
6ed427ca 1117 device_get_nameunit(sc->sc_dev), cc);
984263bc
MD
1118 break;
1119 }
62ade751
MD
1120 cc--;
1121 cp++;
984263bc
MD
1122 }
1123 }
a5950399 1124 crit_exit();
984263bc 1125
62ade751 1126resubmit:
984263bc
MD
1127 err = ucomstartread(sc);
1128 if (err) {
6ed427ca 1129 kprintf("%s: read start failed\n", device_get_nameunit(sc->sc_dev));
984263bc
MD
1130 /* XXX what should we dow now? */
1131 }
1132
1133 if ((sc->sc_state & UCS_RTS_IFLOW) && !ISSET(sc->sc_mcr, UMCR_RTS)
1134 && !(tp->t_state & TS_TBLOCK))
1135 ucomctl(sc, UMCR_RTS, DMBIS);
1136}
1137
6ed427ca 1138static void
984263bc
MD
1139ucom_cleanup(struct ucom_softc *sc)
1140{
1141 DPRINTF(("ucom_cleanup: closing pipes\n"));
1142
1143 ucom_shutdown(sc);
1144 if (sc->sc_bulkin_pipe != NULL) {
1145 usbd_abort_pipe(sc->sc_bulkin_pipe);
1146 usbd_close_pipe(sc->sc_bulkin_pipe);
1147 sc->sc_bulkin_pipe = NULL;
1148 }
1149 if (sc->sc_bulkout_pipe != NULL) {
1150 usbd_abort_pipe(sc->sc_bulkout_pipe);
1151 usbd_close_pipe(sc->sc_bulkout_pipe);
1152 sc->sc_bulkout_pipe = NULL;
1153 }
1154 if (sc->sc_ixfer != NULL) {
1155 usbd_free_xfer(sc->sc_ixfer);
1156 sc->sc_ixfer = NULL;
1157 }
1158 if (sc->sc_oxfer != NULL) {
1159 usbd_free_xfer(sc->sc_oxfer);
1160 sc->sc_oxfer = NULL;
1161 }
1162}
1163
6ed427ca 1164static void
984263bc
MD
1165ucomstopread(struct ucom_softc *sc)
1166{
1167 usbd_status err;
1168
1169 DPRINTF(("ucomstopread: enter\n"));
1170
1171 if (!(sc->sc_state & UCS_RXSTOP)) {
62ade751 1172 sc->sc_state |= UCS_RXSTOP;
984263bc
MD
1173 if (sc->sc_bulkin_pipe == NULL) {
1174 DPRINTF(("ucomstopread: bulkin pipe NULL\n"));
1175 return;
1176 }
984263bc
MD
1177 err = usbd_abort_pipe(sc->sc_bulkin_pipe);
1178 if (err) {
1179 DPRINTF(("ucomstopread: err = %s\n",
1180 usbd_errstr(err)));
1181 }
1182 }
1183
1184 DPRINTF(("ucomstopread: leave\n"));
1185}
1186
1187static void
1188disc_optim(struct tty *tp, struct termios *t, struct ucom_softc *sc)
1189{
1190 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
1191 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
1192 && (!(t->c_iflag & PARMRK)
1193 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
1194 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
1195 && linesw[tp->t_line].l_rint == ttyinput) {
1196 DPRINTF(("disc_optim: bypass l_rint\n"));
1197 tp->t_state |= TS_CAN_BYPASS_L_RINT;
1198 } else {
1199 DPRINTF(("disc_optim: can't bypass l_rint\n"));
1200 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
1201 }
1202 sc->hotchar = linesw[tp->t_line].l_hotchar;
1203}