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>
45 #include <sys/linker.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/syslog.h>
51 #include <sys/fcntl.h>
54 #include <sys/thread2.h>
59 #include <dev/serial/digi/digiio.h>
60 #include <dev/serial/digi/digireg.h>
61 #include <dev/serial/digi/digi.h>
62 #include <dev/serial/digi/digi_pci.h>
63 #include <dev/serial/digi/digi_bios.h>
65 #define CDEV_MAJOR 162
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 = {
149 { "dgm", CDEV_MAJOR, D_TTY },
151 .d_close = digiclose,
153 .d_write = digiwrite,
154 .d_ioctl = digiioctl,
156 .d_kqfilter = ttykqfilter
162 struct digi_softc *sc;
164 sc = (struct digi_softc *)ptr;
165 callout_init(&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(&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 digi_init(struct digi_softc *sc)
237 volatile struct board_chan *bc;
241 if (sc->status == DIGI_STATUS_DISABLED) {
242 log(LOG_ERR, "digi%d: Cannot init a disabled card\n",
246 if (sc->bios.data == NULL) {
247 log(LOG_ERR, "digi%d: Cannot init without BIOS\n",
252 if (sc->link.data == NULL && sc->model >= PCCX) {
253 log(LOG_ERR, "digi%d: Cannot init without link info\n",
258 if (sc->fep.data == NULL) {
259 log(LOG_ERR, "digi%d: Cannot init without fep code\n",
263 sc->status = DIGI_STATUS_NOTINIT;
267 * We're re-initialising - maybe because someone's attached
268 * another port module. For now, we just re-initialise
277 ptr = sc->setwin(sc, MISCGLOBAL);
278 for (i = 0; i < 16; i += 2)
283 outb(sc->wport, 0xff); /* window 7 */
284 ptr = sc->vmem + (BIOSCODE & 0x1fff);
286 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
287 device_printf(sc->dev, "BIOS upload failed\n");
291 outb(sc->port, FEPCLR);
297 ptr = sc->setwin(sc, BIOSCODE + ((0xf000 - sc->mem_seg) << 4));
298 if (!digi_bcopy(sc->bios.data, ptr, sc->bios.size)) {
299 device_printf(sc->dev, "BIOS upload failed\n");
310 outb(sc->port, FEPRST | FEPMEM);
312 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) &
313 FEPMASK) != FEPRST; i++) {
315 log(LOG_ERR, "digi%d: %s init reset failed\n",
316 sc->res.unit, sc->name);
319 digi_delay(sc, "digiinit0", 5);
321 DLOG(DIGIDB_INIT, (sc->dev, "Got init reset after %d us\n", i));
323 /* Now upload the BIOS */
324 cnt = (sc->bios.size < sc->win_size - BIOSOFFSET) ?
325 sc->bios.size : sc->win_size - BIOSOFFSET;
327 ptr = sc->setwin(sc, BIOSOFFSET);
328 if (!digi_bcopy(sc->bios.data, ptr, cnt)) {
329 device_printf(sc->dev, "BIOS upload (1) failed\n");
333 if (cnt != sc->bios.size) {
334 /* and the second part */
335 ptr = sc->setwin(sc, sc->win_size);
336 if (!digi_bcopy(sc->bios.data + cnt, ptr,
337 sc->bios.size - cnt)) {
338 device_printf(sc->dev, "BIOS upload failed\n");
343 ptr = sc->setwin(sc, 0);
344 vW(ptr + 0) = 0x0401;
345 vW(ptr + 2) = 0x0bf0;
346 vW(ptr + 4) = 0x0000;
347 vW(ptr + 6) = 0x0000;
352 DLOG(DIGIDB_INIT, (sc->dev, "BIOS uploaded\n"));
354 ptr = sc->setwin(sc, MISCGLOBAL);
360 } else if (sc->model == PCXEVE) {
361 outb(sc->port, FEPCLR);
364 outb(sc->port, FEPCLR | FEPMEM);
365 resp = FEPRST | FEPMEM;
368 for (i = 0; ((sc->pcibus ? PCIPORT : inb(sc->port)) & FEPMASK)
371 log(LOG_ERR, "digi%d: BIOS start failed\n",
375 digi_delay(sc, "digibios0", 5);
378 DLOG(DIGIDB_INIT, (sc->dev, "BIOS started after %d us\n", i));
380 for (i = 0; vW(ptr) != *(u_short *)"GD"; i++) {
382 log(LOG_ERR, "digi%d: BIOS boot failed "
383 "(0x%02x != 0x%02x)\n",
384 sc->res.unit, vW(ptr), *(u_short *)"GD");
387 digi_delay(sc, "digibios1", 5);
390 DLOG(DIGIDB_INIT, (sc->dev, "BIOS booted after %d iterations\n", i));
392 if (sc->link.data != NULL) {
393 DLOG(DIGIDB_INIT, (sc->dev, "Loading link data\n"));
394 ptr = sc->setwin(sc, 0xcd0);
395 digi_bcopy(sc->link.data, ptr, 21); /* XXX 21 ? */
404 ptr = sc->setwin(sc, sc->model == PCXI ? 0x2000 : 0x0);
405 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
407 /* A BIOS request to move our data to 0x2000 */
408 ptr = sc->setwin(sc, MBOX);
410 vW(ptr + 2) = sc->mem_seg + FEPCODESEG;
412 vW(ptr + 6) = FEPCODESEG;
414 vW(ptr + 10) = sc->fep.size;
416 /* Run the BIOS request */
417 outb(sc->port, FEPREQ | FEPMEM);
418 outb(sc->port, FEPCLR | FEPMEM);
420 for (i = 0; W(ptr); i++) {
422 log(LOG_ERR, "digi%d: FEP/OS move failed\n",
427 digi_delay(sc, "digifep0", 5);
430 (sc->dev, "FEP/OS moved after %d iterations\n", i));
432 /* Clear the confirm word */
433 ptr = sc->setwin(sc, FEPSTAT);
436 /* A BIOS request to execute the FEP/OS */
437 ptr = sc->setwin(sc, MBOX);
439 vW(ptr + 2) = FEPCODESEG;
442 /* Run the BIOS request */
443 outb(sc->port, FEPREQ);
444 outb(sc->port, FEPCLR);
446 ptr = sc->setwin(sc, FEPSTAT);
453 DLOG(DIGIDB_INIT, (sc->dev, "Loading FEP/OS\n"));
455 cnt = (sc->fep.size < sc->win_size - BIOSOFFSET) ?
456 sc->fep.size : sc->win_size - BIOSOFFSET;
458 ptr = sc->setwin(sc, BIOSOFFSET);
459 digi_bcopy(sc->fep.data, ptr, cnt);
461 if (cnt != sc->fep.size) {
462 ptr = sc->setwin(sc, BIOSOFFSET + cnt);
463 digi_bcopy(sc->fep.data + cnt, ptr,
467 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS loaded\n"));
469 ptr = sc->setwin(sc, 0xc30);
475 /* Clear the confirm word */
476 ptr = sc->setwin(sc, FEPSTAT);
480 outb(sc->port, 0); /* XXX necessary ? */
485 ptr = sc->setwin(sc, 0xd000);
486 digi_bcopy(sc->fep.data, ptr, sc->fep.size);
488 /* A BIOS request to execute the FEP/OS */
489 ptr = sc->setwin(sc, 0xc40);
491 W(ptr + 2) = FEPCODE >> 4;
494 /* Clear the confirm word */
495 ptr = sc->setwin(sc, FEPSTAT);
498 /* Run the BIOS request */
499 outb(sc->port, FEPREQ | FEPMEM); /* send interrupt to BIOS */
500 outb(sc->port, FEPCLR | FEPMEM);
504 /* Now wait 'till the FEP/OS has booted */
505 for (i = 0; vW(ptr) != *(u_short *)"OS"; i++) {
507 log(LOG_ERR, "digi%d: FEP/OS start failed "
508 "(0x%02x != 0x%02x)\n",
509 sc->res.unit, vW(ptr), *(u_short *)"OS");
513 digi_delay(sc, "digifep1", 5);
516 DLOG(DIGIDB_INIT, (sc->dev, "FEP/OS started after %d iterations\n", i));
518 if (sc->model >= PCXEM) {
519 ptr = sc->setwin(sc, 0xe04);
521 ptr = sc->setwin(sc, 0xc02);
522 sc->numports = vW(ptr);
524 ptr = sc->setwin(sc, 0xc22);
525 sc->numports = vW(ptr);
528 if (sc->numports == 0) {
529 device_printf(sc->dev, "%s, 0 ports found\n", sc->name);
534 if (sc->numports > 256) {
535 /* Our minor numbering scheme is broken for more than 256 */
536 device_printf(sc->dev, "%s, 256 ports (%d ports found)\n",
537 sc->name, sc->numports);
540 device_printf(sc->dev, "%s, %d ports found\n", sc->name,
544 kfree(sc->ports, M_TTYS);
545 sc->ports = kmalloc(sizeof(struct digi_p) * sc->numports,
546 M_TTYS, M_WAITOK | M_ZERO);
549 kfree(sc->ttys, M_TTYS);
550 sc->ttys = kmalloc(sizeof(struct tty) * sc->numports,
551 M_TTYS, M_WAITOK | M_ZERO);
554 * XXX Should read port 0xc90 for an array of 2byte values, 1 per
555 * port. If the value is 0, the port is broken....
558 ptr = sc->setwin(sc, 0);
560 /* We should now init per-port structures */
561 bc = (volatile struct board_chan *)(ptr + CHANSTRUCT);
562 sc->gdata = (volatile struct global_data *)(ptr + FEP_GLOBAL);
564 sc->memcmd = ptr + sc->gdata->cstart;
565 sc->memevent = ptr + sc->gdata->istart;
567 for (i = 0; i < sc->numports; i++, bc++) {
568 port = sc->ports + i;
571 port->status = ENABLED;
572 port->tp = sc->ttys + i;
575 if (sc->model == PCXEVE) {
577 (((bc->tseg - sc->mem_seg) << 4) & 0x1fff);
579 (((bc->rseg - sc->mem_seg) << 4) & 0x1fff);
580 port->txwin = FEPWIN | ((bc->tseg - sc->mem_seg) >> 9);
581 port->rxwin = FEPWIN | ((bc->rseg - sc->mem_seg) >> 9);
582 } else if (sc->model == PCXI || sc->model == PCXE) {
583 port->txbuf = ptr + ((bc->tseg - sc->mem_seg) << 4);
584 port->rxbuf = ptr + ((bc->rseg - sc->mem_seg) << 4);
585 port->txwin = port->rxwin = 0;
588 (((bc->tseg - sc->mem_seg) << 4) % sc->win_size);
590 (((bc->rseg - sc->mem_seg) << 4) % sc->win_size);
591 port->txwin = FEPWIN |
592 (((bc->tseg - sc->mem_seg) << 4) / sc->win_size);
593 port->rxwin = FEPWIN |
594 (((bc->rseg - sc->mem_seg) << 4) / sc->win_size);
596 port->txbufsize = bc->tmax + 1;
597 port->rxbufsize = bc->rmax + 1;
599 lowwater = port->txbufsize >> 2;
603 fepcmd_w(port, STXLWATER, lowwater, 10);
604 fepcmd_w(port, SRXLWATER, port->rxbufsize >> 2, 10);
605 fepcmd_w(port, SRXHWATER, (3 * port->rxbufsize) >> 2, 10);
608 port->dtr_wait = 3 * hz;
611 * We don't use all the flags from <sys/ttydefaults.h> since
612 * they are only relevant for logins. It's important to have
613 * echo off initially so that the line doesn't start blathering
614 * before the echo flag can be turned off.
616 port->it_in.c_iflag = 0;
617 port->it_in.c_oflag = 0;
618 port->it_in.c_cflag = TTYDEF_CFLAG;
619 port->it_in.c_lflag = 0;
620 termioschars(&port->it_in);
621 port->it_in.c_ispeed = port->it_in.c_ospeed = digidefaultrate;
622 port->it_out = port->it_in;
623 port->send_ring = 1; /* Default action on signal RI */
625 port->dev[0] = make_dev(&digi_ops, (sc->res.unit << 16) + i,
626 UID_ROOT, GID_WHEEL, 0600, "ttyD%d.%d", sc->res.unit, i);
627 port->dev[1] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
628 CONTROL_INIT_STATE, UID_ROOT, GID_WHEEL,
629 0600, "ttyiD%d.%d", sc->res.unit, i);
630 port->dev[2] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
631 CONTROL_LOCK_STATE, UID_ROOT, GID_WHEEL,
632 0600, "ttylD%d.%d", sc->res.unit, i);
633 port->dev[3] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
634 CALLOUT_MASK, UID_UUCP, GID_DIALER,
635 0660, "cuaD%d.%d", sc->res.unit, i);
636 port->dev[4] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
637 CALLOUT_MASK | CONTROL_INIT_STATE, UID_UUCP, GID_DIALER,
638 0660, "cuaiD%d.%d", sc->res.unit, i);
639 port->dev[5] = make_dev(&digi_ops, ((sc->res.unit << 16) + i) |
640 CALLOUT_MASK | CONTROL_LOCK_STATE, UID_UUCP, GID_DIALER,
641 0660, "cualD%d.%d", sc->res.unit, i);
645 callout_reset(&sc->inttest, hz, digi_int_test, sc);
646 /* fepcmd_w(&sc->ports[0], 0xff, 0, 0); */
647 sc->status = DIGI_STATUS_ENABLED;
653 digimctl(struct digi_p *port, int bits, int how)
658 port->sc->setwin(port->sc, 0);
659 mstat = port->bc->mstat;
660 port->sc->hidewin(port->sc);
662 if (mstat & port->sc->csigs->rts)
664 if (mstat & port->cd)
666 if (mstat & port->dsr)
668 if (mstat & port->sc->csigs->cts)
670 if (mstat & port->sc->csigs->ri)
672 if (mstat & port->sc->csigs->dtr)
677 /* Only DTR and RTS may be set */
679 if (bits & TIOCM_DTR)
680 mstat |= port->sc->csigs->dtr;
681 if (bits & TIOCM_RTS)
682 mstat |= port->sc->csigs->rts;
686 fepcmd_b(port, SETMODEM, mstat, ~mstat, 0);
689 fepcmd_b(port, SETMODEM, mstat, 0, 0);
692 fepcmd_b(port, SETMODEM, 0, mstat, 0);
700 digi_disc_optim(struct tty *tp, struct termios *t, struct digi_p *port)
702 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) &&
703 (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK)) &&
704 (!(t->c_iflag & PARMRK) ||
705 (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK)) &&
706 !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) &&
707 linesw[tp->t_line].l_rint == ttyinput)
708 tp->t_state |= TS_CAN_BYPASS_L_RINT;
710 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
714 digiopen(struct dev_open_args *ap)
716 cdev_t dev = ap->a_head.a_dev;
717 struct digi_softc *sc;
723 volatile struct board_chan *bc;
727 unit = MINOR_TO_UNIT(minor(dev));
728 pnum = MINOR_TO_PORT(minor(dev));
730 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
734 if (sc->status != DIGI_STATUS_ENABLED) {
735 DLOG(DIGIDB_OPEN, (sc->dev, "Cannot open a disabled card\n"));
738 if (pnum >= sc->numports) {
739 DLOG(DIGIDB_OPEN, (sc->dev, "port%d: Doesn't exist\n", pnum));
742 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
746 port = &sc->ports[pnum];
747 tp = dev->si_tty = port->tp;
753 while (port->status & DIGI_DTR_OFF) {
755 error = tsleep(&port->dtr_wait, PCATCH, "digidtr", 0);
761 if (tp->t_state & TS_ISOPEN) {
763 * The device is open, so everything has been initialized.
766 if (mynor & CALLOUT_MASK) {
767 if (!port->active_out) {
769 DLOG(DIGIDB_OPEN, (sc->dev, "port %d:"
770 " BUSY error = %d\n", pnum, error));
773 } else if (port->active_out) {
774 if (ap->a_oflags & O_NONBLOCK) {
776 DLOG(DIGIDB_OPEN, (sc->dev,
777 "port %d: BUSY error = %d\n", pnum, error));
781 error = tsleep(&port->active_out, PCATCH, "digibi", 0);
784 DLOG(DIGIDB_OPEN, (sc->dev,
785 "port %d: tsleep(digibi) error = %d\n",
791 if (tp->t_state & TS_XCLUDE && suser_cred(ap->a_cred, 0) != 0) {
797 * The device isn't open, so there are no conflicts.
798 * Initialize it. Initialization is done twice in many
799 * cases: to preempt sleeping callin opens if we are callout,
800 * and to complete a callin open after DCD rises.
802 callout_init(&port->wakeupco);
803 tp->t_oproc = digistart;
804 tp->t_param = digiparam;
805 tp->t_stop = digistop;
807 tp->t_termios = (mynor & CALLOUT_MASK) ?
808 port->it_out : port->it_in;
811 bc->rout = bc->rin; /* clear input queue */
815 bc->mint = port->cd | port->sc->csigs->ri;
818 port->cd = sc->csigs->dsr;
819 port->dsr = sc->csigs->cd;
821 port->cd = sc->csigs->cd;
822 port->dsr = sc->csigs->dsr;
824 port->wopeners++; /* XXX required ? */
825 error = digiparam(tp, &tp->t_termios);
829 DLOG(DIGIDB_OPEN, (sc->dev,
830 "port %d: cxpparam error = %d\n", pnum, error));
835 /* handle fake and initial DCD for callout devices */
837 if (bc->mstat & port->cd || mynor & CALLOUT_MASK)
838 linesw[tp->t_line].l_modem(tp, 1);
841 /* Wait for DCD if necessary */
842 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK) &&
843 !(tp->t_cflag & CLOCAL) && !(ap->a_oflags & O_NONBLOCK)) {
845 error = tsleep(TSA_CARR_ON(tp), PCATCH, "digidcd", 0);
848 DLOG(DIGIDB_OPEN, (sc->dev,
849 "port %d: tsleep(digidcd) error = %d\n",
855 error = linesw[tp->t_line].l_open(dev, tp);
856 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: l_open error = %d\n",
859 digi_disc_optim(tp, &tp->t_termios, port);
861 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
862 port->active_out = TRUE;
864 if (tp->t_state & TS_ISOPEN)
869 if (!(tp->t_state & TS_ISOPEN))
872 DLOG(DIGIDB_OPEN, (sc->dev, "port %d: open() returns %d\n",
879 digiclose(struct dev_close_args *ap)
881 cdev_t dev = ap->a_head.a_dev;
885 struct digi_softc *sc;
889 unit = MINOR_TO_UNIT(mynor);
890 pnum = MINOR_TO_PORT(mynor);
892 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
893 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
895 if (mynor & (CTRL_DEV | CONTROL_MASK)) {
900 port = sc->ports + pnum;
903 DLOG(DIGIDB_CLOSE, (sc->dev, "port %d: closing\n", pnum));
906 linesw[tp->t_line].l_close(tp, ap->a_fflag);
907 digi_disc_optim(tp, &tp->t_termios, port);
908 digistop(tp, FREAD | FWRITE);
917 digidtrwakeup(void *chan)
919 struct digi_p *port = chan;
921 port->status &= ~DIGI_DTR_OFF;
922 wakeup(&port->dtr_wait);
927 digihardclose(struct digi_p *port)
929 volatile struct board_chan *bc;
934 port->sc->setwin(port->sc, 0);
939 if ((port->tp->t_cflag & HUPCL) ||
940 (!port->active_out && !(bc->mstat & port->cd) &&
941 !(port->it_in.c_cflag & CLOCAL)) ||
942 !(port->tp->t_state & TS_ISOPEN)) {
943 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
944 if (port->dtr_wait != 0) {
945 /* Schedule a wakeup of any callin devices */
947 callout_reset(&port->wakeupco, port->dtr_wait,
948 digidtrwakeup, port);
949 port->status |= DIGI_DTR_OFF;
952 port->active_out = FALSE;
953 wakeup(&port->active_out);
954 wakeup(TSA_CARR_ON(port->tp));
959 digiread(struct dev_read_args *ap)
961 cdev_t dev = ap->a_head.a_dev;
964 int error, unit, pnum;
965 struct digi_softc *sc;
968 if (mynor & CONTROL_MASK)
971 unit = MINOR_TO_UNIT(mynor);
972 pnum = MINOR_TO_PORT(mynor);
974 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
975 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
976 tp = &sc->ttys[pnum];
978 error = linesw[tp->t_line].l_read(tp, ap->a_uio, ap->a_ioflag);
979 DLOG(DIGIDB_READ, (sc->dev, "port %d: read() returns %d\n",
986 digiwrite(struct dev_write_args *ap)
988 cdev_t dev = ap->a_head.a_dev;
991 int error, unit, pnum;
992 struct digi_softc *sc;
995 if (mynor & CONTROL_MASK)
998 unit = MINOR_TO_UNIT(mynor);
999 pnum = MINOR_TO_PORT(mynor);
1001 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1002 KASSERT(sc, ("digi%d: softc not allocated in digiclose\n", unit));
1003 tp = &sc->ttys[pnum];
1005 error = linesw[tp->t_line].l_write(tp, ap->a_uio, ap->a_ioflag);
1006 DLOG(DIGIDB_WRITE, (sc->dev, "port %d: write() returns %d\n",
1013 * Load module "digi_<mod>.ko" and look for a symbol called digi_mod_<mod>.
1015 * Populate sc->bios, sc->fep, and sc->link from this data.
1017 * sc->fep.data, sc->bios.data and sc->link.data are malloc()d according
1018 * to their respective sizes.
1020 * The module is unloaded when we're done.
1023 digi_loaddata(struct digi_softc *sc)
1025 struct digi_bios *bios;
1027 KASSERT(sc->bios.data == NULL, ("Uninitialised BIOS variable"));
1028 KASSERT(sc->fep.data == NULL, ("Uninitialised FEP variable"));
1029 KASSERT(sc->link.data == NULL, ("Uninitialised LINK variable"));
1030 KASSERT(sc->module != NULL, ("Uninitialised module name"));
1032 for (bios = digi_bioses; bios->model != NULL; bios++) {
1033 if (!strcmp(bios->model, sc->module))
1036 if (bios->model == NULL) {
1037 kprintf("digi.ko: driver %s not found", sc->module);
1041 sc->bios.size = bios->bios_size;
1042 if (sc->bios.size != 0 && bios->bios != NULL) {
1043 sc->bios.data = kmalloc(sc->bios.size, M_TTYS, M_WAITOK);
1044 bcopy(bios->bios, sc->bios.data, sc->bios.size);
1047 sc->fep.size = bios->fep_size;
1048 if (sc->fep.size != 0 && bios->fep != NULL) {
1049 sc->fep.data = kmalloc(sc->fep.size, M_TTYS, M_WAITOK);
1050 bcopy(bios->fep, sc->fep.data, sc->fep.size);
1057 digiioctl(struct dev_ioctl_args *ap)
1059 cdev_t dev = ap->a_head.a_dev;
1060 u_long cmd = ap->a_cmd;
1061 caddr_t data = ap->a_data;
1062 int unit, pnum, mynor, error;
1063 struct digi_softc *sc;
1064 struct digi_p *port;
1066 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1068 struct termios term;
1072 unit = MINOR_TO_UNIT(mynor);
1073 pnum = MINOR_TO_PORT(mynor);
1075 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1076 KASSERT(sc, ("digi%d: softc not allocated in digiioctl\n", unit));
1078 if (sc->status == DIGI_STATUS_DISABLED)
1081 if (mynor & CTRL_DEV) {
1085 digi_debug = *(int *)data;
1088 device_printf(sc->dev, "DEBUG not defined\n");
1093 error = digi_init(sc);
1098 *(enum digi_model *)data = sc->model;
1102 return (copyout(sc->name, *(char **)data,
1103 strlen(sc->name) + 1));
1107 if (pnum >= sc->numports)
1110 port = sc->ports + pnum;
1111 if (!(port->status & ENABLED))
1116 if (mynor & CONTROL_MASK) {
1119 switch (mynor & CONTROL_MASK) {
1120 case CONTROL_INIT_STATE:
1121 ct = (mynor & CALLOUT_MASK) ?
1122 &port->it_out : &port->it_in;
1124 case CONTROL_LOCK_STATE:
1125 ct = (mynor & CALLOUT_MASK) ?
1126 &port->lt_out : &port->lt_in;
1129 return (ENODEV); /* /dev/nodev */
1134 error = suser_cred(ap->a_cred, 0);
1137 *ct = *(struct termios *)data;
1141 *(struct termios *)data = *ct;
1145 *(int *)data = TTYDISC;
1149 bzero(data, sizeof(struct winsize));
1152 case DIGIIO_GETALTPIN:
1153 switch (mynor & CONTROL_MASK) {
1154 case CONTROL_INIT_STATE:
1155 *(int *)data = port->ialtpin;
1158 case CONTROL_LOCK_STATE:
1159 *(int *)data = port->laltpin;
1163 panic("Confusion when re-testing minor");
1168 case DIGIIO_SETALTPIN:
1169 switch (mynor & CONTROL_MASK) {
1170 case CONTROL_INIT_STATE:
1171 if (!port->laltpin) {
1172 port->ialtpin = !!*(int *)data;
1173 DLOG(DIGIDB_SET, (sc->dev,
1174 "port%d: initial ALTPIN %s\n", pnum,
1175 port->ialtpin ? "set" : "cleared"));
1179 case CONTROL_LOCK_STATE:
1180 port->laltpin = !!*(int *)data;
1181 DLOG(DIGIDB_SET, (sc->dev,
1182 "port%d: ALTPIN %slocked\n",
1183 pnum, port->laltpin ? "" : "un"));
1187 panic("Confusion when re-testing minor");
1198 case DIGIIO_GETALTPIN:
1199 *(int *)data = !!(port->dsr == sc->csigs->cd);
1202 case DIGIIO_SETALTPIN:
1203 if (!port->laltpin) {
1205 DLOG(DIGIDB_SET, (sc->dev,
1206 "port%d: ALTPIN set\n", pnum));
1207 port->cd = sc->csigs->dsr;
1208 port->dsr = sc->csigs->cd;
1210 DLOG(DIGIDB_SET, (sc->dev,
1211 "port%d: ALTPIN cleared\n", pnum));
1212 port->cd = sc->csigs->cd;
1213 port->dsr = sc->csigs->dsr;
1220 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1221 term = tp->t_termios;
1223 error = ttsetcompat(tp, &cmd, data, &term);
1227 data = (caddr_t) & term;
1229 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1234 dt = (struct termios *)data;
1235 lt = (mynor & CALLOUT_MASK) ? &port->lt_out : &port->lt_in;
1238 (tp->t_iflag & lt->c_iflag) | (dt->c_iflag & ~lt->c_iflag);
1240 (tp->t_oflag & lt->c_oflag) | (dt->c_oflag & ~lt->c_oflag);
1242 (tp->t_cflag & lt->c_cflag) | (dt->c_cflag & ~lt->c_cflag);
1244 (tp->t_lflag & lt->c_lflag) | (dt->c_lflag & ~lt->c_lflag);
1245 port->c_iflag = dt->c_iflag & (IXOFF | IXON | IXANY);
1246 dt->c_iflag &= ~(IXOFF | IXON | IXANY);
1247 for (cc = 0; cc < NCCS; ++cc)
1248 if (lt->c_cc[cc] != 0)
1249 dt->c_cc[cc] = tp->t_cc[cc];
1250 if (lt->c_ispeed != 0)
1251 dt->c_ispeed = tp->t_ispeed;
1252 if (lt->c_ospeed != 0)
1253 dt->c_ospeed = tp->t_ospeed;
1255 error = linesw[tp->t_line].l_ioctl(tp, cmd, data,
1256 ap->a_fflag, ap->a_cred);
1257 if (error == 0 && cmd == TIOCGETA)
1258 ((struct termios *)data)->c_iflag |= port->c_iflag;
1260 if (error >= 0 && error != ENOIOCTL)
1263 error = ttioctl(tp, cmd, data, ap->a_fflag);
1264 if (error == 0 && cmd == TIOCGETA)
1265 ((struct termios *)data)->c_iflag |= port->c_iflag;
1267 digi_disc_optim(tp, &tp->t_termios, port);
1268 if (error >= 0 && error != ENOIOCTL) {
1275 port->send_ring = *(u_char *)data;
1279 * now it sends 400 millisecond break because I don't know
1280 * how to send an infinite break
1282 fepcmd_w(port, SENDBREAK, 400, 10);
1285 /* now it's empty */
1288 digimctl(port, TIOCM_DTR, DMBIS);
1291 digimctl(port, TIOCM_DTR, DMBIC);
1294 digimctl(port, *(int *)data, DMSET);
1297 digimctl(port, *(int *)data, DMBIS);
1300 digimctl(port, *(int *)data, DMBIC);
1303 *(int *)data = digimctl(port, 0, DMGET);
1306 error = suser_cred(ap->a_cred, 0);
1311 port->dtr_wait = *(int *)data *hz / 100;
1315 *(int *)data = port->dtr_wait * 100 / hz;
1317 #ifdef DIGI_INTERRUPT
1319 *(struct timeval *)data = sc->intr_timestamp;
1332 digiparam(struct tty *tp, struct termios *t)
1337 struct digi_softc *sc;
1338 struct digi_p *port;
1344 mynor = minor(tp->t_dev);
1345 unit = MINOR_TO_UNIT(mynor);
1346 pnum = MINOR_TO_PORT(mynor);
1348 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1349 KASSERT(sc, ("digi%d: softc not allocated in digiparam\n", unit));
1351 port = &sc->ports[pnum];
1353 DLOG(DIGIDB_SET, (sc->dev, "port%d: setting parameters\n", pnum));
1355 if (t->c_ispeed == 0)
1356 t->c_ispeed = t->c_ospeed;
1358 cflag = ttspeedtab(t->c_ospeed, digispeedtab);
1360 if (cflag < 0 || (cflag > 0 && t->c_ispeed != t->c_ospeed))
1365 window = sc->window;
1368 if (cflag == 0) { /* hangup */
1369 DLOG(DIGIDB_SET, (sc->dev, "port%d: hangup\n", pnum));
1370 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIC);
1372 digimctl(port, TIOCM_DTR | TIOCM_RTS, DMBIS);
1374 DLOG(DIGIDB_SET, (sc->dev, "port%d: CBAUD = %d\n", pnum,
1378 /* convert flags to sysV-style values */
1379 if (t->c_cflag & PARODD)
1381 if (t->c_cflag & PARENB)
1383 if (t->c_cflag & CSTOPB)
1386 /* convert flags to sysV-style values */
1387 if (t->c_cflag & PARODD)
1388 cflag |= FEP_PARODD;
1389 if (t->c_cflag & PARENB)
1390 cflag |= FEP_PARENB;
1391 if (t->c_cflag & CSTOPB)
1392 cflag |= FEP_CSTOPB;
1393 if (t->c_cflag & CLOCAL)
1394 cflag |= FEP_CLOCAL;
1397 cflag |= (t->c_cflag & CSIZE) >> 4;
1398 DLOG(DIGIDB_SET, (sc->dev, "port%d: CFLAG = 0x%x\n", pnum,
1400 fepcmd_w(port, SETCFLAGS, (unsigned)cflag, 0);
1404 t->c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK | INPCK | ISTRIP);
1405 if (port->c_iflag & IXON)
1407 if (port->c_iflag & IXANY)
1409 if (port->c_iflag & IXOFF)
1412 DLOG(DIGIDB_SET, (sc->dev, "port%d: set iflag = 0x%x\n", pnum, iflag));
1413 fepcmd_w(port, SETIFLAGS, (unsigned)iflag, 0);
1416 if (t->c_cflag & CDTR_IFLOW)
1417 hflow |= sc->csigs->dtr;
1418 if (t->c_cflag & CRTS_IFLOW)
1419 hflow |= sc->csigs->rts;
1420 if (t->c_cflag & CCTS_OFLOW)
1421 hflow |= sc->csigs->cts;
1422 if (t->c_cflag & CDSR_OFLOW)
1424 if (t->c_cflag & CCAR_OFLOW)
1427 DLOG(DIGIDB_SET, (sc->dev, "port%d: set hflow = 0x%x\n", pnum, hflow));
1428 fepcmd_w(port, SETHFLOW, 0xff00 | (unsigned)hflow, 0);
1430 DLOG(DIGIDB_SET, (sc->dev, "port%d: set startc(0x%x), stopc(0x%x)\n",
1431 pnum, t->c_cc[VSTART], t->c_cc[VSTOP]));
1432 fepcmd_b(port, SONOFFC, t->c_cc[VSTART], t->c_cc[VSTOP], 0);
1434 if (sc->window != 0)
1437 sc->towin(sc, window);
1446 struct digi_p *port;
1448 struct digi_softc *sc;
1450 volatile struct board_chan *bc;
1464 if (sc->status != DIGI_STATUS_ENABLED) {
1465 DLOG(DIGIDB_IRQ, (sc->dev, "interrupt on disabled board !\n"));
1469 #ifdef DIGI_INTERRUPT
1470 microtime(&sc->intr_timestamp);
1473 window = sc->window;
1476 if (sc->model >= PCXEM && W(sc->vmem + 0xd00)) {
1477 struct con_bios *con = con_bios_list;
1480 ptr = sc->vmem + W(sc->vmem + 0xd00);
1482 if (ptr[1] && W(ptr + 2) == W(con->bios + 2))
1483 /* Not first block -- exact match */
1486 if (W(ptr + 4) >= W(con->bios + 4) &&
1487 W(ptr + 4) <= W(con->bios + 6))
1488 /* Initial search concetrator BIOS */
1493 log(LOG_ERR, "digi%d: wanted bios LREV = 0x%04x"
1494 " not found!\n", sc->res.unit, W(ptr + 4));
1496 W(sc->vmem + 0xd00) = 0;
1500 W(ptr + 4) = W(cxcon + 4);
1501 W(ptr + 6) = W(cxcon + 6);
1503 W(ptr + 2) = W(cxcon + 2);
1504 W(ptr + 8) = (ptr[1] << 6) + W(cxcon + 8);
1505 size = W(cxcon + 10) - (ptr[1] << 10);
1507 W(ptr + 8) = W(cxcon + 8);
1513 bcopy(cxcon + (ptr[1] << 10), ptr + 12, size);
1515 W(sc->vmem + 0xd00) = 0;
1519 ehead = sc->gdata->ein;
1520 etail = sc->gdata->eout;
1521 if (ehead == etail) {
1524 if (sc->intr_count % 6000 == 0) {
1525 DLOG(DIGIDB_IRQ, (sc->dev,
1526 "6000 useless polls %x %x\n", ehead, etail));
1532 while (ehead != etail) {
1533 event = *(volatile struct event *)(sc->memevent + etail);
1535 etail = (etail + 4) & sc->gdata->imax;
1537 if (event.pnum >= sc->numports) {
1538 log(LOG_ERR, "digi%d: port %d: got event"
1539 " on nonexisting port\n", sc->res.unit,
1543 port = &sc->ports[event.pnum];
1547 if (!(tp->t_state & TS_ISOPEN) && !port->wopeners) {
1548 DLOG(DIGIDB_IRQ, (sc->dev,
1549 "port %d: event 0x%x on closed port\n",
1550 event.pnum, event.event));
1558 if (event.event & ~ALL_IND)
1559 log(LOG_ERR, "digi%d: port%d: ? event 0x%x mstat 0x%x"
1560 " lstat 0x%x\n", sc->res.unit, event.pnum,
1561 event.event, event.mstat, event.lstat);
1563 if (event.event & DATA_IND) {
1564 DLOG(DIGIDB_IRQ, (sc->dev, "port %d: DATA_IND\n",
1566 wrapmask = port->rxbufsize - 1;
1571 if (!(tp->t_state & TS_ISOPEN)) {
1575 while (head != tail) {
1578 DLOG(DIGIDB_INT, (sc->dev,
1579 "port %d: p rx head = %d tail = %d\n",
1580 event.pnum, head, tail));
1581 top = (head > tail) ? head : wrapmask + 1;
1582 sc->towin(sc, port->rxwin);
1584 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1585 size = b_to_q((char *)port->rxbuf +
1586 tail, size, &tp->t_rawq);
1589 } else for (; tail < top;) {
1591 l_rint(port->rxbuf[tail], tp);
1592 sc->towin(sc, port->rxwin);
1595 if (tp->t_state & TS_TBLOCK)
1607 CE_RECORD(port, CE_OVERRUN);
1608 log(LOG_ERR, "digi%d: port%d: %s\n",
1609 sc->res.unit, event.pnum,
1610 digi_errortxt(CE_OVERRUN));
1615 tp->t_state |= TS_TBLOCK;
1616 port->status |= PAUSE_RX;
1617 DLOG(DIGIDB_RX, (sc->dev, "port %d: pause RX\n",
1624 if (event.event & MODEMCHG_IND) {
1625 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: MODEMCHG_IND\n",
1628 if ((event.mstat ^ event.lstat) & port->cd) {
1630 linesw[tp->t_line].l_modem
1631 (tp, event.mstat & port->cd);
1633 wakeup(TSA_CARR_ON(tp));
1636 if (event.mstat & sc->csigs->ri) {
1637 DLOG(DIGIDB_RI, (sc->dev, "port %d: RING\n",
1639 if (port->send_ring) {
1640 linesw[tp->t_line].l_rint('R', tp);
1641 linesw[tp->t_line].l_rint('I', tp);
1642 linesw[tp->t_line].l_rint('N', tp);
1643 linesw[tp->t_line].l_rint('G', tp);
1644 linesw[tp->t_line].l_rint('\r', tp);
1645 linesw[tp->t_line].l_rint('\n', tp);
1649 if (event.event & BREAK_IND) {
1650 DLOG(DIGIDB_MODEM, (sc->dev, "port %d: BREAK_IND\n",
1652 linesw[tp->t_line].l_rint(TTY_BI, tp);
1654 if (event.event & (LOWTX_IND | EMPTYTX_IND)) {
1655 DLOG(DIGIDB_IRQ, (sc->dev, "port %d:%s%s\n",
1657 event.event & LOWTX_IND ? " LOWTX" : "",
1658 event.event & EMPTYTX_IND ? " EMPTYTX" : ""));
1659 (*linesw[tp->t_line].l_start)(tp);
1662 sc->gdata->eout = etail;
1664 if (sc->window != 0)
1667 sc->towin(sc, window);
1671 digistart(struct tty *tp)
1675 struct digi_p *port;
1676 struct digi_softc *sc;
1677 volatile struct board_chan *bc;
1679 int size, ocount, totcnt = 0;
1682 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1683 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1685 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1686 KASSERT(sc, ("digi%d: softc not allocated in digistart\n", unit));
1688 port = &sc->ports[pnum];
1691 wmask = port->txbufsize - 1;
1694 port->lcc = tp->t_outq.c_cc;
1696 if (!(tp->t_state & TS_TBLOCK)) {
1697 if (port->status & PAUSE_RX) {
1698 DLOG(DIGIDB_RX, (sc->dev, "port %d: resume RX\n",
1701 * CAREFUL - braces are needed here if the DLOG is
1705 port->status &= ~PAUSE_RX;
1708 if (!(tp->t_state & TS_TTSTOP) && port->status & PAUSE_TX) {
1709 DLOG(DIGIDB_TX, (sc->dev, "port %d: resume TX\n", pnum));
1710 port->status &= ~PAUSE_TX;
1711 fepcmd_w(port, RESUMETX, 0, 10);
1713 if (tp->t_outq.c_cc == 0)
1714 tp->t_state &= ~TS_BUSY;
1716 tp->t_state |= TS_BUSY;
1719 while (tp->t_outq.c_cc != 0) {
1721 DLOG(DIGIDB_INT, (sc->dev, "port%d: s tx head = %d tail = %d\n",
1725 size = tail - head - 1;
1727 size = port->txbufsize - head;
1734 sc->towin(sc, port->txwin);
1735 ocount = q_to_b(&tp->t_outq, port->txbuf + head, size);
1744 port->lostcc = tp->t_outq.c_cc;
1747 size = port->txbufsize - tail + head;
1752 DLOG(DIGIDB_INT, (sc->dev, "port%d: s total cnt = %d\n", pnum, totcnt));
1758 digistop(struct tty *tp, int rw)
1760 struct digi_softc *sc;
1763 struct digi_p *port;
1765 unit = MINOR_TO_UNIT(minor(tp->t_dev));
1766 pnum = MINOR_TO_PORT(minor(tp->t_dev));
1768 sc = (struct digi_softc *)devclass_get_softc(digi_devclass, unit);
1769 KASSERT(sc, ("digi%d: softc not allocated in digistop\n", unit));
1770 port = sc->ports + pnum;
1772 DLOG(DIGIDB_TX, (sc->dev, "port %d: pause TX\n", pnum));
1773 port->status |= PAUSE_TX;
1774 fepcmd_w(port, PAUSETX, 0, 10);
1778 fepcmd(struct digi_p *port, int cmd, int op1, int ncmds)
1781 unsigned tail, head;
1784 mem = port->sc->memcmd;
1786 port->sc->setwin(port->sc, 0);
1788 head = port->sc->gdata->cin;
1789 mem[head + 0] = cmd;
1790 mem[head + 1] = port->pnum;
1791 *(u_short *)(mem + head + 2) = op1;
1793 head = (head + 4) & port->sc->gdata->cmax;
1794 port->sc->gdata->cin = head;
1796 for (count = FEPTIMEOUT; count > 0; count--) {
1797 head = port->sc->gdata->cin;
1798 tail = port->sc->gdata->cout;
1799 n = (head - tail) & port->sc->gdata->cmax;
1801 if (n <= ncmds * sizeof(short) * 4)
1805 log(LOG_ERR, "digi%d: port%d: timeout on FEP command\n",
1806 port->sc->res.unit, port->pnum);
1810 digi_errortxt(int id)
1812 static const char *error_desc[] = {
1814 "interrupt-level buffer overflow",
1815 "tty-level buffer overflow",
1818 KASSERT(id >= 0 && id < sizeof(error_desc) / sizeof(error_desc[0]),
1819 ("Unexpected digi error id %d\n", id));
1821 return (error_desc[id]);
1825 digi_attach(struct digi_softc *sc)
1827 sc->res.ctldev = make_dev(&digi_ops,
1828 (sc->res.unit << 16) | CTRL_DEV, UID_ROOT, GID_WHEEL,
1829 0600, "digi%r.ctl", sc->res.unit);
1839 digi_inuse(struct digi_softc *sc)
1843 for (i = 0; i < sc->numports; i++)
1844 if (sc->ttys[i].t_state & TS_ISOPEN) {
1845 DLOG(DIGIDB_INIT, (sc->dev, "port%d: busy\n", i));
1847 } else if (sc->ports[i].wopeners || sc->ports[i].opencnt) {
1848 DLOG(DIGIDB_INIT, (sc->dev, "port%d: blocked in open\n",
1856 digi_free_state(struct digi_softc *sc)
1860 /* Blow it all away */
1862 for (i = 0; i < sc->numports; i++)
1863 for (d = 0; d < 6; d++)
1864 destroy_dev(sc->ports[i].dev[d]);
1866 callout_stop(&sc->callout);
1867 callout_stop(&sc->inttest);
1869 bus_teardown_intr(sc->dev, sc->res.irq, sc->res.irqHandler);
1870 #ifdef DIGI_INTERRUPT
1871 if (sc->res.irq != NULL) {
1872 bus_release_resource(dev, SYS_RES_IRQ, sc->res.irqrid,
1878 KASSERT(sc->ports, ("digi%d: Lost my ports ?", sc->res.unit));
1879 KASSERT(sc->ttys, ("digi%d: Lost my ttys ?", sc->res.unit));
1880 kfree(sc->ports, M_TTYS);
1882 kfree(sc->ttys, M_TTYS);
1887 sc->status = DIGI_STATUS_NOTINIT;
1891 digi_detach(device_t dev)
1893 struct digi_softc *sc = device_get_softc(dev);
1895 DLOG(DIGIDB_INIT, (sc->dev, "detaching\n"));
1897 /* If we're INIT'd, numports must be 0 */
1898 KASSERT(sc->numports == 0 || sc->status != DIGI_STATUS_NOTINIT,
1899 ("digi%d: numports(%d) & status(%d) are out of sync",
1900 sc->res.unit, sc->numports, (int)sc->status));
1905 digi_free_state(sc);
1907 destroy_dev(sc->res.ctldev);
1909 if (sc->res.mem != NULL) {
1910 bus_release_resource(dev, SYS_RES_MEMORY, sc->res.mrid,
1914 if (sc->res.io != NULL) {
1915 bus_release_resource(dev, SYS_RES_IOPORT, sc->res.iorid,
1920 pmap_unmapdev((vm_offset_t)sc->vmem, sc->msize);
1928 digi_shutdown(device_t dev)
1933 MODULE_VERSION(digi, 1);