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