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 "opt_compat.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
47 #include <sys/linker.h>
48 #include <sys/kernel.h>
50 #include <sys/malloc.h>
52 #include <sys/syslog.h>
53 #include <sys/fcntl.h>
55 #include <sys/thread2.h>
60 #include <dev/serial/digi/digiio.h>
61 #include <dev/serial/digi/digireg.h>
62 #include <dev/serial/digi/digi.h>
63 #include <dev/serial/digi/digi_pci.h>
64 #include <dev/serial/digi/digi_bios.h>
66 #define CTRL_DEV 0x800000
67 #define CALLOUT_MASK 0x400000
68 #define CONTROL_INIT_STATE 0x100000
69 #define CONTROL_LOCK_STATE 0x200000
70 #define CONTROL_MASK (CTRL_DEV|CONTROL_INIT_STATE|CONTROL_LOCK_STATE)
71 #define UNIT_MASK 0x030000
72 #define PORT_MASK 0x0000FF
73 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
74 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
75 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
76 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
78 static d_open_t digiopen;
79 static d_close_t digiclose;
80 static d_read_t digiread;
81 static d_write_t digiwrite;
82 static d_ioctl_t digiioctl;
84 static void digistop(struct tty *tp, int rw);
85 static int digimctl(struct digi_p *port, int bits, int how);
86 static void digi_poll(void *ptr);
87 static void digi_freedata(struct digi_softc *);
88 static void fepcmd(struct digi_p *port, int cmd, int op, int ncmds);
89 static void digistart(struct tty *tp);
90 static int digiparam(struct tty *tp, struct termios *t);
91 static void digihardclose(struct digi_p *port);
92 static void digi_intr(void *);
93 static int digi_init(struct digi_softc *_sc);
94 static int digi_loaddata(struct digi_softc *);
95 static int digi_inuse(struct digi_softc *);
96 static void digi_free_state(struct digi_softc *);
98 #define fepcmd_b(port, cmd, op1, op2, ncmds) \
99 fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
100 #define fepcmd_w fepcmd
103 static speed_t digidefaultrate = TTYDEF_SPEED;
106 struct con_bios *next;
111 static struct con_bios *con_bios_list;
112 devclass_t digi_devclass;
113 unsigned digi_debug = 0;
115 static struct speedtab digispeedtab[] = {
116 { 0, 0}, /* old (sysV-like) Bx codes */
132 { 57600, (02000 | 1)},
133 { 76800, (02000 | 2)},
134 { 115200, (02000 | 3)},
135 { 230400, (02000 | 6)},
139 const struct digi_control_signals digi_xixe_signals = {
140 0x02, 0x08, 0x10, 0x20, 0x40, 0x80
143 const struct digi_control_signals digi_normal_signals = {
144 0x02, 0x80, 0x20, 0x10, 0x40, 0x01
147 static struct dev_ops digi_ops = {
150 .d_close = digiclose,
152 .d_write = digiwrite,
153 .d_ioctl = digiioctl,
154 .d_kqfilter = ttykqfilter,
155 .d_revoke = ttyrevoke
161 struct digi_softc *sc;
163 sc = (struct digi_softc *)ptr;
164 callout_init_mp(&sc->callout);
166 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
170 digi_int_test(void *v)
172 struct digi_softc *sc = v;
174 callout_init_mp(&sc->inttest);
175 #ifdef DIGI_INTERRUPT
176 if (sc->intr_timestamp.tv_sec || sc->intr_timestamp.tv_usec) {
180 log(LOG_ERR, "digi%d: Interrupt didn't work, use polled mode\n", unit);
182 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
186 digi_freedata(struct digi_softc *sc)
188 if (sc->fep.data != NULL) {
189 kfree(sc->fep.data, M_TTYS);
192 if (sc->link.data != NULL) {
193 kfree(sc->link.data, M_TTYS);
194 sc->link.data = NULL;
196 if (sc->bios.data != NULL) {
197 kfree(sc->bios.data, M_TTYS);
198 sc->bios.data = NULL;
203 digi_bcopy(const void *vfrom, void *vto, size_t sz)
205 volatile const char *from = (volatile const char *)vfrom;
206 volatile char *to = (volatile char *)vto;
209 for (i = 0; i < sz; i++)
212 from = (const volatile char *)vfrom;
213 to = (volatile char *)vto;
214 for (i = 0; i < sz; i++)
215 if (*to++ != *from++)
221 digi_delay(struct digi_softc *sc, const char *txt, u_long timo)
224 DELAY(timo * 1000000 / hz);
226 tsleep(sc, PCATCH, txt, timo);
230 * NOTE: Must be called with tty_token held
233 digi_init(struct digi_softc *sc)
239 volatile struct board_chan *bc;
241 ASSERT_LWKT_TOKEN_HELD(&tty_token);
244 if (sc->status == DIGI_STATUS_DISABLED) {
245 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
249 if (sc->bios.data == NULL) {
250 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
255 if (sc->link.data == NULL && sc->model >= PCCX) {
256 log(LOG_ERR, "digi%d: Cannot init without link info\n",
261 if (sc->fep.data == NULL) {
262 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
266 sc->status = DIGI_STATUS_NOTINIT;
270 * We're re-initialising - maybe because someone's attached
271 * another port module. For now, we just re-initialise
280 ptr = sc->setwin(sc, MISCGLOBAL);
281 for (i = 0; i < 16; i += 2)
286 outb(sc->wport, 0xff); /* window 7 */
287 ptr = sc->vmem + (BIOSCODE & 0x1fff);
289 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
290 device_printf(sc->dev, "BIOS upload failed\n");
294 outb(sc->port, FEPCLR);
300 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
301 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
302 device_printf(sc->dev, "BIOS upload failed\n");
313 outb(sc->port, FEPRST | FEPMEM);
315 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
316 FEPMASK) != FEPRST; i++) {
318 log(LOG_ERR, "digi%d: %s init reset failed\n",
319 sc->res.unit, sc->name);
322 digi_delay(sc, "digiinit0", 5);
324 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
326 /* Now upload the BIOS */
327 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
328 sc->bios.size : sc->win_size - BIOSOFFSET;
330 ptr = sc->setwin(sc, BIOSOFFSET);
331 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
332 device_printf(sc->dev, "BIOS upload (1) failed\n");
336 if (cnt != sc->bios.size) {
337 /* and the second part */
338 ptr = sc->setwin(sc, sc->win_size);
339 if (!digi_bcopy(sc->bios.data + cnt, ptr,
340 sc->bios.size - cnt)) {
341 device_printf(sc->dev, "BIOS upload failed\n");
346 ptr = sc->setwin(sc, 0);
347 vW(ptr + 0) = 0x0401;
348 vW(ptr + 2) = 0x0bf0;
349 vW(ptr + 4) = 0x0000;
350 vW(ptr + 6) = 0x0000;
355 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
357 ptr = sc->setwin(sc, MISCGLOBAL);
363 } else if (sc->model == PCXEVE) {
364 outb(sc->port, FEPCLR);
367 outb(sc->port, FEPCLR | FEPMEM);
368 resp = FEPRST | FEPMEM;
371 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
374 log(LOG_ERR, "digi%d: BIOS start failed\n",
378 digi_delay(sc, "digibios0", 5);
381 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
383 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
385 log(LOG_ERR, "digi%d: BIOS boot failed "
386 "(0x%02x != 0x%02x)\n",
387 sc->res.unit, vW(ptr), *(u_short *)"GD");
390 digi_delay(sc, "digibios1", 5);
393 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
395 if (sc->link.data != NULL) {
396 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
397 ptr = sc->setwin(sc, 0xcd0);
398 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
407 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
408 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
410 /* A BIOS request to move our data to 0x2000 */
411 ptr = sc->setwin(sc, MBOX);
413 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
415 vW(ptr + 6) = FEPCODESEG;
417 vW(ptr + 10) = sc->fep.size;
419 /* Run the BIOS request */
420 outb(sc->port, FEPREQ | FEPMEM);
421 outb(sc->port, FEPCLR | FEPMEM);
423 for (i = 0; W(ptr); i++) {
425 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
430 digi_delay(sc, "digifep0", 5);
433 (sc->dev, "FEP/OS moved after %d iterations\n", i));
435 /* Clear the confirm word */
436 ptr = sc->setwin(sc, FEPSTAT);
439 /* A BIOS request to execute the FEP/OS */
440 ptr = sc->setwin(sc, MBOX);
442 vW(ptr + 2) = FEPCODESEG;
445 /* Run the BIOS request */
446 outb(sc->port, FEPREQ);
447 outb(sc->port, FEPCLR);
449 ptr = sc->setwin(sc, FEPSTAT);
456 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
458 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
459 sc->fep.size : sc->win_size - BIOSOFFSET;
461 ptr = sc->setwin(sc, BIOSOFFSET);
462 digi_bcopy(sc->fep.data, ptr, cnt);
464 if (cnt != sc->fep.size) {
465 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
466 digi_bcopy(sc->fep.data + cnt, ptr,
470 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
472 ptr = sc->setwin(sc, 0xc30);
478 /* Clear the confirm word */
479 ptr = sc->setwin(sc, FEPSTAT);
483 outb(sc->port, 0); /* XXX necessary ? */
488 ptr = sc->setwin(sc, 0xd000);
489 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
491 /* A BIOS request to execute the FEP/OS */
492 ptr = sc->setwin(sc, 0xc40);
494 W(ptr + 2) = FEPCODE >> 4;
497 /* Clear the confirm word */
498 ptr = sc->setwin(sc, FEPSTAT);
501 /* Run the BIOS request */
502 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
503 outb(sc->port, FEPCLR | FEPMEM);
507 /* Now wait 'till the FEP/OS has booted */
508 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
510 log(LOG_ERR, "digi%d: FEP/OS start failed "
511 "(0x%02x != 0x%02x)\n",
512 sc->res.unit, vW(ptr), *(u_short *)"OS");
516 digi_delay(sc, "digifep1", 5);
519 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
521 if (sc->model >= PCXEM) {
522 ptr = sc->setwin(sc, 0xe04);
524 ptr = sc->setwin(sc, 0xc02);
525 sc->numports = vW(ptr);
527 ptr = sc->setwin(sc, 0xc22);
528 sc->numports = vW(ptr);
531 if (sc->numports == 0) {
532 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
537 if (sc->numports > 256) {
538 /* Our minor numbering scheme is broken for more than 256 */
539 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
540 sc->name, sc->numports);
543 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
547 kfree(sc->ports, M_TTYS);
548 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
549 M_TTYS, M_WAITOK | M_ZERO);
552 kfree(sc->ttys, M_TTYS);
553 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
554 M_TTYS, M_WAITOK | M_ZERO);
557 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
558 * port. If the value is 0, the port is broken....
561 ptr = sc->setwin(sc, 0);
563 /* We should now init per-port structures */
564 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
565 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
567 sc->memcmd = ptr + sc->gdata->cstart;
568 sc->memevent = ptr + sc->gdata->istart;
570 for (i = 0; i < sc->numports; i++, bc++) {
571 port = sc->ports + i;
574 port->status = ENABLED;
575 port->tp = sc->ttys + i;
578 if (sc->model == PCXEVE) {
580 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
582 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
583 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
584 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
585 } else if (sc->model == PCXI || sc->model == PCXE) {
586 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
587 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
588 port->txwin = port->rxwin = 0;
591 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
593 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
594 port->txwin = FEPWIN |
595 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
596 port->rxwin = FEPWIN |
597 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
599 port->txbufsize = bc->tmax + 1;
600 port->rxbufsize = bc->rmax + 1;
602 lowwater = port->txbufsize >> 2;
606 fepcmd_w(port, STXLWATER, lowwater, 10);
607 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
608 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
611 port->dtr_wait = 3 * hz;
614 * We don't use all the flags from <sys/ttydefaults.h> since
615 * they are only relevant for logins. It's important to have
616 * echo off initially so that the line doesn't start blathering
617 * before the echo flag can be turned off.
619 port->it_in.c_iflag = 0;
620 port->it_in.c_oflag = 0;
621 port->it_in.c_cflag = TTYDEF_CFLAG;
622 port->it_in.c_lflag = 0;
623 termioschars(&port->it_in);
624 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
625 port->it_out = port->it_in;
626 port->send_ring = 1; /* Default action on signal RI */
628 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
629 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
630 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
631 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
632 0600, "ttyiD%d.%d", sc->res.unit, i);
633 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
634 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
635 0600, "ttylD%d.%d", sc->res.unit, i);
636 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
637 CALLOUT_MASK, UID_UUCP, GID_DIALER,
638 0660, "cuaD%d.%d", sc->res.unit, i);
639 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
640 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
641 0660, "cuaiD%d.%d", sc->res.unit, i);
642 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
643 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
644 0660, "cualD%d.%d", sc->res.unit, i);
648 callout_reset(&sc->inttest, hz, digi_int_test, sc);
649 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
650 sc->status = DIGI_STATUS_ENABLED;
656 * NOTE: Must be called with tty_token held
659 digimctl(struct digi_p *port, int bits, int how)
663 ASSERT_LWKT_TOKEN_HELD(&tty_token);
665 port->sc->setwin(port->sc, 0);
666 mstat = port->bc->mstat;
667 port->sc->hidewin(port->sc);
669 if (mstat & port->sc->csigs->rts)
671 if (mstat & port->cd)
673 if (mstat & port->dsr)
675 if (mstat & port->sc->csigs->cts)
677 if (mstat & port->sc->csigs->ri)
679 if (mstat & port->sc->csigs->dtr)
684 /* Only DTR and RTS may be set */
686 if (bits & TIOCM_DTR)
687 mstat |= port->sc->csigs->dtr;
688 if (bits & TIOCM_RTS)
689 mstat |= port->sc->csigs->rts;
693 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
696 fepcmd_b(port, SETMODEM, mstat, 0, 0);
699 fepcmd_b(port, SETMODEM, 0, mstat, 0);
707 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
709 lwkt_gettoken(&tty_token);
710 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
711 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
712 (!(t->c_iflag & PARMRK) ||
713 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
714 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
715 linesw[tp->t_line].l_rint == ttyinput)
716 tp->t_state |= TS_CAN_BYPASS_L_RINT;
718 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
719 lwkt_reltoken(&tty_token);
723 digiopen(struct dev_open_args *ap)
725 cdev_t dev = ap->a_head.a_dev;
726 struct digi_softc *sc;
732 volatile struct board_chan *bc;
736 unit = MINOR_TO_UNIT(minor(dev));
737 pnum = MINOR_TO_PORT(minor(dev));
739 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
743 lwkt_gettoken(&tty_token);
744 if (sc->status != DIGI_STATUS_ENABLED) {
745 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
746 lwkt_reltoken(&tty_token);
749 if (pnum >= sc->numports) {
750 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
751 lwkt_reltoken(&tty_token);
754 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
756 lwkt_reltoken(&tty_token);
759 port = &sc->ports[pnum];
760 tp = dev->si_tty = port->tp;
766 while (port->status & DIGI_DTR_OFF) {
768 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
774 if (tp->t_state & TS_ISOPEN) {
776 * The device is open, so everything has been initialized.
779 if (mynor & CALLOUT_MASK) {
780 if (!port->active_out) {
782 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
783 " BUSY error = %d\n", pnum, error));
786 } else if (port->active_out) {
787 if (ap->a_oflags & O_NONBLOCK) {
789 DLOG(DIGIDB_OPEN, (sc->dev,
790 "port %d: BUSY error = %d\n", pnum, error));
794 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
797 DLOG(DIGIDB_OPEN, (sc->dev,
798 "port %d: tsleep(digibi) error = %d\n",
804 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0) != 0) {
810 * The device isn't open, so there are no conflicts.
811 * Initialize it. Initialization is done twice in many
812 * cases: to preempt sleeping callin opens if we are callout,
813 * and to complete a callin open after DCD rises.
815 callout_init_mp(&port->wakeupco);
816 tp->t_oproc = digistart;
817 tp->t_param = digiparam;
818 tp->t_stop = digistop;
820 tp->t_termios = (mynor & CALLOUT_MASK) ?
821 port->it_out : port->it_in;
824 bc->rout = bc->rin; /* clear input queue */
828 bc->mint = port->cd | port->sc->csigs->ri;
831 port->cd = sc->csigs->dsr;
832 port->dsr = sc->csigs->cd;
834 port->cd = sc->csigs->cd;
835 port->dsr = sc->csigs->dsr;
837 port->wopeners++; /* XXX required ? */
838 error = digiparam(tp, &tp->t_termios);
842 DLOG(DIGIDB_OPEN, (sc->dev,
843 "port %d: cxpparam error = %d\n", pnum, error));
848 /* handle fake and initial DCD for callout devices */
850 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
851 linesw[tp->t_line].l_modem(tp, 1);
854 /* Wait for DCD if necessary */
855 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
856 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
858 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
861 DLOG(DIGIDB_OPEN, (sc->dev,
862 "port %d: tsleep(digidcd) error = %d\n",
868 error = linesw[tp->t_line].l_open(dev, tp);
869 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
872 digi_disc_optim(tp, &tp->t_termios, port);
874 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
875 port->active_out = TRUE;
877 if (tp->t_state & TS_ISOPEN)
882 if (!(tp->t_state & TS_ISOPEN))
885 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
888 lwkt_reltoken(&tty_token);
893 digiclose(struct dev_close_args *ap)
895 cdev_t dev = ap->a_head.a_dev;
899 struct digi_softc *sc;
902 lwkt_gettoken(&tty_token);
904 unit = MINOR_TO_UNIT(mynor);
905 pnum = MINOR_TO_PORT(mynor);
907 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
908 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
910 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
912 lwkt_reltoken(&tty_token);
916 port = sc->ports + pnum;
919 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
922 linesw[tp->t_line].l_close(tp, ap->a_fflag);
923 digi_disc_optim(tp, &tp->t_termios, port);
924 digistop(tp, FREAD | FWRITE);
929 lwkt_reltoken(&tty_token);
934 digidtrwakeup(void *chan)
936 struct digi_p *port = chan;
938 lwkt_gettoken(&tty_token);
939 port->status &= ~DIGI_DTR_OFF;
940 wakeup(&port->dtr_wait);
942 lwkt_reltoken(&tty_token);
946 * NOTE: Must be called with tty_token held
949 digihardclose(struct digi_p *port)
951 volatile struct board_chan *bc;
953 ASSERT_LWKT_TOKEN_HELD(&tty_token);
957 port->sc->setwin(port->sc, 0);
962 if ((port->tp->t_cflag & HUPCL) ||
963 (!port->active_out && !(bc->mstat & port->cd) &&
964 !(port->it_in.c_cflag & CLOCAL)) ||
965 !(port->tp->t_state & TS_ISOPEN)) {
966 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
967 if (port->dtr_wait != 0) {
968 /* Schedule a wakeup of any callin devices */
970 callout_reset(&port->wakeupco, port->dtr_wait,
971 digidtrwakeup, port);
972 port->status |= DIGI_DTR_OFF;
975 port->active_out = FALSE;
976 wakeup(&port->active_out);
977 wakeup(TSA_CARR_ON(port->tp));
982 digiread(struct dev_read_args *ap)
984 cdev_t dev = ap->a_head.a_dev;
987 int error, unit, pnum;
988 struct digi_softc *sc;
991 if (mynor & CONTROL_MASK)
994 lwkt_gettoken(&tty_token);
995 unit = MINOR_TO_UNIT(mynor);
996 pnum = MINOR_TO_PORT(mynor);
998 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
999 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
1000 tp = &sc->ttys[pnum];
1002 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
1003 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
1006 lwkt_reltoken(&tty_token);
1011 digiwrite(struct dev_write_args *ap)
1013 cdev_t dev = ap->a_head.a_dev;
1016 int error, unit, pnum;
1017 struct digi_softc *sc;
1020 if (mynor & CONTROL_MASK)
1023 lwkt_gettoken(&tty_token);
1024 unit = MINOR_TO_UNIT(mynor);
1025 pnum = MINOR_TO_PORT(mynor);
1027 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1028 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
1029 tp = &sc->ttys[pnum];
1031 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1032 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1035 lwkt_reltoken(&tty_token);
1040 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1042 * Populate sc->bios, sc->fep, and sc->link from this data.
1044 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1045 * to their respective sizes.
1047 * The module is unloaded when we're done.
1050 digi_loaddata(struct digi_softc *sc)
1052 struct digi_bios *bios;
1054 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1055 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1056 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1057 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1059 for (bios = digi_bioses; bios->model != NULL; bios++) {
1060 if (!strcmp(bios->model, sc->module))
1063 if (bios->model == NULL) {
1064 kprintf("digi.ko: driver %s not found", sc->module);
1068 sc->bios.size = bios->bios_size;
1069 if (sc->bios.size != 0 && bios->bios != NULL) {
1070 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1071 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1074 sc->fep.size = bios->fep_size;
1075 if (sc->fep.size != 0 && bios->fep != NULL) {
1076 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1077 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1084 digiioctl(struct dev_ioctl_args *ap)
1086 cdev_t dev = ap->a_head.a_dev;
1087 u_long cmd = ap->a_cmd;
1088 caddr_t data = ap->a_data;
1089 int unit, pnum, mynor, error, ret;
1090 struct digi_softc *sc;
1091 struct digi_p *port;
1093 #if defined(COMPAT_43)
1095 struct termios term;
1099 unit = MINOR_TO_UNIT(mynor);
1100 pnum = MINOR_TO_PORT(mynor);
1102 lwkt_gettoken(&tty_token);
1103 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1104 KASSERT(sc, ("digi%d: softc not allocated in digiioctl", unit));
1106 if (sc->status == DIGI_STATUS_DISABLED) {
1107 lwkt_reltoken(&tty_token);
1111 if (mynor & CTRL_DEV) {
1115 digi_debug = *(int *)data;
1116 lwkt_reltoken(&tty_token);
1119 device_printf(sc->dev, "DEBUG not defined\n");
1120 lwkt_reltoken(&tty_token);
1125 error = digi_init(sc);
1127 lwkt_reltoken(&tty_token);
1131 *(enum digi_model *)data = sc->model;
1132 lwkt_reltoken(&tty_token);
1136 ret = copyout(sc->name, *(char **)data,
1137 strlen(sc->name) + 1);
1138 lwkt_reltoken(&tty_token);
1143 if (pnum >= sc->numports) {
1144 lwkt_reltoken(&tty_token);
1148 port = sc->ports + pnum;
1149 if (!(port->status & ENABLED)) {
1150 lwkt_reltoken(&tty_token);
1156 if (mynor & CONTROL_MASK) {
1159 switch (mynor & CONTROL_MASK) {
1160 case CONTROL_INIT_STATE:
1161 ct = (mynor & CALLOUT_MASK) ?
1162 &port->it_out : &port->it_in;
1164 case CONTROL_LOCK_STATE:
1165 ct = (mynor & CALLOUT_MASK) ?
1166 &port->lt_out : &port->lt_in;
1169 lwkt_reltoken(&tty_token);
1170 return (ENODEV); /* /dev/nodev */
1175 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1177 lwkt_reltoken(&tty_token);
1180 *ct = *(struct termios *)data;
1181 lwkt_reltoken(&tty_token);
1185 *(struct termios *)data = *ct;
1186 lwkt_reltoken(&tty_token);
1190 *(int *)data = TTYDISC;
1191 lwkt_reltoken(&tty_token);
1195 bzero(data, sizeof(struct winsize));
1196 lwkt_reltoken(&tty_token);
1199 case DIGIIO_GETALTPIN:
1200 switch (mynor & CONTROL_MASK) {
1201 case CONTROL_INIT_STATE:
1202 *(int *)data = port->ialtpin;
1205 case CONTROL_LOCK_STATE:
1206 *(int *)data = port->laltpin;
1210 panic("Confusion when re-testing minor");
1211 lwkt_reltoken(&tty_token);
1214 lwkt_reltoken(&tty_token);
1217 case DIGIIO_SETALTPIN:
1218 switch (mynor & CONTROL_MASK) {
1219 case CONTROL_INIT_STATE:
1220 if (!port->laltpin) {
1221 port->ialtpin = !!*(int *)data;
1222 DLOG(DIGIDB_SET, (sc->dev,
1223 "port%d: initial ALTPIN %s\n", pnum,
1224 port->ialtpin ? "set" : "cleared"));
1228 case CONTROL_LOCK_STATE:
1229 port->laltpin = !!*(int *)data;
1230 DLOG(DIGIDB_SET, (sc->dev,
1231 "port%d: ALTPIN %slocked\n",
1232 pnum, port->laltpin ? "" : "un"));
1236 panic("Confusion when re-testing minor");
1237 lwkt_reltoken(&tty_token);
1240 lwkt_reltoken(&tty_token);
1244 lwkt_reltoken(&tty_token);
1250 case DIGIIO_GETALTPIN:
1251 *(int *)data = !!(port->dsr == sc->csigs->cd);
1252 lwkt_reltoken(&tty_token);
1255 case DIGIIO_SETALTPIN:
1256 if (!port->laltpin) {
1258 DLOG(DIGIDB_SET, (sc->dev,
1259 "port%d: ALTPIN set\n", pnum));
1260 port->cd = sc->csigs->dsr;
1261 port->dsr = sc->csigs->cd;
1263 DLOG(DIGIDB_SET, (sc->dev,
1264 "port%d: ALTPIN cleared\n", pnum));
1265 port->cd = sc->csigs->cd;
1266 port->dsr = sc->csigs->dsr;
1269 lwkt_reltoken(&tty_token);
1274 #if defined(COMPAT_43)
1275 term = tp->t_termios;
1277 error = ttsetcompat(tp, &cmd, data, &term);
1279 lwkt_reltoken(&tty_token);
1283 data = (caddr_t) & term;
1285 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1290 dt = (struct termios *)data;
1291 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1294 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1296 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1298 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1300 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1301 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1302 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1303 for (cc = 0; cc < NCCS; ++cc)
1304 if (lt->c_cc[cc] != 0)
1305 dt->c_cc[cc] = tp->t_cc[cc];
1306 if (lt->c_ispeed != 0)
1307 dt->c_ispeed = tp->t_ispeed;
1308 if (lt->c_ospeed != 0)
1309 dt->c_ospeed = tp->t_ospeed;
1311 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1312 ap->a_fflag, ap->a_cred);
1313 if (error == 0 && cmd == TIOCGETA)
1314 ((struct termios *)data)->c_iflag |= port->c_iflag;
1316 if (error >= 0 && error != ENOIOCTL) {
1317 lwkt_reltoken(&tty_token);
1321 error = ttioctl(tp, cmd, data, ap->a_fflag);
1322 if (error == 0 && cmd == TIOCGETA)
1323 ((struct termios *)data)->c_iflag |= port->c_iflag;
1325 digi_disc_optim(tp, &tp->t_termios, port);
1326 if (error >= 0 && error != ENOIOCTL) {
1328 lwkt_reltoken(&tty_token);
1334 port->send_ring = *(u_char *)data;
1338 * now it sends 400 millisecond break because I don't know
1339 * how to send an infinite break
1341 fepcmd_w(port, SENDBREAK, 400, 10);
1344 /* now it's empty */
1347 digimctl(port, TIOCM_DTR, DMBIS);
1350 digimctl(port, TIOCM_DTR, DMBIC);
1353 digimctl(port, *(int *)data, DMSET);
1356 digimctl(port, *(int *)data, DMBIS);
1359 digimctl(port, *(int *)data, DMBIC);
1362 *(int *)data = digimctl(port, 0, DMGET);
1365 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1368 lwkt_reltoken(&tty_token);
1371 port->dtr_wait = *(int *)data *hz / 100;
1375 *(int *)data = port->dtr_wait * 100 / hz;
1377 #ifdef DIGI_INTERRUPT
1379 *(struct timeval *)data = sc->intr_timestamp;
1385 lwkt_reltoken(&tty_token);
1389 lwkt_reltoken(&tty_token);
1394 digiparam(struct tty *tp, struct termios *t)
1399 struct digi_softc *sc;
1400 struct digi_p *port;
1406 lwkt_gettoken(&tty_token);
1407 mynor = minor(tp->t_dev);
1408 unit = MINOR_TO_UNIT(mynor);
1409 pnum = MINOR_TO_PORT(mynor);
1411 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1412 KASSERT(sc, ("digi%d: softc not allocated in digiparam", unit));
1414 port = &sc->ports[pnum];
1416 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1418 if (t->c_ispeed == 0)
1419 t->c_ispeed = t->c_ospeed;
1421 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1423 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed)) {
1424 lwkt_reltoken(&tty_token);
1430 window = sc->window;
1433 if (cflag == 0) { /* hangup */
1434 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1435 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1437 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1439 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1443 /* convert flags to sysV-style values */
1444 if (t->c_cflag & PARODD)
1446 if (t->c_cflag & PARENB)
1448 if (t->c_cflag & CSTOPB)
1451 /* convert flags to sysV-style values */
1452 if (t->c_cflag & PARODD)
1453 cflag |= FEP_PARODD;
1454 if (t->c_cflag & PARENB)
1455 cflag |= FEP_PARENB;
1456 if (t->c_cflag & CSTOPB)
1457 cflag |= FEP_CSTOPB;
1458 if (t->c_cflag & CLOCAL)
1459 cflag |= FEP_CLOCAL;
1462 cflag |= (t->c_cflag & CSIZE) >> 4;
1463 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1465 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1469 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1470 if (port->c_iflag & IXON)
1472 if (port->c_iflag & IXANY)
1474 if (port->c_iflag & IXOFF)
1477 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1478 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1481 if (t->c_cflag & CDTR_IFLOW)
1482 hflow |= sc->csigs->dtr;
1483 if (t->c_cflag & CRTS_IFLOW)
1484 hflow |= sc->csigs->rts;
1485 if (t->c_cflag & CCTS_OFLOW)
1486 hflow |= sc->csigs->cts;
1487 if (t->c_cflag & CDSR_OFLOW)
1489 if (t->c_cflag & CCAR_OFLOW)
1492 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1493 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1495 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1496 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1497 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1499 if (sc->window != 0)
1502 sc->towin(sc, window);
1505 lwkt_reltoken(&tty_token);
1512 struct digi_p *port;
1514 struct digi_softc *sc;
1516 volatile struct board_chan *bc;
1528 lwkt_gettoken(&tty_token);
1531 if (sc->status != DIGI_STATUS_ENABLED) {
1532 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1533 lwkt_reltoken(&tty_token);
1537 #ifdef DIGI_INTERRUPT
1538 microtime(&sc->intr_timestamp);
1541 window = sc->window;
1544 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1545 struct con_bios *con = con_bios_list;
1548 ptr = sc->vmem + W(sc->vmem + 0xd00);
1550 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1551 /* Not first block -- exact match */
1554 if (W(ptr + 4) >= W(con->bios + 4) &&
1555 W(ptr + 4) <= W(con->bios + 6))
1556 /* Initial search concetrator BIOS */
1561 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1562 " not found!\n", sc->res.unit, W(ptr + 4));
1564 W(sc->vmem + 0xd00) = 0;
1568 W(ptr + 4) = W(cxcon + 4);
1569 W(ptr + 6) = W(cxcon + 6);
1571 W(ptr + 2) = W(cxcon + 2);
1572 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1573 size = W(cxcon + 10) - (ptr[1] << 10);
1575 W(ptr + 8) = W(cxcon + 8);
1581 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1583 W(sc->vmem + 0xd00) = 0;
1587 ehead = sc->gdata->ein;
1588 etail = sc->gdata->eout;
1589 if (ehead == etail) {
1592 if (sc->intr_count % 6000 == 0) {
1593 DLOG(DIGIDB_IRQ, (sc->dev,
1594 "6000 useless polls %x %x\n", ehead, etail));
1600 while (ehead != etail) {
1601 event = *(volatile struct event *)(sc->memevent + etail);
1603 etail = (etail + 4) & sc->gdata->imax;
1605 if (event.pnum >= sc->numports) {
1606 log(LOG_ERR, "digi%d: port %d: got event"
1607 " on nonexisting port\n", sc->res.unit,
1611 port = &sc->ports[event.pnum];
1615 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1616 DLOG(DIGIDB_IRQ, (sc->dev,
1617 "port %d: event 0x%x on closed port\n",
1618 event.pnum, event.event));
1626 if (event.event & ~ALL_IND)
1627 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1628 " lstat 0x%x\n", sc->res.unit, event.pnum,
1629 event.event, event.mstat, event.lstat);
1631 if (event.event & DATA_IND) {
1632 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1634 wrapmask = port->rxbufsize - 1;
1639 if (!(tp->t_state & TS_ISOPEN)) {
1643 while (head != tail) {
1646 DLOG(DIGIDB_INT, (sc->dev,
1647 "port %d: p rx head = %d tail = %d\n",
1648 event.pnum, head, tail));
1649 top = (head > tail) ? head : wrapmask + 1;
1650 sc->towin(sc, port->rxwin);
1652 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1653 size = b_to_q((char *)port->rxbuf +
1654 tail, size, &tp->t_rawq);
1657 } else for (; tail < top;) {
1659 l_rint(port->rxbuf[tail], tp);
1660 sc->towin(sc, port->rxwin);
1663 if (tp->t_state & TS_TBLOCK)
1675 CE_RECORD(port, CE_OVERRUN);
1676 log(LOG_ERR, "digi%d: port%d: %s\n",
1677 sc->res.unit, event.pnum,
1678 digi_errortxt(CE_OVERRUN));
1683 tp->t_state |= TS_TBLOCK;
1684 port->status |= PAUSE_RX;
1685 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1692 if (event.event & MODEMCHG_IND) {
1693 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1696 if ((event.mstat ^ event.lstat) & port->cd) {
1698 linesw[tp->t_line].l_modem
1699 (tp, event.mstat & port->cd);
1701 wakeup(TSA_CARR_ON(tp));
1704 if (event.mstat & sc->csigs->ri) {
1705 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1707 if (port->send_ring) {
1708 linesw[tp->t_line].l_rint('R', tp);
1709 linesw[tp->t_line].l_rint('I', tp);
1710 linesw[tp->t_line].l_rint('N', tp);
1711 linesw[tp->t_line].l_rint('G', tp);
1712 linesw[tp->t_line].l_rint('\r', tp);
1713 linesw[tp->t_line].l_rint('\n', tp);
1717 if (event.event & BREAK_IND) {
1718 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1720 linesw[tp->t_line].l_rint(TTY_BI, tp);
1722 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1723 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1725 event.event & LOWTX_IND ? " LOWTX" : "",
1726 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1727 (*linesw[tp->t_line].l_start)(tp);
1730 sc->gdata->eout = etail;
1732 if (sc->window != 0)
1735 sc->towin(sc, window);
1736 lwkt_reltoken(&tty_token);
1740 digistart(struct tty *tp)
1744 struct digi_p *port;
1745 struct digi_softc *sc;
1746 volatile struct board_chan *bc;
1748 int size, ocount, totcnt = 0;
1751 lwkt_gettoken(&tty_token);
1752 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1753 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1755 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1756 KASSERT(sc, ("digi%d: softc not allocated in digistart", unit));
1758 port = &sc->ports[pnum];
1761 wmask = port->txbufsize - 1;
1764 port->lcc = tp->t_outq.c_cc;
1766 if (!(tp->t_state & TS_TBLOCK)) {
1767 if (port->status & PAUSE_RX) {
1768 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1771 * CAREFUL - braces are needed here if the DLOG is
1775 port->status &= ~PAUSE_RX;
1778 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1779 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1780 port->status &= ~PAUSE_TX;
1781 fepcmd_w(port, RESUMETX, 0, 10);
1783 if (tp->t_outq.c_cc == 0)
1784 tp->t_state &= ~TS_BUSY;
1786 tp->t_state |= TS_BUSY;
1789 while (tp->t_outq.c_cc != 0) {
1791 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1795 size = tail - head - 1;
1797 size = port->txbufsize - head;
1804 sc->towin(sc, port->txwin);
1805 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1814 port->lostcc = tp->t_outq.c_cc;
1817 size = port->txbufsize - tail + head;
1822 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1825 lwkt_reltoken(&tty_token);
1829 digistop(struct tty *tp, int rw)
1831 struct digi_softc *sc;
1834 struct digi_p *port;
1836 lwkt_gettoken(&tty_token);
1837 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1838 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1840 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1841 KASSERT(sc, ("digi%d: softc not allocated in digistop", unit));
1842 port = sc->ports + pnum;
1844 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1845 port->status |= PAUSE_TX;
1846 fepcmd_w(port, PAUSETX, 0, 10);
1847 lwkt_reltoken(&tty_token);
1851 * NOTE: Must be called with tty_token held
1854 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1857 unsigned tail, head;
1860 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1861 mem = port->sc->memcmd;
1863 port->sc->setwin(port->sc, 0);
1865 head = port->sc->gdata->cin;
1866 mem[head + 0] = cmd;
1867 mem[head + 1] = port->pnum;
1868 *(u_short *)(mem + head + 2) = op1;
1870 head = (head + 4) & port->sc->gdata->cmax;
1871 port->sc->gdata->cin = head;
1873 for (count = FEPTIMEOUT; count > 0; count--) {
1874 head = port->sc->gdata->cin;
1875 tail = port->sc->gdata->cout;
1876 n = (head - tail) & port->sc->gdata->cmax;
1878 if (n <= ncmds * sizeof(short) * 4)
1882 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1883 port->sc->res.unit, port->pnum);
1887 digi_errortxt(int id)
1889 static const char *error_desc[] = {
1891 "interrupt-level buffer overflow",
1892 "tty-level buffer overflow",
1895 KASSERT(id >= 0 && id < NELEM(error_desc),
1896 ("Unexpected digi error id %d\n", id));
1898 return (error_desc[id]);
1902 digi_attach(struct digi_softc *sc)
1904 lwkt_gettoken(&tty_token);
1905 sc->res.ctldev = make_dev(&digi_ops,
1906 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1907 0600, "digi%r.ctl", sc->res.unit);
1913 lwkt_reltoken(&tty_token);
1918 * NOTE: Must be called with tty_token held
1921 digi_inuse(struct digi_softc *sc)
1925 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1926 for (i = 0; i < sc->numports; i++)
1927 if (sc->ttys[i].t_state & TS_ISOPEN) {
1928 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1930 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1931 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1939 * NOTE: Must be called with tty_token held
1942 digi_free_state(struct digi_softc *sc)
1946 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1947 /* Blow it all away */
1949 for (i = 0; i < sc->numports; i++)
1950 for (d = 0; d < 6; d++)
1951 destroy_dev(sc->ports[i].dev[d]);
1953 callout_stop(&sc->callout);
1954 callout_stop(&sc->inttest);
1956 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1957 #ifdef DIGI_INTERRUPT
1958 if (sc->res.irq != NULL) {
1959 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1965 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1966 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1967 kfree(sc->ports, M_TTYS);
1969 kfree(sc->ttys, M_TTYS);
1974 sc->status = DIGI_STATUS_NOTINIT;
1978 digi_detach(device_t dev)
1980 struct digi_softc *sc = device_get_softc(dev);
1982 lwkt_gettoken(&tty_token);
1983 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1985 /* If we're INIT'd, numports must be 0 */
1986 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1987 ("digi%d: numports(%d) & status(%d) are out of sync",
1988 sc->res.unit, sc->numports, (int)sc->status));
1990 if (digi_inuse(sc)) {
1991 lwkt_reltoken(&tty_token);
1995 digi_free_state(sc);
1997 destroy_dev(sc->res.ctldev);
1999 if (sc->res.mem != NULL) {
2000 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
2004 if (sc->res.io != NULL) {
2005 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
2010 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
2014 lwkt_reltoken(&tty_token);
2019 digi_shutdown(device_t dev)
2024 MODULE_VERSION(digi, 1);