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.15 2005/01/31 23:44:35 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"
33 #include "opt_depricated.h"
34 #ifndef I_WANT_DEPRECATED_STUFF
35 #error "Add options I_WANT_DEPRECATED_STUFF to your kernel config and send a mail to kernel@"
40 /* Helg: i.e.25 times per sec board will be polled */
41 #define POLLSPERSEC 25
42 /* How many charactes can we write to input tty rawq */
43 #define DGB_IBUFSIZE (TTYHOG-100)
45 /* the overall number of ports controlled by this driver */
48 # define NDGBPORTS (NDGB*16)
51 #include <sys/param.h>
52 #include <sys/systm.h>
56 #include <sys/dkstat.h>
57 #include <sys/fcntl.h>
58 #include <sys/kernel.h>
59 #include <sys/sysctl.h>
61 #include <machine/clock.h>
66 #include <bus/isa/i386/isa_device.h>
71 #define DGB_DEBUG /* Enable debugging info via sysctl */
74 #define CALLOUT_MASK 0x80
75 #define CONTROL_MASK 0x60
76 #define CONTROL_INIT_STATE 0x20
77 #define CONTROL_LOCK_STATE 0x40
78 #define UNIT_MASK 0x30000
79 #define PORT_MASK 0x1F
80 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
81 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
82 #define MINOR_TO_UNIT(mynor) (((mynor) & UNIT_MASK)>>16)
83 #define MINOR_TO_PORT(mynor) ((mynor) & PORT_MASK)
85 /* types. XXX - should be elsewhere */
86 typedef u_char bool_t; /* boolean */
88 /* digiboard port structure */
92 u_char unit; /* board unit number */
93 u_char pnum; /* port number */
94 u_char omodem; /* FEP output modem status */
95 u_char imodem; /* FEP input modem status */
96 u_char modemfake; /* Modem values to be forced */
97 u_char modem; /* Force values */
124 volatile u_char *txptr;
125 volatile u_char *rxptr;
126 volatile struct board_chan *brdchan;
129 bool_t active_out; /* nonzero if the callout device is open */
130 u_int wopeners; /* # processes waiting for DCD in open() */
133 struct termios it_in; /* should be in struct tty */
134 struct termios it_out;
137 struct termios lt_in; /* should be in struct tty */
138 struct termios lt_out;
141 bool_t do_dcd_timestamp;
142 struct timeval timestamp;
143 struct timeval dcd_timestamp;
145 /* flags of state, are used in sleep() too */
146 u_char closing; /* port is being closed now */
147 u_char draining; /* port is being drained now */
148 u_char used; /* port is being used now */
149 u_char mustdrain; /* data must be waited to drain in dgbparam() */
152 /* Digiboard per-board structure */
154 /* struct board_info */
155 u_char status; /* status: DISABLED/ENABLED */
156 u_char unit; /* unit number */
157 u_char type; /* type of card: PCXE, PCXI, PCXEVE */
158 u_char altpin; /* do we need alternate pin setting ? */
159 int numports; /* number of ports on card */
160 int port; /* I/O port */
161 u_char *vmem; /* virtual memory address */
162 long pmem; /* physical memory address */
163 int mem_seg; /* internal memory segment */
164 struct dgb_p *ports; /* pointer to array of port descriptors */
165 struct tty *ttys; /* pointer to array of TTY structures */
166 volatile struct global_data *mailbox;
167 struct callout dgb_pause;
168 struct callout dgbpoll;
169 struct callout wakeflush;
173 static struct dgb_softc dgb_softc[NDGB];
174 static struct dgb_p dgb_ports[NDGBPORTS];
175 static struct tty dgb_tty[NDGBPORTS];
178 * The public functions in the com module ought to be declared in a com-driver
182 /* Interrupt handling entry points. */
183 static void dgbpoll (void *unit_c);
185 /* Device switch entry points. */
186 #define dgbreset noreset
187 #define dgbmmap nommap
188 #define dgbstrategy nostrategy
190 static int dgbattach (struct isa_device *dev);
191 static int dgbprobe (struct isa_device *dev);
193 static void fepcmd(struct dgb_p *port, unsigned cmd, unsigned op1, unsigned op2,
194 unsigned ncmds, unsigned bytecmd);
196 static void dgbstart (struct tty *tp);
197 static void dgbstop (struct tty *tp, int rw);
198 static int dgbparam (struct tty *tp, struct termios *t);
199 static void dgbhardclose (struct dgb_p *port);
200 static void dgb_drain_or_flush (struct dgb_p *port);
201 static int dgbdrain (struct dgb_p *port);
202 static void dgb_pause (void *chan);
203 static void wakeflush (void *p);
204 static void disc_optim (struct tty *tp, struct termios *t);
207 struct isa_driver dgbdriver = {
208 dgbprobe, dgbattach, "dgb",0
211 static d_open_t dgbopen;
212 static d_close_t dgbclose;
213 static d_ioctl_t dgbioctl;
215 #define CDEV_MAJOR 58
216 static struct cdevsw dgb_cdevsw = {
218 /* maj */ CDEV_MAJOR,
219 /* flags */ D_TTY | D_KQFILTER,
224 /* close */ dgbclose,
226 /* write */ ttywrite,
227 /* ioctl */ dgbioctl,
230 /* strategy */ nostrategy,
233 /* kqfilter */ ttykqfilter
236 static speed_t dgbdefaultrate = TTYDEF_SPEED;
238 static struct speedtab dgbspeedtab[] = {
239 { 0, FEP_B0 }, /* old (sysV-like) Bx codes */
253 { 19200, FEP_B19200 },
254 { 38400, FEP_B38400 },
255 { 57600, (FEP_FASTBAUD|FEP_B50) }, /* B50 & fast baud table */
256 { 115200, (FEP_FASTBAUD|FEP_B110) }, /* B100 & fast baud table */
260 static struct dbgflagtbl
267 { PARODD, PARODD, FEP_PARODD },
268 { PARENB, PARENB, FEP_PARENB },
269 { CSTOPB, CSTOPB, FEP_CSTOPB },
270 { CSIZE, CS5, FEP_CS6 },
271 { CSIZE, CS6, FEP_CS6 },
272 { CSIZE, CS7, FEP_CS7 },
273 { CSIZE, CS8, FEP_CS8 },
274 { CLOCAL, CLOCAL, FEP_CLOCAL },
278 { IGNBRK, IGNBRK, FEP_IGNBRK },
279 { BRKINT, BRKINT, FEP_BRKINT },
280 { IGNPAR, IGNPAR, FEP_IGNPAR },
281 { PARMRK, PARMRK, FEP_PARMRK },
282 { INPCK, INPCK, FEP_INPCK },
283 { ISTRIP, ISTRIP, FEP_ISTRIP },
284 { IXON, IXON, FEP_IXON },
285 { IXOFF, IXOFF, FEP_IXOFF },
286 { IXANY, IXANY, FEP_IXANY },
290 { CRTSCTS, CRTSCTS, CTS|RTS },
291 { CRTSCTS, CCTS_OFLOW, CTS },
292 { CRTSCTS, CRTS_IFLOW, RTS },
296 /* xlat bsd termios flags to dgb sys-v style */
298 dgbflags(struct dbgflagtbl *tbl, tcflag_t input)
303 for (i=0; tbl[i].in_mask != (tcflag_t)-1; i++)
305 if ((input & tbl[i].in_mask) == tbl[i].in_val)
306 output |= tbl[i].out_val;
312 static int dgbdebug=0;
313 SYSCTL_INT(_debug, OID_AUTO, dgb_debug, CTLFLAG_RW, &dgbdebug, 0, "");
316 static __inline int setwin (struct dgb_softc *sc, unsigned addr);
317 static __inline int setinitwin (struct dgb_softc *sc, unsigned addr);
318 static __inline void hidewin (struct dgb_softc *sc);
319 static __inline void towin (struct dgb_softc *sc, int win);
321 /*Helg: to allow recursive dgb...() calls */
323 { /* If we were called and don't want to disturb we need: */
324 int port; /* write to this port */
325 u_char data; /* this data on exit */
326 /* or DATA_WINOFF to close memory window on entry */
327 } BoardMemWinState; /* so several channels and even boards can coexist */
328 #define DATA_WINOFF 0
329 static BoardMemWinState bmws;
331 /* return current memory window state and close window */
332 static BoardMemWinState
335 BoardMemWinState bmwsRet=bmws;
336 if(bmws.data!=DATA_WINOFF)
337 outb(bmws.port, bmws.data=DATA_WINOFF);
341 /* restore memory window state */
343 bmws_set(BoardMemWinState ws)
345 if(ws.data != bmws.data || ws.port!=bmws.port ) {
346 if(bmws.data!=DATA_WINOFF)
347 outb(bmws.port,DATA_WINOFF);
348 if(ws.data!=DATA_WINOFF)
349 outb(ws.port, ws.data);
356 struct dgb_softc *sc;
359 if(sc->type==PCXEVE) {
360 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
361 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
362 return (addr & 0x1FFF);
364 outb(bmws.port=sc->port,bmws.data=FEPMEM);
371 struct dgb_softc *sc;
374 if(sc->type==PCXEVE) {
375 outb(bmws.port=sc->port+1, bmws.data=FEPWIN|(addr>>13));
376 DPRINT3(DB_WIN,"dgb%d: switched to window 0x%x\n",sc->unit,addr>>13);
377 return (addr & 0x1FFF);
379 outb(bmws.port=sc->port,bmws.data=inb(sc->port)|FEPMEM);
386 struct dgb_softc *sc;
390 outb(bmws.port=sc->port+1, bmws.data);
392 outb(bmws.port=sc->port, bmws.data);
397 struct dgb_softc *sc;
400 if(sc->type==PCXEVE) {
401 outb(bmws.port=sc->port+1, bmws.data=win);
403 outb(bmws.port=sc->port,bmws.data=FEPMEM);
409 struct isa_device *dev;
411 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
413 u_long win_size; /* size of vizible memory window */
414 int unit=dev->id_unit;
416 sc->unit=dev->id_unit;
417 sc->port=dev->id_iobase;
419 if(dev->id_flags & DGBFLAG_ALTPIN)
424 /* left 24 bits only (ISA address) */
425 sc->pmem=((intptr_t)(void *)dev->id_maddr & 0xFFFFFF);
427 DPRINT4(DB_INFO,"dgb%d: port 0x%x mem 0x%lx\n",unit,sc->port,sc->pmem);
429 outb(sc->port, FEPRST);
432 for(i=0; i< 1000; i++) {
434 if( (inb(sc->port) & FEPMASK) == FEPRST ) {
436 DPRINT3(DB_EXCEPT,"dgb%d: got reset after %d us\n",unit,i);
441 if(sc->status!=ENABLED) {
442 DPRINT2(DB_EXCEPT,"dgb%d: failed to respond\n",dev->id_unit);
446 /* check type of card and get internal memory characteristics */
455 printf("dgb%d: PC/Xi 64K\n",dev->id_unit);
460 printf("dgb%d: PC/Xi 128K\n",dev->id_unit);
465 printf("dgb%d: PC/Xi 256K\n",dev->id_unit);
467 default: /* case 0x30: */
470 printf("dgb%d: PC/Xi 512K\n",dev->id_unit);
479 printf("dgb%d: PC/Xm isn't supported\n",dev->id_unit);
486 if(dev->id_flags==DGBFLAG_NOWIN || ( v&0xC0 )==0) {
488 printf("dgb%d: PC/Xe 64K\n",dev->id_unit);
492 printf("dgb%d: PC/Xe 64/8K (windowed)\n",dev->id_unit);
494 if((u_long)sc->pmem & ~0xFFE000) {
495 printf("dgb%d: warning: address 0x%lx truncated to 0x%lx\n",
496 dev->id_unit, sc->pmem,
497 sc->pmem & 0xFFE000);
499 dev->id_maddr= (u_char *)(void *)(intptr_t)( sc->pmem & 0xFFE000 );
504 /* save size of vizible memory segment */
505 dev->id_msize=win_size;
508 dev->id_maddr=sc->vmem=pmap_mapdev(sc->pmem,dev->id_msize);
510 outb(sc->port, FEPCLR); /* drop RESET */
511 hidewin(sc); /* Helg: to set initial bmws state */
513 return 4; /* we need I/O space of 4 ports */
518 struct isa_device *dev;
520 int unit=dev->id_unit;
521 struct dgb_softc *sc= &dgb_softc[dev->id_unit];
523 u_char volatile *mem;
524 u_char volatile *ptr;
527 volatile struct board_chan *bc;
530 const volatile ushort *pstat;
535 if(sc->status!=ENABLED) {
536 DPRINT2(DB_EXCEPT,"dbg%d: try to attach a disabled card\n",unit);
540 callout_init(&sc->dgb_pause);
541 callout_init(&sc->dgbpoll);
542 callout_init(&sc->wakeflush);
546 DPRINT3(DB_INFO,"dgb%d: internal memory segment 0x%x\n",unit,sc->mem_seg);
548 outb(sc->port, FEPRST); DELAY(1);
550 for(i=0; (inb(sc->port) & FEPMASK) != FEPRST ; i++) {
552 printf("dgb%d: 1st reset failed\n",dev->id_unit);
560 DPRINT3(DB_INFO,"dgb%d: got reset after %d us\n",unit,i);
562 /* for PCXEVE set up interrupt and base address */
564 if(sc->type==PCXEVE) {
565 t=(((u_long)sc->pmem>>8) & 0xFFE0) | 0x10 /* enable windowing */;
567 outb(sc->port+2,t & 0xFF);
568 outb(sc->port+3,t>>8);
569 } else if(sc->type==PCXE) {
570 t=(((u_long)sc->pmem>>8) & 0xFFE0) /* disable windowing */;
571 outb(sc->port+2,t & 0xFF);
572 outb(sc->port+3,t>>8);
576 if(sc->type==PCXI || sc->type==PCXE) {
577 outb(sc->port, FEPRST|FEPMEM); DELAY(1);
579 for(i=0; (inb(sc->port) & FEPMASK) != (FEPRST|FEPMEM) ; i++) {
581 printf("dgb%d: 2nd reset failed\n",dev->id_unit);
589 DPRINT3(DB_INFO,"dgb%d: got memory after %d us\n",unit,i);
594 /* very short memory test */
596 addr=setinitwin(sc,BOTWIN);
597 *(u_long volatile *)(mem+addr) = 0xA55A3CC3;
598 if(*(u_long volatile *)(mem+addr)!=0xA55A3CC3) {
599 printf("dgb%d: 1st memory test failed\n",dev->id_unit);
605 addr=setinitwin(sc,TOPWIN);
606 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
607 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
608 printf("dgb%d: 2nd memory test failed\n",dev->id_unit);
614 addr=setinitwin(sc,BIOSCODE+((0xF000-sc->mem_seg)<<4));
615 *(u_long volatile *)(mem+addr) = 0x5AA5C33C;
616 if(*(u_long volatile *)(mem+addr)!=0x5AA5C33C) {
617 printf("dgb%d: 3rd (BIOS) memory test failed\n",dev->id_unit);
620 addr=setinitwin(sc,MISCGLOBAL);
621 for(i=0; i<16; i++) {
625 if(sc->type==PCXI || sc->type==PCXE) {
627 addr=BIOSCODE+((0xF000-sc->mem_seg)<<4);
629 DPRINT3(DB_INFO,"dgb%d: BIOS local address=0x%x\n",unit,addr);
633 for(i=0; i<pcxx_nbios; i++, ptr++)
639 for(i=0; i<pcxx_nbios; i++, ptr++)
640 if( *ptr != pcxx_bios[i] ) {
641 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
642 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
645 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
650 outb(sc->port,FEPMEM);
652 for(i=0; (inb(sc->port) & FEPMASK) != FEPMEM ; i++) {
654 printf("dgb%d: BIOS start failed\n",dev->id_unit);
662 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
664 for(i=0; i<200000; i++) {
665 if( *((ushort volatile *)(mem+MISCGLOBAL)) == *((ushort *)"GD") )
669 printf("dgb%d: BIOS download failed\n",dev->id_unit);
670 DPRINT4(DB_EXCEPT,"dgb%d: code=0x%x must be 0x%x\n",
672 *((ushort volatile *)(mem+MISCGLOBAL)),
680 if(sc->type==PCXEVE) {
682 outb(sc->port+1,0xFF);
684 ptr= mem+(BIOSCODE & 0x1FFF);
686 for(i=0; i<pcxx_nbios; i++)
687 *ptr++ = pcxx_bios[i];
689 ptr= mem+(BIOSCODE & 0x1FFF);
692 for(i=0; i<pcxx_nbios; i++, ptr++)
693 if( *ptr != pcxx_bios[i] ) {
694 DPRINT5(DB_EXCEPT,"dgb%d: wrong code in BIOS at addr 0x%x : \
695 0x%x instead of 0x%x\n", unit, ptr-(mem+addr), *ptr, pcxx_bios[i] );
698 printf("dgb%d: 4th memory test (BIOS load) fails\n",unit);
703 outb(sc->port,FEPCLR);
707 for(i=0; (inb(sc->port) & FEPMASK) != FEPCLR ; i++) {
709 printf("dgb%d: BIOS start failed\n",dev->id_unit);
717 DPRINT3(DB_INFO,"dgb%d: reset dropped after %d us\n",unit,i);
719 addr=setwin(sc,MISCGLOBAL);
721 for(i=0; i<200000; i++) {
722 if(*(ushort volatile *)(mem+addr)== *(ushort *)"GD")
726 printf("dgb%d: BIOS download failed\n",dev->id_unit);
727 DPRINT5(DB_EXCEPT,"dgb%d: Error#(0x%x,0x%x) code=0x%x\n",
729 *(ushort volatile *)(mem+0xC12),
730 *(ushort volatile *)(mem+0xC14),
731 *(ushort volatile *)(mem+MISCGLOBAL));
739 DPRINT2(DB_INFO,"dgb%d: BIOS loaded\n",dev->id_unit);
741 addr=setwin(sc,FEPCODE);
745 for(i=0; i<pcxx_ncook; i++)
746 *ptr++ = pcxx_cook[i];
748 addr=setwin(sc,MBOX);
749 *(ushort volatile *)(mem+addr+ 0)=2;
750 *(ushort volatile *)(mem+addr+ 2)=sc->mem_seg+FEPCODESEG;
751 *(ushort volatile *)(mem+addr+ 4)=0;
752 *(ushort volatile *)(mem+addr+ 6)=FEPCODESEG;
753 *(ushort volatile *)(mem+addr+ 8)=0;
754 *(ushort volatile *)(mem+addr+10)=pcxx_ncook;
756 outb(sc->port,FEPMEM|FEPINT); /* send interrupt to BIOS */
757 outb(sc->port,FEPMEM);
759 for(i=0; *(ushort volatile *)(mem+addr)!=0; i++) {
761 printf("dgb%d: FEP code download failed\n",unit);
762 DPRINT3(DB_EXCEPT,"dgb%d: code=0x%x must be 0\n", unit,
763 *(ushort volatile *)(mem+addr));
770 DPRINT2(DB_INFO,"dgb%d: FEP code loaded\n",unit);
772 *(ushort volatile *)(mem+setwin(sc,FEPSTAT))=0;
773 addr=setwin(sc,MBOX);
774 *(ushort volatile *)(mem+addr+0)=1;
775 *(ushort volatile *)(mem+addr+2)=FEPCODESEG;
776 *(ushort volatile *)(mem+addr+4)=0x4;
778 outb(sc->port,FEPINT); /* send interrupt to BIOS */
779 outb(sc->port,FEPCLR);
781 addr=setwin(sc,FEPSTAT);
782 for(i=0; *(ushort volatile *)(mem+addr)!= *(ushort *)"OS"; i++) {
784 printf("dgb%d: FEP/OS start failed\n",dev->id_unit);
791 DPRINT2(DB_INFO,"dgb%d: FEP/OS started\n",dev->id_unit);
793 sc->numports= *(ushort volatile *)(mem+setwin(sc,NPORT));
795 printf("dgb%d: %d ports\n",unit,sc->numports);
797 if(sc->numports > MAX_DGB_PORTS) {
798 printf("dgb%d: too many ports\n",unit);
804 if(nports+sc->numports>NDGBPORTS) {
805 printf("dgb%d: only %d ports are usable\n", unit, NDGBPORTS-nports);
806 sc->numports=NDGBPORTS-nports;
809 /* allocate port and tty structures */
810 sc->ports=&dgb_ports[nports];
811 sc->ttys=&dgb_tty[nports];
812 nports+=sc->numports;
814 addr=setwin(sc,PORTBASE);
815 pstat=(const ushort volatile *)(mem+addr);
817 for(i=0; i<sc->numports && pstat[i]; i++)
819 sc->ports[i].status=ENABLED;
821 sc->ports[i].status=DISABLED;
822 printf("dgb%d: port%d is broken\n", unit, i);
825 /* We should now init per-port structures */
826 bc=(volatile struct board_chan *)(mem + CHANSTRUCT);
827 sc->mailbox=(volatile struct global_data *)(mem + FEP_GLOBAL);
834 for(i=0; i<sc->numports; i++, bc++) {
837 port->tty=&sc->ttys[i];
853 DPRINT2(DB_INFO,"dgb%d: shrinking memory\n",unit);
854 fepcmd(port, SETBUFFER, 32, 0, 0, 0);
858 if(sc->type!=PCXEVE) {
859 port->txptr=mem+((bc->tseg-sc->mem_seg)<<4);
860 port->rxptr=mem+((bc->rseg-sc->mem_seg)<<4);
861 port->txwin=port->rxwin=0;
863 port->txptr=mem+( ((bc->tseg-sc->mem_seg)<<4) & 0x1FFF );
864 port->rxptr=mem+( ((bc->rseg-sc->mem_seg)<<4) & 0x1FFF );
865 port->txwin=FEPWIN | ((bc->tseg-sc->mem_seg)>>9);
866 port->rxwin=FEPWIN | ((bc->rseg-sc->mem_seg)>>9);
871 port->txbufsize=bc->tmax+1;
872 port->rxbufsize=bc->rmax+1;
874 lowwater= (port->txbufsize>=2000) ? 1024 : (port->txbufsize/2);
876 fepcmd(port, STXLWATER, lowwater, 0, 10, 0);
877 fepcmd(port, SRXLWATER, port->rxbufsize/4, 0, 10, 0);
878 fepcmd(port, SRXHWATER, 3*port->rxbufsize/4, 0, 10, 0);
883 port->startc=bc->startc;
884 port->startca=bc->startca;
885 port->stopc=bc->stopc;
886 port->stopca=bc->stopca;
888 /*port->close_delay=50;*/
889 port->close_delay=3 * hz;
890 port->do_timestamp=0;
891 port->do_dcd_timestamp=0;
894 * We don't use all the flags from <sys/ttydefaults.h> since they
895 * are only relevant for logins. It's important to have echo off
896 * initially so that the line doesn't start blathering before the
897 * echo flag can be turned off.
899 port->it_in.c_iflag = TTYDEF_IFLAG;
900 port->it_in.c_oflag = TTYDEF_OFLAG;
901 port->it_in.c_cflag = TTYDEF_CFLAG;
902 port->it_in.c_lflag = TTYDEF_LFLAG;
903 termioschars(&port->it_in);
904 port->it_in.c_ispeed = port->it_in.c_ospeed = dgbdefaultrate;
905 port->it_out = port->it_in;
906 /* MAX_DGB_PORTS is 32 => [0-9a-v] */
907 suffix = i < 10 ? '0' + i : 'a' + i - 10;
908 cdevsw_add(&dgb_cdevsw, 0xffff0000, unit << 16);
909 make_dev(&dgb_cdevsw, (unit<<16)+i,
910 UID_ROOT, GID_WHEEL, 0600, "ttyD%d%c", unit, suffix);
912 make_dev(&dgb_cdevsw, (unit<<16)+i+32,
913 UID_ROOT, GID_WHEEL, 0600, "ttyiD%d%c", unit, suffix);
915 make_dev(&dgb_cdevsw, (unit<<16)+i+64,
916 UID_ROOT, GID_WHEEL, 0600, "ttylD%d%c", unit, suffix);
918 make_dev(&dgb_cdevsw, (unit<<16)+i+128,
919 UID_UUCP, GID_DIALER, 0660, "cuaD%d%c", unit, suffix);
921 make_dev(&dgb_cdevsw, (unit<<16)+i+160,
922 UID_UUCP, GID_DIALER, 0660, "cuaiD%d%c", unit, suffix);
924 make_dev(&dgb_cdevsw, (unit<<16)+i+192,
925 UID_UUCP, GID_DIALER, 0660, "cualD%d%c", unit, suffix);
930 /* register the polling function */
931 callout_reset(&sc->dgbpoll, hz / POLLSPERSEC, dgbpoll, (void *)unit);
938 dgbopen(dev_t dev, int flag, int mode, struct thread *td)
940 struct dgb_softc *sc;
948 volatile struct board_chan *bc;
953 unit=MINOR_TO_UNIT(mynor);
954 pnum=MINOR_TO_PORT(mynor);
957 DPRINT2(DB_EXCEPT,"dgb%d: try to open a nonexisting card\n",unit);
963 if(sc->status!=ENABLED) {
964 DPRINT2(DB_EXCEPT,"dgb%d: try to open a disabled card\n",unit);
968 if(pnum>=sc->numports) {
969 DPRINT3(DB_EXCEPT,"dgb%d: try to open non-existing port %d\n",unit,pnum);
973 if(mynor & CONTROL_MASK)
978 port=&sc->ports[pnum];
985 while(port->closing) {
986 error=tsleep(&port->closing, PCATCH, "dgocl", 0);
989 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgocl) error=%d\n",unit,pnum,error);
994 if (tp->t_state & TS_ISOPEN) {
996 * The device is open, so everything has been initialized.
999 if (mynor & CALLOUT_MASK) {
1000 if (!port->active_out) {
1002 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
1006 if (port->active_out) {
1007 if (flag & O_NONBLOCK) {
1009 DPRINT4(DB_OPEN,"dgb%d: port%d: BUSY error=%d\n",unit,pnum,error);
1012 error = tsleep(&port->active_out,
1015 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgbi) error=%d\n",
1023 if (tp->t_state & TS_XCLUDE && suser(td)) {
1029 * The device isn't open, so there are no conflicts.
1030 * Initialize it. Initialization is done twice in many
1031 * cases: to preempt sleeping callin opens if we are
1032 * callout, and to complete a callin open after DCD rises.
1034 tp->t_oproc=dgbstart;
1035 tp->t_param=dgbparam;
1038 tp->t_termios= (mynor & CALLOUT_MASK) ?
1044 port->imodem=bc->mstat;
1045 bc->rout=bc->rin; /* clear input queue */
1047 #ifdef PRINT_BUFSIZE
1048 printf("dgb buffers tx=%x:%x rx=%x:%x\n",bc->tseg,bc->tmax,bc->rseg,bc->rmax);
1055 error=dgbparam(tp, &tp->t_termios);
1059 DPRINT4(DB_OPEN,"dgb%d: port%d: dgbparam error=%d\n",unit,pnum,error);
1063 /* handle fake DCD for callout devices */
1064 /* and initial DCD */
1066 if( (port->imodem & port->dcd) || mynor & CALLOUT_MASK )
1067 linesw[tp->t_line].l_modem(tp,1);
1072 * Wait for DCD if necessary.
1074 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
1075 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
1077 error = tsleep(TSA_CARR_ON(tp), PCATCH, "dgdcd", 0);
1080 DPRINT4(DB_OPEN,"dgb%d: port%d: tsleep(dgdcd) error=%d\n",unit,pnum,error);
1086 error = linesw[tp->t_line].l_open(dev, tp);
1087 disc_optim(tp,&tp->t_termios);
1088 DPRINT4(DB_OPEN,"dgb%d: port%d: l_open error=%d\n",unit,pnum,error);
1090 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
1091 port->active_out = TRUE;
1095 /* If any port is open (i.e. the open() call is completed for it)
1096 * the device is busy
1100 disc_optim(tp,&tp->t_termios);
1103 if( !(tp->t_state & TS_ISOPEN) && port->wopeners==0 )
1106 DPRINT4(DB_OPEN,"dgb%d: port%d: open() returns %d\n",unit,pnum,error);
1113 dgbclose(dev_t dev, int flag, int mode, struct thread *td)
1117 struct dgb_softc *sc;
1124 if(mynor & CONTROL_MASK)
1126 unit=MINOR_TO_UNIT(mynor);
1127 pnum=MINOR_TO_PORT(mynor);
1129 sc=&dgb_softc[unit];
1131 port=sc->ports+pnum;
1133 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing\n",unit,pnum);
1135 DPRINT3(DB_CLOSE,"dgb%d: port%d: draining port\n",unit,pnum);
1136 dgb_drain_or_flush(port);
1141 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing line disc\n",unit,pnum);
1142 linesw[tp->t_line].l_close(tp,flag);
1143 disc_optim(tp,&tp->t_termios);
1145 DPRINT3(DB_CLOSE,"dgb%d: port%d: hard closing\n",unit,pnum);
1147 DPRINT3(DB_CLOSE,"dgb%d: port%d: closing tty\n",unit,pnum);
1150 wakeup(&port->closing);
1153 /* mark the card idle when all ports are closed */
1155 for(i=0; i<sc->numports; i++)
1156 if(sc->ports[i].used)
1161 DPRINT3(DB_CLOSE,"dgb%d: port%d: closed\n",unit,pnum);
1163 wakeup(TSA_CARR_ON(tp));
1164 wakeup(&port->active_out);
1167 DPRINT3(DB_CLOSE,"dgb%d: port%d: close exit\n",unit,pnum);
1176 struct dgb_softc *sc=&dgb_softc[port->unit];
1177 volatile struct board_chan *bc=port->brdchan;
1181 port->do_timestamp = 0;
1184 bc->idata=0; bc->iempty=0; bc->ilow=0;
1185 if(port->tty->t_cflag & HUPCL) {
1186 port->omodem &= ~(RTS|DTR);
1187 fepcmd(port, SETMODEM, 0, DTR|RTS, 0, 1);
1193 callout_reset(&sc->dgb_pause, hz / 2, dgb_pause, &port->brdchan);
1194 tsleep(&port->brdchan, PCATCH, "dgclo", 0);
1201 wakeup((caddr_t)chan);
1208 int unit=(int)unit_c;
1211 struct dgb_softc *sc=&dgb_softc[unit];
1214 int event, mstat, lstat;
1215 volatile struct board_chan *bc;
1222 int ibuf_full,obuf_full;
1224 BoardMemWinState ws=bmws_get();
1226 if(sc->status==DISABLED) {
1227 printf("dgb%d: polling of disabled board stopped\n",unit);
1233 head=sc->mailbox->ein;
1234 tail=sc->mailbox->eout;
1237 if(head >= FEP_IMAX-FEP_ISTART
1238 || tail >= FEP_IMAX-FEP_ISTART
1239 || (head|tail) & 03 ) {
1240 printf("dgb%d: event queue's head or tail is wrong! hd=%d,tl=%d\n", unit,head,tail);
1244 eventbuf=sc->vmem+tail+FEP_ISTART;
1250 port=&sc->ports[pnum];
1254 if(pnum>=sc->numports || port->status==DISABLED) {
1255 printf("dgb%d: port%d: got event on nonexisting port\n",unit,pnum);
1256 } else if(port->used || port->wopeners>0 ) {
1258 int wrapmask=port->rxbufsize-1;
1260 if( !(event & ALL_IND) )
1261 printf("dgb%d: port%d: ? event 0x%x mstat 0x%x lstat 0x%x\n",
1262 unit, pnum, event, mstat, lstat);
1264 if(event & DATA_IND) {
1265 DPRINT3(DB_DATA,"dgb%d: port%d: DATA_IND\n",unit,pnum);
1267 rhead=bc->rin & wrapmask;
1268 rtail=bc->rout & wrapmask;
1270 if( !(tp->t_cflag & CREAD) || !port->used ) {
1276 printf("dgb%d: port%d: overrun\n", unit, pnum);
1280 if(!(tp->t_state & TS_ISOPEN))
1283 for(ibuf_full=FALSE;rhead!=rtail && !ibuf_full;) {
1284 DPRINT5(DB_RXDATA,"dgb%d: port%d: p rx head=%d tail=%d\n",
1285 unit,pnum,rhead,rtail);
1290 size=port->rxbufsize-rtail;
1292 ptr=__DEVOLATILE(u_char *, port->rxptr+rtail);
1295 if( tp->t_rawq.c_cc + size > DGB_IBUFSIZE ) {
1296 size=DGB_IBUFSIZE-tp->t_rawq.c_cc;
1297 DPRINT1(DB_RXDATA,"*");
1302 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1303 DPRINT1(DB_RXDATA,"!");
1304 towin(sc,port->rxwin);
1307 tp->t_rawcc += size;
1308 b_to_q(ptr,size,&tp->t_rawq);
1314 towin(sc,port->rxwin);
1317 (*linesw[tp->t_line].l_rint)(chr, tp);
1322 rtail= (rtail + size) & wrapmask;
1324 rhead=bc->rin & wrapmask;
1332 if(event & MODEMCHG_IND) {
1333 DPRINT3(DB_MODEM,"dgb%d: port%d: MODEMCHG_IND\n",unit,pnum);
1335 if(mstat & port->dcd) {
1337 linesw[tp->t_line].l_modem(tp,1);
1339 wakeup(TSA_CARR_ON(tp));
1342 linesw[tp->t_line].l_modem(tp,0);
1344 if( port->draining) {
1346 wakeup(&port->draining);
1351 if(event & BREAK_IND) {
1352 if((tp->t_state & TS_ISOPEN) && (tp->t_iflag & IGNBRK)) {
1353 DPRINT3(DB_BREAK,"dgb%d: port%d: BREAK_IND\n",unit,pnum);
1355 linesw[tp->t_line].l_rint(TTY_BI, tp);
1360 /* Helg: with output flow control */
1362 if(event & (LOWTX_IND | EMPTYTX_IND) ) {
1363 DPRINT3(DB_TXDATA,"dgb%d: port%d: LOWTX_IND or EMPTYTX_IND\n",unit,pnum);
1365 if( (event & EMPTYTX_IND ) && tp->t_outq.c_cc==0
1366 && port->draining) {
1368 wakeup(&port->draining);
1369 bc->ilow=0; bc->iempty=0;
1372 int wrapmask=port->txbufsize-1;
1374 for(obuf_full=FALSE; tp->t_outq.c_cc!=0 && !obuf_full; ) {
1376 /* add "last-minute" data to write buffer */
1377 if(!(tp->t_state & TS_BUSY)) {
1379 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1382 if(tp->t_outq.c_cc <= tp->t_lowat) {
1383 if(tp->t_state & TS_ASLEEP) {
1384 tp->t_state &= ~TS_ASLEEP;
1385 wakeup(TSA_OLOWAT(tp));
1387 /* selwakeup(&tp->t_wsel); */
1394 whead=bc->tin & wrapmask;
1395 wtail=bc->tout & wrapmask;
1400 size=port->txbufsize-whead;
1406 DPRINT5(DB_WR,"dgb: head=%d tail=%d size=%d full=%d\n",
1407 whead,wtail,size,obuf_full);
1408 bc->iempty=1; bc->ilow=1;
1414 towin(sc,port->txwin);
1416 ocount=q_to_b(&tp->t_outq, __DEVOLATILE(u_char *, port->txptr+whead), size);
1421 bc->tin=whead & wrapmask;
1426 DPRINT1(DB_WR," +BUSY\n");
1427 tp->t_state|=TS_BUSY;
1429 DPRINT1(DB_WR," -BUSY\n");
1431 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
1432 /* should clear TS_BUSY before ttwwakeup */
1433 if(tp->t_state & TS_BUSY) {
1434 tp->t_state &= ~TS_BUSY;
1435 linesw[tp->t_line].l_start(tp);
1439 if(tp->t_state & TS_ASLEEP) {
1440 tp->t_state &= ~TS_ASLEEP;
1441 wakeup(TSA_OLOWAT(tp));
1443 tp->t_state &= ~TS_BUSY;
1449 bc->idata=1; /* require event on incoming data */
1453 DPRINT4(DB_EXCEPT,"dgb%d: port%d: got event 0x%x on closed port\n",
1456 bc->idata=bc->iempty=bc->ilow=0;
1459 tail= (tail+4) & (FEP_IMAX-FEP_ISTART-4);
1462 sc->mailbox->eout=tail;
1465 callout_reset(&sc->dgbpoll, hz / POLLSPERSEC, dgbpoll, unit_c);
1469 dgbioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
1471 struct dgb_softc *sc;
1476 volatile struct board_chan *bc;
1481 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1483 struct termios term;
1486 BoardMemWinState ws=bmws_get();
1489 unit=MINOR_TO_UNIT(mynor);
1490 pnum=MINOR_TO_PORT(mynor);
1492 sc=&dgb_softc[unit];
1493 port=&sc->ports[pnum];
1497 if (mynor & CONTROL_MASK) {
1500 switch (mynor & CONTROL_MASK) {
1501 case CONTROL_INIT_STATE:
1502 ct = mynor & CALLOUT_MASK ? &port->it_out : &port->it_in;
1504 case CONTROL_LOCK_STATE:
1505 ct = mynor & CALLOUT_MASK ? &port->lt_out : &port->lt_in;
1508 return (ENODEV); /* /dev/nodev */
1515 *ct = *(struct termios *)data;
1518 *(struct termios *)data = *ct;
1521 *(int *)data = TTYDISC;
1524 bzero(data, sizeof(struct winsize));
1531 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1532 term = tp->t_termios;
1533 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1534 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);
1537 error = ttsetcompat(tp, &cmd, data, &term);
1541 data = (caddr_t)&term;
1544 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1546 struct termios *dt = (struct termios *)data;
1547 struct termios *lt = mynor & CALLOUT_MASK
1548 ? &port->lt_out : &port->lt_in;
1550 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);
1551 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1552 | (dt->c_iflag & ~lt->c_iflag);
1553 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1554 | (dt->c_oflag & ~lt->c_oflag);
1555 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1556 | (dt->c_cflag & ~lt->c_cflag);
1557 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1558 | (dt->c_lflag & ~lt->c_lflag);
1559 for (cc = 0; cc < NCCS; ++cc)
1560 if (lt->c_cc[cc] != 0)
1561 dt->c_cc[cc] = tp->t_cc[cc];
1562 if (lt->c_ispeed != 0)
1563 dt->c_ispeed = tp->t_ispeed;
1564 if (lt->c_ospeed != 0)
1565 dt->c_ospeed = tp->t_ospeed;
1571 fepcmd(port, PAUSETX, 0, 0, 0, 0);
1575 } else if(cmd==TIOCSTART) {
1578 fepcmd(port, RESUMETX, 0, 0, 0, 0);
1584 if(cmd==TIOCSETAW || cmd==TIOCSETAF)
1587 error = linesw[tp->t_line].l_ioctl(tp, cmd, data, flag, td);
1588 if (error != ENOIOCTL)
1591 error = ttioctl(tp, cmd, data, flag);
1592 disc_optim(tp,&tp->t_termios);
1594 if (error != ENOIOCTL) {
1596 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1597 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);
1604 /* Helg: commented */
1605 /* error=dgbdrain(port);*/
1615 /* now it sends 250 millisecond break because I don't know */
1616 /* how to send an infinite break */
1618 fepcmd(port, SENDBREAK, 250, 0, 10, 0);
1623 /* now it's empty */
1626 DPRINT3(DB_MODEM,"dgb%d: port%d: set DTR\n",unit,pnum);
1627 port->omodem |= DTR;
1630 fepcmd(port, SETMODEM, port->omodem, RTS, 0, 1);
1632 if( !(bc->mstat & DTR) ) {
1633 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is off\n",unit,pnum);
1640 DPRINT3(DB_MODEM,"dgb%d: port%d: reset DTR\n",unit,pnum);
1641 port->omodem &= ~DTR;
1644 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1646 if( bc->mstat & DTR ) {
1647 DPRINT3(DB_MODEM,"dgb%d: port%d: DTR is on\n",unit,pnum);
1654 if(*(int *)data & TIOCM_DTR)
1657 port->omodem &=~DTR;
1659 if(*(int *)data & TIOCM_RTS)
1662 port->omodem &=~RTS;
1666 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1671 if(*(int *)data & TIOCM_DTR)
1674 if(*(int *)data & TIOCM_RTS)
1679 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1684 if(*(int *)data & TIOCM_DTR)
1685 port->omodem &=~DTR;
1687 if(*(int *)data & TIOCM_RTS)
1688 port->omodem &=~RTS;
1692 fepcmd(port, SETMODEM, port->omodem, RTS|DTR, 0, 1);
1698 port->imodem=bc->mstat;
1701 tiocm_xxx = TIOCM_LE; /* XXX - always enabled while open */
1703 DPRINT3(DB_MODEM,"dgb%d: port%d: modem stat -- ",unit,pnum);
1705 if (port->imodem & DTR) {
1706 DPRINT1(DB_MODEM,"DTR ");
1707 tiocm_xxx |= TIOCM_DTR;
1709 if (port->imodem & RTS) {
1710 DPRINT1(DB_MODEM,"RTS ");
1711 tiocm_xxx |= TIOCM_RTS;
1713 if (port->imodem & CTS) {
1714 DPRINT1(DB_MODEM,"CTS ");
1715 tiocm_xxx |= TIOCM_CTS;
1717 if (port->imodem & port->dcd) {
1718 DPRINT1(DB_MODEM,"DCD ");
1719 tiocm_xxx |= TIOCM_CD;
1721 if (port->imodem & port->dsr) {
1722 DPRINT1(DB_MODEM,"DSR ");
1723 tiocm_xxx |= TIOCM_DSR;
1725 if (port->imodem & RI) {
1726 DPRINT1(DB_MODEM,"RI ");
1727 tiocm_xxx |= TIOCM_RI;
1729 *(int *)data = tiocm_xxx;
1730 DPRINT1(DB_MODEM,"--\n");
1733 /* must be root since the wait applies to following logins */
1739 port->close_delay = *(int *)data * hz / 100;
1742 *(int *)data = port->close_delay * 100 / hz;
1745 port->do_timestamp = TRUE;
1746 *(struct timeval *)data = port->timestamp;
1748 case TIOCDCDTIMESTAMP:
1749 port->do_dcd_timestamp = TRUE;
1750 *(struct timeval *)data = port->dcd_timestamp;
1767 struct dgb_p *port=p;
1769 wakeup(&port->draining);
1772 /* wait for the output to drain */
1778 struct dgb_softc *sc=&dgb_softc[port->unit];
1779 volatile struct board_chan *bc=port->brdchan;
1783 BoardMemWinState ws=bmws_get();
1792 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1793 port->unit, port->pnum, head, tail);
1797 callout_reset(&sc->wakeflush, hz, wakeflush,port);
1798 error=tsleep(&port->draining, PCATCH, "dgdrn", 0);
1803 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgdrn) error=%d\n",
1804 port->unit,port->pnum,error);
1814 DPRINT5(DB_WR,"dgb%d: port%d: drain: head=%d tail=%d\n",
1815 port->unit, port->pnum, head, tail);
1820 /* wait for the output to drain */
1821 /* or simply clear the buffer it it's stopped */
1824 dgb_drain_or_flush(port)
1827 struct tty *tp=port->tty;
1828 struct dgb_softc *sc=&dgb_softc[port->unit];
1829 volatile struct board_chan *bc=port->brdchan;
1841 while(tail!=head /* && tail!=lasttail */ ) {
1842 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1843 port->unit, port->pnum, head, tail);
1845 /* if there is no carrier simply clean the buffer */
1846 if( !(tp->t_state & TS_CARR_ON) ) {
1855 callout_reset(&sc->wakeflush, hz, wakeflush, port);
1856 error=tsleep(&port->draining, PCATCH, "dgfls", 0);
1861 DPRINT4(DB_WR,"dgb%d: port%d: tsleep(dgfls) error=%d\n",
1862 port->unit,port->pnum,error);
1864 /* silently clean the buffer */
1877 DPRINT5(DB_WR,"dgb%d: port%d: flush: head=%d tail=%d\n",
1878 port->unit, port->pnum, head, tail);
1886 int unit=MINOR_TO_UNIT(minor(tp->t_dev));
1887 int pnum=MINOR_TO_PORT(minor(tp->t_dev));
1888 struct dgb_softc *sc=&dgb_softc[unit];
1889 struct dgb_p *port=&sc->ports[pnum];
1890 volatile struct board_chan *bc=port->brdchan;
1898 BoardMemWinState ws=bmws_get();
1900 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);
1902 if(port->mustdrain) {
1903 DPRINT3(DB_PARAM,"dgb%d: port%d: must call dgbdrain()\n",unit,pnum);
1907 cflag=ttspeedtab(t->c_ospeed, dgbspeedtab);
1909 if (t->c_ispeed == 0)
1910 t->c_ispeed = t->c_ospeed;
1912 if (cflag < 0 /* || cflag > 0 && t->c_ispeed != t->c_ospeed */) {
1913 DPRINT4(DB_PARAM,"dgb%d: port%d: invalid cflag=0%o\n",unit,pnum,cflag);
1920 if(cflag==0) { /* hangup */
1921 DPRINT3(DB_PARAM,"dgb%d: port%d: hangup\n",unit,pnum);
1925 fepcmd(port, STOUT, (unsigned)head, 0, 0, 0);
1926 mval= port->omodem & ~(DTR|RTS);
1928 cflag |= dgbflags(dgb_cflags, t->c_cflag);
1930 if(cflag!=port->fepcflag) {
1931 port->fepcflag=cflag;
1932 DPRINT5(DB_PARAM,"dgb%d: port%d: set cflag=0x%x c=0x%x\n",
1933 unit,pnum,cflag,t->c_cflag&~CRTSCTS);
1934 fepcmd(port, SETCTRLFLAGS, (unsigned)cflag, 0, 0, 0);
1936 mval= port->omodem | (DTR|RTS);
1939 iflag=dgbflags(dgb_iflags, t->c_iflag);
1940 if(iflag!=port->fepiflag) {
1941 port->fepiflag=iflag;
1942 DPRINT5(DB_PARAM,"dgb%d: port%d: set iflag=0x%x c=0x%x\n",unit,pnum,iflag,t->c_iflag);
1943 fepcmd(port, SETIFLAGS, (unsigned)iflag, 0, 0, 0);
1948 hflow=dgbflags(dgb_flow, t->c_cflag);
1949 if(hflow!=port->hflow) {
1951 DPRINT5(DB_PARAM,"dgb%d: port%d: set hflow=0x%x f=0x%x\n",unit,pnum,hflow,t->c_cflag&CRTSCTS);
1952 fepcmd(port, SETHFLOW, (unsigned)hflow, 0xff, 0, 1);
1955 if(port->omodem != mval) {
1956 DPRINT5(DB_PARAM,"dgb%d: port%d: setting modem parameters 0x%x was 0x%x\n",
1957 unit,pnum,mval,port->omodem);
1959 fepcmd(port, SETMODEM, (unsigned)mval, RTS|DTR, 0, 1);
1962 if(port->fepstartc!=t->c_cc[VSTART] || port->fepstopc!=t->c_cc[VSTOP]) {
1963 DPRINT5(DB_PARAM,"dgb%d: port%d: set startc=%d, stopc=%d\n",unit,pnum,t->c_cc[VSTART],t->c_cc[VSTOP]);
1964 port->fepstartc=t->c_cc[VSTART];
1965 port->fepstopc=t->c_cc[VSTOP];
1966 fepcmd(port, SONOFFC, port->fepstartc, port->fepstopc, 0, 1);
1983 struct dgb_softc *sc;
1984 volatile struct board_chan *bc;
1990 BoardMemWinState ws=bmws_get();
1992 unit=MINOR_TO_UNIT(minor(tp->t_dev));
1993 pnum=MINOR_TO_PORT(minor(tp->t_dev));
1994 sc=&dgb_softc[unit];
1995 port=&sc->ports[pnum];
1998 wmask=port->txbufsize-1;
2002 while( tp->t_outq.c_cc!=0 ) {
2004 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2007 if(tp->t_outq.c_cc <= tp->t_lowat) {
2008 if(tp->t_state & TS_ASLEEP) {
2009 tp->t_state &= ~TS_ASLEEP;
2010 wakeup(TSA_OLOWAT(tp));
2012 /*selwakeup(&tp->t_wsel);*/
2018 head=bc->tin & wmask;
2020 do { tail=bc->tout; } while (tail != bc->tout);
2021 tail=bc->tout & wmask;
2023 DPRINT5(DB_WR,"dgb%d: port%d: s tx head=%d tail=%d\n",unit,pnum,head,tail);
2025 #ifdef LEAVE_FREE_CHARS
2027 size=tail-head-LEAVE_FREE_CHARS;
2031 size=port->txbufsize-head;
2032 if(tail+port->txbufsize < head)
2040 size=port->txbufsize-head/*-1*/;
2047 bc->iempty=1; bc->ilow=1;
2050 tp->t_state|=TS_BUSY;
2055 towin(sc,port->txwin);
2057 ocount=q_to_b(&tp->t_outq, __DEVOLATILE(u_char *, port->txptr+head), size);
2059 if(head>=port->txbufsize)
2060 head-=port->txbufsize;
2065 DPRINT5(DB_WR,"dgb%d: port%d: tx avail=%d count=%d\n",unit,pnum,size,ocount);
2073 #ifndef TS_ASLEEP /* post 2.0.5 FreeBSD */
2074 if(tp->t_state & TS_BUSY) {
2075 tp->t_state&=~TS_BUSY;
2076 linesw[tp->t_line].l_start(tp);
2080 if(tp->t_state & TS_ASLEEP) {
2081 tp->t_state &= ~TS_ASLEEP;
2082 wakeup(TSA_OLOWAT(tp));
2084 tp->t_state&=~TS_BUSY;
2096 struct dgb_softc *sc;
2097 volatile struct board_chan *bc;
2100 BoardMemWinState ws=bmws_get();
2102 unit=MINOR_TO_UNIT(minor(tp->t_dev));
2103 pnum=MINOR_TO_PORT(minor(tp->t_dev));
2105 sc=&dgb_softc[unit];
2106 port=&sc->ports[pnum];
2109 DPRINT3(DB_WR,"dgb%d: port%d: stop\n",port->unit, port->pnum);
2115 /* clear output queue */
2117 bc->ilow=0;bc->iempty=0;
2120 /* clear input queue */
2131 fepcmd(port, cmd, op1, op2, ncmds, bytecmd)
2133 unsigned cmd, op1, op2, ncmds, bytecmd;
2135 struct dgb_softc *sc=&dgb_softc[port->unit];
2136 u_char *mem=sc->vmem;
2137 unsigned tail, head;
2140 if(port->status==DISABLED) {
2141 printf("dgb%d: port%d: FEP command on disabled port\n",
2142 port->unit, port->pnum);
2146 /* setwin(sc,0); Require this to be set by caller */
2147 head=sc->mailbox->cin;
2149 if(head>=(FEP_CMAX-FEP_CSTART) || (head & 3)) {
2150 printf("dgb%d: port%d: wrong pointer head of command queue : 0x%x\n",
2151 port->unit, port->pnum, head);
2155 mem[head+FEP_CSTART+0]=cmd;
2156 mem[head+FEP_CSTART+1]=port->pnum;
2158 mem[head+FEP_CSTART+2]=op1;
2159 mem[head+FEP_CSTART+3]=op2;
2161 mem[head+FEP_CSTART+2]=op1&0xff;
2162 mem[head+FEP_CSTART+3]=(op1>>8)&0xff;
2165 DPRINT7(DB_FEP,"dgb%d: port%d: %s cmd=0x%x op1=0x%x op2=0x%x\n", port->unit, port->pnum,
2166 (bytecmd)?"byte":"word", cmd, mem[head+FEP_CSTART+2], mem[head+FEP_CSTART+3]);
2168 head=(head+4) & (FEP_CMAX-FEP_CSTART-4);
2169 sc->mailbox->cin=head;
2173 while (count-- != 0) {
2174 head=sc->mailbox->cin;
2175 tail=sc->mailbox->cout;
2177 n = (head-tail) & (FEP_CMAX-FEP_CSTART-4);
2178 if(n <= ncmds * (sizeof(ushort)*4))
2181 printf("dgb%d(%d): timeout on FEP cmd=0x%x\n", port->unit, port->pnum, cmd);
2189 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2190 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2191 && (!(t->c_iflag & PARMRK)
2192 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2193 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2194 && linesw[tp->t_line].l_rint == ttyinput)
2195 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2197 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;