2 * Device driver for Specialix range (SI/XIO) of serial line multiplexors.
4 * Copyright (C) 1990, 1992, 1998 Specialix International,
5 * Copyright (C) 1993, Andy Rutter <andy@acronym.co.uk>
6 * Copyright (C) 2000, Peter Wemm <peter@netplex.com.au>
8 * Originally derived from: SunOS 4.x version
9 * Ported from BSDI version to FreeBSD by Peter Wemm.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notices, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notices, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Andy Rutter of
22 * Advanced Methods and Tools Ltd. based on original information
23 * from Specialix International.
24 * 4. Neither the name of Advanced Methods and Tools, nor Specialix
25 * International may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
31 * NO EVENT SHALL THE AUTHORS BE LIABLE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
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"
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/serial.h>
54 #include <sys/fcntl.h>
55 #include <sys/kernel.h>
56 #include <sys/malloc.h>
58 #include <sys/sysctl.h>
60 #include <machine/bus.h>
62 #include <machine/resource.h>
68 #include <machine/stdarg.h>
70 #include <dev/si/sireg.h>
71 #include <dev/si/sivar.h>
72 #include <dev/si/si.h>
75 * This device driver is designed to interface the Specialix International
76 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA,
77 * EISA or PCI bus machine.
79 * The controller is interfaced to the host via dual port RAM
82 * The code for the Host 1 (very old ISA cards) has not been tested.
85 #define POLL /* turn on poller to scan for lost interrupts */
86 #define REALPOLL /* on each poll, scan for work regardless */
87 #define POLLHZ (hz/10) /* 10 times per second */
88 #define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE)
89 #define INT_COUNT 25000 /* max of 125 ints per second */
90 #define JET_INT_COUNT 100 /* max of 100 ints per second */
91 #define RXINT_COUNT 1 /* one rxint per 10 milliseconds */
93 static void si_command(struct si_port *, int, int);
94 static int si_Sioctl(struct cdev *, u_long, caddr_t, int, struct thread *);
95 static void si_start(struct tty *);
96 static void si_stop(struct tty *, int);
97 static timeout_t si_lstart;
99 static t_break_t sibreak;
100 static t_close_t siclose;
101 static t_modem_t simodem;
102 static t_open_t siopen;
104 static int siparam(struct tty *, struct termios *);
106 static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip);
107 static char * si_modulename(int host_type, int uart_type);
109 static struct cdevsw si_Scdevsw = {
110 .d_version = D_VERSION,
111 .d_ioctl = si_Sioctl,
113 .d_flags = D_TTY | D_NEEDGIANT,
116 static int si_Nports;
117 static int si_Nmodules;
118 static int si_debug = 0; /* data, not bss, so it's patchable */
120 SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, "");
121 TUNABLE_INT("machdep.si_debug", &si_debug);
123 static int si_numunits;
125 devclass_t si_devclass;
127 #ifndef B2000 /* not standard, but the hardware knows it. */
130 static struct speedtab bdrates[] = {
131 { B75, CLK75, }, /* 0x0 */
132 { B110, CLK110, }, /* 0x1 */
133 { B150, CLK150, }, /* 0x3 */
134 { B300, CLK300, }, /* 0x4 */
135 { B600, CLK600, }, /* 0x5 */
136 { B1200, CLK1200, }, /* 0x6 */
137 { B2000, CLK2000, }, /* 0x7 */
138 { B2400, CLK2400, }, /* 0x8 */
139 { B4800, CLK4800, }, /* 0x9 */
140 { B9600, CLK9600, }, /* 0xb */
141 { B19200, CLK19200, }, /* 0xc */
142 { B38400, CLK38400, }, /* 0x2 (out of order!) */
143 { B57600, CLK57600, }, /* 0xd */
144 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */
149 /* populated with approx character/sec rates - translated at card
150 * initialisation time to chars per tick of the clock */
151 static int done_chartimes = 0;
152 static struct speedtab chartimes[] = {
169 static volatile int in_intr = 0; /* Inside interrupt handler? */
172 static int si_pollrate; /* in addition to irq */
173 static int si_realpoll = 0; /* poll HW on timer */
175 SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, "");
176 SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, "");
178 static int init_finished = 0;
179 static void si_poll(void *);
183 * Array of adapter types and the corresponding RAM size. The order of
184 * entries here MUST match the ordinal of the adapter type.
186 static const char *si_type[] = {
189 "SIMCA", /* FreeBSD does not support Microchannel */
198 * We have to make an 8 bit version of bcopy, since some cards can't
199 * deal with 32 bit I/O
202 si_bcopy(const void *src, void *dst, size_t len)
213 si_vbcopy(const volatile void *src, void *dst, size_t len)
216 const volatile u_char *s;
224 si_bcopyv(const void *src, volatile void *dst, size_t len)
236 * Attach the device. Initialize the card.
239 siattach(device_t dev)
245 volatile struct si_channel *ccbp;
246 volatile struct si_reg *regp;
247 volatile caddr_t maddr;
248 struct si_module *modp;
249 struct speedtab *spt;
250 int nmodule, nport, x, y;
253 sc = device_get_softc(dev);
254 unit = device_get_unit(dev);
256 sc->sc_typename = si_type[sc->sc_type];
257 if (si_numunits < unit + 1)
258 si_numunits = unit + 1;
260 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit));
263 if (si_pollrate == 0) {
264 si_pollrate = POLLHZ; /* in addition to irq */
266 si_realpoll = 1; /* scan always */
271 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit,
272 sc->sc_typename, sc->sc_paddr, sc->sc_maddr));
274 sc->sc_ports = NULL; /* mark as uninitialised */
276 maddr = sc->sc_maddr;
278 /* Stop the CPU first so it won't stomp around while we load */
280 switch (sc->sc_type) {
283 outb(sc->sc_iobase + 2, sc->sc_irq << 4);
287 *(maddr+SIPCIRESET) = 0;
289 case SIJETPCI: /* fall through to JET ISA */
291 *(maddr+SIJETCONFIG) = 0;
294 *(maddr+SIPLRESET) = 0;
297 *(maddr+SIRESET) = 0;
299 default: /* this should never happen */
300 printf("si%d: unsupported configuration\n", unit);
305 /* OK, now lets download the download code */
307 if (SI_ISJET(sc->sc_type)) {
308 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n",
309 unit, si3_t225_dsize));
310 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr,
312 DPRINT((0, DBG_DOWNLOAD,
313 "si%d: jet_bootstrap: nbytes %d -> %x\n",
314 unit, si3_t225_bsize, si3_t225_bootloadaddr));
315 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr,
318 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n",
319 unit, si2_z280_dsize));
320 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr,
324 /* Now start the CPU */
326 switch (sc->sc_type) {
329 /* modify the download code to tell it that it's on an EISA */
331 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4);
332 (void)inb(sc->sc_iobase + 3); /* reset interrupt */
336 /* modify the download code to tell it that it's on a PCI */
338 *(maddr+SIPCIRESET) = 1;
339 *(maddr+SIPCIINTCL) = 0;
342 *(maddr+SIJETRESET) = 0;
343 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN;
346 *(maddr+SIJETRESET) = 0;
347 switch (sc->sc_irq) {
349 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90;
352 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0;
355 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0;
358 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0;
361 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0;
366 *(maddr+SIRESET_CL) = 0;
367 *(maddr+SIINTCL_CL) = 0;
370 *(maddr+SIPLRESET) = 0x10;
371 switch (sc->sc_irq) {
373 *(maddr+SIPLIRQ11) = 0x10;
376 *(maddr+SIPLIRQ12) = 0x10;
379 *(maddr+SIPLIRQ15) = 0x10;
382 *(maddr+SIPLIRQCLR) = 0x10;
384 default: /* this should _REALLY_ never happen */
385 printf("si%d: Uh, it was supported a second ago...\n", unit);
389 DELAY(1000000); /* wait around for a second */
391 regp = (struct si_reg *)maddr;
393 /* wait max of 5 sec for init OK */
394 while (regp->initstat == 0 && y++ < 10) {
397 switch (regp->initstat) {
399 printf("si%d: startup timeout - aborting\n", unit);
400 sc->sc_type = SIEMPTY;
403 if (SI_ISJET(sc->sc_type)) {
404 /* set throttle to 100 times per second */
405 regp->int_count = JET_INT_COUNT;
406 /* rx_intr_count is a NOP in Jet */
408 /* set throttle to 125 times per second */
409 regp->int_count = INT_COUNT;
410 /* rx intr max of 25 times per second */
411 regp->rx_int_count = RXINT_COUNT;
413 regp->int_pending = 0; /* no intr pending */
414 regp->int_scounter = 0; /* reset counter */
418 * No modules found, so give up on this one.
420 printf("si%d: %s - no ports found\n", unit,
421 si_type[sc->sc_type]);
424 printf("si%d: download code version error - initstat %x\n",
425 unit, regp->initstat);
430 * First time around the ports just count them in order
431 * to allocate some memory.
434 modp = (struct si_module *)(maddr + 0x80);
436 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp));
437 switch (modp->sm_type) {
439 DPRINT((0, DBG_DOWNLOAD,
440 "si%d: Found old TA4 module, 4 ports\n",
445 DPRINT((0, DBG_DOWNLOAD,
446 "si%d: Found old TA8 module, 8 ports\n",
451 DPRINT((0, DBG_DOWNLOAD,
452 "si%d: Found ASIC TA4 module, 4 ports\n",
457 DPRINT((0, DBG_DOWNLOAD,
458 "si%d: Found ASIC TA8 module, 8 ports\n",
463 DPRINT((0, DBG_DOWNLOAD,
464 "si%d: Found CD1400 module, 8 ports\n",
469 DPRINT((0, DBG_DOWNLOAD,
470 "si%d: Found SXDC module, 8 ports\n",
475 printf("si%d: unknown module type %d\n",
476 unit, modp->sm_type);
480 /* this was limited in firmware and is also a driver issue */
481 if ((nport + x) > SI_MAXPORTPERCARD) {
482 printf("si%d: extra ports ignored\n", unit);
491 if (modp->sm_next == 0)
493 modp = (struct si_module *)
494 (maddr + (unsigned)(modp->sm_next & 0x7fff));
496 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport,
497 M_DEVBUF, M_NOWAIT | M_ZERO);
498 if (sc->sc_ports == 0) {
499 printf("si%d: fail to malloc memory for port structs\n",
503 sc->sc_nport = nport;
506 * Scan round the ports again, this time initialising.
510 modp = (struct si_module *)(maddr + 0x80);
511 uart_type = 1000; /* arbitary, > uchar_max */
513 switch (modp->sm_type) {
536 ccbp = (struct si_channel *)((char *)modp + 0x100);
537 if (uart_type == 1000)
538 uart_type = ccbp->type;
539 else if (uart_type != ccbp->type)
540 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n",
542 ccbp->type, si_modulename(sc->sc_type, ccbp->type),
543 uart_type, si_modulename(sc->sc_type, uart_type));
545 for (x = 0; x < nport; x++, pp++, ccbp++) {
546 pp->sp_ccb = ccbp; /* save the address */
547 pp->sp_pend = IDLE_CLOSE;
548 pp->sp_state = 0; /* internal flag */
550 sprintf(pp->sp_name, "si%r%r", unit,
551 (int)(pp - sc->sc_ports));
553 tp = pp->sp_tty = ttyalloc();
555 tp->t_break = sibreak;
556 tp->t_close = siclose;
557 tp->t_modem = simodem;
559 tp->t_oproc = si_start;
560 tp->t_param = siparam;
561 tp->t_stop = si_stop;
562 ttycreate(tp, TS_CALLOUT, "A%r%r", unit,
563 (int)(pp - sc->sc_ports));
566 if (modp->sm_next == 0) {
567 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n",
573 si_modulename(sc->sc_type, uart_type));
576 modp = (struct si_module *)
577 (maddr + (unsigned)(modp->sm_next & 0x7fff));
579 if (done_chartimes == 0) {
580 for (spt = chartimes ; spt->sp_speed != -1; spt++) {
581 if ((spt->sp_code /= hz) == 0)
588 make_dev(&si_Scdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
594 siopen(struct tty *tp, struct cdev *dev)
599 * We've now got a device, so start the poller.
601 if (init_finished == 0) {
602 timeout(si_poll, (caddr_t)0L, si_pollrate);
610 siclose(struct tty *tp)
615 (void) si_command(pp, FCLOSE, SI_NOWAIT);
619 sibreak(struct tty *tp, int sig)
625 si_command(pp, SBREAK, SI_WAIT);
627 si_command(pp, EBREAK, SI_WAIT);
632 * Handle the Specialix ioctls on the control dev.
635 si_Sioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
637 struct si_softc *xsc;
639 volatile struct si_reg *regp;
641 struct si_pstat *sps;
646 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%x,%x)\n",
647 devtoname(dev), cmd, data, flag));
650 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT));
651 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB));
652 DPRINT((0, DBG_IOCTL, "TCSI_TTY=%x\n", TCSI_TTY));
655 oldspl = spltty(); /* better safe than sorry */
659 #define SUCHECK if ((error = priv_check(td, PRIV_DRIVER))) goto out
677 * Check that a controller for this port exists
680 /* may also be a struct si_pstat, a superset of si_tcsi */
682 dp = (struct si_tcsi *)data;
683 sps = (struct si_pstat *)data;
685 xsc = devclass_get_softc(si_devclass, card); /* check.. */
686 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
691 * And check that a port exists
694 if (port < 0 || port >= xsc->sc_nport) {
698 xpp = xsc->sc_ports + port;
699 regp = (struct si_reg *)xsc->sc_maddr;
709 xpp->sp_debug = DBG_ALL;
710 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
711 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
721 if (cmd == TCSIGDBG_LEVEL) {
722 dp->tc_dbglvl = xpp->sp_debug;
725 xpp->sp_debug = dp->tc_dbglvl;
733 dp->tc_int = regp->rx_int_count;
737 regp->rx_int_count = dp->tc_int;
740 dp->tc_int = regp->int_count;
744 regp->int_count = dp->tc_int;
747 dp->tc_int = xpp->sp_ccb->hi_ip;
749 /* these next three use a different structure */
752 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
756 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
760 si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty));
768 return(error); /* success */
772 * siparam() : Configure line params
773 * called at spltty();
774 * this may sleep, does not flush, nor wait for drain, nor block writes
775 * caller must arrange this if it's important..
778 siparam(struct tty *tp, struct termios *t)
780 struct si_port *pp = tp->t_sc;
781 volatile struct si_channel *ccbp;
782 int oldspl, cflag, iflag, oflag, lflag;
783 int error = 0; /* shutup gcc */
784 int ispeed = 0; /* shutup gcc */
785 int ospeed = 0; /* shutup gcc */
788 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t));
793 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
794 oflag, cflag, iflag, lflag));
796 /* XXX - if Jet host and SXDC module, use extended baud rates */
798 /* if not hung up.. */
799 if (t->c_ospeed != 0) {
800 /* translate baud rate to firmware values */
801 ospeed = ttspeedtab(t->c_ospeed, bdrates);
802 ispeed = t->c_ispeed ?
803 ttspeedtab(t->c_ispeed, bdrates) : ospeed;
805 /* enforce legit baud rate */
806 if (ospeed < 0 || ispeed < 0)
814 /* ========== set hi_break ========== */
816 if (iflag & IGNBRK) /* Breaks */
818 if (iflag & BRKINT) /* Interrupt on break? */
820 if (iflag & PARMRK) /* Parity mark? */
822 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
824 ccbp->hi_break = val;
826 /* ========== set hi_csr ========== */
827 /* if not hung up.. */
828 if (t->c_ospeed != 0) {
830 val = (ispeed << 4) | ospeed;
834 /* ========== set hi_mr2 ========== */
836 if (cflag & CSTOPB) /* Stop bits */
841 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
842 * a DCE, hence the reverse sense of RTS and CTS
844 /* Output Flow - RTS must be raised before data can be sent */
845 if (cflag & CCTS_OFLOW)
850 /* ========== set hi_mr1 ========== */
852 if (!(cflag & PARENB)) /* Parity */
859 if ((cflag & CS8) == CS8) { /* 8 data bits? */
861 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
863 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
865 } else { /* Must be 5 */
869 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
870 * a DCE, hence the reverse sense of RTS and CTS
872 /* Input Flow - CTS is raised when port is ready to receive data */
873 if (cflag & CRTS_IFLOW)
878 /* ========== set hi_mask ========== */
880 if ((cflag & CS8) == CS8) { /* 8 data bits? */
882 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
884 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
886 } else { /* Must be 5 */
894 /* ========== set hi_prtcl ========== */
895 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
905 ccbp->hi_prtcl = val;
908 /* ========== set hi_{rx|tx}{on|off} ========== */
909 /* XXX: the card TOTALLY shields us from the flow control... */
910 ccbp->hi_txon = t->c_cc[VSTART];
911 ccbp->hi_txoff = t->c_cc[VSTOP];
913 ccbp->hi_rxon = t->c_cc[VSTART];
914 ccbp->hi_rxoff = t->c_cc[VSTOP];
916 /* ========== send settings to the card ========== */
917 /* potential sleep here */
918 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
919 si_command(pp, LOPEN, SI_WAIT); /* open it */
921 si_command(pp, CONFIG, SI_WAIT); /* change params */
923 /* ========== set DTR etc ========== */
924 /* Hangup if ospeed == 0 */
925 if (t->c_ospeed == 0) {
926 (void) simodem(tp, 0, SER_DTR | SER_RTS);
929 * If the previous speed was 0, may need to re-enable
932 (void) simodem(tp, SER_DTR | SER_RTS, 0);
935 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n",
936 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break));
943 * Set/Get state of modem control lines.
944 * Due to DCE-like behaviour of the adapter, some signals need translation:
949 simodem(struct tty *tp, int sigon, int sigoff)
952 volatile struct si_channel *ccbp;
956 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "simodem(%x,%x)\n", sigon, sigoff));
957 ccbp = pp->sp_ccb; /* Find channel address */
958 if (sigon == 0 && sigoff == 0) {
961 * XXX: not sure this is correct, should it be CTS&DSR ?
962 * XXX: or do we (just) miss CTS & DSR ?
964 if (x & IP_DCD) sigon |= SER_DCD;
965 if (x & IP_DTR) sigon |= SER_DTR;
966 if (x & IP_RTS) sigon |= SER_RTS;
967 if (x & IP_RI) sigon |= SER_RI;
974 if (sigoff & SER_DTR)
978 if (sigoff & SER_RTS)
985 * Handle change of modem state
988 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
991 if (hi_ip & IP_DCD) {
992 if (!(pp->sp_last_hi_ip & IP_DCD)) {
993 DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n",
995 (void)ttyld_modem(tp, 1);
998 if (pp->sp_last_hi_ip & IP_DCD) {
999 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1000 if (ttyld_modem(tp, 0))
1001 (void) simodem(tp, 0, SER_DTR | SER_RTS);
1004 pp->sp_last_hi_ip = hi_ip;
1009 * Poller to catch missed interrupts.
1011 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1012 * better response. We could really use a "periodic" version timeout(). :-)
1016 si_poll(void *nothing)
1018 struct si_softc *sc;
1020 volatile struct si_reg *regp;
1022 int lost, oldspl, port;
1024 DPRINT((0, DBG_POLL, "si_poll()\n"));
1029 for (i = 0; i < si_numunits; i++) {
1030 sc = devclass_get_softc(si_devclass, i);
1031 if (sc == NULL || sc->sc_type == SIEMPTY)
1033 regp = (struct si_reg *)sc->sc_maddr;
1036 * See if there has been a pending interrupt for 2 seconds
1037 * or so. The test (int_scounter >= 200) won't correspond
1038 * to 2 seconds if int_count gets changed.
1040 if (regp->int_pending != 0) {
1041 if (regp->int_scounter >= 200 &&
1042 regp->initstat == 1) {
1043 printf("si%d: lost intr\n", i);
1047 regp->int_scounter = 0;
1051 * gripe about no input flow control..
1054 for (port = 0; port < sc->sc_nport; pp++, port++) {
1055 if (pp->sp_delta_overflows > 0) {
1056 printf("si%d: %d tty level buffer overflows\n",
1057 i, pp->sp_delta_overflows);
1058 pp->sp_delta_overflows = 0;
1062 if (lost || si_realpoll)
1063 si_intr(NULL); /* call intr with fake vector */
1067 timeout(si_poll, (caddr_t)0L, si_pollrate);
1069 #endif /* ifdef POLL */
1072 * The interrupt handler polls ALL ports on ALL adapters each time
1076 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1077 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1082 struct si_softc *sc;
1084 volatile struct si_channel *ccbp;
1086 volatile caddr_t maddr;
1088 int x, card, port, n, i, isopen;
1094 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1100 * When we get an int we poll all the channels and do ALL pending
1101 * work, not just the first one we find. This allows all cards to
1102 * share the same vector.
1104 * XXX - But if we're sharing the vector with something that's NOT
1105 * a SI/XIO/SX card, we may be making more work for ourselves.
1107 for (card = 0; card < si_numunits; card++) {
1108 sc = devclass_get_softc(si_devclass, card);
1109 if (sc == NULL || sc->sc_type == SIEMPTY)
1113 * First, clear the interrupt
1115 switch(sc->sc_type) {
1117 maddr = sc->sc_maddr;
1118 ((volatile struct si_reg *)maddr)->int_pending = 0;
1119 /* flag nothing pending */
1120 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1121 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1124 maddr = sc->sc_maddr;
1125 ((volatile struct si_reg *)maddr)->int_pending = 0;
1126 *(maddr+SIPLIRQCLR) = 0x00;
1127 *(maddr+SIPLIRQCLR) = 0x10;
1130 maddr = sc->sc_maddr;
1131 ((volatile struct si_reg *)maddr)->int_pending = 0;
1132 *(maddr+SIPCIINTCL) = 0x0;
1134 case SIJETPCI: /* fall through to JETISA case */
1136 maddr = sc->sc_maddr;
1137 ((volatile struct si_reg *)maddr)->int_pending = 0;
1138 *(maddr+SIJETINTCL) = 0x0;
1142 maddr = sc->sc_maddr;
1143 ((volatile struct si_reg *)maddr)->int_pending = 0;
1144 (void)inb(sc->sc_iobase + 3);
1151 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1156 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1162 * See if a command has completed ?
1164 if (ccbp->hi_stat != pp->sp_pend) {
1165 DPRINT((pp, DBG_INTR,
1166 "si_intr hi_stat = 0x%x, pend = %d\n",
1167 ccbp->hi_stat, pp->sp_pend));
1168 switch(pp->sp_pend) {
1175 pp->sp_pend = ccbp->hi_stat;
1176 /* sleeping in si_command */
1177 wakeup(&pp->sp_state);
1180 pp->sp_pend = ccbp->hi_stat;
1185 * Continue on if it's closed
1187 if (ccbp->hi_stat == IDLE_CLOSE) {
1192 * Do modem state change if not a local device
1194 si_modem_state(pp, tp, ccbp->hi_ip);
1197 * Check to see if we should 'receive' characters.
1199 if (tp->t_state & TS_CONNECTED &&
1200 tp->t_state & TS_ISOPEN)
1206 * Do input break processing
1208 if (ccbp->hi_state & ST_BREAK) {
1210 ttyld_rint(tp, TTY_BI);
1212 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1213 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1217 * Do RX stuff - if not open then dump any characters.
1218 * XXX: This is VERY messy and needs to be cleaned up.
1220 * XXX: can we leave data in the host adapter buffer
1221 * when the clists are full? That may be dangerous
1222 * if the user cannot get an interrupt signal through.
1225 more_rx: /* XXX Sorry. the nesting was driving me bats! :-( */
1228 ccbp->hi_rxopos = ccbp->hi_rxipos;
1233 * If the tty input buffers are blocked, stop emptying
1234 * the incoming buffers and let the auto flow control
1237 if (tp->t_state & TS_TBLOCK) {
1242 * Process read characters if not skipped above
1244 op = ccbp->hi_rxopos;
1245 ip = ccbp->hi_rxipos;
1255 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1259 * Suck characters out of host card buffer into the
1260 * "input staging buffer" - so that we dont leave the
1261 * host card in limbo while we're possibly echoing
1262 * characters and possibly flushing input inside the
1263 * ldisc l_rint() routine.
1265 if (n <= SI_BUFFERSIZE - op) {
1267 DPRINT((pp, DBG_INTR, "\tsingle copy\n"));
1268 z = ccbp->hi_rxbuf + op;
1269 si_vbcopy(z, si_rxbuf, n);
1273 x = SI_BUFFERSIZE - op;
1275 DPRINT((pp, DBG_INTR, "\tdouble part 1 %d\n", x));
1276 z = ccbp->hi_rxbuf + op;
1277 si_vbcopy(z, si_rxbuf, x);
1279 DPRINT((pp, DBG_INTR, "\tdouble part 2 %d\n",
1282 si_vbcopy(z, si_rxbuf + x, n - x);
1287 /* clear collected characters from buffer */
1288 ccbp->hi_rxopos = op;
1290 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1295 * n = number of chars placed in si_rxbuf
1299 * Avoid the grotesquely inefficient lineswitch
1300 * routine (ttyinput) in "raw" mode. It usually
1301 * takes about 450 instructions (that's without
1302 * canonical processing or echo!). slinput is
1303 * reasonably fast (usually 40 instructions
1304 * plus call overhead).
1306 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1308 /* block if the driver supports it */
1309 if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER &&
1310 (tp->t_cflag & CRTS_IFLOW ||
1311 tp->t_iflag & IXOFF) &&
1312 !(tp->t_state & TS_TBLOCK))
1319 pp->sp_delta_overflows +=
1320 b_to_q((char *)si_rxbuf, n, &tp->t_rawq);
1323 if (tp->t_state & TS_TTSTOP &&
1324 (tp->t_iflag & IXANY ||
1325 tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1326 tp->t_state &= ~TS_TTSTOP;
1327 tp->t_lflag &= ~FLUSHO;
1332 * It'd be nice to not have to go through the
1333 * function call overhead for each char here.
1334 * It'd be nice to block input it, saving a
1335 * loop here and the call/return overhead.
1337 for(x = 0; x < n; x++) {
1339 if (ttyld_rint(tp, i)
1341 pp->sp_delta_overflows++;
1345 goto more_rx; /* try for more until RXbuf is empty */
1347 end_rx: /* XXX: Again, sorry about the gotos.. :-) */
1354 } /* end of for (all ports on this controller) */
1355 } /* end of for (all controllers) */
1358 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1362 * Nudge the transmitter...
1364 * XXX: I inherited some funny code here. It implies the host card only
1365 * interrupts when the transmit buffer reaches the low-water-mark, and does
1366 * not interrupt when it's actually hits empty. In some cases, we have
1367 * processes waiting for complete drain, and we need to simulate an interrupt
1368 * about when we think the buffer is going to be empty (and retry if not).
1369 * I really am not certain about this... I *need* the hardware manuals.
1372 si_start(struct tty *tp)
1375 volatile struct si_channel *ccbp;
1379 int oldspl, count, n, amount, buffer_full;
1386 DPRINT((pp, DBG_ENTRY|DBG_START,
1387 "si_start(%x) t_state %x sp_state %x t_outq.c_cc %d\n",
1388 tp, tp->t_state, pp->sp_state, qp->c_cc));
1390 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP))
1396 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1397 DPRINT((pp, DBG_START, "count %d\n", (BYTE)count));
1399 while ((nchar = qp->c_cc) > 0) {
1400 if ((BYTE)count >= 255) {
1404 amount = min(nchar, (255 - (BYTE)count));
1405 ipos = (unsigned int)ccbp->hi_txipos;
1406 n = q_to_b(&tp->t_outq, si_txbuf, amount);
1407 /* will it fit in one lump? */
1408 if ((SI_BUFFERSIZE - ipos) >= n) {
1409 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1411 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos],
1412 SI_BUFFERSIZE - ipos);
1413 si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos),
1414 &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos));
1416 ccbp->hi_txipos += n;
1417 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1420 if (count != 0 && nchar == 0) {
1421 tp->t_state |= TS_BUSY;
1423 tp->t_state &= ~TS_BUSY;
1429 DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n",
1430 (BYTE)count, nchar, tp->t_state));
1432 if (tp->t_state & TS_BUSY)
1436 time = ttspeedtab(tp->t_ospeed, chartimes);
1440 time = nchar / time;
1444 DPRINT((pp, DBG_START,
1445 "bad char time value! %d\n", time));
1449 if ((pp->sp_state & (SS_LSTART|SS_INLSTART)) == SS_LSTART) {
1450 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
1452 pp->sp_state |= SS_LSTART;
1454 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
1455 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time);
1460 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
1464 * Note: called at splsoftclock from the timeout code
1465 * This has to deal with two things... cause wakeups while waiting for
1466 * tty drains on last process exit, and call l_start at about the right
1467 * time for protocols like ppp.
1470 si_lstart(void *arg)
1472 struct si_port *pp = arg;
1476 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n",
1482 if ((tp->t_state & TS_ISOPEN) == 0 ||
1483 (pp->sp_state & SS_LSTART) == 0) {
1487 pp->sp_state &= ~SS_LSTART;
1488 pp->sp_state |= SS_INLSTART;
1491 /* deal with the process exit case */
1494 /* nudge protocols - eg: ppp */
1497 pp->sp_state &= ~SS_INLSTART;
1502 * Stop output on a line. called at spltty();
1505 si_stop(struct tty *tp, int rw)
1507 volatile struct si_channel *ccbp;
1513 DPRINT((pp, DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw));
1515 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
1517 /* what level are we meant to be flushing anyway? */
1518 if (tp->t_state & TS_BUSY) {
1519 si_command(pp, WFLUSH, SI_NOWAIT);
1520 tp->t_state &= ~TS_BUSY;
1521 ttwwakeup(tp); /* Bruce???? */
1524 #if 1 /* XXX: this doesn't work right yet.. */
1525 /* XXX: this may have been failing because we used to call l_rint()
1526 * while we were looping based on these two counters. Now, we collect
1527 * the data and then loop stuffing it into l_rint(), making this
1528 * useless. Should we cause this to blow away the staging buffer?
1531 ccbp->hi_rxopos = ccbp->hi_rxipos;
1537 * Issue a command to the host card CPU.
1541 si_command(struct si_port *pp, int cmd, int waitflag)
1544 volatile struct si_channel *ccbp = pp->sp_ccb;
1547 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%x,%d): hi_stat 0x%x\n",
1548 pp, cmd, waitflag, ccbp->hi_stat));
1550 oldspl = spltty(); /* Keep others out */
1552 /* wait until it's finished what it was doing.. */
1553 /* XXX: sits in IDLE_BREAK until something disturbs it or break
1555 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1559 if (in_intr) { /* Prevent sleep in intr */
1560 DPRINT((pp, DBG_PARAM,
1561 "cmd intr collision - completing %d\trequested %d\n",
1565 } else if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH,
1571 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
1573 /* if there was a pending command, cause a state-change wakeup */
1574 switch(pp->sp_pend) {
1581 wakeup(&pp->sp_state);
1587 pp->sp_pend = cmd; /* New command pending */
1588 ccbp->hi_stat = cmd; /* Post it */
1591 if (in_intr) { /* If in interrupt handler */
1592 DPRINT((pp, DBG_PARAM,
1593 "attempt to sleep in si_intr - cmd req %d\n",
1597 } else while(ccbp->hi_stat != IDLE_OPEN &&
1598 ccbp->hi_stat != IDLE_BREAK) {
1599 if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH,
1611 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
1615 if ((pp == NULL && (si_debug&flags)) ||
1616 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
1618 printf("%s: ", pp->sp_name);
1628 si_modulename(int host_type, int uart_type)
1630 switch (host_type) {
1631 /* Z280 based cards */
1638 switch (uart_type) {
1645 /* T225 based hosts */
1648 switch (uart_type) {