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.
94 int RIONewTable(struct rio_info *p)
96 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
104 ** We have been sent a new table to install. We need to break
105 ** it down into little bits and spread it around a bit to see
110 ** (things marked 'xx' aren't checked any more!)
111 ** (1) That there are no booted Hosts/RTAs out there.
112 ** (2) That the names are properly formed
113 ** (3) That blank entries really are.
114 ** xx (4) That hosts mentioned in the table actually exist. xx
115 ** (5) That the IDs are unique (per host).
116 ** (6) That host IDs are zero
117 ** (7) That port numbers are valid
118 ** (8) That port numbers aren't duplicated
119 ** (9) That names aren't duplicated
120 ** xx (10) That hosts that actually exist are mentioned in the table. xx
122 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
123 if (p->RIOSystemUp) { /* (1) */
124 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
128 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
129 p->RIOError.Entry = -1;
130 p->RIOError.Other = -1;
132 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
133 MapP = &p->RIOConnectTable[Entry];
134 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
135 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
136 cptr = MapP->Name; /* (2) */
137 cptr[MAX_NAME_LEN - 1] = '\0';
138 if (cptr[0] == '\0') {
139 bcopy(MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", MapP->Name, 8);
140 MapP->Name[5] = '0' + Entry / 10;
141 MapP->Name[6] = '0' + Entry % 10;
144 if (*cptr < ' ' || *cptr > '~') {
145 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
146 p->RIOError.Entry = Entry;
154 ** If the entry saved was a tentative entry then just forget
157 if (MapP->Flags & SLOT_TENTATIVE) {
158 MapP->HostUniqueNum = 0;
159 MapP->RtaUniqueNum = 0;
163 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
164 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
165 if (MapP->ID || MapP->SysPort || MapP->Flags) {
166 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
167 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
168 p->RIOError.Entry = Entry;
171 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
175 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
176 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
177 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
178 HostP = &p->RIOHosts[Host];
180 ** having done the lookup, we don't really want to do
181 ** it again, so hang the host number in a safe place
183 MapP->Topology[0].Unit = Host;
188 if (Host >= p->RIONumHosts) {
189 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
190 MapP->HostUniqueNum = 0;
191 /* MapP->RtaUniqueNum = 0; */
193 /* MapP->Flags = 0; */
194 /* MapP->SysPort = 0; */
195 /* MapP->Name[0] = 0; */
199 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
200 if (MapP->RtaUniqueNum) { /* (5) */
202 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
203 p->RIOError.Error = ZERO_RTA_ID;
204 p->RIOError.Entry = Entry;
207 if (MapP->ID > MAX_RUP) {
208 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
209 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
210 p->RIOError.Entry = Entry;
213 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
214 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
215 rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
216 p->RIOError.Error = DUPLICATED_RTA_ID;
217 p->RIOError.Entry = Entry;
218 p->RIOError.Other = SubEnt;
222 ** If the RtaUniqueNum is the same, it may be looking at both
223 ** entries for a 16 port RTA, so check the ids
225 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
226 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
227 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
228 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
229 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
230 p->RIOError.Entry = Entry;
231 p->RIOError.Other = SubEnt;
235 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
237 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
238 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);
239 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
240 p->RIOError.Entry = Entry;
243 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
245 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
246 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
247 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
248 p->RIOError.Entry = Entry;
251 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
252 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
254 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
255 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
257 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
258 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
259 p->RIOError.Error = TTY_NUMBER_IN_USE;
260 p->RIOError.Entry = Entry;
261 p->RIOError.Other = SubEnt;
264 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
265 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
266 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
267 p->RIOError.Error = NAME_USED_TWICE;
268 p->RIOError.Entry = Entry;
269 p->RIOError.Other = SubEnt;
275 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
277 rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
278 p->RIOError.Error = HOST_ID_NOT_ZERO;
279 p->RIOError.Entry = Entry;
282 if (MapP->SysPort != NO_PORT) {
283 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
284 p->RIOError.Error = HOST_SYSPORT_BAD;
285 p->RIOError.Entry = Entry;
292 ** wow! if we get here then it's a goody!
296 ** Zero the (old) entries for each host...
298 for (Host = 0; Host < RIO_HOSTS; Host++) {
299 for (Entry = 0; Entry < MAX_RUP; Entry++) {
300 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
302 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
306 ** Copy in the new table entries
308 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
309 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
310 MapP = &p->RIOConnectTable[Entry];
313 ** Now, if it is an empty slot ignore it!
315 if (MapP->HostUniqueNum == 0)
319 ** we saved the host number earlier, so grab it back
321 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
324 ** If it is a host, then we only need to fill in the name field.
327 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
328 bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN);
333 ** Its an RTA entry, so fill in the host mapping entries for it
334 ** and the port mapping entries. Notice that entry zero is for
337 HostMapP = &HostP->Mapping[MapP->ID - 1];
339 if (MapP->Flags & SLOT_IN_USE) {
340 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
342 ** structure assign, then sort out the bits we shouldn't have done
346 HostMapP->Flags = SLOT_IN_USE;
347 if (MapP->Flags & RTA16_SECOND_SLOT)
348 HostMapP->Flags |= RTA16_SECOND_SLOT;
350 RIOReMapPorts(p, HostP, HostMapP);
352 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
356 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
357 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
360 for (Host = 0; Host < p->RIONumHosts; Host++) {
361 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
362 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
363 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
365 for (Entry = 0; Entry < MAX_RUP; Entry++) {
366 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
367 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
368 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
371 if (!p->RIOHosts[Host].Name[0]) {
372 bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
373 p->RIOHosts[Host].Name[5] += Host;
376 ** Check that default name assigned is unique.
380 while (!NameIsUnique) {
382 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
385 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
389 if (Host1 >= p->RIONumHosts)
391 p->RIOHosts[Host].Name[5] = '1' + Host1;
396 ** Rename host if name already used.
399 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
400 bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
401 p->RIOHosts[Host].Name[5] += Host1;
403 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
409 ** User process needs the config table - build it from first
414 int RIOApel(struct rio_info *p)
424 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
426 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
428 for (Host = 0; Host < RIO_HOSTS; Host++) {
429 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
430 HostP = &p->RIOHosts[Host];
431 rio_spin_lock_irqsave(&HostP->HostLock, flags);
433 MapP = &p->RIOConnectTable[Next++];
434 MapP->HostUniqueNum = HostP->UniqueNum;
435 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
437 MapP->RtaUniqueNum = 0;
439 MapP->Flags = SLOT_IN_USE;
440 MapP->SysPort = NO_PORT;
441 for (link = 0; link < LINKS_PER_UNIT; link++)
442 MapP->Topology[link] = HostP->Topology[link];
443 bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN);
444 for (Rup = 0; Rup < MAX_RUP; Rup++) {
445 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
446 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
447 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
448 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
449 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
450 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
451 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
452 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
456 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
462 ** config.rio has taken a dislike to one of the gross maps entries.
463 ** if the entry is suitably inactive, then we can gob on it and remove
464 ** it from the table.
466 int RIODeleteRta(struct rio_info *p, struct Map *MapP)
468 int host, entry, port, link;
471 struct Map *HostMapP;
474 unsigned long lock_flags, sem_flags;
476 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
478 for (host = 0; host < p->RIONumHosts; host++) {
479 HostP = &p->RIOHosts[host];
481 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
483 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
484 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
488 for (entry = 0; entry < MAX_RUP; entry++) {
489 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
490 HostMapP = &HostP->Mapping[entry];
491 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
494 ** Check all four links of the unit are disconnected
496 for (link = 0; link < LINKS_PER_UNIT; link++) {
497 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
498 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
499 p->RIOError.Error = UNIT_IS_IN_USE;
500 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
505 ** Slot has been allocated, BUT not booted/routed/
506 ** connected/selected or anything else-ed
508 SysPort = HostMapP->SysPort;
510 if (SysPort != NO_PORT) {
511 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
512 PortP = p->RIOPortp[port];
513 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
515 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
519 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
521 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
522 PortP->TxBufferIn = PortP->TxBufferOut = 0;
524 wakeup( &PortP->TxBufferIn );
525 wakeup( &PortP->TxBufferOut);
527 PortP->InUse = NOT_INUSE;
529 wakeup( &PortP->InUse );
530 signal(PortP->TtyP->t_pgrp,SIGKILL);
531 ttyflush(PortP->TtyP,(FREAD|FWRITE));
533 PortP->State |= RIO_CLOSING | RIO_DELETED;
537 ** For the second slot of a 16 port RTA, the
538 ** driver needs to reset the changes made to
539 ** the phb to port mappings in RIORouteRup.
541 if (PortP->SecondBlock) {
542 ushort dest_unit = HostMapP->ID;
543 ushort dest_port = port - SysPort;
547 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
549 ** *TxPktP is the pointer to the
550 ** transmit packet on the host card.
551 ** This needs to be translated into
552 ** a 32 bit pointer so it can be
553 ** accessed from the driver.
555 Pkt = (PKT *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
556 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port);
557 writew(dest_unit, &Pkt->dest_unit);
558 writew(dest_port, &Pkt->dest_port);
560 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port);
561 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
563 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
566 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
567 memset(HostMapP, 0, sizeof(struct Map));
571 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
574 /* XXXXX lock me up */
575 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
576 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
577 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
580 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
581 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
588 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
589 p->RIOError.Error = COULDNT_FIND_ENTRY;
593 int RIOAssignRta(struct rio_info *p, struct Map *MapP)
596 struct Map *HostMapP;
601 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);
603 if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
604 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
605 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
608 if (MapP->RtaUniqueNum == 0) {
609 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
610 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
613 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
614 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
615 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
618 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
619 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
620 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
625 ** Copy the name across to the map entry.
627 MapP->Name[MAX_NAME_LEN - 1] = '\0';
630 if (*sptr < ' ' || *sptr > '~') {
631 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
632 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
638 for (host = 0; host < p->RIONumHosts; host++) {
639 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
640 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
641 p->RIOError.Error = HOST_NOT_RUNNING;
646 ** Now we have a host we need to allocate an ID
647 ** if the entry does not already have one.
649 if (MapP->ID == (ushort) - 1) {
652 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
654 ** The idea here is to allow RTA's to be assigned
655 ** before they actually appear on the network.
656 ** This allows the addition of RTA's without having
659 ** - Find a free ID and allocate it to the RTA.
660 ** - If this map entry is the second half of a
661 ** 16 port entry then find the other half and
662 ** make sure the 2 cross reference each other.
664 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
665 p->RIOError.Error = COULDNT_FIND_ENTRY;
668 MapP->ID = (ushort) nNewID + 1;
669 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
670 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
671 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
672 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
673 HostMapP->ID = MapP->ID;
674 for (link = 0; link < LINKS_PER_UNIT; link++) {
675 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
676 HostMapP->Topology[link].Link = NO_LINK;
678 if (MapP->Flags & RTA16_SECOND_SLOT) {
681 for (unit = 0; unit < MAX_RUP; unit++)
682 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
684 if (unit == MAX_RUP) {
685 p->RIOError.Error = COULDNT_FIND_ENTRY;
688 HostMapP->Flags |= RTA16_SECOND_SLOT;
689 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
690 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
691 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
695 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
697 if (HostMapP->Flags & SLOT_IN_USE) {
698 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
699 p->RIOError.Error = ID_ALREADY_IN_USE;
704 ** Assign the sys ports and the name, and mark the slot as
707 HostMapP->SysPort = MapP->SysPort;
708 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
709 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
710 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
712 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
714 if (MapP->Flags & RTA16_SECOND_SLOT)
715 HostMapP->Flags |= RTA16_SECOND_SLOT;
717 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
719 ** Adjust 2nd block of 8 phbs
721 if (MapP->Flags & RTA16_SECOND_SLOT)
722 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
724 if (HostMapP->SysPort != NO_PORT) {
725 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
726 p->RIOFirstPortsBooted = HostMapP->SysPort;
727 if (HostMapP->SysPort > p->RIOLastPortsBooted)
728 p->RIOLastPortsBooted = HostMapP->SysPort;
730 if (MapP->Flags & RTA16_SECOND_SLOT)
731 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
733 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
737 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
738 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
743 int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
752 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
755 ** We need to tell the UnixRups which sysport the rup corresponds to
757 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
759 if (HostMapP->SysPort == NO_PORT)
762 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
763 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
766 ** now map each of its eight ports
768 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
769 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
770 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
771 /* portnumber on host */
773 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
775 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
776 PortP = p->RIOPortp[SysPort];
777 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
780 ** Point at all the real neat data structures
782 rio_spin_lock_irqsave(&PortP->portSem, flags);
783 PortP->HostP = HostP;
784 PortP->Caddr = HostP->Caddr;
787 ** The PhbP cannot be filled in yet
788 ** unless the host has been booted
790 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
791 struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
792 PortP->TxAdd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
793 PortP->TxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
794 PortP->TxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
795 PortP->RxRemove = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
796 PortP->RxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
797 PortP->RxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
802 ** port related flags
804 PortP->HostPort = HostPort;
806 ** For each part of a 16 port RTA, RupNum is ID - 1.
808 PortP->RupNum = HostMapP->ID - 1;
809 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
810 PortP->ID2 = HostMapP->ID2 - 1;
811 PortP->SecondBlock = TRUE;
814 PortP->SecondBlock = FALSE;
816 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
819 ** If the port was already mapped then thats all we need to do.
822 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
825 HostMapP->Flags &= ~RTA_NEWBOOT;
830 ** Check out the module type - if it is special (read only etc.)
831 ** then we need to set flags in the PortP->Config.
832 ** Note: For 16 port RTA, all ports are of the same type.
834 if (RtaType == TYPE_RTA16) {
835 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
837 if (SubEnt < PORTS_PER_MODULE)
838 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
840 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
844 ** more port related flags
846 PortP->PortState = 0;
847 PortP->ModemLines = 0;
848 PortP->ModemState = 0;
849 PortP->CookMode = COOK_WELL;
851 PortP->FlushCmdBodge = 0;
852 PortP->WflushFlag = 0;
853 PortP->MagicFlags = 0;
856 PortP->FirstOpen = 1;
861 PortP->RxDataStart = 0;
863 PortP->Name = &HostMapP->Name[0];
864 PortP->statsGather = 0;
870 if (PortP->TxRingBuffer)
871 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
872 else if (p->RIOBufferSize) {
873 PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL);
874 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
876 PortP->TxBufferOut = 0;
877 PortP->TxBufferIn = 0;
880 ** LastRxTgl stores the state of the rx toggle bit for this
881 ** port, to be compared with the state of the next pkt received.
882 ** If the same, we have received the same rx pkt from the RTA
883 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
885 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
888 ** and mark the port as usable
891 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
893 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
894 p->RIOFirstPortsMapped = HostMapP->SysPort;
895 if (HostMapP->SysPort > p->RIOLastPortsMapped)
896 p->RIOLastPortsMapped = HostMapP->SysPort;
901 int RIOChangeName(struct rio_info *p, struct Map *MapP)
904 struct Map *HostMapP;
907 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);
909 if (MapP->ID > MAX_RUP) {
910 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
911 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
915 MapP->Name[MAX_NAME_LEN - 1] = '\0';
919 if (*sptr < ' ' || *sptr > '~') {
920 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
921 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
927 for (host = 0; host < p->RIONumHosts; host++) {
928 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
929 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
930 p->RIOError.Error = HOST_NOT_RUNNING;
934 CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN);
938 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
940 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
941 p->RIOError.Error = RTA_NUMBER_WRONG;
944 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
948 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
949 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);