ia64/linux-2.6.18-xen.hg

annotate drivers/char/rio/rioroute.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

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