2 ** -----------------------------------------------------------------------------
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
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 static char *_riotable_c_sccs_
= "@(#)riotable.c 1.2";
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>
43 #include <asm/system.h>
44 #include <asm/string.h>
45 #include <asm/semaphore.h>
46 #include <asm/uaccess.h>
48 #include <linux/termios.h>
49 #include <linux/serial.h>
51 #include <linux/generic_serial.h>
54 #include "linux_compat.h"
55 #include "rio_linux.h"
84 ** A configuration table has been loaded. It is now up to us
85 ** to sort it out and use the information contained therein.
87 int RIONewTable(struct rio_info
*p
)
89 int Host
, Host1
, Host2
, NameIsUnique
, Entry
, SubEnt
;
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
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
115 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(1)\n");
116 if (p
->RIOSystemUp
) { /* (1) */
117 p
->RIOError
.Error
= HOST_HAS_ALREADY_BEEN_BOOTED
;
121 p
->RIOError
.Error
= NOTHING_WRONG_AT_ALL
;
122 p
->RIOError
.Entry
= -1;
123 p
->RIOError
.Other
= -1;
125 for (Entry
= 0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++) {
126 MapP
= &p
->RIOConnectTable
[Entry
];
127 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0) {
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') {
132 memcpy(MapP
->Name
, MapP
->RtaUniqueNum
? "RTA NN" : "HOST NN", 8);
133 MapP
->Name
[5] = '0' + Entry
/ 10;
134 MapP
->Name
[6] = '0' + Entry
% 10;
137 if (*cptr
< ' ' || *cptr
> '~') {
138 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
139 p
->RIOError
.Entry
= Entry
;
147 ** If the entry saved was a tentative entry then just forget
150 if (MapP
->Flags
& SLOT_TENTATIVE
) {
151 MapP
->HostUniqueNum
= 0;
152 MapP
->RtaUniqueNum
= 0;
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
);
160 p
->RIOError
.Error
= TABLE_ENTRY_ISNT_PROPERLY_NULL
;
161 p
->RIOError
.Entry
= Entry
;
164 rio_dprintk(RIO_DEBUG_TABLE
, "!RIO: Daemon: test (3) passes\n");
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
) {
171 HostP
= &p
->RIOHosts
[Host
];
173 ** having done the lookup, we don't really want to do
174 ** it again, so hang the host number in a safe place
176 MapP
->Topology
[0].Unit
= Host
;
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
);
183 MapP
->HostUniqueNum
= 0;
184 /* MapP->RtaUniqueNum = 0; */
186 /* MapP->Flags = 0; */
187 /* MapP->SysPort = 0; */
188 /* MapP->Name[0] = 0; */
192 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(5)\n");
193 if (MapP
->RtaUniqueNum
) { /* (5) */
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
;
197 p
->RIOError
.Entry
= Entry
;
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
);
202 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
203 p
->RIOError
.Entry
= Entry
;
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
);
209 p
->RIOError
.Error
= DUPLICATED_RTA_ID
;
210 p
->RIOError
.Entry
= Entry
;
211 p
->RIOError
.Other
= SubEnt
;
215 ** If the RtaUniqueNum is the same, it may be looking at both
216 ** entries for a 16 port RTA, so check the ids
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
);
222 p
->RIOError
.Error
= DUPLICATE_UNIQUE_NUMBER
;
223 p
->RIOError
.Entry
= Entry
;
224 p
->RIOError
.Other
= SubEnt
;
228 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(7a)\n");
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
);
232 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
233 p
->RIOError
.Entry
= Entry
;
236 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(7b)\n");
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
);
240 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
241 p
->RIOError
.Entry
= Entry
;
244 for (SubEnt
= 0; SubEnt
< Entry
; SubEnt
++) {
245 if (p
->RIOConnectTable
[SubEnt
].Flags
& RTA16_SECOND_SLOT
)
247 if (p
->RIOConnectTable
[SubEnt
].RtaUniqueNum
) {
248 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(8)\n");
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
);
252 p
->RIOError
.Error
= TTY_NUMBER_IN_USE
;
253 p
->RIOError
.Entry
= Entry
;
254 p
->RIOError
.Other
= SubEnt
;
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
);
260 p
->RIOError
.Error
= NAME_USED_TWICE
;
261 p
->RIOError
.Entry
= Entry
;
262 p
->RIOError
.Other
= SubEnt
;
268 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: entering(6)\n");
270 rio_dprintk(RIO_DEBUG_TABLE
, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP
->Name
);
271 p
->RIOError
.Error
= HOST_ID_NOT_ZERO
;
272 p
->RIOError
.Entry
= Entry
;
275 if (MapP
->SysPort
!= NO_PORT
) {
276 rio_dprintk(RIO_DEBUG_TABLE
, "RIO: HOST %s has been allocated port numbers!\n", MapP
->Name
);
277 p
->RIOError
.Error
= HOST_SYSPORT_BAD
;
278 p
->RIOError
.Entry
= Entry
;
285 ** wow! if we get here then it's a goody!
289 ** Zero the (old) entries for each host...
291 for (Host
= 0; Host
< RIO_HOSTS
; Host
++) {
292 for (Entry
= 0; Entry
< MAX_RUP
; Entry
++) {
293 memset(&p
->RIOHosts
[Host
].Mapping
[Entry
], 0, sizeof(struct Map
));
295 memset(&p
->RIOHosts
[Host
].Name
[0], 0, sizeof(p
->RIOHosts
[Host
].Name
));
299 ** Copy in the new table entries
301 for (Entry
= 0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++) {
302 rio_dprintk(RIO_DEBUG_TABLE
, "RIONewTable: Copy table for Host entry %d\n", Entry
);
303 MapP
= &p
->RIOConnectTable
[Entry
];
306 ** Now, if it is an empty slot ignore it!
308 if (MapP
->HostUniqueNum
== 0)
312 ** we saved the host number earlier, so grab it back
314 HostP
= &p
->RIOHosts
[MapP
->Topology
[0].Unit
];
317 ** If it is a host, then we only need to fill in the name field.
320 rio_dprintk(RIO_DEBUG_TABLE
, "Host entry found. Name %s\n", MapP
->Name
);
321 memcpy(HostP
->Name
, MapP
->Name
, MAX_NAME_LEN
);
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
330 HostMapP
= &HostP
->Mapping
[MapP
->ID
- 1];
332 if (MapP
->Flags
& SLOT_IN_USE
) {
333 rio_dprintk(RIO_DEBUG_TABLE
, "Rta entry found. Name %s\n", MapP
->Name
);
335 ** structure assign, then sort out the bits we shouldn't have done
339 HostMapP
->Flags
= SLOT_IN_USE
;
340 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
341 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
343 RIOReMapPorts(p
, HostP
, HostMapP
);
345 rio_dprintk(RIO_DEBUG_TABLE
, "TENTATIVE Rta entry found. Name %s\n", MapP
->Name
);
349 for (Entry
= 0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++) {
350 p
->RIOSavedTable
[Entry
] = p
->RIOConnectTable
[Entry
];
353 for (Host
= 0; Host
< p
->RIONumHosts
; Host
++) {
354 for (SubEnt
= 0; SubEnt
< LINKS_PER_UNIT
; SubEnt
++) {
355 p
->RIOHosts
[Host
].Topology
[SubEnt
].Unit
= ROUTE_DISCONNECT
;
356 p
->RIOHosts
[Host
].Topology
[SubEnt
].Link
= NO_LINK
;
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
;
364 if (!p
->RIOHosts
[Host
].Name
[0]) {
365 memcpy(p
->RIOHosts
[Host
].Name
, "HOST 1", 7);
366 p
->RIOHosts
[Host
].Name
[5] += Host
;
369 ** Check that default name assigned is unique.
373 while (!NameIsUnique
) {
375 for (Host2
= 0; Host2
< p
->RIONumHosts
; Host2
++) {
378 if (strcmp(p
->RIOHosts
[Host
].Name
, p
->RIOHosts
[Host2
].Name
)
382 if (Host1
>= p
->RIONumHosts
)
384 p
->RIOHosts
[Host
].Name
[5] = '1' + Host1
;
389 ** Rename host if name already used.
392 rio_dprintk(RIO_DEBUG_TABLE
, "Default name %s already used\n", p
->RIOHosts
[Host
].Name
);
393 memcpy(p
->RIOHosts
[Host
].Name
, "HOST 1", 7);
394 p
->RIOHosts
[Host
].Name
[5] += Host1
;
396 rio_dprintk(RIO_DEBUG_TABLE
, "Assigning default name %s\n", p
->RIOHosts
[Host
].Name
);
402 ** User process needs the config table - build it from first
407 int RIOApel(struct rio_info
*p
)
417 rio_dprintk(RIO_DEBUG_TABLE
, "Generating a table to return to config.rio\n");
419 memset(&p
->RIOConnectTable
[0], 0, sizeof(struct Map
) * TOTAL_MAP_ENTRIES
);
421 for (Host
= 0; Host
< RIO_HOSTS
; Host
++) {
422 rio_dprintk(RIO_DEBUG_TABLE
, "Processing host %d\n", Host
);
423 HostP
= &p
->RIOHosts
[Host
];
424 rio_spin_lock_irqsave(&HostP
->HostLock
, flags
);
426 MapP
= &p
->RIOConnectTable
[Next
++];
427 MapP
->HostUniqueNum
= HostP
->UniqueNum
;
428 if ((HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
429 rio_spin_unlock_irqrestore(&HostP
->HostLock
, flags
);
432 MapP
->RtaUniqueNum
= 0;
434 MapP
->Flags
= SLOT_IN_USE
;
435 MapP
->SysPort
= NO_PORT
;
436 for (link
= 0; link
< LINKS_PER_UNIT
; link
++)
437 MapP
->Topology
[link
] = HostP
->Topology
[link
];
438 memcpy(MapP
->Name
, HostP
->Name
, MAX_NAME_LEN
);
439 for (Rup
= 0; Rup
< MAX_RUP
; Rup
++) {
440 if (HostP
->Mapping
[Rup
].Flags
& (SLOT_IN_USE
| SLOT_TENTATIVE
)) {
441 p
->RIOConnectTable
[Next
] = HostP
->Mapping
[Rup
];
442 if (HostP
->Mapping
[Rup
].Flags
& SLOT_IN_USE
)
443 p
->RIOConnectTable
[Next
].Flags
|= SLOT_IN_USE
;
444 if (HostP
->Mapping
[Rup
].Flags
& SLOT_TENTATIVE
)
445 p
->RIOConnectTable
[Next
].Flags
|= SLOT_TENTATIVE
;
446 if (HostP
->Mapping
[Rup
].Flags
& RTA16_SECOND_SLOT
)
447 p
->RIOConnectTable
[Next
].Flags
|= RTA16_SECOND_SLOT
;
451 rio_spin_unlock_irqrestore(&HostP
->HostLock
, flags
);
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.
461 int RIODeleteRta(struct rio_info
*p
, struct Map
*MapP
)
463 int host
, entry
, port
, link
;
466 struct Map
*HostMapP
;
469 unsigned long lock_flags
, sem_flags
;
471 rio_dprintk(RIO_DEBUG_TABLE
, "Delete entry on host %x, rta %x\n", MapP
->HostUniqueNum
, MapP
->RtaUniqueNum
);
473 for (host
= 0; host
< p
->RIONumHosts
; host
++) {
474 HostP
= &p
->RIOHosts
[host
];
476 rio_spin_lock_irqsave(&HostP
->HostLock
, lock_flags
);
478 if ((HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
479 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
483 for (entry
= 0; entry
< MAX_RUP
; entry
++) {
484 if (MapP
->RtaUniqueNum
== HostP
->Mapping
[entry
].RtaUniqueNum
) {
485 HostMapP
= &HostP
->Mapping
[entry
];
486 rio_dprintk(RIO_DEBUG_TABLE
, "Found entry offset %d on host %s\n", entry
, HostP
->Name
);
489 ** Check all four links of the unit are disconnected
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");
494 p
->RIOError
.Error
= UNIT_IS_IN_USE
;
495 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
500 ** Slot has been allocated, BUT not booted/routed/
501 ** connected/selected or anything else-ed
503 SysPort
= HostMapP
->SysPort
;
505 if (SysPort
!= NO_PORT
) {
506 for (port
= SysPort
; port
< SysPort
+ PORTS_PER_RTA
; port
++) {
507 PortP
= p
->RIOPortp
[port
];
508 rio_dprintk(RIO_DEBUG_TABLE
, "Unmap port\n");
510 rio_spin_lock_irqsave(&PortP
->portSem
, sem_flags
);
514 if (PortP
->State
& (RIO_MOPEN
| RIO_LOPEN
)) {
516 rio_dprintk(RIO_DEBUG_TABLE
, "Gob on port\n");
517 PortP
->TxBufferIn
= PortP
->TxBufferOut
= 0;
519 wakeup( &PortP->TxBufferIn );
520 wakeup( &PortP->TxBufferOut);
522 PortP
->InUse
= NOT_INUSE
;
524 wakeup( &PortP->InUse );
525 signal(PortP->TtyP->t_pgrp,SIGKILL);
526 ttyflush(PortP->TtyP,(FREAD|FWRITE));
528 PortP
->State
|= RIO_CLOSING
| RIO_DELETED
;
532 ** 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.
536 if (PortP
->SecondBlock
) {
537 u16 dest_unit
= HostMapP
->ID
;
538 u16 dest_port
= port
- SysPort
;
540 struct PKT __iomem
*Pkt
;
542 for (TxPktP
= PortP
->TxStart
; TxPktP
<= PortP
->TxEnd
; TxPktP
++) {
544 ** *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.
550 Pkt
= (struct PKT __iomem
*) RIO_PTR(HostP
->Caddr
, readw(&*TxPktP
));
551 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
);
552 writew(dest_unit
, &Pkt
->dest_unit
);
553 writew(dest_port
, &Pkt
->dest_port
);
555 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
);
556 writew(dest_unit
+ (dest_port
<< 8), &PortP
->PhbP
->destination
);
558 rio_spin_unlock_irqrestore(&PortP
->portSem
, sem_flags
);
561 rio_dprintk(RIO_DEBUG_TABLE
, "Entry nulled.\n");
562 memset(HostMapP
, 0, sizeof(struct Map
));
566 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
569 /* XXXXX lock me up */
570 for (entry
= 0; entry
< TOTAL_MAP_ENTRIES
; entry
++) {
571 if (p
->RIOSavedTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
572 memset(&p
->RIOSavedTable
[entry
], 0, sizeof(struct Map
));
575 if (p
->RIOConnectTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
576 memset(&p
->RIOConnectTable
[entry
], 0, sizeof(struct Map
));
583 rio_dprintk(RIO_DEBUG_TABLE
, "Couldn't find entry to be deleted\n");
584 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
588 int RIOAssignRta(struct rio_info
*p
, struct Map
*MapP
)
591 struct Map
*HostMapP
;
596 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
);
598 if ((MapP
->ID
!= (u16
) - 1) && ((int) MapP
->ID
< (int) 1 || (int) MapP
->ID
> MAX_RUP
)) {
599 rio_dprintk(RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
600 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
603 if (MapP
->RtaUniqueNum
== 0) {
604 rio_dprintk(RIO_DEBUG_TABLE
, "Rta Unique number zero!\n");
605 p
->RIOError
.Error
= RTA_UNIQUE_NUMBER_ZERO
;
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
;
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
;
620 ** Copy the name across to the map entry.
622 MapP
->Name
[MAX_NAME_LEN
- 1] = '\0';
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
;
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
;
641 ** Now we have a host we need to allocate an ID
642 ** if the entry does not already have one.
644 if (MapP
->ID
== (u16
) - 1) {
647 rio_dprintk(RIO_DEBUG_TABLE
, "Attempting to get a new ID for rta \"%s\"\n", MapP
->Name
);
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
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.
659 if (RIOFindFreeID(p
, &p
->RIOHosts
[host
], &nNewID
, NULL
) != 0) {
660 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
663 MapP
->ID
= (u16
) nNewID
+ 1;
664 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
;
673 if (MapP
->Flags
& RTA16_SECOND_SLOT
) {
676 for (unit
= 0; unit
< MAX_RUP
; unit
++)
677 if (p
->RIOHosts
[host
].Mapping
[unit
].RtaUniqueNum
== MapP
->RtaUniqueNum
)
679 if (unit
== MAX_RUP
) {
680 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
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
);
690 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
- 1];
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
;
699 ** Assign the sys ports and the name, and mark the slot as
702 HostMapP
->SysPort
= MapP
->SysPort
;
703 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0)
704 memcpy(HostMapP
->Name
, MapP
->Name
, MAX_NAME_LEN
);
705 HostMapP
->Flags
= SLOT_IN_USE
| RTA_BOOTED
;
707 RIO_SV_BROADCAST(p
->RIOHosts
[host
].svFlags
[MapP
->ID
- 1]);
709 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
710 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
712 RIOReMapPorts(p
, &p
->RIOHosts
[host
], HostMapP
);
714 ** Adjust 2nd block of 8 phbs
716 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
717 RIOFixPhbs(p
, &p
->RIOHosts
[host
], HostMapP
->ID
- 1);
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
;
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
);
728 rio_dprintk(RIO_DEBUG_TABLE
, "RTA %s added to configuration\n", MapP
->Name
);
732 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
733 rio_dprintk(RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);
738 int RIOReMapPorts(struct rio_info
*p
, struct Host
*HostP
, struct Map
*HostMapP
)
742 unsigned int HostPort
;
743 unsigned int SysPort
;
747 rio_dprintk(RIO_DEBUG_TABLE
, "Mapping sysport %d to id %d\n", (int) HostMapP
->SysPort
, HostMapP
->ID
);
750 ** We need to tell the UnixRups which sysport the rup corresponds to
752 HostP
->UnixRups
[HostMapP
->ID
- 1].BaseSysPort
= HostMapP
->SysPort
;
754 if (HostMapP
->SysPort
== NO_PORT
)
757 RtaType
= GetUnitType(HostMapP
->RtaUniqueNum
);
758 rio_dprintk(RIO_DEBUG_TABLE
, "Mapping sysport %d-%d\n", (int) HostMapP
->SysPort
, (int) HostMapP
->SysPort
+ PORTS_PER_RTA
- 1);
761 ** now map each of its eight ports
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 */
768 HostPort
= (HostMapP
->ID
- 1) * PORTS_PER_RTA
+ SubEnt
;
770 rio_dprintk(RIO_DEBUG_TABLE
, "c1 p = %p, p->rioPortp = %p\n", p
, p
->RIOPortp
);
771 PortP
= p
->RIOPortp
[SysPort
];
772 rio_dprintk(RIO_DEBUG_TABLE
, "Map port\n");
775 ** Point at all the real neat data structures
777 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
778 PortP
->HostP
= HostP
;
779 PortP
->Caddr
= HostP
->Caddr
;
782 ** The PhbP cannot be filled in yet
783 ** unless the host has been booted
785 if ((HostP
->Flags
& RUN_STATE
) == RC_RUNNING
) {
786 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
));
797 ** port related flags
799 PortP
->HostPort
= HostPort
;
801 ** For each part of a 16 port RTA, RupNum is ID - 1.
803 PortP
->RupNum
= HostMapP
->ID
- 1;
804 if (HostMapP
->Flags
& RTA16_SECOND_SLOT
) {
805 PortP
->ID2
= HostMapP
->ID2
- 1;
806 PortP
->SecondBlock
= 1;
809 PortP
->SecondBlock
= 0;
811 PortP
->RtaUniqueNum
= HostMapP
->RtaUniqueNum
;
814 ** If the port was already mapped then thats all we need to do.
817 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
820 HostMapP
->Flags
&= ~RTA_NEWBOOT
;
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.
829 if (RtaType
== TYPE_RTA16
) {
830 PortP
->Config
|= p
->RIOModuleTypes
[HostP
->UnixRups
[HostMapP
->ID
- 1].ModTypes
].Flags
[SubEnt
% PORTS_PER_MODULE
];
832 if (SubEnt
< PORTS_PER_MODULE
)
833 PortP
->Config
|= p
->RIOModuleTypes
[LONYBLE(HostP
->UnixRups
[HostMapP
->ID
- 1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
835 PortP
->Config
|= p
->RIOModuleTypes
[HINYBLE(HostP
->UnixRups
[HostMapP
->ID
- 1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
839 ** more port related flags
841 PortP
->PortState
= 0;
842 PortP
->ModemLines
= 0;
843 PortP
->ModemState
= 0;
844 PortP
->CookMode
= COOK_WELL
;
846 PortP
->FlushCmdBodge
= 0;
847 PortP
->WflushFlag
= 0;
848 PortP
->MagicFlags
= 0;
851 PortP
->FirstOpen
= 1;
856 PortP
->RxDataStart
= 0;
858 PortP
->Name
= &HostMapP
->Name
[0];
859 PortP
->statsGather
= 0;
865 if (PortP
->TxRingBuffer
)
866 memset(PortP
->TxRingBuffer
, 0, p
->RIOBufferSize
);
867 else if (p
->RIOBufferSize
) {
868 PortP
->TxRingBuffer
= kzalloc(p
->RIOBufferSize
, GFP_KERNEL
);
870 PortP
->TxBufferOut
= 0;
871 PortP
->TxBufferIn
= 0;
874 ** 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.
879 PortP
->LastRxTgl
= ~(u8
) PHB_RX_TGL
;
882 ** and mark the port as usable
885 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
887 if (HostMapP
->SysPort
< p
->RIOFirstPortsMapped
)
888 p
->RIOFirstPortsMapped
= HostMapP
->SysPort
;
889 if (HostMapP
->SysPort
> p
->RIOLastPortsMapped
)
890 p
->RIOLastPortsMapped
= HostMapP
->SysPort
;
895 int RIOChangeName(struct rio_info
*p
, struct Map
*MapP
)
898 struct Map
*HostMapP
;
901 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
);
903 if (MapP
->ID
> MAX_RUP
) {
904 rio_dprintk(RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
905 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
909 MapP
->Name
[MAX_NAME_LEN
- 1] = '\0';
913 if (*sptr
< ' ' || *sptr
> '~') {
914 rio_dprintk(RIO_DEBUG_TABLE
, "Name entry contains non-printing characters!\n");
915 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
921 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
) {
924 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
928 memcpy(p
->RIOHosts
[host
].Name
, MapP
->Name
, MAX_NAME_LEN
);
932 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
- 1];
934 if (HostMapP
->RtaUniqueNum
!= MapP
->RtaUniqueNum
) {
935 p
->RIOError
.Error
= RTA_NUMBER_WRONG
;
938 memcpy(HostMapP
->Name
, MapP
->Name
, MAX_NAME_LEN
);
942 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
943 rio_dprintk(RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);