riointr.c 27 KB

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