riocmd.c 29 KB

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