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 | |
| 92 | #if 0 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 93 | static void ttyseth_pv(struct Port *, struct ttystatics *, struct termios *sg, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
| 96 | static void RIOClearUp(struct Port *PortP); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 97 | 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] | 98 | |
| 99 | #if 0 |
| 100 | static int RIOCookMode(struct ttystatics *); |
| 101 | #endif |
| 102 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 103 | extern int conv_vb[]; /* now defined in ttymgr.c */ |
| 104 | extern int conv_bv[]; /* now defined in ttymgr.c */ |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | /* |
| 107 | ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support |
| 108 | ** |
| 109 | ** ep.def.h is necessary for Modular Kernel Support |
| 110 | ** DO NOT place any kernel 'extern's after this line |
| 111 | ** or this source file will not build riotty.k.o |
| 112 | */ |
| 113 | #ifdef uLYNX |
| 114 | #include <ep.def.h> |
| 115 | #endif |
| 116 | |
| 117 | #ifdef NEED_THIS2 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 118 | static struct old_sgttyb default_sg = { |
| 119 | B19200, B19200, /* input and output speed */ |
| 120 | 'H' - '@', /* erase char */ |
| 121 | -1, /* 2nd erase char */ |
| 122 | 'U' - '@', /* kill char */ |
| 123 | ECHO | CRMOD, /* mode */ |
| 124 | 'C' - '@', /* interrupt character */ |
| 125 | '\\' - '@', /* quit char */ |
| 126 | 'Q' - '@', /* start char */ |
| 127 | 'S' - '@', /* stop char */ |
| 128 | 'D' - '@', /* EOF */ |
| 129 | -1, /* brk */ |
| 130 | (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */ |
| 131 | 'Z' - '@', /* process stop */ |
| 132 | 'Y' - '@', /* delayed stop */ |
| 133 | 'R' - '@', /* reprint line */ |
| 134 | 'O' - '@', /* flush output */ |
| 135 | 'W' - '@', /* word erase */ |
| 136 | 'V' - '@' /* literal next char */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | #endif |
| 139 | |
| 140 | |
| 141 | extern struct rio_info *p; |
| 142 | |
| 143 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 144 | int riotopen(struct tty_struct *tty, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | register uint SysPort; |
| 147 | int Modem; |
| 148 | int repeat_this = 250; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 149 | struct Port *PortP; /* pointer to the port structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | unsigned long flags; |
| 151 | int retval = 0; |
| 152 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 153 | func_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close |
| 156 | is going to oops. |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 157 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | tty->driver_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 160 | SysPort = rio_minor(tty); |
| 161 | Modem = rio_ismodem(tty); |
| 162 | |
| 163 | if (p->RIOFailed) { |
| 164 | rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | pseterr(ENXIO); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 166 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | return -ENXIO; |
| 168 | } |
| 169 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 170 | 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] | 171 | |
| 172 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 173 | ** Validate that we have received a legitimate request. |
| 174 | ** Currently, just check that we are opening a port on |
| 175 | ** a host card that actually exists, and that the port |
| 176 | ** has been mapped onto a host. |
| 177 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | if (SysPort >= RIO_PORTS) { /* out of range ? */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 179 | rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | pseterr(ENXIO); |
| 181 | func_exit(); |
| 182 | return -ENXIO; |
| 183 | } |
| 184 | |
| 185 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 186 | ** Grab pointer to the port stucture |
| 187 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | PortP = p->RIOPortp[SysPort]; /* Get control struc */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 189 | rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP); |
| 190 | if (!PortP->Mapped) { /* we aren't mapped yet! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 192 | ** The system doesn't know which RTA this port |
| 193 | ** corresponds to. |
| 194 | */ |
| 195 | rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n"); |
| 196 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | pseterr(ENXIO); |
| 198 | return -ENXIO; |
| 199 | } |
| 200 | |
| 201 | tty->driver_data = PortP; |
| 202 | |
| 203 | PortP->gs.tty = tty; |
| 204 | PortP->gs.count++; |
| 205 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 206 | 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] | 207 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 208 | retval = gs_init_port(&PortP->gs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | if (retval) { |
| 210 | PortP->gs.count--; |
| 211 | return -ENXIO; |
| 212 | } |
| 213 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 214 | ** If the host hasn't been booted yet, then |
| 215 | ** fail |
| 216 | */ |
| 217 | if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) { |
| 218 | rio_dprintk(RIO_DEBUG_TTY, "Host not running\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | pseterr(ENXIO); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 220 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | return -ENXIO; |
| 222 | } |
| 223 | |
| 224 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 225 | ** If the RTA has not booted yet and the user has choosen to block |
| 226 | ** until the RTA is present then we must spin here waiting for |
| 227 | ** the RTA to boot. |
| 228 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | #if 0 |
| 230 | if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) { |
| 231 | if (PortP->WaitUntilBooted) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 232 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | do { |
| 234 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 235 | rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); |
| 236 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return -EINTR; |
| 238 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 239 | if (repeat_this-- <= 0) { |
| 240 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n"); |
| 241 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | pseterr(EINTR); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 243 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return -EIO; |
| 245 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 246 | } while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)); |
| 247 | rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } else { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 249 | rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | pseterr(ENXIO); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 251 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return 0; |
| 253 | } |
| 254 | } |
| 255 | #else |
| 256 | /* 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^] | 257 | easier to read and shorter. Now, if it works too that would |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | be great... -- REW |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 259 | */ |
| 260 | rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 262 | if (!PortP->WaitUntilBooted) { |
| 263 | rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n"); |
| 264 | func_exit(); |
| 265 | return -ENXIO; |
| 266 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 268 | /* Under Linux you'd normally use a wait instead of this |
| 269 | busy-waiting. I'll stick with the old implementation for |
| 270 | now. --REW |
| 271 | */ |
| 272 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { |
| 273 | rio_dprintk(RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n"); |
| 274 | func_exit(); |
| 275 | return -EINTR; |
| 276 | } |
| 277 | if (repeat_this-- <= 0) { |
| 278 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n"); |
| 279 | func_exit(); |
| 280 | return -EIO; |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 283 | rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | #endif |
| 285 | #if 0 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 286 | tp = PortP->TtyP; /* get tty struct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | #endif |
| 288 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 289 | if (p->RIOHalted) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | goto bombout; |
| 291 | } |
| 292 | #if 0 |
| 293 | retval = gs_init_port(&PortP->gs); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 294 | if (retval) { |
| 295 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return retval; |
| 297 | } |
| 298 | #endif |
| 299 | |
| 300 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 301 | ** If the port is in the final throws of being closed, |
| 302 | ** we should wait here (politely), waiting |
| 303 | ** for it to finish, so that it doesn't close us! |
| 304 | */ |
| 305 | while ((PortP->State & RIO_CLOSING) && !p->RIOHalted) { |
| 306 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n"); |
| 307 | if (repeat_this-- <= 0) { |
| 308 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); |
| 309 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | retval = -EINTR; |
| 311 | goto bombout; |
| 312 | } |
| 313 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 314 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 315 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | retval = -EINTR; |
| 317 | goto bombout; |
| 318 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 319 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 322 | if (!PortP->Mapped) { |
| 323 | rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 325 | retval = -ENXIO; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 326 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | return retval; |
| 328 | } |
| 329 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 330 | if (p->RIOHalted) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | goto bombout; |
| 332 | } |
| 333 | |
| 334 | /* |
| 335 | ** 15.10.1998 ARG - ESIL 0761 part fix |
| 336 | ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure, |
| 337 | ** we need to make sure that the flags are clear when the port is opened. |
| 338 | */ |
| 339 | /* Uh? Suppose I turn these on and then another process opens |
| 340 | the port again? The flags get cleared! Not good. -- REW */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 341 | if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) { |
| 342 | PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | if (!(PortP->firstOpen)) { /* First time ? */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 346 | rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n"); |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
| 349 | PortP->firstOpen++; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 350 | PortP->CookMode = 0; /* XXX RIOCookMode(tp); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | PortP->InUse = NOT_INUSE; |
| 352 | |
| 353 | /* Tentative fix for bug PR27. Didn't work. */ |
| 354 | /* PortP->gs.xmit_cnt = 0; */ |
| 355 | |
| 356 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 357 | #ifdef NEED_THIS |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 358 | ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #endif |
| 360 | |
| 361 | /* Someone explain to me why this delay/config is |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 362 | here. If I read the docs correctly the "open" |
| 363 | command piggybacks the parameters immediately. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | -- REW */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 365 | RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP); /* Open the port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | #if 0 |
| 367 | /* This delay of 1 second was annoying. I removed it. -- REW */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 368 | RIODelay(PortP, HUNDRED_MS * 10); |
| 369 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); /* Config the port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | #endif |
| 371 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 372 | |
| 373 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 374 | ** wait for the port to be not closed. |
| 375 | */ |
| 376 | while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) { |
| 377 | 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] | 378 | /* |
| 379 | ** 15.10.1998 ARG - ESIL 0759 |
| 380 | ** (Part) fix for port being trashed when opened whilst RTA "disconnected" |
| 381 | ** Take out the limited wait - now wait for ever or until user |
| 382 | ** bangs us out. |
| 383 | ** |
| 384 | if (repeat_this -- <= 0) { |
| 385 | rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n")); |
| 386 | RIOPreemptiveCmd(p, PortP, FCLOSE ); |
| 387 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 388 | return -EINTR; |
| 389 | } |
| 390 | ** |
| 391 | */ |
| 392 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 393 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 394 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n"); |
| 395 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 396 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | return -EINTR; |
| 398 | } |
| 399 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 400 | } |
| 401 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 402 | if (p->RIOHalted) { |
| 403 | retval = -EIO; |
| 404 | bombout: |
| 405 | /* RIOClearUp( PortP ); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 407 | return retval; |
| 408 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 409 | rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 411 | #ifdef MODEM_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | if (Modem) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 413 | rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 415 | ** ACTION |
| 416 | ** insert test for carrier here. -- ??? |
| 417 | ** I already see that test here. What's the deal? -- REW |
| 418 | */ |
| 419 | if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) { |
| 420 | rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort); |
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 | tp->tm.c_state |= CARR_ON; |
| 423 | wakeup((caddr_t) &tp->tm.c_canq); |
| 424 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | PortP->State |= RIO_CARR_ON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 426 | wake_up_interruptible(&PortP->gs.open_wait); |
| 427 | } else { /* no carrier - wait for DCD */ |
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 | /* |
| 430 | while (!(PortP->gs.tty->termios->c_state & CARR_ON) && |
| 431 | !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted ) |
| 432 | */ |
| 433 | while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) { |
| 434 | |
| 435 | 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] | 436 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 437 | PortP->gs.tty->termios->c_state |= WOPEN; |
| 438 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | PortP->State |= RIO_WOPEN; |
| 440 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 441 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | #if 0 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 443 | if (sleep((caddr_t) & tp->tm.c_canqo, TTIPRI | PCATCH)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | #endif |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 445 | { |
| 446 | /* |
| 447 | ** ACTION: verify that this is a good thing |
| 448 | ** to do here. -- ??? |
| 449 | ** I think it's OK. -- REW |
| 450 | */ |
| 451 | rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort); |
| 452 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 453 | /* |
| 454 | tp->tm.c_state &= ~WOPEN; |
| 455 | */ |
| 456 | PortP->State &= ~RIO_WOPEN; |
| 457 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 458 | func_exit(); |
| 459 | return -EINTR; |
| 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | PortP->State &= ~RIO_WOPEN; |
| 463 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 464 | if (p->RIOHalted) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | goto bombout; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 466 | rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | PortP->State |= RIO_MOPEN; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 468 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | #endif |
| 470 | { |
| 471 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 472 | ** ACTION |
| 473 | ** Direct line open - force carrier (will probably mean |
| 474 | ** that sleeping Modem line fubar) |
| 475 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | PortP->State |= RIO_LOPEN; |
| 477 | } |
| 478 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 479 | if (p->RIOHalted) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | goto bombout; |
| 481 | } |
| 482 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 483 | rio_dprintk(RIO_DEBUG_TTY, "high level open done\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | #ifdef STATS |
| 486 | PortP->Stat.OpenCnt++; |
| 487 | #endif |
| 488 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 489 | ** Count opens for port statistics reporting |
| 490 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if (PortP->statsGather) |
| 492 | PortP->opens++; |
| 493 | |
| 494 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 495 | rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n"); |
| 496 | func_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /* |
| 501 | ** RIOClose the port. |
| 502 | ** The operating system thinks that this is last close for the device. |
| 503 | ** As there are two interfaces to the port (Modem and tty), we need to |
| 504 | ** check that both are closed before we close the device. |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 505 | */ |
| 506 | int riotclose(void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | { |
| 508 | #if 0 |
| 509 | register uint SysPort = dev; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 510 | struct ttystatics *tp; /* pointer to our ttystruct */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | #endif |
M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 512 | struct Port *PortP = ptr; /* pointer to the port structure */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | int deleted = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 514 | int try = -1; /* Disable the timeouts by setting them to -1 */ |
| 515 | int repeat_this = -1; /* Congrats to those having 15 years of |
| 516 | uptime! (You get to break the driver.) */ |
M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 517 | unsigned long end_time; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 518 | struct tty_struct *tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | unsigned long flags; |
| 520 | int Modem; |
M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 521 | int rv = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 522 | |
| 523 | rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | /* PortP = p->RIOPortp[SysPort]; */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 526 | rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%x\n", (int) PortP); |
| 527 | /* tp = PortP->TtyP; *//* Get tty */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | tty = PortP->gs.tty; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 529 | rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%x\n", (int) tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 531 | if (PortP->gs.closing_wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | end_time = jiffies + PortP->gs.closing_wait; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 533 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | end_time = jiffies + MAX_SCHEDULE_TIMEOUT; |
| 535 | |
| 536 | Modem = rio_ismodem(tty); |
| 537 | #if 0 |
| 538 | /* What F.CKING cache? Even then, a higly idle multiprocessor, |
| 539 | system with large caches this won't work . Better find out when |
| 540 | this doesn't work asap, and fix the cause. -- REW */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 541 | |
| 542 | RIODelay(PortP, HUNDRED_MS * 10); /* To flush the cache */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | #endif |
| 544 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 545 | |
| 546 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 547 | ** Setting this flag will make any process trying to open |
| 548 | ** this port block until we are complete closing it. |
| 549 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | PortP->State |= RIO_CLOSING; |
| 551 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 552 | if ((PortP->State & RIO_DELETED)) { |
| 553 | rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | deleted = 1; |
| 555 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 556 | |
| 557 | if (p->RIOHalted) { |
| 558 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | rv = -EIO; |
| 560 | goto close_end; |
| 561 | } |
| 562 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 563 | rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 565 | ** clear the open bits for this device |
| 566 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN); |
| 568 | PortP->State &= ~RIO_CARR_ON; |
| 569 | PortP->ModemState &= ~MSVR1_CD; |
| 570 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 571 | ** If the device was open as both a Modem and a tty line |
| 572 | ** then we need to wimp out here, as the port has not really |
| 573 | ** been finally closed (gee, whizz!) The test here uses the |
| 574 | ** bit for the OTHER mode of operation, to see if THAT is |
| 575 | ** still active! |
| 576 | */ |
| 577 | if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 579 | ** The port is still open for the other task - |
| 580 | ** return, pretending that we are still active. |
| 581 | */ |
| 582 | rio_dprintk(RIO_DEBUG_TTY, "Channel %d still open !\n", PortP->PortNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | PortP->State &= ~RIO_CLOSING; |
| 584 | if (PortP->firstOpen) |
| 585 | PortP->firstOpen--; |
| 586 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 587 | return -EIO; |
| 588 | } |
| 589 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 590 | rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | PortP->State &= ~RIO_DYNOROD; |
| 593 | |
| 594 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 595 | ** This is where we wait for the port |
| 596 | ** to drain down before closing. Bye-bye.... |
| 597 | ** (We never meant to do this) |
| 598 | */ |
| 599 | rio_dprintk(RIO_DEBUG_TTY, "Timeout 1 starts\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | if (!deleted) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 602 | while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) { |
| 603 | cprintf("Need to flush the ttyport\n"); |
| 604 | if (repeat_this-- <= 0) { |
| 605 | rv = -EINTR; |
| 606 | rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n"); |
| 607 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 608 | goto close_end; |
| 609 | } |
| 610 | rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n"); |
| 611 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 612 | if (RIODelay_ni(PortP, HUNDRED_MS * 10) == RIO_FAIL) { |
| 613 | rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); |
| 614 | rv = -EINTR; |
| 615 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 616 | goto close_end; |
| 617 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | PortP->TxBufferIn = PortP->TxBufferOut = 0; |
| 622 | repeat_this = 0xff; |
| 623 | |
| 624 | PortP->InUse = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 625 | if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 627 | ** The port has been re-opened for the other task - |
| 628 | ** return, pretending that we are still active. |
| 629 | */ |
| 630 | rio_dprintk(RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | PortP->State &= ~RIO_CLOSING; |
| 632 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 633 | if (PortP->firstOpen) |
| 634 | PortP->firstOpen--; |
| 635 | return -EIO; |
| 636 | } |
| 637 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 638 | if (p->RIOHalted) { |
| 639 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | goto close_end; |
| 641 | } |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* Can't call RIOShortCommand with the port locked. */ |
| 644 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 645 | |
| 646 | if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) { |
M.Baris Demiray | d2a457c | 2005-06-25 14:58:40 -0700 | [diff] [blame] | 647 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 648 | goto close_end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | if (!deleted) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 652 | while (try && (PortP->PortState & PORT_ISOPEN)) { |
| 653 | try--; |
| 654 | if (time_after(jiffies, end_time)) { |
| 655 | rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n"); |
| 656 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 657 | break; |
| 658 | } |
| 659 | 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] | 660 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 661 | if (p->RIOHalted) { |
| 662 | RIOClearUp(PortP); |
| 663 | goto close_end; |
| 664 | } |
| 665 | if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) { |
| 666 | rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n"); |
| 667 | RIOPreemptiveCmd(p, PortP, FCLOSE); |
| 668 | break; |
| 669 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 672 | rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try); |
| 673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | /* RIOPreemptiveCmd(p, PortP, FCLOSE); */ |
| 675 | |
| 676 | /* |
| 677 | ** 15.10.1998 ARG - ESIL 0761 part fix |
| 678 | ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,** we need to make sure that the flags are clear when the port is opened. |
| 679 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 680 | PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | #ifdef STATS |
| 683 | PortP->Stat.CloseCnt++; |
| 684 | #endif |
| 685 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 686 | ** Count opens for port statistics reporting |
| 687 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | if (PortP->statsGather) |
| 689 | PortP->closes++; |
| 690 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 691 | close_end: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | /* XXX: Why would a "DELETED" flag be reset here? I'd have |
| 693 | thought that a "deleted" flag means that the port was |
| 694 | permanently gone, but here we can make it reappear by it |
| 695 | being in close during the "deletion". |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 696 | */ |
| 697 | PortP->State &= ~(RIO_CLOSING | RIO_DELETED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if (PortP->firstOpen) |
| 699 | PortP->firstOpen--; |
| 700 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 701 | rio_dprintk(RIO_DEBUG_TTY, "Return from close\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | return rv; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /* |
| 707 | ** decide if we need to use the line discipline. |
| 708 | ** This routine can return one of three values: |
| 709 | ** COOK_RAW if no processing has to be done by the line discipline or the card |
| 710 | ** COOK_WELL if the line discipline must be used to do the processing |
| 711 | ** COOK_MEDIUM if the card can do all the processing necessary. |
| 712 | */ |
| 713 | #if 0 |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 714 | static int RIOCookMode(struct ttystatics *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
| 716 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 717 | ** We can't handle tm.c_mstate != 0 on SCO |
| 718 | ** We can't handle mapping |
| 719 | ** We can't handle non-ttwrite line disc. |
| 720 | ** We can't handle lflag XCASE |
| 721 | ** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3) |
| 722 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | #ifdef CHECK |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 725 | CheckTtyP(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | #endif |
| 727 | if (!(tp->tm.c_oflag & OPOST)) /* No post processing */ |
| 728 | return COOK_RAW; /* Raw mode o/p */ |
| 729 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 730 | if (tp->tm.c_lflag & XCASE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return COOK_WELL; /* Use line disc */ |
| 732 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 733 | if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | return COOK_WELL; /* Use line disc for strange modes */ |
| 735 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 736 | if (tp->tm.c_oflag == OPOST) /* If only OPOST is set, do RAW */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return COOK_RAW; |
| 738 | |
| 739 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 740 | ** So, we need to output process! |
| 741 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | return COOK_MEDIUM; |
| 743 | } |
| 744 | #endif |
| 745 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 746 | static void RIOClearUp(PortP) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | struct Port *PortP; |
| 748 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 749 | rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n"); |
| 750 | PortP->Config = 0; /* Direct semaphore */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | PortP->PortState = 0; |
| 752 | PortP->firstOpen = 0; |
| 753 | PortP->FlushCmdBodge = 0; |
| 754 | PortP->ModemState = PortP->CookMode = 0; |
| 755 | PortP->Mapped = 0; |
| 756 | PortP->WflushFlag = 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 757 | PortP->MagicFlags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | PortP->RxDataStart = 0; |
| 759 | PortP->TxBufferIn = 0; |
| 760 | PortP->TxBufferOut = 0; |
| 761 | } |
| 762 | |
| 763 | /* |
| 764 | ** Put a command onto a port. |
| 765 | ** The PortPointer, command, length and arg are passed. |
| 766 | ** The len is the length *inclusive* of the command byte, |
| 767 | ** and so for a command that takes no data, len==1. |
| 768 | ** The arg is a single byte, and is only used if len==2. |
| 769 | ** Other values of len aren't allowed, and will cause |
| 770 | ** a panic. |
| 771 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 772 | 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] | 773 | { |
| 774 | PKT *PacketP; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 775 | int retries = 20; /* at 10 per second -> 2 seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | unsigned long flags; |
| 777 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 778 | rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | #ifdef CHECK |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 780 | CheckPortP(PortP); |
| 781 | if (len < 1 || len > 2) |
| 782 | cprintf(("STUPID LENGTH %d\n", len)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | #endif |
| 784 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 785 | if (PortP->State & RIO_DELETED) { |
| 786 | rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | return RIO_FAIL; |
| 788 | } |
| 789 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 790 | |
| 791 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 792 | ** If the port is in use for pre-emptive command, then wait for it to |
| 793 | ** be free again. |
| 794 | */ |
| 795 | while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted) { |
| 796 | 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] | 797 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 798 | if (retries-- <= 0) { |
| 799 | return RIO_FAIL; |
| 800 | } |
| 801 | if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) { |
| 802 | return RIO_FAIL; |
| 803 | } |
| 804 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 805 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 806 | if (PortP->State & RIO_DELETED) { |
| 807 | rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 809 | return RIO_FAIL; |
| 810 | } |
| 811 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 812 | while (!can_add_transmit(&PacketP, PortP) && !p->RIOHalted) { |
| 813 | rio_dprintk(RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 815 | if (retries-- <= 0) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 816 | rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return RIO_FAIL; |
| 818 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 819 | if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | return RIO_FAIL; |
| 821 | } |
| 822 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 823 | } |
| 824 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 825 | if (p->RIOHalted) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 827 | return RIO_FAIL; |
| 828 | } |
| 829 | |
| 830 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 831 | ** set the command byte and the argument byte |
| 832 | */ |
| 833 | WBYTE(PacketP->data[0], command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 835 | if (len == 2) |
| 836 | WBYTE(PacketP->data[1], arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 839 | ** set the length of the packet and set the command bit. |
| 840 | */ |
| 841 | WBYTE(PacketP->len, PKT_CMD_BIT | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
| 843 | add_transmit(PortP); |
| 844 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 845 | ** Count characters transmitted for port statistics reporting |
| 846 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | if (PortP->statsGather) |
| 848 | PortP->txchars += len; |
| 849 | |
| 850 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 851 | return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL; |
| 852 | } |
| 853 | |
| 854 | |
| 855 | #if 0 |
| 856 | /* |
| 857 | ** This is an ioctl interface. This is the twentieth century. You know what |
| 858 | ** its all about. |
| 859 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 860 | int riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 862 | register struct Port *PortP; |
| 863 | register struct ttystatics *tp; |
| 864 | int current; |
| 865 | int ParamSemIncremented = 0; |
| 866 | int old_oflag, old_cflag, old_iflag, changed, oldcook; |
| 867 | int i; |
| 868 | unsigned char sio_regs[5]; /* Here be magic */ |
| 869 | short vpix_cflag; |
| 870 | short divisor; |
| 871 | int baud; |
| 872 | uint SysPort = rio_minor(tty); |
| 873 | int Modem = rio_ismodem(tty); |
| 874 | int ioctl_processed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 876 | rio_dprintk(RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n", SysPort, cmd, arg, Modem ? "Modem" : "tty"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 878 | if (SysPort >= RIO_PORTS) { |
| 879 | rio_dprintk(RIO_DEBUG_TTY, "Bad port number %d\n", SysPort); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | return -ENXIO; |
| 881 | } |
| 882 | |
| 883 | PortP = p->RIOPortp[SysPort]; |
| 884 | tp = PortP->TtyP; |
| 885 | |
| 886 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 887 | |
| 888 | #ifdef STATS |
| 889 | PortP->Stat.IoctlCnt++; |
| 890 | #endif |
| 891 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 892 | if (PortP->State & RIO_DELETED) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 894 | return -EIO; |
| 895 | } |
| 896 | |
| 897 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 898 | if (p->RIOHalted) { |
| 899 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 901 | return -EIO; |
| 902 | } |
| 903 | |
| 904 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 905 | ** Count ioctls for port statistics reporting |
| 906 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | if (PortP->statsGather) |
| 908 | PortP->ioctls++; |
| 909 | |
| 910 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 911 | ** Specialix RIO Ioctl calls |
| 912 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | switch (cmd) { |
| 914 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 915 | case TCRIOTRIAD: |
| 916 | if (arg) |
| 917 | PortP->State |= RIO_TRIAD_MODE; |
| 918 | else |
| 919 | PortP->State &= ~RIO_TRIAD_MODE; |
| 920 | /* |
| 921 | ** Normally, when istrip is set on a port, a config is |
| 922 | ** sent to the RTA instructing the CD1400 to do the |
| 923 | ** stripping. In TRIAD mode, the interrupt receive routine |
| 924 | ** must do the stripping instead, since it has to detect |
| 925 | ** an 8 bit function key sequence. If istrip is set with |
| 926 | ** TRIAD mode on(off), and 8 bit data is being read by |
| 927 | ** the port, the user then turns TRIAD mode off(on), the RTA |
| 928 | ** must be reconfigured (not) to do the stripping. |
| 929 | ** Hence we call RIOParam here. |
| 930 | */ |
| 931 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 932 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 933 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 935 | case TCRIOTSTATE: |
| 936 | rio_dprintk(RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n", arg ? "en" : "dis"); |
| 937 | /* MonitorTstate = 0 ; */ |
| 938 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 939 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 940 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 942 | case TCRIOSTATE: /* current state of Modem input pins */ |
| 943 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE\n"); |
| 944 | if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL) |
| 945 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOSTATE command failed\n"); |
| 946 | PortP->State |= RIO_BUSY; |
| 947 | current = PortP->ModemState; |
| 948 | if (copyout((caddr_t) & current, (int) arg, sizeof(current)) == COPYFAIL) { |
| 949 | rio_dprintk(RIO_DEBUG_TTY, "Copyout failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 951 | pseterr(EFAULT); |
| 952 | } |
| 953 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 954 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 956 | case TCRIOMBIS: /* Set modem lines */ |
| 957 | case TCRIOMBIC: /* Clear modem lines */ |
| 958 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n"); |
| 959 | if (cmd == TCRIOMBIS) { |
| 960 | uint state; |
| 961 | state = (uint) arg; |
| 962 | PortP->ModemState |= (ushort) state; |
| 963 | PortP->ModemLines = (ulong) arg; |
| 964 | if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL) |
| 965 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIS command failed\n"); |
| 966 | } else { |
| 967 | uint state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 969 | state = (uint) arg; |
| 970 | PortP->ModemState &= ~(ushort) state; |
| 971 | PortP->ModemLines = (ulong) arg; |
| 972 | if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL) |
| 973 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOMBIC command failed\n"); |
| 974 | } |
| 975 | PortP->State |= RIO_BUSY; |
| 976 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 977 | return 0; |
| 978 | |
| 979 | case TCRIOXPON: /* set Xprint ON string */ |
| 980 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPON\n"); |
| 981 | if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOn, MAX_XP_CTRL_LEN) == COPYFAIL) { |
| 982 | rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n"); |
| 983 | PortP->Xprint.XpOn[0] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 985 | pseterr(EFAULT); |
| 986 | } |
| 987 | PortP->Xprint.XpOn[MAX_XP_CTRL_LEN - 1] = '\0'; |
| 988 | PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff); |
| 989 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 990 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 992 | case TCRIOXPOFF: /* set Xprint OFF string */ |
| 993 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPOFF\n"); |
| 994 | if (copyin((int) arg, (caddr_t) PortP->Xprint.XpOff, MAX_XP_CTRL_LEN) == COPYFAIL) { |
| 995 | rio_dprintk(RIO_DEBUG_TTY, "Copyin failed\n"); |
| 996 | PortP->Xprint.XpOff[0] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 998 | pseterr(EFAULT); |
| 999 | } |
| 1000 | PortP->Xprint.XpOff[MAX_XP_CTRL_LEN - 1] = '\0'; |
| 1001 | PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn) + strlen(PortP->Xprint.XpOff); |
| 1002 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1003 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1005 | case TCRIOXPCPS: /* set Xprint CPS string */ |
| 1006 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPCPS\n"); |
| 1007 | if ((uint) arg > p->RIOConf.MaxXpCps || (uint) arg < p->RIOConf.MinXpCps) { |
| 1008 | rio_dprintk(RIO_DEBUG_TTY, "%d CPS out of range\n", arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1010 | pseterr(EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | return 0; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1012 | } |
| 1013 | PortP->Xprint.XpCps = (uint) arg; |
| 1014 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1015 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1017 | case TCRIOXPRINT: |
| 1018 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPRINT\n"); |
| 1019 | if (copyout((caddr_t) & PortP->Xprint, (int) arg, sizeof(struct Xprint)) == COPYFAIL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1021 | pseterr(EFAULT); |
| 1022 | } |
| 1023 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1024 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1026 | case TCRIOIXANYON: |
| 1027 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYON\n"); |
| 1028 | PortP->Config |= RIO_IXANY; |
| 1029 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1030 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1032 | case TCRIOIXANYOFF: |
| 1033 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXANYOFF\n"); |
| 1034 | PortP->Config &= ~RIO_IXANY; |
| 1035 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1036 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1038 | case TCRIOIXONON: |
| 1039 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONON\n"); |
| 1040 | PortP->Config |= RIO_IXON; |
| 1041 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1042 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1044 | case TCRIOIXONOFF: |
| 1045 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOIXONOFF\n"); |
| 1046 | PortP->Config &= ~RIO_IXON; |
| 1047 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1048 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
| 1050 | /* |
| 1051 | ** 15.10.1998 ARG - ESIL 0761 part fix |
| 1052 | ** Added support for CTS and RTS flow control ioctls : |
| 1053 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1054 | case TCRIOCTSFLOWEN: |
| 1055 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n"); |
| 1056 | PortP->Config |= RIO_CTSFLOW; |
| 1057 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1058 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 1059 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1061 | case TCRIOCTSFLOWDIS: |
| 1062 | rio_dprintk(RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n"); |
| 1063 | PortP->Config &= ~RIO_CTSFLOW; |
| 1064 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1065 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 1066 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1068 | case TCRIORTSFLOWEN: |
| 1069 | rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n"); |
| 1070 | PortP->Config |= RIO_RTSFLOW; |
| 1071 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1072 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 1073 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1075 | case TCRIORTSFLOWDIS: |
| 1076 | rio_dprintk(RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n"); |
| 1077 | PortP->Config &= ~RIO_RTSFLOW; |
| 1078 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1079 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
| 1080 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | /* end ESIL 0761 part fix */ |
| 1083 | |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | /* Lynx IOCTLS */ |
| 1088 | switch (cmd) { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1089 | case TIOCSETP: |
| 1090 | case TIOCSETN: |
| 1091 | case OTIOCSETP: |
| 1092 | case OTIOCSETN: |
| 1093 | ioctl_processed++; |
| 1094 | ttyseth(PortP, tp, (struct old_sgttyb *) arg); |
| 1095 | break; |
| 1096 | case TCSETA: |
| 1097 | case TCSETAW: |
| 1098 | case TCSETAF: |
| 1099 | ioctl_processed++; |
| 1100 | rio_dprintk(RIO_DEBUG_TTY, "NON POSIX ioctl\n"); |
| 1101 | ttyseth_pv(PortP, tp, (struct termios *) arg, 0); |
| 1102 | break; |
| 1103 | case TCSETAP: /* posix tcsetattr() */ |
| 1104 | case TCSETAWP: /* posix tcsetattr() */ |
| 1105 | case TCSETAFP: /* posix tcsetattr() */ |
| 1106 | rio_dprintk(RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n"); |
| 1107 | ttyseth_pv(PortP, tp, (struct termios *) arg, 1); |
| 1108 | ioctl_processed++; |
| 1109 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1113 | ** If its any of the commands that require the port to be in the |
| 1114 | ** non-busy state wait until all output has drained |
| 1115 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | if (!ioctl_processed) |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1117 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | case TCSETAW: |
| 1119 | case TCSETAF: |
| 1120 | case TCSETA: |
| 1121 | case TCSBRK: |
| 1122 | #define OLD_POSIX ('x' << 8) |
| 1123 | #define OLD_POSIX_SETA (OLD_POSIX | 2) |
| 1124 | #define OLD_POSIX_SETAW (OLD_POSIX | 3) |
| 1125 | #define OLD_POSIX_SETAF (OLD_POSIX | 4) |
| 1126 | #define NEW_POSIX (('i' << 24) | ('X' << 16)) |
| 1127 | #define NEW_POSIX_SETA (NEW_POSIX | 2) |
| 1128 | #define NEW_POSIX_SETAW (NEW_POSIX | 3) |
| 1129 | #define NEW_POSIX_SETAF (NEW_POSIX | 4) |
| 1130 | case OLD_POSIX_SETA: |
| 1131 | case OLD_POSIX_SETAW: |
| 1132 | case OLD_POSIX_SETAF: |
| 1133 | case NEW_POSIX_SETA: |
| 1134 | case NEW_POSIX_SETAW: |
| 1135 | case NEW_POSIX_SETAF: |
| 1136 | #ifdef TIOCSETP |
| 1137 | case TIOCSETP: |
| 1138 | #endif |
| 1139 | case TIOCSETD: |
| 1140 | case TIOCSETN: |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1141 | rio_dprintk(RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1143 | ** Wait for drain here, at least as far as the double buffer |
| 1144 | ** being empty. |
| 1145 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | /* XXX Does the above comment mean that this has |
| 1147 | still to be implemented? -- REW */ |
| 1148 | /* XXX Is the locking OK together with locking |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1149 | in txenable? (Deadlock?) -- REW */ |
| 1150 | |
| 1151 | RIOTxEnable((char *) PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | break; |
| 1153 | default: |
| 1154 | break; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
| 1157 | old_cflag = tp->tm.c_cflag; |
| 1158 | old_iflag = tp->tm.c_iflag; |
| 1159 | old_oflag = tp->tm.c_oflag; |
| 1160 | oldcook = PortP->CookMode; |
| 1161 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1162 | if (p->RIOHalted) { |
| 1163 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1165 | pseterr(EIO); |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | PortP->FlushCmdBodge = 0; |
| 1170 | |
| 1171 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1172 | ** If the port is locked, and it is reconfigured, we want |
| 1173 | ** to restore the state of the tty structure so the change is NOT |
| 1174 | ** made. |
| 1175 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | if (PortP->Lock) { |
| 1177 | tp->tm.c_iflag = PortP->StoredTty.iflag; |
| 1178 | tp->tm.c_oflag = PortP->StoredTty.oflag; |
| 1179 | tp->tm.c_cflag = PortP->StoredTty.cflag; |
| 1180 | tp->tm.c_lflag = PortP->StoredTty.lflag; |
| 1181 | tp->tm.c_line = PortP->StoredTty.line; |
| 1182 | for (i = 0; i < NCC + 1; i++) |
| 1183 | tp->tm.c_cc[i] = PortP->StoredTty.cc[i]; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1184 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1186 | ** If the port is set to store the parameters, and it is |
| 1187 | ** reconfigured, we want to save the current tty struct so it |
| 1188 | ** may be restored on the next open. |
| 1189 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | if (PortP->Store) { |
| 1191 | PortP->StoredTty.iflag = tp->tm.c_iflag; |
| 1192 | PortP->StoredTty.oflag = tp->tm.c_oflag; |
| 1193 | PortP->StoredTty.cflag = tp->tm.c_cflag; |
| 1194 | PortP->StoredTty.lflag = tp->tm.c_lflag; |
| 1195 | PortP->StoredTty.line = tp->tm.c_line; |
| 1196 | for (i = 0; i < NCC + 1; i++) |
| 1197 | PortP->StoredTty.cc[i] = tp->tm.c_cc[i]; |
| 1198 | } |
| 1199 | } |
| 1200 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1201 | changed = (tp->tm.c_cflag != old_cflag) || (tp->tm.c_iflag != old_iflag) || (tp->tm.c_oflag != old_oflag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
| 1203 | PortP->CookMode = RIOCookMode(tp); /* Set new cooking mode */ |
| 1204 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1205 | rio_dprintk(RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n", changed, PortP->CookMode, oldcook); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
| 1207 | #ifdef MODEM_SUPPORT |
| 1208 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1209 | ** kludge to force CARR_ON if CLOCAL set |
| 1210 | */ |
| 1211 | if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | tp->tm.c_state |= CARR_ON; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1213 | wakeup((caddr_t) & tp->tm.c_canq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | } |
| 1215 | #endif |
| 1216 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1217 | if (p->RIOHalted) { |
| 1218 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1220 | pseterr(EIO); |
| 1221 | return 0; |
| 1222 | } |
| 1223 | /* |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1224 | ** Re-configure if modes or cooking have changed |
| 1225 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | if (changed || oldcook != PortP->CookMode || (ioctl_processed)) { |
| 1227 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1228 | rio_dprintk(RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n"); |
| 1229 | RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
| 1231 | } |
| 1232 | |
| 1233 | if (p->RIOHalted) { |
| 1234 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1235 | RIOClearUp(PortP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | pseterr(EIO); |
| 1237 | return 0; |
| 1238 | } |
| 1239 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
| 1243 | /* |
| 1244 | ttyseth -- set hardware dependent tty settings |
| 1245 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1246 | void ttyseth(PortP, s, sg) |
| 1247 | struct Port *PortP; |
| 1248 | struct ttystatics *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | struct old_sgttyb *sg; |
| 1250 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1251 | struct old_sgttyb *tsg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | struct termios *tp = &s->tm; |
| 1253 | |
| 1254 | tsg = &s->sg; |
| 1255 | |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1256 | if (sg->sg_flags & (EVENP | ODDP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | tp->c_cflag &= PARENB; |
| 1258 | if (sg->sg_flags & EVENP) { |
| 1259 | if (sg->sg_flags & ODDP) { |
| 1260 | tp->c_cflag &= V_CS7; |
| 1261 | tp->c_cflag &= ~PARENB; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1262 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | tp->c_cflag &= V_CS7; |
| 1264 | tp->c_cflag &= PARENB; |
| 1265 | tp->c_cflag &= PARODD; |
| 1266 | } |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1267 | } else if (sg->sg_flags & ODDP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | tp->c_cflag &= V_CS7; |
| 1269 | tp->c_cflag &= PARENB; |
| 1270 | tp->c_cflag &= PARODD; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1271 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | tp->c_cflag &= V_CS7; |
| 1273 | tp->c_cflag &= PARENB; |
| 1274 | } |
| 1275 | } |
| 1276 | /* |
| 1277 | * Use ispeed as the desired speed. Most implementations don't handle |
| 1278 | * separate input and output speeds very well. If the RIO handles this, |
| 1279 | * I will have to use separate sets of flags to store them in the |
| 1280 | * Port structure. |
| 1281 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1282 | if (!sg->sg_ospeed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | sg->sg_ospeed = sg->sg_ispeed; |
| 1284 | else |
| 1285 | sg->sg_ispeed = sg->sg_ospeed; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1286 | if (sg->sg_ispeed > V_EXTB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | sg->sg_ispeed = V_EXTB; |
| 1288 | if (sg->sg_ispeed < V_B0) |
| 1289 | sg->sg_ispeed = V_B0; |
| 1290 | *tsg = *sg; |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1291 | tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int) sg->sg_ispeed]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | ttyseth_pv -- set hardware dependent tty settings using either the |
| 1296 | POSIX termios structure or the System V termio structure. |
| 1297 | sysv = 0 => (POSIX): struct termios *sg |
| 1298 | sysv != 0 => (System V): struct termio *sg |
| 1299 | */ |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1300 | static void ttyseth_pv(PortP, s, sg, sysv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | struct Port *PortP; |
| 1302 | struct ttystatics *s; |
| 1303 | struct termios *sg; |
| 1304 | int sysv; |
| 1305 | { |
Andrew Morton | 8d8706e | 2006-01-11 12:17:49 -0800 | [diff] [blame^] | 1306 | int speed; |
| 1307 | unsigned char csize; |
| 1308 | unsigned char cread; |
| 1309 | unsigned int lcr_flags; |
| 1310 | int ps; |
| 1311 | |
| 1312 | if (sysv) { |
| 1313 | /* sg points to a System V termio structure */ |
| 1314 | csize = ((struct termio *) sg)->c_cflag & CSIZE; |
| 1315 | cread = ((struct termio *) sg)->c_cflag & CREAD; |
| 1316 | speed = conv_vb[((struct termio *) sg)->c_cflag & V_CBAUD]; |
| 1317 | } else { |
| 1318 | /* sg points to a POSIX termios structure */ |
| 1319 | csize = sg->c_cflag & CSIZE; |
| 1320 | cread = sg->c_cflag & CREAD; |
| 1321 | speed = conv_vb[sg->c_cflag & V_CBAUD]; |
| 1322 | } |
| 1323 | if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) { |
| 1324 | s->sg.sg_ispeed = speed; |
| 1325 | s->sg.sg_ospeed = speed; |
| 1326 | s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) | conv_bv[(int) s->sg.sg_ispeed]; |
| 1327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | } |
| 1329 | #endif |