rioroute.c 34 KB

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