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"
91 ** A configuration table has been loaded. It is now up to us
92 ** to sort it out and use the information contained therein.
98 int Host
, Host1
, Host2
, NameIsUnique
, Entry
, SubEnt
;
100 struct Map
*HostMapP
;
106 ** We have been sent a new table to install. We need to break
107 ** it down into little bits and spread it around a bit to see
112 ** (things marked 'xx' aren't checked any more!)
113 ** (1) That there are no booted Hosts/RTAs out there.
114 ** (2) That the names are properly formed
115 ** (3) That blank entries really are.
116 ** xx (4) That hosts mentioned in the table actually exist. xx
117 ** (5) That the IDs are unique (per host).
118 ** (6) That host IDs are zero
119 ** (7) That port numbers are valid
120 ** (8) That port numbers aren't duplicated
121 ** (9) That names aren't duplicated
122 ** xx (10) That hosts that actually exist are mentioned in the table. xx
124 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(1)\n");
125 if ( p
->RIOSystemUp
) { /* (1) */
126 p
->RIOError
.Error
= HOST_HAS_ALREADY_BEEN_BOOTED
;
130 p
->RIOError
.Error
= NOTHING_WRONG_AT_ALL
;
131 p
->RIOError
.Entry
= -1;
132 p
->RIOError
.Other
= -1;
134 for ( Entry
=0; Entry
<TOTAL_MAP_ENTRIES
; Entry
++ ) {
135 MapP
= &p
->RIOConnectTable
[Entry
];
136 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0) {
137 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(2)\n");
138 cptr
= MapP
->Name
; /* (2) */
139 cptr
[MAX_NAME_LEN
-1]='\0';
140 if ( cptr
[0]=='\0' ) {
141 bcopy(MapP
->RtaUniqueNum
?"RTA NN":"HOST NN",MapP
->Name
,8);
142 MapP
->Name
[5] = '0'+Entry
/10;
143 MapP
->Name
[6] = '0'+Entry
%10;
146 if ( *cptr
<' ' || *cptr
>'~' ) {
147 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
148 p
->RIOError
.Entry
= Entry
;
156 ** If the entry saved was a tentative entry then just forget
159 if ( MapP
->Flags
& SLOT_TENTATIVE
) {
160 MapP
->HostUniqueNum
= 0;
161 MapP
->RtaUniqueNum
= 0;
165 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(3)\n");
166 if ( !MapP
->RtaUniqueNum
&& !MapP
->HostUniqueNum
) { /* (3) */
167 if ( MapP
->ID
|| MapP
->SysPort
|| MapP
->Flags
) {
168 rio_dprintk (RIO_DEBUG_TABLE
, "%s pretending to be empty but isn't\n",MapP
->Name
);
169 p
->RIOError
.Error
= TABLE_ENTRY_ISNT_PROPERLY_NULL
;
170 p
->RIOError
.Entry
= Entry
;
173 rio_dprintk (RIO_DEBUG_TABLE
, "!RIO: Daemon: test (3) passes\n");
177 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(4)\n");
178 for ( Host
=0; Host
<p
->RIONumHosts
; Host
++ ) { /* (4) */
179 if ( p
->RIOHosts
[Host
].UniqueNum
==MapP
->HostUniqueNum
) {
180 HostP
= &p
->RIOHosts
[Host
];
182 ** having done the lookup, we don't really want to do
183 ** it again, so hang the host number in a safe place
185 MapP
->Topology
[0].Unit
= Host
;
190 if ( Host
>= p
->RIONumHosts
) {
191 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has unknown host unique number 0x%x\n",
192 MapP
->Name
, MapP
->HostUniqueNum
);
193 MapP
->HostUniqueNum
= 0;
194 /* MapP->RtaUniqueNum = 0; */
196 /* MapP->Flags = 0; */
197 /* MapP->SysPort = 0; */
198 /* MapP->Name[0] = 0; */
202 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(5)\n");
203 if ( MapP
->RtaUniqueNum
) { /* (5) */
205 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: RTA %s has been allocated an ID of zero!\n",
207 p
->RIOError
.Error
= ZERO_RTA_ID
;
208 p
->RIOError
.Entry
= Entry
;
211 if ( MapP
->ID
> MAX_RUP
) {
212 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: RTA %s has been allocated an invalid ID %d\n",
213 MapP
->Name
, MapP
->ID
);
214 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
215 p
->RIOError
.Entry
= Entry
;
218 for ( SubEnt
=0; SubEnt
<Entry
; SubEnt
++ ) {
219 if ( MapP
->HostUniqueNum
==
220 p
->RIOConnectTable
[SubEnt
].HostUniqueNum
&&
221 MapP
->ID
== p
->RIOConnectTable
[SubEnt
].ID
) {
222 rio_dprintk (RIO_DEBUG_TABLE
, "Dupl. ID number allocated to RTA %s and RTA %s\n",
223 MapP
->Name
, p
->RIOConnectTable
[SubEnt
].Name
);
224 p
->RIOError
.Error
= DUPLICATED_RTA_ID
;
225 p
->RIOError
.Entry
= Entry
;
226 p
->RIOError
.Other
= SubEnt
;
230 ** If the RtaUniqueNum is the same, it may be looking at both
231 ** entries for a 16 port RTA, so check the ids
233 if ((MapP
->RtaUniqueNum
==
234 p
->RIOConnectTable
[SubEnt
].RtaUniqueNum
)
235 && (MapP
->ID2
!= p
->RIOConnectTable
[SubEnt
].ID
)) {
236 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has duplicate unique number\n",MapP
->Name
);
237 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has duplicate unique number\n",
238 p
->RIOConnectTable
[SubEnt
].Name
);
239 p
->RIOError
.Error
= DUPLICATE_UNIQUE_NUMBER
;
240 p
->RIOError
.Entry
= Entry
;
241 p
->RIOError
.Other
= SubEnt
;
245 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(7a)\n");
247 if ((MapP
->SysPort
!= NO_PORT
)&&(MapP
->SysPort
% PORTS_PER_RTA
)) {
248 rio_dprintk (RIO_DEBUG_TABLE
, "TTY Port number %d-RTA %s is not a multiple of %d!\n",
249 (int)MapP
->SysPort
,MapP
->Name
, PORTS_PER_RTA
);
250 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
251 p
->RIOError
.Entry
= Entry
;
254 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(7b)\n");
256 if ((MapP
->SysPort
!= NO_PORT
)&&(MapP
->SysPort
>= RIO_PORTS
)) {
257 rio_dprintk (RIO_DEBUG_TABLE
, "TTY Port number %d for RTA %s is too big\n",
258 (int)MapP
->SysPort
, MapP
->Name
);
259 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
260 p
->RIOError
.Entry
= Entry
;
263 for ( SubEnt
=0; SubEnt
<Entry
; SubEnt
++ ) {
264 if ( p
->RIOConnectTable
[SubEnt
].Flags
& RTA16_SECOND_SLOT
)
266 if ( p
->RIOConnectTable
[SubEnt
].RtaUniqueNum
) {
267 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(8)\n");
269 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
==
270 p
->RIOConnectTable
[SubEnt
].SysPort
) ) {
271 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s:same TTY port # as RTA %s (%d)\n",
272 MapP
->Name
, p
->RIOConnectTable
[SubEnt
].Name
,
274 p
->RIOError
.Error
= TTY_NUMBER_IN_USE
;
275 p
->RIOError
.Entry
= Entry
;
276 p
->RIOError
.Other
= SubEnt
;
279 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(9)\n");
280 if (strcmp(MapP
->Name
,
281 p
->RIOConnectTable
[SubEnt
].Name
)==0 && !(MapP
->Flags
& RTA16_SECOND_SLOT
)) { /* (9) */
282 rio_dprintk (RIO_DEBUG_TABLE
, "RTA name %s used twice\n", MapP
->Name
);
283 p
->RIOError
.Error
= NAME_USED_TWICE
;
284 p
->RIOError
.Entry
= Entry
;
285 p
->RIOError
.Other
= SubEnt
;
292 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(6)\n");
294 rio_dprintk (RIO_DEBUG_TABLE
, "RIO:HOST %s has been allocated ID that isn't zero!\n",
296 p
->RIOError
.Error
= HOST_ID_NOT_ZERO
;
297 p
->RIOError
.Entry
= Entry
;
300 if ( MapP
->SysPort
!= NO_PORT
) {
301 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: HOST %s has been allocated port numbers!\n",
303 p
->RIOError
.Error
= HOST_SYSPORT_BAD
;
304 p
->RIOError
.Entry
= Entry
;
311 ** wow! if we get here then it's a goody!
315 ** Zero the (old) entries for each host...
317 for ( Host
=0; Host
<RIO_HOSTS
; Host
++ ) {
318 for ( Entry
=0; Entry
<MAX_RUP
; Entry
++ ) {
319 bzero((caddr_t
)&p
->RIOHosts
[Host
].Mapping
[Entry
],
322 bzero((caddr_t
)&p
->RIOHosts
[Host
].Name
[0],
323 sizeof(p
->RIOHosts
[Host
].Name
) );
327 ** Copy in the new table entries
329 for ( Entry
=0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++ ) {
330 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: Copy table for Host entry %d\n", Entry
);
331 MapP
= &p
->RIOConnectTable
[Entry
];
334 ** Now, if it is an empty slot ignore it!
336 if ( MapP
->HostUniqueNum
==0 )
340 ** we saved the host number earlier, so grab it back
342 HostP
= &p
->RIOHosts
[MapP
->Topology
[0].Unit
];
345 ** If it is a host, then we only need to fill in the name field.
348 rio_dprintk (RIO_DEBUG_TABLE
, "Host entry found. Name %s\n", MapP
->Name
);
349 bcopy(MapP
->Name
,HostP
->Name
,MAX_NAME_LEN
);
354 ** Its an RTA entry, so fill in the host mapping entries for it
355 ** and the port mapping entries. Notice that entry zero is for
358 HostMapP
= &HostP
->Mapping
[MapP
->ID
-1];
360 if (MapP
->Flags
& SLOT_IN_USE
) {
361 rio_dprintk (RIO_DEBUG_TABLE
, "Rta entry found. Name %s\n", MapP
->Name
);
363 ** structure assign, then sort out the bits we shouldn't have done
367 HostMapP
->Flags
= SLOT_IN_USE
;
368 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
369 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
371 RIOReMapPorts(p
, HostP
, HostMapP
);
374 rio_dprintk (RIO_DEBUG_TABLE
, "TENTATIVE Rta entry found. Name %s\n", MapP
->Name
);
378 for ( Entry
=0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++ ) {
379 p
->RIOSavedTable
[Entry
] = p
->RIOConnectTable
[Entry
];
382 for ( Host
=0; Host
<p
->RIONumHosts
; Host
++ ) {
383 for ( SubEnt
=0; SubEnt
<LINKS_PER_UNIT
; SubEnt
++ ) {
384 p
->RIOHosts
[Host
].Topology
[SubEnt
].Unit
= ROUTE_DISCONNECT
;
385 p
->RIOHosts
[Host
].Topology
[SubEnt
].Link
= NO_LINK
;
387 for ( Entry
=0; Entry
<MAX_RUP
; Entry
++ ) {
388 for ( SubEnt
=0; SubEnt
<LINKS_PER_UNIT
; SubEnt
++ ) {
389 p
->RIOHosts
[Host
].Mapping
[Entry
].Topology
[SubEnt
].Unit
=
391 p
->RIOHosts
[Host
].Mapping
[Entry
].Topology
[SubEnt
].Link
=
395 if ( !p
->RIOHosts
[Host
].Name
[0] ) {
396 bcopy("HOST 1",p
->RIOHosts
[Host
].Name
,7);
397 p
->RIOHosts
[Host
].Name
[5] += Host
;
400 ** Check that default name assigned is unique.
404 while (!NameIsUnique
) {
406 for ( Host2
=0; Host2
<p
->RIONumHosts
; Host2
++ ) {
409 if (strcmp(p
->RIOHosts
[Host
].Name
, p
->RIOHosts
[Host2
].Name
)
413 if (Host1
>= p
->RIONumHosts
)
415 p
->RIOHosts
[Host
].Name
[5] = '1' + Host1
;
420 ** Rename host if name already used.
424 rio_dprintk (RIO_DEBUG_TABLE
, "Default name %s already used\n", p
->RIOHosts
[Host
].Name
);
425 bcopy("HOST 1",p
->RIOHosts
[Host
].Name
,7);
426 p
->RIOHosts
[Host
].Name
[5] += Host1
;
428 rio_dprintk (RIO_DEBUG_TABLE
, "Assigning default name %s\n", p
->RIOHosts
[Host
].Name
);
434 ** User process needs the config table - build it from first
449 disable(oldspl
); /* strange but true! */
451 rio_dprintk (RIO_DEBUG_TABLE
, "Generating a table to return to config.rio\n");
453 bzero((caddr_t
)&p
->RIOConnectTable
[0],
454 sizeof(struct Map
) * TOTAL_MAP_ENTRIES
);
456 for ( Host
=0; Host
<RIO_HOSTS
; Host
++ ) {
457 rio_dprintk (RIO_DEBUG_TABLE
, "Processing host %d\n", Host
);
458 HostP
= &p
->RIOHosts
[Host
];
459 MapP
= &p
->RIOConnectTable
[Next
++];
460 MapP
->HostUniqueNum
= HostP
->UniqueNum
;
461 if ( (HostP
->Flags
& RUN_STATE
) != RC_RUNNING
)
463 MapP
->RtaUniqueNum
= 0;
465 MapP
->Flags
= SLOT_IN_USE
;
466 MapP
->SysPort
= NO_PORT
;
467 for ( link
=0; link
<LINKS_PER_UNIT
; link
++ )
468 MapP
->Topology
[link
] = HostP
->Topology
[link
];
469 bcopy(HostP
->Name
,MapP
->Name
,MAX_NAME_LEN
);
470 for ( Rup
=0; Rup
<MAX_RUP
; Rup
++ ) {
471 if ( HostP
->Mapping
[Rup
].Flags
& (SLOT_IN_USE
|SLOT_TENTATIVE
) ) {
472 p
->RIOConnectTable
[Next
] = HostP
->Mapping
[Rup
];
473 if ( HostP
->Mapping
[Rup
].Flags
& SLOT_IN_USE
)
474 p
->RIOConnectTable
[Next
].Flags
|= SLOT_IN_USE
;
475 if ( HostP
->Mapping
[Rup
].Flags
& SLOT_TENTATIVE
)
476 p
->RIOConnectTable
[Next
].Flags
|= SLOT_TENTATIVE
;
477 if ( HostP
->Mapping
[Rup
].Flags
& RTA16_SECOND_SLOT
)
478 p
->RIOConnectTable
[Next
].Flags
|= RTA16_SECOND_SLOT
;
488 ** config.rio has taken a dislike to one of the gross maps entries.
489 ** if the entry is suitably inactive, then we can gob on it and remove
490 ** it from the table.
493 RIODeleteRta(p
, MapP
)
497 int host
, entry
, port
, link
;
500 struct Map
*HostMapP
;
503 unsigned long lock_flags
, sem_flags
;
505 rio_dprintk (RIO_DEBUG_TABLE
, "Delete entry on host %x, rta %x\n",
506 MapP
->HostUniqueNum
, MapP
->RtaUniqueNum
);
508 for ( host
=0; host
< p
->RIONumHosts
; host
++ ) {
509 HostP
= &p
->RIOHosts
[host
];
511 rio_spin_lock_irqsave( &HostP
->HostLock
, lock_flags
);
513 if ( (HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
514 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
518 for ( entry
=0; entry
<MAX_RUP
; entry
++ ) {
519 if ( MapP
->RtaUniqueNum
== HostP
->Mapping
[entry
].RtaUniqueNum
) {
520 HostMapP
= &HostP
->Mapping
[entry
];
521 rio_dprintk (RIO_DEBUG_TABLE
, "Found entry offset %d on host %s\n",
525 ** Check all four links of the unit are disconnected
527 for ( link
=0; link
< LINKS_PER_UNIT
; link
++ ) {
528 if ( HostMapP
->Topology
[link
].Unit
!= ROUTE_DISCONNECT
) {
529 rio_dprintk (RIO_DEBUG_TABLE
, "Entry is in use and cannot be deleted!\n");
530 p
->RIOError
.Error
= UNIT_IS_IN_USE
;
531 rio_spin_unlock_irqrestore( &HostP
->HostLock
, lock_flags
);
536 ** Slot has been allocated, BUT not booted/routed/
537 ** connected/selected or anything else-ed
539 SysPort
= HostMapP
->SysPort
;
541 if ( SysPort
!= NO_PORT
) {
542 for (port
=SysPort
; port
< SysPort
+PORTS_PER_RTA
; port
++) {
543 PortP
= p
->RIOPortp
[port
];
544 rio_dprintk (RIO_DEBUG_TABLE
, "Unmap port\n");
546 rio_spin_lock_irqsave( &PortP
->portSem
, sem_flags
);
550 if ( PortP
->State
& (RIO_MOPEN
|RIO_LOPEN
) ) {
552 rio_dprintk (RIO_DEBUG_TABLE
, "Gob on port\n");
553 PortP
->TxBufferIn
= PortP
->TxBufferOut
= 0;
555 wakeup( &PortP->TxBufferIn );
556 wakeup( &PortP->TxBufferOut);
558 PortP
->InUse
= NOT_INUSE
;
560 wakeup( &PortP->InUse );
561 signal(PortP->TtyP->t_pgrp,SIGKILL);
562 ttyflush(PortP->TtyP,(FREAD|FWRITE));
564 PortP
->State
|= RIO_CLOSING
| RIO_DELETED
;
568 ** For the second slot of a 16 port RTA, the
569 ** driver needs to reset the changes made to
570 ** the phb to port mappings in RIORouteRup.
572 if (PortP
->SecondBlock
) {
573 ushort dest_unit
= HostMapP
->ID
;
574 ushort dest_port
= port
- SysPort
;
578 for (TxPktP
= PortP
->TxStart
;
579 TxPktP
<= PortP
->TxEnd
; TxPktP
++) {
581 ** *TxPktP is the pointer to the
582 ** transmit packet on the host card.
583 ** This needs to be translated into
584 ** a 32 bit pointer so it can be
585 ** accessed from the driver.
587 Pkt
= (PKT
*) RIO_PTR(HostP
->Caddr
,
589 rio_dprintk (RIO_DEBUG_TABLE
,
590 "Tx packet (%x) destination: Old %x:%x New %x:%x\n",
591 *TxPktP
, Pkt
->dest_unit
,
592 Pkt
->dest_port
, dest_unit
, dest_port
);
593 WWORD(Pkt
->dest_unit
, dest_unit
);
594 WWORD(Pkt
->dest_port
, dest_port
);
596 rio_dprintk (RIO_DEBUG_TABLE
,
597 "Port %d phb destination: Old %x:%x New %x:%x\n",
598 port
, PortP
->PhbP
->destination
& 0xff,
599 (PortP
->PhbP
->destination
>> 8) & 0xff,
600 dest_unit
, dest_port
);
601 WWORD(PortP
->PhbP
->destination
,
602 dest_unit
+ (dest_port
<< 8));
604 rio_spin_unlock_irqrestore(&PortP
->portSem
, sem_flags
);
607 rio_dprintk (RIO_DEBUG_TABLE
, "Entry nulled.\n");
608 bzero((char *)HostMapP
,sizeof(struct Map
));
612 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
615 /* XXXXX lock me up */
616 for ( entry
=0; entry
< TOTAL_MAP_ENTRIES
; entry
++ ) {
617 if ( p
->RIOSavedTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
618 bzero((char *)&p
->RIOSavedTable
[entry
],sizeof(struct Map
));
621 if ( p
->RIOConnectTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
622 bzero((char *)&p
->RIOConnectTable
[entry
],sizeof(struct Map
));
629 rio_dprintk (RIO_DEBUG_TABLE
, "Couldn't find entry to be deleted\n");
630 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
634 int RIOAssignRta( struct rio_info
*p
, struct Map
*MapP
)
637 struct Map
*HostMapP
;
642 rio_dprintk (RIO_DEBUG_TABLE
, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n",
643 MapP
->HostUniqueNum
,MapP
->RtaUniqueNum
,
644 MapP
->ID
, (int)MapP
->SysPort
);
646 if ((MapP
->ID
!= (ushort
)-1) &&
647 ((int)MapP
->ID
< (int)1 || (int)MapP
->ID
> MAX_RUP
))
649 rio_dprintk (RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
650 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
653 if (MapP
->RtaUniqueNum
== 0)
655 rio_dprintk (RIO_DEBUG_TABLE
, "Rta Unique number zero!\n");
656 p
->RIOError
.Error
= RTA_UNIQUE_NUMBER_ZERO
;
659 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
% PORTS_PER_RTA
) )
661 rio_dprintk (RIO_DEBUG_TABLE
, "Port %d not multiple of %d!\n",(int)MapP
->SysPort
,PORTS_PER_RTA
);
662 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
665 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
>= RIO_PORTS
) )
667 rio_dprintk (RIO_DEBUG_TABLE
, "Port %d not valid!\n",(int)MapP
->SysPort
);
668 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
673 ** Copy the name across to the map entry.
675 MapP
->Name
[MAX_NAME_LEN
-1] = '\0';
679 if ( *sptr
<' ' || *sptr
>'~' )
681 rio_dprintk (RIO_DEBUG_TABLE
, "Name entry contains non-printing characters!\n");
682 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
688 for ( host
=0; host
< p
->RIONumHosts
; host
++ )
690 if ( MapP
->HostUniqueNum
== p
->RIOHosts
[host
].UniqueNum
)
692 if ( (p
->RIOHosts
[host
].Flags
& RUN_STATE
) != RC_RUNNING
)
694 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
699 ** Now we have a host we need to allocate an ID
700 ** if the entry does not already have one.
702 if (MapP
->ID
== (ushort
)-1)
706 rio_dprintk (RIO_DEBUG_TABLE
, "Attempting to get a new ID for rta \"%s\"\n",
709 ** The idea here is to allow RTA's to be assigned
710 ** before they actually appear on the network.
711 ** This allows the addition of RTA's without having
714 ** - Find a free ID and allocate it to the RTA.
715 ** - If this map entry is the second half of a
716 ** 16 port entry then find the other half and
717 ** make sure the 2 cross reference each other.
719 if (RIOFindFreeID(p
, &p
->RIOHosts
[host
], &nNewID
, NULL
) != 0)
721 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
724 MapP
->ID
= (ushort
)nNewID
+ 1;
725 rio_dprintk (RIO_DEBUG_TABLE
, "Allocated ID %d for this new RTA.\n", MapP
->ID
);
726 HostMapP
= &p
->RIOHosts
[host
].Mapping
[nNewID
];
727 HostMapP
->RtaUniqueNum
= MapP
->RtaUniqueNum
;
728 HostMapP
->HostUniqueNum
= MapP
->HostUniqueNum
;
729 HostMapP
->ID
= MapP
->ID
;
730 for (link
= 0; link
< LINKS_PER_UNIT
; link
++)
732 HostMapP
->Topology
[link
].Unit
= ROUTE_DISCONNECT
;
733 HostMapP
->Topology
[link
].Link
= NO_LINK
;
735 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
739 for (unit
= 0; unit
< MAX_RUP
; unit
++)
740 if (p
->RIOHosts
[host
].Mapping
[unit
].RtaUniqueNum
==
745 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
748 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
749 HostMapP
->ID2
= MapP
->ID2
= p
->RIOHosts
[host
].Mapping
[unit
].ID
;
750 p
->RIOHosts
[host
].Mapping
[unit
].ID2
= MapP
->ID
;
751 rio_dprintk (RIO_DEBUG_TABLE
, "Cross referenced id %d to ID %d.\n",
753 p
->RIOHosts
[host
].Mapping
[unit
].ID
);
757 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
-1];
759 if ( HostMapP
->Flags
& SLOT_IN_USE
)
761 rio_dprintk (RIO_DEBUG_TABLE
, "Map table slot for ID %d is already in use.\n", MapP
->ID
);
762 p
->RIOError
.Error
= ID_ALREADY_IN_USE
;
767 ** Assign the sys ports and the name, and mark the slot as
770 HostMapP
->SysPort
= MapP
->SysPort
;
771 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0)
772 CCOPY( MapP
->Name
, HostMapP
->Name
, MAX_NAME_LEN
);
773 HostMapP
->Flags
= SLOT_IN_USE
| RTA_BOOTED
;
775 RIO_SV_BROADCAST(p
->RIOHosts
[host
].svFlags
[MapP
->ID
-1]);
777 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
778 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
780 RIOReMapPorts( p
, &p
->RIOHosts
[host
], HostMapP
);
782 ** Adjust 2nd block of 8 phbs
784 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
785 RIOFixPhbs(p
, &p
->RIOHosts
[host
], HostMapP
->ID
- 1);
787 if ( HostMapP
->SysPort
!= NO_PORT
)
789 if ( HostMapP
->SysPort
< p
->RIOFirstPortsBooted
)
790 p
->RIOFirstPortsBooted
= HostMapP
->SysPort
;
791 if ( HostMapP
->SysPort
> p
->RIOLastPortsBooted
)
792 p
->RIOLastPortsBooted
= HostMapP
->SysPort
;
794 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
795 rio_dprintk (RIO_DEBUG_TABLE
, "Second map of RTA %s added to configuration\n",
796 p
->RIOHosts
[host
].Mapping
[MapP
->ID2
- 1].Name
);
798 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s added to configuration\n", MapP
->Name
);
802 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
803 rio_dprintk (RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);
809 RIOReMapPorts(p
, HostP
, HostMapP
)
812 struct Map
*HostMapP
;
814 register struct Port
*PortP
;
823 CheckHostMapP( HostMapP
);
826 rio_dprintk (RIO_DEBUG_TABLE
, "Mapping sysport %d to id %d\n", (int)HostMapP
->SysPort
, HostMapP
->ID
);
829 ** We need to tell the UnixRups which sysport the rup corresponds to
831 HostP
->UnixRups
[HostMapP
->ID
-1].BaseSysPort
= HostMapP
->SysPort
;
833 if ( HostMapP
->SysPort
== NO_PORT
)
836 RtaType
= GetUnitType(HostMapP
->RtaUniqueNum
);
837 rio_dprintk (RIO_DEBUG_TABLE
, "Mapping sysport %d-%d\n",
838 (int)HostMapP
->SysPort
, (int)HostMapP
->SysPort
+PORTS_PER_RTA
-1);
841 ** now map each of its eight ports
843 for ( SubEnt
=0; SubEnt
<PORTS_PER_RTA
; SubEnt
++) {
844 rio_dprintk (RIO_DEBUG_TABLE
, "subent = %d, HostMapP->SysPort = %d\n",
845 SubEnt
, (int)HostMapP
->SysPort
);
846 SysPort
= HostMapP
->SysPort
+SubEnt
; /* portnumber within system */
847 /* portnumber on host */
849 HostPort
= (HostMapP
->ID
-1)*PORTS_PER_RTA
+SubEnt
;
851 rio_dprintk (RIO_DEBUG_TABLE
, "c1 p = %p, p->rioPortp = %p\n", p
, p
->RIOPortp
);
852 PortP
= p
->RIOPortp
[SysPort
];
854 PortP
->TtyP
= &p
->channel
[SysPort
];
856 rio_dprintk (RIO_DEBUG_TABLE
, "Map port\n");
859 ** Point at all the real neat data structures
861 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
862 PortP
->HostP
= HostP
;
863 PortP
->Caddr
= HostP
->Caddr
;
866 ** The PhbP cannot be filled in yet
867 ** unless the host has been booted
869 if ((HostP
->Flags
& RUN_STATE
) == RC_RUNNING
) {
870 struct PHB
*PhbP
= PortP
->PhbP
= &HostP
->PhbP
[HostPort
];
871 PortP
->TxAdd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_add
));
872 PortP
->TxStart
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_start
));
873 PortP
->TxEnd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_end
));
874 PortP
->RxRemove
=(WORD
*)RIO_PTR(HostP
->Caddr
,
875 RWORD(PhbP
->rx_remove
));
876 PortP
->RxStart
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->rx_start
));
877 PortP
->RxEnd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->rx_end
));
883 ** port related flags
885 PortP
->HostPort
= HostPort
;
887 ** For each part of a 16 port RTA, RupNum is ID - 1.
889 PortP
->RupNum
= HostMapP
->ID
- 1;
890 if (HostMapP
->Flags
& RTA16_SECOND_SLOT
) {
891 PortP
->ID2
= HostMapP
->ID2
- 1;
892 PortP
->SecondBlock
= TRUE
;
896 PortP
->SecondBlock
= FALSE
;
898 PortP
->RtaUniqueNum
= HostMapP
->RtaUniqueNum
;
901 ** If the port was already mapped then thats all we need to do.
904 rio_spin_unlock_irqrestore( &PortP
->portSem
, flags
);
907 else HostMapP
->Flags
&= ~RTA_NEWBOOT
;
912 ** Check out the module type - if it is special (read only etc.)
913 ** then we need to set flags in the PortP->Config.
914 ** Note: For 16 port RTA, all ports are of the same type.
916 if (RtaType
== TYPE_RTA16
) {
917 PortP
->Config
|= p
->RIOModuleTypes
[HostP
->UnixRups
918 [HostMapP
->ID
-1].ModTypes
].Flags
[SubEnt
% PORTS_PER_MODULE
];
920 if ( SubEnt
< PORTS_PER_MODULE
)
921 PortP
->Config
|= p
->RIOModuleTypes
[LONYBLE(HostP
->UnixRups
922 [HostMapP
->ID
-1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
924 PortP
->Config
|= p
->RIOModuleTypes
[HINYBLE(HostP
->UnixRups
925 [HostMapP
->ID
-1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
929 ** more port related flags
931 PortP
->PortState
= 0;
932 PortP
->ModemLines
= 0;
933 PortP
->ModemState
= 0;
934 PortP
->CookMode
= COOK_WELL
;
936 PortP
->FlushCmdBodge
= 0;
937 PortP
->WflushFlag
= 0;
938 PortP
->MagicFlags
= 0;
941 PortP
->FirstOpen
= 1;
946 PortP
->RxDataStart
= 0;
948 PortP
->Name
= &HostMapP
->Name
[0];
950 bzero( (caddr_t
)&PortP
->Stat
, sizeof(struct RIOStats
) );
952 PortP
->statsGather
= 0;
958 if ( PortP
->TxRingBuffer
)
959 bzero( PortP
->TxRingBuffer
, p
->RIOBufferSize
);
960 else if ( p
->RIOBufferSize
) {
961 PortP
->TxRingBuffer
= sysbrk(p
->RIOBufferSize
);
962 bzero( PortP
->TxRingBuffer
, p
->RIOBufferSize
);
964 PortP
->TxBufferOut
= 0;
965 PortP
->TxBufferIn
= 0;
968 ** LastRxTgl stores the state of the rx toggle bit for this
969 ** port, to be compared with the state of the next pkt received.
970 ** If the same, we have received the same rx pkt from the RTA
971 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
973 PortP
->LastRxTgl
= ~(uchar
)PHB_RX_TGL
;
976 ** and mark the port as usable
979 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
981 if ( HostMapP
->SysPort
< p
->RIOFirstPortsMapped
)
982 p
->RIOFirstPortsMapped
= HostMapP
->SysPort
;
983 if ( HostMapP
->SysPort
> p
->RIOLastPortsMapped
)
984 p
->RIOLastPortsMapped
= HostMapP
->SysPort
;
990 RIOChangeName(p
, MapP
)
995 struct Map
*HostMapP
;
998 rio_dprintk (RIO_DEBUG_TABLE
, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n",
999 MapP
->HostUniqueNum
,MapP
->RtaUniqueNum
,
1000 MapP
->ID
, (int)MapP
->SysPort
);
1002 if ( MapP
->ID
> MAX_RUP
) {
1003 rio_dprintk (RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
1004 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
1008 MapP
->Name
[MAX_NAME_LEN
-1] = '\0';
1012 if ( *sptr
<' ' || *sptr
>'~' ) {
1013 rio_dprintk (RIO_DEBUG_TABLE
, "Name entry contains non-printing characters!\n");
1014 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
1020 for ( host
=0; host
< p
->RIONumHosts
; host
++ ) {
1021 if ( MapP
->HostUniqueNum
== p
->RIOHosts
[host
].UniqueNum
) {
1022 if ( (p
->RIOHosts
[host
].Flags
& RUN_STATE
) != RC_RUNNING
) {
1023 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
1026 if ( MapP
->ID
==0 ) {
1027 CCOPY( MapP
->Name
, p
->RIOHosts
[host
].Name
, MAX_NAME_LEN
);
1031 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
-1];
1033 if ( HostMapP
->RtaUniqueNum
!= MapP
->RtaUniqueNum
) {
1034 p
->RIOError
.Error
= RTA_NUMBER_WRONG
;
1037 CCOPY( MapP
->Name
, HostMapP
->Name
, MAX_NAME_LEN
);
1041 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
1042 rio_dprintk (RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);