4 * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
6 * Copyright (C) 1990, 1992, 1998 Specialix International,
7 * Copyright (C) 1993, Andy Rutter <andy@acronym.co.uk>
8 * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
10 * Originally derived from: SunOS 4.x version
11 * Ported from BSDI version to FreeBSD by Peter Wemm.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notices, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notices, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by Andy Rutter of
24 * Advanced Methods and Tools Ltd. based on original information
25 * from Specialix International.
26 * 4. Neither the name of Advanced Methods and Tools, nor Specialix
27 * International may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
33 * NO EVENT SHALL THE AUTHORS BE LIABLE.
35 * $FreeBSD: src/sys/dev/si/si.c,v 1.101.2.1 2001/02/26 04:23:06 jlemon Exp $
39 static const char si_copyright1[] = "@(#) Copyright (C) Specialix International, 1990,1992,1998",
40 si_copyright2[] = "@(#) Copyright (C) Andy Rutter 1993",
41 si_copyright3[] = "@(#) Copyright (C) Peter Wemm 2000";
44 #include "opt_compat.h"
45 #include "opt_debug_si.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
50 #include <sys/ioctl_compat.h>
56 #include <sys/fcntl.h>
57 #include <sys/dkstat.h>
58 #include <sys/kernel.h>
59 #include <sys/malloc.h>
60 #include <sys/sysctl.h>
63 #include <sys/thread2.h>
65 #include <machine/clock.h>
70 #include <machine/stdarg.h>
77 * This device driver is designed to interface the Specialix International
78 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA,
79 * EISA or PCI bus machine.
81 * The controller is interfaced to the host via dual port RAM
84 * The code for the Host 1 (very old ISA cards) has not been tested.
87 #define POLL /* turn on poller to scan for lost interrupts */
88 #define REALPOLL /* on each poll, scan for work regardless */
89 #define POLLHZ (hz/10) /* 10 times per second */
90 #define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE)
91 #define INT_COUNT 25000 /* max of 125 ints per second */
92 #define JET_INT_COUNT 100 /* max of 100 ints per second */
93 #define RXINT_COUNT 1 /* one rxint per 10 milliseconds */
95 enum si_mctl { GET, SET, BIS, BIC };
97 static void si_command(struct si_port *, int, int);
98 static int si_modem(struct si_port *, enum si_mctl, int);
99 static void si_write_enable(struct si_port *, int);
100 static int si_Sioctl(cdev_t, u_long, caddr_t, int, struct ucred *);
101 static void si_start(struct tty *);
102 static void si_stop(struct tty *, int);
103 static timeout_t si_lstart;
104 static void si_disc_optim(struct tty *tp, struct termios *t,struct si_port *pp);
105 static void sihardclose(struct si_port *pp);
106 static void sidtrwakeup(void *chan);
109 static char *si_mctl2str(enum si_mctl cmd);
112 static int siparam(struct tty *, struct termios *);
114 static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip);
115 static char * si_modulename(int host_type, int uart_type);
117 static d_open_t siopen;
118 static d_close_t siclose;
119 static d_write_t siwrite;
120 static d_ioctl_t siioctl;
122 static struct dev_ops si_ops = {
129 .d_kqfilter = ttykqfilter,
130 .d_revoke = ttyrevoke
133 static int si_Nports;
134 static int si_Nmodules;
135 static int si_debug = 0; /* data, not bss, so it's patchable */
137 SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, "");
139 static struct tty *si__tty;
141 static int si_numunits;
142 static struct callout poll_ch;
144 devclass_t si_devclass;
146 #ifndef B2000 /* not standard, but the hardware knows it. */
149 static struct speedtab bdrates[] = {
150 { B75, CLK75, }, /* 0x0 */
151 { B110, CLK110, }, /* 0x1 */
152 { B150, CLK150, }, /* 0x3 */
153 { B300, CLK300, }, /* 0x4 */
154 { B600, CLK600, }, /* 0x5 */
155 { B1200, CLK1200, }, /* 0x6 */
156 { B2000, CLK2000, }, /* 0x7 */
157 { B2400, CLK2400, }, /* 0x8 */
158 { B4800, CLK4800, }, /* 0x9 */
159 { B9600, CLK9600, }, /* 0xb */
160 { B19200, CLK19200, }, /* 0xc */
161 { B38400, CLK38400, }, /* 0x2 (out of order!) */
162 { B57600, CLK57600, }, /* 0xd */
163 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */
168 /* populated with approx character/sec rates - translated at card
169 * initialisation time to chars per tick of the clock */
170 static int done_chartimes = 0;
171 static struct speedtab chartimes[] = {
188 static volatile int in_intr = 0; /* Inside interrupt handler? */
191 static int si_pollrate; /* in addition to irq */
192 static int si_realpoll = 0; /* poll HW on timer */
194 SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, "");
195 SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, "");
197 static int init_finished = 0;
198 static void si_poll(void *);
202 * Array of adapter types and the corresponding RAM size. The order of
203 * entries here MUST match the ordinal of the adapter type.
205 static char *si_type[] = {
208 "SIMCA", /* FreeBSD does not support Microchannel */
217 * We have to make an 8 bit version of bcopy, since some cards can't
218 * deal with 32 bit I/O
221 si_bcopy(const void *src, void *dst, size_t len)
223 const uint8_t *src_byte = (const uint8_t *)src;
224 uint8_t *dst_byte = (uint8_t *)dst;
227 *dst_byte++ = *src_byte++;
231 si_vbcopy(const volatile void *src, void *dst, size_t len)
233 volatile const uint8_t *src_byte = (volatile const uint8_t *)src;
234 uint8_t *dst_byte = (uint8_t *)dst;
237 *dst_byte++ = *src_byte++;
241 si_bcopyv(const void *src, volatile void *dst, size_t len)
243 const uint8_t *src_byte = (const uint8_t *)src;
244 volatile uint8_t *dst_byte = (volatile uint8_t *)dst;
247 *dst_byte++ = *src_byte++;
251 * Attach the device. Initialize the card.
254 siattach(device_t dev)
259 volatile struct si_channel *ccbp;
260 volatile struct si_reg *regp;
261 volatile caddr_t maddr;
262 struct si_module *modp;
264 struct speedtab *spt;
265 int nmodule, nport, x, y;
269 if ((poll_ch.c_flags & CALLOUT_DID_INIT) == 0)
270 callout_init_mp(&poll_ch);
272 lwkt_gettoken(&tty_token);
273 sc = device_get_softc(dev);
274 unit = device_get_unit(dev);
276 sc->sc_typename = si_type[sc->sc_type];
277 if (si_numunits < unit + 1)
278 si_numunits = unit + 1;
280 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit));
283 if (si_pollrate == 0) {
284 si_pollrate = POLLHZ; /* in addition to irq */
286 si_realpoll = 1; /* scan always */
291 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %p maddr: %p\n", unit,
292 sc->sc_typename, sc->sc_paddr, sc->sc_maddr));
294 sc->sc_ports = NULL; /* mark as uninitialised */
296 maddr = sc->sc_maddr;
298 /* Stop the CPU first so it won't stomp around while we load */
300 switch (sc->sc_type) {
302 outb(sc->sc_iobase + 2, sc->sc_irq << 4);
305 *(maddr+SIPCIRESET) = 0;
307 case SIJETPCI: /* fall through to JET ISA */
309 *(maddr+SIJETCONFIG) = 0;
312 *(maddr+SIPLRESET) = 0;
315 *(maddr+SIRESET) = 0;
317 default: /* this should never happen */
318 kprintf("si%d: unsupported configuration\n", unit);
319 lwkt_reltoken(&tty_token);
324 /* OK, now lets download the download code */
326 if (SI_ISJET(sc->sc_type)) {
327 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n",
328 unit, si3_t225_dsize));
329 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr,
331 DPRINT((0, DBG_DOWNLOAD,
332 "si%d: jet_bootstrap: nbytes %d -> %x\n",
333 unit, si3_t225_bsize, si3_t225_bootloadaddr));
334 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr,
337 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n",
338 unit, si2_z280_dsize));
339 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr,
343 /* Now start the CPU */
345 switch (sc->sc_type) {
347 /* modify the download code to tell it that it's on an EISA */
349 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4);
350 (void)inb(sc->sc_iobase + 3); /* reset interrupt */
353 /* modify the download code to tell it that it's on a PCI */
355 *(maddr+SIPCIRESET) = 1;
356 *(maddr+SIPCIINTCL) = 0;
359 *(maddr+SIJETRESET) = 0;
360 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN;
363 *(maddr+SIJETRESET) = 0;
364 switch (sc->sc_irq) {
366 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90;
369 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0;
372 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0;
375 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0;
378 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0;
383 *(maddr+SIRESET_CL) = 0;
384 *(maddr+SIINTCL_CL) = 0;
387 *(maddr+SIPLRESET) = 0x10;
388 switch (sc->sc_irq) {
390 *(maddr+SIPLIRQ11) = 0x10;
393 *(maddr+SIPLIRQ12) = 0x10;
396 *(maddr+SIPLIRQ15) = 0x10;
399 *(maddr+SIPLIRQCLR) = 0x10;
401 default: /* this should _REALLY_ never happen */
402 kprintf("si%d: Uh, it was supported a second ago...\n", unit);
403 lwkt_reltoken(&tty_token);
407 DELAY(1000000); /* wait around for a second */
409 regp = (struct si_reg *)maddr;
411 /* wait max of 5 sec for init OK */
412 while (regp->initstat == 0 && y++ < 10) {
415 switch (regp->initstat) {
417 kprintf("si%d: startup timeout - aborting\n", unit);
418 sc->sc_type = SIEMPTY;
419 lwkt_reltoken(&tty_token);
422 if (SI_ISJET(sc->sc_type)) {
423 /* set throttle to 100 times per second */
424 regp->int_count = JET_INT_COUNT;
425 /* rx_intr_count is a NOP in Jet */
427 /* set throttle to 125 times per second */
428 regp->int_count = INT_COUNT;
429 /* rx intr max of 25 times per second */
430 regp->rx_int_count = RXINT_COUNT;
432 regp->int_pending = 0; /* no intr pending */
433 regp->int_scounter = 0; /* reset counter */
437 * No modules found, so give up on this one.
439 kprintf("si%d: %s - no ports found\n", unit,
440 si_type[sc->sc_type]);
441 lwkt_reltoken(&tty_token);
444 kprintf("si%d: download code version error - initstat %x\n",
445 unit, regp->initstat);
446 lwkt_reltoken(&tty_token);
451 * First time around the ports just count them in order
452 * to allocate some memory.
455 modp = (struct si_module *)(maddr + 0x80);
457 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr %p\n", unit, modp));
458 switch (modp->sm_type) {
460 DPRINT((0, DBG_DOWNLOAD,
461 "si%d: Found old TA4 module, 4 ports\n",
466 DPRINT((0, DBG_DOWNLOAD,
467 "si%d: Found old TA8 module, 8 ports\n",
472 DPRINT((0, DBG_DOWNLOAD,
473 "si%d: Found ASIC TA4 module, 4 ports\n",
478 DPRINT((0, DBG_DOWNLOAD,
479 "si%d: Found ASIC TA8 module, 8 ports\n",
484 DPRINT((0, DBG_DOWNLOAD,
485 "si%d: Found CD1400 module, 8 ports\n",
490 DPRINT((0, DBG_DOWNLOAD,
491 "si%d: Found SXDC module, 8 ports\n",
496 kprintf("si%d: unknown module type %d\n",
497 unit, modp->sm_type);
501 /* this was limited in firmware and is also a driver issue */
502 if ((nport + x) > SI_MAXPORTPERCARD) {
503 kprintf("si%d: extra ports ignored\n", unit);
512 if (modp->sm_next == 0)
514 modp = (struct si_module *)
515 (maddr + (unsigned)(modp->sm_next & 0x7fff));
517 sc->sc_ports = kmalloc(sizeof(struct si_port) * nport,
518 M_DEVBUF, M_WAITOK | M_ZERO);
519 sc->sc_nport = nport;
520 for (n = 0; n < nport; ++n) {
521 callout_init_mp(&sc->sc_ports[n].lstart_ch);
522 callout_init_mp(&sc->sc_ports[n].dtr_ch);
526 * allocate tty structures for ports
528 tp = kmalloc(sizeof(*tp) * nport, M_DEVBUF, M_WAITOK | M_ZERO);
532 * Scan round the ports again, this time initialising.
536 modp = (struct si_module *)(maddr + 0x80);
537 uart_type = 1000; /* arbitary, > uchar_max */
539 switch (modp->sm_type) {
562 ccbp = (struct si_channel *)((char *)modp + 0x100);
563 if (uart_type == 1000)
564 uart_type = ccbp->type;
565 else if (uart_type != ccbp->type)
566 kprintf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n",
568 ccbp->type, si_modulename(sc->sc_type, ccbp->type),
569 uart_type, si_modulename(sc->sc_type, uart_type));
571 for (x = 0; x < nport; x++, pp++, ccbp++) {
572 pp->sp_ccb = ccbp; /* save the address */
574 pp->sp_pend = IDLE_CLOSE;
575 pp->sp_state = 0; /* internal flag */
576 pp->sp_dtr_wait = 3 * hz;
577 pp->sp_iin.c_iflag = TTYDEF_IFLAG;
578 pp->sp_iin.c_oflag = TTYDEF_OFLAG;
579 pp->sp_iin.c_cflag = TTYDEF_CFLAG;
580 pp->sp_iin.c_lflag = TTYDEF_LFLAG;
581 termioschars(&pp->sp_iin);
582 pp->sp_iin.c_ispeed = pp->sp_iin.c_ospeed =
584 pp->sp_iout = pp->sp_iin;
587 if (modp->sm_next == 0) {
588 kprintf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n",
594 si_modulename(sc->sc_type, uart_type));
597 modp = (struct si_module *)
598 (maddr + (unsigned)(modp->sm_next & 0x7fff));
600 if (done_chartimes == 0) {
601 for (spt = chartimes ; spt->sp_speed != -1; spt++) {
602 if ((spt->sp_code /= hz) == 0)
608 for (x = 0; x < sc->sc_nport; x++) {
609 /* sync with the manuals that start at 1 */
610 y = x + 1 + unit * (1 << SI_CARDSHIFT);
611 make_dev(&si_ops, x, 0, 0, 0600, "ttyA%02d", y);
612 make_dev(&si_ops, x + 0x00080, 0, 0, 0600, "cuaA%02d", y);
613 make_dev(&si_ops, x + 0x10000, 0, 0, 0600, "ttyiA%02d", y);
614 make_dev(&si_ops, x + 0x10080, 0, 0, 0600, "cuaiA%02d", y);
615 make_dev(&si_ops, x + 0x20000, 0, 0, 0600, "ttylA%02d", y);
616 make_dev(&si_ops, x + 0x20080, 0, 0, 0600, "cualA%02d", y);
618 make_dev(&si_ops, 0x40000, 0, 0, 0600, "si_control");
619 lwkt_reltoken(&tty_token);
624 siopen(struct dev_open_args *ap)
626 cdev_t dev = ap->a_head.a_dev;
631 volatile struct si_channel *ccbp;
633 int mynor = minor(dev);
635 lwkt_gettoken(&tty_token);
636 /* quickly let in /dev/si_control */
637 if (IS_CONTROLDEV(mynor)) {
638 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0))) {
639 lwkt_reltoken(&tty_token);
642 lwkt_reltoken(&tty_token);
646 card = SI_CARD(mynor);
647 sc = devclass_get_softc(si_devclass, card);
649 lwkt_reltoken(&tty_token);
653 if (sc->sc_type == SIEMPTY) {
654 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: type %s??\n",
655 card, sc->sc_typename));
656 lwkt_reltoken(&tty_token);
660 port = SI_PORT(mynor);
661 if (port >= sc->sc_nport) {
662 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: nports %d\n",
663 card, sc->sc_nport));
664 lwkt_reltoken(&tty_token);
670 * We've now got a device, so start the poller.
672 if (init_finished == 0) {
673 callout_reset(&poll_ch, si_pollrate, si_poll, NULL);
678 /* initial/lock device */
679 if (IS_STATE(mynor)) {
680 lwkt_reltoken(&tty_token);
684 pp = sc->sc_ports + port;
685 tp = pp->sp_tty; /* the "real" tty */
687 ccbp = pp->sp_ccb; /* Find control block */
688 DPRINT((pp, DBG_ENTRY|DBG_OPEN, "siopen(%s,%x,%x)\n",
689 devtoname(dev), ap->a_oflags, ap->a_devtype));
691 crit_enter(); /* Keep others out */
695 while (pp->sp_state & SS_DTR_OFF) {
696 error = tsleep(&pp->sp_dtr_wait, PCATCH, "sidtr", 0);
701 if (tp->t_state & TS_ISOPEN) {
703 * The device is open, so everything has been initialised.
706 if (IS_CALLOUT(mynor)) {
707 if (!pp->sp_active_out) {
712 if (pp->sp_active_out) {
713 if (ap->a_oflags & O_NONBLOCK) {
717 error = tsleep(&pp->sp_active_out,
724 if (tp->t_state & TS_XCLUDE &&
725 priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
726 DPRINT((pp, DBG_OPEN|DBG_FAIL,
727 "already open and EXCLUSIVE set\n"));
733 * The device isn't open, so there are no conflicts.
734 * Initialize it. Avoid sleep... :-)
736 DPRINT((pp, DBG_OPEN, "first open\n"));
737 tp->t_oproc = si_start;
738 tp->t_stop = si_stop;
739 tp->t_param = siparam;
741 tp->t_termios = mynor & SI_CALLOUT_MASK
742 ? pp->sp_iout : pp->sp_iin;
744 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
746 ++pp->sp_wopeners; /* in case of sleep in siparam */
748 error = siparam(tp, &tp->t_termios);
753 /* XXX: we should goto_top if siparam slept */
755 /* set initial DCD state */
756 pp->sp_last_hi_ip = ccbp->hi_ip;
757 if ((pp->sp_last_hi_ip & IP_DCD) || IS_CALLOUT(mynor)) {
758 (*linesw[tp->t_line].l_modem)(tp, 1);
762 /* whoops! we beat the close! */
763 if (pp->sp_state & SS_CLOSING) {
764 /* try and stop it from proceeding to bash the hardware */
765 pp->sp_state &= ~SS_CLOSING;
769 * Wait for DCD if necessary
771 if (!(tp->t_state & TS_CARR_ON) &&
772 !IS_CALLOUT(mynor) &&
773 !(tp->t_cflag & CLOCAL) &&
774 !(ap->a_oflags & O_NONBLOCK)) {
776 DPRINT((pp, DBG_OPEN, "sleeping for carrier\n"));
777 error = tsleep(TSA_CARR_ON(tp), PCATCH, "sidcd", 0);
784 error = (*linesw[tp->t_line].l_open)(dev, tp);
785 si_disc_optim(tp, &tp->t_termios, pp);
786 if (tp->t_state & TS_ISOPEN && IS_CALLOUT(mynor))
787 pp->sp_active_out = TRUE;
789 pp->sp_state |= SS_OPEN; /* made it! */
794 DPRINT((pp, DBG_OPEN, "leaving siopen\n"));
796 if (!(tp->t_state & TS_ISOPEN) && pp->sp_wopeners == 0)
799 lwkt_reltoken(&tty_token);
804 siclose(struct dev_close_args *ap)
806 cdev_t dev = ap->a_head.a_dev;
810 int mynor = minor(dev);
812 if (IS_SPECIAL(mynor))
815 lwkt_gettoken(&tty_token);
818 pp = MINOR2PP(mynor);
821 DPRINT((pp, DBG_ENTRY|DBG_CLOSE, "siclose(%s,%x,%x) sp_state:%x\n",
822 devtoname(dev), ap->a_fflag, ap->a_devtype, pp->sp_state));
824 /* did we sleep and loose a race? */
825 if (pp->sp_state & SS_CLOSING) {
826 /* error = ESOMETING? */
830 /* begin race detection.. */
831 pp->sp_state |= SS_CLOSING;
833 si_write_enable(pp, 0); /* block writes for ttywait() */
835 /* THIS MAY SLEEP IN TTYWAIT!!! */
836 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
838 si_write_enable(pp, 1);
840 /* did we sleep and somebody started another open? */
841 if (!(pp->sp_state & SS_CLOSING)) {
842 /* error = ESOMETING? */
845 /* ok. we are now still on the right track.. nuke the hardware */
847 if (pp->sp_state & SS_LSTART) {
848 callout_stop(&pp->lstart_ch);
849 pp->sp_state &= ~SS_LSTART;
852 si_stop(tp, FREAD | FWRITE);
856 pp->sp_state &= ~SS_OPEN;
859 DPRINT((pp, DBG_CLOSE|DBG_EXIT, "close done, returning\n"));
861 lwkt_reltoken(&tty_token);
866 sihardclose(struct si_port *pp)
869 volatile struct si_channel *ccbp;
872 lwkt_gettoken(&tty_token);
875 ccbp = pp->sp_ccb; /* Find control block */
876 if (tp->t_cflag & HUPCL ||
877 (!pp->sp_active_out &&
878 !(ccbp->hi_ip & IP_DCD) &&
879 !(pp->sp_iin.c_cflag & CLOCAL)) ||
880 !(tp->t_state & TS_ISOPEN)) {
882 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS);
883 (void) si_command(pp, FCLOSE, SI_NOWAIT);
885 if (pp->sp_dtr_wait != 0) {
886 callout_reset(&pp->dtr_ch, pp->sp_dtr_wait,
888 pp->sp_state |= SS_DTR_OFF;
892 pp->sp_active_out = FALSE;
893 wakeup((caddr_t)&pp->sp_active_out);
894 wakeup(TSA_CARR_ON(tp));
896 lwkt_reltoken(&tty_token);
902 * called at splsoftclock()...
905 sidtrwakeup(void *chan)
910 lwkt_gettoken(&tty_token);
912 pp = (struct si_port *)chan;
913 pp->sp_state &= ~SS_DTR_OFF;
914 wakeup(&pp->sp_dtr_wait);
916 lwkt_reltoken(&tty_token);
921 siwrite(struct dev_write_args *ap)
923 cdev_t dev = ap->a_head.a_dev;
927 int mynor = minor(dev);
929 lwkt_gettoken(&tty_token);
930 if (IS_SPECIAL(mynor)) {
931 DPRINT((0, DBG_ENTRY|DBG_FAIL|DBG_WRITE, "siwrite(CONTROLDEV!!)\n"));
932 lwkt_reltoken(&tty_token);
935 pp = MINOR2PP(mynor);
937 DPRINT((pp, DBG_WRITE, "siwrite(%s,%p,%x)\n", devtoname(dev), ap->a_uio, ap->a_ioflag));
941 * If writes are currently blocked, wait on the "real" tty
943 while (pp->sp_state & SS_BLOCKWRITE) {
944 pp->sp_state |= SS_WAITWRITE;
945 DPRINT((pp, DBG_WRITE, "in siwrite, wait for SS_BLOCKWRITE to clear\n"));
946 if ((error = ttysleep(tp, (caddr_t)pp, PCATCH,
947 "siwrite", tp->t_timeout))) {
948 if (error == EWOULDBLOCK)
954 error = (*linesw[tp->t_line].l_write)(tp, ap->a_uio, ap->a_ioflag);
957 lwkt_reltoken(&tty_token);
963 siioctl(struct dev_ioctl_args *ap)
965 cdev_t dev = ap->a_head.a_dev;
966 caddr_t data = ap->a_data;
967 u_long cmd = ap->a_cmd;
971 int mynor = minor(dev);
973 #if defined(COMPAT_43)
978 if (IS_SI_IOCTL(cmd))
979 return(si_Sioctl(dev, cmd, data, ap->a_fflag, ap->a_cred));
981 lwkt_gettoken(&tty_token);
982 pp = MINOR2PP(mynor);
985 DPRINT((pp, DBG_ENTRY|DBG_IOCTL, "siioctl(%s,%lx,%p,%x)\n",
986 devtoname(dev), cmd, data, ap->a_fflag));
987 if (IS_STATE(mynor)) {
990 switch (mynor & SI_STATE_MASK) {
991 case SI_INIT_STATE_MASK:
992 ct = IS_CALLOUT(mynor) ? &pp->sp_iout : &pp->sp_iin;
994 case SI_LOCK_STATE_MASK:
995 ct = IS_CALLOUT(mynor) ? &pp->sp_lout : &pp->sp_lin;
998 lwkt_reltoken(&tty_token);
1003 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1006 *ct = *(struct termios *)data;
1007 lwkt_reltoken(&tty_token);
1010 *(struct termios *)data = *ct;
1011 lwkt_reltoken(&tty_token);
1014 *(int *)data = TTYDISC;
1015 lwkt_reltoken(&tty_token);
1018 bzero(data, sizeof(struct winsize));
1019 lwkt_reltoken(&tty_token);
1022 lwkt_reltoken(&tty_token);
1027 * Do the old-style ioctl compat routines...
1029 #if defined(COMPAT_43)
1030 term = tp->t_termios;
1032 error = ttsetcompat(tp, &cmd, data, &term);
1034 lwkt_reltoken(&tty_token);
1038 data = (caddr_t)&term;
1041 * Do the initial / lock state business
1043 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1045 struct termios *dt = (struct termios *)data;
1046 struct termios *lt = mynor & SI_CALLOUT_MASK
1047 ? &pp->sp_lout : &pp->sp_lin;
1049 dt->c_iflag = (tp->t_iflag & lt->c_iflag) |
1050 (dt->c_iflag & ~lt->c_iflag);
1051 dt->c_oflag = (tp->t_oflag & lt->c_oflag) |
1052 (dt->c_oflag & ~lt->c_oflag);
1053 dt->c_cflag = (tp->t_cflag & lt->c_cflag) |
1054 (dt->c_cflag & ~lt->c_cflag);
1055 dt->c_lflag = (tp->t_lflag & lt->c_lflag) |
1056 (dt->c_lflag & ~lt->c_lflag);
1057 for (cc = 0; cc < NCCS; ++cc)
1058 if (lt->c_cc[cc] != 0)
1059 dt->c_cc[cc] = tp->t_cc[cc];
1060 if (lt->c_ispeed != 0)
1061 dt->c_ispeed = tp->t_ispeed;
1062 if (lt->c_ospeed != 0)
1063 dt->c_ospeed = tp->t_ospeed;
1067 * Block user-level writes to give the ttywait()
1068 * a chance to completely drain for commands
1069 * that require the port to be in a quiescent state.
1078 blocked++; /* block writes for ttywait() and siparam() */
1079 si_write_enable(pp, 0);
1082 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data,
1083 ap->a_fflag, ap->a_cred);
1084 if (error != ENOIOCTL)
1089 error = ttioctl(tp, cmd, data, ap->a_fflag);
1090 si_disc_optim(tp, &tp->t_termios, pp);
1091 if (error != ENOIOCTL) {
1099 si_command(pp, SBREAK, SI_WAIT);
1102 si_command(pp, EBREAK, SI_WAIT);
1105 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
1108 (void) si_modem(pp, SET, 0);
1111 (void) si_modem(pp, SET, *(int *)data);
1114 (void) si_modem(pp, BIS, *(int *)data);
1117 (void) si_modem(pp, BIC, *(int *)data);
1120 *(int *)data = si_modem(pp, GET, 0);
1123 /* must be root since the wait applies to following logins */
1124 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1126 pp->sp_dtr_wait = *(int *)data * hz / 100;
1129 *(int *)data = pp->sp_dtr_wait * 100 / hz;
1137 DPRINT((pp, DBG_IOCTL|DBG_EXIT, "siioctl ret %d\n", error));
1139 si_write_enable(pp, 1);
1140 lwkt_reltoken(&tty_token);
1145 * Handle the Specialix ioctls. All MUST be called via the CONTROL device
1148 si_Sioctl(cdev_t dev, u_long cmd, caddr_t data, int flag, struct ucred *cred)
1150 struct si_softc *xsc;
1151 struct si_port *xpp;
1152 volatile struct si_reg *regp;
1154 struct si_pstat *sps;
1157 int mynor = minor(dev);
1159 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%p,%x)\n",
1160 devtoname(dev), cmd, data, flag));
1163 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%lx\n", TCSI_PORT));
1164 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%lx\n", TCSI_CCB));
1165 DPRINT((0, DBG_IOCTL, "TCSI_TTY=%lx\n", TCSI_TTY));
1168 if (!IS_CONTROLDEV(mynor)) {
1169 DPRINT((0, DBG_IOCTL|DBG_FAIL, "not called from control device!\n"));
1173 crit_enter(); /* better safe than sorry */
1174 lwkt_gettoken(&tty_token);
1178 #define SUCHECK if ((error = priv_check_cred(cred, PRIV_ROOT, 0))) goto out
1196 * Check that a controller for this port exists
1199 /* may also be a struct si_pstat, a superset of si_tcsi */
1201 dp = (struct si_tcsi *)data;
1202 sps = (struct si_pstat *)data;
1204 xsc = devclass_get_softc(si_devclass, card); /* check.. */
1205 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
1210 * And check that a port exists
1213 if (port < 0 || port >= xsc->sc_nport) {
1217 xpp = xsc->sc_ports + port;
1218 regp = (struct si_reg *)xsc->sc_maddr;
1228 xpp->sp_debug = DBG_ALL;
1229 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
1230 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
1237 case TCSISDBG_LEVEL:
1238 case TCSIGDBG_LEVEL:
1240 if (cmd == TCSIGDBG_LEVEL) {
1241 dp->tc_dbglvl = xpp->sp_debug;
1244 xpp->sp_debug = dp->tc_dbglvl;
1252 dp->tc_int = regp->rx_int_count;
1256 regp->rx_int_count = dp->tc_int;
1259 dp->tc_int = regp->int_count;
1263 regp->int_count = dp->tc_int;
1266 dp->tc_int = xpp->sp_ccb->hi_ip;
1268 /* these next three use a different structure */
1271 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
1275 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
1279 si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty));
1286 lwkt_reltoken(&tty_token);
1288 return(error); /* success */
1292 * siparam() : Configure line params
1293 * called at spltty();
1294 * this may sleep, does not flush, nor wait for drain, nor block writes
1295 * caller must arrange this if it's important..
1298 siparam(struct tty *tp, struct termios *t)
1300 struct si_port *pp = TP2PP(tp);
1301 volatile struct si_channel *ccbp;
1302 int cflag, iflag, oflag, lflag;
1303 int error = 0; /* shutup gcc */
1304 int ispeed = 0; /* shutup gcc */
1305 int ospeed = 0; /* shutup gcc */
1308 lwkt_gettoken(&tty_token);
1309 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%p,%p)\n", tp, t));
1314 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
1315 oflag, cflag, iflag, lflag));
1317 /* XXX - if Jet host and SXDC module, use extended baud rates */
1319 /* if not hung up.. */
1320 if (t->c_ospeed != 0) {
1321 /* translate baud rate to firmware values */
1322 ospeed = ttspeedtab(t->c_ospeed, bdrates);
1323 ispeed = t->c_ispeed ?
1324 ttspeedtab(t->c_ispeed, bdrates) : ospeed;
1326 /* enforce legit baud rate */
1327 if (ospeed < 0 || ispeed < 0) {
1328 lwkt_reltoken(&tty_token);
1337 /* ========== set hi_break ========== */
1339 if (iflag & IGNBRK) /* Breaks */
1341 if (iflag & BRKINT) /* Interrupt on break? */
1343 if (iflag & PARMRK) /* Parity mark? */
1345 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
1347 ccbp->hi_break = val;
1349 /* ========== set hi_csr ========== */
1350 /* if not hung up.. */
1351 if (t->c_ospeed != 0) {
1352 /* Set I/O speeds */
1353 val = (ispeed << 4) | ospeed;
1357 /* ========== set hi_mr2 ========== */
1359 if (cflag & CSTOPB) /* Stop bits */
1364 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
1365 * a DCE, hence the reverse sense of RTS and CTS
1367 /* Output Flow - RTS must be raised before data can be sent */
1368 if (cflag & CCTS_OFLOW)
1373 /* ========== set hi_mr1 ========== */
1375 if (!(cflag & PARENB)) /* Parity */
1382 if ((cflag & CS8) == CS8) { /* 8 data bits? */
1384 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
1386 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
1388 } else { /* Must be 5 */
1392 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
1393 * a DCE, hence the reverse sense of RTS and CTS
1395 /* Input Flow - CTS is raised when port is ready to receive data */
1396 if (cflag & CRTS_IFLOW)
1401 /* ========== set hi_mask ========== */
1403 if ((cflag & CS8) == CS8) { /* 8 data bits? */
1405 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
1407 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
1409 } else { /* Must be 5 */
1415 ccbp->hi_mask = val;
1417 /* ========== set hi_prtcl ========== */
1418 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
1428 ccbp->hi_prtcl = val;
1431 /* ========== set hi_{rx|tx}{on|off} ========== */
1432 /* XXX: the card TOTALLY shields us from the flow control... */
1433 ccbp->hi_txon = t->c_cc[VSTART];
1434 ccbp->hi_txoff = t->c_cc[VSTOP];
1436 ccbp->hi_rxon = t->c_cc[VSTART];
1437 ccbp->hi_rxoff = t->c_cc[VSTOP];
1439 /* ========== send settings to the card ========== */
1440 /* potential sleep here */
1441 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
1442 si_command(pp, LOPEN, SI_WAIT); /* open it */
1444 si_command(pp, CONFIG, SI_WAIT); /* change params */
1446 /* ========== set DTR etc ========== */
1447 /* Hangup if ospeed == 0 */
1448 if (t->c_ospeed == 0) {
1449 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS);
1452 * If the previous speed was 0, may need to re-enable
1455 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
1458 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n",
1459 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break));
1462 lwkt_reltoken(&tty_token);
1467 * Enable or Disable the writes to this channel...
1468 * "state" -> enabled = 1; disabled = 0;
1469 * NOTE: Must be called with tty_token held
1472 si_write_enable(struct si_port *pp, int state)
1475 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1479 pp->sp_state &= ~SS_BLOCKWRITE;
1480 if (pp->sp_state & SS_WAITWRITE) {
1481 pp->sp_state &= ~SS_WAITWRITE;
1483 wakeup((caddr_t)pp);
1486 pp->sp_state |= SS_BLOCKWRITE;
1493 * Set/Get state of modem control lines.
1494 * Due to DCE-like behaviour of the adapter, some signals need translation:
1497 * NOTE: Must be called with tty_token held
1500 si_modem(struct si_port *pp, enum si_mctl cmd, int bits)
1502 volatile struct si_channel *ccbp;
1505 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1506 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "si_modem(%p,%s,%x)\n", pp, si_mctl2str(cmd), bits));
1507 ccbp = pp->sp_ccb; /* Find channel address */
1512 if (x & IP_DCD) bits |= TIOCM_CAR;
1513 if (x & IP_DTR) bits |= TIOCM_DTR;
1514 if (x & IP_RTS) bits |= TIOCM_RTS;
1515 if (x & IP_RI) bits |= TIOCM_RI;
1518 ccbp->hi_op &= ~(OP_DSR|OP_CTS);
1522 if (bits & TIOCM_DTR)
1524 if (bits & TIOCM_RTS)
1529 if (bits & TIOCM_DTR)
1530 ccbp->hi_op &= ~OP_DSR;
1531 if (bits & TIOCM_RTS)
1532 ccbp->hi_op &= ~OP_CTS;
1538 * Handle change of modem state
1539 * NOTE: Must be called with tty_token held
1542 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
1544 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1545 /* if a modem dev */
1546 if (hi_ip & IP_DCD) {
1547 if (!(pp->sp_last_hi_ip & IP_DCD)) {
1548 DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n",
1550 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
1553 if (pp->sp_last_hi_ip & IP_DCD) {
1554 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1555 if ((*linesw[tp->t_line].l_modem)(tp, 0))
1556 (void) si_modem(pp, SET, 0);
1559 pp->sp_last_hi_ip = hi_ip;
1564 * Poller to catch missed interrupts.
1566 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1567 * better response. We could really use a "periodic" version timeout(). :-)
1571 si_poll(void *nothing)
1573 struct si_softc *sc;
1575 volatile struct si_reg *regp;
1579 DPRINT((0, DBG_POLL, "si_poll()\n"));
1581 lwkt_gettoken(&tty_token);
1585 for (i = 0; i < si_numunits; i++) {
1586 sc = devclass_get_softc(si_devclass, i);
1587 if (sc == NULL || sc->sc_type == SIEMPTY)
1589 regp = (struct si_reg *)sc->sc_maddr;
1592 * See if there has been a pending interrupt for 2 seconds
1593 * or so. The test (int_scounter >= 200) won't correspond
1594 * to 2 seconds if int_count gets changed.
1596 if (regp->int_pending != 0) {
1597 if (regp->int_scounter >= 200 &&
1598 regp->initstat == 1) {
1599 kprintf("si%d: lost intr\n", i);
1603 regp->int_scounter = 0;
1607 * gripe about no input flow control..
1610 for (port = 0; port < sc->sc_nport; pp++, port++) {
1611 if (pp->sp_delta_overflows > 0) {
1612 kprintf("si%d: %d tty level buffer overflows\n",
1613 i, pp->sp_delta_overflows);
1614 pp->sp_delta_overflows = 0;
1618 if (lost || si_realpoll)
1619 si_intr(NULL); /* call intr with fake vector */
1621 lwkt_reltoken(&tty_token);
1624 callout_reset(&poll_ch, si_pollrate, si_poll, NULL);
1626 #endif /* ifdef POLL */
1629 * The interrupt handler polls ALL ports on ALL adapters each time
1633 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1634 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1639 struct si_softc *sc;
1641 volatile struct si_channel *ccbp;
1643 volatile caddr_t maddr;
1645 int x, card, port, n, i, isopen;
1651 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1656 lwkt_gettoken(&tty_token);
1659 * When we get an int we poll all the channels and do ALL pending
1660 * work, not just the first one we find. This allows all cards to
1661 * share the same vector.
1663 * XXX - But if we're sharing the vector with something that's NOT
1664 * a SI/XIO/SX card, we may be making more work for ourselves.
1666 for (card = 0; card < si_numunits; card++) {
1667 sc = devclass_get_softc(si_devclass, card);
1668 if (sc == NULL || sc->sc_type == SIEMPTY)
1672 * First, clear the interrupt
1674 switch(sc->sc_type) {
1676 maddr = sc->sc_maddr;
1677 ((volatile struct si_reg *)maddr)->int_pending = 0;
1678 /* flag nothing pending */
1679 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1680 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1683 maddr = sc->sc_maddr;
1684 ((volatile struct si_reg *)maddr)->int_pending = 0;
1685 *(maddr+SIPLIRQCLR) = 0x00;
1686 *(maddr+SIPLIRQCLR) = 0x10;
1689 maddr = sc->sc_maddr;
1690 ((volatile struct si_reg *)maddr)->int_pending = 0;
1691 *(maddr+SIPCIINTCL) = 0x0;
1693 case SIJETPCI: /* fall through to JETISA case */
1695 maddr = sc->sc_maddr;
1696 ((volatile struct si_reg *)maddr)->int_pending = 0;
1697 *(maddr+SIJETINTCL) = 0x0;
1700 maddr = sc->sc_maddr;
1701 ((volatile struct si_reg *)maddr)->int_pending = 0;
1702 (void)inb(sc->sc_iobase + 3);
1708 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1713 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1719 * See if a command has completed ?
1721 if (ccbp->hi_stat != pp->sp_pend) {
1722 DPRINT((pp, DBG_INTR,
1723 "si_intr hi_stat = 0x%x, pend = %d\n",
1724 ccbp->hi_stat, pp->sp_pend));
1725 switch(pp->sp_pend) {
1732 pp->sp_pend = ccbp->hi_stat;
1733 /* sleeping in si_command */
1734 wakeup(&pp->sp_state);
1737 pp->sp_pend = ccbp->hi_stat;
1742 * Continue on if it's closed
1744 if (ccbp->hi_stat == IDLE_CLOSE) {
1749 * Do modem state change if not a local device
1751 si_modem_state(pp, tp, ccbp->hi_ip);
1754 * Check to see if we should 'receive' characters.
1756 if (tp->t_state & TS_CONNECTED &&
1757 tp->t_state & TS_ISOPEN)
1763 * Do input break processing
1765 if (ccbp->hi_state & ST_BREAK) {
1767 (*linesw[tp->t_line].l_rint)(TTY_BI, tp);
1769 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1770 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1774 * Do RX stuff - if not open then dump any characters.
1775 * XXX: This is VERY messy and needs to be cleaned up.
1777 * XXX: can we leave data in the host adapter buffer
1778 * when the clists are full? That may be dangerous
1779 * if the user cannot get an interrupt signal through.
1782 more_rx: /* XXX Sorry. the nesting was driving me bats! :-( */
1785 ccbp->hi_rxopos = ccbp->hi_rxipos;
1790 * If the tty input buffers are blocked, stop emptying
1791 * the incoming buffers and let the auto flow control
1794 if (tp->t_state & TS_TBLOCK) {
1799 * Process read characters if not skipped above
1801 op = ccbp->hi_rxopos;
1802 ip = ccbp->hi_rxipos;
1812 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1816 * Suck characters out of host card buffer into the
1817 * "input staging buffer" - so that we dont leave the
1818 * host card in limbo while we're possibly echoing
1819 * characters and possibly flushing input inside the
1820 * ldisc l_rint() routine.
1822 if (n <= SI_BUFFERSIZE - op) {
1824 DPRINT((pp, DBG_INTR, "\tsingle copy\n"));
1825 z = ccbp->hi_rxbuf + op;
1826 si_vbcopy(z, si_rxbuf, n);
1830 x = SI_BUFFERSIZE - op;
1832 DPRINT((pp, DBG_INTR, "\tdouble part 1 %d\n", x));
1833 z = ccbp->hi_rxbuf + op;
1834 si_vbcopy(z, si_rxbuf, x);
1836 DPRINT((pp, DBG_INTR, "\tdouble part 2 %d\n",
1839 si_vbcopy(z, si_rxbuf + x, n - x);
1844 /* clear collected characters from buffer */
1845 ccbp->hi_rxopos = op;
1847 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1852 * n = number of chars placed in si_rxbuf
1856 * Avoid the grotesquely inefficient lineswitch
1857 * routine (ttyinput) in "raw" mode. It usually
1858 * takes about 450 instructions (that's without
1859 * canonical processing or echo!). slinput is
1860 * reasonably fast (usually 40 instructions
1861 * plus call overhead).
1863 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1865 /* block if the driver supports it */
1866 if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER &&
1867 (tp->t_cflag & CRTS_IFLOW ||
1868 tp->t_iflag & IXOFF) &&
1869 !(tp->t_state & TS_TBLOCK))
1876 pp->sp_delta_overflows +=
1877 b_to_q((char *)si_rxbuf, n, &tp->t_rawq);
1880 if (tp->t_state & TS_TTSTOP &&
1881 (tp->t_iflag & IXANY ||
1882 tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1883 tp->t_state &= ~TS_TTSTOP;
1884 tp->t_lflag &= ~FLUSHO;
1889 * It'd be nice to not have to go through the
1890 * function call overhead for each char here.
1891 * It'd be nice to block input it, saving a
1892 * loop here and the call/return overhead.
1894 for(x = 0; x < n; x++) {
1896 if ((*linesw[tp->t_line].l_rint)(i, tp)
1898 pp->sp_delta_overflows++;
1901 * doesn't seem to be much point doing
1902 * this here.. this driver has no
1903 * softtty processing! ??
1905 if (pp->sp_hotchar && i == pp->sp_hotchar) {
1910 goto more_rx; /* try for more until RXbuf is empty */
1912 end_rx: /* XXX: Again, sorry about the gotos.. :-) */
1917 (*linesw[tp->t_line].l_start)(tp);
1919 } /* end of for (all ports on this controller) */
1920 } /* end of for (all controllers) */
1923 lwkt_reltoken(&tty_token);
1924 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1928 * Nudge the transmitter...
1930 * XXX: I inherited some funny code here. It implies the host card only
1931 * interrupts when the transmit buffer reaches the low-water-mark, and does
1932 * not interrupt when it's actually hits empty. In some cases, we have
1933 * processes waiting for complete drain, and we need to simulate an interrupt
1934 * about when we think the buffer is going to be empty (and retry if not).
1935 * I really am not certain about this... I *need* the hardware manuals.
1938 si_start(struct tty *tp)
1941 volatile struct si_channel *ccbp;
1945 int count, n, amount, buffer_full;
1948 lwkt_gettoken(&tty_token);
1953 DPRINT((pp, DBG_ENTRY|DBG_START,
1954 "si_start(%p) t_state %x sp_state %x t_outq.c_cc %d\n",
1955 tp, tp->t_state, pp->sp_state, qp->c_cc));
1957 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP))
1963 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1964 DPRINT((pp, DBG_START, "count %d\n", (BYTE)count));
1966 while ((nchar = qp->c_cc) > 0) {
1967 if ((BYTE)count >= 255) {
1971 amount = min(nchar, (255 - (BYTE)count));
1972 ipos = (unsigned int)ccbp->hi_txipos;
1973 n = q_to_b(&tp->t_outq, si_txbuf, amount);
1974 /* will it fit in one lump? */
1975 if ((SI_BUFFERSIZE - ipos) >= n) {
1976 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1978 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos],
1979 SI_BUFFERSIZE - ipos);
1980 si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos),
1981 &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos));
1983 ccbp->hi_txipos += n;
1984 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1987 if (count != 0 && nchar == 0) {
1988 tp->t_state |= TS_BUSY;
1990 tp->t_state &= ~TS_BUSY;
1996 DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n",
1997 (BYTE)count, nchar, tp->t_state));
1999 if (tp->t_state & TS_BUSY)
2003 time = ttspeedtab(tp->t_ospeed, chartimes);
2007 time = nchar / time;
2011 DPRINT((pp, DBG_START,
2012 "bad char time value! %d\n", time));
2016 if ((pp->sp_state & (SS_LSTART|SS_INLSTART)) == SS_LSTART) {
2017 callout_stop(&pp->lstart_ch);
2019 pp->sp_state |= SS_LSTART;
2021 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
2022 callout_reset(&pp->lstart_ch, time, si_lstart, (void *)pp);
2026 lwkt_reltoken(&tty_token);
2028 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
2032 * Note: called at splsoftclock from the timeout code
2033 * This has to deal with two things... cause wakeups while waiting for
2034 * tty drains on last process exit, and call l_start at about the right
2035 * time for protocols like ppp.
2038 si_lstart(void *arg)
2040 struct si_port *pp = arg;
2043 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%p) sp_state %x\n",
2047 lwkt_gettoken(&tty_token);
2049 if ((pp->sp_state & SS_OPEN) == 0 || (pp->sp_state & SS_LSTART) == 0) {
2050 lwkt_reltoken(&tty_token);
2054 pp->sp_state &= ~SS_LSTART;
2055 pp->sp_state |= SS_INLSTART;
2059 /* deal with the process exit case */
2062 /* nudge protocols - eg: ppp */
2063 (*linesw[tp->t_line].l_start)(tp);
2065 pp->sp_state &= ~SS_INLSTART;
2066 lwkt_reltoken(&tty_token);
2071 * Stop output on a line. called at spltty();
2074 si_stop(struct tty *tp, int rw)
2076 volatile struct si_channel *ccbp;
2079 lwkt_gettoken(&tty_token);
2083 DPRINT((TP2PP(tp), DBG_ENTRY|DBG_STOP, "si_stop(%p,%x)\n", tp, rw));
2085 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
2087 /* what level are we meant to be flushing anyway? */
2088 if (tp->t_state & TS_BUSY) {
2089 si_command(TP2PP(tp), WFLUSH, SI_NOWAIT);
2090 tp->t_state &= ~TS_BUSY;
2091 ttwwakeup(tp); /* Bruce???? */
2094 #if 1 /* XXX: this doesn't work right yet.. */
2095 /* XXX: this may have been failing because we used to call l_rint()
2096 * while we were looping based on these two counters. Now, we collect
2097 * the data and then loop stuffing it into l_rint(), making this
2098 * useless. Should we cause this to blow away the staging buffer?
2101 ccbp->hi_rxopos = ccbp->hi_rxipos;
2104 lwkt_reltoken(&tty_token);
2108 * Issue a command to the host card CPU.
2112 si_command(struct si_port *pp, int cmd, int waitflag)
2114 volatile struct si_channel *ccbp = pp->sp_ccb;
2117 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%p,%x,%d): hi_stat 0x%x\n",
2118 pp, cmd, waitflag, ccbp->hi_stat));
2120 crit_enter(); /* Keep others out */
2121 lwkt_gettoken(&tty_token);
2123 /* wait until it's finished what it was doing.. */
2124 /* XXX: sits in IDLE_BREAK until something disturbs it or break
2126 while((x = ccbp->hi_stat) != IDLE_OPEN &&
2130 if (in_intr) { /* Prevent sleep in intr */
2131 DPRINT((pp, DBG_PARAM,
2132 "cmd intr collision - completing %d\trequested %d\n",
2134 lwkt_reltoken(&tty_token);
2137 } else if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, PCATCH,
2139 lwkt_reltoken(&tty_token);
2144 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
2146 /* if there was a pending command, cause a state-change wakeup */
2147 switch(pp->sp_pend) {
2154 wakeup(&pp->sp_state);
2160 pp->sp_pend = cmd; /* New command pending */
2161 ccbp->hi_stat = cmd; /* Post it */
2164 if (in_intr) { /* If in interrupt handler */
2165 DPRINT((pp, DBG_PARAM,
2166 "attempt to sleep in si_intr - cmd req %d\n",
2168 lwkt_reltoken(&tty_token);
2171 } else while(ccbp->hi_stat != IDLE_OPEN &&
2172 ccbp->hi_stat != IDLE_BREAK) {
2173 if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, PCATCH,
2178 lwkt_reltoken(&tty_token);
2183 si_disc_optim(struct tty *tp, struct termios *t, struct si_port *pp)
2185 lwkt_gettoken(&tty_token);
2187 * XXX can skip a lot more cases if Smarts. Maybe
2188 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2189 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2191 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) &&
2192 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
2193 (!(t->c_iflag & PARMRK) ||
2194 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
2195 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
2196 linesw[tp->t_line].l_rint == ttyinput)
2197 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2199 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2200 pp->sp_hotchar = linesw[tp->t_line].l_hotchar;
2201 DPRINT((pp, DBG_OPTIM, "bypass: %s, hotchar: %x\n",
2202 (tp->t_state & TS_CAN_BYPASS_L_RINT) ? "on" : "off",
2204 lwkt_reltoken(&tty_token);
2211 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
2215 if ((pp == NULL && (si_debug&flags)) ||
2216 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
2218 kprintf("%ci%d(%d): ", 's',
2219 (int)SI_CARD(minor(pp->sp_tty->t_dev)),
2220 (int)SI_PORT(minor(pp->sp_tty->t_dev)));
2221 __va_start(ap, fmt);
2228 si_mctl2str(enum si_mctl cmd)
2246 si_modulename(int host_type, int uart_type)
2248 switch (host_type) {
2249 /* Z280 based cards */
2254 switch (uart_type) {
2261 /* T225 based hosts */
2264 switch (uart_type) {