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>
56 #include <sys/thread2.h>
61 #include <dev/serial/digi/digiio.h>
62 #include <dev/serial/digi/digireg.h>
63 #include <dev/serial/digi/digi.h>
64 #include <dev/serial/digi/digi_pci.h>
65 #include <dev/serial/digi/digi_bios.h>
67 #define CTRL_DEV 0x800000
68 #define CALLOUT_MASK 0x400000
69 #define CONTROL_INIT_STATE 0x100000
70 #define CONTROL_LOCK_STATE 0x200000
71 #define CONTROL_MASK (CTRL_DEV|CONTROL_INIT_STATE|CONTROL_LOCK_STATE)
72 #define UNIT_MASK 0x030000
73 #define PORT_MASK 0x0000FF
74 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
75 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
76 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
77 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
79 static d_open_t digiopen;
80 static d_close_t digiclose;
81 static d_read_t digiread;
82 static d_write_t digiwrite;
83 static d_ioctl_t digiioctl;
85 static void digistop(struct tty *tp, int rw);
86 static int digimctl(struct digi_p *port, int bits, int how);
87 static void digi_poll(void *ptr);
88 static void digi_freedata(struct digi_softc *);
89 static void fepcmd(struct digi_p *port, int cmd, int op, int ncmds);
90 static void digistart(struct tty *tp);
91 static int digiparam(struct tty *tp, struct termios *t);
92 static void digihardclose(struct digi_p *port);
93 static void digi_intr(void *);
94 static int digi_init(struct digi_softc *_sc);
95 static int digi_loaddata(struct digi_softc *);
96 static int digi_inuse(struct digi_softc *);
97 static void digi_free_state(struct digi_softc *);
99 #define fepcmd_b(port, cmd, op1, op2, ncmds) \
100 fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
101 #define fepcmd_w fepcmd
104 static speed_t digidefaultrate = TTYDEF_SPEED;
107 struct con_bios *next;
112 static struct con_bios *con_bios_list;
113 devclass_t digi_devclass;
114 unsigned digi_debug = 0;
116 static struct speedtab digispeedtab[] = {
117 { 0, 0}, /* old (sysV-like) Bx codes */
133 { 57600, (02000 | 1)},
134 { 76800, (02000 | 2)},
135 { 115200, (02000 | 3)},
136 { 230400, (02000 | 6)},
140 const struct digi_control_signals digi_xixe_signals = {
141 0x02, 0x08, 0x10, 0x20, 0x40, 0x80
144 const struct digi_control_signals digi_normal_signals = {
145 0x02, 0x80, 0x20, 0x10, 0x40, 0x01
148 static struct dev_ops digi_ops = {
151 .d_close = digiclose,
153 .d_write = digiwrite,
154 .d_ioctl = digiioctl,
155 .d_kqfilter = ttykqfilter,
156 .d_revoke = ttyrevoke
162 struct digi_softc *sc;
164 sc = (struct digi_softc *)ptr;
165 callout_init_mp(&sc->callout);
167 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
171 digi_int_test(void *v)
173 struct digi_softc *sc = v;
175 callout_init_mp(&sc->inttest);
176 #ifdef DIGI_INTERRUPT
177 if (sc->intr_timestamp.tv_sec || sc->intr_timestamp.tv_usec) {
181 log(LOG_ERR, "digi%d: Interrupt didn't work, use polled mode\n", unit);
183 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
187 digi_freedata(struct digi_softc *sc)
189 if (sc->fep.data != NULL) {
190 kfree(sc->fep.data, M_TTYS);
193 if (sc->link.data != NULL) {
194 kfree(sc->link.data, M_TTYS);
195 sc->link.data = NULL;
197 if (sc->bios.data != NULL) {
198 kfree(sc->bios.data, M_TTYS);
199 sc->bios.data = NULL;
204 digi_bcopy(const void *vfrom, void *vto, size_t sz)
206 volatile const char *from = (volatile const char *)vfrom;
207 volatile char *to = (volatile char *)vto;
210 for (i = 0; i < sz; i++)
213 from = (const volatile char *)vfrom;
214 to = (volatile char *)vto;
215 for (i = 0; i < sz; i++)
216 if (*to++ != *from++)
222 digi_delay(struct digi_softc *sc, const char *txt, u_long timo)
225 DELAY(timo * 1000000 / hz);
227 tsleep(sc, PCATCH, txt, timo);
231 * NOTE: Must be called with tty_token held
234 digi_init(struct digi_softc *sc)
240 volatile struct board_chan *bc;
242 ASSERT_LWKT_TOKEN_HELD(&tty_token);
245 if (sc->status == DIGI_STATUS_DISABLED) {
246 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
250 if (sc->bios.data == NULL) {
251 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
256 if (sc->link.data == NULL && sc->model >= PCCX) {
257 log(LOG_ERR, "digi%d: Cannot init without link info\n",
262 if (sc->fep.data == NULL) {
263 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
267 sc->status = DIGI_STATUS_NOTINIT;
271 * We're re-initialising - maybe because someone's attached
272 * another port module. For now, we just re-initialise
281 ptr = sc->setwin(sc, MISCGLOBAL);
282 for (i = 0; i < 16; i += 2)
287 outb(sc->wport, 0xff); /* window 7 */
288 ptr = sc->vmem + (BIOSCODE & 0x1fff);
290 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
291 device_printf(sc->dev, "BIOS upload failed\n");
295 outb(sc->port, FEPCLR);
301 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
302 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
303 device_printf(sc->dev, "BIOS upload failed\n");
314 outb(sc->port, FEPRST | FEPMEM);
316 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
317 FEPMASK) != FEPRST; i++) {
319 log(LOG_ERR, "digi%d: %s init reset failed\n",
320 sc->res.unit, sc->name);
323 digi_delay(sc, "digiinit0", 5);
325 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
327 /* Now upload the BIOS */
328 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
329 sc->bios.size : sc->win_size - BIOSOFFSET;
331 ptr = sc->setwin(sc, BIOSOFFSET);
332 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
333 device_printf(sc->dev, "BIOS upload (1) failed\n");
337 if (cnt != sc->bios.size) {
338 /* and the second part */
339 ptr = sc->setwin(sc, sc->win_size);
340 if (!digi_bcopy(sc->bios.data + cnt, ptr,
341 sc->bios.size - cnt)) {
342 device_printf(sc->dev, "BIOS upload failed\n");
347 ptr = sc->setwin(sc, 0);
348 vW(ptr + 0) = 0x0401;
349 vW(ptr + 2) = 0x0bf0;
350 vW(ptr + 4) = 0x0000;
351 vW(ptr + 6) = 0x0000;
356 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
358 ptr = sc->setwin(sc, MISCGLOBAL);
364 } else if (sc->model == PCXEVE) {
365 outb(sc->port, FEPCLR);
368 outb(sc->port, FEPCLR | FEPMEM);
369 resp = FEPRST | FEPMEM;
372 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
375 log(LOG_ERR, "digi%d: BIOS start failed\n",
379 digi_delay(sc, "digibios0", 5);
382 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
384 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
386 log(LOG_ERR, "digi%d: BIOS boot failed "
387 "(0x%02x != 0x%02x)\n",
388 sc->res.unit, vW(ptr), *(u_short *)"GD");
391 digi_delay(sc, "digibios1", 5);
394 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
396 if (sc->link.data != NULL) {
397 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
398 ptr = sc->setwin(sc, 0xcd0);
399 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
408 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
409 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
411 /* A BIOS request to move our data to 0x2000 */
412 ptr = sc->setwin(sc, MBOX);
414 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
416 vW(ptr + 6) = FEPCODESEG;
418 vW(ptr + 10) = sc->fep.size;
420 /* Run the BIOS request */
421 outb(sc->port, FEPREQ | FEPMEM);
422 outb(sc->port, FEPCLR | FEPMEM);
424 for (i = 0; W(ptr); i++) {
426 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
431 digi_delay(sc, "digifep0", 5);
434 (sc->dev, "FEP/OS moved after %d iterations\n", i));
436 /* Clear the confirm word */
437 ptr = sc->setwin(sc, FEPSTAT);
440 /* A BIOS request to execute the FEP/OS */
441 ptr = sc->setwin(sc, MBOX);
443 vW(ptr + 2) = FEPCODESEG;
446 /* Run the BIOS request */
447 outb(sc->port, FEPREQ);
448 outb(sc->port, FEPCLR);
450 ptr = sc->setwin(sc, FEPSTAT);
457 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
459 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
460 sc->fep.size : sc->win_size - BIOSOFFSET;
462 ptr = sc->setwin(sc, BIOSOFFSET);
463 digi_bcopy(sc->fep.data, ptr, cnt);
465 if (cnt != sc->fep.size) {
466 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
467 digi_bcopy(sc->fep.data + cnt, ptr,
471 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
473 ptr = sc->setwin(sc, 0xc30);
479 /* Clear the confirm word */
480 ptr = sc->setwin(sc, FEPSTAT);
484 outb(sc->port, 0); /* XXX necessary ? */
489 ptr = sc->setwin(sc, 0xd000);
490 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
492 /* A BIOS request to execute the FEP/OS */
493 ptr = sc->setwin(sc, 0xc40);
495 W(ptr + 2) = FEPCODE >> 4;
498 /* Clear the confirm word */
499 ptr = sc->setwin(sc, FEPSTAT);
502 /* Run the BIOS request */
503 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
504 outb(sc->port, FEPCLR | FEPMEM);
508 /* Now wait 'till the FEP/OS has booted */
509 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
511 log(LOG_ERR, "digi%d: FEP/OS start failed "
512 "(0x%02x != 0x%02x)\n",
513 sc->res.unit, vW(ptr), *(u_short *)"OS");
517 digi_delay(sc, "digifep1", 5);
520 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
522 if (sc->model >= PCXEM) {
523 ptr = sc->setwin(sc, 0xe04);
525 ptr = sc->setwin(sc, 0xc02);
526 sc->numports = vW(ptr);
528 ptr = sc->setwin(sc, 0xc22);
529 sc->numports = vW(ptr);
532 if (sc->numports == 0) {
533 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
538 if (sc->numports > 256) {
539 /* Our minor numbering scheme is broken for more than 256 */
540 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
541 sc->name, sc->numports);
544 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
548 kfree(sc->ports, M_TTYS);
549 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
550 M_TTYS, M_WAITOK | M_ZERO);
553 kfree(sc->ttys, M_TTYS);
554 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
555 M_TTYS, M_WAITOK | M_ZERO);
558 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
559 * port. If the value is 0, the port is broken....
562 ptr = sc->setwin(sc, 0);
564 /* We should now init per-port structures */
565 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
566 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
568 sc->memcmd = ptr + sc->gdata->cstart;
569 sc->memevent = ptr + sc->gdata->istart;
571 for (i = 0; i < sc->numports; i++, bc++) {
572 port = sc->ports + i;
575 port->status = ENABLED;
576 port->tp = sc->ttys + i;
579 if (sc->model == PCXEVE) {
581 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
583 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
584 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
585 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
586 } else if (sc->model == PCXI || sc->model == PCXE) {
587 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
588 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
589 port->txwin = port->rxwin = 0;
592 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
594 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
595 port->txwin = FEPWIN |
596 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
597 port->rxwin = FEPWIN |
598 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
600 port->txbufsize = bc->tmax + 1;
601 port->rxbufsize = bc->rmax + 1;
603 lowwater = port->txbufsize >> 2;
607 fepcmd_w(port, STXLWATER, lowwater, 10);
608 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
609 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
612 port->dtr_wait = 3 * hz;
615 * We don't use all the flags from <sys/ttydefaults.h> since
616 * they are only relevant for logins. It's important to have
617 * echo off initially so that the line doesn't start blathering
618 * before the echo flag can be turned off.
620 port->it_in.c_iflag = 0;
621 port->it_in.c_oflag = 0;
622 port->it_in.c_cflag = TTYDEF_CFLAG;
623 port->it_in.c_lflag = 0;
624 termioschars(&port->it_in);
625 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
626 port->it_out = port->it_in;
627 port->send_ring = 1; /* Default action on signal RI */
629 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
630 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
631 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
632 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
633 0600, "ttyiD%d.%d", sc->res.unit, i);
634 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
635 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
636 0600, "ttylD%d.%d", sc->res.unit, i);
637 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
638 CALLOUT_MASK, UID_UUCP, GID_DIALER,
639 0660, "cuaD%d.%d", sc->res.unit, i);
640 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
641 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
642 0660, "cuaiD%d.%d", sc->res.unit, i);
643 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
644 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
645 0660, "cualD%d.%d", sc->res.unit, i);
649 callout_reset(&sc->inttest, hz, digi_int_test, sc);
650 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
651 sc->status = DIGI_STATUS_ENABLED;
657 * NOTE: Must be called with tty_token held
660 digimctl(struct digi_p *port, int bits, int how)
664 ASSERT_LWKT_TOKEN_HELD(&tty_token);
666 port->sc->setwin(port->sc, 0);
667 mstat = port->bc->mstat;
668 port->sc->hidewin(port->sc);
670 if (mstat & port->sc->csigs->rts)
672 if (mstat & port->cd)
674 if (mstat & port->dsr)
676 if (mstat & port->sc->csigs->cts)
678 if (mstat & port->sc->csigs->ri)
680 if (mstat & port->sc->csigs->dtr)
685 /* Only DTR and RTS may be set */
687 if (bits & TIOCM_DTR)
688 mstat |= port->sc->csigs->dtr;
689 if (bits & TIOCM_RTS)
690 mstat |= port->sc->csigs->rts;
694 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
697 fepcmd_b(port, SETMODEM, mstat, 0, 0);
700 fepcmd_b(port, SETMODEM, 0, mstat, 0);
708 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
710 lwkt_gettoken(&tty_token);
711 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
712 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
713 (!(t->c_iflag & PARMRK) ||
714 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
715 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
716 linesw[tp->t_line].l_rint == ttyinput)
717 tp->t_state |= TS_CAN_BYPASS_L_RINT;
719 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
720 lwkt_reltoken(&tty_token);
724 digiopen(struct dev_open_args *ap)
726 cdev_t dev = ap->a_head.a_dev;
727 struct digi_softc *sc;
733 volatile struct board_chan *bc;
737 unit = MINOR_TO_UNIT(minor(dev));
738 pnum = MINOR_TO_PORT(minor(dev));
740 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
744 lwkt_gettoken(&tty_token);
745 if (sc->status != DIGI_STATUS_ENABLED) {
746 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
747 lwkt_reltoken(&tty_token);
750 if (pnum >= sc->numports) {
751 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
752 lwkt_reltoken(&tty_token);
755 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
757 lwkt_reltoken(&tty_token);
760 port = &sc->ports[pnum];
761 tp = dev->si_tty = port->tp;
767 while (port->status & DIGI_DTR_OFF) {
769 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
775 if (tp->t_state & TS_ISOPEN) {
777 * The device is open, so everything has been initialized.
780 if (mynor & CALLOUT_MASK) {
781 if (!port->active_out) {
783 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
784 " BUSY error = %d\n", pnum, error));
787 } else if (port->active_out) {
788 if (ap->a_oflags & O_NONBLOCK) {
790 DLOG(DIGIDB_OPEN, (sc->dev,
791 "port %d: BUSY error = %d\n", pnum, error));
795 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
798 DLOG(DIGIDB_OPEN, (sc->dev,
799 "port %d: tsleep(digibi) error = %d\n",
805 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0) != 0) {
811 * The device isn't open, so there are no conflicts.
812 * Initialize it. Initialization is done twice in many
813 * cases: to preempt sleeping callin opens if we are callout,
814 * and to complete a callin open after DCD rises.
816 callout_init_mp(&port->wakeupco);
817 tp->t_oproc = digistart;
818 tp->t_param = digiparam;
819 tp->t_stop = digistop;
821 tp->t_termios = (mynor & CALLOUT_MASK) ?
822 port->it_out : port->it_in;
825 bc->rout = bc->rin; /* clear input queue */
829 bc->mint = port->cd | port->sc->csigs->ri;
832 port->cd = sc->csigs->dsr;
833 port->dsr = sc->csigs->cd;
835 port->cd = sc->csigs->cd;
836 port->dsr = sc->csigs->dsr;
838 port->wopeners++; /* XXX required ? */
839 error = digiparam(tp, &tp->t_termios);
843 DLOG(DIGIDB_OPEN, (sc->dev,
844 "port %d: cxpparam error = %d\n", pnum, error));
849 /* handle fake and initial DCD for callout devices */
851 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
852 linesw[tp->t_line].l_modem(tp, 1);
855 /* Wait for DCD if necessary */
856 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
857 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
859 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
862 DLOG(DIGIDB_OPEN, (sc->dev,
863 "port %d: tsleep(digidcd) error = %d\n",
869 error = linesw[tp->t_line].l_open(dev, tp);
870 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
873 digi_disc_optim(tp, &tp->t_termios, port);
875 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
876 port->active_out = TRUE;
878 if (tp->t_state & TS_ISOPEN)
883 if (!(tp->t_state & TS_ISOPEN))
886 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
889 lwkt_reltoken(&tty_token);
894 digiclose(struct dev_close_args *ap)
896 cdev_t dev = ap->a_head.a_dev;
900 struct digi_softc *sc;
903 lwkt_gettoken(&tty_token);
905 unit = MINOR_TO_UNIT(mynor);
906 pnum = MINOR_TO_PORT(mynor);
908 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
909 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
911 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
913 lwkt_reltoken(&tty_token);
917 port = sc->ports + pnum;
920 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
923 linesw[tp->t_line].l_close(tp, ap->a_fflag);
924 digi_disc_optim(tp, &tp->t_termios, port);
925 digistop(tp, FREAD | FWRITE);
930 lwkt_reltoken(&tty_token);
935 digidtrwakeup(void *chan)
937 struct digi_p *port = chan;
939 lwkt_gettoken(&tty_token);
940 port->status &= ~DIGI_DTR_OFF;
941 wakeup(&port->dtr_wait);
943 lwkt_reltoken(&tty_token);
947 * NOTE: Must be called with tty_token held
950 digihardclose(struct digi_p *port)
952 volatile struct board_chan *bc;
954 ASSERT_LWKT_TOKEN_HELD(&tty_token);
958 port->sc->setwin(port->sc, 0);
963 if ((port->tp->t_cflag & HUPCL) ||
964 (!port->active_out && !(bc->mstat & port->cd) &&
965 !(port->it_in.c_cflag & CLOCAL)) ||
966 !(port->tp->t_state & TS_ISOPEN)) {
967 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
968 if (port->dtr_wait != 0) {
969 /* Schedule a wakeup of any callin devices */
971 callout_reset(&port->wakeupco, port->dtr_wait,
972 digidtrwakeup, port);
973 port->status |= DIGI_DTR_OFF;
976 port->active_out = FALSE;
977 wakeup(&port->active_out);
978 wakeup(TSA_CARR_ON(port->tp));
983 digiread(struct dev_read_args *ap)
985 cdev_t dev = ap->a_head.a_dev;
988 int error, unit, pnum;
989 struct digi_softc *sc;
992 if (mynor & CONTROL_MASK)
995 lwkt_gettoken(&tty_token);
996 unit = MINOR_TO_UNIT(mynor);
997 pnum = MINOR_TO_PORT(mynor);
999 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1000 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
1001 tp = &sc->ttys[pnum];
1003 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
1004 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
1007 lwkt_reltoken(&tty_token);
1012 digiwrite(struct dev_write_args *ap)
1014 cdev_t dev = ap->a_head.a_dev;
1017 int error, unit, pnum;
1018 struct digi_softc *sc;
1021 if (mynor & CONTROL_MASK)
1024 lwkt_gettoken(&tty_token);
1025 unit = MINOR_TO_UNIT(mynor);
1026 pnum = MINOR_TO_PORT(mynor);
1028 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1029 KASSERT(sc, ("digi%d: softc not allocated in digiclose", unit));
1030 tp = &sc->ttys[pnum];
1032 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1033 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1036 lwkt_reltoken(&tty_token);
1041 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1043 * Populate sc->bios, sc->fep, and sc->link from this data.
1045 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1046 * to their respective sizes.
1048 * The module is unloaded when we're done.
1051 digi_loaddata(struct digi_softc *sc)
1053 struct digi_bios *bios;
1055 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1056 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1057 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1058 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1060 for (bios = digi_bioses; bios->model != NULL; bios++) {
1061 if (!strcmp(bios->model, sc->module))
1064 if (bios->model == NULL) {
1065 kprintf("digi.ko: driver %s not found", sc->module);
1069 sc->bios.size = bios->bios_size;
1070 if (sc->bios.size != 0 && bios->bios != NULL) {
1071 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1072 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1075 sc->fep.size = bios->fep_size;
1076 if (sc->fep.size != 0 && bios->fep != NULL) {
1077 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1078 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1085 digiioctl(struct dev_ioctl_args *ap)
1087 cdev_t dev = ap->a_head.a_dev;
1088 u_long cmd = ap->a_cmd;
1089 caddr_t data = ap->a_data;
1090 int unit, pnum, mynor, error, ret;
1091 struct digi_softc *sc;
1092 struct digi_p *port;
1094 #if defined(COMPAT_43)
1096 struct termios term;
1100 unit = MINOR_TO_UNIT(mynor);
1101 pnum = MINOR_TO_PORT(mynor);
1103 lwkt_gettoken(&tty_token);
1104 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1105 KASSERT(sc, ("digi%d: softc not allocated in digiioctl", unit));
1107 if (sc->status == DIGI_STATUS_DISABLED) {
1108 lwkt_reltoken(&tty_token);
1112 if (mynor & CTRL_DEV) {
1116 digi_debug = *(int *)data;
1117 lwkt_reltoken(&tty_token);
1120 device_printf(sc->dev, "DEBUG not defined\n");
1121 lwkt_reltoken(&tty_token);
1126 error = digi_init(sc);
1128 lwkt_reltoken(&tty_token);
1132 *(enum digi_model *)data = sc->model;
1133 lwkt_reltoken(&tty_token);
1137 ret = copyout(sc->name, *(char **)data,
1138 strlen(sc->name) + 1);
1139 lwkt_reltoken(&tty_token);
1144 if (pnum >= sc->numports) {
1145 lwkt_reltoken(&tty_token);
1149 port = sc->ports + pnum;
1150 if (!(port->status & ENABLED)) {
1151 lwkt_reltoken(&tty_token);
1157 if (mynor & CONTROL_MASK) {
1160 switch (mynor & CONTROL_MASK) {
1161 case CONTROL_INIT_STATE:
1162 ct = (mynor & CALLOUT_MASK) ?
1163 &port->it_out : &port->it_in;
1165 case CONTROL_LOCK_STATE:
1166 ct = (mynor & CALLOUT_MASK) ?
1167 &port->lt_out : &port->lt_in;
1170 lwkt_reltoken(&tty_token);
1171 return (ENODEV); /* /dev/nodev */
1176 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1178 lwkt_reltoken(&tty_token);
1181 *ct = *(struct termios *)data;
1182 lwkt_reltoken(&tty_token);
1186 *(struct termios *)data = *ct;
1187 lwkt_reltoken(&tty_token);
1191 *(int *)data = TTYDISC;
1192 lwkt_reltoken(&tty_token);
1196 bzero(data, sizeof(struct winsize));
1197 lwkt_reltoken(&tty_token);
1200 case DIGIIO_GETALTPIN:
1201 switch (mynor & CONTROL_MASK) {
1202 case CONTROL_INIT_STATE:
1203 *(int *)data = port->ialtpin;
1206 case CONTROL_LOCK_STATE:
1207 *(int *)data = port->laltpin;
1211 panic("Confusion when re-testing minor");
1212 lwkt_reltoken(&tty_token);
1215 lwkt_reltoken(&tty_token);
1218 case DIGIIO_SETALTPIN:
1219 switch (mynor & CONTROL_MASK) {
1220 case CONTROL_INIT_STATE:
1221 if (!port->laltpin) {
1222 port->ialtpin = !!*(int *)data;
1223 DLOG(DIGIDB_SET, (sc->dev,
1224 "port%d: initial ALTPIN %s\n", pnum,
1225 port->ialtpin ? "set" : "cleared"));
1229 case CONTROL_LOCK_STATE:
1230 port->laltpin = !!*(int *)data;
1231 DLOG(DIGIDB_SET, (sc->dev,
1232 "port%d: ALTPIN %slocked\n",
1233 pnum, port->laltpin ? "" : "un"));
1237 panic("Confusion when re-testing minor");
1238 lwkt_reltoken(&tty_token);
1241 lwkt_reltoken(&tty_token);
1245 lwkt_reltoken(&tty_token);
1251 case DIGIIO_GETALTPIN:
1252 *(int *)data = !!(port->dsr == sc->csigs->cd);
1253 lwkt_reltoken(&tty_token);
1256 case DIGIIO_SETALTPIN:
1257 if (!port->laltpin) {
1259 DLOG(DIGIDB_SET, (sc->dev,
1260 "port%d: ALTPIN set\n", pnum));
1261 port->cd = sc->csigs->dsr;
1262 port->dsr = sc->csigs->cd;
1264 DLOG(DIGIDB_SET, (sc->dev,
1265 "port%d: ALTPIN cleared\n", pnum));
1266 port->cd = sc->csigs->cd;
1267 port->dsr = sc->csigs->dsr;
1270 lwkt_reltoken(&tty_token);
1275 #if defined(COMPAT_43)
1276 term = tp->t_termios;
1278 error = ttsetcompat(tp, &cmd, data, &term);
1280 lwkt_reltoken(&tty_token);
1284 data = (caddr_t) & term;
1286 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1291 dt = (struct termios *)data;
1292 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1295 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1297 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1299 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1301 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1302 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1303 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1304 for (cc = 0; cc < NCCS; ++cc)
1305 if (lt->c_cc[cc] != 0)
1306 dt->c_cc[cc] = tp->t_cc[cc];
1307 if (lt->c_ispeed != 0)
1308 dt->c_ispeed = tp->t_ispeed;
1309 if (lt->c_ospeed != 0)
1310 dt->c_ospeed = tp->t_ospeed;
1312 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1313 ap->a_fflag, ap->a_cred);
1314 if (error == 0 && cmd == TIOCGETA)
1315 ((struct termios *)data)->c_iflag |= port->c_iflag;
1317 if (error >= 0 && error != ENOIOCTL) {
1318 lwkt_reltoken(&tty_token);
1322 error = ttioctl(tp, cmd, data, ap->a_fflag);
1323 if (error == 0 && cmd == TIOCGETA)
1324 ((struct termios *)data)->c_iflag |= port->c_iflag;
1326 digi_disc_optim(tp, &tp->t_termios, port);
1327 if (error >= 0 && error != ENOIOCTL) {
1329 lwkt_reltoken(&tty_token);
1335 port->send_ring = *(u_char *)data;
1339 * now it sends 400 millisecond break because I don't know
1340 * how to send an infinite break
1342 fepcmd_w(port, SENDBREAK, 400, 10);
1345 /* now it's empty */
1348 digimctl(port, TIOCM_DTR, DMBIS);
1351 digimctl(port, TIOCM_DTR, DMBIC);
1354 digimctl(port, *(int *)data, DMSET);
1357 digimctl(port, *(int *)data, DMBIS);
1360 digimctl(port, *(int *)data, DMBIC);
1363 *(int *)data = digimctl(port, 0, DMGET);
1366 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1369 lwkt_reltoken(&tty_token);
1372 port->dtr_wait = *(int *)data *hz / 100;
1376 *(int *)data = port->dtr_wait * 100 / hz;
1378 #ifdef DIGI_INTERRUPT
1380 *(struct timeval *)data = sc->intr_timestamp;
1386 lwkt_reltoken(&tty_token);
1390 lwkt_reltoken(&tty_token);
1395 digiparam(struct tty *tp, struct termios *t)
1400 struct digi_softc *sc;
1401 struct digi_p *port;
1407 lwkt_gettoken(&tty_token);
1408 mynor = minor(tp->t_dev);
1409 unit = MINOR_TO_UNIT(mynor);
1410 pnum = MINOR_TO_PORT(mynor);
1412 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1413 KASSERT(sc, ("digi%d: softc not allocated in digiparam", unit));
1415 port = &sc->ports[pnum];
1417 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1419 if (t->c_ispeed == 0)
1420 t->c_ispeed = t->c_ospeed;
1422 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1424 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed)) {
1425 lwkt_reltoken(&tty_token);
1431 window = sc->window;
1434 if (cflag == 0) { /* hangup */
1435 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1436 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1438 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1440 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1444 /* convert flags to sysV-style values */
1445 if (t->c_cflag & PARODD)
1447 if (t->c_cflag & PARENB)
1449 if (t->c_cflag & CSTOPB)
1452 /* convert flags to sysV-style values */
1453 if (t->c_cflag & PARODD)
1454 cflag |= FEP_PARODD;
1455 if (t->c_cflag & PARENB)
1456 cflag |= FEP_PARENB;
1457 if (t->c_cflag & CSTOPB)
1458 cflag |= FEP_CSTOPB;
1459 if (t->c_cflag & CLOCAL)
1460 cflag |= FEP_CLOCAL;
1463 cflag |= (t->c_cflag & CSIZE) >> 4;
1464 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1466 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1470 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1471 if (port->c_iflag & IXON)
1473 if (port->c_iflag & IXANY)
1475 if (port->c_iflag & IXOFF)
1478 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1479 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1482 if (t->c_cflag & CDTR_IFLOW)
1483 hflow |= sc->csigs->dtr;
1484 if (t->c_cflag & CRTS_IFLOW)
1485 hflow |= sc->csigs->rts;
1486 if (t->c_cflag & CCTS_OFLOW)
1487 hflow |= sc->csigs->cts;
1488 if (t->c_cflag & CDSR_OFLOW)
1490 if (t->c_cflag & CCAR_OFLOW)
1493 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1494 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1496 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1497 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1498 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1500 if (sc->window != 0)
1503 sc->towin(sc, window);
1506 lwkt_reltoken(&tty_token);
1513 struct digi_p *port;
1515 struct digi_softc *sc;
1517 volatile struct board_chan *bc;
1529 lwkt_gettoken(&tty_token);
1532 if (sc->status != DIGI_STATUS_ENABLED) {
1533 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1534 lwkt_reltoken(&tty_token);
1538 #ifdef DIGI_INTERRUPT
1539 microtime(&sc->intr_timestamp);
1542 window = sc->window;
1545 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1546 struct con_bios *con = con_bios_list;
1549 ptr = sc->vmem + W(sc->vmem + 0xd00);
1551 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1552 /* Not first block -- exact match */
1555 if (W(ptr + 4) >= W(con->bios + 4) &&
1556 W(ptr + 4) <= W(con->bios + 6))
1557 /* Initial search concetrator BIOS */
1562 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1563 " not found!\n", sc->res.unit, W(ptr + 4));
1565 W(sc->vmem + 0xd00) = 0;
1569 W(ptr + 4) = W(cxcon + 4);
1570 W(ptr + 6) = W(cxcon + 6);
1572 W(ptr + 2) = W(cxcon + 2);
1573 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1574 size = W(cxcon + 10) - (ptr[1] << 10);
1576 W(ptr + 8) = W(cxcon + 8);
1582 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1584 W(sc->vmem + 0xd00) = 0;
1588 ehead = sc->gdata->ein;
1589 etail = sc->gdata->eout;
1590 if (ehead == etail) {
1593 if (sc->intr_count % 6000 == 0) {
1594 DLOG(DIGIDB_IRQ, (sc->dev,
1595 "6000 useless polls %x %x\n", ehead, etail));
1601 while (ehead != etail) {
1602 event = *(volatile struct event *)(sc->memevent + etail);
1604 etail = (etail + 4) & sc->gdata->imax;
1606 if (event.pnum >= sc->numports) {
1607 log(LOG_ERR, "digi%d: port %d: got event"
1608 " on nonexisting port\n", sc->res.unit,
1612 port = &sc->ports[event.pnum];
1616 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1617 DLOG(DIGIDB_IRQ, (sc->dev,
1618 "port %d: event 0x%x on closed port\n",
1619 event.pnum, event.event));
1627 if (event.event & ~ALL_IND)
1628 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1629 " lstat 0x%x\n", sc->res.unit, event.pnum,
1630 event.event, event.mstat, event.lstat);
1632 if (event.event & DATA_IND) {
1633 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1635 wrapmask = port->rxbufsize - 1;
1640 if (!(tp->t_state & TS_ISOPEN)) {
1644 while (head != tail) {
1647 DLOG(DIGIDB_INT, (sc->dev,
1648 "port %d: p rx head = %d tail = %d\n",
1649 event.pnum, head, tail));
1650 top = (head > tail) ? head : wrapmask + 1;
1651 sc->towin(sc, port->rxwin);
1653 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1654 size = b_to_q((char *)port->rxbuf +
1655 tail, size, &tp->t_rawq);
1658 } else for (; tail < top;) {
1660 l_rint(port->rxbuf[tail], tp);
1661 sc->towin(sc, port->rxwin);
1664 if (tp->t_state & TS_TBLOCK)
1676 CE_RECORD(port, CE_OVERRUN);
1677 log(LOG_ERR, "digi%d: port%d: %s\n",
1678 sc->res.unit, event.pnum,
1679 digi_errortxt(CE_OVERRUN));
1684 tp->t_state |= TS_TBLOCK;
1685 port->status |= PAUSE_RX;
1686 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1693 if (event.event & MODEMCHG_IND) {
1694 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1697 if ((event.mstat ^ event.lstat) & port->cd) {
1699 linesw[tp->t_line].l_modem
1700 (tp, event.mstat & port->cd);
1702 wakeup(TSA_CARR_ON(tp));
1705 if (event.mstat & sc->csigs->ri) {
1706 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1708 if (port->send_ring) {
1709 linesw[tp->t_line].l_rint('R', tp);
1710 linesw[tp->t_line].l_rint('I', tp);
1711 linesw[tp->t_line].l_rint('N', tp);
1712 linesw[tp->t_line].l_rint('G', tp);
1713 linesw[tp->t_line].l_rint('\r', tp);
1714 linesw[tp->t_line].l_rint('\n', tp);
1718 if (event.event & BREAK_IND) {
1719 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1721 linesw[tp->t_line].l_rint(TTY_BI, tp);
1723 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1724 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1726 event.event & LOWTX_IND ? " LOWTX" : "",
1727 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1728 (*linesw[tp->t_line].l_start)(tp);
1731 sc->gdata->eout = etail;
1733 if (sc->window != 0)
1736 sc->towin(sc, window);
1737 lwkt_reltoken(&tty_token);
1741 digistart(struct tty *tp)
1745 struct digi_p *port;
1746 struct digi_softc *sc;
1747 volatile struct board_chan *bc;
1749 int size, ocount, totcnt = 0;
1752 lwkt_gettoken(&tty_token);
1753 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1754 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1756 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1757 KASSERT(sc, ("digi%d: softc not allocated in digistart", unit));
1759 port = &sc->ports[pnum];
1762 wmask = port->txbufsize - 1;
1765 port->lcc = tp->t_outq.c_cc;
1767 if (!(tp->t_state & TS_TBLOCK)) {
1768 if (port->status & PAUSE_RX) {
1769 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1772 * CAREFUL - braces are needed here if the DLOG is
1776 port->status &= ~PAUSE_RX;
1779 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1780 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1781 port->status &= ~PAUSE_TX;
1782 fepcmd_w(port, RESUMETX, 0, 10);
1784 if (tp->t_outq.c_cc == 0)
1785 tp->t_state &= ~TS_BUSY;
1787 tp->t_state |= TS_BUSY;
1790 while (tp->t_outq.c_cc != 0) {
1792 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1796 size = tail - head - 1;
1798 size = port->txbufsize - head;
1805 sc->towin(sc, port->txwin);
1806 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1815 port->lostcc = tp->t_outq.c_cc;
1818 size = port->txbufsize - tail + head;
1823 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1826 lwkt_reltoken(&tty_token);
1830 digistop(struct tty *tp, int rw)
1832 struct digi_softc *sc;
1835 struct digi_p *port;
1837 lwkt_gettoken(&tty_token);
1838 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1839 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1841 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1842 KASSERT(sc, ("digi%d: softc not allocated in digistop", unit));
1843 port = sc->ports + pnum;
1845 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1846 port->status |= PAUSE_TX;
1847 fepcmd_w(port, PAUSETX, 0, 10);
1848 lwkt_reltoken(&tty_token);
1852 * NOTE: Must be called with tty_token held
1855 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1858 unsigned tail, head;
1861 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1862 mem = port->sc->memcmd;
1864 port->sc->setwin(port->sc, 0);
1866 head = port->sc->gdata->cin;
1867 mem[head + 0] = cmd;
1868 mem[head + 1] = port->pnum;
1869 *(u_short *)(mem + head + 2) = op1;
1871 head = (head + 4) & port->sc->gdata->cmax;
1872 port->sc->gdata->cin = head;
1874 for (count = FEPTIMEOUT; count > 0; count--) {
1875 head = port->sc->gdata->cin;
1876 tail = port->sc->gdata->cout;
1877 n = (head - tail) & port->sc->gdata->cmax;
1879 if (n <= ncmds * sizeof(short) * 4)
1883 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1884 port->sc->res.unit, port->pnum);
1888 digi_errortxt(int id)
1890 static const char *error_desc[] = {
1892 "interrupt-level buffer overflow",
1893 "tty-level buffer overflow",
1896 KASSERT(id >= 0 && id < NELEM(error_desc),
1897 ("Unexpected digi error id %d\n", id));
1899 return (error_desc[id]);
1903 digi_attach(struct digi_softc *sc)
1905 lwkt_gettoken(&tty_token);
1906 sc->res.ctldev = make_dev(&digi_ops,
1907 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1908 0600, "digi%r.ctl", sc->res.unit);
1914 lwkt_reltoken(&tty_token);
1919 * NOTE: Must be called with tty_token held
1922 digi_inuse(struct digi_softc *sc)
1926 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1927 for (i = 0; i < sc->numports; i++)
1928 if (sc->ttys[i].t_state & TS_ISOPEN) {
1929 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1931 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1932 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1940 * NOTE: Must be called with tty_token held
1943 digi_free_state(struct digi_softc *sc)
1947 ASSERT_LWKT_TOKEN_HELD(&tty_token);
1948 /* Blow it all away */
1950 for (i = 0; i < sc->numports; i++)
1951 for (d = 0; d < 6; d++)
1952 destroy_dev(sc->ports[i].dev[d]);
1954 callout_stop(&sc->callout);
1955 callout_stop(&sc->inttest);
1957 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1958 #ifdef DIGI_INTERRUPT
1959 if (sc->res.irq != NULL) {
1960 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1966 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1967 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1968 kfree(sc->ports, M_TTYS);
1970 kfree(sc->ttys, M_TTYS);
1975 sc->status = DIGI_STATUS_NOTINIT;
1979 digi_detach(device_t dev)
1981 struct digi_softc *sc = device_get_softc(dev);
1983 lwkt_gettoken(&tty_token);
1984 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1986 /* If we're INIT'd, numports must be 0 */
1987 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1988 ("digi%d: numports(%d) & status(%d) are out of sync",
1989 sc->res.unit, sc->numports, (int)sc->status));
1991 if (digi_inuse(sc)) {
1992 lwkt_reltoken(&tty_token);
1996 digi_free_state(sc);
1998 destroy_dev(sc->res.ctldev);
2000 if (sc->res.mem != NULL) {
2001 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
2005 if (sc->res.io != NULL) {
2006 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
2011 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
2015 lwkt_reltoken(&tty_token);
2020 digi_shutdown(device_t dev)
2025 MODULE_VERSION(digi, 1);