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"
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/serial.h>
53 #include <sys/fcntl.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
57 #include <sys/sysctl.h>
59 #include <machine/bus.h>
61 #include <machine/resource.h>
67 #include <machine/stdarg.h>
69 #include <dev/si/sireg.h>
70 #include <dev/si/sivar.h>
71 #include <dev/si/si.h>
74 * This device driver is designed to interface the Specialix International
75 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA,
76 * EISA or PCI bus machine.
78 * The controller is interfaced to the host via dual port RAM
81 * The code for the Host 1 (very old ISA cards) has not been tested.
84 #undef POLL /* turn on poller to scan for lost interrupts */
86 #define REALPOLL /* on each poll, scan for work regardless */
88 #define POLLHZ (hz/10) /* 10 times per second */
89 #define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE)
90 #define INT_COUNT 25000 /* max of 125 ints per second */
91 #define JET_INT_COUNT 100 /* max of 100 ints per second */
92 #define RXINT_COUNT 1 /* one rxint per 10 milliseconds */
94 static void si_command(struct si_port *, int, int);
95 static int si_Sioctl(struct cdev *, u_long, caddr_t, int, struct thread *);
96 /* static void si_stop(struct tty *, int); */
98 static timeout_t si_lstart;
101 static tsw_outwakeup_t si_start;
102 static tsw_ioctl_t siioctl;
103 static tsw_close_t siclose;
104 static tsw_modem_t simodem;
105 static tsw_open_t siopen;
106 static tsw_param_t siparam;
108 static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip);
109 static char * si_modulename(int host_type, int uart_type);
111 static struct cdevsw si_Scdevsw = {
112 .d_version = D_VERSION,
113 .d_ioctl = si_Sioctl,
115 .d_flags = D_TTY | D_NEEDGIANT,
118 static int si_Nports;
119 static int si_Nmodules;
122 SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, "");
123 TUNABLE_INT("machdep.si_debug", &si_debug);
125 static int si_numunits;
127 devclass_t si_devclass;
130 int sp_speed; /* Speed. */
131 int sp_code; /* Code. */
134 #ifndef B2000 /* not standard, but the hardware knows it. */
137 static struct si_speedtab bdrates[] = {
138 { B75, CLK75, }, /* 0x0 */
139 { B110, CLK110, }, /* 0x1 */
140 { B150, CLK150, }, /* 0x3 */
141 { B300, CLK300, }, /* 0x4 */
142 { B600, CLK600, }, /* 0x5 */
143 { B1200, CLK1200, }, /* 0x6 */
144 { B2000, CLK2000, }, /* 0x7 */
145 { B2400, CLK2400, }, /* 0x8 */
146 { B4800, CLK4800, }, /* 0x9 */
147 { B9600, CLK9600, }, /* 0xb */
148 { B19200, CLK19200, }, /* 0xc */
149 { B38400, CLK38400, }, /* 0x2 (out of order!) */
150 { B57600, CLK57600, }, /* 0xd */
151 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */
157 static int si_pollrate; /* in addition to irq */
158 static int si_realpoll = 0; /* poll HW on timer */
160 SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, "");
161 SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, "");
163 static int init_finished = 0;
164 static void si_poll(void *);
168 * Array of adapter types and the corresponding RAM size. The order of
169 * entries here MUST match the ordinal of the adapter type.
171 static const char *si_type[] = {
174 "SIMCA", /* FreeBSD does not support Microchannel */
189 case IDLE_OPEN: return("IDLE_OPEN");
190 case LOPEN: return("LOPEN");
191 case MOPEN: return("MOPEN");
192 case MPEND: return("MPEND");
193 case CONFIG: return("CONFIG");
194 case CLOSE: return("CLOSE");
195 case SBREAK: return("SBREAK");
196 case EBREAK: return("EBREAK");
197 case IDLE_CLOSE: return("IDLE_CLOSE");
198 case IDLE_BREAK: return("IDLE_BREAK");
199 case FCLOSE: return("FCLOSE");
200 case RESUME: return("RESUME");
201 case WFLUSH: return("WFLUSH");
202 case RFLUSH: return("RFLUSH");
204 sprintf(buf, "?cmd:0x%x?", cmd);
211 * We have to make an 8 bit version of bcopy, since some cards can't
212 * deal with 32 bit I/O
215 si_bcopy(const void *src, void *dst, size_t len)
226 si_vbcopy(const volatile void *src, void *dst, size_t len)
229 const volatile u_char *s;
237 si_bcopyv(const void *src, volatile void *dst, size_t len)
249 si_speedtab(int speed, struct si_speedtab *table)
251 for ( ; table->sp_speed != -1; table++)
252 if (table->sp_speed == speed)
253 return (table->sp_code);
258 static struct ttydevsw si_tty_class = {
259 .tsw_flags = TF_INITLOCK|TF_CALLOUT,
261 .tsw_close = siclose,
262 .tsw_outwakeup = si_start,
263 /* .tsw_stop = si_stop */
264 .tsw_ioctl = siioctl,
265 .tsw_param = siparam,
266 .tsw_modem = simodem,
271 * Attach the device. Initialize the card.
274 siattach(device_t dev)
280 volatile struct si_channel *ccbp;
281 volatile struct si_reg *regp;
282 volatile caddr_t maddr;
283 struct si_module *modp;
284 int nmodule, nport, x, y;
287 sc = device_get_softc(dev);
288 unit = device_get_unit(dev);
290 sc->sc_typename = si_type[sc->sc_type];
291 if (si_numunits < unit + 1)
292 si_numunits = unit + 1;
294 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit));
297 if (si_pollrate == 0) {
298 si_pollrate = POLLHZ; /* in addition to irq */
300 si_realpoll = 1; /* scan always */
305 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit,
306 sc->sc_typename, sc->sc_paddr, sc->sc_maddr));
308 sc->sc_ports = NULL; /* mark as uninitialised */
310 maddr = sc->sc_maddr;
312 /* Stop the CPU first so it won't stomp around while we load */
314 switch (sc->sc_type) {
317 outb(sc->sc_iobase + 2, sc->sc_irq << 4);
321 *(maddr+SIPCIRESET) = 0;
323 case SIJETPCI: /* fall through to JET ISA */
325 *(maddr+SIJETCONFIG) = 0;
328 *(maddr+SIPLRESET) = 0;
331 *(maddr+SIRESET) = 0;
333 default: /* this should never happen */
334 printf("si%d: unsupported configuration\n", unit);
339 /* OK, now lets download the download code */
341 if (SI_ISJET(sc->sc_type)) {
342 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n",
343 unit, si3_t225_dsize));
344 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr,
346 DPRINT((0, DBG_DOWNLOAD,
347 "si%d: jet_bootstrap: nbytes %d -> %x\n",
348 unit, si3_t225_bsize, si3_t225_bootloadaddr));
349 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr,
352 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n",
353 unit, si2_z280_dsize));
354 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr,
358 /* Now start the CPU */
360 switch (sc->sc_type) {
363 /* modify the download code to tell it that it's on an EISA */
365 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4);
366 (void)inb(sc->sc_iobase + 3); /* reset interrupt */
370 /* modify the download code to tell it that it's on a PCI */
372 *(maddr+SIPCIRESET) = 1;
373 *(maddr+SIPCIINTCL) = 0;
376 *(maddr+SIJETRESET) = 0;
377 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN;
380 *(maddr+SIJETRESET) = 0;
381 switch (sc->sc_irq) {
383 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90;
386 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0;
389 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0;
392 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0;
395 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0;
400 *(maddr+SIRESET_CL) = 0;
401 *(maddr+SIINTCL_CL) = 0;
404 *(maddr+SIPLRESET) = 0x10;
405 switch (sc->sc_irq) {
407 *(maddr+SIPLIRQ11) = 0x10;
410 *(maddr+SIPLIRQ12) = 0x10;
413 *(maddr+SIPLIRQ15) = 0x10;
416 *(maddr+SIPLIRQCLR) = 0x10;
418 default: /* this should _REALLY_ never happen */
419 printf("si%d: Uh, it was supported a second ago...\n", unit);
423 DELAY(1000000); /* wait around for a second */
425 regp = (struct si_reg *)maddr;
427 /* wait max of 5 sec for init OK */
428 while (regp->initstat == 0 && y++ < 10) {
431 switch (regp->initstat) {
433 printf("si%d: startup timeout - aborting\n", unit);
434 sc->sc_type = SIEMPTY;
437 if (SI_ISJET(sc->sc_type)) {
438 /* set throttle to 100 times per second */
439 regp->int_count = JET_INT_COUNT;
440 /* rx_intr_count is a NOP in Jet */
442 /* set throttle to 125 times per second */
443 regp->int_count = INT_COUNT;
444 /* rx intr max of 25 times per second */
445 regp->rx_int_count = RXINT_COUNT;
447 regp->int_pending = 0; /* no intr pending */
448 regp->int_scounter = 0; /* reset counter */
452 * No modules found, so give up on this one.
454 printf("si%d: %s - no ports found\n", unit,
455 si_type[sc->sc_type]);
458 printf("si%d: download code version error - initstat %x\n",
459 unit, regp->initstat);
464 * First time around the ports just count them in order
465 * to allocate some memory.
468 modp = (struct si_module *)(maddr + 0x80);
470 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp));
471 switch (modp->sm_type) {
473 DPRINT((0, DBG_DOWNLOAD,
474 "si%d: Found old TA4 module, 4 ports\n",
479 DPRINT((0, DBG_DOWNLOAD,
480 "si%d: Found old TA8 module, 8 ports\n",
485 DPRINT((0, DBG_DOWNLOAD,
486 "si%d: Found ASIC TA4 module, 4 ports\n",
491 DPRINT((0, DBG_DOWNLOAD,
492 "si%d: Found ASIC TA8 module, 8 ports\n",
497 DPRINT((0, DBG_DOWNLOAD,
498 "si%d: Found CD1400 module, 8 ports\n",
503 DPRINT((0, DBG_DOWNLOAD,
504 "si%d: Found SXDC module, 8 ports\n",
509 printf("si%d: unknown module type %d\n",
510 unit, modp->sm_type);
514 /* this was limited in firmware and is also a driver issue */
515 if ((nport + x) > SI_MAXPORTPERCARD) {
516 printf("si%d: extra ports ignored\n", unit);
525 if (modp->sm_next == 0)
527 modp = (struct si_module *)
528 (maddr + (unsigned)(modp->sm_next & 0x7fff));
530 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport,
531 M_DEVBUF, M_NOWAIT | M_ZERO);
532 if (sc->sc_ports == 0) {
533 printf("si%d: fail to malloc memory for port structs\n",
537 sc->sc_nport = nport;
540 * Scan round the ports again, this time initialising.
544 modp = (struct si_module *)(maddr + 0x80);
545 uart_type = 1000; /* arbitary, > uchar_max */
547 switch (modp->sm_type) {
570 ccbp = (struct si_channel *)((char *)modp + 0x100);
571 if (uart_type == 1000)
572 uart_type = ccbp->type;
573 else if (uart_type != ccbp->type)
574 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n",
576 ccbp->type, si_modulename(sc->sc_type, ccbp->type),
577 uart_type, si_modulename(sc->sc_type, uart_type));
579 for (x = 0; x < nport; x++, pp++, ccbp++) {
580 pp->sp_ccb = ccbp; /* save the address */
581 pp->sp_pend = IDLE_CLOSE;
582 pp->sp_state = 0; /* internal flag */
584 sprintf(pp->sp_name, "si%r%r", unit,
585 (int)(pp - sc->sc_ports));
587 tp = pp->sp_tty = tty_alloc_mutex(&si_tty_class, pp, &Giant);
588 tty_makedev(tp, NULL, "A%r%r", unit, (int)(pp - sc->sc_ports));
591 if (modp->sm_next == 0) {
592 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n",
598 si_modulename(sc->sc_type, uart_type));
601 modp = (struct si_module *)
602 (maddr + (unsigned)(modp->sm_next & 0x7fff));
606 make_dev(&si_Scdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
612 siopen(struct tty *tp)
615 DPRINT((0, DBG_ENTRY|DBG_OPEN, "siopen()\n"));
616 mtx_assert(&Giant, MA_OWNED);
619 * We've now got a device, so start the poller.
621 if (init_finished == 0) {
622 timeout(si_poll, (caddr_t)0L, si_pollrate);
626 DPRINT((0, DBG_EXIT|DBG_OPEN, "siopen() finished\n"));
631 siclose(struct tty *tp)
635 DPRINT((0, DBG_ENTRY|DBG_CLOSE, "siclose()\n"));
636 mtx_assert(&Giant, MA_OWNED);
638 (void) si_command(pp, FCLOSE, SI_WAIT);
639 DPRINT((0, DBG_EXIT|DBG_CLOSE, "siclose() finished\n"));
643 siioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
647 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "siioctl(0x%lx,0x%x)\n", cmd, data));
648 mtx_assert(&Giant, MA_OWNED);
652 si_command(pp, SBREAK, SI_WAIT);
655 si_command(pp, EBREAK, SI_WAIT);
658 return (ENOIOCTL); /* Let the common tty ioctl handler do it */
662 * Handle the Specialix ioctls on the control dev.
665 si_Sioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
667 struct si_softc *xsc;
669 volatile struct si_reg *regp;
671 struct si_pstat *sps;
676 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,0x%lx,0x%x)\n",
677 devtoname(dev), cmd, data));
678 mtx_assert(&Giant, MA_OWNED);
681 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT));
682 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB));
685 oldspl = spltty(); /* better safe than sorry */
689 #define SUCHECK if ((error = priv_check(td, PRIV_DRIVER))) goto out
707 * Check that a controller for this port exists
710 /* may also be a struct si_pstat, a superset of si_tcsi */
712 dp = (struct si_tcsi *)data;
713 sps = (struct si_pstat *)data;
715 xsc = devclass_get_softc(si_devclass, card); /* check.. */
716 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
721 * And check that a port exists
724 if (port < 0 || port >= xsc->sc_nport) {
728 xpp = xsc->sc_ports + port;
729 regp = (struct si_reg *)xsc->sc_maddr;
739 xpp->sp_debug = DBG_ALL;
740 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
741 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
751 if (cmd == TCSIGDBG_LEVEL) {
752 dp->tc_dbglvl = xpp->sp_debug;
755 xpp->sp_debug = dp->tc_dbglvl;
763 dp->tc_int = regp->rx_int_count;
767 regp->rx_int_count = dp->tc_int;
770 dp->tc_int = regp->int_count;
774 regp->int_count = dp->tc_int;
777 dp->tc_int = xpp->sp_ccb->hi_ip;
779 /* these next three use a different structure */
782 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
786 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
794 return(error); /* success */
798 * siparam() : Configure line params
799 * called at spltty();
800 * this may sleep, does not flush, nor wait for drain, nor block writes
801 * caller must arrange this if it's important..
804 siparam(struct tty *tp, struct termios *t)
806 struct si_port *pp = tty_softc(tp);
807 volatile struct si_channel *ccbp;
808 int oldspl, cflag, iflag, oflag, lflag;
809 int error = 0; /* shutup gcc */
810 int ispeed = 0; /* shutup gcc */
811 int ospeed = 0; /* shutup gcc */
814 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t));
815 mtx_assert(&Giant, MA_OWNED);
820 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
821 oflag, cflag, iflag, lflag));
823 /* XXX - if Jet host and SXDC module, use extended baud rates */
825 /* if not hung up.. */
826 if (t->c_ospeed != 0) {
827 /* translate baud rate to firmware values */
828 ospeed = si_speedtab(t->c_ospeed, bdrates);
829 ispeed = t->c_ispeed ?
830 si_speedtab(t->c_ispeed, bdrates) : ospeed;
831 /* enforce legit baud rate */
832 if (ospeed < 0 || ispeed < 0)
840 /* ========== set hi_break ========== */
842 if (iflag & IGNBRK) /* Breaks */
844 if (iflag & BRKINT) /* Interrupt on break? */
846 if (iflag & PARMRK) /* Parity mark? */
848 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
850 ccbp->hi_break = val;
852 /* ========== set hi_csr ========== */
853 /* if not hung up.. */
854 if (t->c_ospeed != 0) {
856 val = (ispeed << 4) | ospeed;
860 /* ========== set hi_mr2 ========== */
862 if (cflag & CSTOPB) /* Stop bits */
868 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
869 * a DCE, hence the reverse sense of RTS and CTS
871 /* Output Flow - RTS must be raised before data can be sent */
872 if (cflag & CCTS_OFLOW)
877 /* ========== set hi_mr1 ========== */
879 if (!(cflag & PARENB)) /* Parity */
886 if ((cflag & CS8) == CS8) /* 8 data bits? */
888 else if ((cflag & CS7) == CS7) /* 7 data bits? */
890 else if ((cflag & CS6) == CS6) /* 6 data bits? */
896 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
897 * a DCE, hence the reverse sense of RTS and CTS
899 /* Input Flow - CTS is raised when port is ready to receive data */
900 if (cflag & CRTS_IFLOW)
905 /* ========== set hi_mask ========== */
907 if ((cflag & CS8) == CS8) { /* 8 data bits? */
909 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
911 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
913 } else { /* Must be 5 */
921 /* ========== set hi_prtcl ========== */
922 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
932 ccbp->hi_prtcl = val;
935 /* ========== set hi_{rx|tx}{on|off} ========== */
936 /* XXX: the card TOTALLY shields us from the flow control... */
937 ccbp->hi_txon = t->c_cc[VSTART];
938 ccbp->hi_txoff = t->c_cc[VSTOP];
940 ccbp->hi_rxon = t->c_cc[VSTART];
941 ccbp->hi_rxoff = t->c_cc[VSTOP];
943 /* ========== send settings to the card ========== */
944 /* potential sleep here */
945 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
946 si_command(pp, LOPEN, SI_WAIT); /* open it */
948 si_command(pp, CONFIG, SI_WAIT); /* change params */
950 /* ========== set DTR etc ========== */
951 /* Hangup if ospeed == 0 */
952 if (t->c_ospeed == 0) {
953 (void) simodem(tp, 0, SER_DTR | SER_RTS);
956 * If the previous speed was 0, may need to re-enable
959 (void) simodem(tp, SER_DTR | SER_RTS, 0);
962 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x HI_CSR %x\n",
963 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break, ccbp->hi_csr));
970 * Set/Get state of modem control lines.
971 * Due to DCE-like behaviour of the adapter, some signals need translation:
976 simodem(struct tty *tp, int sigon, int sigoff)
979 volatile struct si_channel *ccbp;
983 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "simodem(%x,%x)\n", sigon, sigoff));
984 mtx_assert(&Giant, MA_OWNED);
985 ccbp = pp->sp_ccb; /* Find channel address */
986 if (sigon == 0 && sigoff == 0) {
989 * XXX: not sure this is correct, should it be CTS&DSR ?
990 * XXX: or do we (just) miss CTS & DSR ?
992 if (x & IP_DCD) sigon |= SER_DCD;
993 if (x & IP_DTR) sigon |= SER_DTR;
994 if (x & IP_RTS) sigon |= SER_RTS;
995 if (x & IP_RI) sigon |= SER_RI;
1000 if (sigon & SER_DTR)
1002 if (sigoff & SER_DTR)
1004 if (sigon & SER_RTS)
1006 if (sigoff & SER_RTS)
1013 * Handle change of modem state
1016 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
1018 /* if a modem dev */
1019 mtx_assert(&Giant, MA_OWNED);
1020 if (hi_ip & IP_DCD) {
1021 if (!(pp->sp_last_hi_ip & IP_DCD)) {
1022 DPRINT((pp, DBG_INTR, "modem carr on%d\n"));
1023 (void)ttydisc_modem(tp, 1);
1026 if (pp->sp_last_hi_ip & IP_DCD) {
1027 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1028 #if 0 /* XXX mpsafetty ttyld_modem used to tell us to shutdown the port or not */
1029 if (ttydisc_modem(tp, 0))
1030 (void) simodem(tp, 0, SER_DTR | SER_RTS);
1032 ttydisc_modem(tp, 0);
1036 pp->sp_last_hi_ip = hi_ip;
1041 * Poller to catch missed interrupts.
1043 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1044 * better response. We could really use a "periodic" version timeout(). :-)
1048 si_poll(void *nothing)
1050 struct si_softc *sc;
1052 volatile struct si_reg *regp;
1054 int lost, oldspl, port;
1056 DPRINT((0, DBG_POLL, "si_poll()\n"));
1058 mtx_assert(&Giant, MA_OWNED);
1060 for (i = 0; i < si_numunits; i++) {
1061 sc = devclass_get_softc(si_devclass, i);
1062 if (sc == NULL || sc->sc_type == SIEMPTY)
1064 regp = (struct si_reg *)sc->sc_maddr;
1067 * See if there has been a pending interrupt for 2 seconds
1068 * or so. The test (int_scounter >= 200) won't correspond
1069 * to 2 seconds if int_count gets changed.
1071 if (regp->int_pending != 0) {
1072 if (regp->int_scounter >= 200 &&
1073 regp->initstat == 1) {
1074 printf("si%d: lost intr\n", i);
1078 regp->int_scounter = 0;
1082 * gripe about no input flow control..
1085 for (port = 0; port < sc->sc_nport; pp++, port++) {
1086 if (pp->sp_delta_overflows > 0) {
1087 printf("si%d: %d tty level buffer overflows\n",
1088 i, pp->sp_delta_overflows);
1089 pp->sp_delta_overflows = 0;
1093 if (lost || si_realpoll)
1094 si_intr(NULL); /* call intr with fake vector */
1097 timeout(si_poll, (caddr_t)0L, si_pollrate);
1099 #endif /* ifdef POLL */
1102 * The interrupt handler polls ALL ports on ALL adapters each time
1106 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1107 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1112 struct si_softc *sc;
1114 volatile struct si_channel *ccbp;
1116 volatile caddr_t maddr;
1118 int x, card, port, n, i, isopen;
1123 mtx_assert(&Giant, MA_OWNED);
1125 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1128 * When we get an int we poll all the channels and do ALL pending
1129 * work, not just the first one we find. This allows all cards to
1130 * share the same vector.
1132 * XXX - But if we're sharing the vector with something that's NOT
1133 * a SI/XIO/SX card, we may be making more work for ourselves.
1135 for (card = 0; card < si_numunits; card++) {
1136 sc = devclass_get_softc(si_devclass, card);
1137 if (sc == NULL || sc->sc_type == SIEMPTY)
1141 * First, clear the interrupt
1143 switch(sc->sc_type) {
1145 maddr = sc->sc_maddr;
1146 ((volatile struct si_reg *)maddr)->int_pending = 0;
1147 /* flag nothing pending */
1148 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1149 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1152 maddr = sc->sc_maddr;
1153 ((volatile struct si_reg *)maddr)->int_pending = 0;
1154 *(maddr+SIPLIRQCLR) = 0x00;
1155 *(maddr+SIPLIRQCLR) = 0x10;
1158 maddr = sc->sc_maddr;
1159 ((volatile struct si_reg *)maddr)->int_pending = 0;
1160 *(maddr+SIPCIINTCL) = 0x0;
1162 case SIJETPCI: /* fall through to JETISA case */
1164 maddr = sc->sc_maddr;
1165 ((volatile struct si_reg *)maddr)->int_pending = 0;
1166 *(maddr+SIJETINTCL) = 0x0;
1170 maddr = sc->sc_maddr;
1171 ((volatile struct si_reg *)maddr)->int_pending = 0;
1172 (void)inb(sc->sc_iobase + 3);
1179 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1184 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1191 * See if a command has completed ?
1193 if (ccbp->hi_stat != pp->sp_pend) {
1194 DPRINT((pp, DBG_INTR,
1195 "si_intr hi_stat = %s, pend = %s\n",
1196 si_cmdname(ccbp->hi_stat),
1197 si_cmdname(pp->sp_pend)));
1198 switch(pp->sp_pend) {
1206 /* sleeping in si_command */
1207 DPRINT((pp, DBG_INTR, "do wakeup\n"));
1208 wakeup(&pp->sp_state);
1211 pp->sp_pend = ccbp->hi_stat;
1215 * Continue on if it's closed
1217 if (ccbp->hi_stat == IDLE_CLOSE) {
1223 * Do modem state change if not a local device
1225 si_modem_state(pp, tp, ccbp->hi_ip);
1228 * Check to see if we should 'receive' characters.
1230 isopen = tty_opened(tp);
1233 * Do input break processing
1235 if (ccbp->hi_state & ST_BREAK) {
1237 ttydisc_rint(tp, 0, TRE_BREAK);
1238 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1239 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1243 * Do RX stuff - if not open then dump any characters.
1244 * XXX: This is VERY messy and needs to be cleaned up.
1246 * XXX: can we leave data in the host adapter buffer
1247 * when the clists are full? That may be dangerous
1248 * if the user cannot get an interrupt signal through.
1254 DPRINT((pp, DBG_INTR, "intr1: not open\n"));
1255 ccbp->hi_rxopos = ccbp->hi_rxipos;
1259 #if 0 /* XXXMPSAFETTY */
1261 * If the tty input buffers are blocked, stop emptying
1262 * the incoming buffers and let the auto flow control
1265 if (tp->t_state & TS_TBLOCK)
1270 * Process read characters if not skipped above
1272 op = ccbp->hi_rxopos;
1273 ip = ccbp->hi_rxipos;
1282 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1286 * Suck characters out of host card buffer into the
1287 * "input staging buffer" - so that we dont leave the
1288 * host card in limbo while we're possibly echoing
1289 * characters and possibly flushing input inside the
1290 * ldisc l_rint() routine.
1292 if (n <= SI_BUFFERSIZE - op) {
1294 z = ccbp->hi_rxbuf + op;
1295 si_vbcopy(z, si_rxbuf, n);
1299 x = SI_BUFFERSIZE - op;
1301 z = ccbp->hi_rxbuf + op;
1302 si_vbcopy(z, si_rxbuf, x);
1305 si_vbcopy(z, si_rxbuf + x, n - x);
1310 /* clear collected characters from buffer */
1311 ccbp->hi_rxopos = op;
1315 * n = number of chars placed in si_rxbuf
1318 if (0 && ttydisc_can_bypass(tp)) {
1320 i = ttydisc_rint_bypass(tp, (char *)si_rxbuf, n);
1322 pp->sp_delta_overflows += (n - i);
1326 * It'd be nice to not have to go through the
1327 * function call overhead for each char here.
1328 * It'd be nice to block input it, saving a
1329 * loop here and the call/return overhead.
1331 for(x = 0; x < n; x++) {
1333 if (ttydisc_rint(tp, i, 0) == -1)
1334 pp->sp_delta_overflows++;
1337 goto more_rx; /* try for more until RXbuf is empty */
1341 ttydisc_rint_done(tp);
1349 } /* end of for (all ports on this controller) */
1350 } /* end of for (all controllers) */
1352 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1356 * Nudge the transmitter...
1358 * XXX: I inherited some funny code here. It implies the host card only
1359 * interrupts when the transmit buffer reaches the low-water-mark, and does
1360 * not interrupt when it's actually hits empty. In some cases, we have
1361 * processes waiting for complete drain, and we need to simulate an interrupt
1362 * about when we think the buffer is going to be empty (and retry if not).
1363 * I really am not certain about this... I *need* the hardware manuals.
1366 si_start(struct tty *tp)
1369 volatile struct si_channel *ccbp;
1374 int oldspl, n, amount;
1377 mtx_assert(&Giant, MA_OWNED);
1381 DPRINT((pp, DBG_ENTRY|DBG_START,
1382 "si_start(%x) sp_state %x\n",
1387 while ((count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos) < 255) {
1388 DPRINT((pp, DBG_START, "txbuf pend count %d\n", (BYTE)count));
1389 ipos = (unsigned int)ccbp->hi_txipos;
1390 if ((int)ccbp->hi_txopos <= ipos)
1391 amount = SI_BUFFERSIZE - ipos;
1393 amount = 255 - count;
1394 DPRINT((pp, DBG_START, "spaceleft amount %d\n", amount));
1397 n = ttydisc_getc(tp, si_txbuf, amount);
1398 DPRINT((pp, DBG_START, "getc n=%d\n", n));
1401 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1402 ccbp->hi_txipos += n;
1407 * See if there are any characters still to come. If so, we can
1408 * depend on si_start being called again.
1410 * XXX the manual is vague on this. It implies we get an interrupt
1411 * when the transmit queue reaches the 25% low water mark, but NOT
1412 * when it hits empty.
1414 nchar = ttyoutq_getsize(&tp->t_outq) - ttyoutq_bytesleft(&tp->t_outq);
1415 DPRINT((pp, DBG_START, "count %d, nchar %d\n",
1416 (BYTE)count, nchar));
1418 if (count != 0 && nchar == 0) {
1421 /* XXX lame. Ticks per character. used to be a table. */
1422 time = (tp->t_termios.c_ospeed + 9) / 10;
1426 time = nchar / time;
1430 DPRINT((pp, DBG_START,
1431 "bad char time value! %d\n", time));
1435 if ((pp->sp_state & SS_LSTART) != 0)
1436 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
1437 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
1438 pp->sp_state |= SS_LSTART;
1439 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time);
1444 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
1449 * This has to deal with two things... cause wakeups while waiting for
1450 * tty drains on last process exit, and call l_start at about the right
1451 * time for protocols like ppp.
1454 si_lstart(void *arg)
1456 struct si_port *pp = arg;
1460 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n",
1464 mtx_assert(&Giant, MA_OWNED);
1465 pp->sp_state &= ~SS_LSTART;
1474 #if 0 /* XXX mpsafetty */
1476 * Stop output on a line. called at spltty();
1479 si_stop(struct tty *tp, int rw)
1481 volatile struct si_channel *ccbp;
1484 mtx_assert(&Giant, MA_OWNED);
1488 DPRINT((pp, DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw));
1490 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
1492 /* what level are we meant to be flushing anyway? */
1493 if (tp->t_state & TS_BUSY) {
1494 si_command(pp, WFLUSH, SI_NOWAIT);
1495 tp->t_state &= ~TS_BUSY;
1496 ttwwakeup(tp); /* Bruce???? */
1499 #if 1 /* XXX: this doesn't work right yet.. */
1500 /* XXX: this may have been failing because we used to call l_rint()
1501 * while we were looping based on these two counters. Now, we collect
1502 * the data and then loop stuffing it into l_rint(), making this
1503 * useless. Should we cause this to blow away the staging buffer?
1506 ccbp->hi_rxopos = ccbp->hi_rxipos;
1513 * Issue a command to the host card CPU.
1515 * XXX This is all just so WRONG!. Ed says we're not supposed to sleep
1516 * here anyway. We sort of get away with it for now by using Giant.
1517 * Something better will have to be done.
1518 * Linux does a busy spin here waiting for the 8-bit cpu to notice the
1519 * posted command and respond to it. I'm not sure I like that either.
1522 si_command(struct si_port *pp, int cmd, int waitflag)
1525 volatile struct si_channel *ccbp = pp->sp_ccb;
1529 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%s,%d): hi_stat %s, sp_pend: %s\n",
1530 pp, si_cmdname(cmd), waitflag, si_cmdname(ccbp->hi_stat),
1531 si_cmdname(pp->sp_pend)));
1533 oldspl = spltty(); /* Keep others out */
1534 mtx_assert(&Giant, MA_OWNED);
1536 /* wait until it's finished what it was doing.. */
1537 /* XXX: sits in IDLE_BREAK until something disturbs it or break
1539 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1543 DPRINT((pp, DBG_PARAM, "sicmd1 old cmd pending (going to tsleep): hi_stat (%s)\n", si_cmdname(ccbp->hi_stat)));
1544 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd1", hz/4);
1546 DPRINT((pp, DBG_PARAM, "sicmd1 timeout: hi_stat (%s)\n",
1547 si_cmdname(ccbp->hi_stat)));
1548 /* This is very very bad. The card has crashed. */
1549 /* XXX the driver breaks at this point */
1550 if (err == ETIMEDOUT)
1551 DPRINT(("%s: tsleep1 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1556 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
1557 DPRINT((pp, DBG_PARAM, "sicmd1 now in: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1559 /* if there was a pending command, cause a state-change wakeup */
1560 switch(pp->sp_pend) {
1568 DPRINT((pp, DBG_PARAM, "si_command: sp_pend %s, doing wakeup\n", si_cmdname(pp->sp_pend)));
1569 wakeup(&pp->sp_state);
1575 pp->sp_pend = cmd; /* New command pending */
1576 ccbp->hi_stat = cmd; /* Post it */
1577 DPRINT((pp, DBG_PARAM, "sicmd now posted: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1580 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1583 DPRINT((pp, DBG_PARAM, "sicmd2 now waiting: hi_stat (%s) sp_pend (%s) (going to tsleep)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1584 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd2", hz);
1586 DPRINT((pp, DBG_PARAM, "sicmd2 tsleep error: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1587 if (err == ETIMEDOUT) {
1588 DPRINT(("%s: tsleep2 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1594 DPRINT((pp, DBG_PARAM, "sicmd2 finished: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1602 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
1606 if ((pp == NULL && (si_debug&flags)) ||
1607 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
1609 printf("%s: ", pp->sp_name);
1619 si_modulename(int host_type, int uart_type)
1621 switch (host_type) {
1622 /* Z280 based cards */
1629 switch (uart_type) {
1636 /* T225 based hosts */
1639 switch (uart_type) {