rioroute.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /*
  2. ** -----------------------------------------------------------------------------
  3. **
  4. ** Perle Specialix driver for Linux
  5. ** Ported from existing RIO Driver for SCO sources.
  6. *
  7. * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. **
  23. ** Module : rioroute.c
  24. ** SID : 1.3
  25. ** Last Modified : 11/6/98 10:33:46
  26. ** Retrieved : 11/6/98 10:33:50
  27. **
  28. ** ident @(#)rioroute.c 1.3
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_rioroute_c_sccs_ = "@(#)rioroute.c 1.3";
  34. #endif
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/errno.h>
  38. #include <asm/io.h>
  39. #include <asm/system.h>
  40. #include <asm/string.h>
  41. #include <asm/semaphore.h>
  42. #include <asm/uaccess.h>
  43. #include <linux/termios.h>
  44. #include <linux/serial.h>
  45. #include <linux/generic_serial.h>
  46. #include "linux_compat.h"
  47. #include "rio_linux.h"
  48. #include "pkt.h"
  49. #include "daemon.h"
  50. #include "rio.h"
  51. #include "riospace.h"
  52. #include "cmdpkt.h"
  53. #include "map.h"
  54. #include "rup.h"
  55. #include "port.h"
  56. #include "riodrvr.h"
  57. #include "rioinfo.h"
  58. #include "func.h"
  59. #include "errors.h"
  60. #include "pci.h"
  61. #include "parmmap.h"
  62. #include "unixrup.h"
  63. #include "board.h"
  64. #include "host.h"
  65. #include "phb.h"
  66. #include "link.h"
  67. #include "cmdblk.h"
  68. #include "route.h"
  69. #include "cirrus.h"
  70. #include "rioioctl.h"
  71. #include "param.h"
  72. static int RIOCheckIsolated(struct rio_info *, struct Host *, unsigned int);
  73. static int RIOIsolate(struct rio_info *, struct Host *, unsigned int);
  74. static int RIOCheck(struct Host *, unsigned int);
  75. static void RIOConCon(struct rio_info *, struct Host *, unsigned int, unsigned int, unsigned int, unsigned int, int);
  76. /*
  77. ** Incoming on the ROUTE_RUP
  78. ** I wrote this while I was tired. Forgive me.
  79. */
  80. int RIORouteRup(struct rio_info *p, unsigned int Rup, struct Host *HostP, struct PKT * PacketP)
  81. {
  82. struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
  83. struct PktCmd_M *PktReplyP;
  84. struct CmdBlk *CmdBlkP;
  85. struct Port *PortP;
  86. struct Map *MapP;
  87. struct Top *TopP;
  88. int ThisLink, ThisLinkMin, ThisLinkMax;
  89. int port;
  90. int Mod, Mod1, Mod2;
  91. unsigned short RtaType;
  92. unsigned int RtaUniq;
  93. unsigned int ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */
  94. unsigned int OldUnit, NewUnit, OldLink, NewLink;
  95. char *MyType, *MyName;
  96. int Lies;
  97. unsigned long flags;
  98. /*
  99. ** Is this unit telling us it's current link topology?
  100. */
  101. if (readb(&PktCmdP->Command) == ROUTE_TOPOLOGY) {
  102. MapP = HostP->Mapping;
  103. /*
  104. ** The packet can be sent either by the host or by an RTA.
  105. ** If it comes from the host, then we need to fill in the
  106. ** Topology array in the host structure. If it came in
  107. ** from an RTA then we need to fill in the Mapping structure's
  108. ** Topology array for the unit.
  109. */
  110. if (Rup >= (unsigned short) MAX_RUP) {
  111. ThisUnit = HOST_ID;
  112. TopP = HostP->Topology;
  113. MyType = "Host";
  114. MyName = HostP->Name;
  115. ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
  116. } else {
  117. ThisUnit = Rup + 1;
  118. TopP = HostP->Mapping[Rup].Topology;
  119. MyType = "RTA";
  120. MyName = HostP->Mapping[Rup].Name;
  121. ThisLinkMin = 0;
  122. ThisLinkMax = LINKS_PER_UNIT - 1;
  123. }
  124. /*
  125. ** Lies will not be tolerated.
  126. ** If any pair of links claim to be connected to the same
  127. ** place, then ignore this packet completely.
  128. */
  129. Lies = 0;
  130. for (ThisLink = ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++) {
  131. /*
  132. ** it won't lie about network interconnect, total disconnects
  133. ** and no-IDs. (or at least, it doesn't *matter* if it does)
  134. */
  135. if (readb(&PktCmdP->RouteTopology[ThisLink].Unit) > (unsigned short) MAX_RUP)
  136. continue;
  137. for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
  138. if ((readb(&PktCmdP->RouteTopology[ThisLink].Unit) == readb(&PktCmdP->RouteTopology[NewLink].Unit)) && (readb(&PktCmdP->RouteTopology[ThisLink].Link) == readb(&PktCmdP->RouteTopology[NewLink].Link))) {
  139. Lies++;
  140. }
  141. }
  142. }
  143. if (Lies) {
  144. rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
  145. rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
  146. readb(&PktCmdP->RouteTopology[0].Unit),
  147. 'A' + readb(&PktCmdP->RouteTopology[0].Link),
  148. readb(&PktCmdP->RouteTopology[1].Unit),
  149. 'A' + readb(&PktCmdP->RouteTopology[1].Link), readb(&PktCmdP->RouteTopology[2].Unit), 'A' + readb(&PktCmdP->RouteTopology[2].Link), readb(&PktCmdP->RouteTopology[3].Unit), 'A' + readb(&PktCmdP->RouteTopology[3].Link));
  150. return 1;
  151. }
  152. /*
  153. ** now, process each link.
  154. */
  155. for (ThisLink = ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++) {
  156. /*
  157. ** this is what it was connected to
  158. */
  159. OldUnit = TopP[ThisLink].Unit;
  160. OldLink = TopP[ThisLink].Link;
  161. /*
  162. ** this is what it is now connected to
  163. */
  164. NewUnit = readb(&PktCmdP->RouteTopology[ThisLink].Unit);
  165. NewLink = readb(&PktCmdP->RouteTopology[ThisLink].Link);
  166. if (OldUnit != NewUnit || OldLink != NewLink) {
  167. /*
  168. ** something has changed!
  169. */
  170. if (NewUnit > MAX_RUP && NewUnit != ROUTE_DISCONNECT && NewUnit != ROUTE_NO_ID && NewUnit != ROUTE_INTERCONNECT) {
  171. rio_dprintk(RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n", MyType, MyName, NewUnit, NewLink);
  172. } else {
  173. /*
  174. ** put the new values in
  175. */
  176. TopP[ThisLink].Unit = NewUnit;
  177. TopP[ThisLink].Link = NewLink;
  178. RIOSetChange(p);
  179. if (OldUnit <= MAX_RUP) {
  180. /*
  181. ** If something has become bust, then re-enable them messages
  182. */
  183. if (!p->RIONoMessage)
  184. RIOConCon(p, HostP, ThisUnit, ThisLink, OldUnit, OldLink, DISCONNECT);
  185. }
  186. if ((NewUnit <= MAX_RUP) && !p->RIONoMessage)
  187. RIOConCon(p, HostP, ThisUnit, ThisLink, NewUnit, NewLink, CONNECT);
  188. if (NewUnit == ROUTE_NO_ID)
  189. rio_dprintk(RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n", MyType, MyName, 'A' + ThisLink);
  190. if (NewUnit == ROUTE_INTERCONNECT) {
  191. if (!p->RIONoMessage)
  192. printk(KERN_DEBUG "rio: %s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
  193. }
  194. /*
  195. ** perform an update for 'the other end', so that these messages
  196. ** only appears once. Only disconnect the other end if it is pointing
  197. ** at us!
  198. */
  199. if (OldUnit == HOST_ID) {
  200. if (HostP->Topology[OldLink].Unit == ThisUnit && HostP->Topology[OldLink].Link == ThisLink) {
  201. rio_dprintk(RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink + 'A');
  202. HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
  203. HostP->Topology[OldLink].Link = NO_LINK;
  204. } else {
  205. rio_dprintk(RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n", OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
  206. }
  207. } else if (OldUnit <= MAX_RUP) {
  208. if (HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit == ThisUnit && HostP->Mapping[OldUnit - 1].Topology[OldLink].Link == ThisLink) {
  209. rio_dprintk(RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A');
  210. HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit = ROUTE_DISCONNECT;
  211. HostP->Mapping[OldUnit - 1].Topology[OldLink].Link = NO_LINK;
  212. } else {
  213. rio_dprintk(RIO_DEBUG_ROUTE, "RTA %s (%c) WAS NOT CONNECTED TO %s (%c)\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
  214. }
  215. }
  216. if (NewUnit == HOST_ID) {
  217. rio_dprintk(RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n", NewLink + 'A', MyName, ThisLink + 'A');
  218. HostP->Topology[NewLink].Unit = ThisUnit;
  219. HostP->Topology[NewLink].Link = ThisLink;
  220. } else if (NewUnit <= MAX_RUP) {
  221. rio_dprintk(RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n", HostP->Mapping[NewUnit - 1].Name, NewLink + 'A', MyName, ThisLink + 'A');
  222. HostP->Mapping[NewUnit - 1].Topology[NewLink].Unit = ThisUnit;
  223. HostP->Mapping[NewUnit - 1].Topology[NewLink].Link = ThisLink;
  224. }
  225. }
  226. RIOSetChange(p);
  227. RIOCheckIsolated(p, HostP, OldUnit);
  228. }
  229. }
  230. return 1;
  231. }
  232. /*
  233. ** The only other command we recognise is a route_request command
  234. */
  235. if (readb(&PktCmdP->Command) != ROUTE_REQUEST) {
  236. rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %p ROUTE_RUP\n", readb(&PktCmdP->Command), Rup, HostP);
  237. return 1;
  238. }
  239. RtaUniq = (readb(&PktCmdP->UniqNum[0])) + (readb(&PktCmdP->UniqNum[1]) << 8) + (readb(&PktCmdP->UniqNum[2]) << 16) + (readb(&PktCmdP->UniqNum[3]) << 24);
  240. /*
  241. ** Determine if 8 or 16 port RTA
  242. */
  243. RtaType = GetUnitType(RtaUniq);
  244. rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
  245. Mod = readb(&PktCmdP->ModuleTypes);
  246. Mod1 = LONYBLE(Mod);
  247. if (RtaType == TYPE_RTA16) {
  248. /*
  249. ** Only one ident is set for a 16 port RTA. To make compatible
  250. ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
  251. */
  252. Mod2 = Mod1;
  253. rio_dprintk(RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n", p->RIOModuleTypes[Mod1].Name);
  254. } else {
  255. Mod2 = HINYBLE(Mod);
  256. rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
  257. }
  258. /*
  259. ** try to unhook a command block from the command free list.
  260. */
  261. if (!(CmdBlkP = RIOGetCmdBlk())) {
  262. rio_dprintk(RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
  263. return 0;
  264. }
  265. /*
  266. ** Fill in the default info on the command block
  267. */
  268. CmdBlkP->Packet.dest_unit = Rup;
  269. CmdBlkP->Packet.dest_port = ROUTE_RUP;
  270. CmdBlkP->Packet.src_unit = HOST_ID;
  271. CmdBlkP->Packet.src_port = ROUTE_RUP;
  272. CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
  273. CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
  274. PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
  275. if (!RIOBootOk(p, HostP, RtaUniq)) {
  276. rio_dprintk(RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n", RtaUniq);
  277. PktReplyP->Command = ROUTE_FOAD;
  278. HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
  279. RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
  280. return 1;
  281. }
  282. /*
  283. ** Check to see if the RTA is configured for this host
  284. */
  285. for (ThisUnit = 0; ThisUnit < MAX_RUP; ThisUnit++) {
  286. rio_dprintk(RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
  287. ThisUnit, HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE ? "Slot-In-Use" : "Not In Use", HostP->Mapping[ThisUnit].Flags & SLOT_TENTATIVE ? "Slot-Tentative" : "Not Tentative", HostP->Mapping[ThisUnit].RtaUniqueNum);
  288. /*
  289. ** We have an entry for it.
  290. */
  291. if ((HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq)) {
  292. if (RtaType == TYPE_RTA16) {
  293. ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
  294. rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n", RtaUniq, ThisUnit, ThisUnit2);
  295. } else
  296. rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n", RtaUniq, ThisUnit);
  297. /*
  298. ** If we have no knowledge of booting it, then the host has
  299. ** been re-booted, and so we must kill the RTA, so that it
  300. ** will be booted again (potentially with new bins)
  301. ** and it will then re-ask for an ID, which we will service.
  302. */
  303. if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
  304. if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
  305. if (!p->RIONoMessage)
  306. printk(KERN_DEBUG "rio: RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
  307. HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
  308. }
  309. PktReplyP->Command = ROUTE_FOAD;
  310. HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
  311. RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
  312. return 1;
  313. }
  314. /*
  315. ** Send the ID (entry) to this RTA. The ID number is implicit as
  316. ** the offset into the table. It is worth noting at this stage
  317. ** that offset zero in the table contains the entries for the
  318. ** RTA with ID 1!!!!
  319. */
  320. PktReplyP->Command = ROUTE_ALLOCATE;
  321. PktReplyP->IDNum = ThisUnit + 1;
  322. if (RtaType == TYPE_RTA16) {
  323. if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
  324. /*
  325. ** Adjust the phb and tx pkt dest_units for 2nd block of 8
  326. ** only if the RTA has ports associated (SLOT_IN_USE)
  327. */
  328. RIOFixPhbs(p, HostP, ThisUnit2);
  329. PktReplyP->IDNum2 = ThisUnit2 + 1;
  330. rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
  331. } else {
  332. PktReplyP->IDNum2 = ROUTE_NO_ID;
  333. rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum);
  334. }
  335. HostP->Copy("RT_ALLOCAT", PktReplyP->CommandText, 10);
  336. RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
  337. /*
  338. ** If this is a freshly booted RTA, then we need to re-open
  339. ** the ports, if any where open, so that data may once more
  340. ** flow around the system!
  341. */
  342. if ((HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) && (HostP->Mapping[ThisUnit].SysPort != NO_PORT)) {
  343. /*
  344. ** look at the ports associated with this beast and
  345. ** see if any where open. If they was, then re-open
  346. ** them, using the info from the tty flags.
  347. */
  348. for (port = 0; port < PORTS_PER_RTA; port++) {
  349. PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort];
  350. if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
  351. rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
  352. rio_spin_lock_irqsave(&PortP->portSem, flags);
  353. PortP->MagicFlags |= MAGIC_REBOOT;
  354. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  355. }
  356. }
  357. if (RtaType == TYPE_RTA16) {
  358. for (port = 0; port < PORTS_PER_RTA; port++) {
  359. PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort];
  360. if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
  361. rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
  362. rio_spin_lock_irqsave(&PortP->portSem, flags);
  363. PortP->MagicFlags |= MAGIC_REBOOT;
  364. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  365. }
  366. }
  367. }
  368. }
  369. /*
  370. ** keep a copy of the module types!
  371. */
  372. HostP->UnixRups[ThisUnit].ModTypes = Mod;
  373. if (RtaType == TYPE_RTA16)
  374. HostP->UnixRups[ThisUnit2].ModTypes = Mod;
  375. /*
  376. ** If either of the modules on this unit is read-only or write-only
  377. ** or none-xprint, then we need to transfer that info over to the
  378. ** relevant ports.
  379. */
  380. if (HostP->Mapping[ThisUnit].SysPort != NO_PORT) {
  381. for (port = 0; port < PORTS_PER_MODULE; port++) {
  382. p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
  383. p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
  384. p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
  385. p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
  386. }
  387. if (RtaType == TYPE_RTA16) {
  388. for (port = 0; port < PORTS_PER_MODULE; port++) {
  389. p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
  390. p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
  391. p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
  392. p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
  393. }
  394. }
  395. }
  396. /*
  397. ** Job done, get on with the interrupts!
  398. */
  399. return 1;
  400. }
  401. }
  402. /*
  403. ** There is no table entry for this RTA at all.
  404. **
  405. ** Lets check to see if we actually booted this unit - if not,
  406. ** then we reset it and it will go round the loop of being booted
  407. ** we can then worry about trying to fit it into the table.
  408. */
  409. for (ThisUnit = 0; ThisUnit < HostP->NumExtraBooted; ThisUnit++)
  410. if (HostP->ExtraUnits[ThisUnit] == RtaUniq)
  411. break;
  412. if (ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS) {
  413. /*
  414. ** if the unit wasn't in the table, and the table wasn't full, then
  415. ** we reset the unit, because we didn't boot it.
  416. ** However, if the table is full, it could be that we did boot
  417. ** this unit, and so we won't reboot it, because it isn't really
  418. ** all that disasterous to keep the old bins in most cases. This
  419. ** is a rather tacky feature, but we are on the edge of reallity
  420. ** here, because the implication is that someone has connected
  421. ** 16+MAX_EXTRA_UNITS onto one host.
  422. */
  423. static int UnknownMesgDone = 0;
  424. if (!UnknownMesgDone) {
  425. if (!p->RIONoMessage)
  426. printk(KERN_DEBUG "rio: One or more unknown RTAs are being updated.\n");
  427. UnknownMesgDone = 1;
  428. }
  429. PktReplyP->Command = ROUTE_FOAD;
  430. HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
  431. } else {
  432. /*
  433. ** we did boot it (as an extra), and there may now be a table
  434. ** slot free (because of a delete), so we will try to make
  435. ** a tentative entry for it, so that the configurator can see it
  436. ** and fill in the details for us.
  437. */
  438. if (RtaType == TYPE_RTA16) {
  439. if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
  440. RIODefaultName(p, HostP, ThisUnit);
  441. rio_fill_host_slot(ThisUnit, ThisUnit2, RtaUniq, HostP);
  442. }
  443. } else {
  444. if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
  445. RIODefaultName(p, HostP, ThisUnit);
  446. rio_fill_host_slot(ThisUnit, 0, RtaUniq, HostP);
  447. }
  448. }
  449. PktReplyP->Command = ROUTE_USED;
  450. HostP->Copy("RT_USED", PktReplyP->CommandText, 7);
  451. }
  452. RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
  453. return 1;
  454. }
  455. void RIOFixPhbs(struct rio_info *p, struct Host *HostP, unsigned int unit)
  456. {
  457. unsigned short link, port;
  458. struct Port *PortP;
  459. unsigned long flags;
  460. int PortN = HostP->Mapping[unit].SysPort;
  461. rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
  462. if (PortN != -1) {
  463. unsigned short dest_unit = HostP->Mapping[unit].ID2;
  464. /*
  465. ** Get the link number used for the 1st 8 phbs on this unit.
  466. */
  467. PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
  468. link = readw(&PortP->PhbP->link);
  469. for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
  470. unsigned short dest_port = port + 8;
  471. u16 *TxPktP;
  472. struct PKT *Pkt;
  473. PortP = p->RIOPortp[PortN];
  474. rio_spin_lock_irqsave(&PortP->portSem, flags);
  475. /*
  476. ** If RTA is not powered on, the tx packets will be
  477. ** unset, so go no further.
  478. */
  479. if (PortP->TxStart == 0) {
  480. rio_dprintk(RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
  481. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  482. break;
  483. }
  484. /*
  485. ** For the second slot of a 16 port RTA, the driver needs to
  486. ** sort out the phb to port mappings. The dest_unit for this
  487. ** group of 8 phbs is set to the dest_unit of the accompanying
  488. ** 8 port block. The dest_port of the second unit is set to
  489. ** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
  490. ** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
  491. ** (being the second map ID) will be sent to dest_unit 5, port
  492. ** 14. When this RTA is deleted, dest_unit for ID 6 will be
  493. ** restored, and the dest_port will be reduced by 8.
  494. ** Transmit packets also have a destination field which needs
  495. ** adjusting in the same manner.
  496. ** Note that the unit/port bytes in 'dest' are swapped.
  497. ** We also need to adjust the phb and rup link numbers for the
  498. ** second block of 8 ttys.
  499. */
  500. for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
  501. /*
  502. ** *TxPktP is the pointer to the transmit packet on the host
  503. ** card. This needs to be translated into a 32 bit pointer
  504. ** so it can be accessed from the driver.
  505. */
  506. Pkt = (struct PKT *) RIO_PTR(HostP->Caddr, readw(TxPktP));
  507. /*
  508. ** If the packet is used, reset it.
  509. */
  510. Pkt = (struct PKT *) ((unsigned long) Pkt & ~PKT_IN_USE);
  511. writeb(dest_unit, &Pkt->dest_unit);
  512. writeb(dest_port, &Pkt->dest_port);
  513. }
  514. rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", readw(&PortP->PhbP->destination) & 0xff, (readw(&PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
  515. writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
  516. writew(link, &PortP->PhbP->link);
  517. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  518. }
  519. /*
  520. ** Now make sure the range of ports to be serviced includes
  521. ** the 2nd 8 on this 16 port RTA.
  522. */
  523. if (link > 3)
  524. return;
  525. if (((unit * 8) + 7) > readw(&HostP->LinkStrP[link].last_port)) {
  526. rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
  527. writew((unit * 8) + 7, &HostP->LinkStrP[link].last_port);
  528. }
  529. }
  530. }
  531. /*
  532. ** Check to see if the new disconnection has isolated this unit.
  533. ** If it has, then invalidate all its link information, and tell
  534. ** the world about it. This is done to ensure that the configurator
  535. ** only gets up-to-date information about what is going on.
  536. */
  537. static int RIOCheckIsolated(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
  538. {
  539. unsigned long flags;
  540. rio_spin_lock_irqsave(&HostP->HostLock, flags);
  541. if (RIOCheck(HostP, UnitId)) {
  542. rio_dprintk(RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
  543. rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
  544. return (0);
  545. }
  546. RIOIsolate(p, HostP, UnitId);
  547. RIOSetChange(p);
  548. rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
  549. return 1;
  550. }
  551. /*
  552. ** Invalidate all the link interconnectivity of this unit, and of
  553. ** all the units attached to it. This will mean that the entire
  554. ** subnet will re-introduce itself.
  555. */
  556. static int RIOIsolate(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
  557. {
  558. unsigned int link, unit;
  559. UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
  560. if (UnitId >= MAX_RUP) /* dontcha just lurv unsigned maths! */
  561. return (0);
  562. if (HostP->Mapping[UnitId].Flags & BEEN_HERE)
  563. return (0);
  564. HostP->Mapping[UnitId].Flags |= BEEN_HERE;
  565. if (p->RIOPrintDisabled == DO_PRINT)
  566. rio_dprintk(RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
  567. for (link = 0; link < LINKS_PER_UNIT; link++) {
  568. unit = HostP->Mapping[UnitId].Topology[link].Unit;
  569. HostP->Mapping[UnitId].Topology[link].Unit = ROUTE_DISCONNECT;
  570. HostP->Mapping[UnitId].Topology[link].Link = NO_LINK;
  571. RIOIsolate(p, HostP, unit);
  572. }
  573. HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
  574. return 1;
  575. }
  576. static int RIOCheck(struct Host *HostP, unsigned int UnitId)
  577. {
  578. unsigned char link;
  579. /* rio_dprint(RIO_DEBUG_ROUTE, ("Check to see if unit %d has a route to the host\n",UnitId)); */
  580. rio_dprintk(RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
  581. if (UnitId == HOST_ID) {
  582. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
  583. return 1;
  584. }
  585. UnitId--;
  586. if (UnitId >= MAX_RUP) {
  587. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
  588. return 0;
  589. }
  590. for (link = 0; link < LINKS_PER_UNIT; link++) {
  591. if (HostP->Mapping[UnitId].Topology[link].Unit == HOST_ID) {
  592. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected directly to host via link (%c).\n",
  593. UnitId, 'A'+link)); */
  594. return 1;
  595. }
  596. }
  597. if (HostP->Mapping[UnitId].Flags & BEEN_HERE) {
  598. /* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
  599. return 0;
  600. }
  601. HostP->Mapping[UnitId].Flags |= BEEN_HERE;
  602. for (link = 0; link < LINKS_PER_UNIT; link++) {
  603. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d check link (%c)\n", UnitId,'A'+link)); */
  604. if (RIOCheck(HostP, HostP->Mapping[UnitId].Topology[link].Unit)) {
  605. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected to something that knows the host via link (%c)\n", UnitId,link+'A')); */
  606. HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
  607. return 1;
  608. }
  609. }
  610. HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
  611. /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
  612. return 0;
  613. }
  614. /*
  615. ** Returns the type of unit (host, 16/8 port RTA)
  616. */
  617. unsigned int GetUnitType(unsigned int Uniq)
  618. {
  619. switch ((Uniq >> 28) & 0xf) {
  620. case RIO_AT:
  621. case RIO_MCA:
  622. case RIO_EISA:
  623. case RIO_PCI:
  624. rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Host\n");
  625. return (TYPE_HOST);
  626. case RIO_RTA_16:
  627. rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
  628. return (TYPE_RTA16);
  629. case RIO_RTA:
  630. rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
  631. return (TYPE_RTA8);
  632. default:
  633. rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
  634. return (99);
  635. }
  636. }
  637. int RIOSetChange(struct rio_info *p)
  638. {
  639. if (p->RIOQuickCheck != NOT_CHANGED)
  640. return (0);
  641. p->RIOQuickCheck = CHANGED;
  642. if (p->RIOSignalProcess) {
  643. rio_dprintk(RIO_DEBUG_ROUTE, "Send SIG-HUP");
  644. /*
  645. psignal( RIOSignalProcess, SIGHUP );
  646. */
  647. }
  648. return (0);
  649. }
  650. static void RIOConCon(struct rio_info *p,
  651. struct Host *HostP,
  652. unsigned int FromId,
  653. unsigned int FromLink,
  654. unsigned int ToId,
  655. unsigned int ToLink,
  656. int Change)
  657. {
  658. char *FromName;
  659. char *FromType;
  660. char *ToName;
  661. char *ToType;
  662. unsigned int tp;
  663. /*
  664. ** 15.10.1998 ARG - ESIL 0759
  665. ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
  666. **
  667. ** What's this doing in here anyway ?
  668. ** It was causing the port to be 'unmapped' if opened whilst RTA "disconnected"
  669. **
  670. ** 09.12.1998 ARG - ESIL 0776 - part fix
  671. ** Okay, We've found out what this was all about now !
  672. ** Someone had botched this to use RIOHalted to indicated the number of RTAs
  673. ** 'disconnected'. The value in RIOHalted was then being used in the
  674. ** 'RIO_QUICK_CHECK' ioctl. A none zero value indicating that a least one RTA
  675. ** is 'disconnected'. The change was put in to satisfy a customer's needs.
  676. ** Having taken this bit of code out 'RIO_QUICK_CHECK' now no longer works for
  677. ** the customer.
  678. **
  679. if (Change == CONNECT) {
  680. if (p->RIOHalted) p->RIOHalted --;
  681. }
  682. else {
  683. p->RIOHalted ++;
  684. }
  685. **
  686. ** So - we need to implement it slightly differently - a new member of the
  687. ** rio_info struct - RIORtaDisCons (RIO RTA connections) keeps track of RTA
  688. ** connections and disconnections.
  689. */
  690. if (Change == CONNECT) {
  691. if (p->RIORtaDisCons)
  692. p->RIORtaDisCons--;
  693. } else {
  694. p->RIORtaDisCons++;
  695. }
  696. if (p->RIOPrintDisabled == DONT_PRINT)
  697. return;
  698. if (FromId > ToId) {
  699. tp = FromId;
  700. FromId = ToId;
  701. ToId = tp;
  702. tp = FromLink;
  703. FromLink = ToLink;
  704. ToLink = tp;
  705. }
  706. FromName = FromId ? HostP->Mapping[FromId - 1].Name : HostP->Name;
  707. FromType = FromId ? "RTA" : "HOST";
  708. ToName = ToId ? HostP->Mapping[ToId - 1].Name : HostP->Name;
  709. ToType = ToId ? "RTA" : "HOST";
  710. rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
  711. printk(KERN_DEBUG "rio: Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
  712. }
  713. /*
  714. ** RIORemoveFromSavedTable :
  715. **
  716. ** Delete and RTA entry from the saved table given to us
  717. ** by the configuration program.
  718. */
  719. static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
  720. {
  721. int entry;
  722. /*
  723. ** We loop for all entries even after finding an entry and
  724. ** zeroing it because we may have two entries to delete if
  725. ** it's a 16 port RTA.
  726. */
  727. for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
  728. if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
  729. memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
  730. }
  731. }
  732. return 0;
  733. }
  734. /*
  735. ** RIOCheckDisconnected :
  736. **
  737. ** Scan the unit links to and return zero if the unit is completely
  738. ** disconnected.
  739. */
  740. static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
  741. {
  742. int link;
  743. rio_dprintk(RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
  744. /*
  745. ** If the slot is tentative and does not belong to the
  746. ** second half of a 16 port RTA then scan to see if
  747. ** is disconnected.
  748. */
  749. for (link = 0; link < LINKS_PER_UNIT; link++) {
  750. if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
  751. break;
  752. }
  753. /*
  754. ** If not all links are disconnected then we can forget about it.
  755. */
  756. if (link < LINKS_PER_UNIT)
  757. return 1;
  758. #ifdef NEED_TO_FIX_THIS
  759. /* Ok so all the links are disconnected. But we may have only just
  760. ** made this slot tentative and not yet received a topology update.
  761. ** Lets check how long ago we made it tentative.
  762. */
  763. rio_dprintk(RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
  764. if (drv_getparm(LBOLT, (ulong_t *) & current_time))
  765. rio_dprintk(RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
  766. elapse_time = current_time - TentTime[unit];
  767. rio_dprintk(RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n", elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
  768. if (drv_hztousec(elapse_time) < WAIT_TO_FINISH) {
  769. rio_dprintk(RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n", unit, drv_hztousec(elapse_time));
  770. return 1;
  771. }
  772. #endif
  773. /*
  774. ** We have found an usable slot.
  775. ** If it is half of a 16 port RTA then delete the other half.
  776. */
  777. if (HostP->Mapping[unit].ID2 != 0) {
  778. int nOther = (HostP->Mapping[unit].ID2) - 1;
  779. rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
  780. memset(&HostP->Mapping[nOther], 0, sizeof(struct Map));
  781. }
  782. RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
  783. return 0;
  784. }
  785. /*
  786. ** RIOFindFreeID :
  787. **
  788. ** This function scans the given host table for either one
  789. ** or two free unit ID's.
  790. */
  791. int RIOFindFreeID(struct rio_info *p, struct Host *HostP, unsigned int * pID1, unsigned int * pID2)
  792. {
  793. int unit, tempID;
  794. /*
  795. ** Initialise the ID's to MAX_RUP.
  796. ** We do this to make the loop for setting the ID's as simple as
  797. ** possible.
  798. */
  799. *pID1 = MAX_RUP;
  800. if (pID2 != NULL)
  801. *pID2 = MAX_RUP;
  802. /*
  803. ** Scan all entries of the host mapping table for free slots.
  804. ** We scan for free slots first and then if that is not successful
  805. ** we start all over again looking for tentative slots we can re-use.
  806. */
  807. for (unit = 0; unit < MAX_RUP; unit++) {
  808. rio_dprintk(RIO_DEBUG_ROUTE, "Scanning unit %d\n", unit);
  809. /*
  810. ** If the flags are zero then the slot is empty.
  811. */
  812. if (HostP->Mapping[unit].Flags == 0) {
  813. rio_dprintk(RIO_DEBUG_ROUTE, " This slot is empty.\n");
  814. /*
  815. ** If we haven't allocated the first ID then do it now.
  816. */
  817. if (*pID1 == MAX_RUP) {
  818. rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
  819. *pID1 = unit;
  820. /*
  821. ** If the second ID is not needed then we can return
  822. ** now.
  823. */
  824. if (pID2 == NULL)
  825. return 0;
  826. } else {
  827. /*
  828. ** Allocate the second slot and return.
  829. */
  830. rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
  831. *pID2 = unit;
  832. return 0;
  833. }
  834. }
  835. }
  836. /*
  837. ** If we manage to come out of the free slot loop then we
  838. ** need to start all over again looking for tentative slots
  839. ** that we can re-use.
  840. */
  841. rio_dprintk(RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
  842. for (unit = 0; unit < MAX_RUP; unit++) {
  843. if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) || (HostP->Mapping[unit].Flags == 0)) && !(HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT)) {
  844. rio_dprintk(RIO_DEBUG_ROUTE, " Slot %d looks promising.\n", unit);
  845. if (unit == *pID1) {
  846. rio_dprintk(RIO_DEBUG_ROUTE, " No it isn't, its the 1st half\n");
  847. continue;
  848. }
  849. /*
  850. ** Slot is Tentative or Empty, but not a tentative second
  851. ** slot of a 16 porter.
  852. ** Attempt to free up this slot (and its parnter if
  853. ** it is a 16 port slot. The second slot will become
  854. ** empty after a call to RIOFreeDisconnected so thats why
  855. ** we look for empty slots above as well).
  856. */
  857. if (HostP->Mapping[unit].Flags != 0)
  858. if (RIOFreeDisconnected(p, HostP, unit) != 0)
  859. continue;
  860. /*
  861. ** If we haven't allocated the first ID then do it now.
  862. */
  863. if (*pID1 == MAX_RUP) {
  864. rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
  865. *pID1 = unit;
  866. /*
  867. ** Clear out this slot now that we intend to use it.
  868. */
  869. memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
  870. /*
  871. ** If the second ID is not needed then we can return
  872. ** now.
  873. */
  874. if (pID2 == NULL)
  875. return 0;
  876. } else {
  877. /*
  878. ** Allocate the second slot and return.
  879. */
  880. rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative/empty entry for second unit %d\n", unit);
  881. *pID2 = unit;
  882. /*
  883. ** Clear out this slot now that we intend to use it.
  884. */
  885. memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
  886. /* At this point under the right(wrong?) conditions
  887. ** we may have a first unit ID being higher than the
  888. ** second unit ID. This is a bad idea if we are about
  889. ** to fill the slots with a 16 port RTA.
  890. ** Better check and swap them over.
  891. */
  892. if (*pID1 > *pID2) {
  893. rio_dprintk(RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
  894. tempID = *pID1;
  895. *pID1 = *pID2;
  896. *pID2 = tempID;
  897. }
  898. return 0;
  899. }
  900. }
  901. }
  902. /*
  903. ** If we manage to get to the end of the second loop then we
  904. ** can give up and return a failure.
  905. */
  906. return 1;
  907. }
  908. /*
  909. ** The link switch scenario.
  910. **
  911. ** Rta Wun (A) is connected to Tuw (A).
  912. ** The tables are all up to date, and the system is OK.
  913. **
  914. ** If Wun (A) is now moved to Wun (B) before Wun (A) can
  915. ** become disconnected, then the follow happens:
  916. **
  917. ** Tuw (A) spots the change of unit:link at the other end
  918. ** of its link and Tuw sends a topology packet reflecting
  919. ** the change: Tuw (A) now disconnected from Wun (A), and
  920. ** this is closely followed by a packet indicating that
  921. ** Tuw (A) is now connected to Wun (B).
  922. **
  923. ** Wun (B) will spot that it has now become connected, and
  924. ** Wun will send a topology packet, which indicates that
  925. ** both Wun (A) and Wun (B) is connected to Tuw (A).
  926. **
  927. ** Eventually Wun (A) realises that it is now disconnected
  928. ** and Wun will send out a topology packet indicating that
  929. ** Wun (A) is now disconnected.
  930. */