| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 | ** ----------------------------------------------------------------------------- | 
 | 3 | ** | 
 | 4 | **  Perle Specialix driver for Linux | 
 | 5 | **  Ported from existing RIO Driver for SCO sources. | 
 | 6 |  * | 
 | 7 |  *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK. | 
 | 8 |  * | 
 | 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. | 
 | 13 |  * | 
 | 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. | 
 | 18 |  * | 
 | 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. | 
 | 22 | ** | 
 | 23 | **	Module		: riotty.c | 
 | 24 | **	SID		: 1.3 | 
 | 25 | **	Last Modified	: 11/6/98 10:33:47 | 
 | 26 | **	Retrieved	: 11/6/98 10:33:50 | 
 | 27 | ** | 
 | 28 | **  ident @(#)riotty.c	1.3 | 
 | 29 | ** | 
 | 30 | ** ----------------------------------------------------------------------------- | 
 | 31 | */ | 
 | 32 | #ifdef SCCS_LABELS | 
 | 33 | static char *_riotty_c_sccs_ = "@(#)riotty.c	1.3"; | 
 | 34 | #endif | 
 | 35 |  | 
 | 36 |  | 
 | 37 | #define __EXPLICIT_DEF_H__ | 
 | 38 |  | 
 | 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> | 
 | 44 | #include <asm/io.h> | 
 | 45 | #include <asm/system.h> | 
 | 46 | #include <asm/string.h> | 
 | 47 | #include <asm/semaphore.h> | 
 | 48 | #include <asm/uaccess.h> | 
 | 49 |  | 
 | 50 | #include <linux/termios.h> | 
 | 51 |  | 
 | 52 | #include <linux/serial.h> | 
 | 53 |  | 
 | 54 | #include <linux/generic_serial.h> | 
 | 55 |  | 
 | 56 |  | 
 | 57 | #include "linux_compat.h" | 
 | 58 | #include "rio_linux.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #include "pkt.h" | 
 | 60 | #include "daemon.h" | 
 | 61 | #include "rio.h" | 
 | 62 | #include "riospace.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include "cmdpkt.h" | 
 | 64 | #include "map.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include "rup.h" | 
 | 66 | #include "port.h" | 
 | 67 | #include "riodrvr.h" | 
 | 68 | #include "rioinfo.h" | 
 | 69 | #include "func.h" | 
 | 70 | #include "errors.h" | 
 | 71 | #include "pci.h" | 
 | 72 |  | 
 | 73 | #include "parmmap.h" | 
 | 74 | #include "unixrup.h" | 
 | 75 | #include "board.h" | 
 | 76 | #include "host.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #include "phb.h" | 
 | 78 | #include "link.h" | 
 | 79 | #include "cmdblk.h" | 
 | 80 | #include "route.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include "cirrus.h" | 
 | 82 | #include "rioioctl.h" | 
 | 83 | #include "param.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static void RIOClearUp(struct Port *PortP); | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 86 |  | 
 | 87 | /* Below belongs in func.h */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 88 | int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | extern struct rio_info *p; | 
 | 92 |  | 
 | 93 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 94 | int riotopen(struct tty_struct *tty, struct file *filp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { | 
| Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame] | 96 | 	unsigned int SysPort; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | 	int repeat_this = 250; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 98 | 	struct Port *PortP;	/* pointer to the port structure */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | 	unsigned long flags; | 
 | 100 | 	int retval = 0; | 
 | 101 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 102 | 	func_enter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 |  | 
 | 104 | 	/* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close | 
 | 105 | 	   is going to oops. | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 106 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | 	tty->driver_data = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 109 | 	SysPort = rio_minor(tty); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 110 |  | 
 | 111 | 	if (p->RIOFailed) { | 
 | 112 | 		rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n"); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 113 | 		func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | 		return -ENXIO; | 
 | 115 | 	} | 
 | 116 |  | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 117 | 	rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (mapped:%d)\n", SysPort, p->RIOPortp[SysPort]->Mapped); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 |  | 
 | 119 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 120 | 	 ** Validate that we have received a legitimate request. | 
 | 121 | 	 ** Currently, just check that we are opening a port on | 
 | 122 | 	 ** a host card that actually exists, and that the port | 
 | 123 | 	 ** has been mapped onto a host. | 
 | 124 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | 	if (SysPort >= RIO_PORTS) {	/* out of range ? */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 126 | 		rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | 		func_exit(); | 
 | 128 | 		return -ENXIO; | 
 | 129 | 	} | 
 | 130 |  | 
 | 131 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 132 | 	 ** Grab pointer to the port stucture | 
 | 133 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 	PortP = p->RIOPortp[SysPort];	/* Get control struc */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 135 | 	rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP); | 
 | 136 | 	if (!PortP->Mapped) {	/* we aren't mapped yet! */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | 		/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 138 | 		 ** The system doesn't know which RTA this port | 
 | 139 | 		 ** corresponds to. | 
 | 140 | 		 */ | 
 | 141 | 		rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n"); | 
 | 142 | 		func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | 		return -ENXIO; | 
 | 144 | 	} | 
 | 145 |  | 
 | 146 | 	tty->driver_data = PortP; | 
 | 147 |  | 
 | 148 | 	PortP->gs.tty = tty; | 
 | 149 | 	PortP->gs.count++; | 
 | 150 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 151 | 	rio_dprintk(RIO_DEBUG_TTY, "%d bytes in tx buffer\n", PortP->gs.xmit_cnt); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 153 | 	retval = gs_init_port(&PortP->gs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | 	if (retval) { | 
 | 155 | 		PortP->gs.count--; | 
 | 156 | 		return -ENXIO; | 
 | 157 | 	} | 
 | 158 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 159 | 	 ** If the host hasn't been booted yet, then | 
 | 160 | 	 ** fail | 
 | 161 | 	 */ | 
 | 162 | 	if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) { | 
 | 163 | 		rio_dprintk(RIO_DEBUG_TTY, "Host not running\n"); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 164 | 		func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | 		return -ENXIO; | 
 | 166 | 	} | 
 | 167 |  | 
 | 168 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 169 | 	 ** If the RTA has not booted yet and the user has choosen to block | 
 | 170 | 	 ** until the RTA is present then we must spin here waiting for | 
 | 171 | 	 ** the RTA to boot. | 
 | 172 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | 	/* I find the above code a bit hairy. I find the below code | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 174 | 	   easier to read and shorter. Now, if it works too that would | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | 	   be great... -- REW  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 176 | 	 */ | 
 | 177 | 	rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 	while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 179 | 		if (!PortP->WaitUntilBooted) { | 
 | 180 | 			rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n"); | 
 | 181 | 			func_exit(); | 
 | 182 | 			return -ENXIO; | 
 | 183 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 185 | 		/* Under Linux you'd normally use a wait instead of this | 
 | 186 | 		   busy-waiting. I'll stick with the old implementation for | 
 | 187 | 		   now. --REW | 
 | 188 | 		 */ | 
 | 189 | 		if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { | 
 | 190 | 			rio_dprintk(RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n"); | 
 | 191 | 			func_exit(); | 
 | 192 | 			return -EINTR; | 
 | 193 | 		} | 
 | 194 | 		if (repeat_this-- <= 0) { | 
 | 195 | 			rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n"); | 
 | 196 | 			func_exit(); | 
 | 197 | 			return -EIO; | 
 | 198 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | 	} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 200 | 	rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | 	rio_spin_lock_irqsave(&PortP->portSem, flags); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 202 | 	if (p->RIOHalted) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | 		goto bombout; | 
 | 204 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 |  | 
 | 206 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 207 | 	 ** If the port is in the final throws of being closed, | 
 | 208 | 	 ** we should wait here (politely), waiting | 
 | 209 | 	 ** for it to finish, so that it doesn't close us! | 
 | 210 | 	 */ | 
 | 211 | 	while ((PortP->State & RIO_CLOSING) && !p->RIOHalted) { | 
 | 212 | 		rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n"); | 
 | 213 | 		if (repeat_this-- <= 0) { | 
 | 214 | 			rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); | 
 | 215 | 			RIOPreemptiveCmd(p, PortP, FCLOSE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | 			retval = -EINTR; | 
 | 217 | 			goto bombout; | 
 | 218 | 		} | 
 | 219 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 220 | 		if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 221 | 			rio_spin_lock_irqsave(&PortP->portSem, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 			retval = -EINTR; | 
 | 223 | 			goto bombout; | 
 | 224 | 		} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 225 | 		rio_spin_lock_irqsave(&PortP->portSem, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 	} | 
 | 227 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 228 | 	if (!PortP->Mapped) { | 
 | 229 | 		rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 231 | 		retval = -ENXIO; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 232 | 		func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | 		return retval; | 
 | 234 | 	} | 
 | 235 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 236 | 	if (p->RIOHalted) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 		goto bombout; | 
 | 238 | 	} | 
 | 239 |  | 
 | 240 | /* | 
 | 241 | ** 15.10.1998 ARG - ESIL 0761 part fix | 
 | 242 | ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure, | 
 | 243 | ** we need to make sure that the flags are clear when the port is opened. | 
 | 244 | */ | 
 | 245 | 	/* Uh? Suppose I turn these on and then another process opens | 
 | 246 | 	   the port again? The flags get cleared! Not good. -- REW */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 247 | 	if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) { | 
 | 248 | 		PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | 	} | 
 | 250 |  | 
 | 251 | 	if (!(PortP->firstOpen)) {	/* First time ? */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 252 | 		rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n"); | 
 | 253 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 |  | 
 | 255 | 		PortP->firstOpen++; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 256 | 		PortP->CookMode = 0;	/* XXX RIOCookMode(tp); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | 		PortP->InUse = NOT_INUSE; | 
 | 258 |  | 
 | 259 | 		/* Tentative fix for bug PR27. Didn't work. */ | 
 | 260 | 		/* PortP->gs.xmit_cnt = 0; */ | 
 | 261 |  | 
 | 262 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 |  | 
 | 264 | 		/* Someone explain to me why this delay/config is | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 265 | 		   here. If I read the docs correctly the "open" | 
 | 266 | 		   command piggybacks the parameters immediately. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | 		   -- REW */ | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 268 | 		RIOParam(PortP, OPEN, 1, OK_TO_SLEEP);	/* Open the port */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | 		rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 270 |  | 
 | 271 | 		/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 272 | 		 ** wait for the port to be not closed. | 
 | 273 | 		 */ | 
 | 274 | 		while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) { | 
 | 275 | 			rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 			rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 277 | 			if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 278 | 				rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n"); | 
 | 279 | 				RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 280 | 				func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | 				return -EINTR; | 
 | 282 | 			} | 
 | 283 | 			rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 284 | 		} | 
 | 285 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 286 | 		if (p->RIOHalted) { | 
 | 287 | 			retval = -EIO; | 
 | 288 | 		      bombout: | 
 | 289 | 			/*                    RIOClearUp( PortP ); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | 			rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 291 | 			return retval; | 
 | 292 | 		} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 293 | 		rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | 	} | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 295 | 	rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n"); | 
 | 296 | 	/* | 
 | 297 | 	 ** ACTION | 
 | 298 | 	 ** insert test for carrier here. -- ??? | 
 | 299 | 	 ** I already see that test here. What's the deal? -- REW | 
 | 300 | 	 */ | 
 | 301 | 	if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) { | 
 | 302 | 		rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | 		/* | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 304 | 		   tp->tm.c_state |= CARR_ON; | 
 | 305 | 		   wakeup((caddr_t) &tp->tm.c_canq); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 306 | 		 */ | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 307 | 		PortP->State |= RIO_CARR_ON; | 
 | 308 | 		wake_up_interruptible(&PortP->gs.open_wait); | 
 | 309 | 	} else {	/* no carrier - wait for DCD */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | 			/* | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 311 | 		   while (!(PortP->gs.tty->termios->c_state & CARR_ON) && | 
 | 312 | 		   !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted ) | 
 | 313 | 		 */ | 
 | 314 | 		while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 315 | 				rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort); | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 316 | 			/* | 
 | 317 | 			   PortP->gs.tty->termios->c_state |= WOPEN; | 
 | 318 | 			 */ | 
 | 319 | 			PortP->State |= RIO_WOPEN; | 
 | 320 | 			rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 321 | 			if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | 				/* | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 323 | 				 ** ACTION: verify that this is a good thing | 
 | 324 | 				 ** to do here. -- ??? | 
 | 325 | 				 ** I think it's OK. -- REW | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 326 | 				 */ | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 327 | 				rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort); | 
 | 328 | 				RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 329 | 				/* | 
 | 330 | 				   tp->tm.c_state &= ~WOPEN; | 
 | 331 | 				 */ | 
 | 332 | 				PortP->State &= ~RIO_WOPEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | 				rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 334 | 				func_exit(); | 
 | 335 | 				return -EINTR; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | 		} | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 338 | 		PortP->State &= ~RIO_WOPEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | 	} | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 340 | 	if (p->RIOHalted) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | 		goto bombout; | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 342 | 	rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n"); | 
 | 343 | 	PortP->State |= RIO_MOPEN; | 
 | 344 |  | 
 | 345 | 	if (p->RIOHalted) | 
 | 346 | 		goto bombout; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 348 | 	rio_dprintk(RIO_DEBUG_TTY, "high level open done\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 351 | 	 ** Count opens for port statistics reporting | 
 | 352 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | 	if (PortP->statsGather) | 
 | 354 | 		PortP->opens++; | 
 | 355 |  | 
 | 356 | 	rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 357 | 	rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n"); | 
 | 358 | 	func_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | 	return 0; | 
 | 360 | } | 
 | 361 |  | 
 | 362 | /* | 
 | 363 | ** RIOClose the port. | 
 | 364 | ** The operating system thinks that this is last close for the device. | 
 | 365 | ** As there are two interfaces to the port (Modem and tty), we need to | 
 | 366 | ** check that both are closed before we close the device. | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 367 | */ | 
 | 368 | int riotclose(void *ptr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { | 
| M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 370 | 	struct Port *PortP = ptr;	/* pointer to the port structure */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | 	int deleted = 0; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 372 | 	int try = -1;		/* Disable the timeouts by setting them to -1 */ | 
 | 373 | 	int repeat_this = -1;	/* Congrats to those having 15 years of | 
 | 374 | 				   uptime! (You get to break the driver.) */ | 
| M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 375 | 	unsigned long end_time; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 376 | 	struct tty_struct *tty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | 	unsigned long flags; | 
| M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 378 | 	int rv = 0; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 379 |  | 
 | 380 | 	rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 |  | 
 | 382 | 	/* PortP = p->RIOPortp[SysPort]; */ | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 383 | 	rio_dprintk(RIO_DEBUG_TTY, "Port is at address %p\n", PortP); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 384 | 	/* tp = PortP->TtyP; *//* Get tty */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | 	tty = PortP->gs.tty; | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 386 | 	rio_dprintk(RIO_DEBUG_TTY, "TTY is at address %p\n", tty); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 388 | 	if (PortP->gs.closing_wait) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | 		end_time = jiffies + PortP->gs.closing_wait; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 390 | 	else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | 		end_time = jiffies + MAX_SCHEDULE_TIMEOUT; | 
 | 392 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | 	rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 394 |  | 
 | 395 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 396 | 	 ** Setting this flag will make any process trying to open | 
 | 397 | 	 ** this port block until we are complete closing it. | 
 | 398 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | 	PortP->State |= RIO_CLOSING; | 
 | 400 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 401 | 	if ((PortP->State & RIO_DELETED)) { | 
 | 402 | 		rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 		deleted = 1; | 
 | 404 | 	} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 405 |  | 
 | 406 | 	if (p->RIOHalted) { | 
 | 407 | 		RIOClearUp(PortP); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | 		rv = -EIO; | 
 | 409 | 		goto close_end; | 
 | 410 | 	} | 
 | 411 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 412 | 	rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 414 | 	 ** clear the open bits for this device | 
 | 415 | 	 */ | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 416 | 	PortP->State &= ~RIO_MOPEN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | 	PortP->State &= ~RIO_CARR_ON; | 
 | 418 | 	PortP->ModemState &= ~MSVR1_CD; | 
 | 419 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 420 | 	 ** If the device was open as both a Modem and a tty line | 
 | 421 | 	 ** then we need to wimp out here, as the port has not really | 
 | 422 | 	 ** been finally closed (gee, whizz!) The test here uses the | 
 | 423 | 	 ** bit for the OTHER mode of operation, to see if THAT is | 
 | 424 | 	 ** still active! | 
 | 425 | 	 */ | 
 | 426 | 	if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | 		/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 428 | 		 ** The port is still open for the other task - | 
 | 429 | 		 ** return, pretending that we are still active. | 
 | 430 | 		 */ | 
 | 431 | 		rio_dprintk(RIO_DEBUG_TTY, "Channel %d still open !\n", PortP->PortNum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | 		PortP->State &= ~RIO_CLOSING; | 
 | 433 | 		if (PortP->firstOpen) | 
 | 434 | 			PortP->firstOpen--; | 
 | 435 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 436 | 		return -EIO; | 
 | 437 | 	} | 
 | 438 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 439 | 	rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 |  | 
 | 441 | 	PortP->State &= ~RIO_DYNOROD; | 
 | 442 |  | 
 | 443 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 444 | 	 ** This is where we wait for the port | 
 | 445 | 	 ** to drain down before closing. Bye-bye.... | 
 | 446 | 	 ** (We never meant to do this) | 
 | 447 | 	 */ | 
 | 448 | 	rio_dprintk(RIO_DEBUG_TTY, "Timeout 1 starts\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 |  | 
 | 450 | 	if (!deleted) | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 451 | 		while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 452 | 			if (repeat_this-- <= 0) { | 
 | 453 | 				rv = -EINTR; | 
 | 454 | 				rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); | 
 | 455 | 				RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 456 | 				goto close_end; | 
 | 457 | 			} | 
 | 458 | 			rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n"); | 
 | 459 | 			rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 460 | 			if (RIODelay_ni(PortP, HUNDRED_MS * 10) == RIO_FAIL) { | 
 | 461 | 				rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); | 
 | 462 | 				rv = -EINTR; | 
 | 463 | 				rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 464 | 				goto close_end; | 
 | 465 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | 			rio_spin_lock_irqsave(&PortP->portSem, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 |  | 
 | 469 | 	PortP->TxBufferIn = PortP->TxBufferOut = 0; | 
 | 470 | 	repeat_this = 0xff; | 
 | 471 |  | 
 | 472 | 	PortP->InUse = 0; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 473 | 	if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 		/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 475 | 		 ** The port has been re-opened for the other task - | 
 | 476 | 		 ** return, pretending that we are still active. | 
 | 477 | 		 */ | 
 | 478 | 		rio_dprintk(RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | 		PortP->State &= ~RIO_CLOSING; | 
 | 480 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 481 | 		if (PortP->firstOpen) | 
 | 482 | 			PortP->firstOpen--; | 
 | 483 | 		return -EIO; | 
 | 484 | 	} | 
 | 485 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 486 | 	if (p->RIOHalted) { | 
 | 487 | 		RIOClearUp(PortP); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | 		goto close_end; | 
 | 489 | 	} | 
 | 490 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | 	/* Can't call RIOShortCommand with the port locked. */ | 
 | 492 | 	rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 493 |  | 
 | 494 | 	if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) { | 
| M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 495 | 		RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 496 | 		goto close_end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | 	} | 
 | 498 |  | 
 | 499 | 	if (!deleted) | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 500 | 		while (try && (PortP->PortState & PORT_ISOPEN)) { | 
 | 501 | 			try--; | 
 | 502 | 			if (time_after(jiffies, end_time)) { | 
 | 503 | 				rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n"); | 
 | 504 | 				RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 505 | 				break; | 
 | 506 | 			} | 
 | 507 | 			rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 509 | 			if (p->RIOHalted) { | 
 | 510 | 				RIOClearUp(PortP); | 
 | 511 | 				goto close_end; | 
 | 512 | 			} | 
 | 513 | 			if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { | 
 | 514 | 				rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); | 
 | 515 | 				RIOPreemptiveCmd(p, PortP, FCLOSE); | 
 | 516 | 				break; | 
 | 517 | 			} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | 	rio_spin_lock_irqsave(&PortP->portSem, flags); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 520 | 	rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try); | 
 | 521 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | 	/* RIOPreemptiveCmd(p, PortP, FCLOSE); */ | 
 | 523 |  | 
 | 524 | /* | 
 | 525 | ** 15.10.1998 ARG - ESIL 0761 part fix | 
 | 526 | ** 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. | 
 | 527 | */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 528 | 	PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 531 | 	 ** Count opens for port statistics reporting | 
 | 532 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | 	if (PortP->statsGather) | 
 | 534 | 		PortP->closes++; | 
 | 535 |  | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 536 | close_end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | 	/* XXX: Why would a "DELETED" flag be reset here? I'd have | 
 | 538 | 	   thought that a "deleted" flag means that the port was | 
 | 539 | 	   permanently gone, but here we can make it reappear by it | 
 | 540 | 	   being in close during the "deletion". | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 541 | 	 */ | 
 | 542 | 	PortP->State &= ~(RIO_CLOSING | RIO_DELETED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | 	if (PortP->firstOpen) | 
 | 544 | 		PortP->firstOpen--; | 
 | 545 | 	rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 546 | 	rio_dprintk(RIO_DEBUG_TTY, "Return from close\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | 	return rv; | 
 | 548 | } | 
 | 549 |  | 
 | 550 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 |  | 
| Alan Cox | 554b7c8 | 2006-03-24 03:18:32 -0800 | [diff] [blame] | 552 | static void RIOClearUp(struct Port *PortP) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 554 | 	rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n"); | 
 | 555 | 	PortP->Config = 0;	/* Direct semaphore */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | 	PortP->PortState = 0; | 
 | 557 | 	PortP->firstOpen = 0; | 
 | 558 | 	PortP->FlushCmdBodge = 0; | 
 | 559 | 	PortP->ModemState = PortP->CookMode = 0; | 
 | 560 | 	PortP->Mapped = 0; | 
 | 561 | 	PortP->WflushFlag = 0; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 562 | 	PortP->MagicFlags = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | 	PortP->RxDataStart = 0; | 
 | 564 | 	PortP->TxBufferIn = 0; | 
 | 565 | 	PortP->TxBufferOut = 0; | 
 | 566 | } | 
 | 567 |  | 
 | 568 | /* | 
 | 569 | ** Put a command onto a port. | 
 | 570 | ** The PortPointer, command, length and arg are passed. | 
 | 571 | ** The len is the length *inclusive* of the command byte, | 
 | 572 | ** and so for a command that takes no data, len==1. | 
 | 573 | ** The arg is a single byte, and is only used if len==2. | 
 | 574 | ** Other values of len aren't allowed, and will cause | 
 | 575 | ** a panic. | 
 | 576 | */ | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 577 | int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | { | 
| Al Viro | d886cb5 | 2006-05-27 00:08:25 -0400 | [diff] [blame] | 579 | 	struct PKT __iomem *PacketP; | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 580 | 	int retries = 20;	/* at 10 per second -> 2 seconds */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | 	unsigned long flags; | 
 | 582 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 583 | 	rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 585 | 	if (PortP->State & RIO_DELETED) { | 
 | 586 | 		rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | 		return RIO_FAIL; | 
 | 588 | 	} | 
 | 589 | 	rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 590 |  | 
 | 591 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 592 | 	 ** If the port is in use for pre-emptive command, then wait for it to | 
 | 593 | 	 ** be free again. | 
 | 594 | 	 */ | 
 | 595 | 	while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted) { | 
 | 596 | 		rio_dprintk(RIO_DEBUG_TTY, "Waiting for not in use (%d)\n", retries); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 598 | 		if (retries-- <= 0) { | 
 | 599 | 			return RIO_FAIL; | 
 | 600 | 		} | 
 | 601 | 		if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) { | 
 | 602 | 			return RIO_FAIL; | 
 | 603 | 		} | 
 | 604 | 		rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 605 | 	} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 606 | 	if (PortP->State & RIO_DELETED) { | 
 | 607 | 		rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 609 | 		return RIO_FAIL; | 
 | 610 | 	} | 
 | 611 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 612 | 	while (!can_add_transmit(&PacketP, PortP) && !p->RIOHalted) { | 
 | 613 | 		rio_dprintk(RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 615 | 		if (retries-- <= 0) { | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 616 | 			rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | 			return RIO_FAIL; | 
 | 618 | 		} | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 619 | 		if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | 			return RIO_FAIL; | 
 | 621 | 		} | 
 | 622 | 		rio_spin_lock_irqsave(&PortP->portSem, flags); | 
 | 623 | 	} | 
 | 624 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 625 | 	if (p->RIOHalted) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | 		rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 627 | 		return RIO_FAIL; | 
 | 628 | 	} | 
 | 629 |  | 
 | 630 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 631 | 	 ** set the command byte and the argument byte | 
 | 632 | 	 */ | 
| Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame] | 633 | 	writeb(command, &PacketP->data[0]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 |  | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 635 | 	if (len == 2) | 
| Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame] | 636 | 		writeb(arg, &PacketP->data[1]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 |  | 
 | 638 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 639 | 	 ** set the length of the packet and set the command bit. | 
 | 640 | 	 */ | 
| Alan Cox | e2b3afd | 2006-03-24 03:18:27 -0800 | [diff] [blame] | 641 | 	writeb(PKT_CMD_BIT | len, &PacketP->len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 |  | 
 | 643 | 	add_transmit(PortP); | 
 | 644 | 	/* | 
| Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame] | 645 | 	 ** Count characters transmitted for port statistics reporting | 
 | 646 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | 	if (PortP->statsGather) | 
 | 648 | 		PortP->txchars += len; | 
 | 649 |  | 
 | 650 | 	rio_spin_unlock_irqrestore(&PortP->portSem, flags); | 
 | 651 | 	return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL; | 
 | 652 | } | 
 | 653 |  | 
 | 654 |  |