2 * dgb.c $FreeBSD: src/sys/gnu/i386/isa/dgb.c,v 1.56.2.1 2001/02/26 04:23:09 jlemon Exp $
6 * Stage 1. "Better than nothing".
7 * Stage 2. "Gee, it works!".
9 * Based on sio driver by Bruce Evans and on Linux driver by Troy
10 * De Jongh <troyd@digibd.com> or <troyd@skypoint.com>
11 * which is under GNU General Public License version 2 so this driver
12 * is forced to be under GPL 2 too.
14 * Written by Serge Babkin,
15 * Joint Stock Commercial Bank "Chelindbank"
16 * (Chelyabinsk, Russia)
17 * babkin@hq.icb.chel.su
19 * Assorted hacks to make it more functional and working under 3.0-current.
20 * Fixed broken routines to prevent processes hanging on closed (thanks
21 * to Bruce for his patience and assistance). Thanks also to Maxim Bolotin
22 * <max@run.net> for his patches which did most of the work to get this
23 * running under 2.2/3.0-current.
24 * Implemented ioctls: TIOCMSDTRWAIT, TIOCMGDTRWAIT, TIOCTIMESTAMP &
26 * Sysctl debug flag is now a bitflag, to filter noise during debugging.
27 * David L. Nugent <davidn@blaze.net.au>
30 #include "opt_compat.h"
35 /* Helg: i.e.25 times per sec board will be polled */
36 #define POLLSPERSEC 25
37 /* How many charactes can we write to input tty rawq */
38 #define DGB_IBUFSIZE (TTYHOG-100)
40 /* the overall number of ports controlled by this driver */
43 # define NDGBPORTS (NDGB*16)
46 #include <sys/param.h>
47 #include <sys/systm.h>
51 #include <sys/dkstat.h>
52 #include <sys/fcntl.h>
53 #include <sys/kernel.h>
54 #include <sys/sysctl.h>
56 #include <machine/clock.h>
61 #include <i386/isa/isa_device.h>
63 #include <gnu/i386/isa/dgbios.h>
64 #include <gnu/i386/isa/dgfep.h>
66 #define DGB_DEBUG /* Enable debugging info via sysctl */
67 #include <gnu/i386/isa/dgreg.h>
69 #define CALLOUT_MASK 0x80
70 #define CONTROL_MASK 0x60
71 #define CONTROL_INIT_STATE 0x20
72 #define CONTROL_LOCK_STATE 0x40
73 #define UNIT_MASK 0x30000
74 #define PORT_MASK 0x1F
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 /* types. XXX - should be elsewhere */
81 typedef u_char bool_t; /* boolean */
83 /* digiboard port structure */
87 u_char unit; /* board unit number */
88 u_char pnum; /* port number */
89 u_char omodem; /* FEP output modem status */
90 u_char imodem; /* FEP input modem status */
91 u_char modemfake; /* Modem values to be forced */
92 u_char modem; /* Force values */
121 volatile struct board_chan *brdchan;
124 bool_t active_out; /* nonzero if the callout device is open */
125 u_int wopeners; /* # processes waiting for DCD in open() */
128 struct termios it_in; /* should be in struct tty */
129 struct termios it_out;
132 struct termios lt_in; /* should be in struct tty */
133 struct termios lt_out;
136 bool_t do_dcd_timestamp;
137 struct timeval timestamp;
138 struct timeval dcd_timestamp;
140 /* flags of state, are used in sleep() too */
141 u_char closing; /* port is being closed now */
142 u_char draining; /* port is being drained now */
143 u_char used; /* port is being used now */
144 u_char mustdrain; /* data must be waited to drain in dgbparam() */
147 /* Digiboard per-board structure */
149 /* struct board_info */
150 u_char status; /* status: DISABLED/ENABLED */
151 u_char unit; /* unit number */
152 u_char type; /* type of card: PCXE, PCXI, PCXEVE */
153 u_char altpin; /* do we need alternate pin setting ? */
154 int numports; /* number of ports on card */
155 int port; /* I/O port */
156 u_char *vmem; /* virtual memory address */
157 long pmem; /* physical memory address */
158 int mem_seg; /* internal memory segment */
159 struct dgb_p *ports; /* pointer to array of port descriptors */
160 struct tty *ttys; /* pointer to array of TTY structures */
161 volatile struct global_data *mailbox;
165 static struct dgb_softc dgb_softc[NDGB];
166 static struct dgb_p dgb_ports[NDGBPORTS];
167 static struct tty dgb_tty[NDGBPORTS];
170 * The public functions in the com module ought to be declared in a com-driver
174 /* Interrupt handling entry points. */
175 static void dgbpoll __P((void *unit_c));
177 /* Device switch entry points. */
178 #define dgbreset noreset
179 #define dgbmmap nommap
180 #define dgbstrategy nostrategy
182 static int dgbattach __P((struct isa_device *dev));
183 static int dgbprobe __P((struct isa_device *dev));
185 static void fepcmd(struct dgb_p *port, unsigned cmd, unsigned op1, unsigned op2,
186 unsigned ncmds, unsigned bytecmd);
188 static void dgbstart __P((struct tty *tp));
189 static void dgbstop __P((struct tty *tp, int rw));
190 static int dgbparam __P((struct tty *tp, struct termios *t));
191 static void dgbhardclose __P((struct dgb_p *port));
192 static void dgb_drain_or_flush __P((struct dgb_p *port));
193 static int dgbdrain __P((struct dgb_p *port));
194 static void dgb_pause __P((void *chan));
195 static void wakeflush __P((void *p));
196 static void disc_optim __P((struct tty *tp, struct termios *t));
199 struct isa_driver dgbdriver = {
200 dgbprobe, dgbattach, "dgb",0
203 static d_open_t dgbopen;
204 static d_close_t dgbclose;
205 static d_ioctl_t dgbioctl;
207 #define CDEV_MAJOR 58
208 static struct cdevsw dgb_cdevsw = {
210 /* close */ dgbclose,
212 /* write */ ttywrite,
213 /* ioctl */ dgbioctl,
216 /* strategy */ nostrategy,
218 /* maj */ CDEV_MAJOR,
221 /* flags */ D_TTY | D_KQFILTER,
223 /* kqfilter */ ttykqfilter,
226 static speed_t dgbdefaultrate = TTYDEF_SPEED;
228 static struct speedtab dgbspeedtab[] = {
229 0, FEP_B0, /* old (sysV-like) Bx codes */
245 57600, (FEP_FASTBAUD|FEP_B50), /* B50 & fast baud table */
246 115200, (FEP_FASTBAUD|FEP_B110), /* B100 & fast baud table */
250 static struct dbgflagtbl
257 { PARODD, PARODD, FEP_PARODD },
258 { PARENB, PARENB, FEP_PARENB },
259 { CSTOPB, CSTOPB, FEP_CSTOPB },
260 { CSIZE, CS5, FEP_CS6 },
261 { CSIZE, CS6, FEP_CS6 },
262 { CSIZE, CS7, FEP_CS7 },
263 { CSIZE, CS8, FEP_CS8 },
264 { CLOCAL, CLOCAL, FEP_CLOCAL },
268 { IGNBRK, IGNBRK, FEP_IGNBRK },
269 { BRKINT, BRKINT, FEP_BRKINT },
270 { IGNPAR, IGNPAR, FEP_IGNPAR },
271 { PARMRK, PARMRK, FEP_PARMRK },
272 { INPCK, INPCK, FEP_INPCK },
273 { ISTRIP, ISTRIP, FEP_ISTRIP },
274 { IXON, IXON, FEP_IXON },
275 { IXOFF, IXOFF, FEP_IXOFF },
276 { IXANY, IXANY, FEP_IXANY },
280 { CRTSCTS, CRTSCTS, CTS|RTS },
281 { CRTSCTS, CCTS_OFLOW, CTS },
282 { CRTSCTS, CRTS_IFLOW, RTS },
286 /* xlat bsd termios flags to dgb sys-v style */
288 dgbflags(struct dbgflagtbl *tbl, tcflag_t input)
293 for (i=0; tbl[i].in_mask != (tcflag_t)-1; i++)
295 if ((input & tbl[i].in_mask) == tbl[i].in_val)
296 output |= tbl[i].out_val;
302 static int dgbdebug=0;
303 SYSCTL_INT(_debug, OID_AUTO, dgb_debug, CTLFLAG_RW, &dgbdebug, 0, "");
306 static __inline int setwin __P((struct dgb_softc *sc, unsigned addr));
307 static __inline int setinitwin __P((struct dgb_softc *sc, unsigned addr));
308 static __inline void hidewin __P((struct dgb_softc *sc));
309 static __inline void towin __P((struct dgb_softc *sc, int win));
311 /*Helg: to allow recursive dgb...() calls */
313 { /* If we were called and don't want to disturb we need: */
314 int port; /* write to this port */
315 u_char data; /* this data on exit */
316 /* or DATA_WINOFF to close memory window on entry */
317 } BoardMemWinState; /* so several channels and even boards can coexist */
318 #define DATA_WINOFF 0
319 static BoardMemWinState bmws;
321 /* return current memory window state and close window */
322 static BoardMemWinState
325 BoardMemWinState bmwsRet=bmws;
326 if(bmws.data!=DATA_WINOFF)
327 outb(bmws.port, bmws.data=DATA_WINOFF);
331 /* restore memory window state */
333 bmws_set(BoardMemWinState ws)
335 if(ws.data != bmws.data || ws.port!=bmws.port ) {
336 if(bmws.data!=DATA_WINOFF)
337 outb(bmws.port,DATA_WINOFF);
338 if(ws.data!=DATA_WINOFF)
339 outb(ws.port, ws.data);
346 struct dgb_softc *sc;
349 if(sc->type==PCXEVE) {
350 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
351 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
352 return (addr & 0x1FFF);
354 outb(bmws.port=sc->port,bmws.data=FEPMEM);
361 struct dgb_softc *sc;
364 if(sc->type==PCXEVE) {
365 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
366 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
367 return (addr & 0x1FFF);
369 outb(bmws.port=sc->port,bmws.data=inb(sc->port)|FEPMEM);
376 struct dgb_softc *sc;
380 outb(bmws.port=sc->port+1, bmws.data);
382 outb(bmws.port=sc->port, bmws.data);
387 struct dgb_softc *sc;
390 if(sc->type==PCXEVE) {
391 outb(bmws.port=sc->port+1, bmws.data=win);
393 outb(bmws.port=sc->port,bmws.data=FEPMEM);
399 struct isa_device *dev;
401 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
403 u_long win_size; /* size of vizible memory window */
404 int unit=dev->id_unit;
408 cdevsw_add(&dgb_cdevsw);
409 sc->unit=dev->id_unit;
410 sc->port=dev->id_iobase;
412 if(dev->id_flags & DGBFLAG_ALTPIN)
417 /* left 24 bits only (ISA address) */
418 sc->pmem=((intptr_t)(void *)dev->id_maddr & 0xFFFFFF);
420 DPRINT4(DB_INFO,"dgb%d: port 0x%x mem 0x%lx\n",unit,sc->port,sc->pmem);
422 outb(sc->port, FEPRST);
425 for(i=0; i< 1000; i++) {
427 if( (inb(sc->port) & FEPMASK) == FEPRST ) {
429 DPRINT3(DB_EXCEPT,"dgb%d: got reset after %d us\n",unit,i);
434 if(sc->status!=ENABLED) {
435 DPRINT2(DB_EXCEPT,"dgb%d: failed to respond\n",dev->id_unit);
439 /* check type of card and get internal memory characteristics */
448 printf("dgb%d: PC/Xi 64K\n",dev->id_unit);
453 printf("dgb%d: PC/Xi 128K\n",dev->id_unit);
458 printf("dgb%d: PC/Xi 256K\n",dev->id_unit);
460 default: /* case 0x30: */
463 printf("dgb%d: PC/Xi 512K\n",dev->id_unit);
472 printf("dgb%d: PC/Xm isn't supported\n",dev->id_unit);
479 if(dev->id_flags==DGBFLAG_NOWIN || ( v&0xC0 )==0) {
481 printf("dgb%d: PC/Xe 64K\n",dev->id_unit);
485 printf("dgb%d: PC/Xe 64/8K (windowed)\n",dev->id_unit);
487 if((u_long)sc->pmem & ~0xFFE000) {
488 printf("dgb%d: warning: address 0x%lx truncated to 0x%lx\n",
489 dev->id_unit, sc->pmem,
490 sc->pmem & 0xFFE000);
492 dev->id_maddr= (u_char *)(void *)(intptr_t)( sc->pmem & 0xFFE000 );
497 /* save size of vizible memory segment */
498 dev->id_msize=win_size;
501 dev->id_maddr=sc->vmem=pmap_mapdev(sc->pmem,dev->id_msize);
503 outb(sc->port, FEPCLR); /* drop RESET */
504 hidewin(sc); /* Helg: to set initial bmws state */
506 return 4; /* we need I/O space of 4 ports */
511 struct isa_device *dev;
513 int unit=dev->id_unit;
514 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
516 u_char volatile *mem;
517 u_char volatile *ptr;
520 volatile struct board_chan *bc;
528 if(sc->status!=ENABLED) {
529 DPRINT2(DB_EXCEPT,"dbg%d: try to attach a disabled card\n",unit);
535 DPRINT3(DB_INFO,"dgb%d: internal memory segment 0x%x\n",unit,sc->mem_seg);
537 outb(sc->port, FEPRST); DELAY(1);
539 for(i=0; (inb(sc->port) & FEPMASK) != FEPRST ; i++) {
541 printf("dgb%d: 1st reset failed\n",dev->id_unit);
549 DPRINT3(DB_INFO,"dgb%d: got reset after %d us\n",unit,i);
551 /* for PCXEVE set up interrupt and base address */
553 if(sc->type==PCXEVE) {
554 t=(((u_long)sc->pmem>>8) & 0xFFE0) | 0x10 /* enable windowing */;
556 outb(sc->port+2,t & 0xFF);
557 outb(sc->port+3,t>>8);
558 } else if(sc->type==PCXE) {
559 t=(((u_long)sc->pmem>>8) & 0xFFE0) /* disable windowing */;
560 outb(sc->port+2,t & 0xFF);
561 outb(sc->port+3,t>>8);
565 if(sc->type==PCXI || sc->type==PCXE) {
566 outb(sc->port, FEPRST|FEPMEM); DELAY(1);
568 for(i=0; (inb(sc->port) & FEPMASK) != (FEPRST|FEPMEM) ; i++) {
570 printf("dgb%d: 2nd reset failed\n",dev->id_unit);
578 DPRINT3(DB_INFO,"dgb%d: got memory after %d us\n",unit,i);
583 /* very short memory test */
585 addr=setinitwin(sc,BOTWIN);
586 *(u_long volatile *)(mem+addr) = 0xA55A3CC3;
587 if(*(u_long volatile *)(mem+addr)!=0xA55A3CC3) {
588 printf("dgb%d: 1st memory test failed\n",dev->id_unit);
594 addr=setinitwin(sc,TOPWIN);
595 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
596 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
597 printf("dgb%d: 2nd memory test failed\n",dev->id_unit);
603 addr=setinitwin(sc,BIOSCODE+((0xF000-sc->mem_seg)<<4));
604 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
605 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
606 printf("dgb%d: 3rd (BIOS) memory test failed\n",dev->id_unit);
609 addr=setinitwin(sc,MISCGLOBAL);
610 for(i=0; i<16; i++) {
614 if(sc->type==PCXI || sc->type==PCXE) {
616 addr=BIOSCODE+((0xF000-sc->mem_seg)<<4);
618 DPRINT3(DB_INFO,"dgb%d: BIOS local address=0x%x\n",unit,addr);
622 for(i=0; i<pcxx_nbios; i++, ptr++)
628 for(i=0; i<pcxx_nbios; i++, ptr++)
629 if( *ptr != pcxx_bios[i] ) {
630 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
631 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
634 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
639 outb(sc->port,FEPMEM);
641 for(i=0; (inb(sc->port) & FEPMASK) != FEPMEM ; i++) {
643 printf("dgb%d: BIOS start failed\n",dev->id_unit);
651 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
653 for(i=0; i<200000; i++) {
654 if( *((ushort volatile *)(mem+MISCGLOBAL)) == *((ushort *)"GD") )
658 printf("dgb%d: BIOS download failed\n",dev->id_unit);
659 DPRINT4(DB_EXCEPT,"dgb%d: code=0x%x must be 0x%x\n",
661 *((ushort volatile *)(mem+MISCGLOBAL)),
669 if(sc->type==PCXEVE) {
671 outb(sc->port+1,0xFF);
673 ptr= mem+(BIOSCODE & 0x1FFF);
675 for(i=0; i<pcxx_nbios; i++)
676 *ptr++ = pcxx_bios[i];
678 ptr= mem+(BIOSCODE & 0x1FFF);
681 for(i=0; i<pcxx_nbios; i++, ptr++)
682 if( *ptr != pcxx_bios[i] ) {
683 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
684 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
687 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
692 outb(sc->port,FEPCLR);
696 for(i=0; (inb(sc->port) & FEPMASK) != FEPCLR ; i++) {
698 printf("dgb%d: BIOS start failed\n",dev->id_unit);
706 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
708 addr=setwin(sc,MISCGLOBAL);
710 for(i=0; i<200000; i++) {
711 if(*(ushort volatile *)(mem+addr)== *(ushort *)"GD")
715 printf("dgb%d: BIOS download failed\n",dev->id_unit);
716 DPRINT5(DB_EXCEPT,"dgb%d: Error#(0x%x,0x%x) code=0x%x\n",
718 *(ushort volatile *)(mem+0xC12),
719 *(ushort volatile *)(mem+0xC14),
720 *(ushort volatile *)(mem+MISCGLOBAL));
728 DPRINT2(DB_INFO,"dgb%d: BIOS loaded\n",dev->id_unit);
730 addr=setwin(sc,FEPCODE);
734 for(i=0; i<pcxx_ncook; i++)
735 *ptr++ = pcxx_cook[i];
737 addr=setwin(sc,MBOX);
738 *(ushort volatile *)(mem+addr+ 0)=2;
739 *(ushort volatile *)(mem+addr+ 2)=sc->mem_seg+FEPCODESEG;
740 *(ushort volatile *)(mem+addr+ 4)=0;
741 *(ushort volatile *)(mem+addr+ 6)=FEPCODESEG;
742 *(ushort volatile *)(mem+addr+ 8)=0;
743 *(ushort volatile *)(mem+addr+10)=pcxx_ncook;
745 outb(sc->port,FEPMEM|FEPINT); /* send interrupt to BIOS */
746 outb(sc->port,FEPMEM);
748 for(i=0; *(ushort volatile *)(mem+addr)!=0; i++) {
750 printf("dgb%d: FEP code download failed\n",unit);
751 DPRINT3(DB_EXCEPT,"dgb%d: code=0x%x must be 0\n", unit,
752 *(ushort volatile *)(mem+addr));
759 DPRINT2(DB_INFO,"dgb%d: FEP code loaded\n",unit);
761 *(ushort volatile *)(mem+setwin(sc,FEPSTAT))=0;
762 addr=setwin(sc,MBOX);
763 *(ushort volatile *)(mem+addr+0)=1;
764 *(ushort volatile *)(mem+addr+2)=FEPCODESEG;
765 *(ushort volatile *)(mem+addr+4)=0x4;
767 outb(sc->port,FEPINT); /* send interrupt to BIOS */
768 outb(sc->port,FEPCLR);
770 addr=setwin(sc,FEPSTAT);
771 for(i=0; *(ushort volatile *)(mem+addr)!= *(ushort *)"OS"; i++) {
773 printf("dgb%d: FEP/OS start failed\n",dev->id_unit);
780 DPRINT2(DB_INFO,"dgb%d: FEP/OS started\n",dev->id_unit);
782 sc->numports= *(ushort volatile *)(mem+setwin(sc,NPORT));
784 printf("dgb%d: %d ports\n",unit,sc->numports);
786 if(sc->numports > MAX_DGB_PORTS) {
787 printf("dgb%d: too many ports\n",unit);
793 if(nports+sc->numports>NDGBPORTS) {
794 printf("dgb%d: only %d ports are usable\n", unit, NDGBPORTS-nports);
795 sc->numports=NDGBPORTS-nports;
798 /* allocate port and tty structures */
799 sc->ports=&dgb_ports[nports];
800 sc->ttys=&dgb_tty[nports];
801 nports+=sc->numports;
803 addr=setwin(sc,PORTBASE);
804 pstat=(ushort volatile *)(mem+addr);
806 for(i=0; i<sc->numports && pstat[i]; i++)
808 sc->ports[i].status=ENABLED;
810 sc->ports[i].status=DISABLED;
811 printf("dgb%d: port%d is broken\n", unit, i);
814 /* We should now init per-port structures */
815 bc=(volatile struct board_chan *)(mem + CHANSTRUCT);
816 sc->mailbox=(volatile struct global_data *)(mem + FEP_GLOBAL);
823 for(i=0; i<sc->numports; i++, bc++) {
826 port->tty=&sc->ttys[i];
842 DPRINT2(DB_INFO,"dgb%d: shrinking memory\n",unit);
843 fepcmd(port, SETBUFFER, 32, 0, 0, 0);
847 if(sc->type!=PCXEVE) {
848 port->txptr=mem+((bc->tseg-sc->mem_seg)<<4);
849 port->rxptr=mem+((bc->rseg-sc->mem_seg)<<4);
850 port->txwin=port->rxwin=0;
852 port->txptr=mem+( ((bc->tseg-sc->mem_seg)<<4) & 0x1FFF );
853 port->rxptr=mem+( ((bc->rseg-sc->mem_seg)<<4) & 0x1FFF );
854 port->txwin=FEPWIN | ((bc->tseg-sc->mem_seg)>>9);
855 port->rxwin=FEPWIN | ((bc->rseg-sc->mem_seg)>>9);
860 port->txbufsize=bc->tmax+1;
861 port->rxbufsize=bc->rmax+1;
863 lowwater= (port->txbufsize>=2000) ? 1024 : (port->txbufsize/2);
865 fepcmd(port, STXLWATER, lowwater, 0, 10, 0);
866 fepcmd(port, SRXLWATER, port->rxbufsize/4, 0, 10, 0);
867 fepcmd(port, SRXHWATER, 3*port->rxbufsize/4, 0, 10, 0);
872 port->startc=bc->startc;
873 port->startca=bc->startca;
874 port->stopc=bc->stopc;
875 port->stopca=bc->stopca;
877 /*port->close_delay=50;*/
878 port->close_delay=3 * hz;
879 port->do_timestamp=0;
880 port->do_dcd_timestamp=0;
883 * We don't use all the flags from <sys/ttydefaults.h> since they
884 * are only relevant for logins. It's important to have echo off
885 * initially so that the line doesn't start blathering before the
886 * echo flag can be turned off.
888 port->it_in.c_iflag = TTYDEF_IFLAG;
889 port->it_in.c_oflag = TTYDEF_OFLAG;
890 port->it_in.c_cflag = TTYDEF_CFLAG;
891 port->it_in.c_lflag = TTYDEF_LFLAG;
892 termioschars(&port->it_in);
893 port->it_in.c_ispeed = port->it_in.c_ospeed = dgbdefaultrate;
894 port->it_out = port->it_in;
895 /* MAX_DGB_PORTS is 32 => [0-9a-v] */
896 suffix = i < 10 ? '0' + i : 'a' + i - 10;
897 make_dev(&dgb_cdevsw, (unit*32)+i,
898 UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix);
900 make_dev(&dgb_cdevsw, (unit*32)+i+32,
901 UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix);
903 make_dev(&dgb_cdevsw, (unit*32)+i+64,
904 UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix);
906 make_dev(&dgb_cdevsw, (unit*32)+i+128,
907 UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix);
909 make_dev(&dgb_cdevsw, (unit*32)+i+160,
910 UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix);
912 make_dev(&dgb_cdevsw, (unit*32)+i+192,
913 UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix);
918 /* register the polling function */
919 timeout(dgbpoll, (void *)unit, hz/POLLSPERSEC);
926 dgbopen(dev, flag, mode, p)
932 struct dgb_softc *sc;
940 volatile struct board_chan *bc;
945 unit=MINOR_TO_UNIT(mynor);
946 pnum=MINOR_TO_PORT(mynor);
949 DPRINT2(DB_EXCEPT,"dgb%d: try to open a nonexisting card\n",unit);
955 if(sc->status!=ENABLED) {
956 DPRINT2(DB_EXCEPT,"dgb%d: try to open a disabled card\n",unit);
960 if(pnum>=sc->numports) {
961 DPRINT3(DB_EXCEPT,"dgb%d: try to open non-existing port %d\n",unit,pnum);
965 if(mynor & CONTROL_MASK)
970 port=&sc->ports[pnum];
977 while(port->closing) {
978 error=tsleep(&port->closing, TTOPRI|PCATCH, "dgocl", 0);
981 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgocl) error=%d\n",unit,pnum,error);
986 if (tp->t_state & TS_ISOPEN) {
988 * The device is open, so everything has been initialized.
991 if (mynor & CALLOUT_MASK) {
992 if (!port->active_out) {
994 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
998 if (port->active_out) {
999 if (flag & O_NONBLOCK) {
1001 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
1004 error = tsleep(&port->active_out,
1005 TTIPRI | PCATCH, "dgbi", 0);
1007 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgbi) error=%d\n",
1015 if (tp->t_state & TS_XCLUDE &&
1022 * The device isn't open, so there are no conflicts.
1023 * Initialize it. Initialization is done twice in many
1024 * cases: to preempt sleeping callin opens if we are
1025 * callout, and to complete a callin open after DCD rises.
1027 tp->t_oproc=dgbstart;
1028 tp->t_param=dgbparam;
1031 tp->t_termios= (mynor & CALLOUT_MASK) ?
1037 port->imodem=bc->mstat;
1038 bc->rout=bc->rin; /* clear input queue */
1040 #ifdef PRINT_BUFSIZE
1041 printf("dgb buffers tx=%x:%x rx=%x:%x\n",bc->tseg,bc->tmax,bc->rseg,bc->rmax);
1048 error=dgbparam(tp, &tp->t_termios);
1052 DPRINT4(DB_OPEN,"dgb%d: port%d: dgbparam error=%d\n",unit,pnum,error);
1056 /* handle fake DCD for callout devices */
1057 /* and initial DCD */
1059 if( (port->imodem & port->dcd) || mynor & CALLOUT_MASK )
1060 linesw[tp->t_line].l_modem(tp,1);
1065 * Wait for DCD if necessary.
1067 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1068 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1070 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "dgdcd", 0);
1073 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgdcd) error=%d\n",unit,pnum,error);
1079 error = linesw[tp->t_line].l_open(dev, tp);
1080 disc_optim(tp,&tp->t_termios);
1081 DPRINT4(DB_OPEN,"dgb%d: port%d: l_open error=%d\n",unit,pnum,error);
1083 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1084 port->active_out = TRUE;
1088 /* If any port is open (i.e. the open() call is completed for it)
1089 * the device is busy
1093 disc_optim(tp,&tp->t_termios);
1096 if( !(tp->t_state & TS_ISOPEN) && port->wopeners==0 )
1099 DPRINT4(DB_OPEN,"dgb%d: port%d: open() returns %d\n",unit,pnum,error);
1106 dgbclose(dev, flag, mode, p)
1115 struct dgb_softc *sc;
1121 if(mynor & CONTROL_MASK)
1123 unit=MINOR_TO_UNIT(mynor);
1124 pnum=MINOR_TO_PORT(mynor);
1126 sc=&dgb_softc[unit];
1128 port=sc->ports+pnum;
1130 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing\n",unit,pnum);
1132 DPRINT3(DB_CLOSE,"dgb%d: port%d: draining port\n",unit,pnum);
1133 dgb_drain_or_flush(port);
1138 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing line disc\n",unit,pnum);
1139 linesw[tp->t_line].l_close(tp,flag);
1140 disc_optim(tp,&tp->t_termios);
1142 DPRINT3(DB_CLOSE,"dgb%d: port%d: hard closing\n",unit,pnum);
1144 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing tty\n",unit,pnum);
1147 wakeup(&port->closing);
1150 /* mark the card idle when all ports are closed */
1152 for(i=0; i<sc->numports; i++)
1153 if(sc->ports[i].used)
1158 DPRINT3(DB_CLOSE,"dgb%d: port%d: closed\n",unit,pnum);
1160 wakeup(TSA_CARR_ON(tp));
1161 wakeup(&port->active_out);
1164 DPRINT3(DB_CLOSE,"dgb%d: port%d: close exit\n",unit,pnum);
1173 struct dgb_softc *sc=&dgb_softc[port->unit];
1174 volatile struct board_chan *bc=port->brdchan;
1178 port->do_timestamp = 0;
1181 bc->idata=0; bc->iempty=0; bc->ilow=0;
1182 if(port->tty->t_cflag & HUPCL) {
1183 port->omodem &= ~(RTS|DTR);
1184 fepcmd(port, SETMODEM, 0, DTR|RTS, 0, 1);
1190 timeout(dgb_pause, &port->brdchan, hz/2);
1191 tsleep(&port->brdchan, TTIPRI | PCATCH, "dgclo", 0);
1198 wakeup((caddr_t)chan);
1205 int unit=(int)unit_c;
1208 struct dgb_softc *sc=&dgb_softc[unit];
1211 int event, mstat, lstat;
1212 volatile struct board_chan *bc;
1219 int ibuf_full,obuf_full;
1221 BoardMemWinState ws=bmws_get();
1223 if(sc->status==DISABLED) {
1224 printf("dgb%d: polling of disabled board stopped\n",unit);
1230 head=sc->mailbox->ein;
1231 tail=sc->mailbox->eout;
1234 if(head >= FEP_IMAX-FEP_ISTART
1235 || tail >= FEP_IMAX-FEP_ISTART
1236 || (head|tail) & 03 ) {
1237 printf("dgb%d: event queue's head or tail is wrong! hd=%d,tl=%d\n", unit,head,tail);
1241 eventbuf=sc->vmem+tail+FEP_ISTART;
1247 port=&sc->ports[pnum];
1251 if(pnum>=sc->numports || port->status==DISABLED) {
1252 printf("dgb%d: port%d: got event on nonexisting port\n",unit,pnum);
1253 } else if(port->used || port->wopeners>0 ) {
1255 int wrapmask=port->rxbufsize-1;
1257 if( !(event & ALL_IND) )
1258 printf("dgb%d: port%d: ? event 0x%x mstat 0x%x lstat 0x%x\n",
1259 unit, pnum, event, mstat, lstat);
1261 if(event & DATA_IND) {
1262 DPRINT3(DB_DATA,"dgb%d: port%d: DATA_IND\n",unit,pnum);
1264 rhead=bc->rin & wrapmask;
1265 rtail=bc->rout & wrapmask;
1267 if( !(tp->t_cflag & CREAD) || !port->used ) {
1273 printf("dgb%d: port%d: overrun\n", unit, pnum);
1277 if(!(tp->t_state & TS_ISOPEN))
1280 for(ibuf_full=FALSE;rhead!=rtail && !ibuf_full;) {
1281 DPRINT5(DB_RXDATA,"dgb%d: port%d: p rx head=%d tail=%d\n",
1282 unit,pnum,rhead,rtail);
1287 size=port->rxbufsize-rtail;
1289 ptr=port->rxptr+rtail;
1292 if( tp->t_rawq.c_cc + size > DGB_IBUFSIZE ) {
1293 size=DGB_IBUFSIZE-tp->t_rawq.c_cc;
1294 DPRINT1(DB_RXDATA,"*");
1299 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1300 DPRINT1(DB_RXDATA,"!");
1301 towin(sc,port->rxwin);
1304 tp->t_rawcc += size;
1305 b_to_q(ptr,size,&tp->t_rawq);
1311 towin(sc,port->rxwin);
1314 (*linesw[tp->t_line].l_rint)(chr, tp);
1319 rtail= (rtail + size) & wrapmask;
1321 rhead=bc->rin & wrapmask;
1329 if(event & MODEMCHG_IND) {
1330 DPRINT3(DB_MODEM,"dgb%d: port%d: MODEMCHG_IND\n",unit,pnum);
1332 if(mstat & port->dcd) {
1334 linesw[tp->t_line].l_modem(tp,1);
1336 wakeup(TSA_CARR_ON(tp));
1339 linesw[tp->t_line].l_modem(tp,0);
1341 if( port->draining) {
1343 wakeup(&port->draining);
1348 if(event & BREAK_IND) {
1349 if((tp->t_state & TS_ISOPEN) && (tp->t_iflag & IGNBRK)) {
1350 DPRINT3(DB_BREAK,"dgb%d: port%d: BREAK_IND\n",unit,pnum);
1352 linesw[tp->t_line].l_rint(TTY_BI, tp);
1357 /* Helg: with output flow control */
1359 if(event & (LOWTX_IND | EMPTYTX_IND) ) {
1360 DPRINT3(DB_TXDATA,"dgb%d: port%d: LOWTX_IND or EMPTYTX_IND\n",unit,pnum);
1362 if( (event & EMPTYTX_IND ) && tp->t_outq.c_cc==0
1363 && port->draining) {
1365 wakeup(&port->draining);
1366 bc->ilow=0; bc->iempty=0;
1369 int wrapmask=port->txbufsize-1;
1371 for(obuf_full=FALSE; tp->t_outq.c_cc!=0 && !obuf_full; ) {
1373 /* add "last-minute" data to write buffer */
1374 if(!(tp->t_state & TS_BUSY)) {
1376 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1379 if(tp->t_outq.c_cc <= tp->t_lowat) {
1380 if(tp->t_state & TS_ASLEEP) {
1381 tp->t_state &= ~TS_ASLEEP;
1382 wakeup(TSA_OLOWAT(tp));
1384 /* selwakeup(&tp->t_wsel); */
1391 whead=bc->tin & wrapmask;
1392 wtail=bc->tout & wrapmask;
1397 size=port->txbufsize-whead;
1403 DPRINT5(DB_WR,"dgb: head=%d tail=%d size=%d full=%d\n",
1404 whead,wtail,size,obuf_full);
1405 bc->iempty=1; bc->ilow=1;
1411 towin(sc,port->txwin);
1413 ocount=q_to_b(&tp->t_outq, port->txptr+whead, size);
1418 bc->tin=whead & wrapmask;
1423 DPRINT1(DB_WR," +BUSY\n");
1424 tp->t_state|=TS_BUSY;
1426 DPRINT1(DB_WR," -BUSY\n");
1428 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1429 /* should clear TS_BUSY before ttwwakeup */
1430 if(tp->t_state & TS_BUSY) {
1431 tp->t_state &= ~TS_BUSY;
1432 linesw[tp->t_line].l_start(tp);
1436 if(tp->t_state & TS_ASLEEP) {
1437 tp->t_state &= ~TS_ASLEEP;
1438 wakeup(TSA_OLOWAT(tp));
1440 tp->t_state &= ~TS_BUSY;
1446 bc->idata=1; /* require event on incoming data */
1450 DPRINT4(DB_EXCEPT,"dgb%d: port%d: got event 0x%x on closed port\n",
1453 bc->idata=bc->iempty=bc->ilow=0;
1456 tail= (tail+4) & (FEP_IMAX-FEP_ISTART-4);
1459 sc->mailbox->eout=tail;
1462 timeout(dgbpoll, unit_c, hz/POLLSPERSEC);
1466 dgbioctl(dev, cmd, data, flag, p)
1473 struct dgb_softc *sc;
1478 volatile struct board_chan *bc;
1483 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1485 struct termios term;
1488 BoardMemWinState ws=bmws_get();
1491 unit=MINOR_TO_UNIT(mynor);
1492 pnum=MINOR_TO_PORT(mynor);
1494 sc=&dgb_softc[unit];
1495 port=&sc->ports[pnum];
1499 if (mynor & CONTROL_MASK) {
1502 switch (mynor & CONTROL_MASK) {
1503 case CONTROL_INIT_STATE:
1504 ct = mynor & CALLOUT_MASK ? &port->it_out : &port->it_in;
1506 case CONTROL_LOCK_STATE:
1507 ct = mynor & CALLOUT_MASK ? &port->lt_out : &port->lt_in;
1510 return (ENODEV); /* /dev/nodev */
1517 *ct = *(struct termios *)data;
1520 *(struct termios *)data = *ct;
1523 *(int *)data = TTYDISC;
1526 bzero(data, sizeof(struct winsize));
1533 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1534 term = tp->t_termios;
1535 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1536 DPRINT6(DB_PARAM,"dgb%d: port%d: dgbioctl-ISNOW c=0x%x i=0x%x l=0x%x\n",unit,pnum,term.c_cflag,term.c_iflag,term.c_lflag);
1539 error = ttsetcompat(tp, &cmd, data, &term);
1543 data = (caddr_t)&term;
1546 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1548 struct termios *dt = (struct termios *)data;
1549 struct termios *lt = mynor & CALLOUT_MASK
1550 ? &port->lt_out : &port->lt_in;
1552 DPRINT6(DB_PARAM,"dgb%d: port%d: dgbioctl-TOSET c=0x%x i=0x%x l=0x%x\n",unit,pnum,dt->c_cflag,dt->c_iflag,dt->c_lflag);
1553 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1554 | (dt->c_iflag & ~lt->c_iflag);
1555 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1556 | (dt->c_oflag & ~lt->c_oflag);
1557 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1558 | (dt->c_cflag & ~lt->c_cflag);
1559 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1560 | (dt->c_lflag & ~lt->c_lflag);
1561 for (cc = 0; cc < NCCS; ++cc)
1562 if (lt->c_cc[cc] != 0)
1563 dt->c_cc[cc] = tp->t_cc[cc];
1564 if (lt->c_ispeed != 0)
1565 dt->c_ispeed = tp->t_ispeed;
1566 if (lt->c_ospeed != 0)
1567 dt->c_ospeed = tp->t_ospeed;
1573 fepcmd(port, PAUSETX, 0, 0, 0, 0);
1577 } else if(cmd==TIOCSTART) {
1580 fepcmd(port, RESUMETX, 0, 0, 0, 0);
1586 if(cmd==TIOCSETAW || cmd==TIOCSETAF)
1589 error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p);
1590 if (error != ENOIOCTL)
1593 error = ttioctl(tp, cmd, data, flag);
1594 disc_optim(tp,&tp->t_termios);
1596 if (error != ENOIOCTL) {
1598 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1599 DPRINT6(DB_PARAM,"dgb%d: port%d: dgbioctl-RES c=0x%x i=0x%x l=0x%x\n",unit,pnum,tp->t_cflag,tp->t_iflag,tp->t_lflag);
1606 /* Helg: commented */
1607 /* error=dgbdrain(port);*/
1617 /* now it sends 250 millisecond break because I don't know */
1618 /* how to send an infinite break */
1620 fepcmd(port, SENDBREAK, 250, 0, 10, 0);
1625 /* now it's empty */
1628 DPRINT3(DB_MODEM,"dgb%d: port%d: set DTR\n",unit,pnum);
1629 port->omodem |= DTR;
1632 fepcmd(port, SETMODEM, port->omodem, RTS, 0, 1);
1634 if( !(bc->mstat & DTR) ) {
1635 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is off\n",unit,pnum);
1642 DPRINT3(DB_MODEM,"dgb%d: port%d: reset DTR\n",unit,pnum);
1643 port->omodem &= ~DTR;
1646 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1648 if( bc->mstat & DTR ) {
1649 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is on\n",unit,pnum);
1656 if(*(int *)data & TIOCM_DTR)
1659 port->omodem &=~DTR;
1661 if(*(int *)data & TIOCM_RTS)
1664 port->omodem &=~RTS;
1668 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1673 if(*(int *)data & TIOCM_DTR)
1676 if(*(int *)data & TIOCM_RTS)
1681 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1686 if(*(int *)data & TIOCM_DTR)
1687 port->omodem &=~DTR;
1689 if(*(int *)data & TIOCM_RTS)
1690 port->omodem &=~RTS;
1694 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1700 port->imodem=bc->mstat;
1703 tiocm_xxx = TIOCM_LE; /* XXX - always enabled while open */
1705 DPRINT3(DB_MODEM,"dgb%d: port%d: modem stat -- ",unit,pnum);
1707 if (port->imodem & DTR) {
1708 DPRINT1(DB_MODEM,"DTR ");
1709 tiocm_xxx |= TIOCM_DTR;
1711 if (port->imodem & RTS) {
1712 DPRINT1(DB_MODEM,"RTS ");
1713 tiocm_xxx |= TIOCM_RTS;
1715 if (port->imodem & CTS) {
1716 DPRINT1(DB_MODEM,"CTS ");
1717 tiocm_xxx |= TIOCM_CTS;
1719 if (port->imodem & port->dcd) {
1720 DPRINT1(DB_MODEM,"DCD ");
1721 tiocm_xxx |= TIOCM_CD;
1723 if (port->imodem & port->dsr) {
1724 DPRINT1(DB_MODEM,"DSR ");
1725 tiocm_xxx |= TIOCM_DSR;
1727 if (port->imodem & RI) {
1728 DPRINT1(DB_MODEM,"RI ");
1729 tiocm_xxx |= TIOCM_RI;
1731 *(int *)data = tiocm_xxx;
1732 DPRINT1(DB_MODEM,"--\n");
1735 /* must be root since the wait applies to following logins */
1741 port->close_delay = *(int *)data * hz / 100;
1744 *(int *)data = port->close_delay * 100 / hz;
1747 port->do_timestamp = TRUE;
1748 *(struct timeval *)data = port->timestamp;
1750 case TIOCDCDTIMESTAMP:
1751 port->do_dcd_timestamp = TRUE;
1752 *(struct timeval *)data = port->dcd_timestamp;
1769 struct dgb_p *port=p;
1771 wakeup(&port->draining);
1774 /* wait for the output to drain */
1780 struct dgb_softc *sc=&dgb_softc[port->unit];
1781 volatile struct board_chan *bc=port->brdchan;
1785 BoardMemWinState ws=bmws_get();
1794 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1795 port->unit, port->pnum, head, tail);
1799 timeout(wakeflush,port, hz);
1800 error=tsleep(&port->draining, TTIPRI | PCATCH, "dgdrn", 0);
1805 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgdrn) error=%d\n",
1806 port->unit,port->pnum,error);
1816 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1817 port->unit, port->pnum, head, tail);
1822 /* wait for the output to drain */
1823 /* or simply clear the buffer it it's stopped */
1826 dgb_drain_or_flush(port)
1829 struct tty *tp=port->tty;
1830 struct dgb_softc *sc=&dgb_softc[port->unit];
1831 volatile struct board_chan *bc=port->brdchan;
1843 while(tail!=head /* && tail!=lasttail */ ) {
1844 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1845 port->unit, port->pnum, head, tail);
1847 /* if there is no carrier simply clean the buffer */
1848 if( !(tp->t_state & TS_CARR_ON) ) {
1857 timeout(wakeflush,port, hz);
1858 error=tsleep(&port->draining, TTIPRI | PCATCH, "dgfls", 0);
1863 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgfls) error=%d\n",
1864 port->unit,port->pnum,error);
1866 /* silently clean the buffer */
1879 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1880 port->unit, port->pnum, head, tail);
1888 int unit=MINOR_TO_UNIT(minor(tp->t_dev));
1889 int pnum=MINOR_TO_PORT(minor(tp->t_dev));
1890 struct dgb_softc *sc=&dgb_softc[unit];
1891 struct dgb_p *port=&sc->ports[pnum];
1892 volatile struct board_chan *bc=port->brdchan;
1900 BoardMemWinState ws=bmws_get();
1902 DPRINT6(DB_PARAM,"dgb%d: port%d: dgbparm c=0x%x i=0x%x l=0x%x\n",unit,pnum,t->c_cflag,t->c_iflag,t->c_lflag);
1904 if(port->mustdrain) {
1905 DPRINT3(DB_PARAM,"dgb%d: port%d: must call dgbdrain()\n",unit,pnum);
1909 cflag=ttspeedtab(t->c_ospeed, dgbspeedtab);
1911 if (t->c_ispeed == 0)
1912 t->c_ispeed = t->c_ospeed;
1914 if (cflag < 0 /* || cflag > 0 && t->c_ispeed != t->c_ospeed */) {
1915 DPRINT4(DB_PARAM,"dgb%d: port%d: invalid cflag=0%o\n",unit,pnum,cflag);
1922 if(cflag==0) { /* hangup */
1923 DPRINT3(DB_PARAM,"dgb%d: port%d: hangup\n",unit,pnum);
1927 fepcmd(port, STOUT, (unsigned)head, 0, 0, 0);
1928 mval= port->omodem & ~(DTR|RTS);
1930 cflag |= dgbflags(dgb_cflags, t->c_cflag);
1932 if(cflag!=port->fepcflag) {
1933 port->fepcflag=cflag;
1934 DPRINT5(DB_PARAM,"dgb%d: port%d: set cflag=0x%x c=0x%x\n",
1935 unit,pnum,cflag,t->c_cflag&~CRTSCTS);
1936 fepcmd(port, SETCTRLFLAGS, (unsigned)cflag, 0, 0, 0);
1938 mval= port->omodem | (DTR|RTS);
1941 iflag=dgbflags(dgb_iflags, t->c_iflag);
1942 if(iflag!=port->fepiflag) {
1943 port->fepiflag=iflag;
1944 DPRINT5(DB_PARAM,"dgb%d: port%d: set iflag=0x%x c=0x%x\n",unit,pnum,iflag,t->c_iflag);
1945 fepcmd(port, SETIFLAGS, (unsigned)iflag, 0, 0, 0);
1950 hflow=dgbflags(dgb_flow, t->c_cflag);
1951 if(hflow!=port->hflow) {
1953 DPRINT5(DB_PARAM,"dgb%d: port%d: set hflow=0x%x f=0x%x\n",unit,pnum,hflow,t->c_cflag&CRTSCTS);
1954 fepcmd(port, SETHFLOW, (unsigned)hflow, 0xff, 0, 1);
1957 if(port->omodem != mval) {
1958 DPRINT5(DB_PARAM,"dgb%d: port%d: setting modem parameters 0x%x was 0x%x\n",
1959 unit,pnum,mval,port->omodem);
1961 fepcmd(port, SETMODEM, (unsigned)mval, RTS|DTR, 0, 1);
1964 if(port->fepstartc!=t->c_cc[VSTART] || port->fepstopc!=t->c_cc[VSTOP]) {
1965 DPRINT5(DB_PARAM,"dgb%d: port%d: set startc=%d, stopc=%d\n",unit,pnum,t->c_cc[VSTART],t->c_cc[VSTOP]);
1966 port->fepstartc=t->c_cc[VSTART];
1967 port->fepstopc=t->c_cc[VSTOP];
1968 fepcmd(port, SONOFFC, port->fepstartc, port->fepstopc, 0, 1);
1985 struct dgb_softc *sc;
1986 volatile struct board_chan *bc;
1992 BoardMemWinState ws=bmws_get();
1994 unit=MINOR_TO_UNIT(minor(tp->t_dev));
1995 pnum=MINOR_TO_PORT(minor(tp->t_dev));
1996 sc=&dgb_softc[unit];
1997 port=&sc->ports[pnum];
2000 wmask=port->txbufsize-1;
2004 while( tp->t_outq.c_cc!=0 ) {
2006 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2009 if(tp->t_outq.c_cc <= tp->t_lowat) {
2010 if(tp->t_state & TS_ASLEEP) {
2011 tp->t_state &= ~TS_ASLEEP;
2012 wakeup(TSA_OLOWAT(tp));
2014 /*selwakeup(&tp->t_wsel);*/
2020 head=bc->tin & wmask;
2022 do { tail=bc->tout; } while (tail != bc->tout);
2023 tail=bc->tout & wmask;
2025 DPRINT5(DB_WR,"dgb%d: port%d: s tx head=%d tail=%d\n",unit,pnum,head,tail);
2027 #ifdef LEAVE_FREE_CHARS
2029 size=tail-head-LEAVE_FREE_CHARS;
2033 size=port->txbufsize-head;
2034 if(tail+port->txbufsize < head)
2042 size=port->txbufsize-head/*-1*/;
2049 bc->iempty=1; bc->ilow=1;
2052 tp->t_state|=TS_BUSY;
2057 towin(sc,port->txwin);
2059 ocount=q_to_b(&tp->t_outq, port->txptr+head, size);
2061 if(head>=port->txbufsize)
2062 head-=port->txbufsize;
2067 DPRINT5(DB_WR,"dgb%d: port%d: tx avail=%d count=%d\n",unit,pnum,size,ocount);
2075 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2076 if(tp->t_state & TS_BUSY) {
2077 tp->t_state&=~TS_BUSY;
2078 linesw[tp->t_line].l_start(tp);
2082 if(tp->t_state & TS_ASLEEP) {
2083 tp->t_state &= ~TS_ASLEEP;
2084 wakeup(TSA_OLOWAT(tp));
2086 tp->t_state&=~TS_BUSY;
2098 struct dgb_softc *sc;
2099 volatile struct board_chan *bc;
2102 BoardMemWinState ws=bmws_get();
2104 unit=MINOR_TO_UNIT(minor(tp->t_dev));
2105 pnum=MINOR_TO_PORT(minor(tp->t_dev));
2107 sc=&dgb_softc[unit];
2108 port=&sc->ports[pnum];
2111 DPRINT3(DB_WR,"dgb%d: port%d: stop\n",port->unit, port->pnum);
2117 /* clear output queue */
2119 bc->ilow=0;bc->iempty=0;
2122 /* clear input queue */
2133 fepcmd(port, cmd, op1, op2, ncmds, bytecmd)
2135 unsigned cmd, op1, op2, ncmds, bytecmd;
2137 struct dgb_softc *sc=&dgb_softc[port->unit];
2138 u_char *mem=sc->vmem;
2139 unsigned tail, head;
2142 if(port->status==DISABLED) {
2143 printf("dgb%d: port%d: FEP command on disabled port\n",
2144 port->unit, port->pnum);
2148 /* setwin(sc,0); Require this to be set by caller */
2149 head=sc->mailbox->cin;
2151 if(head>=(FEP_CMAX-FEP_CSTART) || (head & 3)) {
2152 printf("dgb%d: port%d: wrong pointer head of command queue : 0x%x\n",
2153 port->unit, port->pnum, head);
2157 mem[head+FEP_CSTART+0]=cmd;
2158 mem[head+FEP_CSTART+1]=port->pnum;
2160 mem[head+FEP_CSTART+2]=op1;
2161 mem[head+FEP_CSTART+3]=op2;
2163 mem[head+FEP_CSTART+2]=op1&0xff;
2164 mem[head+FEP_CSTART+3]=(op1>>8)&0xff;
2167 DPRINT7(DB_FEP,"dgb%d: port%d: %s cmd=0x%x op1=0x%x op2=0x%x\n", port->unit, port->pnum,
2168 (bytecmd)?"byte":"word", cmd, mem[head+FEP_CSTART+2], mem[head+FEP_CSTART+3]);
2170 head=(head+4) & (FEP_CMAX-FEP_CSTART-4);
2171 sc->mailbox->cin=head;
2175 while (count-- != 0) {
2176 head=sc->mailbox->cin;
2177 tail=sc->mailbox->cout;
2179 n = (head-tail) & (FEP_CMAX-FEP_CSTART-4);
2180 if(n <= ncmds * (sizeof(ushort)*4))
2183 printf("dgb%d(%d): timeout on FEP cmd=0x%x\n", port->unit, port->pnum, cmd);
2191 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2192 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2193 && (!(t->c_iflag & PARMRK)
2194 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2195 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2196 && linesw[tp->t_line].l_rint == ttyinput)
2197 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2199 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;