riocmd.c 29 KB

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