2 * dgb.c $FreeBSD: src/sys/gnu/i386/isa/dgb.c,v 1.56.2.1 2001/02/26 04:23:09 jlemon Exp $
3 * dgb.c $DragonFly: src/sys/platform/pc32/gnu/isa/dgb.c,v 1.4 2003/07/19 21:14:32 dillon Exp $
7 * Stage 1. "Better than nothing".
8 * Stage 2. "Gee, it works!".
10 * Based on sio driver by Bruce Evans and on Linux driver by Troy
11 * De Jongh <troyd@digibd.com> or <troyd@skypoint.com>
12 * which is under GNU General Public License version 2 so this driver
13 * is forced to be under GPL 2 too.
15 * Written by Serge Babkin,
16 * Joint Stock Commercial Bank "Chelindbank"
17 * (Chelyabinsk, Russia)
18 * babkin@hq.icb.chel.su
20 * Assorted hacks to make it more functional and working under 3.0-current.
21 * Fixed broken routines to prevent processes hanging on closed (thanks
22 * to Bruce for his patience and assistance). Thanks also to Maxim Bolotin
23 * <max@run.net> for his patches which did most of the work to get this
24 * running under 2.2/3.0-current.
25 * Implemented ioctls: TIOCMSDTRWAIT, TIOCMGDTRWAIT, TIOCTIMESTAMP &
27 * Sysctl debug flag is now a bitflag, to filter noise during debugging.
28 * David L. Nugent <davidn@blaze.net.au>
31 #include "opt_compat.h"
36 /* Helg: i.e.25 times per sec board will be polled */
37 #define POLLSPERSEC 25
38 /* How many charactes can we write to input tty rawq */
39 #define DGB_IBUFSIZE (TTYHOG-100)
41 /* the overall number of ports controlled by this driver */
44 # define NDGBPORTS (NDGB*16)
47 #include <sys/param.h>
48 #include <sys/systm.h>
52 #include <sys/dkstat.h>
53 #include <sys/fcntl.h>
54 #include <sys/kernel.h>
55 #include <sys/sysctl.h>
57 #include <machine/clock.h>
62 #include <i386/isa/isa_device.h>
64 #include <gnu/i386/isa/dgbios.h>
65 #include <gnu/i386/isa/dgfep.h>
67 #define DGB_DEBUG /* Enable debugging info via sysctl */
68 #include <gnu/i386/isa/dgreg.h>
70 #define CALLOUT_MASK 0x80
71 #define CONTROL_MASK 0x60
72 #define CONTROL_INIT_STATE 0x20
73 #define CONTROL_LOCK_STATE 0x40
74 #define UNIT_MASK 0x30000
75 #define PORT_MASK 0x1F
76 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
77 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
78 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
79 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
81 /* types. XXX - should be elsewhere */
82 typedef u_char bool_t; /* boolean */
84 /* digiboard port structure */
88 u_char unit; /* board unit number */
89 u_char pnum; /* port number */
90 u_char omodem; /* FEP output modem status */
91 u_char imodem; /* FEP input modem status */
92 u_char modemfake; /* Modem values to be forced */
93 u_char modem; /* Force values */
122 volatile struct board_chan *brdchan;
125 bool_t active_out; /* nonzero if the callout device is open */
126 u_int wopeners; /* # processes waiting for DCD in open() */
129 struct termios it_in; /* should be in struct tty */
130 struct termios it_out;
133 struct termios lt_in; /* should be in struct tty */
134 struct termios lt_out;
137 bool_t do_dcd_timestamp;
138 struct timeval timestamp;
139 struct timeval dcd_timestamp;
141 /* flags of state, are used in sleep() too */
142 u_char closing; /* port is being closed now */
143 u_char draining; /* port is being drained now */
144 u_char used; /* port is being used now */
145 u_char mustdrain; /* data must be waited to drain in dgbparam() */
148 /* Digiboard per-board structure */
150 /* struct board_info */
151 u_char status; /* status: DISABLED/ENABLED */
152 u_char unit; /* unit number */
153 u_char type; /* type of card: PCXE, PCXI, PCXEVE */
154 u_char altpin; /* do we need alternate pin setting ? */
155 int numports; /* number of ports on card */
156 int port; /* I/O port */
157 u_char *vmem; /* virtual memory address */
158 long pmem; /* physical memory address */
159 int mem_seg; /* internal memory segment */
160 struct dgb_p *ports; /* pointer to array of port descriptors */
161 struct tty *ttys; /* pointer to array of TTY structures */
162 volatile struct global_data *mailbox;
166 static struct dgb_softc dgb_softc[NDGB];
167 static struct dgb_p dgb_ports[NDGBPORTS];
168 static struct tty dgb_tty[NDGBPORTS];
171 * The public functions in the com module ought to be declared in a com-driver
175 /* Interrupt handling entry points. */
176 static void dgbpoll __P((void *unit_c));
178 /* Device switch entry points. */
179 #define dgbreset noreset
180 #define dgbmmap nommap
181 #define dgbstrategy nostrategy
183 static int dgbattach __P((struct isa_device *dev));
184 static int dgbprobe __P((struct isa_device *dev));
186 static void fepcmd(struct dgb_p *port, unsigned cmd, unsigned op1, unsigned op2,
187 unsigned ncmds, unsigned bytecmd);
189 static void dgbstart __P((struct tty *tp));
190 static void dgbstop __P((struct tty *tp, int rw));
191 static int dgbparam __P((struct tty *tp, struct termios *t));
192 static void dgbhardclose __P((struct dgb_p *port));
193 static void dgb_drain_or_flush __P((struct dgb_p *port));
194 static int dgbdrain __P((struct dgb_p *port));
195 static void dgb_pause __P((void *chan));
196 static void wakeflush __P((void *p));
197 static void disc_optim __P((struct tty *tp, struct termios *t));
200 struct isa_driver dgbdriver = {
201 dgbprobe, dgbattach, "dgb",0
204 static d_open_t dgbopen;
205 static d_close_t dgbclose;
206 static d_ioctl_t dgbioctl;
208 #define CDEV_MAJOR 58
209 static struct cdevsw dgb_cdevsw = {
211 /* close */ dgbclose,
213 /* write */ ttywrite,
214 /* ioctl */ dgbioctl,
217 /* strategy */ nostrategy,
219 /* maj */ CDEV_MAJOR,
222 /* flags */ D_TTY | D_KQFILTER,
224 /* kqfilter */ ttykqfilter,
227 static speed_t dgbdefaultrate = TTYDEF_SPEED;
229 static struct speedtab dgbspeedtab[] = {
230 0, FEP_B0, /* old (sysV-like) Bx codes */
246 57600, (FEP_FASTBAUD|FEP_B50), /* B50 & fast baud table */
247 115200, (FEP_FASTBAUD|FEP_B110), /* B100 & fast baud table */
251 static struct dbgflagtbl
258 { PARODD, PARODD, FEP_PARODD },
259 { PARENB, PARENB, FEP_PARENB },
260 { CSTOPB, CSTOPB, FEP_CSTOPB },
261 { CSIZE, CS5, FEP_CS6 },
262 { CSIZE, CS6, FEP_CS6 },
263 { CSIZE, CS7, FEP_CS7 },
264 { CSIZE, CS8, FEP_CS8 },
265 { CLOCAL, CLOCAL, FEP_CLOCAL },
269 { IGNBRK, IGNBRK, FEP_IGNBRK },
270 { BRKINT, BRKINT, FEP_BRKINT },
271 { IGNPAR, IGNPAR, FEP_IGNPAR },
272 { PARMRK, PARMRK, FEP_PARMRK },
273 { INPCK, INPCK, FEP_INPCK },
274 { ISTRIP, ISTRIP, FEP_ISTRIP },
275 { IXON, IXON, FEP_IXON },
276 { IXOFF, IXOFF, FEP_IXOFF },
277 { IXANY, IXANY, FEP_IXANY },
281 { CRTSCTS, CRTSCTS, CTS|RTS },
282 { CRTSCTS, CCTS_OFLOW, CTS },
283 { CRTSCTS, CRTS_IFLOW, RTS },
287 /* xlat bsd termios flags to dgb sys-v style */
289 dgbflags(struct dbgflagtbl *tbl, tcflag_t input)
294 for (i=0; tbl[i].in_mask != (tcflag_t)-1; i++)
296 if ((input & tbl[i].in_mask) == tbl[i].in_val)
297 output |= tbl[i].out_val;
303 static int dgbdebug=0;
304 SYSCTL_INT(_debug, OID_AUTO, dgb_debug, CTLFLAG_RW, &dgbdebug, 0, "");
307 static __inline int setwin __P((struct dgb_softc *sc, unsigned addr));
308 static __inline int setinitwin __P((struct dgb_softc *sc, unsigned addr));
309 static __inline void hidewin __P((struct dgb_softc *sc));
310 static __inline void towin __P((struct dgb_softc *sc, int win));
312 /*Helg: to allow recursive dgb...() calls */
314 { /* If we were called and don't want to disturb we need: */
315 int port; /* write to this port */
316 u_char data; /* this data on exit */
317 /* or DATA_WINOFF to close memory window on entry */
318 } BoardMemWinState; /* so several channels and even boards can coexist */
319 #define DATA_WINOFF 0
320 static BoardMemWinState bmws;
322 /* return current memory window state and close window */
323 static BoardMemWinState
326 BoardMemWinState bmwsRet=bmws;
327 if(bmws.data!=DATA_WINOFF)
328 outb(bmws.port, bmws.data=DATA_WINOFF);
332 /* restore memory window state */
334 bmws_set(BoardMemWinState ws)
336 if(ws.data != bmws.data || ws.port!=bmws.port ) {
337 if(bmws.data!=DATA_WINOFF)
338 outb(bmws.port,DATA_WINOFF);
339 if(ws.data!=DATA_WINOFF)
340 outb(ws.port, ws.data);
347 struct dgb_softc *sc;
350 if(sc->type==PCXEVE) {
351 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
352 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
353 return (addr & 0x1FFF);
355 outb(bmws.port=sc->port,bmws.data=FEPMEM);
362 struct dgb_softc *sc;
365 if(sc->type==PCXEVE) {
366 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
367 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
368 return (addr & 0x1FFF);
370 outb(bmws.port=sc->port,bmws.data=inb(sc->port)|FEPMEM);
377 struct dgb_softc *sc;
381 outb(bmws.port=sc->port+1, bmws.data);
383 outb(bmws.port=sc->port, bmws.data);
388 struct dgb_softc *sc;
391 if(sc->type==PCXEVE) {
392 outb(bmws.port=sc->port+1, bmws.data=win);
394 outb(bmws.port=sc->port,bmws.data=FEPMEM);
400 struct isa_device *dev;
402 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
404 u_long win_size; /* size of vizible memory window */
405 int unit=dev->id_unit;
409 cdevsw_add(&dgb_cdevsw);
410 sc->unit=dev->id_unit;
411 sc->port=dev->id_iobase;
413 if(dev->id_flags & DGBFLAG_ALTPIN)
418 /* left 24 bits only (ISA address) */
419 sc->pmem=((intptr_t)(void *)dev->id_maddr & 0xFFFFFF);
421 DPRINT4(DB_INFO,"dgb%d: port 0x%x mem 0x%lx\n",unit,sc->port,sc->pmem);
423 outb(sc->port, FEPRST);
426 for(i=0; i< 1000; i++) {
428 if( (inb(sc->port) & FEPMASK) == FEPRST ) {
430 DPRINT3(DB_EXCEPT,"dgb%d: got reset after %d us\n",unit,i);
435 if(sc->status!=ENABLED) {
436 DPRINT2(DB_EXCEPT,"dgb%d: failed to respond\n",dev->id_unit);
440 /* check type of card and get internal memory characteristics */
449 printf("dgb%d: PC/Xi 64K\n",dev->id_unit);
454 printf("dgb%d: PC/Xi 128K\n",dev->id_unit);
459 printf("dgb%d: PC/Xi 256K\n",dev->id_unit);
461 default: /* case 0x30: */
464 printf("dgb%d: PC/Xi 512K\n",dev->id_unit);
473 printf("dgb%d: PC/Xm isn't supported\n",dev->id_unit);
480 if(dev->id_flags==DGBFLAG_NOWIN || ( v&0xC0 )==0) {
482 printf("dgb%d: PC/Xe 64K\n",dev->id_unit);
486 printf("dgb%d: PC/Xe 64/8K (windowed)\n",dev->id_unit);
488 if((u_long)sc->pmem & ~0xFFE000) {
489 printf("dgb%d: warning: address 0x%lx truncated to 0x%lx\n",
490 dev->id_unit, sc->pmem,
491 sc->pmem & 0xFFE000);
493 dev->id_maddr= (u_char *)(void *)(intptr_t)( sc->pmem & 0xFFE000 );
498 /* save size of vizible memory segment */
499 dev->id_msize=win_size;
502 dev->id_maddr=sc->vmem=pmap_mapdev(sc->pmem,dev->id_msize);
504 outb(sc->port, FEPCLR); /* drop RESET */
505 hidewin(sc); /* Helg: to set initial bmws state */
507 return 4; /* we need I/O space of 4 ports */
512 struct isa_device *dev;
514 int unit=dev->id_unit;
515 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
517 u_char volatile *mem;
518 u_char volatile *ptr;
521 volatile struct board_chan *bc;
529 if(sc->status!=ENABLED) {
530 DPRINT2(DB_EXCEPT,"dbg%d: try to attach a disabled card\n",unit);
536 DPRINT3(DB_INFO,"dgb%d: internal memory segment 0x%x\n",unit,sc->mem_seg);
538 outb(sc->port, FEPRST); DELAY(1);
540 for(i=0; (inb(sc->port) & FEPMASK) != FEPRST ; i++) {
542 printf("dgb%d: 1st reset failed\n",dev->id_unit);
550 DPRINT3(DB_INFO,"dgb%d: got reset after %d us\n",unit,i);
552 /* for PCXEVE set up interrupt and base address */
554 if(sc->type==PCXEVE) {
555 t=(((u_long)sc->pmem>>8) & 0xFFE0) | 0x10 /* enable windowing */;
557 outb(sc->port+2,t & 0xFF);
558 outb(sc->port+3,t>>8);
559 } else if(sc->type==PCXE) {
560 t=(((u_long)sc->pmem>>8) & 0xFFE0) /* disable windowing */;
561 outb(sc->port+2,t & 0xFF);
562 outb(sc->port+3,t>>8);
566 if(sc->type==PCXI || sc->type==PCXE) {
567 outb(sc->port, FEPRST|FEPMEM); DELAY(1);
569 for(i=0; (inb(sc->port) & FEPMASK) != (FEPRST|FEPMEM) ; i++) {
571 printf("dgb%d: 2nd reset failed\n",dev->id_unit);
579 DPRINT3(DB_INFO,"dgb%d: got memory after %d us\n",unit,i);
584 /* very short memory test */
586 addr=setinitwin(sc,BOTWIN);
587 *(u_long volatile *)(mem+addr) = 0xA55A3CC3;
588 if(*(u_long volatile *)(mem+addr)!=0xA55A3CC3) {
589 printf("dgb%d: 1st memory test failed\n",dev->id_unit);
595 addr=setinitwin(sc,TOPWIN);
596 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
597 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
598 printf("dgb%d: 2nd memory test failed\n",dev->id_unit);
604 addr=setinitwin(sc,BIOSCODE+((0xF000-sc->mem_seg)<<4));
605 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
606 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
607 printf("dgb%d: 3rd (BIOS) memory test failed\n",dev->id_unit);
610 addr=setinitwin(sc,MISCGLOBAL);
611 for(i=0; i<16; i++) {
615 if(sc->type==PCXI || sc->type==PCXE) {
617 addr=BIOSCODE+((0xF000-sc->mem_seg)<<4);
619 DPRINT3(DB_INFO,"dgb%d: BIOS local address=0x%x\n",unit,addr);
623 for(i=0; i<pcxx_nbios; i++, ptr++)
629 for(i=0; i<pcxx_nbios; i++, ptr++)
630 if( *ptr != pcxx_bios[i] ) {
631 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
632 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
635 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
640 outb(sc->port,FEPMEM);
642 for(i=0; (inb(sc->port) & FEPMASK) != FEPMEM ; i++) {
644 printf("dgb%d: BIOS start failed\n",dev->id_unit);
652 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
654 for(i=0; i<200000; i++) {
655 if( *((ushort volatile *)(mem+MISCGLOBAL)) == *((ushort *)"GD") )
659 printf("dgb%d: BIOS download failed\n",dev->id_unit);
660 DPRINT4(DB_EXCEPT,"dgb%d: code=0x%x must be 0x%x\n",
662 *((ushort volatile *)(mem+MISCGLOBAL)),
670 if(sc->type==PCXEVE) {
672 outb(sc->port+1,0xFF);
674 ptr= mem+(BIOSCODE & 0x1FFF);
676 for(i=0; i<pcxx_nbios; i++)
677 *ptr++ = pcxx_bios[i];
679 ptr= mem+(BIOSCODE & 0x1FFF);
682 for(i=0; i<pcxx_nbios; i++, ptr++)
683 if( *ptr != pcxx_bios[i] ) {
684 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
685 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
688 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
693 outb(sc->port,FEPCLR);
697 for(i=0; (inb(sc->port) & FEPMASK) != FEPCLR ; i++) {
699 printf("dgb%d: BIOS start failed\n",dev->id_unit);
707 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
709 addr=setwin(sc,MISCGLOBAL);
711 for(i=0; i<200000; i++) {
712 if(*(ushort volatile *)(mem+addr)== *(ushort *)"GD")
716 printf("dgb%d: BIOS download failed\n",dev->id_unit);
717 DPRINT5(DB_EXCEPT,"dgb%d: Error#(0x%x,0x%x) code=0x%x\n",
719 *(ushort volatile *)(mem+0xC12),
720 *(ushort volatile *)(mem+0xC14),
721 *(ushort volatile *)(mem+MISCGLOBAL));
729 DPRINT2(DB_INFO,"dgb%d: BIOS loaded\n",dev->id_unit);
731 addr=setwin(sc,FEPCODE);
735 for(i=0; i<pcxx_ncook; i++)
736 *ptr++ = pcxx_cook[i];
738 addr=setwin(sc,MBOX);
739 *(ushort volatile *)(mem+addr+ 0)=2;
740 *(ushort volatile *)(mem+addr+ 2)=sc->mem_seg+FEPCODESEG;
741 *(ushort volatile *)(mem+addr+ 4)=0;
742 *(ushort volatile *)(mem+addr+ 6)=FEPCODESEG;
743 *(ushort volatile *)(mem+addr+ 8)=0;
744 *(ushort volatile *)(mem+addr+10)=pcxx_ncook;
746 outb(sc->port,FEPMEM|FEPINT); /* send interrupt to BIOS */
747 outb(sc->port,FEPMEM);
749 for(i=0; *(ushort volatile *)(mem+addr)!=0; i++) {
751 printf("dgb%d: FEP code download failed\n",unit);
752 DPRINT3(DB_EXCEPT,"dgb%d: code=0x%x must be 0\n", unit,
753 *(ushort volatile *)(mem+addr));
760 DPRINT2(DB_INFO,"dgb%d: FEP code loaded\n",unit);
762 *(ushort volatile *)(mem+setwin(sc,FEPSTAT))=0;
763 addr=setwin(sc,MBOX);
764 *(ushort volatile *)(mem+addr+0)=1;
765 *(ushort volatile *)(mem+addr+2)=FEPCODESEG;
766 *(ushort volatile *)(mem+addr+4)=0x4;
768 outb(sc->port,FEPINT); /* send interrupt to BIOS */
769 outb(sc->port,FEPCLR);
771 addr=setwin(sc,FEPSTAT);
772 for(i=0; *(ushort volatile *)(mem+addr)!= *(ushort *)"OS"; i++) {
774 printf("dgb%d: FEP/OS start failed\n",dev->id_unit);
781 DPRINT2(DB_INFO,"dgb%d: FEP/OS started\n",dev->id_unit);
783 sc->numports= *(ushort volatile *)(mem+setwin(sc,NPORT));
785 printf("dgb%d: %d ports\n",unit,sc->numports);
787 if(sc->numports > MAX_DGB_PORTS) {
788 printf("dgb%d: too many ports\n",unit);
794 if(nports+sc->numports>NDGBPORTS) {
795 printf("dgb%d: only %d ports are usable\n", unit, NDGBPORTS-nports);
796 sc->numports=NDGBPORTS-nports;
799 /* allocate port and tty structures */
800 sc->ports=&dgb_ports[nports];
801 sc->ttys=&dgb_tty[nports];
802 nports+=sc->numports;
804 addr=setwin(sc,PORTBASE);
805 pstat=(ushort volatile *)(mem+addr);
807 for(i=0; i<sc->numports && pstat[i]; i++)
809 sc->ports[i].status=ENABLED;
811 sc->ports[i].status=DISABLED;
812 printf("dgb%d: port%d is broken\n", unit, i);
815 /* We should now init per-port structures */
816 bc=(volatile struct board_chan *)(mem + CHANSTRUCT);
817 sc->mailbox=(volatile struct global_data *)(mem + FEP_GLOBAL);
824 for(i=0; i<sc->numports; i++, bc++) {
827 port->tty=&sc->ttys[i];
843 DPRINT2(DB_INFO,"dgb%d: shrinking memory\n",unit);
844 fepcmd(port, SETBUFFER, 32, 0, 0, 0);
848 if(sc->type!=PCXEVE) {
849 port->txptr=mem+((bc->tseg-sc->mem_seg)<<4);
850 port->rxptr=mem+((bc->rseg-sc->mem_seg)<<4);
851 port->txwin=port->rxwin=0;
853 port->txptr=mem+( ((bc->tseg-sc->mem_seg)<<4) & 0x1FFF );
854 port->rxptr=mem+( ((bc->rseg-sc->mem_seg)<<4) & 0x1FFF );
855 port->txwin=FEPWIN | ((bc->tseg-sc->mem_seg)>>9);
856 port->rxwin=FEPWIN | ((bc->rseg-sc->mem_seg)>>9);
861 port->txbufsize=bc->tmax+1;
862 port->rxbufsize=bc->rmax+1;
864 lowwater= (port->txbufsize>=2000) ? 1024 : (port->txbufsize/2);
866 fepcmd(port, STXLWATER, lowwater, 0, 10, 0);
867 fepcmd(port, SRXLWATER, port->rxbufsize/4, 0, 10, 0);
868 fepcmd(port, SRXHWATER, 3*port->rxbufsize/4, 0, 10, 0);
873 port->startc=bc->startc;
874 port->startca=bc->startca;
875 port->stopc=bc->stopc;
876 port->stopca=bc->stopca;
878 /*port->close_delay=50;*/
879 port->close_delay=3 * hz;
880 port->do_timestamp=0;
881 port->do_dcd_timestamp=0;
884 * We don't use all the flags from <sys/ttydefaults.h> since they
885 * are only relevant for logins. It's important to have echo off
886 * initially so that the line doesn't start blathering before the
887 * echo flag can be turned off.
889 port->it_in.c_iflag = TTYDEF_IFLAG;
890 port->it_in.c_oflag = TTYDEF_OFLAG;
891 port->it_in.c_cflag = TTYDEF_CFLAG;
892 port->it_in.c_lflag = TTYDEF_LFLAG;
893 termioschars(&port->it_in);
894 port->it_in.c_ispeed = port->it_in.c_ospeed = dgbdefaultrate;
895 port->it_out = port->it_in;
896 /* MAX_DGB_PORTS is 32 => [0-9a-v] */
897 suffix = i < 10 ? '0' + i : 'a' + i - 10;
898 make_dev(&dgb_cdevsw, (unit*32)+i,
899 UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix);
901 make_dev(&dgb_cdevsw, (unit*32)+i+32,
902 UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix);
904 make_dev(&dgb_cdevsw, (unit*32)+i+64,
905 UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix);
907 make_dev(&dgb_cdevsw, (unit*32)+i+128,
908 UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix);
910 make_dev(&dgb_cdevsw, (unit*32)+i+160,
911 UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix);
913 make_dev(&dgb_cdevsw, (unit*32)+i+192,
914 UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix);
919 /* register the polling function */
920 timeout(dgbpoll, (void *)unit, hz/POLLSPERSEC);
927 dgbopen(dev_t dev, int flag, int mode, struct thread *td)
929 struct dgb_softc *sc;
937 volatile struct board_chan *bc;
942 unit=MINOR_TO_UNIT(mynor);
943 pnum=MINOR_TO_PORT(mynor);
946 DPRINT2(DB_EXCEPT,"dgb%d: try to open a nonexisting card\n",unit);
952 if(sc->status!=ENABLED) {
953 DPRINT2(DB_EXCEPT,"dgb%d: try to open a disabled card\n",unit);
957 if(pnum>=sc->numports) {
958 DPRINT3(DB_EXCEPT,"dgb%d: try to open non-existing port %d\n",unit,pnum);
962 if(mynor & CONTROL_MASK)
967 port=&sc->ports[pnum];
974 while(port->closing) {
975 error=tsleep(&port->closing, PCATCH, "dgocl", 0);
978 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgocl) error=%d\n",unit,pnum,error);
983 if (tp->t_state & TS_ISOPEN) {
985 * The device is open, so everything has been initialized.
988 if (mynor & CALLOUT_MASK) {
989 if (!port->active_out) {
991 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
995 if (port->active_out) {
996 if (flag & O_NONBLOCK) {
998 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
1001 error = tsleep(&port->active_out,
1004 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgbi) error=%d\n",
1012 if (tp->t_state & TS_XCLUDE && suser(td)) {
1018 * The device isn't open, so there are no conflicts.
1019 * Initialize it. Initialization is done twice in many
1020 * cases: to preempt sleeping callin opens if we are
1021 * callout, and to complete a callin open after DCD rises.
1023 tp->t_oproc=dgbstart;
1024 tp->t_param=dgbparam;
1027 tp->t_termios= (mynor & CALLOUT_MASK) ?
1033 port->imodem=bc->mstat;
1034 bc->rout=bc->rin; /* clear input queue */
1036 #ifdef PRINT_BUFSIZE
1037 printf("dgb buffers tx=%x:%x rx=%x:%x\n",bc->tseg,bc->tmax,bc->rseg,bc->rmax);
1044 error=dgbparam(tp, &tp->t_termios);
1048 DPRINT4(DB_OPEN,"dgb%d: port%d: dgbparam error=%d\n",unit,pnum,error);
1052 /* handle fake DCD for callout devices */
1053 /* and initial DCD */
1055 if( (port->imodem & port->dcd) || mynor & CALLOUT_MASK )
1056 linesw[tp->t_line].l_modem(tp,1);
1061 * Wait for DCD if necessary.
1063 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1064 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1066 error = tsleep(TSA_CARR_ON(tp), PCATCH, "dgdcd", 0);
1069 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgdcd) error=%d\n",unit,pnum,error);
1075 error = linesw[tp->t_line].l_open(dev, tp);
1076 disc_optim(tp,&tp->t_termios);
1077 DPRINT4(DB_OPEN,"dgb%d: port%d: l_open error=%d\n",unit,pnum,error);
1079 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1080 port->active_out = TRUE;
1084 /* If any port is open (i.e. the open() call is completed for it)
1085 * the device is busy
1089 disc_optim(tp,&tp->t_termios);
1092 if( !(tp->t_state & TS_ISOPEN) && port->wopeners==0 )
1095 DPRINT4(DB_OPEN,"dgb%d: port%d: open() returns %d\n",unit,pnum,error);
1102 dgbclose(dev_t dev, int flag, int mode, struct thread *td)
1106 struct dgb_softc *sc;
1113 if(mynor & CONTROL_MASK)
1115 unit=MINOR_TO_UNIT(mynor);
1116 pnum=MINOR_TO_PORT(mynor);
1118 sc=&dgb_softc[unit];
1120 port=sc->ports+pnum;
1122 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing\n",unit,pnum);
1124 DPRINT3(DB_CLOSE,"dgb%d: port%d: draining port\n",unit,pnum);
1125 dgb_drain_or_flush(port);
1130 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing line disc\n",unit,pnum);
1131 linesw[tp->t_line].l_close(tp,flag);
1132 disc_optim(tp,&tp->t_termios);
1134 DPRINT3(DB_CLOSE,"dgb%d: port%d: hard closing\n",unit,pnum);
1136 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing tty\n",unit,pnum);
1139 wakeup(&port->closing);
1142 /* mark the card idle when all ports are closed */
1144 for(i=0; i<sc->numports; i++)
1145 if(sc->ports[i].used)
1150 DPRINT3(DB_CLOSE,"dgb%d: port%d: closed\n",unit,pnum);
1152 wakeup(TSA_CARR_ON(tp));
1153 wakeup(&port->active_out);
1156 DPRINT3(DB_CLOSE,"dgb%d: port%d: close exit\n",unit,pnum);
1165 struct dgb_softc *sc=&dgb_softc[port->unit];
1166 volatile struct board_chan *bc=port->brdchan;
1170 port->do_timestamp = 0;
1173 bc->idata=0; bc->iempty=0; bc->ilow=0;
1174 if(port->tty->t_cflag & HUPCL) {
1175 port->omodem &= ~(RTS|DTR);
1176 fepcmd(port, SETMODEM, 0, DTR|RTS, 0, 1);
1182 timeout(dgb_pause, &port->brdchan, hz/2);
1183 tsleep(&port->brdchan, PCATCH, "dgclo", 0);
1190 wakeup((caddr_t)chan);
1197 int unit=(int)unit_c;
1200 struct dgb_softc *sc=&dgb_softc[unit];
1203 int event, mstat, lstat;
1204 volatile struct board_chan *bc;
1211 int ibuf_full,obuf_full;
1213 BoardMemWinState ws=bmws_get();
1215 if(sc->status==DISABLED) {
1216 printf("dgb%d: polling of disabled board stopped\n",unit);
1222 head=sc->mailbox->ein;
1223 tail=sc->mailbox->eout;
1226 if(head >= FEP_IMAX-FEP_ISTART
1227 || tail >= FEP_IMAX-FEP_ISTART
1228 || (head|tail) & 03 ) {
1229 printf("dgb%d: event queue's head or tail is wrong! hd=%d,tl=%d\n", unit,head,tail);
1233 eventbuf=sc->vmem+tail+FEP_ISTART;
1239 port=&sc->ports[pnum];
1243 if(pnum>=sc->numports || port->status==DISABLED) {
1244 printf("dgb%d: port%d: got event on nonexisting port\n",unit,pnum);
1245 } else if(port->used || port->wopeners>0 ) {
1247 int wrapmask=port->rxbufsize-1;
1249 if( !(event & ALL_IND) )
1250 printf("dgb%d: port%d: ? event 0x%x mstat 0x%x lstat 0x%x\n",
1251 unit, pnum, event, mstat, lstat);
1253 if(event & DATA_IND) {
1254 DPRINT3(DB_DATA,"dgb%d: port%d: DATA_IND\n",unit,pnum);
1256 rhead=bc->rin & wrapmask;
1257 rtail=bc->rout & wrapmask;
1259 if( !(tp->t_cflag & CREAD) || !port->used ) {
1265 printf("dgb%d: port%d: overrun\n", unit, pnum);
1269 if(!(tp->t_state & TS_ISOPEN))
1272 for(ibuf_full=FALSE;rhead!=rtail && !ibuf_full;) {
1273 DPRINT5(DB_RXDATA,"dgb%d: port%d: p rx head=%d tail=%d\n",
1274 unit,pnum,rhead,rtail);
1279 size=port->rxbufsize-rtail;
1281 ptr=port->rxptr+rtail;
1284 if( tp->t_rawq.c_cc + size > DGB_IBUFSIZE ) {
1285 size=DGB_IBUFSIZE-tp->t_rawq.c_cc;
1286 DPRINT1(DB_RXDATA,"*");
1291 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1292 DPRINT1(DB_RXDATA,"!");
1293 towin(sc,port->rxwin);
1296 tp->t_rawcc += size;
1297 b_to_q(ptr,size,&tp->t_rawq);
1303 towin(sc,port->rxwin);
1306 (*linesw[tp->t_line].l_rint)(chr, tp);
1311 rtail= (rtail + size) & wrapmask;
1313 rhead=bc->rin & wrapmask;
1321 if(event & MODEMCHG_IND) {
1322 DPRINT3(DB_MODEM,"dgb%d: port%d: MODEMCHG_IND\n",unit,pnum);
1324 if(mstat & port->dcd) {
1326 linesw[tp->t_line].l_modem(tp,1);
1328 wakeup(TSA_CARR_ON(tp));
1331 linesw[tp->t_line].l_modem(tp,0);
1333 if( port->draining) {
1335 wakeup(&port->draining);
1340 if(event & BREAK_IND) {
1341 if((tp->t_state & TS_ISOPEN) && (tp->t_iflag & IGNBRK)) {
1342 DPRINT3(DB_BREAK,"dgb%d: port%d: BREAK_IND\n",unit,pnum);
1344 linesw[tp->t_line].l_rint(TTY_BI, tp);
1349 /* Helg: with output flow control */
1351 if(event & (LOWTX_IND | EMPTYTX_IND) ) {
1352 DPRINT3(DB_TXDATA,"dgb%d: port%d: LOWTX_IND or EMPTYTX_IND\n",unit,pnum);
1354 if( (event & EMPTYTX_IND ) && tp->t_outq.c_cc==0
1355 && port->draining) {
1357 wakeup(&port->draining);
1358 bc->ilow=0; bc->iempty=0;
1361 int wrapmask=port->txbufsize-1;
1363 for(obuf_full=FALSE; tp->t_outq.c_cc!=0 && !obuf_full; ) {
1365 /* add "last-minute" data to write buffer */
1366 if(!(tp->t_state & TS_BUSY)) {
1368 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1371 if(tp->t_outq.c_cc <= tp->t_lowat) {
1372 if(tp->t_state & TS_ASLEEP) {
1373 tp->t_state &= ~TS_ASLEEP;
1374 wakeup(TSA_OLOWAT(tp));
1376 /* selwakeup(&tp->t_wsel); */
1383 whead=bc->tin & wrapmask;
1384 wtail=bc->tout & wrapmask;
1389 size=port->txbufsize-whead;
1395 DPRINT5(DB_WR,"dgb: head=%d tail=%d size=%d full=%d\n",
1396 whead,wtail,size,obuf_full);
1397 bc->iempty=1; bc->ilow=1;
1403 towin(sc,port->txwin);
1405 ocount=q_to_b(&tp->t_outq, port->txptr+whead, size);
1410 bc->tin=whead & wrapmask;
1415 DPRINT1(DB_WR," +BUSY\n");
1416 tp->t_state|=TS_BUSY;
1418 DPRINT1(DB_WR," -BUSY\n");
1420 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1421 /* should clear TS_BUSY before ttwwakeup */
1422 if(tp->t_state & TS_BUSY) {
1423 tp->t_state &= ~TS_BUSY;
1424 linesw[tp->t_line].l_start(tp);
1428 if(tp->t_state & TS_ASLEEP) {
1429 tp->t_state &= ~TS_ASLEEP;
1430 wakeup(TSA_OLOWAT(tp));
1432 tp->t_state &= ~TS_BUSY;
1438 bc->idata=1; /* require event on incoming data */
1442 DPRINT4(DB_EXCEPT,"dgb%d: port%d: got event 0x%x on closed port\n",
1445 bc->idata=bc->iempty=bc->ilow=0;
1448 tail= (tail+4) & (FEP_IMAX-FEP_ISTART-4);
1451 sc->mailbox->eout=tail;
1454 timeout(dgbpoll, unit_c, hz/POLLSPERSEC);
1458 dgbioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
1460 struct dgb_softc *sc;
1465 volatile struct board_chan *bc;
1470 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1472 struct termios term;
1475 BoardMemWinState ws=bmws_get();
1478 unit=MINOR_TO_UNIT(mynor);
1479 pnum=MINOR_TO_PORT(mynor);
1481 sc=&dgb_softc[unit];
1482 port=&sc->ports[pnum];
1486 if (mynor & CONTROL_MASK) {
1489 switch (mynor & CONTROL_MASK) {
1490 case CONTROL_INIT_STATE:
1491 ct = mynor & CALLOUT_MASK ? &port->it_out : &port->it_in;
1493 case CONTROL_LOCK_STATE:
1494 ct = mynor & CALLOUT_MASK ? &port->lt_out : &port->lt_in;
1497 return (ENODEV); /* /dev/nodev */
1504 *ct = *(struct termios *)data;
1507 *(struct termios *)data = *ct;
1510 *(int *)data = TTYDISC;
1513 bzero(data, sizeof(struct winsize));
1520 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1521 term = tp->t_termios;
1522 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1523 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);
1526 error = ttsetcompat(tp, &cmd, data, &term);
1530 data = (caddr_t)&term;
1533 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1535 struct termios *dt = (struct termios *)data;
1536 struct termios *lt = mynor & CALLOUT_MASK
1537 ? &port->lt_out : &port->lt_in;
1539 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);
1540 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1541 | (dt->c_iflag & ~lt->c_iflag);
1542 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1543 | (dt->c_oflag & ~lt->c_oflag);
1544 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1545 | (dt->c_cflag & ~lt->c_cflag);
1546 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1547 | (dt->c_lflag & ~lt->c_lflag);
1548 for (cc = 0; cc < NCCS; ++cc)
1549 if (lt->c_cc[cc] != 0)
1550 dt->c_cc[cc] = tp->t_cc[cc];
1551 if (lt->c_ispeed != 0)
1552 dt->c_ispeed = tp->t_ispeed;
1553 if (lt->c_ospeed != 0)
1554 dt->c_ospeed = tp->t_ospeed;
1560 fepcmd(port, PAUSETX, 0, 0, 0, 0);
1564 } else if(cmd==TIOCSTART) {
1567 fepcmd(port, RESUMETX, 0, 0, 0, 0);
1573 if(cmd==TIOCSETAW || cmd==TIOCSETAF)
1576 error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, p);
1577 if (error != ENOIOCTL)
1580 error = ttioctl(tp, cmd, data, flag);
1581 disc_optim(tp,&tp->t_termios);
1583 if (error != ENOIOCTL) {
1585 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1586 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);
1593 /* Helg: commented */
1594 /* error=dgbdrain(port);*/
1604 /* now it sends 250 millisecond break because I don't know */
1605 /* how to send an infinite break */
1607 fepcmd(port, SENDBREAK, 250, 0, 10, 0);
1612 /* now it's empty */
1615 DPRINT3(DB_MODEM,"dgb%d: port%d: set DTR\n",unit,pnum);
1616 port->omodem |= DTR;
1619 fepcmd(port, SETMODEM, port->omodem, RTS, 0, 1);
1621 if( !(bc->mstat & DTR) ) {
1622 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is off\n",unit,pnum);
1629 DPRINT3(DB_MODEM,"dgb%d: port%d: reset DTR\n",unit,pnum);
1630 port->omodem &= ~DTR;
1633 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1635 if( bc->mstat & DTR ) {
1636 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is on\n",unit,pnum);
1643 if(*(int *)data & TIOCM_DTR)
1646 port->omodem &=~DTR;
1648 if(*(int *)data & TIOCM_RTS)
1651 port->omodem &=~RTS;
1655 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1660 if(*(int *)data & TIOCM_DTR)
1663 if(*(int *)data & TIOCM_RTS)
1668 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1673 if(*(int *)data & TIOCM_DTR)
1674 port->omodem &=~DTR;
1676 if(*(int *)data & TIOCM_RTS)
1677 port->omodem &=~RTS;
1681 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1687 port->imodem=bc->mstat;
1690 tiocm_xxx = TIOCM_LE; /* XXX - always enabled while open */
1692 DPRINT3(DB_MODEM,"dgb%d: port%d: modem stat -- ",unit,pnum);
1694 if (port->imodem & DTR) {
1695 DPRINT1(DB_MODEM,"DTR ");
1696 tiocm_xxx |= TIOCM_DTR;
1698 if (port->imodem & RTS) {
1699 DPRINT1(DB_MODEM,"RTS ");
1700 tiocm_xxx |= TIOCM_RTS;
1702 if (port->imodem & CTS) {
1703 DPRINT1(DB_MODEM,"CTS ");
1704 tiocm_xxx |= TIOCM_CTS;
1706 if (port->imodem & port->dcd) {
1707 DPRINT1(DB_MODEM,"DCD ");
1708 tiocm_xxx |= TIOCM_CD;
1710 if (port->imodem & port->dsr) {
1711 DPRINT1(DB_MODEM,"DSR ");
1712 tiocm_xxx |= TIOCM_DSR;
1714 if (port->imodem & RI) {
1715 DPRINT1(DB_MODEM,"RI ");
1716 tiocm_xxx |= TIOCM_RI;
1718 *(int *)data = tiocm_xxx;
1719 DPRINT1(DB_MODEM,"--\n");
1722 /* must be root since the wait applies to following logins */
1728 port->close_delay = *(int *)data * hz / 100;
1731 *(int *)data = port->close_delay * 100 / hz;
1734 port->do_timestamp = TRUE;
1735 *(struct timeval *)data = port->timestamp;
1737 case TIOCDCDTIMESTAMP:
1738 port->do_dcd_timestamp = TRUE;
1739 *(struct timeval *)data = port->dcd_timestamp;
1756 struct dgb_p *port=p;
1758 wakeup(&port->draining);
1761 /* wait for the output to drain */
1767 struct dgb_softc *sc=&dgb_softc[port->unit];
1768 volatile struct board_chan *bc=port->brdchan;
1772 BoardMemWinState ws=bmws_get();
1781 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1782 port->unit, port->pnum, head, tail);
1786 timeout(wakeflush,port, hz);
1787 error=tsleep(&port->draining, PCATCH, "dgdrn", 0);
1792 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgdrn) error=%d\n",
1793 port->unit,port->pnum,error);
1803 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1804 port->unit, port->pnum, head, tail);
1809 /* wait for the output to drain */
1810 /* or simply clear the buffer it it's stopped */
1813 dgb_drain_or_flush(port)
1816 struct tty *tp=port->tty;
1817 struct dgb_softc *sc=&dgb_softc[port->unit];
1818 volatile struct board_chan *bc=port->brdchan;
1830 while(tail!=head /* && tail!=lasttail */ ) {
1831 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1832 port->unit, port->pnum, head, tail);
1834 /* if there is no carrier simply clean the buffer */
1835 if( !(tp->t_state & TS_CARR_ON) ) {
1844 timeout(wakeflush,port, hz);
1845 error=tsleep(&port->draining, PCATCH, "dgfls", 0);
1850 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgfls) error=%d\n",
1851 port->unit,port->pnum,error);
1853 /* silently clean the buffer */
1866 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1867 port->unit, port->pnum, head, tail);
1875 int unit=MINOR_TO_UNIT(minor(tp->t_dev));
1876 int pnum=MINOR_TO_PORT(minor(tp->t_dev));
1877 struct dgb_softc *sc=&dgb_softc[unit];
1878 struct dgb_p *port=&sc->ports[pnum];
1879 volatile struct board_chan *bc=port->brdchan;
1887 BoardMemWinState ws=bmws_get();
1889 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);
1891 if(port->mustdrain) {
1892 DPRINT3(DB_PARAM,"dgb%d: port%d: must call dgbdrain()\n",unit,pnum);
1896 cflag=ttspeedtab(t->c_ospeed, dgbspeedtab);
1898 if (t->c_ispeed == 0)
1899 t->c_ispeed = t->c_ospeed;
1901 if (cflag < 0 /* || cflag > 0 && t->c_ispeed != t->c_ospeed */) {
1902 DPRINT4(DB_PARAM,"dgb%d: port%d: invalid cflag=0%o\n",unit,pnum,cflag);
1909 if(cflag==0) { /* hangup */
1910 DPRINT3(DB_PARAM,"dgb%d: port%d: hangup\n",unit,pnum);
1914 fepcmd(port, STOUT, (unsigned)head, 0, 0, 0);
1915 mval= port->omodem & ~(DTR|RTS);
1917 cflag |= dgbflags(dgb_cflags, t->c_cflag);
1919 if(cflag!=port->fepcflag) {
1920 port->fepcflag=cflag;
1921 DPRINT5(DB_PARAM,"dgb%d: port%d: set cflag=0x%x c=0x%x\n",
1922 unit,pnum,cflag,t->c_cflag&~CRTSCTS);
1923 fepcmd(port, SETCTRLFLAGS, (unsigned)cflag, 0, 0, 0);
1925 mval= port->omodem | (DTR|RTS);
1928 iflag=dgbflags(dgb_iflags, t->c_iflag);
1929 if(iflag!=port->fepiflag) {
1930 port->fepiflag=iflag;
1931 DPRINT5(DB_PARAM,"dgb%d: port%d: set iflag=0x%x c=0x%x\n",unit,pnum,iflag,t->c_iflag);
1932 fepcmd(port, SETIFLAGS, (unsigned)iflag, 0, 0, 0);
1937 hflow=dgbflags(dgb_flow, t->c_cflag);
1938 if(hflow!=port->hflow) {
1940 DPRINT5(DB_PARAM,"dgb%d: port%d: set hflow=0x%x f=0x%x\n",unit,pnum,hflow,t->c_cflag&CRTSCTS);
1941 fepcmd(port, SETHFLOW, (unsigned)hflow, 0xff, 0, 1);
1944 if(port->omodem != mval) {
1945 DPRINT5(DB_PARAM,"dgb%d: port%d: setting modem parameters 0x%x was 0x%x\n",
1946 unit,pnum,mval,port->omodem);
1948 fepcmd(port, SETMODEM, (unsigned)mval, RTS|DTR, 0, 1);
1951 if(port->fepstartc!=t->c_cc[VSTART] || port->fepstopc!=t->c_cc[VSTOP]) {
1952 DPRINT5(DB_PARAM,"dgb%d: port%d: set startc=%d, stopc=%d\n",unit,pnum,t->c_cc[VSTART],t->c_cc[VSTOP]);
1953 port->fepstartc=t->c_cc[VSTART];
1954 port->fepstopc=t->c_cc[VSTOP];
1955 fepcmd(port, SONOFFC, port->fepstartc, port->fepstopc, 0, 1);
1972 struct dgb_softc *sc;
1973 volatile struct board_chan *bc;
1979 BoardMemWinState ws=bmws_get();
1981 unit=MINOR_TO_UNIT(minor(tp->t_dev));
1982 pnum=MINOR_TO_PORT(minor(tp->t_dev));
1983 sc=&dgb_softc[unit];
1984 port=&sc->ports[pnum];
1987 wmask=port->txbufsize-1;
1991 while( tp->t_outq.c_cc!=0 ) {
1993 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1996 if(tp->t_outq.c_cc <= tp->t_lowat) {
1997 if(tp->t_state & TS_ASLEEP) {
1998 tp->t_state &= ~TS_ASLEEP;
1999 wakeup(TSA_OLOWAT(tp));
2001 /*selwakeup(&tp->t_wsel);*/
2007 head=bc->tin & wmask;
2009 do { tail=bc->tout; } while (tail != bc->tout);
2010 tail=bc->tout & wmask;
2012 DPRINT5(DB_WR,"dgb%d: port%d: s tx head=%d tail=%d\n",unit,pnum,head,tail);
2014 #ifdef LEAVE_FREE_CHARS
2016 size=tail-head-LEAVE_FREE_CHARS;
2020 size=port->txbufsize-head;
2021 if(tail+port->txbufsize < head)
2029 size=port->txbufsize-head/*-1*/;
2036 bc->iempty=1; bc->ilow=1;
2039 tp->t_state|=TS_BUSY;
2044 towin(sc,port->txwin);
2046 ocount=q_to_b(&tp->t_outq, port->txptr+head, size);
2048 if(head>=port->txbufsize)
2049 head-=port->txbufsize;
2054 DPRINT5(DB_WR,"dgb%d: port%d: tx avail=%d count=%d\n",unit,pnum,size,ocount);
2062 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2063 if(tp->t_state & TS_BUSY) {
2064 tp->t_state&=~TS_BUSY;
2065 linesw[tp->t_line].l_start(tp);
2069 if(tp->t_state & TS_ASLEEP) {
2070 tp->t_state &= ~TS_ASLEEP;
2071 wakeup(TSA_OLOWAT(tp));
2073 tp->t_state&=~TS_BUSY;
2085 struct dgb_softc *sc;
2086 volatile struct board_chan *bc;
2089 BoardMemWinState ws=bmws_get();
2091 unit=MINOR_TO_UNIT(minor(tp->t_dev));
2092 pnum=MINOR_TO_PORT(minor(tp->t_dev));
2094 sc=&dgb_softc[unit];
2095 port=&sc->ports[pnum];
2098 DPRINT3(DB_WR,"dgb%d: port%d: stop\n",port->unit, port->pnum);
2104 /* clear output queue */
2106 bc->ilow=0;bc->iempty=0;
2109 /* clear input queue */
2120 fepcmd(port, cmd, op1, op2, ncmds, bytecmd)
2122 unsigned cmd, op1, op2, ncmds, bytecmd;
2124 struct dgb_softc *sc=&dgb_softc[port->unit];
2125 u_char *mem=sc->vmem;
2126 unsigned tail, head;
2129 if(port->status==DISABLED) {
2130 printf("dgb%d: port%d: FEP command on disabled port\n",
2131 port->unit, port->pnum);
2135 /* setwin(sc,0); Require this to be set by caller */
2136 head=sc->mailbox->cin;
2138 if(head>=(FEP_CMAX-FEP_CSTART) || (head & 3)) {
2139 printf("dgb%d: port%d: wrong pointer head of command queue : 0x%x\n",
2140 port->unit, port->pnum, head);
2144 mem[head+FEP_CSTART+0]=cmd;
2145 mem[head+FEP_CSTART+1]=port->pnum;
2147 mem[head+FEP_CSTART+2]=op1;
2148 mem[head+FEP_CSTART+3]=op2;
2150 mem[head+FEP_CSTART+2]=op1&0xff;
2151 mem[head+FEP_CSTART+3]=(op1>>8)&0xff;
2154 DPRINT7(DB_FEP,"dgb%d: port%d: %s cmd=0x%x op1=0x%x op2=0x%x\n", port->unit, port->pnum,
2155 (bytecmd)?"byte":"word", cmd, mem[head+FEP_CSTART+2], mem[head+FEP_CSTART+3]);
2157 head=(head+4) & (FEP_CMAX-FEP_CSTART-4);
2158 sc->mailbox->cin=head;
2162 while (count-- != 0) {
2163 head=sc->mailbox->cin;
2164 tail=sc->mailbox->cout;
2166 n = (head-tail) & (FEP_CMAX-FEP_CSTART-4);
2167 if(n <= ncmds * (sizeof(ushort)*4))
2170 printf("dgb%d(%d): timeout on FEP cmd=0x%x\n", port->unit, port->pnum, cmd);
2178 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2179 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2180 && (!(t->c_iflag & PARMRK)
2181 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2182 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2183 && linesw[tp->t_line].l_rint == ttyinput)
2184 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2186 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;