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