riocmd.c 29 KB

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