riocmd.c 29 KB

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