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>
76 #include <sys/interrupt.h>
77 #include <sys/kernel.h>
79 #include <sys/malloc.h>
80 #include <sys/mutex.h>
81 #include <sys/syslog.h>
84 #include <machine/psl.h>
86 #include <i386/isa/isa_device.h>
87 #include <i386/isa/cyreg.h>
88 #include <i386/isa/ic/cd1400.h>
91 #error "The cy device requires the old isa compatibility shims"
96 #include <machine/smptests.h> /** xxx_LOCK */
99 #define COM_LOCK() mtx_lock_spin(&com_mtx)
100 #define COM_UNLOCK() mtx_unlock_spin(&com_mtx)
104 #endif /* USE_COMLOCK */
113 extern struct mtx com_mtx;
116 * Dictionary so that I can name everything *sio* or *com* to compare with
117 * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
118 * simplify the comparision. These will go away.
120 #define LSR_BI CD1400_RDSR_BREAK
121 #define LSR_FE CD1400_RDSR_FE
122 #define LSR_OE CD1400_RDSR_OE
123 #define LSR_PE CD1400_RDSR_PE
124 #define MCR_DTR CD1400_MSVR2_DTR
125 #define MCR_RTS CD1400_MSVR1_RTS
126 #define MSR_CTS CD1400_MSVR2_CTS
127 #define MSR_DCD CD1400_MSVR2_CD
128 #define MSR_DSR CD1400_MSVR2_DSR
129 #define MSR_RI CD1400_MSVR2_RI
130 #define NSIO (NCY * CY_MAX_PORTS)
131 #define comconsole cyconsole
132 #define comdefaultrate cydefaultrate
133 #define com_events cy_events
134 #define comhardclose cyhardclose
135 #define commctl cymctl
136 #define comparam cyparam
137 #define comspeed cyspeed
138 #define comstart cystart
139 #define comwakeup cywakeup
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
162 #define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
164 /* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
165 #define CD1400_xIVR_CHAN_SHIFT 3
166 #define CD1400_xIVR_CHAN 0x1F
169 * ETC states. com->etc may also contain a hardware ETC command value,
170 * meaning that execution of that command is pending.
172 #define ETC_NONE 0 /* we depend on bzero() setting this */
173 #define ETC_BREAK_STARTING 1
174 #define ETC_BREAK_STARTED 2
175 #define ETC_BREAK_ENDING 3
176 #define ETC_BREAK_ENDED 4
178 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
180 #define CALLOUT_MASK 0x80
181 #define CONTROL_MASK 0x60
182 #define CONTROL_INIT_STATE 0x20
183 #define CONTROL_LOCK_STATE 0x40
184 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
185 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
187 * Not all of the magic is parametrized in the following macros. 16 and
188 * 0xff are related to the bitfields in a udev_t. CY_MAX_PORTS must be
189 * ((0xff & ~MINOR_MAGIC_MASK) + 1) for things to work.
191 #define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
192 | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
193 #define UNIT_TO_MINOR(unit) (((unit) / CY_MAX_PORTS) << 16 \
194 | (((unit) & 0xff) & ~MINOR_MAGIC_MASK))
198 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
199 * than the other bits so that they can be tested as a group without masking
202 * The following com and tty flags correspond closely:
203 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
205 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
206 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
207 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
208 * TS_FLUSH is not used.
209 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
210 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
212 #define CS_BUSY 0x80 /* output in progress */
213 #define CS_TTGO 0x40 /* output not stopped by XOFF */
214 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
215 #define CS_CHECKMSR 1 /* check of MSR scheduled */
216 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
217 #define CS_DTR_OFF 0x10 /* DTR held off */
218 #define CS_ODONE 4 /* output completed */
219 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
220 #define CSE_ODONE 1 /* output transmitted */
222 static char const * const error_desc[] = {
225 #define CE_INTERRUPT_BUF_OVERFLOW 1
226 "interrupt-level buffer overflow",
227 #define CE_TTY_BUF_OVERFLOW 2
228 "tty-level buffer overflow",
232 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
234 /* types. XXX - should be elsewhere */
235 typedef u_char bool_t; /* boolean */
236 typedef u_char volatile *cy_addr;
238 /* queue of linear buffers */
240 u_char *l_head; /* next char to process */
241 u_char *l_tail; /* one past the last char to process */
242 struct lbq *l_next; /* next in queue */
243 bool_t l_queued; /* nonzero if queued */
246 /* com device structure */
248 u_char state; /* miscellaneous flag bits */
249 bool_t active_out; /* nonzero if the callout device is open */
251 u_char cfcr_image; /* copy of value written to CFCR */
253 u_char etc; /* pending Embedded Transmit Command */
254 u_char extra_state; /* more flag bits, separate for order trick */
256 u_char fifo_image; /* copy of value written to FIFO */
258 u_char gfrcr_image; /* copy of value read from GFRCR */
260 bool_t hasfifo; /* nonzero for 16550 UARTs */
261 bool_t loses_outints; /* nonzero if device loses output interrupts */
263 u_char mcr_dtr; /* MCR bit that is wired to DTR */
264 u_char mcr_image; /* copy of value written to MCR */
265 u_char mcr_rts; /* MCR bit that is wired to RTS */
268 bool_t multiport; /* is this unit part of a multiport device? */
269 #endif /* COM_MULTIPORT */
270 bool_t no_irq; /* nonzero if irq is not attached */
271 bool_t poll; /* nonzero if polling is required */
272 bool_t poll_output; /* nonzero if polling for output is required */
274 int unit; /* unit number */
275 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
279 u_int wopeners; /* # processes waiting for DCD in open() */
282 * The high level of the driver never reads status registers directly
283 * because there would be too many side effects to handle conveniently.
284 * Instead, it reads copies of the registers stored here by the
287 u_char last_modem_status; /* last MSR read by intr handler */
288 u_char prev_modem_status; /* last MSR handled by high level */
290 u_char hotchar; /* ldisc-specific char to be handled ASAP */
291 u_char *ibuf; /* start of input buffer */
292 u_char *ibufend; /* end of input buffer */
293 u_char *ibufold; /* old input buffer, to be freed */
294 u_char *ihighwater; /* threshold in input buffer */
295 u_char *iptr; /* next free spot in input buffer */
296 int ibufsize; /* size of ibuf (not include error bytes) */
297 int ierroff; /* offset of error bytes in ibuf */
299 struct lbq obufq; /* head of queue of output buffers */
300 struct lbq obufs[2]; /* output buffers */
302 int cy_align; /* index for register alignment */
303 cy_addr cy_iobase; /* base address of this port's cyclom */
304 cy_addr iobase; /* base address of this port's cd1400 */
305 int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
307 struct tty *tp; /* cross reference */
310 struct termios it_in; /* should be in struct tty */
311 struct termios it_out;
314 struct termios lt_in; /* should be in struct tty */
315 struct termios lt_out;
318 bool_t do_dcd_timestamp;
319 struct timeval timestamp;
320 struct timeval dcd_timestamp;
322 u_long bytes_in; /* statistics */
324 u_int delta_error_counts[CE_NTYPES];
325 u_long error_counts[CE_NTYPES];
327 u_int recv_exception; /* exception chars received */
328 u_int mdm; /* modem signal changes */
330 u_int start_count; /* no. of calls to comstart() */
331 u_int start_real; /* no. of calls that did something */
333 u_char car; /* CD1400 CAR shadow (if first unit in cd) */
334 u_char channel_control;/* CD1400 CCR control command shadow */
335 u_char cor[3]; /* CD1400 COR1-3 shadows */
336 u_char intr_enable; /* CD1400 SRER shadow */
339 * Data area for output buffers. Someday we should build the output
340 * buffer queue without copying data.
346 /* PCI driver entry point. */
347 int cyattach_common(cy_addr cy_iobase, int cy_align);
350 static int cy_units(cy_addr cy_iobase, int cy_align);
351 static int sioattach(struct isa_device *dev);
352 static void cd1400_channel_cmd(struct com_s *com, int cmd);
353 static void cd1400_channel_cmd_wait(struct com_s *com);
354 static void cd_etc(struct com_s *com, int etc);
355 static int cd_getreg(struct com_s *com, int reg);
356 static void cd_setreg(struct com_s *com, int reg, int val);
357 static timeout_t siodtrwakeup;
358 static void comhardclose(struct com_s *com);
359 static void sioinput(struct com_s *com);
361 static void siointr1(struct com_s *com);
363 static int commctl(struct com_s *com, int bits, int how);
364 static int comparam(struct tty *tp, struct termios *t);
365 static void siopoll(void *arg);
366 static int sioprobe(struct isa_device *dev);
367 static void siosettimeout(void);
368 static int siosetwater(struct com_s *com, speed_t speed);
369 static int comspeed(speed_t speed, u_long cy_clock, int *prescaler_io);
370 static void comstart(struct tty *tp);
371 static void comstop(struct tty *tp, int rw);
372 static timeout_t comwakeup;
373 static void disc_optim(struct tty *tp, struct termios *t,
377 void cystatus(int unit);
380 static char driver_name[] = "cy";
382 /* table and macro for fast conversion from a unit number to its com struct */
383 static struct com_s *p_com_addr[NSIO];
384 #define com_addr(unit) (p_com_addr[unit])
386 struct isa_driver siodriver = {
387 INTR_TYPE_TTY | INTR_FAST,
392 COMPAT_ISA_DRIVER(cy, cydriver); /* XXX */
394 static d_open_t sioopen;
395 static d_close_t sioclose;
396 static d_write_t siowrite;
397 static d_ioctl_t sioioctl;
399 #define CDEV_MAJOR 48
400 static struct cdevsw sio_cdevsw = {
402 /* close */ sioclose,
404 /* write */ siowrite,
405 /* ioctl */ sioioctl,
408 /* strategy */ nostrategy,
409 /* name */ driver_name,
410 /* maj */ CDEV_MAJOR,
413 /* flags */ D_TTY | D_KQFILTER,
414 /* kqfilter */ ttykqfilter,
417 static int comconsole = -1;
418 static speed_t comdefaultrate = TTYDEF_SPEED;
419 static u_int com_events; /* input chars + weighted output completions */
421 static int sio_timeout;
422 static int sio_timeouts_until_log;
423 static struct callout_handle sio_timeout_handle
424 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
427 static u_int cd_inbs;
428 static u_int cy_inbs;
429 static u_int cd_outbs;
430 static u_int cy_outbs;
431 static u_int cy_svrr_probes;
432 static u_int cy_timeouts;
435 static int cy_chip_offset[] = {
436 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
438 static int cy_nr_cd1400s[NCY];
439 static int cy_total_devices;
440 #undef RxFifoThreshold
441 static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
445 struct isa_device *dev;
449 iobase = (cy_addr)dev->id_maddr;
451 /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
452 cy_inb(iobase, CY16_RESET, 0); /* XXX? */
453 DELAY(500); /* wait for the board to get its act together */
455 /* this is needed to get the board out of reset */
456 cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
459 return (cy_units(iobase, 0) == 0 ? 0 : -1);
463 cy_units(cy_iobase, cy_align)
468 u_char firmware_version;
472 for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
473 iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
475 /* wait for chip to become ready for new command */
476 for (i = 0; i < 10; i++) {
478 if (!cd_inb(iobase, CD1400_CCR, cy_align))
482 /* clear the GFRCR register */
483 cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
485 /* issue a reset command */
486 cd_outb(iobase, CD1400_CCR, cy_align,
487 CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
489 /* XXX bogus initialization to avoid a gcc bug/warning. */
490 firmware_version = 0;
492 /* wait for the CD1400 to initialize itself */
493 for (i = 0; i < 200; i++) {
496 /* retrieve firmware version */
497 firmware_version = cd_inb(iobase, CD1400_GFRCR,
499 if ((firmware_version & 0xf0) == 0x40)
504 * Anything in the 0x40-0x4F range is fine.
505 * If one CD1400 is bad then we don't support higher
506 * numbered good ones on this board.
508 if ((firmware_version & 0xf0) != 0x40)
516 struct isa_device *isdp;
520 adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
526 * This kludge is to allow ISA/PCI device specifications in the
527 * kernel config file to be in any order.
529 if (isdp->id_unit != adapter) {
530 printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
531 isdp->id_unit = adapter; /* XXX */
533 isdp->id_ointr = siointr;
534 /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
539 cyattach_common(cy_iobase, cy_align)
545 u_char firmware_version;
551 adapter = cy_total_devices;
552 if ((u_int)adapter >= NCY) {
554 "cy%d: can't attach adapter: insufficient cy devices configured\n",
558 ncyu = cy_units(cy_iobase, cy_align);
561 cy_nr_cd1400s[adapter] = ncyu;
564 unit = adapter * CY_MAX_PORTS;
565 for (cyu = 0; cyu < ncyu; ++cyu) {
568 iobase = (cy_addr) (cy_iobase
569 + (cy_chip_offset[cyu] << cy_align));
570 firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
572 /* Set up a receive timeout period of than 1+ ms. */
573 cd_outb(iobase, CD1400_PPR, cy_align,
574 howmany(CY_CLOCK(firmware_version)
575 / CD1400_PPR_PRESCALER, 1000));
577 for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
581 com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT | M_ZERO);
585 com->gfrcr_image = firmware_version;
586 if (CY_RTS_DTR_SWAPPED(firmware_version)) {
587 com->mcr_dtr = MCR_RTS;
588 com->mcr_rts = MCR_DTR;
589 com->mcr_rts_reg = CD1400_MSVR2;
591 com->mcr_dtr = MCR_DTR;
592 com->mcr_rts = MCR_RTS;
593 com->mcr_rts_reg = CD1400_MSVR1;
595 com->dtr_wait = 3 * hz;
596 com->obufs[0].l_head = com->obuf1;
597 com->obufs[1].l_head = com->obuf2;
599 com->cy_align = cy_align;
600 com->cy_iobase = cy_iobase;
601 com->iobase = iobase;
602 com->car = ~CD1400_CAR_CHAN;
605 * We don't use all the flags from <sys/ttydefaults.h> since they
606 * are only relevant for logins. It's important to have echo off
607 * initially so that the line doesn't start blathering before the
608 * echo flag can be turned off.
610 com->it_in.c_iflag = 0;
611 com->it_in.c_oflag = 0;
612 com->it_in.c_cflag = TTYDEF_CFLAG;
613 com->it_in.c_lflag = 0;
614 if (unit == comconsole) {
615 com->it_in.c_iflag = TTYDEF_IFLAG;
616 com->it_in.c_oflag = TTYDEF_OFLAG;
617 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
618 com->it_in.c_lflag = TTYDEF_LFLAG;
619 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
621 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
625 termioschars(&com->it_in);
626 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
627 com->it_out = com->it_in;
630 com_addr(unit) = com;
633 if (sio_ih == NULL) {
634 swi_add(&tty_ithd, "tty:cy", siopoll, NULL, SWI_TTY, 0,
637 minorbase = UNIT_TO_MINOR(unit);
638 make_dev(&sio_cdevsw, minorbase,
639 UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
640 unit % CY_MAX_PORTS);
641 make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
642 UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
643 unit % CY_MAX_PORTS);
644 make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
645 UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
646 unit % CY_MAX_PORTS);
647 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
648 UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
649 unit % CY_MAX_PORTS);
650 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
651 UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
652 unit % CY_MAX_PORTS);
653 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
654 UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
655 unit % CY_MAX_PORTS);
659 /* ensure an edge for the next interrupt */
660 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
666 sioopen(dev, flag, mode, td)
680 unit = MINOR_TO_UNIT(mynor);
681 if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
683 if (mynor & CONTROL_MASK)
685 tp = dev->si_tty = com->tp = ttymalloc(com->tp);
688 * We jump to this label after all non-interrupted sleeps to pick
689 * up any changes of the device state.
692 while (com->state & CS_DTR_OFF) {
693 error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
697 if (tp->t_state & TS_ISOPEN) {
699 * The device is open, so everything has been initialized.
702 if (mynor & CALLOUT_MASK) {
703 if (!com->active_out) {
708 if (com->active_out) {
709 if (flag & O_NONBLOCK) {
713 error = tsleep(&com->active_out,
714 TTIPRI | PCATCH, "cybi", 0);
720 if (tp->t_state & TS_XCLUDE &&
727 * The device isn't open, so there are no conflicts.
728 * Initialize it. Initialization is done twice in many
729 * cases: to preempt sleeping callin opens if we are
730 * callout, and to complete a callin open after DCD rises.
732 tp->t_oproc = comstart;
733 tp->t_stop = comstop;
734 tp->t_param = comparam;
736 tp->t_termios = mynor & CALLOUT_MASK
737 ? com->it_out : com->it_in;
739 /* Encode per-board unit in LIVR for access in intr routines. */
740 cd_setreg(com, CD1400_LIVR,
741 (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
743 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
745 com->poll = com->no_irq;
746 com->poll_output = com->loses_outints;
749 error = comparam(tp, &tp->t_termios);
756 * (Re)enable and flush fifos.
758 * Certain SMC chips cause problems if the fifos
759 * are enabled while input is ready. Turn off the
760 * fifo if necessary to clear the input. We test
761 * the input ready bit after enabling the fifos
762 * since we've already enabled them in comparam()
763 * and to handle races between enabling and fresh
767 outb(iobase + com_fifo,
768 FIFO_RCV_RST | FIFO_XMT_RST
771 if (!(inb(com->line_status_port) & LSR_RXRDY))
773 outb(iobase + com_fifo, 0);
775 (void) inb(com->data_port);
781 (void) inb(com->line_status_port);
782 (void) inb(com->data_port);
783 com->prev_modem_status = com->last_modem_status
784 = inb(com->modem_status_port);
785 outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
791 * Flush fifos. This requires a full channel reset which
792 * also disables the transmitter and receiver. Recover
795 cd1400_channel_cmd(com,
796 CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
797 cd1400_channel_cmd(com, com->channel_control);
801 com->prev_modem_status = com->last_modem_status
802 = cd_getreg(com, CD1400_MSVR2);
803 cd_setreg(com, CD1400_SRER,
805 = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
810 * Handle initial DCD. Callout devices get a fake initial
811 * DCD (trapdoor DCD). If we are callout, then any sleeping
812 * callin opens get woken up and resume sleeping on "cybi"
813 * instead of "cydcd".
816 * XXX `mynor & CALLOUT_MASK' should be
817 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
818 * TRAPDOOR_CARRIER is the default initial state for callout
819 * devices and SOFT_CARRIER is like CLOCAL except it hides
822 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
823 (*linesw[tp->t_line].l_modem)(tp, 1);
826 * Wait for DCD if necessary.
828 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
829 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
831 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
837 error = (*linesw[tp->t_line].l_open)(dev, tp);
838 disc_optim(tp, &tp->t_termios, com);
839 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
840 com->active_out = TRUE;
844 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
850 sioclose(dev, flag, mode, td)
862 if (mynor & CONTROL_MASK)
864 com = com_addr(MINOR_TO_UNIT(mynor));
867 cd_etc(com, CD1400_ETC_STOPBREAK);
868 (*linesw[tp->t_line].l_close)(tp, flag);
869 disc_optim(tp, &tp->t_termios, com);
870 comstop(tp, FREAD | FWRITE);
875 #ifdef broken /* session holds a ref to the tty; can't deallocate */
892 iobase = com->iobase;
896 com->poll_output = FALSE;
898 com->do_timestamp = 0;
900 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
906 cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
909 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
914 outb(iobase + com_ier, 0);
918 cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
923 if ((tp->t_cflag & HUPCL)
925 * XXX we will miss any carrier drop between here and the
926 * next open. Perhaps we should watch DCD even when the
927 * port is closed; it is not sufficient to check it at
928 * the next open because it might go up and down while
929 * we're not watching.
932 && !(com->prev_modem_status & MSR_DCD)
933 && !(com->it_in.c_cflag & CLOCAL))
934 || !(tp->t_state & TS_ISOPEN)) {
935 (void)commctl(com, TIOCM_DTR, DMBIC);
937 /* Disable receiver (leave transmitter enabled). */
938 com->channel_control = CD1400_CCR_CMDCHANCTL
941 cd1400_channel_cmd(com, com->channel_control);
943 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
944 timeout(siodtrwakeup, com, com->dtr_wait);
945 com->state |= CS_DTR_OFF;
952 * Disable fifos so that they are off after controlled
953 * reboots. Some BIOSes fail to detect 16550s when the
956 outb(iobase + com_fifo, 0);
959 com->active_out = FALSE;
960 wakeup(&com->active_out);
961 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
966 siowrite(dev, uio, flag)
976 if (mynor & CONTROL_MASK)
979 unit = MINOR_TO_UNIT(mynor);
980 tp = com_addr(unit)->tp;
982 * (XXX) We disallow virtual consoles if the physical console is
983 * a serial port. This is in case there is a display attached that
984 * is not the console. In that situation we don't need/want the X
985 * server taking over the console.
987 if (constty != NULL && unit == comconsole)
990 /* XXX duplicate ttwrite(), but without so much output processing on
991 * CR & LF chars. Hardly worth the effort, given that high-throughput
992 * sessions are raw anyhow.
995 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
1005 com = (struct com_s *)chan;
1006 com->state &= ~CS_DTR_OFF;
1007 wakeup(&com->dtr_wait);
1012 * a) needs to be called with COM_LOCK() held, and
1013 * b) needs to return with COM_LOCK() held.
1027 if (!(tp->t_state & TS_ISOPEN)) {
1028 com_events -= (com->iptr - com->ibuf);
1029 com->iptr = com->ibuf;
1032 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1034 * Avoid the grotesquely inefficient lineswitch routine
1035 * (ttyinput) in "raw" mode. It usually takes about 450
1036 * instructions (that's without canonical processing or echo!).
1037 * slinput is reasonably fast (usually 40 instructions plus
1043 * This may look odd, but it is using save-and-enable
1044 * semantics instead of the save-and-disable semantics
1045 * that are used everywhere else.
1049 incc = com->iptr - buf;
1050 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1051 && (com->state & CS_RTS_IFLOW
1052 || tp->t_iflag & IXOFF)
1053 && !(tp->t_state & TS_TBLOCK))
1055 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1056 += b_to_q((char *)buf, incc, &tp->t_rawq);
1060 tp->t_rawcc += incc;
1062 if (tp->t_state & TS_TTSTOP
1063 && (tp->t_iflag & IXANY
1064 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1065 tp->t_state &= ~TS_TTSTOP;
1066 tp->t_lflag &= ~FLUSHO;
1071 } while (buf < com->iptr);
1075 * This may look odd, but it is using save-and-enable
1076 * semantics instead of the save-and-disable semantics
1077 * that are used everywhere else.
1081 line_status = buf[com->ierroff];
1084 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1085 if (line_status & LSR_BI)
1086 recv_data |= TTY_BI;
1087 if (line_status & LSR_FE)
1088 recv_data |= TTY_FE;
1089 if (line_status & LSR_OE)
1090 recv_data |= TTY_OE;
1091 if (line_status & LSR_PE)
1092 recv_data |= TTY_PE;
1094 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1097 } while (buf < com->iptr);
1099 com_events -= (com->iptr - com->ibuf);
1100 com->iptr = com->ibuf;
1103 * There is now room for another low-level buffer full of input,
1104 * so enable RTS if it is now disabled and there is room in the
1105 * high-level buffer.
1107 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
1108 !(tp->t_state & TS_TBLOCK))
1110 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1112 cd_setreg(com, com->mcr_rts_reg,
1113 com->mcr_image |= com->mcr_rts);
1128 COM_LOCK(); /* XXX could this be placed down lower in the loop? */
1130 baseu = unit * CY_MAX_PORTS;
1131 cy_align = com_addr(baseu)->cy_align;
1132 cy_iobase = com_addr(baseu)->cy_iobase;
1134 /* check each CD1400 in turn */
1135 for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
1136 iobase = (cy_addr) (cy_iobase
1137 + (cy_chip_offset[cyu] << cy_align));
1138 /* poll to see if it has any work */
1139 status = cd_inb(iobase, CD1400_SVRR, cy_align);
1145 /* service requests as appropriate, giving priority to RX */
1146 if (status & CD1400_SVRR_RXRDY) {
1158 save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
1160 /* enter rx service */
1161 cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
1162 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1163 = save_rir & CD1400_CAR_CHAN;
1165 serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
1166 com = com_addr(baseu
1167 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1168 & CD1400_xIVR_CHAN));
1170 /* ack receive service */
1171 serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
1173 com = com_addr(baseu +
1174 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1175 & CD1400_xIVR_CHAN));
1178 if (serv_type & CD1400_RIVR_EXCEPTION) {
1179 ++com->recv_exception;
1180 line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
1181 /* break/unnattached error bits or real input? */
1182 recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
1183 #ifndef SOFT_HOTCHAR
1184 if (line_status & CD1400_RDSR_SPECIAL
1185 && com->hotchar != 0)
1186 swi_sched(sio_ih, 0);
1189 #if 1 /* XXX "intelligent" PFO error handling would break O error handling */
1190 if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
1192 Don't store PE if IGNPAR and BI if IGNBRK,
1193 this hack allows "raw" tty optimization
1194 works even if IGN* is set.
1196 if ( com->tp == NULL
1197 || !(com->tp->t_state & TS_ISOPEN)
1198 || ((line_status & (LSR_PE|LSR_FE))
1199 && (com->tp->t_iflag & IGNPAR))
1200 || ((line_status & LSR_BI)
1201 && (com->tp->t_iflag & IGNBRK)))
1203 if ( (line_status & (LSR_PE|LSR_FE))
1204 && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
1205 && ((line_status & LSR_FE)
1206 || ((line_status & LSR_PE)
1207 && (com->tp->t_iflag & INPCK))))
1213 if (com->hotchar != 0 && recv_data == com->hotchar)
1214 swi_sched(sio_ih, 0);
1217 if (ioptr >= com->ibufend)
1218 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
1220 if (com->do_timestamp)
1221 microtime(&com->timestamp);
1223 ioptr[0] = recv_data;
1224 ioptr[com->ierroff] = line_status;
1225 com->iptr = ++ioptr;
1226 if (ioptr == com->ihighwater
1227 && com->state & CS_RTS_IFLOW)
1229 outb(com->modem_ctl_port,
1230 com->mcr_image &= ~MCR_RTS);
1232 cd_outb(iobase, com->mcr_rts_reg,
1237 if (line_status & LSR_OE)
1238 CE_RECORD(com, CE_OVERRUN);
1244 count = cd_inb(iobase, CD1400_RDCR, cy_align);
1247 com->bytes_in += count;
1249 ifree = com->ibufend - ioptr;
1250 if (count > ifree) {
1252 com_events += ifree;
1254 if (com->do_timestamp)
1255 microtime(&com->timestamp);
1257 recv_data = cd_inb(iobase,
1261 if (com->hotchar != 0
1264 swi_sched(sio_ih, 0);
1266 ioptr[0] = recv_data;
1267 ioptr[com->ierroff] = 0;
1269 } while (--ifree != 0);
1271 com->delta_error_counts
1272 [CE_INTERRUPT_BUF_OVERFLOW] += count;
1274 recv_data = cd_inb(iobase, CD1400_RDSR,
1277 if (com->hotchar != 0
1278 && recv_data == com->hotchar)
1279 swi_sched(sio_ih, 0);
1281 } while (--count != 0);
1283 if (com->do_timestamp)
1284 microtime(&com->timestamp);
1285 if (ioptr <= com->ihighwater
1286 && ioptr + count > com->ihighwater
1287 && com->state & CS_RTS_IFLOW)
1289 outb(com->modem_ctl_port,
1290 com->mcr_image &= ~MCR_RTS);
1292 cd_outb(iobase, com->mcr_rts_reg,
1297 com_events += count;
1299 recv_data = cd_inb(iobase, CD1400_RDSR,
1302 if (com->hotchar != 0
1303 && recv_data == com->hotchar)
1304 swi_sched(sio_ih, 0);
1306 ioptr[0] = recv_data;
1307 ioptr[com->ierroff] = 0;
1309 } while (--count != 0);
1315 /* terminate service context */
1317 cd_outb(iobase, CD1400_RIR, cy_align,
1319 & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
1321 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1324 if (status & CD1400_SVRR_MDMCH) {
1326 u_char modem_status;
1334 save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
1336 /* enter modem service */
1337 cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
1338 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1339 = save_mir & CD1400_CAR_CHAN;
1341 com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
1342 + (save_mir & CD1400_MIR_CHAN));
1344 /* ack modem service */
1345 vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
1347 com = com_addr(baseu
1348 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1349 & CD1400_xIVR_CHAN));
1352 modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
1353 if (modem_status != com->last_modem_status) {
1354 if (com->do_dcd_timestamp
1355 && !(com->last_modem_status & MSR_DCD)
1356 && modem_status & MSR_DCD)
1357 microtime(&com->dcd_timestamp);
1360 * Schedule high level to handle DCD changes. Note
1361 * that we don't use the delta bits anywhere. Some
1362 * UARTs mess them up, and it's easy to remember the
1363 * previous bits and calculate the delta.
1365 com->last_modem_status = modem_status;
1366 if (!(com->state & CS_CHECKMSR)) {
1367 com_events += LOTS_OF_EVENTS;
1368 com->state |= CS_CHECKMSR;
1369 swi_sched(sio_ih, 0);
1372 #ifdef SOFT_CTS_OFLOW
1373 /* handle CTS change immediately for crisp flow ctl */
1374 if (com->state & CS_CTS_OFLOW) {
1375 if (modem_status & MSR_CTS) {
1376 com->state |= CS_ODEVREADY;
1377 if (com->state >= (CS_BUSY | CS_TTGO
1379 && !(com->intr_enable
1380 & CD1400_SRER_TXRDY))
1381 cd_outb(iobase, CD1400_SRER,
1385 & ~CD1400_SRER_TXMPTY
1386 | CD1400_SRER_TXRDY);
1388 com->state &= ~CS_ODEVREADY;
1389 if (com->intr_enable
1390 & CD1400_SRER_TXRDY)
1391 cd_outb(iobase, CD1400_SRER,
1395 & ~CD1400_SRER_TXRDY
1396 | CD1400_SRER_TXMPTY);
1402 /* terminate service context */
1404 cd_outb(iobase, CD1400_MIR, cy_align,
1406 & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
1408 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1411 if (status & CD1400_SVRR_TXRDY) {
1420 save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
1422 /* enter tx service */
1423 cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
1424 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1425 = save_tir & CD1400_CAR_CHAN;
1427 com = com_addr(baseu
1428 + cyu * CD1400_NO_OF_CHANNELS
1429 + (save_tir & CD1400_TIR_CHAN));
1431 /* ack transmit service */
1432 vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
1434 com = com_addr(baseu
1435 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1436 & CD1400_xIVR_CHAN));
1439 if (com->etc != ETC_NONE) {
1440 if (com->intr_enable & CD1400_SRER_TXRDY) {
1442 * Here due to sloppy SRER_TXRDY
1443 * enabling. Ignore. Come back when
1446 cd_outb(iobase, CD1400_SRER, cy_align,
1449 & ~CD1400_SRER_TXRDY)
1450 | CD1400_SRER_TXMPTY);
1451 goto terminate_tx_service;
1454 case CD1400_ETC_SENDBREAK:
1455 case CD1400_ETC_STOPBREAK:
1457 * Start the command. Come back on
1458 * next tx empty interrupt, hopefully
1459 * after command has been executed.
1461 cd_outb(iobase, CD1400_COR2, cy_align,
1462 com->cor[1] |= CD1400_COR2_ETC);
1463 cd_outb(iobase, CD1400_TDR, cy_align,
1465 cd_outb(iobase, CD1400_TDR, cy_align,
1467 if (com->etc == CD1400_ETC_SENDBREAK)
1468 com->etc = ETC_BREAK_STARTING;
1470 com->etc = ETC_BREAK_ENDING;
1471 goto terminate_tx_service;
1472 case ETC_BREAK_STARTING:
1474 * BREAK is now on. Continue with
1475 * SRER_TXMPTY processing, hopefully
1478 com->etc = ETC_BREAK_STARTED;
1480 case ETC_BREAK_STARTED:
1482 * Came back due to sloppy SRER_TXMPTY
1483 * enabling. Hope again.
1486 case ETC_BREAK_ENDING:
1488 * BREAK is now off. Continue with
1489 * SRER_TXMPTY processing and don't
1490 * come back. The SWI handler will
1491 * restart tx interrupts if necessary.
1493 cd_outb(iobase, CD1400_COR2, cy_align,
1495 &= ~CD1400_COR2_ETC);
1496 com->etc = ETC_BREAK_ENDED;
1497 if (!(com->state & CS_ODONE)) {
1498 com_events += LOTS_OF_EVENTS;
1499 com->state |= CS_ODONE;
1500 swi_sched(sio_ih, 0);
1503 case ETC_BREAK_ENDED:
1505 * Shouldn't get here. Hope again.
1510 if (com->intr_enable & CD1400_SRER_TXMPTY) {
1511 if (!(com->extra_state & CSE_ODONE)) {
1512 com_events += LOTS_OF_EVENTS;
1513 com->extra_state |= CSE_ODONE;
1514 swi_sched(sio_ih, 0);
1516 cd_outb(iobase, CD1400_SRER, cy_align,
1518 &= ~CD1400_SRER_TXMPTY);
1519 goto terminate_tx_service;
1521 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
1525 ioptr = com->obufq.l_head;
1526 ocount = com->obufq.l_tail - ioptr;
1527 if (ocount > CD1400_TX_FIFO_SIZE)
1528 ocount = CD1400_TX_FIFO_SIZE;
1529 com->bytes_out += ocount;
1531 cd_outb(iobase, CD1400_TDR, cy_align,
1533 while (--ocount != 0);
1534 com->obufq.l_head = ioptr;
1535 if (ioptr >= com->obufq.l_tail) {
1538 qp = com->obufq.l_next;
1539 qp->l_queued = FALSE;
1542 com->obufq.l_head = qp->l_head;
1543 com->obufq.l_tail = qp->l_tail;
1544 com->obufq.l_next = qp;
1546 /* output just completed */
1547 com->state &= ~CS_BUSY;
1550 * The setting of CSE_ODONE may be
1551 * stale here. We currently only
1552 * use it when CS_BUSY is set, and
1553 * fixing it when we clear CS_BUSY
1556 if (com->extra_state & CSE_ODONE) {
1557 com_events -= LOTS_OF_EVENTS;
1558 com->extra_state &= ~CSE_ODONE;
1561 cd_outb(iobase, CD1400_SRER, cy_align,
1564 & ~CD1400_SRER_TXRDY)
1565 | CD1400_SRER_TXMPTY);
1567 if (!(com->state & CS_ODONE)) {
1568 com_events += LOTS_OF_EVENTS;
1569 com->state |= CS_ODONE;
1571 /* handle at high level ASAP */
1572 swi_sched(sio_ih, 0);
1577 /* terminate service context */
1578 terminate_tx_service:
1580 cd_outb(iobase, CD1400_TIR, cy_align,
1582 & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
1584 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1589 /* ensure an edge for the next interrupt */
1590 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
1592 swi_sched(sio_ih, 0);
1606 sioioctl(dev, cmd, data, flag, td)
1618 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1620 struct termios term;
1624 com = com_addr(MINOR_TO_UNIT(mynor));
1625 if (mynor & CONTROL_MASK) {
1628 switch (mynor & CONTROL_MASK) {
1629 case CONTROL_INIT_STATE:
1630 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
1632 case CONTROL_LOCK_STATE:
1633 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
1636 return (ENODEV); /* /dev/nodev */
1643 *ct = *(struct termios *)data;
1646 *(struct termios *)data = *ct;
1649 *(int *)data = TTYDISC;
1652 bzero(data, sizeof(struct winsize));
1659 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1660 term = tp->t_termios;
1662 error = ttsetcompat(tp, &cmd, data, &term);
1666 data = (caddr_t)&term;
1668 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1670 struct termios *dt = (struct termios *)data;
1671 struct termios *lt = mynor & CALLOUT_MASK
1672 ? &com->lt_out : &com->lt_in;
1674 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1675 | (dt->c_iflag & ~lt->c_iflag);
1676 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1677 | (dt->c_oflag & ~lt->c_oflag);
1678 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1679 | (dt->c_cflag & ~lt->c_cflag);
1680 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1681 | (dt->c_lflag & ~lt->c_lflag);
1682 for (cc = 0; cc < NCCS; ++cc)
1683 if (lt->c_cc[cc] != 0)
1684 dt->c_cc[cc] = tp->t_cc[cc];
1685 if (lt->c_ispeed != 0)
1686 dt->c_ispeed = tp->t_ispeed;
1687 if (lt->c_ospeed != 0)
1688 dt->c_ospeed = tp->t_ospeed;
1690 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1691 if (error != ENOIOCTL)
1694 error = ttioctl(tp, cmd, data, flag);
1695 disc_optim(tp, &tp->t_termios, com);
1696 if (error != ENOIOCTL) {
1703 outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
1705 cd_etc(com, CD1400_ETC_SENDBREAK);
1710 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1712 cd_etc(com, CD1400_ETC_STOPBREAK);
1716 (void)commctl(com, TIOCM_DTR, DMBIS);
1719 (void)commctl(com, TIOCM_DTR, DMBIC);
1722 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
1723 * changes get undone on the next call to comparam().
1726 (void)commctl(com, *(int *)data, DMSET);
1729 (void)commctl(com, *(int *)data, DMBIS);
1732 (void)commctl(com, *(int *)data, DMBIC);
1735 *(int *)data = commctl(com, 0, DMGET);
1738 /* must be root since the wait applies to following logins */
1744 com->dtr_wait = *(int *)data * hz / 100;
1747 *(int *)data = com->dtr_wait * 100 / hz;
1750 com->do_timestamp = TRUE;
1751 *(struct timeval *)data = com->timestamp;
1753 case TIOCDCDTIMESTAMP:
1754 com->do_dcd_timestamp = TRUE;
1755 *(struct timeval *)data = com->dcd_timestamp;
1773 if (com_events == 0)
1776 for (unit = 0; unit < NSIO; ++unit) {
1781 com = com_addr(unit);
1787 * XXX forget any events related to closed devices
1788 * (actually never opened devices) so that we don't
1793 incc = com->iptr - com->ibuf;
1794 com->iptr = com->ibuf;
1795 if (com->state & CS_CHECKMSR) {
1796 incc += LOTS_OF_EVENTS;
1797 com->state &= ~CS_CHECKMSR;
1804 "sio%d: %d events for device with no tp\n",
1808 if (com->iptr != com->ibuf) {
1815 if (com->state & CS_CHECKMSR) {
1816 u_char delta_modem_status;
1821 delta_modem_status = com->last_modem_status
1822 ^ com->prev_modem_status;
1823 com->prev_modem_status = com->last_modem_status;
1824 com_events -= LOTS_OF_EVENTS;
1825 com->state &= ~CS_CHECKMSR;
1828 if (delta_modem_status & MSR_DCD)
1829 (*linesw[tp->t_line].l_modem)
1830 (tp, com->prev_modem_status & MSR_DCD);
1832 if (com->extra_state & CSE_ODONE) {
1835 com_events -= LOTS_OF_EVENTS;
1836 com->extra_state &= ~CSE_ODONE;
1839 if (!(com->state & CS_BUSY)) {
1840 tp->t_state &= ~TS_BUSY;
1843 if (com->etc != ETC_NONE) {
1844 if (com->etc == ETC_BREAK_ENDED)
1845 com->etc = ETC_NONE;
1849 if (com->state & CS_ODONE) {
1852 com_events -= LOTS_OF_EVENTS;
1853 com->state &= ~CS_ODONE;
1856 (*linesw[tp->t_line].l_start)(tp);
1858 if (com_events == 0)
1861 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;
2033 if (opt != com->cor[1]) {
2034 cor_change |= CD1400_CCR_COR2;
2035 cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
2041 * set channel option register 3 -
2042 * receiver FIFO interrupt threshold
2045 opt = RxFifoThreshold;
2047 if (t->c_lflag & ICANON)
2048 opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
2050 /* detect and transparently handle START and STOP chars */
2051 opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
2053 if (opt != com->cor[2]) {
2054 cor_change |= CD1400_CCR_COR3;
2055 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2058 /* notify the CD1400 if COR1-3 have changed */
2060 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
2063 * set channel option register 4 -
2066 * received exception processing
2070 opt |= CD1400_COR4_IGNCR;
2073 * we need a new ttyinput() for this, as we don't want to
2074 * have ICRNL && INLCR being done in both layers, or to have
2075 * synchronisation problems
2078 opt |= CD1400_COR4_ICRNL;
2080 opt |= CD1400_COR4_INLCR;
2083 opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
2085 * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
2086 * so only tell the hardware about -brkint if -parmrk.
2088 if (!(iflag & (BRKINT | PARMRK)))
2089 opt |= CD1400_COR4_NOBRKINT;
2091 /* XXX using this "intelligence" breaks reporting of overruns. */
2093 opt |= CD1400_COR4_PFO_DISCARD;
2096 opt |= CD1400_COR4_PFO_ESC;
2098 opt |= CD1400_COR4_PFO_NUL;
2101 opt |= CD1400_COR4_PFO_EXCEPTION;
2103 cd_setreg(com, CD1400_COR4, opt);
2106 * set channel option register 5 -
2110 opt |= CD1400_COR5_ISTRIP;
2111 if (t->c_iflag & IEXTEN)
2112 /* enable LNEXT (e.g. ctrl-v quoting) handling */
2113 opt |= CD1400_COR5_LNEXT;
2115 if (t->c_oflag & ONLCR)
2116 opt |= CD1400_COR5_ONLCR;
2117 if (t->c_oflag & OCRNL)
2118 opt |= CD1400_COR5_OCRNL;
2120 cd_setreg(com, CD1400_COR5, opt);
2123 * We always generate modem status change interrupts for CD changes.
2124 * Among other things, this is necessary to track TS_CARR_ON for
2125 * pstat to print even when the driver doesn't care. CD changes
2126 * should be rare so interrupts for them are not worth extra code to
2127 * avoid. We avoid interrupts for other modem status changes (except
2128 * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
2129 * simplest and best.
2133 * set modem change option register 1
2134 * generate modem interrupts on which 1 -> 0 input transitions
2135 * also controls auto-DTR output flow-control, which we don't use
2137 opt = CD1400_MCOR1_CDzd;
2138 #ifdef SOFT_CTS_OFLOW
2139 if (cflag & CCTS_OFLOW)
2140 opt |= CD1400_MCOR1_CTSzd;
2142 cd_setreg(com, CD1400_MCOR1, opt);
2145 * set modem change option register 2
2146 * generate modem interrupts on specific 0 -> 1 input transitions
2148 opt = CD1400_MCOR2_CDod;
2149 #ifdef SOFT_CTS_OFLOW
2150 if (cflag & CCTS_OFLOW)
2151 opt |= CD1400_MCOR2_CTSod;
2153 cd_setreg(com, CD1400_MCOR2, opt);
2156 * XXX should have done this long ago, but there is too much state
2157 * to change all atomically.
2162 com->state &= ~CS_TTGO;
2163 if (!(tp->t_state & TS_TTSTOP))
2164 com->state |= CS_TTGO;
2165 if (cflag & CRTS_IFLOW) {
2166 com->state |= CS_RTS_IFLOW;
2168 * If CS_RTS_IFLOW just changed from off to on, the change
2169 * needs to be propagated to MCR_RTS. This isn't urgent,
2170 * so do it later by calling comstart() instead of repeating
2171 * a lot of code from comstart() here.
2173 } else if (com->state & CS_RTS_IFLOW) {
2174 com->state &= ~CS_RTS_IFLOW;
2176 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2177 * on here, since comstart() won't do it later.
2180 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2182 cd_setreg(com, com->mcr_rts_reg,
2183 com->mcr_image |= com->mcr_rts);
2188 * Set up state to handle output flow control.
2189 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2190 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2192 com->state |= CS_ODEVREADY;
2193 #ifdef SOFT_CTS_OFLOW
2194 com->state &= ~CS_CTS_OFLOW;
2195 if (cflag & CCTS_OFLOW) {
2196 com->state |= CS_CTS_OFLOW;
2197 if (!(com->last_modem_status & MSR_CTS))
2198 com->state &= ~CS_ODEVREADY;
2201 /* XXX shouldn't call functions while intrs are disabled. */
2202 disc_optim(tp, t, com);
2205 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2206 * unconditionally, but that defeated the careful discarding of
2207 * stale input in sioopen().
2209 if (com->state >= (CS_BUSY | CS_TTGO))
2212 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2213 if (!(com->intr_enable & CD1400_SRER_TXRDY))
2214 cd_setreg(com, CD1400_SRER,
2216 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2217 | CD1400_SRER_TXRDY);
2219 if (com->intr_enable & CD1400_SRER_TXRDY)
2220 cd_setreg(com, CD1400_SRER,
2222 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2223 | CD1400_SRER_TXMPTY);
2230 if (com->ibufold != NULL) {
2231 free(com->ibufold, M_DEVBUF);
2232 com->ibufold = NULL;
2238 siosetwater(com, speed)
2248 * Make the buffer size large enough to handle a softtty interrupt
2249 * latency of about 2 ticks without loss of throughput or data
2250 * (about 3 ticks if input flow control is not used or not honoured,
2251 * but a bit less for CS5-CS7 modes).
2253 cp4ticks = speed / 10 / hz * 4;
2254 for (ibufsize = 128; ibufsize < cp4ticks;)
2256 if (ibufsize == com->ibufsize) {
2261 * Allocate input buffer. The extra factor of 2 in the size is
2262 * to allow for an error byte for each input byte.
2264 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2269 /* Initialize non-critical variables. */
2270 com->ibufold = com->ibuf;
2271 com->ibufsize = ibufsize;
2274 tp->t_ififosize = 2 * ibufsize;
2275 tp->t_ispeedwat = (speed_t)-1;
2276 tp->t_ospeedwat = (speed_t)-1;
2280 * Read current input buffer, if any. Continue with interrupts
2285 if (com->iptr != com->ibuf)
2289 * Initialize critical variables, including input buffer watermarks.
2290 * The external device is asked to stop sending when the buffer
2291 * exactly reaches high water, or when the high level requests it.
2292 * The high level is notified immediately (rather than at a later
2293 * clock tick) when this watermark is reached.
2294 * The buffer size is chosen so the watermark should almost never
2296 * The low watermark is invisibly 0 since the buffer is always
2297 * emptied all at once.
2299 com->iptr = com->ibuf = ibuf;
2300 com->ibufend = ibuf + ibufsize;
2301 com->ierroff = ibufsize;
2302 com->ihighwater = ibuf + 3 * ibufsize / 4;
2320 unit = DEV_TO_UNIT(tp->t_dev);
2321 com = com_addr(unit);
2331 if (tp->t_state & TS_TTSTOP) {
2332 com->state &= ~CS_TTGO;
2333 if (com->intr_enable & CD1400_SRER_TXRDY)
2334 cd_setreg(com, CD1400_SRER,
2336 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2337 | CD1400_SRER_TXMPTY);
2339 com->state |= CS_TTGO;
2340 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
2341 && !(com->intr_enable & CD1400_SRER_TXRDY))
2342 cd_setreg(com, CD1400_SRER,
2344 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2345 | CD1400_SRER_TXRDY);
2347 if (tp->t_state & TS_TBLOCK) {
2348 if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
2350 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2352 cd_setreg(com, com->mcr_rts_reg,
2353 com->mcr_image &= ~com->mcr_rts);
2356 if (!(com->mcr_image & com->mcr_rts)
2357 && com->iptr < com->ihighwater
2358 && com->state & CS_RTS_IFLOW)
2360 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2362 cd_setreg(com, com->mcr_rts_reg,
2363 com->mcr_image |= com->mcr_rts);
2368 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2373 if (tp->t_outq.c_cc != 0) {
2377 if (!com->obufs[0].l_queued) {
2381 com->obufs[0].l_tail
2382 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2384 com->obufs[0].l_next = NULL;
2385 com->obufs[0].l_queued = TRUE;
2388 if (com->state & CS_BUSY) {
2389 qp = com->obufq.l_next;
2390 while ((next = qp->l_next) != NULL)
2392 qp->l_next = &com->obufs[0];
2394 com->obufq.l_head = com->obufs[0].l_head;
2395 com->obufq.l_tail = com->obufs[0].l_tail;
2396 com->obufq.l_next = &com->obufs[0];
2397 com->state |= CS_BUSY;
2398 if (com->state >= (CS_BUSY | CS_TTGO
2400 cd_setreg(com, CD1400_SRER,
2403 & ~CD1400_SRER_TXMPTY)
2404 | CD1400_SRER_TXRDY);
2409 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2413 com->obufs[1].l_tail
2414 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2416 com->obufs[1].l_next = NULL;
2417 com->obufs[1].l_queued = TRUE;
2420 if (com->state & CS_BUSY) {
2421 qp = com->obufq.l_next;
2422 while ((next = qp->l_next) != NULL)
2424 qp->l_next = &com->obufs[1];
2426 com->obufq.l_head = com->obufs[1].l_head;
2427 com->obufq.l_tail = com->obufs[1].l_tail;
2428 com->obufq.l_next = &com->obufs[1];
2429 com->state |= CS_BUSY;
2430 if (com->state >= (CS_BUSY | CS_TTGO
2432 cd_setreg(com, CD1400_SRER,
2435 & ~CD1400_SRER_TXMPTY)
2436 | CD1400_SRER_TXRDY);
2441 tp->t_state |= TS_BUSY;
2450 if (com->state >= (CS_BUSY | CS_TTGO))
2451 siointr1(com); /* fake interrupt to start output */
2467 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2472 com->obufs[0].l_queued = FALSE;
2473 com->obufs[1].l_queued = FALSE;
2474 if (com->extra_state & CSE_ODONE) {
2475 com_events -= LOTS_OF_EVENTS;
2476 com->extra_state &= ~CSE_ODONE;
2477 if (com->etc != ETC_NONE) {
2478 if (com->etc == ETC_BREAK_ENDED)
2479 com->etc = ETC_NONE;
2483 com->tp->t_state &= ~TS_BUSY;
2484 if (com->state & CS_ODONE)
2485 com_events -= LOTS_OF_EVENTS;
2486 com->state &= ~(CS_ODONE | CS_BUSY);
2489 /* XXX no way to reset only input fifo. */
2490 com_events -= (com->iptr - com->ibuf);
2491 com->iptr = com->ibuf;
2497 if (rw & FWRITE && com->etc == ETC_NONE)
2498 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
2503 commctl(com, bits, how)
2512 if (com->channel_control & CD1400_CCR_RCVEN)
2514 mcr = com->mcr_image;
2515 if (mcr & com->mcr_dtr)
2517 if (mcr & com->mcr_rts)
2518 /* XXX wired on for Cyclom-8Ys */
2522 * We must read the modem status from the hardware because
2523 * we don't generate modem status change interrupts for all
2524 * changes, so com->prev_modem_status is not guaranteed to
2525 * be up to date. This is safe, unlike for sio, because
2526 * reading the status register doesn't clear pending modem
2527 * status change interrupts.
2529 msr = cd_getreg(com, CD1400_MSVR2);
2538 /* XXX not connected except for Cyclom-16Y? */
2543 if (bits & TIOCM_DTR)
2544 mcr |= com->mcr_dtr;
2545 if (bits & TIOCM_RTS)
2546 mcr |= com->mcr_rts;
2551 com->mcr_image = mcr;
2552 cd_setreg(com, CD1400_MSVR1, mcr);
2553 cd_setreg(com, CD1400_MSVR2, mcr);
2556 com->mcr_image = mcr = com->mcr_image | mcr;
2557 cd_setreg(com, CD1400_MSVR1, mcr);
2558 cd_setreg(com, CD1400_MSVR2, mcr);
2561 com->mcr_image = mcr = com->mcr_image & ~mcr;
2562 cd_setreg(com, CD1400_MSVR1, mcr);
2563 cd_setreg(com, CD1400_MSVR2, mcr);
2579 * Set our timeout period to 1 second if no polled devices are open.
2580 * Otherwise set it to max(1/200, 1/hz).
2581 * Enable timeouts iff some device is open.
2583 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2586 for (unit = 0; unit < NSIO; ++unit) {
2587 com = com_addr(unit);
2588 if (com != NULL && com->tp != NULL
2589 && com->tp->t_state & TS_ISOPEN) {
2592 if (com->poll || com->poll_output) {
2593 sio_timeout = hz > 200 ? hz / 200 : 1;
2600 sio_timeouts_until_log = hz / sio_timeout;
2601 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2604 /* Flush error messages, if any. */
2605 sio_timeouts_until_log = 1;
2606 comwakeup((void *)NULL);
2607 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2618 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2622 * Recover from lost output interrupts.
2623 * Poll any lines that don't use interrupts.
2625 for (unit = 0; unit < NSIO; ++unit) {
2626 com = com_addr(unit);
2628 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2639 * Check for and log errors, but not too often.
2641 if (--sio_timeouts_until_log > 0)
2643 sio_timeouts_until_log = hz / sio_timeout;
2644 for (unit = 0; unit < NSIO; ++unit) {
2647 com = com_addr(unit);
2650 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2656 delta = com->delta_error_counts[errnum];
2657 com->delta_error_counts[errnum] = 0;
2662 total = com->error_counts[errnum] += delta;
2663 log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
2664 unit, delta, error_desc[errnum],
2665 delta == 1 ? "" : "s", total);
2671 disc_optim(tp, t, com)
2676 #ifndef SOFT_HOTCHAR
2681 * XXX can skip a lot more cases if Smarts. Maybe
2682 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2683 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2685 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2686 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2687 && (!(t->c_iflag & PARMRK)
2688 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2689 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2690 && linesw[tp->t_line].l_rint == ttyinput)
2691 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2693 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2694 com->hotchar = linesw[tp->t_line].l_hotchar;
2695 #ifndef SOFT_HOTCHAR
2696 opt = com->cor[2] & ~CD1400_COR3_SCD34;
2697 if (com->hotchar != 0) {
2698 cd_setreg(com, CD1400_SCHR3, com->hotchar);
2699 cd_setreg(com, CD1400_SCHR4, com->hotchar);
2700 opt |= CD1400_COR3_SCD34;
2702 if (opt != com->cor[2]) {
2703 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2704 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
2710 /* standard line discipline input routine */
2716 /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
2717 * bits, as they are done by the CD1400. Hardly worth the effort,
2718 * given that high-throughput sessions are raw anyhow.
2724 comspeed(speed, cy_clock, prescaler_io)
2737 if (speed < 0 || speed > 150000)
2740 /* determine which prescaler to use */
2741 for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
2742 prescaler_unit--, prescaler >>= 2) {
2743 if (cy_clock / prescaler / speed > 63)
2747 divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
2750 actual = cy_clock/prescaler/divider;
2752 /* 10 times error in percent: */
2753 error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
2755 /* 3.0% max error tolerance */
2756 if (error < -30 || error > 30)
2760 printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
2761 printf("divider = %d (%x)\n", divider, divider);
2762 printf("actual = %d\n", actual);
2763 printf("error = %d\n", error);
2766 *prescaler_io = prescaler_unit;
2771 cd1400_channel_cmd(com, cmd)
2775 cd1400_channel_cmd_wait(com);
2776 cd_setreg(com, CD1400_CCR, cmd);
2777 cd1400_channel_cmd_wait(com);
2781 cd1400_channel_cmd_wait(com)
2784 struct timeval start;
2788 if (cd_getreg(com, CD1400_CCR) == 0)
2792 if (cd_getreg(com, CD1400_CCR) == 0)
2795 usec = 1000000 * (tv.tv_sec - start.tv_sec) +
2796 tv.tv_usec - start.tv_usec;
2799 "cy%d: channel command timeout (%ld usec)\n",
2813 * We can't change the hardware's ETC state while there are any
2814 * characters in the tx fifo, since those characters would be
2815 * interpreted as commands! Unputting characters from the fifo
2816 * is difficult, so we wait up to 12 character times for the fifo
2817 * to drain. The command will be delayed for up to 2 character
2818 * times for the tx to become empty. Unputting characters from
2819 * the tx holding and shift registers is impossible, so we wait
2820 * for the tx to become empty so that the command is sure to be
2821 * executed soon after we issue it.
2825 if (com->etc == etc)
2827 if ((etc == CD1400_ETC_SENDBREAK
2828 && (com->etc == ETC_BREAK_STARTING
2829 || com->etc == ETC_BREAK_STARTED))
2830 || (etc == CD1400_ETC_STOPBREAK
2831 && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
2832 || com->etc == ETC_NONE))) {
2838 cd_setreg(com, CD1400_SRER,
2840 = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
2844 while (com->etc == etc
2845 && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
2854 struct com_s *basecom;
2861 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2862 car = com->unit & CD1400_CAR_CHAN;
2863 cy_align = com->cy_align;
2864 iobase = com->iobase;
2865 eflags = read_eflags();
2869 if (basecom->car != car)
2870 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2871 val = cd_inb(iobase, reg, cy_align);
2879 cd_setreg(com, reg, val)
2884 struct com_s *basecom;
2890 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2891 car = com->unit & CD1400_CAR_CHAN;
2892 cy_align = com->cy_align;
2893 iobase = com->iobase;
2894 eflags = read_eflags();
2898 if (basecom->car != car)
2899 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2900 cd_outb(iobase, reg, cy_align, val);
2917 com = com_addr(unit);
2918 printf("info for channel %d\n", unit);
2919 printf("------------------\n");
2920 printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
2921 printf("calls to upper layer:\t\t%d\n", cy_timeouts);
2924 iobase = com->iobase;
2926 printf("cd1400 base address:\\tt%p\n", iobase);
2927 printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
2928 printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
2929 com->cor[0], com->cor[1], com->cor[2]);
2930 printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
2931 cd_getreg(com, CD1400_SRER), com->intr_enable);
2932 printf("service request register:\t0x%02x\n",
2933 cd_inb(iobase, CD1400_SVRR, com->cy_align));
2934 printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
2935 cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
2936 printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
2937 cd_inb(iobase, CD1400_RIR, com->cy_align),
2938 cd_inb(iobase, CD1400_TIR, com->cy_align),
2939 cd_inb(iobase, CD1400_MIR, com->cy_align));
2941 printf("com state:\t\t\t0x%02x\n", com->state);
2942 printf("calls to comstart():\t\t%d (%d useful)\n",
2943 com->start_count, com->start_real);
2944 printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
2946 if (com->obufs[0].l_queued)
2947 ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
2948 if (com->obufs[1].l_queued)
2949 ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
2950 printf("tx buffer chars:\t\t%u\n", ocount);
2951 printf("received chars:\t\t\t%d\n", com->bytes_in);
2952 printf("received exceptions:\t\t%d\n", com->recv_exception);
2953 printf("modem signal deltas:\t\t%d\n", com->mdm);
2954 printf("transmitted chars:\t\t%d\n", com->bytes_out);
2958 printf("tty state:\t\t\t0x%08x\n", tp->t_state);
2960 "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
2961 tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
2963 printf("tty state:\t\t\tclosed\n");
2965 #endif /* CyDebug */