2 ** -----------------------------------------------------------------------------
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.
25 ** Last Modified : 11/6/98 10:33:44
26 ** Retrieved : 11/6/98 10:33:49
28 ** ident @(#)riointr.c 1.2
30 ** -----------------------------------------------------------------------------
33 static char *_riointr_c_sccs_ = "@(#)riointr.c 1.2";
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/tty.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"
90 ** riopoll is called every clock tick. Once the /dev/rio device has been
91 ** opened, and polldistributed( ) has been called, this routine is called
92 ** every clock tick *by every cpu*. The 'interesting' piece of code that
93 ** manipulates 'RIONumCpus' and 'RIOCpuCountdown' is used to fair-share
94 ** the work between the CPUs. If there are 'N' cpus, then each poll time
95 ** we increment a counter, modulo 'N-1'. When this counter is 0, we call
96 ** the interrupt handler. This has the effect that polls are serviced
97 ** by processor 'N', 'N-1', 'N-2', ... '0', round and round. Neat.
106 ** Here's the deal. We try to fair share as much as possible amongst
107 ** all the processors that are available. Since each processor
108 ** should generate HZ ticks per second and since we only need HZ ticks
109 ** in total for proper operation we simply attempt to cycle round each
110 ** processor in turn, using RIOCpuCountdown to decide whether to call
111 ** the interrupt routine. ( In fact the count zeroes when it reaches
112 ** one less than the total number of processors - so e.g. on a two
113 ** processor system RIOService will get called 2*HZ times per second. )
114 ** this_cpu (cur_cpu()) tells us the number of the current processor
118 ** 1 - first extra CPU
119 ** 2 - second extra CPU
124 ** okay, we've got a cpu that hasn't had a go recently
125 ** - lets check to see what needs doing.
127 for ( host=0; host<p->RIONumHosts; host++ ) {
128 struct Host *HostP = &p->RIOHosts[host];
130 rio_spin_lock( &HostP->HostLock );
132 if ( ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) ||
134 rio_spin_unlock (&HostP->HostLock);
138 if ( RWORD( HostP->ParmMapP->rup_intr ) ||
139 RWORD( HostP->ParmMapP->rx_intr ) ||
140 RWORD( HostP->ParmMapP->tx_intr ) ) {
143 #ifdef FUTURE_RELEASE
144 if( HostP->Type == RIO_EISA )
145 INBZ( HostP->Slot, EISA_INTERRUPT_RESET );
148 WBYTE( HostP->ResetInt , 0xff );
150 rio_spin_lock(&HostP->HostLock);
153 RIOServiceHost(p, HostP, 'p' );
154 rio_spin_lock( &HostP->HostLock);
156 rio_spin_unlock (&HostP->HostLock);
159 rio_spin_unlock (&p->RIOIntrSem);
163 char *firstchars (char *p, int nch)
165 static char buf[2][128];
168 memcpy (buf[t], p, nch);
174 #define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask))
175 /* Enable and start the transmission of packets */
182 struct tty_struct* tty;
184 struct PKT * PacketP;
187 PortP = (struct Port *)en;
188 p = (struct rio_info *)PortP->p;
192 rio_dprintk (RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n",
193 PortP->PortNum, PortP->gs.xmit_cnt);
195 if (!PortP->gs.xmit_cnt) return;
198 /* This routine is an order of magnitude simpler than the specialix
199 version. One of the disadvantages is that this version will send
200 an incomplete packet (usually 64 bytes instead of 72) once for
201 every 4k worth of data. Let's just say that this won't influence
202 performance significantly..... */
204 rio_spin_lock_irqsave(&PortP->portSem, flags);
206 while (can_add_transmit( &PacketP, PortP )) {
207 c = PortP->gs.xmit_cnt;
208 if (c > PKT_MAX_DATA_LEN) c = PKT_MAX_DATA_LEN;
210 /* Don't copy past the end of the source buffer */
211 if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail)
212 c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
217 rio_dprintk (RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n",
219 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail , t),
220 firstchars (PortP->gs.xmit_buf + PortP->gs.xmit_tail + c-t, t));
222 /* If for one reason or another, we can't copy more data,
226 rio_memcpy_toio (PortP->HostP->Caddr, (caddr_t)PacketP->data,
227 PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
230 writeb (c, &(PacketP->len));
231 if (!( PortP->State & RIO_DELETED ) ) {
232 add_transmit ( PortP );
234 ** Count chars tx'd for port statistics reporting
236 if ( PortP->statsGather )
239 PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1);
240 PortP->gs.xmit_cnt -= c;
243 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
245 if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2*PKT_MAX_DATA_LEN)) {
246 rio_dprintk (RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....",
247 (int)(PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)),
248 PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
249 if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
250 PortP->gs.tty->ldisc.write_wakeup)
251 (PortP->gs.tty->ldisc.write_wakeup)(PortP->gs.tty);
252 rio_dprintk (RIO_DEBUG_INTR, "(%d/%d)\n",
253 PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
254 wake_up_interruptible(&PortP->gs.tty->write_wait);
261 ** When a real-life interrupt comes in here, we try to find out
262 ** which host card it belongs to, and then service only that host
263 ** Notice the cunning way that, once we've found a candidate, we
264 ** continue just in case we are sharing interrupts.
272 for ( host=0; host<p->RIONumHosts; host++ ) {
273 struct Host *HostP = &p->RIOHosts[host];
275 rio_dprintk (RIO_DEBUG_INTR, "riointr() doing host %d type %d\n", host, HostP->Type);
277 switch( HostP->Type ) {
281 rio_spin_lock(&HostP->HostLock);
282 WBYTE(HostP->ResetInt , 0xff);
283 if ( !HostP->InIntr ) {
285 rio_spin_unlock (&HostP->HostLock);
286 p->_RIO_Interrupted++;
287 RIOServiceHost(p, HostP, 'i');
288 rio_spin_lock(&HostP->HostLock);
291 rio_spin_unlock(&HostP->HostLock);
293 #ifdef FUTURE_RELEASE
295 if ( ivec == HostP->Ivec )
297 OldSpl = LOCKB( &HostP->HostLock );
298 INBZ( HostP->Slot, EISA_INTERRUPT_RESET );
299 if ( !HostP->InIntr )
302 UNLOCKB( &HostP->HostLock, OldSpl );
303 if ( this_cpu < RIO_CPU_LIMIT )
305 int intrSpl = LOCKB( &RIOIntrLock );
306 UNLOCKB( &RIOIntrLock, intrSpl );
308 p->_RIO_Interrupted++;
309 RIOServiceHost( HostP, 'i' );
310 OldSpl = LOCKB( &HostP->HostLock );
313 UNLOCKB( &HostP->HostLock, OldSpl );
323 #ifdef FUTURE_RELEASE
326 cmn_err( CE_WARN, "RIO: Interrupt received with vector 0x%x\n", ivec );
327 cmn_err( CE_CONT, " Valid vectors are:\n");
328 for ( host=0; host<RIONumHosts; host++ )
330 switch( RIOHosts[host].Type )
335 cmn_err( CE_CONT, "0x%x ", RIOHosts[host].Ivec );
338 cmn_err( CE_CONT, "0x%x ", get_intr_arg( RIOHosts[host].PciDevInfo.busnum, IDIST_PCI_IRQ( RIOHosts[host].PciDevInfo.slotnum, RIOHosts[host].PciDevInfo.funcnum ) ));
342 cmn_err( CE_CONT, "\n" );
348 ** RIO Host Service routine. Does all the work traditionally associated with an
355 RIOServiceHost(p, HostP, From)
360 rio_spin_lock (&HostP->HostLock);
361 if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
363 rio_spin_unlock (&HostP->HostLock);
364 if ((t++ % 200) == 0)
365 rio_dprintk (RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int)HostP->Flags);
368 rio_spin_unlock (&HostP->HostLock);
370 if ( RWORD( HostP->ParmMapP->rup_intr ) ) {
371 WWORD( HostP->ParmMapP->rup_intr , 0 );
374 rio_dprintk (RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP-p->RIOHosts);
375 RIOPollHostCommands(p, HostP );
378 if ( RWORD( HostP->ParmMapP->rx_intr ) ) {
381 WWORD( HostP->ParmMapP->rx_intr , 0 );
385 rio_dprintk (RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP-p->RIOHosts);
387 ** Loop through every port. If the port is mapped into
388 ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
389 ** worth checking. If the port isn't open, grab any packets
390 ** hanging on its receive queue and stuff them on the free
391 ** list; check for commands on the way.
393 for ( port=p->RIOFirstPortsBooted;
394 port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
395 struct Port *PortP = p->RIOPortp[port];
396 struct tty_struct *ttyP;
400 ** not mapped in - most of the RIOPortp[] information
401 ** has not been set up!
402 ** Optimise: ports come in bundles of eight.
404 if ( !PortP->Mapped ) {
406 continue; /* with the next port */
410 ** If the host board isn't THIS host board, check the next one.
411 ** optimise: ports come in bundles of eight.
413 if ( PortP->HostP != HostP ) {
419 ** Let us see - is the port open? If not, then don't service it.
421 if ( !( PortP->PortState & PORT_ISOPEN ) ) {
426 ** find corresponding tty structure. The process of mapping
427 ** the ports puts these here.
429 ttyP = PortP->gs.tty;
432 ** Lock the port before we begin working on it.
434 rio_spin_lock(&PortP->portSem);
437 ** Process received data if there is any.
439 if ( can_remove_receive( &PacketP, PortP ) )
440 RIOReceive(p, PortP);
443 ** If there is no data left to be read from the port, and
444 ** it's handshake bit is set, then we must clear the handshake,
445 ** so that that downstream RTA is re-enabled.
447 if ( !can_remove_receive( &PacketP, PortP ) &&
448 ( RWORD( PortP->PhbP->handshake )==PHB_HANDSHAKE_SET ) ) {
450 ** MAGIC! ( Basically, handshake the RX buffer, so that
451 ** the RTAs upstream can be re-enabled. )
453 rio_dprintk (RIO_DEBUG_INTR, "Set RX handshake bit\n");
454 WWORD( PortP->PhbP->handshake,
455 PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET );
457 rio_spin_unlock(&PortP->portSem);
461 if ( RWORD( HostP->ParmMapP->tx_intr ) ) {
464 WWORD( HostP->ParmMapP->tx_intr , 0);
468 rio_dprintk (RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP-p->RIOHosts);
471 ** Loop through every port.
472 ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
473 ** associated ) then it is worth checking.
475 for ( port=p->RIOFirstPortsBooted;
476 port<p->RIOLastPortsBooted+PORTS_PER_RTA; port++ ) {
477 struct Port *PortP = p->RIOPortp[port];
478 struct tty_struct *ttyP;
482 ** not mapped in - most of the RIOPortp[] information
483 ** has not been set up!
485 if ( !PortP->Mapped ) {
487 continue; /* with the next port */
491 ** If the host board isn't running, then its data structures
492 ** are no use to us - continue quietly.
494 if ( PortP->HostP != HostP ) {
496 continue; /* with the next port */
500 ** Let us see - is the port open? If not, then don't service it.
502 if ( !( PortP->PortState & PORT_ISOPEN ) ) {
506 rio_dprintk (RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
508 ** Lock the port before we begin working on it.
510 rio_spin_lock(&PortP->portSem);
513 ** If we can't add anything to the transmit queue, then
514 ** we need do none of this processing.
516 if ( !can_add_transmit( &PacketP, PortP ) ) {
517 rio_dprintk (RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
518 rio_spin_unlock(&PortP->portSem);
523 ** find corresponding tty structure. The process of mapping
524 ** the ports puts these here.
526 ttyP = PortP->gs.tty;
527 /* If ttyP is NULL, the port is getting closed. Forget about it. */
529 rio_dprintk (RIO_DEBUG_INTR, "no tty, so skipping.\n");
530 rio_spin_unlock(&PortP->portSem);
534 ** If there is more room available we start up the transmit
535 ** data process again. This can be direct I/O, if the cookmode
536 ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
537 ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
538 ** characters via the line discipline. We must always call
539 ** the line discipline,
540 ** so that user input characters can be echoed correctly.
543 ** With the advent of double buffering, we now see if
544 ** TxBufferOut-In is non-zero. If so, then we copy a packet
545 ** to the output place, and set it going. If this empties
546 ** the buffer, then we must issue a wakeup( ) on OUT.
547 ** If it frees space in the buffer then we must issue
548 ** a wakeup( ) on IN.
550 ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
551 ** have to send a WFLUSH command down the PHB, to mark the
552 ** end point of a WFLUSH. We also need to clear out any
553 ** data from the double buffer! ( note that WflushFlag is a
554 ** *count* of the number of WFLUSH commands outstanding! )
556 ** ++++ And there's more!
557 ** If an RTA is powered off, then on again, and rebooted,
558 ** whilst it has ports open, then we need to re-open the ports.
559 ** ( reasonable enough ). We can't do this when we spot the
560 ** re-boot, in interrupt time, because the queue is probably
561 ** full. So, when we come in here, we need to test if any
562 ** ports are in this condition, and re-open the port before
563 ** we try to send any more data to it. Now, the re-booted
564 ** RTA will be discarding packets from the PHB until it
565 ** receives this open packet, but don't worry tooo much
566 ** about that. The one thing that is interesting is the
567 ** combination of this effect and the WFLUSH effect!
569 /* For now don't handle RTA reboots. -- REW.
570 Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
571 if ( PortP->MagicFlags ) {
573 if ( PortP->MagicFlags & MAGIC_REBOOT ) {
575 ** well, the RTA has been rebooted, and there is room
576 ** on its queue to add the open packet that is required.
578 ** The messy part of this line is trying to decide if
579 ** we need to call the Param function as a tty or as
581 ** DONT USE CLOCAL AS A TEST FOR THIS!
583 ** If we can't param the port, then move on to the
586 PortP->InUse = NOT_INUSE;
588 rio_spin_unlock(&PortP->portSem);
589 if ( RIOParam(PortP, OPEN, ((PortP->Cor2Copy &
590 (COR2_RTSFLOW|COR2_CTSFLOW ) )==
591 (COR2_RTSFLOW|COR2_CTSFLOW ) ) ?
592 TRUE : FALSE, DONT_SLEEP ) == RIO_FAIL ) {
593 continue; /* with next port */
595 rio_spin_lock(&PortP->portSem);
596 PortP->MagicFlags &= ~MAGIC_REBOOT;
601 ** As mentioned above, this is a tacky hack to cope
604 if ( PortP->WflushFlag ) {
605 rio_dprintk (RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
608 rio_dprintk (RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
611 while ( PortP->WflushFlag &&
612 can_add_transmit( &PacketP, PortP ) &&
613 ( PortP->InUse == NOT_INUSE ) ) {
615 struct PktCmd *PktCmdP;
617 rio_dprintk (RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
619 ** make it look just like a WFLUSH command
621 PktCmdP = ( struct PktCmd * )&PacketP->data[0];
623 WBYTE( PktCmdP->Command , WFLUSH );
625 p = PortP->HostPort % ( ushort )PORTS_PER_RTA;
628 ** If second block of ports for 16 port RTA, add 8
631 if ( PortP->SecondBlock )
634 WBYTE( PktCmdP->PhbNum, p );
637 ** to make debuggery easier
639 WBYTE( PacketP->data[ 2], 'W' );
640 WBYTE( PacketP->data[ 3], 'F' );
641 WBYTE( PacketP->data[ 4], 'L' );
642 WBYTE( PacketP->data[ 5], 'U' );
643 WBYTE( PacketP->data[ 6], 'S' );
644 WBYTE( PacketP->data[ 7], 'H' );
645 WBYTE( PacketP->data[ 8], ' ' );
646 WBYTE( PacketP->data[ 9], '0'+PortP->WflushFlag );
647 WBYTE( PacketP->data[10], ' ' );
648 WBYTE( PacketP->data[11], ' ' );
649 WBYTE( PacketP->data[12], '\0' );
652 ** its two bytes long!
654 WBYTE( PacketP->len , PKT_CMD_BIT | 2 );
659 if ( !( PortP->State & RIO_DELETED ) ) {
660 add_transmit( PortP );
662 ** Count chars tx'd for port statistics reporting
664 if ( PortP->statsGather )
668 if ( --( PortP->WflushFlag ) == 0 ) {
669 PortP->MagicFlags &= ~MAGIC_FLUSH;
672 rio_dprintk (RIO_DEBUG_INTR, "Wflush count now stands at %d\n",
675 if ( PortP->MagicFlags & MORE_OUTPUT_EYGOR ) {
676 if ( PortP->MagicFlags & MAGIC_FLUSH ) {
677 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
680 if ( !can_add_transmit( &PacketP, PortP ) ) {
681 rio_spin_unlock(&PortP->portSem);
684 rio_spin_unlock(&PortP->portSem);
685 RIOTxEnable((char *)PortP);
686 rio_spin_lock(&PortP->portSem);
687 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
694 ** If we can't add anything to the transmit queue, then
695 ** we need do none of the remaining processing.
697 if (!can_add_transmit( &PacketP, PortP ) ) {
698 rio_spin_unlock(&PortP->portSem);
702 rio_spin_unlock(&PortP->portSem);
703 RIOTxEnable((char *)PortP);
709 ** Routine for handling received data for clist drivers.
710 ** NB: Called with the tty locked. The spl from the lockb( ) is passed.
711 ** we return the ttySpl level that we re-locked at.
718 struct tty_struct *TtyP;
719 register ushort transCount;
721 register uint DataCnt;
725 static int intCount, RxIntCnt;
728 ** The receive data process is to remove packets from the
729 ** PHB until there aren't any more or the current cblock
730 ** is full. When this occurs, there will be some left over
731 ** data in the packet, that we must do something with.
732 ** As we haven't unhooked the packet from the read list
733 ** yet, we can just leave the packet there, having first
734 ** made a note of how far we got. This means that we need
735 ** a pointer per port saying where we start taking the
736 ** data from - this will normally be zero, but when we
737 ** run out of space it will be set to the offset of the
738 ** next byte to copy from the packet data area. The packet
739 ** length field is decremented by the number of bytes that
740 ** we succesfully removed from the packet. When this reaches
741 ** zero, we reset the offset pointer to be zero, and free
742 ** the packet from the front of the queue.
747 TtyP = PortP->gs.tty;
749 rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
753 if (PortP->State & RIO_THROTTLE_RX) {
754 rio_dprintk (RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
758 if ( PortP->State & RIO_DELETED )
760 while ( can_remove_receive( &PacketP, PortP ) )
762 remove_receive( PortP );
763 put_free_end( PortP->HostP, PacketP );
769 ** loop, just so long as:
770 ** i ) there's some data ( i.e. can_remove_receive )
771 ** ii ) we haven't been blocked
772 ** iii ) there's somewhere to put the data
773 ** iv ) we haven't outstayed our welcome
776 while ( can_remove_receive(&PacketP, PortP)
780 PortP->Stat.RxIntCnt++;
785 ** check that it is not a command!
787 if ( PacketP->len & PKT_CMD_BIT ) {
788 rio_dprintk (RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
789 /* rio_dprint(RIO_DEBUG_INTR, (" sysport = %d\n", p->RIOPortp->PortNum)); */
790 rio_dprintk (RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit);
791 rio_dprintk (RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port);
792 rio_dprintk (RIO_DEBUG_INTR, " src_unit = %d\n", PacketP->src_unit);
793 rio_dprintk (RIO_DEBUG_INTR, " src_port = %d\n", PacketP->src_port);
794 rio_dprintk (RIO_DEBUG_INTR, " len = %d\n", PacketP->len);
795 rio_dprintk (RIO_DEBUG_INTR, " control = %d\n", PacketP->control);
796 rio_dprintk (RIO_DEBUG_INTR, " csum = %d\n", PacketP->csum);
797 rio_dprintk (RIO_DEBUG_INTR, " data bytes: ");
798 for ( DataCnt=0; DataCnt<PKT_MAX_DATA_LEN; DataCnt++ )
799 rio_dprintk (RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]);
800 remove_receive( PortP );
801 put_free_end( PortP->HostP, PacketP );
802 continue; /* with next packet */
806 ** How many characters can we move 'upstream' ?
808 ** Determine the minimum of the amount of data
809 ** available and the amount of space in which to
812 ** 1. Get the packet length by masking 'len'
813 ** for only the length bits.
814 ** 2. Available space is [buffer size] - [space used]
816 ** Transfer count is the minimum of packet length
817 ** and available space.
820 transCount = min_t(unsigned int, PacketP->len & PKT_LEN_MASK,
821 TTY_FLIPBUF_SIZE - TtyP->flip.count);
822 rio_dprintk (RIO_DEBUG_REC, "port %d: Copy %d bytes\n",
823 PortP->PortNum, transCount);
825 ** To use the following 'kkprintfs' for debugging - change the '#undef'
826 ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
829 #undef ___DEBUG_IT___
830 #ifdef ___DEBUG_IT___
831 kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ",
839 ptr = (uchar *) PacketP->data + PortP->RxDataStart;
841 rio_memcpy_fromio (TtyP->flip.char_buf_ptr, ptr, transCount);
842 memset(TtyP->flip.flag_buf_ptr, TTY_NORMAL, transCount);
846 ** keep a count for statistical purposes
848 PortP->Stat.RxCharCnt += transCount;
850 PortP->RxDataStart += transCount;
851 PacketP->len -= transCount;
852 copied += transCount;
853 TtyP->flip.count += transCount;
854 TtyP->flip.char_buf_ptr += transCount;
855 TtyP->flip.flag_buf_ptr += transCount;
858 #ifdef ___DEBUG_IT___
859 kkprintf("T:%d L:%d\n", DataCnt, PacketP->len );
862 if ( PacketP->len == 0 )
865 ** If we have emptied the packet, then we can
866 ** free it, and reset the start pointer for
869 remove_receive( PortP );
870 put_free_end( PortP->HostP, PacketP );
871 PortP->RxDataStart = 0;
874 ** more lies ( oops, I mean statistics )
876 PortP->Stat.RxPktCnt++;
882 rio_dprintk (RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
883 tty_flip_buffer_push (TtyP);
889 #ifdef FUTURE_RELEASE
891 ** The proc routine called by the line discipline to do the work for it.
892 ** The proc routine works hand in hand with the interrupt routine.
895 riotproc(p, tp, cmd, port)
897 register struct ttystatics *tp;
901 register struct Port *PortP;
905 SysPort = port; /* Believe me, it works. */
907 if ( SysPort < 0 || SysPort >= RIO_PORTS ) {
908 rio_dprintk (RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n",SysPort);
911 PortP = p->RIOPortp[SysPort];
913 if ((uint)PortP->PhbP < (uint)PortP->Caddr ||
914 (uint)PortP->PhbP >= (uint)PortP->Caddr+SIXTY_FOUR_K ) {
915 rio_dprintk (RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n",
917 rio_dprintk (RIO_DEBUG_INTR, " PortP = 0x%x\n",PortP);
918 rio_dprintk (RIO_DEBUG_INTR, " PortP->PhbP = 0x%x\n",PortP->PhbP);
919 rio_dprintk (RIO_DEBUG_INTR, " PortP->Caddr = 0x%x\n",PortP->PhbP);
920 rio_dprintk (RIO_DEBUG_INTR, " PortP->HostPort = 0x%x\n",PortP->HostPort);
926 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH\n");
928 ** Because of the spooky way the RIO works, we don't need
929 ** to issue a flush command on any of the SET*F commands,
930 ** as that causes trouble with getty and login, which issue
931 ** these commands to incur a READ flush, and rely on the fact
932 ** that the line discipline does a wait for drain for them.
933 ** As the rio doesn't wait for drain, the write flush would
934 ** destroy the Password: prompt. This isn't very friendly, so
935 ** here we only issue a WFLUSH command if we are in the interrupt
936 ** routine, or we aren't executing a SET*F command.
938 if ( PortP->HostP->InIntr || !PortP->FlushCmdBodge ) {
940 ** form a wflush packet - 1 byte long, no data
942 if ( PortP->State & RIO_DELETED ) {
943 rio_dprintk (RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
946 if ( RIOPreemptiveCmd(p, PortP, WFLUSH ) == RIO_FAIL ) {
947 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
950 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command\n");
953 ** WFLUSH operation - flush the data!
955 PortP->TxBufferIn = PortP->TxBufferOut = 0;
958 rio_dprintk (RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
961 ** sort out the line discipline
963 if (PortP->CookMode == COOK_WELL)
968 rio_dprintk (RIO_DEBUG_INTR, "T_RESUME\n");
970 ** send pre-emptive resume packet
972 if ( PortP->State & RIO_DELETED ) {
973 rio_dprintk (RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
976 if ( RIOPreemptiveCmd(p, PortP, RESUME ) == RIO_FAIL ) {
977 rio_dprintk (RIO_DEBUG_INTR, "T_RESUME Command failed\n");
981 ** and re-start the sender software!
983 if (PortP->CookMode == COOK_WELL)
988 rio_dprintk (RIO_DEBUG_INTR, "T_TIME\n");
990 ** T_TIME is called when xDLY is set in oflags and
991 ** the line discipline timeout has expired. It's
992 ** function in life is to clear the TIMEOUT flag
993 ** and to re-start output to the port.
996 ** Fall through and re-start output
1000 if ( PortP->MagicFlags & MAGIC_FLUSH ) {
1001 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
1004 RIOTxEnable((char *)PortP);
1005 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
1006 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n");*/
1010 rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND\n");
1012 ** send a suspend pre-emptive packet.
1014 if ( PortP->State & RIO_DELETED ) {
1015 rio_dprintk (RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
1018 if ( RIOPreemptiveCmd(p, PortP, SUSPEND ) == RIO_FAIL ) {
1019 rio_dprintk (RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
1028 rio_dprintk (RIO_DEBUG_INTR, "T_BLOCK\n");
1032 rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH\n");
1033 if ( PortP->State & RIO_DELETED ) {
1034 rio_dprintk (RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
1035 PortP->RxDataStart = 0;
1038 if ( RIOPreemptiveCmd( p, PortP, RFLUSH ) == RIO_FAIL ) {
1039 rio_dprintk (RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
1042 PortP->RxDataStart = 0;
1043 while ( can_remove_receive(&PacketP, PortP) ) {
1044 remove_receive(PortP);
1045 ShowPacket(DBG_PROC, PacketP );
1046 put_free_end(PortP->HostP, PacketP );
1048 if ( PortP->PhbP->handshake == PHB_HANDSHAKE_SET ) {
1052 rio_dprintk (RIO_DEBUG_INTR, "Set receive handshake bit\n");
1053 PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
1059 rio_dprintk (RIO_DEBUG_INTR, "T_UNBLOCK\n");
1061 ** If there is any data to receive set a timeout to service it.
1063 RIOReceive(p, PortP);
1067 rio_dprintk (RIO_DEBUG_INTR, "T_BREAK\n");
1069 ** Send a break command. For Sys V
1070 ** this is a timed break, so we
1071 ** send a SBREAK[time] packet
1074 ** Build a BREAK command
1076 if ( PortP->State & RIO_DELETED ) {
1077 rio_dprintk (RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
1080 if (RIOShortCommand(PortP,SBREAK,2,
1081 p->RIOConf.BreakInterval)==RIO_FAIL) {
1082 rio_dprintk (RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
1092 rio_dprintk (RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
1095 rio_dprintk (RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
1099 rio_dprintk (RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
1103 rio_dprintk (RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n",cmd);
1106 ** T_OUTPUT returns without passing through this point!
1108 /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n");*/