rioroute.c 35 KB

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