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.9 2003/08/26 21:42:17 rob 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 */
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;
411 cdevsw_add(&dgb_cdevsw);
412 sc->unit=dev->id_unit;
413 sc->port=dev->id_iobase;
415 if(dev->id_flags & DGBFLAG_ALTPIN)
420 /* left 24 bits only (ISA address) */
421 sc->pmem=((intptr_t)(void *)dev->id_maddr & 0xFFFFFF);
423 DPRINT4(DB_INFO,"dgb%d: port 0x%x mem 0x%lx\n",unit,sc->port,sc->pmem);
425 outb(sc->port, FEPRST);
428 for(i=0; i< 1000; i++) {
430 if( (inb(sc->port) & FEPMASK) == FEPRST ) {
432 DPRINT3(DB_EXCEPT,"dgb%d: got reset after %d us\n",unit,i);
437 if(sc->status!=ENABLED) {
438 DPRINT2(DB_EXCEPT,"dgb%d: failed to respond\n",dev->id_unit);
442 /* check type of card and get internal memory characteristics */
451 printf("dgb%d: PC/Xi 64K\n",dev->id_unit);
456 printf("dgb%d: PC/Xi 128K\n",dev->id_unit);
461 printf("dgb%d: PC/Xi 256K\n",dev->id_unit);
463 default: /* case 0x30: */
466 printf("dgb%d: PC/Xi 512K\n",dev->id_unit);
475 printf("dgb%d: PC/Xm isn't supported\n",dev->id_unit);
482 if(dev->id_flags==DGBFLAG_NOWIN || ( v&0xC0 )==0) {
484 printf("dgb%d: PC/Xe 64K\n",dev->id_unit);
488 printf("dgb%d: PC/Xe 64/8K (windowed)\n",dev->id_unit);
490 if((u_long)sc->pmem & ~0xFFE000) {
491 printf("dgb%d: warning: address 0x%lx truncated to 0x%lx\n",
492 dev->id_unit, sc->pmem,
493 sc->pmem & 0xFFE000);
495 dev->id_maddr= (u_char *)(void *)(intptr_t)( sc->pmem & 0xFFE000 );
500 /* save size of vizible memory segment */
501 dev->id_msize=win_size;
504 dev->id_maddr=sc->vmem=pmap_mapdev(sc->pmem,dev->id_msize);
506 outb(sc->port, FEPCLR); /* drop RESET */
507 hidewin(sc); /* Helg: to set initial bmws state */
509 return 4; /* we need I/O space of 4 ports */
514 struct isa_device *dev;
516 int unit=dev->id_unit;
517 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
519 u_char volatile *mem;
520 u_char volatile *ptr;
523 volatile struct board_chan *bc;
526 const volatile ushort *pstat;
531 if(sc->status!=ENABLED) {
532 DPRINT2(DB_EXCEPT,"dbg%d: try to attach a disabled card\n",unit);
538 DPRINT3(DB_INFO,"dgb%d: internal memory segment 0x%x\n",unit,sc->mem_seg);
540 outb(sc->port, FEPRST); DELAY(1);
542 for(i=0; (inb(sc->port) & FEPMASK) != FEPRST ; i++) {
544 printf("dgb%d: 1st reset failed\n",dev->id_unit);
552 DPRINT3(DB_INFO,"dgb%d: got reset after %d us\n",unit,i);
554 /* for PCXEVE set up interrupt and base address */
556 if(sc->type==PCXEVE) {
557 t=(((u_long)sc->pmem>>8) & 0xFFE0) | 0x10 /* enable windowing */;
559 outb(sc->port+2,t & 0xFF);
560 outb(sc->port+3,t>>8);
561 } else if(sc->type==PCXE) {
562 t=(((u_long)sc->pmem>>8) & 0xFFE0) /* disable windowing */;
563 outb(sc->port+2,t & 0xFF);
564 outb(sc->port+3,t>>8);
568 if(sc->type==PCXI || sc->type==PCXE) {
569 outb(sc->port, FEPRST|FEPMEM); DELAY(1);
571 for(i=0; (inb(sc->port) & FEPMASK) != (FEPRST|FEPMEM) ; i++) {
573 printf("dgb%d: 2nd reset failed\n",dev->id_unit);
581 DPRINT3(DB_INFO,"dgb%d: got memory after %d us\n",unit,i);
586 /* very short memory test */
588 addr=setinitwin(sc,BOTWIN);
589 *(u_long volatile *)(mem+addr) = 0xA55A3CC3;
590 if(*(u_long volatile *)(mem+addr)!=0xA55A3CC3) {
591 printf("dgb%d: 1st memory test failed\n",dev->id_unit);
597 addr=setinitwin(sc,TOPWIN);
598 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
599 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
600 printf("dgb%d: 2nd memory test failed\n",dev->id_unit);
606 addr=setinitwin(sc,BIOSCODE+((0xF000-sc->mem_seg)<<4));
607 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
608 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
609 printf("dgb%d: 3rd (BIOS) memory test failed\n",dev->id_unit);
612 addr=setinitwin(sc,MISCGLOBAL);
613 for(i=0; i<16; i++) {
617 if(sc->type==PCXI || sc->type==PCXE) {
619 addr=BIOSCODE+((0xF000-sc->mem_seg)<<4);
621 DPRINT3(DB_INFO,"dgb%d: BIOS local address=0x%x\n",unit,addr);
625 for(i=0; i<pcxx_nbios; i++, ptr++)
631 for(i=0; i<pcxx_nbios; i++, ptr++)
632 if( *ptr != pcxx_bios[i] ) {
633 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
634 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
637 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
642 outb(sc->port,FEPMEM);
644 for(i=0; (inb(sc->port) & FEPMASK) != FEPMEM ; i++) {
646 printf("dgb%d: BIOS start failed\n",dev->id_unit);
654 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
656 for(i=0; i<200000; i++) {
657 if( *((ushort volatile *)(mem+MISCGLOBAL)) == *((ushort *)"GD") )
661 printf("dgb%d: BIOS download failed\n",dev->id_unit);
662 DPRINT4(DB_EXCEPT,"dgb%d: code=0x%x must be 0x%x\n",
664 *((ushort volatile *)(mem+MISCGLOBAL)),
672 if(sc->type==PCXEVE) {
674 outb(sc->port+1,0xFF);
676 ptr= mem+(BIOSCODE & 0x1FFF);
678 for(i=0; i<pcxx_nbios; i++)
679 *ptr++ = pcxx_bios[i];
681 ptr= mem+(BIOSCODE & 0x1FFF);
684 for(i=0; i<pcxx_nbios; i++, ptr++)
685 if( *ptr != pcxx_bios[i] ) {
686 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
687 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
690 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
695 outb(sc->port,FEPCLR);
699 for(i=0; (inb(sc->port) & FEPMASK) != FEPCLR ; i++) {
701 printf("dgb%d: BIOS start failed\n",dev->id_unit);
709 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
711 addr=setwin(sc,MISCGLOBAL);
713 for(i=0; i<200000; i++) {
714 if(*(ushort volatile *)(mem+addr)== *(ushort *)"GD")
718 printf("dgb%d: BIOS download failed\n",dev->id_unit);
719 DPRINT5(DB_EXCEPT,"dgb%d: Error#(0x%x,0x%x) code=0x%x\n",
721 *(ushort volatile *)(mem+0xC12),
722 *(ushort volatile *)(mem+0xC14),
723 *(ushort volatile *)(mem+MISCGLOBAL));
731 DPRINT2(DB_INFO,"dgb%d: BIOS loaded\n",dev->id_unit);
733 addr=setwin(sc,FEPCODE);
737 for(i=0; i<pcxx_ncook; i++)
738 *ptr++ = pcxx_cook[i];
740 addr=setwin(sc,MBOX);
741 *(ushort volatile *)(mem+addr+ 0)=2;
742 *(ushort volatile *)(mem+addr+ 2)=sc->mem_seg+FEPCODESEG;
743 *(ushort volatile *)(mem+addr+ 4)=0;
744 *(ushort volatile *)(mem+addr+ 6)=FEPCODESEG;
745 *(ushort volatile *)(mem+addr+ 8)=0;
746 *(ushort volatile *)(mem+addr+10)=pcxx_ncook;
748 outb(sc->port,FEPMEM|FEPINT); /* send interrupt to BIOS */
749 outb(sc->port,FEPMEM);
751 for(i=0; *(ushort volatile *)(mem+addr)!=0; i++) {
753 printf("dgb%d: FEP code download failed\n",unit);
754 DPRINT3(DB_EXCEPT,"dgb%d: code=0x%x must be 0\n", unit,
755 *(ushort volatile *)(mem+addr));
762 DPRINT2(DB_INFO,"dgb%d: FEP code loaded\n",unit);
764 *(ushort volatile *)(mem+setwin(sc,FEPSTAT))=0;
765 addr=setwin(sc,MBOX);
766 *(ushort volatile *)(mem+addr+0)=1;
767 *(ushort volatile *)(mem+addr+2)=FEPCODESEG;
768 *(ushort volatile *)(mem+addr+4)=0x4;
770 outb(sc->port,FEPINT); /* send interrupt to BIOS */
771 outb(sc->port,FEPCLR);
773 addr=setwin(sc,FEPSTAT);
774 for(i=0; *(ushort volatile *)(mem+addr)!= *(ushort *)"OS"; i++) {
776 printf("dgb%d: FEP/OS start failed\n",dev->id_unit);
783 DPRINT2(DB_INFO,"dgb%d: FEP/OS started\n",dev->id_unit);
785 sc->numports= *(ushort volatile *)(mem+setwin(sc,NPORT));
787 printf("dgb%d: %d ports\n",unit,sc->numports);
789 if(sc->numports > MAX_DGB_PORTS) {
790 printf("dgb%d: too many ports\n",unit);
796 if(nports+sc->numports>NDGBPORTS) {
797 printf("dgb%d: only %d ports are usable\n", unit, NDGBPORTS-nports);
798 sc->numports=NDGBPORTS-nports;
801 /* allocate port and tty structures */
802 sc->ports=&dgb_ports[nports];
803 sc->ttys=&dgb_tty[nports];
804 nports+=sc->numports;
806 addr=setwin(sc,PORTBASE);
807 pstat=(const ushort volatile *)(mem+addr);
809 for(i=0; i<sc->numports && pstat[i]; i++)
811 sc->ports[i].status=ENABLED;
813 sc->ports[i].status=DISABLED;
814 printf("dgb%d: port%d is broken\n", unit, i);
817 /* We should now init per-port structures */
818 bc=(volatile struct board_chan *)(mem + CHANSTRUCT);
819 sc->mailbox=(volatile struct global_data *)(mem + FEP_GLOBAL);
826 for(i=0; i<sc->numports; i++, bc++) {
829 port->tty=&sc->ttys[i];
845 DPRINT2(DB_INFO,"dgb%d: shrinking memory\n",unit);
846 fepcmd(port, SETBUFFER, 32, 0, 0, 0);
850 if(sc->type!=PCXEVE) {
851 port->txptr=mem+((bc->tseg-sc->mem_seg)<<4);
852 port->rxptr=mem+((bc->rseg-sc->mem_seg)<<4);
853 port->txwin=port->rxwin=0;
855 port->txptr=mem+( ((bc->tseg-sc->mem_seg)<<4) & 0x1FFF );
856 port->rxptr=mem+( ((bc->rseg-sc->mem_seg)<<4) & 0x1FFF );
857 port->txwin=FEPWIN | ((bc->tseg-sc->mem_seg)>>9);
858 port->rxwin=FEPWIN | ((bc->rseg-sc->mem_seg)>>9);
863 port->txbufsize=bc->tmax+1;
864 port->rxbufsize=bc->rmax+1;
866 lowwater= (port->txbufsize>=2000) ? 1024 : (port->txbufsize/2);
868 fepcmd(port, STXLWATER, lowwater, 0, 10, 0);
869 fepcmd(port, SRXLWATER, port->rxbufsize/4, 0, 10, 0);
870 fepcmd(port, SRXHWATER, 3*port->rxbufsize/4, 0, 10, 0);
875 port->startc=bc->startc;
876 port->startca=bc->startca;
877 port->stopc=bc->stopc;
878 port->stopca=bc->stopca;
880 /*port->close_delay=50;*/
881 port->close_delay=3 * hz;
882 port->do_timestamp=0;
883 port->do_dcd_timestamp=0;
886 * We don't use all the flags from <sys/ttydefaults.h> since they
887 * are only relevant for logins. It's important to have echo off
888 * initially so that the line doesn't start blathering before the
889 * echo flag can be turned off.
891 port->it_in.c_iflag = TTYDEF_IFLAG;
892 port->it_in.c_oflag = TTYDEF_OFLAG;
893 port->it_in.c_cflag = TTYDEF_CFLAG;
894 port->it_in.c_lflag = TTYDEF_LFLAG;
895 termioschars(&port->it_in);
896 port->it_in.c_ispeed = port->it_in.c_ospeed = dgbdefaultrate;
897 port->it_out = port->it_in;
898 /* MAX_DGB_PORTS is 32 => [0-9a-v] */
899 suffix = i < 10 ? '0' + i : 'a' + i - 10;
900 make_dev(&dgb_cdevsw, (unit*32)+i,
901 UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix);
903 make_dev(&dgb_cdevsw, (unit*32)+i+32,
904 UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix);
906 make_dev(&dgb_cdevsw, (unit*32)+i+64,
907 UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix);
909 make_dev(&dgb_cdevsw, (unit*32)+i+128,
910 UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix);
912 make_dev(&dgb_cdevsw, (unit*32)+i+160,
913 UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix);
915 make_dev(&dgb_cdevsw, (unit*32)+i+192,
916 UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix);
921 /* register the polling function */
922 timeout(dgbpoll, (void *)unit, hz/POLLSPERSEC);
929 dgbopen(dev_t dev, int flag, int mode, struct thread *td)
931 struct dgb_softc *sc;
939 volatile struct board_chan *bc;
944 unit=MINOR_TO_UNIT(mynor);
945 pnum=MINOR_TO_PORT(mynor);
948 DPRINT2(DB_EXCEPT,"dgb%d: try to open a nonexisting card\n",unit);
954 if(sc->status!=ENABLED) {
955 DPRINT2(DB_EXCEPT,"dgb%d: try to open a disabled card\n",unit);
959 if(pnum>=sc->numports) {
960 DPRINT3(DB_EXCEPT,"dgb%d: try to open non-existing port %d\n",unit,pnum);
964 if(mynor & CONTROL_MASK)
969 port=&sc->ports[pnum];
976 while(port->closing) {
977 error=tsleep(&port->closing, PCATCH, "dgocl", 0);
980 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgocl) error=%d\n",unit,pnum,error);
985 if (tp->t_state & TS_ISOPEN) {
987 * The device is open, so everything has been initialized.
990 if (mynor & CALLOUT_MASK) {
991 if (!port->active_out) {
993 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
997 if (port->active_out) {
998 if (flag & O_NONBLOCK) {
1000 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
1003 error = tsleep(&port->active_out,
1006 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgbi) error=%d\n",
1014 if (tp->t_state & TS_XCLUDE && suser(td)) {
1020 * The device isn't open, so there are no conflicts.
1021 * Initialize it. Initialization is done twice in many
1022 * cases: to preempt sleeping callin opens if we are
1023 * callout, and to complete a callin open after DCD rises.
1025 tp->t_oproc=dgbstart;
1026 tp->t_param=dgbparam;
1029 tp->t_termios= (mynor & CALLOUT_MASK) ?
1035 port->imodem=bc->mstat;
1036 bc->rout=bc->rin; /* clear input queue */
1038 #ifdef PRINT_BUFSIZE
1039 printf("dgb buffers tx=%x:%x rx=%x:%x\n",bc->tseg,bc->tmax,bc->rseg,bc->rmax);
1046 error=dgbparam(tp, &tp->t_termios);
1050 DPRINT4(DB_OPEN,"dgb%d: port%d: dgbparam error=%d\n",unit,pnum,error);
1054 /* handle fake DCD for callout devices */
1055 /* and initial DCD */
1057 if( (port->imodem & port->dcd) || mynor & CALLOUT_MASK )
1058 linesw[tp->t_line].l_modem(tp,1);
1063 * Wait for DCD if necessary.
1065 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1066 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1068 error = tsleep(TSA_CARR_ON(tp), PCATCH, "dgdcd", 0);
1071 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgdcd) error=%d\n",unit,pnum,error);
1077 error = linesw[tp->t_line].l_open(dev, tp);
1078 disc_optim(tp,&tp->t_termios);
1079 DPRINT4(DB_OPEN,"dgb%d: port%d: l_open error=%d\n",unit,pnum,error);
1081 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1082 port->active_out = TRUE;
1086 /* If any port is open (i.e. the open() call is completed for it)
1087 * the device is busy
1091 disc_optim(tp,&tp->t_termios);
1094 if( !(tp->t_state & TS_ISOPEN) && port->wopeners==0 )
1097 DPRINT4(DB_OPEN,"dgb%d: port%d: open() returns %d\n",unit,pnum,error);
1104 dgbclose(dev_t dev, int flag, int mode, struct thread *td)
1108 struct dgb_softc *sc;
1115 if(mynor & CONTROL_MASK)
1117 unit=MINOR_TO_UNIT(mynor);
1118 pnum=MINOR_TO_PORT(mynor);
1120 sc=&dgb_softc[unit];
1122 port=sc->ports+pnum;
1124 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing\n",unit,pnum);
1126 DPRINT3(DB_CLOSE,"dgb%d: port%d: draining port\n",unit,pnum);
1127 dgb_drain_or_flush(port);
1132 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing line disc\n",unit,pnum);
1133 linesw[tp->t_line].l_close(tp,flag);
1134 disc_optim(tp,&tp->t_termios);
1136 DPRINT3(DB_CLOSE,"dgb%d: port%d: hard closing\n",unit,pnum);
1138 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing tty\n",unit,pnum);
1141 wakeup(&port->closing);
1144 /* mark the card idle when all ports are closed */
1146 for(i=0; i<sc->numports; i++)
1147 if(sc->ports[i].used)
1152 DPRINT3(DB_CLOSE,"dgb%d: port%d: closed\n",unit,pnum);
1154 wakeup(TSA_CARR_ON(tp));
1155 wakeup(&port->active_out);
1158 DPRINT3(DB_CLOSE,"dgb%d: port%d: close exit\n",unit,pnum);
1167 struct dgb_softc *sc=&dgb_softc[port->unit];
1168 volatile struct board_chan *bc=port->brdchan;
1172 port->do_timestamp = 0;
1175 bc->idata=0; bc->iempty=0; bc->ilow=0;
1176 if(port->tty->t_cflag & HUPCL) {
1177 port->omodem &= ~(RTS|DTR);
1178 fepcmd(port, SETMODEM, 0, DTR|RTS, 0, 1);
1184 timeout(dgb_pause, &port->brdchan, hz/2);
1185 tsleep(&port->brdchan, PCATCH, "dgclo", 0);
1192 wakeup((caddr_t)chan);
1199 int unit=(int)unit_c;
1202 struct dgb_softc *sc=&dgb_softc[unit];
1205 int event, mstat, lstat;
1206 volatile struct board_chan *bc;
1213 int ibuf_full,obuf_full;
1215 BoardMemWinState ws=bmws_get();
1217 if(sc->status==DISABLED) {
1218 printf("dgb%d: polling of disabled board stopped\n",unit);
1224 head=sc->mailbox->ein;
1225 tail=sc->mailbox->eout;
1228 if(head >= FEP_IMAX-FEP_ISTART
1229 || tail >= FEP_IMAX-FEP_ISTART
1230 || (head|tail) & 03 ) {
1231 printf("dgb%d: event queue's head or tail is wrong! hd=%d,tl=%d\n", unit,head,tail);
1235 eventbuf=sc->vmem+tail+FEP_ISTART;
1241 port=&sc->ports[pnum];
1245 if(pnum>=sc->numports || port->status==DISABLED) {
1246 printf("dgb%d: port%d: got event on nonexisting port\n",unit,pnum);
1247 } else if(port->used || port->wopeners>0 ) {
1249 int wrapmask=port->rxbufsize-1;
1251 if( !(event & ALL_IND) )
1252 printf("dgb%d: port%d: ? event 0x%x mstat 0x%x lstat 0x%x\n",
1253 unit, pnum, event, mstat, lstat);
1255 if(event & DATA_IND) {
1256 DPRINT3(DB_DATA,"dgb%d: port%d: DATA_IND\n",unit,pnum);
1258 rhead=bc->rin & wrapmask;
1259 rtail=bc->rout & wrapmask;
1261 if( !(tp->t_cflag & CREAD) || !port->used ) {
1267 printf("dgb%d: port%d: overrun\n", unit, pnum);
1271 if(!(tp->t_state & TS_ISOPEN))
1274 for(ibuf_full=FALSE;rhead!=rtail && !ibuf_full;) {
1275 DPRINT5(DB_RXDATA,"dgb%d: port%d: p rx head=%d tail=%d\n",
1276 unit,pnum,rhead,rtail);
1281 size=port->rxbufsize-rtail;
1283 ptr=port->rxptr+rtail;
1286 if( tp->t_rawq.c_cc + size > DGB_IBUFSIZE ) {
1287 size=DGB_IBUFSIZE-tp->t_rawq.c_cc;
1288 DPRINT1(DB_RXDATA,"*");
1293 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1294 DPRINT1(DB_RXDATA,"!");
1295 towin(sc,port->rxwin);
1298 tp->t_rawcc += size;
1299 b_to_q(ptr,size,&tp->t_rawq);
1305 towin(sc,port->rxwin);
1308 (*linesw[tp->t_line].l_rint)(chr, tp);
1313 rtail= (rtail + size) & wrapmask;
1315 rhead=bc->rin & wrapmask;
1323 if(event & MODEMCHG_IND) {
1324 DPRINT3(DB_MODEM,"dgb%d: port%d: MODEMCHG_IND\n",unit,pnum);
1326 if(mstat & port->dcd) {
1328 linesw[tp->t_line].l_modem(tp,1);
1330 wakeup(TSA_CARR_ON(tp));
1333 linesw[tp->t_line].l_modem(tp,0);
1335 if( port->draining) {
1337 wakeup(&port->draining);
1342 if(event & BREAK_IND) {
1343 if((tp->t_state & TS_ISOPEN) && (tp->t_iflag & IGNBRK)) {
1344 DPRINT3(DB_BREAK,"dgb%d: port%d: BREAK_IND\n",unit,pnum);
1346 linesw[tp->t_line].l_rint(TTY_BI, tp);
1351 /* Helg: with output flow control */
1353 if(event & (LOWTX_IND | EMPTYTX_IND) ) {
1354 DPRINT3(DB_TXDATA,"dgb%d: port%d: LOWTX_IND or EMPTYTX_IND\n",unit,pnum);
1356 if( (event & EMPTYTX_IND ) && tp->t_outq.c_cc==0
1357 && port->draining) {
1359 wakeup(&port->draining);
1360 bc->ilow=0; bc->iempty=0;
1363 int wrapmask=port->txbufsize-1;
1365 for(obuf_full=FALSE; tp->t_outq.c_cc!=0 && !obuf_full; ) {
1367 /* add "last-minute" data to write buffer */
1368 if(!(tp->t_state & TS_BUSY)) {
1370 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1373 if(tp->t_outq.c_cc <= tp->t_lowat) {
1374 if(tp->t_state & TS_ASLEEP) {
1375 tp->t_state &= ~TS_ASLEEP;
1376 wakeup(TSA_OLOWAT(tp));
1378 /* selwakeup(&tp->t_wsel); */
1385 whead=bc->tin & wrapmask;
1386 wtail=bc->tout & wrapmask;
1391 size=port->txbufsize-whead;
1397 DPRINT5(DB_WR,"dgb: head=%d tail=%d size=%d full=%d\n",
1398 whead,wtail,size,obuf_full);
1399 bc->iempty=1; bc->ilow=1;
1405 towin(sc,port->txwin);
1407 ocount=q_to_b(&tp->t_outq, port->txptr+whead, size);
1412 bc->tin=whead & wrapmask;
1417 DPRINT1(DB_WR," +BUSY\n");
1418 tp->t_state|=TS_BUSY;
1420 DPRINT1(DB_WR," -BUSY\n");
1422 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1423 /* should clear TS_BUSY before ttwwakeup */
1424 if(tp->t_state & TS_BUSY) {
1425 tp->t_state &= ~TS_BUSY;
1426 linesw[tp->t_line].l_start(tp);
1430 if(tp->t_state & TS_ASLEEP) {
1431 tp->t_state &= ~TS_ASLEEP;
1432 wakeup(TSA_OLOWAT(tp));
1434 tp->t_state &= ~TS_BUSY;
1440 bc->idata=1; /* require event on incoming data */
1444 DPRINT4(DB_EXCEPT,"dgb%d: port%d: got event 0x%x on closed port\n",
1447 bc->idata=bc->iempty=bc->ilow=0;
1450 tail= (tail+4) & (FEP_IMAX-FEP_ISTART-4);
1453 sc->mailbox->eout=tail;
1456 timeout(dgbpoll, unit_c, hz/POLLSPERSEC);
1460 dgbioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
1462 struct dgb_softc *sc;
1467 volatile struct board_chan *bc;
1472 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1474 struct termios term;
1477 BoardMemWinState ws=bmws_get();
1480 unit=MINOR_TO_UNIT(mynor);
1481 pnum=MINOR_TO_PORT(mynor);
1483 sc=&dgb_softc[unit];
1484 port=&sc->ports[pnum];
1488 if (mynor & CONTROL_MASK) {
1491 switch (mynor & CONTROL_MASK) {
1492 case CONTROL_INIT_STATE:
1493 ct = mynor & CALLOUT_MASK ? &port->it_out : &port->it_in;
1495 case CONTROL_LOCK_STATE:
1496 ct = mynor & CALLOUT_MASK ? &port->lt_out : &port->lt_in;
1499 return (ENODEV); /* /dev/nodev */
1506 *ct = *(struct termios *)data;
1509 *(struct termios *)data = *ct;
1512 *(int *)data = TTYDISC;
1515 bzero(data, sizeof(struct winsize));
1522 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1523 term = tp->t_termios;
1524 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1525 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);
1528 error = ttsetcompat(tp, &cmd, data, &term);
1532 data = (caddr_t)&term;
1535 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1537 struct termios *dt = (struct termios *)data;
1538 struct termios *lt = mynor & CALLOUT_MASK
1539 ? &port->lt_out : &port->lt_in;
1541 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);
1542 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1543 | (dt->c_iflag & ~lt->c_iflag);
1544 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1545 | (dt->c_oflag & ~lt->c_oflag);
1546 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1547 | (dt->c_cflag & ~lt->c_cflag);
1548 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1549 | (dt->c_lflag & ~lt->c_lflag);
1550 for (cc = 0; cc < NCCS; ++cc)
1551 if (lt->c_cc[cc] != 0)
1552 dt->c_cc[cc] = tp->t_cc[cc];
1553 if (lt->c_ispeed != 0)
1554 dt->c_ispeed = tp->t_ispeed;
1555 if (lt->c_ospeed != 0)
1556 dt->c_ospeed = tp->t_ospeed;
1562 fepcmd(port, PAUSETX, 0, 0, 0, 0);
1566 } else if(cmd==TIOCSTART) {
1569 fepcmd(port, RESUMETX, 0, 0, 0, 0);
1575 if(cmd==TIOCSETAW || cmd==TIOCSETAF)
1578 error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, td);
1579 if (error != ENOIOCTL)
1582 error = ttioctl(tp, cmd, data, flag);
1583 disc_optim(tp,&tp->t_termios);
1585 if (error != ENOIOCTL) {
1587 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1588 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);
1595 /* Helg: commented */
1596 /* error=dgbdrain(port);*/
1606 /* now it sends 250 millisecond break because I don't know */
1607 /* how to send an infinite break */
1609 fepcmd(port, SENDBREAK, 250, 0, 10, 0);
1614 /* now it's empty */
1617 DPRINT3(DB_MODEM,"dgb%d: port%d: set DTR\n",unit,pnum);
1618 port->omodem |= DTR;
1621 fepcmd(port, SETMODEM, port->omodem, RTS, 0, 1);
1623 if( !(bc->mstat & DTR) ) {
1624 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is off\n",unit,pnum);
1631 DPRINT3(DB_MODEM,"dgb%d: port%d: reset DTR\n",unit,pnum);
1632 port->omodem &= ~DTR;
1635 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1637 if( bc->mstat & DTR ) {
1638 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is on\n",unit,pnum);
1645 if(*(int *)data & TIOCM_DTR)
1648 port->omodem &=~DTR;
1650 if(*(int *)data & TIOCM_RTS)
1653 port->omodem &=~RTS;
1657 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1662 if(*(int *)data & TIOCM_DTR)
1665 if(*(int *)data & TIOCM_RTS)
1670 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1675 if(*(int *)data & TIOCM_DTR)
1676 port->omodem &=~DTR;
1678 if(*(int *)data & TIOCM_RTS)
1679 port->omodem &=~RTS;
1683 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1689 port->imodem=bc->mstat;
1692 tiocm_xxx = TIOCM_LE; /* XXX - always enabled while open */
1694 DPRINT3(DB_MODEM,"dgb%d: port%d: modem stat -- ",unit,pnum);
1696 if (port->imodem & DTR) {
1697 DPRINT1(DB_MODEM,"DTR ");
1698 tiocm_xxx |= TIOCM_DTR;
1700 if (port->imodem & RTS) {
1701 DPRINT1(DB_MODEM,"RTS ");
1702 tiocm_xxx |= TIOCM_RTS;
1704 if (port->imodem & CTS) {
1705 DPRINT1(DB_MODEM,"CTS ");
1706 tiocm_xxx |= TIOCM_CTS;
1708 if (port->imodem & port->dcd) {
1709 DPRINT1(DB_MODEM,"DCD ");
1710 tiocm_xxx |= TIOCM_CD;
1712 if (port->imodem & port->dsr) {
1713 DPRINT1(DB_MODEM,"DSR ");
1714 tiocm_xxx |= TIOCM_DSR;
1716 if (port->imodem & RI) {
1717 DPRINT1(DB_MODEM,"RI ");
1718 tiocm_xxx |= TIOCM_RI;
1720 *(int *)data = tiocm_xxx;
1721 DPRINT1(DB_MODEM,"--\n");
1724 /* must be root since the wait applies to following logins */
1730 port->close_delay = *(int *)data * hz / 100;
1733 *(int *)data = port->close_delay * 100 / hz;
1736 port->do_timestamp = TRUE;
1737 *(struct timeval *)data = port->timestamp;
1739 case TIOCDCDTIMESTAMP:
1740 port->do_dcd_timestamp = TRUE;
1741 *(struct timeval *)data = port->dcd_timestamp;
1758 struct dgb_p *port=p;
1760 wakeup(&port->draining);
1763 /* wait for the output to drain */
1769 struct dgb_softc *sc=&dgb_softc[port->unit];
1770 volatile struct board_chan *bc=port->brdchan;
1774 BoardMemWinState ws=bmws_get();
1783 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1784 port->unit, port->pnum, head, tail);
1788 timeout(wakeflush,port, hz);
1789 error=tsleep(&port->draining, PCATCH, "dgdrn", 0);
1794 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgdrn) error=%d\n",
1795 port->unit,port->pnum,error);
1805 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1806 port->unit, port->pnum, head, tail);
1811 /* wait for the output to drain */
1812 /* or simply clear the buffer it it's stopped */
1815 dgb_drain_or_flush(port)
1818 struct tty *tp=port->tty;
1819 struct dgb_softc *sc=&dgb_softc[port->unit];
1820 volatile struct board_chan *bc=port->brdchan;
1832 while(tail!=head /* && tail!=lasttail */ ) {
1833 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1834 port->unit, port->pnum, head, tail);
1836 /* if there is no carrier simply clean the buffer */
1837 if( !(tp->t_state & TS_CARR_ON) ) {
1846 timeout(wakeflush,port, hz);
1847 error=tsleep(&port->draining, PCATCH, "dgfls", 0);
1852 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgfls) error=%d\n",
1853 port->unit,port->pnum,error);
1855 /* silently clean the buffer */
1868 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1869 port->unit, port->pnum, head, tail);
1877 int unit=MINOR_TO_UNIT(minor(tp->t_dev));
1878 int pnum=MINOR_TO_PORT(minor(tp->t_dev));
1879 struct dgb_softc *sc=&dgb_softc[unit];
1880 struct dgb_p *port=&sc->ports[pnum];
1881 volatile struct board_chan *bc=port->brdchan;
1889 BoardMemWinState ws=bmws_get();
1891 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);
1893 if(port->mustdrain) {
1894 DPRINT3(DB_PARAM,"dgb%d: port%d: must call dgbdrain()\n",unit,pnum);
1898 cflag=ttspeedtab(t->c_ospeed, dgbspeedtab);
1900 if (t->c_ispeed == 0)
1901 t->c_ispeed = t->c_ospeed;
1903 if (cflag < 0 /* || cflag > 0 && t->c_ispeed != t->c_ospeed */) {
1904 DPRINT4(DB_PARAM,"dgb%d: port%d: invalid cflag=0%o\n",unit,pnum,cflag);
1911 if(cflag==0) { /* hangup */
1912 DPRINT3(DB_PARAM,"dgb%d: port%d: hangup\n",unit,pnum);
1916 fepcmd(port, STOUT, (unsigned)head, 0, 0, 0);
1917 mval= port->omodem & ~(DTR|RTS);
1919 cflag |= dgbflags(dgb_cflags, t->c_cflag);
1921 if(cflag!=port->fepcflag) {
1922 port->fepcflag=cflag;
1923 DPRINT5(DB_PARAM,"dgb%d: port%d: set cflag=0x%x c=0x%x\n",
1924 unit,pnum,cflag,t->c_cflag&~CRTSCTS);
1925 fepcmd(port, SETCTRLFLAGS, (unsigned)cflag, 0, 0, 0);
1927 mval= port->omodem | (DTR|RTS);
1930 iflag=dgbflags(dgb_iflags, t->c_iflag);
1931 if(iflag!=port->fepiflag) {
1932 port->fepiflag=iflag;
1933 DPRINT5(DB_PARAM,"dgb%d: port%d: set iflag=0x%x c=0x%x\n",unit,pnum,iflag,t->c_iflag);
1934 fepcmd(port, SETIFLAGS, (unsigned)iflag, 0, 0, 0);
1939 hflow=dgbflags(dgb_flow, t->c_cflag);
1940 if(hflow!=port->hflow) {
1942 DPRINT5(DB_PARAM,"dgb%d: port%d: set hflow=0x%x f=0x%x\n",unit,pnum,hflow,t->c_cflag&CRTSCTS);
1943 fepcmd(port, SETHFLOW, (unsigned)hflow, 0xff, 0, 1);
1946 if(port->omodem != mval) {
1947 DPRINT5(DB_PARAM,"dgb%d: port%d: setting modem parameters 0x%x was 0x%x\n",
1948 unit,pnum,mval,port->omodem);
1950 fepcmd(port, SETMODEM, (unsigned)mval, RTS|DTR, 0, 1);
1953 if(port->fepstartc!=t->c_cc[VSTART] || port->fepstopc!=t->c_cc[VSTOP]) {
1954 DPRINT5(DB_PARAM,"dgb%d: port%d: set startc=%d, stopc=%d\n",unit,pnum,t->c_cc[VSTART],t->c_cc[VSTOP]);
1955 port->fepstartc=t->c_cc[VSTART];
1956 port->fepstopc=t->c_cc[VSTOP];
1957 fepcmd(port, SONOFFC, port->fepstartc, port->fepstopc, 0, 1);
1974 struct dgb_softc *sc;
1975 volatile struct board_chan *bc;
1981 BoardMemWinState ws=bmws_get();
1983 unit=MINOR_TO_UNIT(minor(tp->t_dev));
1984 pnum=MINOR_TO_PORT(minor(tp->t_dev));
1985 sc=&dgb_softc[unit];
1986 port=&sc->ports[pnum];
1989 wmask=port->txbufsize-1;
1993 while( tp->t_outq.c_cc!=0 ) {
1995 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1998 if(tp->t_outq.c_cc <= tp->t_lowat) {
1999 if(tp->t_state & TS_ASLEEP) {
2000 tp->t_state &= ~TS_ASLEEP;
2001 wakeup(TSA_OLOWAT(tp));
2003 /*selwakeup(&tp->t_wsel);*/
2009 head=bc->tin & wmask;
2011 do { tail=bc->tout; } while (tail != bc->tout);
2012 tail=bc->tout & wmask;
2014 DPRINT5(DB_WR,"dgb%d: port%d: s tx head=%d tail=%d\n",unit,pnum,head,tail);
2016 #ifdef LEAVE_FREE_CHARS
2018 size=tail-head-LEAVE_FREE_CHARS;
2022 size=port->txbufsize-head;
2023 if(tail+port->txbufsize < head)
2031 size=port->txbufsize-head/*-1*/;
2038 bc->iempty=1; bc->ilow=1;
2041 tp->t_state|=TS_BUSY;
2046 towin(sc,port->txwin);
2048 ocount=q_to_b(&tp->t_outq, port->txptr+head, size);
2050 if(head>=port->txbufsize)
2051 head-=port->txbufsize;
2056 DPRINT5(DB_WR,"dgb%d: port%d: tx avail=%d count=%d\n",unit,pnum,size,ocount);
2064 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2065 if(tp->t_state & TS_BUSY) {
2066 tp->t_state&=~TS_BUSY;
2067 linesw[tp->t_line].l_start(tp);
2071 if(tp->t_state & TS_ASLEEP) {
2072 tp->t_state &= ~TS_ASLEEP;
2073 wakeup(TSA_OLOWAT(tp));
2075 tp->t_state&=~TS_BUSY;
2087 struct dgb_softc *sc;
2088 volatile struct board_chan *bc;
2091 BoardMemWinState ws=bmws_get();
2093 unit=MINOR_TO_UNIT(minor(tp->t_dev));
2094 pnum=MINOR_TO_PORT(minor(tp->t_dev));
2096 sc=&dgb_softc[unit];
2097 port=&sc->ports[pnum];
2100 DPRINT3(DB_WR,"dgb%d: port%d: stop\n",port->unit, port->pnum);
2106 /* clear output queue */
2108 bc->ilow=0;bc->iempty=0;
2111 /* clear input queue */
2122 fepcmd(port, cmd, op1, op2, ncmds, bytecmd)
2124 unsigned cmd, op1, op2, ncmds, bytecmd;
2126 struct dgb_softc *sc=&dgb_softc[port->unit];
2127 u_char *mem=sc->vmem;
2128 unsigned tail, head;
2131 if(port->status==DISABLED) {
2132 printf("dgb%d: port%d: FEP command on disabled port\n",
2133 port->unit, port->pnum);
2137 /* setwin(sc,0); Require this to be set by caller */
2138 head=sc->mailbox->cin;
2140 if(head>=(FEP_CMAX-FEP_CSTART) || (head & 3)) {
2141 printf("dgb%d: port%d: wrong pointer head of command queue : 0x%x\n",
2142 port->unit, port->pnum, head);
2146 mem[head+FEP_CSTART+0]=cmd;
2147 mem[head+FEP_CSTART+1]=port->pnum;
2149 mem[head+FEP_CSTART+2]=op1;
2150 mem[head+FEP_CSTART+3]=op2;
2152 mem[head+FEP_CSTART+2]=op1&0xff;
2153 mem[head+FEP_CSTART+3]=(op1>>8)&0xff;
2156 DPRINT7(DB_FEP,"dgb%d: port%d: %s cmd=0x%x op1=0x%x op2=0x%x\n", port->unit, port->pnum,
2157 (bytecmd)?"byte":"word", cmd, mem[head+FEP_CSTART+2], mem[head+FEP_CSTART+3]);
2159 head=(head+4) & (FEP_CMAX-FEP_CSTART-4);
2160 sc->mailbox->cin=head;
2164 while (count-- != 0) {
2165 head=sc->mailbox->cin;
2166 tail=sc->mailbox->cout;
2168 n = (head-tail) & (FEP_CMAX-FEP_CSTART-4);
2169 if(n <= ncmds * (sizeof(ushort)*4))
2172 printf("dgb%d(%d): timeout on FEP cmd=0x%x\n", port->unit, port->pnum, cmd);
2180 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2181 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2182 && (!(t->c_iflag & PARMRK)
2183 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2184 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2185 && linesw[tp->t_line].l_rint == ttyinput)
2186 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2188 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;