Index: head/sys/dev/si/si.c =================================================================== --- head/sys/dev/si/si.c (revision 179667) +++ head/sys/dev/si/si.c (revision 179668) @@ -1,1670 +1,1665 @@ /*- * Device driver for Specialix range (SI/XIO) of serial line multiplexors. * * Copyright (C) 1990, 1992, 1998 Specialix International, * Copyright (C) 1993, Andy Rutter * Copyright (C) 2000, Peter Wemm * * Originally derived from: SunOS 4.x version * Ported from BSDI version to FreeBSD by Peter Wemm. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notices, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notices, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Andy Rutter of * Advanced Methods and Tools Ltd. based on original information * from Specialix International. * 4. Neither the name of Advanced Methods and Tools, nor Specialix * International may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHORS BE LIABLE. * */ #include __FBSDID("$FreeBSD$"); #ifndef lint static const char si_copyright1[] = "@(#) Copyright (C) Specialix International, 1990,1992,1998", si_copyright2[] = "@(#) Copyright (C) Andy Rutter 1993", si_copyright3[] = "@(#) Copyright (C) Peter Wemm 2000"; #endif /* not lint */ #include "opt_compat.h" #include "opt_debug_si.h" #include "opt_eisa.h" #include "opt_tty.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * This device driver is designed to interface the Specialix International * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA, * EISA or PCI bus machine. * * The controller is interfaced to the host via dual port RAM * and an interrupt. * * The code for the Host 1 (very old ISA cards) has not been tested. */ #define POLL /* turn on poller to scan for lost interrupts */ #if 0 #define REALPOLL /* on each poll, scan for work regardless */ #endif #define POLLHZ (hz/10) /* 10 times per second */ #define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE) #define INT_COUNT 25000 /* max of 125 ints per second */ #define JET_INT_COUNT 100 /* max of 100 ints per second */ #define RXINT_COUNT 1 /* one rxint per 10 milliseconds */ static void si_command(struct si_port *, int, int); static int si_Sioctl(struct cdev *, u_long, caddr_t, int, struct thread *); static void si_start(struct tty *); static void si_stop(struct tty *, int); static timeout_t si_lstart; static t_break_t sibreak; static t_close_t siclose; static t_modem_t simodem; static t_open_t siopen; static int siparam(struct tty *, struct termios *); static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip); static char * si_modulename(int host_type, int uart_type); static struct cdevsw si_Scdevsw = { .d_version = D_VERSION, .d_ioctl = si_Sioctl, .d_name = "si", .d_flags = D_TTY | D_NEEDGIANT, }; static int si_Nports; static int si_Nmodules; static int si_debug = 0; /* data, not bss, so it's patchable */ SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, ""); TUNABLE_INT("machdep.si_debug", &si_debug); static int si_numunits; devclass_t si_devclass; #ifndef B2000 /* not standard, but the hardware knows it. */ # define B2000 2000 #endif static struct speedtab bdrates[] = { { B75, CLK75, }, /* 0x0 */ { B110, CLK110, }, /* 0x1 */ { B150, CLK150, }, /* 0x3 */ { B300, CLK300, }, /* 0x4 */ { B600, CLK600, }, /* 0x5 */ { B1200, CLK1200, }, /* 0x6 */ { B2000, CLK2000, }, /* 0x7 */ { B2400, CLK2400, }, /* 0x8 */ { B4800, CLK4800, }, /* 0x9 */ { B9600, CLK9600, }, /* 0xb */ { B19200, CLK19200, }, /* 0xc */ { B38400, CLK38400, }, /* 0x2 (out of order!) */ { B57600, CLK57600, }, /* 0xd */ { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */ { -1, -1 }, }; /* populated with approx character/sec rates - translated at card * initialisation time to chars per tick of the clock */ static int done_chartimes = 0; static struct speedtab chartimes[] = { { B75, 8, }, { B110, 11, }, { B150, 15, }, { B300, 30, }, { B600, 60, }, { B1200, 120, }, { B2000, 200, }, { B2400, 240, }, { B4800, 480, }, { B9600, 960, }, { B19200, 1920, }, { B38400, 3840, }, { B57600, 5760, }, { B115200, 11520, }, { -1, -1 }, }; #ifdef POLL static int si_pollrate; /* in addition to irq */ static int si_realpoll = 0; /* poll HW on timer */ SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, ""); SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, ""); static int init_finished = 0; static void si_poll(void *); #endif /* * Array of adapter types and the corresponding RAM size. The order of * entries here MUST match the ordinal of the adapter type. */ static const char *si_type[] = { "EMPTY", "SIHOST", "SIMCA", /* FreeBSD does not support Microchannel */ "SIHOST2", "SIEISA", "SIPCI", "SXPCI", "SXISA", }; #ifdef SI_DEBUG static char * si_cmdname(int cmd) { static char buf[32]; switch (cmd) { case IDLE_OPEN: return("IDLE_OPEN"); case LOPEN: return("LOPEN"); case MOPEN: return("MOPEN"); case MPEND: return("MPEND"); case CONFIG: return("CONFIG"); case CLOSE: return("CLOSE"); case SBREAK: return("SBREAK"); case EBREAK: return("EBREAK"); case IDLE_CLOSE: return("IDLE_CLOSE"); case IDLE_BREAK: return("IDLE_BREAK"); case FCLOSE: return("FCLOSE"); case RESUME: return("RESUME"); case WFLUSH: return("WFLUSH"); case RFLUSH: return("RFLUSH"); default: sprintf(buf, "?cmd:0x%x?", cmd); return (buf); } } #endif /* * We have to make an 8 bit version of bcopy, since some cards can't * deal with 32 bit I/O */ static void __inline si_bcopy(const void *src, void *dst, size_t len) { u_char *d; const u_char *s; d = dst; s = src; while (len--) *d++ = *s++; } static void __inline si_vbcopy(const volatile void *src, void *dst, size_t len) { u_char *d; const volatile u_char *s; d = dst; s = src; while (len--) *d++ = *s++; } static void __inline si_bcopyv(const void *src, volatile void *dst, size_t len) { volatile u_char *d; const u_char *s; d = dst; s = src; while (len--) *d++ = *s++; } /* * Attach the device. Initialize the card. */ int siattach(device_t dev) { int unit; struct si_softc *sc; struct si_port *pp; struct tty *tp; volatile struct si_channel *ccbp; volatile struct si_reg *regp; volatile caddr_t maddr; struct si_module *modp; struct speedtab *spt; int nmodule, nport, x, y; int uart_type; sc = device_get_softc(dev); unit = device_get_unit(dev); sc->sc_typename = si_type[sc->sc_type]; if (si_numunits < unit + 1) si_numunits = unit + 1; DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit)); #ifdef POLL if (si_pollrate == 0) { si_pollrate = POLLHZ; /* in addition to irq */ #ifdef REALPOLL si_realpoll = 1; /* scan always */ #endif } #endif DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit, sc->sc_typename, sc->sc_paddr, sc->sc_maddr)); sc->sc_ports = NULL; /* mark as uninitialised */ maddr = sc->sc_maddr; /* Stop the CPU first so it won't stomp around while we load */ switch (sc->sc_type) { #ifdef DEV_EISA case SIEISA: outb(sc->sc_iobase + 2, sc->sc_irq << 4); #endif break; case SIPCI: *(maddr+SIPCIRESET) = 0; break; case SIJETPCI: /* fall through to JET ISA */ case SIJETISA: *(maddr+SIJETCONFIG) = 0; break; case SIHOST2: *(maddr+SIPLRESET) = 0; break; case SIHOST: *(maddr+SIRESET) = 0; break; default: /* this should never happen */ printf("si%d: unsupported configuration\n", unit); return EINVAL; break; } /* OK, now lets download the download code */ if (SI_ISJET(sc->sc_type)) { DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n", unit, si3_t225_dsize)); si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr, si3_t225_dsize); DPRINT((0, DBG_DOWNLOAD, "si%d: jet_bootstrap: nbytes %d -> %x\n", unit, si3_t225_bsize, si3_t225_bootloadaddr)); si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr, si3_t225_bsize); } else { DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n", unit, si2_z280_dsize)); si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr, si2_z280_dsize); } /* Now start the CPU */ switch (sc->sc_type) { #ifdef DEV_EISA case SIEISA: /* modify the download code to tell it that it's on an EISA */ *(maddr + 0x42) = 1; outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4); (void)inb(sc->sc_iobase + 3); /* reset interrupt */ break; #endif case SIPCI: /* modify the download code to tell it that it's on a PCI */ *(maddr+0x42) = 1; *(maddr+SIPCIRESET) = 1; *(maddr+SIPCIINTCL) = 0; break; case SIJETPCI: *(maddr+SIJETRESET) = 0; *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN; break; case SIJETISA: *(maddr+SIJETRESET) = 0; switch (sc->sc_irq) { case 9: *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90; break; case 10: *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0; break; case 11: *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0; break; case 12: *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0; break; case 15: *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0; break; } break; case SIHOST: *(maddr+SIRESET_CL) = 0; *(maddr+SIINTCL_CL) = 0; break; case SIHOST2: *(maddr+SIPLRESET) = 0x10; switch (sc->sc_irq) { case 11: *(maddr+SIPLIRQ11) = 0x10; break; case 12: *(maddr+SIPLIRQ12) = 0x10; break; case 15: *(maddr+SIPLIRQ15) = 0x10; break; } *(maddr+SIPLIRQCLR) = 0x10; break; default: /* this should _REALLY_ never happen */ printf("si%d: Uh, it was supported a second ago...\n", unit); return EINVAL; } DELAY(1000000); /* wait around for a second */ regp = (struct si_reg *)maddr; y = 0; /* wait max of 5 sec for init OK */ while (regp->initstat == 0 && y++ < 10) { DELAY(500000); } switch (regp->initstat) { case 0: printf("si%d: startup timeout - aborting\n", unit); sc->sc_type = SIEMPTY; return EINVAL; case 1: if (SI_ISJET(sc->sc_type)) { /* set throttle to 100 times per second */ regp->int_count = JET_INT_COUNT; /* rx_intr_count is a NOP in Jet */ } else { /* set throttle to 125 times per second */ regp->int_count = INT_COUNT; /* rx intr max of 25 times per second */ regp->rx_int_count = RXINT_COUNT; } regp->int_pending = 0; /* no intr pending */ regp->int_scounter = 0; /* reset counter */ break; case 0xff: /* * No modules found, so give up on this one. */ printf("si%d: %s - no ports found\n", unit, si_type[sc->sc_type]); return 0; default: printf("si%d: download code version error - initstat %x\n", unit, regp->initstat); return EINVAL; } /* * First time around the ports just count them in order * to allocate some memory. */ nport = 0; modp = (struct si_module *)(maddr + 0x80); for (;;) { DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp)); switch (modp->sm_type) { case TA4: DPRINT((0, DBG_DOWNLOAD, "si%d: Found old TA4 module, 4 ports\n", unit)); x = 4; break; case TA8: DPRINT((0, DBG_DOWNLOAD, "si%d: Found old TA8 module, 8 ports\n", unit)); x = 8; break; case TA4_ASIC: DPRINT((0, DBG_DOWNLOAD, "si%d: Found ASIC TA4 module, 4 ports\n", unit)); x = 4; break; case TA8_ASIC: DPRINT((0, DBG_DOWNLOAD, "si%d: Found ASIC TA8 module, 8 ports\n", unit)); x = 8; break; case MTA: DPRINT((0, DBG_DOWNLOAD, "si%d: Found CD1400 module, 8 ports\n", unit)); x = 8; break; case SXDC: DPRINT((0, DBG_DOWNLOAD, "si%d: Found SXDC module, 8 ports\n", unit)); x = 8; break; default: printf("si%d: unknown module type %d\n", unit, modp->sm_type); goto try_next; } /* this was limited in firmware and is also a driver issue */ if ((nport + x) > SI_MAXPORTPERCARD) { printf("si%d: extra ports ignored\n", unit); goto try_next; } nport += x; si_Nports += x; si_Nmodules++; try_next: if (modp->sm_next == 0) break; modp = (struct si_module *) (maddr + (unsigned)(modp->sm_next & 0x7fff)); } sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport, M_DEVBUF, M_NOWAIT | M_ZERO); if (sc->sc_ports == 0) { printf("si%d: fail to malloc memory for port structs\n", unit); return EINVAL; } sc->sc_nport = nport; /* * Scan round the ports again, this time initialising. */ pp = sc->sc_ports; nmodule = 0; modp = (struct si_module *)(maddr + 0x80); uart_type = 1000; /* arbitary, > uchar_max */ for (;;) { switch (modp->sm_type) { case TA4: nport = 4; break; case TA8: nport = 8; break; case TA4_ASIC: nport = 4; break; case TA8_ASIC: nport = 8; break; case MTA: nport = 8; break; case SXDC: nport = 8; break; default: goto try_next2; } nmodule++; ccbp = (struct si_channel *)((char *)modp + 0x100); if (uart_type == 1000) uart_type = ccbp->type; else if (uart_type != ccbp->type) printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n", unit, nmodule, ccbp->type, si_modulename(sc->sc_type, ccbp->type), uart_type, si_modulename(sc->sc_type, uart_type)); for (x = 0; x < nport; x++, pp++, ccbp++) { pp->sp_ccb = ccbp; /* save the address */ pp->sp_pend = IDLE_CLOSE; pp->sp_state = 0; /* internal flag */ #ifdef SI_DEBUG sprintf(pp->sp_name, "si%r%r", unit, (int)(pp - sc->sc_ports)); #endif tp = pp->sp_tty = ttyalloc(); tp->t_sc = pp; tp->t_break = sibreak; tp->t_close = siclose; tp->t_modem = simodem; tp->t_open = siopen; tp->t_oproc = si_start; tp->t_param = siparam; tp->t_stop = si_stop; ttycreate(tp, TS_CALLOUT, "A%r%r", unit, (int)(pp - sc->sc_ports)); } try_next2: if (modp->sm_next == 0) { printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n", unit, sc->sc_typename, sc->sc_nport, nmodule, uart_type, si_modulename(sc->sc_type, uart_type)); break; } modp = (struct si_module *) (maddr + (unsigned)(modp->sm_next & 0x7fff)); } if (done_chartimes == 0) { for (spt = chartimes ; spt->sp_speed != -1; spt++) { if ((spt->sp_code /= hz) == 0) spt->sp_code = 1; } done_chartimes = 1; } if (unit == 0) make_dev(&si_Scdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "si_control"); return (0); } static int siopen(struct tty *tp, struct cdev *dev) { mtx_assert(&Giant, MA_OWNED); #ifdef POLL /* * We've now got a device, so start the poller. */ if (init_finished == 0) { timeout(si_poll, (caddr_t)0L, si_pollrate); init_finished = 1; } #endif return(0); } static void siclose(struct tty *tp) { struct si_port *pp; mtx_assert(&Giant, MA_OWNED); pp = tp->t_sc; (void) si_command(pp, FCLOSE, SI_WAIT); } static void sibreak(struct tty *tp, int sig) { struct si_port *pp; mtx_assert(&Giant, MA_OWNED); pp = tp->t_sc; if (sig) si_command(pp, SBREAK, SI_WAIT); else si_command(pp, EBREAK, SI_WAIT); } /* * Handle the Specialix ioctls on the control dev. */ static int si_Sioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag, struct thread *td) { struct si_softc *xsc; struct si_port *xpp; volatile struct si_reg *regp; struct si_tcsi *dp; struct si_pstat *sps; int *ip, error = 0; int oldspl; int card, port; DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%x,%x)\n", devtoname(dev), cmd, data, flag)); mtx_assert(&Giant, MA_OWNED); #if 1 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT)); DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB)); - DPRINT((0, DBG_IOCTL, "TCSI_TTY=%x\n", TCSI_TTY)); #endif oldspl = spltty(); /* better safe than sorry */ ip = (int *)data; #define SUCHECK if ((error = priv_check(td, PRIV_DRIVER))) goto out switch (cmd) { case TCSIPORTS: *ip = si_Nports; goto out; case TCSIMODULES: *ip = si_Nmodules; goto out; case TCSISDBG_ALL: SUCHECK; si_debug = *ip; goto out; case TCSIGDBG_ALL: *ip = si_debug; goto out; default: /* * Check that a controller for this port exists */ /* may also be a struct si_pstat, a superset of si_tcsi */ dp = (struct si_tcsi *)data; sps = (struct si_pstat *)data; card = dp->tc_card; xsc = devclass_get_softc(si_devclass, card); /* check.. */ if (xsc == NULL || xsc->sc_type == SIEMPTY) { error = ENOENT; goto out; } /* * And check that a port exists */ port = dp->tc_port; if (port < 0 || port >= xsc->sc_nport) { error = ENOENT; goto out; } xpp = xsc->sc_ports + port; regp = (struct si_reg *)xsc->sc_maddr; } switch (cmd) { case TCSIDEBUG: #ifdef SI_DEBUG SUCHECK; if (xpp->sp_debug) xpp->sp_debug = 0; else { xpp->sp_debug = DBG_ALL; DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n", (xpp->sp_debug&DBG_ALL)?"ON":"OFF")); } break; #else error = ENODEV; goto out; #endif case TCSISDBG_LEVEL: case TCSIGDBG_LEVEL: #ifdef SI_DEBUG if (cmd == TCSIGDBG_LEVEL) { dp->tc_dbglvl = xpp->sp_debug; } else { SUCHECK; xpp->sp_debug = dp->tc_dbglvl; } break; #else error = ENODEV; goto out; #endif case TCSIGRXIT: dp->tc_int = regp->rx_int_count; break; case TCSIRXIT: SUCHECK; regp->rx_int_count = dp->tc_int; break; case TCSIGIT: dp->tc_int = regp->int_count; break; case TCSIIT: SUCHECK; regp->int_count = dp->tc_int; break; case TCSISTATE: dp->tc_int = xpp->sp_ccb->hi_ip; break; /* these next three use a different structure */ case TCSI_PORT: SUCHECK; si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport)); break; case TCSI_CCB: SUCHECK; si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb)); - break; - case TCSI_TTY: - SUCHECK; - si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty)); break; default: error = EINVAL; goto out; } out: splx(oldspl); return(error); /* success */ } /* * siparam() : Configure line params * called at spltty(); * this may sleep, does not flush, nor wait for drain, nor block writes * caller must arrange this if it's important.. */ static int siparam(struct tty *tp, struct termios *t) { struct si_port *pp = tp->t_sc; volatile struct si_channel *ccbp; int oldspl, cflag, iflag, oflag, lflag; int error = 0; /* shutup gcc */ int ispeed = 0; /* shutup gcc */ int ospeed = 0; /* shutup gcc */ BYTE val; DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t)); mtx_assert(&Giant, MA_OWNED); cflag = t->c_cflag; iflag = t->c_iflag; oflag = t->c_oflag; lflag = t->c_lflag; DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n", oflag, cflag, iflag, lflag)); /* XXX - if Jet host and SXDC module, use extended baud rates */ /* if not hung up.. */ if (t->c_ospeed != 0) { /* translate baud rate to firmware values */ ospeed = ttspeedtab(t->c_ospeed, bdrates); ispeed = t->c_ispeed ? ttspeedtab(t->c_ispeed, bdrates) : ospeed; /* enforce legit baud rate */ if (ospeed < 0 || ispeed < 0) return (EINVAL); } oldspl = spltty(); ccbp = pp->sp_ccb; /* ========== set hi_break ========== */ val = 0; if (iflag & IGNBRK) /* Breaks */ val |= BR_IGN; if (iflag & BRKINT) /* Interrupt on break? */ val |= BR_INT; if (iflag & PARMRK) /* Parity mark? */ val |= BR_PARMRK; if (iflag & IGNPAR) /* Ignore chars with parity errors? */ val |= BR_PARIGN; ccbp->hi_break = val; /* ========== set hi_csr ========== */ /* if not hung up.. */ if (t->c_ospeed != 0) { /* Set I/O speeds */ val = (ispeed << 4) | ospeed; } ccbp->hi_csr = val; /* ========== set hi_mr2 ========== */ val = 0; if (cflag & CSTOPB) /* Stop bits */ val |= MR2_2_STOP; else val |= MR2_1_STOP; /* * Enable H/W RTS/CTS handshaking. The default TA/MTA is * a DCE, hence the reverse sense of RTS and CTS */ /* Output Flow - RTS must be raised before data can be sent */ if (cflag & CCTS_OFLOW) val |= MR2_RTSCONT; ccbp->hi_mr2 = val; /* ========== set hi_mr1 ========== */ val = 0; if (!(cflag & PARENB)) /* Parity */ val |= MR1_NONE; else val |= MR1_WITH; if (cflag & PARODD) val |= MR1_ODD; if ((cflag & CS8) == CS8) { /* 8 data bits? */ val |= MR1_8_BITS; } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ val |= MR1_7_BITS; } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ val |= MR1_6_BITS; } else { /* Must be 5 */ val |= MR1_5_BITS; } /* * Enable H/W RTS/CTS handshaking. The default TA/MTA is * a DCE, hence the reverse sense of RTS and CTS */ /* Input Flow - CTS is raised when port is ready to receive data */ if (cflag & CRTS_IFLOW) val |= MR1_CTSCONT; ccbp->hi_mr1 = val; /* ========== set hi_mask ========== */ val = 0xff; if ((cflag & CS8) == CS8) { /* 8 data bits? */ val &= 0xFF; } else if ((cflag & CS7) == CS7) { /* 7 data bits? */ val &= 0x7F; } else if ((cflag & CS6) == CS6) { /* 6 data bits? */ val &= 0x3F; } else { /* Must be 5 */ val &= 0x1F; } if (iflag & ISTRIP) val &= 0x7F; ccbp->hi_mask = val; /* ========== set hi_prtcl ========== */ val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */ if (iflag & IXANY) val |= SP_TANY; if (iflag & IXON) val |= SP_TXEN; if (iflag & IXOFF) val |= SP_RXEN; if (iflag & INPCK) val |= SP_PAEN; ccbp->hi_prtcl = val; /* ========== set hi_{rx|tx}{on|off} ========== */ /* XXX: the card TOTALLY shields us from the flow control... */ ccbp->hi_txon = t->c_cc[VSTART]; ccbp->hi_txoff = t->c_cc[VSTOP]; ccbp->hi_rxon = t->c_cc[VSTART]; ccbp->hi_rxoff = t->c_cc[VSTOP]; /* ========== send settings to the card ========== */ /* potential sleep here */ if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */ si_command(pp, LOPEN, SI_WAIT); /* open it */ else si_command(pp, CONFIG, SI_WAIT); /* change params */ /* ========== set DTR etc ========== */ /* Hangup if ospeed == 0 */ if (t->c_ospeed == 0) { (void) simodem(tp, 0, SER_DTR | SER_RTS); } else { /* * If the previous speed was 0, may need to re-enable * the modem signals */ (void) simodem(tp, SER_DTR | SER_RTS, 0); } DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n", ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break)); splx(oldspl); return(error); } /* * Set/Get state of modem control lines. * Due to DCE-like behaviour of the adapter, some signals need translation: * TIOCM_DTR DSR * TIOCM_RTS CTS */ static int simodem(struct tty *tp, int sigon, int sigoff) { struct si_port *pp; volatile struct si_channel *ccbp; int x; pp = tp->t_sc; DPRINT((pp, DBG_ENTRY|DBG_MODEM, "simodem(%x,%x)\n", sigon, sigoff)); mtx_assert(&Giant, MA_OWNED); ccbp = pp->sp_ccb; /* Find channel address */ if (sigon == 0 && sigoff == 0) { x = ccbp->hi_ip; /* * XXX: not sure this is correct, should it be CTS&DSR ? * XXX: or do we (just) miss CTS & DSR ? */ if (x & IP_DCD) sigon |= SER_DCD; if (x & IP_DTR) sigon |= SER_DTR; if (x & IP_RTS) sigon |= SER_RTS; if (x & IP_RI) sigon |= SER_RI; return (sigon); } x = ccbp->hi_op; if (sigon & SER_DTR) x |= OP_DSR; if (sigoff & SER_DTR) x &= ~OP_DSR; if (sigon & SER_RTS) x |= OP_CTS; if (sigoff & SER_RTS) x &= ~OP_CTS; ccbp->hi_op = x; return 0; } /* * Handle change of modem state */ static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip) { /* if a modem dev */ mtx_assert(&Giant, MA_OWNED); if (hi_ip & IP_DCD) { if (!(pp->sp_last_hi_ip & IP_DCD)) { DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n", tp->t_line)); (void)ttyld_modem(tp, 1); } } else { if (pp->sp_last_hi_ip & IP_DCD) { DPRINT((pp, DBG_INTR, "modem carr off\n")); if (ttyld_modem(tp, 0)) (void) simodem(tp, 0, SER_DTR | SER_RTS); } } pp->sp_last_hi_ip = hi_ip; } /* * Poller to catch missed interrupts. * * Note that the SYSV Specialix drivers poll at 100 times per second to get * better response. We could really use a "periodic" version timeout(). :-) */ #ifdef POLL static void si_poll(void *nothing) { struct si_softc *sc; int i; volatile struct si_reg *regp; struct si_port *pp; int lost, oldspl, port; DPRINT((0, DBG_POLL, "si_poll()\n")); oldspl = spltty(); mtx_assert(&Giant, MA_OWNED); lost = 0; for (i = 0; i < si_numunits; i++) { sc = devclass_get_softc(si_devclass, i); if (sc == NULL || sc->sc_type == SIEMPTY) continue; regp = (struct si_reg *)sc->sc_maddr; /* * See if there has been a pending interrupt for 2 seconds * or so. The test (int_scounter >= 200) won't correspond * to 2 seconds if int_count gets changed. */ if (regp->int_pending != 0) { if (regp->int_scounter >= 200 && regp->initstat == 1) { printf("si%d: lost intr\n", i); lost++; } } else { regp->int_scounter = 0; } /* * gripe about no input flow control.. */ pp = sc->sc_ports; for (port = 0; port < sc->sc_nport; pp++, port++) { if (pp->sp_delta_overflows > 0) { printf("si%d: %d tty level buffer overflows\n", i, pp->sp_delta_overflows); pp->sp_delta_overflows = 0; } } } if (lost || si_realpoll) si_intr(NULL); /* call intr with fake vector */ splx(oldspl); timeout(si_poll, (caddr_t)0L, si_pollrate); } #endif /* ifdef POLL */ /* * The interrupt handler polls ALL ports on ALL adapters each time * it is called. */ static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */ static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */ void si_intr(void *arg) { struct si_softc *sc; struct si_port *pp; volatile struct si_channel *ccbp; struct tty *tp; volatile caddr_t maddr; BYTE op, ip; int x, card, port, n, i, isopen; volatile BYTE *z; BYTE c; sc = arg; mtx_assert(&Giant, MA_OWNED); DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n")); /* * When we get an int we poll all the channels and do ALL pending * work, not just the first one we find. This allows all cards to * share the same vector. * * XXX - But if we're sharing the vector with something that's NOT * a SI/XIO/SX card, we may be making more work for ourselves. */ for (card = 0; card < si_numunits; card++) { sc = devclass_get_softc(si_devclass, card); if (sc == NULL || sc->sc_type == SIEMPTY) continue; /* * First, clear the interrupt */ switch(sc->sc_type) { case SIHOST: maddr = sc->sc_maddr; ((volatile struct si_reg *)maddr)->int_pending = 0; /* flag nothing pending */ *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */ *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */ break; case SIHOST2: maddr = sc->sc_maddr; ((volatile struct si_reg *)maddr)->int_pending = 0; *(maddr+SIPLIRQCLR) = 0x00; *(maddr+SIPLIRQCLR) = 0x10; break; case SIPCI: maddr = sc->sc_maddr; ((volatile struct si_reg *)maddr)->int_pending = 0; *(maddr+SIPCIINTCL) = 0x0; break; case SIJETPCI: /* fall through to JETISA case */ case SIJETISA: maddr = sc->sc_maddr; ((volatile struct si_reg *)maddr)->int_pending = 0; *(maddr+SIJETINTCL) = 0x0; break; #ifdef DEV_EISA case SIEISA: maddr = sc->sc_maddr; ((volatile struct si_reg *)maddr)->int_pending = 0; (void)inb(sc->sc_iobase + 3); break; #endif case SIEMPTY: default: continue; } ((volatile struct si_reg *)maddr)->int_scounter = 0; /* * check each port */ for (pp = sc->sc_ports, port = 0; port < sc->sc_nport; pp++, port++) { ccbp = pp->sp_ccb; tp = pp->sp_tty; /* * See if a command has completed ? */ if (ccbp->hi_stat != pp->sp_pend) { DPRINT((pp, DBG_INTR, "si_intr hi_stat = %s, pend = %s\n", si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend))); switch(pp->sp_pend) { case LOPEN: case MPEND: case MOPEN: case FCLOSE: case CONFIG: case SBREAK: case EBREAK: /* sleeping in si_command */ DPRINT((pp, DBG_INTR, "do wakeup\n")); wakeup(&pp->sp_state); break; } pp->sp_pend = ccbp->hi_stat; } /* * Continue on if it's closed */ if (ccbp->hi_stat == IDLE_CLOSE) continue; /* * Do modem state change if not a local device */ si_modem_state(pp, tp, ccbp->hi_ip); /* * Check to see if we should 'receive' characters. */ if (tp->t_state & TS_CONNECTED && tp->t_state & TS_ISOPEN) isopen = 1; else isopen = 0; /* * Do input break processing */ if (ccbp->hi_state & ST_BREAK) { if (isopen) ttyld_rint(tp, TTY_BI); ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */ DPRINT((pp, DBG_INTR, "si_intr break\n")); } /* * Do RX stuff - if not open then dump any characters. * XXX: This is VERY messy and needs to be cleaned up. * * XXX: can we leave data in the host adapter buffer * when the clists are full? That may be dangerous * if the user cannot get an interrupt signal through. */ more_rx: if (!isopen) { ccbp->hi_rxopos = ccbp->hi_rxipos; goto end_rx; } /* * If the tty input buffers are blocked, stop emptying * the incoming buffers and let the auto flow control * assert.. */ if (tp->t_state & TS_TBLOCK) goto end_rx; /* * Process read characters if not skipped above */ op = ccbp->hi_rxopos; ip = ccbp->hi_rxipos; c = ip - op; if (c == 0) goto end_rx; n = c & 0xff; if (n > 250) n = 250; DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", n, op, ip)); /* * Suck characters out of host card buffer into the * "input staging buffer" - so that we dont leave the * host card in limbo while we're possibly echoing * characters and possibly flushing input inside the * ldisc l_rint() routine. */ if (n <= SI_BUFFERSIZE - op) { z = ccbp->hi_rxbuf + op; si_vbcopy(z, si_rxbuf, n); op += n; } else { x = SI_BUFFERSIZE - op; z = ccbp->hi_rxbuf + op; si_vbcopy(z, si_rxbuf, x); z = ccbp->hi_rxbuf; si_vbcopy(z, si_rxbuf + x, n - x); op += n; } /* clear collected characters from buffer */ ccbp->hi_rxopos = op; DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n", n, op, ip)); /* * at this point... * n = number of chars placed in si_rxbuf */ /* * Avoid the grotesquely inefficient lineswitch * routine (ttyinput) in "raw" mode. It usually * takes about 450 instructions (that's without * canonical processing or echo!). slinput is * reasonably fast (usually 40 instructions * plus call overhead). */ if (tp->t_state & TS_CAN_BYPASS_L_RINT) { /* block if the driver supports it */ if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER && (tp->t_cflag & CRTS_IFLOW || tp->t_iflag & IXOFF) && !(tp->t_state & TS_TBLOCK)) ttyblock(tp); tk_nin += n; tk_rawcc += n; tp->t_rawcc += n; pp->sp_delta_overflows += b_to_q((char *)si_rxbuf, n, &tp->t_rawq); ttwakeup(tp); if (tp->t_state & TS_TTSTOP && (tp->t_iflag & IXANY || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) { tp->t_state &= ~TS_TTSTOP; tp->t_lflag &= ~FLUSHO; si_start(tp); } } else { /* * It'd be nice to not have to go through the * function call overhead for each char here. * It'd be nice to block input it, saving a * loop here and the call/return overhead. */ for(x = 0; x < n; x++) { i = si_rxbuf[x]; if (ttyld_rint(tp, i) == -1) pp->sp_delta_overflows++; } } goto more_rx; /* try for more until RXbuf is empty */ end_rx: /* * Do TX stuff */ ttyld_start(tp); } /* end of for (all ports on this controller) */ } /* end of for (all controllers) */ DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n")); } /* * Nudge the transmitter... * * XXX: I inherited some funny code here. It implies the host card only * interrupts when the transmit buffer reaches the low-water-mark, and does * not interrupt when it's actually hits empty. In some cases, we have * processes waiting for complete drain, and we need to simulate an interrupt * about when we think the buffer is going to be empty (and retry if not). * I really am not certain about this... I *need* the hardware manuals. */ static void si_start(struct tty *tp) { struct si_port *pp; volatile struct si_channel *ccbp; struct clist *qp; BYTE ipos; int nchar; int oldspl, count, n, amount; oldspl = spltty(); mtx_assert(&Giant, MA_OWNED); qp = &tp->t_outq; pp = tp->t_sc; DPRINT((pp, DBG_ENTRY|DBG_START, "si_start(%x) t_state %x sp_state %x t_outq.c_cc %d\n", tp, tp->t_state, pp->sp_state, qp->c_cc)); if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP)) goto out; ccbp = pp->sp_ccb; count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; DPRINT((pp, DBG_START, "count %d\n", (BYTE)count)); while ((nchar = qp->c_cc) > 0) { if ((BYTE)count >= 255) break; amount = min(nchar, (255 - (BYTE)count)); ipos = (unsigned int)ccbp->hi_txipos; n = q_to_b(&tp->t_outq, si_txbuf, amount); /* will it fit in one lump? */ if ((SI_BUFFERSIZE - ipos) >= n) { si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n); } else { si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], SI_BUFFERSIZE - ipos); si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos), &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos)); } ccbp->hi_txipos += n; count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos; } if (count != 0 && nchar == 0) tp->t_state |= TS_BUSY; else tp->t_state &= ~TS_BUSY; /* wakeup time? */ ttwwakeup(tp); DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n", (BYTE)count, nchar, tp->t_state)); if (tp->t_state & TS_BUSY) { int time; time = ttspeedtab(tp->t_ospeed, chartimes); if (time > 0) { if (time < nchar) time = nchar / time; else time = 2; } else { DPRINT((pp, DBG_START, "bad char time value! %d\n", time)); time = hz/10; } if ((pp->sp_state & SS_LSTART) != 0) untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch); DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time)); pp->sp_state |= SS_LSTART; pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time); } out: splx(oldspl); DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n")); } /* * Note: called at splsoftclock from the timeout code * This has to deal with two things... cause wakeups while waiting for * tty drains on last process exit, and call l_start at about the right * time for protocols like ppp. */ static void si_lstart(void *arg) { struct si_port *pp = arg; struct tty *tp; int oldspl; DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n", pp, pp->sp_state)); oldspl = spltty(); mtx_assert(&Giant, MA_OWNED); pp->sp_state &= ~SS_LSTART; tp = pp->sp_tty; if ((tp->t_state & TS_ISOPEN) == 0) { splx(oldspl); return; } /* deal with the process exit case */ ttwwakeup(tp); /* nudge protocols - eg: ppp */ ttyld_start(tp); splx(oldspl); } /* * Stop output on a line. called at spltty(); */ static void si_stop(struct tty *tp, int rw) { volatile struct si_channel *ccbp; struct si_port *pp; mtx_assert(&Giant, MA_OWNED); pp = tp->t_sc; ccbp = pp->sp_ccb; DPRINT((pp, DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw)); /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */ if (rw & FWRITE) { /* what level are we meant to be flushing anyway? */ if (tp->t_state & TS_BUSY) { si_command(pp, WFLUSH, SI_NOWAIT); tp->t_state &= ~TS_BUSY; ttwwakeup(tp); /* Bruce???? */ } } #if 1 /* XXX: this doesn't work right yet.. */ /* XXX: this may have been failing because we used to call l_rint() * while we were looping based on these two counters. Now, we collect * the data and then loop stuffing it into l_rint(), making this * useless. Should we cause this to blow away the staging buffer? */ if (rw & FREAD) { ccbp->hi_rxopos = ccbp->hi_rxipos; } #endif } /* * Issue a command to the host card CPU. */ static void si_command(struct si_port *pp, int cmd, int waitflag) { int oldspl; volatile struct si_channel *ccbp = pp->sp_ccb; int x; DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%s,%d): hi_stat %s, sp_pend: %s\n", pp, si_cmdname(cmd), waitflag, si_cmdname(ccbp->hi_stat), si_cmdname(pp->sp_pend))); oldspl = spltty(); /* Keep others out */ mtx_assert(&Giant, MA_OWNED); /* wait until it's finished what it was doing.. */ /* XXX: sits in IDLE_BREAK until something disturbs it or break * is turned off. */ while((x = ccbp->hi_stat) != IDLE_OPEN && x != IDLE_CLOSE && x != IDLE_BREAK && x != cmd) { if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, "sicmd1", hz/4)) { DPRINT((pp, DBG_PARAM, "sicmd1 timeout: hi_stat (%s)\n", si_cmdname(ccbp->hi_stat))); /* This is very very bad. The card has crashed. */ /* XXX the driver breaks at this point */ splx(oldspl); return; } } /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */ /* if there was a pending command, cause a state-change wakeup */ switch(pp->sp_pend) { case LOPEN: case MPEND: case MOPEN: case FCLOSE: case CONFIG: case SBREAK: case EBREAK: DPRINT((pp, DBG_PARAM, "si_command: sp_pend %s\n", si_cmdname(pp->sp_pend))); wakeup(&pp->sp_state); break; default: break; } pp->sp_pend = cmd; /* New command pending */ ccbp->hi_stat = cmd; /* Post it */ if (waitflag) { while((x = ccbp->hi_stat) != IDLE_OPEN && x != IDLE_CLOSE && x != IDLE_BREAK) { if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH, "sicmd2", 0)) break; } } splx(oldspl); } #ifdef SI_DEBUG void si_dprintf(struct si_port *pp, int flags, const char *fmt, ...) { va_list ap; if ((pp == NULL && (si_debug&flags)) || (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) { if (pp != NULL) printf("%s: ", pp->sp_name); va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); } } #endif /* DEBUG */ static char * si_modulename(int host_type, int uart_type) { switch (host_type) { /* Z280 based cards */ #ifdef DEV_EISA case SIEISA: #endif case SIHOST2: case SIHOST: case SIPCI: switch (uart_type) { case 0: return(" (XIO)"); case 1: return(" (SI)"); } break; /* T225 based hosts */ case SIJETPCI: case SIJETISA: switch (uart_type) { case 0: return(" (SI)"); case 40: return(" (XIO)"); case 72: return(" (SXDC)"); } break; } return(""); } Index: head/sys/dev/si/si.h =================================================================== --- head/sys/dev/si/si.h (revision 179667) +++ head/sys/dev/si/si.h (revision 179668) @@ -1,396 +1,395 @@ /*- * Device driver for Specialix range (SI/XIO) of serial line multiplexors. * 'C' definitions for Specialix serial multiplex driver. * * Copyright (C) 1990, 1992, 1998 Specialix International, * Copyright (C) 1993, Andy Rutter * Copyright (C) 1995, Peter Wemm * * Derived from: SunOS 4.x version * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notices, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notices, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Andy Rutter of * Advanced Methods and Tools Ltd. based on original information * from Specialix International. * 4. Neither the name of Advanced Methods and Tools, nor Specialix * International may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHORS BE LIABLE. * * $FreeBSD$ */ #include /* * We name devices with %r in make_dev() with a radix of 32. */ #define SI_MAXPORTPERCARD 32 /* Buffer parameters */ #define SI_BUFFERSIZE 256 typedef uint8_t BYTE; /* Type cast for unsigned 8 bit */ typedef uint16_t WORD; /* Type cast for unsigned 16 bit */ /* * Hardware `registers', stored in the shared memory. * These are related to the firmware running on the Z280. */ struct si_reg { BYTE initstat; BYTE memsize; WORD int_count; WORD revision; BYTE rx_int_count; /* isr_count on Jet */ BYTE main_count; /* spare on Z-280 */ WORD int_pending; WORD int_counter; BYTE int_scounter; BYTE res[0x80 - 13]; }; /* * Per module control structure, stored in shared memory. */ struct si_module { WORD sm_next; /* Next module */ BYTE sm_type; /* Number of channels */ BYTE sm_number; /* Module number on cable */ BYTE sm_dsr; /* Private dsr copy */ BYTE sm_res[0x80 - 5]; /* Reserve space to 128 bytes */ }; /* * The 'next' pointer & with 0x7fff + SI base addres give * the address of the next module block if fitted. (else 0) * Note that next points to the TX buffer so 0x60 must be * subtracted to find the true base. */ #define TA4 0x00 #define TA8 0x08 #define TA4_ASIC 0x0A #define TA8_ASIC 0x0B #define MTA 0x28 #define SXDC 0x48 /* * Per channel(port) control structure, stored in shared memory. */ struct si_channel { /* * Generic stuff */ WORD next; /* Next Channel */ WORD addr_uart; /* Uart address */ WORD module; /* address of module struct */ BYTE type; /* Uart type */ BYTE fill; /* * Uart type specific stuff */ BYTE x_status; /* XON / XOFF status */ BYTE c_status; /* cooking status */ BYTE hi_rxipos; /* stuff into rx buff */ BYTE hi_rxopos; /* stuff out of rx buffer */ BYTE hi_txopos; /* Stuff into tx ptr */ BYTE hi_txipos; /* ditto out */ BYTE hi_stat; /* Command register */ BYTE dsr_bit; /* Magic bit for DSR */ BYTE txon; /* TX XON char */ BYTE txoff; /* ditto XOFF */ BYTE rxon; /* RX XON char */ BYTE rxoff; /* ditto XOFF */ BYTE hi_mr1; /* mode 1 image */ BYTE hi_mr2; /* mode 2 image */ BYTE hi_csr; /* clock register */ BYTE hi_op; /* Op control */ BYTE hi_ip; /* Input pins */ BYTE hi_state; /* status */ BYTE hi_prtcl; /* Protocol */ BYTE hi_txon; /* host copy tx xon stuff */ BYTE hi_txoff; BYTE hi_rxon; BYTE hi_rxoff; BYTE close_prev; /* Was channel previously closed */ BYTE hi_break; /* host copy break process */ BYTE break_state; /* local copy ditto */ BYTE hi_mask; /* Mask for CS7 etc. */ BYTE mask_z280; /* Z280's copy */ BYTE res[0x60 - 36]; BYTE hi_txbuf[SI_BUFFERSIZE]; BYTE hi_rxbuf[SI_BUFFERSIZE]; BYTE res1[0xA0]; }; /* * Register definitions */ /* * Break input control register definitions */ #define BR_IGN 0x01 /* Ignore any received breaks */ #define BR_INT 0x02 /* Interrupt on received break */ #define BR_PARMRK 0x04 /* Enable parmrk parity error processing */ #define BR_PARIGN 0x08 /* Ignore chars with parity errors */ /* * Protocol register provided by host for XON/XOFF and cooking */ #define SP_TANY 0x01 /* Tx XON any char */ #define SP_TXEN 0x02 /* Tx XON/XOFF enabled */ #define SP_CEN 0x04 /* Cooking enabled */ #define SP_RXEN 0x08 /* Rx XON/XOFF enabled */ #define SP_DCEN 0x20 /* DCD / DTR check */ #define SP_PAEN 0x80 /* Parity checking enabled */ /* * HOST STATUS / COMMAND REGISTER */ #define IDLE_OPEN 0x00 /* Default mode, TX and RX polled buffer updated etc */ #define LOPEN 0x02 /* Local open command (no modem ctl */ #define MOPEN 0x04 /* Open and monitor modem lines (blocks for DCD */ #define MPEND 0x06 /* Wating for DCD */ #define CONFIG 0x08 /* Channel config has changed */ #define CLOSE 0x0A /* Close channel */ #define SBREAK 0x0C /* Start break */ #define EBREAK 0x0E /* End break */ #define IDLE_CLOSE 0x10 /* Closed channel */ #define IDLE_BREAK 0x12 /* In a break */ #define FCLOSE 0x14 /* Force a close */ #define RESUME 0x16 /* Clear a pending xoff */ #define WFLUSH 0x18 /* Flush output buffer */ #define RFLUSH 0x1A /* Flush input buffer */ /* * Host status register */ #define ST_BREAK 0x01 /* Break received (clear with config) */ /* * OUTPUT PORT REGISTER */ #define OP_CTS 0x01 /* Enable CTS */ #define OP_DSR 0x02 /* Enable DSR */ /* * INPUT PORT REGISTER */ #define IP_DCD 0x04 /* DCD High */ #define IP_DTR 0x20 /* DTR High */ #define IP_RTS 0x02 /* RTS High */ #define IP_RI 0x40 /* RI High */ /* * Mode register and uart specific stuff */ /* * MODE REGISTER 1 */ #define MR1_5_BITS 0x00 #define MR1_6_BITS 0x01 #define MR1_7_BITS 0x02 #define MR1_8_BITS 0x03 /* * Parity */ #define MR1_ODD 0x04 #define MR1_EVEN 0x00 /* * Parity mode */ #define MR1_WITH 0x00 #define MR1_FORCE 0x08 #define MR1_NONE 0x10 #define MR1_SPECIAL 0x18 /* * Error mode */ #define MR1_CHAR 0x00 #define MR1_BLOCK 0x20 /* * Request to send line automatic control */ #define MR1_CTSCONT 0x80 /* * MODE REGISTER 2 */ /* * Number of stop bits */ #define MR2_1_STOP 0x07 #define MR2_2_STOP 0x0F /* * Clear to send automatic testing before character sent */ #define MR2_RTSCONT 0x10 /* * Reset RTS automatically after sending character? */ #define MR2_CTSCONT 0x20 /* * Channel mode */ #define MR2_NORMAL 0x00 #define MR2_AUTO 0x40 #define MR2_LOCAL 0x80 #define MR2_REMOTE 0xC0 /* * CLOCK SELECT REGISTER - this and the code assumes ispeed == ospeed */ /* * Clocking rates are in lower and upper nibbles.. R = upper, T = lower */ #define CLK75 0x0 #define CLK110 0x1 /* 110 on XIO!! */ #define CLK38400 0x2 /* out of sequence */ #define CLK150 0x3 #define CLK300 0x4 #define CLK600 0x5 #define CLK1200 0x6 #define CLK2000 0x7 #define CLK2400 0x8 #define CLK4800 0x9 #define CLK7200 0xa /* unchecked */ #define CLK9600 0xb #define CLK19200 0xc #define CLK57600 0xd /* * Per-port (channel) soft information structure, stored in the driver. * This is visible via ioctl()'s. */ struct si_port { volatile struct si_channel *sp_ccb; struct tty *sp_tty; int sp_pend; /* pending command */ int sp_last_hi_ip; /* cached DCD */ int sp_state; int sp_delta_overflows; struct callout_handle lstart_ch;/* For canceling our timeout */ int sp_debug; /* debug mask */ char sp_name[5]; }; /* sp_state */ /* 0x0001 -- */ /* 0x0002 -- */ /* 0x0004 -- */ /* 0x0008 -- */ /* 0x0010 -- */ /* 0x0020 -- */ /* 0x0040 -- */ /* 0x0080 -- */ #define SS_LSTART 0x0100 /* lstart timeout pending */ /* 0x0200 -- */ /* 0x0400 -- */ /* 0x0800 -- */ /* * Command post flags */ #define SI_NOWAIT 0x00 /* Don't wait for command */ #define SI_WAIT 0x01 /* Wait for complete */ /* * SI ioctls */ /* * struct for use by Specialix ioctls - used by siconfig(8) */ typedef struct { unsigned char sid_port:5, /* 0 - 31 ports per card */ sid_card:2, /* 0 - 3 cards */ sid_control:1; /* controlling device (all cards) */ } sidev_t; struct si_tcsi { sidev_t tc_dev; union { int x_int; int x_dbglvl; } tc_action; #define tc_card tc_dev.sid_card #define tc_port tc_dev.sid_port #define tc_int tc_action.x_int #define tc_dbglvl tc_action.x_dbglvl }; struct si_pstat { sidev_t tc_dev; union { struct si_port x_siport; struct si_channel x_ccb; struct tty x_tty; } tc_action; #define tc_siport tc_action.x_siport #define tc_ccb tc_action.x_ccb #define tc_tty tc_action.x_tty }; #define IOCTL_MIN 96 #define TCSIDEBUG _IOW('S', 96, struct si_tcsi) /* Toggle debug */ #define TCSIRXIT _IOW('S', 97, struct si_tcsi) /* RX int throttle */ #define TCSIIT _IOW('S', 98, struct si_tcsi) /* TX int throttle */ /* 99 defunct */ /* 100 defunct */ /* 101 defunct */ /* 102 defunct */ /* 103 defunct */ /* 104 defunct */ #define TCSISTATE _IOWR('S', 105, struct si_tcsi) /* get current state of RTS DCD and DTR pins */ /* 106 defunct */ #define TCSIPORTS _IOR('S', 107, int) /* Number of ports found */ #define TCSISDBG_LEVEL _IOW('S', 108, struct si_tcsi) /* equivalent of TCSIDEBUG which sets a * particular debug level (DBG_??? bit * mask), default is 0xffff */ #define TCSIGDBG_LEVEL _IOWR('S', 109, struct si_tcsi) #define TCSIGRXIT _IOWR('S', 110, struct si_tcsi) #define TCSIGIT _IOWR('S', 111, struct si_tcsi) /* 112 defunct */ /* 113 defunct */ /* 114 defunct */ /* 115 defunct */ /* 116 defunct */ /* 117 defunct */ #define TCSISDBG_ALL _IOW('S', 118, int) /* set global debug level */ #define TCSIGDBG_ALL _IOR('S', 119, int) /* get global debug level */ /* 120 defunct */ /* 121 defunct */ /* 122 defunct */ /* 123 defunct */ #define TCSIMODULES _IOR('S', 124, int) /* Number of modules found */ /* Various stats and monitoring hooks per tty device */ #define TCSI_PORT _IOWR('S', 125, struct si_pstat) /* get si_port */ #define TCSI_CCB _IOWR('S', 126, struct si_pstat) /* get si_ccb */ -#define TCSI_TTY _IOWR('S', 127, struct si_pstat) /* get tty struct */ #define IOCTL_MAX 127 #define IS_SI_IOCTL(cmd) ((u_int)((cmd)&0xff00) == ('S'<<8) && \ (u_int)((cmd)&0xff) >= IOCTL_MIN && \ (u_int)((cmd)&0xff) <= IOCTL_MAX) #define CONTROLDEV "/dev/si_control" Index: head/usr.sbin/sicontrol/sicontrol.8 =================================================================== --- head/usr.sbin/sicontrol/sicontrol.8 (revision 179667) +++ head/usr.sbin/sicontrol/sicontrol.8 (revision 179668) @@ -1,112 +1,109 @@ .\" $FreeBSD$ .\" .Dd September 26, 1995 .Dt SICONTROL 8 .Os .Sh NAME .Nm sicontrol .Nd Specialix SI/XIO driver configuration and debugging .Sh SYNOPSIS .Nm device .Ar command Op Ar param ... .Sh DESCRIPTION The .Nm utility is used to configure and monitor the SI/XIO device driver. .Pp The .Nm utility operates on the specified .Ar device to indicate which port is to be used. .Pp The special .Ar device string `-' is used to indicate the global driver settings instead. .Pp A .Pa /dev/ is included if necessary. .Pp The following commands are used for the global settings and should be specified with the '-' device name: .Bl -tag -width 4n .It Cm int_throttle Op Cm value Configure the `aggregate interrupt throttle value'. The maximum number of host adapter interrupts per second is determined by: .Pp .Ar "controller CPU clock / (8 * int_throttle)" .Pp The default value at boot time is 25000. The host adapter cpu clock is 25MHz. This gives a maximum interrupt rate of about 125 interrupts per second. .Pp Lowering this value will increase the rate in which the host adapter can interrupt the operating system for attention. .\" .It Cm rxint_throttle Op Cm value Configure the receiver interrupt throttle value. The default value of 4 at boot time allows an interrupt rate of approximately 25. .Pp Lowering this value will increase the rate in which the host adapter can interrupt the operating system to empty the receiver fifos. .\" .It Cm nport Return the number of ports under the control of the device driver. .El .Pp The following commands are used for the individual ports and should be specified with a device name from .Pa /dev : .Bl -tag -width 4n .It Cm mstate Show the current incoming modem control signals. .It Cm ccbstat Show the current "ccb" structure for the specified port. This is not of much use outside of debugging the driver and determining why a port is wedged. -.It Cm ttystat -Show the current "tty" structure that the kernel has for the specified port. -This is not much use outside of debugging the driver. .El .Sh FILES .Bl -tag -width /dev/si_control -compact .It Pa /dev/si_control global driver control file for use by .Nm .It Pa /dev/ttyA* terminal control ports .It Pa /dev/ttyiA* initial termios state devices, for use by .Xr stty 1 .It Pa /dev/ttylA* locked termios state devices, for use by .Xr stty 1 .El .Sh DIAGNOSTICS Generally self explanatory..... .Sh SEE ALSO .Xr stty 1 , .Xr si 4 , .Xr termios 4 , .Xr tty 4 , .Xr comcontrol 8 .Sh HISTORY The .Nm utility is loosely based on a utility called .Nm siconfig which was written by .An Andy Rutter Aq andy@acronym.co.uk .Pp Specialix International do not support this device driver in any way. .Sh AUTHORS .An Peter Wemm Aq peter@FreeBSD.org .Sh BUGS Bound to be many... :-) Index: head/usr.sbin/sicontrol/sicontrol.c =================================================================== --- head/usr.sbin/sicontrol/sicontrol.c (revision 179667) +++ head/usr.sbin/sicontrol/sicontrol.c (revision 179668) @@ -1,789 +1,726 @@ /* * Device driver for Specialix range (SLXOS) of serial line multiplexors. * SLXOS configuration and debug interface * * Copyright (C) 1990, 1992 Specialix International, * Copyright (C) 1993, Andy Rutter * Copyright (C) 1995, Peter Wemm * * Derived from: SunOS 4.x version * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notices, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notices, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of Advanced Methods and Tools, nor Specialix * International may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN * NO EVENT SHALL THE AUTHORS BE LIABLE. */ #ifndef lint static const char rcsid[] = "$FreeBSD$"; #endif /* not lint */ #include #include #include #include #include #include #include #include #include #include #include #include #define SI_DEBUG #include #include struct lv { char *lv_name; int lv_bit; } lv[] = { {"entry", DBG_ENTRY}, {"open", DBG_OPEN}, {"close", DBG_CLOSE}, {"read", DBG_READ}, {"write", DBG_WRITE}, {"param", DBG_PARAM}, {"modem", DBG_MODEM}, {"select", DBG_SELECT}, {"optim", DBG_OPTIM}, {"intr", DBG_INTR}, {"start", DBG_START}, {"lstart", DBG_LSTART}, {"ioctl", DBG_IOCTL}, {"fail", DBG_FAIL}, {"autoboot", DBG_AUTOBOOT}, {"download", DBG_DOWNLOAD}, {"drain", DBG_DRAIN}, {"poll", DBG_POLL}, {0, 0} }; static int alldev = 0; void ccb_stat(int, char **); void port_stat(int, char **); void debug(int, char **); void dostat(void); int getnum(char *); int islevel(char *); int lvls2bits(char *); void mstate(int, char **); void nport(int, char **); void onoff(int, char **, int, char *, char *, int); int opencontrol(void); void prlevels(int); void prusage(int, int); void rxint(int, char **); -void tty_stat(int, char **); void txint(int, char **); struct opt { char *o_name; void (*o_func)(int, char **); } opt[] = { {"debug", debug}, {"rxint_throttle", rxint}, {"int_throttle", txint}, {"nport", nport}, {"mstate", mstate}, {"ccbstat", ccb_stat}, {"portstat", port_stat}, - {"ttystat", tty_stat}, {0, 0} }; struct stat_list { void (*st_func)(int, char **); } stat_list[] = { {mstate}, {0} }; #define U_DEBUG 0 #define U_TXINT 1 #define U_RXINT 2 #define U_NPORT 3 #define U_MSTATE 4 #define U_STAT_CCB 5 #define U_STAT_PORT 6 -#define U_STAT_TTY 7 -#define U_MAX 8 +#define U_MAX 7 #define U_ALL -1 char *usage[] = { "debug [[add|del|set debug_levels] | [off]]\n", "int_throttle [newvalue]\n", "rxint_throttle [newvalue]\n", "nport\n", "mstate\n", "ccbstat\n", "portstat\n", - "ttystat\n", 0 }; int ctlfd; char *Devname; struct si_tcsi tc; int main(int argc, char **argv) { struct opt *op; void (*func)(int, char **) = NULL; if (argc < 2) prusage(U_ALL, 1); Devname = argv[1]; if (strcmp(Devname, "-") == 0) { alldev = 1; } else { sidev_t dev; int n; int card, port; n = sscanf(Devname, "%d:%d", &card, &port); if (n != 2) errx(1, "Devname must be in form card:port. eg: 0:7"); dev.sid_card = card; dev.sid_port = port; tc.tc_dev = dev; } ctlfd = opencontrol(); if (argc == 2) { dostat(); exit(0); } argc--; argv++; for (op = opt; op->o_name; op++) { if (strcmp(argv[1], op->o_name) == 0) { func = op->o_func; break; } } if (func == NULL) prusage(U_ALL, 1); argc -= 2; argv += 2; (*func)(argc, argv); exit(0); } int opencontrol(void) { int fd; fd = open(CONTROLDEV, O_RDWR|O_NDELAY); if (fd < 0) err(1, "open on %s", CONTROLDEV); return(fd); } /* * Print a usage message - this relies on U_DEBUG==0 and U_BOOT==1. * Don't print the DEBUG usage string unless explicity requested. */ void prusage(int strn, int eflag) { char **cp; if (strn == U_ALL) { fprintf(stderr, "usage: sicontrol %s", usage[1]); fprintf(stderr, " sicontrol %s", usage[2]); fprintf(stderr, " sicontrol %s", usage[3]); fprintf(stderr, " sicontrol devname %s", usage[4]); for (cp = &usage[5]; *cp; cp++) fprintf(stderr, " sicontrol devname %s", *cp); } else if (strn >= 0 && strn <= U_MAX) fprintf(stderr, "usage: sicontrol devname %s", usage[strn]); else fprintf(stderr, "sicontrol: usage ???\n"); exit(eflag); } /* print port status */ void dostat(void) { char *av[1], *acp; struct stat_list *stp; struct si_tcsi stc; int donefirst = 0; printf("%s: ", alldev ? "ALL" : Devname); acp = malloc(strlen(Devname) + 3); memset(acp, ' ', strlen(Devname)); strcat(acp, " "); stc = tc; for (stp = stat_list; stp->st_func != NULL; stp++) { if (donefirst) fputs(acp, stdout); else donefirst++; av[0] = NULL; tc = stc; (*stp->st_func)(-1, av); } } /* * debug * debug [[set|add|del debug_lvls] | [off]] */ void debug(int ac, char **av) { int level; if (ac > 2) prusage(U_DEBUG, 1); if (alldev) { if (ioctl(ctlfd, TCSIGDBG_ALL, &tc.tc_dbglvl) < 0) err(1, "TCSIGDBG_ALL on %s", Devname); } else { if (ioctl(ctlfd, TCSIGDBG_LEVEL, &tc) < 0) err(1, "TCSIGDBG_LEVEL on %s", Devname); } switch (ac) { case 0: printf("%s: debug levels - ", Devname); prlevels(tc.tc_dbglvl); return; case 1: if (strcmp(av[0], "off") == 0) { tc.tc_dbglvl = 0; break; } prusage(U_DEBUG, 1); /* no return */ case 2: level = lvls2bits(av[1]); if (strcmp(av[0], "add") == 0) tc.tc_dbglvl |= level; else if (strcmp(av[0], "del") == 0) tc.tc_dbglvl &= ~level; else if (strcmp(av[0], "set") == 0) tc.tc_dbglvl = level; else prusage(U_DEBUG, 1); } if (alldev) { if (ioctl(ctlfd, TCSISDBG_ALL, &tc.tc_dbglvl) < 0) err(1, "TCSISDBG_ALL on %s", Devname); } else { if (ioctl(ctlfd, TCSISDBG_LEVEL, &tc) < 0) err(1, "TCSISDBG_LEVEL on %s", Devname); } } void rxint(int ac, char **av) { tc.tc_port = 0; switch (ac) { case 0: printf("%s: ", Devname); case -1: if (ioctl(ctlfd, TCSIGRXIT, &tc) < 0) err(1, "TCSIGRXIT"); printf("RX interrupt throttle: %d msec\n", tc.tc_int*10); break; case 1: tc.tc_int = getnum(av[0]) / 10; if (tc.tc_int == 0) tc.tc_int = 1; if (ioctl(ctlfd, TCSIRXIT, &tc) < 0) err(1, "TCSIRXIT on %s at %d msec", Devname, tc.tc_int*10); break; default: prusage(U_RXINT, 1); } } void txint(int ac, char **av) { tc.tc_port = 0; switch (ac) { case 0: printf("%s: ", Devname); case -1: if (ioctl(ctlfd, TCSIGIT, &tc) < 0) err(1, "TCSIGIT"); printf("aggregate interrupt throttle: %d\n", tc.tc_int); break; case 1: tc.tc_int = getnum(av[0]); if (ioctl(ctlfd, TCSIIT, &tc) < 0) err(1, "TCSIIT on %s at %d", Devname, tc.tc_int); break; default: prusage(U_TXINT, 1); } } void onoff(int ac, char **av, int cmd, char *cmdstr, char *prstr, int usage) { if (ac > 1) prusage(usage, 1); if (ac == 1) { if (strcmp(av[0], "on") == 0) tc.tc_int = 1; else if (strcmp(av[0], "off") == 0) tc.tc_int = 0; else prusage(usage, 1); } else tc.tc_int = -1; if (ioctl(ctlfd, cmd, &tc) < 0) err(1, "%s on %s", cmdstr, Devname); switch (ac) { case 0: printf("%s: ", Devname); case -1: printf("%s ", prstr); if (tc.tc_int) printf("on\n"); else printf("off\n"); } } void mstate(int ac, char **av) { switch (ac) { case 0: printf("%s: ", Devname); case -1: break; default: prusage(U_MSTATE, 1); } if (ioctl(ctlfd, TCSISTATE, &tc) < 0) err(1, "TCSISTATE on %s", Devname); printf("modem bits state - (0x%x)", tc.tc_int); if (tc.tc_int & IP_DCD) printf(" DCD"); if (tc.tc_int & IP_DTR) printf(" DTR"); if (tc.tc_int & IP_RTS) printf(" RTS"); printf("\n"); } void nport(int ac, char **av) { int ports; if (ac != 0) prusage(U_NPORT, 1); if (ioctl(ctlfd, TCSIPORTS, &ports) < 0) err(1, "TCSIPORTS on %s", Devname); printf("SLXOS: total of %d ports\n", ports); } const char *s_stat(int stat) { switch (stat) { case IDLE_OPEN: return "IDLE_OPEN"; case LOPEN: return "LOPEN"; case MOPEN: return "MOPEN"; case MPEND: return "MPEND"; case CONFIG: return "CONFIG"; case CLOSE: return "CLOSE"; case SBREAK: return "SBREAK"; case EBREAK: return "EBREAK"; case IDLE_CLOSE:return "IDLE_CLOSE"; case IDLE_BREAK:return "IDLE_BREAK"; case FCLOSE: return "FCLOSE"; case RESUME: return "RESUME"; case WFLUSH: return "WFLUSH"; case RFLUSH: return "RFLUSH"; default: return "??"; } } const char *s_mr1(int mr1) { static char msg[200]; sprintf(msg, "%dbit, %s, parity:[", 5 + (mr1 & MR1_8_BITS), mr1 & MR1_ODD ? "odd" : "even"); if (mr1 & MR1_WITH) strcat(msg, "with;"); if (mr1 & MR1_FORCE) strcat(msg, "force;"); if (mr1 & MR1_NONE) strcat(msg, "none;"); if (mr1 & MR1_SPECIAL) strcat(msg, "special;"); strcpy(msg + strlen(msg) - 1, "]"); sprintf(msg + strlen(msg), ", err: %s", mr1 & MR1_BLOCK ? "block" : "none"); sprintf(msg + strlen(msg), ", cts: %s", mr1 & MR1_CTSCONT ? "auto" : "none"); return (msg); } const char *s_mr2(int mr2) { static char msg[200]; switch (mr2 & 0xf) { case MR2_1_STOP: strcpy(msg, "1stop"); break; case MR2_2_STOP: strcpy(msg, "2stop"); break; default: sprintf(msg, "??stop (0x%x)", mr2 & 0xf); break; } if (mr2 & MR2_RTSCONT) strcat(msg, ", rtscont"); if (mr2 & MR2_CTSCONT) strcat(msg, ", ctscont"); switch (mr2 & 0xc0) { case MR2_NORMAL: strcat(msg, ", mode:normal"); break; case MR2_AUTO: strcat(msg, ", mode:auto"); break; case MR2_LOCAL: strcat(msg, ", mode:local"); break; case MR2_REMOTE: strcat(msg, ", mode:remote"); break; } return (msg); } const char *s_clk(int clk) { switch (clk & 0xf) { case 0x0: return "75"; case 0x1: return "110/115200"; case 0x2: return "38400"; case 0x3: return "150"; case 0x4: return "300"; case 0x5: return "600"; case 0x6: return "1200"; case 0x7: return "2000"; case 0x8: return "2400"; case 0x9: return "4800"; case 0xa: return "7200"; case 0xb: return "9600"; case 0xc: return "19200"; case 0xd: return "57600"; case 0xe: return "?0xe"; case 0xf: return "?0xf"; } return ("gcc sucks"); } const char *s_op(int op) { static char msg[200]; sprintf(msg, "cts:%s", (op & OP_CTS) ? "on" : "off"); sprintf(msg + strlen(msg), ", dsr:%s", (op & OP_DSR) ? "on" : "off"); return (msg); } const char *s_ip(int ip) { static char msg[200]; sprintf(msg, "rts:%s", (ip & IP_RTS) ? "on" : "off"); sprintf(msg + strlen(msg), ", dcd:%s", (ip & IP_DCD) ? "on" : "off"); sprintf(msg + strlen(msg), ", dtr:%s", (ip & IP_DTR) ? "on" : "off"); sprintf(msg + strlen(msg), ", ri:%s", (ip & IP_RI) ? "on" : "off"); return (msg); } const char *s_state(int state) { return (state & ST_BREAK ? "break:on" : "break:off"); } const char *s_prtcl(int pr) { static char msg[200]; sprintf(msg, "tx xon any:%s", (pr & SP_TANY) ? "on" : "off"); sprintf(msg + strlen(msg), ", tx xon/xoff:%s", (pr & SP_TXEN) ? "on" : "off"); sprintf(msg + strlen(msg), ", cooking:%s", (pr & SP_CEN) ? "on" : "off"); sprintf(msg + strlen(msg), ", rx xon/xoff:%s", (pr & SP_RXEN) ? "on" : "off"); sprintf(msg + strlen(msg), ", dcd/dsr check:%s", (pr & SP_DCEN) ? "on" : "off"); sprintf(msg + strlen(msg), ", parity check:%s", (pr & SP_PAEN) ? "on" : "off"); return (msg); } const char *s_break(int br) { static char msg[200]; sprintf(msg, "ignore rx brk:%s", (br & BR_IGN) ? "on" : "off"); sprintf(msg + strlen(msg), ", brk interrupt:%s", (br & BR_INT) ? "on" : "off"); sprintf(msg + strlen(msg), ", parmrking:%s", (br & BR_PARMRK) ? "on" : "off"); sprintf(msg + strlen(msg), ", parign:%s", (br & BR_PARIGN) ? "on" : "off"); return (msg); } const char * s_xstat(int xs) { static char msg[200]; msg[0] = 0; /* MTA definitions, not TA */ if (xs & 0x01) strcat(msg, "TION "); /* Tx interrupts on (MTA only) */ if (xs & 0x02) strcat(msg, "RTSEN "); /* RTS FLOW enabled (MTA only) */ if (xs & 0x04) strcat(msg, "RTSLOW "); /* XOFF received (TA only) */ if (xs & 0x08) strcat(msg, "RXEN "); /* Rx XON/XOFF enabled */ if (xs & 0x10) strcat(msg, "ANYXO "); /* XOFF pending/sent or RTS dropped */ if (xs & 0x20) strcat(msg, "RXSE "); /* Rx XOFF sent */ if (xs & 0x40) strcat(msg, "NPEND "); /* Rx XON pending or XOFF pending */ if (xs & 0x40) strcat(msg, "FPEND "); /* Rx XOFF pending */ return (msg); } const char * s_cstat(int cs) { static char msg[200]; msg[0] = 0; /* MTA definitions, not TA */ if (cs & 0x01) strcat(msg, "TEMR "); /* Tx empty requested (MTA only) */ if (cs & 0x02) strcat(msg, "TEMA "); /* Tx empty acked (MTA only) */ if (cs & 0x04) strcat(msg, "EN "); /* Cooking enabled (on MTA means port is also || */ if (cs & 0x08) strcat(msg, "HIGH "); /* Buffer previously hit high water */ if (cs & 0x10) strcat(msg, "CTSEN "); /* CTS automatic flow-control enabled */ if (cs & 0x20) strcat(msg, "DCDEN "); /* DCD/DTR checking enabled */ if (cs & 0x40) strcat(msg, "BREAK "); /* Break detected */ if (cs & 0x80) strcat(msg, "RTSEN "); /* RTS automatic flow control enabled (MTA only) */ return (msg); } void ccb_stat(int ac, char **av) { struct si_pstat sip; #define CCB sip.tc_ccb if (ac != 0) prusage(U_STAT_CCB, 1); sip.tc_dev = tc.tc_dev; if (ioctl(ctlfd, TCSI_CCB, &sip) < 0) err(1, "TCSI_CCB on %s", Devname); printf("%s: ", Devname); /* WORD next - Next Channel */ /* WORD addr_uart - Uart address */ /* WORD module - address of module struct */ printf("\tuart_type 0x%x\n", CCB.type); /* BYTE type - Uart type */ /* BYTE fill - */ printf("\tx_status 0x%x %s\n", CCB.x_status, s_xstat(CCB.x_status)); /* BYTE x_status - XON / XOFF status */ printf("\tc_status 0x%x %s\n", CCB.c_status, s_cstat(CCB.c_status)); /* BYTE c_status - cooking status */ printf("\thi_rxipos 0x%x\n", CCB.hi_rxipos); /* BYTE hi_rxipos - stuff into rx buff */ printf("\thi_rxopos 0x%x\n", CCB.hi_rxopos); /* BYTE hi_rxopos - stuff out of rx buffer */ printf("\thi_txopos 0x%x\n", CCB.hi_txopos); /* BYTE hi_txopos - Stuff into tx ptr */ printf("\thi_txipos 0x%x\n", CCB.hi_txipos); /* BYTE hi_txipos - ditto out */ printf("\thi_stat 0x%x %s\n", CCB.hi_stat, s_stat(CCB.hi_stat));/* BYTE hi_stat - Command register */ printf("\tdsr_bit 0x%x\n", CCB.dsr_bit); /* BYTE dsr_bit - Magic bit for DSR */ printf("\ttxon 0x%x\n", CCB.txon); /* BYTE txon - TX XON char */ printf("\ttxoff 0x%x\n", CCB.txoff); /* BYTE txoff - ditto XOFF */ printf("\trxon 0x%x\n", CCB.rxon); /* BYTE rxon - RX XON char */ printf("\trxoff 0x%x\n", CCB.rxoff); /* BYTE rxoff - ditto XOFF */ printf("\thi_mr1 0x%x %s\n", CCB.hi_mr1, s_mr1(CCB.hi_mr1)); /* BYTE hi_mr1 - mode 1 image */ printf("\thi_mr2 0x%x %s\n", CCB.hi_mr2, s_mr2(CCB.hi_mr2)); /* BYTE hi_mr2 - mode 2 image */ printf("\thi_csr 0x%x in:%s out:%s\n", CCB.hi_csr, s_clk(CCB.hi_csr >> 4), s_clk(CCB.hi_csr)); /* BYTE hi_csr - clock register */ printf("\thi_op 0x%x %s\n", CCB.hi_op, s_op(CCB.hi_op)); /* BYTE hi_op - Op control */ printf("\thi_ip 0x%x %s\n", CCB.hi_ip, s_ip(CCB.hi_ip)); /* BYTE hi_ip - Input pins */ printf("\thi_state 0x%x %s\n", CCB.hi_state, s_state(CCB.hi_state)); /* BYTE hi_state - status */ printf("\thi_prtcl 0x%x %s\n", CCB.hi_prtcl, s_prtcl(CCB.hi_prtcl)); /* BYTE hi_prtcl - Protocol */ printf("\thi_txon 0x%x\n", CCB.hi_txon); /* BYTE hi_txon - host copy tx xon stuff */ printf("\thi_txoff 0x%x\n", CCB.hi_txoff); /* BYTE hi_txoff - */ printf("\thi_rxon 0x%x\n", CCB.hi_rxon); /* BYTE hi_rxon - */ printf("\thi_rxoff 0x%x\n", CCB.hi_rxoff); /* BYTE hi_rxoff - */ printf("\tclose_prev 0x%x\n", CCB.close_prev); /* BYTE close_prev - Was channel previously closed */ printf("\thi_break 0x%x %s\n", CCB.hi_break, s_break(CCB.hi_break)); /* BYTE hi_break - host copy break process */ printf("\tbreak_state 0x%x\n", CCB.break_state); /* BYTE break_state - local copy ditto */ printf("\thi_mask 0x%x\n", CCB.hi_mask); /* BYTE hi_mask - Mask for CS7 etc. */ printf("\tmask_z280 0x%x\n", CCB.mask_z280); /* BYTE mask_z280 - Z280's copy */ /* BYTE res[0x60 - 36] - */ /* BYTE hi_txbuf[SLXOS_BUFFERSIZE] - */ /* BYTE hi_rxbuf[SLXOS_BUFFERSIZE] - */ /* BYTE res1[0xA0] - */ } const char *sp_state(int st) { if (st & SS_LSTART) return("lstart "); else return(""); } void port_stat(int ac, char **av) { struct si_pstat sip; #define PRT sip.tc_siport if (ac != 0) prusage(U_STAT_PORT, 1); sip.tc_dev = tc.tc_dev; if (ioctl(ctlfd, TCSI_PORT, &sip) < 0) err(1, "TCSI_PORT on %s", Devname); printf("%s: ", Devname); printf("\tsp_pend 0x%x %s\n", PRT.sp_pend, s_stat(PRT.sp_pend)); printf("\tsp_last_hi_ip 0x%x %s\n", PRT.sp_last_hi_ip, s_ip(PRT.sp_last_hi_ip)); printf("\tsp_state 0x%x %s\n", PRT.sp_state, sp_state(PRT.sp_state)); printf("\tsp_delta_overflows 0x%d\n", PRT.sp_delta_overflows); -} - -const char *pt_state(int ts) -{ - static char buf[200]; - - buf[0] = 0; - if (ts & TS_SO_OLOWAT) strcat(buf, "TS_SO_OLOWAT "); - if (ts & TS_ASYNC) strcat(buf, "TS_ASYNC "); - if (ts & TS_BUSY) strcat(buf, "TS_BUSY "); - if (ts & TS_CARR_ON) strcat(buf, "TS_CARR_ON "); - if (ts & TS_FLUSH) strcat(buf, "TS_FLUSH "); - if (ts & TS_ISOPEN) strcat(buf, "TS_ISOPEN "); - if (ts & TS_TBLOCK) strcat(buf, "TS_TBLOCK "); - if (ts & TS_TIMEOUT) strcat(buf, "TS_TIMEOUT "); - if (ts & TS_TTSTOP) strcat(buf, "TS_TTSTOP "); - if (ts & TS_XCLUDE) strcat(buf, "TS_XCLUDE "); - if (ts & TS_BKSL) strcat(buf, "TS_BKSL "); - if (ts & TS_CNTTB) strcat(buf, "TS_CNTTB "); - if (ts & TS_ERASE) strcat(buf, "TS_ERASE "); - if (ts & TS_TYPEN) strcat(buf, "TS_TYPEN "); - if (ts & TS_CAN_BYPASS_L_RINT) strcat(buf, "TS_CAN_BYPASS_L_RINT "); - if (ts & TS_CONNECTED) strcat(buf, "TS_CONNECTED "); - if (ts & TS_SNOOP) strcat(buf, "TS_SNOOP "); - if (ts & TS_SO_OCOMPLETE) strcat(buf, "TS_OCOMPLETE "); - if (ts & TS_ZOMBIE) strcat(buf, "TS_ZOMBIE "); - if (ts & TS_CAR_OFLOW) strcat(buf, "TS_CAR_OFLOW "); - if (ts & TS_DTR_WAIT) strcat(buf, "TS_DTR_WAIT "); - if (ts & TS_GONE) strcat(buf, "TS_GONE "); - if (ts & TS_CALLOUT) strcat(buf, "TS_CALLOUT "); - return (buf); -} -void -tty_stat(int ac, char **av) -{ - struct si_pstat sip; -#define TTY sip.tc_tty - - if (ac != 0) - prusage(U_STAT_TTY, 1); - sip.tc_dev = tc.tc_dev; - if (ioctl(ctlfd, TCSI_TTY, &sip) < 0) - err(1, "TCSI_TTY on %s", Devname); - printf("%s: ", Devname); - - printf("\tt_outq.c_cc %d\n", TTY.t_outq.c_cc); /* struct clist t_outq */ - printf("\tt_flags 0x%x\n", TTY.t_flags); /* int t_flags */ - printf("\tt_state 0x%x %s\n", TTY.t_state, pt_state(TTY.t_state)); /* int t_state */ - printf("\tt_ihiwat %d\n", TTY.t_ihiwat); /* int t_ihiwat */ - printf("\tt_ilowat %d\n", TTY.t_ilowat); /* int t_ilowat */ - printf("\tt_ohiwat %d\n", TTY.t_ohiwat); /* int t_ohiwat */ - printf("\tt_olowat %d\n", TTY.t_olowat); /* int t_olowat */ - printf("\tt_iflag 0x%x\n", TTY.t_iflag); /* t_iflag */ - printf("\tt_oflag 0x%x\n", TTY.t_oflag); /* t_oflag */ - printf("\tt_cflag 0x%x\n", TTY.t_cflag); /* t_cflag */ - printf("\tt_lflag 0x%x\n", TTY.t_lflag); /* t_lflag */ - printf("\tt_cc %p\n", (void *)TTY.t_cc); /* t_cc */ - printf("\tt_termios.c_ispeed %d\n", TTY.t_termios.c_ispeed); /* t_termios.c_ispeed */ - printf("\tt_termios.c_ospeed %d\n", TTY.t_termios.c_ospeed); /* t_termios.c_ospeed */ } int islevel(char *tk) { struct lv *lvp; char *acp; for (acp = tk; *acp; acp++) if (isupper(*acp)) *acp = tolower(*acp); for (lvp = lv; lvp->lv_name; lvp++) if (strcmp(lvp->lv_name, tk) == 0) return(lvp->lv_bit); return(0); } /* * Convert a string consisting of tokens separated by white space, commas * or `|' into a bitfield - flag any unrecognised tokens. */ int lvls2bits(char *str) { int i, bits = 0; int errflag = 0; char token[20]; while (sscanf(str, "%[^,| \t]", token) == 1) { str += strlen(token); while (isspace(*str) || *str==',' || *str=='|') str++; if (strcmp(token, "all") == 0) return(0xffffffff); if ((i = islevel(token)) == 0) { warnx("unknown token '%s'", token); errflag++; } else bits |= i; } if (errflag) exit(1); return(bits); } int getnum(char *str) { int x; char *acp = str; x = 0; while (*acp) { if (!isdigit(*acp)) errx(1, "%s is not a number", str); x *= 10; x += (*acp - '0'); acp++; } return(x); } void prlevels(int x) { struct lv *lvp; switch (x) { case 0: printf("(none)\n"); break; case 0xffffffff: printf("all\n"); break; default: for (lvp = lv; lvp->lv_name; lvp++) if (x & lvp->lv_bit) printf(" %s", lvp->lv_name); printf("\n"); } }