blob: f1d50142b91d52f761b863b26b946bc7539d3a57 [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 : riotable.c
24** SID : 1.2
25** Last Modified : 11/6/98 10:33:47
26** Retrieved : 11/6/98 10:33:50
27**
28** ident @(#)riotable.c 1.2
29**
30** -----------------------------------------------------------------------------
31*/
32#ifdef SCCS_LABELS
33static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
34#endif
35
36#include <linux/module.h>
37#include <linux/slab.h>
38#include <linux/errno.h>
39#include <linux/interrupt.h>
40#include <linux/string.h>
41
42#include <asm/io.h>
43#include <asm/system.h>
44#include <asm/string.h>
45#include <asm/semaphore.h>
46#include <asm/uaccess.h>
47
48#include <linux/termios.h>
49#include <linux/serial.h>
50
51#include <linux/generic_serial.h>
52
53
54#include "linux_compat.h"
55#include "rio_linux.h"
56#include "typdef.h"
57#include "pkt.h"
58#include "daemon.h"
59#include "rio.h"
60#include "riospace.h"
61#include "top.h"
62#include "cmdpkt.h"
63#include "map.h"
64#include "riotypes.h"
65#include "rup.h"
66#include "port.h"
67#include "riodrvr.h"
68#include "rioinfo.h"
69#include "func.h"
70#include "errors.h"
71#include "pci.h"
72
73#include "parmmap.h"
74#include "unixrup.h"
75#include "board.h"
76#include "host.h"
77#include "error.h"
78#include "phb.h"
79#include "link.h"
80#include "cmdblk.h"
81#include "route.h"
82#include "control.h"
83#include "cirrus.h"
84#include "rioioctl.h"
85#include "param.h"
86#include "list.h"
87#include "sam.h"
88#include "protsts.h"
89
90/*
91** A configuration table has been loaded. It is now up to us
92** to sort it out and use the information contained therein.
93*/
Alan Coxe2b3afd2006-03-24 03:18:27 -080094int RIONewTable(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
97 struct Map *MapP;
98 struct Map *HostMapP;
99 struct Host *HostP;
100
101 char *cptr;
102
103 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800104 ** We have been sent a new table to install. We need to break
105 ** it down into little bits and spread it around a bit to see
106 ** what we have got.
107 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800109 ** Things to check:
110 ** (things marked 'xx' aren't checked any more!)
111 ** (1) That there are no booted Hosts/RTAs out there.
112 ** (2) That the names are properly formed
113 ** (3) That blank entries really are.
114 ** xx (4) That hosts mentioned in the table actually exist. xx
115 ** (5) That the IDs are unique (per host).
116 ** (6) That host IDs are zero
117 ** (7) That port numbers are valid
118 ** (8) That port numbers aren't duplicated
119 ** (9) That names aren't duplicated
120 ** xx (10) That hosts that actually exist are mentioned in the table. xx
121 */
122 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
123 if (p->RIOSystemUp) { /* (1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
125 return -EBUSY;
126 }
127
128 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
129 p->RIOError.Entry = -1;
130 p->RIOError.Other = -1;
131
Andrew Morton8d8706e2006-01-11 12:17:49 -0800132 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 MapP = &p->RIOConnectTable[Entry];
134 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800135 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
136 cptr = MapP->Name; /* (2) */
137 cptr[MAX_NAME_LEN - 1] = '\0';
138 if (cptr[0] == '\0') {
139 bcopy(MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", MapP->Name, 8);
140 MapP->Name[5] = '0' + Entry / 10;
141 MapP->Name[6] = '0' + Entry % 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800143 while (*cptr) {
144 if (*cptr < ' ' || *cptr > '~') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
146 p->RIOError.Entry = Entry;
147 return -ENXIO;
148 }
149 cptr++;
150 }
151 }
152
153 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800154 ** If the entry saved was a tentative entry then just forget
155 ** about it.
156 */
157 if (MapP->Flags & SLOT_TENTATIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 MapP->HostUniqueNum = 0;
159 MapP->RtaUniqueNum = 0;
160 continue;
161 }
162
Andrew Morton8d8706e2006-01-11 12:17:49 -0800163 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
164 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
165 if (MapP->ID || MapP->SysPort || MapP->Flags) {
166 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
168 p->RIOError.Entry = Entry;
169 return -ENXIO;
170 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800171 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 continue;
173 }
174
Andrew Morton8d8706e2006-01-11 12:17:49 -0800175 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
176 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
177 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 HostP = &p->RIOHosts[Host];
179 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800180 ** having done the lookup, we don't really want to do
181 ** it again, so hang the host number in a safe place
182 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 MapP->Topology[0].Unit = Host;
184 break;
185 }
186 }
187
Andrew Morton8d8706e2006-01-11 12:17:49 -0800188 if (Host >= p->RIONumHosts) {
189 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 MapP->HostUniqueNum = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800191 /* MapP->RtaUniqueNum = 0; */
192 /* MapP->ID = 0; */
193 /* MapP->Flags = 0; */
194 /* MapP->SysPort = 0; */
195 /* MapP->Name[0] = 0; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 continue;
197 }
198
Andrew Morton8d8706e2006-01-11 12:17:49 -0800199 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
200 if (MapP->RtaUniqueNum) { /* (5) */
201 if (!MapP->ID) {
202 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
203 p->RIOError.Error = ZERO_RTA_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 p->RIOError.Entry = Entry;
205 return -ENXIO;
206 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800207 if (MapP->ID > MAX_RUP) {
208 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
210 p->RIOError.Entry = Entry;
211 return -ENXIO;
212 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800213 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
214 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
215 rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 p->RIOError.Error = DUPLICATED_RTA_ID;
217 p->RIOError.Entry = Entry;
218 p->RIOError.Other = SubEnt;
219 return -ENXIO;
220 }
221 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800222 ** If the RtaUniqueNum is the same, it may be looking at both
223 ** entries for a 16 port RTA, so check the ids
224 */
225 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
226 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
227 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
228 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
230 p->RIOError.Entry = Entry;
231 p->RIOError.Other = SubEnt;
232 return -ENXIO;
233 }
234 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /* (7a) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800237 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
238 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n", (int) MapP->SysPort, MapP->Name, PORTS_PER_RTA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
240 p->RIOError.Entry = Entry;
241 return -ENXIO;
242 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800243 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* (7b) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800245 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
246 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
248 p->RIOError.Entry = Entry;
249 return -ENXIO;
250 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800251 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
252 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
253 continue;
254 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
255 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 /* (8) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800257 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
258 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 p->RIOError.Error = TTY_NUMBER_IN_USE;
260 p->RIOError.Entry = Entry;
261 p->RIOError.Other = SubEnt;
262 return -ENXIO;
263 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800264 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
265 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
266 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 p->RIOError.Error = NAME_USED_TWICE;
268 p->RIOError.Entry = Entry;
269 p->RIOError.Other = SubEnt;
270 return -ENXIO;
271 }
272 }
273 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800274 } else { /* (6) */
275 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
276 if (MapP->ID) {
277 rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 p->RIOError.Error = HOST_ID_NOT_ZERO;
279 p->RIOError.Entry = Entry;
280 return -ENXIO;
281 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800282 if (MapP->SysPort != NO_PORT) {
283 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 p->RIOError.Error = HOST_SYSPORT_BAD;
285 p->RIOError.Entry = Entry;
286 return -ENXIO;
287 }
288 }
289 }
290
291 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800292 ** wow! if we get here then it's a goody!
293 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800296 ** Zero the (old) entries for each host...
297 */
298 for (Host = 0; Host < RIO_HOSTS; Host++) {
299 for (Entry = 0; Entry < MAX_RUP; Entry++) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800300 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800302 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306 ** Copy in the new table entries
307 */
308 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
309 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 MapP = &p->RIOConnectTable[Entry];
311
312 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800313 ** Now, if it is an empty slot ignore it!
314 */
315 if (MapP->HostUniqueNum == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 continue;
317
318 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319 ** we saved the host number earlier, so grab it back
320 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
322
323 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324 ** If it is a host, then we only need to fill in the name field.
325 */
326 if (MapP->ID == 0) {
327 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
328 bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 continue;
330 }
331
332 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800333 ** Its an RTA entry, so fill in the host mapping entries for it
334 ** and the port mapping entries. Notice that entry zero is for
335 ** ID one.
336 */
337 HostMapP = &HostP->Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 if (MapP->Flags & SLOT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342 ** structure assign, then sort out the bits we shouldn't have done
343 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 *HostMapP = *MapP;
345
346 HostMapP->Flags = SLOT_IN_USE;
347 if (MapP->Flags & RTA16_SECOND_SLOT)
348 HostMapP->Flags |= RTA16_SECOND_SLOT;
349
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 RIOReMapPorts(p, HostP, HostMapP);
351 } else {
352 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
354 }
355
Andrew Morton8d8706e2006-01-11 12:17:49 -0800356 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
358 }
359
Andrew Morton8d8706e2006-01-11 12:17:49 -0800360 for (Host = 0; Host < p->RIONumHosts; Host++) {
361 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
363 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
364 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800365 for (Entry = 0; Entry < MAX_RUP; Entry++) {
366 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
367 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
368 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800371 if (!p->RIOHosts[Host].Name[0]) {
372 bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 p->RIOHosts[Host].Name[5] += Host;
374 }
375 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800376 ** Check that default name assigned is unique.
377 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 Host1 = Host;
379 NameIsUnique = 0;
380 while (!NameIsUnique) {
381 NameIsUnique = 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800382 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (Host2 == Host)
384 continue;
385 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800386 == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 NameIsUnique = 0;
388 Host1++;
389 if (Host1 >= p->RIONumHosts)
390 Host1 = 0;
391 p->RIOHosts[Host].Name[5] = '1' + Host1;
392 }
393 }
394 }
395 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 ** Rename host if name already used.
397 */
398 if (Host1 != Host) {
399 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
400 bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 p->RIOHosts[Host].Name[5] += Host1;
402 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405 return 0;
406}
407
408/*
409** User process needs the config table - build it from first
410** principles.
Alan Coxe2b3afd2006-03-24 03:18:27 -0800411**
412* FIXME: SMP locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800414int RIOApel(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 int Host;
417 int link;
418 int Rup;
419 int Next = 0;
420 struct Map *MapP;
421 struct Host *HostP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800422 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrew Morton8d8706e2006-01-11 12:17:49 -0800424 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Alan Coxe2b3afd2006-03-24 03:18:27 -0800426 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800427
428 for (Host = 0; Host < RIO_HOSTS; Host++) {
429 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 HostP = &p->RIOHosts[Host];
Alan Coxe2b3afd2006-03-24 03:18:27 -0800431 rio_spin_lock_irqsave(&HostP->HostLock, flags);
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 MapP = &p->RIOConnectTable[Next++];
434 MapP->HostUniqueNum = HostP->UniqueNum;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800435 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 continue;
437 MapP->RtaUniqueNum = 0;
438 MapP->ID = 0;
439 MapP->Flags = SLOT_IN_USE;
440 MapP->SysPort = NO_PORT;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441 for (link = 0; link < LINKS_PER_UNIT; link++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 MapP->Topology[link] = HostP->Topology[link];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN);
444 for (Rup = 0; Rup < MAX_RUP; Rup++) {
445 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800447 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800449 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
453 Next++;
454 }
455 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800456 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return 0;
459}
460
461/*
462** config.rio has taken a dislike to one of the gross maps entries.
463** if the entry is suitably inactive, then we can gob on it and remove
464** it from the table.
465*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800466int RIODeleteRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467{
468 int host, entry, port, link;
469 int SysPort;
470 struct Host *HostP;
471 struct Map *HostMapP;
472 struct Port *PortP;
473 int work_done = 0;
474 unsigned long lock_flags, sem_flags;
475
Andrew Morton8d8706e2006-01-11 12:17:49 -0800476 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 for (host = 0; host < p->RIONumHosts; host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 HostP = &p->RIOHosts[host];
480
Andrew Morton8d8706e2006-01-11 12:17:49 -0800481 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
485 continue;
486 }
487
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 for (entry = 0; entry < MAX_RUP; entry++) {
489 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 HostMapP = &HostP->Mapping[entry];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800491 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800494 ** Check all four links of the unit are disconnected
495 */
496 for (link = 0; link < LINKS_PER_UNIT; link++) {
497 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
498 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 p->RIOError.Error = UNIT_IS_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 return -EBUSY;
502 }
503 }
504 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800505 ** Slot has been allocated, BUT not booted/routed/
506 ** connected/selected or anything else-ed
507 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 SysPort = HostMapP->SysPort;
509
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 if (SysPort != NO_PORT) {
511 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 PortP = p->RIOPortp[port];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Andrew Morton8d8706e2006-01-11 12:17:49 -0800515 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 PortP->Mapped = 0;
518
Andrew Morton8d8706e2006-01-11 12:17:49 -0800519 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Andrew Morton8d8706e2006-01-11 12:17:49 -0800521 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 PortP->TxBufferIn = PortP->TxBufferOut = 0;
523 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 wakeup( &PortP->TxBufferIn );
525 wakeup( &PortP->TxBufferOut);
526 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 PortP->InUse = NOT_INUSE;
528 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 wakeup( &PortP->InUse );
530 signal(PortP->TtyP->t_pgrp,SIGKILL);
531 ttyflush(PortP->TtyP,(FREAD|FWRITE));
532 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 PortP->State |= RIO_CLOSING | RIO_DELETED;
534 }
535
536 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800537 ** For the second slot of a 16 port RTA, the
538 ** driver needs to reset the changes made to
539 ** the phb to port mappings in RIORouteRup.
540 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 if (PortP->SecondBlock) {
542 ushort dest_unit = HostMapP->ID;
543 ushort dest_port = port - SysPort;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800544 u16 *TxPktP;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800545 PKT *Pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800549 ** *TxPktP is the pointer to the
550 ** transmit packet on the host card.
551 ** This needs to be translated into
552 ** a 32 bit pointer so it can be
553 ** accessed from the driver.
554 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800555 Pkt = (PKT *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800556 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800557 writew(dest_unit, &Pkt->dest_unit);
558 writew(dest_port, &Pkt->dest_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800561 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
564 }
565 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800566 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800567 memset(HostMapP, 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 work_done++;
569 }
570 }
571 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
572 }
573
574 /* XXXXX lock me up */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800575 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
576 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800577 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 work_done++;
579 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800581 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 work_done++;
583 }
584 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800585 if (work_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return 0;
587
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 p->RIOError.Error = COULDNT_FIND_ENTRY;
590 return -ENXIO;
591}
592
Andrew Morton8d8706e2006-01-11 12:17:49 -0800593int RIOAssignRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800595 int host;
596 struct Map *HostMapP;
597 char *sptr;
598 int link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600
Andrew Morton8d8706e2006-01-11 12:17:49 -0800601 rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Andrew Morton8d8706e2006-01-11 12:17:49 -0800603 if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
604 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
605 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
606 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800608 if (MapP->RtaUniqueNum == 0) {
609 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
610 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
611 return -EINVAL;
612 }
613 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
614 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
615 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
616 return -EINVAL;
617 }
618 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
619 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
620 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
621 return -EINVAL;
622 }
623
624 /*
625 ** Copy the name across to the map entry.
626 */
627 MapP->Name[MAX_NAME_LEN - 1] = '\0';
628 sptr = MapP->Name;
629 while (*sptr) {
630 if (*sptr < ' ' || *sptr > '~') {
631 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
632 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
633 return -EINVAL;
634 }
635 sptr++;
636 }
637
638 for (host = 0; host < p->RIONumHosts; host++) {
639 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
640 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
641 p->RIOError.Error = HOST_NOT_RUNNING;
642 return -ENXIO;
643 }
644
645 /*
646 ** Now we have a host we need to allocate an ID
647 ** if the entry does not already have one.
648 */
649 if (MapP->ID == (ushort) - 1) {
650 int nNewID;
651
652 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
653 /*
654 ** The idea here is to allow RTA's to be assigned
655 ** before they actually appear on the network.
656 ** This allows the addition of RTA's without having
657 ** to plug them in.
658 ** What we do is:
659 ** - Find a free ID and allocate it to the RTA.
660 ** - If this map entry is the second half of a
661 ** 16 port entry then find the other half and
662 ** make sure the 2 cross reference each other.
663 */
664 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
665 p->RIOError.Error = COULDNT_FIND_ENTRY;
666 return -EBUSY;
667 }
668 MapP->ID = (ushort) nNewID + 1;
669 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
670 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
671 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
672 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
673 HostMapP->ID = MapP->ID;
674 for (link = 0; link < LINKS_PER_UNIT; link++) {
675 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
676 HostMapP->Topology[link].Link = NO_LINK;
677 }
678 if (MapP->Flags & RTA16_SECOND_SLOT) {
679 int unit;
680
681 for (unit = 0; unit < MAX_RUP; unit++)
682 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
683 break;
684 if (unit == MAX_RUP) {
685 p->RIOError.Error = COULDNT_FIND_ENTRY;
686 return -EBUSY;
687 }
688 HostMapP->Flags |= RTA16_SECOND_SLOT;
689 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
690 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
691 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
692 }
693 }
694
695 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
696
697 if (HostMapP->Flags & SLOT_IN_USE) {
698 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
699 p->RIOError.Error = ID_ALREADY_IN_USE;
700 return -EBUSY;
701 }
702
703 /*
704 ** Assign the sys ports and the name, and mark the slot as
705 ** being in use.
706 */
707 HostMapP->SysPort = MapP->SysPort;
708 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
709 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
710 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
711#ifdef NEED_TO_FIX
712 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
713#endif
714 if (MapP->Flags & RTA16_SECOND_SLOT)
715 HostMapP->Flags |= RTA16_SECOND_SLOT;
716
717 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
718 /*
719 ** Adjust 2nd block of 8 phbs
720 */
721 if (MapP->Flags & RTA16_SECOND_SLOT)
722 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
723
724 if (HostMapP->SysPort != NO_PORT) {
725 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
726 p->RIOFirstPortsBooted = HostMapP->SysPort;
727 if (HostMapP->SysPort > p->RIOLastPortsBooted)
728 p->RIOLastPortsBooted = HostMapP->SysPort;
729 }
730 if (MapP->Flags & RTA16_SECOND_SLOT)
731 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
732 else
733 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
734 return 0;
735 }
736 }
737 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
738 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
739 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740}
741
742
Alan Coxe2b3afd2006-03-24 03:18:27 -0800743int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800745 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 uint SubEnt;
747 uint HostPort;
748 uint SysPort;
749 ushort RtaType;
750 unsigned long flags;
751
Andrew Morton8d8706e2006-01-11 12:17:49 -0800752 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800755 ** We need to tell the UnixRups which sysport the rup corresponds to
756 */
757 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Andrew Morton8d8706e2006-01-11 12:17:49 -0800759 if (HostMapP->SysPort == NO_PORT)
760 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800763 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800766 ** now map each of its eight ports
767 */
768 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
769 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
770 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
771 /* portnumber on host */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Andrew Morton8d8706e2006-01-11 12:17:49 -0800773 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
774
775 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 PortP = p->RIOPortp[SysPort];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800777 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 ** Point at all the real neat data structures
781 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 rio_spin_lock_irqsave(&PortP->portSem, flags);
783 PortP->HostP = HostP;
784 PortP->Caddr = HostP->Caddr;
785
786 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 ** The PhbP cannot be filled in yet
788 ** unless the host has been booted
789 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
791 struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
Alan Coxe2b3afd2006-03-24 03:18:27 -0800792 PortP->TxAdd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
793 PortP->TxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
794 PortP->TxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
795 PortP->RxRemove = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
796 PortP->RxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
797 PortP->RxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800798 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 PortP->PhbP = NULL;
800
801 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800802 ** port related flags
803 */
804 PortP->HostPort = HostPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800806 ** For each part of a 16 port RTA, RupNum is ID - 1.
807 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 PortP->RupNum = HostMapP->ID - 1;
809 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800810 PortP->ID2 = HostMapP->ID2 - 1;
811 PortP->SecondBlock = TRUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800813 PortP->ID2 = 0;
814 PortP->SecondBlock = FALSE;
815 }
816 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
817
818 /*
819 ** If the port was already mapped then thats all we need to do.
820 */
821 if (PortP->Mapped) {
822 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
823 continue;
824 } else
825 HostMapP->Flags &= ~RTA_NEWBOOT;
826
827 PortP->State = 0;
828 PortP->Config = 0;
829 /*
830 ** Check out the module type - if it is special (read only etc.)
831 ** then we need to set flags in the PortP->Config.
832 ** Note: For 16 port RTA, all ports are of the same type.
833 */
834 if (RtaType == TYPE_RTA16) {
835 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
836 } else {
837 if (SubEnt < PORTS_PER_MODULE)
838 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800840 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 }
842
843 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800844 ** more port related flags
845 */
846 PortP->PortState = 0;
847 PortP->ModemLines = 0;
848 PortP->ModemState = 0;
849 PortP->CookMode = COOK_WELL;
850 PortP->ParamSem = 0;
851 PortP->FlushCmdBodge = 0;
852 PortP->WflushFlag = 0;
853 PortP->MagicFlags = 0;
854 PortP->Lock = 0;
855 PortP->Store = 0;
856 PortP->FirstOpen = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800859 ** Buffers 'n things
860 */
861 PortP->RxDataStart = 0;
862 PortP->Cor2Copy = 0;
863 PortP->Name = &HostMapP->Name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 PortP->statsGather = 0;
865 PortP->txchars = 0;
866 PortP->rxchars = 0;
867 PortP->opens = 0;
868 PortP->closes = 0;
869 PortP->ioctls = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800870 if (PortP->TxRingBuffer)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800871 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800872 else if (p->RIOBufferSize) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800873 PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL);
874 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800876 PortP->TxBufferOut = 0;
877 PortP->TxBufferIn = 0;
878 PortP->Debug = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800880 ** LastRxTgl stores the state of the rx toggle bit for this
881 ** port, to be compared with the state of the next pkt received.
882 ** If the same, we have received the same rx pkt from the RTA
883 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
884 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800885 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800888 ** and mark the port as usable
889 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 PortP->Mapped = 1;
891 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
892 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800893 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 p->RIOFirstPortsMapped = HostMapP->SysPort;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800895 if (HostMapP->SysPort > p->RIOLastPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 p->RIOLastPortsMapped = HostMapP->SysPort;
897
898 return 0;
899}
900
Alan Coxe2b3afd2006-03-24 03:18:27 -0800901int RIOChangeName(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
903 int host;
904 struct Map *HostMapP;
905 char *sptr;
906
Andrew Morton8d8706e2006-01-11 12:17:49 -0800907 rio_dprintk(RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Andrew Morton8d8706e2006-01-11 12:17:49 -0800909 if (MapP->ID > MAX_RUP) {
910 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
912 return -EINVAL;
913 }
914
Andrew Morton8d8706e2006-01-11 12:17:49 -0800915 MapP->Name[MAX_NAME_LEN - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 sptr = MapP->Name;
917
Andrew Morton8d8706e2006-01-11 12:17:49 -0800918 while (*sptr) {
919 if (*sptr < ' ' || *sptr > '~') {
920 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
922 return -EINVAL;
923 }
924 sptr++;
925 }
926
Andrew Morton8d8706e2006-01-11 12:17:49 -0800927 for (host = 0; host < p->RIONumHosts; host++) {
928 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
929 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 p->RIOError.Error = HOST_NOT_RUNNING;
931 return -ENXIO;
932 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800933 if (MapP->ID == 0) {
934 CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return 0;
936 }
937
Andrew Morton8d8706e2006-01-11 12:17:49 -0800938 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Andrew Morton8d8706e2006-01-11 12:17:49 -0800940 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 p->RIOError.Error = RTA_NUMBER_WRONG;
942 return -ENXIO;
943 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800944 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 return 0;
946 }
947 }
948 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800949 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 return -ENXIO;
951}