riointr.c 19 KB

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