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 *, struct termios *sg, int);
96 static void RIOClearUp(struct Port *PortP);
97 int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
100 static int RIOCookMode(struct ttystatics *);
103 extern int conv_vb[]; /* now defined in ttymgr.c */
104 extern int conv_bv[]; /* now defined in ttymgr.c */
107 ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support
109 ** ep.def.h is necessary for Modular Kernel Support
110 ** DO NOT place any kernel 'extern's after this line
111 ** or this source file will not build riotty.k.o
118 static struct old_sgttyb default_sg = {
119 B19200, B19200, /* input and output speed */
120 'H' - '@', /* erase char */
121 -1, /* 2nd erase char */
122 'U' - '@', /* kill char */
123 ECHO | CRMOD, /* mode */
124 'C' - '@', /* interrupt character */
125 '\\' - '@', /* quit char */
126 'Q' - '@', /* start char */
127 'S' - '@', /* stop char */
130 (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */
131 'Z' - '@', /* process stop */
132 'Y' - '@', /* delayed stop */
133 'R' - '@', /* reprint line */
134 'O' - '@', /* flush output */
135 'W' - '@', /* word erase */
136 'V' - '@' /* literal next char */
141 extern struct rio_info *p;
144 int riotopen(struct tty_struct *tty, struct file *filp)
146 register uint SysPort;
148 int repeat_this = 250;
149 struct Port *PortP; /* pointer to the port structure */
155 /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
158 tty->driver_data = NULL;
160 SysPort = rio_minor(tty);
161 Modem = rio_ismodem(tty);
164 rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n");
170 rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n", SysPort, Modem ? "Modem" : "tty", p->RIOPortp[SysPort]->Mapped);
173 ** Validate that we have received a legitimate request.
174 ** Currently, just check that we are opening a port on
175 ** a host card that actually exists, and that the port
176 ** has been mapped onto a host.
178 if (SysPort >= RIO_PORTS) { /* out of range ? */
179 rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort);
186 ** Grab pointer to the port stucture
188 PortP = p->RIOPortp[SysPort]; /* Get control struc */
189 rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP);
190 if (!PortP->Mapped) { /* we aren't mapped yet! */
192 ** The system doesn't know which RTA this port
195 rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n");
201 tty->driver_data = PortP;
206 rio_dprintk(RIO_DEBUG_TTY, "%d bytes in tx buffer\n", PortP->gs.xmit_cnt);
208 retval = gs_init_port(&PortP->gs);
214 ** If the host hasn't been booted yet, then
217 if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) {
218 rio_dprintk(RIO_DEBUG_TTY, "Host not running\n");
225 ** If the RTA has not booted yet and the user has choosen to block
226 ** until the RTA is present then we must spin here waiting for
230 if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
231 if (PortP->WaitUntilBooted) {
232 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
234 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
235 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
239 if (repeat_this-- <= 0) {
240 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
241 RIOPreemptiveCmd(p, PortP, FCLOSE);
246 } while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
247 rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
249 rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
256 /* I find the above code a bit hairy. I find the below code
257 easier to read and shorter. Now, if it works too that would
260 rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
261 while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
262 if (!PortP->WaitUntilBooted) {
263 rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
268 /* Under Linux you'd normally use a wait instead of this
269 busy-waiting. I'll stick with the old implementation for
272 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
273 rio_dprintk(RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
277 if (repeat_this-- <= 0) {
278 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
283 rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
286 tp = PortP->TtyP; /* get tty struct */
288 rio_spin_lock_irqsave(&PortP->portSem, flags);
293 retval = gs_init_port(&PortP->gs);
301 ** If the port is in the final throws of being closed,
302 ** we should wait here (politely), waiting
303 ** for it to finish, so that it doesn't close us!
305 while ((PortP->State & RIO_CLOSING) && !p->RIOHalted) {
306 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
307 if (repeat_this-- <= 0) {
308 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
309 RIOPreemptiveCmd(p, PortP, FCLOSE);
313 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
314 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
315 rio_spin_lock_irqsave(&PortP->portSem, flags);
319 rio_spin_lock_irqsave(&PortP->portSem, flags);
322 if (!PortP->Mapped) {
323 rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n");
324 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
335 ** 15.10.1998 ARG - ESIL 0761 part fix
336 ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,
337 ** we need to make sure that the flags are clear when the port is opened.
339 /* Uh? Suppose I turn these on and then another process opens
340 the port again? The flags get cleared! Not good. -- REW */
341 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
342 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
345 if (!(PortP->firstOpen)) { /* First time ? */
346 rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n");
350 PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
351 PortP->InUse = NOT_INUSE;
353 /* Tentative fix for bug PR27. Didn't work. */
354 /* PortP->gs.xmit_cnt = 0; */
356 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
358 ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg);
361 /* Someone explain to me why this delay/config is
362 here. If I read the docs correctly the "open"
363 command piggybacks the parameters immediately.
365 RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP); /* Open the port */
367 /* This delay of 1 second was annoying. I removed it. -- REW */
368 RIODelay(PortP, HUNDRED_MS * 10);
369 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); /* Config the port */
371 rio_spin_lock_irqsave(&PortP->portSem, flags);
374 ** wait for the port to be not closed.
376 while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) {
377 rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState);
379 ** 15.10.1998 ARG - ESIL 0759
380 ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
381 ** Take out the limited wait - now wait for ever or until user
384 if (repeat_this -- <= 0) {
385 rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n"));
386 RIOPreemptiveCmd(p, PortP, FCLOSE );
387 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
392 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
393 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
394 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
395 RIOPreemptiveCmd(p, PortP, FCLOSE);
399 rio_spin_lock_irqsave(&PortP->portSem, flags);
405 /* RIOClearUp( PortP ); */
406 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
409 rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
413 rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n");
416 ** insert test for carrier here. -- ???
417 ** I already see that test here. What's the deal? -- REW
419 if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
420 rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
422 tp->tm.c_state |= CARR_ON;
423 wakeup((caddr_t) &tp->tm.c_canq);
425 PortP->State |= RIO_CARR_ON;
426 wake_up_interruptible(&PortP->gs.open_wait);
427 } else { /* no carrier - wait for DCD */
430 while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
431 !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
433 while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) {
435 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort);
437 PortP->gs.tty->termios->c_state |= WOPEN;
439 PortP->State |= RIO_WOPEN;
440 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
441 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL)
443 if (sleep((caddr_t) & tp->tm.c_canqo, TTIPRI | PCATCH))
447 ** ACTION: verify that this is a good thing
448 ** to do here. -- ???
449 ** I think it's OK. -- REW
451 rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
452 RIOPreemptiveCmd(p, PortP, FCLOSE);
454 tp->tm.c_state &= ~WOPEN;
456 PortP->State &= ~RIO_WOPEN;
457 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
462 PortP->State &= ~RIO_WOPEN;
466 rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
467 PortP->State |= RIO_MOPEN;
473 ** Direct line open - force carrier (will probably mean
474 ** that sleeping Modem line fubar)
476 PortP->State |= RIO_LOPEN;
483 rio_dprintk(RIO_DEBUG_TTY, "high level open done\n");
486 PortP->Stat.OpenCnt++;
489 ** Count opens for port statistics reporting
491 if (PortP->statsGather)
494 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
495 rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n");
501 ** RIOClose the port.
502 ** The operating system thinks that this is last close for the device.
503 ** As there are two interfaces to the port (Modem and tty), we need to
504 ** check that both are closed before we close the device.
506 int riotclose(void *ptr)
509 register uint SysPort = dev;
510 struct ttystatics *tp; /* pointer to our ttystruct */
512 struct Port *PortP = ptr; /* pointer to the port structure */
514 int try = -1; /* Disable the timeouts by setting them to -1 */
515 int repeat_this = -1; /* Congrats to those having 15 years of
516 uptime! (You get to break the driver.) */
517 unsigned long end_time;
518 struct tty_struct *tty;
523 rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum);
525 /* PortP = p->RIOPortp[SysPort]; */
526 rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%x\n", (int) PortP);
527 /* tp = PortP->TtyP; *//* Get tty */
529 rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%x\n", (int) tty);
531 if (PortP->gs.closing_wait)
532 end_time = jiffies + PortP->gs.closing_wait;
534 end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
536 Modem = rio_ismodem(tty);
538 /* What F.CKING cache? Even then, a higly idle multiprocessor,
539 system with large caches this won't work . Better find out when
540 this doesn't work asap, and fix the cause. -- REW */
542 RIODelay(PortP, HUNDRED_MS * 10); /* To flush the cache */
544 rio_spin_lock_irqsave(&PortP->portSem, flags);
547 ** Setting this flag will make any process trying to open
548 ** this port block until we are complete closing it.
550 PortP->State |= RIO_CLOSING;
552 if ((PortP->State & RIO_DELETED)) {
553 rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n");
563 rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n");
565 ** clear the open bits for this device
567 PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
568 PortP->State &= ~RIO_CARR_ON;
569 PortP->ModemState &= ~MSVR1_CD;
571 ** If the device was open as both a Modem and a tty line
572 ** then we need to wimp out here, as the port has not really
573 ** been finally closed (gee, whizz!) The test here uses the
574 ** bit for the OTHER mode of operation, to see if THAT is
577 if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
579 ** The port is still open for the other task -
580 ** return, pretending that we are still active.
582 rio_dprintk(RIO_DEBUG_TTY, "Channel %d still open !\n", PortP->PortNum);
583 PortP->State &= ~RIO_CLOSING;
584 if (PortP->firstOpen)
586 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
590 rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n");
592 PortP->State &= ~RIO_DYNOROD;
595 ** This is where we wait for the port
596 ** to drain down before closing. Bye-bye....
597 ** (We never meant to do this)
599 rio_dprintk(RIO_DEBUG_TTY, "Timeout 1 starts\n");
602 while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) {
603 cprintf("Need to flush the ttyport\n");
604 if (repeat_this-- <= 0) {
606 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
607 RIOPreemptiveCmd(p, PortP, FCLOSE);
610 rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
611 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
612 if (RIODelay_ni(PortP, HUNDRED_MS * 10) == RIO_FAIL) {
613 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
615 rio_spin_lock_irqsave(&PortP->portSem, flags);
618 rio_spin_lock_irqsave(&PortP->portSem, flags);
621 PortP->TxBufferIn = PortP->TxBufferOut = 0;
625 if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
627 ** The port has been re-opened for the other task -
628 ** return, pretending that we are still active.
630 rio_dprintk(RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
631 PortP->State &= ~RIO_CLOSING;
632 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
633 if (PortP->firstOpen)
643 /* Can't call RIOShortCommand with the port locked. */
644 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
646 if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) {
647 RIOPreemptiveCmd(p, PortP, FCLOSE);
652 while (try && (PortP->PortState & PORT_ISOPEN)) {
654 if (time_after(jiffies, end_time)) {
655 rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n");
656 RIOPreemptiveCmd(p, PortP, FCLOSE);
659 rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN);
665 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
666 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
667 RIOPreemptiveCmd(p, PortP, FCLOSE);
671 rio_spin_lock_irqsave(&PortP->portSem, flags);
672 rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try);
674 /* RIOPreemptiveCmd(p, PortP, FCLOSE); */
677 ** 15.10.1998 ARG - ESIL 0761 part fix
678 ** 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.
680 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
683 PortP->Stat.CloseCnt++;
686 ** Count opens for port statistics reporting
688 if (PortP->statsGather)
692 /* XXX: Why would a "DELETED" flag be reset here? I'd have
693 thought that a "deleted" flag means that the port was
694 permanently gone, but here we can make it reappear by it
695 being in close during the "deletion".
697 PortP->State &= ~(RIO_CLOSING | RIO_DELETED);
698 if (PortP->firstOpen)
700 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
701 rio_dprintk(RIO_DEBUG_TTY, "Return from close\n");
707 ** decide if we need to use the line discipline.
708 ** This routine can return one of three values:
709 ** COOK_RAW if no processing has to be done by the line discipline or the card
710 ** COOK_WELL if the line discipline must be used to do the processing
711 ** COOK_MEDIUM if the card can do all the processing necessary.
714 static int RIOCookMode(struct ttystatics *tp)
717 ** We can't handle tm.c_mstate != 0 on SCO
718 ** We can't handle mapping
719 ** We can't handle non-ttwrite line disc.
720 ** We can't handle lflag XCASE
721 ** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3)
727 if (!(tp->tm.c_oflag & OPOST)) /* No post processing */
728 return COOK_RAW; /* Raw mode o/p */
730 if (tp->tm.c_lflag & XCASE)
731 return COOK_WELL; /* Use line disc */
733 if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3))
734 return COOK_WELL; /* Use line disc for strange modes */
736 if (tp->tm.c_oflag == OPOST) /* If only OPOST is set, do RAW */
740 ** So, we need to output process!
746 static void RIOClearUp(PortP)
749 rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n");
750 PortP->Config = 0; /* Direct semaphore */
751 PortP->PortState = 0;
752 PortP->firstOpen = 0;
753 PortP->FlushCmdBodge = 0;
754 PortP->ModemState = PortP->CookMode = 0;
756 PortP->WflushFlag = 0;
757 PortP->MagicFlags = 0;
758 PortP->RxDataStart = 0;
759 PortP->TxBufferIn = 0;
760 PortP->TxBufferOut = 0;
764 ** Put a command onto a port.
765 ** The PortPointer, command, length and arg are passed.
766 ** The len is the length *inclusive* of the command byte,
767 ** and so for a command that takes no data, len==1.
768 ** The arg is a single byte, and is only used if len==2.
769 ** Other values of len aren't allowed, and will cause
772 int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg)
775 int retries = 20; /* at 10 per second -> 2 seconds */
778 rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n");
781 if (len < 1 || len > 2)
782 cprintf(("STUPID LENGTH %d\n", len));
785 if (PortP->State & RIO_DELETED) {
786 rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
789 rio_spin_lock_irqsave(&PortP->portSem, flags);
792 ** If the port is in use for pre-emptive command, then wait for it to
795 while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted) {
796 rio_dprintk(RIO_DEBUG_TTY, "Waiting for not in use (%d)\n", retries);
797 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
798 if (retries-- <= 0) {
801 if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
804 rio_spin_lock_irqsave(&PortP->portSem, flags);
806 if (PortP->State & RIO_DELETED) {
807 rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
808 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
812 while (!can_add_transmit(&PacketP, PortP) && !p->RIOHalted) {
813 rio_dprintk(RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
814 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
815 if (retries-- <= 0) {
816 rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n");
819 if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
822 rio_spin_lock_irqsave(&PortP->portSem, flags);
826 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
831 ** set the command byte and the argument byte
833 WBYTE(PacketP->data[0], command);
836 WBYTE(PacketP->data[1], arg);
839 ** set the length of the packet and set the command bit.
841 WBYTE(PacketP->len, PKT_CMD_BIT | len);
845 ** Count characters transmitted for port statistics reporting
847 if (PortP->statsGather)
848 PortP->txchars += len;
850 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
851 return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL;
857 ** This is an ioctl interface. This is the twentieth century. You know what
860 int riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
862 register struct Port *PortP;
863 register struct ttystatics *tp;
865 int ParamSemIncremented = 0;
866 int old_oflag, old_cflag, old_iflag, changed, oldcook;
868 unsigned char sio_regs[5]; /* Here be magic */
872 uint SysPort = rio_minor(tty);
873 int Modem = rio_ismodem(tty);
876 rio_dprintk(RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n", SysPort, cmd, arg, Modem ? "Modem" : "tty");
878 if (SysPort >= RIO_PORTS) {
879 rio_dprintk(RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
883 PortP = p->RIOPortp[SysPort];
886 rio_spin_lock_irqsave(&PortP->portSem, flags);
889 PortP->Stat.IoctlCnt++;
892 if (PortP->State & RIO_DELETED) {
893 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
900 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
905 ** Count ioctls for port statistics reporting
907 if (PortP->statsGather)
911 ** Specialix RIO Ioctl calls
917 PortP->State |= RIO_TRIAD_MODE;
919 PortP->State &= ~RIO_TRIAD_MODE;
921 ** Normally, when istrip is set on a port, a config is
922 ** sent to the RTA instructing the CD1400 to do the
923 ** stripping. In TRIAD mode, the interrupt receive routine
924 ** must do the stripping instead, since it has to detect
925 ** an 8 bit function key sequence. If istrip is set with
926 ** TRIAD mode on(off), and 8 bit data is being read by
927 ** the port, the user then turns TRIAD mode off(on), the RTA
928 ** must be reconfigured (not) to do the stripping.
929 ** Hence we call RIOParam here.
931 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
932 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
936 rio_dprintk(RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n", arg ? "en" : "dis");
937 /* MonitorTstate = 0 ; */
938 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
939 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
942 case TCRIOSTATE: /* current state of Modem input pins */
943 rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE\n");
944 if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL)
945 rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE command failed\n");
946 PortP->State |= RIO_BUSY;
947 current = PortP->ModemState;
948 if (copyout((caddr_t) & current, (int) arg, sizeof(current)) == COPYFAIL) {
949 rio_dprintk(RIO_DEBUG_TTY, "Copyout failed\n");
950 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
953 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
956 case TCRIOMBIS: /* Set modem lines */
957 case TCRIOMBIC: /* Clear modem lines */
958 rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n");
959 if (cmd == TCRIOMBIS) {
962 PortP->ModemState |= (ushort) state;
963 PortP->ModemLines = (ulong) arg;
964 if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL)
965 rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS command failed\n");
970 PortP->ModemState &= ~(ushort) state;
971 PortP->ModemLines = (ulong) arg;
972 if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL)
973 rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIC command failed\n");
975 PortP->State |= RIO_BUSY;
976 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
979 case TCRIOXPON: /* set Xprint ON string */
980 rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPON\n");
981 if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOn, MAX_XP_CTRL_LEN) == COPYFAIL) {
982 rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n");
983 PortP->Xprint.XpOn[0] = '\0';
984 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
987 PortP->Xprint.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
988 PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff);
989 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
992 case TCRIOXPOFF: /* set Xprint OFF string */
993 rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPOFF\n");
994 if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOff, MAX_XP_CTRL_LEN) == COPYFAIL) {
995 rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n");
996 PortP->Xprint.XpOff[0] = '\0';
997 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1000 PortP->Xprint.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
1001 PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff);
1002 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1005 case TCRIOXPCPS: /* set Xprint CPS string */
1006 rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPCPS\n");
1007 if ((uint) arg > p->RIOConf.MaxXpCps || (uint) arg < p->RIOConf.MinXpCps) {
1008 rio_dprintk(RIO_DEBUG_TTY, "%d CPS out of range\n", arg);
1009 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1013 PortP->Xprint.XpCps = (uint) arg;
1014 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1018 rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPRINT\n");
1019 if (copyout((caddr_t) & PortP->Xprint, (int) arg, sizeof(struct Xprint)) == COPYFAIL) {
1020 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1023 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1027 rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYON\n");
1028 PortP->Config |= RIO_IXANY;
1029 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1033 rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYOFF\n");
1034 PortP->Config &= ~RIO_IXANY;
1035 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1039 rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONON\n");
1040 PortP->Config |= RIO_IXON;
1041 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1045 rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONOFF\n");
1046 PortP->Config &= ~RIO_IXON;
1047 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1051 ** 15.10.1998 ARG - ESIL 0761 part fix
1052 ** Added support for CTS and RTS flow control ioctls :
1054 case TCRIOCTSFLOWEN:
1055 rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n");
1056 PortP->Config |= RIO_CTSFLOW;
1057 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1058 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
1061 case TCRIOCTSFLOWDIS:
1062 rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n");
1063 PortP->Config &= ~RIO_CTSFLOW;
1064 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1065 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
1068 case TCRIORTSFLOWEN:
1069 rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n");
1070 PortP->Config |= RIO_RTSFLOW;
1071 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1072 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
1075 case TCRIORTSFLOWDIS:
1076 rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n");
1077 PortP->Config &= ~RIO_RTSFLOW;
1078 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1079 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
1082 /* end ESIL 0761 part fix */
1094 ttyseth(PortP, tp, (struct old_sgttyb *) arg);
1100 rio_dprintk(RIO_DEBUG_TTY, "NON POSIX ioctl\n");
1101 ttyseth_pv(PortP, tp, (struct termios *) arg, 0);
1103 case TCSETAP: /* posix tcsetattr() */
1104 case TCSETAWP: /* posix tcsetattr() */
1105 case TCSETAFP: /* posix tcsetattr() */
1106 rio_dprintk(RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n");
1107 ttyseth_pv(PortP, tp, (struct termios *) arg, 1);
1113 ** If its any of the commands that require the port to be in the
1114 ** non-busy state wait until all output has drained
1116 if (!ioctl_processed)
1122 #define OLD_POSIX ('x' << 8)
1123 #define OLD_POSIX_SETA (OLD_POSIX | 2)
1124 #define OLD_POSIX_SETAW (OLD_POSIX | 3)
1125 #define OLD_POSIX_SETAF (OLD_POSIX | 4)
1126 #define NEW_POSIX (('i' << 24) | ('X' << 16))
1127 #define NEW_POSIX_SETA (NEW_POSIX | 2)
1128 #define NEW_POSIX_SETAW (NEW_POSIX | 3)
1129 #define NEW_POSIX_SETAF (NEW_POSIX | 4)
1130 case OLD_POSIX_SETA:
1131 case OLD_POSIX_SETAW:
1132 case OLD_POSIX_SETAF:
1133 case NEW_POSIX_SETA:
1134 case NEW_POSIX_SETAW:
1135 case NEW_POSIX_SETAF:
1141 rio_dprintk(RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
1143 ** Wait for drain here, at least as far as the double buffer
1146 /* XXX Does the above comment mean that this has
1147 still to be implemented? -- REW */
1148 /* XXX Is the locking OK together with locking
1149 in txenable? (Deadlock?) -- REW */
1151 RIOTxEnable((char *) PortP);
1157 old_cflag = tp->tm.c_cflag;
1158 old_iflag = tp->tm.c_iflag;
1159 old_oflag = tp->tm.c_oflag;
1160 oldcook = PortP->CookMode;
1164 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1169 PortP->FlushCmdBodge = 0;
1172 ** If the port is locked, and it is reconfigured, we want
1173 ** to restore the state of the tty structure so the change is NOT
1177 tp->tm.c_iflag = PortP->StoredTty.iflag;
1178 tp->tm.c_oflag = PortP->StoredTty.oflag;
1179 tp->tm.c_cflag = PortP->StoredTty.cflag;
1180 tp->tm.c_lflag = PortP->StoredTty.lflag;
1181 tp->tm.c_line = PortP->StoredTty.line;
1182 for (i = 0; i < NCC + 1; i++)
1183 tp->tm.c_cc[i] = PortP->StoredTty.cc[i];
1186 ** If the port is set to store the parameters, and it is
1187 ** reconfigured, we want to save the current tty struct so it
1188 ** may be restored on the next open.
1191 PortP->StoredTty.iflag = tp->tm.c_iflag;
1192 PortP->StoredTty.oflag = tp->tm.c_oflag;
1193 PortP->StoredTty.cflag = tp->tm.c_cflag;
1194 PortP->StoredTty.lflag = tp->tm.c_lflag;
1195 PortP->StoredTty.line = tp->tm.c_line;
1196 for (i = 0; i < NCC + 1; i++)
1197 PortP->StoredTty.cc[i] = tp->tm.c_cc[i];
1201 changed = (tp->tm.c_cflag != old_cflag) || (tp->tm.c_iflag != old_iflag) || (tp->tm.c_oflag != old_oflag);
1203 PortP->CookMode = RIOCookMode(tp); /* Set new cooking mode */
1205 rio_dprintk(RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n", changed, PortP->CookMode, oldcook);
1207 #ifdef MODEM_SUPPORT
1209 ** kludge to force CARR_ON if CLOCAL set
1211 if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
1212 tp->tm.c_state |= CARR_ON;
1213 wakeup((caddr_t) & tp->tm.c_canq);
1219 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1224 ** Re-configure if modes or cooking have changed
1226 if (changed || oldcook != PortP->CookMode || (ioctl_processed)) {
1227 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1228 rio_dprintk(RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
1229 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
1230 rio_spin_lock_irqsave(&PortP->portSem, flags);
1234 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1239 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1244 ttyseth -- set hardware dependent tty settings
1246 void ttyseth(PortP, s, sg)
1248 struct ttystatics *s;
1249 struct old_sgttyb *sg;
1251 struct old_sgttyb *tsg;
1252 struct termios *tp = &s->tm;
1256 if (sg->sg_flags & (EVENP | ODDP)) {
1257 tp->c_cflag &= PARENB;
1258 if (sg->sg_flags & EVENP) {
1259 if (sg->sg_flags & ODDP) {
1260 tp->c_cflag &= V_CS7;
1261 tp->c_cflag &= ~PARENB;
1263 tp->c_cflag &= V_CS7;
1264 tp->c_cflag &= PARENB;
1265 tp->c_cflag &= PARODD;
1267 } else if (sg->sg_flags & ODDP) {
1268 tp->c_cflag &= V_CS7;
1269 tp->c_cflag &= PARENB;
1270 tp->c_cflag &= PARODD;
1272 tp->c_cflag &= V_CS7;
1273 tp->c_cflag &= PARENB;
1277 * Use ispeed as the desired speed. Most implementations don't handle
1278 * separate input and output speeds very well. If the RIO handles this,
1279 * I will have to use separate sets of flags to store them in the
1283 sg->sg_ospeed = sg->sg_ispeed;
1285 sg->sg_ispeed = sg->sg_ospeed;
1286 if (sg->sg_ispeed > V_EXTB)
1287 sg->sg_ispeed = V_EXTB;
1288 if (sg->sg_ispeed < V_B0)
1289 sg->sg_ispeed = V_B0;
1291 tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int) sg->sg_ispeed];
1295 ttyseth_pv -- set hardware dependent tty settings using either the
1296 POSIX termios structure or the System V termio structure.
1297 sysv = 0 => (POSIX): struct termios *sg
1298 sysv != 0 => (System V): struct termio *sg
1300 static void ttyseth_pv(PortP, s, sg, sysv)
1302 struct ttystatics *s;
1307 unsigned char csize;
1308 unsigned char cread;
1309 unsigned int lcr_flags;
1313 /* sg points to a System V termio structure */
1314 csize = ((struct termio *) sg)->c_cflag & CSIZE;
1315 cread = ((struct termio *) sg)->c_cflag & CREAD;
1316 speed = conv_vb[((struct termio *) sg)->c_cflag & V_CBAUD];
1318 /* sg points to a POSIX termios structure */
1319 csize = sg->c_cflag & CSIZE;
1320 cread = sg->c_cflag & CREAD;
1321 speed = conv_vb[sg->c_cflag & V_CBAUD];
1323 if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) {
1324 s->sg.sg_ispeed = speed;
1325 s->sg.sg_ospeed = speed;
1326 s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) | conv_bv[(int) s->sg.sg_ispeed];