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