/* ** A configuration table has been loaded. It is now up to us ** to sort it out and use the information contained therein. */ int RIONewTable(struct rio_info *p) { int Host, Host1, Host2, NameIsUnique, Entry, SubEnt; struct Map *MapP; struct Map *HostMapP; struct Host *HostP; char *cptr; /* ** We have been sent a new table to install. We need to break ** it down into little bits and spread it around a bit to see ** what we have got. */ /* ** Things to check: ** (things marked 'xx' aren't checked any more!) ** (1) That there are no booted Hosts/RTAs out there. ** (2) That the names are properly formed ** (3) That blank entries really are. ** xx (4) That hosts mentioned in the table actually exist. xx ** (5) That the IDs are unique (per host). ** (6) That host IDs are zero ** (7) That port numbers are valid ** (8) That port numbers aren't duplicated ** (9) That names aren't duplicated ** xx (10) That hosts that actually exist are mentioned in the table. xx */ rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n"); if (p->RIOSystemUp) { /* (1) */ p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED; return -EBUSY; } p->RIOError.Error = NOTHING_WRONG_AT_ALL; p->RIOError.Entry = -1; p->RIOError.Other = -1; for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { MapP = &p->RIOConnectTable[Entry]; if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) { rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n"); cptr = MapP->Name; /* (2) */ cptr[MAX_NAME_LEN - 1] = '\0'; if (cptr[0] == '\0') { memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8); MapP->Name[5] = '0' + Entry / 10; MapP->Name[6] = '0' + Entry % 10; } while (*cptr) { if (*cptr < ' ' || *cptr > '~') { p->RIOError.Error = BAD_CHARACTER_IN_NAME; p->RIOError.Entry = Entry; return -ENXIO; } cptr++; } } /* ** If the entry saved was a tentative entry then just forget ** about it. */ if (MapP->Flags & SLOT_TENTATIVE) { MapP->HostUniqueNum = 0; MapP->RtaUniqueNum = 0; continue; } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n"); if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */ if (MapP->ID || MapP->SysPort || MapP->Flags) { rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name); p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL; p->RIOError.Entry = Entry; return -ENXIO; } rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n"); continue; } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n"); for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */ if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) { HostP = &p->RIOHosts[Host]; /* ** having done the lookup, we don't really want to do ** it again, so hang the host number in a safe place */ MapP->Topology[0].Unit = Host; break; } } if (Host >= p->RIONumHosts) { rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum); MapP->HostUniqueNum = 0; /* MapP->RtaUniqueNum = 0; */ /* MapP->ID = 0; */ /* MapP->Flags = 0; */ /* MapP->SysPort = 0; */ /* MapP->Name[0] = 0; */ continue; } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n"); if (MapP->RtaUniqueNum) { /* (5) */ if (!MapP->ID) { rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name); p->RIOError.Error = ZERO_RTA_ID; p->RIOError.Entry = Entry; return -ENXIO; } if (MapP->ID > MAX_RUP) { rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID); p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; p->RIOError.Entry = Entry; return -ENXIO; } for (SubEnt = 0; SubEnt < Entry; SubEnt++) { if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) { rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name); p->RIOError.Error = DUPLICATED_RTA_ID; p->RIOError.Entry = Entry; p->RIOError.Other = SubEnt; return -ENXIO; } /* ** If the RtaUniqueNum is the same, it may be looking at both ** entries for a 16 port RTA, so check the ids */ if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum) && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) { rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name); rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name); p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER; p->RIOError.Entry = Entry; p->RIOError.Other = SubEnt; return -ENXIO; } } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n"); /* (7a) */ if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) { 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); p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; p->RIOError.Entry = Entry; return -ENXIO; } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n"); /* (7b) */ if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) { rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name); p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; p->RIOError.Entry = Entry; return -ENXIO; } for (SubEnt = 0; SubEnt < Entry; SubEnt++) { if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT) continue; if (p->RIOConnectTable[SubEnt].RtaUniqueNum) { rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n"); /* (8) */ if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) { rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort); p->RIOError.Error = TTY_NUMBER_IN_USE; p->RIOError.Entry = Entry; p->RIOError.Other = SubEnt; return -ENXIO; } rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n"); if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */ rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name); p->RIOError.Error = NAME_USED_TWICE; p->RIOError.Entry = Entry; p->RIOError.Other = SubEnt; return -ENXIO; } } } } else { /* (6) */ rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n"); if (MapP->ID) { rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name); p->RIOError.Error = HOST_ID_NOT_ZERO; p->RIOError.Entry = Entry; return -ENXIO; } if (MapP->SysPort != NO_PORT) { rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name); p->RIOError.Error = HOST_SYSPORT_BAD; p->RIOError.Entry = Entry; return -ENXIO; } } } /* ** wow! if we get here then it's a goody! */ /* ** Zero the (old) entries for each host... */ for (Host = 0; Host < RIO_HOSTS; Host++) { for (Entry = 0; Entry < MAX_RUP; Entry++) { memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map)); } memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name)); } /* ** Copy in the new table entries */ for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry); MapP = &p->RIOConnectTable[Entry]; /* ** Now, if it is an empty slot ignore it! */ if (MapP->HostUniqueNum == 0) continue; /* ** we saved the host number earlier, so grab it back */ HostP = &p->RIOHosts[MapP->Topology[0].Unit]; /* ** If it is a host, then we only need to fill in the name field. */ if (MapP->ID == 0) { rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name); memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN); continue; } /* ** Its an RTA entry, so fill in the host mapping entries for it ** and the port mapping entries. Notice that entry zero is for ** ID one. */ HostMapP = &HostP->Mapping[MapP->ID - 1]; if (MapP->Flags & SLOT_IN_USE) { rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name); /* ** structure assign, then sort out the bits we shouldn't have done */ *HostMapP = *MapP; HostMapP->Flags = SLOT_IN_USE; if (MapP->Flags & RTA16_SECOND_SLOT) HostMapP->Flags |= RTA16_SECOND_SLOT; RIOReMapPorts(p, HostP, HostMapP); } else { rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name); } } for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) { p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry]; } for (Host = 0; Host < p->RIONumHosts; Host++) { for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) { p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT; p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK; } for (Entry = 0; Entry < MAX_RUP; Entry++) { for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) { p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT; p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK; } } if (!p->RIOHosts[Host].Name[0]) { memcpy(p->RIOHosts[Host].Name, "HOST 1", 7); p->RIOHosts[Host].Name[5] += Host; } /* ** Check that default name assigned is unique. */ Host1 = Host; NameIsUnique = 0; while (!NameIsUnique) { NameIsUnique = 1; for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) { if (Host2 == Host) continue; if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name) == 0) { NameIsUnique = 0; Host1++; if (Host1 >= p->RIONumHosts) Host1 = 0; p->RIOHosts[Host].Name[5] = '1' + Host1; } } } /* ** Rename host if name already used. */ if (Host1 != Host) { rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name); memcpy(p->RIOHosts[Host].Name, "HOST 1", 7); p->RIOHosts[Host].Name[5] += Host1; } rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name); } return 0; }
int RIOAssignRta(struct rio_info *p, struct Map *MapP) { int host; struct Map *HostMapP; char *sptr; int link; ; if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) { ; p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE; return -EINVAL; } if (MapP->RtaUniqueNum == 0) { ; p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO; return -EINVAL; } if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) { ; p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; return -EINVAL; } if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) { ; p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE; return -EINVAL; } /* ** Copy the name across to the map entry. */ MapP->Name[MAX_NAME_LEN - 1] = '\0'; sptr = MapP->Name; while (*sptr) { if (*sptr < ' ' || *sptr > '~') { ; p->RIOError.Error = BAD_CHARACTER_IN_NAME; return -EINVAL; } sptr++; } for (host = 0; host < p->RIONumHosts; host++) { if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) { if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) { p->RIOError.Error = HOST_NOT_RUNNING; return -ENXIO; } /* ** Now we have a host we need to allocate an ID ** if the entry does not already have one. */ if (MapP->ID == (u16) - 1) { int nNewID; ; /* ** The idea here is to allow RTA's to be assigned ** before they actually appear on the network. ** This allows the addition of RTA's without having ** to plug them in. ** What we do is: ** - Find a free ID and allocate it to the RTA. ** - If this map entry is the second half of a ** 16 port entry then find the other half and ** make sure the 2 cross reference each other. */ if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) { p->RIOError.Error = COULDNT_FIND_ENTRY; return -EBUSY; } MapP->ID = (u16) nNewID + 1; ; HostMapP = &p->RIOHosts[host].Mapping[nNewID]; HostMapP->RtaUniqueNum = MapP->RtaUniqueNum; HostMapP->HostUniqueNum = MapP->HostUniqueNum; HostMapP->ID = MapP->ID; for (link = 0; link < LINKS_PER_UNIT; link++) { HostMapP->Topology[link].Unit = ROUTE_DISCONNECT; HostMapP->Topology[link].Link = NO_LINK; } if (MapP->Flags & RTA16_SECOND_SLOT) { int unit; for (unit = 0; unit < MAX_RUP; unit++) if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum) break; if (unit == MAX_RUP) { p->RIOError.Error = COULDNT_FIND_ENTRY; return -EBUSY; } HostMapP->Flags |= RTA16_SECOND_SLOT; HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID; p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID; ; } } HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1]; if (HostMapP->Flags & SLOT_IN_USE) { ; p->RIOError.Error = ID_ALREADY_IN_USE; return -EBUSY; } /* ** Assign the sys ports and the name, and mark the slot as ** being in use. */ HostMapP->SysPort = MapP->SysPort; if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN); HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED; #ifdef NEED_TO_FIX RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]); #endif if (MapP->Flags & RTA16_SECOND_SLOT) HostMapP->Flags |= RTA16_SECOND_SLOT; RIOReMapPorts(p, &p->RIOHosts[host], HostMapP); /* ** Adjust 2nd block of 8 phbs */ if (MapP->Flags & RTA16_SECOND_SLOT) RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1); if (HostMapP->SysPort != NO_PORT) { if (HostMapP->SysPort < p->RIOFirstPortsBooted) p->RIOFirstPortsBooted = HostMapP->SysPort; if (HostMapP->SysPort > p->RIOLastPortsBooted) p->RIOLastPortsBooted = HostMapP->SysPort; } if (MapP->Flags & RTA16_SECOND_SLOT) ; else ; return 0; } } p->RIOError.Error = UNKNOWN_HOST_NUMBER; ; return -ENXIO; }