4 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
5 * based on work by Slawa Olhovchenkov
6 * John Prince <johnp@knight-trosoft.com>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/sys/dev/digi/digi.c,v 1.36 2003/09/26 09:05:57 phk Exp $
36 * Figure out what the con bios stuff is supposed to do
37 * Test with *LOTS* more cards - I only have a PCI8r and an ISA Xem.
40 #include <sys/param.h>
41 #include <sys/systm.h>
45 #include <sys/linker.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/ttydefaults.h> /* for TTYDEF_* */
51 #include <sys/syslog.h>
52 #include <sys/fcntl.h>
54 #include <sys/thread2.h>
59 #include <dev/serial/digi/digiio.h>
60 #include <dev/serial/digi/digireg.h>
61 #include <dev/serial/digi/digi.h>
62 #include <dev/serial/digi/digi_pci.h>
63 #include <dev/serial/digi/digi_bios.h>
65 #define CTRL_DEV 0x800000
66 #define CALLOUT_MASK 0x400000
67 #define CONTROL_INIT_STATE 0x100000
68 #define CONTROL_LOCK_STATE 0x200000
69 #define CONTROL_MASK (CTRL_DEV|CONTROL_INIT_STATE|CONTROL_LOCK_STATE)
70 #define UNIT_MASK 0x030000
71 #define PORT_MASK 0x0000FF
72 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
73 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
74 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
75 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
77 static d_open_t digiopen;
78 static d_close_t digiclose;
79 static d_read_t digiread;
80 static d_write_t digiwrite;
81 static d_ioctl_t digiioctl;
83 static void digistop(struct tty *tp, int rw);
84 static int digimctl(struct digi_p *port, int bits, int how);
85 static void digi_poll(void *ptr);
86 static void digi_freedata(struct digi_softc *);
87 static void fepcmd(struct digi_p *port, int cmd, int op, int ncmds);
88 static void digistart(struct tty *tp);
89 static int digiparam(struct tty *tp, struct termios *t);
90 static void digihardclose(struct digi_p *port);
91 static void digi_intr(void *);
92 static int digi_init(struct digi_softc *_sc);
93 static int digi_loaddata(struct digi_softc *);
94 static int digi_inuse(struct digi_softc *);
95 static void digi_free_state(struct digi_softc *);
97 #define fepcmd_b(port, cmd, op1, op2, ncmds) \
98 fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
99 #define fepcmd_w fepcmd
102 static speed_t digidefaultrate = TTYDEF_SPEED;
105 struct con_bios *next;
110 static struct con_bios *con_bios_list;
111 devclass_t digi_devclass;
112 unsigned digi_debug = 0;
114 static struct speedtab digispeedtab[] = {
115 { 0, 0}, /* old (sysV-like) Bx codes */
131 { 57600, (02000 | 1)},
132 { 76800, (02000 | 2)},
133 { 115200, (02000 | 3)},
134 { 230400, (02000 | 6)},
138 const struct digi_control_signals digi_xixe_signals = {
139 0x02, 0x08, 0x10, 0x20, 0x40, 0x80
142 const struct digi_control_signals digi_normal_signals = {
143 0x02, 0x80, 0x20, 0x10, 0x40, 0x01
146 static struct dev_ops digi_ops = {
149 .d_close = digiclose,
151 .d_write = digiwrite,
152 .d_ioctl = digiioctl,
153 .d_kqfilter = ttykqfilter,
154 .d_revoke = ttyrevoke
160 struct digi_softc *sc;
162 sc = (struct digi_softc *)ptr;
163 callout_init_mp(&sc->callout);
165 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
169 digi_int_test(void *v)
171 struct digi_softc *sc = v;
173 callout_init_mp(&sc->inttest);
174 #ifdef DIGI_INTERRUPT
175 if (sc->intr_timestamp.tv_sec || sc->intr_timestamp.tv_usec) {
179 log(LOG_ERR, "digi%d: Interrupt didn't work, use polled mode\n", unit);
181 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
185 digi_freedata(struct digi_softc *sc)
187 if (sc->fep.data != NULL) {
188 kfree(sc->fep.data, M_TTYS);
191 if (sc->link.data != NULL) {
192 kfree(sc->link.data, M_TTYS);
193 sc->link.data = NULL;
195 if (sc->bios.data != NULL) {
196 kfree(sc->bios.data, M_TTYS);
197 sc->bios.data = NULL;
202 digi_bcopy(const void *vfrom, void *vto, size_t sz)
204 volatile const char *from = (volatile const char *)vfrom;
205 volatile char *to = (volatile char *)vto;
208 for (i = 0; i < sz; i++)
211 from = (const volatile char *)vfrom;
212 to = (volatile char *)vto;
213 for (i = 0; i < sz; i++)
214 if (*to++ != *from++)
220 digi_delay(struct digi_softc *sc, const char *txt, u_long timo)
223 DELAY(timo * 1000000 / hz);
225 tsleep(sc, PCATCH, txt, timo);
229 * NOTE: Must be called with tty_token held
232 digi_init(struct digi_softc *sc)
238 volatile struct board_chan *bc;
240 ASSERT_LWKT_TOKEN_HELD(&tty_token);
243 if (sc->status == DIGI_STATUS_DISABLED) {
244 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
248 if (sc->bios.data == NULL) {
249 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
254 if (sc->link.data == NULL && sc->model >= PCCX) {
255 log(LOG_ERR, "digi%d: Cannot init without link info\n",
260 if (sc->fep.data == NULL) {
261 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
265 sc->status = DIGI_STATUS_NOTINIT;
269 * We're re-initialising - maybe because someone's attached
270 * another port module. For now, we just re-initialise
279 ptr = sc->setwin(sc, MISCGLOBAL);
280 for (i = 0; i < 16; i += 2)
285 outb(sc->wport, 0xff); /* window 7 */
286 ptr = sc->vmem + (BIOSCODE & 0x1fff);
288 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
289 device_printf(sc->dev, "BIOS upload failed\n");
293 outb(sc->port, FEPCLR);
299 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
300 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
301 device_printf(sc->dev, "BIOS upload failed\n");
312 outb(sc->port, FEPRST | FEPMEM);
314 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
315 FEPMASK) != FEPRST; i++) {
317 log(LOG_ERR, "digi%d: %s init reset failed\n",
318 sc->res.unit, sc->name);
321 digi_delay(sc, "digiinit0", 5);
323 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
325 /* Now upload the BIOS */
326 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
327 sc->bios.size : sc->win_size - BIOSOFFSET;
329 ptr = sc->setwin(sc, BIOSOFFSET);
330 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
331 device_printf(sc->dev, "BIOS upload (1) failed\n");
335 if (cnt != sc->bios.size) {
336 /* and the second part */
337 ptr = sc->setwin(sc, sc->win_size);
338 if (!digi_bcopy(sc->bios.data + cnt, ptr,
339 sc->bios.size - cnt)) {
340 device_printf(sc->dev, "BIOS upload failed\n");
345 ptr = sc->setwin(sc, 0);
346 vW(ptr + 0) = 0x0401;
347 vW(ptr + 2) = 0x0bf0;
348 vW(ptr + 4) = 0x0000;
349 vW(ptr + 6) = 0x0000;
354 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
356 ptr = sc->setwin(sc, MISCGLOBAL);
362 } else if (sc->model == PCXEVE) {
363 outb(sc->port, FEPCLR);
366 outb(sc->port, FEPCLR | FEPMEM);
367 resp = FEPRST | FEPMEM;
370 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
373 log(LOG_ERR, "digi%d: BIOS start failed\n",
377 digi_delay(sc, "digibios0", 5);
380 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
382 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
384 log(LOG_ERR, "digi%d: BIOS boot failed "
385 "(0x%02x != 0x%02x)\n",
386 sc->res.unit, vW(ptr), *(u_short *)"GD");
389 digi_delay(sc, "digibios1", 5);
392 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
394 if (sc->link.data != NULL) {
395 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
396 ptr = sc->setwin(sc, 0xcd0);
397 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
406 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
407 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
409 /* A BIOS request to move our data to 0x2000 */
410 ptr = sc->setwin(sc, MBOX);
412 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
414 vW(ptr + 6) = FEPCODESEG;
416 vW(ptr + 10) = sc->fep.size;
418 /* Run the BIOS request */
419 outb(sc->port, FEPREQ | FEPMEM);
420 outb(sc->port, FEPCLR | FEPMEM);
422 for (i = 0; W(ptr); i++) {
424 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
429 digi_delay(sc, "digifep0", 5);
432 (sc->dev, "FEP/OS moved after %d iterations\n", i));
434 /* Clear the confirm word */
435 ptr = sc->setwin(sc, FEPSTAT);
438 /* A BIOS request to execute the FEP/OS */
439 ptr = sc->setwin(sc, MBOX);
441 vW(ptr + 2) = FEPCODESEG;
444 /* Run the BIOS request */
445 outb(sc->port, FEPREQ);
446 outb(sc->port, FEPCLR);
448 ptr = sc->setwin(sc, FEPSTAT);
455 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
457 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
458 sc->fep.size : sc->win_size - BIOSOFFSET;
460 ptr = sc->setwin(sc, BIOSOFFSET);
461 digi_bcopy(sc->fep.data, ptr, cnt);
463 if (cnt != sc->fep.size) {
464 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
465 digi_bcopy(sc->fep.data + cnt, ptr,
469 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
471 ptr = sc->setwin(sc, 0xc30);
477 /* Clear the confirm word */
478 ptr = sc->setwin(sc, FEPSTAT);
482 outb(sc->port, 0); /* XXX necessary ? */
487 ptr = sc->setwin(sc, 0xd000);
488 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
490 /* A BIOS request to execute the FEP/OS */
491 ptr = sc->setwin(sc, 0xc40);
493 W(ptr + 2) = FEPCODE >> 4;
496 /* Clear the confirm word */
497 ptr = sc->setwin(sc, FEPSTAT);
500 /* Run the BIOS request */
501 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
502 outb(sc->port, FEPCLR | FEPMEM);
506 /* Now wait 'till the FEP/OS has booted */
507 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
509 log(LOG_ERR, "digi%d: FEP/OS start failed "
510 "(0x%02x != 0x%02x)\n",
511 sc->res.unit, vW(ptr), *(u_short *)"OS");
515 digi_delay(sc, "digifep1", 5);
518 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
520 if (sc->model >= PCXEM) {
521 ptr = sc->setwin(sc, 0xe04);
523 ptr = sc->setwin(sc, 0xc02);
524 sc->numports = vW(ptr);
526 ptr = sc->setwin(sc, 0xc22);
527 sc->numports = vW(ptr);
530 if (sc->numports == 0) {
531 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
536 if (sc->numports > 256) {
537 /* Our minor numbering scheme is broken for more than 256 */
538 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
539 sc->name, sc->numports);
542 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
546 kfree(sc->ports, M_TTYS);
547 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
548 M_TTYS, M_WAITOK | M_ZERO);
551 kfree(sc->ttys, M_TTYS);
552 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
553 M_TTYS, M_WAITOK | M_ZERO);
556 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
557 * port. If the value is 0, the port is broken....
560 ptr = sc->setwin(sc, 0);
562 /* We should now init per-port structures */
563 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
564 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
566 sc->memcmd = ptr + sc->gdata->cstart;
567 sc->memevent = ptr + sc->gdata->istart;
569 for (i = 0; i < sc->numports; i++, bc++) {
570 port = sc->ports + i;
573 port->status = ENABLED;
574 port->tp = sc->ttys + i;
577 if (sc->model == PCXEVE) {
579 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
581 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
582 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
583 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
584 } else if (sc->model == PCXI || sc->model == PCXE) {
585 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
586 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
587 port->txwin = port->rxwin = 0;
590 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
592 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
593 port->txwin = FEPWIN |
594 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
595 port->rxwin = FEPWIN |
596 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
598 port->txbufsize = bc->tmax + 1;
599 port->rxbufsize = bc->rmax + 1;
601 lowwater = port->txbufsize >> 2;
605 fepcmd_w(port, STXLWATER, lowwater, 10);
606 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
607 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
610 port->dtr_wait = 3 * hz;
613 * We don't use all the flags from <sys/ttydefaults.h> since
614 * they are only relevant for logins. It's important to have
615 * echo off initially so that the line doesn't start blathering
616 * before the echo flag can be turned off.
618 port->it_in.c_iflag = 0;
619 port->it_in.c_oflag = 0;
620 port->it_in.c_cflag = TTYDEF_CFLAG;
621 port->it_in.c_lflag = 0;
622 termioschars(&port->it_in);
623 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
624 port->it_out = port->it_in;
625 port->send_ring = 1; /* Default action on signal RI */
627 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
628 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
629 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
630 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
631 0600, "ttyiD%d.%d", sc->res.unit, i);
632 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
633 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
634 0600, "ttylD%d.%d", sc->res.unit, i);
635 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
636 CALLOUT_MASK, UID_UUCP, GID_DIALER,
637 0660, "cuaD%d.%d", sc->res.unit, i);
638 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
639 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
640 0660, "cuaiD%d.%d", sc->res.unit, i);
641 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
642 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
643 0660, "cualD%d.%d", sc->res.unit, i);
647 callout_reset(&sc->inttest, hz, digi_int_test, sc);
648 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
649 sc->status = DIGI_STATUS_ENABLED;
655 * NOTE: Must be called with tty_token held
658 digimctl(struct digi_p *port, int bits, int how)
662 ASSERT_LWKT_TOKEN_HELD(&tty_token);
664 port->sc->setwin(port->sc, 0);
665 mstat = port->bc->mstat;
666 port->sc->hidewin(port->sc);
668 if (mstat & port->sc->csigs->rts)
670 if (mstat & port->cd)
672 if (mstat & port->dsr)
674 if (mstat & port->sc->csigs->cts)
676 if (mstat & port->sc->csigs->ri)
678 if (mstat & port->sc->csigs->dtr)
683 /* Only DTR and RTS may be set */
685 if (bits & TIOCM_DTR)
686 mstat |= port->sc->csigs->dtr;
687 if (bits & TIOCM_RTS)
688 mstat |= port->sc->csigs->rts;
692 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
695 fepcmd_b(port, SETMODEM, mstat, 0, 0);
698 fepcmd_b(port, SETMODEM, 0, mstat, 0);
706 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
708 lwkt_gettoken(&tty_token);
709 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
710 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
711 (!(t->c_iflag & PARMRK) ||
712 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
713 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
714 linesw[tp->t_line].l_rint == ttyinput)
715 tp->t_state |= TS_CAN_BYPASS_L_RINT;
717 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
718 lwkt_reltoken(&tty_token);
722 digiopen(struct dev_open_args *ap)
724 cdev_t dev = ap->a_head.a_dev;
725 struct digi_softc *sc;
731 volatile struct board_chan *bc;
735 unit = MINOR_TO_UNIT(minor(dev));
736 pnum = MINOR_TO_PORT(minor(dev));
738 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
742 lwkt_gettoken(&tty_token);
743 if (sc->status != DIGI_STATUS_ENABLED) {
744 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
745 lwkt_reltoken(&tty_token);
748 if (pnum >= sc->numports) {
749 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
750 lwkt_reltoken(&tty_token);
753 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
755 lwkt_reltoken(&tty_token);
758 port = &sc->ports[pnum];
759 tp = dev->si_tty = port->tp;
765 while (port->status & DIGI_DTR_OFF) {
767 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
773 if (tp->t_state & TS_ISOPEN) {
775 * The device is open, so everything has been initialized.
778 if (mynor & CALLOUT_MASK) {
779 if (!port->active_out) {
781 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
782 " BUSY error = %d\n", pnum, error));
785 } else if (port->active_out) {
786 if (ap->a_oflags & O_NONBLOCK) {
788 DLOG(DIGIDB_OPEN, (sc->dev,
789 "port %d: BUSY error = %d\n", pnum, error));
793 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
796 DLOG(DIGIDB_OPEN, (sc->dev,
797 "port %d: tsleep(digibi) error = %d\n",
803 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0) != 0) {
809 * The device isn't open, so there are no conflicts.
810 * Initialize it. Initialization is done twice in many
811 * cases: to preempt sleeping callin opens if we are callout,
812 * and to complete a callin open after DCD rises.
814 callout_init_mp(&port->wakeupco);
815 tp->t_oproc = digistart;
816 tp->t_param = digiparam;
817 tp->t_stop = digistop;
819 tp->t_termios = (mynor & CALLOUT_MASK) ?
820 port->it_out : port->it_in;
823 bc->rout = bc->rin; /* clear input queue */
827 bc->mint = port->cd | port->sc->csigs->ri;
830 port->cd = sc->csigs->dsr;
831 port->dsr = sc->csigs->cd;
833 port->cd = sc->csigs->cd;
834 port->dsr = sc->csigs->dsr;
836 port->wopeners++; /* XXX required ? */
837 error = digiparam(tp, &tp->t_termios);
841 DLOG(DIGIDB_OPEN, (sc->dev,
842 "port %d: cxpparam error = %d\n", pnum, error));
847 /* handle fake and initial DCD for callout devices */
849 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
850 linesw[tp->t_line].l_modem(tp, 1);
853 /* Wait for DCD if necessary */
854 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
855 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
857 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
860 DLOG(DIGIDB_OPEN, (sc->dev,
861 "port %d: tsleep(digidcd) error = %d\n",
867 error = linesw[tp->t_line].l_open(dev, tp);
868 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
871 digi_disc_optim(tp, &tp->t_termios, port);
873 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
874 port->active_out = TRUE;
876 if (tp->t_state & TS_ISOPEN)
881 if (!(tp->t_state & TS_ISOPEN))
884 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
887 lwkt_reltoken(&tty_token);
892 digiclose(struct dev_close_args *ap)
894 cdev_t dev = ap->a_head.a_dev;
898 struct digi_softc *sc;
901 lwkt_gettoken(&tty_token);
903 unit = MINOR_TO_UNIT(mynor);
904 pnum = MINOR_TO_PORT(mynor);
906 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
907 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
909 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
911 lwkt_reltoken(&tty_token);
915 port = sc->ports + pnum;
918 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
921 linesw[tp->t_line].l_close(tp, ap->a_fflag);
922 digi_disc_optim(tp, &tp->t_termios, port);
923 digistop(tp, FREAD | FWRITE);
928 lwkt_reltoken(&tty_token);
933 digidtrwakeup(void *chan)
935 struct digi_p *port = chan;
937 lwkt_gettoken(&tty_token);
938 port->status &= ~DIGI_DTR_OFF;
939 wakeup(&port->dtr_wait);
941 lwkt_reltoken(&tty_token);
945 * NOTE: Must be called with tty_token held
948 digihardclose(struct digi_p *port)
950 volatile struct board_chan *bc;
952 ASSERT_LWKT_TOKEN_HELD(&tty_token);
956 port->sc->setwin(port->sc, 0);
961 if ((port->tp->t_cflag & HUPCL) ||
962 (!port->active_out && !(bc->mstat & port->cd) &&
963 !(port->it_in.c_cflag & CLOCAL)) ||
964 !(port->tp->t_state & TS_ISOPEN)) {
965 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
966 if (port->dtr_wait != 0) {
967 /* Schedule a wakeup of any callin devices */
969 callout_reset(&port->wakeupco, port->dtr_wait,
970 digidtrwakeup, port);
971 port->status |= DIGI_DTR_OFF;
974 port->active_out = FALSE;
975 wakeup(&port->active_out);
976 wakeup(TSA_CARR_ON(port->tp));
981 digiread(struct dev_read_args *ap)
983 cdev_t dev = ap->a_head.a_dev;
986 int error, unit, pnum;
987 struct digi_softc *sc;
990 if (mynor & CONTROL_MASK)
993 lwkt_gettoken(&tty_token);
994 unit = MINOR_TO_UNIT(mynor);
995 pnum = MINOR_TO_PORT(mynor);
997 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
998 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
999 tp = &sc->ttys[pnum];
1001 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
1002 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
1005 lwkt_reltoken(&tty_token);
1010 digiwrite(struct dev_write_args *ap)
1012 cdev_t dev = ap->a_head.a_dev;
1015 int error, unit, pnum;
1016 struct digi_softc *sc;
1019 if (mynor & CONTROL_MASK)
1022 lwkt_gettoken(&tty_token);
1023 unit = MINOR_TO_UNIT(mynor);
1024 pnum = MINOR_TO_PORT(mynor);
1026 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1027 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
1028 tp = &sc->ttys[pnum];
1030 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1031 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1034 lwkt_reltoken(&tty_token);
1039 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1041 * Populate sc->bios, sc->fep, and sc->link from this data.
1043 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1044 * to their respective sizes.
1046 * The module is unloaded when we're done.
1049 digi_loaddata(struct digi_softc *sc)
1051 struct digi_bios *bios;
1053 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1054 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1055 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1056 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1058 for (bios = digi_bioses; bios->model != NULL; bios++) {
1059 if (!strcmp(bios->model, sc->module))
1062 if (bios->model == NULL) {
1063 kprintf("digi.ko: driver %s not found", sc->module);
1067 sc->bios.size = bios->bios_size;
1068 if (sc->bios.size != 0 && bios->bios != NULL) {
1069 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1070 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1073 sc->fep.size = bios->fep_size;
1074 if (sc->fep.size != 0 && bios->fep != NULL) {
1075 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1076 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1083 digiioctl(struct dev_ioctl_args *ap)
1085 cdev_t dev = ap->a_head.a_dev;
1086 u_long cmd = ap->a_cmd;
1087 caddr_t data = ap->a_data;
1088 int unit, pnum, mynor, error, ret;
1089 struct digi_softc *sc;
1090 struct digi_p *port;
1094 unit = MINOR_TO_UNIT(mynor);
1095 pnum = MINOR_TO_PORT(mynor);
1097 lwkt_gettoken(&tty_token);
1098 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1099 KASSERT(sc, ("digi%d: softc not allocated in digiioctl", unit));
1101 if (sc->status == DIGI_STATUS_DISABLED) {
1102 lwkt_reltoken(&tty_token);
1106 if (mynor & CTRL_DEV) {
1110 digi_debug = *(int *)data;
1111 lwkt_reltoken(&tty_token);
1114 device_printf(sc->dev, "DEBUG not defined\n");
1115 lwkt_reltoken(&tty_token);
1120 error = digi_init(sc);
1122 lwkt_reltoken(&tty_token);
1126 *(enum digi_model *)data = sc->model;
1127 lwkt_reltoken(&tty_token);
1131 ret = copyout(sc->name, *(char **)data,
1132 strlen(sc->name) + 1);
1133 lwkt_reltoken(&tty_token);
1138 if (pnum >= sc->numports) {
1139 lwkt_reltoken(&tty_token);
1143 port = sc->ports + pnum;
1144 if (!(port->status & ENABLED)) {
1145 lwkt_reltoken(&tty_token);
1151 if (mynor & CONTROL_MASK) {
1154 switch (mynor & CONTROL_MASK) {
1155 case CONTROL_INIT_STATE:
1156 ct = (mynor & CALLOUT_MASK) ?
1157 &port->it_out : &port->it_in;
1159 case CONTROL_LOCK_STATE:
1160 ct = (mynor & CALLOUT_MASK) ?
1161 &port->lt_out : &port->lt_in;
1164 lwkt_reltoken(&tty_token);
1165 return (ENODEV); /* /dev/nodev */
1170 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1172 lwkt_reltoken(&tty_token);
1175 *ct = *(struct termios *)data;
1176 lwkt_reltoken(&tty_token);
1180 *(struct termios *)data = *ct;
1181 lwkt_reltoken(&tty_token);
1185 *(int *)data = TTYDISC;
1186 lwkt_reltoken(&tty_token);
1190 bzero(data, sizeof(struct winsize));
1191 lwkt_reltoken(&tty_token);
1194 case DIGIIO_GETALTPIN:
1195 switch (mynor & CONTROL_MASK) {
1196 case CONTROL_INIT_STATE:
1197 *(int *)data = port->ialtpin;
1200 case CONTROL_LOCK_STATE:
1201 *(int *)data = port->laltpin;
1205 panic("Confusion when re-testing minor");
1206 lwkt_reltoken(&tty_token);
1209 lwkt_reltoken(&tty_token);
1212 case DIGIIO_SETALTPIN:
1213 switch (mynor & CONTROL_MASK) {
1214 case CONTROL_INIT_STATE:
1215 if (!port->laltpin) {
1216 port->ialtpin = !!*(int *)data;
1217 DLOG(DIGIDB_SET, (sc->dev,
1218 "port%d: initial ALTPIN %s\n", pnum,
1219 port->ialtpin ? "set" : "cleared"));
1223 case CONTROL_LOCK_STATE:
1224 port->laltpin = !!*(int *)data;
1225 DLOG(DIGIDB_SET, (sc->dev,
1226 "port%d: ALTPIN %slocked\n",
1227 pnum, port->laltpin ? "" : "un"));
1231 panic("Confusion when re-testing minor");
1232 lwkt_reltoken(&tty_token);
1235 lwkt_reltoken(&tty_token);
1239 lwkt_reltoken(&tty_token);
1245 case DIGIIO_GETALTPIN:
1246 *(int *)data = !!(port->dsr == sc->csigs->cd);
1247 lwkt_reltoken(&tty_token);
1250 case DIGIIO_SETALTPIN:
1251 if (!port->laltpin) {
1253 DLOG(DIGIDB_SET, (sc->dev,
1254 "port%d: ALTPIN set\n", pnum));
1255 port->cd = sc->csigs->dsr;
1256 port->dsr = sc->csigs->cd;
1258 DLOG(DIGIDB_SET, (sc->dev,
1259 "port%d: ALTPIN cleared\n", pnum));
1260 port->cd = sc->csigs->cd;
1261 port->dsr = sc->csigs->dsr;
1264 lwkt_reltoken(&tty_token);
1269 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1274 dt = (struct termios *)data;
1275 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1278 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1280 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1282 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1284 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1285 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1286 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1287 for (cc = 0; cc < NCCS; ++cc)
1288 if (lt->c_cc[cc] != 0)
1289 dt->c_cc[cc] = tp->t_cc[cc];
1290 if (lt->c_ispeed != 0)
1291 dt->c_ispeed = tp->t_ispeed;
1292 if (lt->c_ospeed != 0)
1293 dt->c_ospeed = tp->t_ospeed;
1295 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1296 ap->a_fflag, ap->a_cred);
1297 if (error == 0 && cmd == TIOCGETA)
1298 ((struct termios *)data)->c_iflag |= port->c_iflag;
1300 if (error >= 0 && error != ENOIOCTL) {
1301 lwkt_reltoken(&tty_token);
1305 error = ttioctl(tp, cmd, data, ap->a_fflag);
1306 if (error == 0 && cmd == TIOCGETA)
1307 ((struct termios *)data)->c_iflag |= port->c_iflag;
1309 digi_disc_optim(tp, &tp->t_termios, port);
1310 if (error >= 0 && error != ENOIOCTL) {
1312 lwkt_reltoken(&tty_token);
1318 port->send_ring = *(u_char *)data;
1322 * now it sends 400 millisecond break because I don't know
1323 * how to send an infinite break
1325 fepcmd_w(port, SENDBREAK, 400, 10);
1328 /* now it's empty */
1331 digimctl(port, TIOCM_DTR, DMBIS);
1334 digimctl(port, TIOCM_DTR, DMBIC);
1337 digimctl(port, *(int *)data, DMSET);
1340 digimctl(port, *(int *)data, DMBIS);
1343 digimctl(port, *(int *)data, DMBIC);
1346 *(int *)data = digimctl(port, 0, DMGET);
1349 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1352 lwkt_reltoken(&tty_token);
1355 port->dtr_wait = *(int *)data *hz / 100;
1359 *(int *)data = port->dtr_wait * 100 / hz;
1361 #ifdef DIGI_INTERRUPT
1363 *(struct timeval *)data = sc->intr_timestamp;
1369 lwkt_reltoken(&tty_token);
1373 lwkt_reltoken(&tty_token);
1378 digiparam(struct tty *tp, struct termios *t)
1383 struct digi_softc *sc;
1384 struct digi_p *port;
1390 lwkt_gettoken(&tty_token);
1391 mynor = minor(tp->t_dev);
1392 unit = MINOR_TO_UNIT(mynor);
1393 pnum = MINOR_TO_PORT(mynor);
1395 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1396 KASSERT(sc, ("digi%d: softc not allocated in digiparam", unit));
1398 port = &sc->ports[pnum];
1400 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1402 if (t->c_ispeed == 0)
1403 t->c_ispeed = t->c_ospeed;
1405 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1407 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed)) {
1408 lwkt_reltoken(&tty_token);
1414 window = sc->window;
1417 if (cflag == 0) { /* hangup */
1418 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1419 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1421 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1423 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1427 /* convert flags to sysV-style values */
1428 if (t->c_cflag & PARODD)
1430 if (t->c_cflag & PARENB)
1432 if (t->c_cflag & CSTOPB)
1435 /* convert flags to sysV-style values */
1436 if (t->c_cflag & PARODD)
1437 cflag |= FEP_PARODD;
1438 if (t->c_cflag & PARENB)
1439 cflag |= FEP_PARENB;
1440 if (t->c_cflag & CSTOPB)
1441 cflag |= FEP_CSTOPB;
1442 if (t->c_cflag & CLOCAL)
1443 cflag |= FEP_CLOCAL;
1446 cflag |= (t->c_cflag & CSIZE) >> 4;
1447 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1449 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1453 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1454 if (port->c_iflag & IXON)
1456 if (port->c_iflag & IXANY)
1458 if (port->c_iflag & IXOFF)
1461 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1462 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1465 if (t->c_cflag & CDTR_IFLOW)
1466 hflow |= sc->csigs->dtr;
1467 if (t->c_cflag & CRTS_IFLOW)
1468 hflow |= sc->csigs->rts;
1469 if (t->c_cflag & CCTS_OFLOW)
1470 hflow |= sc->csigs->cts;
1471 if (t->c_cflag & CDSR_OFLOW)
1473 if (t->c_cflag & CCAR_OFLOW)
1476 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1477 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1479 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1480 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1481 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1483 if (sc->window != 0)
1486 sc->towin(sc, window);
1489 lwkt_reltoken(&tty_token);
1496 struct digi_p *port;
1498 struct digi_softc *sc;
1500 volatile struct board_chan *bc;
1512 lwkt_gettoken(&tty_token);
1515 if (sc->status != DIGI_STATUS_ENABLED) {
1516 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1517 lwkt_reltoken(&tty_token);
1521 #ifdef DIGI_INTERRUPT
1522 microtime(&sc->intr_timestamp);
1525 window = sc->window;
1528 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1529 struct con_bios *con = con_bios_list;
1532 ptr = sc->vmem + W(sc->vmem + 0xd00);
1534 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1535 /* Not first block -- exact match */
1538 if (W(ptr + 4) >= W(con->bios + 4) &&
1539 W(ptr + 4) <= W(con->bios + 6))
1540 /* Initial search concetrator BIOS */
1545 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1546 " not found!\n", sc->res.unit, W(ptr + 4));
1548 W(sc->vmem + 0xd00) = 0;
1552 W(ptr + 4) = W(cxcon + 4);
1553 W(ptr + 6) = W(cxcon + 6);
1555 W(ptr + 2) = W(cxcon + 2);
1556 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1557 size = W(cxcon + 10) - (ptr[1] << 10);
1559 W(ptr + 8) = W(cxcon + 8);
1565 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1567 W(sc->vmem + 0xd00) = 0;
1571 ehead = sc->gdata->ein;
1572 etail = sc->gdata->eout;
1573 if (ehead == etail) {
1576 if (sc->intr_count % 6000 == 0) {
1577 DLOG(DIGIDB_IRQ, (sc->dev,
1578 "6000 useless polls %x %x\n", ehead, etail));
1584 while (ehead != etail) {
1585 event = *(volatile struct event *)(sc->memevent + etail);
1587 etail = (etail + 4) & sc->gdata->imax;
1589 if (event.pnum >= sc->numports) {
1590 log(LOG_ERR, "digi%d: port %d: got event"
1591 " on nonexisting port\n", sc->res.unit,
1595 port = &sc->ports[event.pnum];
1599 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1600 DLOG(DIGIDB_IRQ, (sc->dev,
1601 "port %d: event 0x%x on closed port\n",
1602 event.pnum, event.event));
1610 if (event.event & ~ALL_IND)
1611 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1612 " lstat 0x%x\n", sc->res.unit, event.pnum,
1613 event.event, event.mstat, event.lstat);
1615 if (event.event & DATA_IND) {
1616 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1618 wrapmask = port->rxbufsize - 1;
1623 if (!(tp->t_state & TS_ISOPEN)) {
1627 while (head != tail) {
1630 DLOG(DIGIDB_INT, (sc->dev,
1631 "port %d: p rx head = %d tail = %d\n",
1632 event.pnum, head, tail));
1633 top = (head > tail) ? head : wrapmask + 1;
1634 sc->towin(sc, port->rxwin);
1636 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1637 size = b_to_q((char *)port->rxbuf +
1638 tail, size, &tp->t_rawq);
1641 } else for (; tail < top;) {
1643 l_rint(port->rxbuf[tail], tp);
1644 sc->towin(sc, port->rxwin);
1647 if (tp->t_state & TS_TBLOCK)
1659 CE_RECORD(port, CE_OVERRUN);
1660 log(LOG_ERR, "digi%d: port%d: %s\n",
1661 sc->res.unit, event.pnum,
1662 digi_errortxt(CE_OVERRUN));
1667 tp->t_state |= TS_TBLOCK;
1668 port->status |= PAUSE_RX;
1669 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1676 if (event.event & MODEMCHG_IND) {
1677 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1680 if ((event.mstat ^ event.lstat) & port->cd) {
1682 linesw[tp->t_line].l_modem
1683 (tp, event.mstat & port->cd);
1685 wakeup(TSA_CARR_ON(tp));
1688 if (event.mstat & sc->csigs->ri) {
1689 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1691 if (port->send_ring) {
1692 linesw[tp->t_line].l_rint('R', tp);
1693 linesw[tp->t_line].l_rint('I', tp);
1694 linesw[tp->t_line].l_rint('N', tp);
1695 linesw[tp->t_line].l_rint('G', tp);
1696 linesw[tp->t_line].l_rint('\r', tp);
1697 linesw[tp->t_line].l_rint('\n', tp);
1701 if (event.event & BREAK_IND) {
1702 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1704 linesw[tp->t_line].l_rint(TTY_BI, tp);
1706 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1707 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1709 event.event & LOWTX_IND ? " LOWTX" : "",
1710 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1711 (*linesw[tp->t_line].l_start)(tp);
1714 sc->gdata->eout = etail;
1716 if (sc->window != 0)
1719 sc->towin(sc, window);
1720 lwkt_reltoken(&tty_token);
1724 digistart(struct tty *tp)
1728 struct digi_p *port;
1729 struct digi_softc *sc;
1730 volatile struct board_chan *bc;
1732 int size, ocount, totcnt = 0;
1735 lwkt_gettoken(&tty_token);
1736 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1737 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1739 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1740 KASSERT(sc, ("digi%d: softc not allocated in digistart", unit));
1742 port = &sc->ports[pnum];
1745 wmask = port->txbufsize - 1;
1748 port->lcc = tp->t_outq.c_cc;
1750 if (!(tp->t_state & TS_TBLOCK)) {
1751 if (port->status & PAUSE_RX) {
1752 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1755 * CAREFUL - braces are needed here if the DLOG is
1759 port->status &= ~PAUSE_RX;
1762 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1763 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1764 port->status &= ~PAUSE_TX;
1765 fepcmd_w(port, RESUMETX, 0, 10);
1767 if (tp->t_outq.c_cc == 0)
1768 tp->t_state &= ~TS_BUSY;
1770 tp->t_state |= TS_BUSY;
1773 while (tp->t_outq.c_cc != 0) {
1775 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1779 size = tail - head - 1;
1781 size = port->txbufsize - head;
1788 sc->towin(sc, port->txwin);
1789 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1798 port->lostcc = tp->t_outq.c_cc;
1801 size = port->txbufsize - tail + head;
1806 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1809 lwkt_reltoken(&tty_token);
1813 digistop(struct tty *tp, int rw)
1815 struct digi_softc *sc;
1818 struct digi_p *port;
1820 lwkt_gettoken(&tty_token);
1821 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1822 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1824 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1825 KASSERT(sc, ("digi%d: softc not allocated in digistop", unit));
1826 port = sc->ports + pnum;
1828 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1829 port->status |= PAUSE_TX;
1830 fepcmd_w(port, PAUSETX, 0, 10);
1831 lwkt_reltoken(&tty_token);
1835 * NOTE: Must be called with tty_token held
1838 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1841 unsigned tail, head;
1844 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1845 mem = port->sc->memcmd;
1847 port->sc->setwin(port->sc, 0);
1849 head = port->sc->gdata->cin;
1850 mem[head + 0] = cmd;
1851 mem[head + 1] = port->pnum;
1852 *(u_short *)(mem + head + 2) = op1;
1854 head = (head + 4) & port->sc->gdata->cmax;
1855 port->sc->gdata->cin = head;
1857 for (count = FEPTIMEOUT; count > 0; count--) {
1858 head = port->sc->gdata->cin;
1859 tail = port->sc->gdata->cout;
1860 n = (head - tail) & port->sc->gdata->cmax;
1862 if (n <= ncmds * sizeof(short) * 4)
1866 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1867 port->sc->res.unit, port->pnum);
1871 digi_errortxt(int id)
1873 static const char *error_desc[] = {
1875 "interrupt-level buffer overflow",
1876 "tty-level buffer overflow",
1879 KASSERT(id >= 0 && id < NELEM(error_desc),
1880 ("Unexpected digi error id %d\n", id));
1882 return (error_desc[id]);
1886 digi_attach(struct digi_softc *sc)
1888 char tbuf[MAKEDEV_MINNBUF];
1890 lwkt_gettoken(&tty_token);
1891 sc->res.ctldev = make_dev(&digi_ops,
1892 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1893 0600, "digi%s.ctl", makedev_unit_b32(tbuf, sc->res.unit));
1899 lwkt_reltoken(&tty_token);
1904 * NOTE: Must be called with tty_token held
1907 digi_inuse(struct digi_softc *sc)
1911 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1912 for (i = 0; i < sc->numports; i++)
1913 if (sc->ttys[i].t_state & TS_ISOPEN) {
1914 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1916 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1917 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1925 * NOTE: Must be called with tty_token held
1928 digi_free_state(struct digi_softc *sc)
1932 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1933 /* Blow it all away */
1935 for (i = 0; i < sc->numports; i++)
1936 for (d = 0; d < 6; d++)
1937 destroy_dev(sc->ports[i].dev[d]);
1939 callout_stop(&sc->callout);
1940 callout_stop(&sc->inttest);
1942 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1943 #ifdef DIGI_INTERRUPT
1944 if (sc->res.irq != NULL) {
1945 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1951 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1952 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1953 kfree(sc->ports, M_TTYS);
1955 kfree(sc->ttys, M_TTYS);
1960 sc->status = DIGI_STATUS_NOTINIT;
1964 digi_detach(device_t dev)
1966 struct digi_softc *sc = device_get_softc(dev);
1968 lwkt_gettoken(&tty_token);
1969 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1971 /* If we're INIT'd, numports must be 0 */
1972 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1973 ("digi%d: numports(%d) & status(%d) are out of sync",
1974 sc->res.unit, sc->numports, (int)sc->status));
1976 if (digi_inuse(sc)) {
1977 lwkt_reltoken(&tty_token);
1981 digi_free_state(sc);
1983 destroy_dev(sc->res.ctldev);
1985 if (sc->res.mem != NULL) {
1986 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
1990 if (sc->res.io != NULL) {
1991 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
1996 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
2000 lwkt_reltoken(&tty_token);
2005 digi_shutdown(device_t dev)
2010 MODULE_VERSION(digi, 1);