Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | |
33 | static 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" | |
1da177e4 LT |
56 | #include "pkt.h" |
57 | #include "daemon.h" | |
58 | #include "rio.h" | |
59 | #include "riospace.h" | |
1da177e4 LT |
60 | #include "cmdpkt.h" |
61 | #include "map.h" | |
1da177e4 LT |
62 | #include "rup.h" |
63 | #include "port.h" | |
64 | #include "riodrvr.h" | |
65 | #include "rioinfo.h" | |
66 | #include "func.h" | |
67 | #include "errors.h" | |
68 | #include "pci.h" | |
69 | ||
70 | #include "parmmap.h" | |
71 | #include "unixrup.h" | |
72 | #include "board.h" | |
73 | #include "host.h" | |
1da177e4 LT |
74 | #include "phb.h" |
75 | #include "link.h" | |
76 | #include "cmdblk.h" | |
77 | #include "route.h" | |
1da177e4 LT |
78 | #include "cirrus.h" |
79 | #include "rioioctl.h" | |
80 | #include "param.h" | |
1da177e4 LT |
81 | #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 | */ | |
e2b3afd6 | 87 | int RIONewTable(struct rio_info *p) |
1da177e4 LT |
88 | { |
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 | /* | |
8d8706e2 AM |
97 | ** 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 | */ | |
1da177e4 | 101 | /* |
8d8706e2 AM |
102 | ** 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) */ | |
1da177e4 LT |
117 | 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 | ||
8d8706e2 | 125 | for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { |
1da177e4 LT |
126 | MapP = &p->RIOConnectTable[Entry]; |
127 | if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) { | |
8d8706e2 AM |
128 | 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') { | |
554b7c80 | 132 | memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8); |
8d8706e2 AM |
133 | MapP->Name[5] = '0' + Entry / 10; |
134 | MapP->Name[6] = '0' + Entry % 10; | |
1da177e4 | 135 | } |
8d8706e2 AM |
136 | while (*cptr) { |
137 | if (*cptr < ' ' || *cptr > '~') { | |
1da177e4 LT |
138 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; |
139 | p->RIOError.Entry = Entry; | |
140 | return -ENXIO; | |
141 | } | |
142 | cptr++; | |
143 | } | |
144 | } | |
145 | ||
146 | /* | |
8d8706e2 AM |
147 | ** If the entry saved was a tentative entry then just forget |
148 | ** about it. | |
149 | */ | |
150 | if (MapP->Flags & SLOT_TENTATIVE) { | |
1da177e4 LT |
151 | MapP->HostUniqueNum = 0; |
152 | MapP->RtaUniqueNum = 0; | |
153 | continue; | |
154 | } | |
155 | ||
8d8706e2 AM |
156 | 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); | |
1da177e4 LT |
160 | p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL; |
161 | p->RIOError.Entry = Entry; | |
162 | return -ENXIO; | |
163 | } | |
8d8706e2 | 164 | rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n"); |
1da177e4 LT |
165 | continue; |
166 | } | |
167 | ||
8d8706e2 AM |
168 | 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) { | |
1da177e4 LT |
171 | HostP = &p->RIOHosts[Host]; |
172 | /* | |
8d8706e2 AM |
173 | ** having done the lookup, we don't really want to do |
174 | ** it again, so hang the host number in a safe place | |
175 | */ | |
1da177e4 LT |
176 | MapP->Topology[0].Unit = Host; |
177 | break; | |
178 | } | |
179 | } | |
180 | ||
8d8706e2 AM |
181 | if (Host >= p->RIONumHosts) { |
182 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum); | |
1da177e4 | 183 | MapP->HostUniqueNum = 0; |
8d8706e2 AM |
184 | /* MapP->RtaUniqueNum = 0; */ |
185 | /* MapP->ID = 0; */ | |
186 | /* MapP->Flags = 0; */ | |
187 | /* MapP->SysPort = 0; */ | |
188 | /* MapP->Name[0] = 0; */ | |
1da177e4 LT |
189 | continue; |
190 | } | |
191 | ||
8d8706e2 AM |
192 | 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; | |
1da177e4 LT |
197 | p->RIOError.Entry = Entry; |
198 | return -ENXIO; | |
199 | } | |
8d8706e2 AM |
200 | 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); | |
1da177e4 LT |
202 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; |
203 | p->RIOError.Entry = Entry; | |
204 | return -ENXIO; | |
205 | } | |
8d8706e2 AM |
206 | 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); | |
1da177e4 LT |
209 | p->RIOError.Error = DUPLICATED_RTA_ID; |
210 | p->RIOError.Entry = Entry; | |
211 | p->RIOError.Other = SubEnt; | |
212 | return -ENXIO; | |
213 | } | |
214 | /* | |
8d8706e2 AM |
215 | ** 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); | |
1da177e4 LT |
222 | p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER; |
223 | p->RIOError.Entry = Entry; | |
224 | p->RIOError.Other = SubEnt; | |
225 | return -ENXIO; | |
226 | } | |
227 | } | |
8d8706e2 | 228 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n"); |
1da177e4 | 229 | /* (7a) */ |
8d8706e2 AM |
230 | 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); | |
1da177e4 LT |
232 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
233 | p->RIOError.Entry = Entry; | |
234 | return -ENXIO; | |
235 | } | |
8d8706e2 | 236 | rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n"); |
1da177e4 | 237 | /* (7b) */ |
8d8706e2 AM |
238 | 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); | |
1da177e4 LT |
240 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; |
241 | p->RIOError.Entry = Entry; | |
242 | return -ENXIO; | |
243 | } | |
8d8706e2 AM |
244 | 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"); | |
1da177e4 | 249 | /* (8) */ |
8d8706e2 AM |
250 | 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); | |
1da177e4 LT |
252 | p->RIOError.Error = TTY_NUMBER_IN_USE; |
253 | p->RIOError.Entry = Entry; | |
254 | p->RIOError.Other = SubEnt; | |
255 | return -ENXIO; | |
256 | } | |
8d8706e2 AM |
257 | 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); | |
1da177e4 LT |
260 | p->RIOError.Error = NAME_USED_TWICE; |
261 | p->RIOError.Entry = Entry; | |
262 | p->RIOError.Other = SubEnt; | |
263 | return -ENXIO; | |
264 | } | |
265 | } | |
266 | } | |
8d8706e2 AM |
267 | } 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); | |
1da177e4 LT |
271 | p->RIOError.Error = HOST_ID_NOT_ZERO; |
272 | p->RIOError.Entry = Entry; | |
273 | return -ENXIO; | |
274 | } | |
8d8706e2 AM |
275 | if (MapP->SysPort != NO_PORT) { |
276 | rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name); | |
1da177e4 LT |
277 | p->RIOError.Error = HOST_SYSPORT_BAD; |
278 | p->RIOError.Entry = Entry; | |
279 | return -ENXIO; | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
284 | /* | |
8d8706e2 AM |
285 | ** wow! if we get here then it's a goody! |
286 | */ | |
1da177e4 LT |
287 | |
288 | /* | |
8d8706e2 AM |
289 | ** Zero the (old) entries for each host... |
290 | */ | |
291 | for (Host = 0; Host < RIO_HOSTS; Host++) { | |
292 | for (Entry = 0; Entry < MAX_RUP; Entry++) { | |
e2b3afd6 | 293 | memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map)); |
1da177e4 | 294 | } |
e2b3afd6 | 295 | memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name)); |
1da177e4 LT |
296 | } |
297 | ||
298 | /* | |
8d8706e2 AM |
299 | ** 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); | |
1da177e4 LT |
303 | MapP = &p->RIOConnectTable[Entry]; |
304 | ||
305 | /* | |
8d8706e2 AM |
306 | ** Now, if it is an empty slot ignore it! |
307 | */ | |
308 | if (MapP->HostUniqueNum == 0) | |
1da177e4 LT |
309 | continue; |
310 | ||
311 | /* | |
8d8706e2 AM |
312 | ** we saved the host number earlier, so grab it back |
313 | */ | |
1da177e4 LT |
314 | HostP = &p->RIOHosts[MapP->Topology[0].Unit]; |
315 | ||
316 | /* | |
8d8706e2 AM |
317 | ** 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); | |
554b7c80 | 321 | memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN); |
1da177e4 LT |
322 | continue; |
323 | } | |
324 | ||
325 | /* | |
8d8706e2 AM |
326 | ** 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]; | |
1da177e4 LT |
331 | |
332 | if (MapP->Flags & SLOT_IN_USE) { | |
8d8706e2 | 333 | rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name); |
1da177e4 | 334 | /* |
8d8706e2 AM |
335 | ** structure assign, then sort out the bits we shouldn't have done |
336 | */ | |
1da177e4 LT |
337 | *HostMapP = *MapP; |
338 | ||
339 | HostMapP->Flags = SLOT_IN_USE; | |
340 | if (MapP->Flags & RTA16_SECOND_SLOT) | |
341 | HostMapP->Flags |= RTA16_SECOND_SLOT; | |
342 | ||
8d8706e2 AM |
343 | RIOReMapPorts(p, HostP, HostMapP); |
344 | } else { | |
345 | rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name); | |
1da177e4 LT |
346 | } |
347 | } | |
348 | ||
8d8706e2 | 349 | for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { |
1da177e4 LT |
350 | p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry]; |
351 | } | |
352 | ||
8d8706e2 AM |
353 | for (Host = 0; Host < p->RIONumHosts; Host++) { |
354 | for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) { | |
1da177e4 LT |
355 | p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT; |
356 | p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK; | |
357 | } | |
8d8706e2 AM |
358 | 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; | |
1da177e4 LT |
362 | } |
363 | } | |
8d8706e2 | 364 | if (!p->RIOHosts[Host].Name[0]) { |
554b7c80 | 365 | memcpy(p->RIOHosts[Host].Name, "HOST 1", 7); |
1da177e4 LT |
366 | p->RIOHosts[Host].Name[5] += Host; |
367 | } | |
368 | /* | |
8d8706e2 AM |
369 | ** Check that default name assigned is unique. |
370 | */ | |
1da177e4 LT |
371 | Host1 = Host; |
372 | NameIsUnique = 0; | |
373 | while (!NameIsUnique) { | |
374 | NameIsUnique = 1; | |
8d8706e2 | 375 | for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) { |
1da177e4 LT |
376 | if (Host2 == Host) |
377 | continue; | |
378 | if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name) | |
8d8706e2 | 379 | == 0) { |
1da177e4 LT |
380 | NameIsUnique = 0; |
381 | Host1++; | |
382 | if (Host1 >= p->RIONumHosts) | |
383 | Host1 = 0; | |
384 | p->RIOHosts[Host].Name[5] = '1' + Host1; | |
385 | } | |
386 | } | |
387 | } | |
388 | /* | |
8d8706e2 AM |
389 | ** 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); | |
554b7c80 | 393 | memcpy(p->RIOHosts[Host].Name, "HOST 1", 7); |
1da177e4 LT |
394 | p->RIOHosts[Host].Name[5] += Host1; |
395 | } | |
8d8706e2 | 396 | rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name); |
1da177e4 LT |
397 | } |
398 | return 0; | |
399 | } | |
400 | ||
401 | /* | |
402 | ** User process needs the config table - build it from first | |
403 | ** principles. | |
e2b3afd6 AC |
404 | ** |
405 | * FIXME: SMP locking | |
1da177e4 | 406 | */ |
e2b3afd6 | 407 | int RIOApel(struct rio_info *p) |
1da177e4 LT |
408 | { |
409 | int Host; | |
410 | int link; | |
411 | int Rup; | |
412 | int Next = 0; | |
413 | struct Map *MapP; | |
414 | struct Host *HostP; | |
e2b3afd6 | 415 | unsigned long flags; |
8d8706e2 AM |
416 | |
417 | rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n"); | |
1da177e4 | 418 | |
e2b3afd6 | 419 | memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES); |
1da177e4 | 420 | |
8d8706e2 AM |
421 | for (Host = 0; Host < RIO_HOSTS; Host++) { |
422 | rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host); | |
1da177e4 | 423 | HostP = &p->RIOHosts[Host]; |
e2b3afd6 AC |
424 | rio_spin_lock_irqsave(&HostP->HostLock, flags); |
425 | ||
1da177e4 LT |
426 | MapP = &p->RIOConnectTable[Next++]; |
427 | MapP->HostUniqueNum = HostP->UniqueNum; | |
8d8706e2 | 428 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) |
1da177e4 LT |
429 | continue; |
430 | MapP->RtaUniqueNum = 0; | |
431 | MapP->ID = 0; | |
432 | MapP->Flags = SLOT_IN_USE; | |
433 | MapP->SysPort = NO_PORT; | |
8d8706e2 | 434 | for (link = 0; link < LINKS_PER_UNIT; link++) |
1da177e4 | 435 | MapP->Topology[link] = HostP->Topology[link]; |
554b7c80 | 436 | memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN); |
8d8706e2 AM |
437 | for (Rup = 0; Rup < MAX_RUP; Rup++) { |
438 | if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) { | |
1da177e4 | 439 | p->RIOConnectTable[Next] = HostP->Mapping[Rup]; |
8d8706e2 | 440 | if (HostP->Mapping[Rup].Flags & SLOT_IN_USE) |
1da177e4 | 441 | p->RIOConnectTable[Next].Flags |= SLOT_IN_USE; |
8d8706e2 | 442 | if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE) |
1da177e4 | 443 | p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE; |
8d8706e2 | 444 | if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT) |
1da177e4 LT |
445 | p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT; |
446 | Next++; | |
447 | } | |
448 | } | |
e2b3afd6 | 449 | rio_spin_unlock_irqrestore(&HostP->HostLock, flags); |
1da177e4 | 450 | } |
1da177e4 LT |
451 | return 0; |
452 | } | |
453 | ||
454 | /* | |
455 | ** config.rio has taken a dislike to one of the gross maps entries. | |
456 | ** if the entry is suitably inactive, then we can gob on it and remove | |
457 | ** it from the table. | |
458 | */ | |
e2b3afd6 | 459 | int RIODeleteRta(struct rio_info *p, struct Map *MapP) |
1da177e4 LT |
460 | { |
461 | int host, entry, port, link; | |
462 | int SysPort; | |
463 | struct Host *HostP; | |
464 | struct Map *HostMapP; | |
465 | struct Port *PortP; | |
466 | int work_done = 0; | |
467 | unsigned long lock_flags, sem_flags; | |
468 | ||
8d8706e2 | 469 | rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum); |
1da177e4 | 470 | |
8d8706e2 | 471 | for (host = 0; host < p->RIONumHosts; host++) { |
1da177e4 LT |
472 | HostP = &p->RIOHosts[host]; |
473 | ||
8d8706e2 | 474 | rio_spin_lock_irqsave(&HostP->HostLock, lock_flags); |
1da177e4 | 475 | |
8d8706e2 | 476 | if ((HostP->Flags & RUN_STATE) != RC_RUNNING) { |
1da177e4 LT |
477 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); |
478 | continue; | |
479 | } | |
480 | ||
8d8706e2 AM |
481 | for (entry = 0; entry < MAX_RUP; entry++) { |
482 | if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) { | |
1da177e4 | 483 | HostMapP = &HostP->Mapping[entry]; |
8d8706e2 | 484 | rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name); |
1da177e4 LT |
485 | |
486 | /* | |
8d8706e2 AM |
487 | ** Check all four links of the unit are disconnected |
488 | */ | |
489 | for (link = 0; link < LINKS_PER_UNIT; link++) { | |
490 | if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) { | |
491 | rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n"); | |
1da177e4 | 492 | p->RIOError.Error = UNIT_IS_IN_USE; |
8d8706e2 | 493 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); |
1da177e4 LT |
494 | return -EBUSY; |
495 | } | |
496 | } | |
497 | /* | |
8d8706e2 AM |
498 | ** Slot has been allocated, BUT not booted/routed/ |
499 | ** connected/selected or anything else-ed | |
500 | */ | |
1da177e4 LT |
501 | SysPort = HostMapP->SysPort; |
502 | ||
8d8706e2 AM |
503 | if (SysPort != NO_PORT) { |
504 | for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) { | |
1da177e4 | 505 | PortP = p->RIOPortp[port]; |
8d8706e2 | 506 | rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n"); |
1da177e4 | 507 | |
8d8706e2 | 508 | rio_spin_lock_irqsave(&PortP->portSem, sem_flags); |
1da177e4 LT |
509 | |
510 | PortP->Mapped = 0; | |
511 | ||
8d8706e2 | 512 | if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) { |
1da177e4 | 513 | |
8d8706e2 | 514 | rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n"); |
1da177e4 LT |
515 | PortP->TxBufferIn = PortP->TxBufferOut = 0; |
516 | /* What should I do | |
8d8706e2 AM |
517 | wakeup( &PortP->TxBufferIn ); |
518 | wakeup( &PortP->TxBufferOut); | |
519 | */ | |
1da177e4 LT |
520 | PortP->InUse = NOT_INUSE; |
521 | /* What should I do | |
8d8706e2 AM |
522 | wakeup( &PortP->InUse ); |
523 | signal(PortP->TtyP->t_pgrp,SIGKILL); | |
524 | ttyflush(PortP->TtyP,(FREAD|FWRITE)); | |
525 | */ | |
1da177e4 LT |
526 | PortP->State |= RIO_CLOSING | RIO_DELETED; |
527 | } | |
528 | ||
529 | /* | |
8d8706e2 AM |
530 | ** For the second slot of a 16 port RTA, the |
531 | ** driver needs to reset the changes made to | |
532 | ** the phb to port mappings in RIORouteRup. | |
533 | */ | |
1da177e4 | 534 | if (PortP->SecondBlock) { |
554b7c80 AC |
535 | u16 dest_unit = HostMapP->ID; |
536 | u16 dest_port = port - SysPort; | |
d886cb58 AV |
537 | u16 __iomem *TxPktP; |
538 | struct PKT __iomem *Pkt; | |
1da177e4 | 539 | |
8d8706e2 | 540 | for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) { |
1da177e4 | 541 | /* |
8d8706e2 AM |
542 | ** *TxPktP is the pointer to the |
543 | ** transmit packet on the host card. | |
544 | ** This needs to be translated into | |
545 | ** a 32 bit pointer so it can be | |
546 | ** accessed from the driver. | |
547 | */ | |
d886cb58 | 548 | Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&*TxPktP)); |
92af11cd | 549 | 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); |
e2b3afd6 AC |
550 | writew(dest_unit, &Pkt->dest_unit); |
551 | writew(dest_port, &Pkt->dest_port); | |
1da177e4 | 552 | } |
92af11cd | 553 | 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); |
e2b3afd6 | 554 | writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination); |
1da177e4 LT |
555 | } |
556 | rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags); | |
557 | } | |
558 | } | |
8d8706e2 | 559 | rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n"); |
e2b3afd6 | 560 | memset(HostMapP, 0, sizeof(struct Map)); |
1da177e4 LT |
561 | work_done++; |
562 | } | |
563 | } | |
564 | rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags); | |
565 | } | |
566 | ||
567 | /* XXXXX lock me up */ | |
8d8706e2 AM |
568 | for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) { |
569 | if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { | |
e2b3afd6 | 570 | memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map)); |
1da177e4 LT |
571 | work_done++; |
572 | } | |
8d8706e2 | 573 | if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) { |
e2b3afd6 | 574 | memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map)); |
1da177e4 LT |
575 | work_done++; |
576 | } | |
577 | } | |
8d8706e2 | 578 | if (work_done) |
1da177e4 LT |
579 | return 0; |
580 | ||
8d8706e2 | 581 | rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n"); |
1da177e4 LT |
582 | p->RIOError.Error = COULDNT_FIND_ENTRY; |
583 | return -ENXIO; | |
584 | } | |
585 | ||
8d8706e2 | 586 | int RIOAssignRta(struct rio_info *p, struct Map *MapP) |
1da177e4 | 587 | { |
8d8706e2 AM |
588 | int host; |
589 | struct Map *HostMapP; | |
590 | char *sptr; | |
591 | int link; | |
592 | ||
593 | ||
594 | 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); | |
595 | ||
554b7c80 | 596 | if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) { |
8d8706e2 AM |
597 | rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n"); |
598 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; | |
599 | return -EINVAL; | |
600 | } | |
601 | if (MapP->RtaUniqueNum == 0) { | |
602 | rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n"); | |
603 | p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO; | |
604 | return -EINVAL; | |
605 | } | |
606 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) { | |
607 | rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA); | |
608 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; | |
609 | return -EINVAL; | |
610 | } | |
611 | if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) { | |
612 | rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort); | |
613 | p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; | |
614 | return -EINVAL; | |
615 | } | |
616 | ||
617 | /* | |
618 | ** Copy the name across to the map entry. | |
619 | */ | |
620 | MapP->Name[MAX_NAME_LEN - 1] = '\0'; | |
621 | sptr = MapP->Name; | |
622 | while (*sptr) { | |
623 | if (*sptr < ' ' || *sptr > '~') { | |
624 | rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n"); | |
625 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; | |
626 | return -EINVAL; | |
1da177e4 | 627 | } |
8d8706e2 AM |
628 | sptr++; |
629 | } | |
630 | ||
631 | for (host = 0; host < p->RIONumHosts; host++) { | |
632 | if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) { | |
633 | if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) { | |
634 | p->RIOError.Error = HOST_NOT_RUNNING; | |
635 | return -ENXIO; | |
636 | } | |
1da177e4 | 637 | |
8d8706e2 AM |
638 | /* |
639 | ** Now we have a host we need to allocate an ID | |
640 | ** if the entry does not already have one. | |
641 | */ | |
554b7c80 | 642 | if (MapP->ID == (u16) - 1) { |
8d8706e2 | 643 | int nNewID; |
1da177e4 | 644 | |
8d8706e2 AM |
645 | rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name); |
646 | /* | |
647 | ** The idea here is to allow RTA's to be assigned | |
648 | ** before they actually appear on the network. | |
649 | ** This allows the addition of RTA's without having | |
650 | ** to plug them in. | |
651 | ** What we do is: | |
652 | ** - Find a free ID and allocate it to the RTA. | |
653 | ** - If this map entry is the second half of a | |
654 | ** 16 port entry then find the other half and | |
655 | ** make sure the 2 cross reference each other. | |
656 | */ | |
657 | if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) { | |
658 | p->RIOError.Error = COULDNT_FIND_ENTRY; | |
659 | return -EBUSY; | |
660 | } | |
554b7c80 | 661 | MapP->ID = (u16) nNewID + 1; |
8d8706e2 AM |
662 | rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID); |
663 | HostMapP = &p->RIOHosts[host].Mapping[nNewID]; | |
664 | HostMapP->RtaUniqueNum = MapP->RtaUniqueNum; | |
665 | HostMapP->HostUniqueNum = MapP->HostUniqueNum; | |
666 | HostMapP->ID = MapP->ID; | |
667 | for (link = 0; link < LINKS_PER_UNIT; link++) { | |
668 | HostMapP->Topology[link].Unit = ROUTE_DISCONNECT; | |
669 | HostMapP->Topology[link].Link = NO_LINK; | |
670 | } | |
671 | if (MapP->Flags & RTA16_SECOND_SLOT) { | |
672 | int unit; | |
673 | ||
674 | for (unit = 0; unit < MAX_RUP; unit++) | |
675 | if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum) | |
676 | break; | |
677 | if (unit == MAX_RUP) { | |
678 | p->RIOError.Error = COULDNT_FIND_ENTRY; | |
679 | return -EBUSY; | |
680 | } | |
681 | HostMapP->Flags |= RTA16_SECOND_SLOT; | |
682 | HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID; | |
683 | p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID; | |
684 | rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID); | |
685 | } | |
686 | } | |
687 | ||
688 | HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1]; | |
689 | ||
690 | if (HostMapP->Flags & SLOT_IN_USE) { | |
691 | rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID); | |
692 | p->RIOError.Error = ID_ALREADY_IN_USE; | |
693 | return -EBUSY; | |
694 | } | |
695 | ||
696 | /* | |
697 | ** Assign the sys ports and the name, and mark the slot as | |
698 | ** being in use. | |
699 | */ | |
700 | HostMapP->SysPort = MapP->SysPort; | |
701 | if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) | |
554b7c80 | 702 | memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN); |
8d8706e2 | 703 | HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED; |
44456d37 | 704 | #ifdef NEED_TO_FIX |
8d8706e2 | 705 | RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]); |
1da177e4 | 706 | #endif |
8d8706e2 AM |
707 | if (MapP->Flags & RTA16_SECOND_SLOT) |
708 | HostMapP->Flags |= RTA16_SECOND_SLOT; | |
709 | ||
710 | RIOReMapPorts(p, &p->RIOHosts[host], HostMapP); | |
711 | /* | |
712 | ** Adjust 2nd block of 8 phbs | |
713 | */ | |
714 | if (MapP->Flags & RTA16_SECOND_SLOT) | |
715 | RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1); | |
716 | ||
717 | if (HostMapP->SysPort != NO_PORT) { | |
718 | if (HostMapP->SysPort < p->RIOFirstPortsBooted) | |
719 | p->RIOFirstPortsBooted = HostMapP->SysPort; | |
720 | if (HostMapP->SysPort > p->RIOLastPortsBooted) | |
721 | p->RIOLastPortsBooted = HostMapP->SysPort; | |
722 | } | |
723 | if (MapP->Flags & RTA16_SECOND_SLOT) | |
724 | rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name); | |
725 | else | |
726 | rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name); | |
727 | return 0; | |
728 | } | |
1da177e4 | 729 | } |
8d8706e2 AM |
730 | p->RIOError.Error = UNKNOWN_HOST_NUMBER; |
731 | rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum); | |
732 | return -ENXIO; | |
1da177e4 LT |
733 | } |
734 | ||
735 | ||
e2b3afd6 | 736 | int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP) |
1da177e4 | 737 | { |
e2b3afd6 | 738 | struct Port *PortP; |
554b7c80 AC |
739 | unsigned int SubEnt; |
740 | unsigned int HostPort; | |
741 | unsigned int SysPort; | |
742 | u16 RtaType; | |
1da177e4 LT |
743 | unsigned long flags; |
744 | ||
8d8706e2 | 745 | rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID); |
1da177e4 LT |
746 | |
747 | /* | |
8d8706e2 AM |
748 | ** We need to tell the UnixRups which sysport the rup corresponds to |
749 | */ | |
750 | HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort; | |
1da177e4 | 751 | |
8d8706e2 AM |
752 | if (HostMapP->SysPort == NO_PORT) |
753 | return (0); | |
1da177e4 LT |
754 | |
755 | RtaType = GetUnitType(HostMapP->RtaUniqueNum); | |
8d8706e2 | 756 | rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1); |
1da177e4 LT |
757 | |
758 | /* | |
8d8706e2 AM |
759 | ** now map each of its eight ports |
760 | */ | |
761 | for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) { | |
762 | rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort); | |
763 | SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */ | |
764 | /* portnumber on host */ | |
765 | ||
766 | HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt; | |
767 | ||
768 | rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp); | |
1da177e4 | 769 | PortP = p->RIOPortp[SysPort]; |
8d8706e2 | 770 | rio_dprintk(RIO_DEBUG_TABLE, "Map port\n"); |
1da177e4 LT |
771 | |
772 | /* | |
8d8706e2 AM |
773 | ** Point at all the real neat data structures |
774 | */ | |
1da177e4 LT |
775 | rio_spin_lock_irqsave(&PortP->portSem, flags); |
776 | PortP->HostP = HostP; | |
777 | PortP->Caddr = HostP->Caddr; | |
778 | ||
779 | /* | |
8d8706e2 AM |
780 | ** The PhbP cannot be filled in yet |
781 | ** unless the host has been booted | |
782 | */ | |
1da177e4 | 783 | if ((HostP->Flags & RUN_STATE) == RC_RUNNING) { |
d886cb58 AV |
784 | struct PHB __iomem *PhbP = PortP->PhbP = &HostP->PhbP[HostPort]; |
785 | PortP->TxAdd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add)); | |
786 | PortP->TxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start)); | |
787 | PortP->TxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end)); | |
788 | PortP->RxRemove = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove)); | |
789 | PortP->RxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start)); | |
790 | PortP->RxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end)); | |
8d8706e2 | 791 | } else |
1da177e4 LT |
792 | PortP->PhbP = NULL; |
793 | ||
794 | /* | |
8d8706e2 AM |
795 | ** port related flags |
796 | */ | |
797 | PortP->HostPort = HostPort; | |
1da177e4 | 798 | /* |
8d8706e2 AM |
799 | ** For each part of a 16 port RTA, RupNum is ID - 1. |
800 | */ | |
1da177e4 LT |
801 | PortP->RupNum = HostMapP->ID - 1; |
802 | if (HostMapP->Flags & RTA16_SECOND_SLOT) { | |
8d8706e2 | 803 | PortP->ID2 = HostMapP->ID2 - 1; |
554b7c80 | 804 | PortP->SecondBlock = 1; |
8d8706e2 AM |
805 | } else { |
806 | PortP->ID2 = 0; | |
554b7c80 | 807 | PortP->SecondBlock = 0; |
1da177e4 | 808 | } |
8d8706e2 | 809 | PortP->RtaUniqueNum = HostMapP->RtaUniqueNum; |
1da177e4 LT |
810 | |
811 | /* | |
8d8706e2 AM |
812 | ** If the port was already mapped then thats all we need to do. |
813 | */ | |
1da177e4 | 814 | if (PortP->Mapped) { |
8d8706e2 | 815 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); |
1da177e4 | 816 | continue; |
8d8706e2 AM |
817 | } else |
818 | HostMapP->Flags &= ~RTA_NEWBOOT; | |
1da177e4 | 819 | |
8d8706e2 AM |
820 | PortP->State = 0; |
821 | PortP->Config = 0; | |
1da177e4 | 822 | /* |
8d8706e2 AM |
823 | ** Check out the module type - if it is special (read only etc.) |
824 | ** then we need to set flags in the PortP->Config. | |
825 | ** Note: For 16 port RTA, all ports are of the same type. | |
826 | */ | |
1da177e4 | 827 | if (RtaType == TYPE_RTA16) { |
8d8706e2 | 828 | PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE]; |
1da177e4 | 829 | } else { |
8d8706e2 AM |
830 | if (SubEnt < PORTS_PER_MODULE) |
831 | PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE]; | |
1da177e4 | 832 | else |
8d8706e2 | 833 | PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE]; |
1da177e4 LT |
834 | } |
835 | ||
836 | /* | |
8d8706e2 AM |
837 | ** more port related flags |
838 | */ | |
839 | PortP->PortState = 0; | |
840 | PortP->ModemLines = 0; | |
841 | PortP->ModemState = 0; | |
842 | PortP->CookMode = COOK_WELL; | |
843 | PortP->ParamSem = 0; | |
844 | PortP->FlushCmdBodge = 0; | |
845 | PortP->WflushFlag = 0; | |
846 | PortP->MagicFlags = 0; | |
847 | PortP->Lock = 0; | |
848 | PortP->Store = 0; | |
849 | PortP->FirstOpen = 1; | |
1da177e4 LT |
850 | |
851 | /* | |
8d8706e2 AM |
852 | ** Buffers 'n things |
853 | */ | |
854 | PortP->RxDataStart = 0; | |
855 | PortP->Cor2Copy = 0; | |
856 | PortP->Name = &HostMapP->Name[0]; | |
1da177e4 LT |
857 | PortP->statsGather = 0; |
858 | PortP->txchars = 0; | |
859 | PortP->rxchars = 0; | |
860 | PortP->opens = 0; | |
861 | PortP->closes = 0; | |
862 | PortP->ioctls = 0; | |
8d8706e2 | 863 | if (PortP->TxRingBuffer) |
e2b3afd6 | 864 | memset(PortP->TxRingBuffer, 0, p->RIOBufferSize); |
8d8706e2 | 865 | else if (p->RIOBufferSize) { |
e2b3afd6 AC |
866 | PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL); |
867 | memset(PortP->TxRingBuffer, 0, p->RIOBufferSize); | |
1da177e4 | 868 | } |
8d8706e2 AM |
869 | PortP->TxBufferOut = 0; |
870 | PortP->TxBufferIn = 0; | |
871 | PortP->Debug = 0; | |
1da177e4 | 872 | /* |
8d8706e2 AM |
873 | ** 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 | */ | |
e2b3afd6 | 878 | PortP->LastRxTgl = ~(u8) PHB_RX_TGL; |
1da177e4 LT |
879 | |
880 | /* | |
8d8706e2 AM |
881 | ** and mark the port as usable |
882 | */ | |
1da177e4 LT |
883 | PortP->Mapped = 1; |
884 | rio_spin_unlock_irqrestore(&PortP->portSem, flags); | |
885 | } | |
8d8706e2 | 886 | if (HostMapP->SysPort < p->RIOFirstPortsMapped) |
1da177e4 | 887 | p->RIOFirstPortsMapped = HostMapP->SysPort; |
8d8706e2 | 888 | if (HostMapP->SysPort > p->RIOLastPortsMapped) |
1da177e4 LT |
889 | p->RIOLastPortsMapped = HostMapP->SysPort; |
890 | ||
891 | return 0; | |
892 | } | |
893 | ||
e2b3afd6 | 894 | int RIOChangeName(struct rio_info *p, struct Map *MapP) |
1da177e4 LT |
895 | { |
896 | int host; | |
897 | struct Map *HostMapP; | |
898 | char *sptr; | |
899 | ||
8d8706e2 | 900 | 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); |
1da177e4 | 901 | |
8d8706e2 AM |
902 | if (MapP->ID > MAX_RUP) { |
903 | rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n"); | |
1da177e4 LT |
904 | p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; |
905 | return -EINVAL; | |
906 | } | |
907 | ||
8d8706e2 | 908 | MapP->Name[MAX_NAME_LEN - 1] = '\0'; |
1da177e4 LT |
909 | sptr = MapP->Name; |
910 | ||
8d8706e2 AM |
911 | while (*sptr) { |
912 | if (*sptr < ' ' || *sptr > '~') { | |
913 | rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n"); | |
1da177e4 LT |
914 | p->RIOError.Error = BAD_CHARACTER_IN_NAME; |
915 | return -EINVAL; | |
916 | } | |
917 | sptr++; | |
918 | } | |
919 | ||
8d8706e2 AM |
920 | 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) { | |
1da177e4 LT |
923 | p->RIOError.Error = HOST_NOT_RUNNING; |
924 | return -ENXIO; | |
925 | } | |
8d8706e2 | 926 | if (MapP->ID == 0) { |
554b7c80 | 927 | memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN); |
1da177e4 LT |
928 | return 0; |
929 | } | |
930 | ||
8d8706e2 | 931 | HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1]; |
1da177e4 | 932 | |
8d8706e2 | 933 | if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) { |
1da177e4 LT |
934 | p->RIOError.Error = RTA_NUMBER_WRONG; |
935 | return -ENXIO; | |
936 | } | |
554b7c80 | 937 | memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN); |
1da177e4 LT |
938 | return 0; |
939 | } | |
940 | } | |
941 | p->RIOError.Error = UNKNOWN_HOST_NUMBER; | |
8d8706e2 | 942 | rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum); |
1da177e4 LT |
943 | return -ENXIO; |
944 | } |