rioroute.c 34 KB

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