Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
[linux-2.6] / drivers / char / rio / riointr.c
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          : riointr.c
24 **      SID             : 1.2
25 **      Last Modified   : 11/6/98 10:33:44
26 **      Retrieved       : 11/6/98 10:33:49
27 **
28 **  ident @(#)riointr.c 1.2
29 **
30 ** -----------------------------------------------------------------------------
31 */
32 #ifdef SCCS_LABELS
33 static char *_riointr_c_sccs_ = "@(#)riointr.c  1.2";
34 #endif
35
36
37 #include <linux/module.h>
38 #include <linux/slab.h>
39 #include <linux/errno.h>
40 #include <linux/tty.h>
41 #include <linux/tty_flip.h>
42 #include <asm/io.h>
43 #include <asm/system.h>
44 #include <asm/string.h>
45 #include <asm/uaccess.h>
46
47 #include <linux/termios.h>
48 #include <linux/serial.h>
49
50 #include <linux/generic_serial.h>
51
52 #include <linux/delay.h>
53
54 #include "linux_compat.h"
55 #include "rio_linux.h"
56 #include "pkt.h"
57 #include "daemon.h"
58 #include "rio.h"
59 #include "riospace.h"
60 #include "cmdpkt.h"
61 #include "map.h"
62 #include "rup.h"
63 #include "port.h"
64 #include "riodrvr.h"
65 #include "rioinfo.h"
66 #include "func.h"
67 #include "errors.h"
68 #include "pci.h"
69
70 #include "parmmap.h"
71 #include "unixrup.h"
72 #include "board.h"
73 #include "host.h"
74 #include "phb.h"
75 #include "link.h"
76 #include "cmdblk.h"
77 #include "route.h"
78 #include "cirrus.h"
79 #include "rioioctl.h"
80
81
82 static void RIOReceive(struct rio_info *, struct Port *);
83
84
85 static char *firstchars(char *p, int nch)
86 {
87         static char buf[2][128];
88         static int t = 0;
89         t = !t;
90         memcpy(buf[t], p, nch);
91         buf[t][nch] = 0;
92         return buf[t];
93 }
94
95
96 #define INCR( P, I )    ((P) = (((P)+(I)) & p->RIOBufferMask))
97 /* Enable and start the transmission of packets */
98 void RIOTxEnable(char *en)
99 {
100         struct Port *PortP;
101         struct rio_info *p;
102         struct tty_struct *tty;
103         int c;
104         struct PKT __iomem *PacketP;
105         unsigned long flags;
106
107         PortP = (struct Port *) en;
108         p = (struct rio_info *) PortP->p;
109         tty = PortP->gs.tty;
110
111
112         rio_dprintk(RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n", PortP->PortNum, PortP->gs.xmit_cnt);
113
114         if (!PortP->gs.xmit_cnt)
115                 return;
116
117
118         /* This routine is an order of magnitude simpler than the specialix
119            version. One of the disadvantages is that this version will send
120            an incomplete packet (usually 64 bytes instead of 72) once for
121            every 4k worth of data. Let's just say that this won't influence
122            performance significantly..... */
123
124         rio_spin_lock_irqsave(&PortP->portSem, flags);
125
126         while (can_add_transmit(&PacketP, PortP)) {
127                 c = PortP->gs.xmit_cnt;
128                 if (c > PKT_MAX_DATA_LEN)
129                         c = PKT_MAX_DATA_LEN;
130
131                 /* Don't copy past the end of the source buffer */
132                 if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail)
133                         c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
134
135                 {
136                         int t;
137                         t = (c > 10) ? 10 : c;
138
139                         rio_dprintk(RIO_DEBUG_INTR, "rio: tx port %d: copying %d chars: %s - %s\n", PortP->PortNum, c, firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail, t), firstchars(PortP->gs.xmit_buf + PortP->gs.xmit_tail + c - t, t));
140                 }
141                 /* If for one reason or another, we can't copy more data,
142                    we're done! */
143                 if (c == 0)
144                         break;
145
146                 rio_memcpy_toio(PortP->HostP->Caddr, PacketP->data, PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
147                 /*    udelay (1); */
148
149                 writeb(c, &(PacketP->len));
150                 if (!(PortP->State & RIO_DELETED)) {
151                         add_transmit(PortP);
152                         /*
153                          ** Count chars tx'd for port statistics reporting
154                          */
155                         if (PortP->statsGather)
156                                 PortP->txchars += c;
157                 }
158                 PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE - 1);
159                 PortP->gs.xmit_cnt -= c;
160         }
161
162         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
163
164         if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN))
165                 tty_wakeup(PortP->gs.tty);
166
167 }
168
169
170 /*
171 ** RIO Host Service routine. Does all the work traditionally associated with an
172 ** interrupt.
173 */
174 static int RupIntr;
175 static int RxIntr;
176 static int TxIntr;
177
178 void RIOServiceHost(struct rio_info *p, struct Host *HostP)
179 {
180         rio_spin_lock(&HostP->HostLock);
181         if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
182                 static int t = 0;
183                 rio_spin_unlock(&HostP->HostLock);
184                 if ((t++ % 200) == 0)
185                         rio_dprintk(RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int) HostP->Flags);
186                 return;
187         }
188         rio_spin_unlock(&HostP->HostLock);
189
190         if (readw(&HostP->ParmMapP->rup_intr)) {
191                 writew(0, &HostP->ParmMapP->rup_intr);
192                 p->RIORupCount++;
193                 RupIntr++;
194                 rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %Zd\n", HostP - p->RIOHosts);
195                 RIOPollHostCommands(p, HostP);
196         }
197
198         if (readw(&HostP->ParmMapP->rx_intr)) {
199                 int port;
200
201                 writew(0, &HostP->ParmMapP->rx_intr);
202                 p->RIORxCount++;
203                 RxIntr++;
204
205                 rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %Zd\n", HostP - p->RIOHosts);
206                 /*
207                  ** Loop through every port. If the port is mapped into
208                  ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
209                  ** worth checking. If the port isn't open, grab any packets
210                  ** hanging on its receive queue and stuff them on the free
211                  ** list; check for commands on the way.
212                  */
213                 for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
214                         struct Port *PortP = p->RIOPortp[port];
215                         struct tty_struct *ttyP;
216                         struct PKT __iomem *PacketP;
217
218                         /*
219                          ** not mapped in - most of the RIOPortp[] information
220                          ** has not been set up!
221                          ** Optimise: ports come in bundles of eight.
222                          */
223                         if (!PortP->Mapped) {
224                                 port += 7;
225                                 continue;       /* with the next port */
226                         }
227
228                         /*
229                          ** If the host board isn't THIS host board, check the next one.
230                          ** optimise: ports come in bundles of eight.
231                          */
232                         if (PortP->HostP != HostP) {
233                                 port += 7;
234                                 continue;
235                         }
236
237                         /*
238                          ** Let us see - is the port open? If not, then don't service it.
239                          */
240                         if (!(PortP->PortState & PORT_ISOPEN)) {
241                                 continue;
242                         }
243
244                         /*
245                          ** find corresponding tty structure. The process of mapping
246                          ** the ports puts these here.
247                          */
248                         ttyP = PortP->gs.tty;
249
250                         /*
251                          ** Lock the port before we begin working on it.
252                          */
253                         rio_spin_lock(&PortP->portSem);
254
255                         /*
256                          ** Process received data if there is any.
257                          */
258                         if (can_remove_receive(&PacketP, PortP))
259                                 RIOReceive(p, PortP);
260
261                         /*
262                          ** If there is no data left to be read from the port, and
263                          ** it's handshake bit is set, then we must clear the handshake,
264                          ** so that that downstream RTA is re-enabled.
265                          */
266                         if (!can_remove_receive(&PacketP, PortP) && (readw(&PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) {
267                                 /*
268                                  ** MAGIC! ( Basically, handshake the RX buffer, so that
269                                  ** the RTAs upstream can be re-enabled. )
270                                  */
271                                 rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n");
272                                 writew(PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET, &PortP->PhbP->handshake);
273                         }
274                         rio_spin_unlock(&PortP->portSem);
275                 }
276         }
277
278         if (readw(&HostP->ParmMapP->tx_intr)) {
279                 int port;
280
281                 writew(0, &HostP->ParmMapP->tx_intr);
282
283                 p->RIOTxCount++;
284                 TxIntr++;
285                 rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %Zd\n", HostP - p->RIOHosts);
286
287                 /*
288                  ** Loop through every port.
289                  ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
290                  ** associated ) then it is worth checking.
291                  */
292                 for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
293                         struct Port *PortP = p->RIOPortp[port];
294                         struct tty_struct *ttyP;
295                         struct PKT __iomem *PacketP;
296
297                         /*
298                          ** not mapped in - most of the RIOPortp[] information
299                          ** has not been set up!
300                          */
301                         if (!PortP->Mapped) {
302                                 port += 7;
303                                 continue;       /* with the next port */
304                         }
305
306                         /*
307                          ** If the host board isn't running, then its data structures
308                          ** are no use to us - continue quietly.
309                          */
310                         if (PortP->HostP != HostP) {
311                                 port += 7;
312                                 continue;       /* with the next port */
313                         }
314
315                         /*
316                          ** Let us see - is the port open? If not, then don't service it.
317                          */
318                         if (!(PortP->PortState & PORT_ISOPEN)) {
319                                 continue;
320                         }
321
322                         rio_dprintk(RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
323                         /*
324                          ** Lock the port before we begin working on it.
325                          */
326                         rio_spin_lock(&PortP->portSem);
327
328                         /*
329                          ** If we can't add anything to the transmit queue, then
330                          ** we need do none of this processing.
331                          */
332                         if (!can_add_transmit(&PacketP, PortP)) {
333                                 rio_dprintk(RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
334                                 rio_spin_unlock(&PortP->portSem);
335                                 continue;
336                         }
337
338                         /*
339                          ** find corresponding tty structure. The process of mapping
340                          ** the ports puts these here.
341                          */
342                         ttyP = PortP->gs.tty;
343                         /* If ttyP is NULL, the port is getting closed. Forget about it. */
344                         if (!ttyP) {
345                                 rio_dprintk(RIO_DEBUG_INTR, "no tty, so skipping.\n");
346                                 rio_spin_unlock(&PortP->portSem);
347                                 continue;
348                         }
349                         /*
350                          ** If there is more room available we start up the transmit
351                          ** data process again. This can be direct I/O, if the cookmode
352                          ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
353                          ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
354                          ** characters via the line discipline. We must always call
355                          ** the line discipline,
356                          ** so that user input characters can be echoed correctly.
357                          **
358                          ** ++++ Update +++++
359                          ** With the advent of double buffering, we now see if
360                          ** TxBufferOut-In is non-zero. If so, then we copy a packet
361                          ** to the output place, and set it going. If this empties
362                          ** the buffer, then we must issue a wakeup( ) on OUT.
363                          ** If it frees space in the buffer then we must issue
364                          ** a wakeup( ) on IN.
365                          **
366                          ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
367                          ** have to send a WFLUSH command down the PHB, to mark the
368                          ** end point of a WFLUSH. We also need to clear out any
369                          ** data from the double buffer! ( note that WflushFlag is a
370                          ** *count* of the number of WFLUSH commands outstanding! )
371                          **
372                          ** ++++ And there's more!
373                          ** If an RTA is powered off, then on again, and rebooted,
374                          ** whilst it has ports open, then we need to re-open the ports.
375                          ** ( reasonable enough ). We can't do this when we spot the
376                          ** re-boot, in interrupt time, because the queue is probably
377                          ** full. So, when we come in here, we need to test if any
378                          ** ports are in this condition, and re-open the port before
379                          ** we try to send any more data to it. Now, the re-booted
380                          ** RTA will be discarding packets from the PHB until it
381                          ** receives this open packet, but don't worry tooo much
382                          ** about that. The one thing that is interesting is the
383                          ** combination of this effect and the WFLUSH effect!
384                          */
385                         /* For now don't handle RTA reboots. -- REW.
386                            Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
387                         if (PortP->MagicFlags) {
388                                 if (PortP->MagicFlags & MAGIC_REBOOT) {
389                                         /*
390                                          ** well, the RTA has been rebooted, and there is room
391                                          ** on its queue to add the open packet that is required.
392                                          **
393                                          ** The messy part of this line is trying to decide if
394                                          ** we need to call the Param function as a tty or as
395                                          ** a modem.
396                                          ** DONT USE CLOCAL AS A TEST FOR THIS!
397                                          **
398                                          ** If we can't param the port, then move on to the
399                                          ** next port.
400                                          */
401                                         PortP->InUse = NOT_INUSE;
402
403                                         rio_spin_unlock(&PortP->portSem);
404                                         if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? 1 : 0, DONT_SLEEP) == RIO_FAIL) {
405                                                 continue;       /* with next port */
406                                         }
407                                         rio_spin_lock(&PortP->portSem);
408                                         PortP->MagicFlags &= ~MAGIC_REBOOT;
409                                 }
410
411                                 /*
412                                  ** As mentioned above, this is a tacky hack to cope
413                                  ** with WFLUSH
414                                  */
415                                 if (PortP->WflushFlag) {
416                                         rio_dprintk(RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
417
418                                         if (PortP->InUse)
419                                                 rio_dprintk(RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
420                                 }
421
422                                 while (PortP->WflushFlag && can_add_transmit(&PacketP, PortP) && (PortP->InUse == NOT_INUSE)) {
423                                         int p;
424                                         struct PktCmd __iomem *PktCmdP;
425
426                                         rio_dprintk(RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
427                                         /*
428                                          ** make it look just like a WFLUSH command
429                                          */
430                                         PktCmdP = (struct PktCmd __iomem *) &PacketP->data[0];
431
432                                         writeb(WFLUSH, &PktCmdP->Command);
433
434                                         p = PortP->HostPort % (u16) PORTS_PER_RTA;
435
436                                         /*
437                                          ** If second block of ports for 16 port RTA, add 8
438                                          ** to index 8-15.
439                                          */
440                                         if (PortP->SecondBlock)
441                                                 p += PORTS_PER_RTA;
442
443                                         writeb(p, &PktCmdP->PhbNum);
444
445                                         /*
446                                          ** to make debuggery easier
447                                          */
448                                         writeb('W', &PacketP->data[2]);
449                                         writeb('F', &PacketP->data[3]);
450                                         writeb('L', &PacketP->data[4]);
451                                         writeb('U', &PacketP->data[5]);
452                                         writeb('S', &PacketP->data[6]);
453                                         writeb('H', &PacketP->data[7]);
454                                         writeb(' ', &PacketP->data[8]);
455                                         writeb('0' + PortP->WflushFlag, &PacketP->data[9]);
456                                         writeb(' ', &PacketP->data[10]);
457                                         writeb(' ', &PacketP->data[11]);
458                                         writeb('\0', &PacketP->data[12]);
459
460                                         /*
461                                          ** its two bytes long!
462                                          */
463                                         writeb(PKT_CMD_BIT | 2, &PacketP->len);
464
465                                         /*
466                                          ** queue it!
467                                          */
468                                         if (!(PortP->State & RIO_DELETED)) {
469                                                 add_transmit(PortP);
470                                                 /*
471                                                  ** Count chars tx'd for port statistics reporting
472                                                  */
473                                                 if (PortP->statsGather)
474                                                         PortP->txchars += 2;
475                                         }
476
477                                         if (--(PortP->WflushFlag) == 0) {
478                                                 PortP->MagicFlags &= ~MAGIC_FLUSH;
479                                         }
480
481                                         rio_dprintk(RIO_DEBUG_INTR, "Wflush count now stands at %d\n", PortP->WflushFlag);
482                                 }
483                                 if (PortP->MagicFlags & MORE_OUTPUT_EYGOR) {
484                                         if (PortP->MagicFlags & MAGIC_FLUSH) {
485                                                 PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
486                                         } else {
487                                                 if (!can_add_transmit(&PacketP, PortP)) {
488                                                         rio_spin_unlock(&PortP->portSem);
489                                                         continue;
490                                                 }
491                                                 rio_spin_unlock(&PortP->portSem);
492                                                 RIOTxEnable((char *) PortP);
493                                                 rio_spin_lock(&PortP->portSem);
494                                                 PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
495                                         }
496                                 }
497                         }
498
499
500                         /*
501                          ** If we can't add anything to the transmit queue, then
502                          ** we need do none of the remaining processing.
503                          */
504                         if (!can_add_transmit(&PacketP, PortP)) {
505                                 rio_spin_unlock(&PortP->portSem);
506                                 continue;
507                         }
508
509                         rio_spin_unlock(&PortP->portSem);
510                         RIOTxEnable((char *) PortP);
511                 }
512         }
513 }
514
515 /*
516 ** Routine for handling received data for tty drivers
517 */
518 static void RIOReceive(struct rio_info *p, struct Port *PortP)
519 {
520         struct tty_struct *TtyP;
521         unsigned short transCount;
522         struct PKT __iomem *PacketP;
523         register unsigned int DataCnt;
524         unsigned char __iomem *ptr;
525         unsigned char *buf;
526         int copied = 0;
527
528         static int intCount, RxIntCnt;
529
530         /*
531          ** The receive data process is to remove packets from the
532          ** PHB until there aren't any more or the current cblock
533          ** is full. When this occurs, there will be some left over
534          ** data in the packet, that we must do something with.
535          ** As we haven't unhooked the packet from the read list
536          ** yet, we can just leave the packet there, having first
537          ** made a note of how far we got. This means that we need
538          ** a pointer per port saying where we start taking the
539          ** data from - this will normally be zero, but when we
540          ** run out of space it will be set to the offset of the
541          ** next byte to copy from the packet data area. The packet
542          ** length field is decremented by the number of bytes that
543          ** we successfully removed from the packet. When this reaches
544          ** zero, we reset the offset pointer to be zero, and free
545          ** the packet from the front of the queue.
546          */
547
548         intCount++;
549
550         TtyP = PortP->gs.tty;
551         if (!TtyP) {
552                 rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
553                 return;
554         }
555
556         if (PortP->State & RIO_THROTTLE_RX) {
557                 rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
558                 return;
559         }
560
561         if (PortP->State & RIO_DELETED) {
562                 while (can_remove_receive(&PacketP, PortP)) {
563                         remove_receive(PortP);
564                         put_free_end(PortP->HostP, PacketP);
565                 }
566         } else {
567                 /*
568                  ** loop, just so long as:
569                  **   i ) there's some data ( i.e. can_remove_receive )
570                  **  ii ) we haven't been blocked
571                  ** iii ) there's somewhere to put the data
572                  **  iv ) we haven't outstayed our welcome
573                  */
574                 transCount = 1;
575                 while (can_remove_receive(&PacketP, PortP)
576                        && transCount) {
577                         RxIntCnt++;
578
579                         /*
580                          ** check that it is not a command!
581                          */
582                         if (readb(&PacketP->len) & PKT_CMD_BIT) {
583                                 rio_dprintk(RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
584                                 /*      rio_dprint(RIO_DEBUG_INTR, (" sysport   = %d\n", p->RIOPortp->PortNum)); */
585                                 rio_dprintk(RIO_DEBUG_INTR, " dest_unit = %d\n", readb(&PacketP->dest_unit));
586                                 rio_dprintk(RIO_DEBUG_INTR, " dest_port = %d\n", readb(&PacketP->dest_port));
587                                 rio_dprintk(RIO_DEBUG_INTR, " src_unit  = %d\n", readb(&PacketP->src_unit));
588                                 rio_dprintk(RIO_DEBUG_INTR, " src_port  = %d\n", readb(&PacketP->src_port));
589                                 rio_dprintk(RIO_DEBUG_INTR, " len          = %d\n", readb(&PacketP->len));
590                                 rio_dprintk(RIO_DEBUG_INTR, " control   = %d\n", readb(&PacketP->control));
591                                 rio_dprintk(RIO_DEBUG_INTR, " csum         = %d\n", readw(&PacketP->csum));
592                                 rio_dprintk(RIO_DEBUG_INTR, "    data bytes: ");
593                                 for (DataCnt = 0; DataCnt < PKT_MAX_DATA_LEN; DataCnt++)
594                                         rio_dprintk(RIO_DEBUG_INTR, "%d\n", readb(&PacketP->data[DataCnt]));
595                                 remove_receive(PortP);
596                                 put_free_end(PortP->HostP, PacketP);
597                                 continue;       /* with next packet */
598                         }
599
600                         /*
601                          ** How many characters can we move 'upstream' ?
602                          **
603                          ** Determine the minimum of the amount of data
604                          ** available and the amount of space in which to
605                          ** put it.
606                          **
607                          ** 1.        Get the packet length by masking 'len'
608                          **   for only the length bits.
609                          ** 2.        Available space is [buffer size] - [space used]
610                          **
611                          ** Transfer count is the minimum of packet length
612                          ** and available space.
613                          */
614
615                         transCount = tty_buffer_request_room(TtyP, readb(&PacketP->len) & PKT_LEN_MASK);
616                         rio_dprintk(RIO_DEBUG_REC, "port %d: Copy %d bytes\n", PortP->PortNum, transCount);
617                         /*
618                          ** To use the following 'kkprintfs' for debugging - change the '#undef'
619                          ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
620                          ** driver).
621                          */
622                         ptr = (unsigned char __iomem *) PacketP->data + PortP->RxDataStart;
623
624                         tty_prepare_flip_string(TtyP, &buf, transCount);
625                         rio_memcpy_fromio(buf, ptr, transCount);
626                         PortP->RxDataStart += transCount;
627                         writeb(readb(&PacketP->len)-transCount, &PacketP->len);
628                         copied += transCount;
629
630
631
632                         if (readb(&PacketP->len) == 0) {
633                                 /*
634                                  ** If we have emptied the packet, then we can
635                                  ** free it, and reset the start pointer for
636                                  ** the next packet.
637                                  */
638                                 remove_receive(PortP);
639                                 put_free_end(PortP->HostP, PacketP);
640                                 PortP->RxDataStart = 0;
641                         }
642                 }
643         }
644         if (copied) {
645                 rio_dprintk(RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
646                 tty_flip_buffer_push(TtyP);
647         }
648
649         return;
650 }
651