rioroute.c 34 KB

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