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>
74 #include <sys/dkstat.h>
75 #include <sys/fcntl.h>
77 #include <sys/interrupt.h>
79 #include <sys/kernel.h>
80 #include <sys/malloc.h>
81 #include <sys/mutex.h>
82 #include <sys/syslog.h>
83 #include <machine/psl.h>
85 #include <i386/isa/isa_device.h>
86 #include <i386/isa/cyreg.h>
87 #include <i386/isa/ic/cd1400.h>
90 #error "The cy device requires the old isa compatibility shims"
95 #include <machine/smptests.h> /** xxx_LOCK */
98 #define COM_LOCK() mtx_lock_spin(&com_mtx)
99 #define COM_UNLOCK() mtx_unlock_spin(&com_mtx)
103 #endif /* USE_COMLOCK */
112 extern struct mtx com_mtx;
115 * Dictionary so that I can name everything *sio* or *com* to compare with
116 * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
117 * simplify the comparision. These will go away.
119 #define LSR_BI CD1400_RDSR_BREAK
120 #define LSR_FE CD1400_RDSR_FE
121 #define LSR_OE CD1400_RDSR_OE
122 #define LSR_PE CD1400_RDSR_PE
123 #define MCR_DTR CD1400_MSVR2_DTR
124 #define MCR_RTS CD1400_MSVR1_RTS
125 #define MSR_CTS CD1400_MSVR2_CTS
126 #define MSR_DCD CD1400_MSVR2_CD
127 #define MSR_DSR CD1400_MSVR2_DSR
128 #define MSR_RI CD1400_MSVR2_RI
129 #define NSIO (NCY * CY_MAX_PORTS)
130 #define comconsole cyconsole
131 #define comdefaultrate cydefaultrate
132 #define com_events cy_events
133 #define comhardclose cyhardclose
134 #define commctl cymctl
135 #define comparam cyparam
136 #define comspeed cyspeed
137 #define comstart cystart
138 #define comwakeup cywakeup
139 #define nsio_tty ncy_tty
140 #define p_com_addr p_cy_addr
141 #define sioattach cyattach
142 #define sioclose cyclose
143 #define siodriver cydriver
144 #define siodtrwakeup cydtrwakeup
145 #define sioinput cyinput
146 #define siointr cyintr
147 #define siointr1 cyintr1
148 #define sioioctl cyioctl
149 #define sioopen cyopen
150 #define siopoll cypoll
151 #define sioprobe cyprobe
152 #define siosettimeout cysettimeout
153 #define siosetwater cysetwater
154 #define comstop cystop
155 #define siowrite cywrite
157 #define sio_irec cy_irec
158 #define sio_timeout cy_timeout
159 #define sio_timeout_handle cy_timeout_handle
160 #define sio_timeouts_until_log cy_timeouts_until_log
161 #define sio_tty cy_tty
163 #define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
165 /* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
166 #define CD1400_xIVR_CHAN_SHIFT 3
167 #define CD1400_xIVR_CHAN 0x1F
170 * ETC states. com->etc may also contain a hardware ETC command value,
171 * meaning that execution of that command is pending.
173 #define ETC_NONE 0 /* we depend on bzero() setting this */
174 #define ETC_BREAK_STARTING 1
175 #define ETC_BREAK_STARTED 2
176 #define ETC_BREAK_ENDING 3
177 #define ETC_BREAK_ENDED 4
179 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
181 #define CALLOUT_MASK 0x80
182 #define CONTROL_MASK 0x60
183 #define CONTROL_INIT_STATE 0x20
184 #define CONTROL_LOCK_STATE 0x40
185 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
186 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
187 #define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
188 | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
192 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
193 * than the other bits so that they can be tested as a group without masking
196 * The following com and tty flags correspond closely:
197 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
199 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
200 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
201 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
202 * TS_FLUSH is not used.
203 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
204 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
206 #define CS_BUSY 0x80 /* output in progress */
207 #define CS_TTGO 0x40 /* output not stopped by XOFF */
208 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
209 #define CS_CHECKMSR 1 /* check of MSR scheduled */
210 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
211 #define CS_DTR_OFF 0x10 /* DTR held off */
212 #define CS_ODONE 4 /* output completed */
213 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
214 #define CSE_ODONE 1 /* output transmitted */
216 static char const * const error_desc[] = {
219 #define CE_INTERRUPT_BUF_OVERFLOW 1
220 "interrupt-level buffer overflow",
221 #define CE_TTY_BUF_OVERFLOW 2
222 "tty-level buffer overflow",
226 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
228 /* types. XXX - should be elsewhere */
229 typedef u_char bool_t; /* boolean */
230 typedef u_char volatile *cy_addr;
232 /* queue of linear buffers */
234 u_char *l_head; /* next char to process */
235 u_char *l_tail; /* one past the last char to process */
236 struct lbq *l_next; /* next in queue */
237 bool_t l_queued; /* nonzero if queued */
240 /* com device structure */
242 u_char state; /* miscellaneous flag bits */
243 bool_t active_out; /* nonzero if the callout device is open */
245 u_char cfcr_image; /* copy of value written to CFCR */
247 u_char etc; /* pending Embedded Transmit Command */
248 u_char extra_state; /* more flag bits, separate for order trick */
250 u_char fifo_image; /* copy of value written to FIFO */
252 u_char gfrcr_image; /* copy of value read from GFRCR */
254 bool_t hasfifo; /* nonzero for 16550 UARTs */
255 bool_t loses_outints; /* nonzero if device loses output interrupts */
257 u_char mcr_dtr; /* MCR bit that is wired to DTR */
258 u_char mcr_image; /* copy of value written to MCR */
259 u_char mcr_rts; /* MCR bit that is wired to RTS */
262 bool_t multiport; /* is this unit part of a multiport device? */
263 #endif /* COM_MULTIPORT */
264 bool_t no_irq; /* nonzero if irq is not attached */
265 bool_t poll; /* nonzero if polling is required */
266 bool_t poll_output; /* nonzero if polling for output is required */
268 int unit; /* unit number */
269 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
273 u_int wopeners; /* # processes waiting for DCD in open() */
276 * The high level of the driver never reads status registers directly
277 * because there would be too many side effects to handle conveniently.
278 * Instead, it reads copies of the registers stored here by the
281 u_char last_modem_status; /* last MSR read by intr handler */
282 u_char prev_modem_status; /* last MSR handled by high level */
284 u_char hotchar; /* ldisc-specific char to be handled ASAP */
285 u_char *ibuf; /* start of input buffer */
286 u_char *ibufend; /* end of input buffer */
287 u_char *ibufold; /* old input buffer, to be freed */
288 u_char *ihighwater; /* threshold in input buffer */
289 u_char *iptr; /* next free spot in input buffer */
290 int ibufsize; /* size of ibuf (not include error bytes) */
291 int ierroff; /* offset of error bytes in ibuf */
293 struct lbq obufq; /* head of queue of output buffers */
294 struct lbq obufs[2]; /* output buffers */
296 int cy_align; /* index for register alignment */
297 cy_addr cy_iobase; /* base address of this port's cyclom */
298 cy_addr iobase; /* base address of this port's cd1400 */
299 int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
301 struct tty *tp; /* cross reference */
304 struct termios it_in; /* should be in struct tty */
305 struct termios it_out;
308 struct termios lt_in; /* should be in struct tty */
309 struct termios lt_out;
312 bool_t do_dcd_timestamp;
313 struct timeval timestamp;
314 struct timeval dcd_timestamp;
316 u_long bytes_in; /* statistics */
318 u_int delta_error_counts[CE_NTYPES];
319 u_long error_counts[CE_NTYPES];
321 u_int recv_exception; /* exception chars received */
322 u_int mdm; /* modem signal changes */
324 u_int start_count; /* no. of calls to comstart() */
325 u_int start_real; /* no. of calls that did something */
327 u_char car; /* CD1400 CAR shadow (if first unit in cd) */
328 u_char channel_control;/* CD1400 CCR control command shadow */
329 u_char cor[3]; /* CD1400 COR1-3 shadows */
330 u_char intr_enable; /* CD1400 SRER shadow */
333 * Data area for output buffers. Someday we should build the output
334 * buffer queue without copying data.
340 /* PCI driver entry point. */
341 int cyattach_common __P((cy_addr cy_iobase, int cy_align));
344 static int cy_units __P((cy_addr cy_iobase, int cy_align));
345 static int sioattach __P((struct isa_device *dev));
346 static void cd1400_channel_cmd __P((struct com_s *com, int cmd));
347 static void cd1400_channel_cmd_wait __P((struct com_s *com));
348 static void cd_etc __P((struct com_s *com, int etc));
349 static int cd_getreg __P((struct com_s *com, int reg));
350 static void cd_setreg __P((struct com_s *com, int reg, int val));
351 static timeout_t siodtrwakeup;
352 static void comhardclose __P((struct com_s *com));
353 static void sioinput __P((struct com_s *com));
355 static void siointr1 __P((struct com_s *com));
357 static int commctl __P((struct com_s *com, int bits, int how));
358 static int comparam __P((struct tty *tp, struct termios *t));
359 static void siopoll __P((void *arg));
360 static int sioprobe __P((struct isa_device *dev));
361 static void siosettimeout __P((void));
362 static int siosetwater __P((struct com_s *com, speed_t speed));
363 static int comspeed __P((speed_t speed, u_long cy_clock,
365 static void comstart __P((struct tty *tp));
366 static void comstop __P((struct tty *tp, int rw));
367 static timeout_t comwakeup;
368 static void disc_optim __P((struct tty *tp, struct termios *t,
372 void cystatus __P((int unit));
375 static char driver_name[] = "cy";
377 /* table and macro for fast conversion from a unit number to its com struct */
378 static struct com_s *p_com_addr[NSIO];
379 #define com_addr(unit) (p_com_addr[unit])
381 struct isa_driver siodriver = {
382 INTR_TYPE_TTY | INTR_FAST,
387 COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
389 static d_open_t sioopen;
390 static d_close_t sioclose;
391 static d_write_t siowrite;
392 static d_ioctl_t sioioctl;
394 #define CDEV_MAJOR 48
395 static struct cdevsw sio_cdevsw = {
397 /* close */ sioclose,
399 /* write */ siowrite,
400 /* ioctl */ sioioctl,
403 /* strategy */ nostrategy,
404 /* name */ driver_name,
405 /* maj */ CDEV_MAJOR,
408 /* flags */ D_TTY | D_KQFILTER,
410 /* kqfilter */ ttykqfilter,
413 static int comconsole = -1;
414 static speed_t comdefaultrate = TTYDEF_SPEED;
415 static u_int com_events; /* input chars + weighted output completions */
417 static int sio_timeout;
418 static int sio_timeouts_until_log;
419 static struct callout_handle sio_timeout_handle
420 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
422 static struct tty *sio_tty[NSIO];
424 static struct tty sio_tty[NSIO];
426 static const int nsio_tty = NSIO;
429 static u_int cd_inbs;
430 static u_int cy_inbs;
431 static u_int cd_outbs;
432 static u_int cy_outbs;
433 static u_int cy_svrr_probes;
434 static u_int cy_timeouts;
437 static int cy_chip_offset[] = {
438 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
440 static int cy_nr_cd1400s[NCY];
441 static int cy_total_devices;
442 #undef RxFifoThreshold
443 static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
447 struct isa_device *dev;
451 iobase = (cy_addr)dev->id_maddr;
453 /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
454 cy_inb(iobase, CY16_RESET, 0); /* XXX? */
455 DELAY(500); /* wait for the board to get its act together */
457 /* this is needed to get the board out of reset */
458 cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
461 return (cy_units(iobase, 0) == 0 ? 0 : -1);
465 cy_units(cy_iobase, cy_align)
470 u_char firmware_version;
474 for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
475 iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
477 /* wait for chip to become ready for new command */
478 for (i = 0; i < 10; i++) {
480 if (!cd_inb(iobase, CD1400_CCR, cy_align))
484 /* clear the GFRCR register */
485 cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
487 /* issue a reset command */
488 cd_outb(iobase, CD1400_CCR, cy_align,
489 CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
491 /* wait for the CD1400 to initialize itself */
492 for (i = 0; i < 200; i++) {
495 /* retrieve firmware version */
496 firmware_version = cd_inb(iobase, CD1400_GFRCR,
498 if ((firmware_version & 0xf0) == 0x40)
503 * Anything in the 0x40-0x4F range is fine.
504 * If one CD1400 is bad then we don't support higher
505 * numbered good ones on this board.
507 if ((firmware_version & 0xf0) != 0x40)
515 struct isa_device *isdp;
519 adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
525 * This kludge is to allow ISA/PCI device specifications in the
526 * kernel config file to be in any order.
528 if (isdp->id_unit != adapter) {
529 printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
530 isdp->id_unit = adapter; /* XXX */
532 isdp->id_ointr = siointr;
533 /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
538 cyattach_common(cy_iobase, cy_align)
544 u_char firmware_version;
549 adapter = cy_total_devices;
550 if ((u_int)adapter >= NCY) {
552 "cy%d: can't attach adapter: insufficient cy devices configured\n",
556 ncyu = cy_units(cy_iobase, cy_align);
559 cy_nr_cd1400s[adapter] = ncyu;
562 unit = adapter * CY_MAX_PORTS;
563 for (cyu = 0; cyu < ncyu; ++cyu) {
566 iobase = (cy_addr) (cy_iobase
567 + (cy_chip_offset[cyu] << cy_align));
568 firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
570 /* Set up a receive timeout period of than 1+ ms. */
571 cd_outb(iobase, CD1400_PPR, cy_align,
572 howmany(CY_CLOCK(firmware_version)
573 / CD1400_PPR_PRESCALER, 1000));
575 for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
579 com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT | M_ZERO);
583 com->gfrcr_image = firmware_version;
584 if (CY_RTS_DTR_SWAPPED(firmware_version)) {
585 com->mcr_dtr = MCR_RTS;
586 com->mcr_rts = MCR_DTR;
587 com->mcr_rts_reg = CD1400_MSVR2;
589 com->mcr_dtr = MCR_DTR;
590 com->mcr_rts = MCR_RTS;
591 com->mcr_rts_reg = CD1400_MSVR1;
593 com->dtr_wait = 3 * hz;
594 com->obufs[0].l_head = com->obuf1;
595 com->obufs[1].l_head = com->obuf2;
597 com->cy_align = cy_align;
598 com->cy_iobase = cy_iobase;
599 com->iobase = iobase;
600 com->car = ~CD1400_CAR_CHAN;
603 * We don't use all the flags from <sys/ttydefaults.h> since they
604 * are only relevant for logins. It's important to have echo off
605 * initially so that the line doesn't start blathering before the
606 * echo flag can be turned off.
608 com->it_in.c_iflag = 0;
609 com->it_in.c_oflag = 0;
610 com->it_in.c_cflag = TTYDEF_CFLAG;
611 com->it_in.c_lflag = 0;
612 if (unit == comconsole) {
613 com->it_in.c_iflag = TTYDEF_IFLAG;
614 com->it_in.c_oflag = TTYDEF_OFLAG;
615 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
616 com->it_in.c_lflag = TTYDEF_LFLAG;
617 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
619 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
623 termioschars(&com->it_in);
624 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
625 com->it_out = com->it_in;
628 com_addr(unit) = com;
631 if (sio_ih == NULL) {
632 cdevsw_add(&sio_cdevsw);
633 swi_add(&tty_ithd, "tty:cy", siopoll, NULL, SWI_TTY, 0,
636 make_dev(&sio_cdevsw, unit,
637 UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
638 unit % CY_MAX_PORTS);
639 make_dev(&sio_cdevsw, unit | CONTROL_INIT_STATE,
640 UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
641 unit % CY_MAX_PORTS);
642 make_dev(&sio_cdevsw, unit | CONTROL_LOCK_STATE,
643 UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
644 unit % CY_MAX_PORTS);
645 make_dev(&sio_cdevsw, unit | CALLOUT_MASK,
646 UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
647 unit % CY_MAX_PORTS);
648 make_dev(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_INIT_STATE,
649 UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
650 unit % CY_MAX_PORTS);
651 make_dev(&sio_cdevsw, unit | CALLOUT_MASK | CONTROL_LOCK_STATE,
652 UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
653 unit % CY_MAX_PORTS);
657 /* ensure an edge for the next interrupt */
658 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
664 sioopen(dev, flag, mode, p)
679 unit = MINOR_TO_UNIT(mynor);
680 if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
682 if (mynor & CONTROL_MASK)
685 tp = com->tp = sio_tty[unit] = ttymalloc(sio_tty[unit]);
687 tp = com->tp = &sio_tty[unit];
692 * We jump to this label after all non-interrupted sleeps to pick
693 * up any changes of the device state.
696 while (com->state & CS_DTR_OFF) {
697 error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
701 if (tp->t_state & TS_ISOPEN) {
703 * The device is open, so everything has been initialized.
706 if (mynor & CALLOUT_MASK) {
707 if (!com->active_out) {
712 if (com->active_out) {
713 if (flag & O_NONBLOCK) {
717 error = tsleep(&com->active_out,
718 TTIPRI | PCATCH, "cybi", 0);
724 if (tp->t_state & TS_XCLUDE &&
731 * The device isn't open, so there are no conflicts.
732 * Initialize it. Initialization is done twice in many
733 * cases: to preempt sleeping callin opens if we are
734 * callout, and to complete a callin open after DCD rises.
736 tp->t_oproc = comstart;
737 tp->t_stop = comstop;
738 tp->t_param = comparam;
740 tp->t_termios = mynor & CALLOUT_MASK
741 ? com->it_out : com->it_in;
743 /* Encode per-board unit in LIVR for access in intr routines. */
744 cd_setreg(com, CD1400_LIVR,
745 (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
747 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
749 com->poll = com->no_irq;
750 com->poll_output = com->loses_outints;
753 error = comparam(tp, &tp->t_termios);
760 * (Re)enable and flush fifos.
762 * Certain SMC chips cause problems if the fifos
763 * are enabled while input is ready. Turn off the
764 * fifo if necessary to clear the input. We test
765 * the input ready bit after enabling the fifos
766 * since we've already enabled them in comparam()
767 * and to handle races between enabling and fresh
771 outb(iobase + com_fifo,
772 FIFO_RCV_RST | FIFO_XMT_RST
775 if (!(inb(com->line_status_port) & LSR_RXRDY))
777 outb(iobase + com_fifo, 0);
779 (void) inb(com->data_port);
783 intrsave = save_intr();
786 (void) inb(com->line_status_port);
787 (void) inb(com->data_port);
788 com->prev_modem_status = com->last_modem_status
789 = inb(com->modem_status_port);
790 outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
793 restore_intr(intrsave);
796 * Flush fifos. This requires a full channel reset which
797 * also disables the transmitter and receiver. Recover
800 cd1400_channel_cmd(com,
801 CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
802 cd1400_channel_cmd(com, com->channel_control);
804 intrsave = save_intr();
807 com->prev_modem_status = com->last_modem_status
808 = cd_getreg(com, CD1400_MSVR2);
809 cd_setreg(com, CD1400_SRER,
811 = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
813 restore_intr(intrsave);
816 * Handle initial DCD. Callout devices get a fake initial
817 * DCD (trapdoor DCD). If we are callout, then any sleeping
818 * callin opens get woken up and resume sleeping on "cybi"
819 * instead of "cydcd".
822 * XXX `mynor & CALLOUT_MASK' should be
823 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
824 * TRAPDOOR_CARRIER is the default initial state for callout
825 * devices and SOFT_CARRIER is like CLOCAL except it hides
828 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
829 (*linesw[tp->t_line].l_modem)(tp, 1);
832 * Wait for DCD if necessary.
834 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
835 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
837 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
843 error = (*linesw[tp->t_line].l_open)(dev, tp);
844 disc_optim(tp, &tp->t_termios, com);
845 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
846 com->active_out = TRUE;
850 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
856 sioclose(dev, flag, mode, p)
868 if (mynor & CONTROL_MASK)
870 com = com_addr(MINOR_TO_UNIT(mynor));
873 cd_etc(com, CD1400_ETC_STOPBREAK);
874 (*linesw[tp->t_line].l_close)(tp, flag);
875 disc_optim(tp, &tp->t_termios, com);
876 comstop(tp, FREAD | FWRITE);
881 #ifdef broken /* session holds a ref to the tty; can't deallocate */
883 com->tp = sio_tty[unit] = NULL;
899 iobase = com->iobase;
903 com->poll_output = FALSE;
905 com->do_timestamp = 0;
907 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
910 intrsave = save_intr();
914 cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
916 restore_intr(intrsave);
917 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
922 outb(iobase + com_ier, 0);
924 intrsave = save_intr();
927 cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
929 restore_intr(intrsave);
932 if ((tp->t_cflag & HUPCL)
934 * XXX we will miss any carrier drop between here and the
935 * next open. Perhaps we should watch DCD even when the
936 * port is closed; it is not sufficient to check it at
937 * the next open because it might go up and down while
938 * we're not watching.
941 && !(com->prev_modem_status & MSR_DCD)
942 && !(com->it_in.c_cflag & CLOCAL))
943 || !(tp->t_state & TS_ISOPEN)) {
944 (void)commctl(com, TIOCM_DTR, DMBIC);
946 /* Disable receiver (leave transmitter enabled). */
947 com->channel_control = CD1400_CCR_CMDCHANCTL
950 cd1400_channel_cmd(com, com->channel_control);
952 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
953 timeout(siodtrwakeup, com, com->dtr_wait);
954 com->state |= CS_DTR_OFF;
961 * Disable fifos so that they are off after controlled
962 * reboots. Some BIOSes fail to detect 16550s when the
965 outb(iobase + com_fifo, 0);
968 com->active_out = FALSE;
969 wakeup(&com->active_out);
970 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
975 siowrite(dev, uio, flag)
985 if (mynor & CONTROL_MASK)
988 unit = MINOR_TO_UNIT(mynor);
989 tp = com_addr(unit)->tp;
991 * (XXX) We disallow virtual consoles if the physical console is
992 * a serial port. This is in case there is a display attached that
993 * is not the console. In that situation we don't need/want the X
994 * server taking over the console.
996 if (constty != NULL && unit == comconsole)
999 /* XXX duplicate ttwrite(), but without so much output processing on
1000 * CR & LF chars. Hardly worth the effort, given that high-throughput
1001 * sessions are raw anyhow.
1004 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
1014 com = (struct com_s *)chan;
1015 com->state &= ~CS_DTR_OFF;
1016 wakeup(&com->dtr_wait);
1021 * a) needs to be called with COM_LOCK() held, and
1022 * b) needs to return with COM_LOCK() held.
1037 if (!(tp->t_state & TS_ISOPEN)) {
1038 com_events -= (com->iptr - com->ibuf);
1039 com->iptr = com->ibuf;
1042 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1044 * Avoid the grotesquely inefficient lineswitch routine
1045 * (ttyinput) in "raw" mode. It usually takes about 450
1046 * instructions (that's without canonical processing or echo!).
1047 * slinput is reasonably fast (usually 40 instructions plus
1053 * This may look odd, but it is using save-and-enable
1054 * semantics instead of the save-and-disable semantics
1055 * that are used everywhere else.
1057 intrsave = save_intr();
1060 incc = com->iptr - buf;
1061 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1062 && (com->state & CS_RTS_IFLOW
1063 || tp->t_iflag & IXOFF)
1064 && !(tp->t_state & TS_TBLOCK))
1066 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1067 += b_to_q((char *)buf, incc, &tp->t_rawq);
1071 tp->t_rawcc += incc;
1073 if (tp->t_state & TS_TTSTOP
1074 && (tp->t_iflag & IXANY
1075 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1076 tp->t_state &= ~TS_TTSTOP;
1077 tp->t_lflag &= ~FLUSHO;
1080 restore_intr(intrsave);
1082 } while (buf < com->iptr);
1086 * This may look odd, but it is using save-and-enable
1087 * semantics instead of the save-and-disable semantics
1088 * that are used everywhere else.
1090 intrsave = save_intr();
1093 line_status = buf[com->ierroff];
1096 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1097 if (line_status & LSR_BI)
1098 recv_data |= TTY_BI;
1099 if (line_status & LSR_FE)
1100 recv_data |= TTY_FE;
1101 if (line_status & LSR_OE)
1102 recv_data |= TTY_OE;
1103 if (line_status & LSR_PE)
1104 recv_data |= TTY_PE;
1106 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1107 restore_intr(intrsave);
1109 } while (buf < com->iptr);
1111 com_events -= (com->iptr - com->ibuf);
1112 com->iptr = com->ibuf;
1115 * There is now room for another low-level buffer full of input,
1116 * so enable RTS if it is now disabled and there is room in the
1117 * high-level buffer.
1119 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
1120 !(tp->t_state & TS_TBLOCK))
1122 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1124 cd_setreg(com, com->mcr_rts_reg,
1125 com->mcr_image |= com->mcr_rts);
1140 COM_LOCK(); /* XXX could this be placed down lower in the loop? */
1142 baseu = unit * CY_MAX_PORTS;
1143 cy_align = com_addr(baseu)->cy_align;
1144 cy_iobase = com_addr(baseu)->cy_iobase;
1146 /* check each CD1400 in turn */
1147 for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
1148 iobase = (cy_addr) (cy_iobase
1149 + (cy_chip_offset[cyu] << cy_align));
1150 /* poll to see if it has any work */
1151 status = cd_inb(iobase, CD1400_SVRR, cy_align);
1157 /* service requests as appropriate, giving priority to RX */
1158 if (status & CD1400_SVRR_RXRDY) {
1170 save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
1172 /* enter rx service */
1173 cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
1174 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1175 = save_rir & CD1400_CAR_CHAN;
1177 serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
1178 com = com_addr(baseu
1179 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1180 & CD1400_xIVR_CHAN));
1182 /* ack receive service */
1183 serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
1185 com = com_addr(baseu +
1186 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1187 & CD1400_xIVR_CHAN));
1190 if (serv_type & CD1400_RIVR_EXCEPTION) {
1191 ++com->recv_exception;
1192 line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
1193 /* break/unnattached error bits or real input? */
1194 recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
1195 #ifndef SOFT_HOTCHAR
1196 if (line_status & CD1400_RDSR_SPECIAL
1197 && com->hotchar != 0)
1198 swi_sched(sio_ih, SWI_NOSWITCH);
1201 #if 1 /* XXX "intelligent" PFO error handling would break O error handling */
1202 if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
1204 Don't store PE if IGNPAR and BI if IGNBRK,
1205 this hack allows "raw" tty optimization
1206 works even if IGN* is set.
1208 if ( com->tp == NULL
1209 || !(com->tp->t_state & TS_ISOPEN)
1210 || ((line_status & (LSR_PE|LSR_FE))
1211 && (com->tp->t_iflag & IGNPAR))
1212 || ((line_status & LSR_BI)
1213 && (com->tp->t_iflag & IGNBRK)))
1215 if ( (line_status & (LSR_PE|LSR_FE))
1216 && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
1217 && ((line_status & LSR_FE)
1218 || ((line_status & LSR_PE)
1219 && (com->tp->t_iflag & INPCK))))
1225 if (com->hotchar != 0 && recv_data == com->hotchar)
1226 swi_sched(sio_ih, SWI_NOSWITCH);
1229 if (ioptr >= com->ibufend)
1230 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
1232 if (com->do_timestamp)
1233 microtime(&com->timestamp);
1235 ioptr[0] = recv_data;
1236 ioptr[com->ierroff] = line_status;
1237 com->iptr = ++ioptr;
1238 if (ioptr == com->ihighwater
1239 && com->state & CS_RTS_IFLOW)
1241 outb(com->modem_ctl_port,
1242 com->mcr_image &= ~MCR_RTS);
1244 cd_outb(iobase, com->mcr_rts_reg,
1249 if (line_status & LSR_OE)
1250 CE_RECORD(com, CE_OVERRUN);
1256 count = cd_inb(iobase, CD1400_RDCR, cy_align);
1259 com->bytes_in += count;
1261 ifree = com->ibufend - ioptr;
1262 if (count > ifree) {
1264 com_events += ifree;
1266 if (com->do_timestamp)
1267 microtime(&com->timestamp);
1269 recv_data = cd_inb(iobase,
1273 if (com->hotchar != 0
1276 swi_sched(sio_ih, SWI_NOSWITCH);
1278 ioptr[0] = recv_data;
1279 ioptr[com->ierroff] = 0;
1281 } while (--ifree != 0);
1283 com->delta_error_counts
1284 [CE_INTERRUPT_BUF_OVERFLOW] += count;
1286 recv_data = cd_inb(iobase, CD1400_RDSR,
1289 if (com->hotchar != 0
1290 && recv_data == com->hotchar)
1291 swi_sched(sio_ih, SWI_NOSWITCH);
1293 } while (--count != 0);
1295 if (com->do_timestamp)
1296 microtime(&com->timestamp);
1297 if (ioptr <= com->ihighwater
1298 && ioptr + count > com->ihighwater
1299 && com->state & CS_RTS_IFLOW)
1301 outb(com->modem_ctl_port,
1302 com->mcr_image &= ~MCR_RTS);
1304 cd_outb(iobase, com->mcr_rts_reg,
1309 com_events += count;
1311 recv_data = cd_inb(iobase, CD1400_RDSR,
1314 if (com->hotchar != 0
1315 && recv_data == com->hotchar)
1316 swi_sched(sio_ih, SWI_NOSWITCH);
1318 ioptr[0] = recv_data;
1319 ioptr[com->ierroff] = 0;
1321 } while (--count != 0);
1327 /* terminate service context */
1329 cd_outb(iobase, CD1400_RIR, cy_align,
1331 & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
1333 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1336 if (status & CD1400_SVRR_MDMCH) {
1338 u_char modem_status;
1346 save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
1348 /* enter modem service */
1349 cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
1350 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1351 = save_mir & CD1400_CAR_CHAN;
1353 com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
1354 + (save_mir & CD1400_MIR_CHAN));
1356 /* ack modem service */
1357 vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
1359 com = com_addr(baseu
1360 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1361 & CD1400_xIVR_CHAN));
1364 modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
1365 if (modem_status != com->last_modem_status) {
1366 if (com->do_dcd_timestamp
1367 && !(com->last_modem_status & MSR_DCD)
1368 && modem_status & MSR_DCD)
1369 microtime(&com->dcd_timestamp);
1372 * Schedule high level to handle DCD changes. Note
1373 * that we don't use the delta bits anywhere. Some
1374 * UARTs mess them up, and it's easy to remember the
1375 * previous bits and calculate the delta.
1377 com->last_modem_status = modem_status;
1378 if (!(com->state & CS_CHECKMSR)) {
1379 com_events += LOTS_OF_EVENTS;
1380 com->state |= CS_CHECKMSR;
1381 swi_sched(sio_ih, SWI_NOSWITCH);
1384 #ifdef SOFT_CTS_OFLOW
1385 /* handle CTS change immediately for crisp flow ctl */
1386 if (com->state & CS_CTS_OFLOW) {
1387 if (modem_status & MSR_CTS) {
1388 com->state |= CS_ODEVREADY;
1389 if (com->state >= (CS_BUSY | CS_TTGO
1391 && !(com->intr_enable
1392 & CD1400_SRER_TXRDY))
1393 cd_outb(iobase, CD1400_SRER,
1397 & ~CD1400_SRER_TXMPTY
1398 | CD1400_SRER_TXRDY);
1400 com->state &= ~CS_ODEVREADY;
1401 if (com->intr_enable
1402 & CD1400_SRER_TXRDY)
1403 cd_outb(iobase, CD1400_SRER,
1407 & ~CD1400_SRER_TXRDY
1408 | CD1400_SRER_TXMPTY);
1414 /* terminate service context */
1416 cd_outb(iobase, CD1400_MIR, cy_align,
1418 & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
1420 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1423 if (status & CD1400_SVRR_TXRDY) {
1432 save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
1434 /* enter tx service */
1435 cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
1436 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1437 = save_tir & CD1400_CAR_CHAN;
1439 com = com_addr(baseu
1440 + cyu * CD1400_NO_OF_CHANNELS
1441 + (save_tir & CD1400_TIR_CHAN));
1443 /* ack transmit service */
1444 vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
1446 com = com_addr(baseu
1447 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1448 & CD1400_xIVR_CHAN));
1451 if (com->etc != ETC_NONE) {
1452 if (com->intr_enable & CD1400_SRER_TXRDY) {
1454 * Here due to sloppy SRER_TXRDY
1455 * enabling. Ignore. Come back when
1458 cd_outb(iobase, CD1400_SRER, cy_align,
1461 & ~CD1400_SRER_TXRDY)
1462 | CD1400_SRER_TXMPTY);
1463 goto terminate_tx_service;
1466 case CD1400_ETC_SENDBREAK:
1467 case CD1400_ETC_STOPBREAK:
1469 * Start the command. Come back on
1470 * next tx empty interrupt, hopefully
1471 * after command has been executed.
1473 cd_outb(iobase, CD1400_COR2, cy_align,
1474 com->cor[1] |= CD1400_COR2_ETC);
1475 cd_outb(iobase, CD1400_TDR, cy_align,
1477 cd_outb(iobase, CD1400_TDR, cy_align,
1479 if (com->etc == CD1400_ETC_SENDBREAK)
1480 com->etc = ETC_BREAK_STARTING;
1482 com->etc = ETC_BREAK_ENDING;
1483 goto terminate_tx_service;
1484 case ETC_BREAK_STARTING:
1486 * BREAK is now on. Continue with
1487 * SRER_TXMPTY processing, hopefully
1490 com->etc = ETC_BREAK_STARTED;
1492 case ETC_BREAK_STARTED:
1494 * Came back due to sloppy SRER_TXMPTY
1495 * enabling. Hope again.
1498 case ETC_BREAK_ENDING:
1500 * BREAK is now off. Continue with
1501 * SRER_TXMPTY processing and don't
1502 * come back. The SWI handler will
1503 * restart tx interrupts if necessary.
1505 cd_outb(iobase, CD1400_COR2, cy_align,
1507 &= ~CD1400_COR2_ETC);
1508 com->etc = ETC_BREAK_ENDED;
1509 if (!(com->state & CS_ODONE)) {
1510 com_events += LOTS_OF_EVENTS;
1511 com->state |= CS_ODONE;
1512 swi_sched(sio_ih, SWI_NOSWITCH);
1515 case ETC_BREAK_ENDED:
1517 * Shouldn't get here. Hope again.
1522 if (com->intr_enable & CD1400_SRER_TXMPTY) {
1523 if (!(com->extra_state & CSE_ODONE)) {
1524 com_events += LOTS_OF_EVENTS;
1525 com->extra_state |= CSE_ODONE;
1526 swi_sched(sio_ih, SWI_NOSWITCH);
1528 cd_outb(iobase, CD1400_SRER, cy_align,
1530 &= ~CD1400_SRER_TXMPTY);
1531 goto terminate_tx_service;
1533 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
1537 ioptr = com->obufq.l_head;
1538 ocount = com->obufq.l_tail - ioptr;
1539 if (ocount > CD1400_TX_FIFO_SIZE)
1540 ocount = CD1400_TX_FIFO_SIZE;
1541 com->bytes_out += ocount;
1543 cd_outb(iobase, CD1400_TDR, cy_align,
1545 while (--ocount != 0);
1546 com->obufq.l_head = ioptr;
1547 if (ioptr >= com->obufq.l_tail) {
1550 qp = com->obufq.l_next;
1551 qp->l_queued = FALSE;
1554 com->obufq.l_head = qp->l_head;
1555 com->obufq.l_tail = qp->l_tail;
1556 com->obufq.l_next = qp;
1558 /* output just completed */
1559 com->state &= ~CS_BUSY;
1562 * The setting of CSE_ODONE may be
1563 * stale here. We currently only
1564 * use it when CS_BUSY is set, and
1565 * fixing it when we clear CS_BUSY
1568 if (com->extra_state & CSE_ODONE) {
1569 com_events -= LOTS_OF_EVENTS;
1570 com->extra_state &= ~CSE_ODONE;
1573 cd_outb(iobase, CD1400_SRER, cy_align,
1576 & ~CD1400_SRER_TXRDY)
1577 | CD1400_SRER_TXMPTY);
1579 if (!(com->state & CS_ODONE)) {
1580 com_events += LOTS_OF_EVENTS;
1581 com->state |= CS_ODONE;
1583 /* handle at high level ASAP */
1584 swi_sched(sio_ih, SWI_NOSWITCH);
1589 /* terminate service context */
1590 terminate_tx_service:
1592 cd_outb(iobase, CD1400_TIR, cy_align,
1594 & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
1596 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1601 /* ensure an edge for the next interrupt */
1602 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
1604 swi_sched(sio_ih, SWI_NOSWITCH);
1618 sioioctl(dev, cmd, data, flag, p)
1630 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1632 struct termios term;
1636 com = com_addr(MINOR_TO_UNIT(mynor));
1637 if (mynor & CONTROL_MASK) {
1640 switch (mynor & CONTROL_MASK) {
1641 case CONTROL_INIT_STATE:
1642 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
1644 case CONTROL_LOCK_STATE:
1645 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
1648 return (ENODEV); /* /dev/nodev */
1655 *ct = *(struct termios *)data;
1658 *(struct termios *)data = *ct;
1661 *(int *)data = TTYDISC;
1664 bzero(data, sizeof(struct winsize));
1671 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1672 term = tp->t_termios;
1674 error = ttsetcompat(tp, &cmd, data, &term);
1678 data = (caddr_t)&term;
1680 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1682 struct termios *dt = (struct termios *)data;
1683 struct termios *lt = mynor & CALLOUT_MASK
1684 ? &com->lt_out : &com->lt_in;
1686 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1687 | (dt->c_iflag & ~lt->c_iflag);
1688 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1689 | (dt->c_oflag & ~lt->c_oflag);
1690 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1691 | (dt->c_cflag & ~lt->c_cflag);
1692 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1693 | (dt->c_lflag & ~lt->c_lflag);
1694 for (cc = 0; cc < NCCS; ++cc)
1695 if (lt->c_cc[cc] != 0)
1696 dt->c_cc[cc] = tp->t_cc[cc];
1697 if (lt->c_ispeed != 0)
1698 dt->c_ispeed = tp->t_ispeed;
1699 if (lt->c_ospeed != 0)
1700 dt->c_ospeed = tp->t_ospeed;
1702 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1703 if (error != ENOIOCTL)
1706 error = ttioctl(tp, cmd, data, flag);
1707 disc_optim(tp, &tp->t_termios, com);
1708 if (error != ENOIOCTL) {
1715 outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
1717 cd_etc(com, CD1400_ETC_SENDBREAK);
1722 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1724 cd_etc(com, CD1400_ETC_STOPBREAK);
1728 (void)commctl(com, TIOCM_DTR, DMBIS);
1731 (void)commctl(com, TIOCM_DTR, DMBIC);
1734 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
1735 * changes get undone on the next call to comparam().
1738 (void)commctl(com, *(int *)data, DMSET);
1741 (void)commctl(com, *(int *)data, DMBIS);
1744 (void)commctl(com, *(int *)data, DMBIC);
1747 *(int *)data = commctl(com, 0, DMGET);
1750 /* must be root since the wait applies to following logins */
1756 com->dtr_wait = *(int *)data * hz / 100;
1759 *(int *)data = com->dtr_wait * 100 / hz;
1762 com->do_timestamp = TRUE;
1763 *(struct timeval *)data = com->timestamp;
1765 case TIOCDCDTIMESTAMP:
1766 com->do_dcd_timestamp = TRUE;
1767 *(struct timeval *)data = com->dcd_timestamp;
1786 if (com_events == 0)
1789 for (unit = 0; unit < NSIO; ++unit) {
1794 com = com_addr(unit);
1800 * XXX forget any events related to closed devices
1801 * (actually never opened devices) so that we don't
1804 intrsave = save_intr();
1807 incc = com->iptr - com->ibuf;
1808 com->iptr = com->ibuf;
1809 if (com->state & CS_CHECKMSR) {
1810 incc += LOTS_OF_EVENTS;
1811 com->state &= ~CS_CHECKMSR;
1815 restore_intr(intrsave);
1818 "sio%d: %d events for device with no tp\n",
1822 if (com->iptr != com->ibuf) {
1823 intrsave = save_intr();
1828 restore_intr(intrsave);
1830 if (com->state & CS_CHECKMSR) {
1831 u_char delta_modem_status;
1833 intrsave = save_intr();
1837 delta_modem_status = com->last_modem_status
1838 ^ com->prev_modem_status;
1839 com->prev_modem_status = com->last_modem_status;
1840 com_events -= LOTS_OF_EVENTS;
1841 com->state &= ~CS_CHECKMSR;
1843 restore_intr(intrsave);
1844 if (delta_modem_status & MSR_DCD)
1845 (*linesw[tp->t_line].l_modem)
1846 (tp, com->prev_modem_status & MSR_DCD);
1848 if (com->extra_state & CSE_ODONE) {
1849 intrsave = save_intr();
1852 com_events -= LOTS_OF_EVENTS;
1853 com->extra_state &= ~CSE_ODONE;
1855 restore_intr(intrsave);
1856 if (!(com->state & CS_BUSY)) {
1857 tp->t_state &= ~TS_BUSY;
1860 if (com->etc != ETC_NONE) {
1861 if (com->etc == ETC_BREAK_ENDED)
1862 com->etc = ETC_NONE;
1866 if (com->state & CS_ODONE) {
1867 intrsave = save_intr();
1870 com_events -= LOTS_OF_EVENTS;
1871 com->state &= ~CS_ODONE;
1873 restore_intr(intrsave);
1874 (*linesw[tp->t_line].l_start)(tp);
1876 if (com_events == 0)
1879 if (com_events >= LOTS_OF_EVENTS)
1904 /* do historical conversions */
1905 if (t->c_ispeed == 0)
1906 t->c_ispeed = t->c_ospeed;
1908 unit = DEV_TO_UNIT(tp->t_dev);
1909 com = com_addr(unit);
1911 /* check requested parameters */
1912 cy_clock = CY_CLOCK(com->gfrcr_image);
1913 idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
1916 odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
1920 /* parameters are OK, convert them to the com struct and the device */
1923 (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
1925 (void)commctl(com, TIOCM_DTR, DMBIS);
1927 (void) siosetwater(com, t->c_ispeed);
1929 /* XXX we don't actually change the speed atomically. */
1931 if (idivisor != 0) {
1932 cd_setreg(com, CD1400_RBPR, idivisor);
1933 cd_setreg(com, CD1400_RCOR, iprescaler);
1935 if (odivisor != 0) {
1936 cd_setreg(com, CD1400_TBPR, odivisor);
1937 cd_setreg(com, CD1400_TCOR, oprescaler);
1943 * transmitter enable (always set)
1946 opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN
1947 | (cflag & CREAD ? CD1400_CCR_RCVEN : CD1400_CCR_RCVDIS);
1948 if (opt != com->channel_control) {
1949 com->channel_control = opt;
1950 cd1400_channel_cmd(com, opt);
1954 /* set special chars */
1955 /* XXX if one is _POSIX_VDISABLE, can't use some others */
1956 if (t->c_cc[VSTOP] != _POSIX_VDISABLE)
1957 cd_setreg(com, CD1400_SCHR1, t->c_cc[VSTOP]);
1958 if (t->c_cc[VSTART] != _POSIX_VDISABLE)
1959 cd_setreg(com, CD1400_SCHR2, t->c_cc[VSTART]);
1960 if (t->c_cc[VINTR] != _POSIX_VDISABLE)
1961 cd_setreg(com, CD1400_SCHR3, t->c_cc[VINTR]);
1962 if (t->c_cc[VSUSP] != _POSIX_VDISABLE)
1963 cd_setreg(com, CD1400_SCHR4, t->c_cc[VSUSP]);
1967 * set channel option register 1 -
1974 if (cflag & PARENB) {
1976 opt |= CD1400_COR1_PARODD;
1977 opt |= CD1400_COR1_PARNORMAL;
1980 if (!(iflag & INPCK))
1981 opt |= CD1400_COR1_NOINPCK;
1984 if (cflag & CSTOPB) {
1986 opt |= CD1400_COR1_STOP2;
1989 switch (cflag & CSIZE) {
1992 opt |= CD1400_COR1_CS5;
1996 opt |= CD1400_COR1_CS6;
2000 opt |= CD1400_COR1_CS7;
2004 opt |= CD1400_COR1_CS8;
2008 if (opt != com->cor[0]) {
2009 cor_change |= CD1400_CCR_COR1;
2010 cd_setreg(com, CD1400_COR1, com->cor[0] = opt);
2014 * Set receive time-out period, normally to max(one char time, 5 ms).
2016 if (t->c_ispeed == 0)
2017 itimeout = cd_getreg(com, CD1400_RTPR);
2019 itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
2025 if (itimeout < MIN_RTP)
2028 if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
2029 && t->c_cc[VTIME] * 10 > itimeout)
2030 itimeout = t->c_cc[VTIME] * 10;
2033 cd_setreg(com, CD1400_RTPR, itimeout);
2036 * set channel option register 2 -
2042 opt |= CD1400_COR2_IXANY;
2044 opt |= CD1400_COR2_IXOFF;
2046 #ifndef SOFT_CTS_OFLOW
2047 if (cflag & CCTS_OFLOW)
2048 opt |= CD1400_COR2_CCTS_OFLOW;
2050 intrsave = save_intr();
2053 if (opt != com->cor[1]) {
2054 cor_change |= CD1400_CCR_COR2;
2055 cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
2058 restore_intr(intrsave);
2061 * set channel option register 3 -
2062 * receiver FIFO interrupt threshold
2065 opt = RxFifoThreshold;
2067 if (t->c_lflag & ICANON)
2068 opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
2070 /* detect and transparently handle START and STOP chars */
2071 opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
2073 if (opt != com->cor[2]) {
2074 cor_change |= CD1400_CCR_COR3;
2075 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2078 /* notify the CD1400 if COR1-3 have changed */
2080 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
2083 * set channel option register 4 -
2086 * received exception processing
2090 opt |= CD1400_COR4_IGNCR;
2093 * we need a new ttyinput() for this, as we don't want to
2094 * have ICRNL && INLCR being done in both layers, or to have
2095 * synchronisation problems
2098 opt |= CD1400_COR4_ICRNL;
2100 opt |= CD1400_COR4_INLCR;
2103 opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
2105 * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
2106 * so only tell the hardware about -brkint if -parmrk.
2108 if (!(iflag & (BRKINT | PARMRK)))
2109 opt |= CD1400_COR4_NOBRKINT;
2111 /* XXX using this "intelligence" breaks reporting of overruns. */
2113 opt |= CD1400_COR4_PFO_DISCARD;
2116 opt |= CD1400_COR4_PFO_ESC;
2118 opt |= CD1400_COR4_PFO_NUL;
2121 opt |= CD1400_COR4_PFO_EXCEPTION;
2123 cd_setreg(com, CD1400_COR4, opt);
2126 * set channel option register 5 -
2130 opt |= CD1400_COR5_ISTRIP;
2131 if (t->c_iflag & IEXTEN)
2132 /* enable LNEXT (e.g. ctrl-v quoting) handling */
2133 opt |= CD1400_COR5_LNEXT;
2135 if (t->c_oflag & ONLCR)
2136 opt |= CD1400_COR5_ONLCR;
2137 if (t->c_oflag & OCRNL)
2138 opt |= CD1400_COR5_OCRNL;
2140 cd_setreg(com, CD1400_COR5, opt);
2143 * We always generate modem status change interrupts for CD changes.
2144 * Among other things, this is necessary to track TS_CARR_ON for
2145 * pstat to print even when the driver doesn't care. CD changes
2146 * should be rare so interrupts for them are not worth extra code to
2147 * avoid. We avoid interrupts for other modem status changes (except
2148 * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
2149 * simplest and best.
2153 * set modem change option register 1
2154 * generate modem interrupts on which 1 -> 0 input transitions
2155 * also controls auto-DTR output flow-control, which we don't use
2157 opt = CD1400_MCOR1_CDzd;
2158 #ifdef SOFT_CTS_OFLOW
2159 if (cflag & CCTS_OFLOW)
2160 opt |= CD1400_MCOR1_CTSzd;
2162 cd_setreg(com, CD1400_MCOR1, opt);
2165 * set modem change option register 2
2166 * generate modem interrupts on specific 0 -> 1 input transitions
2168 opt = CD1400_MCOR2_CDod;
2169 #ifdef SOFT_CTS_OFLOW
2170 if (cflag & CCTS_OFLOW)
2171 opt |= CD1400_MCOR2_CTSod;
2173 cd_setreg(com, CD1400_MCOR2, opt);
2176 * XXX should have done this long ago, but there is too much state
2177 * to change all atomically.
2179 intrsave = save_intr();
2183 com->state &= ~CS_TTGO;
2184 if (!(tp->t_state & TS_TTSTOP))
2185 com->state |= CS_TTGO;
2186 if (cflag & CRTS_IFLOW) {
2187 com->state |= CS_RTS_IFLOW;
2189 * If CS_RTS_IFLOW just changed from off to on, the change
2190 * needs to be propagated to MCR_RTS. This isn't urgent,
2191 * so do it later by calling comstart() instead of repeating
2192 * a lot of code from comstart() here.
2194 } else if (com->state & CS_RTS_IFLOW) {
2195 com->state &= ~CS_RTS_IFLOW;
2197 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2198 * on here, since comstart() won't do it later.
2201 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2203 cd_setreg(com, com->mcr_rts_reg,
2204 com->mcr_image |= com->mcr_rts);
2209 * Set up state to handle output flow control.
2210 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2211 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2213 com->state |= CS_ODEVREADY;
2214 #ifdef SOFT_CTS_OFLOW
2215 com->state &= ~CS_CTS_OFLOW;
2216 if (cflag & CCTS_OFLOW) {
2217 com->state |= CS_CTS_OFLOW;
2218 if (!(com->last_modem_status & MSR_CTS))
2219 com->state &= ~CS_ODEVREADY;
2222 /* XXX shouldn't call functions while intrs are disabled. */
2223 disc_optim(tp, t, com);
2226 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2227 * unconditionally, but that defeated the careful discarding of
2228 * stale input in sioopen().
2230 if (com->state >= (CS_BUSY | CS_TTGO))
2233 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2234 if (!(com->intr_enable & CD1400_SRER_TXRDY))
2235 cd_setreg(com, CD1400_SRER,
2237 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2238 | CD1400_SRER_TXRDY);
2240 if (com->intr_enable & CD1400_SRER_TXRDY)
2241 cd_setreg(com, CD1400_SRER,
2243 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2244 | CD1400_SRER_TXMPTY);
2248 restore_intr(intrsave);
2251 if (com->ibufold != NULL) {
2252 free(com->ibufold, M_DEVBUF);
2253 com->ibufold = NULL;
2259 siosetwater(com, speed)
2270 * Make the buffer size large enough to handle a softtty interrupt
2271 * latency of about 2 ticks without loss of throughput or data
2272 * (about 3 ticks if input flow control is not used or not honoured,
2273 * but a bit less for CS5-CS7 modes).
2275 cp4ticks = speed / 10 / hz * 4;
2276 for (ibufsize = 128; ibufsize < cp4ticks;)
2278 if (ibufsize == com->ibufsize) {
2283 * Allocate input buffer. The extra factor of 2 in the size is
2284 * to allow for an error byte for each input byte.
2286 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2291 /* Initialize non-critical variables. */
2292 com->ibufold = com->ibuf;
2293 com->ibufsize = ibufsize;
2296 tp->t_ififosize = 2 * ibufsize;
2297 tp->t_ispeedwat = (speed_t)-1;
2298 tp->t_ospeedwat = (speed_t)-1;
2302 * Read current input buffer, if any. Continue with interrupts
2305 intrsave = save_intr();
2308 if (com->iptr != com->ibuf)
2312 * Initialize critical variables, including input buffer watermarks.
2313 * The external device is asked to stop sending when the buffer
2314 * exactly reaches high water, or when the high level requests it.
2315 * The high level is notified immediately (rather than at a later
2316 * clock tick) when this watermark is reached.
2317 * The buffer size is chosen so the watermark should almost never
2319 * The low watermark is invisibly 0 since the buffer is always
2320 * emptied all at once.
2322 com->iptr = com->ibuf = ibuf;
2323 com->ibufend = ibuf + ibufsize;
2324 com->ierroff = ibufsize;
2325 com->ihighwater = ibuf + 3 * ibufsize / 4;
2328 restore_intr(intrsave);
2344 unit = DEV_TO_UNIT(tp->t_dev);
2345 com = com_addr(unit);
2353 intrsave = save_intr();
2356 if (tp->t_state & TS_TTSTOP) {
2357 com->state &= ~CS_TTGO;
2358 if (com->intr_enable & CD1400_SRER_TXRDY)
2359 cd_setreg(com, CD1400_SRER,
2361 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2362 | CD1400_SRER_TXMPTY);
2364 com->state |= CS_TTGO;
2365 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
2366 && !(com->intr_enable & CD1400_SRER_TXRDY))
2367 cd_setreg(com, CD1400_SRER,
2369 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2370 | CD1400_SRER_TXRDY);
2372 if (tp->t_state & TS_TBLOCK) {
2373 if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
2375 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2377 cd_setreg(com, com->mcr_rts_reg,
2378 com->mcr_image &= ~com->mcr_rts);
2381 if (!(com->mcr_image & com->mcr_rts)
2382 && com->iptr < com->ihighwater
2383 && com->state & CS_RTS_IFLOW)
2385 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2387 cd_setreg(com, com->mcr_rts_reg,
2388 com->mcr_image |= com->mcr_rts);
2392 restore_intr(intrsave);
2393 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2398 if (tp->t_outq.c_cc != 0) {
2402 if (!com->obufs[0].l_queued) {
2406 com->obufs[0].l_tail
2407 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2409 com->obufs[0].l_next = NULL;
2410 com->obufs[0].l_queued = TRUE;
2411 intrsave = save_intr();
2414 if (com->state & CS_BUSY) {
2415 qp = com->obufq.l_next;
2416 while ((next = qp->l_next) != NULL)
2418 qp->l_next = &com->obufs[0];
2420 com->obufq.l_head = com->obufs[0].l_head;
2421 com->obufq.l_tail = com->obufs[0].l_tail;
2422 com->obufq.l_next = &com->obufs[0];
2423 com->state |= CS_BUSY;
2424 if (com->state >= (CS_BUSY | CS_TTGO
2426 cd_setreg(com, CD1400_SRER,
2429 & ~CD1400_SRER_TXMPTY)
2430 | CD1400_SRER_TXRDY);
2433 restore_intr(intrsave);
2435 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2439 com->obufs[1].l_tail
2440 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2442 com->obufs[1].l_next = NULL;
2443 com->obufs[1].l_queued = TRUE;
2444 intrsave = save_intr();
2447 if (com->state & CS_BUSY) {
2448 qp = com->obufq.l_next;
2449 while ((next = qp->l_next) != NULL)
2451 qp->l_next = &com->obufs[1];
2453 com->obufq.l_head = com->obufs[1].l_head;
2454 com->obufq.l_tail = com->obufs[1].l_tail;
2455 com->obufq.l_next = &com->obufs[1];
2456 com->state |= CS_BUSY;
2457 if (com->state >= (CS_BUSY | CS_TTGO
2459 cd_setreg(com, CD1400_SRER,
2462 & ~CD1400_SRER_TXMPTY)
2463 | CD1400_SRER_TXRDY);
2466 restore_intr(intrsave);
2468 tp->t_state |= TS_BUSY;
2475 intrsave = save_intr();
2478 if (com->state >= (CS_BUSY | CS_TTGO))
2479 siointr1(com); /* fake interrupt to start output */
2481 restore_intr(intrsave);
2496 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2498 intrsave = save_intr();
2502 com->obufs[0].l_queued = FALSE;
2503 com->obufs[1].l_queued = FALSE;
2504 if (com->extra_state & CSE_ODONE) {
2505 com_events -= LOTS_OF_EVENTS;
2506 com->extra_state &= ~CSE_ODONE;
2507 if (com->etc != ETC_NONE) {
2508 if (com->etc == ETC_BREAK_ENDED)
2509 com->etc = ETC_NONE;
2513 com->tp->t_state &= ~TS_BUSY;
2514 if (com->state & CS_ODONE)
2515 com_events -= LOTS_OF_EVENTS;
2516 com->state &= ~(CS_ODONE | CS_BUSY);
2519 /* XXX no way to reset only input fifo. */
2520 com_events -= (com->iptr - com->ibuf);
2521 com->iptr = com->ibuf;
2524 restore_intr(intrsave);
2527 if (rw & FWRITE && com->etc == ETC_NONE)
2528 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
2533 commctl(com, bits, how)
2543 if (com->channel_control & CD1400_CCR_RCVEN)
2545 mcr = com->mcr_image;
2546 if (mcr & com->mcr_dtr)
2548 if (mcr & com->mcr_rts)
2549 /* XXX wired on for Cyclom-8Ys */
2553 * We must read the modem status from the hardware because
2554 * we don't generate modem status change interrupts for all
2555 * changes, so com->prev_modem_status is not guaranteed to
2556 * be up to date. This is safe, unlike for sio, because
2557 * reading the status register doesn't clear pending modem
2558 * status change interrupts.
2560 msr = cd_getreg(com, CD1400_MSVR2);
2569 /* XXX not connected except for Cyclom-16Y? */
2574 if (bits & TIOCM_DTR)
2575 mcr |= com->mcr_dtr;
2576 if (bits & TIOCM_RTS)
2577 mcr |= com->mcr_rts;
2578 intrsave = save_intr();
2583 com->mcr_image = mcr;
2584 cd_setreg(com, CD1400_MSVR1, mcr);
2585 cd_setreg(com, CD1400_MSVR2, mcr);
2588 com->mcr_image = mcr = com->mcr_image | mcr;
2589 cd_setreg(com, CD1400_MSVR1, mcr);
2590 cd_setreg(com, CD1400_MSVR2, mcr);
2593 com->mcr_image = mcr = com->mcr_image & ~mcr;
2594 cd_setreg(com, CD1400_MSVR1, mcr);
2595 cd_setreg(com, CD1400_MSVR2, mcr);
2599 restore_intr(intrsave);
2611 * Set our timeout period to 1 second if no polled devices are open.
2612 * Otherwise set it to max(1/200, 1/hz).
2613 * Enable timeouts iff some device is open.
2615 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2618 for (unit = 0; unit < NSIO; ++unit) {
2619 com = com_addr(unit);
2620 if (com != NULL && com->tp != NULL
2621 && com->tp->t_state & TS_ISOPEN) {
2624 if (com->poll || com->poll_output) {
2625 sio_timeout = hz > 200 ? hz / 200 : 1;
2632 sio_timeouts_until_log = hz / sio_timeout;
2633 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2636 /* Flush error messages, if any. */
2637 sio_timeouts_until_log = 1;
2638 comwakeup((void *)NULL);
2639 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2650 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2654 * Recover from lost output interrupts.
2655 * Poll any lines that don't use interrupts.
2657 for (unit = 0; unit < NSIO; ++unit) {
2658 com = com_addr(unit);
2660 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2663 intrsave = save_intr();
2668 restore_intr(intrsave);
2674 * Check for and log errors, but not too often.
2676 if (--sio_timeouts_until_log > 0)
2678 sio_timeouts_until_log = hz / sio_timeout;
2679 for (unit = 0; unit < NSIO; ++unit) {
2682 com = com_addr(unit);
2685 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2690 intrsave = save_intr();
2693 delta = com->delta_error_counts[errnum];
2694 com->delta_error_counts[errnum] = 0;
2696 restore_intr(intrsave);
2699 total = com->error_counts[errnum] += delta;
2700 log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
2701 unit, delta, error_desc[errnum],
2702 delta == 1 ? "" : "s", total);
2708 disc_optim(tp, t, com)
2713 #ifndef SOFT_HOTCHAR
2718 * XXX can skip a lot more cases if Smarts. Maybe
2719 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2720 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2722 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2723 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2724 && (!(t->c_iflag & PARMRK)
2725 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2726 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2727 && linesw[tp->t_line].l_rint == ttyinput)
2728 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2730 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2731 com->hotchar = linesw[tp->t_line].l_hotchar;
2732 #ifndef SOFT_HOTCHAR
2733 opt = com->cor[2] & ~CD1400_COR3_SCD34;
2734 if (com->hotchar != 0) {
2735 cd_setreg(com, CD1400_SCHR3, com->hotchar);
2736 cd_setreg(com, CD1400_SCHR4, com->hotchar);
2737 opt |= CD1400_COR3_SCD34;
2739 if (opt != com->cor[2]) {
2740 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2741 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
2747 /* standard line discipline input routine */
2753 /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
2754 * bits, as they are done by the CD1400. Hardly worth the effort,
2755 * given that high-throughput sessions are raw anyhow.
2761 comspeed(speed, cy_clock, prescaler_io)
2774 if (speed < 0 || speed > 150000)
2777 /* determine which prescaler to use */
2778 for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
2779 prescaler_unit--, prescaler >>= 2) {
2780 if (cy_clock / prescaler / speed > 63)
2784 divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
2787 actual = cy_clock/prescaler/divider;
2789 /* 10 times error in percent: */
2790 error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
2792 /* 3.0% max error tolerance */
2793 if (error < -30 || error > 30)
2797 printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
2798 printf("divider = %d (%x)\n", divider, divider);
2799 printf("actual = %d\n", actual);
2800 printf("error = %d\n", error);
2803 *prescaler_io = prescaler_unit;
2808 cd1400_channel_cmd(com, cmd)
2812 cd1400_channel_cmd_wait(com);
2813 cd_setreg(com, CD1400_CCR, cmd);
2814 cd1400_channel_cmd_wait(com);
2818 cd1400_channel_cmd_wait(com)
2821 struct timeval start;
2825 if (cd_getreg(com, CD1400_CCR) == 0)
2829 if (cd_getreg(com, CD1400_CCR) == 0)
2832 usec = 1000000 * (tv.tv_sec - start.tv_sec) +
2833 tv.tv_usec - start.tv_usec;
2836 "cy%d: channel command timeout (%ld usec)\n",
2851 * We can't change the hardware's ETC state while there are any
2852 * characters in the tx fifo, since those characters would be
2853 * interpreted as commands! Unputting characters from the fifo
2854 * is difficult, so we wait up to 12 character times for the fifo
2855 * to drain. The command will be delayed for up to 2 character
2856 * times for the tx to become empty. Unputting characters from
2857 * the tx holding and shift registers is impossible, so we wait
2858 * for the tx to become empty so that the command is sure to be
2859 * executed soon after we issue it.
2861 intrsave = save_intr();
2864 if (com->etc == etc)
2866 if ((etc == CD1400_ETC_SENDBREAK
2867 && (com->etc == ETC_BREAK_STARTING
2868 || com->etc == ETC_BREAK_STARTED))
2869 || (etc == CD1400_ETC_STOPBREAK
2870 && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
2871 || com->etc == ETC_NONE))) {
2873 restore_intr(intrsave);
2877 cd_setreg(com, CD1400_SRER,
2879 = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
2882 restore_intr(intrsave);
2883 while (com->etc == etc
2884 && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
2893 struct com_s *basecom;
2900 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2901 car = com->unit & CD1400_CAR_CHAN;
2902 cy_align = com->cy_align;
2903 iobase = com->iobase;
2904 intrsave = save_intr();
2906 if (intrsave & PSL_I)
2908 if (basecom->car != car)
2909 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2910 val = cd_inb(iobase, reg, cy_align);
2911 if (intrsave & PSL_I)
2913 restore_intr(intrsave);
2918 cd_setreg(com, reg, val)
2923 struct com_s *basecom;
2929 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2930 car = com->unit & CD1400_CAR_CHAN;
2931 cy_align = com->cy_align;
2932 iobase = com->iobase;
2933 intrsave = save_intr();
2935 if (intrsave & PSL_I)
2937 if (basecom->car != car)
2938 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2939 cd_outb(iobase, reg, cy_align, val);
2940 if (intrsave & PSL_I)
2942 restore_intr(intrsave);
2956 com = com_addr(unit);
2957 printf("info for channel %d\n", unit);
2958 printf("------------------\n");
2959 printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
2960 printf("calls to upper layer:\t\t%d\n", cy_timeouts);
2963 iobase = com->iobase;
2965 printf("cd1400 base address:\\tt%p\n", iobase);
2966 printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
2967 printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
2968 com->cor[0], com->cor[1], com->cor[2]);
2969 printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
2970 cd_getreg(com, CD1400_SRER), com->intr_enable);
2971 printf("service request register:\t0x%02x\n",
2972 cd_inb(iobase, CD1400_SVRR, com->cy_align));
2973 printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
2974 cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
2975 printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
2976 cd_inb(iobase, CD1400_RIR, com->cy_align),
2977 cd_inb(iobase, CD1400_TIR, com->cy_align),
2978 cd_inb(iobase, CD1400_MIR, com->cy_align));
2980 printf("com state:\t\t\t0x%02x\n", com->state);
2981 printf("calls to comstart():\t\t%d (%d useful)\n",
2982 com->start_count, com->start_real);
2983 printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
2985 if (com->obufs[0].l_queued)
2986 ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
2987 if (com->obufs[1].l_queued)
2988 ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
2989 printf("tx buffer chars:\t\t%u\n", ocount);
2990 printf("received chars:\t\t\t%d\n", com->bytes_in);
2991 printf("received exceptions:\t\t%d\n", com->recv_exception);
2992 printf("modem signal deltas:\t\t%d\n", com->mdm);
2993 printf("transmitted chars:\t\t%d\n", com->bytes_out);
2997 printf("tty state:\t\t\t0x%08x\n", tp->t_state);
2999 "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
3000 tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
3002 printf("tty state:\t\t\tclosed\n");
3004 #endif /* CyDebug */