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 $
32 * $DragonFly: src/sys/dev/serial/digi/digi.c,v 1.11 2008/04/30 17:28:17 dillon Exp $
37 * Figure out what the con bios stuff is supposed to do
38 * Test with *LOTS* more cards - I only have a PCI8r and an ISA Xem.
41 #include "opt_compat.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
48 #include <sys/linker.h>
49 #include <sys/kernel.h>
51 #include <sys/malloc.h>
53 #include <sys/syslog.h>
54 #include <sys/fcntl.h>
57 #include <sys/thread2.h>
62 #include <dev/serial/digi/digiio.h>
63 #include <dev/serial/digi/digireg.h>
64 #include <dev/serial/digi/digi.h>
65 #include <dev/serial/digi/digi_pci.h>
66 #include <dev/serial/digi/digi_bios.h>
68 #define CDEV_MAJOR 162
70 #define CTRL_DEV 0x800000
71 #define CALLOUT_MASK 0x400000
72 #define CONTROL_INIT_STATE 0x100000
73 #define CONTROL_LOCK_STATE 0x200000
74 #define CONTROL_MASK (CTRL_DEV|CONTROL_INIT_STATE|CONTROL_LOCK_STATE)
75 #define UNIT_MASK 0x030000
76 #define PORT_MASK 0x0000FF
77 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
78 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
79 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
80 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
82 static d_open_t digiopen;
83 static d_close_t digiclose;
84 static d_read_t digiread;
85 static d_write_t digiwrite;
86 static d_ioctl_t digiioctl;
88 static void digistop(struct tty *tp, int rw);
89 static int digimctl(struct digi_p *port, int bits, int how);
90 static void digi_poll(void *ptr);
91 static void digi_freedata(struct digi_softc *);
92 static void fepcmd(struct digi_p *port, int cmd, int op, int ncmds);
93 static void digistart(struct tty *tp);
94 static int digiparam(struct tty *tp, struct termios *t);
95 static void digihardclose(struct digi_p *port);
96 static void digi_intr(void *);
97 static int digi_init(struct digi_softc *_sc);
98 static int digi_loaddata(struct digi_softc *);
99 static int digi_inuse(struct digi_softc *);
100 static void digi_free_state(struct digi_softc *);
102 #define fepcmd_b(port, cmd, op1, op2, ncmds) \
103 fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
104 #define fepcmd_w fepcmd
107 static speed_t digidefaultrate = TTYDEF_SPEED;
110 struct con_bios *next;
115 static struct con_bios *con_bios_list;
116 devclass_t digi_devclass;
117 unsigned digi_debug = 0;
119 static struct speedtab digispeedtab[] = {
120 { 0, 0}, /* old (sysV-like) Bx codes */
136 { 57600, (02000 | 1)},
137 { 76800, (02000 | 2)},
138 { 115200, (02000 | 3)},
139 { 230400, (02000 | 6)},
143 const struct digi_control_signals digi_xixe_signals = {
144 0x02, 0x08, 0x10, 0x20, 0x40, 0x80
147 const struct digi_control_signals digi_normal_signals = {
148 0x02, 0x80, 0x20, 0x10, 0x40, 0x01
151 static struct dev_ops digi_ops = {
152 { "dgm", CDEV_MAJOR, D_TTY },
154 .d_close = digiclose,
156 .d_write = digiwrite,
157 .d_ioctl = digiioctl,
158 .d_kqfilter = ttykqfilter,
159 .d_revoke = ttyrevoke
165 struct digi_softc *sc;
167 sc = (struct digi_softc *)ptr;
168 callout_init_mp(&sc->callout);
170 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
174 digi_int_test(void *v)
176 struct digi_softc *sc = v;
178 callout_init_mp(&sc->inttest);
179 #ifdef DIGI_INTERRUPT
180 if (sc->intr_timestamp.tv_sec || sc->intr_timestamp.tv_usec) {
184 log(LOG_ERR, "digi%d: Interrupt didn't work, use polled mode\n", unit);
186 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
190 digi_freedata(struct digi_softc *sc)
192 if (sc->fep.data != NULL) {
193 kfree(sc->fep.data, M_TTYS);
196 if (sc->link.data != NULL) {
197 kfree(sc->link.data, M_TTYS);
198 sc->link.data = NULL;
200 if (sc->bios.data != NULL) {
201 kfree(sc->bios.data, M_TTYS);
202 sc->bios.data = NULL;
207 digi_bcopy(const void *vfrom, void *vto, size_t sz)
209 volatile const char *from = (volatile const char *)vfrom;
210 volatile char *to = (volatile char *)vto;
213 for (i = 0; i < sz; i++)
216 from = (const volatile char *)vfrom;
217 to = (volatile char *)vto;
218 for (i = 0; i < sz; i++)
219 if (*to++ != *from++)
225 digi_delay(struct digi_softc *sc, const char *txt, u_long timo)
228 DELAY(timo * 1000000 / hz);
230 tsleep(sc, PCATCH, txt, timo);
234 * NOTE: Must be called with tty_token held
237 digi_init(struct digi_softc *sc)
243 volatile struct board_chan *bc;
245 ASSERT_LWKT_TOKEN_HELD(&tty_token);
248 if (sc->status == DIGI_STATUS_DISABLED) {
249 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
253 if (sc->bios.data == NULL) {
254 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
259 if (sc->link.data == NULL && sc->model >= PCCX) {
260 log(LOG_ERR, "digi%d: Cannot init without link info\n",
265 if (sc->fep.data == NULL) {
266 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
270 sc->status = DIGI_STATUS_NOTINIT;
274 * We're re-initialising - maybe because someone's attached
275 * another port module. For now, we just re-initialise
284 ptr = sc->setwin(sc, MISCGLOBAL);
285 for (i = 0; i < 16; i += 2)
290 outb(sc->wport, 0xff); /* window 7 */
291 ptr = sc->vmem + (BIOSCODE & 0x1fff);
293 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
294 device_printf(sc->dev, "BIOS upload failed\n");
298 outb(sc->port, FEPCLR);
304 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
305 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
306 device_printf(sc->dev, "BIOS upload failed\n");
317 outb(sc->port, FEPRST | FEPMEM);
319 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
320 FEPMASK) != FEPRST; i++) {
322 log(LOG_ERR, "digi%d: %s init reset failed\n",
323 sc->res.unit, sc->name);
326 digi_delay(sc, "digiinit0", 5);
328 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
330 /* Now upload the BIOS */
331 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
332 sc->bios.size : sc->win_size - BIOSOFFSET;
334 ptr = sc->setwin(sc, BIOSOFFSET);
335 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
336 device_printf(sc->dev, "BIOS upload (1) failed\n");
340 if (cnt != sc->bios.size) {
341 /* and the second part */
342 ptr = sc->setwin(sc, sc->win_size);
343 if (!digi_bcopy(sc->bios.data + cnt, ptr,
344 sc->bios.size - cnt)) {
345 device_printf(sc->dev, "BIOS upload failed\n");
350 ptr = sc->setwin(sc, 0);
351 vW(ptr + 0) = 0x0401;
352 vW(ptr + 2) = 0x0bf0;
353 vW(ptr + 4) = 0x0000;
354 vW(ptr + 6) = 0x0000;
359 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
361 ptr = sc->setwin(sc, MISCGLOBAL);
367 } else if (sc->model == PCXEVE) {
368 outb(sc->port, FEPCLR);
371 outb(sc->port, FEPCLR | FEPMEM);
372 resp = FEPRST | FEPMEM;
375 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
378 log(LOG_ERR, "digi%d: BIOS start failed\n",
382 digi_delay(sc, "digibios0", 5);
385 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
387 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
389 log(LOG_ERR, "digi%d: BIOS boot failed "
390 "(0x%02x != 0x%02x)\n",
391 sc->res.unit, vW(ptr), *(u_short *)"GD");
394 digi_delay(sc, "digibios1", 5);
397 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
399 if (sc->link.data != NULL) {
400 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
401 ptr = sc->setwin(sc, 0xcd0);
402 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
411 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
412 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
414 /* A BIOS request to move our data to 0x2000 */
415 ptr = sc->setwin(sc, MBOX);
417 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
419 vW(ptr + 6) = FEPCODESEG;
421 vW(ptr + 10) = sc->fep.size;
423 /* Run the BIOS request */
424 outb(sc->port, FEPREQ | FEPMEM);
425 outb(sc->port, FEPCLR | FEPMEM);
427 for (i = 0; W(ptr); i++) {
429 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
434 digi_delay(sc, "digifep0", 5);
437 (sc->dev, "FEP/OS moved after %d iterations\n", i));
439 /* Clear the confirm word */
440 ptr = sc->setwin(sc, FEPSTAT);
443 /* A BIOS request to execute the FEP/OS */
444 ptr = sc->setwin(sc, MBOX);
446 vW(ptr + 2) = FEPCODESEG;
449 /* Run the BIOS request */
450 outb(sc->port, FEPREQ);
451 outb(sc->port, FEPCLR);
453 ptr = sc->setwin(sc, FEPSTAT);
460 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
462 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
463 sc->fep.size : sc->win_size - BIOSOFFSET;
465 ptr = sc->setwin(sc, BIOSOFFSET);
466 digi_bcopy(sc->fep.data, ptr, cnt);
468 if (cnt != sc->fep.size) {
469 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
470 digi_bcopy(sc->fep.data + cnt, ptr,
474 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
476 ptr = sc->setwin(sc, 0xc30);
482 /* Clear the confirm word */
483 ptr = sc->setwin(sc, FEPSTAT);
487 outb(sc->port, 0); /* XXX necessary ? */
492 ptr = sc->setwin(sc, 0xd000);
493 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
495 /* A BIOS request to execute the FEP/OS */
496 ptr = sc->setwin(sc, 0xc40);
498 W(ptr + 2) = FEPCODE >> 4;
501 /* Clear the confirm word */
502 ptr = sc->setwin(sc, FEPSTAT);
505 /* Run the BIOS request */
506 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
507 outb(sc->port, FEPCLR | FEPMEM);
511 /* Now wait 'till the FEP/OS has booted */
512 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
514 log(LOG_ERR, "digi%d: FEP/OS start failed "
515 "(0x%02x != 0x%02x)\n",
516 sc->res.unit, vW(ptr), *(u_short *)"OS");
520 digi_delay(sc, "digifep1", 5);
523 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
525 if (sc->model >= PCXEM) {
526 ptr = sc->setwin(sc, 0xe04);
528 ptr = sc->setwin(sc, 0xc02);
529 sc->numports = vW(ptr);
531 ptr = sc->setwin(sc, 0xc22);
532 sc->numports = vW(ptr);
535 if (sc->numports == 0) {
536 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
541 if (sc->numports > 256) {
542 /* Our minor numbering scheme is broken for more than 256 */
543 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
544 sc->name, sc->numports);
547 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
551 kfree(sc->ports, M_TTYS);
552 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
553 M_TTYS, M_WAITOK | M_ZERO);
556 kfree(sc->ttys, M_TTYS);
557 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
558 M_TTYS, M_WAITOK | M_ZERO);
561 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
562 * port. If the value is 0, the port is broken....
565 ptr = sc->setwin(sc, 0);
567 /* We should now init per-port structures */
568 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
569 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
571 sc->memcmd = ptr + sc->gdata->cstart;
572 sc->memevent = ptr + sc->gdata->istart;
574 for (i = 0; i < sc->numports; i++, bc++) {
575 port = sc->ports + i;
578 port->status = ENABLED;
579 port->tp = sc->ttys + i;
582 if (sc->model == PCXEVE) {
584 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
586 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
587 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
588 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
589 } else if (sc->model == PCXI || sc->model == PCXE) {
590 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
591 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
592 port->txwin = port->rxwin = 0;
595 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
597 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
598 port->txwin = FEPWIN |
599 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
600 port->rxwin = FEPWIN |
601 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
603 port->txbufsize = bc->tmax + 1;
604 port->rxbufsize = bc->rmax + 1;
606 lowwater = port->txbufsize >> 2;
610 fepcmd_w(port, STXLWATER, lowwater, 10);
611 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
612 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
615 port->dtr_wait = 3 * hz;
618 * We don't use all the flags from <sys/ttydefaults.h> since
619 * they are only relevant for logins. It's important to have
620 * echo off initially so that the line doesn't start blathering
621 * before the echo flag can be turned off.
623 port->it_in.c_iflag = 0;
624 port->it_in.c_oflag = 0;
625 port->it_in.c_cflag = TTYDEF_CFLAG;
626 port->it_in.c_lflag = 0;
627 termioschars(&port->it_in);
628 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
629 port->it_out = port->it_in;
630 port->send_ring = 1; /* Default action on signal RI */
632 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
633 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
634 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
635 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
636 0600, "ttyiD%d.%d", sc->res.unit, i);
637 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
638 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
639 0600, "ttylD%d.%d", sc->res.unit, i);
640 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
641 CALLOUT_MASK, UID_UUCP, GID_DIALER,
642 0660, "cuaD%d.%d", sc->res.unit, i);
643 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
644 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
645 0660, "cuaiD%d.%d", sc->res.unit, i);
646 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
647 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
648 0660, "cualD%d.%d", sc->res.unit, i);
652 callout_reset(&sc->inttest, hz, digi_int_test, sc);
653 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
654 sc->status = DIGI_STATUS_ENABLED;
660 * NOTE: Must be called with tty_token held
663 digimctl(struct digi_p *port, int bits, int how)
667 ASSERT_LWKT_TOKEN_HELD(&tty_token);
669 port->sc->setwin(port->sc, 0);
670 mstat = port->bc->mstat;
671 port->sc->hidewin(port->sc);
673 if (mstat & port->sc->csigs->rts)
675 if (mstat & port->cd)
677 if (mstat & port->dsr)
679 if (mstat & port->sc->csigs->cts)
681 if (mstat & port->sc->csigs->ri)
683 if (mstat & port->sc->csigs->dtr)
688 /* Only DTR and RTS may be set */
690 if (bits & TIOCM_DTR)
691 mstat |= port->sc->csigs->dtr;
692 if (bits & TIOCM_RTS)
693 mstat |= port->sc->csigs->rts;
697 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
700 fepcmd_b(port, SETMODEM, mstat, 0, 0);
703 fepcmd_b(port, SETMODEM, 0, mstat, 0);
711 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
713 lwkt_gettoken(&tty_token);
714 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
715 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
716 (!(t->c_iflag & PARMRK) ||
717 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
718 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
719 linesw[tp->t_line].l_rint == ttyinput)
720 tp->t_state |= TS_CAN_BYPASS_L_RINT;
722 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
723 lwkt_reltoken(&tty_token);
727 digiopen(struct dev_open_args *ap)
729 cdev_t dev = ap->a_head.a_dev;
730 struct digi_softc *sc;
736 volatile struct board_chan *bc;
740 unit = MINOR_TO_UNIT(minor(dev));
741 pnum = MINOR_TO_PORT(minor(dev));
743 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
747 lwkt_gettoken(&tty_token);
748 if (sc->status != DIGI_STATUS_ENABLED) {
749 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
750 lwkt_reltoken(&tty_token);
753 if (pnum >= sc->numports) {
754 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
755 lwkt_reltoken(&tty_token);
758 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
760 lwkt_reltoken(&tty_token);
763 port = &sc->ports[pnum];
764 tp = dev->si_tty = port->tp;
770 while (port->status & DIGI_DTR_OFF) {
772 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
778 if (tp->t_state & TS_ISOPEN) {
780 * The device is open, so everything has been initialized.
783 if (mynor & CALLOUT_MASK) {
784 if (!port->active_out) {
786 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
787 " BUSY error = %d\n", pnum, error));
790 } else if (port->active_out) {
791 if (ap->a_oflags & O_NONBLOCK) {
793 DLOG(DIGIDB_OPEN, (sc->dev,
794 "port %d: BUSY error = %d\n", pnum, error));
798 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
801 DLOG(DIGIDB_OPEN, (sc->dev,
802 "port %d: tsleep(digibi) error = %d\n",
808 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0) != 0) {
814 * The device isn't open, so there are no conflicts.
815 * Initialize it. Initialization is done twice in many
816 * cases: to preempt sleeping callin opens if we are callout,
817 * and to complete a callin open after DCD rises.
819 callout_init_mp(&port->wakeupco);
820 tp->t_oproc = digistart;
821 tp->t_param = digiparam;
822 tp->t_stop = digistop;
824 tp->t_termios = (mynor & CALLOUT_MASK) ?
825 port->it_out : port->it_in;
828 bc->rout = bc->rin; /* clear input queue */
832 bc->mint = port->cd | port->sc->csigs->ri;
835 port->cd = sc->csigs->dsr;
836 port->dsr = sc->csigs->cd;
838 port->cd = sc->csigs->cd;
839 port->dsr = sc->csigs->dsr;
841 port->wopeners++; /* XXX required ? */
842 error = digiparam(tp, &tp->t_termios);
846 DLOG(DIGIDB_OPEN, (sc->dev,
847 "port %d: cxpparam error = %d\n", pnum, error));
852 /* handle fake and initial DCD for callout devices */
854 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
855 linesw[tp->t_line].l_modem(tp, 1);
858 /* Wait for DCD if necessary */
859 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
860 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
862 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
865 DLOG(DIGIDB_OPEN, (sc->dev,
866 "port %d: tsleep(digidcd) error = %d\n",
872 error = linesw[tp->t_line].l_open(dev, tp);
873 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
876 digi_disc_optim(tp, &tp->t_termios, port);
878 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
879 port->active_out = TRUE;
881 if (tp->t_state & TS_ISOPEN)
886 if (!(tp->t_state & TS_ISOPEN))
889 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
892 lwkt_reltoken(&tty_token);
897 digiclose(struct dev_close_args *ap)
899 cdev_t dev = ap->a_head.a_dev;
903 struct digi_softc *sc;
906 lwkt_gettoken(&tty_token);
908 unit = MINOR_TO_UNIT(mynor);
909 pnum = MINOR_TO_PORT(mynor);
911 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
912 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
914 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
916 lwkt_reltoken(&tty_token);
920 port = sc->ports + pnum;
923 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
926 linesw[tp->t_line].l_close(tp, ap->a_fflag);
927 digi_disc_optim(tp, &tp->t_termios, port);
928 digistop(tp, FREAD | FWRITE);
933 lwkt_reltoken(&tty_token);
938 digidtrwakeup(void *chan)
940 struct digi_p *port = chan;
942 lwkt_gettoken(&tty_token);
943 port->status &= ~DIGI_DTR_OFF;
944 wakeup(&port->dtr_wait);
946 lwkt_reltoken(&tty_token);
950 * NOTE: Must be called with tty_token held
953 digihardclose(struct digi_p *port)
955 volatile struct board_chan *bc;
957 ASSERT_LWKT_TOKEN_HELD(&tty_token);
961 port->sc->setwin(port->sc, 0);
966 if ((port->tp->t_cflag & HUPCL) ||
967 (!port->active_out && !(bc->mstat & port->cd) &&
968 !(port->it_in.c_cflag & CLOCAL)) ||
969 !(port->tp->t_state & TS_ISOPEN)) {
970 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
971 if (port->dtr_wait != 0) {
972 /* Schedule a wakeup of any callin devices */
974 callout_reset(&port->wakeupco, port->dtr_wait,
975 digidtrwakeup, port);
976 port->status |= DIGI_DTR_OFF;
979 port->active_out = FALSE;
980 wakeup(&port->active_out);
981 wakeup(TSA_CARR_ON(port->tp));
986 digiread(struct dev_read_args *ap)
988 cdev_t dev = ap->a_head.a_dev;
991 int error, unit, pnum;
992 struct digi_softc *sc;
995 if (mynor & CONTROL_MASK)
998 lwkt_gettoken(&tty_token);
999 unit = MINOR_TO_UNIT(mynor);
1000 pnum = MINOR_TO_PORT(mynor);
1002 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1003 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
1004 tp = &sc->ttys[pnum];
1006 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
1007 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
1010 lwkt_reltoken(&tty_token);
1015 digiwrite(struct dev_write_args *ap)
1017 cdev_t dev = ap->a_head.a_dev;
1020 int error, unit, pnum;
1021 struct digi_softc *sc;
1024 if (mynor & CONTROL_MASK)
1027 lwkt_gettoken(&tty_token);
1028 unit = MINOR_TO_UNIT(mynor);
1029 pnum = MINOR_TO_PORT(mynor);
1031 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1032 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
1033 tp = &sc->ttys[pnum];
1035 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1036 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1039 lwkt_reltoken(&tty_token);
1044 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1046 * Populate sc->bios, sc->fep, and sc->link from this data.
1048 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1049 * to their respective sizes.
1051 * The module is unloaded when we're done.
1054 digi_loaddata(struct digi_softc *sc)
1056 struct digi_bios *bios;
1058 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1059 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1060 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1061 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1063 for (bios = digi_bioses; bios->model != NULL; bios++) {
1064 if (!strcmp(bios->model, sc->module))
1067 if (bios->model == NULL) {
1068 kprintf("digi.ko: driver %s not found", sc->module);
1072 sc->bios.size = bios->bios_size;
1073 if (sc->bios.size != 0 && bios->bios != NULL) {
1074 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1075 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1078 sc->fep.size = bios->fep_size;
1079 if (sc->fep.size != 0 && bios->fep != NULL) {
1080 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1081 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1088 digiioctl(struct dev_ioctl_args *ap)
1090 cdev_t dev = ap->a_head.a_dev;
1091 u_long cmd = ap->a_cmd;
1092 caddr_t data = ap->a_data;
1093 int unit, pnum, mynor, error, ret;
1094 struct digi_softc *sc;
1095 struct digi_p *port;
1097 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1099 struct termios term;
1103 unit = MINOR_TO_UNIT(mynor);
1104 pnum = MINOR_TO_PORT(mynor);
1106 lwkt_gettoken(&tty_token);
1107 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1108 KASSERT(sc, ("digi%d: softc not allocated in digiioctl\n", unit));
1110 if (sc->status == DIGI_STATUS_DISABLED) {
1111 lwkt_reltoken(&tty_token);
1115 if (mynor & CTRL_DEV) {
1119 digi_debug = *(int *)data;
1120 lwkt_reltoken(&tty_token);
1123 device_printf(sc->dev, "DEBUG not defined\n");
1124 lwkt_reltoken(&tty_token);
1129 error = digi_init(sc);
1131 lwkt_reltoken(&tty_token);
1135 *(enum digi_model *)data = sc->model;
1136 lwkt_reltoken(&tty_token);
1140 ret = copyout(sc->name, *(char **)data,
1141 strlen(sc->name) + 1);
1142 lwkt_reltoken(&tty_token);
1147 if (pnum >= sc->numports) {
1148 lwkt_reltoken(&tty_token);
1152 port = sc->ports + pnum;
1153 if (!(port->status & ENABLED)) {
1154 lwkt_reltoken(&tty_token);
1160 if (mynor & CONTROL_MASK) {
1163 switch (mynor & CONTROL_MASK) {
1164 case CONTROL_INIT_STATE:
1165 ct = (mynor & CALLOUT_MASK) ?
1166 &port->it_out : &port->it_in;
1168 case CONTROL_LOCK_STATE:
1169 ct = (mynor & CALLOUT_MASK) ?
1170 &port->lt_out : &port->lt_in;
1173 lwkt_reltoken(&tty_token);
1174 return (ENODEV); /* /dev/nodev */
1179 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1181 lwkt_reltoken(&tty_token);
1184 *ct = *(struct termios *)data;
1185 lwkt_reltoken(&tty_token);
1189 *(struct termios *)data = *ct;
1190 lwkt_reltoken(&tty_token);
1194 *(int *)data = TTYDISC;
1195 lwkt_reltoken(&tty_token);
1199 bzero(data, sizeof(struct winsize));
1200 lwkt_reltoken(&tty_token);
1203 case DIGIIO_GETALTPIN:
1204 switch (mynor & CONTROL_MASK) {
1205 case CONTROL_INIT_STATE:
1206 *(int *)data = port->ialtpin;
1209 case CONTROL_LOCK_STATE:
1210 *(int *)data = port->laltpin;
1214 panic("Confusion when re-testing minor");
1215 lwkt_reltoken(&tty_token);
1218 lwkt_reltoken(&tty_token);
1221 case DIGIIO_SETALTPIN:
1222 switch (mynor & CONTROL_MASK) {
1223 case CONTROL_INIT_STATE:
1224 if (!port->laltpin) {
1225 port->ialtpin = !!*(int *)data;
1226 DLOG(DIGIDB_SET, (sc->dev,
1227 "port%d: initial ALTPIN %s\n", pnum,
1228 port->ialtpin ? "set" : "cleared"));
1232 case CONTROL_LOCK_STATE:
1233 port->laltpin = !!*(int *)data;
1234 DLOG(DIGIDB_SET, (sc->dev,
1235 "port%d: ALTPIN %slocked\n",
1236 pnum, port->laltpin ? "" : "un"));
1240 panic("Confusion when re-testing minor");
1241 lwkt_reltoken(&tty_token);
1244 lwkt_reltoken(&tty_token);
1248 lwkt_reltoken(&tty_token);
1254 case DIGIIO_GETALTPIN:
1255 *(int *)data = !!(port->dsr == sc->csigs->cd);
1256 lwkt_reltoken(&tty_token);
1259 case DIGIIO_SETALTPIN:
1260 if (!port->laltpin) {
1262 DLOG(DIGIDB_SET, (sc->dev,
1263 "port%d: ALTPIN set\n", pnum));
1264 port->cd = sc->csigs->dsr;
1265 port->dsr = sc->csigs->cd;
1267 DLOG(DIGIDB_SET, (sc->dev,
1268 "port%d: ALTPIN cleared\n", pnum));
1269 port->cd = sc->csigs->cd;
1270 port->dsr = sc->csigs->dsr;
1273 lwkt_reltoken(&tty_token);
1278 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1279 term = tp->t_termios;
1281 error = ttsetcompat(tp, &cmd, data, &term);
1283 lwkt_reltoken(&tty_token);
1287 data = (caddr_t) & term;
1289 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1294 dt = (struct termios *)data;
1295 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1298 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1300 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1302 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1304 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1305 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1306 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1307 for (cc = 0; cc < NCCS; ++cc)
1308 if (lt->c_cc[cc] != 0)
1309 dt->c_cc[cc] = tp->t_cc[cc];
1310 if (lt->c_ispeed != 0)
1311 dt->c_ispeed = tp->t_ispeed;
1312 if (lt->c_ospeed != 0)
1313 dt->c_ospeed = tp->t_ospeed;
1315 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1316 ap->a_fflag, ap->a_cred);
1317 if (error == 0 && cmd == TIOCGETA)
1318 ((struct termios *)data)->c_iflag |= port->c_iflag;
1320 if (error >= 0 && error != ENOIOCTL) {
1321 lwkt_reltoken(&tty_token);
1325 error = ttioctl(tp, cmd, data, ap->a_fflag);
1326 if (error == 0 && cmd == TIOCGETA)
1327 ((struct termios *)data)->c_iflag |= port->c_iflag;
1329 digi_disc_optim(tp, &tp->t_termios, port);
1330 if (error >= 0 && error != ENOIOCTL) {
1332 lwkt_reltoken(&tty_token);
1338 port->send_ring = *(u_char *)data;
1342 * now it sends 400 millisecond break because I don't know
1343 * how to send an infinite break
1345 fepcmd_w(port, SENDBREAK, 400, 10);
1348 /* now it's empty */
1351 digimctl(port, TIOCM_DTR, DMBIS);
1354 digimctl(port, TIOCM_DTR, DMBIC);
1357 digimctl(port, *(int *)data, DMSET);
1360 digimctl(port, *(int *)data, DMBIS);
1363 digimctl(port, *(int *)data, DMBIC);
1366 *(int *)data = digimctl(port, 0, DMGET);
1369 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1372 lwkt_reltoken(&tty_token);
1375 port->dtr_wait = *(int *)data *hz / 100;
1379 *(int *)data = port->dtr_wait * 100 / hz;
1381 #ifdef DIGI_INTERRUPT
1383 *(struct timeval *)data = sc->intr_timestamp;
1389 lwkt_reltoken(&tty_token);
1393 lwkt_reltoken(&tty_token);
1398 digiparam(struct tty *tp, struct termios *t)
1403 struct digi_softc *sc;
1404 struct digi_p *port;
1410 lwkt_gettoken(&tty_token);
1411 mynor = minor(tp->t_dev);
1412 unit = MINOR_TO_UNIT(mynor);
1413 pnum = MINOR_TO_PORT(mynor);
1415 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1416 KASSERT(sc, ("digi%d: softc not allocated in digiparam\n", unit));
1418 port = &sc->ports[pnum];
1420 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1422 if (t->c_ispeed == 0)
1423 t->c_ispeed = t->c_ospeed;
1425 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1427 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed)) {
1428 lwkt_reltoken(&tty_token);
1434 window = sc->window;
1437 if (cflag == 0) { /* hangup */
1438 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1439 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1441 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1443 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1447 /* convert flags to sysV-style values */
1448 if (t->c_cflag & PARODD)
1450 if (t->c_cflag & PARENB)
1452 if (t->c_cflag & CSTOPB)
1455 /* convert flags to sysV-style values */
1456 if (t->c_cflag & PARODD)
1457 cflag |= FEP_PARODD;
1458 if (t->c_cflag & PARENB)
1459 cflag |= FEP_PARENB;
1460 if (t->c_cflag & CSTOPB)
1461 cflag |= FEP_CSTOPB;
1462 if (t->c_cflag & CLOCAL)
1463 cflag |= FEP_CLOCAL;
1466 cflag |= (t->c_cflag & CSIZE) >> 4;
1467 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1469 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1473 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1474 if (port->c_iflag & IXON)
1476 if (port->c_iflag & IXANY)
1478 if (port->c_iflag & IXOFF)
1481 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1482 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1485 if (t->c_cflag & CDTR_IFLOW)
1486 hflow |= sc->csigs->dtr;
1487 if (t->c_cflag & CRTS_IFLOW)
1488 hflow |= sc->csigs->rts;
1489 if (t->c_cflag & CCTS_OFLOW)
1490 hflow |= sc->csigs->cts;
1491 if (t->c_cflag & CDSR_OFLOW)
1493 if (t->c_cflag & CCAR_OFLOW)
1496 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1497 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1499 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1500 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1501 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1503 if (sc->window != 0)
1506 sc->towin(sc, window);
1509 lwkt_reltoken(&tty_token);
1516 struct digi_p *port;
1518 struct digi_softc *sc;
1520 volatile struct board_chan *bc;
1532 lwkt_gettoken(&tty_token);
1535 if (sc->status != DIGI_STATUS_ENABLED) {
1536 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1537 lwkt_reltoken(&tty_token);
1541 #ifdef DIGI_INTERRUPT
1542 microtime(&sc->intr_timestamp);
1545 window = sc->window;
1548 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1549 struct con_bios *con = con_bios_list;
1552 ptr = sc->vmem + W(sc->vmem + 0xd00);
1554 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1555 /* Not first block -- exact match */
1558 if (W(ptr + 4) >= W(con->bios + 4) &&
1559 W(ptr + 4) <= W(con->bios + 6))
1560 /* Initial search concetrator BIOS */
1565 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1566 " not found!\n", sc->res.unit, W(ptr + 4));
1568 W(sc->vmem + 0xd00) = 0;
1572 W(ptr + 4) = W(cxcon + 4);
1573 W(ptr + 6) = W(cxcon + 6);
1575 W(ptr + 2) = W(cxcon + 2);
1576 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1577 size = W(cxcon + 10) - (ptr[1] << 10);
1579 W(ptr + 8) = W(cxcon + 8);
1585 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1587 W(sc->vmem + 0xd00) = 0;
1591 ehead = sc->gdata->ein;
1592 etail = sc->gdata->eout;
1593 if (ehead == etail) {
1596 if (sc->intr_count % 6000 == 0) {
1597 DLOG(DIGIDB_IRQ, (sc->dev,
1598 "6000 useless polls %x %x\n", ehead, etail));
1604 while (ehead != etail) {
1605 event = *(volatile struct event *)(sc->memevent + etail);
1607 etail = (etail + 4) & sc->gdata->imax;
1609 if (event.pnum >= sc->numports) {
1610 log(LOG_ERR, "digi%d: port %d: got event"
1611 " on nonexisting port\n", sc->res.unit,
1615 port = &sc->ports[event.pnum];
1619 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1620 DLOG(DIGIDB_IRQ, (sc->dev,
1621 "port %d: event 0x%x on closed port\n",
1622 event.pnum, event.event));
1630 if (event.event & ~ALL_IND)
1631 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1632 " lstat 0x%x\n", sc->res.unit, event.pnum,
1633 event.event, event.mstat, event.lstat);
1635 if (event.event & DATA_IND) {
1636 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1638 wrapmask = port->rxbufsize - 1;
1643 if (!(tp->t_state & TS_ISOPEN)) {
1647 while (head != tail) {
1650 DLOG(DIGIDB_INT, (sc->dev,
1651 "port %d: p rx head = %d tail = %d\n",
1652 event.pnum, head, tail));
1653 top = (head > tail) ? head : wrapmask + 1;
1654 sc->towin(sc, port->rxwin);
1656 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1657 size = b_to_q((char *)port->rxbuf +
1658 tail, size, &tp->t_rawq);
1661 } else for (; tail < top;) {
1663 l_rint(port->rxbuf[tail], tp);
1664 sc->towin(sc, port->rxwin);
1667 if (tp->t_state & TS_TBLOCK)
1679 CE_RECORD(port, CE_OVERRUN);
1680 log(LOG_ERR, "digi%d: port%d: %s\n",
1681 sc->res.unit, event.pnum,
1682 digi_errortxt(CE_OVERRUN));
1687 tp->t_state |= TS_TBLOCK;
1688 port->status |= PAUSE_RX;
1689 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1696 if (event.event & MODEMCHG_IND) {
1697 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1700 if ((event.mstat ^ event.lstat) & port->cd) {
1702 linesw[tp->t_line].l_modem
1703 (tp, event.mstat & port->cd);
1705 wakeup(TSA_CARR_ON(tp));
1708 if (event.mstat & sc->csigs->ri) {
1709 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1711 if (port->send_ring) {
1712 linesw[tp->t_line].l_rint('R', tp);
1713 linesw[tp->t_line].l_rint('I', tp);
1714 linesw[tp->t_line].l_rint('N', tp);
1715 linesw[tp->t_line].l_rint('G', tp);
1716 linesw[tp->t_line].l_rint('\r', tp);
1717 linesw[tp->t_line].l_rint('\n', tp);
1721 if (event.event & BREAK_IND) {
1722 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1724 linesw[tp->t_line].l_rint(TTY_BI, tp);
1726 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1727 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1729 event.event & LOWTX_IND ? " LOWTX" : "",
1730 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1731 (*linesw[tp->t_line].l_start)(tp);
1734 sc->gdata->eout = etail;
1736 if (sc->window != 0)
1739 sc->towin(sc, window);
1740 lwkt_reltoken(&tty_token);
1744 digistart(struct tty *tp)
1748 struct digi_p *port;
1749 struct digi_softc *sc;
1750 volatile struct board_chan *bc;
1752 int size, ocount, totcnt = 0;
1755 lwkt_gettoken(&tty_token);
1756 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1757 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1759 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1760 KASSERT(sc, ("digi%d: softc not allocated in digistart\n", unit));
1762 port = &sc->ports[pnum];
1765 wmask = port->txbufsize - 1;
1768 port->lcc = tp->t_outq.c_cc;
1770 if (!(tp->t_state & TS_TBLOCK)) {
1771 if (port->status & PAUSE_RX) {
1772 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1775 * CAREFUL - braces are needed here if the DLOG is
1779 port->status &= ~PAUSE_RX;
1782 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1783 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1784 port->status &= ~PAUSE_TX;
1785 fepcmd_w(port, RESUMETX, 0, 10);
1787 if (tp->t_outq.c_cc == 0)
1788 tp->t_state &= ~TS_BUSY;
1790 tp->t_state |= TS_BUSY;
1793 while (tp->t_outq.c_cc != 0) {
1795 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1799 size = tail - head - 1;
1801 size = port->txbufsize - head;
1808 sc->towin(sc, port->txwin);
1809 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1818 port->lostcc = tp->t_outq.c_cc;
1821 size = port->txbufsize - tail + head;
1826 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1829 lwkt_reltoken(&tty_token);
1833 digistop(struct tty *tp, int rw)
1835 struct digi_softc *sc;
1838 struct digi_p *port;
1840 lwkt_gettoken(&tty_token);
1841 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1842 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1844 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1845 KASSERT(sc, ("digi%d: softc not allocated in digistop\n", unit));
1846 port = sc->ports + pnum;
1848 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1849 port->status |= PAUSE_TX;
1850 fepcmd_w(port, PAUSETX, 0, 10);
1851 lwkt_reltoken(&tty_token);
1855 * NOTE: Must be called with tty_token held
1858 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1861 unsigned tail, head;
1864 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1865 mem = port->sc->memcmd;
1867 port->sc->setwin(port->sc, 0);
1869 head = port->sc->gdata->cin;
1870 mem[head + 0] = cmd;
1871 mem[head + 1] = port->pnum;
1872 *(u_short *)(mem + head + 2) = op1;
1874 head = (head + 4) & port->sc->gdata->cmax;
1875 port->sc->gdata->cin = head;
1877 for (count = FEPTIMEOUT; count > 0; count--) {
1878 head = port->sc->gdata->cin;
1879 tail = port->sc->gdata->cout;
1880 n = (head - tail) & port->sc->gdata->cmax;
1882 if (n <= ncmds * sizeof(short) * 4)
1886 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1887 port->sc->res.unit, port->pnum);
1891 digi_errortxt(int id)
1893 static const char *error_desc[] = {
1895 "interrupt-level buffer overflow",
1896 "tty-level buffer overflow",
1899 KASSERT(id >= 0 && id < sizeof(error_desc) / sizeof(error_desc[0]),
1900 ("Unexpected digi error id %d\n", id));
1902 return (error_desc[id]);
1906 digi_attach(struct digi_softc *sc)
1908 lwkt_gettoken(&tty_token);
1909 sc->res.ctldev = make_dev(&digi_ops,
1910 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1911 0600, "digi%r.ctl", sc->res.unit);
1917 lwkt_reltoken(&tty_token);
1922 * NOTE: Must be called with tty_token held
1925 digi_inuse(struct digi_softc *sc)
1929 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1930 for (i = 0; i < sc->numports; i++)
1931 if (sc->ttys[i].t_state & TS_ISOPEN) {
1932 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1934 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1935 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1943 * NOTE: Must be called with tty_token held
1946 digi_free_state(struct digi_softc *sc)
1950 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1951 /* Blow it all away */
1953 for (i = 0; i < sc->numports; i++)
1954 for (d = 0; d < 6; d++)
1955 destroy_dev(sc->ports[i].dev[d]);
1957 callout_stop(&sc->callout);
1958 callout_stop(&sc->inttest);
1960 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1961 #ifdef DIGI_INTERRUPT
1962 if (sc->res.irq != NULL) {
1963 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1969 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1970 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1971 kfree(sc->ports, M_TTYS);
1973 kfree(sc->ttys, M_TTYS);
1978 sc->status = DIGI_STATUS_NOTINIT;
1982 digi_detach(device_t dev)
1984 struct digi_softc *sc = device_get_softc(dev);
1986 lwkt_gettoken(&tty_token);
1987 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1989 /* If we're INIT'd, numports must be 0 */
1990 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1991 ("digi%d: numports(%d) & status(%d) are out of sync",
1992 sc->res.unit, sc->numports, (int)sc->status));
1994 if (digi_inuse(sc)) {
1995 lwkt_reltoken(&tty_token);
1999 digi_free_state(sc);
2001 destroy_dev(sc->res.ctldev);
2003 if (sc->res.mem != NULL) {
2004 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
2008 if (sc->res.io != NULL) {
2009 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
2014 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
2018 lwkt_reltoken(&tty_token);
2023 digi_shutdown(device_t dev)
2028 MODULE_VERSION(digi, 1);