blob: 5894a25b01137f5d623d3f3d887cd8b77dd39829 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
33static 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 Morton8d8706e2006-01-11 12:17:49 -080093static void ttyseth_pv(struct Port *, struct ttystatics *, struct termios *sg, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#endif
95
96static void RIOClearUp(struct Port *PortP);
Andrew Morton8d8706e2006-01-11 12:17:49 -080097int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99#if 0
100static int RIOCookMode(struct ttystatics *);
101#endif
102
Andrew Morton8d8706e2006-01-11 12:17:49 -0800103extern int conv_vb[]; /* now defined in ttymgr.c */
104extern int conv_bv[]; /* now defined in ttymgr.c */
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/*
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 Morton8d8706e2006-01-11 12:17:49 -0800118static 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 Torvalds1da177e2005-04-16 15:20:36 -0700137};
138#endif
139
140
141extern struct rio_info *p;
142
143
Andrew Morton8d8706e2006-01-11 12:17:49 -0800144int riotopen(struct tty_struct *tty, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 register uint SysPort;
147 int Modem;
148 int repeat_this = 250;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800149 struct Port *PortP; /* pointer to the port structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned long flags;
151 int retval = 0;
152
Andrew Morton8d8706e2006-01-11 12:17:49 -0800153 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
156 is going to oops.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800157 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 tty->driver_data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Andrew Morton8d8706e2006-01-11 12:17:49 -0800160 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 Torvalds1da177e2005-04-16 15:20:36 -0700165 pseterr(ENXIO);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800166 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 return -ENXIO;
168 }
169
Andrew Morton8d8706e2006-01-11 12:17:49 -0800170 rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n", SysPort, Modem ? "Modem" : "tty", p->RIOPortp[SysPort]->Mapped);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700178 if (SysPort >= RIO_PORTS) { /* out of range ? */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800179 rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 pseterr(ENXIO);
181 func_exit();
182 return -ENXIO;
183 }
184
185 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800186 ** Grab pointer to the port stucture
187 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 PortP = p->RIOPortp[SysPort]; /* Get control struc */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800189 rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP);
190 if (!PortP->Mapped) { /* we aren't mapped yet! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800192 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700197 pseterr(ENXIO);
198 return -ENXIO;
199 }
200
201 tty->driver_data = PortP;
202
203 PortP->gs.tty = tty;
204 PortP->gs.count++;
205
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206 rio_dprintk(RIO_DEBUG_TTY, "%d bytes in tx buffer\n", PortP->gs.xmit_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Andrew Morton8d8706e2006-01-11 12:17:49 -0800208 retval = gs_init_port(&PortP->gs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 if (retval) {
210 PortP->gs.count--;
211 return -ENXIO;
212 }
213 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800214 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700219 pseterr(ENXIO);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800220 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 return -ENXIO;
222 }
223
224 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800225 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700229#if 0
230 if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
231 if (PortP->WaitUntilBooted) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800232 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 do {
234 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235 rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
236 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return -EINTR;
238 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800239 if (repeat_this-- <= 0) {
240 rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
241 RIOPreemptiveCmd(p, PortP, FCLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 pseterr(EINTR);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return -EIO;
245 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800246 } while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
247 rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800249 rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 pseterr(ENXIO);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800251 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return 0;
253 }
254 }
255#else
256 /* I find the above code a bit hairy. I find the below code
Andrew Morton8d8706e2006-01-11 12:17:49 -0800257 easier to read and shorter. Now, if it works too that would
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 be great... -- REW
Andrew Morton8d8706e2006-01-11 12:17:49 -0800259 */
260 rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800262 if (!PortP->WaitUntilBooted) {
263 rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
264 func_exit();
265 return -ENXIO;
266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Andrew Morton8d8706e2006-01-11 12:17:49 -0800268 /* 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 Torvalds1da177e2005-04-16 15:20:36 -0700282 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
285#if 0
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286 tp = PortP->TtyP; /* get tty struct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287#endif
288 rio_spin_lock_irqsave(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800289 if (p->RIOHalted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 goto bombout;
291 }
292#if 0
293 retval = gs_init_port(&PortP->gs);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800294 if (retval) {
295 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 return retval;
297 }
298#endif
299
300 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800301 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700310 retval = -EINTR;
311 goto bombout;
312 }
313 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
314 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800315 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 retval = -EINTR;
317 goto bombout;
318 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
Andrew Morton8d8706e2006-01-11 12:17:49 -0800322 if (!PortP->Mapped) {
323 rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
325 retval = -ENXIO;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800326 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return retval;
328 }
329
Andrew Morton8d8706e2006-01-11 12:17:49 -0800330 if (p->RIOHalted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 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 Morton8d8706e2006-01-11 12:17:49 -0800341 if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
342 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344
345 if (!(PortP->firstOpen)) { /* First time ? */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346 rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n");
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 PortP->firstOpen++;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 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 Morton8d8706e2006-01-11 12:17:49 -0800358 ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359#endif
360
361 /* Someone explain to me why this delay/config is
Andrew Morton8d8706e2006-01-11 12:17:49 -0800362 here. If I read the docs correctly the "open"
363 command piggybacks the parameters immediately.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800365 RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP); /* Open the port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#if 0
367 /* This delay of 1 second was annoying. I removed it. -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 RIODelay(PortP, HUNDRED_MS * 10);
369 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP); /* Config the port */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370#endif
371 rio_spin_lock_irqsave(&PortP->portSem, flags);
372
373 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800374 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700378/*
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 Morton8d8706e2006-01-11 12:17:49 -0800394 rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
395 RIOPreemptiveCmd(p, PortP, FCLOSE);
396 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return -EINTR;
398 }
399 rio_spin_lock_irqsave(&PortP->portSem, flags);
400 }
401
Andrew Morton8d8706e2006-01-11 12:17:49 -0800402 if (p->RIOHalted) {
403 retval = -EIO;
404 bombout:
405 /* RIOClearUp( PortP ); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
407 return retval;
408 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800409 rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800411#ifdef MODEM_SUPPORT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (Modem) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800415 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700421 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800422 tp->tm.c_state |= CARR_ON;
423 wakeup((caddr_t) &tp->tm.c_canq);
424 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 PortP->State |= RIO_CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800426 wake_up_interruptible(&PortP->gs.open_wait);
427 } else { /* no carrier - wait for DCD */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Andrew Morton8d8706e2006-01-11 12:17:49 -0800429 /*
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 Torvalds1da177e2005-04-16 15:20:36 -0700436 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800437 PortP->gs.tty->termios->c_state |= WOPEN;
438 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 PortP->State |= RIO_WOPEN;
440 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441 if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#if 0
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 if (sleep((caddr_t) & tp->tm.c_canqo, TTIPRI | PCATCH))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800445 {
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 Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462 PortP->State &= ~RIO_WOPEN;
463 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800464 if (p->RIOHalted)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 goto bombout;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 PortP->State |= RIO_MOPEN;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800468 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#endif
470 {
471 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 ** ACTION
473 ** Direct line open - force carrier (will probably mean
474 ** that sleeping Modem line fubar)
475 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 PortP->State |= RIO_LOPEN;
477 }
478
Andrew Morton8d8706e2006-01-11 12:17:49 -0800479 if (p->RIOHalted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 goto bombout;
481 }
482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 rio_dprintk(RIO_DEBUG_TTY, "high level open done\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485#ifdef STATS
486 PortP->Stat.OpenCnt++;
487#endif
488 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800489 ** Count opens for port statistics reporting
490 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (PortP->statsGather)
492 PortP->opens++;
493
494 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495 rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n");
496 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 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 Morton8d8706e2006-01-11 12:17:49 -0800505*/
506int riotclose(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
508#if 0
509 register uint SysPort = dev;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 struct ttystatics *tp; /* pointer to our ttystruct */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#endif
M.Baris Demirayd2a457c2005-06-25 14:58:40 -0700512 struct Port *PortP = ptr; /* pointer to the port structure */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 int deleted = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 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 Demirayd2a457c2005-06-25 14:58:40 -0700517 unsigned long end_time;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 struct tty_struct *tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 unsigned long flags;
520 int Modem;
M.Baris Demirayd2a457c2005-06-25 14:58:40 -0700521 int rv = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800522
523 rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 /* PortP = p->RIOPortp[SysPort]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800526 rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%x\n", (int) PortP);
527 /* tp = PortP->TtyP; *//* Get tty */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 tty = PortP->gs.tty;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%x\n", (int) tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 if (PortP->gs.closing_wait)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 end_time = jiffies + PortP->gs.closing_wait;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 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 Morton8d8706e2006-01-11 12:17:49 -0800541
542 RIODelay(PortP, HUNDRED_MS * 10); /* To flush the cache */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#endif
544 rio_spin_lock_irqsave(&PortP->portSem, flags);
545
546 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 ** Setting this flag will make any process trying to open
548 ** this port block until we are complete closing it.
549 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 PortP->State |= RIO_CLOSING;
551
Andrew Morton8d8706e2006-01-11 12:17:49 -0800552 if ((PortP->State & RIO_DELETED)) {
553 rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 deleted = 1;
555 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556
557 if (p->RIOHalted) {
558 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 rv = -EIO;
560 goto close_end;
561 }
562
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563 rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800565 ** clear the open bits for this device
566 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
568 PortP->State &= ~RIO_CARR_ON;
569 PortP->ModemState &= ~MSVR1_CD;
570 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800571 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700578 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700583 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 Morton8d8706e2006-01-11 12:17:49 -0800590 rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 PortP->State &= ~RIO_DYNOROD;
593
594 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800595 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700600
601 if (!deleted)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 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 Torvalds1da177e2005-04-16 15:20:36 -0700618 rio_spin_lock_irqsave(&PortP->portSem, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 PortP->TxBufferIn = PortP->TxBufferOut = 0;
622 repeat_this = 0xff;
623
624 PortP->InUse = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800625 if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700631 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 Morton8d8706e2006-01-11 12:17:49 -0800638 if (p->RIOHalted) {
639 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 goto close_end;
641 }
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* 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 Demirayd2a457c2005-06-25 14:58:40 -0700647 RIOPreemptiveCmd(p, PortP, FCLOSE);
648 goto close_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650
651 if (!deleted)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800652 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 Torvalds1da177e2005-04-16 15:20:36 -0700660
Andrew Morton8d8706e2006-01-11 12:17:49 -0800661 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 Torvalds1da177e2005-04-16 15:20:36 -0700670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 rio_spin_lock_irqsave(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800672 rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try);
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* 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 Morton8d8706e2006-01-11 12:17:49 -0800680 PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682#ifdef STATS
683 PortP->Stat.CloseCnt++;
684#endif
685 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800686 ** Count opens for port statistics reporting
687 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (PortP->statsGather)
689 PortP->closes++;
690
Andrew Morton8d8706e2006-01-11 12:17:49 -0800691 close_end:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 /* 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 Morton8d8706e2006-01-11 12:17:49 -0800696 */
697 PortP->State &= ~(RIO_CLOSING | RIO_DELETED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (PortP->firstOpen)
699 PortP->firstOpen--;
700 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800701 rio_dprintk(RIO_DEBUG_TTY, "Return from close\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 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 Morton8d8706e2006-01-11 12:17:49 -0800714static int RIOCookMode(struct ttystatics *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
716 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800717 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700723
724#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800725 CheckTtyP(tp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726#endif
727 if (!(tp->tm.c_oflag & OPOST)) /* No post processing */
728 return COOK_RAW; /* Raw mode o/p */
729
Andrew Morton8d8706e2006-01-11 12:17:49 -0800730 if (tp->tm.c_lflag & XCASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 return COOK_WELL; /* Use line disc */
732
Andrew Morton8d8706e2006-01-11 12:17:49 -0800733 if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return COOK_WELL; /* Use line disc for strange modes */
735
Andrew Morton8d8706e2006-01-11 12:17:49 -0800736 if (tp->tm.c_oflag == OPOST) /* If only OPOST is set, do RAW */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return COOK_RAW;
738
739 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800740 ** So, we need to output process!
741 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return COOK_MEDIUM;
743}
744#endif
745
Andrew Morton8d8706e2006-01-11 12:17:49 -0800746static void RIOClearUp(PortP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747struct Port *PortP;
748{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800749 rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n");
750 PortP->Config = 0; /* Direct semaphore */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 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 Morton8d8706e2006-01-11 12:17:49 -0800757 PortP->MagicFlags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 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 Morton8d8706e2006-01-11 12:17:49 -0800772int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 PKT *PacketP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 int retries = 20; /* at 10 per second -> 2 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 unsigned long flags;
777
Andrew Morton8d8706e2006-01-11 12:17:49 -0800778 rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 CheckPortP(PortP);
781 if (len < 1 || len > 2)
782 cprintf(("STUPID LENGTH %d\n", len));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783#endif
784
Andrew Morton8d8706e2006-01-11 12:17:49 -0800785 if (PortP->State & RIO_DELETED) {
786 rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return RIO_FAIL;
788 }
789 rio_spin_lock_irqsave(&PortP->portSem, flags);
790
791 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800792 ** 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 Torvalds1da177e2005-04-16 15:20:36 -0700797 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 Morton8d8706e2006-01-11 12:17:49 -0800806 if (PortP->State & RIO_DELETED) {
807 rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
809 return RIO_FAIL;
810 }
811
Andrew Morton8d8706e2006-01-11 12:17:49 -0800812 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 Torvalds1da177e2005-04-16 15:20:36 -0700814 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
815 if (retries-- <= 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800816 rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 return RIO_FAIL;
818 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800819 if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return RIO_FAIL;
821 }
822 rio_spin_lock_irqsave(&PortP->portSem, flags);
823 }
824
Andrew Morton8d8706e2006-01-11 12:17:49 -0800825 if (p->RIOHalted) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
827 return RIO_FAIL;
828 }
829
830 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800831 ** set the command byte and the argument byte
832 */
833 WBYTE(PacketP->data[0], command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Andrew Morton8d8706e2006-01-11 12:17:49 -0800835 if (len == 2)
836 WBYTE(PacketP->data[1], arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 ** set the length of the packet and set the command bit.
840 */
841 WBYTE(PacketP->len, PKT_CMD_BIT | len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 add_transmit(PortP);
844 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800845 ** Count characters transmitted for port statistics reporting
846 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 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 Morton8d8706e2006-01-11 12:17:49 -0800860int riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800862 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 Torvalds1da177e2005-04-16 15:20:36 -0700875
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 rio_dprintk(RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n", SysPort, cmd, arg, Modem ? "Modem" : "tty");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Andrew Morton8d8706e2006-01-11 12:17:49 -0800878 if (SysPort >= RIO_PORTS) {
879 rio_dprintk(RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 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 Morton8d8706e2006-01-11 12:17:49 -0800892 if (PortP->State & RIO_DELETED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
894 return -EIO;
895 }
896
897
Andrew Morton8d8706e2006-01-11 12:17:49 -0800898 if (p->RIOHalted) {
899 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
901 return -EIO;
902 }
903
904 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800905 ** Count ioctls for port statistics reporting
906 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (PortP->statsGather)
908 PortP->ioctls++;
909
910 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800911 ** Specialix RIO Ioctl calls
912 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 switch (cmd) {
914
Andrew Morton8d8706e2006-01-11 12:17:49 -0800915 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 Torvalds1da177e2005-04-16 15:20:36 -0700934
Andrew Morton8d8706e2006-01-11 12:17:49 -0800935 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 Torvalds1da177e2005-04-16 15:20:36 -0700941
Andrew Morton8d8706e2006-01-11 12:17:49 -0800942 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 Torvalds1da177e2005-04-16 15:20:36 -0700950 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800951 pseterr(EFAULT);
952 }
953 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
954 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Morton8d8706e2006-01-11 12:17:49 -0800956 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 Torvalds1da177e2005-04-16 15:20:36 -0700968
Andrew Morton8d8706e2006-01-11 12:17:49 -0800969 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 Torvalds1da177e2005-04-16 15:20:36 -0700984 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800985 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 Torvalds1da177e2005-04-16 15:20:36 -0700991
Andrew Morton8d8706e2006-01-11 12:17:49 -0800992 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 Torvalds1da177e2005-04-16 15:20:36 -0700997 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800998 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 Torvalds1da177e2005-04-16 15:20:36 -07001004
Andrew Morton8d8706e2006-01-11 12:17:49 -08001005 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 Torvalds1da177e2005-04-16 15:20:36 -07001009 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001010 pseterr(EINVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001012 }
1013 PortP->Xprint.XpCps = (uint) arg;
1014 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1015 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Andrew Morton8d8706e2006-01-11 12:17:49 -08001017 case TCRIOXPRINT:
1018 rio_dprintk(RIO_DEBUG_TTY, "TCRIOXPRINT\n");
1019 if (copyout((caddr_t) & PortP->Xprint, (int) arg, sizeof(struct Xprint)) == COPYFAIL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001021 pseterr(EFAULT);
1022 }
1023 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1024 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Andrew Morton8d8706e2006-01-11 12:17:49 -08001026 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 Torvalds1da177e2005-04-16 15:20:36 -07001031
Andrew Morton8d8706e2006-01-11 12:17:49 -08001032 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 Torvalds1da177e2005-04-16 15:20:36 -07001037
Andrew Morton8d8706e2006-01-11 12:17:49 -08001038 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 Torvalds1da177e2005-04-16 15:20:36 -07001043
Andrew Morton8d8706e2006-01-11 12:17:49 -08001044 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 Torvalds1da177e2005-04-16 15:20:36 -07001049
1050/*
1051** 15.10.1998 ARG - ESIL 0761 part fix
1052** Added support for CTS and RTS flow control ioctls :
1053*/
Andrew Morton8d8706e2006-01-11 12:17:49 -08001054 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 Torvalds1da177e2005-04-16 15:20:36 -07001060
Andrew Morton8d8706e2006-01-11 12:17:49 -08001061 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 Torvalds1da177e2005-04-16 15:20:36 -07001067
Andrew Morton8d8706e2006-01-11 12:17:49 -08001068 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 Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Morton8d8706e2006-01-11 12:17:49 -08001075 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 Torvalds1da177e2005-04-16 15:20:36 -07001081
1082/* end ESIL 0761 part fix */
1083
1084 }
1085
1086
1087 /* Lynx IOCTLS */
1088 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001089 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 Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111
1112 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001113 ** 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 Torvalds1da177e2005-04-16 15:20:36 -07001116 if (!ioctl_processed)
Andrew Morton8d8706e2006-01-11 12:17:49 -08001117 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 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 Morton8d8706e2006-01-11 12:17:49 -08001141 rio_dprintk(RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001143 ** Wait for drain here, at least as far as the double buffer
1144 ** being empty.
1145 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 /* 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 Morton8d8706e2006-01-11 12:17:49 -08001149 in txenable? (Deadlock?) -- REW */
1150
1151 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 break;
1153 default:
1154 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
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 Morton8d8706e2006-01-11 12:17:49 -08001162 if (p->RIOHalted) {
1163 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1165 pseterr(EIO);
1166 return 0;
1167 }
1168
1169 PortP->FlushCmdBodge = 0;
1170
1171 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001172 ** 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 Torvalds1da177e2005-04-16 15:20:36 -07001176 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 Morton8d8706e2006-01-11 12:17:49 -08001184 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001186 ** 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 Torvalds1da177e2005-04-16 15:20:36 -07001190 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 Morton8d8706e2006-01-11 12:17:49 -08001201 changed = (tp->tm.c_cflag != old_cflag) || (tp->tm.c_iflag != old_iflag) || (tp->tm.c_oflag != old_oflag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
1203 PortP->CookMode = RIOCookMode(tp); /* Set new cooking mode */
1204
Andrew Morton8d8706e2006-01-11 12:17:49 -08001205 rio_dprintk(RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n", changed, PortP->CookMode, oldcook);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
1207#ifdef MODEM_SUPPORT
1208 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001209 ** kludge to force CARR_ON if CLOCAL set
1210 */
1211 if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 tp->tm.c_state |= CARR_ON;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001213 wakeup((caddr_t) & tp->tm.c_canq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 }
1215#endif
1216
Andrew Morton8d8706e2006-01-11 12:17:49 -08001217 if (p->RIOHalted) {
1218 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
1220 pseterr(EIO);
1221 return 0;
1222 }
1223 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -08001224 ** Re-configure if modes or cooking have changed
1225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 if (changed || oldcook != PortP->CookMode || (ioctl_processed)) {
1227 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001228 rio_dprintk(RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
1229 RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 rio_spin_lock_irqsave(&PortP->portSem, flags);
1231 }
1232
1233 if (p->RIOHalted) {
1234 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001235 RIOClearUp(PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 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 Morton8d8706e2006-01-11 12:17:49 -08001246void ttyseth(PortP, s, sg)
1247struct Port *PortP;
1248struct ttystatics *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249struct old_sgttyb *sg;
1250{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001251 struct old_sgttyb *tsg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 struct termios *tp = &s->tm;
1253
1254 tsg = &s->sg;
1255
Andrew Morton8d8706e2006-01-11 12:17:49 -08001256 if (sg->sg_flags & (EVENP | ODDP)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 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 Morton8d8706e2006-01-11 12:17:49 -08001262 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 tp->c_cflag &= V_CS7;
1264 tp->c_cflag &= PARENB;
1265 tp->c_cflag &= PARODD;
1266 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001267 } else if (sg->sg_flags & ODDP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 tp->c_cflag &= V_CS7;
1269 tp->c_cflag &= PARENB;
1270 tp->c_cflag &= PARODD;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001271 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 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 Morton8d8706e2006-01-11 12:17:49 -08001282 if (!sg->sg_ospeed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 sg->sg_ospeed = sg->sg_ispeed;
1284 else
1285 sg->sg_ispeed = sg->sg_ospeed;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001286 if (sg->sg_ispeed > V_EXTB)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 sg->sg_ispeed = V_EXTB;
1288 if (sg->sg_ispeed < V_B0)
1289 sg->sg_ispeed = V_B0;
1290 *tsg = *sg;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001291 tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int) sg->sg_ispeed];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292}
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 Morton8d8706e2006-01-11 12:17:49 -08001300static void ttyseth_pv(PortP, s, sg, sysv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301struct Port *PortP;
1302struct ttystatics *s;
1303struct termios *sg;
1304int sysv;
1305{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001306 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 Torvalds1da177e2005-04-16 15:20:36 -07001328}
1329#endif