blob: 0f4cd33ba641764ae79e63e421f57fd87762a4f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
33static 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
86static int RIOCheckIsolated(struct rio_info *, struct Host *, uint);
87static int RIOIsolate(struct rio_info *, struct Host *, uint);
88static int RIOCheck(struct Host *, uint);
89static 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 Morton8d8706e2006-01-11 12:17:49 -080096int RIORouteRup(struct rio_info *p, uint Rup, struct Host *HostP, PKT * PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Andrew Morton8d8706e2006-01-11 12:17:49 -080098 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 Torvalds1da177e2005-04-16 15:20:36 -0700114
115#ifdef STACK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800116 RIOStackCheck("RIORouteRup");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif
118#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800119 CheckPacketP(PacketP);
120 CheckHostP(HostP);
121 CheckRup(Rup);
122 CheckHost(Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800125 ** Is this unit telling us it's current link topology?
126 */
127 if (RBYTE(PktCmdP->Command) == ROUTE_TOPOLOGY) {
128 MapP = HostP->Mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Andrew Morton8d8706e2006-01-11 12:17:49 -0800130 /*
131 ** The packet can be sent either by the host or by an RTA.
132 ** If it comes from the host, then we need to fill in the
133 ** Topology array in the host structure. If it came in
134 ** from an RTA then we need to fill in the Mapping structure's
135 ** Topology array for the unit.
136 */
137 if (Rup >= (ushort) MAX_RUP) {
138 ThisUnit = HOST_ID;
139 TopP = HostP->Topology;
140 MyType = "Host";
141 MyName = HostP->Name;
142 ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
143 } else {
144 ThisUnit = Rup + 1;
145 TopP = HostP->Mapping[Rup].Topology;
146 MyType = "RTA";
147 MyName = HostP->Mapping[Rup].Name;
148 ThisLinkMin = 0;
149 ThisLinkMax = LINKS_PER_UNIT - 1;
150 }
151
152 /*
153 ** Lies will not be tolerated.
154 ** If any pair of links claim to be connected to the same
155 ** place, then ignore this packet completely.
156 */
157 Lies = 0;
158 for (ThisLink = ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++) {
159 /*
160 ** it won't lie about network interconnect, total disconnects
161 ** and no-IDs. (or at least, it doesn't *matter* if it does)
162 */
163 if (RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) > (ushort) MAX_RUP)
164 continue;
165
166 for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
167 if ((RBYTE(PktCmdP->RouteTopology[ThisLink].Unit) == RBYTE(PktCmdP->RouteTopology[NewLink].Unit)) && (RBYTE(PktCmdP->RouteTopology[ThisLink].Link) == RBYTE(PktCmdP->RouteTopology[NewLink].Link))) {
168 Lies++;
169 }
170 }
171 }
172
173 if (Lies) {
174 rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
175 rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
176 RBYTE(PktCmdP->RouteTopology[0].Unit),
177 'A' + RBYTE(PktCmdP->RouteTopology[0].Link),
178 RBYTE(PktCmdP->RouteTopology[1].Unit),
179 'A' + RBYTE(PktCmdP->RouteTopology[1].Link), RBYTE(PktCmdP->RouteTopology[2].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[2].Link), RBYTE(PktCmdP->RouteTopology[3].Unit), 'A' + RBYTE(PktCmdP->RouteTopology[3].Link));
180 return TRUE;
181 }
182
183 /*
184 ** now, process each link.
185 */
186 for (ThisLink = ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++) {
187 /*
188 ** this is what it was connected to
189 */
190 OldUnit = TopP[ThisLink].Unit;
191 OldLink = TopP[ThisLink].Link;
192
193 /*
194 ** this is what it is now connected to
195 */
196 NewUnit = RBYTE(PktCmdP->RouteTopology[ThisLink].Unit);
197 NewLink = RBYTE(PktCmdP->RouteTopology[ThisLink].Link);
198
199 if (OldUnit != NewUnit || OldLink != NewLink) {
200 /*
201 ** something has changed!
202 */
203
204 if (NewUnit > MAX_RUP && NewUnit != ROUTE_DISCONNECT && NewUnit != ROUTE_NO_ID && NewUnit != ROUTE_INTERCONNECT) {
205 rio_dprintk(RIO_DEBUG_ROUTE, "I have a link from %s %s to unit %d:%d - I don't like it.\n", MyType, MyName, NewUnit, NewLink);
206 } else {
207 /*
208 ** put the new values in
209 */
210 TopP[ThisLink].Unit = NewUnit;
211 TopP[ThisLink].Link = NewLink;
212
213 RIOSetChange(p);
214
215 if (OldUnit <= MAX_RUP) {
216 /*
217 ** If something has become bust, then re-enable them messages
218 */
219 if (!p->RIONoMessage)
220 RIOConCon(p, HostP, ThisUnit, ThisLink, OldUnit, OldLink, DISCONNECT);
221 }
222
223 if ((NewUnit <= MAX_RUP) && !p->RIONoMessage)
224 RIOConCon(p, HostP, ThisUnit, ThisLink, NewUnit, NewLink, CONNECT);
225
226 if (NewUnit == ROUTE_NO_ID)
227 rio_dprintk(RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n", MyType, MyName, 'A' + ThisLink);
228
229 if (NewUnit == ROUTE_INTERCONNECT) {
230 if (!p->RIONoMessage)
231 cprintf("%s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
232 }
233
234 /*
235 ** perform an update for 'the other end', so that these messages
236 ** only appears once. Only disconnect the other end if it is pointing
237 ** at us!
238 */
239 if (OldUnit == HOST_ID) {
240 if (HostP->Topology[OldLink].Unit == ThisUnit && HostP->Topology[OldLink].Link == ThisLink) {
241 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink + 'A');
242 HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
243 HostP->Topology[OldLink].Link = NO_LINK;
244 } else {
245 rio_dprintk(RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n", OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
246 }
247 } else if (OldUnit <= MAX_RUP) {
248 if (HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit == ThisUnit && HostP->Mapping[OldUnit - 1].Topology[OldLink].Link == ThisLink) {
249 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A');
250 HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit = ROUTE_DISCONNECT;
251 HostP->Mapping[OldUnit - 1].Topology[OldLink].Link = NO_LINK;
252 } else {
253 rio_dprintk(RIO_DEBUG_ROUTE, "RTA %s (%c) WAS NOT CONNECTED TO %s (%c)\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
254 }
255 }
256 if (NewUnit == HOST_ID) {
257 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n", NewLink + 'A', MyName, ThisLink + 'A');
258 HostP->Topology[NewLink].Unit = ThisUnit;
259 HostP->Topology[NewLink].Link = ThisLink;
260 } else if (NewUnit <= MAX_RUP) {
261 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n", HostP->Mapping[NewUnit - 1].Name, NewLink + 'A', MyName, ThisLink + 'A');
262 HostP->Mapping[NewUnit - 1].Topology[NewLink].Unit = ThisUnit;
263 HostP->Mapping[NewUnit - 1].Topology[NewLink].Link = ThisLink;
264 }
265 }
266 RIOSetChange(p);
267 RIOCheckIsolated(p, HostP, OldUnit);
268 }
269 }
270 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Andrew Morton8d8706e2006-01-11 12:17:49 -0800273 /*
274 ** The only other command we recognise is a route_request command
275 */
276 if (RBYTE(PktCmdP->Command) != ROUTE_REQUEST) {
277 rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %d ROUTE_RUP\n", RBYTE(PktCmdP->Command), Rup, (int) HostP);
278 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Andrew Morton8d8706e2006-01-11 12:17:49 -0800281 RtaUniq = (RBYTE(PktCmdP->UniqNum[0])) + (RBYTE(PktCmdP->UniqNum[1]) << 8) + (RBYTE(PktCmdP->UniqNum[2]) << 16) + (RBYTE(PktCmdP->UniqNum[3]) << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 /*
284 ** Determine if 8 or 16 port RTA
285 */
286 RtaType = GetUnitType(RtaUniq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Andrew Morton8d8706e2006-01-11 12:17:49 -0800290 Mod = RBYTE(PktCmdP->ModuleTypes);
291 Mod1 = LONYBLE(Mod);
292 if (RtaType == TYPE_RTA16) {
293 /*
294 ** Only one ident is set for a 16 port RTA. To make compatible
295 ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
296 */
297 Mod2 = Mod1;
298 rio_dprintk(RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n", p->RIOModuleTypes[Mod1].Name);
299 } else {
300 Mod2 = HINYBLE(Mod);
301 rio_dprintk(RIO_DEBUG_ROUTE, "Module types are %s (ports 0-3) and %s (ports 4-7)\n", p->RIOModuleTypes[Mod1].Name, p->RIOModuleTypes[Mod2].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800303
304 if (RtaUniq == 0xffffffff) {
305 ShowPacket(DBG_SPECIAL, PacketP);
306 }
307
308 /*
309 ** try to unhook a command block from the command free list.
310 */
311 if (!(CmdBlkP = RIOGetCmdBlk())) {
312 rio_dprintk(RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
313 return 0;
314 }
315
316 /*
317 ** Fill in the default info on the command block
318 */
319 CmdBlkP->Packet.dest_unit = Rup;
320 CmdBlkP->Packet.dest_port = ROUTE_RUP;
321 CmdBlkP->Packet.src_unit = HOST_ID;
322 CmdBlkP->Packet.src_port = ROUTE_RUP;
323 CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
324 CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
325 PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
326
327 if (!RIOBootOk(p, HostP, RtaUniq)) {
328 rio_dprintk(RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n", RtaUniq);
329 PktReplyP->Command = ROUTE_FOAD;
330 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
331 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
332 return TRUE;
333 }
334
335 /*
336 ** Check to see if the RTA is configured for this host
337 */
338 for (ThisUnit = 0; ThisUnit < MAX_RUP; ThisUnit++) {
339 rio_dprintk(RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
340 ThisUnit, HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE ? "Slot-In-Use" : "Not In Use", HostP->Mapping[ThisUnit].Flags & SLOT_TENTATIVE ? "Slot-Tentative" : "Not Tentative", HostP->Mapping[ThisUnit].RtaUniqueNum);
341
342 /*
343 ** We have an entry for it.
344 */
345 if ((HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq)) {
346 if (RtaType == TYPE_RTA16) {
347 ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
348 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n", RtaUniq, ThisUnit, ThisUnit2);
349 } else
350 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n", RtaUniq, ThisUnit);
351 /*
352 ** If we have no knowledge of booting it, then the host has
353 ** been re-booted, and so we must kill the RTA, so that it
354 ** will be booted again (potentially with new bins)
355 ** and it will then re-ask for an ID, which we will service.
356 */
357 if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
358 if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
359 if (!p->RIONoMessage)
360 cprintf("RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
361 HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
362 }
363 PktReplyP->Command = ROUTE_FOAD;
364 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
365 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
366 return TRUE;
367 }
368
369 /*
370 ** Send the ID (entry) to this RTA. The ID number is implicit as
371 ** the offset into the table. It is worth noting at this stage
372 ** that offset zero in the table contains the entries for the
373 ** RTA with ID 1!!!!
374 */
375 PktReplyP->Command = ROUTE_ALLOCATE;
376 PktReplyP->IDNum = ThisUnit + 1;
377 if (RtaType == TYPE_RTA16) {
378 if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
379 /*
380 ** Adjust the phb and tx pkt dest_units for 2nd block of 8
381 ** only if the RTA has ports associated (SLOT_IN_USE)
382 */
383 RIOFixPhbs(p, HostP, ThisUnit2);
384 PktReplyP->IDNum2 = ThisUnit2 + 1;
385 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
386 } else {
387 PktReplyP->IDNum2 = ROUTE_NO_ID;
388 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum);
389 }
390 HostP->Copy("RT_ALLOCAT", PktReplyP->CommandText, 10);
391
392 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
393
394 /*
395 ** If this is a freshly booted RTA, then we need to re-open
396 ** the ports, if any where open, so that data may once more
397 ** flow around the system!
398 */
399 if ((HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) && (HostP->Mapping[ThisUnit].SysPort != NO_PORT)) {
400 /*
401 ** look at the ports associated with this beast and
402 ** see if any where open. If they was, then re-open
403 ** them, using the info from the tty flags.
404 */
405 for (port = 0; port < PORTS_PER_RTA; port++) {
406 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort];
407 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
408 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
409 rio_spin_lock_irqsave(&PortP->portSem, flags);
410 PortP->MagicFlags |= MAGIC_REBOOT;
411 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
412 }
413 }
414 if (RtaType == TYPE_RTA16) {
415 for (port = 0; port < PORTS_PER_RTA; port++) {
416 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort];
417 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
418 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
419 rio_spin_lock_irqsave(&PortP->portSem, flags);
420 PortP->MagicFlags |= MAGIC_REBOOT;
421 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
422 }
423 }
424 }
425 }
426
427 /*
428 ** keep a copy of the module types!
429 */
430 HostP->UnixRups[ThisUnit].ModTypes = Mod;
431 if (RtaType == TYPE_RTA16)
432 HostP->UnixRups[ThisUnit2].ModTypes = Mod;
433
434 /*
435 ** If either of the modules on this unit is read-only or write-only
436 ** or none-xprint, then we need to transfer that info over to the
437 ** relevant ports.
438 */
439 if (HostP->Mapping[ThisUnit].SysPort != NO_PORT) {
440 for (port = 0; port < PORTS_PER_MODULE; port++) {
441 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
442 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
443 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
444 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
445 }
446 if (RtaType == TYPE_RTA16) {
447 for (port = 0; port < PORTS_PER_MODULE; port++) {
448 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
449 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
450 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
451 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
452 }
453 }
454 }
455
456 /*
457 ** Job done, get on with the interrupts!
458 */
459 return TRUE;
460 }
461 }
462 /*
463 ** There is no table entry for this RTA at all.
464 **
465 ** Lets check to see if we actually booted this unit - if not,
466 ** then we reset it and it will go round the loop of being booted
467 ** we can then worry about trying to fit it into the table.
468 */
469 for (ThisUnit = 0; ThisUnit < HostP->NumExtraBooted; ThisUnit++)
470 if (HostP->ExtraUnits[ThisUnit] == RtaUniq)
471 break;
472 if (ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS) {
473 /*
474 ** if the unit wasn't in the table, and the table wasn't full, then
475 ** we reset the unit, because we didn't boot it.
476 ** However, if the table is full, it could be that we did boot
477 ** this unit, and so we won't reboot it, because it isn't really
478 ** all that disasterous to keep the old bins in most cases. This
479 ** is a rather tacky feature, but we are on the edge of reallity
480 ** here, because the implication is that someone has connected
481 ** 16+MAX_EXTRA_UNITS onto one host.
482 */
483 static int UnknownMesgDone = 0;
484
485 if (!UnknownMesgDone) {
486 if (!p->RIONoMessage)
487 cprintf("One or more unknown RTAs are being updated.\n");
488 UnknownMesgDone = 1;
489 }
490
491 PktReplyP->Command = ROUTE_FOAD;
492 HostP->Copy("RT_FOAD", PktReplyP->CommandText, 7);
493 } else {
494 /*
495 ** we did boot it (as an extra), and there may now be a table
496 ** slot free (because of a delete), so we will try to make
497 ** a tentative entry for it, so that the configurator can see it
498 ** and fill in the details for us.
499 */
500 if (RtaType == TYPE_RTA16) {
501 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
502 RIODefaultName(p, HostP, ThisUnit);
503 FillSlot(ThisUnit, ThisUnit2, RtaUniq, HostP);
504 }
505 } else {
506 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
507 RIODefaultName(p, HostP, ThisUnit);
508 FillSlot(ThisUnit, 0, RtaUniq, HostP);
509 }
510 }
511 PktReplyP->Command = ROUTE_USED;
512 HostP->Copy("RT_USED", PktReplyP->CommandText, 7);
513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
515 return TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516}
517
518
Andrew Morton8d8706e2006-01-11 12:17:49 -0800519void RIOFixPhbs(p, HostP, unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520struct rio_info *p;
521struct Host *HostP;
522uint unit;
523{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 ushort link, port;
525 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 unsigned long flags;
527 int PortN = HostP->Mapping[unit].SysPort;
528
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 if (PortN != -1) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800532 ushort dest_unit = HostP->Mapping[unit].ID2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800535 ** Get the link number used for the 1st 8 phbs on this unit.
536 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
538
539 link = RWORD(PortP->PhbP->link);
540
541 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800542 ushort dest_port = port + 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#if 0
Andrew Morton8d8706e2006-01-11 12:17:49 -0800544 uint PktInt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546 WORD *TxPktP;
547 PKT *Pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 PortP = p->RIOPortp[PortN];
550
551 rio_spin_lock_irqsave(&PortP->portSem, flags);
552 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800553 ** If RTA is not powered on, the tx packets will be
554 ** unset, so go no further.
555 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (PortP->TxStart == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800557 rio_dprintk(RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
558 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
559 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
562 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563 ** For the second slot of a 16 port RTA, the driver needs to
564 ** sort out the phb to port mappings. The dest_unit for this
565 ** group of 8 phbs is set to the dest_unit of the accompanying
566 ** 8 port block. The dest_port of the second unit is set to
567 ** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
568 ** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
569 ** (being the second map ID) will be sent to dest_unit 5, port
570 ** 14. When this RTA is deleted, dest_unit for ID 6 will be
571 ** restored, and the dest_port will be reduced by 8.
572 ** Transmit packets also have a destination field which needs
573 ** adjusting in the same manner.
574 ** Note that the unit/port bytes in 'dest' are swapped.
575 ** We also need to adjust the phb and rup link numbers for the
576 ** second block of 8 ttys.
577 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
579 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580 ** *TxPktP is the pointer to the transmit packet on the host
581 ** card. This needs to be translated into a 32 bit pointer
582 ** so it can be accessed from the driver.
583 */
584 Pkt = (PKT *) RIO_PTR(HostP->Caddr, RINDW(TxPktP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800587 ** If the packet is used, reset it.
588 */
589 Pkt = (PKT *) ((uint) Pkt & ~PKT_IN_USE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 WBYTE(Pkt->dest_unit, dest_unit);
591 WBYTE(Pkt->dest_port, dest_port);
592 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800593 rio_dprintk(RIO_DEBUG_ROUTE, "phb dest: Old %x:%x New %x:%x\n", RWORD(PortP->PhbP->destination) & 0xff, (RWORD(PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8));
595 WWORD(PortP->PhbP->link, link);
596
597 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
598 }
599 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800600 ** Now make sure the range of ports to be serviced includes
601 ** the 2nd 8 on this 16 port RTA.
602 */
603 if (link > 3)
604 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (((unit * 8) + 7) > RWORD(HostP->LinkStrP[link].last_port)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800606 rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 WWORD(HostP->LinkStrP[link].last_port, (unit * 8) + 7);
608 }
609 }
610}
611
612/*
613** Check to see if the new disconnection has isolated this unit.
614** If it has, then invalidate all its link information, and tell
615** the world about it. This is done to ensure that the configurator
616** only gets up-to-date information about what is going on.
617*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800618static int RIOCheckIsolated(p, HostP, UnitId)
619struct rio_info *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620struct Host *HostP;
621uint UnitId;
622{
623 unsigned long flags;
624 rio_spin_lock_irqsave(&HostP->HostLock, flags);
625
626#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 CheckHostP(HostP);
628 CheckUnitId(UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -0800630 if (RIOCheck(HostP, UnitId)) {
631 rio_dprintk(RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635
Andrew Morton8d8706e2006-01-11 12:17:49 -0800636 RIOIsolate(p, HostP, UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 RIOSetChange(p);
638 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
639 return 1;
640}
641
642/*
643** Invalidate all the link interconnectivity of this unit, and of
644** all the units attached to it. This will mean that the entire
645** subnet will re-introduce itself.
646*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800647static int RIOIsolate(p, HostP, UnitId)
648struct rio_info *p;
649struct Host *HostP;
650uint UnitId;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
652 uint link, unit;
653
654#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800655 CheckHostP(HostP);
656 CheckUnitId(UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#endif
658 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
659
Andrew Morton8d8706e2006-01-11 12:17:49 -0800660 if (UnitId >= MAX_RUP) /* dontcha just lurv unsigned maths! */
661 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 if (HostP->Mapping[UnitId].Flags & BEEN_HERE)
664 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
667
Andrew Morton8d8706e2006-01-11 12:17:49 -0800668 if (p->RIOPrintDisabled == DO_PRINT)
669 rio_dprintk(RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Andrew Morton8d8706e2006-01-11 12:17:49 -0800671 for (link = 0; link < LINKS_PER_UNIT; link++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 unit = HostP->Mapping[UnitId].Topology[link].Unit;
673 HostP->Mapping[UnitId].Topology[link].Unit = ROUTE_DISCONNECT;
674 HostP->Mapping[UnitId].Topology[link].Link = NO_LINK;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800675 RIOIsolate(p, HostP, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 }
677 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
678 return 1;
679}
680
Andrew Morton8d8706e2006-01-11 12:17:49 -0800681static int RIOCheck(HostP, UnitId)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682struct Host *HostP;
683uint UnitId;
684{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800685 unsigned char link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687#ifdef CHECK
Andrew Morton8d8706e2006-01-11 12:17:49 -0800688 CheckHostP(HostP);
689 CheckUnitId(UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690#endif
691/* rio_dprint(RIO_DEBUG_ROUTE, ("Check to see if unit %d has a route to the host\n",UnitId)); */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800692 rio_dprintk(RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Andrew Morton8d8706e2006-01-11 12:17:49 -0800694 if (UnitId == HOST_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
696 return 1;
697 }
698
699 UnitId--;
700
Andrew Morton8d8706e2006-01-11 12:17:49 -0800701 if (UnitId >= MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
703 return 0;
704 }
705
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 for (link = 0; link < LINKS_PER_UNIT; link++) {
707 if (HostP->Mapping[UnitId].Topology[link].Unit == HOST_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected directly to host via link (%c).\n",
Andrew Morton8d8706e2006-01-11 12:17:49 -0800709 UnitId, 'A'+link)); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return 1;
711 }
712 }
713
Andrew Morton8d8706e2006-01-11 12:17:49 -0800714 if (HostP->Mapping[UnitId].Flags & BEEN_HERE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 /* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
716 return 0;
717 }
718
719 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
720
Andrew Morton8d8706e2006-01-11 12:17:49 -0800721 for (link = 0; link < LINKS_PER_UNIT; link++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d check link (%c)\n", UnitId,'A'+link)); */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 if (RIOCheck(HostP, HostP->Mapping[UnitId].Topology[link].Unit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected to something that knows the host via link (%c)\n", UnitId,link+'A')); */
725 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
726 return 1;
727 }
728 }
729
730 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
731
732 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return 0;
735}
736
737/*
738** Returns the type of unit (host, 16/8 port RTA)
739*/
740
Andrew Morton8d8706e2006-01-11 12:17:49 -0800741uint GetUnitType(Uniq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742uint Uniq;
743{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800744 switch ((Uniq >> 28) & 0xf) {
745 case RIO_AT:
746 case RIO_MCA:
747 case RIO_EISA:
748 case RIO_PCI:
749 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Host\n");
750 return (TYPE_HOST);
751 case RIO_RTA_16:
752 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
753 return (TYPE_RTA16);
754 case RIO_RTA:
755 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
756 return (TYPE_RTA8);
757 default:
758 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
759 return (99);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761}
762
Andrew Morton8d8706e2006-01-11 12:17:49 -0800763int RIOSetChange(p)
764struct rio_info *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800766 if (p->RIOQuickCheck != NOT_CHANGED)
767 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 p->RIOQuickCheck = CHANGED;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800769 if (p->RIOSignalProcess) {
770 rio_dprintk(RIO_DEBUG_ROUTE, "Send SIG-HUP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800772 psignal( RIOSignalProcess, SIGHUP );
773 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
777
Andrew Morton8d8706e2006-01-11 12:17:49 -0800778static void RIOConCon(p, HostP, FromId, FromLink, ToId, ToLink, Change)
779struct rio_info *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780struct Host *HostP;
781uint FromId;
782uint FromLink;
783uint ToId;
784uint ToLink;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800785int Change;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 char *FromName;
788 char *FromType;
789 char *ToName;
790 char *ToType;
791 unsigned int tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793/*
794** 15.10.1998 ARG - ESIL 0759
795** (Part) fix for port being trashed when opened whilst RTA "disconnected"
796**
797** What's this doing in here anyway ?
798** It was causing the port to be 'unmapped' if opened whilst RTA "disconnected"
799**
800** 09.12.1998 ARG - ESIL 0776 - part fix
801** Okay, We've found out what this was all about now !
802** Someone had botched this to use RIOHalted to indicated the number of RTAs
803** 'disconnected'. The value in RIOHalted was then being used in the
804** 'RIO_QUICK_CHECK' ioctl. A none zero value indicating that a least one RTA
805** is 'disconnected'. The change was put in to satisfy a customer's needs.
806** Having taken this bit of code out 'RIO_QUICK_CHECK' now no longer works for
807** the customer.
808**
809 if (Change == CONNECT) {
810 if (p->RIOHalted) p->RIOHalted --;
811 }
812 else {
813 p->RIOHalted ++;
814 }
815**
816** So - we need to implement it slightly differently - a new member of the
817** rio_info struct - RIORtaDisCons (RIO RTA connections) keeps track of RTA
818** connections and disconnections.
819*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800820 if (Change == CONNECT) {
821 if (p->RIORtaDisCons)
822 p->RIORtaDisCons--;
823 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 p->RIORtaDisCons++;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
Andrew Morton8d8706e2006-01-11 12:17:49 -0800827 if (p->RIOPrintDisabled == DONT_PRINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 return;
829
Andrew Morton8d8706e2006-01-11 12:17:49 -0800830 if (FromId > ToId) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 tp = FromId;
832 FromId = ToId;
833 ToId = tp;
834 tp = FromLink;
835 FromLink = ToLink;
836 ToLink = tp;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 FromName = FromId ? HostP->Mapping[FromId - 1].Name : HostP->Name;
840 FromType = FromId ? "RTA" : "HOST";
841 ToName = ToId ? HostP->Mapping[ToId - 1].Name : HostP->Name;
842 ToType = ToId ? "RTA" : "HOST";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 rio_dprintk(RIO_DEBUG_ROUTE, "Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
845 cprintf("Link between %s '%s' (%c) and %s '%s' (%c) %s.\n", FromType, FromName, 'A' + FromLink, ToType, ToName, 'A' + ToLink, (Change == CONNECT) ? "established" : "disconnected");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
848/*
849** RIORemoveFromSavedTable :
850**
851** Delete and RTA entry from the saved table given to us
852** by the configuration program.
853*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856 int entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Andrew Morton8d8706e2006-01-11 12:17:49 -0800858 /*
859 ** We loop for all entries even after finding an entry and
860 ** zeroing it because we may have two entries to delete if
861 ** it's a 16 port RTA.
862 */
863 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
864 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
865 bzero((caddr_t) & p->RIOSavedTable[entry], sizeof(struct Map));
866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800868 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
870
871
872/*
873** RIOCheckDisconnected :
874**
875** Scan the unit links to and return zero if the unit is completely
876** disconnected.
877*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800878static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800880 int link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882
Andrew Morton8d8706e2006-01-11 12:17:49 -0800883 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
884 /*
885 ** If the slot is tentative and does not belong to the
886 ** second half of a 16 port RTA then scan to see if
887 ** is disconnected.
888 */
889 for (link = 0; link < LINKS_PER_UNIT; link++) {
890 if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
891 break;
892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Andrew Morton8d8706e2006-01-11 12:17:49 -0800894 /*
895 ** If not all links are disconnected then we can forget about it.
896 */
897 if (link < LINKS_PER_UNIT)
898 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Olaf Hering44456d32005-07-27 11:45:17 -0700900#ifdef NEED_TO_FIX_THIS
Andrew Morton8d8706e2006-01-11 12:17:49 -0800901 /* Ok so all the links are disconnected. But we may have only just
902 ** made this slot tentative and not yet received a topology update.
903 ** Lets check how long ago we made it tentative.
904 */
905 rio_dprintk(RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
906 if (drv_getparm(LBOLT, (ulong_t *) & current_time))
907 rio_dprintk(RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Andrew Morton8d8706e2006-01-11 12:17:49 -0800909 elapse_time = current_time - TentTime[unit];
910 rio_dprintk(RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n", elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
911 if (drv_hztousec(elapse_time) < WAIT_TO_FINISH) {
912 rio_dprintk(RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n", unit, drv_hztousec(elapse_time));
913 return 1;
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915#endif
916
Andrew Morton8d8706e2006-01-11 12:17:49 -0800917 /*
918 ** We have found an usable slot.
919 ** If it is half of a 16 port RTA then delete the other half.
920 */
921 if (HostP->Mapping[unit].ID2 != 0) {
922 int nOther = (HostP->Mapping[unit].ID2) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Andrew Morton8d8706e2006-01-11 12:17:49 -0800924 rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
925 bzero((caddr_t) & HostP->Mapping[nOther], sizeof(struct Map));
926 }
927 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andrew Morton8d8706e2006-01-11 12:17:49 -0800929 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931
932
933/*
934** RIOFindFreeID :
935**
936** This function scans the given host table for either one
937** or two free unit ID's.
938*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800939int RIOFindFreeID(struct rio_info *p, struct Host *HostP, uint * pID1, uint * pID2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800941 int unit, tempID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800944 ** Initialise the ID's to MAX_RUP.
945 ** We do this to make the loop for setting the ID's as simple as
946 ** possible.
947 */
948 *pID1 = MAX_RUP;
949 if (pID2 != NULL)
950 *pID2 = MAX_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Andrew Morton8d8706e2006-01-11 12:17:49 -0800952 /*
953 ** Scan all entries of the host mapping table for free slots.
954 ** We scan for free slots first and then if that is not successful
955 ** we start all over again looking for tentative slots we can re-use.
956 */
957 for (unit = 0; unit < MAX_RUP; unit++) {
958 rio_dprintk(RIO_DEBUG_ROUTE, "Scanning unit %d\n", unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800960 ** If the flags are zero then the slot is empty.
961 */
962 if (HostP->Mapping[unit].Flags == 0) {
963 rio_dprintk(RIO_DEBUG_ROUTE, " This slot is empty.\n");
964 /*
965 ** If we haven't allocated the first ID then do it now.
966 */
967 if (*pID1 == MAX_RUP) {
968 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
969 *pID1 = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
Andrew Morton8d8706e2006-01-11 12:17:49 -0800971 /*
972 ** If the second ID is not needed then we can return
973 ** now.
974 */
975 if (pID2 == NULL)
976 return 0;
977 } else {
978 /*
979 ** Allocate the second slot and return.
980 */
981 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
982 *pID2 = unit;
983 return 0;
984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Andrew Morton8d8706e2006-01-11 12:17:49 -0800988 /*
989 ** If we manage to come out of the free slot loop then we
990 ** need to start all over again looking for tentative slots
991 ** that we can re-use.
992 */
993 rio_dprintk(RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
994 for (unit = 0; unit < MAX_RUP; unit++) {
995 if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) || (HostP->Mapping[unit].Flags == 0)) && !(HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT)) {
996 rio_dprintk(RIO_DEBUG_ROUTE, " Slot %d looks promising.\n", unit);
997
998 if (unit == *pID1) {
999 rio_dprintk(RIO_DEBUG_ROUTE, " No it isn't, its the 1st half\n");
1000 continue;
1001 }
1002
1003 /*
1004 ** Slot is Tentative or Empty, but not a tentative second
1005 ** slot of a 16 porter.
1006 ** Attempt to free up this slot (and its parnter if
1007 ** it is a 16 port slot. The second slot will become
1008 ** empty after a call to RIOFreeDisconnected so thats why
1009 ** we look for empty slots above as well).
1010 */
1011 if (HostP->Mapping[unit].Flags != 0)
1012 if (RIOFreeDisconnected(p, HostP, unit) != 0)
1013 continue;
1014 /*
1015 ** If we haven't allocated the first ID then do it now.
1016 */
1017 if (*pID1 == MAX_RUP) {
1018 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
1019 *pID1 = unit;
1020
1021 /*
1022 ** Clear out this slot now that we intend to use it.
1023 */
1024 bzero(&HostP->Mapping[unit], sizeof(struct Map));
1025
1026 /*
1027 ** If the second ID is not needed then we can return
1028 ** now.
1029 */
1030 if (pID2 == NULL)
1031 return 0;
1032 } else {
1033 /*
1034 ** Allocate the second slot and return.
1035 */
1036 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative/empty entry for second unit %d\n", unit);
1037 *pID2 = unit;
1038
1039 /*
1040 ** Clear out this slot now that we intend to use it.
1041 */
1042 bzero(&HostP->Mapping[unit], sizeof(struct Map));
1043
1044 /* At this point under the right(wrong?) conditions
1045 ** we may have a first unit ID being higher than the
1046 ** second unit ID. This is a bad idea if we are about
1047 ** to fill the slots with a 16 port RTA.
1048 ** Better check and swap them over.
1049 */
1050
1051 if (*pID1 > *pID2) {
1052 rio_dprintk(RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
1053 tempID = *pID1;
1054 *pID1 = *pID2;
1055 *pID2 = tempID;
1056 }
1057 return 0;
1058 }
1059 }
1060 }
1061
1062 /*
1063 ** If we manage to get to the end of the second loop then we
1064 ** can give up and return a failure.
1065 */
1066 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067}
1068
1069
1070/*
1071** The link switch scenario.
1072**
1073** Rta Wun (A) is connected to Tuw (A).
1074** The tables are all up to date, and the system is OK.
1075**
1076** If Wun (A) is now moved to Wun (B) before Wun (A) can
1077** become disconnected, then the follow happens:
1078**
1079** Tuw (A) spots the change of unit:link at the other end
1080** of its link and Tuw sends a topology packet reflecting
1081** the change: Tuw (A) now disconnected from Wun (A), and
1082** this is closely followed by a packet indicating that
1083** Tuw (A) is now connected to Wun (B).
1084**
1085** Wun (B) will spot that it has now become connected, and
1086** Wun will send a topology packet, which indicates that
1087** both Wun (A) and Wun (B) is connected to Tuw (A).
1088**
1089** Eventually Wun (A) realises that it is now disconnected
1090** and Wun will send out a topology packet indicating that
1091** Wun (A) is now disconnected.
1092*/