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 __IDSTRING(si_copyright1, "@(#) Copyright (C) Specialix International, 1990,1992,1998");
40 __IDSTRING(si_copyright2, "@(#) Copyright (C) Andy Rutter 1993");
41 __IDSTRING(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_RWTUN, &si_debug, 0, "");
124 static int si_numunits;
126 devclass_t si_devclass;
129 int sp_speed; /* Speed. */
130 int sp_code; /* Code. */
133 #ifndef B2000 /* not standard, but the hardware knows it. */
136 static struct si_speedtab bdrates[] = {
137 { B75, CLK75, }, /* 0x0 */
138 { B110, CLK110, }, /* 0x1 */
139 { B150, CLK150, }, /* 0x3 */
140 { B300, CLK300, }, /* 0x4 */
141 { B600, CLK600, }, /* 0x5 */
142 { B1200, CLK1200, }, /* 0x6 */
143 { B2000, CLK2000, }, /* 0x7 */
144 { B2400, CLK2400, }, /* 0x8 */
145 { B4800, CLK4800, }, /* 0x9 */
146 { B9600, CLK9600, }, /* 0xb */
147 { B19200, CLK19200, }, /* 0xc */
148 { B38400, CLK38400, }, /* 0x2 (out of order!) */
149 { B57600, CLK57600, }, /* 0xd */
150 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */
156 static int si_pollrate; /* in addition to irq */
157 static int si_realpoll = 0; /* poll HW on timer */
159 SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, "");
160 SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, "");
162 static int init_finished = 0;
163 static void si_poll(void *);
167 * Array of adapter types and the corresponding RAM size. The order of
168 * entries here MUST match the ordinal of the adapter type.
170 static const char *si_type[] = {
173 "SIMCA", /* FreeBSD does not support Microchannel */
188 case IDLE_OPEN: return("IDLE_OPEN");
189 case LOPEN: return("LOPEN");
190 case MOPEN: return("MOPEN");
191 case MPEND: return("MPEND");
192 case CONFIG: return("CONFIG");
193 case CLOSE: return("CLOSE");
194 case SBREAK: return("SBREAK");
195 case EBREAK: return("EBREAK");
196 case IDLE_CLOSE: return("IDLE_CLOSE");
197 case IDLE_BREAK: return("IDLE_BREAK");
198 case FCLOSE: return("FCLOSE");
199 case RESUME: return("RESUME");
200 case WFLUSH: return("WFLUSH");
201 case RFLUSH: return("RFLUSH");
203 sprintf(buf, "?cmd:0x%x?", cmd);
210 * We have to make an 8 bit version of bcopy, since some cards can't
211 * deal with 32 bit I/O
214 si_bcopy(const void *src, void *dst, size_t len)
225 si_vbcopy(const volatile void *src, void *dst, size_t len)
228 const volatile u_char *s;
236 si_bcopyv(const void *src, volatile void *dst, size_t len)
248 si_speedtab(int speed, struct si_speedtab *table)
250 for ( ; table->sp_speed != -1; table++)
251 if (table->sp_speed == speed)
252 return (table->sp_code);
257 static struct ttydevsw si_tty_class = {
258 .tsw_flags = TF_INITLOCK|TF_CALLOUT,
260 .tsw_close = siclose,
261 .tsw_outwakeup = si_start,
262 /* .tsw_stop = si_stop */
263 .tsw_ioctl = siioctl,
264 .tsw_param = siparam,
265 .tsw_modem = simodem,
270 * Attach the device. Initialize the card.
273 siattach(device_t dev)
279 volatile struct si_channel *ccbp;
280 volatile struct si_reg *regp;
281 volatile caddr_t maddr;
282 struct si_module *modp;
283 int nmodule, nport, x, y;
286 sc = device_get_softc(dev);
287 unit = device_get_unit(dev);
289 sc->sc_typename = si_type[sc->sc_type];
290 if (si_numunits < unit + 1)
291 si_numunits = unit + 1;
293 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit));
296 if (si_pollrate == 0) {
297 si_pollrate = POLLHZ; /* in addition to irq */
299 si_realpoll = 1; /* scan always */
304 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit,
305 sc->sc_typename, sc->sc_paddr, sc->sc_maddr));
307 sc->sc_ports = NULL; /* mark as uninitialised */
309 maddr = sc->sc_maddr;
311 /* Stop the CPU first so it won't stomp around while we load */
313 switch (sc->sc_type) {
316 outb(sc->sc_iobase + 2, sc->sc_irq << 4);
320 *(maddr+SIPCIRESET) = 0;
322 case SIJETPCI: /* fall through to JET ISA */
324 *(maddr+SIJETCONFIG) = 0;
327 *(maddr+SIPLRESET) = 0;
330 *(maddr+SIRESET) = 0;
332 default: /* this should never happen */
333 printf("si%d: unsupported configuration\n", unit);
338 /* OK, now lets download the download code */
340 if (SI_ISJET(sc->sc_type)) {
341 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n",
342 unit, si3_t225_dsize));
343 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr,
345 DPRINT((0, DBG_DOWNLOAD,
346 "si%d: jet_bootstrap: nbytes %d -> %x\n",
347 unit, si3_t225_bsize, si3_t225_bootloadaddr));
348 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr,
351 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n",
352 unit, si2_z280_dsize));
353 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr,
357 /* Now start the CPU */
359 switch (sc->sc_type) {
362 /* modify the download code to tell it that it's on an EISA */
364 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4);
365 (void)inb(sc->sc_iobase + 3); /* reset interrupt */
369 /* modify the download code to tell it that it's on a PCI */
371 *(maddr+SIPCIRESET) = 1;
372 *(maddr+SIPCIINTCL) = 0;
375 *(maddr+SIJETRESET) = 0;
376 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN;
379 *(maddr+SIJETRESET) = 0;
380 switch (sc->sc_irq) {
382 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90;
385 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0;
388 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0;
391 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0;
394 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0;
399 *(maddr+SIRESET_CL) = 0;
400 *(maddr+SIINTCL_CL) = 0;
403 *(maddr+SIPLRESET) = 0x10;
404 switch (sc->sc_irq) {
406 *(maddr+SIPLIRQ11) = 0x10;
409 *(maddr+SIPLIRQ12) = 0x10;
412 *(maddr+SIPLIRQ15) = 0x10;
415 *(maddr+SIPLIRQCLR) = 0x10;
417 default: /* this should _REALLY_ never happen */
418 printf("si%d: Uh, it was supported a second ago...\n", unit);
422 DELAY(1000000); /* wait around for a second */
424 regp = (struct si_reg *)maddr;
426 /* wait max of 5 sec for init OK */
427 while (regp->initstat == 0 && y++ < 10) {
430 switch (regp->initstat) {
432 printf("si%d: startup timeout - aborting\n", unit);
433 sc->sc_type = SIEMPTY;
436 if (SI_ISJET(sc->sc_type)) {
437 /* set throttle to 100 times per second */
438 regp->int_count = JET_INT_COUNT;
439 /* rx_intr_count is a NOP in Jet */
441 /* set throttle to 125 times per second */
442 regp->int_count = INT_COUNT;
443 /* rx intr max of 25 times per second */
444 regp->rx_int_count = RXINT_COUNT;
446 regp->int_pending = 0; /* no intr pending */
447 regp->int_scounter = 0; /* reset counter */
451 * No modules found, so give up on this one.
453 printf("si%d: %s - no ports found\n", unit,
454 si_type[sc->sc_type]);
457 printf("si%d: download code version error - initstat %x\n",
458 unit, regp->initstat);
463 * First time around the ports just count them in order
464 * to allocate some memory.
467 modp = (struct si_module *)(maddr + 0x80);
469 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp));
470 switch (modp->sm_type) {
472 DPRINT((0, DBG_DOWNLOAD,
473 "si%d: Found old TA4 module, 4 ports\n",
478 DPRINT((0, DBG_DOWNLOAD,
479 "si%d: Found old TA8 module, 8 ports\n",
484 DPRINT((0, DBG_DOWNLOAD,
485 "si%d: Found ASIC TA4 module, 4 ports\n",
490 DPRINT((0, DBG_DOWNLOAD,
491 "si%d: Found ASIC TA8 module, 8 ports\n",
496 DPRINT((0, DBG_DOWNLOAD,
497 "si%d: Found CD1400 module, 8 ports\n",
502 DPRINT((0, DBG_DOWNLOAD,
503 "si%d: Found SXDC module, 8 ports\n",
508 printf("si%d: unknown module type %d\n",
509 unit, modp->sm_type);
513 /* this was limited in firmware and is also a driver issue */
514 if ((nport + x) > SI_MAXPORTPERCARD) {
515 printf("si%d: extra ports ignored\n", unit);
524 if (modp->sm_next == 0)
526 modp = (struct si_module *)
527 (maddr + (unsigned)(modp->sm_next & 0x7fff));
529 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport,
530 M_DEVBUF, M_NOWAIT | M_ZERO);
531 if (sc->sc_ports == 0) {
532 printf("si%d: fail to malloc memory for port structs\n",
536 sc->sc_nport = nport;
539 * Scan round the ports again, this time initialising.
543 modp = (struct si_module *)(maddr + 0x80);
544 uart_type = 1000; /* arbitary, > uchar_max */
546 switch (modp->sm_type) {
569 ccbp = (struct si_channel *)((char *)modp + 0x100);
570 if (uart_type == 1000)
571 uart_type = ccbp->type;
572 else if (uart_type != ccbp->type)
573 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n",
575 ccbp->type, si_modulename(sc->sc_type, ccbp->type),
576 uart_type, si_modulename(sc->sc_type, uart_type));
578 for (x = 0; x < nport; x++, pp++, ccbp++) {
579 pp->sp_ccb = ccbp; /* save the address */
580 pp->sp_pend = IDLE_CLOSE;
581 pp->sp_state = 0; /* internal flag */
583 sprintf(pp->sp_name, "si%r%r", unit,
584 (int)(pp - sc->sc_ports));
586 tp = pp->sp_tty = tty_alloc_mutex(&si_tty_class, pp, &Giant);
587 tty_makedev(tp, NULL, "A%r%r", unit, (int)(pp - sc->sc_ports));
590 if (modp->sm_next == 0) {
591 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n",
597 si_modulename(sc->sc_type, uart_type));
600 modp = (struct si_module *)
601 (maddr + (unsigned)(modp->sm_next & 0x7fff));
605 make_dev(&si_Scdevsw, 0, UID_ROOT, GID_WHEEL, 0600,
611 siopen(struct tty *tp)
614 DPRINT((0, DBG_ENTRY|DBG_OPEN, "siopen()\n"));
615 mtx_assert(&Giant, MA_OWNED);
618 * We've now got a device, so start the poller.
620 if (init_finished == 0) {
621 timeout(si_poll, (caddr_t)0L, si_pollrate);
625 DPRINT((0, DBG_EXIT|DBG_OPEN, "siopen() finished\n"));
630 siclose(struct tty *tp)
634 DPRINT((0, DBG_ENTRY|DBG_CLOSE, "siclose()\n"));
635 mtx_assert(&Giant, MA_OWNED);
637 (void) si_command(pp, FCLOSE, SI_WAIT);
638 DPRINT((0, DBG_EXIT|DBG_CLOSE, "siclose() finished\n"));
642 siioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
646 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "siioctl(0x%lx,0x%x)\n", cmd, data));
647 mtx_assert(&Giant, MA_OWNED);
651 si_command(pp, SBREAK, SI_WAIT);
654 si_command(pp, EBREAK, SI_WAIT);
657 return (ENOIOCTL); /* Let the common tty ioctl handler do it */
661 * Handle the Specialix ioctls on the control dev.
664 si_Sioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
666 struct si_softc *xsc;
668 volatile struct si_reg *regp;
670 struct si_pstat *sps;
675 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,0x%lx,0x%x)\n",
676 devtoname(dev), cmd, data));
677 mtx_assert(&Giant, MA_OWNED);
680 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT));
681 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB));
684 oldspl = spltty(); /* better safe than sorry */
688 #define SUCHECK if ((error = priv_check(td, PRIV_DRIVER))) goto out
706 * Check that a controller for this port exists
709 /* may also be a struct si_pstat, a superset of si_tcsi */
711 dp = (struct si_tcsi *)data;
712 sps = (struct si_pstat *)data;
714 xsc = devclass_get_softc(si_devclass, card); /* check.. */
715 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
720 * And check that a port exists
723 if (port < 0 || port >= xsc->sc_nport) {
727 xpp = xsc->sc_ports + port;
728 regp = (struct si_reg *)xsc->sc_maddr;
738 xpp->sp_debug = DBG_ALL;
739 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
740 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
750 if (cmd == TCSIGDBG_LEVEL) {
751 dp->tc_dbglvl = xpp->sp_debug;
754 xpp->sp_debug = dp->tc_dbglvl;
762 dp->tc_int = regp->rx_int_count;
766 regp->rx_int_count = dp->tc_int;
769 dp->tc_int = regp->int_count;
773 regp->int_count = dp->tc_int;
776 dp->tc_int = xpp->sp_ccb->hi_ip;
778 /* these next three use a different structure */
781 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
785 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
793 return(error); /* success */
797 * siparam() : Configure line params
798 * called at spltty();
799 * this may sleep, does not flush, nor wait for drain, nor block writes
800 * caller must arrange this if it's important..
803 siparam(struct tty *tp, struct termios *t)
805 struct si_port *pp = tty_softc(tp);
806 volatile struct si_channel *ccbp;
807 int oldspl, cflag, iflag, oflag, lflag;
808 int error = 0; /* shutup gcc */
809 int ispeed = 0; /* shutup gcc */
810 int ospeed = 0; /* shutup gcc */
813 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t));
814 mtx_assert(&Giant, MA_OWNED);
819 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
820 oflag, cflag, iflag, lflag));
822 /* XXX - if Jet host and SXDC module, use extended baud rates */
824 /* if not hung up.. */
825 if (t->c_ospeed != 0) {
826 /* translate baud rate to firmware values */
827 ospeed = si_speedtab(t->c_ospeed, bdrates);
828 ispeed = t->c_ispeed ?
829 si_speedtab(t->c_ispeed, bdrates) : ospeed;
830 /* enforce legit baud rate */
831 if (ospeed < 0 || ispeed < 0)
839 /* ========== set hi_break ========== */
841 if (iflag & IGNBRK) /* Breaks */
843 if (iflag & BRKINT) /* Interrupt on break? */
845 if (iflag & PARMRK) /* Parity mark? */
847 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
849 ccbp->hi_break = val;
851 /* ========== set hi_csr ========== */
852 /* if not hung up.. */
853 if (t->c_ospeed != 0) {
855 val = (ispeed << 4) | ospeed;
859 /* ========== set hi_mr2 ========== */
861 if (cflag & CSTOPB) /* Stop bits */
867 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
868 * a DCE, hence the reverse sense of RTS and CTS
870 /* Output Flow - RTS must be raised before data can be sent */
871 if (cflag & CCTS_OFLOW)
876 /* ========== set hi_mr1 ========== */
878 if (!(cflag & PARENB)) /* Parity */
885 if ((cflag & CS8) == CS8) /* 8 data bits? */
887 else if ((cflag & CS7) == CS7) /* 7 data bits? */
889 else if ((cflag & CS6) == CS6) /* 6 data bits? */
895 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
896 * a DCE, hence the reverse sense of RTS and CTS
898 /* Input Flow - CTS is raised when port is ready to receive data */
899 if (cflag & CRTS_IFLOW)
904 /* ========== set hi_mask ========== */
906 if ((cflag & CS8) == CS8) { /* 8 data bits? */
908 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
910 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
912 } else { /* Must be 5 */
920 /* ========== set hi_prtcl ========== */
921 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
931 ccbp->hi_prtcl = val;
934 /* ========== set hi_{rx|tx}{on|off} ========== */
935 /* XXX: the card TOTALLY shields us from the flow control... */
936 ccbp->hi_txon = t->c_cc[VSTART];
937 ccbp->hi_txoff = t->c_cc[VSTOP];
939 ccbp->hi_rxon = t->c_cc[VSTART];
940 ccbp->hi_rxoff = t->c_cc[VSTOP];
942 /* ========== send settings to the card ========== */
943 /* potential sleep here */
944 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
945 si_command(pp, LOPEN, SI_WAIT); /* open it */
947 si_command(pp, CONFIG, SI_WAIT); /* change params */
949 /* ========== set DTR etc ========== */
950 /* Hangup if ospeed == 0 */
951 if (t->c_ospeed == 0) {
952 (void) simodem(tp, 0, SER_DTR | SER_RTS);
955 * If the previous speed was 0, may need to re-enable
958 (void) simodem(tp, SER_DTR | SER_RTS, 0);
961 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x HI_CSR %x\n",
962 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break, ccbp->hi_csr));
969 * Set/Get state of modem control lines.
970 * Due to DCE-like behaviour of the adapter, some signals need translation:
975 simodem(struct tty *tp, int sigon, int sigoff)
978 volatile struct si_channel *ccbp;
982 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "simodem(%x,%x)\n", sigon, sigoff));
983 mtx_assert(&Giant, MA_OWNED);
984 ccbp = pp->sp_ccb; /* Find channel address */
985 if (sigon == 0 && sigoff == 0) {
988 * XXX: not sure this is correct, should it be CTS&DSR ?
989 * XXX: or do we (just) miss CTS & DSR ?
991 if (x & IP_DCD) sigon |= SER_DCD;
992 if (x & IP_DTR) sigon |= SER_DTR;
993 if (x & IP_RTS) sigon |= SER_RTS;
994 if (x & IP_RI) sigon |= SER_RI;
1001 if (sigoff & SER_DTR)
1003 if (sigon & SER_RTS)
1005 if (sigoff & SER_RTS)
1012 * Handle change of modem state
1015 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
1017 /* if a modem dev */
1018 mtx_assert(&Giant, MA_OWNED);
1019 if (hi_ip & IP_DCD) {
1020 if (!(pp->sp_last_hi_ip & IP_DCD)) {
1021 DPRINT((pp, DBG_INTR, "modem carr on%d\n"));
1022 (void)ttydisc_modem(tp, 1);
1025 if (pp->sp_last_hi_ip & IP_DCD) {
1026 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1027 #if 0 /* XXX mpsafetty ttyld_modem used to tell us to shutdown the port or not */
1028 if (ttydisc_modem(tp, 0))
1029 (void) simodem(tp, 0, SER_DTR | SER_RTS);
1031 ttydisc_modem(tp, 0);
1035 pp->sp_last_hi_ip = hi_ip;
1040 * Poller to catch missed interrupts.
1042 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1043 * better response. We could really use a "periodic" version timeout(). :-)
1047 si_poll(void *nothing)
1049 struct si_softc *sc;
1051 volatile struct si_reg *regp;
1053 int lost, oldspl, port;
1055 DPRINT((0, DBG_POLL, "si_poll()\n"));
1057 mtx_assert(&Giant, MA_OWNED);
1059 for (i = 0; i < si_numunits; i++) {
1060 sc = devclass_get_softc(si_devclass, i);
1061 if (sc == NULL || sc->sc_type == SIEMPTY)
1063 regp = (struct si_reg *)sc->sc_maddr;
1066 * See if there has been a pending interrupt for 2 seconds
1067 * or so. The test (int_scounter >= 200) won't correspond
1068 * to 2 seconds if int_count gets changed.
1070 if (regp->int_pending != 0) {
1071 if (regp->int_scounter >= 200 &&
1072 regp->initstat == 1) {
1073 printf("si%d: lost intr\n", i);
1077 regp->int_scounter = 0;
1081 * gripe about no input flow control..
1084 for (port = 0; port < sc->sc_nport; pp++, port++) {
1085 if (pp->sp_delta_overflows > 0) {
1086 printf("si%d: %d tty level buffer overflows\n",
1087 i, pp->sp_delta_overflows);
1088 pp->sp_delta_overflows = 0;
1092 if (lost || si_realpoll)
1093 si_intr(NULL); /* call intr with fake vector */
1096 timeout(si_poll, (caddr_t)0L, si_pollrate);
1098 #endif /* ifdef POLL */
1101 * The interrupt handler polls ALL ports on ALL adapters each time
1105 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1106 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1111 struct si_softc *sc;
1113 volatile struct si_channel *ccbp;
1115 volatile caddr_t maddr;
1117 int x, card, port, n, i, isopen;
1122 mtx_assert(&Giant, MA_OWNED);
1124 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1127 * When we get an int we poll all the channels and do ALL pending
1128 * work, not just the first one we find. This allows all cards to
1129 * share the same vector.
1131 * XXX - But if we're sharing the vector with something that's NOT
1132 * a SI/XIO/SX card, we may be making more work for ourselves.
1134 for (card = 0; card < si_numunits; card++) {
1135 sc = devclass_get_softc(si_devclass, card);
1136 if (sc == NULL || sc->sc_type == SIEMPTY)
1140 * First, clear the interrupt
1142 switch(sc->sc_type) {
1144 maddr = sc->sc_maddr;
1145 ((volatile struct si_reg *)maddr)->int_pending = 0;
1146 /* flag nothing pending */
1147 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1148 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1151 maddr = sc->sc_maddr;
1152 ((volatile struct si_reg *)maddr)->int_pending = 0;
1153 *(maddr+SIPLIRQCLR) = 0x00;
1154 *(maddr+SIPLIRQCLR) = 0x10;
1157 maddr = sc->sc_maddr;
1158 ((volatile struct si_reg *)maddr)->int_pending = 0;
1159 *(maddr+SIPCIINTCL) = 0x0;
1161 case SIJETPCI: /* fall through to JETISA case */
1163 maddr = sc->sc_maddr;
1164 ((volatile struct si_reg *)maddr)->int_pending = 0;
1165 *(maddr+SIJETINTCL) = 0x0;
1169 maddr = sc->sc_maddr;
1170 ((volatile struct si_reg *)maddr)->int_pending = 0;
1171 (void)inb(sc->sc_iobase + 3);
1178 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1183 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1190 * See if a command has completed ?
1192 if (ccbp->hi_stat != pp->sp_pend) {
1193 DPRINT((pp, DBG_INTR,
1194 "si_intr hi_stat = %s, pend = %s\n",
1195 si_cmdname(ccbp->hi_stat),
1196 si_cmdname(pp->sp_pend)));
1197 switch(pp->sp_pend) {
1205 /* sleeping in si_command */
1206 DPRINT((pp, DBG_INTR, "do wakeup\n"));
1207 wakeup(&pp->sp_state);
1210 pp->sp_pend = ccbp->hi_stat;
1214 * Continue on if it's closed
1216 if (ccbp->hi_stat == IDLE_CLOSE) {
1222 * Do modem state change if not a local device
1224 si_modem_state(pp, tp, ccbp->hi_ip);
1227 * Check to see if we should 'receive' characters.
1229 isopen = tty_opened(tp);
1232 * Do input break processing
1234 if (ccbp->hi_state & ST_BREAK) {
1236 ttydisc_rint(tp, 0, TRE_BREAK);
1237 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1238 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1242 * Do RX stuff - if not open then dump any characters.
1243 * XXX: This is VERY messy and needs to be cleaned up.
1245 * XXX: can we leave data in the host adapter buffer
1246 * when the clists are full? That may be dangerous
1247 * if the user cannot get an interrupt signal through.
1253 DPRINT((pp, DBG_INTR, "intr1: not open\n"));
1254 ccbp->hi_rxopos = ccbp->hi_rxipos;
1258 #if 0 /* XXXMPSAFETTY */
1260 * If the tty input buffers are blocked, stop emptying
1261 * the incoming buffers and let the auto flow control
1264 if (tp->t_state & TS_TBLOCK)
1269 * Process read characters if not skipped above
1271 op = ccbp->hi_rxopos;
1272 ip = ccbp->hi_rxipos;
1281 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1285 * Suck characters out of host card buffer into the
1286 * "input staging buffer" - so that we dont leave the
1287 * host card in limbo while we're possibly echoing
1288 * characters and possibly flushing input inside the
1289 * ldisc l_rint() routine.
1291 if (n <= SI_BUFFERSIZE - op) {
1293 z = ccbp->hi_rxbuf + op;
1294 si_vbcopy(z, si_rxbuf, n);
1298 x = SI_BUFFERSIZE - op;
1300 z = ccbp->hi_rxbuf + op;
1301 si_vbcopy(z, si_rxbuf, x);
1304 si_vbcopy(z, si_rxbuf + x, n - x);
1309 /* clear collected characters from buffer */
1310 ccbp->hi_rxopos = op;
1314 * n = number of chars placed in si_rxbuf
1317 if (0 && ttydisc_can_bypass(tp)) {
1319 i = ttydisc_rint_bypass(tp, (char *)si_rxbuf, n);
1321 pp->sp_delta_overflows += (n - i);
1325 * It'd be nice to not have to go through the
1326 * function call overhead for each char here.
1327 * It'd be nice to block input it, saving a
1328 * loop here and the call/return overhead.
1330 for(x = 0; x < n; x++) {
1332 if (ttydisc_rint(tp, i, 0) == -1)
1333 pp->sp_delta_overflows++;
1336 goto more_rx; /* try for more until RXbuf is empty */
1340 ttydisc_rint_done(tp);
1348 } /* end of for (all ports on this controller) */
1349 } /* end of for (all controllers) */
1351 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1355 * Nudge the transmitter...
1357 * XXX: I inherited some funny code here. It implies the host card only
1358 * interrupts when the transmit buffer reaches the low-water-mark, and does
1359 * not interrupt when it's actually hits empty. In some cases, we have
1360 * processes waiting for complete drain, and we need to simulate an interrupt
1361 * about when we think the buffer is going to be empty (and retry if not).
1362 * I really am not certain about this... I *need* the hardware manuals.
1365 si_start(struct tty *tp)
1368 volatile struct si_channel *ccbp;
1373 int oldspl, n, amount;
1376 mtx_assert(&Giant, MA_OWNED);
1380 DPRINT((pp, DBG_ENTRY|DBG_START,
1381 "si_start(%x) sp_state %x\n",
1386 while ((count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos) < 255) {
1387 DPRINT((pp, DBG_START, "txbuf pend count %d\n", (BYTE)count));
1388 ipos = (unsigned int)ccbp->hi_txipos;
1389 if ((int)ccbp->hi_txopos <= ipos)
1390 amount = SI_BUFFERSIZE - ipos;
1392 amount = 255 - count;
1393 DPRINT((pp, DBG_START, "spaceleft amount %d\n", amount));
1396 n = ttydisc_getc(tp, si_txbuf, amount);
1397 DPRINT((pp, DBG_START, "getc n=%d\n", n));
1400 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1401 ccbp->hi_txipos += n;
1406 * See if there are any characters still to come. If so, we can
1407 * depend on si_start being called again.
1409 * XXX the manual is vague on this. It implies we get an interrupt
1410 * when the transmit queue reaches the 25% low water mark, but NOT
1411 * when it hits empty.
1413 nchar = ttyoutq_getsize(&tp->t_outq) - ttyoutq_bytesleft(&tp->t_outq);
1414 DPRINT((pp, DBG_START, "count %d, nchar %d\n",
1415 (BYTE)count, nchar));
1417 if (count != 0 && nchar == 0) {
1420 /* XXX lame. Ticks per character. used to be a table. */
1421 time = (tp->t_termios.c_ospeed + 9) / 10;
1425 time = nchar / time;
1429 DPRINT((pp, DBG_START,
1430 "bad char time value! %d\n", time));
1434 if ((pp->sp_state & SS_LSTART) != 0)
1435 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
1436 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
1437 pp->sp_state |= SS_LSTART;
1438 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time);
1443 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
1448 * This has to deal with two things... cause wakeups while waiting for
1449 * tty drains on last process exit, and call l_start at about the right
1450 * time for protocols like ppp.
1453 si_lstart(void *arg)
1455 struct si_port *pp = arg;
1459 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n",
1463 mtx_assert(&Giant, MA_OWNED);
1464 pp->sp_state &= ~SS_LSTART;
1473 #if 0 /* XXX mpsafetty */
1475 * Stop output on a line. called at spltty();
1478 si_stop(struct tty *tp, int rw)
1480 volatile struct si_channel *ccbp;
1483 mtx_assert(&Giant, MA_OWNED);
1487 DPRINT((pp, DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw));
1489 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
1491 /* what level are we meant to be flushing anyway? */
1492 if (tp->t_state & TS_BUSY) {
1493 si_command(pp, WFLUSH, SI_NOWAIT);
1494 tp->t_state &= ~TS_BUSY;
1495 ttwwakeup(tp); /* Bruce???? */
1498 #if 1 /* XXX: this doesn't work right yet.. */
1499 /* XXX: this may have been failing because we used to call l_rint()
1500 * while we were looping based on these two counters. Now, we collect
1501 * the data and then loop stuffing it into l_rint(), making this
1502 * useless. Should we cause this to blow away the staging buffer?
1505 ccbp->hi_rxopos = ccbp->hi_rxipos;
1512 * Issue a command to the host card CPU.
1514 * XXX This is all just so WRONG!. Ed says we're not supposed to sleep
1515 * here anyway. We sort of get away with it for now by using Giant.
1516 * Something better will have to be done.
1517 * Linux does a busy spin here waiting for the 8-bit cpu to notice the
1518 * posted command and respond to it. I'm not sure I like that either.
1521 si_command(struct si_port *pp, int cmd, int waitflag)
1524 volatile struct si_channel *ccbp = pp->sp_ccb;
1528 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%s,%d): hi_stat %s, sp_pend: %s\n",
1529 pp, si_cmdname(cmd), waitflag, si_cmdname(ccbp->hi_stat),
1530 si_cmdname(pp->sp_pend)));
1532 oldspl = spltty(); /* Keep others out */
1533 mtx_assert(&Giant, MA_OWNED);
1535 /* wait until it's finished what it was doing.. */
1536 /* XXX: sits in IDLE_BREAK until something disturbs it or break
1538 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1542 DPRINT((pp, DBG_PARAM, "sicmd1 old cmd pending (going to tsleep): hi_stat (%s)\n", si_cmdname(ccbp->hi_stat)));
1543 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd1", hz/4);
1545 DPRINT((pp, DBG_PARAM, "sicmd1 timeout: hi_stat (%s)\n",
1546 si_cmdname(ccbp->hi_stat)));
1547 /* This is very very bad. The card has crashed. */
1548 /* XXX the driver breaks at this point */
1549 if (err == ETIMEDOUT)
1550 DPRINT(("%s: tsleep1 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1555 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
1556 DPRINT((pp, DBG_PARAM, "sicmd1 now in: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1558 /* if there was a pending command, cause a state-change wakeup */
1559 switch(pp->sp_pend) {
1567 DPRINT((pp, DBG_PARAM, "si_command: sp_pend %s, doing wakeup\n", si_cmdname(pp->sp_pend)));
1568 wakeup(&pp->sp_state);
1574 pp->sp_pend = cmd; /* New command pending */
1575 ccbp->hi_stat = cmd; /* Post it */
1576 DPRINT((pp, DBG_PARAM, "sicmd now posted: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1579 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1582 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)));
1583 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd2", hz);
1585 DPRINT((pp, DBG_PARAM, "sicmd2 tsleep error: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1586 if (err == ETIMEDOUT) {
1587 DPRINT(("%s: tsleep2 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1593 DPRINT((pp, DBG_PARAM, "sicmd2 finished: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1601 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
1605 if ((pp == NULL && (si_debug&flags)) ||
1606 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
1608 printf("%s: ", pp->sp_name);
1618 si_modulename(int host_type, int uart_type)
1620 switch (host_type) {
1621 /* Z280 based cards */
1628 switch (uart_type) {
1635 /* T225 based hosts */
1638 switch (uart_type) {