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