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>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
53 #include "linux_compat.h"
54 #include "rio_linux.h"
90 ** A configuration table has been loaded. It is now up to us
91 ** to sort it out and use the information contained therein.
97 int Host
, Host1
, Host2
, NameIsUnique
, Entry
, SubEnt
;
105 ** We have been sent a new table to install. We need to break
106 ** it down into little bits and spread it around a bit to see
111 ** (things marked 'xx' aren't checked any more!)
112 ** (1) That there are no booted Hosts/RTAs out there.
113 ** (2) That the names are properly formed
114 ** (3) That blank entries really are.
115 ** xx (4) That hosts mentioned in the table actually exist. xx
116 ** (5) That the IDs are unique (per host).
117 ** (6) That host IDs are zero
118 ** (7) That port numbers are valid
119 ** (8) That port numbers aren't duplicated
120 ** (9) That names aren't duplicated
121 ** xx (10) That hosts that actually exist are mentioned in the table. xx
123 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(1)\n");
124 if ( p
->RIOSystemUp
) { /* (1) */
125 p
->RIOError
.Error
= HOST_HAS_ALREADY_BEEN_BOOTED
;
129 p
->RIOError
.Error
= NOTHING_WRONG_AT_ALL
;
130 p
->RIOError
.Entry
= -1;
131 p
->RIOError
.Other
= -1;
133 for ( Entry
=0; Entry
<TOTAL_MAP_ENTRIES
; Entry
++ ) {
134 MapP
= &p
->RIOConnectTable
[Entry
];
135 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0) {
136 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(2)\n");
137 cptr
= MapP
->Name
; /* (2) */
138 cptr
[MAX_NAME_LEN
-1]='\0';
139 if ( cptr
[0]=='\0' ) {
140 bcopy(MapP
->RtaUniqueNum
?"RTA NN":"HOST NN",MapP
->Name
,8);
141 MapP
->Name
[5] = '0'+Entry
/10;
142 MapP
->Name
[6] = '0'+Entry
%10;
145 if ( *cptr
<' ' || *cptr
>'~' ) {
146 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
147 p
->RIOError
.Entry
= Entry
;
155 ** If the entry saved was a tentative entry then just forget
158 if ( MapP
->Flags
& SLOT_TENTATIVE
) {
159 MapP
->HostUniqueNum
= 0;
160 MapP
->RtaUniqueNum
= 0;
164 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(3)\n");
165 if ( !MapP
->RtaUniqueNum
&& !MapP
->HostUniqueNum
) { /* (3) */
166 if ( MapP
->ID
|| MapP
->SysPort
|| MapP
->Flags
) {
167 rio_dprintk (RIO_DEBUG_TABLE
, "%s pretending to be empty but isn't\n",MapP
->Name
);
168 p
->RIOError
.Error
= TABLE_ENTRY_ISNT_PROPERLY_NULL
;
169 p
->RIOError
.Entry
= Entry
;
172 rio_dprintk (RIO_DEBUG_TABLE
, "!RIO: Daemon: test (3) passes\n");
176 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(4)\n");
177 for ( Host
=0; Host
<p
->RIONumHosts
; Host
++ ) { /* (4) */
178 if ( p
->RIOHosts
[Host
].UniqueNum
==MapP
->HostUniqueNum
) {
179 HostP
= &p
->RIOHosts
[Host
];
181 ** having done the lookup, we don't really want to do
182 ** it again, so hang the host number in a safe place
184 MapP
->Topology
[0].Unit
= Host
;
189 if ( Host
>= p
->RIONumHosts
) {
190 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has unknown host unique number 0x%x\n",
191 MapP
->Name
, MapP
->HostUniqueNum
);
192 MapP
->HostUniqueNum
= 0;
193 /* MapP->RtaUniqueNum = 0; */
195 /* MapP->Flags = 0; */
196 /* MapP->SysPort = 0; */
197 /* MapP->Name[0] = 0; */
201 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(5)\n");
202 if ( MapP
->RtaUniqueNum
) { /* (5) */
204 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: RTA %s has been allocated an ID of zero!\n",
206 p
->RIOError
.Error
= ZERO_RTA_ID
;
207 p
->RIOError
.Entry
= Entry
;
210 if ( MapP
->ID
> MAX_RUP
) {
211 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: RTA %s has been allocated an illegal ID %d\n",
212 MapP
->Name
, MapP
->ID
);
213 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
214 p
->RIOError
.Entry
= Entry
;
217 for ( SubEnt
=0; SubEnt
<Entry
; SubEnt
++ ) {
218 if ( MapP
->HostUniqueNum
==
219 p
->RIOConnectTable
[SubEnt
].HostUniqueNum
&&
220 MapP
->ID
== p
->RIOConnectTable
[SubEnt
].ID
) {
221 rio_dprintk (RIO_DEBUG_TABLE
, "Dupl. ID number allocated to RTA %s and RTA %s\n",
222 MapP
->Name
, p
->RIOConnectTable
[SubEnt
].Name
);
223 p
->RIOError
.Error
= DUPLICATED_RTA_ID
;
224 p
->RIOError
.Entry
= Entry
;
225 p
->RIOError
.Other
= SubEnt
;
229 ** If the RtaUniqueNum is the same, it may be looking at both
230 ** entries for a 16 port RTA, so check the ids
232 if ((MapP
->RtaUniqueNum
==
233 p
->RIOConnectTable
[SubEnt
].RtaUniqueNum
)
234 && (MapP
->ID2
!= p
->RIOConnectTable
[SubEnt
].ID
)) {
235 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has duplicate unique number\n",MapP
->Name
);
236 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s has duplicate unique number\n",
237 p
->RIOConnectTable
[SubEnt
].Name
);
238 p
->RIOError
.Error
= DUPLICATE_UNIQUE_NUMBER
;
239 p
->RIOError
.Entry
= Entry
;
240 p
->RIOError
.Other
= SubEnt
;
244 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(7a)\n");
246 if ((MapP
->SysPort
!= NO_PORT
)&&(MapP
->SysPort
% PORTS_PER_RTA
)) {
247 rio_dprintk (RIO_DEBUG_TABLE
, "TTY Port number %d-RTA %s is not a multiple of %d!\n",
248 (int)MapP
->SysPort
,MapP
->Name
, PORTS_PER_RTA
);
249 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
250 p
->RIOError
.Entry
= Entry
;
253 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(7b)\n");
255 if ((MapP
->SysPort
!= NO_PORT
)&&(MapP
->SysPort
>= RIO_PORTS
)) {
256 rio_dprintk (RIO_DEBUG_TABLE
, "TTY Port number %d for RTA %s is too big\n",
257 (int)MapP
->SysPort
, MapP
->Name
);
258 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
259 p
->RIOError
.Entry
= Entry
;
262 for ( SubEnt
=0; SubEnt
<Entry
; SubEnt
++ ) {
263 if ( p
->RIOConnectTable
[SubEnt
].Flags
& RTA16_SECOND_SLOT
)
265 if ( p
->RIOConnectTable
[SubEnt
].RtaUniqueNum
) {
266 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(8)\n");
268 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
==
269 p
->RIOConnectTable
[SubEnt
].SysPort
) ) {
270 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s:same TTY port # as RTA %s (%d)\n",
271 MapP
->Name
, p
->RIOConnectTable
[SubEnt
].Name
,
273 p
->RIOError
.Error
= TTY_NUMBER_IN_USE
;
274 p
->RIOError
.Entry
= Entry
;
275 p
->RIOError
.Other
= SubEnt
;
278 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(9)\n");
279 if (RIOStrCmp(MapP
->Name
,
280 p
->RIOConnectTable
[SubEnt
].Name
)==0 && !(MapP
->Flags
& RTA16_SECOND_SLOT
)) { /* (9) */
281 rio_dprintk (RIO_DEBUG_TABLE
, "RTA name %s used twice\n", MapP
->Name
);
282 p
->RIOError
.Error
= NAME_USED_TWICE
;
283 p
->RIOError
.Entry
= Entry
;
284 p
->RIOError
.Other
= SubEnt
;
291 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: entering(6)\n");
293 rio_dprintk (RIO_DEBUG_TABLE
, "RIO:HOST %s has been allocated ID that isn't zero!\n",
295 p
->RIOError
.Error
= HOST_ID_NOT_ZERO
;
296 p
->RIOError
.Entry
= Entry
;
299 if ( MapP
->SysPort
!= NO_PORT
) {
300 rio_dprintk (RIO_DEBUG_TABLE
, "RIO: HOST %s has been allocated port numbers!\n",
302 p
->RIOError
.Error
= HOST_SYSPORT_BAD
;
303 p
->RIOError
.Entry
= Entry
;
310 ** wow! if we get here then it's a goody!
314 ** Zero the (old) entries for each host...
316 for ( Host
=0; Host
<RIO_HOSTS
; Host
++ ) {
317 for ( Entry
=0; Entry
<MAX_RUP
; Entry
++ ) {
318 bzero((caddr_t
)&p
->RIOHosts
[Host
].Mapping
[Entry
],
321 bzero((caddr_t
)&p
->RIOHosts
[Host
].Name
[0],
322 sizeof(p
->RIOHosts
[Host
].Name
) );
326 ** Copy in the new table entries
328 for ( Entry
=0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++ ) {
329 rio_dprintk (RIO_DEBUG_TABLE
, "RIONewTable: Copy table for Host entry %d\n", Entry
);
330 MapP
= &p
->RIOConnectTable
[Entry
];
333 ** Now, if it is an empty slot ignore it!
335 if ( MapP
->HostUniqueNum
==0 )
339 ** we saved the host number earlier, so grab it back
341 HostP
= &p
->RIOHosts
[MapP
->Topology
[0].Unit
];
344 ** If it is a host, then we only need to fill in the name field.
347 rio_dprintk (RIO_DEBUG_TABLE
, "Host entry found. Name %s\n", MapP
->Name
);
348 bcopy(MapP
->Name
,HostP
->Name
,MAX_NAME_LEN
);
353 ** Its an RTA entry, so fill in the host mapping entries for it
354 ** and the port mapping entries. Notice that entry zero is for
357 HostMapP
= &HostP
->Mapping
[MapP
->ID
-1];
359 if (MapP
->Flags
& SLOT_IN_USE
) {
360 rio_dprintk (RIO_DEBUG_TABLE
, "Rta entry found. Name %s\n", MapP
->Name
);
362 ** structure assign, then sort out the bits we shouldn't have done
366 HostMapP
->Flags
= SLOT_IN_USE
;
367 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
368 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
370 RIOReMapPorts(p
, HostP
, HostMapP
);
373 rio_dprintk (RIO_DEBUG_TABLE
, "TENTATIVE Rta entry found. Name %s\n", MapP
->Name
);
377 for ( Entry
=0; Entry
< TOTAL_MAP_ENTRIES
; Entry
++ ) {
378 p
->RIOSavedTable
[Entry
] = p
->RIOConnectTable
[Entry
];
381 for ( Host
=0; Host
<p
->RIONumHosts
; Host
++ ) {
382 for ( SubEnt
=0; SubEnt
<LINKS_PER_UNIT
; SubEnt
++ ) {
383 p
->RIOHosts
[Host
].Topology
[SubEnt
].Unit
= ROUTE_DISCONNECT
;
384 p
->RIOHosts
[Host
].Topology
[SubEnt
].Link
= NO_LINK
;
386 for ( Entry
=0; Entry
<MAX_RUP
; Entry
++ ) {
387 for ( SubEnt
=0; SubEnt
<LINKS_PER_UNIT
; SubEnt
++ ) {
388 p
->RIOHosts
[Host
].Mapping
[Entry
].Topology
[SubEnt
].Unit
=
390 p
->RIOHosts
[Host
].Mapping
[Entry
].Topology
[SubEnt
].Link
=
394 if ( !p
->RIOHosts
[Host
].Name
[0] ) {
395 bcopy("HOST 1",p
->RIOHosts
[Host
].Name
,7);
396 p
->RIOHosts
[Host
].Name
[5] += Host
;
399 ** Check that default name assigned is unique.
403 while (!NameIsUnique
) {
405 for ( Host2
=0; Host2
<p
->RIONumHosts
; Host2
++ ) {
408 if (RIOStrCmp(p
->RIOHosts
[Host
].Name
, p
->RIOHosts
[Host2
].Name
)
412 if (Host1
>= p
->RIONumHosts
)
414 p
->RIOHosts
[Host
].Name
[5] = '1' + Host1
;
419 ** Rename host if name already used.
423 rio_dprintk (RIO_DEBUG_TABLE
, "Default name %s already used\n", p
->RIOHosts
[Host
].Name
);
424 bcopy("HOST 1",p
->RIOHosts
[Host
].Name
,7);
425 p
->RIOHosts
[Host
].Name
[5] += Host1
;
427 rio_dprintk (RIO_DEBUG_TABLE
, "Assigning default name %s\n", p
->RIOHosts
[Host
].Name
);
433 ** User process needs the config table - build it from first
448 disable(oldspl
); /* strange but true! */
450 rio_dprintk (RIO_DEBUG_TABLE
, "Generating a table to return to config.rio\n");
452 bzero((caddr_t
)&p
->RIOConnectTable
[0],
453 sizeof(struct Map
) * TOTAL_MAP_ENTRIES
);
455 for ( Host
=0; Host
<RIO_HOSTS
; Host
++ ) {
456 rio_dprintk (RIO_DEBUG_TABLE
, "Processing host %d\n", Host
);
457 HostP
= &p
->RIOHosts
[Host
];
458 MapP
= &p
->RIOConnectTable
[Next
++];
459 MapP
->HostUniqueNum
= HostP
->UniqueNum
;
460 if ( (HostP
->Flags
& RUN_STATE
) != RC_RUNNING
)
462 MapP
->RtaUniqueNum
= 0;
464 MapP
->Flags
= SLOT_IN_USE
;
465 MapP
->SysPort
= NO_PORT
;
466 for ( link
=0; link
<LINKS_PER_UNIT
; link
++ )
467 MapP
->Topology
[link
] = HostP
->Topology
[link
];
468 bcopy(HostP
->Name
,MapP
->Name
,MAX_NAME_LEN
);
469 for ( Rup
=0; Rup
<MAX_RUP
; Rup
++ ) {
470 if ( HostP
->Mapping
[Rup
].Flags
& (SLOT_IN_USE
|SLOT_TENTATIVE
) ) {
471 p
->RIOConnectTable
[Next
] = HostP
->Mapping
[Rup
];
472 if ( HostP
->Mapping
[Rup
].Flags
& SLOT_IN_USE
)
473 p
->RIOConnectTable
[Next
].Flags
|= SLOT_IN_USE
;
474 if ( HostP
->Mapping
[Rup
].Flags
& SLOT_TENTATIVE
)
475 p
->RIOConnectTable
[Next
].Flags
|= SLOT_TENTATIVE
;
476 if ( HostP
->Mapping
[Rup
].Flags
& RTA16_SECOND_SLOT
)
477 p
->RIOConnectTable
[Next
].Flags
|= RTA16_SECOND_SLOT
;
487 ** config.rio has taken a dislike to one of the gross maps entries.
488 ** if the entry is suitably inactive, then we can gob on it and remove
489 ** it from the table.
492 RIODeleteRta(p
, MapP
)
496 int host
, entry
, port
, link
;
499 struct Map
*HostMapP
;
502 unsigned long lock_flags
, sem_flags
;
504 rio_dprintk (RIO_DEBUG_TABLE
, "Delete entry on host %x, rta %x\n",
505 MapP
->HostUniqueNum
, MapP
->RtaUniqueNum
);
507 for ( host
=0; host
< p
->RIONumHosts
; host
++ ) {
508 HostP
= &p
->RIOHosts
[host
];
510 rio_spin_lock_irqsave( &HostP
->HostLock
, lock_flags
);
512 if ( (HostP
->Flags
& RUN_STATE
) != RC_RUNNING
) {
513 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
517 for ( entry
=0; entry
<MAX_RUP
; entry
++ ) {
518 if ( MapP
->RtaUniqueNum
== HostP
->Mapping
[entry
].RtaUniqueNum
) {
519 HostMapP
= &HostP
->Mapping
[entry
];
520 rio_dprintk (RIO_DEBUG_TABLE
, "Found entry offset %d on host %s\n",
524 ** Check all four links of the unit are disconnected
526 for ( link
=0; link
< LINKS_PER_UNIT
; link
++ ) {
527 if ( HostMapP
->Topology
[link
].Unit
!= ROUTE_DISCONNECT
) {
528 rio_dprintk (RIO_DEBUG_TABLE
, "Entry is in use and cannot be deleted!\n");
529 p
->RIOError
.Error
= UNIT_IS_IN_USE
;
530 rio_spin_unlock_irqrestore( &HostP
->HostLock
, lock_flags
);
535 ** Slot has been allocated, BUT not booted/routed/
536 ** connected/selected or anything else-ed
538 SysPort
= HostMapP
->SysPort
;
540 if ( SysPort
!= NO_PORT
) {
541 for (port
=SysPort
; port
< SysPort
+PORTS_PER_RTA
; port
++) {
542 PortP
= p
->RIOPortp
[port
];
543 rio_dprintk (RIO_DEBUG_TABLE
, "Unmap port\n");
545 rio_spin_lock_irqsave( &PortP
->portSem
, sem_flags
);
549 if ( PortP
->State
& (RIO_MOPEN
|RIO_LOPEN
) ) {
551 rio_dprintk (RIO_DEBUG_TABLE
, "Gob on port\n");
552 PortP
->TxBufferIn
= PortP
->TxBufferOut
= 0;
554 wakeup( &PortP->TxBufferIn );
555 wakeup( &PortP->TxBufferOut);
557 PortP
->InUse
= NOT_INUSE
;
559 wakeup( &PortP->InUse );
560 signal(PortP->TtyP->t_pgrp,SIGKILL);
561 ttyflush(PortP->TtyP,(FREAD|FWRITE));
563 PortP
->State
|= RIO_CLOSING
| RIO_DELETED
;
567 ** For the second slot of a 16 port RTA, the
568 ** driver needs to reset the changes made to
569 ** the phb to port mappings in RIORouteRup.
571 if (PortP
->SecondBlock
) {
572 ushort dest_unit
= HostMapP
->ID
;
573 ushort dest_port
= port
- SysPort
;
577 for (TxPktP
= PortP
->TxStart
;
578 TxPktP
<= PortP
->TxEnd
; TxPktP
++) {
580 ** *TxPktP is the pointer to the
581 ** transmit packet on the host card.
582 ** This needs to be translated into
583 ** a 32 bit pointer so it can be
584 ** accessed from the driver.
586 Pkt
= (PKT
*) RIO_PTR(HostP
->Caddr
,
588 rio_dprintk (RIO_DEBUG_TABLE
,
589 "Tx packet (%x) destination: Old %x:%x New %x:%x\n",
590 *TxPktP
, Pkt
->dest_unit
,
591 Pkt
->dest_port
, dest_unit
, dest_port
);
592 WWORD(Pkt
->dest_unit
, dest_unit
);
593 WWORD(Pkt
->dest_port
, dest_port
);
595 rio_dprintk (RIO_DEBUG_TABLE
,
596 "Port %d phb destination: Old %x:%x New %x:%x\n",
597 port
, PortP
->PhbP
->destination
& 0xff,
598 (PortP
->PhbP
->destination
>> 8) & 0xff,
599 dest_unit
, dest_port
);
600 WWORD(PortP
->PhbP
->destination
,
601 dest_unit
+ (dest_port
<< 8));
603 rio_spin_unlock_irqrestore(&PortP
->portSem
, sem_flags
);
606 rio_dprintk (RIO_DEBUG_TABLE
, "Entry nulled.\n");
607 bzero((char *)HostMapP
,sizeof(struct Map
));
611 rio_spin_unlock_irqrestore(&HostP
->HostLock
, lock_flags
);
614 /* XXXXX lock me up */
615 for ( entry
=0; entry
< TOTAL_MAP_ENTRIES
; entry
++ ) {
616 if ( p
->RIOSavedTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
617 bzero((char *)&p
->RIOSavedTable
[entry
],sizeof(struct Map
));
620 if ( p
->RIOConnectTable
[entry
].RtaUniqueNum
== MapP
->RtaUniqueNum
) {
621 bzero((char *)&p
->RIOConnectTable
[entry
],sizeof(struct Map
));
628 rio_dprintk (RIO_DEBUG_TABLE
, "Couldn't find entry to be deleted\n");
629 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
633 int RIOAssignRta( struct rio_info
*p
, struct Map
*MapP
)
636 struct Map
*HostMapP
;
641 rio_dprintk (RIO_DEBUG_TABLE
, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n",
642 MapP
->HostUniqueNum
,MapP
->RtaUniqueNum
,
643 MapP
->ID
, (int)MapP
->SysPort
);
645 if ((MapP
->ID
!= (ushort
)-1) &&
646 ((int)MapP
->ID
< (int)1 || (int)MapP
->ID
> MAX_RUP
))
648 rio_dprintk (RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
649 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
652 if (MapP
->RtaUniqueNum
== 0)
654 rio_dprintk (RIO_DEBUG_TABLE
, "Rta Unique number zero!\n");
655 p
->RIOError
.Error
= RTA_UNIQUE_NUMBER_ZERO
;
658 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
% PORTS_PER_RTA
) )
660 rio_dprintk (RIO_DEBUG_TABLE
, "Port %d not multiple of %d!\n",(int)MapP
->SysPort
,PORTS_PER_RTA
);
661 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
664 if ( (MapP
->SysPort
!= NO_PORT
) && (MapP
->SysPort
>= RIO_PORTS
) )
666 rio_dprintk (RIO_DEBUG_TABLE
, "Port %d not valid!\n",(int)MapP
->SysPort
);
667 p
->RIOError
.Error
= TTY_NUMBER_OUT_OF_RANGE
;
672 ** Copy the name across to the map entry.
674 MapP
->Name
[MAX_NAME_LEN
-1] = '\0';
678 if ( *sptr
<' ' || *sptr
>'~' )
680 rio_dprintk (RIO_DEBUG_TABLE
, "Name entry contains non-printing characters!\n");
681 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
687 for ( host
=0; host
< p
->RIONumHosts
; host
++ )
689 if ( MapP
->HostUniqueNum
== p
->RIOHosts
[host
].UniqueNum
)
691 if ( (p
->RIOHosts
[host
].Flags
& RUN_STATE
) != RC_RUNNING
)
693 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
698 ** Now we have a host we need to allocate an ID
699 ** if the entry does not already have one.
701 if (MapP
->ID
== (ushort
)-1)
705 rio_dprintk (RIO_DEBUG_TABLE
, "Attempting to get a new ID for rta \"%s\"\n",
708 ** The idea here is to allow RTA's to be assigned
709 ** before they actually appear on the network.
710 ** This allows the addition of RTA's without having
713 ** - Find a free ID and allocate it to the RTA.
714 ** - If this map entry is the second half of a
715 ** 16 port entry then find the other half and
716 ** make sure the 2 cross reference each other.
718 if (RIOFindFreeID(p
, &p
->RIOHosts
[host
], &nNewID
, NULL
) != 0)
720 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
723 MapP
->ID
= (ushort
)nNewID
+ 1;
724 rio_dprintk (RIO_DEBUG_TABLE
, "Allocated ID %d for this new RTA.\n", MapP
->ID
);
725 HostMapP
= &p
->RIOHosts
[host
].Mapping
[nNewID
];
726 HostMapP
->RtaUniqueNum
= MapP
->RtaUniqueNum
;
727 HostMapP
->HostUniqueNum
= MapP
->HostUniqueNum
;
728 HostMapP
->ID
= MapP
->ID
;
729 for (link
= 0; link
< LINKS_PER_UNIT
; link
++)
731 HostMapP
->Topology
[link
].Unit
= ROUTE_DISCONNECT
;
732 HostMapP
->Topology
[link
].Link
= NO_LINK
;
734 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
738 for (unit
= 0; unit
< MAX_RUP
; unit
++)
739 if (p
->RIOHosts
[host
].Mapping
[unit
].RtaUniqueNum
==
744 p
->RIOError
.Error
= COULDNT_FIND_ENTRY
;
747 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
748 HostMapP
->ID2
= MapP
->ID2
= p
->RIOHosts
[host
].Mapping
[unit
].ID
;
749 p
->RIOHosts
[host
].Mapping
[unit
].ID2
= MapP
->ID
;
750 rio_dprintk (RIO_DEBUG_TABLE
, "Cross referenced id %d to ID %d.\n",
752 p
->RIOHosts
[host
].Mapping
[unit
].ID
);
756 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
-1];
758 if ( HostMapP
->Flags
& SLOT_IN_USE
)
760 rio_dprintk (RIO_DEBUG_TABLE
, "Map table slot for ID %d is already in use.\n", MapP
->ID
);
761 p
->RIOError
.Error
= ID_ALREADY_IN_USE
;
766 ** Assign the sys ports and the name, and mark the slot as
769 HostMapP
->SysPort
= MapP
->SysPort
;
770 if ((MapP
->Flags
& RTA16_SECOND_SLOT
) == 0)
771 CCOPY( MapP
->Name
, HostMapP
->Name
, MAX_NAME_LEN
);
772 HostMapP
->Flags
= SLOT_IN_USE
| RTA_BOOTED
;
774 RIO_SV_BROADCAST(p
->RIOHosts
[host
].svFlags
[MapP
->ID
-1]);
776 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
777 HostMapP
->Flags
|= RTA16_SECOND_SLOT
;
779 RIOReMapPorts( p
, &p
->RIOHosts
[host
], HostMapP
);
781 ** Adjust 2nd block of 8 phbs
783 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
784 RIOFixPhbs(p
, &p
->RIOHosts
[host
], HostMapP
->ID
- 1);
786 if ( HostMapP
->SysPort
!= NO_PORT
)
788 if ( HostMapP
->SysPort
< p
->RIOFirstPortsBooted
)
789 p
->RIOFirstPortsBooted
= HostMapP
->SysPort
;
790 if ( HostMapP
->SysPort
> p
->RIOLastPortsBooted
)
791 p
->RIOLastPortsBooted
= HostMapP
->SysPort
;
793 if (MapP
->Flags
& RTA16_SECOND_SLOT
)
794 rio_dprintk (RIO_DEBUG_TABLE
, "Second map of RTA %s added to configuration\n",
795 p
->RIOHosts
[host
].Mapping
[MapP
->ID2
- 1].Name
);
797 rio_dprintk (RIO_DEBUG_TABLE
, "RTA %s added to configuration\n", MapP
->Name
);
801 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
802 rio_dprintk (RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);
808 RIOReMapPorts(p
, HostP
, HostMapP
)
811 struct Map
*HostMapP
;
813 register struct Port
*PortP
;
822 CheckHostMapP( HostMapP
);
825 rio_dprintk (RIO_DEBUG_TABLE
, "Mapping sysport %d to id %d\n", (int)HostMapP
->SysPort
, HostMapP
->ID
);
828 ** We need to tell the UnixRups which sysport the rup corresponds to
830 HostP
->UnixRups
[HostMapP
->ID
-1].BaseSysPort
= HostMapP
->SysPort
;
832 if ( HostMapP
->SysPort
== NO_PORT
)
835 RtaType
= GetUnitType(HostMapP
->RtaUniqueNum
);
836 rio_dprintk (RIO_DEBUG_TABLE
, "Mapping sysport %d-%d\n",
837 (int)HostMapP
->SysPort
, (int)HostMapP
->SysPort
+PORTS_PER_RTA
-1);
840 ** now map each of its eight ports
842 for ( SubEnt
=0; SubEnt
<PORTS_PER_RTA
; SubEnt
++) {
843 rio_dprintk (RIO_DEBUG_TABLE
, "subent = %d, HostMapP->SysPort = %d\n",
844 SubEnt
, (int)HostMapP
->SysPort
);
845 SysPort
= HostMapP
->SysPort
+SubEnt
; /* portnumber within system */
846 /* portnumber on host */
848 HostPort
= (HostMapP
->ID
-1)*PORTS_PER_RTA
+SubEnt
;
850 rio_dprintk (RIO_DEBUG_TABLE
, "c1 p = %p, p->rioPortp = %p\n", p
, p
->RIOPortp
);
851 PortP
= p
->RIOPortp
[SysPort
];
853 PortP
->TtyP
= &p
->channel
[SysPort
];
855 rio_dprintk (RIO_DEBUG_TABLE
, "Map port\n");
858 ** Point at all the real neat data structures
860 rio_spin_lock_irqsave(&PortP
->portSem
, flags
);
861 PortP
->HostP
= HostP
;
862 PortP
->Caddr
= HostP
->Caddr
;
865 ** The PhbP cannot be filled in yet
866 ** unless the host has been booted
868 if ((HostP
->Flags
& RUN_STATE
) == RC_RUNNING
) {
869 struct PHB
*PhbP
= PortP
->PhbP
= &HostP
->PhbP
[HostPort
];
870 PortP
->TxAdd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_add
));
871 PortP
->TxStart
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_start
));
872 PortP
->TxEnd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->tx_end
));
873 PortP
->RxRemove
=(WORD
*)RIO_PTR(HostP
->Caddr
,
874 RWORD(PhbP
->rx_remove
));
875 PortP
->RxStart
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->rx_start
));
876 PortP
->RxEnd
=(WORD
*)RIO_PTR(HostP
->Caddr
,RWORD(PhbP
->rx_end
));
882 ** port related flags
884 PortP
->HostPort
= HostPort
;
886 ** For each part of a 16 port RTA, RupNum is ID - 1.
888 PortP
->RupNum
= HostMapP
->ID
- 1;
889 if (HostMapP
->Flags
& RTA16_SECOND_SLOT
) {
890 PortP
->ID2
= HostMapP
->ID2
- 1;
891 PortP
->SecondBlock
= TRUE
;
895 PortP
->SecondBlock
= FALSE
;
897 PortP
->RtaUniqueNum
= HostMapP
->RtaUniqueNum
;
900 ** If the port was already mapped then thats all we need to do.
903 rio_spin_unlock_irqrestore( &PortP
->portSem
, flags
);
906 else HostMapP
->Flags
&= ~RTA_NEWBOOT
;
911 ** Check out the module type - if it is special (read only etc.)
912 ** then we need to set flags in the PortP->Config.
913 ** Note: For 16 port RTA, all ports are of the same type.
915 if (RtaType
== TYPE_RTA16
) {
916 PortP
->Config
|= p
->RIOModuleTypes
[HostP
->UnixRups
917 [HostMapP
->ID
-1].ModTypes
].Flags
[SubEnt
% PORTS_PER_MODULE
];
919 if ( SubEnt
< PORTS_PER_MODULE
)
920 PortP
->Config
|= p
->RIOModuleTypes
[LONYBLE(HostP
->UnixRups
921 [HostMapP
->ID
-1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
923 PortP
->Config
|= p
->RIOModuleTypes
[HINYBLE(HostP
->UnixRups
924 [HostMapP
->ID
-1].ModTypes
)].Flags
[SubEnt
% PORTS_PER_MODULE
];
928 ** more port related flags
930 PortP
->PortState
= 0;
931 PortP
->ModemLines
= 0;
932 PortP
->ModemState
= 0;
933 PortP
->CookMode
= COOK_WELL
;
935 PortP
->FlushCmdBodge
= 0;
936 PortP
->WflushFlag
= 0;
937 PortP
->MagicFlags
= 0;
940 PortP
->FirstOpen
= 1;
943 ** handle the xprint issues
945 #ifdef XPRINT_SUPPORT
946 PortP
->Xprint
.XpActive
= 0;
947 PortP
->Xprint
.XttyP
= &riox_tty
[SysPort
];
949 RIOStrNCpy( PortP
->Xprint
.XpOn
, RIOConf
.XpOn
, MAX_XP_CTRL_LEN
);
950 RIOStrNCpy( PortP
->Xprint
.XpOff
, RIOConf
.XpOff
, MAX_XP_CTRL_LEN
);
951 PortP
->Xprint
.XpCps
= RIOConf
.XpCps
;
952 PortP
->Xprint
.XpLen
= RIOStrlen(PortP
->Xprint
.XpOn
)+
953 RIOStrlen(PortP
->Xprint
.XpOff
);
959 PortP
->RxDataStart
= 0;
961 PortP
->Name
= &HostMapP
->Name
[0];
963 bzero( (caddr_t
)&PortP
->Stat
, sizeof(struct RIOStats
) );
965 PortP
->statsGather
= 0;
971 if ( PortP
->TxRingBuffer
)
972 bzero( PortP
->TxRingBuffer
, p
->RIOBufferSize
);
973 else if ( p
->RIOBufferSize
) {
974 PortP
->TxRingBuffer
= sysbrk(p
->RIOBufferSize
);
975 bzero( PortP
->TxRingBuffer
, p
->RIOBufferSize
);
977 PortP
->TxBufferOut
= 0;
978 PortP
->TxBufferIn
= 0;
981 ** LastRxTgl stores the state of the rx toggle bit for this
982 ** port, to be compared with the state of the next pkt received.
983 ** If the same, we have received the same rx pkt from the RTA
984 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
986 PortP
->LastRxTgl
= ~(uchar
)PHB_RX_TGL
;
989 ** and mark the port as usable
992 rio_spin_unlock_irqrestore(&PortP
->portSem
, flags
);
994 if ( HostMapP
->SysPort
< p
->RIOFirstPortsMapped
)
995 p
->RIOFirstPortsMapped
= HostMapP
->SysPort
;
996 if ( HostMapP
->SysPort
> p
->RIOLastPortsMapped
)
997 p
->RIOLastPortsMapped
= HostMapP
->SysPort
;
1003 RIOChangeName(p
, MapP
)
1008 struct Map
*HostMapP
;
1011 rio_dprintk (RIO_DEBUG_TABLE
, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n",
1012 MapP
->HostUniqueNum
,MapP
->RtaUniqueNum
,
1013 MapP
->ID
, (int)MapP
->SysPort
);
1015 if ( MapP
->ID
> MAX_RUP
) {
1016 rio_dprintk (RIO_DEBUG_TABLE
, "Bad ID in map entry!\n");
1017 p
->RIOError
.Error
= ID_NUMBER_OUT_OF_RANGE
;
1021 MapP
->Name
[MAX_NAME_LEN
-1] = '\0';
1025 if ( *sptr
<' ' || *sptr
>'~' ) {
1026 rio_dprintk (RIO_DEBUG_TABLE
, "Name entry contains non-printing characters!\n");
1027 p
->RIOError
.Error
= BAD_CHARACTER_IN_NAME
;
1033 for ( host
=0; host
< p
->RIONumHosts
; host
++ ) {
1034 if ( MapP
->HostUniqueNum
== p
->RIOHosts
[host
].UniqueNum
) {
1035 if ( (p
->RIOHosts
[host
].Flags
& RUN_STATE
) != RC_RUNNING
) {
1036 p
->RIOError
.Error
= HOST_NOT_RUNNING
;
1039 if ( MapP
->ID
==0 ) {
1040 CCOPY( MapP
->Name
, p
->RIOHosts
[host
].Name
, MAX_NAME_LEN
);
1044 HostMapP
= &p
->RIOHosts
[host
].Mapping
[MapP
->ID
-1];
1046 if ( HostMapP
->RtaUniqueNum
!= MapP
->RtaUniqueNum
) {
1047 p
->RIOError
.Error
= RTA_NUMBER_WRONG
;
1050 CCOPY( MapP
->Name
, HostMapP
->Name
, MAX_NAME_LEN
);
1054 p
->RIOError
.Error
= UNKNOWN_HOST_NUMBER
;
1055 rio_dprintk (RIO_DEBUG_TABLE
, "Unknown host %x\n", MapP
->HostUniqueNum
);