blob: 7a9df7dcf9a88d54677d798d04b34972624f0864 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/uaccess.h>
43
44#include <linux/termios.h>
45#include <linux/serial.h>
46
47#include <linux/generic_serial.h>
48
49
50#include "linux_compat.h"
51#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "pkt.h"
53#include "daemon.h"
54#include "rio.h"
55#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include "cmdpkt.h"
57#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "rup.h"
59#include "port.h"
60#include "riodrvr.h"
61#include "rioinfo.h"
62#include "func.h"
63#include "errors.h"
64#include "pci.h"
65
66#include "parmmap.h"
67#include "unixrup.h"
68#include "board.h"
69#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#include "phb.h"
71#include "link.h"
72#include "cmdblk.h"
73#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include "cirrus.h"
75#include "rioioctl.h"
76#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Alan Cox554b7c82006-03-24 03:18:32 -080078static int RIOCheckIsolated(struct rio_info *, struct Host *, unsigned int);
79static int RIOIsolate(struct rio_info *, struct Host *, unsigned int);
80static int RIOCheck(struct Host *, unsigned int);
81static void RIOConCon(struct rio_info *, struct Host *, unsigned int, unsigned int, unsigned int, unsigned int, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83
84/*
85** Incoming on the ROUTE_RUP
86** I wrote this while I was tired. Forgive me.
87*/
Al Virod886cb52006-05-27 00:08:25 -040088int RIORouteRup(struct rio_info *p, unsigned int Rup, struct Host *HostP, struct PKT __iomem * PacketP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Al Virod886cb52006-05-27 00:08:25 -040090 struct PktCmd __iomem *PktCmdP = (struct PktCmd __iomem *) PacketP->data;
Andrew Morton8d8706e2006-01-11 12:17:49 -080091 struct PktCmd_M *PktReplyP;
92 struct CmdBlk *CmdBlkP;
93 struct Port *PortP;
94 struct Map *MapP;
95 struct Top *TopP;
96 int ThisLink, ThisLinkMin, ThisLinkMax;
97 int port;
98 int Mod, Mod1, Mod2;
Alan Cox554b7c82006-03-24 03:18:32 -080099 unsigned short RtaType;
100 unsigned int RtaUniq;
101 unsigned int ThisUnit, ThisUnit2; /* 2 ids to accommodate 16 port RTA */
102 unsigned int OldUnit, NewUnit, OldLink, NewLink;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800103 char *MyType, *MyName;
104 int Lies;
105 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800108 ** Is this unit telling us it's current link topology?
109 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800110 if (readb(&PktCmdP->Command) == ROUTE_TOPOLOGY) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800111 MapP = HostP->Mapping;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Andrew Morton8d8706e2006-01-11 12:17:49 -0800113 /*
114 ** The packet can be sent either by the host or by an RTA.
115 ** If it comes from the host, then we need to fill in the
116 ** Topology array in the host structure. If it came in
117 ** from an RTA then we need to fill in the Mapping structure's
118 ** Topology array for the unit.
119 */
Alan Cox554b7c82006-03-24 03:18:32 -0800120 if (Rup >= (unsigned short) MAX_RUP) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800121 ThisUnit = HOST_ID;
122 TopP = HostP->Topology;
123 MyType = "Host";
124 MyName = HostP->Name;
125 ThisLinkMin = ThisLinkMax = Rup - MAX_RUP;
126 } else {
127 ThisUnit = Rup + 1;
128 TopP = HostP->Mapping[Rup].Topology;
129 MyType = "RTA";
130 MyName = HostP->Mapping[Rup].Name;
131 ThisLinkMin = 0;
132 ThisLinkMax = LINKS_PER_UNIT - 1;
133 }
134
135 /*
136 ** Lies will not be tolerated.
137 ** If any pair of links claim to be connected to the same
138 ** place, then ignore this packet completely.
139 */
140 Lies = 0;
141 for (ThisLink = ThisLinkMin + 1; ThisLink <= ThisLinkMax; ThisLink++) {
142 /*
143 ** it won't lie about network interconnect, total disconnects
144 ** and no-IDs. (or at least, it doesn't *matter* if it does)
145 */
Alan Cox554b7c82006-03-24 03:18:32 -0800146 if (readb(&PktCmdP->RouteTopology[ThisLink].Unit) > (unsigned short) MAX_RUP)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800147 continue;
148
149 for (NewLink = ThisLinkMin; NewLink < ThisLink; NewLink++) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800150 if ((readb(&PktCmdP->RouteTopology[ThisLink].Unit) == readb(&PktCmdP->RouteTopology[NewLink].Unit)) && (readb(&PktCmdP->RouteTopology[ThisLink].Link) == readb(&PktCmdP->RouteTopology[NewLink].Link))) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800151 Lies++;
152 }
153 }
154 }
155
156 if (Lies) {
157 rio_dprintk(RIO_DEBUG_ROUTE, "LIES! DAMN LIES! %d LIES!\n", Lies);
158 rio_dprintk(RIO_DEBUG_ROUTE, "%d:%c %d:%c %d:%c %d:%c\n",
Alan Coxe2b3afd2006-03-24 03:18:27 -0800159 readb(&PktCmdP->RouteTopology[0].Unit),
160 'A' + readb(&PktCmdP->RouteTopology[0].Link),
161 readb(&PktCmdP->RouteTopology[1].Unit),
162 '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));
Alan Cox554b7c82006-03-24 03:18:32 -0800163 return 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164 }
165
166 /*
167 ** now, process each link.
168 */
169 for (ThisLink = ThisLinkMin; ThisLink <= ThisLinkMax; ThisLink++) {
170 /*
171 ** this is what it was connected to
172 */
173 OldUnit = TopP[ThisLink].Unit;
174 OldLink = TopP[ThisLink].Link;
175
176 /*
177 ** this is what it is now connected to
178 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800179 NewUnit = readb(&PktCmdP->RouteTopology[ThisLink].Unit);
180 NewLink = readb(&PktCmdP->RouteTopology[ThisLink].Link);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800181
182 if (OldUnit != NewUnit || OldLink != NewLink) {
183 /*
184 ** something has changed!
185 */
186
187 if (NewUnit > MAX_RUP && NewUnit != ROUTE_DISCONNECT && NewUnit != ROUTE_NO_ID && NewUnit != ROUTE_INTERCONNECT) {
188 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);
189 } else {
190 /*
191 ** put the new values in
192 */
193 TopP[ThisLink].Unit = NewUnit;
194 TopP[ThisLink].Link = NewLink;
195
196 RIOSetChange(p);
197
198 if (OldUnit <= MAX_RUP) {
199 /*
200 ** If something has become bust, then re-enable them messages
201 */
202 if (!p->RIONoMessage)
203 RIOConCon(p, HostP, ThisUnit, ThisLink, OldUnit, OldLink, DISCONNECT);
204 }
205
206 if ((NewUnit <= MAX_RUP) && !p->RIONoMessage)
207 RIOConCon(p, HostP, ThisUnit, ThisLink, NewUnit, NewLink, CONNECT);
208
209 if (NewUnit == ROUTE_NO_ID)
210 rio_dprintk(RIO_DEBUG_ROUTE, "%s %s (%c) is connected to an unconfigured unit.\n", MyType, MyName, 'A' + ThisLink);
211
212 if (NewUnit == ROUTE_INTERCONNECT) {
213 if (!p->RIONoMessage)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800214 printk(KERN_DEBUG "rio: %s '%s' (%c) is connected to another network.\n", MyType, MyName, 'A' + ThisLink);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800215 }
216
217 /*
218 ** perform an update for 'the other end', so that these messages
219 ** only appears once. Only disconnect the other end if it is pointing
220 ** at us!
221 */
222 if (OldUnit == HOST_ID) {
223 if (HostP->Topology[OldLink].Unit == ThisUnit && HostP->Topology[OldLink].Link == ThisLink) {
224 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING HOST (%c) TO DISCONNECTED!\n", OldLink + 'A');
225 HostP->Topology[OldLink].Unit = ROUTE_DISCONNECT;
226 HostP->Topology[OldLink].Link = NO_LINK;
227 } else {
228 rio_dprintk(RIO_DEBUG_ROUTE, "HOST(%c) WAS NOT CONNECTED TO %s (%c)!\n", OldLink + 'A', HostP->Mapping[ThisUnit - 1].Name, ThisLink + 'A');
229 }
230 } else if (OldUnit <= MAX_RUP) {
231 if (HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit == ThisUnit && HostP->Mapping[OldUnit - 1].Topology[OldLink].Link == ThisLink) {
232 rio_dprintk(RIO_DEBUG_ROUTE, "SETTING RTA %s (%c) TO DISCONNECTED!\n", HostP->Mapping[OldUnit - 1].Name, OldLink + 'A');
233 HostP->Mapping[OldUnit - 1].Topology[OldLink].Unit = ROUTE_DISCONNECT;
234 HostP->Mapping[OldUnit - 1].Topology[OldLink].Link = NO_LINK;
235 } else {
236 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');
237 }
238 }
239 if (NewUnit == HOST_ID) {
240 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING HOST (%c) CONNECTED TO %s (%c)\n", NewLink + 'A', MyName, ThisLink + 'A');
241 HostP->Topology[NewLink].Unit = ThisUnit;
242 HostP->Topology[NewLink].Link = ThisLink;
243 } else if (NewUnit <= MAX_RUP) {
244 rio_dprintk(RIO_DEBUG_ROUTE, "MARKING RTA %s (%c) CONNECTED TO %s (%c)\n", HostP->Mapping[NewUnit - 1].Name, NewLink + 'A', MyName, ThisLink + 'A');
245 HostP->Mapping[NewUnit - 1].Topology[NewLink].Unit = ThisUnit;
246 HostP->Mapping[NewUnit - 1].Topology[NewLink].Link = ThisLink;
247 }
248 }
249 RIOSetChange(p);
250 RIOCheckIsolated(p, HostP, OldUnit);
251 }
252 }
Alan Cox554b7c82006-03-24 03:18:32 -0800253 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Andrew Morton8d8706e2006-01-11 12:17:49 -0800256 /*
257 ** The only other command we recognise is a route_request command
258 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800259 if (readb(&PktCmdP->Command) != ROUTE_REQUEST) {
260 rio_dprintk(RIO_DEBUG_ROUTE, "Unknown command %d received on rup %d host %p ROUTE_RUP\n", readb(&PktCmdP->Command), Rup, HostP);
Alan Cox554b7c82006-03-24 03:18:32 -0800261 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Alan Coxe2b3afd2006-03-24 03:18:27 -0800264 RtaUniq = (readb(&PktCmdP->UniqNum[0])) + (readb(&PktCmdP->UniqNum[1]) << 8) + (readb(&PktCmdP->UniqNum[2]) << 16) + (readb(&PktCmdP->UniqNum[3]) << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Andrew Morton8d8706e2006-01-11 12:17:49 -0800266 /*
267 ** Determine if 8 or 16 port RTA
268 */
269 RtaType = GetUnitType(RtaUniq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Andrew Morton8d8706e2006-01-11 12:17:49 -0800271 rio_dprintk(RIO_DEBUG_ROUTE, "Received a request for an ID for serial number %x\n", RtaUniq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Alan Coxe2b3afd2006-03-24 03:18:27 -0800273 Mod = readb(&PktCmdP->ModuleTypes);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800274 Mod1 = LONYBLE(Mod);
275 if (RtaType == TYPE_RTA16) {
276 /*
277 ** Only one ident is set for a 16 port RTA. To make compatible
278 ** with 8 port, set 2nd ident in Mod2 to the same as Mod1.
279 */
280 Mod2 = Mod1;
281 rio_dprintk(RIO_DEBUG_ROUTE, "Backplane type is %s (all ports)\n", p->RIOModuleTypes[Mod1].Name);
282 } else {
283 Mod2 = HINYBLE(Mod);
284 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 -0700285 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800286
Andrew Morton8d8706e2006-01-11 12:17:49 -0800287 /*
288 ** try to unhook a command block from the command free list.
289 */
290 if (!(CmdBlkP = RIOGetCmdBlk())) {
291 rio_dprintk(RIO_DEBUG_ROUTE, "No command blocks to route RTA! come back later.\n");
292 return 0;
293 }
294
295 /*
296 ** Fill in the default info on the command block
297 */
298 CmdBlkP->Packet.dest_unit = Rup;
299 CmdBlkP->Packet.dest_port = ROUTE_RUP;
300 CmdBlkP->Packet.src_unit = HOST_ID;
301 CmdBlkP->Packet.src_port = ROUTE_RUP;
302 CmdBlkP->Packet.len = PKT_CMD_BIT | 1;
303 CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
304 PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
305
306 if (!RIOBootOk(p, HostP, RtaUniq)) {
307 rio_dprintk(RIO_DEBUG_ROUTE, "RTA %x tried to get an ID, but does not belong - FOAD it!\n", RtaUniq);
308 PktReplyP->Command = ROUTE_FOAD;
Al Virobfa6b7b2006-05-27 00:36:10 -0400309 memcpy(PktReplyP->CommandText, "RT_FOAD", 7);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800310 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
Alan Cox554b7c82006-03-24 03:18:32 -0800311 return 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800312 }
313
314 /*
315 ** Check to see if the RTA is configured for this host
316 */
317 for (ThisUnit = 0; ThisUnit < MAX_RUP; ThisUnit++) {
318 rio_dprintk(RIO_DEBUG_ROUTE, "Entry %d Flags=%s %s UniqueNum=0x%x\n",
319 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);
320
321 /*
322 ** We have an entry for it.
323 */
324 if ((HostP->Mapping[ThisUnit].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (HostP->Mapping[ThisUnit].RtaUniqueNum == RtaUniq)) {
325 if (RtaType == TYPE_RTA16) {
326 ThisUnit2 = HostP->Mapping[ThisUnit].ID2 - 1;
327 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slots %d+%d\n", RtaUniq, ThisUnit, ThisUnit2);
328 } else
329 rio_dprintk(RIO_DEBUG_ROUTE, "Found unit 0x%x at slot %d\n", RtaUniq, ThisUnit);
330 /*
331 ** If we have no knowledge of booting it, then the host has
332 ** been re-booted, and so we must kill the RTA, so that it
333 ** will be booted again (potentially with new bins)
334 ** and it will then re-ask for an ID, which we will service.
335 */
336 if ((HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE) && !(HostP->Mapping[ThisUnit].Flags & RTA_BOOTED)) {
337 if (!(HostP->Mapping[ThisUnit].Flags & MSG_DONE)) {
338 if (!p->RIONoMessage)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800339 printk(KERN_DEBUG "rio: RTA '%s' is being updated.\n", HostP->Mapping[ThisUnit].Name);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340 HostP->Mapping[ThisUnit].Flags |= MSG_DONE;
341 }
342 PktReplyP->Command = ROUTE_FOAD;
Al Virobfa6b7b2006-05-27 00:36:10 -0400343 memcpy(PktReplyP->CommandText, "RT_FOAD", 7);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800344 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
Alan Cox554b7c82006-03-24 03:18:32 -0800345 return 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346 }
347
348 /*
349 ** Send the ID (entry) to this RTA. The ID number is implicit as
350 ** the offset into the table. It is worth noting at this stage
351 ** that offset zero in the table contains the entries for the
352 ** RTA with ID 1!!!!
353 */
354 PktReplyP->Command = ROUTE_ALLOCATE;
355 PktReplyP->IDNum = ThisUnit + 1;
356 if (RtaType == TYPE_RTA16) {
357 if (HostP->Mapping[ThisUnit].Flags & SLOT_IN_USE)
358 /*
359 ** Adjust the phb and tx pkt dest_units for 2nd block of 8
360 ** only if the RTA has ports associated (SLOT_IN_USE)
361 */
362 RIOFixPhbs(p, HostP, ThisUnit2);
363 PktReplyP->IDNum2 = ThisUnit2 + 1;
364 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated IDs %d+%d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum, PktReplyP->IDNum2);
365 } else {
366 PktReplyP->IDNum2 = ROUTE_NO_ID;
367 rio_dprintk(RIO_DEBUG_ROUTE, "RTA '%s' has been allocated ID %d\n", HostP->Mapping[ThisUnit].Name, PktReplyP->IDNum);
368 }
Al Virobfa6b7b2006-05-27 00:36:10 -0400369 memcpy(PktReplyP->CommandText, "RT_ALLOCAT", 10);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800370
371 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
372
373 /*
374 ** If this is a freshly booted RTA, then we need to re-open
375 ** the ports, if any where open, so that data may once more
376 ** flow around the system!
377 */
378 if ((HostP->Mapping[ThisUnit].Flags & RTA_NEWBOOT) && (HostP->Mapping[ThisUnit].SysPort != NO_PORT)) {
379 /*
380 ** look at the ports associated with this beast and
381 ** see if any where open. If they was, then re-open
382 ** them, using the info from the tty flags.
383 */
384 for (port = 0; port < PORTS_PER_RTA; port++) {
385 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort];
386 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
387 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
388 rio_spin_lock_irqsave(&PortP->portSem, flags);
389 PortP->MagicFlags |= MAGIC_REBOOT;
390 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
391 }
392 }
393 if (RtaType == TYPE_RTA16) {
394 for (port = 0; port < PORTS_PER_RTA; port++) {
395 PortP = p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort];
396 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
397 rio_dprintk(RIO_DEBUG_ROUTE, "Re-opened this port\n");
398 rio_spin_lock_irqsave(&PortP->portSem, flags);
399 PortP->MagicFlags |= MAGIC_REBOOT;
400 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
401 }
402 }
403 }
404 }
405
406 /*
407 ** keep a copy of the module types!
408 */
409 HostP->UnixRups[ThisUnit].ModTypes = Mod;
410 if (RtaType == TYPE_RTA16)
411 HostP->UnixRups[ThisUnit2].ModTypes = Mod;
412
413 /*
414 ** If either of the modules on this unit is read-only or write-only
415 ** or none-xprint, then we need to transfer that info over to the
416 ** relevant ports.
417 */
418 if (HostP->Mapping[ThisUnit].SysPort != NO_PORT) {
419 for (port = 0; port < PORTS_PER_MODULE; port++) {
420 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
421 p->RIOPortp[port + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
422 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config &= ~RIO_NOMASK;
423 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
424 }
425 if (RtaType == TYPE_RTA16) {
426 for (port = 0; port < PORTS_PER_MODULE; port++) {
427 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
428 p->RIOPortp[port + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod1].Flags[port];
429 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config &= ~RIO_NOMASK;
430 p->RIOPortp[port + PORTS_PER_MODULE + HostP->Mapping[ThisUnit2].SysPort]->Config |= p->RIOModuleTypes[Mod2].Flags[port];
431 }
432 }
433 }
434
435 /*
436 ** Job done, get on with the interrupts!
437 */
Alan Cox554b7c82006-03-24 03:18:32 -0800438 return 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800439 }
440 }
441 /*
442 ** There is no table entry for this RTA at all.
443 **
444 ** Lets check to see if we actually booted this unit - if not,
445 ** then we reset it and it will go round the loop of being booted
446 ** we can then worry about trying to fit it into the table.
447 */
448 for (ThisUnit = 0; ThisUnit < HostP->NumExtraBooted; ThisUnit++)
449 if (HostP->ExtraUnits[ThisUnit] == RtaUniq)
450 break;
451 if (ThisUnit == HostP->NumExtraBooted && ThisUnit != MAX_EXTRA_UNITS) {
452 /*
453 ** if the unit wasn't in the table, and the table wasn't full, then
454 ** we reset the unit, because we didn't boot it.
455 ** However, if the table is full, it could be that we did boot
456 ** this unit, and so we won't reboot it, because it isn't really
457 ** all that disasterous to keep the old bins in most cases. This
458 ** is a rather tacky feature, but we are on the edge of reallity
459 ** here, because the implication is that someone has connected
460 ** 16+MAX_EXTRA_UNITS onto one host.
461 */
462 static int UnknownMesgDone = 0;
463
464 if (!UnknownMesgDone) {
465 if (!p->RIONoMessage)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800466 printk(KERN_DEBUG "rio: One or more unknown RTAs are being updated.\n");
Andrew Morton8d8706e2006-01-11 12:17:49 -0800467 UnknownMesgDone = 1;
468 }
469
470 PktReplyP->Command = ROUTE_FOAD;
Al Virobfa6b7b2006-05-27 00:36:10 -0400471 memcpy(PktReplyP->CommandText, "RT_FOAD", 7);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 } else {
473 /*
474 ** we did boot it (as an extra), and there may now be a table
475 ** slot free (because of a delete), so we will try to make
476 ** a tentative entry for it, so that the configurator can see it
477 ** and fill in the details for us.
478 */
479 if (RtaType == TYPE_RTA16) {
480 if (RIOFindFreeID(p, HostP, &ThisUnit, &ThisUnit2) == 0) {
481 RIODefaultName(p, HostP, ThisUnit);
Alan Cox554b7c82006-03-24 03:18:32 -0800482 rio_fill_host_slot(ThisUnit, ThisUnit2, RtaUniq, HostP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 }
484 } else {
485 if (RIOFindFreeID(p, HostP, &ThisUnit, NULL) == 0) {
486 RIODefaultName(p, HostP, ThisUnit);
Alan Cox554b7c82006-03-24 03:18:32 -0800487 rio_fill_host_slot(ThisUnit, 0, RtaUniq, HostP);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 }
489 }
490 PktReplyP->Command = ROUTE_USED;
Al Virobfa6b7b2006-05-27 00:36:10 -0400491 memcpy(PktReplyP->CommandText, "RT_USED", 7);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
Alan Cox554b7c82006-03-24 03:18:32 -0800494 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
497
Alan Cox554b7c82006-03-24 03:18:32 -0800498void RIOFixPhbs(struct rio_info *p, struct Host *HostP, unsigned int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Alan Cox554b7c82006-03-24 03:18:32 -0800500 unsigned short link, port;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800501 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 unsigned long flags;
503 int PortN = HostP->Mapping[unit].SysPort;
504
Andrew Morton8d8706e2006-01-11 12:17:49 -0800505 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFixPhbs unit %d sysport %d\n", unit, PortN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 if (PortN != -1) {
Alan Cox554b7c82006-03-24 03:18:32 -0800508 unsigned short dest_unit = HostP->Mapping[unit].ID2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800511 ** Get the link number used for the 1st 8 phbs on this unit.
512 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 PortP = p->RIOPortp[HostP->Mapping[dest_unit - 1].SysPort];
514
Alan Coxe2b3afd2006-03-24 03:18:27 -0800515 link = readw(&PortP->PhbP->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 for (port = 0; port < PORTS_PER_RTA; port++, PortN++) {
Alan Cox554b7c82006-03-24 03:18:32 -0800518 unsigned short dest_port = port + 8;
Al Virod886cb52006-05-27 00:08:25 -0400519 u16 __iomem *TxPktP;
520 struct PKT __iomem *Pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 PortP = p->RIOPortp[PortN];
523
524 rio_spin_lock_irqsave(&PortP->portSem, flags);
525 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800526 ** If RTA is not powered on, the tx packets will be
527 ** unset, so go no further.
528 */
Harvey Harrisona01e0352008-04-28 16:50:04 -0700529 if (!PortP->TxStart) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 rio_dprintk(RIO_DEBUG_ROUTE, "Tx pkts not set up yet\n");
531 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
532 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
534
535 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800536 ** For the second slot of a 16 port RTA, the driver needs to
537 ** sort out the phb to port mappings. The dest_unit for this
538 ** group of 8 phbs is set to the dest_unit of the accompanying
539 ** 8 port block. The dest_port of the second unit is set to
540 ** be in the range 8-15 (i.e. 8 is added). Thus, for a 16 port
541 ** RTA with IDs 5 and 6, traffic bound for port 6 of unit 6
542 ** (being the second map ID) will be sent to dest_unit 5, port
543 ** 14. When this RTA is deleted, dest_unit for ID 6 will be
544 ** restored, and the dest_port will be reduced by 8.
545 ** Transmit packets also have a destination field which needs
546 ** adjusting in the same manner.
547 ** Note that the unit/port bytes in 'dest' are swapped.
548 ** We also need to adjust the phb and rup link numbers for the
549 ** second block of 8 ttys.
550 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
552 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800553 ** *TxPktP is the pointer to the transmit packet on the host
554 ** card. This needs to be translated into a 32 bit pointer
555 ** so it can be accessed from the driver.
556 */
Al Virod886cb52006-05-27 00:08:25 -0400557 Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(TxPktP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 ** If the packet is used, reset it.
561 */
Al Virod886cb52006-05-27 00:08:25 -0400562 Pkt = (struct PKT __iomem *) ((unsigned long) Pkt & ~PKT_IN_USE);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800563 writeb(dest_unit, &Pkt->dest_unit);
564 writeb(dest_port, &Pkt->dest_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800566 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);
567 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
568 writew(link, &PortP->PhbP->link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
571 }
572 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800573 ** Now make sure the range of ports to be serviced includes
574 ** the 2nd 8 on this 16 port RTA.
575 */
576 if (link > 3)
577 return;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800578 if (((unit * 8) + 7) > readw(&HostP->LinkStrP[link].last_port)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579 rio_dprintk(RIO_DEBUG_ROUTE, "last port on host link %d: %d\n", link, (unit * 8) + 7);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800580 writew((unit * 8) + 7, &HostP->LinkStrP[link].last_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582 }
583}
584
585/*
586** Check to see if the new disconnection has isolated this unit.
587** If it has, then invalidate all its link information, and tell
588** the world about it. This is done to ensure that the configurator
589** only gets up-to-date information about what is going on.
590*/
Alan Cox554b7c82006-03-24 03:18:32 -0800591static int RIOCheckIsolated(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
593 unsigned long flags;
594 rio_spin_lock_irqsave(&HostP->HostLock, flags);
595
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 if (RIOCheck(HostP, UnitId)) {
597 rio_dprintk(RIO_DEBUG_ROUTE, "Unit %d is NOT isolated\n", UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 }
601
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 RIOIsolate(p, HostP, UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 RIOSetChange(p);
604 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
605 return 1;
606}
607
608/*
609** Invalidate all the link interconnectivity of this unit, and of
610** all the units attached to it. This will mean that the entire
611** subnet will re-introduce itself.
612*/
Alan Cox554b7c82006-03-24 03:18:32 -0800613static int RIOIsolate(struct rio_info *p, struct Host *HostP, unsigned int UnitId)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Alan Cox554b7c82006-03-24 03:18:32 -0800615 unsigned int link, unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 UnitId--; /* this trick relies on the Unit Id being UNSIGNED! */
618
Andrew Morton8d8706e2006-01-11 12:17:49 -0800619 if (UnitId >= MAX_RUP) /* dontcha just lurv unsigned maths! */
620 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Andrew Morton8d8706e2006-01-11 12:17:49 -0800622 if (HostP->Mapping[UnitId].Flags & BEEN_HERE)
623 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
626
Andrew Morton8d8706e2006-01-11 12:17:49 -0800627 if (p->RIOPrintDisabled == DO_PRINT)
628 rio_dprintk(RIO_DEBUG_ROUTE, "RIOMesgIsolated %s", HostP->Mapping[UnitId].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Andrew Morton8d8706e2006-01-11 12:17:49 -0800630 for (link = 0; link < LINKS_PER_UNIT; link++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 unit = HostP->Mapping[UnitId].Topology[link].Unit;
632 HostP->Mapping[UnitId].Topology[link].Unit = ROUTE_DISCONNECT;
633 HostP->Mapping[UnitId].Topology[link].Link = NO_LINK;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800634 RIOIsolate(p, HostP, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
637 return 1;
638}
639
Alan Cox554b7c82006-03-24 03:18:32 -0800640static int RIOCheck(struct Host *HostP, unsigned int UnitId)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800642 unsigned char link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644/* 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 -0800645 rio_dprintk(RIO_DEBUG_ROUTE, "RIOCheck : UnitID = %d\n", UnitId);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Andrew Morton8d8706e2006-01-11 12:17:49 -0800647 if (UnitId == HOST_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is NOT isolated - it IS the host!\n", UnitId)); */
649 return 1;
650 }
651
652 UnitId--;
653
Andrew Morton8d8706e2006-01-11 12:17:49 -0800654 if (UnitId >= MAX_RUP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d - ignored.\n", UnitId)); */
656 return 0;
657 }
658
Andrew Morton8d8706e2006-01-11 12:17:49 -0800659 for (link = 0; link < LINKS_PER_UNIT; link++) {
660 if (HostP->Mapping[UnitId].Topology[link].Unit == HOST_ID) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected directly to host via link (%c).\n",
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662 UnitId, 'A'+link)); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 return 1;
664 }
665 }
666
Andrew Morton8d8706e2006-01-11 12:17:49 -0800667 if (HostP->Mapping[UnitId].Flags & BEEN_HERE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 /* rio_dprint(RIO_DEBUG_ROUTE, ("Been to Unit %d before - ignoring\n", UnitId)); */
669 return 0;
670 }
671
672 HostP->Mapping[UnitId].Flags |= BEEN_HERE;
673
Andrew Morton8d8706e2006-01-11 12:17:49 -0800674 for (link = 0; link < LINKS_PER_UNIT; link++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d check link (%c)\n", UnitId,'A'+link)); */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800676 if (RIOCheck(HostP, HostP->Mapping[UnitId].Topology[link].Unit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d is connected to something that knows the host via link (%c)\n", UnitId,link+'A')); */
678 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
679 return 1;
680 }
681 }
682
683 HostP->Mapping[UnitId].Flags &= ~BEEN_HERE;
684
685 /* rio_dprint(RIO_DEBUG_ROUTE, ("Unit %d DOESNT KNOW THE HOST!\n", UnitId)); */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 return 0;
688}
689
690/*
691** Returns the type of unit (host, 16/8 port RTA)
692*/
693
Alan Cox554b7c82006-03-24 03:18:32 -0800694unsigned int GetUnitType(unsigned int Uniq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800696 switch ((Uniq >> 28) & 0xf) {
697 case RIO_AT:
698 case RIO_MCA:
699 case RIO_EISA:
700 case RIO_PCI:
701 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Host\n");
702 return (TYPE_HOST);
703 case RIO_RTA_16:
704 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 16 port RTA\n");
705 return (TYPE_RTA16);
706 case RIO_RTA:
707 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: 8 port RTA\n");
708 return (TYPE_RTA8);
709 default:
710 rio_dprintk(RIO_DEBUG_ROUTE, "Unit type: Unrecognised\n");
711 return (99);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713}
714
Alan Cox554b7c82006-03-24 03:18:32 -0800715int RIOSetChange(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800717 if (p->RIOQuickCheck != NOT_CHANGED)
718 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 p->RIOQuickCheck = CHANGED;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800720 if (p->RIOSignalProcess) {
721 rio_dprintk(RIO_DEBUG_ROUTE, "Send SIG-HUP");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800723 psignal( RIOSignalProcess, SIGHUP );
724 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800726 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Alan Cox554b7c82006-03-24 03:18:32 -0800729static void RIOConCon(struct rio_info *p,
730 struct Host *HostP,
731 unsigned int FromId,
732 unsigned int FromLink,
733 unsigned int ToId,
734 unsigned int ToLink,
735 int Change)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800737 char *FromName;
738 char *FromType;
739 char *ToName;
740 char *ToType;
741 unsigned int tp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743/*
744** 15.10.1998 ARG - ESIL 0759
745** (Part) fix for port being trashed when opened whilst RTA "disconnected"
746**
747** What's this doing in here anyway ?
748** It was causing the port to be 'unmapped' if opened whilst RTA "disconnected"
749**
750** 09.12.1998 ARG - ESIL 0776 - part fix
751** Okay, We've found out what this was all about now !
752** Someone had botched this to use RIOHalted to indicated the number of RTAs
753** 'disconnected'. The value in RIOHalted was then being used in the
754** 'RIO_QUICK_CHECK' ioctl. A none zero value indicating that a least one RTA
755** is 'disconnected'. The change was put in to satisfy a customer's needs.
756** Having taken this bit of code out 'RIO_QUICK_CHECK' now no longer works for
757** the customer.
758**
759 if (Change == CONNECT) {
760 if (p->RIOHalted) p->RIOHalted --;
761 }
762 else {
763 p->RIOHalted ++;
764 }
765**
766** So - we need to implement it slightly differently - a new member of the
767** rio_info struct - RIORtaDisCons (RIO RTA connections) keeps track of RTA
768** connections and disconnections.
769*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800770 if (Change == CONNECT) {
771 if (p->RIORtaDisCons)
772 p->RIORtaDisCons--;
773 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 p->RIORtaDisCons++;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Andrew Morton8d8706e2006-01-11 12:17:49 -0800777 if (p->RIOPrintDisabled == DONT_PRINT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 return;
779
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 if (FromId > ToId) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 tp = FromId;
782 FromId = ToId;
783 ToId = tp;
784 tp = FromLink;
785 FromLink = ToLink;
786 ToLink = tp;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Andrew Morton8d8706e2006-01-11 12:17:49 -0800789 FromName = FromId ? HostP->Mapping[FromId - 1].Name : HostP->Name;
790 FromType = FromId ? "RTA" : "HOST";
791 ToName = ToId ? HostP->Mapping[ToId - 1].Name : HostP->Name;
792 ToType = ToId ? "RTA" : "HOST";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Andrew Morton8d8706e2006-01-11 12:17:49 -0800794 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 Coxe2b3afd2006-03-24 03:18:27 -0800795 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 Torvalds1da177e2005-04-16 15:20:36 -0700796}
797
798/*
799** RIORemoveFromSavedTable :
800**
801** Delete and RTA entry from the saved table given to us
802** by the configuration program.
803*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804static int RIORemoveFromSavedTable(struct rio_info *p, struct Map *pMap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800806 int entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
Andrew Morton8d8706e2006-01-11 12:17:49 -0800808 /*
809 ** We loop for all entries even after finding an entry and
810 ** zeroing it because we may have two entries to delete if
811 ** it's a 16 port RTA.
812 */
813 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
814 if (p->RIOSavedTable[entry].RtaUniqueNum == pMap->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800815 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800818 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819}
820
821
822/*
823** RIOCheckDisconnected :
824**
825** Scan the unit links to and return zero if the unit is completely
826** disconnected.
827*/
Andrew Morton8d8706e2006-01-11 12:17:49 -0800828static int RIOFreeDisconnected(struct rio_info *p, struct Host *HostP, int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800830 int link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832
Andrew Morton8d8706e2006-01-11 12:17:49 -0800833 rio_dprintk(RIO_DEBUG_ROUTE, "RIOFreeDisconnect unit %d\n", unit);
834 /*
835 ** If the slot is tentative and does not belong to the
836 ** second half of a 16 port RTA then scan to see if
837 ** is disconnected.
838 */
839 for (link = 0; link < LINKS_PER_UNIT; link++) {
840 if (HostP->Mapping[unit].Topology[link].Unit != ROUTE_DISCONNECT)
841 break;
842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 /*
845 ** If not all links are disconnected then we can forget about it.
846 */
847 if (link < LINKS_PER_UNIT)
848 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Olaf Hering44456d32005-07-27 11:45:17 -0700850#ifdef NEED_TO_FIX_THIS
Andrew Morton8d8706e2006-01-11 12:17:49 -0800851 /* Ok so all the links are disconnected. But we may have only just
852 ** made this slot tentative and not yet received a topology update.
853 ** Lets check how long ago we made it tentative.
854 */
855 rio_dprintk(RIO_DEBUG_ROUTE, "Just about to check LBOLT on entry %d\n", unit);
856 if (drv_getparm(LBOLT, (ulong_t *) & current_time))
857 rio_dprintk(RIO_DEBUG_ROUTE, "drv_getparm(LBOLT,....) Failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 elapse_time = current_time - TentTime[unit];
860 rio_dprintk(RIO_DEBUG_ROUTE, "elapse %d = current %d - tent %d (%d usec)\n", elapse_time, current_time, TentTime[unit], drv_hztousec(elapse_time));
861 if (drv_hztousec(elapse_time) < WAIT_TO_FINISH) {
862 rio_dprintk(RIO_DEBUG_ROUTE, "Skipping slot %d, not timed out yet %d\n", unit, drv_hztousec(elapse_time));
863 return 1;
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865#endif
866
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 /*
868 ** We have found an usable slot.
869 ** If it is half of a 16 port RTA then delete the other half.
870 */
871 if (HostP->Mapping[unit].ID2 != 0) {
872 int nOther = (HostP->Mapping[unit].ID2) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Andrew Morton8d8706e2006-01-11 12:17:49 -0800874 rio_dprintk(RIO_DEBUG_ROUTE, "RioFreedis second slot %d.\n", nOther);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800875 memset(&HostP->Mapping[nOther], 0, sizeof(struct Map));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 }
877 RIORemoveFromSavedTable(p, &HostP->Mapping[unit]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
Andrew Morton8d8706e2006-01-11 12:17:49 -0800879 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880}
881
882
883/*
884** RIOFindFreeID :
885**
886** This function scans the given host table for either one
887** or two free unit ID's.
888*/
Alan Cox554b7c82006-03-24 03:18:32 -0800889
890int RIOFindFreeID(struct rio_info *p, struct Host *HostP, unsigned int * pID1, unsigned int * pID2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800892 int unit, tempID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800895 ** Initialise the ID's to MAX_RUP.
896 ** We do this to make the loop for setting the ID's as simple as
897 ** possible.
898 */
899 *pID1 = MAX_RUP;
900 if (pID2 != NULL)
901 *pID2 = MAX_RUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Andrew Morton8d8706e2006-01-11 12:17:49 -0800903 /*
904 ** Scan all entries of the host mapping table for free slots.
905 ** We scan for free slots first and then if that is not successful
906 ** we start all over again looking for tentative slots we can re-use.
907 */
908 for (unit = 0; unit < MAX_RUP; unit++) {
909 rio_dprintk(RIO_DEBUG_ROUTE, "Scanning unit %d\n", unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800911 ** If the flags are zero then the slot is empty.
912 */
913 if (HostP->Mapping[unit].Flags == 0) {
914 rio_dprintk(RIO_DEBUG_ROUTE, " This slot is empty.\n");
915 /*
916 ** If we haven't allocated the first ID then do it now.
917 */
918 if (*pID1 == MAX_RUP) {
919 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for first unit %d\n", unit);
920 *pID1 = unit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Andrew Morton8d8706e2006-01-11 12:17:49 -0800922 /*
923 ** If the second ID is not needed then we can return
924 ** now.
925 */
926 if (pID2 == NULL)
927 return 0;
928 } else {
929 /*
930 ** Allocate the second slot and return.
931 */
932 rio_dprintk(RIO_DEBUG_ROUTE, "Make tentative entry for second unit %d\n", unit);
933 *pID2 = unit;
934 return 0;
935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Andrew Morton8d8706e2006-01-11 12:17:49 -0800939 /*
940 ** If we manage to come out of the free slot loop then we
941 ** need to start all over again looking for tentative slots
942 ** that we can re-use.
943 */
944 rio_dprintk(RIO_DEBUG_ROUTE, "Starting to scan for tentative slots\n");
945 for (unit = 0; unit < MAX_RUP; unit++) {
946 if (((HostP->Mapping[unit].Flags & SLOT_TENTATIVE) || (HostP->Mapping[unit].Flags == 0)) && !(HostP->Mapping[unit].Flags & RTA16_SECOND_SLOT)) {
947 rio_dprintk(RIO_DEBUG_ROUTE, " Slot %d looks promising.\n", unit);
948
949 if (unit == *pID1) {
950 rio_dprintk(RIO_DEBUG_ROUTE, " No it isn't, its the 1st half\n");
951 continue;
952 }
953
954 /*
955 ** Slot is Tentative or Empty, but not a tentative second
956 ** slot of a 16 porter.
957 ** Attempt to free up this slot (and its parnter if
958 ** it is a 16 port slot. The second slot will become
959 ** empty after a call to RIOFreeDisconnected so thats why
960 ** we look for empty slots above as well).
961 */
962 if (HostP->Mapping[unit].Flags != 0)
963 if (RIOFreeDisconnected(p, HostP, unit) != 0)
964 continue;
965 /*
966 ** If we haven't allocated the first ID then do it now.
967 */
968 if (*pID1 == MAX_RUP) {
969 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative entry for first unit %d\n", unit);
970 *pID1 = unit;
971
972 /*
973 ** Clear out this slot now that we intend to use it.
974 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800975 memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800976
977 /*
978 ** If the second ID is not needed then we can return
979 ** now.
980 */
981 if (pID2 == NULL)
982 return 0;
983 } else {
984 /*
985 ** Allocate the second slot and return.
986 */
987 rio_dprintk(RIO_DEBUG_ROUTE, "Grab tentative/empty entry for second unit %d\n", unit);
988 *pID2 = unit;
989
990 /*
991 ** Clear out this slot now that we intend to use it.
992 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800993 memset(&HostP->Mapping[unit], 0, sizeof(struct Map));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800994
995 /* At this point under the right(wrong?) conditions
996 ** we may have a first unit ID being higher than the
997 ** second unit ID. This is a bad idea if we are about
998 ** to fill the slots with a 16 port RTA.
999 ** Better check and swap them over.
1000 */
1001
1002 if (*pID1 > *pID2) {
1003 rio_dprintk(RIO_DEBUG_ROUTE, "Swapping IDS %d %d\n", *pID1, *pID2);
1004 tempID = *pID1;
1005 *pID1 = *pID2;
1006 *pID2 = tempID;
1007 }
1008 return 0;
1009 }
1010 }
1011 }
1012
1013 /*
1014 ** If we manage to get to the end of the second loop then we
1015 ** can give up and return a failure.
1016 */
1017 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
1020
1021/*
1022** The link switch scenario.
1023**
1024** Rta Wun (A) is connected to Tuw (A).
1025** The tables are all up to date, and the system is OK.
1026**
1027** If Wun (A) is now moved to Wun (B) before Wun (A) can
1028** become disconnected, then the follow happens:
1029**
1030** Tuw (A) spots the change of unit:link at the other end
1031** of its link and Tuw sends a topology packet reflecting
1032** the change: Tuw (A) now disconnected from Wun (A), and
1033** this is closely followed by a packet indicating that
1034** Tuw (A) is now connected to Wun (B).
1035**
1036** Wun (B) will spot that it has now become connected, and
1037** Wun will send a topology packet, which indicates that
1038** both Wun (A) and Wun (B) is connected to Tuw (A).
1039**
1040** Eventually Wun (A) realises that it is now disconnected
1041** and Wun will send out a topology packet indicating that
1042** Wun (A) is now disconnected.
1043*/