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