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.
37 static const char si_copyright1[] = "@(#) Copyright (C) Specialix International, 1990,1992,1998",
38 si_copyright2[] = "@(#) Copyright (C) Andy Rutter 1993",
39 si_copyright3[] = "@(#) Copyright (C) Peter Wemm 2000";
42 #include "opt_compat.h"
43 #include "opt_debug_si.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
48 #include <sys/ioctl_compat.h>
52 #include <sys/fcntl.h>
53 #include <sys/dkstat.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
56 #include <sys/sysctl.h>
58 #include <machine/bus.h>
60 #include <machine/resource.h>
66 #include <machine/stdarg.h>
68 #include <dev/si/sireg.h>
69 #include <dev/si/sivar.h>
70 #include <dev/si/si.h>
73 * This device driver is designed to interface the Specialix International
74 * SI, XIO and SX range of serial multiplexor cards to FreeBSD on an ISA,
75 * EISA or PCI bus machine.
77 * The controller is interfaced to the host via dual port RAM
80 * The code for the Host 1 (very old ISA cards) has not been tested.
83 #define POLL /* turn on poller to scan for lost interrupts */
84 #define REALPOLL /* on each poll, scan for work regardless */
85 #define POLLHZ (hz/10) /* 10 times per second */
86 #define SI_I_HIGH_WATER (TTYHOG - 2 * SI_BUFFERSIZE)
87 #define INT_COUNT 25000 /* max of 125 ints per second */
88 #define JET_INT_COUNT 100 /* max of 100 ints per second */
89 #define RXINT_COUNT 1 /* one rxint per 10 milliseconds */
91 enum si_mctl { GET, SET, BIS, BIC };
93 static void si_command(struct si_port *, int, int);
94 static int si_modem(struct si_port *, enum si_mctl, int);
95 static void si_write_enable(struct si_port *, int);
96 static int si_Sioctl(dev_t, u_long, caddr_t, int, struct thread *);
97 static void si_start(struct tty *);
98 static void si_stop(struct tty *, int);
99 static timeout_t si_lstart;
100 static void si_disc_optim(struct tty *tp, struct termios *t,struct si_port *pp);
101 static void sihardclose(struct si_port *pp);
102 static void sidtrwakeup(void *chan);
105 static char *si_mctl2str(enum si_mctl cmd);
108 static int siparam(struct tty *, struct termios *);
110 static void si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip);
111 static char * si_modulename(int host_type, int uart_type);
113 static d_open_t siopen;
114 static d_close_t siclose;
115 static d_write_t siwrite;
116 static d_ioctl_t siioctl;
118 #define CDEV_MAJOR 68
119 static struct cdevsw si_cdevsw = {
127 /* strategy */ nostrategy,
129 /* maj */ CDEV_MAJOR,
132 /* flags */ D_TTY | D_KQFILTER,
133 /* kqfilter */ ttykqfilter,
136 static int si_Nports;
137 static int si_Nmodules;
138 static int si_debug = 0; /* data, not bss, so it's patchable */
140 SYSCTL_INT(_machdep, OID_AUTO, si_debug, CTLFLAG_RW, &si_debug, 0, "");
141 TUNABLE_INT("machdep.si_debug", &si_debug);
143 static int si_numunits;
145 devclass_t si_devclass;
147 #ifndef B2000 /* not standard, but the hardware knows it. */
150 static struct speedtab bdrates[] = {
151 { B75, CLK75, }, /* 0x0 */
152 { B110, CLK110, }, /* 0x1 */
153 { B150, CLK150, }, /* 0x3 */
154 { B300, CLK300, }, /* 0x4 */
155 { B600, CLK600, }, /* 0x5 */
156 { B1200, CLK1200, }, /* 0x6 */
157 { B2000, CLK2000, }, /* 0x7 */
158 { B2400, CLK2400, }, /* 0x8 */
159 { B4800, CLK4800, }, /* 0x9 */
160 { B9600, CLK9600, }, /* 0xb */
161 { B19200, CLK19200, }, /* 0xc */
162 { B38400, CLK38400, }, /* 0x2 (out of order!) */
163 { B57600, CLK57600, }, /* 0xd */
164 { B115200, CLK110, }, /* 0x1 (dupe!, 110 baud on "si") */
169 /* populated with approx character/sec rates - translated at card
170 * initialisation time to chars per tick of the clock */
171 static int done_chartimes = 0;
172 static struct speedtab chartimes[] = {
189 static volatile int in_intr = 0; /* Inside interrupt handler? */
192 static int si_pollrate; /* in addition to irq */
193 static int si_realpoll = 0; /* poll HW on timer */
195 SYSCTL_INT(_machdep, OID_AUTO, si_pollrate, CTLFLAG_RW, &si_pollrate, 0, "");
196 SYSCTL_INT(_machdep, OID_AUTO, si_realpoll, CTLFLAG_RW, &si_realpoll, 0, "");
198 static int init_finished = 0;
199 static void si_poll(void *);
203 * Array of adapter types and the corresponding RAM size. The order of
204 * entries here MUST match the ordinal of the adapter type.
206 static char *si_type[] = {
209 "SIMCA", /* FreeBSD does not support Microchannel */
218 * We have to make an 8 bit version of bcopy, since some cards can't
219 * deal with 32 bit I/O
222 si_bcopy(const void *src, void *dst, size_t len)
225 *(((u_char *)dst)++) = *(((const u_char *)src)++);
228 si_vbcopy(const volatile void *src, void *dst, size_t len)
231 *(((u_char *)dst)++) = *(((const volatile u_char *)src)++);
234 si_bcopyv(const void *src, volatile void *dst, size_t len)
237 *(((volatile u_char *)dst)++) = *(((const u_char *)src)++);
242 * Attach the device. Initialize the card.
245 siattach(device_t dev)
250 volatile struct si_channel *ccbp;
251 volatile struct si_reg *regp;
252 volatile caddr_t maddr;
253 struct si_module *modp;
254 struct speedtab *spt;
255 int nmodule, nport, x, y;
258 sc = device_get_softc(dev);
259 unit = device_get_unit(dev);
261 sc->sc_typename = si_type[sc->sc_type];
262 if (si_numunits < unit + 1)
263 si_numunits = unit + 1;
265 DPRINT((0, DBG_AUTOBOOT, "si%d: siattach\n", unit));
268 if (si_pollrate == 0) {
269 si_pollrate = POLLHZ; /* in addition to irq */
271 si_realpoll = 1; /* scan always */
276 DPRINT((0, DBG_AUTOBOOT, "si%d: type: %s paddr: %x maddr: %x\n", unit,
277 sc->sc_typename, sc->sc_paddr, sc->sc_maddr));
279 sc->sc_ports = NULL; /* mark as uninitialised */
281 maddr = sc->sc_maddr;
283 /* Stop the CPU first so it won't stomp around while we load */
285 switch (sc->sc_type) {
287 outb(sc->sc_iobase + 2, sc->sc_irq << 4);
290 *(maddr+SIPCIRESET) = 0;
292 case SIJETPCI: /* fall through to JET ISA */
294 *(maddr+SIJETCONFIG) = 0;
297 *(maddr+SIPLRESET) = 0;
300 *(maddr+SIRESET) = 0;
302 default: /* this should never happen */
303 printf("si%d: unsupported configuration\n", unit);
308 /* OK, now lets download the download code */
310 if (SI_ISJET(sc->sc_type)) {
311 DPRINT((0, DBG_DOWNLOAD, "si%d: jet_download: nbytes %d\n",
312 unit, si3_t225_dsize));
313 si_bcopy(si3_t225_download, maddr + si3_t225_downloadaddr,
315 DPRINT((0, DBG_DOWNLOAD,
316 "si%d: jet_bootstrap: nbytes %d -> %x\n",
317 unit, si3_t225_bsize, si3_t225_bootloadaddr));
318 si_bcopy(si3_t225_bootstrap, maddr + si3_t225_bootloadaddr,
321 DPRINT((0, DBG_DOWNLOAD, "si%d: si_download: nbytes %d\n",
322 unit, si2_z280_dsize));
323 si_bcopy(si2_z280_download, maddr + si2_z280_downloadaddr,
327 /* Now start the CPU */
329 switch (sc->sc_type) {
331 /* modify the download code to tell it that it's on an EISA */
333 outb(sc->sc_iobase + 2, (sc->sc_irq << 4) | 4);
334 (void)inb(sc->sc_iobase + 3); /* reset interrupt */
337 /* modify the download code to tell it that it's on a PCI */
339 *(maddr+SIPCIRESET) = 1;
340 *(maddr+SIPCIINTCL) = 0;
343 *(maddr+SIJETRESET) = 0;
344 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN;
347 *(maddr+SIJETRESET) = 0;
348 switch (sc->sc_irq) {
350 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0x90;
353 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xa0;
356 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xb0;
359 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xc0;
362 *(maddr+SIJETCONFIG) = SIJETBUSEN|SIJETIRQEN|0xf0;
367 *(maddr+SIRESET_CL) = 0;
368 *(maddr+SIINTCL_CL) = 0;
371 *(maddr+SIPLRESET) = 0x10;
372 switch (sc->sc_irq) {
374 *(maddr+SIPLIRQ11) = 0x10;
377 *(maddr+SIPLIRQ12) = 0x10;
380 *(maddr+SIPLIRQ15) = 0x10;
383 *(maddr+SIPLIRQCLR) = 0x10;
385 default: /* this should _REALLY_ never happen */
386 printf("si%d: Uh, it was supported a second ago...\n", unit);
390 DELAY(1000000); /* wait around for a second */
392 regp = (struct si_reg *)maddr;
394 /* wait max of 5 sec for init OK */
395 while (regp->initstat == 0 && y++ < 10) {
398 switch (regp->initstat) {
400 printf("si%d: startup timeout - aborting\n", unit);
401 sc->sc_type = SIEMPTY;
404 if (SI_ISJET(sc->sc_type)) {
405 /* set throttle to 100 times per second */
406 regp->int_count = JET_INT_COUNT;
407 /* rx_intr_count is a NOP in Jet */
409 /* set throttle to 125 times per second */
410 regp->int_count = INT_COUNT;
411 /* rx intr max of 25 times per second */
412 regp->rx_int_count = RXINT_COUNT;
414 regp->int_pending = 0; /* no intr pending */
415 regp->int_scounter = 0; /* reset counter */
419 * No modules found, so give up on this one.
421 printf("si%d: %s - no ports found\n", unit,
422 si_type[sc->sc_type]);
425 printf("si%d: download code version error - initstat %x\n",
426 unit, regp->initstat);
431 * First time around the ports just count them in order
432 * to allocate some memory.
435 modp = (struct si_module *)(maddr + 0x80);
437 DPRINT((0, DBG_DOWNLOAD, "si%d: ccb addr 0x%x\n", unit, modp));
438 switch (modp->sm_type) {
440 DPRINT((0, DBG_DOWNLOAD,
441 "si%d: Found old TA4 module, 4 ports\n",
446 DPRINT((0, DBG_DOWNLOAD,
447 "si%d: Found old TA8 module, 8 ports\n",
452 DPRINT((0, DBG_DOWNLOAD,
453 "si%d: Found ASIC TA4 module, 4 ports\n",
458 DPRINT((0, DBG_DOWNLOAD,
459 "si%d: Found ASIC TA8 module, 8 ports\n",
464 DPRINT((0, DBG_DOWNLOAD,
465 "si%d: Found CD1400 module, 8 ports\n",
470 DPRINT((0, DBG_DOWNLOAD,
471 "si%d: Found SXDC module, 8 ports\n",
476 printf("si%d: unknown module type %d\n",
477 unit, modp->sm_type);
481 /* this was limited in firmware and is also a driver issue */
482 if ((nport + x) > SI_MAXPORTPERCARD) {
483 printf("si%d: extra ports ignored\n", unit);
492 if (modp->sm_next == 0)
494 modp = (struct si_module *)
495 (maddr + (unsigned)(modp->sm_next & 0x7fff));
497 sc->sc_ports = (struct si_port *)malloc(sizeof(struct si_port) * nport,
498 M_DEVBUF, M_NOWAIT | M_ZERO);
499 if (sc->sc_ports == 0) {
500 printf("si%d: fail to malloc memory for port structs\n",
504 sc->sc_nport = nport;
507 * Scan round the ports again, this time initialising.
511 modp = (struct si_module *)(maddr + 0x80);
512 uart_type = 1000; /* arbitary, > uchar_max */
514 switch (modp->sm_type) {
537 ccbp = (struct si_channel *)((char *)modp + 0x100);
538 if (uart_type == 1000)
539 uart_type = ccbp->type;
540 else if (uart_type != ccbp->type)
541 printf("si%d: Warning: module %d mismatch! (%d%s != %d%s)\n",
543 ccbp->type, si_modulename(sc->sc_type, ccbp->type),
544 uart_type, si_modulename(sc->sc_type, uart_type));
546 for (x = 0; x < nport; x++, pp++, ccbp++) {
547 pp->sp_ccb = ccbp; /* save the address */
548 pp->sp_tty = ttymalloc(NULL);
549 pp->sp_pend = IDLE_CLOSE;
550 pp->sp_state = 0; /* internal flag */
551 pp->sp_dtr_wait = 3 * hz;
552 pp->sp_iin.c_iflag = TTYDEF_IFLAG;
553 pp->sp_iin.c_oflag = TTYDEF_OFLAG;
554 pp->sp_iin.c_cflag = TTYDEF_CFLAG;
555 pp->sp_iin.c_lflag = TTYDEF_LFLAG;
556 termioschars(&pp->sp_iin);
557 pp->sp_iin.c_ispeed = pp->sp_iin.c_ospeed =
559 pp->sp_iout = pp->sp_iin;
562 if (modp->sm_next == 0) {
563 printf("si%d: card: %s, ports: %d, modules: %d, type: %d%s\n",
569 si_modulename(sc->sc_type, uart_type));
572 modp = (struct si_module *)
573 (maddr + (unsigned)(modp->sm_next & 0x7fff));
575 if (done_chartimes == 0) {
576 for (spt = chartimes ; spt->sp_speed != -1; spt++) {
577 if ((spt->sp_code /= hz) == 0)
583 /* path name devsw minor type uid gid perm*/
584 for (x = 0; x < sc->sc_nport; x++) {
585 /* sync with the manuals that start at 1 */
586 y = x + 1 + unit * (1 << SI_CARDSHIFT);
587 make_dev(&si_cdevsw, x, 0, 0, 0600, "ttyA%02d", y);
588 make_dev(&si_cdevsw, x + 0x00080, 0, 0, 0600, "cuaA%02d", y);
589 make_dev(&si_cdevsw, x + 0x10000, 0, 0, 0600, "ttyiA%02d", y);
590 make_dev(&si_cdevsw, x + 0x10080, 0, 0, 0600, "cuaiA%02d", y);
591 make_dev(&si_cdevsw, x + 0x20000, 0, 0, 0600, "ttylA%02d", y);
592 make_dev(&si_cdevsw, x + 0x20080, 0, 0, 0600, "cualA%02d", y);
594 make_dev(&si_cdevsw, 0x40000, 0, 0, 0600, "si_control");
599 siopen(dev_t dev, int flag, int mode, struct thread *td)
605 volatile struct si_channel *ccbp;
607 int mynor = minor(dev);
609 /* quickly let in /dev/si_control */
610 if (IS_CONTROLDEV(mynor)) {
611 if ((error = suser(td)))
616 card = SI_CARD(mynor);
617 sc = devclass_get_softc(si_devclass, card);
621 if (sc->sc_type == SIEMPTY) {
622 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: type %s??\n",
623 card, sc->sc_typename));
627 port = SI_PORT(mynor);
628 if (port >= sc->sc_nport) {
629 DPRINT((0, DBG_OPEN|DBG_FAIL, "si%d: nports %d\n",
630 card, sc->sc_nport));
636 * We've now got a device, so start the poller.
638 if (init_finished == 0) {
639 timeout(si_poll, (caddr_t)0L, si_pollrate);
644 /* initial/lock device */
645 if (IS_STATE(mynor)) {
649 pp = sc->sc_ports + port;
650 tp = pp->sp_tty; /* the "real" tty */
652 ccbp = pp->sp_ccb; /* Find control block */
653 DPRINT((pp, DBG_ENTRY|DBG_OPEN, "siopen(%s,%x,%x,%x)\n",
654 devtoname(dev), flag, mode, td));
656 oldspl = spltty(); /* Keep others out */
660 while (pp->sp_state & SS_DTR_OFF) {
661 error = tsleep(&pp->sp_dtr_wait, TTIPRI|PCATCH, "sidtr", 0);
666 if (tp->t_state & TS_ISOPEN) {
668 * The device is open, so everything has been initialised.
671 if (IS_CALLOUT(mynor)) {
672 if (!pp->sp_active_out) {
677 if (pp->sp_active_out) {
678 if (flag & O_NONBLOCK) {
682 error = tsleep(&pp->sp_active_out,
683 TTIPRI|PCATCH, "sibi", 0);
689 if (tp->t_state & TS_XCLUDE &&
691 DPRINT((pp, DBG_OPEN|DBG_FAIL,
692 "already open and EXCLUSIVE set\n"));
698 * The device isn't open, so there are no conflicts.
699 * Initialize it. Avoid sleep... :-)
701 DPRINT((pp, DBG_OPEN, "first open\n"));
702 tp->t_oproc = si_start;
703 tp->t_stop = si_stop;
704 tp->t_param = siparam;
706 tp->t_termios = mynor & SI_CALLOUT_MASK
707 ? pp->sp_iout : pp->sp_iin;
709 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
711 ++pp->sp_wopeners; /* in case of sleep in siparam */
713 error = siparam(tp, &tp->t_termios);
718 /* XXX: we should goto_top if siparam slept */
720 /* set initial DCD state */
721 pp->sp_last_hi_ip = ccbp->hi_ip;
722 if ((pp->sp_last_hi_ip & IP_DCD) || IS_CALLOUT(mynor)) {
723 (*linesw[tp->t_line].l_modem)(tp, 1);
727 /* whoops! we beat the close! */
728 if (pp->sp_state & SS_CLOSING) {
729 /* try and stop it from proceeding to bash the hardware */
730 pp->sp_state &= ~SS_CLOSING;
734 * Wait for DCD if necessary
736 if (!(tp->t_state & TS_CARR_ON) &&
737 !IS_CALLOUT(mynor) &&
738 !(tp->t_cflag & CLOCAL) &&
739 !(flag & O_NONBLOCK)) {
741 DPRINT((pp, DBG_OPEN, "sleeping for carrier\n"));
742 error = tsleep(TSA_CARR_ON(tp), TTIPRI|PCATCH, "sidcd", 0);
749 error = (*linesw[tp->t_line].l_open)(dev, tp);
750 si_disc_optim(tp, &tp->t_termios, pp);
751 if (tp->t_state & TS_ISOPEN && IS_CALLOUT(mynor))
752 pp->sp_active_out = TRUE;
754 pp->sp_state |= SS_OPEN; /* made it! */
759 DPRINT((pp, DBG_OPEN, "leaving siopen\n"));
761 if (!(tp->t_state & TS_ISOPEN) && pp->sp_wopeners == 0)
768 siclose(dev_t dev, int flag, int mode, struct thread *td)
774 int mynor = minor(dev);
776 if (IS_SPECIAL(mynor))
781 pp = MINOR2PP(mynor);
784 DPRINT((pp, DBG_ENTRY|DBG_CLOSE, "siclose(%s,%x,%x,%x) sp_state:%x\n",
785 devtoname(dev), flag, mode, td, pp->sp_state));
787 /* did we sleep and loose a race? */
788 if (pp->sp_state & SS_CLOSING) {
789 /* error = ESOMETING? */
793 /* begin race detection.. */
794 pp->sp_state |= SS_CLOSING;
796 si_write_enable(pp, 0); /* block writes for ttywait() */
798 /* THIS MAY SLEEP IN TTYWAIT!!! */
799 (*linesw[tp->t_line].l_close)(tp, flag);
801 si_write_enable(pp, 1);
803 /* did we sleep and somebody started another open? */
804 if (!(pp->sp_state & SS_CLOSING)) {
805 /* error = ESOMETING? */
808 /* ok. we are now still on the right track.. nuke the hardware */
810 if (pp->sp_state & SS_LSTART) {
811 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
812 pp->sp_state &= ~SS_LSTART;
815 si_stop(tp, FREAD | FWRITE);
819 pp->sp_state &= ~SS_OPEN;
822 DPRINT((pp, DBG_CLOSE|DBG_EXIT, "close done, returning\n"));
828 sihardclose(struct si_port *pp)
832 volatile struct si_channel *ccbp;
837 ccbp = pp->sp_ccb; /* Find control block */
838 if (tp->t_cflag & HUPCL ||
839 (!pp->sp_active_out &&
840 !(ccbp->hi_ip & IP_DCD) &&
841 !(pp->sp_iin.c_cflag && CLOCAL)) ||
842 !(tp->t_state & TS_ISOPEN)) {
844 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS);
845 (void) si_command(pp, FCLOSE, SI_NOWAIT);
847 if (pp->sp_dtr_wait != 0) {
848 timeout(sidtrwakeup, pp, pp->sp_dtr_wait);
849 pp->sp_state |= SS_DTR_OFF;
853 pp->sp_active_out = FALSE;
854 wakeup((caddr_t)&pp->sp_active_out);
855 wakeup(TSA_CARR_ON(tp));
862 * called at splsoftclock()...
865 sidtrwakeup(void *chan)
872 pp = (struct si_port *)chan;
873 pp->sp_state &= ~SS_DTR_OFF;
874 wakeup(&pp->sp_dtr_wait);
880 siwrite(dev_t dev, struct uio *uio, int flag)
885 int mynor = minor(dev);
888 if (IS_SPECIAL(mynor)) {
889 DPRINT((0, DBG_ENTRY|DBG_FAIL|DBG_WRITE, "siwrite(CONTROLDEV!!)\n"));
892 pp = MINOR2PP(mynor);
894 DPRINT((pp, DBG_WRITE, "siwrite(%s,%x,%x)\n", devtoname(dev), uio, flag));
898 * If writes are currently blocked, wait on the "real" tty
900 while (pp->sp_state & SS_BLOCKWRITE) {
901 pp->sp_state |= SS_WAITWRITE;
902 DPRINT((pp, DBG_WRITE, "in siwrite, wait for SS_BLOCKWRITE to clear\n"));
903 if ((error = ttysleep(tp, (caddr_t)pp, TTOPRI|PCATCH,
904 "siwrite", tp->t_timeout))) {
905 if (error == EWOULDBLOCK)
911 error = (*linesw[tp->t_line].l_write)(tp, uio, flag);
919 siioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
924 int mynor = minor(dev);
927 #if defined(COMPAT_43)
932 if (IS_SI_IOCTL(cmd))
933 return(si_Sioctl(dev, cmd, data, flag, td));
935 pp = MINOR2PP(mynor);
938 DPRINT((pp, DBG_ENTRY|DBG_IOCTL, "siioctl(%s,%lx,%x,%x)\n",
939 devtoname(dev), cmd, data, flag));
940 if (IS_STATE(mynor)) {
943 switch (mynor & SI_STATE_MASK) {
944 case SI_INIT_STATE_MASK:
945 ct = IS_CALLOUT(mynor) ? &pp->sp_iout : &pp->sp_iin;
947 case SI_LOCK_STATE_MASK:
948 ct = IS_CALLOUT(mynor) ? &pp->sp_lout : &pp->sp_lin;
958 *ct = *(struct termios *)data;
961 *(struct termios *)data = *ct;
964 *(int *)data = TTYDISC;
967 bzero(data, sizeof(struct winsize));
974 * Do the old-style ioctl compat routines...
976 #if defined(COMPAT_43)
977 term = tp->t_termios;
979 error = ttsetcompat(tp, &cmd, data, &term);
983 data = (caddr_t)&term;
986 * Do the initial / lock state business
988 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
990 struct termios *dt = (struct termios *)data;
991 struct termios *lt = mynor & SI_CALLOUT_MASK
992 ? &pp->sp_lout : &pp->sp_lin;
994 dt->c_iflag = (tp->t_iflag & lt->c_iflag) |
995 (dt->c_iflag & ~lt->c_iflag);
996 dt->c_oflag = (tp->t_oflag & lt->c_oflag) |
997 (dt->c_oflag & ~lt->c_oflag);
998 dt->c_cflag = (tp->t_cflag & lt->c_cflag) |
999 (dt->c_cflag & ~lt->c_cflag);
1000 dt->c_lflag = (tp->t_lflag & lt->c_lflag) |
1001 (dt->c_lflag & ~lt->c_lflag);
1002 for (cc = 0; cc < NCCS; ++cc)
1003 if (lt->c_cc[cc] != 0)
1004 dt->c_cc[cc] = tp->t_cc[cc];
1005 if (lt->c_ispeed != 0)
1006 dt->c_ispeed = tp->t_ispeed;
1007 if (lt->c_ospeed != 0)
1008 dt->c_ospeed = tp->t_ospeed;
1012 * Block user-level writes to give the ttywait()
1013 * a chance to completely drain for commands
1014 * that require the port to be in a quiescent state.
1023 blocked++; /* block writes for ttywait() and siparam() */
1024 si_write_enable(pp, 0);
1027 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1028 if (error != ENOIOCTL)
1033 error = ttioctl(tp, cmd, data, flag);
1034 si_disc_optim(tp, &tp->t_termios, pp);
1035 if (error != ENOIOCTL) {
1043 si_command(pp, SBREAK, SI_WAIT);
1046 si_command(pp, EBREAK, SI_WAIT);
1049 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
1052 (void) si_modem(pp, SET, 0);
1055 (void) si_modem(pp, SET, *(int *)data);
1058 (void) si_modem(pp, BIS, *(int *)data);
1061 (void) si_modem(pp, BIC, *(int *)data);
1064 *(int *)data = si_modem(pp, GET, 0);
1067 /* must be root since the wait applies to following logins */
1070 pp->sp_dtr_wait = *(int *)data * hz / 100;
1073 *(int *)data = pp->sp_dtr_wait * 100 / hz;
1081 DPRINT((pp, DBG_IOCTL|DBG_EXIT, "siioctl ret %d\n", error));
1083 si_write_enable(pp, 1);
1088 * Handle the Specialix ioctls. All MUST be called via the CONTROL device
1091 si_Sioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
1093 struct si_softc *xsc;
1094 struct si_port *xpp;
1095 volatile struct si_reg *regp;
1097 struct si_pstat *sps;
1101 int mynor = minor(dev);
1103 DPRINT((0, DBG_ENTRY|DBG_IOCTL, "si_Sioctl(%s,%lx,%x,%x)\n",
1104 devtoname(dev), cmd, data, flag));
1107 DPRINT((0, DBG_IOCTL, "TCSI_PORT=%x\n", TCSI_PORT));
1108 DPRINT((0, DBG_IOCTL, "TCSI_CCB=%x\n", TCSI_CCB));
1109 DPRINT((0, DBG_IOCTL, "TCSI_TTY=%x\n", TCSI_TTY));
1112 if (!IS_CONTROLDEV(mynor)) {
1113 DPRINT((0, DBG_IOCTL|DBG_FAIL, "not called from control device!\n"));
1117 oldspl = spltty(); /* better safe than sorry */
1121 #define SUCHECK if ((error = suser(td))) goto out
1139 * Check that a controller for this port exists
1142 /* may also be a struct si_pstat, a superset of si_tcsi */
1144 dp = (struct si_tcsi *)data;
1145 sps = (struct si_pstat *)data;
1147 xsc = devclass_get_softc(si_devclass, card); /* check.. */
1148 if (xsc == NULL || xsc->sc_type == SIEMPTY) {
1153 * And check that a port exists
1156 if (port < 0 || port >= xsc->sc_nport) {
1160 xpp = xsc->sc_ports + port;
1161 regp = (struct si_reg *)xsc->sc_maddr;
1171 xpp->sp_debug = DBG_ALL;
1172 DPRINT((xpp, DBG_IOCTL, "debug toggled %s\n",
1173 (xpp->sp_debug&DBG_ALL)?"ON":"OFF"));
1180 case TCSISDBG_LEVEL:
1181 case TCSIGDBG_LEVEL:
1183 if (cmd == TCSIGDBG_LEVEL) {
1184 dp->tc_dbglvl = xpp->sp_debug;
1187 xpp->sp_debug = dp->tc_dbglvl;
1195 dp->tc_int = regp->rx_int_count;
1199 regp->rx_int_count = dp->tc_int;
1202 dp->tc_int = regp->int_count;
1206 regp->int_count = dp->tc_int;
1209 dp->tc_int = xpp->sp_ccb->hi_ip;
1211 /* these next three use a different structure */
1214 si_bcopy(xpp, &sps->tc_siport, sizeof(sps->tc_siport));
1218 si_vbcopy(xpp->sp_ccb, &sps->tc_ccb, sizeof(sps->tc_ccb));
1222 si_bcopy(xpp->sp_tty, &sps->tc_tty, sizeof(sps->tc_tty));
1230 return(error); /* success */
1234 * siparam() : Configure line params
1235 * called at spltty();
1236 * this may sleep, does not flush, nor wait for drain, nor block writes
1237 * caller must arrange this if it's important..
1240 siparam(struct tty *tp, struct termios *t)
1242 struct si_port *pp = TP2PP(tp);
1243 volatile struct si_channel *ccbp;
1244 int oldspl, cflag, iflag, oflag, lflag;
1245 int error = 0; /* shutup gcc */
1246 int ispeed = 0; /* shutup gcc */
1247 int ospeed = 0; /* shutup gcc */
1250 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "siparam(%x,%x)\n", tp, t));
1255 DPRINT((pp, DBG_PARAM, "OFLAG 0x%x CFLAG 0x%x IFLAG 0x%x LFLAG 0x%x\n",
1256 oflag, cflag, iflag, lflag));
1258 /* XXX - if Jet host and SXDC module, use extended baud rates */
1260 /* if not hung up.. */
1261 if (t->c_ospeed != 0) {
1262 /* translate baud rate to firmware values */
1263 ospeed = ttspeedtab(t->c_ospeed, bdrates);
1264 ispeed = t->c_ispeed ?
1265 ttspeedtab(t->c_ispeed, bdrates) : ospeed;
1267 /* enforce legit baud rate */
1268 if (ospeed < 0 || ispeed < 0)
1276 /* ========== set hi_break ========== */
1278 if (iflag & IGNBRK) /* Breaks */
1280 if (iflag & BRKINT) /* Interrupt on break? */
1282 if (iflag & PARMRK) /* Parity mark? */
1284 if (iflag & IGNPAR) /* Ignore chars with parity errors? */
1286 ccbp->hi_break = val;
1288 /* ========== set hi_csr ========== */
1289 /* if not hung up.. */
1290 if (t->c_ospeed != 0) {
1291 /* Set I/O speeds */
1292 val = (ispeed << 4) | ospeed;
1296 /* ========== set hi_mr2 ========== */
1298 if (cflag & CSTOPB) /* Stop bits */
1303 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
1304 * a DCE, hence the reverse sense of RTS and CTS
1306 /* Output Flow - RTS must be raised before data can be sent */
1307 if (cflag & CCTS_OFLOW)
1312 /* ========== set hi_mr1 ========== */
1314 if (!(cflag & PARENB)) /* Parity */
1321 if ((cflag & CS8) == CS8) { /* 8 data bits? */
1323 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
1325 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
1327 } else { /* Must be 5 */
1331 * Enable H/W RTS/CTS handshaking. The default TA/MTA is
1332 * a DCE, hence the reverse sense of RTS and CTS
1334 /* Input Flow - CTS is raised when port is ready to receive data */
1335 if (cflag & CRTS_IFLOW)
1340 /* ========== set hi_mask ========== */
1342 if ((cflag & CS8) == CS8) { /* 8 data bits? */
1344 } else if ((cflag & CS7) == CS7) { /* 7 data bits? */
1346 } else if ((cflag & CS6) == CS6) { /* 6 data bits? */
1348 } else { /* Must be 5 */
1354 ccbp->hi_mask = val;
1356 /* ========== set hi_prtcl ========== */
1357 val = SP_DCEN; /* Monitor DCD always, or TIOCMGET misses it */
1367 ccbp->hi_prtcl = val;
1370 /* ========== set hi_{rx|tx}{on|off} ========== */
1371 /* XXX: the card TOTALLY shields us from the flow control... */
1372 ccbp->hi_txon = t->c_cc[VSTART];
1373 ccbp->hi_txoff = t->c_cc[VSTOP];
1375 ccbp->hi_rxon = t->c_cc[VSTART];
1376 ccbp->hi_rxoff = t->c_cc[VSTOP];
1378 /* ========== send settings to the card ========== */
1379 /* potential sleep here */
1380 if (ccbp->hi_stat == IDLE_CLOSE) /* Not yet open */
1381 si_command(pp, LOPEN, SI_WAIT); /* open it */
1383 si_command(pp, CONFIG, SI_WAIT); /* change params */
1385 /* ========== set DTR etc ========== */
1386 /* Hangup if ospeed == 0 */
1387 if (t->c_ospeed == 0) {
1388 (void) si_modem(pp, BIC, TIOCM_DTR|TIOCM_RTS);
1391 * If the previous speed was 0, may need to re-enable
1394 (void) si_modem(pp, SET, TIOCM_DTR|TIOCM_RTS);
1397 DPRINT((pp, DBG_PARAM, "siparam, complete: MR1 %x MR2 %x HI_MASK %x PRTCL %x HI_BREAK %x\n",
1398 ccbp->hi_mr1, ccbp->hi_mr2, ccbp->hi_mask, ccbp->hi_prtcl, ccbp->hi_break));
1405 * Enable or Disable the writes to this channel...
1406 * "state" -> enabled = 1; disabled = 0;
1409 si_write_enable(struct si_port *pp, int state)
1416 pp->sp_state &= ~SS_BLOCKWRITE;
1417 if (pp->sp_state & SS_WAITWRITE) {
1418 pp->sp_state &= ~SS_WAITWRITE;
1420 wakeup((caddr_t)pp);
1423 pp->sp_state |= SS_BLOCKWRITE;
1430 * Set/Get state of modem control lines.
1431 * Due to DCE-like behaviour of the adapter, some signals need translation:
1436 si_modem(struct si_port *pp, enum si_mctl cmd, int bits)
1438 volatile struct si_channel *ccbp;
1441 DPRINT((pp, DBG_ENTRY|DBG_MODEM, "si_modem(%x,%s,%x)\n", pp, si_mctl2str(cmd), bits));
1442 ccbp = pp->sp_ccb; /* Find channel address */
1447 if (x & IP_DCD) bits |= TIOCM_CAR;
1448 if (x & IP_DTR) bits |= TIOCM_DTR;
1449 if (x & IP_RTS) bits |= TIOCM_RTS;
1450 if (x & IP_RI) bits |= TIOCM_RI;
1453 ccbp->hi_op &= ~(OP_DSR|OP_CTS);
1457 if (bits & TIOCM_DTR)
1459 if (bits & TIOCM_RTS)
1464 if (bits & TIOCM_DTR)
1465 ccbp->hi_op &= ~OP_DSR;
1466 if (bits & TIOCM_RTS)
1467 ccbp->hi_op &= ~OP_CTS;
1473 * Handle change of modem state
1476 si_modem_state(struct si_port *pp, struct tty *tp, int hi_ip)
1478 /* if a modem dev */
1479 if (hi_ip & IP_DCD) {
1480 if (!(pp->sp_last_hi_ip & IP_DCD)) {
1481 DPRINT((pp, DBG_INTR, "modem carr on t_line %d\n",
1483 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
1486 if (pp->sp_last_hi_ip & IP_DCD) {
1487 DPRINT((pp, DBG_INTR, "modem carr off\n"));
1488 if ((*linesw[tp->t_line].l_modem)(tp, 0))
1489 (void) si_modem(pp, SET, 0);
1492 pp->sp_last_hi_ip = hi_ip;
1497 * Poller to catch missed interrupts.
1499 * Note that the SYSV Specialix drivers poll at 100 times per second to get
1500 * better response. We could really use a "periodic" version timeout(). :-)
1504 si_poll(void *nothing)
1506 struct si_softc *sc;
1508 volatile struct si_reg *regp;
1510 int lost, oldspl, port;
1512 DPRINT((0, DBG_POLL, "si_poll()\n"));
1517 for (i = 0; i < si_numunits; i++) {
1518 sc = devclass_get_softc(si_devclass, i);
1519 if (sc == NULL || sc->sc_type == SIEMPTY)
1521 regp = (struct si_reg *)sc->sc_maddr;
1524 * See if there has been a pending interrupt for 2 seconds
1525 * or so. The test (int_scounter >= 200) won't correspond
1526 * to 2 seconds if int_count gets changed.
1528 if (regp->int_pending != 0) {
1529 if (regp->int_scounter >= 200 &&
1530 regp->initstat == 1) {
1531 printf("si%d: lost intr\n", i);
1535 regp->int_scounter = 0;
1539 * gripe about no input flow control..
1542 for (port = 0; port < sc->sc_nport; pp++, port++) {
1543 if (pp->sp_delta_overflows > 0) {
1544 printf("si%d: %d tty level buffer overflows\n",
1545 i, pp->sp_delta_overflows);
1546 pp->sp_delta_overflows = 0;
1550 if (lost || si_realpoll)
1551 si_intr(NULL); /* call intr with fake vector */
1555 timeout(si_poll, (caddr_t)0L, si_pollrate);
1557 #endif /* ifdef POLL */
1560 * The interrupt handler polls ALL ports on ALL adapters each time
1564 static BYTE si_rxbuf[SI_BUFFERSIZE]; /* input staging area */
1565 static BYTE si_txbuf[SI_BUFFERSIZE]; /* output staging area */
1570 struct si_softc *sc;
1572 volatile struct si_channel *ccbp;
1574 volatile caddr_t maddr;
1576 int x, card, port, n, i, isopen;
1582 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "si_intr\n"));
1588 * When we get an int we poll all the channels and do ALL pending
1589 * work, not just the first one we find. This allows all cards to
1590 * share the same vector.
1592 * XXX - But if we're sharing the vector with something that's NOT
1593 * a SI/XIO/SX card, we may be making more work for ourselves.
1595 for (card = 0; card < si_numunits; card++) {
1596 sc = devclass_get_softc(si_devclass, card);
1597 if (sc == NULL || sc->sc_type == SIEMPTY)
1601 * First, clear the interrupt
1603 switch(sc->sc_type) {
1605 maddr = sc->sc_maddr;
1606 ((volatile struct si_reg *)maddr)->int_pending = 0;
1607 /* flag nothing pending */
1608 *(maddr+SIINTCL) = 0x00; /* Set IRQ clear */
1609 *(maddr+SIINTCL_CL) = 0x00; /* Clear IRQ clear */
1612 maddr = sc->sc_maddr;
1613 ((volatile struct si_reg *)maddr)->int_pending = 0;
1614 *(maddr+SIPLIRQCLR) = 0x00;
1615 *(maddr+SIPLIRQCLR) = 0x10;
1618 maddr = sc->sc_maddr;
1619 ((volatile struct si_reg *)maddr)->int_pending = 0;
1620 *(maddr+SIPCIINTCL) = 0x0;
1622 case SIJETPCI: /* fall through to JETISA case */
1624 maddr = sc->sc_maddr;
1625 ((volatile struct si_reg *)maddr)->int_pending = 0;
1626 *(maddr+SIJETINTCL) = 0x0;
1629 maddr = sc->sc_maddr;
1630 ((volatile struct si_reg *)maddr)->int_pending = 0;
1631 (void)inb(sc->sc_iobase + 3);
1637 ((volatile struct si_reg *)maddr)->int_scounter = 0;
1642 for (pp = sc->sc_ports, port = 0; port < sc->sc_nport;
1648 * See if a command has completed ?
1650 if (ccbp->hi_stat != pp->sp_pend) {
1651 DPRINT((pp, DBG_INTR,
1652 "si_intr hi_stat = 0x%x, pend = %d\n",
1653 ccbp->hi_stat, pp->sp_pend));
1654 switch(pp->sp_pend) {
1661 pp->sp_pend = ccbp->hi_stat;
1662 /* sleeping in si_command */
1663 wakeup(&pp->sp_state);
1666 pp->sp_pend = ccbp->hi_stat;
1671 * Continue on if it's closed
1673 if (ccbp->hi_stat == IDLE_CLOSE) {
1678 * Do modem state change if not a local device
1680 si_modem_state(pp, tp, ccbp->hi_ip);
1683 * Check to see if we should 'receive' characters.
1685 if (tp->t_state & TS_CONNECTED &&
1686 tp->t_state & TS_ISOPEN)
1692 * Do input break processing
1694 if (ccbp->hi_state & ST_BREAK) {
1696 (*linesw[tp->t_line].l_rint)(TTY_BI, tp);
1698 ccbp->hi_state &= ~ST_BREAK; /* A Bit iffy this */
1699 DPRINT((pp, DBG_INTR, "si_intr break\n"));
1703 * Do RX stuff - if not open then dump any characters.
1704 * XXX: This is VERY messy and needs to be cleaned up.
1706 * XXX: can we leave data in the host adapter buffer
1707 * when the clists are full? That may be dangerous
1708 * if the user cannot get an interrupt signal through.
1711 more_rx: /* XXX Sorry. the nesting was driving me bats! :-( */
1714 ccbp->hi_rxopos = ccbp->hi_rxipos;
1719 * If the tty input buffers are blocked, stop emptying
1720 * the incoming buffers and let the auto flow control
1723 if (tp->t_state & TS_TBLOCK) {
1728 * Process read characters if not skipped above
1730 op = ccbp->hi_rxopos;
1731 ip = ccbp->hi_rxipos;
1741 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1745 * Suck characters out of host card buffer into the
1746 * "input staging buffer" - so that we dont leave the
1747 * host card in limbo while we're possibly echoing
1748 * characters and possibly flushing input inside the
1749 * ldisc l_rint() routine.
1751 if (n <= SI_BUFFERSIZE - op) {
1753 DPRINT((pp, DBG_INTR, "\tsingle copy\n"));
1754 z = ccbp->hi_rxbuf + op;
1755 si_vbcopy(z, si_rxbuf, n);
1759 x = SI_BUFFERSIZE - op;
1761 DPRINT((pp, DBG_INTR, "\tdouble part 1 %d\n", x));
1762 z = ccbp->hi_rxbuf + op;
1763 si_vbcopy(z, si_rxbuf, x);
1765 DPRINT((pp, DBG_INTR, "\tdouble part 2 %d\n",
1768 si_vbcopy(z, si_rxbuf + x, n - x);
1773 /* clear collected characters from buffer */
1774 ccbp->hi_rxopos = op;
1776 DPRINT((pp, DBG_INTR, "n = %d, op = %d, ip = %d\n",
1781 * n = number of chars placed in si_rxbuf
1785 * Avoid the grotesquely inefficient lineswitch
1786 * routine (ttyinput) in "raw" mode. It usually
1787 * takes about 450 instructions (that's without
1788 * canonical processing or echo!). slinput is
1789 * reasonably fast (usually 40 instructions
1790 * plus call overhead).
1792 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1794 /* block if the driver supports it */
1795 if (tp->t_rawq.c_cc + n >= SI_I_HIGH_WATER &&
1796 (tp->t_cflag & CRTS_IFLOW ||
1797 tp->t_iflag & IXOFF) &&
1798 !(tp->t_state & TS_TBLOCK))
1805 pp->sp_delta_overflows +=
1806 b_to_q((char *)si_rxbuf, n, &tp->t_rawq);
1809 if (tp->t_state & TS_TTSTOP &&
1810 (tp->t_iflag & IXANY ||
1811 tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1812 tp->t_state &= ~TS_TTSTOP;
1813 tp->t_lflag &= ~FLUSHO;
1818 * It'd be nice to not have to go through the
1819 * function call overhead for each char here.
1820 * It'd be nice to block input it, saving a
1821 * loop here and the call/return overhead.
1823 for(x = 0; x < n; x++) {
1825 if ((*linesw[tp->t_line].l_rint)(i, tp)
1827 pp->sp_delta_overflows++;
1831 goto more_rx; /* try for more until RXbuf is empty */
1833 end_rx: /* XXX: Again, sorry about the gotos.. :-) */
1838 (*linesw[tp->t_line].l_start)(tp);
1840 } /* end of for (all ports on this controller) */
1841 } /* end of for (all controllers) */
1844 DPRINT((0, arg == NULL ? DBG_POLL:DBG_INTR, "end si_intr\n"));
1848 * Nudge the transmitter...
1850 * XXX: I inherited some funny code here. It implies the host card only
1851 * interrupts when the transmit buffer reaches the low-water-mark, and does
1852 * not interrupt when it's actually hits empty. In some cases, we have
1853 * processes waiting for complete drain, and we need to simulate an interrupt
1854 * about when we think the buffer is going to be empty (and retry if not).
1855 * I really am not certain about this... I *need* the hardware manuals.
1858 si_start(struct tty *tp)
1861 volatile struct si_channel *ccbp;
1865 int oldspl, count, n, amount, buffer_full;
1872 DPRINT((pp, DBG_ENTRY|DBG_START,
1873 "si_start(%x) t_state %x sp_state %x t_outq.c_cc %d\n",
1874 tp, tp->t_state, pp->sp_state, qp->c_cc));
1876 if (tp->t_state & (TS_TIMEOUT|TS_TTSTOP))
1882 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1883 DPRINT((pp, DBG_START, "count %d\n", (BYTE)count));
1885 while ((nchar = qp->c_cc) > 0) {
1886 if ((BYTE)count >= 255) {
1890 amount = min(nchar, (255 - (BYTE)count));
1891 ipos = (unsigned int)ccbp->hi_txipos;
1892 n = q_to_b(&tp->t_outq, si_txbuf, amount);
1893 /* will it fit in one lump? */
1894 if ((SI_BUFFERSIZE - ipos) >= n) {
1895 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos], n);
1897 si_bcopyv(si_txbuf, &ccbp->hi_txbuf[ipos],
1898 SI_BUFFERSIZE - ipos);
1899 si_bcopyv(si_txbuf + (SI_BUFFERSIZE - ipos),
1900 &ccbp->hi_txbuf[0], n - (SI_BUFFERSIZE - ipos));
1902 ccbp->hi_txipos += n;
1903 count = (int)ccbp->hi_txipos - (int)ccbp->hi_txopos;
1906 if (count != 0 && nchar == 0) {
1907 tp->t_state |= TS_BUSY;
1909 tp->t_state &= ~TS_BUSY;
1915 DPRINT((pp, DBG_START, "count %d, nchar %d, tp->t_state 0x%x\n",
1916 (BYTE)count, nchar, tp->t_state));
1918 if (tp->t_state & TS_BUSY)
1922 time = ttspeedtab(tp->t_ospeed, chartimes);
1926 time = nchar / time;
1930 DPRINT((pp, DBG_START,
1931 "bad char time value! %d\n", time));
1935 if ((pp->sp_state & (SS_LSTART|SS_INLSTART)) == SS_LSTART) {
1936 untimeout(si_lstart, (caddr_t)pp, pp->lstart_ch);
1938 pp->sp_state |= SS_LSTART;
1940 DPRINT((pp, DBG_START, "arming lstart, time=%d\n", time));
1941 pp->lstart_ch = timeout(si_lstart, (caddr_t)pp, time);
1946 DPRINT((pp, DBG_EXIT|DBG_START, "leave si_start()\n"));
1950 * Note: called at splsoftclock from the timeout code
1951 * This has to deal with two things... cause wakeups while waiting for
1952 * tty drains on last process exit, and call l_start at about the right
1953 * time for protocols like ppp.
1956 si_lstart(void *arg)
1958 struct si_port *pp = arg;
1962 DPRINT((pp, DBG_ENTRY|DBG_LSTART, "si_lstart(%x) sp_state %x\n",
1967 if ((pp->sp_state & SS_OPEN) == 0 || (pp->sp_state & SS_LSTART) == 0) {
1971 pp->sp_state &= ~SS_LSTART;
1972 pp->sp_state |= SS_INLSTART;
1976 /* deal with the process exit case */
1979 /* nudge protocols - eg: ppp */
1980 (*linesw[tp->t_line].l_start)(tp);
1982 pp->sp_state &= ~SS_INLSTART;
1987 * Stop output on a line. called at spltty();
1990 si_stop(struct tty *tp, int rw)
1992 volatile struct si_channel *ccbp;
1998 DPRINT((TP2PP(tp), DBG_ENTRY|DBG_STOP, "si_stop(%x,%x)\n", tp, rw));
2000 /* XXX: must check (rw & FWRITE | FREAD) etc flushing... */
2002 /* what level are we meant to be flushing anyway? */
2003 if (tp->t_state & TS_BUSY) {
2004 si_command(TP2PP(tp), WFLUSH, SI_NOWAIT);
2005 tp->t_state &= ~TS_BUSY;
2006 ttwwakeup(tp); /* Bruce???? */
2009 #if 1 /* XXX: this doesn't work right yet.. */
2010 /* XXX: this may have been failing because we used to call l_rint()
2011 * while we were looping based on these two counters. Now, we collect
2012 * the data and then loop stuffing it into l_rint(), making this
2013 * useless. Should we cause this to blow away the staging buffer?
2016 ccbp->hi_rxopos = ccbp->hi_rxipos;
2022 * Issue a command to the host card CPU.
2026 si_command(struct si_port *pp, int cmd, int waitflag)
2029 volatile struct si_channel *ccbp = pp->sp_ccb;
2032 DPRINT((pp, DBG_ENTRY|DBG_PARAM, "si_command(%x,%x,%d): hi_stat 0x%x\n",
2033 pp, cmd, waitflag, ccbp->hi_stat));
2035 oldspl = spltty(); /* Keep others out */
2037 /* wait until it's finished what it was doing.. */
2038 /* XXX: sits in IDLE_BREAK until something disturbs it or break
2040 while((x = ccbp->hi_stat) != IDLE_OPEN &&
2044 if (in_intr) { /* Prevent sleep in intr */
2045 DPRINT((pp, DBG_PARAM,
2046 "cmd intr collision - completing %d\trequested %d\n",
2050 } else if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH,
2056 /* it should now be in IDLE_{OPEN|CLOSE|BREAK}, or "cmd" */
2058 /* if there was a pending command, cause a state-change wakeup */
2059 switch(pp->sp_pend) {
2066 wakeup(&pp->sp_state);
2072 pp->sp_pend = cmd; /* New command pending */
2073 ccbp->hi_stat = cmd; /* Post it */
2076 if (in_intr) { /* If in interrupt handler */
2077 DPRINT((pp, DBG_PARAM,
2078 "attempt to sleep in si_intr - cmd req %d\n",
2082 } else while(ccbp->hi_stat != IDLE_OPEN &&
2083 ccbp->hi_stat != IDLE_BREAK) {
2084 if (ttysleep(pp->sp_tty, (caddr_t)&pp->sp_state, TTIPRI|PCATCH,
2093 si_disc_optim(struct tty *tp, struct termios *t, struct si_port *pp)
2096 * XXX can skip a lot more cases if Smarts. Maybe
2097 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2098 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2100 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON)) &&
2101 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
2102 (!(t->c_iflag & PARMRK) ||
2103 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
2104 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
2105 linesw[tp->t_line].l_rint == ttyinput)
2106 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2108 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2109 pp->sp_hotchar = linesw[tp->t_line].l_hotchar;
2110 DPRINT((pp, DBG_OPTIM, "bypass: %s, hotchar: %x\n",
2111 (tp->t_state & TS_CAN_BYPASS_L_RINT) ? "on" : "off",
2119 si_dprintf(struct si_port *pp, int flags, const char *fmt, ...)
2123 if ((pp == NULL && (si_debug&flags)) ||
2124 (pp != NULL && ((pp->sp_debug&flags) || (si_debug&flags)))) {
2126 printf("%ci%d(%d): ", 's',
2127 (int)SI_CARD(minor(pp->sp_tty->t_dev)),
2128 (int)SI_PORT(minor(pp->sp_tty->t_dev)));
2136 si_mctl2str(enum si_mctl cmd)
2154 si_modulename(int host_type, int uart_type)
2156 switch (host_type) {
2157 /* Z280 based cards */
2162 switch (uart_type) {
2169 /* T225 based hosts */
2172 switch (uart_type) {