riocmd.c 29 KB

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