riointr.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  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 "typdef.h"
  52. #include "pkt.h"
  53. #include "daemon.h"
  54. #include "rio.h"
  55. #include "riospace.h"
  56. #include "top.h"
  57. #include "cmdpkt.h"
  58. #include "map.h"
  59. #include "riotypes.h"
  60. #include "rup.h"
  61. #include "port.h"
  62. #include "riodrvr.h"
  63. #include "rioinfo.h"
  64. #include "func.h"
  65. #include "errors.h"
  66. #include "pci.h"
  67. #include "parmmap.h"
  68. #include "unixrup.h"
  69. #include "board.h"
  70. #include "host.h"
  71. #include "error.h"
  72. #include "phb.h"
  73. #include "link.h"
  74. #include "cmdblk.h"
  75. #include "route.h"
  76. #include "control.h"
  77. #include "cirrus.h"
  78. #include "rioioctl.h"
  79. static void RIOReceive(struct rio_info *, struct Port *);
  80. static char *firstchars(char *p, int nch)
  81. {
  82. static char buf[2][128];
  83. static int t = 0;
  84. t = !t;
  85. memcpy(buf[t], p, nch);
  86. buf[t][nch] = 0;
  87. return buf[t];
  88. }
  89. #define INCR( P, I ) ((P) = (((P)+(I)) & p->RIOBufferMask))
  90. /* Enable and start the transmission of packets */
  91. void RIOTxEnable(en)
  92. char *en;
  93. {
  94. struct Port *PortP;
  95. struct rio_info *p;
  96. struct tty_struct *tty;
  97. int c;
  98. struct PKT *PacketP;
  99. unsigned long flags;
  100. PortP = (struct Port *) en;
  101. p = (struct rio_info *) PortP->p;
  102. tty = PortP->gs.tty;
  103. rio_dprintk(RIO_DEBUG_INTR, "tx port %d: %d chars queued.\n", PortP->PortNum, PortP->gs.xmit_cnt);
  104. if (!PortP->gs.xmit_cnt)
  105. return;
  106. /* This routine is an order of magnitude simpler than the specialix
  107. version. One of the disadvantages is that this version will send
  108. an incomplete packet (usually 64 bytes instead of 72) once for
  109. every 4k worth of data. Let's just say that this won't influence
  110. performance significantly..... */
  111. rio_spin_lock_irqsave(&PortP->portSem, flags);
  112. while (can_add_transmit(&PacketP, PortP)) {
  113. c = PortP->gs.xmit_cnt;
  114. if (c > PKT_MAX_DATA_LEN)
  115. c = PKT_MAX_DATA_LEN;
  116. /* Don't copy past the end of the source buffer */
  117. if (c > SERIAL_XMIT_SIZE - PortP->gs.xmit_tail)
  118. c = SERIAL_XMIT_SIZE - PortP->gs.xmit_tail;
  119. {
  120. int t;
  121. t = (c > 10) ? 10 : c;
  122. 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));
  123. }
  124. /* If for one reason or another, we can't copy more data,
  125. we're done! */
  126. if (c == 0)
  127. break;
  128. rio_memcpy_toio(PortP->HostP->Caddr, (caddr_t) PacketP->data, PortP->gs.xmit_buf + PortP->gs.xmit_tail, c);
  129. /* udelay (1); */
  130. writeb(c, &(PacketP->len));
  131. if (!(PortP->State & RIO_DELETED)) {
  132. add_transmit(PortP);
  133. /*
  134. ** Count chars tx'd for port statistics reporting
  135. */
  136. if (PortP->statsGather)
  137. PortP->txchars += c;
  138. }
  139. PortP->gs.xmit_tail = (PortP->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE - 1);
  140. PortP->gs.xmit_cnt -= c;
  141. }
  142. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  143. if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN)) {
  144. 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);
  145. if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && PortP->gs.tty->ldisc.write_wakeup)
  146. (PortP->gs.tty->ldisc.write_wakeup) (PortP->gs.tty);
  147. rio_dprintk(RIO_DEBUG_INTR, "(%d/%d)\n", PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
  148. wake_up_interruptible(&PortP->gs.tty->write_wait);
  149. }
  150. }
  151. /*
  152. ** RIO Host Service routine. Does all the work traditionally associated with an
  153. ** interrupt.
  154. */
  155. static int RupIntr;
  156. static int RxIntr;
  157. static int TxIntr;
  158. void RIOServiceHost(p, HostP, From)
  159. struct rio_info *p;
  160. struct Host *HostP;
  161. int From;
  162. {
  163. rio_spin_lock(&HostP->HostLock);
  164. if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
  165. static int t = 0;
  166. rio_spin_unlock(&HostP->HostLock);
  167. if ((t++ % 200) == 0)
  168. rio_dprintk(RIO_DEBUG_INTR, "Interrupt but host not running. flags=%x.\n", (int) HostP->Flags);
  169. return;
  170. }
  171. rio_spin_unlock(&HostP->HostLock);
  172. if (RWORD(HostP->ParmMapP->rup_intr)) {
  173. WWORD(HostP->ParmMapP->rup_intr, 0);
  174. p->RIORupCount++;
  175. RupIntr++;
  176. rio_dprintk(RIO_DEBUG_INTR, "rio: RUP interrupt on host %d\n", HostP - p->RIOHosts);
  177. RIOPollHostCommands(p, HostP);
  178. }
  179. if (RWORD(HostP->ParmMapP->rx_intr)) {
  180. int port;
  181. WWORD(HostP->ParmMapP->rx_intr, 0);
  182. p->RIORxCount++;
  183. RxIntr++;
  184. rio_dprintk(RIO_DEBUG_INTR, "rio: RX interrupt on host %d\n", HostP - p->RIOHosts);
  185. /*
  186. ** Loop through every port. If the port is mapped into
  187. ** the system ( i.e. has /dev/ttyXXXX associated ) then it is
  188. ** worth checking. If the port isn't open, grab any packets
  189. ** hanging on its receive queue and stuff them on the free
  190. ** list; check for commands on the way.
  191. */
  192. for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
  193. struct Port *PortP = p->RIOPortp[port];
  194. struct tty_struct *ttyP;
  195. struct PKT *PacketP;
  196. /*
  197. ** not mapped in - most of the RIOPortp[] information
  198. ** has not been set up!
  199. ** Optimise: ports come in bundles of eight.
  200. */
  201. if (!PortP->Mapped) {
  202. port += 7;
  203. continue; /* with the next port */
  204. }
  205. /*
  206. ** If the host board isn't THIS host board, check the next one.
  207. ** optimise: ports come in bundles of eight.
  208. */
  209. if (PortP->HostP != HostP) {
  210. port += 7;
  211. continue;
  212. }
  213. /*
  214. ** Let us see - is the port open? If not, then don't service it.
  215. */
  216. if (!(PortP->PortState & PORT_ISOPEN)) {
  217. continue;
  218. }
  219. /*
  220. ** find corresponding tty structure. The process of mapping
  221. ** the ports puts these here.
  222. */
  223. ttyP = PortP->gs.tty;
  224. /*
  225. ** Lock the port before we begin working on it.
  226. */
  227. rio_spin_lock(&PortP->portSem);
  228. /*
  229. ** Process received data if there is any.
  230. */
  231. if (can_remove_receive(&PacketP, PortP))
  232. RIOReceive(p, PortP);
  233. /*
  234. ** If there is no data left to be read from the port, and
  235. ** it's handshake bit is set, then we must clear the handshake,
  236. ** so that that downstream RTA is re-enabled.
  237. */
  238. if (!can_remove_receive(&PacketP, PortP) && (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET)) {
  239. /*
  240. ** MAGIC! ( Basically, handshake the RX buffer, so that
  241. ** the RTAs upstream can be re-enabled. )
  242. */
  243. rio_dprintk(RIO_DEBUG_INTR, "Set RX handshake bit\n");
  244. WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
  245. }
  246. rio_spin_unlock(&PortP->portSem);
  247. }
  248. }
  249. if (RWORD(HostP->ParmMapP->tx_intr)) {
  250. int port;
  251. WWORD(HostP->ParmMapP->tx_intr, 0);
  252. p->RIOTxCount++;
  253. TxIntr++;
  254. rio_dprintk(RIO_DEBUG_INTR, "rio: TX interrupt on host %d\n", HostP - p->RIOHosts);
  255. /*
  256. ** Loop through every port.
  257. ** If the port is mapped into the system ( i.e. has /dev/ttyXXXX
  258. ** associated ) then it is worth checking.
  259. */
  260. for (port = p->RIOFirstPortsBooted; port < p->RIOLastPortsBooted + PORTS_PER_RTA; port++) {
  261. struct Port *PortP = p->RIOPortp[port];
  262. struct tty_struct *ttyP;
  263. struct PKT *PacketP;
  264. /*
  265. ** not mapped in - most of the RIOPortp[] information
  266. ** has not been set up!
  267. */
  268. if (!PortP->Mapped) {
  269. port += 7;
  270. continue; /* with the next port */
  271. }
  272. /*
  273. ** If the host board isn't running, then its data structures
  274. ** are no use to us - continue quietly.
  275. */
  276. if (PortP->HostP != HostP) {
  277. port += 7;
  278. continue; /* with the next port */
  279. }
  280. /*
  281. ** Let us see - is the port open? If not, then don't service it.
  282. */
  283. if (!(PortP->PortState & PORT_ISOPEN)) {
  284. continue;
  285. }
  286. rio_dprintk(RIO_DEBUG_INTR, "rio: Looking into port %d.\n", port);
  287. /*
  288. ** Lock the port before we begin working on it.
  289. */
  290. rio_spin_lock(&PortP->portSem);
  291. /*
  292. ** If we can't add anything to the transmit queue, then
  293. ** we need do none of this processing.
  294. */
  295. if (!can_add_transmit(&PacketP, PortP)) {
  296. rio_dprintk(RIO_DEBUG_INTR, "Can't add to port, so skipping.\n");
  297. rio_spin_unlock(&PortP->portSem);
  298. continue;
  299. }
  300. /*
  301. ** find corresponding tty structure. The process of mapping
  302. ** the ports puts these here.
  303. */
  304. ttyP = PortP->gs.tty;
  305. /* If ttyP is NULL, the port is getting closed. Forget about it. */
  306. if (!ttyP) {
  307. rio_dprintk(RIO_DEBUG_INTR, "no tty, so skipping.\n");
  308. rio_spin_unlock(&PortP->portSem);
  309. continue;
  310. }
  311. /*
  312. ** If there is more room available we start up the transmit
  313. ** data process again. This can be direct I/O, if the cookmode
  314. ** is set to COOK_RAW or COOK_MEDIUM, or will be a call to the
  315. ** riotproc( T_OUTPUT ) if we are in COOK_WELL mode, to fetch
  316. ** characters via the line discipline. We must always call
  317. ** the line discipline,
  318. ** so that user input characters can be echoed correctly.
  319. **
  320. ** ++++ Update +++++
  321. ** With the advent of double buffering, we now see if
  322. ** TxBufferOut-In is non-zero. If so, then we copy a packet
  323. ** to the output place, and set it going. If this empties
  324. ** the buffer, then we must issue a wakeup( ) on OUT.
  325. ** If it frees space in the buffer then we must issue
  326. ** a wakeup( ) on IN.
  327. **
  328. ** ++++ Extra! Extra! If PortP->WflushFlag is set, then we
  329. ** have to send a WFLUSH command down the PHB, to mark the
  330. ** end point of a WFLUSH. We also need to clear out any
  331. ** data from the double buffer! ( note that WflushFlag is a
  332. ** *count* of the number of WFLUSH commands outstanding! )
  333. **
  334. ** ++++ And there's more!
  335. ** If an RTA is powered off, then on again, and rebooted,
  336. ** whilst it has ports open, then we need to re-open the ports.
  337. ** ( reasonable enough ). We can't do this when we spot the
  338. ** re-boot, in interrupt time, because the queue is probably
  339. ** full. So, when we come in here, we need to test if any
  340. ** ports are in this condition, and re-open the port before
  341. ** we try to send any more data to it. Now, the re-booted
  342. ** RTA will be discarding packets from the PHB until it
  343. ** receives this open packet, but don't worry tooo much
  344. ** about that. The one thing that is interesting is the
  345. ** combination of this effect and the WFLUSH effect!
  346. */
  347. /* For now don't handle RTA reboots. -- REW.
  348. Reenabled. Otherwise RTA reboots didn't work. Duh. -- REW */
  349. if (PortP->MagicFlags) {
  350. #if 1
  351. if (PortP->MagicFlags & MAGIC_REBOOT) {
  352. /*
  353. ** well, the RTA has been rebooted, and there is room
  354. ** on its queue to add the open packet that is required.
  355. **
  356. ** The messy part of this line is trying to decide if
  357. ** we need to call the Param function as a tty or as
  358. ** a modem.
  359. ** DONT USE CLOCAL AS A TEST FOR THIS!
  360. **
  361. ** If we can't param the port, then move on to the
  362. ** next port.
  363. */
  364. PortP->InUse = NOT_INUSE;
  365. rio_spin_unlock(&PortP->portSem);
  366. if (RIOParam(PortP, OPEN, ((PortP->Cor2Copy & (COR2_RTSFLOW | COR2_CTSFLOW)) == (COR2_RTSFLOW | COR2_CTSFLOW)) ? TRUE : FALSE, DONT_SLEEP) == RIO_FAIL) {
  367. continue; /* with next port */
  368. }
  369. rio_spin_lock(&PortP->portSem);
  370. PortP->MagicFlags &= ~MAGIC_REBOOT;
  371. }
  372. #endif
  373. /*
  374. ** As mentioned above, this is a tacky hack to cope
  375. ** with WFLUSH
  376. */
  377. if (PortP->WflushFlag) {
  378. rio_dprintk(RIO_DEBUG_INTR, "Want to WFLUSH mark this port\n");
  379. if (PortP->InUse)
  380. rio_dprintk(RIO_DEBUG_INTR, "FAILS - PORT IS IN USE\n");
  381. }
  382. while (PortP->WflushFlag && can_add_transmit(&PacketP, PortP) && (PortP->InUse == NOT_INUSE)) {
  383. int p;
  384. struct PktCmd *PktCmdP;
  385. rio_dprintk(RIO_DEBUG_INTR, "Add WFLUSH marker to data queue\n");
  386. /*
  387. ** make it look just like a WFLUSH command
  388. */
  389. PktCmdP = (struct PktCmd *) &PacketP->data[0];
  390. WBYTE(PktCmdP->Command, WFLUSH);
  391. p = PortP->HostPort % (ushort) PORTS_PER_RTA;
  392. /*
  393. ** If second block of ports for 16 port RTA, add 8
  394. ** to index 8-15.
  395. */
  396. if (PortP->SecondBlock)
  397. p += PORTS_PER_RTA;
  398. WBYTE(PktCmdP->PhbNum, p);
  399. /*
  400. ** to make debuggery easier
  401. */
  402. WBYTE(PacketP->data[2], 'W');
  403. WBYTE(PacketP->data[3], 'F');
  404. WBYTE(PacketP->data[4], 'L');
  405. WBYTE(PacketP->data[5], 'U');
  406. WBYTE(PacketP->data[6], 'S');
  407. WBYTE(PacketP->data[7], 'H');
  408. WBYTE(PacketP->data[8], ' ');
  409. WBYTE(PacketP->data[9], '0' + PortP->WflushFlag);
  410. WBYTE(PacketP->data[10], ' ');
  411. WBYTE(PacketP->data[11], ' ');
  412. WBYTE(PacketP->data[12], '\0');
  413. /*
  414. ** its two bytes long!
  415. */
  416. WBYTE(PacketP->len, PKT_CMD_BIT | 2);
  417. /*
  418. ** queue it!
  419. */
  420. if (!(PortP->State & RIO_DELETED)) {
  421. add_transmit(PortP);
  422. /*
  423. ** Count chars tx'd for port statistics reporting
  424. */
  425. if (PortP->statsGather)
  426. PortP->txchars += 2;
  427. }
  428. if (--(PortP->WflushFlag) == 0) {
  429. PortP->MagicFlags &= ~MAGIC_FLUSH;
  430. }
  431. rio_dprintk(RIO_DEBUG_INTR, "Wflush count now stands at %d\n", PortP->WflushFlag);
  432. }
  433. if (PortP->MagicFlags & MORE_OUTPUT_EYGOR) {
  434. if (PortP->MagicFlags & MAGIC_FLUSH) {
  435. PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
  436. } else {
  437. if (!can_add_transmit(&PacketP, PortP)) {
  438. rio_spin_unlock(&PortP->portSem);
  439. continue;
  440. }
  441. rio_spin_unlock(&PortP->portSem);
  442. RIOTxEnable((char *) PortP);
  443. rio_spin_lock(&PortP->portSem);
  444. PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
  445. }
  446. }
  447. }
  448. /*
  449. ** If we can't add anything to the transmit queue, then
  450. ** we need do none of the remaining processing.
  451. */
  452. if (!can_add_transmit(&PacketP, PortP)) {
  453. rio_spin_unlock(&PortP->portSem);
  454. continue;
  455. }
  456. rio_spin_unlock(&PortP->portSem);
  457. RIOTxEnable((char *) PortP);
  458. }
  459. }
  460. }
  461. /*
  462. ** Routine for handling received data for clist drivers.
  463. ** NB: Called with the tty locked. The spl from the lockb( ) is passed.
  464. ** we return the ttySpl level that we re-locked at.
  465. */
  466. static void RIOReceive(p, PortP)
  467. struct rio_info *p;
  468. struct Port *PortP;
  469. {
  470. struct tty_struct *TtyP;
  471. register ushort transCount;
  472. struct PKT *PacketP;
  473. register uint DataCnt;
  474. uchar *ptr;
  475. unsigned char *buf;
  476. int copied = 0;
  477. static int intCount, RxIntCnt;
  478. /*
  479. ** The receive data process is to remove packets from the
  480. ** PHB until there aren't any more or the current cblock
  481. ** is full. When this occurs, there will be some left over
  482. ** data in the packet, that we must do something with.
  483. ** As we haven't unhooked the packet from the read list
  484. ** yet, we can just leave the packet there, having first
  485. ** made a note of how far we got. This means that we need
  486. ** a pointer per port saying where we start taking the
  487. ** data from - this will normally be zero, but when we
  488. ** run out of space it will be set to the offset of the
  489. ** next byte to copy from the packet data area. The packet
  490. ** length field is decremented by the number of bytes that
  491. ** we succesfully removed from the packet. When this reaches
  492. ** zero, we reset the offset pointer to be zero, and free
  493. ** the packet from the front of the queue.
  494. */
  495. intCount++;
  496. TtyP = PortP->gs.tty;
  497. if (!TtyP) {
  498. rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: tty is null. \n");
  499. return;
  500. }
  501. if (PortP->State & RIO_THROTTLE_RX) {
  502. rio_dprintk(RIO_DEBUG_INTR, "RIOReceive: Throttled. Can't handle more input.\n");
  503. return;
  504. }
  505. if (PortP->State & RIO_DELETED) {
  506. while (can_remove_receive(&PacketP, PortP)) {
  507. remove_receive(PortP);
  508. put_free_end(PortP->HostP, PacketP);
  509. }
  510. } else {
  511. /*
  512. ** loop, just so long as:
  513. ** i ) there's some data ( i.e. can_remove_receive )
  514. ** ii ) we haven't been blocked
  515. ** iii ) there's somewhere to put the data
  516. ** iv ) we haven't outstayed our welcome
  517. */
  518. transCount = 1;
  519. while (can_remove_receive(&PacketP, PortP)
  520. && transCount) {
  521. #ifdef STATS
  522. PortP->Stat.RxIntCnt++;
  523. #endif /* STATS */
  524. RxIntCnt++;
  525. /*
  526. ** check that it is not a command!
  527. */
  528. if (PacketP->len & PKT_CMD_BIT) {
  529. rio_dprintk(RIO_DEBUG_INTR, "RIO: unexpected command packet received on PHB\n");
  530. /* rio_dprint(RIO_DEBUG_INTR, (" sysport = %d\n", p->RIOPortp->PortNum)); */
  531. rio_dprintk(RIO_DEBUG_INTR, " dest_unit = %d\n", PacketP->dest_unit);
  532. rio_dprintk(RIO_DEBUG_INTR, " dest_port = %d\n", PacketP->dest_port);
  533. rio_dprintk(RIO_DEBUG_INTR, " src_unit = %d\n", PacketP->src_unit);
  534. rio_dprintk(RIO_DEBUG_INTR, " src_port = %d\n", PacketP->src_port);
  535. rio_dprintk(RIO_DEBUG_INTR, " len = %d\n", PacketP->len);
  536. rio_dprintk(RIO_DEBUG_INTR, " control = %d\n", PacketP->control);
  537. rio_dprintk(RIO_DEBUG_INTR, " csum = %d\n", PacketP->csum);
  538. rio_dprintk(RIO_DEBUG_INTR, " data bytes: ");
  539. for (DataCnt = 0; DataCnt < PKT_MAX_DATA_LEN; DataCnt++)
  540. rio_dprintk(RIO_DEBUG_INTR, "%d\n", PacketP->data[DataCnt]);
  541. remove_receive(PortP);
  542. put_free_end(PortP->HostP, PacketP);
  543. continue; /* with next packet */
  544. }
  545. /*
  546. ** How many characters can we move 'upstream' ?
  547. **
  548. ** Determine the minimum of the amount of data
  549. ** available and the amount of space in which to
  550. ** put it.
  551. **
  552. ** 1. Get the packet length by masking 'len'
  553. ** for only the length bits.
  554. ** 2. Available space is [buffer size] - [space used]
  555. **
  556. ** Transfer count is the minimum of packet length
  557. ** and available space.
  558. */
  559. transCount = tty_buffer_request_room(TtyP, PacketP->len & PKT_LEN_MASK);
  560. rio_dprintk(RIO_DEBUG_REC, "port %d: Copy %d bytes\n", PortP->PortNum, transCount);
  561. /*
  562. ** To use the following 'kkprintfs' for debugging - change the '#undef'
  563. ** to '#define', (this is the only place ___DEBUG_IT___ occurs in the
  564. ** driver).
  565. */
  566. #undef ___DEBUG_IT___
  567. #ifdef ___DEBUG_IT___
  568. kkprintf("I:%d R:%d P:%d Q:%d C:%d F:%x ", intCount, RxIntCnt, PortP->PortNum, TtyP->rxqueue.count, transCount, TtyP->flags);
  569. #endif
  570. ptr = (uchar *) PacketP->data + PortP->RxDataStart;
  571. tty_prepare_flip_string(TtyP, &buf, transCount);
  572. rio_memcpy_fromio(buf, ptr, transCount);
  573. #ifdef STATS
  574. /*
  575. ** keep a count for statistical purposes
  576. */
  577. PortP->Stat.RxCharCnt += transCount;
  578. #endif
  579. PortP->RxDataStart += transCount;
  580. PacketP->len -= transCount;
  581. copied += transCount;
  582. #ifdef ___DEBUG_IT___
  583. kkprintf("T:%d L:%d\n", DataCnt, PacketP->len);
  584. #endif
  585. if (PacketP->len == 0) {
  586. /*
  587. ** If we have emptied the packet, then we can
  588. ** free it, and reset the start pointer for
  589. ** the next packet.
  590. */
  591. remove_receive(PortP);
  592. put_free_end(PortP->HostP, PacketP);
  593. PortP->RxDataStart = 0;
  594. #ifdef STATS
  595. /*
  596. ** more lies ( oops, I mean statistics )
  597. */
  598. PortP->Stat.RxPktCnt++;
  599. #endif /* STATS */
  600. }
  601. }
  602. }
  603. if (copied) {
  604. rio_dprintk(RIO_DEBUG_REC, "port %d: pushing tty flip buffer: %d total bytes copied.\n", PortP->PortNum, copied);
  605. tty_flip_buffer_push(TtyP);
  606. }
  607. return;
  608. }
  609. #ifdef FUTURE_RELEASE
  610. /*
  611. ** The proc routine called by the line discipline to do the work for it.
  612. ** The proc routine works hand in hand with the interrupt routine.
  613. */
  614. int riotproc(p, tp, cmd, port)
  615. struct rio_info *p;
  616. register struct ttystatics *tp;
  617. int cmd;
  618. int port;
  619. {
  620. register struct Port *PortP;
  621. int SysPort;
  622. struct PKT *PacketP;
  623. SysPort = port; /* Believe me, it works. */
  624. if (SysPort < 0 || SysPort >= RIO_PORTS) {
  625. rio_dprintk(RIO_DEBUG_INTR, "Illegal port %d derived from TTY in riotproc()\n", SysPort);
  626. return 0;
  627. }
  628. PortP = p->RIOPortp[SysPort];
  629. if ((uint) PortP->PhbP < (uint) PortP->Caddr || (uint) PortP->PhbP >= (uint) PortP->Caddr + SIXTY_FOUR_K) {
  630. rio_dprintk(RIO_DEBUG_INTR, "RIO: NULL or BAD PhbP on sys port %d in proc routine\n", SysPort);
  631. rio_dprintk(RIO_DEBUG_INTR, " PortP = 0x%x\n", PortP);
  632. rio_dprintk(RIO_DEBUG_INTR, " PortP->PhbP = 0x%x\n", PortP->PhbP);
  633. rio_dprintk(RIO_DEBUG_INTR, " PortP->Caddr = 0x%x\n", PortP->PhbP);
  634. rio_dprintk(RIO_DEBUG_INTR, " PortP->HostPort = 0x%x\n", PortP->HostPort);
  635. return 0;
  636. }
  637. switch (cmd) {
  638. case T_WFLUSH:
  639. rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH\n");
  640. /*
  641. ** Because of the spooky way the RIO works, we don't need
  642. ** to issue a flush command on any of the SET*F commands,
  643. ** as that causes trouble with getty and login, which issue
  644. ** these commands to incur a READ flush, and rely on the fact
  645. ** that the line discipline does a wait for drain for them.
  646. ** As the rio doesn't wait for drain, the write flush would
  647. ** destroy the Password: prompt. This isn't very friendly, so
  648. ** here we only issue a WFLUSH command if we are in the interrupt
  649. ** routine, or we aren't executing a SET*F command.
  650. */
  651. if (PortP->HostP->InIntr || !PortP->FlushCmdBodge) {
  652. /*
  653. ** form a wflush packet - 1 byte long, no data
  654. */
  655. if (PortP->State & RIO_DELETED) {
  656. rio_dprintk(RIO_DEBUG_INTR, "WFLUSH on deleted RTA\n");
  657. } else {
  658. if (RIOPreemptiveCmd(p, PortP, WFLUSH) == RIO_FAIL) {
  659. rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command failed\n");
  660. } else
  661. rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command\n");
  662. }
  663. /*
  664. ** WFLUSH operation - flush the data!
  665. */
  666. PortP->TxBufferIn = PortP->TxBufferOut = 0;
  667. } else {
  668. rio_dprintk(RIO_DEBUG_INTR, "T_WFLUSH Command ignored\n");
  669. }
  670. /*
  671. ** sort out the line discipline
  672. */
  673. if (PortP->CookMode == COOK_WELL)
  674. goto start;
  675. break;
  676. case T_RESUME:
  677. rio_dprintk(RIO_DEBUG_INTR, "T_RESUME\n");
  678. /*
  679. ** send pre-emptive resume packet
  680. */
  681. if (PortP->State & RIO_DELETED) {
  682. rio_dprintk(RIO_DEBUG_INTR, "RESUME on deleted RTA\n");
  683. } else {
  684. if (RIOPreemptiveCmd(p, PortP, RESUME) == RIO_FAIL) {
  685. rio_dprintk(RIO_DEBUG_INTR, "T_RESUME Command failed\n");
  686. }
  687. }
  688. /*
  689. ** and re-start the sender software!
  690. */
  691. if (PortP->CookMode == COOK_WELL)
  692. goto start;
  693. break;
  694. case T_TIME:
  695. rio_dprintk(RIO_DEBUG_INTR, "T_TIME\n");
  696. /*
  697. ** T_TIME is called when xDLY is set in oflags and
  698. ** the line discipline timeout has expired. It's
  699. ** function in life is to clear the TIMEOUT flag
  700. ** and to re-start output to the port.
  701. */
  702. /*
  703. ** Fall through and re-start output
  704. */
  705. case T_OUTPUT:
  706. start:
  707. if (PortP->MagicFlags & MAGIC_FLUSH) {
  708. PortP->MagicFlags |= MORE_OUTPUT_EYGOR;
  709. return 0;
  710. }
  711. RIOTxEnable((char *) PortP);
  712. PortP->MagicFlags &= ~MORE_OUTPUT_EYGOR;
  713. /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"T_OUTPUT finished\n"); */
  714. break;
  715. case T_SUSPEND:
  716. rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND\n");
  717. /*
  718. ** send a suspend pre-emptive packet.
  719. */
  720. if (PortP->State & RIO_DELETED) {
  721. rio_dprintk(RIO_DEBUG_INTR, "SUSPEND deleted RTA\n");
  722. } else {
  723. if (RIOPreemptiveCmd(p, PortP, SUSPEND) == RIO_FAIL) {
  724. rio_dprintk(RIO_DEBUG_INTR, "T_SUSPEND Command failed\n");
  725. }
  726. }
  727. /*
  728. ** done!
  729. */
  730. break;
  731. case T_BLOCK:
  732. rio_dprintk(RIO_DEBUG_INTR, "T_BLOCK\n");
  733. break;
  734. case T_RFLUSH:
  735. rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH\n");
  736. if (PortP->State & RIO_DELETED) {
  737. rio_dprintk(RIO_DEBUG_INTR, "RFLUSH on deleted RTA\n");
  738. PortP->RxDataStart = 0;
  739. } else {
  740. if (RIOPreemptiveCmd(p, PortP, RFLUSH) == RIO_FAIL) {
  741. rio_dprintk(RIO_DEBUG_INTR, "T_RFLUSH Command failed\n");
  742. return 0;
  743. }
  744. PortP->RxDataStart = 0;
  745. while (can_remove_receive(&PacketP, PortP)) {
  746. remove_receive(PortP);
  747. ShowPacket(DBG_PROC, PacketP);
  748. put_free_end(PortP->HostP, PacketP);
  749. }
  750. if (PortP->PhbP->handshake == PHB_HANDSHAKE_SET) {
  751. /*
  752. ** MAGIC!
  753. */
  754. rio_dprintk(RIO_DEBUG_INTR, "Set receive handshake bit\n");
  755. PortP->PhbP->handshake |= PHB_HANDSHAKE_RESET;
  756. }
  757. }
  758. break;
  759. /* FALLTHROUGH */
  760. case T_UNBLOCK:
  761. rio_dprintk(RIO_DEBUG_INTR, "T_UNBLOCK\n");
  762. /*
  763. ** If there is any data to receive set a timeout to service it.
  764. */
  765. RIOReceive(p, PortP);
  766. break;
  767. case T_BREAK:
  768. rio_dprintk(RIO_DEBUG_INTR, "T_BREAK\n");
  769. /*
  770. ** Send a break command. For Sys V
  771. ** this is a timed break, so we
  772. ** send a SBREAK[time] packet
  773. */
  774. /*
  775. ** Build a BREAK command
  776. */
  777. if (PortP->State & RIO_DELETED) {
  778. rio_dprintk(RIO_DEBUG_INTR, "BREAK on deleted RTA\n");
  779. } else {
  780. if (RIOShortCommand(PortP, SBREAK, 2, p->RIOConf.BreakInterval) == RIO_FAIL) {
  781. rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
  782. }
  783. }
  784. /*
  785. ** done!
  786. */
  787. break;
  788. case T_INPUT:
  789. rio_dprintk(RIO_DEBUG_INTR, "Proc T_INPUT called - I don't know what to do!\n");
  790. break;
  791. case T_PARM:
  792. rio_dprintk(RIO_DEBUG_INTR, "Proc T_PARM called - I don't know what to do!\n");
  793. break;
  794. case T_SWTCH:
  795. rio_dprintk(RIO_DEBUG_INTR, "Proc T_SWTCH called - I don't know what to do!\n");
  796. break;
  797. default:
  798. rio_dprintk(RIO_DEBUG_INTR, "Proc UNKNOWN command %d\n", cmd);
  799. }
  800. /*
  801. ** T_OUTPUT returns without passing through this point!
  802. */
  803. /*rio_dprint(RIO_DEBUG_INTR, PortP,DBG_PROC,"riotproc done\n"); */
  804. return (0);
  805. }
  806. #endif