riocmd.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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. #ifdef CHECK
  331. CheckHost(Host);
  332. CheckHostP(HostP);
  333. CheckPacketP(PacketP);
  334. #endif
  335. /*
  336. ** 16 port RTA note:
  337. ** Command rup packets coming from the RTA will have pkt->data[1] (which
  338. ** translates to PktCmdP->PhbNum) set to the host port number for the
  339. ** particular unit. To access the correct BaseSysPort for a 16 port RTA,
  340. ** we can use PhbNum to get the rup number for the appropriate 8 port
  341. ** block (for the first block, this should be equal to 'Rup').
  342. */
  343. rup = RBYTE(PktCmdP->PhbNum) / (ushort) PORTS_PER_RTA;
  344. UnixRupP = &HostP->UnixRups[rup];
  345. SysPort = UnixRupP->BaseSysPort + (RBYTE(PktCmdP->PhbNum) % (ushort) PORTS_PER_RTA);
  346. rio_dprintk(RIO_DEBUG_CMD, "Command on rup %d, port %d\n", rup, SysPort);
  347. #ifdef CHECK
  348. CheckRup(rup);
  349. CheckUnixRupP(UnixRupP);
  350. #endif
  351. if (UnixRupP->BaseSysPort == NO_PORT) {
  352. rio_dprintk(RIO_DEBUG_CMD, "OBSCURE ERROR!\n");
  353. rio_dprintk(RIO_DEBUG_CMD, "Diagnostics follow. Please WRITE THESE DOWN and report them to Specialix Technical Support\n");
  354. rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %d, name ``%s''\n", HostP - p->RIOHosts, HostP->Name);
  355. rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Rup number 0x%x\n", rup);
  356. if (Rup >= (ushort) MAX_RUP) {
  357. rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for RTA ``%s''\n", HostP->Mapping[Rup].Name);
  358. } else
  359. rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: This is the RUP for link ``%c'' of host ``%s''\n", ('A' + Rup - MAX_RUP), HostP->Name);
  360. rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Destination 0x%x:0x%x\n", PacketP->dest_unit, PacketP->dest_port);
  361. rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Source 0x%x:0x%x\n", PacketP->src_unit, PacketP->src_port);
  362. rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Length 0x%x (%d)\n", PacketP->len, PacketP->len);
  363. rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Control 0x%x (%d)\n", PacketP->control, PacketP->control);
  364. rio_dprintk(RIO_DEBUG_CMD, "PACKET information: Check 0x%x (%d)\n", PacketP->csum, PacketP->csum);
  365. rio_dprintk(RIO_DEBUG_CMD, "COMMAND information: Host Port Number 0x%x, " "Command Code 0x%x\n", PktCmdP->PhbNum, PktCmdP->Command);
  366. return TRUE;
  367. }
  368. #ifdef CHECK
  369. CheckSysPort(SysPort);
  370. #endif
  371. PortP = p->RIOPortp[SysPort];
  372. rio_spin_lock_irqsave(&PortP->portSem, flags);
  373. switch (RBYTE(PktCmdP->Command)) {
  374. case BREAK_RECEIVED:
  375. rio_dprintk(RIO_DEBUG_CMD, "Received a break!\n");
  376. /* If the current line disc. is not multi-threading and
  377. the current processor is not the default, reset rup_intr
  378. and return FALSE to ensure that the command packet is
  379. not freed. */
  380. /* Call tmgr HANGUP HERE */
  381. /* Fix this later when every thing works !!!! RAMRAJ */
  382. gs_got_break(&PortP->gs);
  383. break;
  384. case COMPLETE:
  385. rio_dprintk(RIO_DEBUG_CMD, "Command complete on phb %d host %d\n", RBYTE(PktCmdP->PhbNum), HostP - p->RIOHosts);
  386. subCommand = 1;
  387. switch (RBYTE(PktCmdP->SubCommand)) {
  388. case MEMDUMP:
  389. rio_dprintk(RIO_DEBUG_CMD, "Memory dump cmd (0x%x) from addr 0x%x\n", RBYTE(PktCmdP->SubCommand), RWORD(PktCmdP->SubAddr));
  390. break;
  391. case READ_REGISTER:
  392. rio_dprintk(RIO_DEBUG_CMD, "Read register (0x%x)\n", RWORD(PktCmdP->SubAddr));
  393. p->CdRegister = (RBYTE(PktCmdP->ModemStatus) & MSVR1_HOST);
  394. break;
  395. default:
  396. subCommand = 0;
  397. break;
  398. }
  399. if (subCommand)
  400. break;
  401. rio_dprintk(RIO_DEBUG_CMD, "New status is 0x%x was 0x%x\n", RBYTE(PktCmdP->PortStatus), PortP->PortState);
  402. if (PortP->PortState != RBYTE(PktCmdP->PortStatus)) {
  403. rio_dprintk(RIO_DEBUG_CMD, "Mark status & wakeup\n");
  404. PortP->PortState = RBYTE(PktCmdP->PortStatus);
  405. /* What should we do here ...
  406. wakeup( &PortP->PortState );
  407. */
  408. } else
  409. rio_dprintk(RIO_DEBUG_CMD, "No change\n");
  410. /* FALLTHROUGH */
  411. case MODEM_STATUS:
  412. /*
  413. ** Knock out the tbusy and tstop bits, as these are not relevant
  414. ** to the check for modem status change (they're just there because
  415. ** it's a convenient place to put them!).
  416. */
  417. ReportedModemStatus = RBYTE(PktCmdP->ModemStatus);
  418. if ((PortP->ModemState & MSVR1_HOST) == (ReportedModemStatus & MSVR1_HOST)) {
  419. rio_dprintk(RIO_DEBUG_CMD, "Modem status unchanged 0x%x\n", PortP->ModemState);
  420. /*
  421. ** Update ModemState just in case tbusy or tstop states have
  422. ** changed.
  423. */
  424. PortP->ModemState = ReportedModemStatus;
  425. } else {
  426. rio_dprintk(RIO_DEBUG_CMD, "Modem status change from 0x%x to 0x%x\n", PortP->ModemState, ReportedModemStatus);
  427. PortP->ModemState = ReportedModemStatus;
  428. #ifdef MODEM_SUPPORT
  429. if (PortP->Mapped) {
  430. /***********************************************************\
  431. *************************************************************
  432. *** ***
  433. *** M O D E M S T A T E C H A N G E ***
  434. *** ***
  435. *************************************************************
  436. \***********************************************************/
  437. /*
  438. ** If the device is a modem, then check the modem
  439. ** carrier.
  440. */
  441. if (PortP->gs.tty == NULL)
  442. break;
  443. if (PortP->gs.tty->termios == NULL)
  444. break;
  445. if (!(PortP->gs.tty->termios->c_cflag & CLOCAL) && ((PortP->State & (RIO_MOPEN | RIO_WOPEN)))) {
  446. rio_dprintk(RIO_DEBUG_CMD, "Is there a Carrier?\n");
  447. /*
  448. ** Is there a carrier?
  449. */
  450. if (PortP->ModemState & MSVR1_CD) {
  451. /*
  452. ** Has carrier just appeared?
  453. */
  454. if (!(PortP->State & RIO_CARR_ON)) {
  455. rio_dprintk(RIO_DEBUG_CMD, "Carrier just came up.\n");
  456. PortP->State |= RIO_CARR_ON;
  457. /*
  458. ** wakeup anyone in WOPEN
  459. */
  460. if (PortP->State & (PORT_ISOPEN | RIO_WOPEN))
  461. wake_up_interruptible(&PortP->gs.open_wait);
  462. #ifdef STATS
  463. PortP->Stat.ModemOnCnt++;
  464. #endif
  465. }
  466. } else {
  467. /*
  468. ** Has carrier just dropped?
  469. */
  470. if (PortP->State & RIO_CARR_ON) {
  471. if (PortP->State & (PORT_ISOPEN | RIO_WOPEN | RIO_MOPEN))
  472. tty_hangup(PortP->gs.tty);
  473. PortP->State &= ~RIO_CARR_ON;
  474. rio_dprintk(RIO_DEBUG_CMD, "Carrirer just went down\n");
  475. #ifdef STATS
  476. PortP->Stat.ModemOffCnt++;
  477. #endif
  478. }
  479. }
  480. }
  481. }
  482. #endif
  483. }
  484. break;
  485. default:
  486. rio_dprintk(RIO_DEBUG_CMD, "Unknown command %d on CMD_RUP of host %d\n", RBYTE(PktCmdP->Command), HostP - p->RIOHosts);
  487. break;
  488. }
  489. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  490. func_exit();
  491. return TRUE;
  492. }
  493. /*
  494. ** The command mechanism:
  495. ** Each rup has a chain of commands associated with it.
  496. ** This chain is maintained by routines in this file.
  497. ** Periodically we are called and we run a quick check of all the
  498. ** active chains to determine if there is a command to be executed,
  499. ** and if the rup is ready to accept it.
  500. **
  501. */
  502. /*
  503. ** Allocate an empty command block.
  504. */
  505. struct CmdBlk *RIOGetCmdBlk(void)
  506. {
  507. struct CmdBlk *CmdBlkP;
  508. CmdBlkP = (struct CmdBlk *) sysbrk(sizeof(struct CmdBlk));
  509. if (CmdBlkP)
  510. bzero(CmdBlkP, sizeof(struct CmdBlk));
  511. return CmdBlkP;
  512. }
  513. /*
  514. ** Return a block to the head of the free list.
  515. */
  516. void RIOFreeCmdBlk(struct CmdBlk *CmdBlkP)
  517. {
  518. sysfree((void *) CmdBlkP, sizeof(struct CmdBlk));
  519. }
  520. /*
  521. ** attach a command block to the list of commands to be performed for
  522. ** a given rup.
  523. */
  524. int RIOQueueCmdBlk(struct Host *HostP, uint Rup, struct CmdBlk *CmdBlkP)
  525. {
  526. struct CmdBlk **Base;
  527. struct UnixRup *UnixRupP;
  528. unsigned long flags;
  529. #ifdef CHECK
  530. CheckHostP(HostP);
  531. CheckRup(Rup);
  532. CheckCmdBlkP(CmdBlkP);
  533. #endif
  534. if (Rup >= (ushort) (MAX_RUP + LINKS_PER_UNIT)) {
  535. rio_dprintk(RIO_DEBUG_CMD, "Illegal rup number %d in RIOQueueCmdBlk\n", Rup);
  536. RIOFreeCmdBlk(CmdBlkP);
  537. return RIO_FAIL;
  538. }
  539. UnixRupP = &HostP->UnixRups[Rup];
  540. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  541. /*
  542. ** If the RUP is currently inactive, then put the request
  543. ** straight on the RUP....
  544. */
  545. if ((UnixRupP->CmdsWaitingP == NULL) && (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE) && (CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP)
  546. : TRUE)) {
  547. rio_dprintk(RIO_DEBUG_CMD, "RUP inactive-placing command straight on. Cmd byte is 0x%x\n", CmdBlkP->Packet.data[0]);
  548. /*
  549. ** Whammy! blat that pack!
  550. */
  551. HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
  552. /*
  553. ** place command packet on the pending position.
  554. */
  555. UnixRupP->CmdPendingP = CmdBlkP;
  556. /*
  557. ** set the command register
  558. */
  559. WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
  560. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  561. return RIO_SUCCESS;
  562. }
  563. rio_dprintk(RIO_DEBUG_CMD, "RUP active - en-queing\n");
  564. if (UnixRupP->CmdsWaitingP != NULL)
  565. rio_dprintk(RIO_DEBUG_CMD, "Rup active - command waiting\n");
  566. if (UnixRupP->CmdPendingP != NULL)
  567. rio_dprintk(RIO_DEBUG_CMD, "Rup active - command pending\n");
  568. if (RWORD(UnixRupP->RupP->txcontrol) != TX_RUP_INACTIVE)
  569. rio_dprintk(RIO_DEBUG_CMD, "Rup active - command rup not ready\n");
  570. Base = &UnixRupP->CmdsWaitingP;
  571. rio_dprintk(RIO_DEBUG_CMD, "First try to queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
  572. while (*Base) {
  573. rio_dprintk(RIO_DEBUG_CMD, "Command cmdblk 0x%x here\n", (int) (*Base));
  574. Base = &((*Base)->NextP);
  575. rio_dprintk(RIO_DEBUG_CMD, "Now try to queue cmd cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
  576. }
  577. rio_dprintk(RIO_DEBUG_CMD, "Will queue cmdblk 0x%x at 0x%x\n", (int) CmdBlkP, (int) Base);
  578. *Base = CmdBlkP;
  579. CmdBlkP->NextP = NULL;
  580. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  581. return RIO_SUCCESS;
  582. }
  583. /*
  584. ** Here we go - if there is an empty rup, fill it!
  585. ** must be called at splrio() or higher.
  586. */
  587. void RIOPollHostCommands(struct rio_info *p, struct Host *HostP)
  588. {
  589. register struct CmdBlk *CmdBlkP;
  590. register struct UnixRup *UnixRupP;
  591. struct PKT *PacketP;
  592. ushort Rup;
  593. unsigned long flags;
  594. Rup = MAX_RUP + LINKS_PER_UNIT;
  595. do { /* do this loop for each RUP */
  596. /*
  597. ** locate the rup we are processing & lock it
  598. */
  599. UnixRupP = &HostP->UnixRups[--Rup];
  600. spin_lock_irqsave(&UnixRupP->RupLock, flags);
  601. /*
  602. ** First check for incoming commands:
  603. */
  604. if (RWORD(UnixRupP->RupP->rxcontrol) != RX_RUP_INACTIVE) {
  605. int FreeMe;
  606. PacketP = (PKT *) RIO_PTR(HostP->Caddr, RWORD(UnixRupP->RupP->rxpkt));
  607. ShowPacket(DBG_CMD, PacketP);
  608. switch (RBYTE(PacketP->dest_port)) {
  609. case BOOT_RUP:
  610. rio_dprintk(RIO_DEBUG_CMD, "Incoming Boot %s packet '%x'\n", RBYTE(PacketP->len) & 0x80 ? "Command" : "Data", RBYTE(PacketP->data[0]));
  611. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  612. FreeMe = RIOBootRup(p, Rup, HostP, PacketP);
  613. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  614. break;
  615. case COMMAND_RUP:
  616. /*
  617. ** Free the RUP lock as loss of carrier causes a
  618. ** ttyflush which will (eventually) call another
  619. ** routine that uses the RUP lock.
  620. */
  621. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  622. FreeMe = RIOCommandRup(p, Rup, HostP, PacketP);
  623. if (PacketP->data[5] == MEMDUMP) {
  624. rio_dprintk(RIO_DEBUG_CMD, "Memdump from 0x%x complete\n", *(ushort *) & (PacketP->data[6]));
  625. HostP->Copy((caddr_t) & (PacketP->data[8]), (caddr_t) p->RIOMemDump, 32);
  626. }
  627. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  628. break;
  629. case ROUTE_RUP:
  630. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  631. FreeMe = RIORouteRup(p, Rup, HostP, PacketP);
  632. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  633. break;
  634. default:
  635. rio_dprintk(RIO_DEBUG_CMD, "Unknown RUP %d\n", RBYTE(PacketP->dest_port));
  636. FreeMe = 1;
  637. break;
  638. }
  639. if (FreeMe) {
  640. rio_dprintk(RIO_DEBUG_CMD, "Free processed incoming command packet\n");
  641. put_free_end(HostP, PacketP);
  642. WWORD(UnixRupP->RupP->rxcontrol, RX_RUP_INACTIVE);
  643. if (RWORD(UnixRupP->RupP->handshake) == PHB_HANDSHAKE_SET) {
  644. rio_dprintk(RIO_DEBUG_CMD, "Handshake rup %d\n", Rup);
  645. WWORD(UnixRupP->RupP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
  646. }
  647. }
  648. }
  649. /*
  650. ** IF a command was running on the port,
  651. ** and it has completed, then tidy it up.
  652. */
  653. if ((CmdBlkP = UnixRupP->CmdPendingP) && /* ASSIGN! */
  654. (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
  655. /*
  656. ** we are idle.
  657. ** there is a command in pending.
  658. ** Therefore, this command has finished.
  659. ** So, wakeup whoever is waiting for it (and tell them
  660. ** what happened).
  661. */
  662. if (CmdBlkP->Packet.dest_port == BOOT_RUP)
  663. rio_dprintk(RIO_DEBUG_CMD, "Free Boot %s Command Block '%x'\n", CmdBlkP->Packet.len & 0x80 ? "Command" : "Data", CmdBlkP->Packet.data[0]);
  664. rio_dprintk(RIO_DEBUG_CMD, "Command 0x%x completed\n", (int) CmdBlkP);
  665. /*
  666. ** Clear the Rup lock to prevent mutual exclusion.
  667. */
  668. if (CmdBlkP->PostFuncP) {
  669. rio_spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  670. (*CmdBlkP->PostFuncP) (CmdBlkP->PostArg, CmdBlkP);
  671. rio_spin_lock_irqsave(&UnixRupP->RupLock, flags);
  672. }
  673. /*
  674. ** ....clear the pending flag....
  675. */
  676. UnixRupP->CmdPendingP = NULL;
  677. /*
  678. ** ....and return the command block to the freelist.
  679. */
  680. RIOFreeCmdBlk(CmdBlkP);
  681. }
  682. /*
  683. ** If there is a command for this rup, and the rup
  684. ** is idle, then process the command
  685. */
  686. if ((CmdBlkP = UnixRupP->CmdsWaitingP) && /* ASSIGN! */
  687. (UnixRupP->CmdPendingP == NULL) && (RWORD(UnixRupP->RupP->txcontrol) == TX_RUP_INACTIVE)) {
  688. /*
  689. ** if the pre-function is non-zero, call it.
  690. ** If it returns RIO_FAIL then don't
  691. ** send this command yet!
  692. */
  693. #ifdef CHECK
  694. CheckCmdBlkP(CmdBlkP);
  695. #endif
  696. if (!(CmdBlkP->PreFuncP ? (*CmdBlkP->PreFuncP) (CmdBlkP->PreArg, CmdBlkP) : TRUE)) {
  697. rio_dprintk(RIO_DEBUG_CMD, "Not ready to start command 0x%x\n", (int) CmdBlkP);
  698. } else {
  699. rio_dprintk(RIO_DEBUG_CMD, "Start new command 0x%x Cmd byte is 0x%x\n", (int) CmdBlkP, CmdBlkP->Packet.data[0]);
  700. /*
  701. ** Whammy! blat that pack!
  702. */
  703. #ifdef CHECK
  704. CheckPacketP((PKT *) RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt));
  705. #endif
  706. HostP->Copy((caddr_t) & CmdBlkP->Packet, RIO_PTR(HostP->Caddr, UnixRupP->RupP->txpkt), sizeof(PKT));
  707. /*
  708. ** remove the command from the rup command queue...
  709. */
  710. UnixRupP->CmdsWaitingP = CmdBlkP->NextP;
  711. /*
  712. ** ...and place it on the pending position.
  713. */
  714. UnixRupP->CmdPendingP = CmdBlkP;
  715. /*
  716. ** set the command register
  717. */
  718. WWORD(UnixRupP->RupP->txcontrol, TX_PACKET_READY);
  719. /*
  720. ** the command block will be freed
  721. ** when the command has been processed.
  722. */
  723. }
  724. }
  725. spin_unlock_irqrestore(&UnixRupP->RupLock, flags);
  726. } while (Rup);
  727. }
  728. int RIOWFlushMark(int iPortP, struct CmdBlk *CmdBlkP)
  729. {
  730. struct Port *PortP = (struct Port *) iPortP;
  731. unsigned long flags;
  732. rio_spin_lock_irqsave(&PortP->portSem, flags);
  733. #ifdef CHECK
  734. CheckPortP(PortP);
  735. #endif
  736. PortP->WflushFlag++;
  737. PortP->MagicFlags |= MAGIC_FLUSH;
  738. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  739. return RIOUnUse(iPortP, CmdBlkP);
  740. }
  741. int RIORFlushEnable(int iPortP, struct CmdBlk *CmdBlkP)
  742. {
  743. struct Port *PortP = (struct Port *) iPortP;
  744. PKT *PacketP;
  745. unsigned long flags;
  746. rio_spin_lock_irqsave(&PortP->portSem, flags);
  747. while (can_remove_receive(&PacketP, PortP)) {
  748. remove_receive(PortP);
  749. ShowPacket(DBG_PROC, PacketP);
  750. put_free_end(PortP->HostP, PacketP);
  751. }
  752. if (RWORD(PortP->PhbP->handshake) == PHB_HANDSHAKE_SET) {
  753. /*
  754. ** MAGIC! (Basically, handshake the RX buffer, so that
  755. ** the RTAs upstream can be re-enabled.)
  756. */
  757. rio_dprintk(RIO_DEBUG_CMD, "Util: Set RX handshake bit\n");
  758. WWORD(PortP->PhbP->handshake, PHB_HANDSHAKE_SET | PHB_HANDSHAKE_RESET);
  759. }
  760. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  761. return RIOUnUse(iPortP, CmdBlkP);
  762. }
  763. int RIOUnUse(int iPortP, struct CmdBlk *CmdBlkP)
  764. {
  765. struct Port *PortP = (struct Port *) iPortP;
  766. unsigned long flags;
  767. rio_spin_lock_irqsave(&PortP->portSem, flags);
  768. #ifdef CHECK
  769. CheckPortP(PortP);
  770. #endif
  771. rio_dprintk(RIO_DEBUG_CMD, "Decrement in use count for port\n");
  772. if (PortP->InUse) {
  773. if (--PortP->InUse != NOT_INUSE) {
  774. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  775. return 0;
  776. }
  777. }
  778. /*
  779. ** While PortP->InUse is set (i.e. a preemptive command has been sent to
  780. ** the RTA and is awaiting completion), any transmit data is prevented from
  781. ** being transferred from the write queue into the transmit packets
  782. ** (add_transmit) and no furthur transmit interrupt will be sent for that
  783. ** data. The next interrupt will occur up to 500ms later (RIOIntr is called
  784. ** twice a second as a saftey measure). This was the case when kermit was
  785. ** used to send data into a RIO port. After each packet was sent, TCFLSH
  786. ** was called to flush the read queue preemptively. PortP->InUse was
  787. ** incremented, thereby blocking the 6 byte acknowledgement packet
  788. ** transmitted back. This acknowledgment hung around for 500ms before
  789. ** being sent, thus reducing input performance substantially!.
  790. ** When PortP->InUse becomes NOT_INUSE, we must ensure that any data
  791. ** hanging around in the transmit buffer is sent immediately.
  792. */
  793. WWORD(PortP->HostP->ParmMapP->tx_intr, 1);
  794. /* What to do here ..
  795. wakeup( (caddr_t)&(PortP->InUse) );
  796. */
  797. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  798. return 0;
  799. }
  800. void ShowPacket(uint Flags, struct PKT *PacketP)
  801. {
  802. }
  803. /*
  804. **
  805. ** How to use this file:
  806. **
  807. ** To send a command down a rup, you need to allocate a command block, fill
  808. ** in the packet information, fill in the command number, fill in the pre-
  809. ** and post- functions and arguments, and then add the command block to the
  810. ** queue of command blocks for the port in question. When the port is idle,
  811. ** then the pre-function will be called. If this returns RIO_FAIL then the
  812. ** command will be re-queued and tried again at a later date (probably in one
  813. ** clock tick). If the pre-function returns NOT RIO_FAIL, then the command
  814. ** packet will be queued on the RUP, and the txcontrol field set to the
  815. ** command number. When the txcontrol field has changed from being the
  816. ** command number, then the post-function will be called, with the argument
  817. ** specified earlier, a pointer to the command block, and the value of
  818. ** txcontrol.
  819. **
  820. ** To allocate a command block, call RIOGetCmdBlk(). This returns a pointer
  821. ** to the command block structure allocated, or NULL if there aren't any.
  822. ** The block will have been zeroed for you.
  823. **
  824. ** The structure has the following fields:
  825. **
  826. ** struct CmdBlk
  827. ** {
  828. ** struct CmdBlk *NextP; ** Pointer to next command block **
  829. ** struct PKT Packet; ** A packet, to copy to the rup **
  830. ** int (*PreFuncP)(); ** The func to call to check if OK **
  831. ** int PreArg; ** The arg for the func **
  832. ** int (*PostFuncP)(); ** The func to call when completed **
  833. ** int PostArg; ** The arg for the func **
  834. ** };
  835. **
  836. ** You need to fill in ALL fields EXCEPT NextP, which is used to link the
  837. ** blocks together either on the free list or on the Rup list.
  838. **
  839. ** Packet is an actual packet structure to be filled in with the packet
  840. ** information associated with the command. You need to fill in everything,
  841. ** as the command processore doesn't process the command packet in any way.
  842. **
  843. ** The PreFuncP is called before the packet is enqueued on the host rup.
  844. ** PreFuncP is called as (*PreFuncP)(PreArg, CmdBlkP);. PreFuncP must
  845. ** return !RIO_FAIL to have the packet queued on the rup, and RIO_FAIL
  846. ** if the packet is NOT to be queued.
  847. **
  848. ** The PostFuncP is called when the command has completed. It is called
  849. ** as (*PostFuncP)(PostArg, CmdBlkP, txcontrol);. PostFuncP is not expected
  850. ** to return a value. PostFuncP does NOT need to free the command block,
  851. ** as this happens automatically after PostFuncP returns.
  852. **
  853. ** Once the command block has been filled in, it is attached to the correct
  854. ** queue by calling RIOQueueCmdBlk( HostP, Rup, CmdBlkP ) where HostP is
  855. ** a pointer to the struct Host, Rup is the NUMBER of the rup (NOT a pointer
  856. ** to it!), and CmdBlkP is the pointer to the command block allocated using
  857. ** RIOGetCmdBlk().
  858. **
  859. */