2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Slawa Olhovchenkov
4 * John Prince <johnp@knight-trosoft.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $FreeBSD: src/sys/dev/digi/digi.c,v 1.36 2003/09/26 09:05:57 phk Exp $
30 * $DragonFly: src/sys/dev/serial/digi/digi.c,v 1.11 2008/04/30 17:28:17 dillon Exp $
35 * Figure out what the con bios stuff is supposed to do
36 * Test with *LOTS* more cards - I only have a PCI8r and an ISA Xem.
39 #include "opt_compat.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
46 #include <sys/linker.h>
47 #include <sys/kernel.h>
49 #include <sys/malloc.h>
51 #include <sys/syslog.h>
52 #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 CDEV_MAJOR 162
68 #define CTRL_DEV 0x800000
69 #define CALLOUT_MASK 0x400000
70 #define CONTROL_INIT_STATE 0x100000
71 #define CONTROL_LOCK_STATE 0x200000
72 #define CONTROL_MASK (CTRL_DEV|CONTROL_INIT_STATE|CONTROL_LOCK_STATE)
73 #define UNIT_MASK 0x030000
74 #define PORT_MASK 0x0000FF
75 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
76 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
77 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
78 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
80 static d_open_t digiopen;
81 static d_close_t digiclose;
82 static d_read_t digiread;
83 static d_write_t digiwrite;
84 static d_ioctl_t digiioctl;
86 static void digistop(struct tty *tp, int rw);
87 static int digimctl(struct digi_p *port, int bits, int how);
88 static void digi_poll(void *ptr);
89 static void digi_freedata(struct digi_softc *);
90 static void fepcmd(struct digi_p *port, int cmd, int op, int ncmds);
91 static void digistart(struct tty *tp);
92 static int digiparam(struct tty *tp, struct termios *t);
93 static void digihardclose(struct digi_p *port);
94 static void digi_intr(void *);
95 static int digi_init(struct digi_softc *_sc);
96 static int digi_loaddata(struct digi_softc *);
97 static int digi_inuse(struct digi_softc *);
98 static void digi_free_state(struct digi_softc *);
100 #define fepcmd_b(port, cmd, op1, op2, ncmds) \
101 fepcmd(port, cmd, (op2 << 8) | op1, ncmds)
102 #define fepcmd_w fepcmd
105 static speed_t digidefaultrate = TTYDEF_SPEED;
108 struct con_bios *next;
113 static struct con_bios *con_bios_list;
114 devclass_t digi_devclass;
115 unsigned digi_debug = 0;
117 static struct speedtab digispeedtab[] = {
118 { 0, 0}, /* old (sysV-like) Bx codes */
134 { 57600, (02000 | 1)},
135 { 76800, (02000 | 2)},
136 { 115200, (02000 | 3)},
137 { 230400, (02000 | 6)},
141 const struct digi_control_signals digi_xixe_signals = {
142 0x02, 0x08, 0x10, 0x20, 0x40, 0x80
145 const struct digi_control_signals digi_normal_signals = {
146 0x02, 0x80, 0x20, 0x10, 0x40, 0x01
149 static struct dev_ops digi_ops = {
150 { "dgm", CDEV_MAJOR, D_TTY },
152 .d_close = digiclose,
154 .d_write = digiwrite,
155 .d_ioctl = digiioctl,
157 .d_kqfilter = ttykqfilter,
158 .d_revoke = ttyrevoke
164 struct digi_softc *sc;
166 sc = (struct digi_softc *)ptr;
167 callout_init(&sc->callout);
169 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
173 digi_int_test(void *v)
175 struct digi_softc *sc = v;
177 callout_init(&sc->inttest);
178 #ifdef DIGI_INTERRUPT
179 if (sc->intr_timestamp.tv_sec || sc->intr_timestamp.tv_usec) {
183 log(LOG_ERR, "digi%d: Interrupt didn't work, use polled mode\n", unit);
185 callout_reset(&sc->callout, (hz >= 200) ? hz / 100 : 1, digi_poll, sc);
189 digi_freedata(struct digi_softc *sc)
191 if (sc->fep.data != NULL) {
192 kfree(sc->fep.data, M_TTYS);
195 if (sc->link.data != NULL) {
196 kfree(sc->link.data, M_TTYS);
197 sc->link.data = NULL;
199 if (sc->bios.data != NULL) {
200 kfree(sc->bios.data, M_TTYS);
201 sc->bios.data = NULL;
206 digi_bcopy(const void *vfrom, void *vto, size_t sz)
208 volatile const char *from = (volatile const char *)vfrom;
209 volatile char *to = (volatile char *)vto;
212 for (i = 0; i < sz; i++)
215 from = (const volatile char *)vfrom;
216 to = (volatile char *)vto;
217 for (i = 0; i < sz; i++)
218 if (*to++ != *from++)
224 digi_delay(struct digi_softc *sc, const char *txt, u_long timo)
227 DELAY(timo * 1000000 / hz);
229 tsleep(sc, PCATCH, txt, timo);
233 digi_init(struct digi_softc *sc)
239 volatile struct board_chan *bc;
243 if (sc->status == DIGI_STATUS_DISABLED) {
244 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
248 if (sc->bios.data == NULL) {
249 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
254 if (sc->link.data == NULL && sc->model >= PCCX) {
255 log(LOG_ERR, "digi%d: Cannot init without link info\n",
260 if (sc->fep.data == NULL) {
261 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
265 sc->status = DIGI_STATUS_NOTINIT;
269 * We're re-initialising - maybe because someone's attached
270 * another port module. For now, we just re-initialise
279 ptr = sc->setwin(sc, MISCGLOBAL);
280 for (i = 0; i < 16; i += 2)
285 outb(sc->wport, 0xff); /* window 7 */
286 ptr = sc->vmem + (BIOSCODE & 0x1fff);
288 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
289 device_printf(sc->dev, "BIOS upload failed\n");
293 outb(sc->port, FEPCLR);
299 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
300 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
301 device_printf(sc->dev, "BIOS upload failed\n");
312 outb(sc->port, FEPRST | FEPMEM);
314 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
315 FEPMASK) != FEPRST; i++) {
317 log(LOG_ERR, "digi%d: %s init reset failed\n",
318 sc->res.unit, sc->name);
321 digi_delay(sc, "digiinit0", 5);
323 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
325 /* Now upload the BIOS */
326 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
327 sc->bios.size : sc->win_size - BIOSOFFSET;
329 ptr = sc->setwin(sc, BIOSOFFSET);
330 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
331 device_printf(sc->dev, "BIOS upload (1) failed\n");
335 if (cnt != sc->bios.size) {
336 /* and the second part */
337 ptr = sc->setwin(sc, sc->win_size);
338 if (!digi_bcopy(sc->bios.data + cnt, ptr,
339 sc->bios.size - cnt)) {
340 device_printf(sc->dev, "BIOS upload failed\n");
345 ptr = sc->setwin(sc, 0);
346 vW(ptr + 0) = 0x0401;
347 vW(ptr + 2) = 0x0bf0;
348 vW(ptr + 4) = 0x0000;
349 vW(ptr + 6) = 0x0000;
354 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
356 ptr = sc->setwin(sc, MISCGLOBAL);
362 } else if (sc->model == PCXEVE) {
363 outb(sc->port, FEPCLR);
366 outb(sc->port, FEPCLR | FEPMEM);
367 resp = FEPRST | FEPMEM;
370 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
373 log(LOG_ERR, "digi%d: BIOS start failed\n",
377 digi_delay(sc, "digibios0", 5);
380 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
382 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
384 log(LOG_ERR, "digi%d: BIOS boot failed "
385 "(0x%02x != 0x%02x)\n",
386 sc->res.unit, vW(ptr), *(u_short *)"GD");
389 digi_delay(sc, "digibios1", 5);
392 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
394 if (sc->link.data != NULL) {
395 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
396 ptr = sc->setwin(sc, 0xcd0);
397 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
406 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
407 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
409 /* A BIOS request to move our data to 0x2000 */
410 ptr = sc->setwin(sc, MBOX);
412 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
414 vW(ptr + 6) = FEPCODESEG;
416 vW(ptr + 10) = sc->fep.size;
418 /* Run the BIOS request */
419 outb(sc->port, FEPREQ | FEPMEM);
420 outb(sc->port, FEPCLR | FEPMEM);
422 for (i = 0; W(ptr); i++) {
424 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
429 digi_delay(sc, "digifep0", 5);
432 (sc->dev, "FEP/OS moved after %d iterations\n", i));
434 /* Clear the confirm word */
435 ptr = sc->setwin(sc, FEPSTAT);
438 /* A BIOS request to execute the FEP/OS */
439 ptr = sc->setwin(sc, MBOX);
441 vW(ptr + 2) = FEPCODESEG;
444 /* Run the BIOS request */
445 outb(sc->port, FEPREQ);
446 outb(sc->port, FEPCLR);
448 ptr = sc->setwin(sc, FEPSTAT);
455 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
457 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
458 sc->fep.size : sc->win_size - BIOSOFFSET;
460 ptr = sc->setwin(sc, BIOSOFFSET);
461 digi_bcopy(sc->fep.data, ptr, cnt);
463 if (cnt != sc->fep.size) {
464 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
465 digi_bcopy(sc->fep.data + cnt, ptr,
469 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
471 ptr = sc->setwin(sc, 0xc30);
477 /* Clear the confirm word */
478 ptr = sc->setwin(sc, FEPSTAT);
482 outb(sc->port, 0); /* XXX necessary ? */
487 ptr = sc->setwin(sc, 0xd000);
488 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
490 /* A BIOS request to execute the FEP/OS */
491 ptr = sc->setwin(sc, 0xc40);
493 W(ptr + 2) = FEPCODE >> 4;
496 /* Clear the confirm word */
497 ptr = sc->setwin(sc, FEPSTAT);
500 /* Run the BIOS request */
501 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
502 outb(sc->port, FEPCLR | FEPMEM);
506 /* Now wait 'till the FEP/OS has booted */
507 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
509 log(LOG_ERR, "digi%d: FEP/OS start failed "
510 "(0x%02x != 0x%02x)\n",
511 sc->res.unit, vW(ptr), *(u_short *)"OS");
515 digi_delay(sc, "digifep1", 5);
518 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
520 if (sc->model >= PCXEM) {
521 ptr = sc->setwin(sc, 0xe04);
523 ptr = sc->setwin(sc, 0xc02);
524 sc->numports = vW(ptr);
526 ptr = sc->setwin(sc, 0xc22);
527 sc->numports = vW(ptr);
530 if (sc->numports == 0) {
531 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
536 if (sc->numports > 256) {
537 /* Our minor numbering scheme is broken for more than 256 */
538 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
539 sc->name, sc->numports);
542 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
546 kfree(sc->ports, M_TTYS);
547 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
548 M_TTYS, M_WAITOK | M_ZERO);
551 kfree(sc->ttys, M_TTYS);
552 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
553 M_TTYS, M_WAITOK | M_ZERO);
556 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
557 * port. If the value is 0, the port is broken....
560 ptr = sc->setwin(sc, 0);
562 /* We should now init per-port structures */
563 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
564 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
566 sc->memcmd = ptr + sc->gdata->cstart;
567 sc->memevent = ptr + sc->gdata->istart;
569 for (i = 0; i < sc->numports; i++, bc++) {
570 port = sc->ports + i;
573 port->status = ENABLED;
574 port->tp = sc->ttys + i;
577 if (sc->model == PCXEVE) {
579 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
581 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
582 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
583 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
584 } else if (sc->model == PCXI || sc->model == PCXE) {
585 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
586 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
587 port->txwin = port->rxwin = 0;
590 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
592 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
593 port->txwin = FEPWIN |
594 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
595 port->rxwin = FEPWIN |
596 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
598 port->txbufsize = bc->tmax + 1;
599 port->rxbufsize = bc->rmax + 1;
601 lowwater = port->txbufsize >> 2;
605 fepcmd_w(port, STXLWATER, lowwater, 10);
606 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
607 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
610 port->dtr_wait = 3 * hz;
613 * We don't use all the flags from <sys/ttydefaults.h> since
614 * they are only relevant for logins. It's important to have
615 * echo off initially so that the line doesn't start blathering
616 * before the echo flag can be turned off.
618 port->it_in.c_iflag = 0;
619 port->it_in.c_oflag = 0;
620 port->it_in.c_cflag = TTYDEF_CFLAG;
621 port->it_in.c_lflag = 0;
622 termioschars(&port->it_in);
623 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
624 port->it_out = port->it_in;
625 port->send_ring = 1; /* Default action on signal RI */
627 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
628 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
629 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
630 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
631 0600, "ttyiD%d.%d", sc->res.unit, i);
632 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
633 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
634 0600, "ttylD%d.%d", sc->res.unit, i);
635 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
636 CALLOUT_MASK, UID_UUCP, GID_DIALER,
637 0660, "cuaD%d.%d", sc->res.unit, i);
638 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
639 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
640 0660, "cuaiD%d.%d", sc->res.unit, i);
641 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
642 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
643 0660, "cualD%d.%d", sc->res.unit, i);
647 callout_reset(&sc->inttest, hz, digi_int_test, sc);
648 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
649 sc->status = DIGI_STATUS_ENABLED;
655 digimctl(struct digi_p *port, int bits, int how)
660 port->sc->setwin(port->sc, 0);
661 mstat = port->bc->mstat;
662 port->sc->hidewin(port->sc);
664 if (mstat & port->sc->csigs->rts)
666 if (mstat & port->cd)
668 if (mstat & port->dsr)
670 if (mstat & port->sc->csigs->cts)
672 if (mstat & port->sc->csigs->ri)
674 if (mstat & port->sc->csigs->dtr)
679 /* Only DTR and RTS may be set */
681 if (bits & TIOCM_DTR)
682 mstat |= port->sc->csigs->dtr;
683 if (bits & TIOCM_RTS)
684 mstat |= port->sc->csigs->rts;
688 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
691 fepcmd_b(port, SETMODEM, mstat, 0, 0);
694 fepcmd_b(port, SETMODEM, 0, mstat, 0);
702 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
704 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
705 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
706 (!(t->c_iflag & PARMRK) ||
707 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
708 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
709 linesw[tp->t_line].l_rint == ttyinput)
710 tp->t_state |= TS_CAN_BYPASS_L_RINT;
712 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
716 digiopen(struct dev_open_args *ap)
718 cdev_t dev = ap->a_head.a_dev;
719 struct digi_softc *sc;
725 volatile struct board_chan *bc;
729 unit = MINOR_TO_UNIT(minor(dev));
730 pnum = MINOR_TO_PORT(minor(dev));
732 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
736 if (sc->status != DIGI_STATUS_ENABLED) {
737 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
740 if (pnum >= sc->numports) {
741 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
744 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
748 port = &sc->ports[pnum];
749 tp = dev->si_tty = port->tp;
755 while (port->status & DIGI_DTR_OFF) {
757 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
763 if (tp->t_state & TS_ISOPEN) {
765 * The device is open, so everything has been initialized.
768 if (mynor & CALLOUT_MASK) {
769 if (!port->active_out) {
771 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
772 " BUSY error = %d\n", pnum, error));
775 } else if (port->active_out) {
776 if (ap->a_oflags & O_NONBLOCK) {
778 DLOG(DIGIDB_OPEN, (sc->dev,
779 "port %d: BUSY error = %d\n", pnum, error));
783 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
786 DLOG(DIGIDB_OPEN, (sc->dev,
787 "port %d: tsleep(digibi) error = %d\n",
793 if (tp->t_state & TS_XCLUDE && priv_check_cred(ap->a_cred, PRIV_ROOT, 0) != 0) {
799 * The device isn't open, so there are no conflicts.
800 * Initialize it. Initialization is done twice in many
801 * cases: to preempt sleeping callin opens if we are callout,
802 * and to complete a callin open after DCD rises.
804 callout_init(&port->wakeupco);
805 tp->t_oproc = digistart;
806 tp->t_param = digiparam;
807 tp->t_stop = digistop;
809 tp->t_termios = (mynor & CALLOUT_MASK) ?
810 port->it_out : port->it_in;
813 bc->rout = bc->rin; /* clear input queue */
817 bc->mint = port->cd | port->sc->csigs->ri;
820 port->cd = sc->csigs->dsr;
821 port->dsr = sc->csigs->cd;
823 port->cd = sc->csigs->cd;
824 port->dsr = sc->csigs->dsr;
826 port->wopeners++; /* XXX required ? */
827 error = digiparam(tp, &tp->t_termios);
831 DLOG(DIGIDB_OPEN, (sc->dev,
832 "port %d: cxpparam error = %d\n", pnum, error));
837 /* handle fake and initial DCD for callout devices */
839 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
840 linesw[tp->t_line].l_modem(tp, 1);
843 /* Wait for DCD if necessary */
844 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
845 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
847 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
850 DLOG(DIGIDB_OPEN, (sc->dev,
851 "port %d: tsleep(digidcd) error = %d\n",
857 error = linesw[tp->t_line].l_open(dev, tp);
858 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
861 digi_disc_optim(tp, &tp->t_termios, port);
863 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
864 port->active_out = TRUE;
866 if (tp->t_state & TS_ISOPEN)
871 if (!(tp->t_state & TS_ISOPEN))
874 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
881 digiclose(struct dev_close_args *ap)
883 cdev_t dev = ap->a_head.a_dev;
887 struct digi_softc *sc;
891 unit = MINOR_TO_UNIT(mynor);
892 pnum = MINOR_TO_PORT(mynor);
894 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
895 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
897 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
902 port = sc->ports + pnum;
905 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
908 linesw[tp->t_line].l_close(tp, ap->a_fflag);
909 digi_disc_optim(tp, &tp->t_termios, port);
910 digistop(tp, FREAD | FWRITE);
919 digidtrwakeup(void *chan)
921 struct digi_p *port = chan;
923 port->status &= ~DIGI_DTR_OFF;
924 wakeup(&port->dtr_wait);
929 digihardclose(struct digi_p *port)
931 volatile struct board_chan *bc;
936 port->sc->setwin(port->sc, 0);
941 if ((port->tp->t_cflag & HUPCL) ||
942 (!port->active_out && !(bc->mstat & port->cd) &&
943 !(port->it_in.c_cflag & CLOCAL)) ||
944 !(port->tp->t_state & TS_ISOPEN)) {
945 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
946 if (port->dtr_wait != 0) {
947 /* Schedule a wakeup of any callin devices */
949 callout_reset(&port->wakeupco, port->dtr_wait,
950 digidtrwakeup, port);
951 port->status |= DIGI_DTR_OFF;
954 port->active_out = FALSE;
955 wakeup(&port->active_out);
956 wakeup(TSA_CARR_ON(port->tp));
961 digiread(struct dev_read_args *ap)
963 cdev_t dev = ap->a_head.a_dev;
966 int error, unit, pnum;
967 struct digi_softc *sc;
970 if (mynor & CONTROL_MASK)
973 unit = MINOR_TO_UNIT(mynor);
974 pnum = MINOR_TO_PORT(mynor);
976 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
977 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
978 tp = &sc->ttys[pnum];
980 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
981 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
988 digiwrite(struct dev_write_args *ap)
990 cdev_t dev = ap->a_head.a_dev;
993 int error, unit, pnum;
994 struct digi_softc *sc;
997 if (mynor & CONTROL_MASK)
1000 unit = MINOR_TO_UNIT(mynor);
1001 pnum = MINOR_TO_PORT(mynor);
1003 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1004 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
1005 tp = &sc->ttys[pnum];
1007 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1008 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1015 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1017 * Populate sc->bios, sc->fep, and sc->link from this data.
1019 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1020 * to their respective sizes.
1022 * The module is unloaded when we're done.
1025 digi_loaddata(struct digi_softc *sc)
1027 struct digi_bios *bios;
1029 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1030 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1031 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1032 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1034 for (bios = digi_bioses; bios->model != NULL; bios++) {
1035 if (!strcmp(bios->model, sc->module))
1038 if (bios->model == NULL) {
1039 kprintf("digi.ko: driver %s not found", sc->module);
1043 sc->bios.size = bios->bios_size;
1044 if (sc->bios.size != 0 && bios->bios != NULL) {
1045 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1046 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1049 sc->fep.size = bios->fep_size;
1050 if (sc->fep.size != 0 && bios->fep != NULL) {
1051 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1052 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1059 digiioctl(struct dev_ioctl_args *ap)
1061 cdev_t dev = ap->a_head.a_dev;
1062 u_long cmd = ap->a_cmd;
1063 caddr_t data = ap->a_data;
1064 int unit, pnum, mynor, error;
1065 struct digi_softc *sc;
1066 struct digi_p *port;
1068 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1070 struct termios term;
1074 unit = MINOR_TO_UNIT(mynor);
1075 pnum = MINOR_TO_PORT(mynor);
1077 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1078 KASSERT(sc, ("digi%d: softc not allocated in digiioctl\n", unit));
1080 if (sc->status == DIGI_STATUS_DISABLED)
1083 if (mynor & CTRL_DEV) {
1087 digi_debug = *(int *)data;
1090 device_printf(sc->dev, "DEBUG not defined\n");
1095 error = digi_init(sc);
1100 *(enum digi_model *)data = sc->model;
1104 return (copyout(sc->name, *(char **)data,
1105 strlen(sc->name) + 1));
1109 if (pnum >= sc->numports)
1112 port = sc->ports + pnum;
1113 if (!(port->status & ENABLED))
1118 if (mynor & CONTROL_MASK) {
1121 switch (mynor & CONTROL_MASK) {
1122 case CONTROL_INIT_STATE:
1123 ct = (mynor & CALLOUT_MASK) ?
1124 &port->it_out : &port->it_in;
1126 case CONTROL_LOCK_STATE:
1127 ct = (mynor & CALLOUT_MASK) ?
1128 &port->lt_out : &port->lt_in;
1131 return (ENODEV); /* /dev/nodev */
1136 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1139 *ct = *(struct termios *)data;
1143 *(struct termios *)data = *ct;
1147 *(int *)data = TTYDISC;
1151 bzero(data, sizeof(struct winsize));
1154 case DIGIIO_GETALTPIN:
1155 switch (mynor & CONTROL_MASK) {
1156 case CONTROL_INIT_STATE:
1157 *(int *)data = port->ialtpin;
1160 case CONTROL_LOCK_STATE:
1161 *(int *)data = port->laltpin;
1165 panic("Confusion when re-testing minor");
1170 case DIGIIO_SETALTPIN:
1171 switch (mynor & CONTROL_MASK) {
1172 case CONTROL_INIT_STATE:
1173 if (!port->laltpin) {
1174 port->ialtpin = !!*(int *)data;
1175 DLOG(DIGIDB_SET, (sc->dev,
1176 "port%d: initial ALTPIN %s\n", pnum,
1177 port->ialtpin ? "set" : "cleared"));
1181 case CONTROL_LOCK_STATE:
1182 port->laltpin = !!*(int *)data;
1183 DLOG(DIGIDB_SET, (sc->dev,
1184 "port%d: ALTPIN %slocked\n",
1185 pnum, port->laltpin ? "" : "un"));
1189 panic("Confusion when re-testing minor");
1200 case DIGIIO_GETALTPIN:
1201 *(int *)data = !!(port->dsr == sc->csigs->cd);
1204 case DIGIIO_SETALTPIN:
1205 if (!port->laltpin) {
1207 DLOG(DIGIDB_SET, (sc->dev,
1208 "port%d: ALTPIN set\n", pnum));
1209 port->cd = sc->csigs->dsr;
1210 port->dsr = sc->csigs->cd;
1212 DLOG(DIGIDB_SET, (sc->dev,
1213 "port%d: ALTPIN cleared\n", pnum));
1214 port->cd = sc->csigs->cd;
1215 port->dsr = sc->csigs->dsr;
1222 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1223 term = tp->t_termios;
1225 error = ttsetcompat(tp, &cmd, data, &term);
1229 data = (caddr_t) & term;
1231 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1236 dt = (struct termios *)data;
1237 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1240 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1242 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1244 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1246 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1247 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1248 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1249 for (cc = 0; cc < NCCS; ++cc)
1250 if (lt->c_cc[cc] != 0)
1251 dt->c_cc[cc] = tp->t_cc[cc];
1252 if (lt->c_ispeed != 0)
1253 dt->c_ispeed = tp->t_ispeed;
1254 if (lt->c_ospeed != 0)
1255 dt->c_ospeed = tp->t_ospeed;
1257 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1258 ap->a_fflag, ap->a_cred);
1259 if (error == 0 && cmd == TIOCGETA)
1260 ((struct termios *)data)->c_iflag |= port->c_iflag;
1262 if (error >= 0 && error != ENOIOCTL)
1265 error = ttioctl(tp, cmd, data, ap->a_fflag);
1266 if (error == 0 && cmd == TIOCGETA)
1267 ((struct termios *)data)->c_iflag |= port->c_iflag;
1269 digi_disc_optim(tp, &tp->t_termios, port);
1270 if (error >= 0 && error != ENOIOCTL) {
1277 port->send_ring = *(u_char *)data;
1281 * now it sends 400 millisecond break because I don't know
1282 * how to send an infinite break
1284 fepcmd_w(port, SENDBREAK, 400, 10);
1287 /* now it's empty */
1290 digimctl(port, TIOCM_DTR, DMBIS);
1293 digimctl(port, TIOCM_DTR, DMBIC);
1296 digimctl(port, *(int *)data, DMSET);
1299 digimctl(port, *(int *)data, DMBIS);
1302 digimctl(port, *(int *)data, DMBIC);
1305 *(int *)data = digimctl(port, 0, DMGET);
1308 error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0);
1313 port->dtr_wait = *(int *)data *hz / 100;
1317 *(int *)data = port->dtr_wait * 100 / hz;
1319 #ifdef DIGI_INTERRUPT
1321 *(struct timeval *)data = sc->intr_timestamp;
1334 digiparam(struct tty *tp, struct termios *t)
1339 struct digi_softc *sc;
1340 struct digi_p *port;
1346 mynor = minor(tp->t_dev);
1347 unit = MINOR_TO_UNIT(mynor);
1348 pnum = MINOR_TO_PORT(mynor);
1350 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1351 KASSERT(sc, ("digi%d: softc not allocated in digiparam\n", unit));
1353 port = &sc->ports[pnum];
1355 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1357 if (t->c_ispeed == 0)
1358 t->c_ispeed = t->c_ospeed;
1360 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1362 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed))
1367 window = sc->window;
1370 if (cflag == 0) { /* hangup */
1371 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1372 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1374 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1376 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1380 /* convert flags to sysV-style values */
1381 if (t->c_cflag & PARODD)
1383 if (t->c_cflag & PARENB)
1385 if (t->c_cflag & CSTOPB)
1388 /* convert flags to sysV-style values */
1389 if (t->c_cflag & PARODD)
1390 cflag |= FEP_PARODD;
1391 if (t->c_cflag & PARENB)
1392 cflag |= FEP_PARENB;
1393 if (t->c_cflag & CSTOPB)
1394 cflag |= FEP_CSTOPB;
1395 if (t->c_cflag & CLOCAL)
1396 cflag |= FEP_CLOCAL;
1399 cflag |= (t->c_cflag & CSIZE) >> 4;
1400 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1402 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1406 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1407 if (port->c_iflag & IXON)
1409 if (port->c_iflag & IXANY)
1411 if (port->c_iflag & IXOFF)
1414 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1415 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1418 if (t->c_cflag & CDTR_IFLOW)
1419 hflow |= sc->csigs->dtr;
1420 if (t->c_cflag & CRTS_IFLOW)
1421 hflow |= sc->csigs->rts;
1422 if (t->c_cflag & CCTS_OFLOW)
1423 hflow |= sc->csigs->cts;
1424 if (t->c_cflag & CDSR_OFLOW)
1426 if (t->c_cflag & CCAR_OFLOW)
1429 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1430 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1432 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1433 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1434 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1436 if (sc->window != 0)
1439 sc->towin(sc, window);
1448 struct digi_p *port;
1450 struct digi_softc *sc;
1452 volatile struct board_chan *bc;
1466 if (sc->status != DIGI_STATUS_ENABLED) {
1467 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1471 #ifdef DIGI_INTERRUPT
1472 microtime(&sc->intr_timestamp);
1475 window = sc->window;
1478 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1479 struct con_bios *con = con_bios_list;
1482 ptr = sc->vmem + W(sc->vmem + 0xd00);
1484 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1485 /* Not first block -- exact match */
1488 if (W(ptr + 4) >= W(con->bios + 4) &&
1489 W(ptr + 4) <= W(con->bios + 6))
1490 /* Initial search concetrator BIOS */
1495 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1496 " not found!\n", sc->res.unit, W(ptr + 4));
1498 W(sc->vmem + 0xd00) = 0;
1502 W(ptr + 4) = W(cxcon + 4);
1503 W(ptr + 6) = W(cxcon + 6);
1505 W(ptr + 2) = W(cxcon + 2);
1506 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1507 size = W(cxcon + 10) - (ptr[1] << 10);
1509 W(ptr + 8) = W(cxcon + 8);
1515 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1517 W(sc->vmem + 0xd00) = 0;
1521 ehead = sc->gdata->ein;
1522 etail = sc->gdata->eout;
1523 if (ehead == etail) {
1526 if (sc->intr_count % 6000 == 0) {
1527 DLOG(DIGIDB_IRQ, (sc->dev,
1528 "6000 useless polls %x %x\n", ehead, etail));
1534 while (ehead != etail) {
1535 event = *(volatile struct event *)(sc->memevent + etail);
1537 etail = (etail + 4) & sc->gdata->imax;
1539 if (event.pnum >= sc->numports) {
1540 log(LOG_ERR, "digi%d: port %d: got event"
1541 " on nonexisting port\n", sc->res.unit,
1545 port = &sc->ports[event.pnum];
1549 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1550 DLOG(DIGIDB_IRQ, (sc->dev,
1551 "port %d: event 0x%x on closed port\n",
1552 event.pnum, event.event));
1560 if (event.event & ~ALL_IND)
1561 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1562 " lstat 0x%x\n", sc->res.unit, event.pnum,
1563 event.event, event.mstat, event.lstat);
1565 if (event.event & DATA_IND) {
1566 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1568 wrapmask = port->rxbufsize - 1;
1573 if (!(tp->t_state & TS_ISOPEN)) {
1577 while (head != tail) {
1580 DLOG(DIGIDB_INT, (sc->dev,
1581 "port %d: p rx head = %d tail = %d\n",
1582 event.pnum, head, tail));
1583 top = (head > tail) ? head : wrapmask + 1;
1584 sc->towin(sc, port->rxwin);
1586 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1587 size = b_to_q((char *)port->rxbuf +
1588 tail, size, &tp->t_rawq);
1591 } else for (; tail < top;) {
1593 l_rint(port->rxbuf[tail], tp);
1594 sc->towin(sc, port->rxwin);
1597 if (tp->t_state & TS_TBLOCK)
1609 CE_RECORD(port, CE_OVERRUN);
1610 log(LOG_ERR, "digi%d: port%d: %s\n",
1611 sc->res.unit, event.pnum,
1612 digi_errortxt(CE_OVERRUN));
1617 tp->t_state |= TS_TBLOCK;
1618 port->status |= PAUSE_RX;
1619 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1626 if (event.event & MODEMCHG_IND) {
1627 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1630 if ((event.mstat ^ event.lstat) & port->cd) {
1632 linesw[tp->t_line].l_modem
1633 (tp, event.mstat & port->cd);
1635 wakeup(TSA_CARR_ON(tp));
1638 if (event.mstat & sc->csigs->ri) {
1639 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1641 if (port->send_ring) {
1642 linesw[tp->t_line].l_rint('R', tp);
1643 linesw[tp->t_line].l_rint('I', tp);
1644 linesw[tp->t_line].l_rint('N', tp);
1645 linesw[tp->t_line].l_rint('G', tp);
1646 linesw[tp->t_line].l_rint('\r', tp);
1647 linesw[tp->t_line].l_rint('\n', tp);
1651 if (event.event & BREAK_IND) {
1652 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1654 linesw[tp->t_line].l_rint(TTY_BI, tp);
1656 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1657 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1659 event.event & LOWTX_IND ? " LOWTX" : "",
1660 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1661 (*linesw[tp->t_line].l_start)(tp);
1664 sc->gdata->eout = etail;
1666 if (sc->window != 0)
1669 sc->towin(sc, window);
1673 digistart(struct tty *tp)
1677 struct digi_p *port;
1678 struct digi_softc *sc;
1679 volatile struct board_chan *bc;
1681 int size, ocount, totcnt = 0;
1684 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1685 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1687 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1688 KASSERT(sc, ("digi%d: softc not allocated in digistart\n", unit));
1690 port = &sc->ports[pnum];
1693 wmask = port->txbufsize - 1;
1696 port->lcc = tp->t_outq.c_cc;
1698 if (!(tp->t_state & TS_TBLOCK)) {
1699 if (port->status & PAUSE_RX) {
1700 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1703 * CAREFUL - braces are needed here if the DLOG is
1707 port->status &= ~PAUSE_RX;
1710 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1711 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1712 port->status &= ~PAUSE_TX;
1713 fepcmd_w(port, RESUMETX, 0, 10);
1715 if (tp->t_outq.c_cc == 0)
1716 tp->t_state &= ~TS_BUSY;
1718 tp->t_state |= TS_BUSY;
1721 while (tp->t_outq.c_cc != 0) {
1723 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1727 size = tail - head - 1;
1729 size = port->txbufsize - head;
1736 sc->towin(sc, port->txwin);
1737 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1746 port->lostcc = tp->t_outq.c_cc;
1749 size = port->txbufsize - tail + head;
1754 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1760 digistop(struct tty *tp, int rw)
1762 struct digi_softc *sc;
1765 struct digi_p *port;
1767 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1768 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1770 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1771 KASSERT(sc, ("digi%d: softc not allocated in digistop\n", unit));
1772 port = sc->ports + pnum;
1774 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1775 port->status |= PAUSE_TX;
1776 fepcmd_w(port, PAUSETX, 0, 10);
1780 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1783 unsigned tail, head;
1786 mem = port->sc->memcmd;
1788 port->sc->setwin(port->sc, 0);
1790 head = port->sc->gdata->cin;
1791 mem[head + 0] = cmd;
1792 mem[head + 1] = port->pnum;
1793 *(u_short *)(mem + head + 2) = op1;
1795 head = (head + 4) & port->sc->gdata->cmax;
1796 port->sc->gdata->cin = head;
1798 for (count = FEPTIMEOUT; count > 0; count--) {
1799 head = port->sc->gdata->cin;
1800 tail = port->sc->gdata->cout;
1801 n = (head - tail) & port->sc->gdata->cmax;
1803 if (n <= ncmds * sizeof(short) * 4)
1807 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1808 port->sc->res.unit, port->pnum);
1812 digi_errortxt(int id)
1814 static const char *error_desc[] = {
1816 "interrupt-level buffer overflow",
1817 "tty-level buffer overflow",
1820 KASSERT(id >= 0 && id < sizeof(error_desc) / sizeof(error_desc[0]),
1821 ("Unexpected digi error id %d\n", id));
1823 return (error_desc[id]);
1827 digi_attach(struct digi_softc *sc)
1829 sc->res.ctldev = make_dev(&digi_ops,
1830 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1831 0600, "digi%r.ctl", sc->res.unit);
1841 digi_inuse(struct digi_softc *sc)
1845 for (i = 0; i < sc->numports; i++)
1846 if (sc->ttys[i].t_state & TS_ISOPEN) {
1847 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1849 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1850 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1858 digi_free_state(struct digi_softc *sc)
1862 /* Blow it all away */
1864 for (i = 0; i < sc->numports; i++)
1865 for (d = 0; d < 6; d++)
1866 destroy_dev(sc->ports[i].dev[d]);
1868 callout_stop(&sc->callout);
1869 callout_stop(&sc->inttest);
1871 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1872 #ifdef DIGI_INTERRUPT
1873 if (sc->res.irq != NULL) {
1874 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1880 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1881 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1882 kfree(sc->ports, M_TTYS);
1884 kfree(sc->ttys, M_TTYS);
1889 sc->status = DIGI_STATUS_NOTINIT;
1893 digi_detach(device_t dev)
1895 struct digi_softc *sc = device_get_softc(dev);
1897 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1899 /* If we're INIT'd, numports must be 0 */
1900 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1901 ("digi%d: numports(%d) & status(%d) are out of sync",
1902 sc->res.unit, sc->numports, (int)sc->status));
1907 digi_free_state(sc);
1909 destroy_dev(sc->res.ctldev);
1911 if (sc->res.mem != NULL) {
1912 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
1916 if (sc->res.io != NULL) {
1917 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
1922 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
1930 digi_shutdown(device_t dev)
1935 MODULE_VERSION(digi, 1);