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,
609 "WARNING: This driver is deprecated and will be removed.\n");
614 siopen(struct tty *tp)
617 DPRINT((0, DBG_ENTRY|DBG_OPEN, "siopen()\n"));
618 mtx_assert(&Giant, MA_OWNED);
621 * We've now got a device, so start the poller.
623 if (init_finished == 0) {
624 timeout(si_poll, (caddr_t)0L, si_pollrate);
628 DPRINT((0, DBG_EXIT|DBG_OPEN, "siopen() finished\n"));
633 siclose(struct tty *tp)
637 DPRINT((0, DBG_ENTRY|DBG_CLOSE, "siclose()\n"));
638 mtx_assert(&Giant, MA_OWNED);
640 (void) si_command(pp, FCLOSE, SI_WAIT);
641 DPRINT((0, DBG_EXIT|DBG_CLOSE, "siclose() finished\n"));
645 siioctl(struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
649 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "siioctl(0x%lx,0x%x)\n", cmd, data));
650 mtx_assert(&Giant, MA_OWNED);
654 si_command(pp, SBREAK, SI_WAIT);
657 si_command(pp, EBREAK, SI_WAIT);
660 return (ENOIOCTL); /* Let the common tty ioctl handler do it */
664 * Handle the Specialix ioctls on the control dev.
667 si_Sioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td)
669 struct si_softc *xsc;
671 volatile struct si_reg *regp;
673 struct si_pstat *sps;
678 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,0x%lx,0x%x)\n",
679 devtoname(dev), cmd, data));
680 mtx_assert(&Giant, MA_OWNED);
683 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT));
684 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB));
687 oldspl = spltty(); /* better safe than sorry */
691 #define SUCHECK if ((error = priv_check(td, PRIV_DRIVER))) goto out
709 * Check that a controller for this port exists
712 /* may also be a struct si_pstat, a superset of si_tcsi */
714 dp = (struct si_tcsi *)data;
715 sps = (struct si_pstat *)data;
717 xsc = devclass_get_softc(si_devclass, card); /* check.. */
718 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
723 * And check that a port exists
726 if (port < 0 || port >= xsc->sc_nport) {
730 xpp = xsc->sc_ports + port;
731 regp = (struct si_reg *)xsc->sc_maddr;
741 xpp->sp_debug = DBG_ALL;
742 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
743 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
753 if (cmd == TCSIGDBG_LEVEL) {
754 dp->tc_dbglvl = xpp->sp_debug;
757 xpp->sp_debug = dp->tc_dbglvl;
765 dp->tc_int = regp->rx_int_count;
769 regp->rx_int_count = dp->tc_int;
772 dp->tc_int = regp->int_count;
776 regp->int_count = dp->tc_int;
779 dp->tc_int = xpp->sp_ccb->hi_ip;
781 /* these next three use a different structure */
784 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
788 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
796 return(error); /* success */
800 * siparam() : Configure line params
801 * called at spltty();
802 * this may sleep, does not flush, nor wait for drain, nor block writes
803 * caller must arrange this if it's important..
806 siparam(struct tty *tp, struct termios *t)
808 struct si_port *pp = tty_softc(tp);
809 volatile struct si_channel *ccbp;
810 int oldspl, cflag, iflag, oflag, lflag;
811 int error = 0; /* shutup gcc */
812 int ispeed = 0; /* shutup gcc */
813 int ospeed = 0; /* shutup gcc */
816 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t));
817 mtx_assert(&Giant, MA_OWNED);
822 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
823 oflag, cflag, iflag, lflag));
825 /* XXX - if Jet host and SXDC module, use extended baud rates */
827 /* if not hung up.. */
828 if (t->c_ospeed != 0) {
829 /* translate baud rate to firmware values */
830 ospeed = si_speedtab(t->c_ospeed, bdrates);
831 ispeed = t->c_ispeed ?
832 si_speedtab(t->c_ispeed, bdrates) : ospeed;
833 /* enforce legit baud rate */
834 if (ospeed < 0 || ispeed < 0)
842 /* ========== set hi_break ========== */
844 if (iflag & IGNBRK) /* Breaks */
846 if (iflag & BRKINT) /* Interrupt on break? */
848 if (iflag & PARMRK) /* Parity mark? */
850 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
852 ccbp->hi_break = val;
854 /* ========== set hi_csr ========== */
855 /* if not hung up.. */
856 if (t->c_ospeed != 0) {
858 val = (ispeed << 4) | ospeed;
862 /* ========== set hi_mr2 ========== */
864 if (cflag & CSTOPB) /* Stop bits */
870 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
871 * a DCE, hence the reverse sense of RTS and CTS
873 /* Output Flow - RTS must be raised before data can be sent */
874 if (cflag & CCTS_OFLOW)
879 /* ========== set hi_mr1 ========== */
881 if (!(cflag & PARENB)) /* Parity */
888 if ((cflag & CS8) == CS8) /* 8 data bits? */
890 else if ((cflag & CS7) == CS7) /* 7 data bits? */
892 else if ((cflag & CS6) == CS6) /* 6 data bits? */
898 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
899 * a DCE, hence the reverse sense of RTS and CTS
901 /* Input Flow - CTS is raised when port is ready to receive data */
902 if (cflag & CRTS_IFLOW)
907 /* ========== set hi_mask ========== */
909 if ((cflag & CS8) == CS8) { /* 8 data bits? */
911 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
913 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
915 } else { /* Must be 5 */
923 /* ========== set hi_prtcl ========== */
924 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
934 ccbp->hi_prtcl = val;
937 /* ========== set hi_{rx|tx}{on|off} ========== */
938 /* XXX: the card TOTALLY shields us from the flow control... */
939 ccbp->hi_txon = t->c_cc[VSTART];
940 ccbp->hi_txoff = t->c_cc[VSTOP];
942 ccbp->hi_rxon = t->c_cc[VSTART];
943 ccbp->hi_rxoff = t->c_cc[VSTOP];
945 /* ========== send settings to the card ========== */
946 /* potential sleep here */
947 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
948 si_command(pp, LOPEN, SI_WAIT); /* open it */
950 si_command(pp, CONFIG, SI_WAIT); /* change params */
952 /* ========== set DTR etc ========== */
953 /* Hangup if ospeed == 0 */
954 if (t->c_ospeed == 0) {
955 (void) simodem(tp, 0, SER_DTR | SER_RTS);
958 * If the previous speed was 0, may need to re-enable
961 (void) simodem(tp, SER_DTR | SER_RTS, 0);
964 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x HI_CSR %x\n",
965 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break, ccbp->hi_csr));
972 * Set/Get state of modem control lines.
973 * Due to DCE-like behaviour of the adapter, some signals need translation:
978 simodem(struct tty *tp, int sigon, int sigoff)
981 volatile struct si_channel *ccbp;
985 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "simodem(%x,%x)\n", sigon, sigoff));
986 mtx_assert(&Giant, MA_OWNED);
987 ccbp = pp->sp_ccb; /* Find channel address */
988 if (sigon == 0 && sigoff == 0) {
991 * XXX: not sure this is correct, should it be CTS&DSR ?
992 * XXX: or do we (just) miss CTS & DSR ?
994 if (x & IP_DCD) sigon |= SER_DCD;
995 if (x & IP_DTR) sigon |= SER_DTR;
996 if (x & IP_RTS) sigon |= SER_RTS;
997 if (x & IP_RI) sigon |= SER_RI;
1002 if (sigon & SER_DTR)
1004 if (sigoff & SER_DTR)
1006 if (sigon & SER_RTS)
1008 if (sigoff & SER_RTS)
1015 * Handle change of modem state
1018 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
1020 /* if a modem dev */
1021 mtx_assert(&Giant, MA_OWNED);
1022 if (hi_ip & IP_DCD) {
1023 if (!(pp->sp_last_hi_ip & IP_DCD)) {
1024 DPRINT((pp, DBG_INTR, "modem carr on%d\n"));
1025 (void)ttydisc_modem(tp, 1);
1028 if (pp->sp_last_hi_ip & IP_DCD) {
1029 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1030 #if 0 /* XXX mpsafetty ttyld_modem used to tell us to shutdown the port or not */
1031 if (ttydisc_modem(tp, 0))
1032 (void) simodem(tp, 0, SER_DTR | SER_RTS);
1034 ttydisc_modem(tp, 0);
1038 pp->sp_last_hi_ip = hi_ip;
1043 * Poller to catch missed interrupts.
1045 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1046 * better response. We could really use a "periodic" version timeout(). :-)
1050 si_poll(void *nothing)
1052 struct si_softc *sc;
1054 volatile struct si_reg *regp;
1056 int lost, oldspl, port;
1058 DPRINT((0, DBG_POLL, "si_poll()\n"));
1060 mtx_assert(&Giant, MA_OWNED);
1062 for (i = 0; i < si_numunits; i++) {
1063 sc = devclass_get_softc(si_devclass, i);
1064 if (sc == NULL || sc->sc_type == SIEMPTY)
1066 regp = (struct si_reg *)sc->sc_maddr;
1069 * See if there has been a pending interrupt for 2 seconds
1070 * or so. The test (int_scounter >= 200) won't correspond
1071 * to 2 seconds if int_count gets changed.
1073 if (regp->int_pending != 0) {
1074 if (regp->int_scounter >= 200 &&
1075 regp->initstat == 1) {
1076 printf("si%d: lost intr\n", i);
1080 regp->int_scounter = 0;
1084 * gripe about no input flow control..
1087 for (port = 0; port < sc->sc_nport; pp++, port++) {
1088 if (pp->sp_delta_overflows > 0) {
1089 printf("si%d: %d tty level buffer overflows\n",
1090 i, pp->sp_delta_overflows);
1091 pp->sp_delta_overflows = 0;
1095 if (lost || si_realpoll)
1096 si_intr(NULL); /* call intr with fake vector */
1099 timeout(si_poll, (caddr_t)0L, si_pollrate);
1101 #endif /* ifdef POLL */
1104 * The interrupt handler polls ALL ports on ALL adapters each time
1108 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1109 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1114 struct si_softc *sc;
1116 volatile struct si_channel *ccbp;
1118 volatile caddr_t maddr;
1120 int x, card, port, n, i, isopen;
1125 mtx_assert(&Giant, MA_OWNED);
1127 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1130 * When we get an int we poll all the channels and do ALL pending
1131 * work, not just the first one we find. This allows all cards to
1132 * share the same vector.
1134 * XXX - But if we're sharing the vector with something that's NOT
1135 * a SI/XIO/SX card, we may be making more work for ourselves.
1137 for (card = 0; card < si_numunits; card++) {
1138 sc = devclass_get_softc(si_devclass, card);
1139 if (sc == NULL || sc->sc_type == SIEMPTY)
1143 * First, clear the interrupt
1145 switch(sc->sc_type) {
1147 maddr = sc->sc_maddr;
1148 ((volatile struct si_reg *)maddr)->int_pending = 0;
1149 /* flag nothing pending */
1150 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1151 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1154 maddr = sc->sc_maddr;
1155 ((volatile struct si_reg *)maddr)->int_pending = 0;
1156 *(maddr+SIPLIRQCLR) = 0x00;
1157 *(maddr+SIPLIRQCLR) = 0x10;
1160 maddr = sc->sc_maddr;
1161 ((volatile struct si_reg *)maddr)->int_pending = 0;
1162 *(maddr+SIPCIINTCL) = 0x0;
1164 case SIJETPCI: /* fall through to JETISA case */
1166 maddr = sc->sc_maddr;
1167 ((volatile struct si_reg *)maddr)->int_pending = 0;
1168 *(maddr+SIJETINTCL) = 0x0;
1172 maddr = sc->sc_maddr;
1173 ((volatile struct si_reg *)maddr)->int_pending = 0;
1174 (void)inb(sc->sc_iobase + 3);
1181 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1186 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1193 * See if a command has completed ?
1195 if (ccbp->hi_stat != pp->sp_pend) {
1196 DPRINT((pp, DBG_INTR,
1197 "si_intr hi_stat = %s, pend = %s\n",
1198 si_cmdname(ccbp->hi_stat),
1199 si_cmdname(pp->sp_pend)));
1200 switch(pp->sp_pend) {
1208 /* sleeping in si_command */
1209 DPRINT((pp, DBG_INTR, "do wakeup\n"));
1210 wakeup(&pp->sp_state);
1213 pp->sp_pend = ccbp->hi_stat;
1217 * Continue on if it's closed
1219 if (ccbp->hi_stat == IDLE_CLOSE) {
1225 * Do modem state change if not a local device
1227 si_modem_state(pp, tp, ccbp->hi_ip);
1230 * Check to see if we should 'receive' characters.
1232 isopen = tty_opened(tp);
1235 * Do input break processing
1237 if (ccbp->hi_state & ST_BREAK) {
1239 ttydisc_rint(tp, 0, TRE_BREAK);
1240 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1241 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1245 * Do RX stuff - if not open then dump any characters.
1246 * XXX: This is VERY messy and needs to be cleaned up.
1248 * XXX: can we leave data in the host adapter buffer
1249 * when the clists are full? That may be dangerous
1250 * if the user cannot get an interrupt signal through.
1256 DPRINT((pp, DBG_INTR, "intr1: not open\n"));
1257 ccbp->hi_rxopos = ccbp->hi_rxipos;
1261 #if 0 /* XXXMPSAFETTY */
1263 * If the tty input buffers are blocked, stop emptying
1264 * the incoming buffers and let the auto flow control
1267 if (tp->t_state & TS_TBLOCK)
1272 * Process read characters if not skipped above
1274 op = ccbp->hi_rxopos;
1275 ip = ccbp->hi_rxipos;
1284 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1288 * Suck characters out of host card buffer into the
1289 * "input staging buffer" - so that we dont leave the
1290 * host card in limbo while we're possibly echoing
1291 * characters and possibly flushing input inside the
1292 * ldisc l_rint() routine.
1294 if (n <= SI_BUFFERSIZE - op) {
1296 z = ccbp->hi_rxbuf + op;
1297 si_vbcopy(z, si_rxbuf, n);
1301 x = SI_BUFFERSIZE - op;
1303 z = ccbp->hi_rxbuf + op;
1304 si_vbcopy(z, si_rxbuf, x);
1307 si_vbcopy(z, si_rxbuf + x, n - x);
1312 /* clear collected characters from buffer */
1313 ccbp->hi_rxopos = op;
1317 * n = number of chars placed in si_rxbuf
1320 if (0 && ttydisc_can_bypass(tp)) {
1322 i = ttydisc_rint_bypass(tp, (char *)si_rxbuf, n);
1324 pp->sp_delta_overflows += (n - i);
1328 * It'd be nice to not have to go through the
1329 * function call overhead for each char here.
1330 * It'd be nice to block input it, saving a
1331 * loop here and the call/return overhead.
1333 for(x = 0; x < n; x++) {
1335 if (ttydisc_rint(tp, i, 0) == -1)
1336 pp->sp_delta_overflows++;
1339 goto more_rx; /* try for more until RXbuf is empty */
1343 ttydisc_rint_done(tp);
1351 } /* end of for (all ports on this controller) */
1352 } /* end of for (all controllers) */
1354 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1358 * Nudge the transmitter...
1360 * XXX: I inherited some funny code here. It implies the host card only
1361 * interrupts when the transmit buffer reaches the low-water-mark, and does
1362 * not interrupt when it's actually hits empty. In some cases, we have
1363 * processes waiting for complete drain, and we need to simulate an interrupt
1364 * about when we think the buffer is going to be empty (and retry if not).
1365 * I really am not certain about this... I *need* the hardware manuals.
1368 si_start(struct tty *tp)
1371 volatile struct si_channel *ccbp;
1376 int oldspl, n, amount;
1379 mtx_assert(&Giant, MA_OWNED);
1383 DPRINT((pp, DBG_ENTRY|DBG_START,
1384 "si_start(%x) sp_state %x\n",
1389 while ((count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos) < 255) {
1390 DPRINT((pp, DBG_START, "txbuf pend count %d\n", (BYTE)count));
1391 ipos = (unsigned int)ccbp->hi_txipos;
1392 if ((int)ccbp->hi_txopos <= ipos)
1393 amount = SI_BUFFERSIZE - ipos;
1395 amount = 255 - count;
1396 DPRINT((pp, DBG_START, "spaceleft amount %d\n", amount));
1399 n = ttydisc_getc(tp, si_txbuf, amount);
1400 DPRINT((pp, DBG_START, "getc n=%d\n", n));
1403 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1404 ccbp->hi_txipos += n;
1409 * See if there are any characters still to come. If so, we can
1410 * depend on si_start being called again.
1412 * XXX the manual is vague on this. It implies we get an interrupt
1413 * when the transmit queue reaches the 25% low water mark, but NOT
1414 * when it hits empty.
1416 nchar = ttyoutq_getsize(&tp->t_outq) - ttyoutq_bytesleft(&tp->t_outq);
1417 DPRINT((pp, DBG_START, "count %d, nchar %d\n",
1418 (BYTE)count, nchar));
1420 if (count != 0 && nchar == 0) {
1423 /* XXX lame. Ticks per character. used to be a table. */
1424 time = (tp->t_termios.c_ospeed + 9) / 10;
1428 time = nchar / time;
1432 DPRINT((pp, DBG_START,
1433 "bad char time value! %d\n", time));
1437 if ((pp->sp_state & SS_LSTART) != 0)
1438 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
1439 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
1440 pp->sp_state |= SS_LSTART;
1441 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time);
1446 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
1451 * This has to deal with two things... cause wakeups while waiting for
1452 * tty drains on last process exit, and call l_start at about the right
1453 * time for protocols like ppp.
1456 si_lstart(void *arg)
1458 struct si_port *pp = arg;
1462 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n",
1466 mtx_assert(&Giant, MA_OWNED);
1467 pp->sp_state &= ~SS_LSTART;
1476 #if 0 /* XXX mpsafetty */
1478 * Stop output on a line. called at spltty();
1481 si_stop(struct tty *tp, int rw)
1483 volatile struct si_channel *ccbp;
1486 mtx_assert(&Giant, MA_OWNED);
1490 DPRINT((pp, DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw));
1492 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
1494 /* what level are we meant to be flushing anyway? */
1495 if (tp->t_state & TS_BUSY) {
1496 si_command(pp, WFLUSH, SI_NOWAIT);
1497 tp->t_state &= ~TS_BUSY;
1498 ttwwakeup(tp); /* Bruce???? */
1501 #if 1 /* XXX: this doesn't work right yet.. */
1502 /* XXX: this may have been failing because we used to call l_rint()
1503 * while we were looping based on these two counters. Now, we collect
1504 * the data and then loop stuffing it into l_rint(), making this
1505 * useless. Should we cause this to blow away the staging buffer?
1508 ccbp->hi_rxopos = ccbp->hi_rxipos;
1515 * Issue a command to the host card CPU.
1517 * XXX This is all just so WRONG!. Ed says we're not supposed to sleep
1518 * here anyway. We sort of get away with it for now by using Giant.
1519 * Something better will have to be done.
1520 * Linux does a busy spin here waiting for the 8-bit cpu to notice the
1521 * posted command and respond to it. I'm not sure I like that either.
1524 si_command(struct si_port *pp, int cmd, int waitflag)
1527 volatile struct si_channel *ccbp = pp->sp_ccb;
1531 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%s,%d): hi_stat %s, sp_pend: %s\n",
1532 pp, si_cmdname(cmd), waitflag, si_cmdname(ccbp->hi_stat),
1533 si_cmdname(pp->sp_pend)));
1535 oldspl = spltty(); /* Keep others out */
1536 mtx_assert(&Giant, MA_OWNED);
1538 /* wait until it's finished what it was doing.. */
1539 /* XXX: sits in IDLE_BREAK until something disturbs it or break
1541 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1545 DPRINT((pp, DBG_PARAM, "sicmd1 old cmd pending (going to tsleep): hi_stat (%s)\n", si_cmdname(ccbp->hi_stat)));
1546 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd1", hz/4);
1548 DPRINT((pp, DBG_PARAM, "sicmd1 timeout: hi_stat (%s)\n",
1549 si_cmdname(ccbp->hi_stat)));
1550 /* This is very very bad. The card has crashed. */
1551 /* XXX the driver breaks at this point */
1552 if (err == ETIMEDOUT)
1553 DPRINT(("%s: tsleep1 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1558 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
1559 DPRINT((pp, DBG_PARAM, "sicmd1 now in: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1561 /* if there was a pending command, cause a state-change wakeup */
1562 switch(pp->sp_pend) {
1570 DPRINT((pp, DBG_PARAM, "si_command: sp_pend %s, doing wakeup\n", si_cmdname(pp->sp_pend)));
1571 wakeup(&pp->sp_state);
1577 pp->sp_pend = cmd; /* New command pending */
1578 ccbp->hi_stat = cmd; /* Post it */
1579 DPRINT((pp, DBG_PARAM, "sicmd now posted: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1582 while((x = ccbp->hi_stat) != IDLE_OPEN &&
1585 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)));
1586 err = tsleep(&pp->sp_state, (PSOCK+1)|PCATCH, "sicmd2", hz);
1588 DPRINT((pp, DBG_PARAM, "sicmd2 tsleep error: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1589 if (err == ETIMEDOUT) {
1590 DPRINT(("%s: tsleep2 timeout. hi_stat %s, sp_pend %s\n", pp->sp_name, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1596 DPRINT((pp, DBG_PARAM, "sicmd2 finished: hi_stat (%s) sp_pend (%s)\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend)));
1604 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
1608 if ((pp == NULL && (si_debug&flags)) ||
1609 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
1611 printf("%s: ", pp->sp_name);
1621 si_modulename(int host_type, int uart_type)
1623 switch (host_type) {
1624 /* Z280 based cards */
1631 switch (uart_type) {
1638 /* T225 based hosts */
1641 switch (uart_type) {