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