[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / char / rio / riointr.c
blobe42e7b50bf6bf50184ca1e16e4588b442ea2add5
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
23 ** Module : riointr.c
24 ** SID : 1.2
25 ** Last Modified : 11/6/98 10:33:44
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)riointr.c 1.2
30 ** -----------------------------------------------------------------------------
32 #ifdef SCCS_LABELS
33 static char *_riointr_c_sccs_ = "@(#)riointr.c 1.2";
34 #endif
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/tty.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
52 #include <linux/delay.h>
54 #include "linux_compat.h"
55 #include "rio_linux.h"
56 #include "typdef.h"
57 #include "pkt.h"
58 #include "daemon.h"
59 #include "rio.h"
60 #include "riospace.h"
61 #include "top.h"
62 #include "cmdpkt.h"
63 #include "map.h"
64 #include "riotypes.h"
65 #include "rup.h"
66 #include "port.h"
67 #include "riodrvr.h"
68 #include "rioinfo.h"
69 #include "func.h"
70 #include "errors.h"
71 #include "pci.h"
73 #include "parmmap.h"
74 #include "unixrup.h"
75 #include "board.h"
76 #include "host.h"
77 #include "error.h"
78 #include "phb.h"
79 #include "link.h"
80 #include "cmdblk.h"
81 #include "route.h"
82 #include "control.h"
83 #include "cirrus.h"
84 #include "rioioctl.h"
87 static void RIOReceive(struct rio_info *, struct Port *);
90 static char *firstchars (char *p, int nch)
92 static char buf[2][128];
93 static int t=0;
94 t = ! t;
95 memcpy (buf[t], p, nch);
96 buf[t][nch] = 0;
97 return buf[t];
101 #define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask))
102 /* Enable and start the transmission of packets */
103 void
104 RIOTxEnable(en)
105 char * en;
107 struct Port * PortP;
108 struct rio_info *p;
109 struct tty_struct* tty;
110 int c;
111 struct PKT * PacketP;
112 unsigned long flags;
114 PortP = (struct Port *)en;
115 p = (struct rio_info *)PortP->p;
116 tty = PortP->gs.tty;
119 rio_dprintk (RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n",
120 PortP->PortNum, PortP->gs.xmit_cnt);
122 if (!PortP->gs.xmit_cnt) return;
125 /* This routine is an order of magnitude simpler than the specialix
126 version. One of the disadvantages is that this version will send
127 an incomplete packet (usually 64 bytes instead of 72) once for
128 every 4k worth of data. Let's just say that this won't influence
129 performance significantly..... */
131 rio_spin_lock_irqsave(&PortP->portSem, flags);
133 while (can_add_transmit( &PacketP, PortP )) {
134 c = PortP->gs.xmit_cnt;
135 if (c > PKT_MAX_DATA_LEN) c = PKT_MAX_DATA_LEN;
137 /* Don't copy past the end of the source buffer */
138 if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail)
139 c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
141 { int t;
142 t = (c > 10)?10:c;
144 rio_dprintk (RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n",
145 PortP->PortNum, c,
146 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail , t),
147 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail + c-t, t));
149 /* If for one reason or another, we can't copy more data,
150 we're done! */
151 if (c == 0) break;
153 rio_memcpy_toio (PortP->HostP->Caddr, (caddr_t)PacketP->data,
154 PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
155 /* udelay (1); */
157 writeb (c, &(PacketP->len));
158 if (!( PortP->State & RIO_DELETED ) ) {
159 add_transmit ( PortP );
161 ** Count chars tx'd for port statistics reporting
163 if ( PortP->statsGather )
164 PortP->txchars += c;
166 PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
167 PortP->gs.xmit_cnt -= c;
170 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
172 if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2*PKT_MAX_DATA_LEN)) {
173 rio_dprintk (RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....",
174 (int)(PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)),
175 PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
176 if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
177 PortP->gs.tty->ldisc.write_wakeup)
178 (PortP->gs.tty->ldisc.write_wakeup)(PortP->gs.tty);
179 rio_dprintk (RIO_DEBUG_INTR, "(%d/%d)\n",
180 PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
181 wake_up_interruptible(&PortP->gs.tty->write_wait);
188 ** RIO Host Service routine. Does all the work traditionally associated with an
189 ** interrupt.
191 static int RupIntr;
192 static int RxIntr;
193 static int TxIntr;
194 void
195 RIOServiceHost(p, HostP, From)
196 struct rio_info * p;
197 struct Host *HostP;
198 int From;
200 rio_spin_lock (&HostP->HostLock);
201 if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
202 static int t =0;
203 rio_spin_unlock (&HostP->HostLock);
204 if ((t++ % 200) == 0)
205 rio_dprintk (RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int)HostP->Flags);
206 return;
208 rio_spin_unlock (&HostP->HostLock);
210 if ( RWORD( HostP->ParmMapP->rup_intr ) ) {
211 WWORD( HostP->ParmMapP->rup_intr , 0 );
212 p->RIORupCount++;
213 RupIntr++;
214 rio_dprintk (RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP-p->RIOHosts);
215 RIOPollHostCommands(p, HostP );
218 if ( RWORD( HostP->ParmMapP->rx_intr ) ) {
219 int port;
221 WWORD( HostP->ParmMapP->rx_intr , 0 );
222 p->RIORxCount++;
223 RxIntr++;
225 rio_dprintk (RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP-p->RIOHosts);
227 ** Loop through every port. If the port is mapped into
228 ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
229 ** worth checking. If the port isn't open, grab any packets
230 ** hanging on its receive queue and stuff them on the free
231 ** list; check for commands on the way.
233 for ( port=p->RIOFirstPortsBooted;
234 port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
235 struct Port *PortP = p->RIOPortp[port];
236 struct tty_struct *ttyP;
237 struct PKT *PacketP;
240 ** not mapped in - most of the RIOPortp[] information
241 ** has not been set up!
242 ** Optimise: ports come in bundles of eight.
244 if ( !PortP->Mapped ) {
245 port += 7;
246 continue; /* with the next port */
250 ** If the host board isn't THIS host board, check the next one.
251 ** optimise: ports come in bundles of eight.
253 if ( PortP->HostP != HostP ) {
254 port += 7;
255 continue;
259 ** Let us see - is the port open? If not, then don't service it.
261 if ( !( PortP->PortState & PORT_ISOPEN ) ) {
262 continue;
266 ** find corresponding tty structure. The process of mapping
267 ** the ports puts these here.
269 ttyP = PortP->gs.tty;
272 ** Lock the port before we begin working on it.
274 rio_spin_lock(&PortP->portSem);
277 ** Process received data if there is any.
279 if ( can_remove_receive( &PacketP, PortP ) )
280 RIOReceive(p, PortP);
283 ** If there is no data left to be read from the port, and
284 ** it's handshake bit is set, then we must clear the handshake,
285 ** so that that downstream RTA is re-enabled.
287 if ( !can_remove_receive( &PacketP, PortP ) &&
288 ( RWORD( PortP->PhbP->handshake )==PHB_HANDSHAKE_SET ) ) {
290 ** MAGIC! ( Basically, handshake the RX buffer, so that
291 ** the RTAs upstream can be re-enabled. )
293 rio_dprintk (RIO_DEBUG_INTR, "Set RX handshake bit\n");
294 WWORD( PortP->PhbP->handshake,
295 PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET );
297 rio_spin_unlock(&PortP->portSem);
301 if ( RWORD( HostP->ParmMapP->tx_intr ) ) {
302 int port;
304 WWORD( HostP->ParmMapP->tx_intr , 0);
306 p->RIOTxCount++;
307 TxIntr++;
308 rio_dprintk (RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP-p->RIOHosts);
311 ** Loop through every port.
312 ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
313 ** associated ) then it is worth checking.
315 for ( port=p->RIOFirstPortsBooted;
316 port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
317 struct Port *PortP = p->RIOPortp[port];
318 struct tty_struct *ttyP;
319 struct PKT *PacketP;
322 ** not mapped in - most of the RIOPortp[] information
323 ** has not been set up!
325 if ( !PortP->Mapped ) {
326 port += 7;
327 continue; /* with the next port */
331 ** If the host board isn't running, then its data structures
332 ** are no use to us - continue quietly.
334 if ( PortP->HostP != HostP ) {
335 port += 7;
336 continue; /* with the next port */
340 ** Let us see - is the port open? If not, then don't service it.
342 if ( !( PortP->PortState & PORT_ISOPEN ) ) {
343 continue;
346 rio_dprintk (RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
348 ** Lock the port before we begin working on it.
350 rio_spin_lock(&PortP->portSem);
353 ** If we can't add anything to the transmit queue, then
354 ** we need do none of this processing.
356 if ( !can_add_transmit( &PacketP, PortP ) ) {
357 rio_dprintk (RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
358 rio_spin_unlock(&PortP->portSem);
359 continue;
363 ** find corresponding tty structure. The process of mapping
364 ** the ports puts these here.
366 ttyP = PortP->gs.tty;
367 /* If ttyP is NULL, the port is getting closed. Forget about it. */
368 if (!ttyP) {
369 rio_dprintk (RIO_DEBUG_INTR, "no tty, so skipping.\n");
370 rio_spin_unlock(&PortP->portSem);
371 continue;
374 ** If there is more room available we start up the transmit
375 ** data process again. This can be direct I/O, if the cookmode
376 ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
377 ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
378 ** characters via the line discipline. We must always call
379 ** the line discipline,
380 ** so that user input characters can be echoed correctly.
382 ** ++++ Update +++++
383 ** With the advent of double buffering, we now see if
384 ** TxBufferOut-In is non-zero. If so, then we copy a packet
385 ** to the output place, and set it going. If this empties
386 ** the buffer, then we must issue a wakeup( ) on OUT.
387 ** If it frees space in the buffer then we must issue
388 ** a wakeup( ) on IN.
390 ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
391 ** have to send a WFLUSH command down the PHB, to mark the
392 ** end point of a WFLUSH. We also need to clear out any
393 ** data from the double buffer! ( note that WflushFlag is a
394 ** *count* of the number of WFLUSH commands outstanding! )
396 ** ++++ And there's more!
397 ** If an RTA is powered off, then on again, and rebooted,
398 ** whilst it has ports open, then we need to re-open the ports.
399 ** ( reasonable enough ). We can't do this when we spot the
400 ** re-boot, in interrupt time, because the queue is probably
401 ** full. So, when we come in here, we need to test if any
402 ** ports are in this condition, and re-open the port before
403 ** we try to send any more data to it. Now, the re-booted
404 ** RTA will be discarding packets from the PHB until it
405 ** receives this open packet, but don't worry tooo much
406 ** about that. The one thing that is interesting is the
407 ** combination of this effect and the WFLUSH effect!
409 /* For now don't handle RTA reboots. -- REW.
410 Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
411 if ( PortP->MagicFlags ) {
412 #if 1
413 if ( PortP->MagicFlags & MAGIC_REBOOT ) {
415 ** well, the RTA has been rebooted, and there is room
416 ** on its queue to add the open packet that is required.
418 ** The messy part of this line is trying to decide if
419 ** we need to call the Param function as a tty or as
420 ** a modem.
421 ** DONT USE CLOCAL AS A TEST FOR THIS!
423 ** If we can't param the port, then move on to the
424 ** next port.
426 PortP->InUse = NOT_INUSE;
428 rio_spin_unlock(&PortP->portSem);
429 if ( RIOParam(PortP, OPEN, ((PortP->Cor2Copy &
430 (COR2_RTSFLOW|COR2_CTSFLOW ) )==
431 (COR2_RTSFLOW|COR2_CTSFLOW ) ) ?
432 TRUE : FALSE, DONT_SLEEP ) == RIO_FAIL ) {
433 continue; /* with next port */
435 rio_spin_lock(&PortP->portSem);
436 PortP->MagicFlags &= ~MAGIC_REBOOT;
438 #endif
441 ** As mentioned above, this is a tacky hack to cope
442 ** with WFLUSH
444 if ( PortP->WflushFlag ) {
445 rio_dprintk (RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
447 if ( PortP->InUse )
448 rio_dprintk (RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
451 while ( PortP->WflushFlag &&
452 can_add_transmit( &PacketP, PortP ) &&
453 ( PortP->InUse == NOT_INUSE ) ) {
454 int p;
455 struct PktCmd *PktCmdP;
457 rio_dprintk (RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
459 ** make it look just like a WFLUSH command
461 PktCmdP = ( struct PktCmd * )&PacketP->data[0];
463 WBYTE( PktCmdP->Command , WFLUSH );
465 p = PortP->HostPort % ( ushort )PORTS_PER_RTA;
468 ** If second block of ports for 16 port RTA, add 8
469 ** to index 8-15.
471 if ( PortP->SecondBlock )
472 p += PORTS_PER_RTA;
474 WBYTE( PktCmdP->PhbNum, p );
477 ** to make debuggery easier
479 WBYTE( PacketP->data[ 2], 'W' );
480 WBYTE( PacketP->data[ 3], 'F' );
481 WBYTE( PacketP->data[ 4], 'L' );
482 WBYTE( PacketP->data[ 5], 'U' );
483 WBYTE( PacketP->data[ 6], 'S' );
484 WBYTE( PacketP->data[ 7], 'H' );
485 WBYTE( PacketP->data[ 8], ' ' );
486 WBYTE( PacketP->data[ 9], '0'+PortP->WflushFlag );
487 WBYTE( PacketP->data[10], ' ' );
488 WBYTE( PacketP->data[11], ' ' );
489 WBYTE( PacketP->data[12], '\0' );
492 ** its two bytes long!
494 WBYTE( PacketP->len , PKT_CMD_BIT | 2 );
497 ** queue it!
499 if ( !( PortP->State & RIO_DELETED ) ) {
500 add_transmit( PortP );
502 ** Count chars tx'd for port statistics reporting
504 if ( PortP->statsGather )
505 PortP->txchars += 2;
508 if ( --( PortP->WflushFlag ) == 0 ) {
509 PortP->MagicFlags &= ~MAGIC_FLUSH;
512 rio_dprintk (RIO_DEBUG_INTR, "Wflush count now stands at %d\n",
513 PortP->WflushFlag);
515 if ( PortP->MagicFlags & MORE_OUTPUT_EYGOR ) {
516 if ( PortP->MagicFlags & MAGIC_FLUSH ) {
517 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
519 else {
520 if ( !can_add_transmit( &PacketP, PortP ) ) {
521 rio_spin_unlock(&PortP->portSem);
522 continue;
524 rio_spin_unlock(&PortP->portSem);
525 RIOTxEnable((char *)PortP);
526 rio_spin_lock(&PortP->portSem);
527 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
534 ** If we can't add anything to the transmit queue, then
535 ** we need do none of the remaining processing.
537 if (!can_add_transmit( &PacketP, PortP ) ) {
538 rio_spin_unlock(&PortP->portSem);
539 continue;
542 rio_spin_unlock(&PortP->portSem);
543 RIOTxEnable((char *)PortP);
549 ** Routine for handling received data for clist drivers.
550 ** NB: Called with the tty locked. The spl from the lockb( ) is passed.
551 ** we return the ttySpl level that we re-locked at.
553 static void
554 RIOReceive(p, PortP)
555 struct rio_info * p;
556 struct Port * PortP;
558 struct tty_struct *TtyP;
559 register ushort transCount;
560 struct PKT *PacketP;
561 register uint DataCnt;
562 uchar * ptr;
563 int copied =0;
565 static int intCount, RxIntCnt;
568 ** The receive data process is to remove packets from the
569 ** PHB until there aren't any more or the current cblock
570 ** is full. When this occurs, there will be some left over
571 ** data in the packet, that we must do something with.
572 ** As we haven't unhooked the packet from the read list
573 ** yet, we can just leave the packet there, having first
574 ** made a note of how far we got. This means that we need
575 ** a pointer per port saying where we start taking the
576 ** data from - this will normally be zero, but when we
577 ** run out of space it will be set to the offset of the
578 ** next byte to copy from the packet data area. The packet
579 ** length field is decremented by the number of bytes that
580 ** we succesfully removed from the packet. When this reaches
581 ** zero, we reset the offset pointer to be zero, and free
582 ** the packet from the front of the queue.
585 intCount++;
587 TtyP = PortP->gs.tty;
588 if (!TtyP) {
589 rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
590 return;
593 if (PortP->State & RIO_THROTTLE_RX) {
594 rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
595 return;
598 if ( PortP->State & RIO_DELETED )
600 while ( can_remove_receive( &PacketP, PortP ) )
602 remove_receive( PortP );
603 put_free_end( PortP->HostP, PacketP );
606 else
609 ** loop, just so long as:
610 ** i ) there's some data ( i.e. can_remove_receive )
611 ** ii ) we haven't been blocked
612 ** iii ) there's somewhere to put the data
613 ** iv ) we haven't outstayed our welcome
615 transCount = 1;
616 while ( can_remove_receive(&PacketP, PortP)
617 && transCount)
619 #ifdef STATS
620 PortP->Stat.RxIntCnt++;
621 #endif /* STATS */
622 RxIntCnt++;
625 ** check that it is not a command!
627 if ( PacketP->len & PKT_CMD_BIT ) {
628 rio_dprintk (RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
629 /* rio_dprint(RIO_DEBUG_INTR, (" sysport = %d\n", p->RIOPortp->PortNum)); */
630 rio_dprintk (RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit);
631 rio_dprintk (RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port);
632 rio_dprintk (RIO_DEBUG_INTR, " src_unit = %d\n", PacketP->src_unit);
633 rio_dprintk (RIO_DEBUG_INTR, " src_port = %d\n", PacketP->src_port);
634 rio_dprintk (RIO_DEBUG_INTR, " len = %d\n", PacketP->len);
635 rio_dprintk (RIO_DEBUG_INTR, " control = %d\n", PacketP->control);
636 rio_dprintk (RIO_DEBUG_INTR, " csum = %d\n", PacketP->csum);
637 rio_dprintk (RIO_DEBUG_INTR, " data bytes: ");
638 for ( DataCnt=0; DataCnt<PKT_MAX_DATA_LEN; DataCnt++ )
639 rio_dprintk (RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]);
640 remove_receive( PortP );
641 put_free_end( PortP->HostP, PacketP );
642 continue; /* with next packet */
646 ** How many characters can we move 'upstream' ?
648 ** Determine the minimum of the amount of data
649 ** available and the amount of space in which to
650 ** put it.
652 ** 1. Get the packet length by masking 'len'
653 ** for only the length bits.
654 ** 2. Available space is [buffer size] - [space used]
656 ** Transfer count is the minimum of packet length
657 ** and available space.
660 transCount = min_t(unsigned int, PacketP->len & PKT_LEN_MASK,
661 TTY_FLIPBUF_SIZE - TtyP->flip.count);
662 rio_dprintk (RIO_DEBUG_REC, "port %d: Copy %d bytes\n",
663 PortP->PortNum, transCount);
665 ** To use the following 'kkprintfs' for debugging - change the '#undef'
666 ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
667 ** driver).
669 #undef ___DEBUG_IT___
670 #ifdef ___DEBUG_IT___
671 kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ",
672 intCount,
673 RxIntCnt,
674 PortP->PortNum,
675 TtyP->rxqueue.count,
676 transCount,
677 TtyP->flags );
678 #endif
679 ptr = (uchar *) PacketP->data + PortP->RxDataStart;
681 rio_memcpy_fromio (TtyP->flip.char_buf_ptr, ptr, transCount);
682 memset(TtyP->flip.flag_buf_ptr, TTY_NORMAL, transCount);
684 #ifdef STATS
686 ** keep a count for statistical purposes
688 PortP->Stat.RxCharCnt += transCount;
689 #endif
690 PortP->RxDataStart += transCount;
691 PacketP->len -= transCount;
692 copied += transCount;
693 TtyP->flip.count += transCount;
694 TtyP->flip.char_buf_ptr += transCount;
695 TtyP->flip.flag_buf_ptr += transCount;
698 #ifdef ___DEBUG_IT___
699 kkprintf("T:%d L:%d\n", DataCnt, PacketP->len );
700 #endif
702 if ( PacketP->len == 0 )
705 ** If we have emptied the packet, then we can
706 ** free it, and reset the start pointer for
707 ** the next packet.
709 remove_receive( PortP );
710 put_free_end( PortP->HostP, PacketP );
711 PortP->RxDataStart = 0;
712 #ifdef STATS
714 ** more lies ( oops, I mean statistics )
716 PortP->Stat.RxPktCnt++;
717 #endif /* STATS */
721 if (copied) {
722 rio_dprintk (RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
723 tty_flip_buffer_push (TtyP);
726 return;
729 #ifdef FUTURE_RELEASE
731 ** The proc routine called by the line discipline to do the work for it.
732 ** The proc routine works hand in hand with the interrupt routine.
735 riotproc(p, tp, cmd, port)
736 struct rio_info * p;
737 register struct ttystatics *tp;
738 int cmd;
739 int port;
741 register struct Port *PortP;
742 int SysPort;
743 struct PKT *PacketP;
745 SysPort = port; /* Believe me, it works. */
747 if ( SysPort < 0 || SysPort >= RIO_PORTS ) {
748 rio_dprintk (RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n",SysPort);
749 return 0;
751 PortP = p->RIOPortp[SysPort];
753 if ((uint)PortP->PhbP < (uint)PortP->Caddr ||
754 (uint)PortP->PhbP >= (uint)PortP->Caddr+SIXTY_FOUR_K ) {
755 rio_dprintk (RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n",
756 SysPort);
757 rio_dprintk (RIO_DEBUG_INTR, " PortP = 0x%x\n",PortP);
758 rio_dprintk (RIO_DEBUG_INTR, " PortP->PhbP = 0x%x\n",PortP->PhbP);
759 rio_dprintk (RIO_DEBUG_INTR, " PortP->Caddr = 0x%x\n",PortP->PhbP);
760 rio_dprintk (RIO_DEBUG_INTR, " PortP->HostPort = 0x%x\n",PortP->HostPort);
761 return 0;
764 switch(cmd) {
765 case T_WFLUSH:
766 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH\n");
768 ** Because of the spooky way the RIO works, we don't need
769 ** to issue a flush command on any of the SET*F commands,
770 ** as that causes trouble with getty and login, which issue
771 ** these commands to incur a READ flush, and rely on the fact
772 ** that the line discipline does a wait for drain for them.
773 ** As the rio doesn't wait for drain, the write flush would
774 ** destroy the Password: prompt. This isn't very friendly, so
775 ** here we only issue a WFLUSH command if we are in the interrupt
776 ** routine, or we aren't executing a SET*F command.
778 if ( PortP->HostP->InIntr || !PortP->FlushCmdBodge ) {
780 ** form a wflush packet - 1 byte long, no data
782 if ( PortP->State & RIO_DELETED ) {
783 rio_dprintk (RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
785 else {
786 if ( RIOPreemptiveCmd(p, PortP, WFLUSH ) == RIO_FAIL ) {
787 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
789 else
790 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command\n");
793 ** WFLUSH operation - flush the data!
795 PortP->TxBufferIn = PortP->TxBufferOut = 0;
797 else {
798 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
801 ** sort out the line discipline
803 if (PortP->CookMode == COOK_WELL)
804 goto start;
805 break;
807 case T_RESUME:
808 rio_dprintk (RIO_DEBUG_INTR, "T_RESUME\n");
810 ** send pre-emptive resume packet
812 if ( PortP->State & RIO_DELETED ) {
813 rio_dprintk (RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
815 else {
816 if ( RIOPreemptiveCmd(p, PortP, RESUME ) == RIO_FAIL ) {
817 rio_dprintk (RIO_DEBUG_INTR, "T_RESUME Command failed\n");
821 ** and re-start the sender software!
823 if (PortP->CookMode == COOK_WELL)
824 goto start;
825 break;
827 case T_TIME:
828 rio_dprintk (RIO_DEBUG_INTR, "T_TIME\n");
830 ** T_TIME is called when xDLY is set in oflags and
831 ** the line discipline timeout has expired. It's
832 ** function in life is to clear the TIMEOUT flag
833 ** and to re-start output to the port.
836 ** Fall through and re-start output
838 case T_OUTPUT:
839 start:
840 if ( PortP->MagicFlags & MAGIC_FLUSH ) {
841 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
842 return 0;
844 RIOTxEnable((char *)PortP);
845 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
846 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n");*/
847 break;
849 case T_SUSPEND:
850 rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND\n");
852 ** send a suspend pre-emptive packet.
854 if ( PortP->State & RIO_DELETED ) {
855 rio_dprintk (RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
857 else {
858 if ( RIOPreemptiveCmd(p, PortP, SUSPEND ) == RIO_FAIL ) {
859 rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
863 ** done!
865 break;
867 case T_BLOCK:
868 rio_dprintk (RIO_DEBUG_INTR, "T_BLOCK\n");
869 break;
871 case T_RFLUSH:
872 rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH\n");
873 if ( PortP->State & RIO_DELETED ) {
874 rio_dprintk (RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
875 PortP->RxDataStart = 0;
877 else {
878 if ( RIOPreemptiveCmd( p, PortP, RFLUSH ) == RIO_FAIL ) {
879 rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
880 return 0;
882 PortP->RxDataStart = 0;
883 while ( can_remove_receive(&PacketP, PortP) ) {
884 remove_receive(PortP);
885 ShowPacket(DBG_PROC, PacketP );
886 put_free_end(PortP->HostP, PacketP );
888 if ( PortP->PhbP->handshake == PHB_HANDSHAKE_SET ) {
890 ** MAGIC!
892 rio_dprintk (RIO_DEBUG_INTR, "Set receive handshake bit\n");
893 PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
896 break;
897 /* FALLTHROUGH */
898 case T_UNBLOCK:
899 rio_dprintk (RIO_DEBUG_INTR, "T_UNBLOCK\n");
901 ** If there is any data to receive set a timeout to service it.
903 RIOReceive(p, PortP);
904 break;
906 case T_BREAK:
907 rio_dprintk (RIO_DEBUG_INTR, "T_BREAK\n");
909 ** Send a break command. For Sys V
910 ** this is a timed break, so we
911 ** send a SBREAK[time] packet
914 ** Build a BREAK command
916 if ( PortP->State & RIO_DELETED ) {
917 rio_dprintk (RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
919 else {
920 if (RIOShortCommand(PortP,SBREAK,2,
921 p->RIOConf.BreakInterval)==RIO_FAIL) {
922 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
927 ** done!
929 break;
931 case T_INPUT:
932 rio_dprintk (RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
933 break;
934 case T_PARM:
935 rio_dprintk (RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
936 break;
938 case T_SWTCH:
939 rio_dprintk (RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
940 break;
942 default:
943 rio_dprintk (RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n",cmd);
946 ** T_OUTPUT returns without passing through this point!
948 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n");*/
949 return(0);
951 #endif