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"
86 static int RIOCheckIsolated(struct rio_info *, struct Host *, uint);
87 static int RIOIsolate(struct rio_info *, struct Host *, uint);
88 static int RIOCheck(struct Host *, uint);
89 static void RIOConCon(struct rio_info *, struct Host *, uint, uint, uint, uint, int);
93 ** Incoming on the ROUTE_RUP
94 ** I wrote this while I was tired. Forgive me.
96 int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
98 struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
99 struct PktCmd_M *PktReplyP;
100 struct CmdBlk *CmdBlkP;
104 int ThisLink, ThisLinkMin, ThisLinkMax;
109 uint ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */
110 uint OldUnit, NewUnit, OldLink, NewLink;
111 char *MyType, *MyName;
116 RIOStackCheck("RIORouteRup");
119 CheckPacketP(PacketP);
125 ** Is this unit telling us it's current link topology?
127 if (RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY) {
128 MapP = HostP->Mapping;
131 ** The packet can be sent either by the host or by an RTA.
132 ** If it comes from the host, then we need to fill in the
133 ** Topology array in the host structure. If it came in
134 ** from an RTA then we need to fill in the Mapping structure's
135 ** Topology array for the unit.
137 if (Rup >= (ushort) MAX_RUP) {
139 TopP = HostP->Topology;
141 MyName = HostP->Name;
142 ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
145 TopP = HostP->Mapping[Rup].Topology;
147 MyName = HostP->Mapping[Rup].Name;
149 ThisLinkMax = LINKS_PER_UNIT - 1;
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.
158 for (ThisLink = ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++) {
160 ** it won't lie about network interconnect, total disconnects
161 ** and no-IDs. (or at least, it doesn't *matter* if it does)
163 if (RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort) MAX_RUP)
166 for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
167 if ((RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) == RBYTE(PktCmdP->RouteTopology[NewLink].Unit)) && (RBYTE(PktCmdP->RouteTopology[ThisLink].Link) == RBYTE(PktCmdP->RouteTopology[NewLink].Link))) {
174 rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
175 rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
176 RBYTE(PktCmdP->RouteTopology[0].Unit),
177 'A' + RBYTE(PktCmdP->RouteTopology[0].Link),
178 RBYTE(PktCmdP->RouteTopology[1].Unit),
179 'A' + RBYTE(PktCmdP->RouteTopology[1].Link), RBYTE(PktCmdP->RouteTopology[2].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[2].Link), RBYTE(PktCmdP->RouteTopology[3].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[3].Link));
184 ** now, process each link.
186 for (ThisLink = ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++) {
188 ** this is what it was connected to
190 OldUnit = TopP[ThisLink].Unit;
191 OldLink = TopP[ThisLink].Link;
194 ** this is what it is now connected to
196 NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit);
197 NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link);
199 if (OldUnit != NewUnit || OldLink != NewLink) {
201 ** something has changed!
204 if (NewUnit > MAX_RUP && NewUnit != ROUTE_DISCONNECT && NewUnit != ROUTE_NO_ID && NewUnit != ROUTE_INTERCONNECT) {
205 rio_dprintk(RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n", MyType, MyName, NewUnit, NewLink);
208 ** put the new values in
210 TopP[ThisLink].Unit = NewUnit;
211 TopP[ThisLink].Link = NewLink;
215 if (OldUnit <= MAX_RUP) {
217 ** If something has become bust, then re-enable them messages
219 if (!p->RIONoMessage)
220 RIOConCon(p, HostP, ThisUnit, ThisLink, OldUnit, OldLink, DISCONNECT);
223 if ((NewUnit <= MAX_RUP) && !p->RIONoMessage)
224 RIOConCon(p, HostP, ThisUnit, ThisLink, NewUnit, NewLink, CONNECT);
226 if (NewUnit == ROUTE_NO_ID)
227 rio_dprintk(RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n", MyType, MyName, 'A' + ThisLink);
229 if (NewUnit == ROUTE_INTERCONNECT) {
230 if (!p->RIONoMessage)
231 cprintf("%s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
235 ** perform an update for 'the other end', so that these messages
236 ** only appears once. Only disconnect the other end if it is pointing
239 if (OldUnit == HOST_ID) {
240 if (HostP->Topology[OldLink].Unit == ThisUnit && HostP->Topology[OldLink].Link == ThisLink) {
241 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink + 'A');
242 HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
243 HostP->Topology[OldLink].Link = NO_LINK;
245 rio_dprintk(RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n", OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
247 } else if (OldUnit <= MAX_RUP) {
248 if (HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit == ThisUnit && HostP->Mapping[OldUnit - 1].Topology[OldLink].Link == ThisLink) {
249 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A');
250 HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit = ROUTE_DISCONNECT;
251 HostP->Mapping[OldUnit - 1].Topology[OldLink].Link = NO_LINK;
253 rio_dprintk(RIO_DEBUG_ROUTE, "RTA %s (%c) WAS NOT CONNECTED TO %s (%c)\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
256 if (NewUnit == HOST_ID) {
257 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n", NewLink + 'A', MyName, ThisLink + 'A');
258 HostP->Topology[NewLink].Unit = ThisUnit;
259 HostP->Topology[NewLink].Link = ThisLink;
260 } else if (NewUnit <= MAX_RUP) {
261 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n", HostP->Mapping[NewUnit - 1].Name, NewLink + 'A', MyName, ThisLink + 'A');
262 HostP->Mapping[NewUnit - 1].Topology[NewLink].Unit = ThisUnit;
263 HostP->Mapping[NewUnit - 1].Topology[NewLink].Link = ThisLink;
267 RIOCheckIsolated(p, HostP, OldUnit);
274 ** The only other command we recognise is a route_request command
276 if (RBYTE(PktCmdP->Command) != ROUTE_REQUEST) {
277 rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %d ROUTE_RUP\n", RBYTE(PktCmdP->Command), Rup, (int) HostP);
281 RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) + (RBYTE(PktCmdP->UniqNum[1]) << 8) + (RBYTE(PktCmdP->UniqNum[2]) << 16) + (RBYTE(PktCmdP->UniqNum[3]) << 24);
284 ** Determine if 8 or 16 port RTA
286 RtaType = GetUnitType(RtaUniq);
288 rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
290 Mod = RBYTE(PktCmdP->ModuleTypes);
292 if (RtaType == TYPE_RTA16) {
294 ** Only one ident is set for a 16 port RTA. To make compatible
295 ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
298 rio_dprintk(RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n", p->RIOModuleTypes[Mod1].Name);
301 rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
304 if (RtaUniq == 0xffffffff) {
305 ShowPacket(DBG_SPECIAL, PacketP);
309 ** try to unhook a command block from the command free list.
311 if (!(CmdBlkP = RIOGetCmdBlk())) {
312 rio_dprintk(RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
317 ** Fill in the default info on the command block
319 CmdBlkP->Packet.dest_unit = Rup;
320 CmdBlkP->Packet.dest_port = ROUTE_RUP;
321 CmdBlkP->Packet.src_unit = HOST_ID;
322 CmdBlkP->Packet.src_port = ROUTE_RUP;
323 CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
324 CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
325 PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
327 if (!RIOBootOk(p, HostP, RtaUniq)) {
328 rio_dprintk(RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n", RtaUniq);
329 PktReplyP->Command = ROUTE_FOAD;
330 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
331 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
336 ** Check to see if the RTA is configured for this host
338 for (ThisUnit = 0; ThisUnit < MAX_RUP; ThisUnit++) {
339 rio_dprintk(RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
340 ThisUnit, HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE ? "Slot-In-Use" : "Not In Use", HostP->Mapping[ThisUnit].Flags & SLOT_TENTATIVE ? "Slot-Tentative" : "Not Tentative", HostP->Mapping[ThisUnit].RtaUniqueNum);
343 ** We have an entry for it.
345 if ((HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq)) {
346 if (RtaType == TYPE_RTA16) {
347 ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
348 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n", RtaUniq, ThisUnit, ThisUnit2);
350 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n", RtaUniq, ThisUnit);
352 ** If we have no knowledge of booting it, then the host has
353 ** been re-booted, and so we must kill the RTA, so that it
354 ** will be booted again (potentially with new bins)
355 ** and it will then re-ask for an ID, which we will service.
357 if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
358 if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
359 if (!p->RIONoMessage)
360 cprintf("RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
361 HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
363 PktReplyP->Command = ROUTE_FOAD;
364 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
365 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
370 ** Send the ID (entry) to this RTA. The ID number is implicit as
371 ** the offset into the table. It is worth noting at this stage
372 ** that offset zero in the table contains the entries for the
375 PktReplyP->Command = ROUTE_ALLOCATE;
376 PktReplyP->IDNum = ThisUnit + 1;
377 if (RtaType == TYPE_RTA16) {
378 if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
380 ** Adjust the phb and tx pkt dest_units for 2nd block of 8
381 ** only if the RTA has ports associated (SLOT_IN_USE)
383 RIOFixPhbs(p, HostP, ThisUnit2);
384 PktReplyP->IDNum2 = ThisUnit2 + 1;
385 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
387 PktReplyP->IDNum2 = ROUTE_NO_ID;
388 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum);
390 HostP->Copy("RT_ALLOCAT", PktReplyP->CommandText, 10);
392 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
395 ** If this is a freshly booted RTA, then we need to re-open
396 ** the ports, if any where open, so that data may once more
397 ** flow around the system!
399 if ((HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) && (HostP->Mapping[ThisUnit].SysPort != NO_PORT)) {
401 ** look at the ports associated with this beast and
402 ** see if any where open. If they was, then re-open
403 ** them, using the info from the tty flags.
405 for (port = 0; port < PORTS_PER_RTA; port++) {
406 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort];
407 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
408 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
409 rio_spin_lock_irqsave(&PortP->portSem, flags);
410 PortP->MagicFlags |= MAGIC_REBOOT;
411 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
414 if (RtaType == TYPE_RTA16) {
415 for (port = 0; port < PORTS_PER_RTA; port++) {
416 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort];
417 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
418 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
419 rio_spin_lock_irqsave(&PortP->portSem, flags);
420 PortP->MagicFlags |= MAGIC_REBOOT;
421 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
428 ** keep a copy of the module types!
430 HostP->UnixRups[ThisUnit].ModTypes = Mod;
431 if (RtaType == TYPE_RTA16)
432 HostP->UnixRups[ThisUnit2].ModTypes = Mod;
435 ** If either of the modules on this unit is read-only or write-only
436 ** or none-xprint, then we need to transfer that info over to the
439 if (HostP->Mapping[ThisUnit].SysPort != NO_PORT) {
440 for (port = 0; port < PORTS_PER_MODULE; port++) {
441 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
442 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
443 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
444 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
446 if (RtaType == TYPE_RTA16) {
447 for (port = 0; port < PORTS_PER_MODULE; port++) {
448 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
449 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
450 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
451 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
457 ** Job done, get on with the interrupts!
463 ** There is no table entry for this RTA at all.
465 ** Lets check to see if we actually booted this unit - if not,
466 ** then we reset it and it will go round the loop of being booted
467 ** we can then worry about trying to fit it into the table.
469 for (ThisUnit = 0; ThisUnit < HostP->NumExtraBooted; ThisUnit++)
470 if (HostP->ExtraUnits[ThisUnit] == RtaUniq)
472 if (ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS) {
474 ** if the unit wasn't in the table, and the table wasn't full, then
475 ** we reset the unit, because we didn't boot it.
476 ** However, if the table is full, it could be that we did boot
477 ** this unit, and so we won't reboot it, because it isn't really
478 ** all that disasterous to keep the old bins in most cases. This
479 ** is a rather tacky feature, but we are on the edge of reallity
480 ** here, because the implication is that someone has connected
481 ** 16+MAX_EXTRA_UNITS onto one host.
483 static int UnknownMesgDone = 0;
485 if (!UnknownMesgDone) {
486 if (!p->RIONoMessage)
487 cprintf("One or more unknown RTAs are being updated.\n");
491 PktReplyP->Command = ROUTE_FOAD;
492 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
495 ** we did boot it (as an extra), and there may now be a table
496 ** slot free (because of a delete), so we will try to make
497 ** a tentative entry for it, so that the configurator can see it
498 ** and fill in the details for us.
500 if (RtaType == TYPE_RTA16) {
501 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
502 RIODefaultName(p, HostP, ThisUnit);
503 FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP);
506 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
507 RIODefaultName(p, HostP, ThisUnit);
508 FillSlot(ThisUnit, 0, RtaUniq, HostP);
511 PktReplyP->Command = ROUTE_USED;
512 HostP->Copy("RT_USED", PktReplyP->CommandText, 7);
514 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
519 void RIOFixPhbs(p, HostP, unit)
527 int PortN = HostP->Mapping[unit].SysPort;
529 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
532 ushort dest_unit = HostP->Mapping[unit].ID2;
535 ** Get the link number used for the 1st 8 phbs on this unit.
537 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
539 link = RWORD(PortP->PhbP->link);
541 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
542 ushort dest_port = port + 8;
549 PortP = p->RIOPortp[PortN];
551 rio_spin_lock_irqsave(&PortP->portSem, flags);
553 ** If RTA is not powered on, the tx packets will be
554 ** unset, so go no further.
556 if (PortP->TxStart == 0) {
557 rio_dprintk(RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
558 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
563 ** For the second slot of a 16 port RTA, the driver needs to
564 ** sort out the phb to port mappings. The dest_unit for this
565 ** group of 8 phbs is set to the dest_unit of the accompanying
566 ** 8 port block. The dest_port of the second unit is set to
567 ** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
568 ** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
569 ** (being the second map ID) will be sent to dest_unit 5, port
570 ** 14. When this RTA is deleted, dest_unit for ID 6 will be
571 ** restored, and the dest_port will be reduced by 8.
572 ** Transmit packets also have a destination field which needs
573 ** adjusting in the same manner.
574 ** Note that the unit/port bytes in 'dest' are swapped.
575 ** We also need to adjust the phb and rup link numbers for the
576 ** second block of 8 ttys.
578 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
580 ** *TxPktP is the pointer to the transmit packet on the host
581 ** card. This needs to be translated into a 32 bit pointer
582 ** so it can be accessed from the driver.
584 Pkt = (PKT *) RIO_PTR(HostP->Caddr, RINDW(TxPktP));
587 ** If the packet is used, reset it.
589 Pkt = (PKT *) ((uint) Pkt & ~PKT_IN_USE);
590 WBYTE(Pkt->dest_unit, dest_unit);
591 WBYTE(Pkt->dest_port, dest_port);
593 rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", RWORD(PortP->PhbP->destination) & 0xff, (RWORD(PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
594 WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8));
595 WWORD(PortP->PhbP->link, link);
597 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
600 ** Now make sure the range of ports to be serviced includes
601 ** the 2nd 8 on this 16 port RTA.
605 if (((unit * 8) + 7) > RWORD(HostP->LinkStrP[link].last_port)) {
606 rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
607 WWORD(HostP->LinkStrP[link].last_port, (unit * 8) + 7);
613 ** Check to see if the new disconnection has isolated this unit.
614 ** If it has, then invalidate all its link information, and tell
615 ** the world about it. This is done to ensure that the configurator
616 ** only gets up-to-date information about what is going on.
618 static int RIOCheckIsolated(p, HostP, UnitId)
624 rio_spin_lock_irqsave(&HostP->HostLock, flags);
630 if (RIOCheck(HostP, UnitId)) {
631 rio_dprintk(RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
632 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
636 RIOIsolate(p, HostP, UnitId);
638 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
643 ** Invalidate all the link interconnectivity of this unit, and of
644 ** all the units attached to it. This will mean that the entire
645 ** subnet will re-introduce itself.
647 static int RIOIsolate(p, HostP, UnitId)
658 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
660 if (UnitId >= MAX_RUP) /* dontcha just lurv unsigned maths! */
663 if (HostP->Mapping[UnitId].Flags & BEEN_HERE)
666 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
668 if (p->RIOPrintDisabled == DO_PRINT)
669 rio_dprintk(RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
671 for (link = 0; link < LINKS_PER_UNIT; link++) {
672 unit = HostP->Mapping[UnitId].Topology[link].Unit;
673 HostP->Mapping[UnitId].Topology[link].Unit = ROUTE_DISCONNECT;
674 HostP->Mapping[UnitId].Topology[link].Link = NO_LINK;
675 RIOIsolate(p, HostP, unit);
677 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
681 static int RIOCheck(HostP, UnitId)
691 /* rio_dprint(RIO_DEBUG_ROUTE, ("Check to see if unit %d has a route to the host\n",UnitId)); */
692 rio_dprintk(RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
694 if (UnitId == HOST_ID) {
695 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
701 if (UnitId >= MAX_RUP) {
702 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
706 for (link = 0; link < LINKS_PER_UNIT; link++) {
707 if (HostP->Mapping[UnitId].Topology[link].Unit == HOST_ID) {
708 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected directly to host via link (%c).\n",
709 UnitId, 'A'+link)); */
714 if (HostP->Mapping[UnitId].Flags & BEEN_HERE) {
715 /* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
719 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
721 for (link = 0; link < LINKS_PER_UNIT; link++) {
722 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d check link (%c)\n", UnitId,'A'+link)); */
723 if (RIOCheck(HostP, HostP->Mapping[UnitId].Topology[link].Unit)) {
724 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected to something that knows the host via link (%c)\n", UnitId,link+'A')); */
725 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
730 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
732 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
738 ** Returns the type of unit (host, 16/8 port RTA)
741 uint GetUnitType(Uniq)
744 switch ((Uniq >> 28) & 0xf) {
749 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Host\n");
752 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
755 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
758 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
766 if (p->RIOQuickCheck != NOT_CHANGED)
768 p->RIOQuickCheck = CHANGED;
769 if (p->RIOSignalProcess) {
770 rio_dprintk(RIO_DEBUG_ROUTE, "Send SIG-HUP");
772 psignal( RIOSignalProcess, SIGHUP );
778 static void RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change)
794 ** 15.10.1998 ARG - ESIL 0759
795 ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
797 ** What's this doing in here anyway ?
798 ** It was causing the port to be 'unmapped' if opened whilst RTA "disconnected"
800 ** 09.12.1998 ARG - ESIL 0776 - part fix
801 ** Okay, We've found out what this was all about now !
802 ** Someone had botched this to use RIOHalted to indicated the number of RTAs
803 ** 'disconnected'. The value in RIOHalted was then being used in the
804 ** 'RIO_QUICK_CHECK' ioctl. A none zero value indicating that a least one RTA
805 ** is 'disconnected'. The change was put in to satisfy a customer's needs.
806 ** Having taken this bit of code out 'RIO_QUICK_CHECK' now no longer works for
809 if (Change == CONNECT) {
810 if (p->RIOHalted) p->RIOHalted --;
816 ** So - we need to implement it slightly differently - a new member of the
817 ** rio_info struct - RIORtaDisCons (RIO RTA connections) keeps track of RTA
818 ** connections and disconnections.
820 if (Change == CONNECT) {
821 if (p->RIORtaDisCons)
827 if (p->RIOPrintDisabled == DONT_PRINT)
839 FromName = FromId ? HostP->Mapping[FromId - 1].Name : HostP->Name;
840 FromType = FromId ? "RTA" : "HOST";
841 ToName = ToId ? HostP->Mapping[ToId - 1].Name : HostP->Name;
842 ToType = ToId ? "RTA" : "HOST";
844 rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
845 cprintf("Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
849 ** RIORemoveFromSavedTable :
851 ** Delete and RTA entry from the saved table given to us
852 ** by the configuration program.
854 static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
859 ** We loop for all entries even after finding an entry and
860 ** zeroing it because we may have two entries to delete if
861 ** it's a 16 port RTA.
863 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
864 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
865 bzero((caddr_t) & p->RIOSavedTable[entry], sizeof(struct Map));
873 ** RIOCheckDisconnected :
875 ** Scan the unit links to and return zero if the unit is completely
878 static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
883 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
885 ** If the slot is tentative and does not belong to the
886 ** second half of a 16 port RTA then scan to see if
889 for (link = 0; link < LINKS_PER_UNIT; link++) {
890 if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
895 ** If not all links are disconnected then we can forget about it.
897 if (link < LINKS_PER_UNIT)
900 #ifdef NEED_TO_FIX_THIS
901 /* Ok so all the links are disconnected. But we may have only just
902 ** made this slot tentative and not yet received a topology update.
903 ** Lets check how long ago we made it tentative.
905 rio_dprintk(RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
906 if (drv_getparm(LBOLT, (ulong_t *) & current_time))
907 rio_dprintk(RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
909 elapse_time = current_time - TentTime[unit];
910 rio_dprintk(RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n", elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
911 if (drv_hztousec(elapse_time) < WAIT_TO_FINISH) {
912 rio_dprintk(RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n", unit, drv_hztousec(elapse_time));
918 ** We have found an usable slot.
919 ** If it is half of a 16 port RTA then delete the other half.
921 if (HostP->Mapping[unit].ID2 != 0) {
922 int nOther = (HostP->Mapping[unit].ID2) - 1;
924 rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
925 bzero((caddr_t) & HostP->Mapping[nOther], sizeof(struct Map));
927 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
936 ** This function scans the given host table for either one
937 ** or two free unit ID's.
939 int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pID2)
944 ** Initialise the ID's to MAX_RUP.
945 ** We do this to make the loop for setting the ID's as simple as
953 ** Scan all entries of the host mapping table for free slots.
954 ** We scan for free slots first and then if that is not successful
955 ** we start all over again looking for tentative slots we can re-use.
957 for (unit = 0; unit < MAX_RUP; unit++) {
958 rio_dprintk(RIO_DEBUG_ROUTE, "Scanning unit %d\n", unit);
960 ** If the flags are zero then the slot is empty.
962 if (HostP->Mapping[unit].Flags == 0) {
963 rio_dprintk(RIO_DEBUG_ROUTE, " This slot is empty.\n");
965 ** If we haven't allocated the first ID then do it now.
967 if (*pID1 == MAX_RUP) {
968 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
972 ** If the second ID is not needed then we can return
979 ** Allocate the second slot and return.
981 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
989 ** If we manage to come out of the free slot loop then we
990 ** need to start all over again looking for tentative slots
991 ** that we can re-use.
993 rio_dprintk(RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
994 for (unit = 0; unit < MAX_RUP; unit++) {
995 if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) || (HostP->Mapping[unit].Flags == 0)) && !(HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT)) {
996 rio_dprintk(RIO_DEBUG_ROUTE, " Slot %d looks promising.\n", unit);
999 rio_dprintk(RIO_DEBUG_ROUTE, " No it isn't, its the 1st half\n");
1004 ** Slot is Tentative or Empty, but not a tentative second
1005 ** slot of a 16 porter.
1006 ** Attempt to free up this slot (and its parnter if
1007 ** it is a 16 port slot. The second slot will become
1008 ** empty after a call to RIOFreeDisconnected so thats why
1009 ** we look for empty slots above as well).
1011 if (HostP->Mapping[unit].Flags != 0)
1012 if (RIOFreeDisconnected(p, HostP, unit) != 0)
1015 ** If we haven't allocated the first ID then do it now.
1017 if (*pID1 == MAX_RUP) {
1018 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
1022 ** Clear out this slot now that we intend to use it.
1024 bzero(&HostP->Mapping[unit], sizeof(struct Map));
1027 ** If the second ID is not needed then we can return
1034 ** Allocate the second slot and return.
1036 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative/empty entry for second unit %d\n", unit);
1040 ** Clear out this slot now that we intend to use it.
1042 bzero(&HostP->Mapping[unit], sizeof(struct Map));
1044 /* At this point under the right(wrong?) conditions
1045 ** we may have a first unit ID being higher than the
1046 ** second unit ID. This is a bad idea if we are about
1047 ** to fill the slots with a 16 port RTA.
1048 ** Better check and swap them over.
1051 if (*pID1 > *pID2) {
1052 rio_dprintk(RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
1063 ** If we manage to get to the end of the second loop then we
1064 ** can give up and return a failure.
1071 ** The link switch scenario.
1073 ** Rta Wun (A) is connected to Tuw (A).
1074 ** The tables are all up to date, and the system is OK.
1076 ** If Wun (A) is now moved to Wun (B) before Wun (A) can
1077 ** become disconnected, then the follow happens:
1079 ** Tuw (A) spots the change of unit:link at the other end
1080 ** of its link and Tuw sends a topology packet reflecting
1081 ** the change: Tuw (A) now disconnected from Wun (A), and
1082 ** this is closely followed by a packet indicating that
1083 ** Tuw (A) is now connected to Wun (B).
1085 ** Wun (B) will spot that it has now become connected, and
1086 ** Wun will send a topology packet, which indicates that
1087 ** both Wun (A) and Wun (B) is connected to Tuw (A).
1089 ** Eventually Wun (A) realises that it is now disconnected
1090 ** and Wun will send out a topology packet indicating that
1091 ** Wun (A) is now disconnected.