2 ** -----------------------------------------------------------------------------
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
23 ** Module : rioroute.c
25 ** Last Modified : 11/6/98 10:33:46
26 ** Retrieved : 11/6/98 10:33:50
28 ** ident @(#)rioroute.c 1.3
30 ** -----------------------------------------------------------------------------
33 static char *_rioroute_c_sccs_ = "@(#)rioroute.c 1.3";
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/errno.h>
40 #include <asm/system.h>
41 #include <asm/string.h>
42 #include <asm/semaphore.h>
43 #include <asm/uaccess.h>
45 #include <linux/termios.h>
46 #include <linux/serial.h>
48 #include <linux/generic_serial.h>
51 #include "linux_compat.h"
52 #include "rio_linux.h"
87 ** Incoming on the ROUTE_RUP
88 ** I wrote this while I was tired. Forgive me.
90 int RIORouteRup( struct rio_info *p, uint Rup, struct Host *HostP, PKT *PacketP )
92 struct PktCmd *PktCmdP = (struct PktCmd *)PacketP->data;
93 struct PktCmd_M *PktReplyP;
94 struct CmdBlk *CmdBlkP;
98 int ThisLink, ThisLinkMin, ThisLinkMax;
103 uint ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */
104 uint OldUnit, NewUnit, OldLink, NewLink;
105 char *MyType, *MyName;
110 RIOStackCheck("RIORouteRup");
113 CheckPacketP(PacketP);
119 ** Is this unit telling us it's current link topology?
121 if ( RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY )
123 MapP = HostP->Mapping;
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.
132 if ( Rup >= (ushort)MAX_RUP )
135 TopP = HostP->Topology;
137 MyName = HostP->Name;
138 ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
143 TopP = HostP->Mapping[Rup].Topology;
145 MyName = HostP->Mapping[Rup].Name;
147 ThisLinkMax = LINKS_PER_UNIT - 1;
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.
156 for ( ThisLink=ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++)
159 ** it won't lie about network interconnect, total disconnects
160 ** and no-IDs. (or at least, it doesn't *matter* if it does)
162 if ( RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort)MAX_RUP )
165 for ( NewLink=ThisLinkMin; NewLink < ThisLink; NewLink++ )
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)) )
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));
193 ** now, process each link.
195 for ( ThisLink=ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++)
198 ** this is what it was connected to
200 OldUnit = TopP[ThisLink].Unit;
201 OldLink = TopP[ThisLink].Link;
204 ** this is what it is now connected to
206 NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit);
207 NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link);
209 if ( OldUnit != NewUnit || OldLink != NewLink )
212 ** something has changed!
215 if ( NewUnit > MAX_RUP &&
216 NewUnit != ROUTE_DISCONNECT &&
217 NewUnit != ROUTE_NO_ID &&
218 NewUnit != ROUTE_INTERCONNECT )
220 rio_dprintk (RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n",
229 ** put the new values in
231 TopP[ThisLink].Unit = NewUnit;
232 TopP[ThisLink].Link = NewLink;
236 if ( OldUnit <= MAX_RUP )
239 ** If something has become bust, then re-enable them messages
241 if (! p->RIONoMessage)
242 RIOConCon(p,HostP,ThisUnit,ThisLink,OldUnit,OldLink,DISCONNECT);
245 if ( ( NewUnit <= MAX_RUP ) && !p->RIONoMessage )
246 RIOConCon(p,HostP,ThisUnit,ThisLink,NewUnit,NewLink,CONNECT);
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);
252 if ( NewUnit == ROUTE_INTERCONNECT )
254 if (! p->RIONoMessage)
255 cprintf("%s '%s' (%c) is connected to another network.\n", MyType,MyName,'A'+ThisLink);
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
263 if ( OldUnit == HOST_ID )
265 if ( HostP->Topology[OldLink].Unit == ThisUnit &&
266 HostP->Topology[OldLink].Link == ThisLink )
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;
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');
278 else if ( OldUnit <= MAX_RUP )
280 if ( HostP->Mapping[OldUnit-1].Topology[OldLink].Unit == ThisUnit &&
281 HostP->Mapping[OldUnit-1].Topology[OldLink].Link == ThisLink )
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;
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');
295 if ( NewUnit == HOST_ID )
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;
302 else if ( NewUnit <= MAX_RUP )
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;
311 RIOCheckIsolated(p, HostP, OldUnit );
318 ** The only other command we recognise is a route_request command
320 if ( RBYTE(PktCmdP->Command) != ROUTE_REQUEST )
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);
327 RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) +
328 (RBYTE(PktCmdP->UniqNum[1]) << 8) +
329 (RBYTE(PktCmdP->UniqNum[2]) << 16) +
330 (RBYTE(PktCmdP->UniqNum[3]) << 24);
333 ** Determine if 8 or 16 port RTA
335 RtaType = GetUnitType(RtaUniq);
337 rio_dprintk (RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
339 Mod = RBYTE(PktCmdP->ModuleTypes);
341 if (RtaType == TYPE_RTA16)
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.
348 rio_dprintk (RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n",
349 p->RIOModuleTypes[Mod1].Name);
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);
358 if ( RtaUniq == 0xffffffff )
360 ShowPacket( DBG_SPECIAL, PacketP );
364 ** try to unhook a command block from the command free list.
366 if ( !(CmdBlkP = RIOGetCmdBlk()) )
368 rio_dprintk (RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
373 ** Fill in the default info on the command block
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;
383 if (! RIOBootOk(p, HostP, RtaUniq))
385 rio_dprintk (RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n",
387 PktReplyP->Command = ROUTE_FOAD;
388 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
389 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
394 ** Check to see if the RTA is configured for this host
396 for ( ThisUnit=0; ThisUnit<MAX_RUP; ThisUnit++ )
398 rio_dprintk (RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
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);
407 ** We have an entry for it.
409 if ( (HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) &&
410 (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq) )
412 if (RtaType == TYPE_RTA16)
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);
419 rio_dprintk (RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n",
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.
427 if ( (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) &&
428 !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED) )
430 if ( !(HostP->Mapping[ThisUnit].Flags & MSG_DONE) )
432 if ( !p->RIONoMessage )
433 cprintf("RTA '%s' is being updated.\n",HostP->Mapping[ThisUnit].Name);
434 HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
436 PktReplyP->Command = ROUTE_FOAD;
437 HostP->Copy("RT_FOAD",PktReplyP->CommandText,7);
438 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
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
448 PktReplyP->Command = ROUTE_ALLOCATE;
449 PktReplyP->IDNum = ThisUnit+1;
450 if (RtaType == TYPE_RTA16)
452 if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
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)
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);
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);
468 HostP->Copy("RT_ALLOCAT",PktReplyP->CommandText,10);
470 RIOQueueCmdBlk( HostP, Rup, CmdBlkP);
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!
477 if ( (HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) &&
478 (HostP->Mapping[ThisUnit].SysPort != NO_PORT) )
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.
485 for ( port=0; port<PORTS_PER_RTA; port++ )
487 PortP = p->RIOPortp[port+HostP->Mapping[ThisUnit].SysPort];
488 if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) )
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);
496 if (RtaType == TYPE_RTA16)
498 for ( port=0; port<PORTS_PER_RTA; port++ )
500 PortP = p->RIOPortp[port+HostP->Mapping[ThisUnit2].SysPort];
501 if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) )
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);
513 ** keep a copy of the module types!
515 HostP->UnixRups[ThisUnit].ModTypes = Mod;
516 if (RtaType == TYPE_RTA16)
517 HostP->UnixRups[ThisUnit2].ModTypes = Mod;
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
524 if ( HostP->Mapping[ThisUnit].SysPort != NO_PORT )
526 for ( port=0; port<PORTS_PER_MODULE; port++ )
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];
534 if (RtaType == TYPE_RTA16)
536 for ( port=0; port<PORTS_PER_MODULE; port++ )
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];
547 ** Job done, get on with the interrupts!
553 ** There is no table entry for this RTA at all.
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.
559 for ( ThisUnit=0; ThisUnit<HostP->NumExtraBooted; ThisUnit++ )
560 if ( HostP->ExtraUnits[ThisUnit] == RtaUniq )
562 if ( ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS )
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.
574 static int UnknownMesgDone = 0;
576 if ( !UnknownMesgDone )
578 if (! p->RIONoMessage)
579 cprintf("One or more unknown RTAs are being updated.\n");
583 PktReplyP->Command = ROUTE_FOAD;
584 HostP->Copy("RT_FOAD",PktReplyP->CommandText,7);
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.
594 if (RtaType == TYPE_RTA16)
596 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0)
598 RIODefaultName(p, HostP, ThisUnit);
599 FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP);
604 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0)
606 RIODefaultName(p, HostP, ThisUnit);
607 FillSlot(ThisUnit, 0, RtaUniq, HostP);
610 PktReplyP->Command = ROUTE_USED;
611 HostP->Copy("RT_USED",PktReplyP->CommandText,7);
613 RIOQueueCmdBlk( HostP, Rup, CmdBlkP);
619 RIOFixPhbs(p, HostP, unit)
627 int PortN = HostP->Mapping[unit].SysPort;
629 rio_dprintk (RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
632 ushort dest_unit = HostP->Mapping[unit].ID2;
635 ** Get the link number used for the 1st 8 phbs on this unit.
637 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
639 link = RWORD(PortP->PhbP->link);
641 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
642 ushort dest_port = port + 8;
649 PortP = p->RIOPortp[PortN];
651 rio_spin_lock_irqsave(&PortP->portSem, flags);
653 ** If RTA is not powered on, the tx packets will be
654 ** unset, so go no further.
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);
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.
678 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
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.
684 Pkt = (PKT *) RIO_PTR(HostP->Caddr,RINDW(TxPktP));
687 ** If the packet is used, reset it.
689 Pkt = (PKT *)((uint)Pkt & ~PKT_IN_USE);
690 WBYTE(Pkt->dest_unit, dest_unit);
691 WBYTE(Pkt->dest_port, dest_port);
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);
700 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
703 ** Now make sure the range of ports to be serviced includes
704 ** the 2nd 8 on this 16 port RTA.
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);
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.
721 RIOCheckIsolated(p, HostP, UnitId)
727 rio_spin_lock_irqsave(&HostP->HostLock, flags);
731 CheckUnitId( UnitId );
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);
739 RIOIsolate(p, HostP, UnitId );
741 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
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.
751 RIOIsolate(p, HostP, UnitId)
760 CheckUnitId( UnitId );
762 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
764 if ( UnitId >= MAX_RUP ) /* dontcha just lurv unsigned maths! */
767 if ( HostP->Mapping[UnitId].Flags & BEEN_HERE )
770 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
772 if ( p->RIOPrintDisabled == DO_PRINT )
773 rio_dprintk (RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
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 );
781 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
786 RIOCheck(HostP, UnitId)
794 CheckUnitId( UnitId );
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);
799 if ( UnitId == HOST_ID ) {
800 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
806 if ( UnitId >= MAX_RUP ) {
807 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
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)); */
819 if ( HostP->Mapping[UnitId].Flags & BEEN_HERE ) {
820 /* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
824 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
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;
835 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
837 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
843 ** Returns the type of unit (host, 16/8 port RTA)
850 switch ( (Uniq >> 28) & 0xf)
856 rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: Host\n");
859 rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
862 rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
865 rio_dprintk (RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
874 if ( p->RIOQuickCheck != NOT_CHANGED )
876 p->RIOQuickCheck = CHANGED;
877 if ( p->RIOSignalProcess ) {
878 rio_dprintk (RIO_DEBUG_ROUTE, "Send SIG-HUP");
880 psignal( RIOSignalProcess, SIGHUP );
887 RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change)
903 ** 15.10.1998 ARG - ESIL 0759
904 ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
906 ** What's this doing in here anyway ?
907 ** It was causing the port to be 'unmapped' if opened whilst RTA "disconnected"
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
918 if (Change == CONNECT) {
919 if (p->RIOHalted) p->RIOHalted --;
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.
929 if (Change == CONNECT) {
930 if (p->RIORtaDisCons) p->RIORtaDisCons--;
936 if ( p->RIOPrintDisabled == DONT_PRINT )
939 if ( FromId > ToId ) {
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";
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");
964 ** RIORemoveFromSavedTable :
966 ** Delete and RTA entry from the saved table given to us
967 ** by the configuration program.
970 RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
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.
979 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++)
981 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum)
983 bzero((caddr_t)&p->RIOSavedTable[entry], sizeof(struct Map));
991 ** RIOCheckDisconnected :
993 ** Scan the unit links to and return zero if the unit is completely
997 RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
1002 rio_dprintk (RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
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
1008 for (link = 0; link < LINKS_PER_UNIT; link++)
1010 if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
1015 ** If not all links are disconnected then we can forget about it.
1017 if (link < LINKS_PER_UNIT)
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.
1025 rio_dprintk (RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
1026 if (drv_getparm(LBOLT, (ulong_t *) ¤t_time))
1027 rio_dprintk (RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
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)
1034 rio_dprintk (RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n",
1035 unit, drv_hztousec(elapse_time));
1041 ** We have found an usable slot.
1042 ** If it is half of a 16 port RTA then delete the other half.
1044 if (HostP->Mapping[unit].ID2 != 0)
1046 int nOther = (HostP->Mapping[unit].ID2) -1;
1048 rio_dprintk (RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
1049 bzero((caddr_t)&HostP->Mapping[nOther], sizeof(struct Map));
1051 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
1060 ** This function scans the given host table for either one
1061 ** or two free unit ID's.
1064 RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint *pID1, uint *pID2)
1069 ** Initialise the ID's to MAX_RUP.
1070 ** We do this to make the loop for setting the ID's as simple as
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.
1082 for (unit = 0; unit < MAX_RUP; unit++)
1084 rio_dprintk (RIO_DEBUG_ROUTE, "Scanning unit %d\n",unit);
1086 ** If the flags are zero then the slot is empty.
1088 if (HostP->Mapping[unit].Flags == 0)
1090 rio_dprintk (RIO_DEBUG_ROUTE, " This slot is empty.\n");
1092 ** If we haven't allocated the first ID then do it now.
1094 if (*pID1 == MAX_RUP)
1096 rio_dprintk (RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
1100 ** If the second ID is not needed then we can return
1109 ** Allocate the second slot and return.
1111 rio_dprintk (RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
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.
1123 rio_dprintk (RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
1124 for (unit = 0; unit < MAX_RUP; unit++)
1126 if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) ||
1127 (HostP->Mapping[unit].Flags == 0)) && !
1128 (HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT ))
1130 rio_dprintk (RIO_DEBUG_ROUTE, " Slot %d looks promising.\n",unit);
1134 rio_dprintk (RIO_DEBUG_ROUTE, " No it isn't, its the 1st half\n");
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).
1146 if (HostP->Mapping[unit].Flags != 0)
1147 if (RIOFreeDisconnected(p, HostP, unit) != 0)
1150 ** If we haven't allocated the first ID then do it now.
1152 if (*pID1 == MAX_RUP)
1154 rio_dprintk (RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
1158 ** Clear out this slot now that we intend to use it.
1160 bzero(&HostP->Mapping[unit], sizeof(struct Map));
1163 ** If the second ID is not needed then we can return
1172 ** Allocate the second slot and return.
1174 rio_dprintk (RIO_DEBUG_ROUTE, "Grab tentative/empty entry for second unit %d\n",
1179 ** Clear out this slot now that we intend to use it.
1181 bzero(&HostP->Mapping[unit], sizeof(struct Map));
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.
1192 rio_dprintk (RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
1203 ** If we manage to get to the end of the second loop then we
1204 ** can give up and return a failure.
1211 ** The link switch scenario.
1213 ** Rta Wun (A) is connected to Tuw (A).
1214 ** The tables are all up to date, and the system is OK.
1216 ** If Wun (A) is now moved to Wun (B) before Wun (A) can
1217 ** become disconnected, then the follow happens:
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).
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).
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.