2 ** -----------------------------------------------------------------------------
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 ** Last Modified : 11/6/98 10:33:47
26 ** Retrieved : 11/6/98 10:33:50
28 ** ident @(#)riotty.c 1.3
30 ** -----------------------------------------------------------------------------
33 static char *_riotty_c_sccs_ = "@(#)riotty.c 1.3";
37 #define __EXPLICIT_DEF_H__
39 #include <linux/module.h>
40 #include <linux/slab.h>
41 #include <linux/errno.h>
42 #include <linux/tty.h>
43 #include <linux/string.h>
45 #include <asm/system.h>
46 #include <asm/string.h>
47 #include <asm/semaphore.h>
48 #include <asm/uaccess.h>
50 #include <linux/termios.h>
52 #include <linux/serial.h>
54 #include <linux/generic_serial.h>
57 #include "linux_compat.h"
58 #include "rio_linux.h"
93 static void ttyseth_pv(struct Port *, struct ttystatics *,
94 struct termios *sg, int);
97 static void RIOClearUp(struct Port *PortP);
98 int RIOShortCommand(struct rio_info *p, struct Port *PortP,
99 int command, int len, int arg);
102 static int RIOCookMode(struct ttystatics *);
105 extern int conv_vb[]; /* now defined in ttymgr.c */
106 extern int conv_bv[]; /* now defined in ttymgr.c */
109 ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support
111 ** ep.def.h is necessary for Modular Kernel Support
112 ** DO NOT place any kernel 'extern's after this line
113 ** or this source file will not build riotty.k.o
120 static struct old_sgttyb
123 B19200, B19200, /* input and output speed */
124 'H' - '@', /* erase char */
125 -1, /* 2nd erase char */
126 'U' - '@', /* kill char */
127 ECHO | CRMOD, /* mode */
128 'C' - '@', /* interrupt character */
129 '\\' - '@', /* quit char */
130 'Q' - '@', /* start char */
131 'S' - '@', /* stop char */
134 (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */
135 'Z' - '@', /* process stop */
136 'Y' - '@', /* delayed stop */
137 'R' - '@', /* reprint line */
138 'O' - '@', /* flush output */
139 'W' - '@', /* word erase */
140 'V' - '@' /* literal next char */
145 extern struct rio_info *p;
149 riotopen(struct tty_struct * tty, struct file * filp)
151 register uint SysPort;
153 int repeat_this = 250;
154 struct Port *PortP; /* pointer to the port structure */
160 /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
163 tty->driver_data = NULL;
165 SysPort = rio_minor(tty);
166 Modem = rio_ismodem(tty);
168 if ( p->RIOFailed ) {
169 rio_dprintk (RIO_DEBUG_TTY, "System initialisation failed\n");
175 rio_dprintk (RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n",
176 SysPort, Modem ? "Modem" : "tty",
177 p->RIOPortp[SysPort]->Mapped);
180 ** Validate that we have received a legitimate request.
181 ** Currently, just check that we are opening a port on
182 ** a host card that actually exists, and that the port
183 ** has been mapped onto a host.
185 if (SysPort >= RIO_PORTS) { /* out of range ? */
186 rio_dprintk (RIO_DEBUG_TTY, "Illegal port number %d\n",SysPort);
193 ** Grab pointer to the port stucture
195 PortP = p->RIOPortp[SysPort]; /* Get control struc */
196 rio_dprintk (RIO_DEBUG_TTY, "PortP: %p\n", PortP);
197 if ( !PortP->Mapped ) { /* we aren't mapped yet! */
199 ** The system doesn't know which RTA this port
202 rio_dprintk (RIO_DEBUG_TTY, "port not mapped into system\n");
208 tty->driver_data = PortP;
213 rio_dprintk (RIO_DEBUG_TTY, "%d bytes in tx buffer\n",
216 retval = gs_init_port (&PortP->gs);
222 ** If the host hasn't been booted yet, then
225 if ( (PortP->HostP->Flags & RUN_STATE) != RC_RUNNING ) {
226 rio_dprintk (RIO_DEBUG_TTY, "Host not running\n");
233 ** If the RTA has not booted yet and the user has choosen to block
234 ** until the RTA is present then we must spin here waiting for
238 if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
239 if (PortP->WaitUntilBooted) {
240 rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
242 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
243 rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
247 if (repeat_this -- <= 0) {
248 rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
249 RIOPreemptiveCmd(p, PortP, FCLOSE );
254 } while(!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
255 rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
257 rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
264 /* I find the above code a bit hairy. I find the below code
265 easier to read and shorter. Now, if it works too that would
268 rio_dprintk (RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
269 while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
270 if (!PortP->WaitUntilBooted) {
271 rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
276 /* Under Linux you'd normally use a wait instead of this
277 busy-waiting. I'll stick with the old implementation for
280 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
281 rio_dprintk (RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
285 if (repeat_this -- <= 0) {
286 rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
291 rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
294 tp = PortP->TtyP; /* get tty struct */
296 rio_spin_lock_irqsave(&PortP->portSem, flags);
297 if ( p->RIOHalted ) {
301 retval = gs_init_port(&PortP->gs);
309 ** If the port is in the final throws of being closed,
310 ** we should wait here (politely), waiting
311 ** for it to finish, so that it doesn't close us!
313 while ( (PortP->State & RIO_CLOSING) && !p->RIOHalted ) {
314 rio_dprintk (RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
315 if (repeat_this -- <= 0) {
316 rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
317 RIOPreemptiveCmd(p, PortP, FCLOSE );
321 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
322 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
323 rio_spin_lock_irqsave(&PortP->portSem, flags);
327 rio_spin_lock_irqsave(&PortP->portSem, flags);
330 if ( !PortP->Mapped ) {
331 rio_dprintk (RIO_DEBUG_TTY, "Port unmapped while closing!\n");
332 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
338 if ( p->RIOHalted ) {
343 ** 15.10.1998 ARG - ESIL 0761 part fix
344 ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,
345 ** we need to make sure that the flags are clear when the port is opened.
347 /* Uh? Suppose I turn these on and then another process opens
348 the port again? The flags get cleared! Not good. -- REW */
349 if ( !(PortP->State & (RIO_LOPEN | RIO_MOPEN)) ) {
350 PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
353 if (!(PortP->firstOpen)) { /* First time ? */
354 rio_dprintk (RIO_DEBUG_TTY, "First open for this port\n");
358 PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
359 PortP->InUse = NOT_INUSE;
361 /* Tentative fix for bug PR27. Didn't work. */
362 /* PortP->gs.xmit_cnt = 0; */
364 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
366 ttyseth(PortP, tp, (struct old_sgttyb *)&default_sg);
369 /* Someone explain to me why this delay/config is
370 here. If I read the docs correctly the "open"
371 command piggybacks the parameters immediately.
373 RIOParam(PortP,OPEN,Modem,OK_TO_SLEEP); /* Open the port */
375 /* This delay of 1 second was annoying. I removed it. -- REW */
376 RIODelay(PortP, HUNDRED_MS*10);
377 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP); /* Config the port */
379 rio_spin_lock_irqsave(&PortP->portSem, flags);
382 ** wait for the port to be not closed.
384 while ( !(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted ) {
385 rio_dprintk (RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n",PortP->PortState);
387 ** 15.10.1998 ARG - ESIL 0759
388 ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
389 ** Take out the limited wait - now wait for ever or until user
392 if (repeat_this -- <= 0) {
393 rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n"));
394 RIOPreemptiveCmd(p, PortP, FCLOSE );
395 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
400 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
401 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
402 rio_dprintk (RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
403 RIOPreemptiveCmd(p, PortP, FCLOSE );
407 rio_spin_lock_irqsave(&PortP->portSem, flags);
410 if ( p->RIOHalted ) {
413 /* RIOClearUp( PortP ); */
414 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
417 rio_dprintk (RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
422 rio_dprintk (RIO_DEBUG_TTY, "Modem - test for carrier\n");
425 ** insert test for carrier here. -- ???
426 ** I already see that test here. What's the deal? -- REW
428 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD))
430 rio_dprintk (RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
432 tp->tm.c_state |= CARR_ON;
433 wakeup((caddr_t) &tp->tm.c_canq);
435 PortP->State |= RIO_CARR_ON;
436 wake_up_interruptible (&PortP->gs.open_wait);
438 else /* no carrier - wait for DCD */
441 while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
442 !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
444 while (!(PortP->State & RIO_CARR_ON) &&
445 !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted ) {
447 rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n",SysPort);
449 PortP->gs.tty->termios->c_state |= WOPEN;
451 PortP->State |= RIO_WOPEN;
452 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
453 if (RIODelay (PortP, HUNDRED_MS) == RIO_FAIL)
455 if ( sleep((caddr_t)&tp->tm.c_canqo, TTIPRI|PCATCH))
459 ** ACTION: verify that this is a good thing
460 ** to do here. -- ???
461 ** I think it's OK. -- REW
463 rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n",
465 RIOPreemptiveCmd( p, PortP, FCLOSE );
467 tp->tm.c_state &= ~WOPEN;
469 PortP->State &= ~RIO_WOPEN;
470 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
475 PortP->State &= ~RIO_WOPEN;
479 rio_dprintk (RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
480 PortP->State |= RIO_MOPEN;
487 ** Direct line open - force carrier (will probably mean
488 ** that sleeping Modem line fubar)
490 PortP->State |= RIO_LOPEN;
493 if ( p->RIOHalted ) {
497 rio_dprintk (RIO_DEBUG_TTY, "high level open done\n");
500 PortP->Stat.OpenCnt++;
503 ** Count opens for port statistics reporting
505 if (PortP->statsGather)
508 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
509 rio_dprintk (RIO_DEBUG_TTY, "Returning from open\n");
515 ** RIOClose the port.
516 ** The operating system thinks that this is last close for the device.
517 ** As there are two interfaces to the port (Modem and tty), we need to
518 ** check that both are closed before we close the device.
524 register uint SysPort = dev;
525 struct ttystatics *tp; /* pointer to our ttystruct */
527 struct Port *PortP = ptr; /* pointer to the port structure */
529 int try = -1; /* Disable the timeouts by setting them to -1 */
530 int repeat_this = -1; /* Congrats to those having 15 years of
531 uptime! (You get to break the driver.) */
532 unsigned long end_time;
533 struct tty_struct * tty;
538 rio_dprintk (RIO_DEBUG_TTY, "port close SysPort %d\n",PortP->PortNum);
540 /* PortP = p->RIOPortp[SysPort]; */
541 rio_dprintk (RIO_DEBUG_TTY, "Port is at address 0x%x\n",(int)PortP);
542 /* tp = PortP->TtyP;*/ /* Get tty */
544 rio_dprintk (RIO_DEBUG_TTY, "TTY is at address 0x%x\n",(int)tty);
546 if (PortP->gs.closing_wait)
547 end_time = jiffies + PortP->gs.closing_wait;
549 end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
551 Modem = rio_ismodem(tty);
553 /* What F.CKING cache? Even then, a higly idle multiprocessor,
554 system with large caches this won't work . Better find out when
555 this doesn't work asap, and fix the cause. -- REW */
557 RIODelay(PortP, HUNDRED_MS*10); /* To flush the cache */
559 rio_spin_lock_irqsave(&PortP->portSem, flags);
562 ** Setting this flag will make any process trying to open
563 ** this port block until we are complete closing it.
565 PortP->State |= RIO_CLOSING;
567 if ( (PortP->State & RIO_DELETED) ) {
568 rio_dprintk (RIO_DEBUG_TTY, "Close on deleted RTA\n");
572 if ( p->RIOHalted ) {
578 rio_dprintk (RIO_DEBUG_TTY, "Clear bits\n");
580 ** clear the open bits for this device
582 PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
583 PortP->State &= ~RIO_CARR_ON;
584 PortP->ModemState &= ~MSVR1_CD;
586 ** If the device was open as both a Modem and a tty line
587 ** then we need to wimp out here, as the port has not really
588 ** been finally closed (gee, whizz!) The test here uses the
589 ** bit for the OTHER mode of operation, to see if THAT is
592 if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
594 ** The port is still open for the other task -
595 ** return, pretending that we are still active.
597 rio_dprintk (RIO_DEBUG_TTY, "Channel %d still open !\n",PortP->PortNum);
598 PortP->State &= ~RIO_CLOSING;
599 if (PortP->firstOpen)
601 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
605 rio_dprintk (RIO_DEBUG_TTY, "Closing down - everything must go!\n");
607 PortP->State &= ~RIO_DYNOROD;
610 ** This is where we wait for the port
611 ** to drain down before closing. Bye-bye....
612 ** (We never meant to do this)
614 rio_dprintk (RIO_DEBUG_TTY, "Timeout 1 starts\n");
617 while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted &&
618 (PortP->TxBufferIn != PortP->TxBufferOut) ) {
619 cprintf("Need to flush the ttyport\n");
620 if (repeat_this -- <= 0) {
622 rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
623 RIOPreemptiveCmd(p, PortP, FCLOSE);
626 rio_dprintk (RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
627 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
628 if (RIODelay_ni(PortP, HUNDRED_MS*10) == RIO_FAIL) {
629 rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
631 rio_spin_lock_irqsave(&PortP->portSem, flags);
634 rio_spin_lock_irqsave(&PortP->portSem, flags);
637 PortP->TxBufferIn = PortP->TxBufferOut = 0;
641 if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
643 ** The port has been re-opened for the other task -
644 ** return, pretending that we are still active.
646 rio_dprintk (RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
647 PortP->State &= ~RIO_CLOSING;
648 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
649 if (PortP->firstOpen)
654 if ( p->RIOHalted ) {
659 /* Can't call RIOShortCommand with the port locked. */
660 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
662 if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) {
663 RIOPreemptiveCmd(p, PortP, FCLOSE);
668 while (try && (PortP->PortState & PORT_ISOPEN)) {
670 if (time_after (jiffies, end_time)) {
671 rio_dprintk (RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n" );
672 RIOPreemptiveCmd(p, PortP,FCLOSE);
675 rio_dprintk (RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n",
676 PortP->PortState & PORT_ISOPEN);
678 if ( p->RIOHalted ) {
682 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
683 rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
684 RIOPreemptiveCmd(p, PortP,FCLOSE);
688 rio_spin_lock_irqsave(&PortP->portSem, flags);
689 rio_dprintk (RIO_DEBUG_TTY, "Close: try was %d on completion\n", try );
691 /* RIOPreemptiveCmd(p, PortP, FCLOSE); */
694 ** 15.10.1998 ARG - ESIL 0761 part fix
695 ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,** we need to make sure that the flags are clear when the port is opened.
697 PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
700 PortP->Stat.CloseCnt++;
703 ** Count opens for port statistics reporting
705 if (PortP->statsGather)
709 /* XXX: Why would a "DELETED" flag be reset here? I'd have
710 thought that a "deleted" flag means that the port was
711 permanently gone, but here we can make it reappear by it
712 being in close during the "deletion".
714 PortP->State &= ~(RIO_CLOSING|RIO_DELETED);
715 if (PortP->firstOpen)
717 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
718 rio_dprintk (RIO_DEBUG_TTY, "Return from close\n");
724 ** decide if we need to use the line discipline.
725 ** This routine can return one of three values:
726 ** COOK_RAW if no processing has to be done by the line discipline or the card
727 ** COOK_WELL if the line discipline must be used to do the processing
728 ** COOK_MEDIUM if the card can do all the processing necessary.
732 RIOCookMode(struct ttystatics *tp)
735 ** We can't handle tm.c_mstate != 0 on SCO
736 ** We can't handle mapping
737 ** We can't handle non-ttwrite line disc.
738 ** We can't handle lflag XCASE
739 ** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3)
745 if (!(tp->tm.c_oflag & OPOST)) /* No post processing */
746 return COOK_RAW; /* Raw mode o/p */
748 if ( tp->tm.c_lflag & XCASE )
749 return COOK_WELL; /* Use line disc */
751 if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3 ) )
752 return COOK_WELL; /* Use line disc for strange modes */
754 if ( tp->tm.c_oflag == OPOST ) /* If only OPOST is set, do RAW */
758 ** So, we need to output process!
768 rio_dprintk (RIO_DEBUG_TTY, "RIOHalted set\n");
769 PortP->Config = 0; /* Direct semaphore */
770 PortP->PortState = 0;
771 PortP->firstOpen = 0;
772 PortP->FlushCmdBodge = 0;
773 PortP->ModemState = PortP->CookMode = 0;
775 PortP->WflushFlag = 0;
776 PortP->MagicFlags = 0;
777 PortP->RxDataStart = 0;
778 PortP->TxBufferIn = 0;
779 PortP->TxBufferOut = 0;
783 ** Put a command onto a port.
784 ** The PortPointer, command, length and arg are passed.
785 ** The len is the length *inclusive* of the command byte,
786 ** and so for a command that takes no data, len==1.
787 ** The arg is a single byte, and is only used if len==2.
788 ** Other values of len aren't allowed, and will cause
791 int RIOShortCommand(struct rio_info *p, struct Port *PortP,
792 int command, int len, int arg)
795 int retries = 20; /* at 10 per second -> 2 seconds */
798 rio_dprintk (RIO_DEBUG_TTY, "entering shortcommand.\n");
801 if ( len < 1 || len > 2 )
802 cprintf(("STUPID LENGTH %d\n",len));
805 if ( PortP->State & RIO_DELETED ) {
806 rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
809 rio_spin_lock_irqsave(&PortP->portSem, flags);
812 ** If the port is in use for pre-emptive command, then wait for it to
815 while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted ) {
816 rio_dprintk (RIO_DEBUG_TTY, "Waiting for not in use (%d)\n",
818 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
819 if (retries-- <= 0) {
822 if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
825 rio_spin_lock_irqsave(&PortP->portSem, flags);
827 if ( PortP->State & RIO_DELETED ) {
828 rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
829 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
833 while ( !can_add_transmit(&PacketP,PortP) && !p->RIOHalted ) {
834 rio_dprintk (RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
835 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
836 if (retries-- <= 0) {
837 rio_dprintk (RIO_DEBUG_TTY, "out of tries. Failing\n");
840 if ( RIODelay_ni(PortP, HUNDRED_MS)==RIO_FAIL ) {
843 rio_spin_lock_irqsave(&PortP->portSem, flags);
846 if ( p->RIOHalted ) {
847 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
852 ** set the command byte and the argument byte
854 WBYTE(PacketP->data[0] , command);
857 WBYTE(PacketP->data[1] , arg);
860 ** set the length of the packet and set the command bit.
862 WBYTE(PacketP->len , PKT_CMD_BIT | len);
866 ** Count characters transmitted for port statistics reporting
868 if (PortP->statsGather)
869 PortP->txchars += len;
871 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
872 return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL;
878 ** This is an ioctl interface. This is the twentieth century. You know what
882 riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
884 register struct Port *PortP;
885 register struct ttystatics *tp;
887 int ParamSemIncremented = 0;
888 int old_oflag, old_cflag, old_iflag, changed, oldcook;
890 unsigned char sio_regs[5]; /* Here be magic */
894 uint SysPort = rio_minor(tty);
895 int Modem = rio_ismodem(tty);
898 rio_dprintk (RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n",
899 SysPort, cmd, arg, Modem?"Modem":"tty") ;
901 if ( SysPort >= RIO_PORTS ) {
902 rio_dprintk (RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
906 PortP = p->RIOPortp[SysPort];
909 rio_spin_lock_irqsave(&PortP->portSem, flags);
912 PortP->Stat.IoctlCnt++;
915 if ( PortP->State & RIO_DELETED ) {
916 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
921 if ( p->RIOHalted ) {
923 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
928 ** Count ioctls for port statistics reporting
930 if (PortP->statsGather)
934 ** Specialix RIO Ioctl calls
940 PortP->State |= RIO_TRIAD_MODE;
942 PortP->State &= ~RIO_TRIAD_MODE;
944 ** Normally, when istrip is set on a port, a config is
945 ** sent to the RTA instructing the CD1400 to do the
946 ** stripping. In TRIAD mode, the interrupt receive routine
947 ** must do the stripping instead, since it has to detect
948 ** an 8 bit function key sequence. If istrip is set with
949 ** TRIAD mode on(off), and 8 bit data is being read by
950 ** the port, the user then turns TRIAD mode off(on), the RTA
951 ** must be reconfigured (not) to do the stripping.
952 ** Hence we call RIOParam here.
954 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
955 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
959 rio_dprintk (RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n",
961 /* MonitorTstate = 0 ;*/
962 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
963 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
966 case TCRIOSTATE: /* current state of Modem input pins */
967 rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE\n");
968 if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL)
969 rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE command failed\n");
970 PortP->State |= RIO_BUSY;
971 current = PortP->ModemState;
972 if ( copyout((caddr_t)¤t, (int)arg,
973 sizeof(current))==COPYFAIL ) {
974 rio_dprintk (RIO_DEBUG_TTY, "Copyout failed\n");
975 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
978 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
981 case TCRIOMBIS: /* Set modem lines */
982 case TCRIOMBIC: /* Clear modem lines */
983 rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n");
984 if (cmd == TCRIOMBIS) {
987 PortP->ModemState |= (ushort)state;
988 PortP->ModemLines = (ulong) arg;
989 if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL)
990 rio_dprintk (RIO_DEBUG_TTY,
991 "TCRIOMBIS command failed\n");
997 PortP->ModemState &= ~(ushort)state;
998 PortP->ModemLines = (ulong) arg;
999 if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL)
1000 rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIC command failed\n");
1002 PortP->State |= RIO_BUSY;
1003 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1006 case TCRIOXPON: /* set Xprint ON string */
1007 rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPON\n");
1008 if ( copyin((int)arg, (caddr_t)PortP->Xprint.XpOn,
1009 MAX_XP_CTRL_LEN)==COPYFAIL ) {
1010 rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
1011 PortP->Xprint.XpOn[0] = '\0';
1012 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1015 PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
1016 PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
1017 strlen(PortP->Xprint.XpOff);
1018 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1021 case TCRIOXPOFF: /* set Xprint OFF string */
1022 rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPOFF\n");
1023 if ( copyin( (int)arg, (caddr_t)PortP->Xprint.XpOff,
1024 MAX_XP_CTRL_LEN)==COPYFAIL ) {
1025 rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
1026 PortP->Xprint.XpOff[0] = '\0';
1027 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1030 PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
1031 PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
1032 strlen(PortP->Xprint.XpOff);
1033 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1036 case TCRIOXPCPS: /* set Xprint CPS string */
1037 rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPCPS\n");
1038 if ( (uint)arg > p->RIOConf.MaxXpCps ||
1039 (uint)arg < p->RIOConf.MinXpCps ) {
1040 rio_dprintk (RIO_DEBUG_TTY, "%d CPS out of range\n",arg);
1041 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1045 PortP->Xprint.XpCps = (uint)arg;
1046 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1050 rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPRINT\n");
1051 if ( copyout((caddr_t)&PortP->Xprint, (int)arg,
1052 sizeof(struct Xprint))==COPYFAIL ) {
1053 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1056 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1060 rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYON\n");
1061 PortP->Config |= RIO_IXANY;
1062 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1066 rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYOFF\n");
1067 PortP->Config &= ~RIO_IXANY;
1068 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1072 rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONON\n");
1073 PortP->Config |= RIO_IXON;
1074 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1078 rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONOFF\n");
1079 PortP->Config &= ~RIO_IXON;
1080 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1084 ** 15.10.1998 ARG - ESIL 0761 part fix
1085 ** Added support for CTS and RTS flow control ioctls :
1087 case TCRIOCTSFLOWEN:
1088 rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n");
1089 PortP->Config |= RIO_CTSFLOW;
1090 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1091 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
1094 case TCRIOCTSFLOWDIS:
1095 rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n");
1096 PortP->Config &= ~RIO_CTSFLOW;
1097 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1098 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
1101 case TCRIORTSFLOWEN:
1102 rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n");
1103 PortP->Config |= RIO_RTSFLOW;
1104 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1105 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
1108 case TCRIORTSFLOWDIS:
1109 rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n");
1110 PortP->Config &= ~RIO_RTSFLOW;
1111 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1112 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
1115 /* end ESIL 0761 part fix */
1127 ttyseth(PortP, tp, (struct old_sgttyb *)arg);
1133 rio_dprintk (RIO_DEBUG_TTY, "NON POSIX ioctl\n");
1134 ttyseth_pv(PortP, tp, (struct termios *)arg, 0);
1136 case TCSETAP: /* posix tcsetattr() */
1137 case TCSETAWP: /* posix tcsetattr() */
1138 case TCSETAFP: /* posix tcsetattr() */
1139 rio_dprintk (RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n");
1140 ttyseth_pv(PortP, tp, (struct termios *)arg, 1);
1146 ** If its any of the commands that require the port to be in the
1147 ** non-busy state wait until all output has drained
1149 if (!ioctl_processed)
1155 #define OLD_POSIX ('x' << 8)
1156 #define OLD_POSIX_SETA (OLD_POSIX | 2)
1157 #define OLD_POSIX_SETAW (OLD_POSIX | 3)
1158 #define OLD_POSIX_SETAF (OLD_POSIX | 4)
1159 #define NEW_POSIX (('i' << 24) | ('X' << 16))
1160 #define NEW_POSIX_SETA (NEW_POSIX | 2)
1161 #define NEW_POSIX_SETAW (NEW_POSIX | 3)
1162 #define NEW_POSIX_SETAF (NEW_POSIX | 4)
1163 case OLD_POSIX_SETA:
1164 case OLD_POSIX_SETAW:
1165 case OLD_POSIX_SETAF:
1166 case NEW_POSIX_SETA:
1167 case NEW_POSIX_SETAW:
1168 case NEW_POSIX_SETAF:
1174 rio_dprintk (RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
1176 ** Wait for drain here, at least as far as the double buffer
1179 /* XXX Does the above comment mean that this has
1180 still to be implemented? -- REW */
1181 /* XXX Is the locking OK together with locking
1182 in txenable? (Deadlock?) -- REW */
1184 RIOTxEnable((char *)PortP);
1190 old_cflag = tp->tm.c_cflag;
1191 old_iflag = tp->tm.c_iflag;
1192 old_oflag = tp->tm.c_oflag;
1193 oldcook = PortP->CookMode;
1195 if ( p->RIOHalted ) {
1196 RIOClearUp( PortP );
1197 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1202 PortP->FlushCmdBodge = 0;
1205 ** If the port is locked, and it is reconfigured, we want
1206 ** to restore the state of the tty structure so the change is NOT
1210 tp->tm.c_iflag = PortP->StoredTty.iflag;
1211 tp->tm.c_oflag = PortP->StoredTty.oflag;
1212 tp->tm.c_cflag = PortP->StoredTty.cflag;
1213 tp->tm.c_lflag = PortP->StoredTty.lflag;
1214 tp->tm.c_line = PortP->StoredTty.line;
1215 for (i = 0; i < NCC + 1; i++)
1216 tp->tm.c_cc[i] = PortP->StoredTty.cc[i];
1220 ** If the port is set to store the parameters, and it is
1221 ** reconfigured, we want to save the current tty struct so it
1222 ** may be restored on the next open.
1225 PortP->StoredTty.iflag = tp->tm.c_iflag;
1226 PortP->StoredTty.oflag = tp->tm.c_oflag;
1227 PortP->StoredTty.cflag = tp->tm.c_cflag;
1228 PortP->StoredTty.lflag = tp->tm.c_lflag;
1229 PortP->StoredTty.line = tp->tm.c_line;
1230 for (i = 0; i < NCC + 1; i++)
1231 PortP->StoredTty.cc[i] = tp->tm.c_cc[i];
1235 changed = (tp->tm.c_cflag != old_cflag) ||
1236 (tp->tm.c_iflag != old_iflag) ||
1237 (tp->tm.c_oflag != old_oflag);
1239 PortP->CookMode = RIOCookMode(tp); /* Set new cooking mode */
1241 rio_dprintk (RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n",
1242 changed,PortP->CookMode,oldcook);
1244 #ifdef MODEM_SUPPORT
1246 ** kludge to force CARR_ON if CLOCAL set
1248 if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
1249 tp->tm.c_state |= CARR_ON;
1250 wakeup ((caddr_t)&tp->tm.c_canq);
1254 if ( p->RIOHalted ) {
1255 RIOClearUp( PortP );
1256 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1261 ** Re-configure if modes or cooking have changed
1263 if (changed || oldcook != PortP->CookMode || (ioctl_processed)) {
1264 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1265 rio_dprintk (RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
1266 RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
1267 rio_spin_lock_irqsave(&PortP->portSem, flags);
1271 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1272 RIOClearUp( PortP );
1276 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1281 ttyseth -- set hardware dependent tty settings
1284 ttyseth(PortP, s, sg)
1285 struct Port * PortP;
1286 struct ttystatics * s;
1287 struct old_sgttyb *sg;
1289 struct old_sgttyb * tsg;
1290 struct termios *tp = &s->tm;
1294 if (sg->sg_flags & (EVENP|ODDP)) {
1295 tp->c_cflag &= PARENB;
1296 if (sg->sg_flags & EVENP) {
1297 if (sg->sg_flags & ODDP) {
1298 tp->c_cflag &= V_CS7;
1299 tp->c_cflag &= ~PARENB;
1302 tp->c_cflag &= V_CS7;
1303 tp->c_cflag &= PARENB;
1304 tp->c_cflag &= PARODD;
1307 else if (sg->sg_flags & ODDP) {
1308 tp->c_cflag &= V_CS7;
1309 tp->c_cflag &= PARENB;
1310 tp->c_cflag &= PARODD;
1313 tp->c_cflag &= V_CS7;
1314 tp->c_cflag &= PARENB;
1318 * Use ispeed as the desired speed. Most implementations don't handle
1319 * separate input and output speeds very well. If the RIO handles this,
1320 * I will have to use separate sets of flags to store them in the
1323 if ( !sg->sg_ospeed )
1324 sg->sg_ospeed = sg->sg_ispeed;
1326 sg->sg_ispeed = sg->sg_ospeed;
1327 if (sg->sg_ispeed > V_EXTB )
1328 sg->sg_ispeed = V_EXTB;
1329 if (sg->sg_ispeed < V_B0)
1330 sg->sg_ispeed = V_B0;
1332 tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int)sg->sg_ispeed];
1336 ttyseth_pv -- set hardware dependent tty settings using either the
1337 POSIX termios structure or the System V termio structure.
1338 sysv = 0 => (POSIX): struct termios *sg
1339 sysv != 0 => (System V): struct termio *sg
1342 ttyseth_pv(PortP, s, sg, sysv)
1344 struct ttystatics *s;
1349 unsigned char csize;
1350 unsigned char cread;
1351 unsigned int lcr_flags;
1355 /* sg points to a System V termio structure */
1356 csize = ((struct termio *)sg)->c_cflag & CSIZE;
1357 cread = ((struct termio *)sg)->c_cflag & CREAD;
1358 speed = conv_vb[((struct termio *)sg)->c_cflag & V_CBAUD];
1361 /* sg points to a POSIX termios structure */
1362 csize = sg->c_cflag & CSIZE;
1363 cread = sg->c_cflag & CREAD;
1364 speed = conv_vb[sg->c_cflag & V_CBAUD];
1366 if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) {
1367 s->sg.sg_ispeed = speed;
1368 s->sg.sg_ospeed = speed;
1369 s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) |
1370 conv_bv[(int)s->sg.sg_ispeed];