GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / rio / riotable.c
blob83e1e9d203abbedc894e810d4b16bb6095eae9d1
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 ** Perle Specialix driver for Linux
5 ** Ported from existing RIO Driver for SCO sources.
7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
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.
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.
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.
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
28 ** ident @(#)riotable.c 1.2
30 ** -----------------------------------------------------------------------------
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/errno.h>
36 #include <linux/interrupt.h>
37 #include <linux/string.h>
39 #include <asm/io.h>
40 #include <asm/system.h>
41 #include <asm/string.h>
42 #include <asm/uaccess.h>
44 #include <linux/termios.h>
45 #include <linux/serial.h>
47 #include <linux/generic_serial.h>
50 #include "linux_compat.h"
51 #include "rio_linux.h"
52 #include "pkt.h"
53 #include "daemon.h"
54 #include "rio.h"
55 #include "riospace.h"
56 #include "cmdpkt.h"
57 #include "map.h"
58 #include "rup.h"
59 #include "port.h"
60 #include "riodrvr.h"
61 #include "rioinfo.h"
62 #include "func.h"
63 #include "errors.h"
64 #include "pci.h"
66 #include "parmmap.h"
67 #include "unixrup.h"
68 #include "board.h"
69 #include "host.h"
70 #include "phb.h"
71 #include "link.h"
72 #include "cmdblk.h"
73 #include "route.h"
74 #include "cirrus.h"
75 #include "rioioctl.h"
76 #include "param.h"
77 #include "protsts.h"
80 ** A configuration table has been loaded. It is now up to us
81 ** to sort it out and use the information contained therein.
83 int RIONewTable(struct rio_info *p)
85 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
86 struct Map *MapP;
87 struct Map *HostMapP;
88 struct Host *HostP;
90 char *cptr;
93 ** We have been sent a new table to install. We need to break
94 ** it down into little bits and spread it around a bit to see
95 ** what we have got.
98 ** Things to check:
99 ** (things marked 'xx' aren't checked any more!)
100 ** (1) That there are no booted Hosts/RTAs out there.
101 ** (2) That the names are properly formed
102 ** (3) That blank entries really are.
103 ** xx (4) That hosts mentioned in the table actually exist. xx
104 ** (5) That the IDs are unique (per host).
105 ** (6) That host IDs are zero
106 ** (7) That port numbers are valid
107 ** (8) That port numbers aren't duplicated
108 ** (9) That names aren't duplicated
109 ** xx (10) That hosts that actually exist are mentioned in the table. xx
111 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
112 if (p->RIOSystemUp) { /* (1) */
113 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
114 return -EBUSY;
117 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
118 p->RIOError.Entry = -1;
119 p->RIOError.Other = -1;
121 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
122 MapP = &p->RIOConnectTable[Entry];
123 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
124 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
125 cptr = MapP->Name; /* (2) */
126 cptr[MAX_NAME_LEN - 1] = '\0';
127 if (cptr[0] == '\0') {
128 memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8);
129 MapP->Name[5] = '0' + Entry / 10;
130 MapP->Name[6] = '0' + Entry % 10;
132 while (*cptr) {
133 if (*cptr < ' ' || *cptr > '~') {
134 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
135 p->RIOError.Entry = Entry;
136 return -ENXIO;
138 cptr++;
143 ** If the entry saved was a tentative entry then just forget
144 ** about it.
146 if (MapP->Flags & SLOT_TENTATIVE) {
147 MapP->HostUniqueNum = 0;
148 MapP->RtaUniqueNum = 0;
149 continue;
152 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
153 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
154 if (MapP->ID || MapP->SysPort || MapP->Flags) {
155 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
156 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
157 p->RIOError.Entry = Entry;
158 return -ENXIO;
160 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
161 continue;
164 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
165 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
166 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
167 HostP = &p->RIOHosts[Host];
169 ** having done the lookup, we don't really want to do
170 ** it again, so hang the host number in a safe place
172 MapP->Topology[0].Unit = Host;
173 break;
177 if (Host >= p->RIONumHosts) {
178 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
179 MapP->HostUniqueNum = 0;
180 /* MapP->RtaUniqueNum = 0; */
181 /* MapP->ID = 0; */
182 /* MapP->Flags = 0; */
183 /* MapP->SysPort = 0; */
184 /* MapP->Name[0] = 0; */
185 continue;
188 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
189 if (MapP->RtaUniqueNum) { /* (5) */
190 if (!MapP->ID) {
191 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
192 p->RIOError.Error = ZERO_RTA_ID;
193 p->RIOError.Entry = Entry;
194 return -ENXIO;
196 if (MapP->ID > MAX_RUP) {
197 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
198 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
199 p->RIOError.Entry = Entry;
200 return -ENXIO;
202 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
203 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
204 rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
205 p->RIOError.Error = DUPLICATED_RTA_ID;
206 p->RIOError.Entry = Entry;
207 p->RIOError.Other = SubEnt;
208 return -ENXIO;
211 ** If the RtaUniqueNum is the same, it may be looking at both
212 ** entries for a 16 port RTA, so check the ids
214 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
215 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
216 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
217 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
218 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
219 p->RIOError.Entry = Entry;
220 p->RIOError.Other = SubEnt;
221 return -ENXIO;
224 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
225 /* (7a) */
226 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
227 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);
228 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
229 p->RIOError.Entry = Entry;
230 return -ENXIO;
232 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
233 /* (7b) */
234 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
235 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
236 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
237 p->RIOError.Entry = Entry;
238 return -ENXIO;
240 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
241 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
242 continue;
243 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
244 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
245 /* (8) */
246 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
247 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
248 p->RIOError.Error = TTY_NUMBER_IN_USE;
249 p->RIOError.Entry = Entry;
250 p->RIOError.Other = SubEnt;
251 return -ENXIO;
253 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
254 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
255 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
256 p->RIOError.Error = NAME_USED_TWICE;
257 p->RIOError.Entry = Entry;
258 p->RIOError.Other = SubEnt;
259 return -ENXIO;
263 } else { /* (6) */
264 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
265 if (MapP->ID) {
266 rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
267 p->RIOError.Error = HOST_ID_NOT_ZERO;
268 p->RIOError.Entry = Entry;
269 return -ENXIO;
271 if (MapP->SysPort != NO_PORT) {
272 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
273 p->RIOError.Error = HOST_SYSPORT_BAD;
274 p->RIOError.Entry = Entry;
275 return -ENXIO;
281 ** wow! if we get here then it's a goody!
285 ** Zero the (old) entries for each host...
287 for (Host = 0; Host < RIO_HOSTS; Host++) {
288 for (Entry = 0; Entry < MAX_RUP; Entry++) {
289 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
291 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
295 ** Copy in the new table entries
297 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
298 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
299 MapP = &p->RIOConnectTable[Entry];
302 ** Now, if it is an empty slot ignore it!
304 if (MapP->HostUniqueNum == 0)
305 continue;
308 ** we saved the host number earlier, so grab it back
310 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
313 ** If it is a host, then we only need to fill in the name field.
315 if (MapP->ID == 0) {
316 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
317 memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN);
318 continue;
322 ** Its an RTA entry, so fill in the host mapping entries for it
323 ** and the port mapping entries. Notice that entry zero is for
324 ** ID one.
326 HostMapP = &HostP->Mapping[MapP->ID - 1];
328 if (MapP->Flags & SLOT_IN_USE) {
329 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
331 ** structure assign, then sort out the bits we shouldn't have done
333 *HostMapP = *MapP;
335 HostMapP->Flags = SLOT_IN_USE;
336 if (MapP->Flags & RTA16_SECOND_SLOT)
337 HostMapP->Flags |= RTA16_SECOND_SLOT;
339 RIOReMapPorts(p, HostP, HostMapP);
340 } else {
341 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
345 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
346 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
349 for (Host = 0; Host < p->RIONumHosts; Host++) {
350 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
351 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
352 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
354 for (Entry = 0; Entry < MAX_RUP; Entry++) {
355 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
356 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
357 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
360 if (!p->RIOHosts[Host].Name[0]) {
361 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
362 p->RIOHosts[Host].Name[5] += Host;
365 ** Check that default name assigned is unique.
367 Host1 = Host;
368 NameIsUnique = 0;
369 while (!NameIsUnique) {
370 NameIsUnique = 1;
371 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
372 if (Host2 == Host)
373 continue;
374 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
375 == 0) {
376 NameIsUnique = 0;
377 Host1++;
378 if (Host1 >= p->RIONumHosts)
379 Host1 = 0;
380 p->RIOHosts[Host].Name[5] = '1' + Host1;
385 ** Rename host if name already used.
387 if (Host1 != Host) {
388 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
389 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
390 p->RIOHosts[Host].Name[5] += Host1;
392 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
394 return 0;
397 int RIOApel(struct rio_info *p)
399 int Host;
400 int link;
401 int Rup;
402 int Next = 0;
403 struct Map *MapP;
404 struct Host *HostP;
405 unsigned long flags;
407 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
409 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
411 for (Host = 0; Host < RIO_HOSTS; Host++) {
412 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
413 HostP = &p->RIOHosts[Host];
414 rio_spin_lock_irqsave(&HostP->HostLock, flags);
416 MapP = &p->RIOConnectTable[Next++];
417 MapP->HostUniqueNum = HostP->UniqueNum;
418 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
419 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
420 continue;
422 MapP->RtaUniqueNum = 0;
423 MapP->ID = 0;
424 MapP->Flags = SLOT_IN_USE;
425 MapP->SysPort = NO_PORT;
426 for (link = 0; link < LINKS_PER_UNIT; link++)
427 MapP->Topology[link] = HostP->Topology[link];
428 memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN);
429 for (Rup = 0; Rup < MAX_RUP; Rup++) {
430 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
431 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
432 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
433 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
434 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
435 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
436 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
437 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
438 Next++;
441 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
443 return 0;
447 ** config.rio has taken a dislike to one of the gross maps entries.
448 ** if the entry is suitably inactive, then we can gob on it and remove
449 ** it from the table.
451 int RIODeleteRta(struct rio_info *p, struct Map *MapP)
453 int host, entry, port, link;
454 int SysPort;
455 struct Host *HostP;
456 struct Map *HostMapP;
457 struct Port *PortP;
458 int work_done = 0;
459 unsigned long lock_flags, sem_flags;
461 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
463 for (host = 0; host < p->RIONumHosts; host++) {
464 HostP = &p->RIOHosts[host];
466 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
468 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
469 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
470 continue;
473 for (entry = 0; entry < MAX_RUP; entry++) {
474 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
475 HostMapP = &HostP->Mapping[entry];
476 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
479 ** Check all four links of the unit are disconnected
481 for (link = 0; link < LINKS_PER_UNIT; link++) {
482 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
483 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
484 p->RIOError.Error = UNIT_IS_IN_USE;
485 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
486 return -EBUSY;
490 ** Slot has been allocated, BUT not booted/routed/
491 ** connected/selected or anything else-ed
493 SysPort = HostMapP->SysPort;
495 if (SysPort != NO_PORT) {
496 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
497 PortP = p->RIOPortp[port];
498 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
500 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
502 PortP->Mapped = 0;
504 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
506 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
507 PortP->TxBufferIn = PortP->TxBufferOut = 0;
508 /* What should I do
509 wakeup( &PortP->TxBufferIn );
510 wakeup( &PortP->TxBufferOut);
512 PortP->InUse = NOT_INUSE;
513 /* What should I do
514 wakeup( &PortP->InUse );
515 signal(PortP->TtyP->t_pgrp,SIGKILL);
516 ttyflush(PortP->TtyP,(FREAD|FWRITE));
518 PortP->State |= RIO_CLOSING | RIO_DELETED;
522 ** For the second slot of a 16 port RTA, the
523 ** driver needs to reset the changes made to
524 ** the phb to port mappings in RIORouteRup.
526 if (PortP->SecondBlock) {
527 u16 dest_unit = HostMapP->ID;
528 u16 dest_port = port - SysPort;
529 u16 __iomem *TxPktP;
530 struct PKT __iomem *Pkt;
532 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
534 ** *TxPktP is the pointer to the
535 ** transmit packet on the host card.
536 ** This needs to be translated into
537 ** a 32 bit pointer so it can be
538 ** accessed from the driver.
540 Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
541 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);
542 writew(dest_unit, &Pkt->dest_unit);
543 writew(dest_port, &Pkt->dest_port);
545 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);
546 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
548 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
551 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
552 memset(HostMapP, 0, sizeof(struct Map));
553 work_done++;
556 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
559 /* XXXXX lock me up */
560 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
561 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
562 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
563 work_done++;
565 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
566 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
567 work_done++;
570 if (work_done)
571 return 0;
573 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
574 p->RIOError.Error = COULDNT_FIND_ENTRY;
575 return -ENXIO;
578 int RIOAssignRta(struct rio_info *p, struct Map *MapP)
580 int host;
581 struct Map *HostMapP;
582 char *sptr;
583 int link;
586 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);
588 if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
589 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
590 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
591 return -EINVAL;
593 if (MapP->RtaUniqueNum == 0) {
594 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
595 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
596 return -EINVAL;
598 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
599 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
600 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
601 return -EINVAL;
603 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
604 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
605 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
606 return -EINVAL;
610 ** Copy the name across to the map entry.
612 MapP->Name[MAX_NAME_LEN - 1] = '\0';
613 sptr = MapP->Name;
614 while (*sptr) {
615 if (*sptr < ' ' || *sptr > '~') {
616 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
617 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
618 return -EINVAL;
620 sptr++;
623 for (host = 0; host < p->RIONumHosts; host++) {
624 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
625 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
626 p->RIOError.Error = HOST_NOT_RUNNING;
627 return -ENXIO;
631 ** Now we have a host we need to allocate an ID
632 ** if the entry does not already have one.
634 if (MapP->ID == (u16) - 1) {
635 int nNewID;
637 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
639 ** The idea here is to allow RTA's to be assigned
640 ** before they actually appear on the network.
641 ** This allows the addition of RTA's without having
642 ** to plug them in.
643 ** What we do is:
644 ** - Find a free ID and allocate it to the RTA.
645 ** - If this map entry is the second half of a
646 ** 16 port entry then find the other half and
647 ** make sure the 2 cross reference each other.
649 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
650 p->RIOError.Error = COULDNT_FIND_ENTRY;
651 return -EBUSY;
653 MapP->ID = (u16) nNewID + 1;
654 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
655 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
656 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
657 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
658 HostMapP->ID = MapP->ID;
659 for (link = 0; link < LINKS_PER_UNIT; link++) {
660 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
661 HostMapP->Topology[link].Link = NO_LINK;
663 if (MapP->Flags & RTA16_SECOND_SLOT) {
664 int unit;
666 for (unit = 0; unit < MAX_RUP; unit++)
667 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
668 break;
669 if (unit == MAX_RUP) {
670 p->RIOError.Error = COULDNT_FIND_ENTRY;
671 return -EBUSY;
673 HostMapP->Flags |= RTA16_SECOND_SLOT;
674 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
675 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
676 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
680 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
682 if (HostMapP->Flags & SLOT_IN_USE) {
683 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
684 p->RIOError.Error = ID_ALREADY_IN_USE;
685 return -EBUSY;
689 ** Assign the sys ports and the name, and mark the slot as
690 ** being in use.
692 HostMapP->SysPort = MapP->SysPort;
693 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
694 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
695 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
696 #ifdef NEED_TO_FIX
697 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
698 #endif
699 if (MapP->Flags & RTA16_SECOND_SLOT)
700 HostMapP->Flags |= RTA16_SECOND_SLOT;
702 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
704 ** Adjust 2nd block of 8 phbs
706 if (MapP->Flags & RTA16_SECOND_SLOT)
707 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
709 if (HostMapP->SysPort != NO_PORT) {
710 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
711 p->RIOFirstPortsBooted = HostMapP->SysPort;
712 if (HostMapP->SysPort > p->RIOLastPortsBooted)
713 p->RIOLastPortsBooted = HostMapP->SysPort;
715 if (MapP->Flags & RTA16_SECOND_SLOT)
716 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
717 else
718 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
719 return 0;
722 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
723 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
724 return -ENXIO;
728 int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
730 struct Port *PortP;
731 unsigned int SubEnt;
732 unsigned int HostPort;
733 unsigned int SysPort;
734 u16 RtaType;
735 unsigned long flags;
737 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
740 ** We need to tell the UnixRups which sysport the rup corresponds to
742 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
744 if (HostMapP->SysPort == NO_PORT)
745 return (0);
747 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
748 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
751 ** now map each of its eight ports
753 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
754 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
755 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
756 /* portnumber on host */
758 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
760 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
761 PortP = p->RIOPortp[SysPort];
762 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
765 ** Point at all the real neat data structures
767 rio_spin_lock_irqsave(&PortP->portSem, flags);
768 PortP->HostP = HostP;
769 PortP->Caddr = HostP->Caddr;
772 ** The PhbP cannot be filled in yet
773 ** unless the host has been booted
775 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
776 struct PHB __iomem *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
777 PortP->TxAdd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
778 PortP->TxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
779 PortP->TxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
780 PortP->RxRemove = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
781 PortP->RxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
782 PortP->RxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
783 } else
784 PortP->PhbP = NULL;
787 ** port related flags
789 PortP->HostPort = HostPort;
791 ** For each part of a 16 port RTA, RupNum is ID - 1.
793 PortP->RupNum = HostMapP->ID - 1;
794 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
795 PortP->ID2 = HostMapP->ID2 - 1;
796 PortP->SecondBlock = 1;
797 } else {
798 PortP->ID2 = 0;
799 PortP->SecondBlock = 0;
801 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
804 ** If the port was already mapped then thats all we need to do.
806 if (PortP->Mapped) {
807 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
808 continue;
809 } else
810 HostMapP->Flags &= ~RTA_NEWBOOT;
812 PortP->State = 0;
813 PortP->Config = 0;
815 ** Check out the module type - if it is special (read only etc.)
816 ** then we need to set flags in the PortP->Config.
817 ** Note: For 16 port RTA, all ports are of the same type.
819 if (RtaType == TYPE_RTA16) {
820 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
821 } else {
822 if (SubEnt < PORTS_PER_MODULE)
823 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
824 else
825 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
829 ** more port related flags
831 PortP->PortState = 0;
832 PortP->ModemLines = 0;
833 PortP->ModemState = 0;
834 PortP->CookMode = COOK_WELL;
835 PortP->ParamSem = 0;
836 PortP->FlushCmdBodge = 0;
837 PortP->WflushFlag = 0;
838 PortP->MagicFlags = 0;
839 PortP->Lock = 0;
840 PortP->Store = 0;
841 PortP->FirstOpen = 1;
844 ** Buffers 'n things
846 PortP->RxDataStart = 0;
847 PortP->Cor2Copy = 0;
848 PortP->Name = &HostMapP->Name[0];
849 PortP->statsGather = 0;
850 PortP->txchars = 0;
851 PortP->rxchars = 0;
852 PortP->opens = 0;
853 PortP->closes = 0;
854 PortP->ioctls = 0;
855 if (PortP->TxRingBuffer)
856 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
857 else if (p->RIOBufferSize) {
858 PortP->TxRingBuffer = kzalloc(p->RIOBufferSize, GFP_KERNEL);
860 PortP->TxBufferOut = 0;
861 PortP->TxBufferIn = 0;
862 PortP->Debug = 0;
864 ** LastRxTgl stores the state of the rx toggle bit for this
865 ** port, to be compared with the state of the next pkt received.
866 ** If the same, we have received the same rx pkt from the RTA
867 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
869 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
872 ** and mark the port as usable
874 PortP->Mapped = 1;
875 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
877 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
878 p->RIOFirstPortsMapped = HostMapP->SysPort;
879 if (HostMapP->SysPort > p->RIOLastPortsMapped)
880 p->RIOLastPortsMapped = HostMapP->SysPort;
882 return 0;
885 int RIOChangeName(struct rio_info *p, struct Map *MapP)
887 int host;
888 struct Map *HostMapP;
889 char *sptr;
891 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);
893 if (MapP->ID > MAX_RUP) {
894 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
895 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
896 return -EINVAL;
899 MapP->Name[MAX_NAME_LEN - 1] = '\0';
900 sptr = MapP->Name;
902 while (*sptr) {
903 if (*sptr < ' ' || *sptr > '~') {
904 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
905 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
906 return -EINVAL;
908 sptr++;
911 for (host = 0; host < p->RIONumHosts; host++) {
912 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
913 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
914 p->RIOError.Error = HOST_NOT_RUNNING;
915 return -ENXIO;
917 if (MapP->ID == 0) {
918 memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN);
919 return 0;
922 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
924 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
925 p->RIOError.Error = RTA_NUMBER_WRONG;
926 return -ENXIO;
928 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
929 return 0;
932 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
933 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
934 return -ENXIO;