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/i386/gnu/isa/Attic/dgb.c,v 1.12 2004/06/02 13:49:46 joerg 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 <bus/isa/i386/isa_device.h>
67 #define DGB_DEBUG /* Enable debugging info via sysctl */
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 */
120 volatile u_char *txptr;
121 volatile u_char *rxptr;
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 (void *unit_c);
178 /* Device switch entry points. */
179 #define dgbreset noreset
180 #define dgbmmap nommap
181 #define dgbstrategy nostrategy
183 static int dgbattach (struct isa_device *dev);
184 static int dgbprobe (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 (struct tty *tp);
190 static void dgbstop (struct tty *tp, int rw);
191 static int dgbparam (struct tty *tp, struct termios *t);
192 static void dgbhardclose (struct dgb_p *port);
193 static void dgb_drain_or_flush (struct dgb_p *port);
194 static int dgbdrain (struct dgb_p *port);
195 static void dgb_pause (void *chan);
196 static void wakeflush (void *p);
197 static void disc_optim (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 /* maj */ CDEV_MAJOR,
212 /* flags */ D_TTY | D_KQFILTER,
217 /* close */ dgbclose,
219 /* write */ ttywrite,
220 /* ioctl */ dgbioctl,
223 /* strategy */ nostrategy,
226 /* kqfilter */ ttykqfilter
229 static speed_t dgbdefaultrate = TTYDEF_SPEED;
231 static struct speedtab dgbspeedtab[] = {
232 { 0, FEP_B0 }, /* old (sysV-like) Bx codes */
246 { 19200, FEP_B19200 },
247 { 38400, FEP_B38400 },
248 { 57600, (FEP_FASTBAUD|FEP_B50) }, /* B50 & fast baud table */
249 { 115200, (FEP_FASTBAUD|FEP_B110) }, /* B100 & fast baud table */
253 static struct dbgflagtbl
260 { PARODD, PARODD, FEP_PARODD },
261 { PARENB, PARENB, FEP_PARENB },
262 { CSTOPB, CSTOPB, FEP_CSTOPB },
263 { CSIZE, CS5, FEP_CS6 },
264 { CSIZE, CS6, FEP_CS6 },
265 { CSIZE, CS7, FEP_CS7 },
266 { CSIZE, CS8, FEP_CS8 },
267 { CLOCAL, CLOCAL, FEP_CLOCAL },
271 { IGNBRK, IGNBRK, FEP_IGNBRK },
272 { BRKINT, BRKINT, FEP_BRKINT },
273 { IGNPAR, IGNPAR, FEP_IGNPAR },
274 { PARMRK, PARMRK, FEP_PARMRK },
275 { INPCK, INPCK, FEP_INPCK },
276 { ISTRIP, ISTRIP, FEP_ISTRIP },
277 { IXON, IXON, FEP_IXON },
278 { IXOFF, IXOFF, FEP_IXOFF },
279 { IXANY, IXANY, FEP_IXANY },
283 { CRTSCTS, CRTSCTS, CTS|RTS },
284 { CRTSCTS, CCTS_OFLOW, CTS },
285 { CRTSCTS, CRTS_IFLOW, RTS },
289 /* xlat bsd termios flags to dgb sys-v style */
291 dgbflags(struct dbgflagtbl *tbl, tcflag_t input)
296 for (i=0; tbl[i].in_mask != (tcflag_t)-1; i++)
298 if ((input & tbl[i].in_mask) == tbl[i].in_val)
299 output |= tbl[i].out_val;
305 static int dgbdebug=0;
306 SYSCTL_INT(_debug, OID_AUTO, dgb_debug, CTLFLAG_RW, &dgbdebug, 0, "");
309 static __inline int setwin (struct dgb_softc *sc, unsigned addr);
310 static __inline int setinitwin (struct dgb_softc *sc, unsigned addr);
311 static __inline void hidewin (struct dgb_softc *sc);
312 static __inline void towin (struct dgb_softc *sc, int win);
314 /*Helg: to allow recursive dgb...() calls */
316 { /* If we were called and don't want to disturb we need: */
317 int port; /* write to this port */
318 u_char data; /* this data on exit */
319 /* or DATA_WINOFF to close memory window on entry */
320 } BoardMemWinState; /* so several channels and even boards can coexist */
321 #define DATA_WINOFF 0
322 static BoardMemWinState bmws;
324 /* return current memory window state and close window */
325 static BoardMemWinState
328 BoardMemWinState bmwsRet=bmws;
329 if(bmws.data!=DATA_WINOFF)
330 outb(bmws.port, bmws.data=DATA_WINOFF);
334 /* restore memory window state */
336 bmws_set(BoardMemWinState ws)
338 if(ws.data != bmws.data || ws.port!=bmws.port ) {
339 if(bmws.data!=DATA_WINOFF)
340 outb(bmws.port,DATA_WINOFF);
341 if(ws.data!=DATA_WINOFF)
342 outb(ws.port, ws.data);
349 struct dgb_softc *sc;
352 if(sc->type==PCXEVE) {
353 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
354 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
355 return (addr & 0x1FFF);
357 outb(bmws.port=sc->port,bmws.data=FEPMEM);
364 struct dgb_softc *sc;
367 if(sc->type==PCXEVE) {
368 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
369 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
370 return (addr & 0x1FFF);
372 outb(bmws.port=sc->port,bmws.data=inb(sc->port)|FEPMEM);
379 struct dgb_softc *sc;
383 outb(bmws.port=sc->port+1, bmws.data);
385 outb(bmws.port=sc->port, bmws.data);
390 struct dgb_softc *sc;
393 if(sc->type==PCXEVE) {
394 outb(bmws.port=sc->port+1, bmws.data=win);
396 outb(bmws.port=sc->port,bmws.data=FEPMEM);
402 struct isa_device *dev;
404 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
406 u_long win_size; /* size of vizible memory window */
407 int unit=dev->id_unit;
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;
523 const volatile ushort *pstat;
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=(const 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 cdevsw_add(&dgb_cdevsw, 0xffff0000, unit << 16);
898 make_dev(&dgb_cdevsw, (unit<<16)+i,
899 UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix);
901 make_dev(&dgb_cdevsw, (unit<<16)+i+32,
902 UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix);
904 make_dev(&dgb_cdevsw, (unit<<16)+i+64,
905 UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix);
907 make_dev(&dgb_cdevsw, (unit<<16)+i+128,
908 UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix);
910 make_dev(&dgb_cdevsw, (unit<<16)+i+160,
911 UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix);
913 make_dev(&dgb_cdevsw, (unit<<16)+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=__DEVOLATILE(u_char *, 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, __DEVOLATILE(u_char *, 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, td);
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, __DEVOLATILE(u_char *, 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;