riointr.c 19 KB

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