blob: 9b52892a501f67702222eca6eedcf913783e3fc3 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include "pkt.h"
57#include "daemon.h"
58#include "rio.h"
59#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include "cmdpkt.h"
61#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include "rup.h"
63#include "port.h"
64#include "riodrvr.h"
65#include "rioinfo.h"
66#include "func.h"
67#include "errors.h"
68#include "pci.h"
69
70#include "parmmap.h"
71#include "unixrup.h"
72#include "board.h"
73#include "host.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#include "phb.h"
75#include "link.h"
76#include "cmdblk.h"
77#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include "cirrus.h"
79#include "rioioctl.h"
80#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#include "protsts.h"
82
83/*
84** A configuration table has been loaded. It is now up to us
85** to sort it out and use the information contained therein.
86*/
Alan Coxe2b3afd2006-03-24 03:18:27 -080087int RIONewTable(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
90 struct Map *MapP;
91 struct Map *HostMapP;
92 struct Host *HostP;
93
94 char *cptr;
95
96 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -080097 ** We have been sent a new table to install. We need to break
98 ** it down into little bits and spread it around a bit to see
99 ** what we have got.
100 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800102 ** Things to check:
103 ** (things marked 'xx' aren't checked any more!)
104 ** (1) That there are no booted Hosts/RTAs out there.
105 ** (2) That the names are properly formed
106 ** (3) That blank entries really are.
107 ** xx (4) That hosts mentioned in the table actually exist. xx
108 ** (5) That the IDs are unique (per host).
109 ** (6) That host IDs are zero
110 ** (7) That port numbers are valid
111 ** (8) That port numbers aren't duplicated
112 ** (9) That names aren't duplicated
113 ** xx (10) That hosts that actually exist are mentioned in the table. xx
114 */
115 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
116 if (p->RIOSystemUp) { /* (1) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
118 return -EBUSY;
119 }
120
121 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
122 p->RIOError.Entry = -1;
123 p->RIOError.Other = -1;
124
Andrew Morton8d8706e2006-01-11 12:17:49 -0800125 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 MapP = &p->RIOConnectTable[Entry];
127 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800128 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
129 cptr = MapP->Name; /* (2) */
130 cptr[MAX_NAME_LEN - 1] = '\0';
131 if (cptr[0] == '\0') {
Alan Cox554b7c82006-03-24 03:18:32 -0800132 memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800133 MapP->Name[5] = '0' + Entry / 10;
134 MapP->Name[6] = '0' + Entry % 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800136 while (*cptr) {
137 if (*cptr < ' ' || *cptr > '~') {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
139 p->RIOError.Entry = Entry;
140 return -ENXIO;
141 }
142 cptr++;
143 }
144 }
145
146 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800147 ** If the entry saved was a tentative entry then just forget
148 ** about it.
149 */
150 if (MapP->Flags & SLOT_TENTATIVE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 MapP->HostUniqueNum = 0;
152 MapP->RtaUniqueNum = 0;
153 continue;
154 }
155
Andrew Morton8d8706e2006-01-11 12:17:49 -0800156 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
157 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
158 if (MapP->ID || MapP->SysPort || MapP->Flags) {
159 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
161 p->RIOError.Entry = Entry;
162 return -ENXIO;
163 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800164 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 continue;
166 }
167
Andrew Morton8d8706e2006-01-11 12:17:49 -0800168 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
169 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
170 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 HostP = &p->RIOHosts[Host];
172 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800173 ** having done the lookup, we don't really want to do
174 ** it again, so hang the host number in a safe place
175 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 MapP->Topology[0].Unit = Host;
177 break;
178 }
179 }
180
Andrew Morton8d8706e2006-01-11 12:17:49 -0800181 if (Host >= p->RIONumHosts) {
182 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 -0700183 MapP->HostUniqueNum = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800184 /* MapP->RtaUniqueNum = 0; */
185 /* MapP->ID = 0; */
186 /* MapP->Flags = 0; */
187 /* MapP->SysPort = 0; */
188 /* MapP->Name[0] = 0; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 continue;
190 }
191
Andrew Morton8d8706e2006-01-11 12:17:49 -0800192 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
193 if (MapP->RtaUniqueNum) { /* (5) */
194 if (!MapP->ID) {
195 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
196 p->RIOError.Error = ZERO_RTA_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 p->RIOError.Entry = Entry;
198 return -ENXIO;
199 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800200 if (MapP->ID > MAX_RUP) {
201 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 -0700202 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
203 p->RIOError.Entry = Entry;
204 return -ENXIO;
205 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800206 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
207 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
208 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 -0700209 p->RIOError.Error = DUPLICATED_RTA_ID;
210 p->RIOError.Entry = Entry;
211 p->RIOError.Other = SubEnt;
212 return -ENXIO;
213 }
214 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800215 ** If the RtaUniqueNum is the same, it may be looking at both
216 ** entries for a 16 port RTA, so check the ids
217 */
218 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
219 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
220 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
221 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
223 p->RIOError.Entry = Entry;
224 p->RIOError.Other = SubEnt;
225 return -ENXIO;
226 }
227 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800228 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 /* (7a) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800230 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
231 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 -0700232 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
233 p->RIOError.Entry = Entry;
234 return -ENXIO;
235 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800236 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* (7b) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800238 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
239 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 -0700240 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
241 p->RIOError.Entry = Entry;
242 return -ENXIO;
243 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800244 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
245 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
246 continue;
247 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
248 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 /* (8) */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800250 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
251 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 -0700252 p->RIOError.Error = TTY_NUMBER_IN_USE;
253 p->RIOError.Entry = Entry;
254 p->RIOError.Other = SubEnt;
255 return -ENXIO;
256 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800257 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
258 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
259 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 p->RIOError.Error = NAME_USED_TWICE;
261 p->RIOError.Entry = Entry;
262 p->RIOError.Other = SubEnt;
263 return -ENXIO;
264 }
265 }
266 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800267 } else { /* (6) */
268 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
269 if (MapP->ID) {
270 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 -0700271 p->RIOError.Error = HOST_ID_NOT_ZERO;
272 p->RIOError.Entry = Entry;
273 return -ENXIO;
274 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800275 if (MapP->SysPort != NO_PORT) {
276 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 p->RIOError.Error = HOST_SYSPORT_BAD;
278 p->RIOError.Entry = Entry;
279 return -ENXIO;
280 }
281 }
282 }
283
284 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800285 ** wow! if we get here then it's a goody!
286 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800289 ** Zero the (old) entries for each host...
290 */
291 for (Host = 0; Host < RIO_HOSTS; Host++) {
292 for (Entry = 0; Entry < MAX_RUP; Entry++) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800293 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800295 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 }
297
298 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800299 ** Copy in the new table entries
300 */
301 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
302 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 MapP = &p->RIOConnectTable[Entry];
304
305 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306 ** Now, if it is an empty slot ignore it!
307 */
308 if (MapP->HostUniqueNum == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 continue;
310
311 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800312 ** we saved the host number earlier, so grab it back
313 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
315
316 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800317 ** If it is a host, then we only need to fill in the name field.
318 */
319 if (MapP->ID == 0) {
320 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
Alan Cox554b7c82006-03-24 03:18:32 -0800321 memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 continue;
323 }
324
325 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800326 ** Its an RTA entry, so fill in the host mapping entries for it
327 ** and the port mapping entries. Notice that entry zero is for
328 ** ID one.
329 */
330 HostMapP = &HostP->Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if (MapP->Flags & SLOT_IN_USE) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800333 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800335 ** structure assign, then sort out the bits we shouldn't have done
336 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 *HostMapP = *MapP;
338
339 HostMapP->Flags = SLOT_IN_USE;
340 if (MapP->Flags & RTA16_SECOND_SLOT)
341 HostMapP->Flags |= RTA16_SECOND_SLOT;
342
Andrew Morton8d8706e2006-01-11 12:17:49 -0800343 RIOReMapPorts(p, HostP, HostMapP);
344 } else {
345 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347 }
348
Andrew Morton8d8706e2006-01-11 12:17:49 -0800349 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
351 }
352
Andrew Morton8d8706e2006-01-11 12:17:49 -0800353 for (Host = 0; Host < p->RIONumHosts; Host++) {
354 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
356 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
357 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800358 for (Entry = 0; Entry < MAX_RUP; Entry++) {
359 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
360 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
361 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800364 if (!p->RIOHosts[Host].Name[0]) {
Alan Cox554b7c82006-03-24 03:18:32 -0800365 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 p->RIOHosts[Host].Name[5] += Host;
367 }
368 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800369 ** Check that default name assigned is unique.
370 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 Host1 = Host;
372 NameIsUnique = 0;
373 while (!NameIsUnique) {
374 NameIsUnique = 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800375 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 if (Host2 == Host)
377 continue;
378 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 NameIsUnique = 0;
381 Host1++;
382 if (Host1 >= p->RIONumHosts)
383 Host1 = 0;
384 p->RIOHosts[Host].Name[5] = '1' + Host1;
385 }
386 }
387 }
388 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800389 ** Rename host if name already used.
390 */
391 if (Host1 != Host) {
392 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
Alan Cox554b7c82006-03-24 03:18:32 -0800393 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 p->RIOHosts[Host].Name[5] += Host1;
395 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
398 return 0;
399}
400
401/*
402** User process needs the config table - build it from first
403** principles.
Alan Coxe2b3afd2006-03-24 03:18:27 -0800404**
405* FIXME: SMP locking
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800407int RIOApel(struct rio_info *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
409 int Host;
410 int link;
411 int Rup;
412 int Next = 0;
413 struct Map *MapP;
414 struct Host *HostP;
Alan Coxe2b3afd2006-03-24 03:18:27 -0800415 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Andrew Morton8d8706e2006-01-11 12:17:49 -0800417 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Alan Coxe2b3afd2006-03-24 03:18:27 -0800419 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800420
421 for (Host = 0; Host < RIO_HOSTS; Host++) {
422 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 HostP = &p->RIOHosts[Host];
Alan Coxe2b3afd2006-03-24 03:18:27 -0800424 rio_spin_lock_irqsave(&HostP->HostLock, flags);
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 MapP = &p->RIOConnectTable[Next++];
427 MapP->HostUniqueNum = HostP->UniqueNum;
Jiri Slaby212e7bb2008-04-02 13:04:48 -0700428 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
429 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 continue;
Jiri Slaby212e7bb2008-04-02 13:04:48 -0700431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 MapP->RtaUniqueNum = 0;
433 MapP->ID = 0;
434 MapP->Flags = SLOT_IN_USE;
435 MapP->SysPort = NO_PORT;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800436 for (link = 0; link < LINKS_PER_UNIT; link++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 MapP->Topology[link] = HostP->Topology[link];
Alan Cox554b7c82006-03-24 03:18:32 -0800438 memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800439 for (Rup = 0; Rup < MAX_RUP; Rup++) {
440 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800444 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800446 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
448 Next++;
449 }
450 }
Alan Coxe2b3afd2006-03-24 03:18:27 -0800451 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return 0;
454}
455
456/*
457** config.rio has taken a dislike to one of the gross maps entries.
458** if the entry is suitably inactive, then we can gob on it and remove
459** it from the table.
460*/
Alan Coxe2b3afd2006-03-24 03:18:27 -0800461int RIODeleteRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 int host, entry, port, link;
464 int SysPort;
465 struct Host *HostP;
466 struct Map *HostMapP;
467 struct Port *PortP;
468 int work_done = 0;
469 unsigned long lock_flags, sem_flags;
470
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Andrew Morton8d8706e2006-01-11 12:17:49 -0800473 for (host = 0; host < p->RIONumHosts; host++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 HostP = &p->RIOHosts[host];
475
Andrew Morton8d8706e2006-01-11 12:17:49 -0800476 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Andrew Morton8d8706e2006-01-11 12:17:49 -0800478 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
480 continue;
481 }
482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 for (entry = 0; entry < MAX_RUP; entry++) {
484 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 HostMapP = &HostP->Mapping[entry];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800486 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800489 ** Check all four links of the unit are disconnected
490 */
491 for (link = 0; link < LINKS_PER_UNIT; link++) {
492 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
493 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 p->RIOError.Error = UNIT_IS_IN_USE;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return -EBUSY;
497 }
498 }
499 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 ** Slot has been allocated, BUT not booted/routed/
501 ** connected/selected or anything else-ed
502 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 SysPort = HostMapP->SysPort;
504
Andrew Morton8d8706e2006-01-11 12:17:49 -0800505 if (SysPort != NO_PORT) {
506 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 PortP = p->RIOPortp[port];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800508 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 PortP->Mapped = 0;
513
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Andrew Morton8d8706e2006-01-11 12:17:49 -0800516 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 PortP->TxBufferIn = PortP->TxBufferOut = 0;
518 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800519 wakeup( &PortP->TxBufferIn );
520 wakeup( &PortP->TxBufferOut);
521 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 PortP->InUse = NOT_INUSE;
523 /* What should I do
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524 wakeup( &PortP->InUse );
525 signal(PortP->TtyP->t_pgrp,SIGKILL);
526 ttyflush(PortP->TtyP,(FREAD|FWRITE));
527 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 PortP->State |= RIO_CLOSING | RIO_DELETED;
529 }
530
531 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800532 ** For the second slot of a 16 port RTA, the
533 ** driver needs to reset the changes made to
534 ** the phb to port mappings in RIORouteRup.
535 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (PortP->SecondBlock) {
Alan Cox554b7c82006-03-24 03:18:32 -0800537 u16 dest_unit = HostMapP->ID;
538 u16 dest_port = port - SysPort;
Al Virod886cb52006-05-27 00:08:25 -0400539 u16 __iomem *TxPktP;
540 struct PKT __iomem *Pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Andrew Morton8d8706e2006-01-11 12:17:49 -0800542 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800544 ** *TxPktP is the pointer to the
545 ** transmit packet on the host card.
546 ** This needs to be translated into
547 ** a 32 bit pointer so it can be
548 ** accessed from the driver.
549 */
Al Virod886cb52006-05-27 00:08:25 -0400550 Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
Al Viro92af11c2006-05-27 02:24:14 -0400551 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 -0800552 writew(dest_unit, &Pkt->dest_unit);
553 writew(dest_port, &Pkt->dest_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
Al Viro92af11c2006-05-27 02:24:14 -0400555 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 -0800556 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
559 }
560 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800561 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
Alan Coxe2b3afd2006-03-24 03:18:27 -0800562 memset(HostMapP, 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 work_done++;
564 }
565 }
566 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
567 }
568
569 /* XXXXX lock me up */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800570 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
571 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800572 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 work_done++;
574 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800575 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
Alan Coxe2b3afd2006-03-24 03:18:27 -0800576 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 work_done++;
578 }
579 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580 if (work_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 return 0;
582
Andrew Morton8d8706e2006-01-11 12:17:49 -0800583 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 p->RIOError.Error = COULDNT_FIND_ENTRY;
585 return -ENXIO;
586}
587
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588int RIOAssignRta(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800590 int host;
591 struct Map *HostMapP;
592 char *sptr;
593 int link;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595
Andrew Morton8d8706e2006-01-11 12:17:49 -0800596 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 -0700597
Alan Cox554b7c82006-03-24 03:18:32 -0800598 if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
600 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
601 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800603 if (MapP->RtaUniqueNum == 0) {
604 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
605 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
606 return -EINVAL;
607 }
608 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
609 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
610 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
611 return -EINVAL;
612 }
613 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
614 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
615 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
616 return -EINVAL;
617 }
618
619 /*
620 ** Copy the name across to the map entry.
621 */
622 MapP->Name[MAX_NAME_LEN - 1] = '\0';
623 sptr = MapP->Name;
624 while (*sptr) {
625 if (*sptr < ' ' || *sptr > '~') {
626 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
627 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
628 return -EINVAL;
629 }
630 sptr++;
631 }
632
633 for (host = 0; host < p->RIONumHosts; host++) {
634 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
635 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
636 p->RIOError.Error = HOST_NOT_RUNNING;
637 return -ENXIO;
638 }
639
640 /*
641 ** Now we have a host we need to allocate an ID
642 ** if the entry does not already have one.
643 */
Alan Cox554b7c82006-03-24 03:18:32 -0800644 if (MapP->ID == (u16) - 1) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800645 int nNewID;
646
647 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
648 /*
649 ** The idea here is to allow RTA's to be assigned
650 ** before they actually appear on the network.
651 ** This allows the addition of RTA's without having
652 ** to plug them in.
653 ** What we do is:
654 ** - Find a free ID and allocate it to the RTA.
655 ** - If this map entry is the second half of a
656 ** 16 port entry then find the other half and
657 ** make sure the 2 cross reference each other.
658 */
659 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
660 p->RIOError.Error = COULDNT_FIND_ENTRY;
661 return -EBUSY;
662 }
Alan Cox554b7c82006-03-24 03:18:32 -0800663 MapP->ID = (u16) nNewID + 1;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800664 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
665 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
666 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
667 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
668 HostMapP->ID = MapP->ID;
669 for (link = 0; link < LINKS_PER_UNIT; link++) {
670 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
671 HostMapP->Topology[link].Link = NO_LINK;
672 }
673 if (MapP->Flags & RTA16_SECOND_SLOT) {
674 int unit;
675
676 for (unit = 0; unit < MAX_RUP; unit++)
677 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
678 break;
679 if (unit == MAX_RUP) {
680 p->RIOError.Error = COULDNT_FIND_ENTRY;
681 return -EBUSY;
682 }
683 HostMapP->Flags |= RTA16_SECOND_SLOT;
684 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
685 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
686 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
687 }
688 }
689
690 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
691
692 if (HostMapP->Flags & SLOT_IN_USE) {
693 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
694 p->RIOError.Error = ID_ALREADY_IN_USE;
695 return -EBUSY;
696 }
697
698 /*
699 ** Assign the sys ports and the name, and mark the slot as
700 ** being in use.
701 */
702 HostMapP->SysPort = MapP->SysPort;
703 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
Alan Cox554b7c82006-03-24 03:18:32 -0800704 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800705 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
706#ifdef NEED_TO_FIX
707 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
708#endif
709 if (MapP->Flags & RTA16_SECOND_SLOT)
710 HostMapP->Flags |= RTA16_SECOND_SLOT;
711
712 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
713 /*
714 ** Adjust 2nd block of 8 phbs
715 */
716 if (MapP->Flags & RTA16_SECOND_SLOT)
717 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
718
719 if (HostMapP->SysPort != NO_PORT) {
720 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
721 p->RIOFirstPortsBooted = HostMapP->SysPort;
722 if (HostMapP->SysPort > p->RIOLastPortsBooted)
723 p->RIOLastPortsBooted = HostMapP->SysPort;
724 }
725 if (MapP->Flags & RTA16_SECOND_SLOT)
726 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
727 else
728 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
729 return 0;
730 }
731 }
732 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
733 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
734 return -ENXIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735}
736
737
Alan Coxe2b3afd2006-03-24 03:18:27 -0800738int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
Alan Coxe2b3afd2006-03-24 03:18:27 -0800740 struct Port *PortP;
Alan Cox554b7c82006-03-24 03:18:32 -0800741 unsigned int SubEnt;
742 unsigned int HostPort;
743 unsigned int SysPort;
744 u16 RtaType;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 unsigned long flags;
746
Andrew Morton8d8706e2006-01-11 12:17:49 -0800747 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800750 ** We need to tell the UnixRups which sysport the rup corresponds to
751 */
752 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Andrew Morton8d8706e2006-01-11 12:17:49 -0800754 if (HostMapP->SysPort == NO_PORT)
755 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800758 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 -0700759
760 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800761 ** now map each of its eight ports
762 */
763 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
764 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
765 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
766 /* portnumber on host */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Andrew Morton8d8706e2006-01-11 12:17:49 -0800768 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
769
770 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 PortP = p->RIOPortp[SysPort];
Andrew Morton8d8706e2006-01-11 12:17:49 -0800772 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800775 ** Point at all the real neat data structures
776 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 rio_spin_lock_irqsave(&PortP->portSem, flags);
778 PortP->HostP = HostP;
779 PortP->Caddr = HostP->Caddr;
780
781 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800782 ** The PhbP cannot be filled in yet
783 ** unless the host has been booted
784 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
Al Virod886cb52006-05-27 00:08:25 -0400786 struct PHB __iomem *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
787 PortP->TxAdd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
788 PortP->TxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
789 PortP->TxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
790 PortP->RxRemove = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
791 PortP->RxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
792 PortP->RxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 PortP->PhbP = NULL;
795
796 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800797 ** port related flags
798 */
799 PortP->HostPort = HostPort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800801 ** For each part of a 16 port RTA, RupNum is ID - 1.
802 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 PortP->RupNum = HostMapP->ID - 1;
804 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805 PortP->ID2 = HostMapP->ID2 - 1;
Alan Cox554b7c82006-03-24 03:18:32 -0800806 PortP->SecondBlock = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 } else {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800808 PortP->ID2 = 0;
Alan Cox554b7c82006-03-24 03:18:32 -0800809 PortP->SecondBlock = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800810 }
811 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
812
813 /*
814 ** If the port was already mapped then thats all we need to do.
815 */
816 if (PortP->Mapped) {
817 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
818 continue;
819 } else
820 HostMapP->Flags &= ~RTA_NEWBOOT;
821
822 PortP->State = 0;
823 PortP->Config = 0;
824 /*
825 ** Check out the module type - if it is special (read only etc.)
826 ** then we need to set flags in the PortP->Config.
827 ** Note: For 16 port RTA, all ports are of the same type.
828 */
829 if (RtaType == TYPE_RTA16) {
830 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
831 } else {
832 if (SubEnt < PORTS_PER_MODULE)
833 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800835 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
838 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 ** more port related flags
840 */
841 PortP->PortState = 0;
842 PortP->ModemLines = 0;
843 PortP->ModemState = 0;
844 PortP->CookMode = COOK_WELL;
845 PortP->ParamSem = 0;
846 PortP->FlushCmdBodge = 0;
847 PortP->WflushFlag = 0;
848 PortP->MagicFlags = 0;
849 PortP->Lock = 0;
850 PortP->Store = 0;
851 PortP->FirstOpen = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 ** Buffers 'n things
855 */
856 PortP->RxDataStart = 0;
857 PortP->Cor2Copy = 0;
858 PortP->Name = &HostMapP->Name[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 PortP->statsGather = 0;
860 PortP->txchars = 0;
861 PortP->rxchars = 0;
862 PortP->opens = 0;
863 PortP->closes = 0;
864 PortP->ioctls = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800865 if (PortP->TxRingBuffer)
Alan Coxe2b3afd2006-03-24 03:18:27 -0800866 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800867 else if (p->RIOBufferSize) {
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700868 PortP->TxRingBuffer = kzalloc(p->RIOBufferSize, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800870 PortP->TxBufferOut = 0;
871 PortP->TxBufferIn = 0;
872 PortP->Debug = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800874 ** LastRxTgl stores the state of the rx toggle bit for this
875 ** port, to be compared with the state of the next pkt received.
876 ** If the same, we have received the same rx pkt from the RTA
877 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
878 */
Alan Coxe2b3afd2006-03-24 03:18:27 -0800879 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
881 /*
Andrew Morton8d8706e2006-01-11 12:17:49 -0800882 ** and mark the port as usable
883 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 PortP->Mapped = 1;
885 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
886 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800887 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 p->RIOFirstPortsMapped = HostMapP->SysPort;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800889 if (HostMapP->SysPort > p->RIOLastPortsMapped)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 p->RIOLastPortsMapped = HostMapP->SysPort;
891
892 return 0;
893}
894
Alan Coxe2b3afd2006-03-24 03:18:27 -0800895int RIOChangeName(struct rio_info *p, struct Map *MapP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
897 int host;
898 struct Map *HostMapP;
899 char *sptr;
900
Andrew Morton8d8706e2006-01-11 12:17:49 -0800901 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 -0700902
Andrew Morton8d8706e2006-01-11 12:17:49 -0800903 if (MapP->ID > MAX_RUP) {
904 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
906 return -EINVAL;
907 }
908
Andrew Morton8d8706e2006-01-11 12:17:49 -0800909 MapP->Name[MAX_NAME_LEN - 1] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 sptr = MapP->Name;
911
Andrew Morton8d8706e2006-01-11 12:17:49 -0800912 while (*sptr) {
913 if (*sptr < ' ' || *sptr > '~') {
914 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
916 return -EINVAL;
917 }
918 sptr++;
919 }
920
Andrew Morton8d8706e2006-01-11 12:17:49 -0800921 for (host = 0; host < p->RIONumHosts; host++) {
922 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
923 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 p->RIOError.Error = HOST_NOT_RUNNING;
925 return -ENXIO;
926 }
Andrew Morton8d8706e2006-01-11 12:17:49 -0800927 if (MapP->ID == 0) {
Alan Cox554b7c82006-03-24 03:18:32 -0800928 memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 return 0;
930 }
931
Andrew Morton8d8706e2006-01-11 12:17:49 -0800932 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
Andrew Morton8d8706e2006-01-11 12:17:49 -0800934 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 p->RIOError.Error = RTA_NUMBER_WRONG;
936 return -ENXIO;
937 }
Alan Cox554b7c82006-03-24 03:18:32 -0800938 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return 0;
940 }
941 }
942 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800943 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 return -ENXIO;
945}