2 * cyclades cyclom-y serial driver
3 * Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
5 * Copyright (c) 1993 Andrew Herbert.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name Andrew Herbert may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "opt_compat.h"
43 * Temporary compile-time configuration options.
45 #define RxFifoThreshold (CD1400_RX_FIFO_SIZE / 2)
46 /* Number of chars in the receiver FIFO before an
47 * an interrupt is generated. Should depend on
48 * line speed. Needs to be about 6 on a 486DX33
49 * for 4 active ports at 115200 bps. Why doesn't
52 #define PollMode /* Use polling-based irq service routine, not the
53 * hardware svcack lines. Must be defined for
54 * Cyclom-16Y boards. Less efficient for Cyclom-8Ys,
55 * and stops 4 * 115200 bps from working.
57 #undef Smarts /* Enable slightly more CD1400 intelligence. Mainly
58 * the output CR/LF processing, plus we can avoid a
59 * few checks usually done in ttyinput().
61 * XXX not fully implemented, and not particularly
64 #undef CyDebug /* Include debugging code (not very expensive). */
66 /* These will go away. */
70 #include <sys/param.h>
71 #include <sys/systm.h>
75 #include <sys/dkstat.h>
76 #include <sys/fcntl.h>
77 #include <sys/interrupt.h>
78 #include <sys/kernel.h>
79 #include <sys/malloc.h>
80 #include <sys/syslog.h>
82 #include <machine/clock.h>
83 #include <machine/ipl.h>
85 #include <machine/lock.h>
87 #include <machine/psl.h>
89 #include <i386/isa/isa_device.h>
90 #include <i386/isa/cyreg.h>
91 #include <i386/isa/ic/cd1400.h>
94 #error "The cy device requires the old isa compatibility shims"
98 * Dictionary so that I can name everything *sio* or *com* to compare with
99 * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
100 * simplify the comparision. These will go away.
102 #define LSR_BI CD1400_RDSR_BREAK
103 #define LSR_FE CD1400_RDSR_FE
104 #define LSR_OE CD1400_RDSR_OE
105 #define LSR_PE CD1400_RDSR_PE
106 #define MCR_DTR CD1400_MSVR2_DTR
107 #define MCR_RTS CD1400_MSVR1_RTS
108 #define MSR_CTS CD1400_MSVR2_CTS
109 #define MSR_DCD CD1400_MSVR2_CD
110 #define MSR_DSR CD1400_MSVR2_DSR
111 #define MSR_RI CD1400_MSVR2_RI
112 #define NSIO (NCY * CY_MAX_PORTS)
113 #define comconsole cyconsole
114 #define comdefaultrate cydefaultrate
115 #define com_events cy_events
116 #define comhardclose cyhardclose
117 #define commctl cymctl
118 #define comparam cyparam
119 #define comspeed cyspeed
120 #define comstart cystart
121 #define comwakeup cywakeup
122 #define nsio_tty ncy_tty
123 #define p_com_addr p_cy_addr
124 #define sioattach cyattach
125 #define sioclose cyclose
126 #define siodriver cydriver
127 #define siodtrwakeup cydtrwakeup
128 #define sioinput cyinput
129 #define siointr cyintr
130 #define siointr1 cyintr1
131 #define sioioctl cyioctl
132 #define sioopen cyopen
133 #define siopoll cypoll
134 #define sioprobe cyprobe
135 #define siosettimeout cysettimeout
136 #define siosetwater cysetwater
137 #define comstop cystop
138 #define siowrite cywrite
139 #define sio_registered cy_registered
140 #define sio_timeout cy_timeout
141 #define sio_timeout_handle cy_timeout_handle
142 #define sio_timeouts_until_log cy_timeouts_until_log
143 #define sio_tty cy_tty
145 #define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
147 /* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
148 #define CD1400_xIVR_CHAN_SHIFT 3
149 #define CD1400_xIVR_CHAN 0x1F
152 * ETC states. com->etc may also contain a hardware ETC command value,
153 * meaning that execution of that command is pending.
155 #define ETC_NONE 0 /* we depend on bzero() setting this */
156 #define ETC_BREAK_STARTING 1
157 #define ETC_BREAK_STARTED 2
158 #define ETC_BREAK_ENDING 3
159 #define ETC_BREAK_ENDED 4
161 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
163 #define CALLOUT_MASK 0x80
164 #define CONTROL_MASK 0x60
165 #define CONTROL_INIT_STATE 0x20
166 #define CONTROL_LOCK_STATE 0x40
167 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
168 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
169 #define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
170 | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
174 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
175 * than the other bits so that they can be tested as a group without masking
178 * The following com and tty flags correspond closely:
179 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
181 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
182 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
183 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
184 * TS_FLUSH is not used.
185 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
186 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
188 #define CS_BUSY 0x80 /* output in progress */
189 #define CS_TTGO 0x40 /* output not stopped by XOFF */
190 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
191 #define CS_CHECKMSR 1 /* check of MSR scheduled */
192 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
193 #define CS_DTR_OFF 0x10 /* DTR held off */
194 #define CS_ODONE 4 /* output completed */
195 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
196 #define CSE_ODONE 1 /* output transmitted */
198 static char const * const error_desc[] = {
201 #define CE_INTERRUPT_BUF_OVERFLOW 1
202 "interrupt-level buffer overflow",
203 #define CE_TTY_BUF_OVERFLOW 2
204 "tty-level buffer overflow",
208 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
210 /* types. XXX - should be elsewhere */
211 typedef u_char bool_t; /* boolean */
212 typedef u_char volatile *cy_addr;
214 /* queue of linear buffers */
216 u_char *l_head; /* next char to process */
217 u_char *l_tail; /* one past the last char to process */
218 struct lbq *l_next; /* next in queue */
219 bool_t l_queued; /* nonzero if queued */
222 /* com device structure */
224 u_char state; /* miscellaneous flag bits */
225 bool_t active_out; /* nonzero if the callout device is open */
227 u_char cfcr_image; /* copy of value written to CFCR */
229 u_char etc; /* pending Embedded Transmit Command */
230 u_char extra_state; /* more flag bits, separate for order trick */
232 u_char fifo_image; /* copy of value written to FIFO */
234 u_char gfrcr_image; /* copy of value read from GFRCR */
236 bool_t hasfifo; /* nonzero for 16550 UARTs */
237 bool_t loses_outints; /* nonzero if device loses output interrupts */
239 u_char mcr_dtr; /* MCR bit that is wired to DTR */
240 u_char mcr_image; /* copy of value written to MCR */
241 u_char mcr_rts; /* MCR bit that is wired to RTS */
244 bool_t multiport; /* is this unit part of a multiport device? */
245 #endif /* COM_MULTIPORT */
246 bool_t no_irq; /* nonzero if irq is not attached */
247 bool_t poll; /* nonzero if polling is required */
248 bool_t poll_output; /* nonzero if polling for output is required */
250 int unit; /* unit number */
251 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
255 u_int wopeners; /* # processes waiting for DCD in open() */
258 * The high level of the driver never reads status registers directly
259 * because there would be too many side effects to handle conveniently.
260 * Instead, it reads copies of the registers stored here by the
263 u_char last_modem_status; /* last MSR read by intr handler */
264 u_char prev_modem_status; /* last MSR handled by high level */
266 u_char hotchar; /* ldisc-specific char to be handled ASAP */
267 u_char *ibuf; /* start of input buffer */
268 u_char *ibufend; /* end of input buffer */
269 u_char *ibufold; /* old input buffer, to be freed */
270 u_char *ihighwater; /* threshold in input buffer */
271 u_char *iptr; /* next free spot in input buffer */
272 int ibufsize; /* size of ibuf (not include error bytes) */
273 int ierroff; /* offset of error bytes in ibuf */
275 struct lbq obufq; /* head of queue of output buffers */
276 struct lbq obufs[2]; /* output buffers */
278 int cy_align; /* index for register alignment */
279 cy_addr cy_iobase; /* base address of this port's cyclom */
280 cy_addr iobase; /* base address of this port's cd1400 */
281 int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
283 struct tty *tp; /* cross reference */
286 struct termios it_in; /* should be in struct tty */
287 struct termios it_out;
290 struct termios lt_in; /* should be in struct tty */
291 struct termios lt_out;
294 bool_t do_dcd_timestamp;
295 struct timeval timestamp;
296 struct timeval dcd_timestamp;
298 u_long bytes_in; /* statistics */
300 u_int delta_error_counts[CE_NTYPES];
301 u_long error_counts[CE_NTYPES];
303 u_int recv_exception; /* exception chars received */
304 u_int mdm; /* modem signal changes */
306 u_int start_count; /* no. of calls to comstart() */
307 u_int start_real; /* no. of calls that did something */
309 u_char car; /* CD1400 CAR shadow (if first unit in cd) */
310 u_char channel_control;/* CD1400 CCR control command shadow */
311 u_char cor[3]; /* CD1400 COR1-3 shadows */
312 u_char intr_enable; /* CD1400 SRER shadow */
315 * Data area for output buffers. Someday we should build the output
316 * buffer queue without copying data.
322 /* PCI driver entry point. */
323 int cyattach_common __P((cy_addr cy_iobase, int cy_align));
326 static int cy_units __P((cy_addr cy_iobase, int cy_align));
327 static int sioattach __P((struct isa_device *dev));
328 static void cd1400_channel_cmd __P((struct com_s *com, int cmd));
329 static void cd1400_channel_cmd_wait __P((struct com_s *com));
330 static void cd_etc __P((struct com_s *com, int etc));
331 static int cd_getreg __P((struct com_s *com, int reg));
332 static void cd_setreg __P((struct com_s *com, int reg, int val));
333 static timeout_t siodtrwakeup;
334 static void comhardclose __P((struct com_s *com));
335 static void sioinput __P((struct com_s *com));
337 static void siointr1 __P((struct com_s *com));
339 static int commctl __P((struct com_s *com, int bits, int how));
340 static int comparam __P((struct tty *tp, struct termios *t));
341 static swihand_t siopoll;
342 static int sioprobe __P((struct isa_device *dev));
343 static void siosettimeout __P((void));
344 static int siosetwater __P((struct com_s *com, speed_t speed));
345 static int comspeed __P((speed_t speed, u_long cy_clock,
347 static void comstart __P((struct tty *tp));
348 static void comstop __P((struct tty *tp, int rw));
349 static timeout_t comwakeup;
350 static void disc_optim __P((struct tty *tp, struct termios *t,
354 void cystatus __P((int unit));
357 static char driver_name[] = "cy";
359 /* table and macro for fast conversion from a unit number to its com struct */
360 static struct com_s *p_com_addr[NSIO];
361 #define com_addr(unit) (p_com_addr[unit])
363 struct isa_driver siodriver = {
364 INTR_TYPE_TTY | INTR_FAST,
369 COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
371 static d_open_t sioopen;
372 static d_close_t sioclose;
373 static d_write_t siowrite;
374 static d_ioctl_t sioioctl;
376 #define CDEV_MAJOR 48
377 static struct cdevsw sio_cdevsw = {
379 /* close */ sioclose,
381 /* write */ siowrite,
382 /* ioctl */ sioioctl,
385 /* strategy */ nostrategy,
386 /* name */ driver_name,
387 /* maj */ CDEV_MAJOR,
394 static int comconsole = -1;
395 static speed_t comdefaultrate = TTYDEF_SPEED;
396 static u_int com_events; /* input chars + weighted output completions */
397 static bool_t sio_registered;
398 static int sio_timeout;
399 static int sio_timeouts_until_log;
400 static struct callout_handle sio_timeout_handle
401 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
403 static struct tty *sio_tty[NSIO];
405 static struct tty sio_tty[NSIO];
407 static const int nsio_tty = NSIO;
410 static u_int cd_inbs;
411 static u_int cy_inbs;
412 static u_int cd_outbs;
413 static u_int cy_outbs;
414 static u_int cy_svrr_probes;
415 static u_int cy_timeouts;
418 static int cy_chip_offset[] = {
419 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
421 static int cy_nr_cd1400s[NCY];
422 static int cy_total_devices;
423 #undef RxFifoThreshold
424 static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
428 struct isa_device *dev;
432 iobase = (cy_addr)dev->id_maddr;
434 /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
435 cy_inb(iobase, CY16_RESET, 0); /* XXX? */
436 DELAY(500); /* wait for the board to get its act together */
438 /* this is needed to get the board out of reset */
439 cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
442 return (cy_units(iobase, 0) == 0 ? 0 : -1);
446 cy_units(cy_iobase, cy_align)
451 u_char firmware_version;
455 for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
456 iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
458 /* wait for chip to become ready for new command */
459 for (i = 0; i < 10; i++) {
461 if (!cd_inb(iobase, CD1400_CCR, cy_align))
465 /* clear the GFRCR register */
466 cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
468 /* issue a reset command */
469 cd_outb(iobase, CD1400_CCR, cy_align,
470 CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
472 /* wait for the CD1400 to initialize itself */
473 for (i = 0; i < 200; i++) {
476 /* retrieve firmware version */
477 firmware_version = cd_inb(iobase, CD1400_GFRCR,
479 if ((firmware_version & 0xf0) == 0x40)
484 * Anything in the 0x40-0x4F range is fine.
485 * If one CD1400 is bad then we don't support higher
486 * numbered good ones on this board.
488 if ((firmware_version & 0xf0) != 0x40)
496 struct isa_device *isdp;
500 adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
506 * This kludge is to allow ISA/PCI device specifications in the
507 * kernel config file to be in any order.
509 if (isdp->id_unit != adapter) {
510 printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
511 isdp->id_unit = adapter; /* XXX */
513 isdp->id_ointr = siointr;
514 /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
519 cyattach_common(cy_iobase, cy_align)
525 u_char firmware_version;
530 adapter = cy_total_devices;
531 if ((u_int)adapter >= NCY) {
533 "cy%d: can't attach adapter: insufficient cy devices configured\n",
537 ncyu = cy_units(cy_iobase, cy_align);
540 cy_nr_cd1400s[adapter] = ncyu;
543 unit = adapter * CY_MAX_PORTS;
544 for (cyu = 0; cyu < ncyu; ++cyu) {
547 iobase = (cy_addr) (cy_iobase
548 + (cy_chip_offset[cyu] << cy_align));
549 firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
551 /* Set up a receive timeout period of than 1+ ms. */
552 cd_outb(iobase, CD1400_PPR, cy_align,
553 howmany(CY_CLOCK(firmware_version)
554 / CD1400_PPR_PRESCALER, 1000));
556 for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
560 com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT);
563 bzero(com, sizeof *com);
565 com->gfrcr_image = firmware_version;
566 if (CY_RTS_DTR_SWAPPED(firmware_version)) {
567 com->mcr_dtr = MCR_RTS;
568 com->mcr_rts = MCR_DTR;
569 com->mcr_rts_reg = CD1400_MSVR2;
571 com->mcr_dtr = MCR_DTR;
572 com->mcr_rts = MCR_RTS;
573 com->mcr_rts_reg = CD1400_MSVR1;
575 com->dtr_wait = 3 * hz;
576 com->obufs[0].l_head = com->obuf1;
577 com->obufs[1].l_head = com->obuf2;
579 com->cy_align = cy_align;
580 com->cy_iobase = cy_iobase;
581 com->iobase = iobase;
582 com->car = ~CD1400_CAR_CHAN;
585 * We don't use all the flags from <sys/ttydefaults.h> since they
586 * are only relevant for logins. It's important to have echo off
587 * initially so that the line doesn't start blathering before the
588 * echo flag can be turned off.
590 com->it_in.c_iflag = 0;
591 com->it_in.c_oflag = 0;
592 com->it_in.c_cflag = TTYDEF_CFLAG;
593 com->it_in.c_lflag = 0;
594 if (unit == comconsole) {
595 com->it_in.c_iflag = TTYDEF_IFLAG;
596 com->it_in.c_oflag = TTYDEF_OFLAG;
597 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
598 com->it_in.c_lflag = TTYDEF_LFLAG;
599 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
601 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
605 termioschars(&com->it_in);
606 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
607 com->it_out = com->it_in;
610 com_addr(unit) = com;
613 if (!sio_registered) {
614 cdevsw_add(&sio_cdevsw);
615 register_swi(SWI_TTY, siopoll);
616 sio_registered = TRUE;
618 make_dev(&sio_cdevsw, unit,
619 UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
620 unit % CY_MAX_PORTS);
621 make_dev(&sio_cdevsw, unit | CONTROL_INIT_STATE,
622 UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
623 unit % CY_MAX_PORTS);
624 make_dev(&sio_cdevsw, unit | CONTROL_LOCK_STATE,
625 UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
626 unit % CY_MAX_PORTS);
627 make_dev(&sio_cdevsw, unit | CALLOUT_MASK,
628 UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
629 unit % CY_MAX_PORTS);
630 make_dev(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_INIT_STATE,
631 UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
632 unit % CY_MAX_PORTS);
633 make_dev(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_LOCK_STATE,
634 UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
635 unit % CY_MAX_PORTS);
639 /* ensure an edge for the next interrupt */
640 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
646 sioopen(dev, flag, mode, p)
661 unit = MINOR_TO_UNIT(mynor);
662 if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
664 if (mynor & CONTROL_MASK)
667 tp = com->tp = sio_tty[unit] = ttymalloc(sio_tty[unit]);
669 tp = com->tp = &sio_tty[unit];
674 * We jump to this label after all non-interrupted sleeps to pick
675 * up any changes of the device state.
678 while (com->state & CS_DTR_OFF) {
679 error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
683 if (tp->t_state & TS_ISOPEN) {
685 * The device is open, so everything has been initialized.
688 if (mynor & CALLOUT_MASK) {
689 if (!com->active_out) {
694 if (com->active_out) {
695 if (flag & O_NONBLOCK) {
699 error = tsleep(&com->active_out,
700 TTIPRI | PCATCH, "cybi", 0);
706 if (tp->t_state & TS_XCLUDE &&
713 * The device isn't open, so there are no conflicts.
714 * Initialize it. Initialization is done twice in many
715 * cases: to preempt sleeping callin opens if we are
716 * callout, and to complete a callin open after DCD rises.
718 tp->t_oproc = comstart;
719 tp->t_stop = comstop;
720 tp->t_param = comparam;
722 tp->t_termios = mynor & CALLOUT_MASK
723 ? com->it_out : com->it_in;
725 /* Encode per-board unit in LIVR for access in intr routines. */
726 cd_setreg(com, CD1400_LIVR,
727 (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
729 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
731 com->poll = com->no_irq;
732 com->poll_output = com->loses_outints;
735 error = comparam(tp, &tp->t_termios);
742 * (Re)enable and flush fifos.
744 * Certain SMC chips cause problems if the fifos
745 * are enabled while input is ready. Turn off the
746 * fifo if necessary to clear the input. We test
747 * the input ready bit after enabling the fifos
748 * since we've already enabled them in comparam()
749 * and to handle races between enabling and fresh
753 outb(iobase + com_fifo,
754 FIFO_RCV_RST | FIFO_XMT_RST
757 if (!(inb(com->line_status_port) & LSR_RXRDY))
759 outb(iobase + com_fifo, 0);
761 (void) inb(com->data_port);
765 intrsave = save_intr();
768 (void) inb(com->line_status_port);
769 (void) inb(com->data_port);
770 com->prev_modem_status = com->last_modem_status
771 = inb(com->modem_status_port);
772 outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
775 restore_intr(intrsave);
778 * Flush fifos. This requires a full channel reset which
779 * also disables the transmitter and receiver. Recover
782 cd1400_channel_cmd(com,
783 CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
784 cd1400_channel_cmd(com, com->channel_control);
786 intrsave = save_intr();
789 com->prev_modem_status = com->last_modem_status
790 = cd_getreg(com, CD1400_MSVR2);
791 cd_setreg(com, CD1400_SRER,
793 = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
795 restore_intr(intrsave);
798 * Handle initial DCD. Callout devices get a fake initial
799 * DCD (trapdoor DCD). If we are callout, then any sleeping
800 * callin opens get woken up and resume sleeping on "cybi"
801 * instead of "cydcd".
804 * XXX `mynor & CALLOUT_MASK' should be
805 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
806 * TRAPDOOR_CARRIER is the default initial state for callout
807 * devices and SOFT_CARRIER is like CLOCAL except it hides
810 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
811 (*linesw[tp->t_line].l_modem)(tp, 1);
814 * Wait for DCD if necessary.
816 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
817 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
819 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
825 error = (*linesw[tp->t_line].l_open)(dev, tp);
826 disc_optim(tp, &tp->t_termios, com);
827 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
828 com->active_out = TRUE;
832 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
838 sioclose(dev, flag, mode, p)
850 if (mynor & CONTROL_MASK)
852 com = com_addr(MINOR_TO_UNIT(mynor));
855 cd_etc(com, CD1400_ETC_STOPBREAK);
856 (*linesw[tp->t_line].l_close)(tp, flag);
857 disc_optim(tp, &tp->t_termios, com);
858 comstop(tp, FREAD | FWRITE);
863 #ifdef broken /* session holds a ref to the tty; can't deallocate */
865 com->tp = sio_tty[unit] = NULL;
881 iobase = com->iobase;
885 com->poll_output = FALSE;
887 com->do_timestamp = 0;
889 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
892 intrsave = save_intr();
896 cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
898 restore_intr(intrsave);
899 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
904 outb(iobase + com_ier, 0);
906 intrsave = save_intr();
909 cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
911 restore_intr(intrsave);
914 if ((tp->t_cflag & HUPCL)
916 * XXX we will miss any carrier drop between here and the
917 * next open. Perhaps we should watch DCD even when the
918 * port is closed; it is not sufficient to check it at
919 * the next open because it might go up and down while
920 * we're not watching.
923 && !(com->prev_modem_status & MSR_DCD)
924 && !(com->it_in.c_cflag & CLOCAL))
925 || !(tp->t_state & TS_ISOPEN)) {
926 (void)commctl(com, TIOCM_DTR, DMBIC);
928 /* Disable receiver (leave transmitter enabled). */
929 com->channel_control = CD1400_CCR_CMDCHANCTL
932 cd1400_channel_cmd(com, com->channel_control);
934 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
935 timeout(siodtrwakeup, com, com->dtr_wait);
936 com->state |= CS_DTR_OFF;
943 * Disable fifos so that they are off after controlled
944 * reboots. Some BIOSes fail to detect 16550s when the
947 outb(iobase + com_fifo, 0);
950 com->active_out = FALSE;
951 wakeup(&com->active_out);
952 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
957 siowrite(dev, uio, flag)
967 if (mynor & CONTROL_MASK)
970 unit = MINOR_TO_UNIT(mynor);
971 tp = com_addr(unit)->tp;
973 * (XXX) We disallow virtual consoles if the physical console is
974 * a serial port. This is in case there is a display attached that
975 * is not the console. In that situation we don't need/want the X
976 * server taking over the console.
978 if (constty != NULL && unit == comconsole)
981 /* XXX duplicate ttwrite(), but without so much output processing on
982 * CR & LF chars. Hardly worth the effort, given that high-throughput
983 * sessions are raw anyhow.
986 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
996 com = (struct com_s *)chan;
997 com->state &= ~CS_DTR_OFF;
998 wakeup(&com->dtr_wait);
1003 * a) needs to be called with COM_LOCK() held, and
1004 * b) needs to return with COM_LOCK() held.
1019 if (!(tp->t_state & TS_ISOPEN)) {
1020 com_events -= (com->iptr - com->ibuf);
1021 com->iptr = com->ibuf;
1024 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1026 * Avoid the grotesquely inefficient lineswitch routine
1027 * (ttyinput) in "raw" mode. It usually takes about 450
1028 * instructions (that's without canonical processing or echo!).
1029 * slinput is reasonably fast (usually 40 instructions plus
1035 * This may look odd, but it is using save-and-enable
1036 * semantics instead of the save-and-disable semantics
1037 * that are used everywhere else.
1039 intrsave = save_intr();
1042 incc = com->iptr - buf;
1043 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1044 && (com->state & CS_RTS_IFLOW
1045 || tp->t_iflag & IXOFF)
1046 && !(tp->t_state & TS_TBLOCK))
1048 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1049 += b_to_q((char *)buf, incc, &tp->t_rawq);
1053 tp->t_rawcc += incc;
1055 if (tp->t_state & TS_TTSTOP
1056 && (tp->t_iflag & IXANY
1057 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1058 tp->t_state &= ~TS_TTSTOP;
1059 tp->t_lflag &= ~FLUSHO;
1062 restore_intr(intrsave);
1064 } while (buf < com->iptr);
1068 * This may look odd, but it is using save-and-enable
1069 * semantics instead of the save-and-disable semantics
1070 * that are used everywhere else.
1072 intrsave = save_intr();
1075 line_status = buf[com->ierroff];
1078 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1079 if (line_status & LSR_BI)
1080 recv_data |= TTY_BI;
1081 if (line_status & LSR_FE)
1082 recv_data |= TTY_FE;
1083 if (line_status & LSR_OE)
1084 recv_data |= TTY_OE;
1085 if (line_status & LSR_PE)
1086 recv_data |= TTY_PE;
1088 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1089 restore_intr(intrsave);
1091 } while (buf < com->iptr);
1093 com_events -= (com->iptr - com->ibuf);
1094 com->iptr = com->ibuf;
1097 * There is now room for another low-level buffer full of input,
1098 * so enable RTS if it is now disabled and there is room in the
1099 * high-level buffer.
1101 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
1102 !(tp->t_state & TS_TBLOCK))
1104 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1106 cd_setreg(com, com->mcr_rts_reg,
1107 com->mcr_image |= com->mcr_rts);
1122 COM_LOCK(); /* XXX could this be placed down lower in the loop? */
1124 baseu = unit * CY_MAX_PORTS;
1125 cy_align = com_addr(baseu)->cy_align;
1126 cy_iobase = com_addr(baseu)->cy_iobase;
1128 /* check each CD1400 in turn */
1129 for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
1130 iobase = (cy_addr) (cy_iobase
1131 + (cy_chip_offset[cyu] << cy_align));
1132 /* poll to see if it has any work */
1133 status = cd_inb(iobase, CD1400_SVRR, cy_align);
1139 /* service requests as appropriate, giving priority to RX */
1140 if (status & CD1400_SVRR_RXRDY) {
1152 save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
1154 /* enter rx service */
1155 cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
1156 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1157 = save_rir & CD1400_CAR_CHAN;
1159 serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
1160 com = com_addr(baseu
1161 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1162 & CD1400_xIVR_CHAN));
1164 /* ack receive service */
1165 serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
1167 com = com_addr(baseu +
1168 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1169 & CD1400_xIVR_CHAN));
1172 if (serv_type & CD1400_RIVR_EXCEPTION) {
1173 ++com->recv_exception;
1174 line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
1175 /* break/unnattached error bits or real input? */
1176 recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
1177 #ifndef SOFT_HOTCHAR
1178 if (line_status & CD1400_RDSR_SPECIAL
1179 && com->hotchar != 0)
1182 #if 1 /* XXX "intelligent" PFO error handling would break O error handling */
1183 if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
1185 Don't store PE if IGNPAR and BI if IGNBRK,
1186 this hack allows "raw" tty optimization
1187 works even if IGN* is set.
1189 if ( com->tp == NULL
1190 || !(com->tp->t_state & TS_ISOPEN)
1191 || ((line_status & (LSR_PE|LSR_FE))
1192 && (com->tp->t_iflag & IGNPAR))
1193 || ((line_status & LSR_BI)
1194 && (com->tp->t_iflag & IGNBRK)))
1196 if ( (line_status & (LSR_PE|LSR_FE))
1197 && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
1198 && ((line_status & LSR_FE)
1199 || ((line_status & LSR_PE)
1200 && (com->tp->t_iflag & INPCK))))
1206 if (com->hotchar != 0 && recv_data == com->hotchar)
1210 if (ioptr >= com->ibufend)
1211 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
1213 if (com->do_timestamp)
1214 microtime(&com->timestamp);
1216 ioptr[0] = recv_data;
1217 ioptr[com->ierroff] = line_status;
1218 com->iptr = ++ioptr;
1219 if (ioptr == com->ihighwater
1220 && com->state & CS_RTS_IFLOW)
1222 outb(com->modem_ctl_port,
1223 com->mcr_image &= ~MCR_RTS);
1225 cd_outb(iobase, com->mcr_rts_reg,
1230 if (line_status & LSR_OE)
1231 CE_RECORD(com, CE_OVERRUN);
1237 count = cd_inb(iobase, CD1400_RDCR, cy_align);
1240 com->bytes_in += count;
1242 ifree = com->ibufend - ioptr;
1243 if (count > ifree) {
1245 com_events += ifree;
1247 if (com->do_timestamp)
1248 microtime(&com->timestamp);
1250 recv_data = cd_inb(iobase,
1254 if (com->hotchar != 0
1259 ioptr[0] = recv_data;
1260 ioptr[com->ierroff] = 0;
1262 } while (--ifree != 0);
1264 com->delta_error_counts
1265 [CE_INTERRUPT_BUF_OVERFLOW] += count;
1267 recv_data = cd_inb(iobase, CD1400_RDSR,
1270 if (com->hotchar != 0
1271 && recv_data == com->hotchar)
1274 } while (--count != 0);
1276 if (com->do_timestamp)
1277 microtime(&com->timestamp);
1278 if (ioptr <= com->ihighwater
1279 && ioptr + count > com->ihighwater
1280 && com->state & CS_RTS_IFLOW)
1282 outb(com->modem_ctl_port,
1283 com->mcr_image &= ~MCR_RTS);
1285 cd_outb(iobase, com->mcr_rts_reg,
1290 com_events += count;
1292 recv_data = cd_inb(iobase, CD1400_RDSR,
1295 if (com->hotchar != 0
1296 && recv_data == com->hotchar)
1299 ioptr[0] = recv_data;
1300 ioptr[com->ierroff] = 0;
1302 } while (--count != 0);
1308 /* terminate service context */
1310 cd_outb(iobase, CD1400_RIR, cy_align,
1312 & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
1314 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1317 if (status & CD1400_SVRR_MDMCH) {
1319 u_char modem_status;
1327 save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
1329 /* enter modem service */
1330 cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
1331 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1332 = save_mir & CD1400_CAR_CHAN;
1334 com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
1335 + (save_mir & CD1400_MIR_CHAN));
1337 /* ack modem service */
1338 vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
1340 com = com_addr(baseu
1341 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1342 & CD1400_xIVR_CHAN));
1345 modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
1346 if (modem_status != com->last_modem_status) {
1347 if (com->do_dcd_timestamp
1348 && !(com->last_modem_status & MSR_DCD)
1349 && modem_status & MSR_DCD)
1350 microtime(&com->dcd_timestamp);
1353 * Schedule high level to handle DCD changes. Note
1354 * that we don't use the delta bits anywhere. Some
1355 * UARTs mess them up, and it's easy to remember the
1356 * previous bits and calculate the delta.
1358 com->last_modem_status = modem_status;
1359 if (!(com->state & CS_CHECKMSR)) {
1360 com_events += LOTS_OF_EVENTS;
1361 com->state |= CS_CHECKMSR;
1365 #ifdef SOFT_CTS_OFLOW
1366 /* handle CTS change immediately for crisp flow ctl */
1367 if (com->state & CS_CTS_OFLOW) {
1368 if (modem_status & MSR_CTS) {
1369 com->state |= CS_ODEVREADY;
1370 if (com->state >= (CS_BUSY | CS_TTGO
1372 && !(com->intr_enable
1373 & CD1400_SRER_TXRDY))
1374 cd_outb(iobase, CD1400_SRER,
1378 & ~CD1400_SRER_TXMPTY
1379 | CD1400_SRER_TXRDY);
1381 com->state &= ~CS_ODEVREADY;
1382 if (com->intr_enable
1383 & CD1400_SRER_TXRDY)
1384 cd_outb(iobase, CD1400_SRER,
1388 & ~CD1400_SRER_TXRDY
1389 | CD1400_SRER_TXMPTY);
1395 /* terminate service context */
1397 cd_outb(iobase, CD1400_MIR, cy_align,
1399 & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
1401 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1404 if (status & CD1400_SVRR_TXRDY) {
1413 save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
1415 /* enter tx service */
1416 cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
1417 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1418 = save_tir & CD1400_CAR_CHAN;
1420 com = com_addr(baseu
1421 + cyu * CD1400_NO_OF_CHANNELS
1422 + (save_tir & CD1400_TIR_CHAN));
1424 /* ack transmit service */
1425 vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
1427 com = com_addr(baseu
1428 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1429 & CD1400_xIVR_CHAN));
1432 if (com->etc != ETC_NONE) {
1433 if (com->intr_enable & CD1400_SRER_TXRDY) {
1435 * Here due to sloppy SRER_TXRDY
1436 * enabling. Ignore. Come back when
1439 cd_outb(iobase, CD1400_SRER, cy_align,
1442 & ~CD1400_SRER_TXRDY)
1443 | CD1400_SRER_TXMPTY);
1444 goto terminate_tx_service;
1447 case CD1400_ETC_SENDBREAK:
1448 case CD1400_ETC_STOPBREAK:
1450 * Start the command. Come back on
1451 * next tx empty interrupt, hopefully
1452 * after command has been executed.
1454 cd_outb(iobase, CD1400_COR2, cy_align,
1455 com->cor[1] |= CD1400_COR2_ETC);
1456 cd_outb(iobase, CD1400_TDR, cy_align,
1458 cd_outb(iobase, CD1400_TDR, cy_align,
1460 if (com->etc == CD1400_ETC_SENDBREAK)
1461 com->etc = ETC_BREAK_STARTING;
1463 com->etc = ETC_BREAK_ENDING;
1464 goto terminate_tx_service;
1465 case ETC_BREAK_STARTING:
1467 * BREAK is now on. Continue with
1468 * SRER_TXMPTY processing, hopefully
1471 com->etc = ETC_BREAK_STARTED;
1473 case ETC_BREAK_STARTED:
1475 * Came back due to sloppy SRER_TXMPTY
1476 * enabling. Hope again.
1479 case ETC_BREAK_ENDING:
1481 * BREAK is now off. Continue with
1482 * SRER_TXMPTY processing and don't
1483 * come back. The SWI handler will
1484 * restart tx interrupts if necessary.
1486 cd_outb(iobase, CD1400_COR2, cy_align,
1488 &= ~CD1400_COR2_ETC);
1489 com->etc = ETC_BREAK_ENDED;
1490 if (!(com->state & CS_ODONE)) {
1491 com_events += LOTS_OF_EVENTS;
1492 com->state |= CS_ODONE;
1496 case ETC_BREAK_ENDED:
1498 * Shouldn't get here. Hope again.
1503 if (com->intr_enable & CD1400_SRER_TXMPTY) {
1504 if (!(com->extra_state & CSE_ODONE)) {
1505 com_events += LOTS_OF_EVENTS;
1506 com->extra_state |= CSE_ODONE;
1509 cd_outb(iobase, CD1400_SRER, cy_align,
1511 &= ~CD1400_SRER_TXMPTY);
1512 goto terminate_tx_service;
1514 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
1518 ioptr = com->obufq.l_head;
1519 ocount = com->obufq.l_tail - ioptr;
1520 if (ocount > CD1400_TX_FIFO_SIZE)
1521 ocount = CD1400_TX_FIFO_SIZE;
1522 com->bytes_out += ocount;
1524 cd_outb(iobase, CD1400_TDR, cy_align,
1526 while (--ocount != 0);
1527 com->obufq.l_head = ioptr;
1528 if (ioptr >= com->obufq.l_tail) {
1531 qp = com->obufq.l_next;
1532 qp->l_queued = FALSE;
1535 com->obufq.l_head = qp->l_head;
1536 com->obufq.l_tail = qp->l_tail;
1537 com->obufq.l_next = qp;
1539 /* output just completed */
1540 com->state &= ~CS_BUSY;
1543 * The setting of CSE_ODONE may be
1544 * stale here. We currently only
1545 * use it when CS_BUSY is set, and
1546 * fixing it when we clear CS_BUSY
1549 if (com->extra_state & CSE_ODONE) {
1550 com_events -= LOTS_OF_EVENTS;
1551 com->extra_state &= ~CSE_ODONE;
1554 cd_outb(iobase, CD1400_SRER, cy_align,
1557 & ~CD1400_SRER_TXRDY)
1558 | CD1400_SRER_TXMPTY);
1560 if (!(com->state & CS_ODONE)) {
1561 com_events += LOTS_OF_EVENTS;
1562 com->state |= CS_ODONE;
1564 /* handle at high level ASAP */
1570 /* terminate service context */
1571 terminate_tx_service:
1573 cd_outb(iobase, CD1400_TIR, cy_align,
1575 & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
1577 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1582 /* ensure an edge for the next interrupt */
1583 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
1599 sioioctl(dev, cmd, data, flag, p)
1611 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1613 struct termios term;
1617 com = com_addr(MINOR_TO_UNIT(mynor));
1618 if (mynor & CONTROL_MASK) {
1621 switch (mynor & CONTROL_MASK) {
1622 case CONTROL_INIT_STATE:
1623 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
1625 case CONTROL_LOCK_STATE:
1626 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
1629 return (ENODEV); /* /dev/nodev */
1636 *ct = *(struct termios *)data;
1639 *(struct termios *)data = *ct;
1642 *(int *)data = TTYDISC;
1645 bzero(data, sizeof(struct winsize));
1652 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1653 term = tp->t_termios;
1655 error = ttsetcompat(tp, &cmd, data, &term);
1659 data = (caddr_t)&term;
1661 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1663 struct termios *dt = (struct termios *)data;
1664 struct termios *lt = mynor & CALLOUT_MASK
1665 ? &com->lt_out : &com->lt_in;
1667 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1668 | (dt->c_iflag & ~lt->c_iflag);
1669 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1670 | (dt->c_oflag & ~lt->c_oflag);
1671 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1672 | (dt->c_cflag & ~lt->c_cflag);
1673 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1674 | (dt->c_lflag & ~lt->c_lflag);
1675 for (cc = 0; cc < NCCS; ++cc)
1676 if (lt->c_cc[cc] != 0)
1677 dt->c_cc[cc] = tp->t_cc[cc];
1678 if (lt->c_ispeed != 0)
1679 dt->c_ispeed = tp->t_ispeed;
1680 if (lt->c_ospeed != 0)
1681 dt->c_ospeed = tp->t_ospeed;
1683 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1684 if (error != ENOIOCTL)
1687 error = ttioctl(tp, cmd, data, flag);
1688 disc_optim(tp, &tp->t_termios, com);
1689 if (error != ENOIOCTL) {
1696 outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
1698 cd_etc(com, CD1400_ETC_SENDBREAK);
1703 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1705 cd_etc(com, CD1400_ETC_STOPBREAK);
1709 (void)commctl(com, TIOCM_DTR, DMBIS);
1712 (void)commctl(com, TIOCM_DTR, DMBIC);
1715 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
1716 * changes get undone on the next call to comparam().
1719 (void)commctl(com, *(int *)data, DMSET);
1722 (void)commctl(com, *(int *)data, DMBIS);
1725 (void)commctl(com, *(int *)data, DMBIC);
1728 *(int *)data = commctl(com, 0, DMGET);
1731 /* must be root since the wait applies to following logins */
1737 com->dtr_wait = *(int *)data * hz / 100;
1740 *(int *)data = com->dtr_wait * 100 / hz;
1743 com->do_timestamp = TRUE;
1744 *(struct timeval *)data = com->timestamp;
1746 case TIOCDCDTIMESTAMP:
1747 com->do_dcd_timestamp = TRUE;
1748 *(struct timeval *)data = com->dcd_timestamp;
1767 if (com_events == 0)
1770 for (unit = 0; unit < NSIO; ++unit) {
1775 com = com_addr(unit);
1781 * XXX forget any events related to closed devices
1782 * (actually never opened devices) so that we don't
1785 intrsave = save_intr();
1788 incc = com->iptr - com->ibuf;
1789 com->iptr = com->ibuf;
1790 if (com->state & CS_CHECKMSR) {
1791 incc += LOTS_OF_EVENTS;
1792 com->state &= ~CS_CHECKMSR;
1796 restore_intr(intrsave);
1799 "sio%d: %d events for device with no tp\n",
1803 if (com->iptr != com->ibuf) {
1804 intrsave = save_intr();
1809 restore_intr(intrsave);
1811 if (com->state & CS_CHECKMSR) {
1812 u_char delta_modem_status;
1814 intrsave = save_intr();
1818 delta_modem_status = com->last_modem_status
1819 ^ com->prev_modem_status;
1820 com->prev_modem_status = com->last_modem_status;
1821 com_events -= LOTS_OF_EVENTS;
1822 com->state &= ~CS_CHECKMSR;
1824 restore_intr(intrsave);
1825 if (delta_modem_status & MSR_DCD)
1826 (*linesw[tp->t_line].l_modem)
1827 (tp, com->prev_modem_status & MSR_DCD);
1829 if (com->extra_state & CSE_ODONE) {
1830 intrsave = save_intr();
1833 com_events -= LOTS_OF_EVENTS;
1834 com->extra_state &= ~CSE_ODONE;
1836 restore_intr(intrsave);
1837 if (!(com->state & CS_BUSY)) {
1838 tp->t_state &= ~TS_BUSY;
1841 if (com->etc != ETC_NONE) {
1842 if (com->etc == ETC_BREAK_ENDED)
1843 com->etc = ETC_NONE;
1847 if (com->state & CS_ODONE) {
1848 intrsave = save_intr();
1851 com_events -= LOTS_OF_EVENTS;
1852 com->state &= ~CS_ODONE;
1854 restore_intr(intrsave);
1855 (*linesw[tp->t_line].l_start)(tp);
1857 if (com_events == 0)
1860 if (com_events >= LOTS_OF_EVENTS)
1885 /* do historical conversions */
1886 if (t->c_ispeed == 0)
1887 t->c_ispeed = t->c_ospeed;
1889 unit = DEV_TO_UNIT(tp->t_dev);
1890 com = com_addr(unit);
1892 /* check requested parameters */
1893 cy_clock = CY_CLOCK(com->gfrcr_image);
1894 idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
1897 odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
1901 /* parameters are OK, convert them to the com struct and the device */
1904 (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
1906 (void)commctl(com, TIOCM_DTR, DMBIS);
1908 (void) siosetwater(com, t->c_ispeed);
1910 /* XXX we don't actually change the speed atomically. */
1912 if (idivisor != 0) {
1913 cd_setreg(com, CD1400_RBPR, idivisor);
1914 cd_setreg(com, CD1400_RCOR, iprescaler);
1916 if (odivisor != 0) {
1917 cd_setreg(com, CD1400_TBPR, odivisor);
1918 cd_setreg(com, CD1400_TCOR, oprescaler);
1924 * transmitter enable (always set)
1927 opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN
1928 | (cflag & CREAD ? CD1400_CCR_RCVEN : CD1400_CCR_RCVDIS);
1929 if (opt != com->channel_control) {
1930 com->channel_control = opt;
1931 cd1400_channel_cmd(com, opt);
1935 /* set special chars */
1936 /* XXX if one is _POSIX_VDISABLE, can't use some others */
1937 if (t->c_cc[VSTOP] != _POSIX_VDISABLE)
1938 cd_setreg(com, CD1400_SCHR1, t->c_cc[VSTOP]);
1939 if (t->c_cc[VSTART] != _POSIX_VDISABLE)
1940 cd_setreg(com, CD1400_SCHR2, t->c_cc[VSTART]);
1941 if (t->c_cc[VINTR] != _POSIX_VDISABLE)
1942 cd_setreg(com, CD1400_SCHR3, t->c_cc[VINTR]);
1943 if (t->c_cc[VSUSP] != _POSIX_VDISABLE)
1944 cd_setreg(com, CD1400_SCHR4, t->c_cc[VSUSP]);
1948 * set channel option register 1 -
1955 if (cflag & PARENB) {
1957 opt |= CD1400_COR1_PARODD;
1958 opt |= CD1400_COR1_PARNORMAL;
1961 if (!(iflag & INPCK))
1962 opt |= CD1400_COR1_NOINPCK;
1965 if (cflag & CSTOPB) {
1967 opt |= CD1400_COR1_STOP2;
1970 switch (cflag & CSIZE) {
1973 opt |= CD1400_COR1_CS5;
1977 opt |= CD1400_COR1_CS6;
1981 opt |= CD1400_COR1_CS7;
1985 opt |= CD1400_COR1_CS8;
1989 if (opt != com->cor[0]) {
1990 cor_change |= CD1400_CCR_COR1;
1991 cd_setreg(com, CD1400_COR1, com->cor[0] = opt);
1995 * Set receive time-out period, normally to max(one char time, 5 ms).
1997 if (t->c_ispeed == 0)
1998 itimeout = cd_getreg(com, CD1400_RTPR);
2000 itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
2006 if (itimeout < MIN_RTP)
2009 if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
2010 && t->c_cc[VTIME] * 10 > itimeout)
2011 itimeout = t->c_cc[VTIME] * 10;
2014 cd_setreg(com, CD1400_RTPR, itimeout);
2017 * set channel option register 2 -
2023 opt |= CD1400_COR2_IXANY;
2025 opt |= CD1400_COR2_IXOFF;
2027 #ifndef SOFT_CTS_OFLOW
2028 if (cflag & CCTS_OFLOW)
2029 opt |= CD1400_COR2_CCTS_OFLOW;
2031 intrsave = save_intr();
2034 if (opt != com->cor[1]) {
2035 cor_change |= CD1400_CCR_COR2;
2036 cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
2039 restore_intr(intrsave);
2042 * set channel option register 3 -
2043 * receiver FIFO interrupt threshold
2046 opt = RxFifoThreshold;
2048 if (t->c_lflag & ICANON)
2049 opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
2051 /* detect and transparently handle START and STOP chars */
2052 opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
2054 if (opt != com->cor[2]) {
2055 cor_change |= CD1400_CCR_COR3;
2056 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2059 /* notify the CD1400 if COR1-3 have changed */
2061 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
2064 * set channel option register 4 -
2067 * received exception processing
2071 opt |= CD1400_COR4_IGNCR;
2074 * we need a new ttyinput() for this, as we don't want to
2075 * have ICRNL && INLCR being done in both layers, or to have
2076 * synchronisation problems
2079 opt |= CD1400_COR4_ICRNL;
2081 opt |= CD1400_COR4_INLCR;
2084 opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
2086 * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
2087 * so only tell the hardware about -brkint if -parmrk.
2089 if (!(iflag & (BRKINT | PARMRK)))
2090 opt |= CD1400_COR4_NOBRKINT;
2092 /* XXX using this "intelligence" breaks reporting of overruns. */
2094 opt |= CD1400_COR4_PFO_DISCARD;
2097 opt |= CD1400_COR4_PFO_ESC;
2099 opt |= CD1400_COR4_PFO_NUL;
2102 opt |= CD1400_COR4_PFO_EXCEPTION;
2104 cd_setreg(com, CD1400_COR4, opt);
2107 * set channel option register 5 -
2111 opt |= CD1400_COR5_ISTRIP;
2112 if (t->c_iflag & IEXTEN)
2113 /* enable LNEXT (e.g. ctrl-v quoting) handling */
2114 opt |= CD1400_COR5_LNEXT;
2116 if (t->c_oflag & ONLCR)
2117 opt |= CD1400_COR5_ONLCR;
2118 if (t->c_oflag & OCRNL)
2119 opt |= CD1400_COR5_OCRNL;
2121 cd_setreg(com, CD1400_COR5, opt);
2124 * We always generate modem status change interrupts for CD changes.
2125 * Among other things, this is necessary to track TS_CARR_ON for
2126 * pstat to print even when the driver doesn't care. CD changes
2127 * should be rare so interrupts for them are not worth extra code to
2128 * avoid. We avoid interrupts for other modem status changes (except
2129 * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
2130 * simplest and best.
2134 * set modem change option register 1
2135 * generate modem interrupts on which 1 -> 0 input transitions
2136 * also controls auto-DTR output flow-control, which we don't use
2138 opt = CD1400_MCOR1_CDzd;
2139 #ifdef SOFT_CTS_OFLOW
2140 if (cflag & CCTS_OFLOW)
2141 opt |= CD1400_MCOR1_CTSzd;
2143 cd_setreg(com, CD1400_MCOR1, opt);
2146 * set modem change option register 2
2147 * generate modem interrupts on specific 0 -> 1 input transitions
2149 opt = CD1400_MCOR2_CDod;
2150 #ifdef SOFT_CTS_OFLOW
2151 if (cflag & CCTS_OFLOW)
2152 opt |= CD1400_MCOR2_CTSod;
2154 cd_setreg(com, CD1400_MCOR2, opt);
2157 * XXX should have done this long ago, but there is too much state
2158 * to change all atomically.
2160 intrsave = save_intr();
2164 com->state &= ~CS_TTGO;
2165 if (!(tp->t_state & TS_TTSTOP))
2166 com->state |= CS_TTGO;
2167 if (cflag & CRTS_IFLOW) {
2168 com->state |= CS_RTS_IFLOW;
2170 * If CS_RTS_IFLOW just changed from off to on, the change
2171 * needs to be propagated to MCR_RTS. This isn't urgent,
2172 * so do it later by calling comstart() instead of repeating
2173 * a lot of code from comstart() here.
2175 } else if (com->state & CS_RTS_IFLOW) {
2176 com->state &= ~CS_RTS_IFLOW;
2178 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2179 * on here, since comstart() won't do it later.
2182 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2184 cd_setreg(com, com->mcr_rts_reg,
2185 com->mcr_image |= com->mcr_rts);
2190 * Set up state to handle output flow control.
2191 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2192 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2194 com->state |= CS_ODEVREADY;
2195 #ifdef SOFT_CTS_OFLOW
2196 com->state &= ~CS_CTS_OFLOW;
2197 if (cflag & CCTS_OFLOW) {
2198 com->state |= CS_CTS_OFLOW;
2199 if (!(com->last_modem_status & MSR_CTS))
2200 com->state &= ~CS_ODEVREADY;
2203 /* XXX shouldn't call functions while intrs are disabled. */
2204 disc_optim(tp, t, com);
2207 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2208 * unconditionally, but that defeated the careful discarding of
2209 * stale input in sioopen().
2211 if (com->state >= (CS_BUSY | CS_TTGO))
2214 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2215 if (!(com->intr_enable & CD1400_SRER_TXRDY))
2216 cd_setreg(com, CD1400_SRER,
2218 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2219 | CD1400_SRER_TXRDY);
2221 if (com->intr_enable & CD1400_SRER_TXRDY)
2222 cd_setreg(com, CD1400_SRER,
2224 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2225 | CD1400_SRER_TXMPTY);
2229 restore_intr(intrsave);
2232 if (com->ibufold != NULL) {
2233 free(com->ibufold, M_DEVBUF);
2234 com->ibufold = NULL;
2240 siosetwater(com, speed)
2251 * Make the buffer size large enough to handle a softtty interrupt
2252 * latency of about 2 ticks without loss of throughput or data
2253 * (about 3 ticks if input flow control is not used or not honoured,
2254 * but a bit less for CS5-CS7 modes).
2256 cp4ticks = speed / 10 / hz * 4;
2257 for (ibufsize = 128; ibufsize < cp4ticks;)
2259 if (ibufsize == com->ibufsize) {
2264 * Allocate input buffer. The extra factor of 2 in the size is
2265 * to allow for an error byte for each input byte.
2267 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2272 /* Initialize non-critical variables. */
2273 com->ibufold = com->ibuf;
2274 com->ibufsize = ibufsize;
2277 tp->t_ififosize = 2 * ibufsize;
2278 tp->t_ispeedwat = (speed_t)-1;
2279 tp->t_ospeedwat = (speed_t)-1;
2283 * Read current input buffer, if any. Continue with interrupts
2286 intrsave = save_intr();
2289 if (com->iptr != com->ibuf)
2293 * Initialize critical variables, including input buffer watermarks.
2294 * The external device is asked to stop sending when the buffer
2295 * exactly reaches high water, or when the high level requests it.
2296 * The high level is notified immediately (rather than at a later
2297 * clock tick) when this watermark is reached.
2298 * The buffer size is chosen so the watermark should almost never
2300 * The low watermark is invisibly 0 since the buffer is always
2301 * emptied all at once.
2303 com->iptr = com->ibuf = ibuf;
2304 com->ibufend = ibuf + ibufsize;
2305 com->ierroff = ibufsize;
2306 com->ihighwater = ibuf + 3 * ibufsize / 4;
2309 restore_intr(intrsave);
2325 unit = DEV_TO_UNIT(tp->t_dev);
2326 com = com_addr(unit);
2334 intrsave = save_intr();
2337 if (tp->t_state & TS_TTSTOP) {
2338 com->state &= ~CS_TTGO;
2339 if (com->intr_enable & CD1400_SRER_TXRDY)
2340 cd_setreg(com, CD1400_SRER,
2342 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2343 | CD1400_SRER_TXMPTY);
2345 com->state |= CS_TTGO;
2346 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
2347 && !(com->intr_enable & CD1400_SRER_TXRDY))
2348 cd_setreg(com, CD1400_SRER,
2350 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2351 | CD1400_SRER_TXRDY);
2353 if (tp->t_state & TS_TBLOCK) {
2354 if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
2356 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2358 cd_setreg(com, com->mcr_rts_reg,
2359 com->mcr_image &= ~com->mcr_rts);
2362 if (!(com->mcr_image & com->mcr_rts)
2363 && com->iptr < com->ihighwater
2364 && com->state & CS_RTS_IFLOW)
2366 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2368 cd_setreg(com, com->mcr_rts_reg,
2369 com->mcr_image |= com->mcr_rts);
2373 restore_intr(intrsave);
2374 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2379 if (tp->t_outq.c_cc != 0) {
2383 if (!com->obufs[0].l_queued) {
2387 com->obufs[0].l_tail
2388 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2390 com->obufs[0].l_next = NULL;
2391 com->obufs[0].l_queued = TRUE;
2392 intrsave = save_intr();
2395 if (com->state & CS_BUSY) {
2396 qp = com->obufq.l_next;
2397 while ((next = qp->l_next) != NULL)
2399 qp->l_next = &com->obufs[0];
2401 com->obufq.l_head = com->obufs[0].l_head;
2402 com->obufq.l_tail = com->obufs[0].l_tail;
2403 com->obufq.l_next = &com->obufs[0];
2404 com->state |= CS_BUSY;
2405 if (com->state >= (CS_BUSY | CS_TTGO
2407 cd_setreg(com, CD1400_SRER,
2410 & ~CD1400_SRER_TXMPTY)
2411 | CD1400_SRER_TXRDY);
2414 restore_intr(intrsave);
2416 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2420 com->obufs[1].l_tail
2421 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2423 com->obufs[1].l_next = NULL;
2424 com->obufs[1].l_queued = TRUE;
2425 intrsave = save_intr();
2428 if (com->state & CS_BUSY) {
2429 qp = com->obufq.l_next;
2430 while ((next = qp->l_next) != NULL)
2432 qp->l_next = &com->obufs[1];
2434 com->obufq.l_head = com->obufs[1].l_head;
2435 com->obufq.l_tail = com->obufs[1].l_tail;
2436 com->obufq.l_next = &com->obufs[1];
2437 com->state |= CS_BUSY;
2438 if (com->state >= (CS_BUSY | CS_TTGO
2440 cd_setreg(com, CD1400_SRER,
2443 & ~CD1400_SRER_TXMPTY)
2444 | CD1400_SRER_TXRDY);
2447 restore_intr(intrsave);
2449 tp->t_state |= TS_BUSY;
2456 intrsave = save_intr();
2459 if (com->state >= (CS_BUSY | CS_TTGO))
2460 siointr1(com); /* fake interrupt to start output */
2462 restore_intr(intrsave);
2477 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2479 intrsave = save_intr();
2483 com->obufs[0].l_queued = FALSE;
2484 com->obufs[1].l_queued = FALSE;
2485 if (com->extra_state & CSE_ODONE) {
2486 com_events -= LOTS_OF_EVENTS;
2487 com->extra_state &= ~CSE_ODONE;
2488 if (com->etc != ETC_NONE) {
2489 if (com->etc == ETC_BREAK_ENDED)
2490 com->etc = ETC_NONE;
2494 com->tp->t_state &= ~TS_BUSY;
2495 if (com->state & CS_ODONE)
2496 com_events -= LOTS_OF_EVENTS;
2497 com->state &= ~(CS_ODONE | CS_BUSY);
2500 /* XXX no way to reset only input fifo. */
2501 com_events -= (com->iptr - com->ibuf);
2502 com->iptr = com->ibuf;
2505 restore_intr(intrsave);
2508 if (rw & FWRITE && com->etc == ETC_NONE)
2509 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
2514 commctl(com, bits, how)
2524 if (com->channel_control & CD1400_CCR_RCVEN)
2526 mcr = com->mcr_image;
2527 if (mcr & com->mcr_dtr)
2529 if (mcr & com->mcr_rts)
2530 /* XXX wired on for Cyclom-8Ys */
2534 * We must read the modem status from the hardware because
2535 * we don't generate modem status change interrupts for all
2536 * changes, so com->prev_modem_status is not guaranteed to
2537 * be up to date. This is safe, unlike for sio, because
2538 * reading the status register doesn't clear pending modem
2539 * status change interrupts.
2541 msr = cd_getreg(com, CD1400_MSVR2);
2550 /* XXX not connected except for Cyclom-16Y? */
2555 if (bits & TIOCM_DTR)
2556 mcr |= com->mcr_dtr;
2557 if (bits & TIOCM_RTS)
2558 mcr |= com->mcr_rts;
2559 intrsave = save_intr();
2564 com->mcr_image = mcr;
2565 cd_setreg(com, CD1400_MSVR1, mcr);
2566 cd_setreg(com, CD1400_MSVR2, mcr);
2569 com->mcr_image = mcr = com->mcr_image | mcr;
2570 cd_setreg(com, CD1400_MSVR1, mcr);
2571 cd_setreg(com, CD1400_MSVR2, mcr);
2574 com->mcr_image = mcr = com->mcr_image & ~mcr;
2575 cd_setreg(com, CD1400_MSVR1, mcr);
2576 cd_setreg(com, CD1400_MSVR2, mcr);
2580 restore_intr(intrsave);
2592 * Set our timeout period to 1 second if no polled devices are open.
2593 * Otherwise set it to max(1/200, 1/hz).
2594 * Enable timeouts iff some device is open.
2596 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2599 for (unit = 0; unit < NSIO; ++unit) {
2600 com = com_addr(unit);
2601 if (com != NULL && com->tp != NULL
2602 && com->tp->t_state & TS_ISOPEN) {
2605 if (com->poll || com->poll_output) {
2606 sio_timeout = hz > 200 ? hz / 200 : 1;
2613 sio_timeouts_until_log = hz / sio_timeout;
2614 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2617 /* Flush error messages, if any. */
2618 sio_timeouts_until_log = 1;
2619 comwakeup((void *)NULL);
2620 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2631 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2635 * Recover from lost output interrupts.
2636 * Poll any lines that don't use interrupts.
2638 for (unit = 0; unit < NSIO; ++unit) {
2639 com = com_addr(unit);
2641 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2644 intrsave = save_intr();
2649 restore_intr(intrsave);
2655 * Check for and log errors, but not too often.
2657 if (--sio_timeouts_until_log > 0)
2659 sio_timeouts_until_log = hz / sio_timeout;
2660 for (unit = 0; unit < NSIO; ++unit) {
2663 com = com_addr(unit);
2666 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2671 intrsave = save_intr();
2674 delta = com->delta_error_counts[errnum];
2675 com->delta_error_counts[errnum] = 0;
2677 restore_intr(intrsave);
2680 total = com->error_counts[errnum] += delta;
2681 log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
2682 unit, delta, error_desc[errnum],
2683 delta == 1 ? "" : "s", total);
2689 disc_optim(tp, t, com)
2694 #ifndef SOFT_HOTCHAR
2699 * XXX can skip a lot more cases if Smarts. Maybe
2700 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2701 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2703 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2704 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2705 && (!(t->c_iflag & PARMRK)
2706 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2707 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2708 && linesw[tp->t_line].l_rint == ttyinput)
2709 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2711 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2712 com->hotchar = linesw[tp->t_line].l_hotchar;
2713 #ifndef SOFT_HOTCHAR
2714 opt = com->cor[2] & ~CD1400_COR3_SCD34;
2715 if (com->hotchar != 0) {
2716 cd_setreg(com, CD1400_SCHR3, com->hotchar);
2717 cd_setreg(com, CD1400_SCHR4, com->hotchar);
2718 opt |= CD1400_COR3_SCD34;
2720 if (opt != com->cor[2]) {
2721 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2722 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
2728 /* standard line discipline input routine */
2734 /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
2735 * bits, as they are done by the CD1400. Hardly worth the effort,
2736 * given that high-throughput sessions are raw anyhow.
2742 comspeed(speed, cy_clock, prescaler_io)
2755 if (speed < 0 || speed > 150000)
2758 /* determine which prescaler to use */
2759 for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
2760 prescaler_unit--, prescaler >>= 2) {
2761 if (cy_clock / prescaler / speed > 63)
2765 divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
2768 actual = cy_clock/prescaler/divider;
2770 /* 10 times error in percent: */
2771 error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
2773 /* 3.0% max error tolerance */
2774 if (error < -30 || error > 30)
2778 printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
2779 printf("divider = %d (%x)\n", divider, divider);
2780 printf("actual = %d\n", actual);
2781 printf("error = %d\n", error);
2784 *prescaler_io = prescaler_unit;
2789 cd1400_channel_cmd(com, cmd)
2793 cd1400_channel_cmd_wait(com);
2794 cd_setreg(com, CD1400_CCR, cmd);
2795 cd1400_channel_cmd_wait(com);
2799 cd1400_channel_cmd_wait(com)
2802 struct timeval start;
2806 if (cd_getreg(com, CD1400_CCR) == 0)
2810 if (cd_getreg(com, CD1400_CCR) == 0)
2813 usec = 1000000 * (tv.tv_sec - start.tv_sec) +
2814 tv.tv_usec - start.tv_usec;
2817 "cy%d: channel command timeout (%ld usec)\n",
2832 * We can't change the hardware's ETC state while there are any
2833 * characters in the tx fifo, since those characters would be
2834 * interpreted as commands! Unputting characters from the fifo
2835 * is difficult, so we wait up to 12 character times for the fifo
2836 * to drain. The command will be delayed for up to 2 character
2837 * times for the tx to become empty. Unputting characters from
2838 * the tx holding and shift registers is impossible, so we wait
2839 * for the tx to become empty so that the command is sure to be
2840 * executed soon after we issue it.
2842 intrsave = save_intr();
2845 if (com->etc == etc)
2847 if ((etc == CD1400_ETC_SENDBREAK
2848 && (com->etc == ETC_BREAK_STARTING
2849 || com->etc == ETC_BREAK_STARTED))
2850 || (etc == CD1400_ETC_STOPBREAK
2851 && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
2852 || com->etc == ETC_NONE))) {
2854 restore_intr(intrsave);
2858 cd_setreg(com, CD1400_SRER,
2860 = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
2863 restore_intr(intrsave);
2864 while (com->etc == etc
2865 && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
2874 struct com_s *basecom;
2881 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2882 car = com->unit & CD1400_CAR_CHAN;
2883 cy_align = com->cy_align;
2884 iobase = com->iobase;
2885 intrsave = save_intr();
2887 if (intrsave & PSL_I)
2889 if (basecom->car != car)
2890 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2891 val = cd_inb(iobase, reg, cy_align);
2892 if (intrsave & PSL_I)
2894 restore_intr(intrsave);
2899 cd_setreg(com, reg, val)
2904 struct com_s *basecom;
2910 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2911 car = com->unit & CD1400_CAR_CHAN;
2912 cy_align = com->cy_align;
2913 iobase = com->iobase;
2914 intrsave = save_intr();
2916 if (intrsave & PSL_I)
2918 if (basecom->car != car)
2919 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2920 cd_outb(iobase, reg, cy_align, val);
2921 if (intrsave & PSL_I)
2923 restore_intr(intrsave);
2937 com = com_addr(unit);
2938 printf("info for channel %d\n", unit);
2939 printf("------------------\n");
2940 printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
2941 printf("calls to upper layer:\t\t%d\n", cy_timeouts);
2944 iobase = com->iobase;
2946 printf("cd1400 base address:\\tt%p\n", iobase);
2947 printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
2948 printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
2949 com->cor[0], com->cor[1], com->cor[2]);
2950 printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
2951 cd_getreg(com, CD1400_SRER), com->intr_enable);
2952 printf("service request register:\t0x%02x\n",
2953 cd_inb(iobase, CD1400_SVRR, com->cy_align));
2954 printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
2955 cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
2956 printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
2957 cd_inb(iobase, CD1400_RIR, com->cy_align),
2958 cd_inb(iobase, CD1400_TIR, com->cy_align),
2959 cd_inb(iobase, CD1400_MIR, com->cy_align));
2961 printf("com state:\t\t\t0x%02x\n", com->state);
2962 printf("calls to comstart():\t\t%d (%d useful)\n",
2963 com->start_count, com->start_real);
2964 printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
2966 if (com->obufs[0].l_queued)
2967 ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
2968 if (com->obufs[1].l_queued)
2969 ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
2970 printf("tx buffer chars:\t\t%u\n", ocount);
2971 printf("received chars:\t\t\t%d\n", com->bytes_in);
2972 printf("received exceptions:\t\t%d\n", com->recv_exception);
2973 printf("modem signal deltas:\t\t%d\n", com->mdm);
2974 printf("transmitted chars:\t\t%d\n", com->bytes_out);
2978 printf("tty state:\t\t\t0x%08x\n", tp->t_state);
2980 "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
2981 tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
2983 printf("tty state:\t\t\tclosed\n");
2985 #endif /* CyDebug */