riocmd.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. /*
  2. ** -----------------------------------------------------------------------------
  3. **
  4. ** Perle Specialix driver for Linux
  5. ** ported from the existing SCO driver source
  6. **
  7. *
  8. * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. **
  24. ** Module : riocmd.c
  25. ** SID : 1.2
  26. ** Last Modified : 11/6/98 10:33:41
  27. ** Retrieved : 11/6/98 10:33:49
  28. **
  29. ** ident @(#)riocmd.c 1.2
  30. **
  31. ** -----------------------------------------------------------------------------
  32. */
  33. #ifdef SCCS_LABELS
  34. static char *_riocmd_c_sccs_ = "@(#)riocmd.c 1.2";
  35. #endif
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/tty.h>
  40. #include <asm/io.h>
  41. #include <asm/system.h>
  42. #include <asm/string.h>
  43. #include <asm/semaphore.h>
  44. #include <linux/termios.h>
  45. #include <linux/serial.h>
  46. #include <linux/generic_serial.h>
  47. #include "linux_compat.h"
  48. #include "rio_linux.h"
  49. #include "typdef.h"
  50. #include "pkt.h"
  51. #include "daemon.h"
  52. #include "rio.h"
  53. #include "riospace.h"
  54. #include "top.h"
  55. #include "cmdpkt.h"
  56. #include "map.h"
  57. #include "riotypes.h"
  58. #include "rup.h"
  59. #include "port.h"
  60. #include "riodrvr.h"
  61. #include "rioinfo.h"
  62. #include "func.h"
  63. #include "errors.h"
  64. #include "pci.h"
  65. #include "parmmap.h"
  66. #include "unixrup.h"
  67. #include "board.h"
  68. #include "host.h"
  69. #include "error.h"
  70. #include "phb.h"
  71. #include "link.h"
  72. #include "cmdblk.h"
  73. #include "route.h"
  74. #include "control.h"
  75. #include "cirrus.h"
  76. static struct IdentifyRta IdRta;
  77. static struct KillNeighbour KillUnit;
  78. int
  79. RIOFoadRta(struct Host *HostP, struct Map *MapP)
  80. {
  81. struct CmdBlk *CmdBlkP;
  82. rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA\n");
  83. CmdBlkP = RIOGetCmdBlk();
  84. if ( !CmdBlkP ) {
  85. rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA: GetCmdBlk failed\n");
  86. return -ENXIO;
  87. }
  88. CmdBlkP->Packet.dest_unit = MapP->ID;
  89. CmdBlkP->Packet.dest_port = BOOT_RUP;
  90. CmdBlkP->Packet.src_unit = 0;
  91. CmdBlkP->Packet.src_port = BOOT_RUP;
  92. CmdBlkP->Packet.len = 0x84;
  93. CmdBlkP->Packet.data[0] = IFOAD;
  94. CmdBlkP->Packet.data[1] = 0;
  95. CmdBlkP->Packet.data[2] = IFOAD_MAGIC & 0xFF;
  96. CmdBlkP->Packet.data[3] = (IFOAD_MAGIC >> 8) & 0xFF;
  97. if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
  98. rio_dprintk (RIO_DEBUG_CMD, "FOAD RTA: Failed to queue foad command\n");
  99. return -EIO;
  100. }
  101. return 0;
  102. }
  103. int
  104. RIOZombieRta(struct Host *HostP, struct Map *MapP)
  105. {
  106. struct CmdBlk *CmdBlkP;
  107. rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA\n");
  108. CmdBlkP = RIOGetCmdBlk();
  109. if ( !CmdBlkP ) {
  110. rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA: GetCmdBlk failed\n");
  111. return -ENXIO;
  112. }
  113. CmdBlkP->Packet.dest_unit = MapP->ID;
  114. CmdBlkP->Packet.dest_port = BOOT_RUP;
  115. CmdBlkP->Packet.src_unit = 0;
  116. CmdBlkP->Packet.src_port = BOOT_RUP;
  117. CmdBlkP->Packet.len = 0x84;
  118. CmdBlkP->Packet.data[0] = ZOMBIE;
  119. CmdBlkP->Packet.data[1] = 0;
  120. CmdBlkP->Packet.data[2] = ZOMBIE_MAGIC & 0xFF;
  121. CmdBlkP->Packet.data[3] = (ZOMBIE_MAGIC >> 8) & 0xFF;
  122. if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
  123. rio_dprintk (RIO_DEBUG_CMD, "ZOMBIE RTA: Failed to queue zombie command\n");
  124. return -EIO;
  125. }
  126. return 0;
  127. }
  128. int
  129. RIOCommandRta(struct rio_info *p, uint RtaUnique,
  130. int (* func)(struct Host *HostP, struct Map *MapP))
  131. {
  132. uint Host;
  133. rio_dprintk (RIO_DEBUG_CMD, "Command RTA 0x%x func 0x%x\n", RtaUnique, (int)func);
  134. if ( !RtaUnique )
  135. return(0);
  136. for ( Host = 0; Host < p->RIONumHosts; Host++ ) {
  137. uint Rta;
  138. struct Host *HostP = &p->RIOHosts[Host];
  139. for ( Rta = 0; Rta < RTAS_PER_HOST; Rta++ ) {
  140. struct Map *MapP = &HostP->Mapping[Rta];
  141. if ( MapP->RtaUniqueNum == RtaUnique ) {
  142. uint Link;
  143. /*
  144. ** now, lets just check we have a route to it...
  145. ** IF the routing stuff is working, then one of the
  146. ** topology entries for this unit will have a legit
  147. ** route *somewhere*. We care not where - if its got
  148. ** any connections, we can get to it.
  149. */
  150. for ( Link = 0; Link < LINKS_PER_UNIT; Link++ ) {
  151. if ( MapP->Topology[Link].Unit <= (uchar)MAX_RUP ) {
  152. /*
  153. ** Its worth trying the operation...
  154. */
  155. return (*func)( HostP, MapP );
  156. }
  157. }
  158. }
  159. }
  160. }
  161. return -ENXIO;
  162. }
  163. int
  164. RIOIdentifyRta(struct rio_info *p, caddr_t arg)
  165. {
  166. uint Host;
  167. if ( copyin( (int)arg, (caddr_t)&IdRta, sizeof(IdRta) ) == COPYFAIL ) {
  168. rio_dprintk (RIO_DEBUG_CMD, "RIO_IDENTIFY_RTA copy failed\n");
  169. p->RIOError.Error = COPYIN_FAILED;
  170. return -EFAULT;
  171. }
  172. for ( Host = 0 ; Host < p->RIONumHosts; Host++ ) {
  173. uint Rta;
  174. struct Host *HostP = &p->RIOHosts[Host];
  175. for ( Rta = 0; Rta < RTAS_PER_HOST; Rta++ ) {
  176. struct Map *MapP = &HostP->Mapping[Rta];
  177. if ( MapP->RtaUniqueNum == IdRta.RtaUnique ) {
  178. uint Link;
  179. /*
  180. ** now, lets just check we have a route to it...
  181. ** IF the routing stuff is working, then one of the
  182. ** topology entries for this unit will have a legit
  183. ** route *somewhere*. We care not where - if its got
  184. ** any connections, we can get to it.
  185. */
  186. for ( Link = 0; Link < LINKS_PER_UNIT; Link++ ) {
  187. if ( MapP->Topology[Link].Unit <= (uchar)MAX_RUP ) {
  188. /*
  189. ** Its worth trying the operation...
  190. */
  191. struct CmdBlk *CmdBlkP;
  192. rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA\n");
  193. CmdBlkP = RIOGetCmdBlk();
  194. if ( !CmdBlkP ) {
  195. rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA: GetCmdBlk failed\n");
  196. return -ENXIO;
  197. }
  198. CmdBlkP->Packet.dest_unit = MapP->ID;
  199. CmdBlkP->Packet.dest_port = BOOT_RUP;
  200. CmdBlkP->Packet.src_unit = 0;
  201. CmdBlkP->Packet.src_port = BOOT_RUP;
  202. CmdBlkP->Packet.len = 0x84;
  203. CmdBlkP->Packet.data[0] = IDENTIFY;
  204. CmdBlkP->Packet.data[1] = 0;
  205. CmdBlkP->Packet.data[2] = IdRta.ID;
  206. if ( RIOQueueCmdBlk( HostP, MapP->ID-1, CmdBlkP) == RIO_FAIL ) {
  207. rio_dprintk (RIO_DEBUG_CMD, "IDENTIFY RTA: Failed to queue command\n");
  208. return -EIO;
  209. }
  210. return 0;
  211. }
  212. }
  213. }
  214. }
  215. }
  216. return -ENOENT;
  217. }
  218. int
  219. RIOKillNeighbour(struct rio_info *p, caddr_t arg)
  220. {
  221. uint Host;
  222. uint ID;
  223. struct Host *HostP;
  224. struct CmdBlk *CmdBlkP;
  225. rio_dprintk (RIO_DEBUG_CMD, "KILL HOST NEIGHBOUR\n");
  226. if ( copyin( (int)arg, (caddr_t)&KillUnit, sizeof(KillUnit) ) == COPYFAIL ) {
  227. rio_dprintk (RIO_DEBUG_CMD, "RIO_KILL_NEIGHBOUR copy failed\n");
  228. p->RIOError.Error = COPYIN_FAILED;
  229. return -EFAULT;
  230. }
  231. if ( KillUnit.Link > 3 )
  232. return -ENXIO;
  233. CmdBlkP = RIOGetCmdBlk();
  234. if ( !CmdBlkP ) {
  235. rio_dprintk (RIO_DEBUG_CMD, "UFOAD: GetCmdBlk failed\n");
  236. return -ENXIO;
  237. }
  238. CmdBlkP->Packet.dest_unit = 0;
  239. CmdBlkP->Packet.src_unit = 0;
  240. CmdBlkP->Packet.dest_port = BOOT_RUP;
  241. CmdBlkP->Packet.src_port = BOOT_RUP;
  242. CmdBlkP->Packet.len = 0x84;
  243. CmdBlkP->Packet.data[0] = UFOAD;
  244. CmdBlkP->Packet.data[1] = KillUnit.Link;
  245. CmdBlkP->Packet.data[2] = UFOAD_MAGIC & 0xFF;
  246. CmdBlkP->Packet.data[3] = (UFOAD_MAGIC >> 8) & 0xFF;
  247. for ( Host = 0; Host < p->RIONumHosts; Host++ ) {
  248. ID = 0;
  249. HostP = &p->RIOHosts[Host];
  250. if ( HostP->UniqueNum == KillUnit.UniqueNum ) {
  251. if ( RIOQueueCmdBlk( HostP, RTAS_PER_HOST+KillUnit.Link,
  252. CmdBlkP) == RIO_FAIL ) {
  253. rio_dprintk (RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
  254. return -EIO;
  255. }
  256. return 0;
  257. }
  258. for ( ID=0; ID < RTAS_PER_HOST; ID++ ) {
  259. if ( HostP->Mapping[ID].RtaUniqueNum == KillUnit.UniqueNum ) {
  260. CmdBlkP->Packet.dest_unit = ID+1;
  261. if ( RIOQueueCmdBlk( HostP, ID, CmdBlkP) == RIO_FAIL ) {
  262. rio_dprintk (RIO_DEBUG_CMD, "UFOAD: Failed queue command\n");
  263. return -EIO;
  264. }
  265. return 0;
  266. }
  267. }
  268. }
  269. RIOFreeCmdBlk( CmdBlkP );
  270. return -ENXIO;
  271. }
  272. int
  273. RIOSuspendBootRta(struct Host *HostP, int ID, int Link)
  274. {
  275. struct CmdBlk *CmdBlkP;
  276. rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA ID %d, link %c\n", ID, 'A' + Link);
  277. CmdBlkP = RIOGetCmdBlk();
  278. if ( !CmdBlkP ) {
  279. rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: GetCmdBlk failed\n");
  280. return -ENXIO;
  281. }
  282. CmdBlkP->Packet.dest_unit = ID;
  283. CmdBlkP->Packet.dest_port = BOOT_RUP;
  284. CmdBlkP->Packet.src_unit = 0;
  285. CmdBlkP->Packet.src_port = BOOT_RUP;
  286. CmdBlkP->Packet.len = 0x84;
  287. CmdBlkP->Packet.data[0] = IWAIT;
  288. CmdBlkP->Packet.data[1] = Link;
  289. CmdBlkP->Packet.data[2] = IWAIT_MAGIC & 0xFF;
  290. CmdBlkP->Packet.data[3] = (IWAIT_MAGIC >> 8) & 0xFF;
  291. if ( RIOQueueCmdBlk( HostP, ID - 1, CmdBlkP) == RIO_FAIL ) {
  292. rio_dprintk (RIO_DEBUG_CMD, "SUSPEND BOOT ON RTA: Failed to queue iwait command\n");
  293. return -EIO;
  294. }
  295. return 0;
  296. }
  297. int
  298. RIOFoadWakeup(struct rio_info *p)
  299. {
  300. int port;
  301. register struct Port *PortP;
  302. unsigned long flags;
  303. for ( port=0; port<RIO_PORTS; port++) {
  304. PortP = p->RIOPortp[port];
  305. rio_spin_lock_irqsave(&PortP->portSem, flags);
  306. PortP->Config = 0;
  307. PortP->State = 0;
  308. PortP->InUse = NOT_INUSE;
  309. PortP->PortState = 0;
  310. PortP->FlushCmdBodge = 0;
  311. PortP->ModemLines = 0;
  312. PortP->ModemState = 0;
  313. PortP->CookMode = 0;
  314. PortP->ParamSem = 0;
  315. PortP->Mapped = 0;
  316. PortP->WflushFlag = 0;
  317. PortP->MagicFlags = 0;
  318. PortP->RxDataStart = 0;
  319. PortP->TxBufferIn = 0;
  320. PortP->TxBufferOut = 0;
  321. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  322. }
  323. return(0);
  324. }
  325. /*
  326. ** Incoming command on the COMMAND_RUP to be processed.
  327. */
  328. static int
  329. RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT *PacketP)
  330. {
  331. struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data;
  332. struct Port *PortP;
  333. struct UnixRup *UnixRupP;
  334. ushort SysPort;
  335. ushort ReportedModemStatus;
  336. ushort rup;
  337. ushort subCommand;
  338. unsigned long flags;
  339. func_enter ();
  340. #ifdef CHECK
  341. CheckHost( Host );
  342. CheckHostP( HostP );
  343. CheckPacketP( PacketP );
  344. #endif
  345. /*
  346. ** 16 port RTA note:
  347. ** Command rup packets coming from the RTA will have pkt->data[1] (which
  348. ** translates to PktCmdP->PhbNum) set to the host port number for the
  349. ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
  350. ** we can use PhbNum to get the rup number for the appropriate 8 port
  351. ** block (for the first block, this should be equal to 'Rup').
  352. */
  353. rup = RBYTE(PktCmdP->PhbNum) / (ushort)PORTS_PER_RTA;
  354. UnixRupP = &HostP->UnixRups[rup];
  355. SysPort = UnixRupP->BaseSysPort +
  356. (RBYTE(PktCmdP->PhbNum) % (ushort)PORTS_PER_RTA);
  357. rio_dprintk (RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
  358. #ifdef CHECK
  359. CheckRup( rup );
  360. CheckUnixRupP( UnixRupP );
  361. #endif
  362. if ( UnixRupP->BaseSysPort == NO_PORT ) {
  363. rio_dprintk (RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
  364. rio_dprintk (RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
  365. rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n",
  366. HostP-p->RIOHosts, HostP->Name );
  367. rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
  368. if ( Rup >= (ushort)MAX_RUP ) {
  369. rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n",
  370. HostP->Mapping[Rup].Name);
  371. } else
  372. rio_dprintk (RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n",
  373. ('A' + Rup - MAX_RUP), HostP->Name);
  374. rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n",
  375. PacketP->dest_unit, PacketP->dest_port );
  376. rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n",
  377. PacketP->src_unit, PacketP->src_port );
  378. rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", PacketP->len,PacketP->len );
  379. rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control);
  380. rio_dprintk (RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum );
  381. rio_dprintk (RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, "
  382. "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command );
  383. return TRUE;
  384. }
  385. #ifdef CHECK
  386. CheckSysPort( SysPort );
  387. #endif
  388. PortP = p->RIOPortp[ SysPort ];
  389. rio_spin_lock_irqsave(&PortP->portSem, flags);
  390. switch( RBYTE(PktCmdP->Command) ) {
  391. case BREAK_RECEIVED:
  392. rio_dprintk (RIO_DEBUG_CMD, "Received a break!\n");
  393. /* If the current line disc. is not multi-threading and
  394. the current processor is not the default, reset rup_intr
  395. and return FALSE to ensure that the command packet is
  396. not freed. */
  397. /* Call tmgr HANGUP HERE */
  398. /* Fix this later when every thing works !!!! RAMRAJ */
  399. gs_got_break (&PortP->gs);
  400. break;
  401. case COMPLETE:
  402. rio_dprintk (RIO_DEBUG_CMD, "Command complete on phb %d host %d\n",
  403. RBYTE(PktCmdP->PhbNum), HostP-p->RIOHosts);
  404. subCommand = 1;
  405. switch (RBYTE(PktCmdP->SubCommand)) {
  406. case MEMDUMP :
  407. rio_dprintk (RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n",
  408. RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr));
  409. break;
  410. case READ_REGISTER :
  411. rio_dprintk (RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr));
  412. p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST);
  413. break;
  414. default :
  415. subCommand = 0;
  416. break;
  417. }
  418. if (subCommand)
  419. break;
  420. rio_dprintk (RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n",
  421. RBYTE(PktCmdP->PortStatus),PortP->PortState);
  422. if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) {
  423. rio_dprintk (RIO_DEBUG_CMD, "Mark status & wakeup\n");
  424. PortP->PortState = RBYTE(PktCmdP->PortStatus);
  425. /* What should we do here ...
  426. wakeup( &PortP->PortState );
  427. */
  428. } else
  429. rio_dprintk (RIO_DEBUG_CMD, "No change\n");
  430. /* FALLTHROUGH */
  431. case MODEM_STATUS:
  432. /*
  433. ** Knock out the tbusy and tstop bits, as these are not relevant
  434. ** to the check for modem status change (they're just there because
  435. ** it's a convenient place to put them!).
  436. */
  437. ReportedModemStatus = RBYTE(PktCmdP->ModemStatus);
  438. if ((PortP->ModemState & MSVR1_HOST) ==
  439. (ReportedModemStatus & MSVR1_HOST)) {
  440. rio_dprintk (RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
  441. /*
  442. ** Update ModemState just in case tbusy or tstop states have
  443. ** changed.
  444. */
  445. PortP->ModemState = ReportedModemStatus;
  446. }
  447. else {
  448. rio_dprintk (RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n",
  449. PortP->ModemState, ReportedModemStatus);
  450. PortP->ModemState = ReportedModemStatus;
  451. #ifdef MODEM_SUPPORT
  452. if ( PortP->Mapped ) {
  453. /***********************************************************\
  454. *************************************************************
  455. *** ***
  456. *** M O D E M S T A T E C H A N G E ***
  457. *** ***
  458. *************************************************************
  459. \***********************************************************/
  460. /*
  461. ** If the device is a modem, then check the modem
  462. ** carrier.
  463. */
  464. if (PortP->gs.tty == NULL)
  465. break;
  466. if (PortP->gs.tty->termios == NULL)
  467. break;
  468. if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) &&
  469. ((PortP->State & (RIO_MOPEN|RIO_WOPEN)))) {
  470. rio_dprintk (RIO_DEBUG_CMD, "Is there a Carrier?\n");
  471. /*
  472. ** Is there a carrier?
  473. */
  474. if ( PortP->ModemState & MSVR1_CD ) {
  475. /*
  476. ** Has carrier just appeared?
  477. */
  478. if (!(PortP->State & RIO_CARR_ON)) {
  479. rio_dprintk (RIO_DEBUG_CMD, "Carrier just came up.\n");
  480. PortP->State |= RIO_CARR_ON;
  481. /*
  482. ** wakeup anyone in WOPEN
  483. */
  484. if (PortP->State & (PORT_ISOPEN | RIO_WOPEN) )
  485. wake_up_interruptible (&PortP->gs.open_wait);
  486. #ifdef STATS
  487. PortP->Stat.ModemOnCnt++;
  488. #endif
  489. }
  490. } else {
  491. /*
  492. ** Has carrier just dropped?
  493. */
  494. if (PortP->State & RIO_CARR_ON) {
  495. if (PortP->State & (PORT_ISOPEN|RIO_WOPEN|RIO_MOPEN))
  496. tty_hangup (PortP->gs.tty);
  497. PortP->State &= ~RIO_CARR_ON;
  498. rio_dprintk (RIO_DEBUG_CMD, "Carrirer just went down\n");
  499. #ifdef STATS
  500. PortP->Stat.ModemOffCnt++;
  501. #endif
  502. }
  503. }
  504. }
  505. }
  506. #endif
  507. }
  508. break;
  509. default:
  510. rio_dprintk (RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n",
  511. RBYTE(PktCmdP->Command),HostP-p->RIOHosts);
  512. break;
  513. }
  514. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  515. func_exit ();
  516. return TRUE;
  517. }
  518. /*
  519. ** The command mechanism:
  520. ** Each rup has a chain of commands associated with it.
  521. ** This chain is maintained by routines in this file.
  522. ** Periodically we are called and we run a quick check of all the
  523. ** active chains to determine if there is a command to be executed,
  524. ** and if the rup is ready to accept it.
  525. **
  526. */
  527. /*
  528. ** Allocate an empty command block.
  529. */
  530. struct CmdBlk *
  531. RIOGetCmdBlk(void)
  532. {
  533. struct CmdBlk *CmdBlkP;
  534. CmdBlkP = (struct CmdBlk *)sysbrk(sizeof(struct CmdBlk));
  535. if (CmdBlkP)
  536. bzero(CmdBlkP, sizeof(struct CmdBlk));
  537. return CmdBlkP;
  538. }
  539. /*
  540. ** Return a block to the head of the free list.
  541. */
  542. void
  543. RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
  544. {
  545. sysfree((void *)CmdBlkP, sizeof(struct CmdBlk));
  546. }
  547. /*
  548. ** attach a command block to the list of commands to be performed for
  549. ** a given rup.
  550. */
  551. int
  552. RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
  553. {
  554. struct CmdBlk **Base;
  555. struct UnixRup *UnixRupP;
  556. unsigned long flags;
  557. #ifdef CHECK
  558. CheckHostP( HostP );
  559. CheckRup( Rup );
  560. CheckCmdBlkP( CmdBlkP );
  561. #endif
  562. if ( Rup >= (ushort)(MAX_RUP+LINKS_PER_UNIT) ) {
  563. rio_dprintk (RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n",Rup);
  564. RIOFreeCmdBlk( CmdBlkP );
  565. return RIO_FAIL;
  566. }
  567. UnixRupP = &HostP->UnixRups[Rup];
  568. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  569. /*
  570. ** If the RUP is currently inactive, then put the request
  571. ** straight on the RUP....
  572. */
  573. if ( (UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) &&
  574. (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE ) &&
  575. (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP)(CmdBlkP->PreArg,CmdBlkP)
  576. :TRUE)) {
  577. rio_dprintk (RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n",
  578. CmdBlkP->Packet.data[0]);
  579. /*
  580. ** Whammy! blat that pack!
  581. */
  582. HostP->Copy( (caddr_t)&CmdBlkP->Packet,
  583. RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt ), sizeof(PKT) );
  584. /*
  585. ** place command packet on the pending position.
  586. */
  587. UnixRupP->CmdPendingP = CmdBlkP;
  588. /*
  589. ** set the command register
  590. */
  591. WWORD(UnixRupP->RupP->txcontrol , TX_PACKET_READY);
  592. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  593. return RIO_SUCCESS;
  594. }
  595. rio_dprintk (RIO_DEBUG_CMD, "RUP active - en-queing\n");
  596. if ( UnixRupP->CmdsWaitingP != NULL)
  597. rio_dprintk (RIO_DEBUG_CMD, "Rup active - command waiting\n");
  598. if ( UnixRupP->CmdPendingP != NULL )
  599. rio_dprintk (RIO_DEBUG_CMD, "Rup active - command pending\n");
  600. if ( RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE )
  601. rio_dprintk (RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
  602. Base = &UnixRupP->CmdsWaitingP;
  603. rio_dprintk (RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int)CmdBlkP,(int)Base);
  604. while ( *Base ) {
  605. rio_dprintk (RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int)(*Base));
  606. Base = &((*Base)->NextP);
  607. rio_dprintk (RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n",
  608. (int)CmdBlkP,(int)Base);
  609. }
  610. rio_dprintk (RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n",(int)CmdBlkP,(int)Base);
  611. *Base = CmdBlkP;
  612. CmdBlkP->NextP = NULL;
  613. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  614. return RIO_SUCCESS;
  615. }
  616. /*
  617. ** Here we go - if there is an empty rup, fill it!
  618. ** must be called at splrio() or higher.
  619. */
  620. void
  621. RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
  622. {
  623. register struct CmdBlk *CmdBlkP;
  624. register struct UnixRup *UnixRupP;
  625. struct PKT *PacketP;
  626. ushort Rup;
  627. unsigned long flags;
  628. Rup = MAX_RUP+LINKS_PER_UNIT;
  629. do { /* do this loop for each RUP */
  630. /*
  631. ** locate the rup we are processing & lock it
  632. */
  633. UnixRupP = &HostP->UnixRups[--Rup];
  634. spin_lock_irqsave(&UnixRupP->RupLock, flags);
  635. /*
  636. ** First check for incoming commands:
  637. */
  638. if ( RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE ) {
  639. int FreeMe;
  640. PacketP =(PKT *)RIO_PTR(HostP->Caddr,RWORD(UnixRupP->RupP->rxpkt));
  641. ShowPacket( DBG_CMD, PacketP );
  642. switch ( RBYTE(PacketP->dest_port) ) {
  643. case BOOT_RUP:
  644. rio_dprintk (RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n",
  645. RBYTE(PacketP->len) & 0x80 ? "Command":"Data",
  646. RBYTE(PacketP->data[0]));
  647. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  648. FreeMe= RIOBootRup(p, Rup,HostP,PacketP);
  649. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  650. break;
  651. case COMMAND_RUP:
  652. /*
  653. ** Free the RUP lock as loss of carrier causes a
  654. ** ttyflush which will (eventually) call another
  655. ** routine that uses the RUP lock.
  656. */
  657. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  658. FreeMe= RIOCommandRup(p, Rup,HostP,PacketP);
  659. if (PacketP->data[5] == MEMDUMP) {
  660. rio_dprintk (RIO_DEBUG_CMD, "Memdump from 0x%x complete\n",
  661. *(ushort *) &(PacketP->data[6]));
  662. HostP->Copy( (caddr_t)&(PacketP->data[8]),
  663. (caddr_t)p->RIOMemDump, 32 );
  664. }
  665. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  666. break;
  667. case ROUTE_RUP:
  668. rio_spin_unlock_irqrestore( &UnixRupP->RupLock, flags);
  669. FreeMe = RIORouteRup(p, Rup, HostP, PacketP );
  670. rio_spin_lock_irqsave( &UnixRupP->RupLock, flags );
  671. break;
  672. default:
  673. rio_dprintk (RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port));
  674. FreeMe = 1;
  675. break;
  676. }
  677. if ( FreeMe ) {
  678. rio_dprintk (RIO_DEBUG_CMD, "Free processed incoming command packet\n");
  679. put_free_end(HostP,PacketP);
  680. WWORD(UnixRupP->RupP->rxcontrol , RX_RUP_INACTIVE);
  681. if ( RWORD(UnixRupP->RupP->handshake)==PHB_HANDSHAKE_SET ) {
  682. rio_dprintk (RIO_DEBUG_CMD, "Handshake rup %d\n",Rup);
  683. WWORD(UnixRupP->RupP->handshake,
  684. PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET);
  685. }
  686. }
  687. }
  688. /*
  689. ** IF a command was running on the port,
  690. ** and it has completed, then tidy it up.
  691. */
  692. if ( (CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
  693. (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
  694. /*
  695. ** we are idle.
  696. ** there is a command in pending.
  697. ** Therefore, this command has finished.
  698. ** So, wakeup whoever is waiting for it (and tell them
  699. ** what happened).
  700. */
  701. if ( CmdBlkP->Packet.dest_port == BOOT_RUP )
  702. rio_dprintk (RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n",
  703. CmdBlkP->Packet.len & 0x80 ? "Command":"Data",
  704. CmdBlkP->Packet.data[0]);
  705. rio_dprintk (RIO_DEBUG_CMD, "Command 0x%x completed\n",(int)CmdBlkP);
  706. /*
  707. ** Clear the Rup lock to prevent mutual exclusion.
  708. */
  709. if ( CmdBlkP->PostFuncP ) {
  710. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  711. (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg,CmdBlkP);
  712. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  713. }
  714. /*
  715. ** ....clear the pending flag....
  716. */
  717. UnixRupP->CmdPendingP = NULL;
  718. /*
  719. ** ....and return the command block to the freelist.
  720. */
  721. RIOFreeCmdBlk( CmdBlkP );
  722. }
  723. /*
  724. ** If there is a command for this rup, and the rup
  725. ** is idle, then process the command
  726. */
  727. if ( (CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
  728. (UnixRupP->CmdPendingP == NULL) &&
  729. (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
  730. /*
  731. ** if the pre-function is non-zero, call it.
  732. ** If it returns RIO_FAIL then don't
  733. ** send this command yet!
  734. */
  735. #ifdef CHECK
  736. CheckCmdBlkP (CmdBlkP);
  737. #endif
  738. if ( !(CmdBlkP->PreFuncP ?
  739. (*CmdBlkP->PreFuncP)(CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
  740. rio_dprintk (RIO_DEBUG_CMD, "Not ready to start command 0x%x\n",(int)CmdBlkP);
  741. }
  742. else {
  743. rio_dprintk (RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n",
  744. (int)CmdBlkP, CmdBlkP->Packet.data[0]);
  745. /*
  746. ** Whammy! blat that pack!
  747. */
  748. #ifdef CHECK
  749. CheckPacketP ((PKT *)RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt));
  750. #endif
  751. HostP->Copy( (caddr_t)&CmdBlkP->Packet,
  752. RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
  753. /*
  754. ** remove the command from the rup command queue...
  755. */
  756. UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
  757. /*
  758. ** ...and place it on the pending position.
  759. */
  760. UnixRupP->CmdPendingP = CmdBlkP;
  761. /*
  762. ** set the command register
  763. */
  764. WWORD(UnixRupP->RupP->txcontrol,TX_PACKET_READY);
  765. /*
  766. ** the command block will be freed
  767. ** when the command has been processed.
  768. */
  769. }
  770. }
  771. spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  772. } while ( Rup );
  773. }
  774. int
  775. RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
  776. {
  777. struct Port * PortP = (struct Port *)iPortP;
  778. unsigned long flags;
  779. rio_spin_lock_irqsave(&PortP->portSem, flags);
  780. #ifdef CHECK
  781. CheckPortP( PortP );
  782. #endif
  783. PortP->WflushFlag++;
  784. PortP->MagicFlags |= MAGIC_FLUSH;
  785. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  786. return RIOUnUse( iPortP, CmdBlkP );
  787. }
  788. int
  789. RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP)
  790. {
  791. struct Port * PortP = (struct Port *)iPortP;
  792. PKT *PacketP;
  793. unsigned long flags;
  794. rio_spin_lock_irqsave(&PortP->portSem, flags);
  795. while ( can_remove_receive(&PacketP, PortP) ) {
  796. remove_receive(PortP);
  797. ShowPacket(DBG_PROC, PacketP );
  798. put_free_end( PortP->HostP, PacketP );
  799. }
  800. if ( RWORD(PortP->PhbP->handshake)==PHB_HANDSHAKE_SET ) {
  801. /*
  802. ** MAGIC! (Basically, handshake the RX buffer, so that
  803. ** the RTAs upstream can be re-enabled.)
  804. */
  805. rio_dprintk (RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
  806. WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET|PHB_HANDSHAKE_RESET);
  807. }
  808. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  809. return RIOUnUse( iPortP, CmdBlkP );
  810. }
  811. int
  812. RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
  813. {
  814. struct Port * PortP = (struct Port *)iPortP;
  815. unsigned long flags;
  816. rio_spin_lock_irqsave(&PortP->portSem, flags);
  817. #ifdef CHECK
  818. CheckPortP( PortP );
  819. #endif
  820. rio_dprintk (RIO_DEBUG_CMD, "Decrement in use count for port\n");
  821. if (PortP->InUse) {
  822. if ( --PortP->InUse != NOT_INUSE ) {
  823. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  824. return 0;
  825. }
  826. }
  827. /*
  828. ** While PortP->InUse is set (i.e. a preemptive command has been sent to
  829. ** the RTA and is awaiting completion), any transmit data is prevented from
  830. ** being transferred from the write queue into the transmit packets
  831. ** (add_transmit) and no furthur transmit interrupt will be sent for that
  832. ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
  833. ** twice a second as a saftey measure). This was the case when kermit was
  834. ** used to send data into a RIO port. After each packet was sent, TCFLSH
  835. ** was called to flush the read queue preemptively. PortP->InUse was
  836. ** incremented, thereby blocking the 6 byte acknowledgement packet
  837. ** transmitted back. This acknowledgment hung around for 500ms before
  838. ** being sent, thus reducing input performance substantially!.
  839. ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
  840. ** hanging around in the transmit buffer is sent immediately.
  841. */
  842. WWORD(PortP->HostP->ParmMapP->tx_intr, 1);
  843. /* What to do here ..
  844. wakeup( (caddr_t)&(PortP->InUse) );
  845. */
  846. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  847. return 0;
  848. }
  849. void
  850. ShowPacket(uint Flags, struct PKT *PacketP)
  851. {
  852. }
  853. /*
  854. **
  855. ** How to use this file:
  856. **
  857. ** To send a command down a rup, you need to allocate a command block, fill
  858. ** in the packet information, fill in the command number, fill in the pre-
  859. ** and post- functions and arguments, and then add the command block to the
  860. ** queue of command blocks for the port in question. When the port is idle,
  861. ** then the pre-function will be called. If this returns RIO_FAIL then the
  862. ** command will be re-queued and tried again at a later date (probably in one
  863. ** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
  864. ** packet will be queued on the RUP, and the txcontrol field set to the
  865. ** command number. When the txcontrol field has changed from being the
  866. ** command number, then the post-function will be called, with the argument
  867. ** specified earlier, a pointer to the command block, and the value of
  868. ** txcontrol.
  869. **
  870. ** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
  871. ** to the command block structure allocated, or NULL if there aren't any.
  872. ** The block will have been zeroed for you.
  873. **
  874. ** The structure has the following fields:
  875. **
  876. ** struct CmdBlk
  877. ** {
  878. ** struct CmdBlk *NextP; ** Pointer to next command block **
  879. ** struct PKT Packet; ** A packet, to copy to the rup **
  880. ** int (*PreFuncP)(); ** The func to call to check if OK **
  881. ** int PreArg; ** The arg for the func **
  882. ** int (*PostFuncP)(); ** The func to call when completed **
  883. ** int PostArg; ** The arg for the func **
  884. ** };
  885. **
  886. ** You need to fill in ALL fields EXCEPT NextP, which is used to link the
  887. ** blocks together either on the free list or on the Rup list.
  888. **
  889. ** Packet is an actual packet structure to be filled in with the packet
  890. ** information associated with the command. You need to fill in everything,
  891. ** as the command processore doesn't process the command packet in any way.
  892. **
  893. ** The PreFuncP is called before the packet is enqueued on the host rup.
  894. ** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
  895. ** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
  896. ** if the packet is NOT to be queued.
  897. **
  898. ** The PostFuncP is called when the command has completed. It is called
  899. ** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
  900. ** to return a value. PostFuncP does NOT need to free the command block,
  901. ** as this happens automatically after PostFuncP returns.
  902. **
  903. ** Once the command block has been filled in, it is attached to the correct
  904. ** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
  905. ** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
  906. ** to it!), and CmdBlkP is the pointer to the command block allocated using
  907. ** RIOGetCmdBlk().
  908. **
  909. */