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