blob: 2b24488e95f284eeb0d2fe1bcaac23139a4c0c53 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/uaccess.h>
46
47#include <linux/termios.h>
48#include <linux/serial.h>
49
50#include <linux/generic_serial.h>
51
52
53#include "linux_compat.h"
54#include "rio_linux.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include "pkt.h"
56#include "daemon.h"
57#include "rio.h"
58#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include "cmdpkt.h"
60#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include "rup.h"
62#include "port.h"
63#include "riodrvr.h"
64#include "rioinfo.h"
65#include "func.h"
66#include "errors.h"
67#include "pci.h"
68
69#include "parmmap.h"
70#include "unixrup.h"
71#include "board.h"
72#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include "phb.h"
74#include "link.h"
75#include "cmdblk.h"
76#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#include "cirrus.h"
78#include "rioioctl.h"
79#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include "protsts.h"
81
82/*
83** A configuration table has been loaded. It is now up to us
84** to sort it out and use the information contained therein.
85*/
Alan Coxe2b3afd2006-03-24 03:18:27 -080086int RIONewTable(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
88 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
89 struct Map *MapP;
90 struct Map *HostMapP;
91 struct Host *HostP;
92
93 char *cptr;
94
95 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -080096 ** We have been sent a new table to install. We need to break
97 ** it down into little bits and spread it around a bit to see
98 ** what we have got.
99 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800101 ** Things to check:
102 ** (things marked 'xx' aren't checked any more!)
103 ** (1) That there are no booted Hosts/RTAs out there.
104 ** (2) That the names are properly formed
105 ** (3) That blank entries really are.
106 ** xx (4) That hosts mentioned in the table actually exist. xx
107 ** (5) That the IDs are unique (per host).
108 ** (6) That host IDs are zero
109 ** (7) That port numbers are valid
110 ** (8) That port numbers aren't duplicated
111 ** (9) That names aren't duplicated
112 ** xx (10) That hosts that actually exist are mentioned in the table. xx
113 */
114 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
115 if (p->RIOSystemUp) { /* (1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
117 return -EBUSY;
118 }
119
120 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
121 p->RIOError.Entry = -1;
122 p->RIOError.Other = -1;
123
Andrew Morton8d8706e2006-01-11 12:17:49 -0800124 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 MapP = &p->RIOConnectTable[Entry];
126 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800127 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
128 cptr = MapP->Name; /* (2) */
129 cptr[MAX_NAME_LEN - 1] = '\0';
130 if (cptr[0] == '\0') {
Alan Cox554b7c82006-03-24 03:18:32 -0800131 memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800132 MapP->Name[5] = '0' + Entry / 10;
133 MapP->Name[6] = '0' + Entry % 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800135 while (*cptr) {
136 if (*cptr < ' ' || *cptr > '~') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
138 p->RIOError.Entry = Entry;
139 return -ENXIO;
140 }
141 cptr++;
142 }
143 }
144
145 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800146 ** If the entry saved was a tentative entry then just forget
147 ** about it.
148 */
149 if (MapP->Flags & SLOT_TENTATIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 MapP->HostUniqueNum = 0;
151 MapP->RtaUniqueNum = 0;
152 continue;
153 }
154
Andrew Morton8d8706e2006-01-11 12:17:49 -0800155 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
156 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
157 if (MapP->ID || MapP->SysPort || MapP->Flags) {
158 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
160 p->RIOError.Entry = Entry;
161 return -ENXIO;
162 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800163 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 continue;
165 }
166
Andrew Morton8d8706e2006-01-11 12:17:49 -0800167 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
168 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
169 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 HostP = &p->RIOHosts[Host];
171 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800172 ** having done the lookup, we don't really want to do
173 ** it again, so hang the host number in a safe place
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 MapP->Topology[0].Unit = Host;
176 break;
177 }
178 }
179
Andrew Morton8d8706e2006-01-11 12:17:49 -0800180 if (Host >= p->RIONumHosts) {
181 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 -0700182 MapP->HostUniqueNum = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800183 /* MapP->RtaUniqueNum = 0; */
184 /* MapP->ID = 0; */
185 /* MapP->Flags = 0; */
186 /* MapP->SysPort = 0; */
187 /* MapP->Name[0] = 0; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 continue;
189 }
190
Andrew Morton8d8706e2006-01-11 12:17:49 -0800191 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
192 if (MapP->RtaUniqueNum) { /* (5) */
193 if (!MapP->ID) {
194 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
195 p->RIOError.Error = ZERO_RTA_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 p->RIOError.Entry = Entry;
197 return -ENXIO;
198 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800199 if (MapP->ID > MAX_RUP) {
200 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 -0700201 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
202 p->RIOError.Entry = Entry;
203 return -ENXIO;
204 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800205 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
206 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
207 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 -0700208 p->RIOError.Error = DUPLICATED_RTA_ID;
209 p->RIOError.Entry = Entry;
210 p->RIOError.Other = SubEnt;
211 return -ENXIO;
212 }
213 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800214 ** If the RtaUniqueNum is the same, it may be looking at both
215 ** entries for a 16 port RTA, so check the ids
216 */
217 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
218 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
219 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
220 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
222 p->RIOError.Entry = Entry;
223 p->RIOError.Other = SubEnt;
224 return -ENXIO;
225 }
226 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800227 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /* (7a) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800229 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
230 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 -0700231 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
232 p->RIOError.Entry = Entry;
233 return -ENXIO;
234 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800235 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 /* (7b) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800237 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
238 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 -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 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
244 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
245 continue;
246 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
247 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 /* (8) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800249 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
250 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 -0700251 p->RIOError.Error = TTY_NUMBER_IN_USE;
252 p->RIOError.Entry = Entry;
253 p->RIOError.Other = SubEnt;
254 return -ENXIO;
255 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800256 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
257 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
258 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 p->RIOError.Error = NAME_USED_TWICE;
260 p->RIOError.Entry = Entry;
261 p->RIOError.Other = SubEnt;
262 return -ENXIO;
263 }
264 }
265 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800266 } else { /* (6) */
267 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
268 if (MapP->ID) {
269 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 -0700270 p->RIOError.Error = HOST_ID_NOT_ZERO;
271 p->RIOError.Entry = Entry;
272 return -ENXIO;
273 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800274 if (MapP->SysPort != NO_PORT) {
275 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 p->RIOError.Error = HOST_SYSPORT_BAD;
277 p->RIOError.Entry = Entry;
278 return -ENXIO;
279 }
280 }
281 }
282
283 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800284 ** wow! if we get here then it's a goody!
285 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 ** Zero the (old) entries for each host...
289 */
290 for (Host = 0; Host < RIO_HOSTS; Host++) {
291 for (Entry = 0; Entry < MAX_RUP; Entry++) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800292 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800294 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 }
296
297 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800298 ** Copy in the new table entries
299 */
300 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
301 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 MapP = &p->RIOConnectTable[Entry];
303
304 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800305 ** Now, if it is an empty slot ignore it!
306 */
307 if (MapP->HostUniqueNum == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 continue;
309
310 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800311 ** we saved the host number earlier, so grab it back
312 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
314
315 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800316 ** If it is a host, then we only need to fill in the name field.
317 */
318 if (MapP->ID == 0) {
319 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
Alan Cox554b7c82006-03-24 03:18:32 -0800320 memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 continue;
322 }
323
324 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800325 ** Its an RTA entry, so fill in the host mapping entries for it
326 ** and the port mapping entries. Notice that entry zero is for
327 ** ID one.
328 */
329 HostMapP = &HostP->Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 if (MapP->Flags & SLOT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800332 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800334 ** structure assign, then sort out the bits we shouldn't have done
335 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *HostMapP = *MapP;
337
338 HostMapP->Flags = SLOT_IN_USE;
339 if (MapP->Flags & RTA16_SECOND_SLOT)
340 HostMapP->Flags |= RTA16_SECOND_SLOT;
341
Andrew Morton8d8706e2006-01-11 12:17:49 -0800342 RIOReMapPorts(p, HostP, HostMapP);
343 } else {
344 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346 }
347
Andrew Morton8d8706e2006-01-11 12:17:49 -0800348 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
350 }
351
Andrew Morton8d8706e2006-01-11 12:17:49 -0800352 for (Host = 0; Host < p->RIONumHosts; Host++) {
353 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
355 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
356 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800357 for (Entry = 0; Entry < MAX_RUP; Entry++) {
358 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
359 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
360 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 if (!p->RIOHosts[Host].Name[0]) {
Alan Cox554b7c82006-03-24 03:18:32 -0800364 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 p->RIOHosts[Host].Name[5] += Host;
366 }
367 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 ** Check that default name assigned is unique.
369 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 Host1 = Host;
371 NameIsUnique = 0;
372 while (!NameIsUnique) {
373 NameIsUnique = 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800374 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (Host2 == Host)
376 continue;
377 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800378 == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 NameIsUnique = 0;
380 Host1++;
381 if (Host1 >= p->RIONumHosts)
382 Host1 = 0;
383 p->RIOHosts[Host].Name[5] = '1' + Host1;
384 }
385 }
386 }
387 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800388 ** Rename host if name already used.
389 */
390 if (Host1 != Host) {
391 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
Alan Cox554b7c82006-03-24 03:18:32 -0800392 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 p->RIOHosts[Host].Name[5] += Host1;
394 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800395 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 }
397 return 0;
398}
399
400/*
401** User process needs the config table - build it from first
402** principles.
Alan Coxe2b3afd2006-03-24 03:18:27 -0800403**
404* FIXME: SMP locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800406int RIOApel(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407{
408 int Host;
409 int link;
410 int Rup;
411 int Next = 0;
412 struct Map *MapP;
413 struct Host *HostP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800414 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Andrew Morton8d8706e2006-01-11 12:17:49 -0800416 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Alan Coxe2b3afd2006-03-24 03:18:27 -0800418 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800419
420 for (Host = 0; Host < RIO_HOSTS; Host++) {
421 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 HostP = &p->RIOHosts[Host];
Alan Coxe2b3afd2006-03-24 03:18:27 -0800423 rio_spin_lock_irqsave(&HostP->HostLock, flags);
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 MapP = &p->RIOConnectTable[Next++];
426 MapP->HostUniqueNum = HostP->UniqueNum;
Jiri Slaby212e7bb2008-04-02 13:04:48 -0700427 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
428 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 continue;
Jiri Slaby212e7bb2008-04-02 13:04:48 -0700430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 MapP->RtaUniqueNum = 0;
432 MapP->ID = 0;
433 MapP->Flags = SLOT_IN_USE;
434 MapP->SysPort = NO_PORT;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800435 for (link = 0; link < LINKS_PER_UNIT; link++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 MapP->Topology[link] = HostP->Topology[link];
Alan Cox554b7c82006-03-24 03:18:32 -0800437 memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800438 for (Rup = 0; Rup < MAX_RUP; Rup++) {
439 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800443 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800445 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
447 Next++;
448 }
449 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800450 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return 0;
453}
454
455/*
456** config.rio has taken a dislike to one of the gross maps entries.
457** if the entry is suitably inactive, then we can gob on it and remove
458** it from the table.
459*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800460int RIODeleteRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461{
462 int host, entry, port, link;
463 int SysPort;
464 struct Host *HostP;
465 struct Map *HostMapP;
466 struct Port *PortP;
467 int work_done = 0;
468 unsigned long lock_flags, sem_flags;
469
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 for (host = 0; host < p->RIONumHosts; host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 HostP = &p->RIOHosts[host];
474
Andrew Morton8d8706e2006-01-11 12:17:49 -0800475 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Andrew Morton8d8706e2006-01-11 12:17:49 -0800477 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
479 continue;
480 }
481
Andrew Morton8d8706e2006-01-11 12:17:49 -0800482 for (entry = 0; entry < MAX_RUP; entry++) {
483 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 HostMapP = &HostP->Mapping[entry];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800485 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800488 ** Check all four links of the unit are disconnected
489 */
490 for (link = 0; link < LINKS_PER_UNIT; link++) {
491 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
492 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 p->RIOError.Error = UNIT_IS_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800494 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 return -EBUSY;
496 }
497 }
498 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 ** Slot has been allocated, BUT not booted/routed/
500 ** connected/selected or anything else-ed
501 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 SysPort = HostMapP->SysPort;
503
Andrew Morton8d8706e2006-01-11 12:17:49 -0800504 if (SysPort != NO_PORT) {
505 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 PortP = p->RIOPortp[port];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800507 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Andrew Morton8d8706e2006-01-11 12:17:49 -0800509 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 PortP->Mapped = 0;
512
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Andrew Morton8d8706e2006-01-11 12:17:49 -0800515 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 PortP->TxBufferIn = PortP->TxBufferOut = 0;
517 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800518 wakeup( &PortP->TxBufferIn );
519 wakeup( &PortP->TxBufferOut);
520 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 PortP->InUse = NOT_INUSE;
522 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800523 wakeup( &PortP->InUse );
524 signal(PortP->TtyP->t_pgrp,SIGKILL);
525 ttyflush(PortP->TtyP,(FREAD|FWRITE));
526 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 PortP->State |= RIO_CLOSING | RIO_DELETED;
528 }
529
530 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 ** For the second slot of a 16 port RTA, the
532 ** driver needs to reset the changes made to
533 ** the phb to port mappings in RIORouteRup.
534 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (PortP->SecondBlock) {
Alan Cox554b7c82006-03-24 03:18:32 -0800536 u16 dest_unit = HostMapP->ID;
537 u16 dest_port = port - SysPort;
Al Virod886cb52006-05-27 00:08:25 -0400538 u16 __iomem *TxPktP;
539 struct PKT __iomem *Pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Andrew Morton8d8706e2006-01-11 12:17:49 -0800541 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800543 ** *TxPktP is the pointer to the
544 ** transmit packet on the host card.
545 ** This needs to be translated into
546 ** a 32 bit pointer so it can be
547 ** accessed from the driver.
548 */
Al Virod886cb52006-05-27 00:08:25 -0400549 Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
Al Viro92af11c2006-05-27 02:24:14 -0400550 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", readw(TxPktP), readb(&Pkt->dest_unit), readb(&Pkt->dest_port), dest_unit, dest_port);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800551 writew(dest_unit, &Pkt->dest_unit);
552 writew(dest_port, &Pkt->dest_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
Al Viro92af11c2006-05-27 02:24:14 -0400554 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, readb(&PortP->PhbP->destination) & 0xff, (readb(&PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
Alan Coxe2b3afd2006-03-24 03:18:27 -0800555 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
558 }
559 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800560 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800561 memset(HostMapP, 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 work_done++;
563 }
564 }
565 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
566 }
567
568 /* XXXXX lock me up */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800569 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
570 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800571 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 work_done++;
573 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800574 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800575 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 work_done++;
577 }
578 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800579 if (work_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return 0;
581
Andrew Morton8d8706e2006-01-11 12:17:49 -0800582 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 p->RIOError.Error = COULDNT_FIND_ENTRY;
584 return -ENXIO;
585}
586
Andrew Morton8d8706e2006-01-11 12:17:49 -0800587int RIOAssignRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 int host;
590 struct Map *HostMapP;
591 char *sptr;
592 int link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594
Andrew Morton8d8706e2006-01-11 12:17:49 -0800595 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 -0700596
Alan Cox554b7c82006-03-24 03:18:32 -0800597 if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800598 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
599 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
600 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800602 if (MapP->RtaUniqueNum == 0) {
603 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
604 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
605 return -EINVAL;
606 }
607 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
608 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
609 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
610 return -EINVAL;
611 }
612 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
613 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
614 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
615 return -EINVAL;
616 }
617
618 /*
619 ** Copy the name across to the map entry.
620 */
621 MapP->Name[MAX_NAME_LEN - 1] = '\0';
622 sptr = MapP->Name;
623 while (*sptr) {
624 if (*sptr < ' ' || *sptr > '~') {
625 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
626 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
627 return -EINVAL;
628 }
629 sptr++;
630 }
631
632 for (host = 0; host < p->RIONumHosts; host++) {
633 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
634 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
635 p->RIOError.Error = HOST_NOT_RUNNING;
636 return -ENXIO;
637 }
638
639 /*
640 ** Now we have a host we need to allocate an ID
641 ** if the entry does not already have one.
642 */
Alan Cox554b7c82006-03-24 03:18:32 -0800643 if (MapP->ID == (u16) - 1) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800644 int nNewID;
645
646 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
647 /*
648 ** The idea here is to allow RTA's to be assigned
649 ** before they actually appear on the network.
650 ** This allows the addition of RTA's without having
651 ** to plug them in.
652 ** What we do is:
653 ** - Find a free ID and allocate it to the RTA.
654 ** - If this map entry is the second half of a
655 ** 16 port entry then find the other half and
656 ** make sure the 2 cross reference each other.
657 */
658 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
659 p->RIOError.Error = COULDNT_FIND_ENTRY;
660 return -EBUSY;
661 }
Alan Cox554b7c82006-03-24 03:18:32 -0800662 MapP->ID = (u16) nNewID + 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
664 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
665 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
666 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
667 HostMapP->ID = MapP->ID;
668 for (link = 0; link < LINKS_PER_UNIT; link++) {
669 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
670 HostMapP->Topology[link].Link = NO_LINK;
671 }
672 if (MapP->Flags & RTA16_SECOND_SLOT) {
673 int unit;
674
675 for (unit = 0; unit < MAX_RUP; unit++)
676 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
677 break;
678 if (unit == MAX_RUP) {
679 p->RIOError.Error = COULDNT_FIND_ENTRY;
680 return -EBUSY;
681 }
682 HostMapP->Flags |= RTA16_SECOND_SLOT;
683 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
684 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
685 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
686 }
687 }
688
689 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
690
691 if (HostMapP->Flags & SLOT_IN_USE) {
692 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
693 p->RIOError.Error = ID_ALREADY_IN_USE;
694 return -EBUSY;
695 }
696
697 /*
698 ** Assign the sys ports and the name, and mark the slot as
699 ** being in use.
700 */
701 HostMapP->SysPort = MapP->SysPort;
702 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
Alan Cox554b7c82006-03-24 03:18:32 -0800703 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800704 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
705#ifdef NEED_TO_FIX
706 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
707#endif
708 if (MapP->Flags & RTA16_SECOND_SLOT)
709 HostMapP->Flags |= RTA16_SECOND_SLOT;
710
711 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
712 /*
713 ** Adjust 2nd block of 8 phbs
714 */
715 if (MapP->Flags & RTA16_SECOND_SLOT)
716 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
717
718 if (HostMapP->SysPort != NO_PORT) {
719 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
720 p->RIOFirstPortsBooted = HostMapP->SysPort;
721 if (HostMapP->SysPort > p->RIOLastPortsBooted)
722 p->RIOLastPortsBooted = HostMapP->SysPort;
723 }
724 if (MapP->Flags & RTA16_SECOND_SLOT)
725 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
726 else
727 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
728 return 0;
729 }
730 }
731 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
732 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
733 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}
735
736
Alan Coxe2b3afd2006-03-24 03:18:27 -0800737int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800739 struct Port *PortP;
Alan Cox554b7c82006-03-24 03:18:32 -0800740 unsigned int SubEnt;
741 unsigned int HostPort;
742 unsigned int SysPort;
743 u16 RtaType;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 unsigned long flags;
745
Andrew Morton8d8706e2006-01-11 12:17:49 -0800746 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747
748 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800749 ** We need to tell the UnixRups which sysport the rup corresponds to
750 */
751 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Andrew Morton8d8706e2006-01-11 12:17:49 -0800753 if (HostMapP->SysPort == NO_PORT)
754 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800757 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 -0700758
759 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800760 ** now map each of its eight ports
761 */
762 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
763 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
764 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
765 /* portnumber on host */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766
Andrew Morton8d8706e2006-01-11 12:17:49 -0800767 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
768
769 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 PortP = p->RIOPortp[SysPort];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800771 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800774 ** Point at all the real neat data structures
775 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 rio_spin_lock_irqsave(&PortP->portSem, flags);
777 PortP->HostP = HostP;
778 PortP->Caddr = HostP->Caddr;
779
780 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800781 ** The PhbP cannot be filled in yet
782 ** unless the host has been booted
783 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
Al Virod886cb52006-05-27 00:08:25 -0400785 struct PHB __iomem *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
786 PortP->TxAdd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
787 PortP->TxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
788 PortP->TxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
789 PortP->RxRemove = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
790 PortP->RxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
791 PortP->RxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800792 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 PortP->PhbP = NULL;
794
795 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800796 ** port related flags
797 */
798 PortP->HostPort = HostPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800800 ** For each part of a 16 port RTA, RupNum is ID - 1.
801 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 PortP->RupNum = HostMapP->ID - 1;
803 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804 PortP->ID2 = HostMapP->ID2 - 1;
Alan Cox554b7c82006-03-24 03:18:32 -0800805 PortP->SecondBlock = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800807 PortP->ID2 = 0;
Alan Cox554b7c82006-03-24 03:18:32 -0800808 PortP->SecondBlock = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809 }
810 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
811
812 /*
813 ** If the port was already mapped then thats all we need to do.
814 */
815 if (PortP->Mapped) {
816 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
817 continue;
818 } else
819 HostMapP->Flags &= ~RTA_NEWBOOT;
820
821 PortP->State = 0;
822 PortP->Config = 0;
823 /*
824 ** Check out the module type - if it is special (read only etc.)
825 ** then we need to set flags in the PortP->Config.
826 ** Note: For 16 port RTA, all ports are of the same type.
827 */
828 if (RtaType == TYPE_RTA16) {
829 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
830 } else {
831 if (SubEnt < PORTS_PER_MODULE)
832 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800834 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800838 ** more port related flags
839 */
840 PortP->PortState = 0;
841 PortP->ModemLines = 0;
842 PortP->ModemState = 0;
843 PortP->CookMode = COOK_WELL;
844 PortP->ParamSem = 0;
845 PortP->FlushCmdBodge = 0;
846 PortP->WflushFlag = 0;
847 PortP->MagicFlags = 0;
848 PortP->Lock = 0;
849 PortP->Store = 0;
850 PortP->FirstOpen = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800853 ** Buffers 'n things
854 */
855 PortP->RxDataStart = 0;
856 PortP->Cor2Copy = 0;
857 PortP->Name = &HostMapP->Name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 PortP->statsGather = 0;
859 PortP->txchars = 0;
860 PortP->rxchars = 0;
861 PortP->opens = 0;
862 PortP->closes = 0;
863 PortP->ioctls = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800864 if (PortP->TxRingBuffer)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800865 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800866 else if (p->RIOBufferSize) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700867 PortP->TxRingBuffer = kzalloc(p->RIOBufferSize, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800869 PortP->TxBufferOut = 0;
870 PortP->TxBufferIn = 0;
871 PortP->Debug = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873 ** LastRxTgl stores the state of the rx toggle bit for this
874 ** port, to be compared with the state of the next pkt received.
875 ** If the same, we have received the same rx pkt from the RTA
876 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
877 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800878 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800881 ** and mark the port as usable
882 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 PortP->Mapped = 1;
884 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
885 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800886 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 p->RIOFirstPortsMapped = HostMapP->SysPort;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800888 if (HostMapP->SysPort > p->RIOLastPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 p->RIOLastPortsMapped = HostMapP->SysPort;
890
891 return 0;
892}
893
Alan Coxe2b3afd2006-03-24 03:18:27 -0800894int RIOChangeName(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895{
896 int host;
897 struct Map *HostMapP;
898 char *sptr;
899
Andrew Morton8d8706e2006-01-11 12:17:49 -0800900 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 -0700901
Andrew Morton8d8706e2006-01-11 12:17:49 -0800902 if (MapP->ID > MAX_RUP) {
903 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
905 return -EINVAL;
906 }
907
Andrew Morton8d8706e2006-01-11 12:17:49 -0800908 MapP->Name[MAX_NAME_LEN - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 sptr = MapP->Name;
910
Andrew Morton8d8706e2006-01-11 12:17:49 -0800911 while (*sptr) {
912 if (*sptr < ' ' || *sptr > '~') {
913 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
915 return -EINVAL;
916 }
917 sptr++;
918 }
919
Andrew Morton8d8706e2006-01-11 12:17:49 -0800920 for (host = 0; host < p->RIONumHosts; host++) {
921 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
922 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 p->RIOError.Error = HOST_NOT_RUNNING;
924 return -ENXIO;
925 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800926 if (MapP->ID == 0) {
Alan Cox554b7c82006-03-24 03:18:32 -0800927 memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return 0;
929 }
930
Andrew Morton8d8706e2006-01-11 12:17:49 -0800931 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Andrew Morton8d8706e2006-01-11 12:17:49 -0800933 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 p->RIOError.Error = RTA_NUMBER_WRONG;
935 return -ENXIO;
936 }
Alan Cox554b7c82006-03-24 03:18:32 -0800937 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return 0;
939 }
940 }
941 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800942 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 return -ENXIO;
944}