#if NEED_TO_FIX 
#ifdef NEED_TO_FIX 
static int RIOBootComplete( struct rio_info *p, struct Host *HostP, uint Rup, struct PktCmd *PktCmdP ){	struct Map	*MapP = NULL;	struct Map	*MapP2 = NULL;	int	Flag;	int	found;	int	host, rta;	int	EmptySlot = -1;	int	entry, entry2;	char	*MyType, *MyName;	uint	MyLink;	ushort	RtaType;	uint	RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) +			  (RBYTE(PktCmdP->UniqNum[1]) << 8) +			  (RBYTE(PktCmdP->UniqNum[2]) << 16) +			  (RBYTE(PktCmdP->UniqNum[3]) << 24);	/* Was RIOBooting-- . That's bad. If an RTA sends two of them, the	   driver will never think that the RTA has booted... -- REW */	p->RIOBooting = 0;	rio_dprintk (RIO_DEBUG_BOOT, "RTA Boot completed - BootInProgress now %d\n", p->RIOBooting);	/*	** Determine type of unit (16/8 port RTA).	*/	RtaType = GetUnitType(RtaUniq);        if ( Rup >= (ushort)MAX_RUP ) {	    rio_dprintk (RIO_DEBUG_BOOT, "RIO: Host %s has booted an RTA(%d) on link %c\n",	     HostP->Name, 8 * RtaType, RBYTE(PktCmdP->LinkNum)+'A');	} else {	    rio_dprintk (RIO_DEBUG_BOOT, "RIO: RTA %s has booted an RTA(%d) on link %c\n",	     HostP->Mapping[Rup].Name, 8 * RtaType,	     RBYTE(PktCmdP->LinkNum)+'A');	}	rio_dprintk (RIO_DEBUG_BOOT, "UniqNum is 0x%x\n",RtaUniq);        if ( ( RtaUniq == 0x00000000 ) || ( RtaUniq == 0xffffffff ) )	{	    rio_dprintk (RIO_DEBUG_BOOT, "Illegal RTA Uniq Number\n");	    return TRUE;	}	/*	** If this RTA has just booted an RTA which doesn't belong to this	** system, or the system is in slave mode, do not attempt to create	** a new table entry for it.	*/	if (!RIOBootOk(p, HostP, RtaUniq))	{	    MyLink = RBYTE(PktCmdP->LinkNum);	    if (Rup < (ushort) MAX_RUP)	    {		/*		** RtaUniq was clone booted (by this RTA). Instruct this RTA		** to hold off further attempts to boot on this link for 30		** seconds.		*/		if (RIOSuspendBootRta(HostP, HostP->Mapping[Rup].ID, MyLink))		{		    rio_dprintk (RIO_DEBUG_BOOT, "RTA failed to suspend booting on link %c\n",		     'A' + MyLink);		}	    }	    else	    {		/*		** RtaUniq was booted by this host. Set the booting link		** to hold off for 30 seconds to give another unit a		** chance to boot it.		*/		WWORD(HostP->LinkStrP[MyLink].WaitNoBoot, 30);	    }	    rio_dprintk (RIO_DEBUG_BOOT, "RTA %x not owned - suspend booting down link %c on unit %x\n",	      RtaUniq, 'A' + MyLink, HostP->Mapping[Rup].RtaUniqueNum);	    return TRUE;	}	/*	** Check for a SLOT_IN_USE entry for this RTA attached to the	** current host card in the driver table.	**	** If it exists, make a note that we have booted it. Other parts of	** the driver are interested in this information at a later date,	** in particular when the booting RTA asks for an ID for this unit,	** we must have set the BOOTED flag, and the NEWBOOT flag is used	** to force an open on any ports that where previously open on this	** unit.	*/        for ( entry=0; entry<MAX_RUP; entry++ )	{	    uint sysport;	    if ((HostP->Mapping[entry].Flags & SLOT_IN_USE) && 	       (HostP->Mapping[entry].RtaUniqueNum==RtaUniq))	    {	        HostP->Mapping[entry].Flags |= RTA_BOOTED|RTA_NEWBOOT;#if NEED_TO_FIX		RIO_SV_BROADCAST(HostP->svFlags[entry]);#endif		if ( (sysport=HostP->Mapping[entry].SysPort) != NO_PORT )		{		   if ( sysport < p->RIOFirstPortsBooted )			p->RIOFirstPortsBooted = sysport;		   if ( sysport > p->RIOLastPortsBooted )			p->RIOLastPortsBooted = sysport;		   /*		   ** For a 16 port RTA, check the second bank of 8 ports		   */		   if (RtaType == TYPE_RTA16)		   {			entry2 = HostP->Mapping[entry].ID2 - 1;			HostP->Mapping[entry2].Flags |= RTA_BOOTED|RTA_NEWBOOT;#if NEED_TO_FIX			RIO_SV_BROADCAST(HostP->svFlags[entry2]);#endif			sysport = HostP->Mapping[entry2].SysPort;			if ( sysport < p->RIOFirstPortsBooted )			    p->RIOFirstPortsBooted = sysport;			if ( sysport > p->RIOLastPortsBooted )			    p->RIOLastPortsBooted = sysport;		   }		}		if (RtaType == TYPE_RTA16) {		   rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given IDs %d+%d\n",		    entry+1, entry2+1);		} else {		   rio_dprintk (RIO_DEBUG_BOOT, "RTA will be given ID %d\n",entry+1);		}		return TRUE;	    }	}	rio_dprintk (RIO_DEBUG_BOOT, "RTA not configured for this host\n");	if ( Rup >= (ushort)MAX_RUP )	{	    /*	    ** It was a host that did the booting	    */	    MyType = "Host";	    MyName = HostP->Name;	}	else	{	    /*	    ** It was an RTA that did the booting	    */	    MyType = "RTA";	    MyName = HostP->Mapping[Rup].Name;	}#ifdef CHECK	CheckString(MyType);	CheckString(MyName);#endif	MyLink = RBYTE(PktCmdP->LinkNum);	/*	** There is no SLOT_IN_USE entry for this RTA attached to the current	** host card in the driver table.	**	** Check for a SLOT_TENTATIVE entry for this RTA attached to the	** current host card in the driver table.	**	** If we find one, then we re-use that slot.	*/	for ( entry=0; entry<MAX_RUP; entry++ )	{	    if ( (HostP->Mapping[entry].Flags & SLOT_TENTATIVE) &&		 (HostP->Mapping[entry].RtaUniqueNum == RtaUniq) )	    {		if (RtaType == TYPE_RTA16)		{		    entry2 = HostP->Mapping[entry].ID2 - 1;		    if ( (HostP->Mapping[entry2].Flags & SLOT_TENTATIVE) &&			 (HostP->Mapping[entry2].RtaUniqueNum == RtaUniq) )			rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slots (%d+%d)\n",			 entry, entry2);		    else			continue;		}		else			rio_dprintk (RIO_DEBUG_BOOT, "Found previous tentative slot (%d)\n",entry);		if (! p->RIONoMessage)		    cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');		return TRUE;	    }	}	/*	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA	** attached to the current host card in the driver table.	**	** Check if there is a SLOT_IN_USE or SLOT_TENTATIVE entry on another	** host for this RTA in the driver table.	**	** For a SLOT_IN_USE entry on another host, we need to delete the RTA	** entry from the other host and add it to this host (using some of	** the functions from table.c which do this).	** For a SLOT_TENTATIVE entry on another host, we must cope with the	** following scenario:	**	** + Plug 8 port RTA into host A. (This creates SLOT_TENTATIVE entry	**   in table)	** + Unplug RTA and plug into host B. (We now have 2 SLOT_TENTATIVE	**   entries)	** + Configure RTA on host B. (This slot now becomes SLOT_IN_USE)	** + Unplug RTA and plug back into host A.	** + Configure RTA on host A. We now have the same RTA configured	**   with different ports on two different hosts.	*/	rio_dprintk (RIO_DEBUG_BOOT, "Have we seen RTA %x before?\n", RtaUniq );	found = 0;	Flag = 0; /* Convince the compiler this variable is initialized */	for ( host = 0; !found && (host < p->RIONumHosts); host++ )	{	    for ( rta=0; rta<MAX_RUP; rta++ )	    {		if ((p->RIOHosts[host].Mapping[rta].Flags &		 (SLOT_IN_USE | SLOT_TENTATIVE)) &&		 (p->RIOHosts[host].Mapping[rta].RtaUniqueNum==RtaUniq))		{		    Flag = p->RIOHosts[host].Mapping[rta].Flags;		    MapP = &p->RIOHosts[host].Mapping[rta];		    if (RtaType == TYPE_RTA16)		    {			MapP2 = &p->RIOHosts[host].Mapping[MapP->ID2 - 1];			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is units %d+%d from host %s\n",			 rta+1, MapP->ID2, p->RIOHosts[host].Name);		    }		    else			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is unit %d from host %s\n",			 rta+1, p->RIOHosts[host].Name);		    found = 1;		    break;		}	    }	}	/*	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA	** attached to the current host card in the driver table.	**	** If we have not found a SLOT_IN_USE or SLOT_TENTATIVE entry on	** another host for this RTA in the driver table...	**	** Check for a SLOT_IN_USE entry for this RTA in the config table.	*/	if ( !MapP )	{	    rio_dprintk (RIO_DEBUG_BOOT, "Look for RTA %x in RIOSavedTable\n",RtaUniq);	    for ( rta=0; rta < TOTAL_MAP_ENTRIES; rta++ )	    {		rio_dprintk (RIO_DEBUG_BOOT, "Check table entry %d (%x)",		      rta,		      p->RIOSavedTable[rta].RtaUniqueNum);		if ( (p->RIOSavedTable[rta].Flags & SLOT_IN_USE) &&		 (p->RIOSavedTable[rta].RtaUniqueNum == RtaUniq) )		{		    MapP = &p->RIOSavedTable[rta];		    Flag = p->RIOSavedTable[rta].Flags;		    if (RtaType == TYPE_RTA16)		    {                        for (entry2 = rta + 1; entry2 < TOTAL_MAP_ENTRIES;                         entry2++)                        {                            if (p->RIOSavedTable[entry2].RtaUniqueNum == RtaUniq)                                break;                        }                        MapP2 = &p->RIOSavedTable[entry2];                        rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entries %d+%d\n",                              rta, entry2);		    }		    else			rio_dprintk (RIO_DEBUG_BOOT, "This RTA is from table entry %d\n", rta);		    break;		}	    }	}	/*	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA	** attached to the current host card in the driver table.	**	** We may have found a SLOT_IN_USE entry on another host for this	** RTA in the config table, or a SLOT_IN_USE or SLOT_TENTATIVE entry	** on another host for this RTA in the driver table.	**	** Check the driver table for room to fit this newly discovered RTA.	** RIOFindFreeID() first looks for free slots and if it does not	** find any free slots it will then attempt to oust any	** tentative entry in the table.	*/	EmptySlot = 1;	if (RtaType == TYPE_RTA16)	{	    if (RIOFindFreeID(p, HostP, &entry, &entry2) == 0)	    {		RIODefaultName(p, HostP, entry);		FillSlot(entry, entry2, RtaUniq, HostP);		EmptySlot = 0;	    }	}	else	{	    if (RIOFindFreeID(p, HostP, &entry, NULL) == 0)	    {		RIODefaultName(p, HostP, entry);		FillSlot(entry, 0, RtaUniq, HostP);		EmptySlot = 0;	    }	}	/*	** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA	** attached to the current host card in the driver table.	**	** If we found a SLOT_IN_USE entry on another host for this	** RTA in the config or driver table, and there are enough free	** slots in the driver table, then we need to move it over and	** delete it from the other host.	** If we found a SLOT_TENTATIVE entry on another host for this	** RTA in the driver table, just delete the other host entry.	*/	if (EmptySlot == 0)	{	    if ( MapP )	    {		if (Flag & SLOT_IN_USE)		{		    rio_dprintk (RIO_DEBUG_BOOT,     "This RTA configured on another host - move entry to current host (1)\n");		    HostP->Mapping[entry].SysPort = MapP->SysPort;		    CCOPY( MapP->Name, HostP->Mapping[entry].Name, MAX_NAME_LEN );		    HostP->Mapping[entry].Flags =		     SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT;#if NEED_TO_FIX		    RIO_SV_BROADCAST(HostP->svFlags[entry]);#endif		    RIOReMapPorts( p, HostP, &HostP->Mapping[entry] );		    if ( HostP->Mapping[entry].SysPort < p->RIOFirstPortsBooted )			p->RIOFirstPortsBooted = HostP->Mapping[entry].SysPort;		    if ( HostP->Mapping[entry].SysPort > p->RIOLastPortsBooted )			p->RIOLastPortsBooted = HostP->Mapping[entry].SysPort;		    rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",(int)MapP->SysPort,MapP->Name);		}		else		{		    rio_dprintk (RIO_DEBUG_BOOT,    "This RTA has a tentative entry on another host - delete that entry (1)\n");		    HostP->Mapping[entry].Flags =		     SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT;#if NEED_TO_FIX		    RIO_SV_BROADCAST(HostP->svFlags[entry]);#endif		}		if (RtaType == TYPE_RTA16)		{		    if (Flag & SLOT_IN_USE)		    {			HostP->Mapping[entry2].Flags = SLOT_IN_USE |			 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;#if NEED_TO_FIX			RIO_SV_BROADCAST(HostP->svFlags[entry2]);#endif			HostP->Mapping[entry2].SysPort = MapP2->SysPort;			/*			** Map second block of ttys for 16 port RTA			*/			RIOReMapPorts( p, HostP, &HostP->Mapping[entry2] );		       if (HostP->Mapping[entry2].SysPort < p->RIOFirstPortsBooted)			 p->RIOFirstPortsBooted = HostP->Mapping[entry2].SysPort;		       if (HostP->Mapping[entry2].SysPort > p->RIOLastPortsBooted)			 p->RIOLastPortsBooted = HostP->Mapping[entry2].SysPort;			rio_dprintk (RIO_DEBUG_BOOT, "SysPort %d, Name %s\n",			       (int)HostP->Mapping[entry2].SysPort,			       HostP->Mapping[entry].Name);		    }		    else			HostP->Mapping[entry2].Flags = SLOT_TENTATIVE |			 RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;#if NEED_TO_FIX			RIO_SV_BROADCAST(HostP->svFlags[entry2]);#endif		    bzero( (caddr_t)MapP2, sizeof(struct Map) );		}		bzero( (caddr_t)MapP, sizeof(struct Map) );		if (! p->RIONoMessage)		    cprintf("An orphaned RTA has been adopted by %s '%s' (%c).\n",MyType,MyName,MyLink+'A');	    }	    else if (! p->RIONoMessage)		cprintf("RTA connected to %s '%s' (%c) not configured.\n",MyType,MyName,MyLink+'A');	    RIOSetChange(p);	    return TRUE;	}	/*	** There is no room in the driver table to make an entry for the	** booted RTA. Keep a note of its Uniq Num in the overflow table,	** so we can ignore it's ID requests.	*/	if (! p->RIONoMessage)	    cprintf("The RTA connected to %s '%s' (%c) cannot be configured.  You cannot configure more than 128 ports to one host card.\n",MyType,MyName,MyLink+'A');	for ( entry=0; entry<HostP->NumExtraBooted; entry++ )	{	    if ( HostP->ExtraUnits[entry] == RtaUniq )	    {		/*		** already got it!		*/		return TRUE;	    }	}	/*	** If there is room, add the unit to the list of extras	*/	if ( HostP->NumExtraBooted < MAX_EXTRA_UNITS )	    HostP->ExtraUnits[HostP->NumExtraBooted++] = RtaUniq;	return TRUE;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/44456d37b59d8e541936ed26d8b6e08d27e88ac1/rioboot.c/clean/drivers/char/rio/rioboot.c