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.
 
  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", MapP->Name, MapP->HostUniqueNum);
 
 191                         MapP->HostUniqueNum = 0;
 
 192                         /* MapP->RtaUniqueNum   = 0; */
 
 194                         /* MapP->Flags           = 0; */
 
 195                         /* MapP->SysPort                 = 0; */
 
 196                         /* MapP->Name[0]                 = 0; */
 
 200                 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
 
 201                 if (MapP->RtaUniqueNum) {       /* (5) */
 
 203                                 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
 
 204                                 p->RIOError.Error = ZERO_RTA_ID;
 
 205                                 p->RIOError.Entry = Entry;
 
 208                         if (MapP->ID > MAX_RUP) {
 
 209                                 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
 
 210                                 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
 
 211                                 p->RIOError.Entry = Entry;
 
 214                         for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
 
 215                                 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
 
 216                                         rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
 
 217                                         p->RIOError.Error = DUPLICATED_RTA_ID;
 
 218                                         p->RIOError.Entry = Entry;
 
 219                                         p->RIOError.Other = SubEnt;
 
 223                                  ** If the RtaUniqueNum is the same, it may be looking at both
 
 224                                  ** entries for a 16 port RTA, so check the ids
 
 226                                 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
 
 227                                     && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
 
 228                                         rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
 
 229                                         rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
 
 230                                         p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
 
 231                                         p->RIOError.Entry = Entry;
 
 232                                         p->RIOError.Other = SubEnt;
 
 236                         rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
 
 238                         if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
 
 239                                 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);
 
 240                                 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 
 241                                 p->RIOError.Entry = Entry;
 
 244                         rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
 
 246                         if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
 
 247                                 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
 
 248                                 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 
 249                                 p->RIOError.Entry = Entry;
 
 252                         for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
 
 253                                 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
 
 255                                 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
 
 256                                         rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
 
 258                                         if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
 
 259                                                 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
 
 260                                                 p->RIOError.Error = TTY_NUMBER_IN_USE;
 
 261                                                 p->RIOError.Entry = Entry;
 
 262                                                 p->RIOError.Other = SubEnt;
 
 265                                         rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
 
 266                                         if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) {   /* (9) */
 
 267                                                 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
 
 268                                                 p->RIOError.Error = NAME_USED_TWICE;
 
 269                                                 p->RIOError.Entry = Entry;
 
 270                                                 p->RIOError.Other = SubEnt;
 
 276                         rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
 
 278                                 rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
 
 279                                 p->RIOError.Error = HOST_ID_NOT_ZERO;
 
 280                                 p->RIOError.Entry = Entry;
 
 283                         if (MapP->SysPort != NO_PORT) {
 
 284                                 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
 
 285                                 p->RIOError.Error = HOST_SYSPORT_BAD;
 
 286                                 p->RIOError.Entry = Entry;
 
 293          ** wow! if we get here then it's a goody!
 
 297          ** Zero the (old) entries for each host...
 
 299         for (Host = 0; Host < RIO_HOSTS; Host++) {
 
 300                 for (Entry = 0; Entry < MAX_RUP; Entry++) {
 
 301                         bzero((caddr_t) & p->RIOHosts[Host].Mapping[Entry], sizeof(struct Map));
 
 303                 bzero((caddr_t) & p->RIOHosts[Host].Name[0], sizeof(p->RIOHosts[Host].Name));
 
 307          ** Copy in the new table entries
 
 309         for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
 
 310                 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
 
 311                 MapP = &p->RIOConnectTable[Entry];
 
 314                  ** Now, if it is an empty slot ignore it!
 
 316                 if (MapP->HostUniqueNum == 0)
 
 320                  ** we saved the host number earlier, so grab it back
 
 322                 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
 
 325                  ** If it is a host, then we only need to fill in the name field.
 
 328                         rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
 
 329                         bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN);
 
 334                  ** Its an RTA entry, so fill in the host mapping entries for it
 
 335                  ** and the port mapping entries. Notice that entry zero is for
 
 338                 HostMapP = &HostP->Mapping[MapP->ID - 1];
 
 340                 if (MapP->Flags & SLOT_IN_USE) {
 
 341                         rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
 
 343                          ** structure assign, then sort out the bits we shouldn't have done
 
 347                         HostMapP->Flags = SLOT_IN_USE;
 
 348                         if (MapP->Flags & RTA16_SECOND_SLOT)
 
 349                                 HostMapP->Flags |= RTA16_SECOND_SLOT;
 
 351                         RIOReMapPorts(p, HostP, HostMapP);
 
 353                         rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
 
 357         for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
 
 358                 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
 
 361         for (Host = 0; Host < p->RIONumHosts; Host++) {
 
 362                 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
 
 363                         p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
 
 364                         p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
 
 366                 for (Entry = 0; Entry < MAX_RUP; Entry++) {
 
 367                         for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
 
 368                                 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
 
 369                                 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
 
 372                 if (!p->RIOHosts[Host].Name[0]) {
 
 373                         bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
 
 374                         p->RIOHosts[Host].Name[5] += Host;
 
 377                  ** Check that default name assigned is unique.
 
 381                 while (!NameIsUnique) {
 
 383                         for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
 
 386                                 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
 
 390                                         if (Host1 >= p->RIONumHosts)
 
 392                                         p->RIOHosts[Host].Name[5] = '1' + Host1;
 
 397                  ** Rename host if name already used.
 
 400                         rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
 
 401                         bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
 
 402                         p->RIOHosts[Host].Name[5] += Host1;
 
 404                 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
 
 410 ** User process needs the config table - build it from first
 
 424         disable(oldspl);        /* strange but true! */
 
 426         rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
 
 428         bzero((caddr_t) & p->RIOConnectTable[0], sizeof(struct Map) * TOTAL_MAP_ENTRIES);
 
 430         for (Host = 0; Host < RIO_HOSTS; Host++) {
 
 431                 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
 
 432                 HostP = &p->RIOHosts[Host];
 
 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;
 
 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(p, MapP)
 
 470         int host, entry, port, link;
 
 473         struct Map *HostMapP;
 
 476         unsigned long lock_flags, sem_flags;
 
 478         rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
 
 480         for (host = 0; host < p->RIONumHosts; host++) {
 
 481                 HostP = &p->RIOHosts[host];
 
 483                 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
 
 485                 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
 
 486                         rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
 
 490                 for (entry = 0; entry < MAX_RUP; entry++) {
 
 491                         if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
 
 492                                 HostMapP = &HostP->Mapping[entry];
 
 493                                 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
 
 496                                  ** Check all four links of the unit are disconnected
 
 498                                 for (link = 0; link < LINKS_PER_UNIT; link++) {
 
 499                                         if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
 
 500                                                 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
 
 501                                                 p->RIOError.Error = UNIT_IS_IN_USE;
 
 502                                                 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
 
 507                                  ** Slot has been allocated, BUT not booted/routed/
 
 508                                  ** connected/selected or anything else-ed
 
 510                                 SysPort = HostMapP->SysPort;
 
 512                                 if (SysPort != NO_PORT) {
 
 513                                         for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
 
 514                                                 PortP = p->RIOPortp[port];
 
 515                                                 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
 
 517                                                 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
 
 521                                                 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
 
 523                                                         rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
 
 524                                                         PortP->TxBufferIn = PortP->TxBufferOut = 0;
 
 526                                                            wakeup( &PortP->TxBufferIn );
 
 527                                                            wakeup( &PortP->TxBufferOut);
 
 529                                                         PortP->InUse = NOT_INUSE;
 
 531                                                            wakeup( &PortP->InUse );
 
 532                                                            signal(PortP->TtyP->t_pgrp,SIGKILL);
 
 533                                                            ttyflush(PortP->TtyP,(FREAD|FWRITE));
 
 535                                                         PortP->State |= RIO_CLOSING | RIO_DELETED;
 
 539                                                  ** For the second slot of a 16 port RTA, the
 
 540                                                  ** driver needs to reset the changes made to
 
 541                                                  ** the phb to port mappings in RIORouteRup.
 
 543                                                 if (PortP->SecondBlock) {
 
 544                                                         ushort dest_unit = HostMapP->ID;
 
 545                                                         ushort dest_port = port - SysPort;
 
 549                                                         for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
 
 551                                                                  ** *TxPktP is the pointer to the
 
 552                                                                  ** transmit packet on the host card.
 
 553                                                                  ** This needs to be translated into
 
 554                                                                  ** a 32 bit pointer so it can be
 
 555                                                                  ** accessed from the driver.
 
 557                                                                 Pkt = (PKT *) RIO_PTR(HostP->Caddr, RWORD(*TxPktP));
 
 558                                                                 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);
 
 559                                                                 WWORD(Pkt->dest_unit, dest_unit);
 
 560                                                                 WWORD(Pkt->dest_port, dest_port);
 
 562                                                         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);
 
 563                                                         WWORD(PortP->PhbP->destination, dest_unit + (dest_port << 8));
 
 565                                                 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
 
 568                                 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
 
 569                                 bzero((char *) HostMapP, sizeof(struct Map));
 
 573                 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
 
 576         /* XXXXX lock me up */
 
 577         for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
 
 578                 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
 
 579                         bzero((char *) &p->RIOSavedTable[entry], sizeof(struct Map));
 
 582                 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
 
 583                         bzero((char *) &p->RIOConnectTable[entry], sizeof(struct Map));
 
 590         rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
 
 591         p->RIOError.Error = COULDNT_FIND_ENTRY;
 
 595 int RIOAssignRta(struct rio_info *p, struct Map *MapP)
 
 598         struct Map *HostMapP;
 
 603         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);
 
 605         if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
 
 606                 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
 
 607                 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
 
 610         if (MapP->RtaUniqueNum == 0) {
 
 611                 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
 
 612                 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
 
 615         if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
 
 616                 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
 
 617                 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 
 620         if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
 
 621                 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
 
 622                 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
 
 627          ** Copy the name across to the map entry.
 
 629         MapP->Name[MAX_NAME_LEN - 1] = '\0';
 
 632                 if (*sptr < ' ' || *sptr > '~') {
 
 633                         rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
 
 634                         p->RIOError.Error = BAD_CHARACTER_IN_NAME;
 
 640         for (host = 0; host < p->RIONumHosts; host++) {
 
 641                 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
 
 642                         if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
 
 643                                 p->RIOError.Error = HOST_NOT_RUNNING;
 
 648                          ** Now we have a host we need to allocate an ID
 
 649                          ** if the entry does not already have one.
 
 651                         if (MapP->ID == (ushort) - 1) {
 
 654                                 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
 
 656                                  ** The idea here is to allow RTA's to be assigned
 
 657                                  ** before they actually appear on the network.
 
 658                                  ** This allows the addition of RTA's without having
 
 661                                  **  - Find a free ID and allocate it to the RTA.
 
 662                                  **  - If this map entry is the second half of a
 
 663                                  **    16 port entry then find the other half and
 
 664                                  **    make sure the 2 cross reference each other.
 
 666                                 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
 
 667                                         p->RIOError.Error = COULDNT_FIND_ENTRY;
 
 670                                 MapP->ID = (ushort) nNewID + 1;
 
 671                                 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
 
 672                                 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
 
 673                                 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
 
 674                                 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
 
 675                                 HostMapP->ID = MapP->ID;
 
 676                                 for (link = 0; link < LINKS_PER_UNIT; link++) {
 
 677                                         HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
 
 678                                         HostMapP->Topology[link].Link = NO_LINK;
 
 680                                 if (MapP->Flags & RTA16_SECOND_SLOT) {
 
 683                                         for (unit = 0; unit < MAX_RUP; unit++)
 
 684                                                 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
 
 686                                         if (unit == MAX_RUP) {
 
 687                                                 p->RIOError.Error = COULDNT_FIND_ENTRY;
 
 690                                         HostMapP->Flags |= RTA16_SECOND_SLOT;
 
 691                                         HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
 
 692                                         p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
 
 693                                         rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
 
 697                         HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
 
 699                         if (HostMapP->Flags & SLOT_IN_USE) {
 
 700                                 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
 
 701                                 p->RIOError.Error = ID_ALREADY_IN_USE;
 
 706                          ** Assign the sys ports and the name, and mark the slot as
 
 709                         HostMapP->SysPort = MapP->SysPort;
 
 710                         if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
 
 711                                 CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
 
 712                         HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
 
 714                         RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
 
 716                         if (MapP->Flags & RTA16_SECOND_SLOT)
 
 717                                 HostMapP->Flags |= RTA16_SECOND_SLOT;
 
 719                         RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
 
 721                          ** Adjust 2nd block of 8 phbs
 
 723                         if (MapP->Flags & RTA16_SECOND_SLOT)
 
 724                                 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
 
 726                         if (HostMapP->SysPort != NO_PORT) {
 
 727                                 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
 
 728                                         p->RIOFirstPortsBooted = HostMapP->SysPort;
 
 729                                 if (HostMapP->SysPort > p->RIOLastPortsBooted)
 
 730                                         p->RIOLastPortsBooted = HostMapP->SysPort;
 
 732                         if (MapP->Flags & RTA16_SECOND_SLOT)
 
 733                                 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
 
 735                                 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
 
 739         p->RIOError.Error = UNKNOWN_HOST_NUMBER;
 
 740         rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
 
 745 int RIOReMapPorts(p, HostP, HostMapP)
 
 748 struct Map *HostMapP;
 
 750         register struct Port *PortP;
 
 757         rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
 
 760          ** We need to tell the UnixRups which sysport the rup corresponds to
 
 762         HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
 
 764         if (HostMapP->SysPort == NO_PORT)
 
 767         RtaType = GetUnitType(HostMapP->RtaUniqueNum);
 
 768         rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
 
 771          ** now map each of its eight ports
 
 773         for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
 
 774                 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
 
 775                 SysPort = HostMapP->SysPort + SubEnt;   /* portnumber within system */
 
 776                 /* portnumber on host */
 
 778                 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
 
 780                 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
 
 781                 PortP = p->RIOPortp[SysPort];
 
 782                 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
 
 785                  ** Point at all the real neat data structures
 
 787                 rio_spin_lock_irqsave(&PortP->portSem, flags);
 
 788                 PortP->HostP = HostP;
 
 789                 PortP->Caddr = HostP->Caddr;
 
 792                  ** The PhbP cannot be filled in yet
 
 793                  ** unless the host has been booted
 
 795                 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
 
 796                         struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
 
 797                         PortP->TxAdd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_add));
 
 798                         PortP->TxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_start));
 
 799                         PortP->TxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->tx_end));
 
 800                         PortP->RxRemove = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_remove));
 
 801                         PortP->RxStart = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_start));
 
 802                         PortP->RxEnd = (WORD *) RIO_PTR(HostP->Caddr, RWORD(PhbP->rx_end));
 
 807                  ** port related flags
 
 809                 PortP->HostPort = HostPort;
 
 811                  ** For each part of a 16 port RTA, RupNum is ID - 1.
 
 813                 PortP->RupNum = HostMapP->ID - 1;
 
 814                 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
 
 815                         PortP->ID2 = HostMapP->ID2 - 1;
 
 816                         PortP->SecondBlock = TRUE;
 
 819                         PortP->SecondBlock = FALSE;
 
 821                 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
 
 824                  ** If the port was already mapped then thats all we need to do.
 
 827                         rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 
 830                         HostMapP->Flags &= ~RTA_NEWBOOT;
 
 835                  ** Check out the module type - if it is special (read only etc.)
 
 836                  ** then we need to set flags in the PortP->Config.
 
 837                  ** Note: For 16 port RTA, all ports are of the same type.
 
 839                 if (RtaType == TYPE_RTA16) {
 
 840                         PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
 
 842                         if (SubEnt < PORTS_PER_MODULE)
 
 843                                 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
 
 845                                 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
 
 849                  ** more port related flags
 
 851                 PortP->PortState = 0;
 
 852                 PortP->ModemLines = 0;
 
 853                 PortP->ModemState = 0;
 
 854                 PortP->CookMode = COOK_WELL;
 
 856                 PortP->FlushCmdBodge = 0;
 
 857                 PortP->WflushFlag = 0;
 
 858                 PortP->MagicFlags = 0;
 
 861                 PortP->FirstOpen = 1;
 
 866                 PortP->RxDataStart = 0;
 
 868                 PortP->Name = &HostMapP->Name[0];
 
 870                 bzero((caddr_t) & PortP->Stat, sizeof(struct RIOStats));
 
 872                 PortP->statsGather = 0;
 
 878                 if (PortP->TxRingBuffer)
 
 879                         bzero(PortP->TxRingBuffer, p->RIOBufferSize);
 
 880                 else if (p->RIOBufferSize) {
 
 881                         PortP->TxRingBuffer = sysbrk(p->RIOBufferSize);
 
 882                         bzero(PortP->TxRingBuffer, p->RIOBufferSize);
 
 884                 PortP->TxBufferOut = 0;
 
 885                 PortP->TxBufferIn = 0;
 
 888                  ** LastRxTgl stores the state of the rx toggle bit for this
 
 889                  ** port, to be compared with the state of the next pkt received.
 
 890                  ** If the same, we have received the same rx pkt from the RTA
 
 891                  ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
 
 893                 PortP->LastRxTgl = ~(uchar) PHB_RX_TGL;
 
 896                  ** and mark the port as usable
 
 899                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
 
 901         if (HostMapP->SysPort < p->RIOFirstPortsMapped)
 
 902                 p->RIOFirstPortsMapped = HostMapP->SysPort;
 
 903         if (HostMapP->SysPort > p->RIOLastPortsMapped)
 
 904                 p->RIOLastPortsMapped = HostMapP->SysPort;
 
 909 int RIOChangeName(p, MapP)
 
 914         struct Map *HostMapP;
 
 917         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);
 
 919         if (MapP->ID > MAX_RUP) {
 
 920                 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
 
 921                 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
 
 925         MapP->Name[MAX_NAME_LEN - 1] = '\0';
 
 929                 if (*sptr < ' ' || *sptr > '~') {
 
 930                         rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
 
 931                         p->RIOError.Error = BAD_CHARACTER_IN_NAME;
 
 937         for (host = 0; host < p->RIONumHosts; host++) {
 
 938                 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
 
 939                         if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
 
 940                                 p->RIOError.Error = HOST_NOT_RUNNING;
 
 944                                 CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN);
 
 948                         HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
 
 950                         if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
 
 951                                 p->RIOError.Error = RTA_NUMBER_WRONG;
 
 954                         CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
 
 958         p->RIOError.Error = UNKNOWN_HOST_NUMBER;
 
 959         rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);