riocmd.c 29 KB

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