ia64/linux-2.6.18-xen.hg

annotate drivers/char/rio/riotable.c @ 893:f994bfe9b93b

linux/blktap2: reduce TLB flush scope

c/s 885 added very coarse TLB flushing. Since these flushes always
follow single page updates, single page flushes (when available) are
sufficient.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 04 10:32:57 2009 +0100 (2009-06-04)
parents 831230e53067
children
rev   line source
ian@0 1 /*
ian@0 2 ** -----------------------------------------------------------------------------
ian@0 3 **
ian@0 4 ** Perle Specialix driver for Linux
ian@0 5 ** Ported from existing RIO Driver for SCO sources.
ian@0 6 *
ian@0 7 * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
ian@0 8 *
ian@0 9 * This program is free software; you can redistribute it and/or modify
ian@0 10 * it under the terms of the GNU General Public License as published by
ian@0 11 * the Free Software Foundation; either version 2 of the License, or
ian@0 12 * (at your option) any later version.
ian@0 13 *
ian@0 14 * This program is distributed in the hope that it will be useful,
ian@0 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 17 * GNU General Public License for more details.
ian@0 18 *
ian@0 19 * You should have received a copy of the GNU General Public License
ian@0 20 * along with this program; if not, write to the Free Software
ian@0 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
ian@0 22 **
ian@0 23 ** Module : riotable.c
ian@0 24 ** SID : 1.2
ian@0 25 ** Last Modified : 11/6/98 10:33:47
ian@0 26 ** Retrieved : 11/6/98 10:33:50
ian@0 27 **
ian@0 28 ** ident @(#)riotable.c 1.2
ian@0 29 **
ian@0 30 ** -----------------------------------------------------------------------------
ian@0 31 */
ian@0 32 #ifdef SCCS_LABELS
ian@0 33 static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
ian@0 34 #endif
ian@0 35
ian@0 36 #include <linux/module.h>
ian@0 37 #include <linux/slab.h>
ian@0 38 #include <linux/errno.h>
ian@0 39 #include <linux/interrupt.h>
ian@0 40 #include <linux/string.h>
ian@0 41
ian@0 42 #include <asm/io.h>
ian@0 43 #include <asm/system.h>
ian@0 44 #include <asm/string.h>
ian@0 45 #include <asm/semaphore.h>
ian@0 46 #include <asm/uaccess.h>
ian@0 47
ian@0 48 #include <linux/termios.h>
ian@0 49 #include <linux/serial.h>
ian@0 50
ian@0 51 #include <linux/generic_serial.h>
ian@0 52
ian@0 53
ian@0 54 #include "linux_compat.h"
ian@0 55 #include "rio_linux.h"
ian@0 56 #include "pkt.h"
ian@0 57 #include "daemon.h"
ian@0 58 #include "rio.h"
ian@0 59 #include "riospace.h"
ian@0 60 #include "cmdpkt.h"
ian@0 61 #include "map.h"
ian@0 62 #include "rup.h"
ian@0 63 #include "port.h"
ian@0 64 #include "riodrvr.h"
ian@0 65 #include "rioinfo.h"
ian@0 66 #include "func.h"
ian@0 67 #include "errors.h"
ian@0 68 #include "pci.h"
ian@0 69
ian@0 70 #include "parmmap.h"
ian@0 71 #include "unixrup.h"
ian@0 72 #include "board.h"
ian@0 73 #include "host.h"
ian@0 74 #include "phb.h"
ian@0 75 #include "link.h"
ian@0 76 #include "cmdblk.h"
ian@0 77 #include "route.h"
ian@0 78 #include "cirrus.h"
ian@0 79 #include "rioioctl.h"
ian@0 80 #include "param.h"
ian@0 81 #include "protsts.h"
ian@0 82
ian@0 83 /*
ian@0 84 ** A configuration table has been loaded. It is now up to us
ian@0 85 ** to sort it out and use the information contained therein.
ian@0 86 */
ian@0 87 int RIONewTable(struct rio_info *p)
ian@0 88 {
ian@0 89 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
ian@0 90 struct Map *MapP;
ian@0 91 struct Map *HostMapP;
ian@0 92 struct Host *HostP;
ian@0 93
ian@0 94 char *cptr;
ian@0 95
ian@0 96 /*
ian@0 97 ** We have been sent a new table to install. We need to break
ian@0 98 ** it down into little bits and spread it around a bit to see
ian@0 99 ** what we have got.
ian@0 100 */
ian@0 101 /*
ian@0 102 ** Things to check:
ian@0 103 ** (things marked 'xx' aren't checked any more!)
ian@0 104 ** (1) That there are no booted Hosts/RTAs out there.
ian@0 105 ** (2) That the names are properly formed
ian@0 106 ** (3) That blank entries really are.
ian@0 107 ** xx (4) That hosts mentioned in the table actually exist. xx
ian@0 108 ** (5) That the IDs are unique (per host).
ian@0 109 ** (6) That host IDs are zero
ian@0 110 ** (7) That port numbers are valid
ian@0 111 ** (8) That port numbers aren't duplicated
ian@0 112 ** (9) That names aren't duplicated
ian@0 113 ** xx (10) That hosts that actually exist are mentioned in the table. xx
ian@0 114 */
ian@0 115 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
ian@0 116 if (p->RIOSystemUp) { /* (1) */
ian@0 117 p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
ian@0 118 return -EBUSY;
ian@0 119 }
ian@0 120
ian@0 121 p->RIOError.Error = NOTHING_WRONG_AT_ALL;
ian@0 122 p->RIOError.Entry = -1;
ian@0 123 p->RIOError.Other = -1;
ian@0 124
ian@0 125 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
ian@0 126 MapP = &p->RIOConnectTable[Entry];
ian@0 127 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
ian@0 128 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
ian@0 129 cptr = MapP->Name; /* (2) */
ian@0 130 cptr[MAX_NAME_LEN - 1] = '\0';
ian@0 131 if (cptr[0] == '\0') {
ian@0 132 memcpy(MapP->Name, MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", 8);
ian@0 133 MapP->Name[5] = '0' + Entry / 10;
ian@0 134 MapP->Name[6] = '0' + Entry % 10;
ian@0 135 }
ian@0 136 while (*cptr) {
ian@0 137 if (*cptr < ' ' || *cptr > '~') {
ian@0 138 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
ian@0 139 p->RIOError.Entry = Entry;
ian@0 140 return -ENXIO;
ian@0 141 }
ian@0 142 cptr++;
ian@0 143 }
ian@0 144 }
ian@0 145
ian@0 146 /*
ian@0 147 ** If the entry saved was a tentative entry then just forget
ian@0 148 ** about it.
ian@0 149 */
ian@0 150 if (MapP->Flags & SLOT_TENTATIVE) {
ian@0 151 MapP->HostUniqueNum = 0;
ian@0 152 MapP->RtaUniqueNum = 0;
ian@0 153 continue;
ian@0 154 }
ian@0 155
ian@0 156 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
ian@0 157 if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
ian@0 158 if (MapP->ID || MapP->SysPort || MapP->Flags) {
ian@0 159 rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
ian@0 160 p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
ian@0 161 p->RIOError.Entry = Entry;
ian@0 162 return -ENXIO;
ian@0 163 }
ian@0 164 rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
ian@0 165 continue;
ian@0 166 }
ian@0 167
ian@0 168 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
ian@0 169 for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
ian@0 170 if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
ian@0 171 HostP = &p->RIOHosts[Host];
ian@0 172 /*
ian@0 173 ** having done the lookup, we don't really want to do
ian@0 174 ** it again, so hang the host number in a safe place
ian@0 175 */
ian@0 176 MapP->Topology[0].Unit = Host;
ian@0 177 break;
ian@0 178 }
ian@0 179 }
ian@0 180
ian@0 181 if (Host >= p->RIONumHosts) {
ian@0 182 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
ian@0 183 MapP->HostUniqueNum = 0;
ian@0 184 /* MapP->RtaUniqueNum = 0; */
ian@0 185 /* MapP->ID = 0; */
ian@0 186 /* MapP->Flags = 0; */
ian@0 187 /* MapP->SysPort = 0; */
ian@0 188 /* MapP->Name[0] = 0; */
ian@0 189 continue;
ian@0 190 }
ian@0 191
ian@0 192 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
ian@0 193 if (MapP->RtaUniqueNum) { /* (5) */
ian@0 194 if (!MapP->ID) {
ian@0 195 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
ian@0 196 p->RIOError.Error = ZERO_RTA_ID;
ian@0 197 p->RIOError.Entry = Entry;
ian@0 198 return -ENXIO;
ian@0 199 }
ian@0 200 if (MapP->ID > MAX_RUP) {
ian@0 201 rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
ian@0 202 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
ian@0 203 p->RIOError.Entry = Entry;
ian@0 204 return -ENXIO;
ian@0 205 }
ian@0 206 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
ian@0 207 if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
ian@0 208 rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
ian@0 209 p->RIOError.Error = DUPLICATED_RTA_ID;
ian@0 210 p->RIOError.Entry = Entry;
ian@0 211 p->RIOError.Other = SubEnt;
ian@0 212 return -ENXIO;
ian@0 213 }
ian@0 214 /*
ian@0 215 ** If the RtaUniqueNum is the same, it may be looking at both
ian@0 216 ** entries for a 16 port RTA, so check the ids
ian@0 217 */
ian@0 218 if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
ian@0 219 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
ian@0 220 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
ian@0 221 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
ian@0 222 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
ian@0 223 p->RIOError.Entry = Entry;
ian@0 224 p->RIOError.Other = SubEnt;
ian@0 225 return -ENXIO;
ian@0 226 }
ian@0 227 }
ian@0 228 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
ian@0 229 /* (7a) */
ian@0 230 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
ian@0 231 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);
ian@0 232 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
ian@0 233 p->RIOError.Entry = Entry;
ian@0 234 return -ENXIO;
ian@0 235 }
ian@0 236 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
ian@0 237 /* (7b) */
ian@0 238 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
ian@0 239 rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
ian@0 240 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
ian@0 241 p->RIOError.Entry = Entry;
ian@0 242 return -ENXIO;
ian@0 243 }
ian@0 244 for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
ian@0 245 if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
ian@0 246 continue;
ian@0 247 if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
ian@0 248 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
ian@0 249 /* (8) */
ian@0 250 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
ian@0 251 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
ian@0 252 p->RIOError.Error = TTY_NUMBER_IN_USE;
ian@0 253 p->RIOError.Entry = Entry;
ian@0 254 p->RIOError.Other = SubEnt;
ian@0 255 return -ENXIO;
ian@0 256 }
ian@0 257 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
ian@0 258 if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
ian@0 259 rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
ian@0 260 p->RIOError.Error = NAME_USED_TWICE;
ian@0 261 p->RIOError.Entry = Entry;
ian@0 262 p->RIOError.Other = SubEnt;
ian@0 263 return -ENXIO;
ian@0 264 }
ian@0 265 }
ian@0 266 }
ian@0 267 } else { /* (6) */
ian@0 268 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
ian@0 269 if (MapP->ID) {
ian@0 270 rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
ian@0 271 p->RIOError.Error = HOST_ID_NOT_ZERO;
ian@0 272 p->RIOError.Entry = Entry;
ian@0 273 return -ENXIO;
ian@0 274 }
ian@0 275 if (MapP->SysPort != NO_PORT) {
ian@0 276 rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
ian@0 277 p->RIOError.Error = HOST_SYSPORT_BAD;
ian@0 278 p->RIOError.Entry = Entry;
ian@0 279 return -ENXIO;
ian@0 280 }
ian@0 281 }
ian@0 282 }
ian@0 283
ian@0 284 /*
ian@0 285 ** wow! if we get here then it's a goody!
ian@0 286 */
ian@0 287
ian@0 288 /*
ian@0 289 ** Zero the (old) entries for each host...
ian@0 290 */
ian@0 291 for (Host = 0; Host < RIO_HOSTS; Host++) {
ian@0 292 for (Entry = 0; Entry < MAX_RUP; Entry++) {
ian@0 293 memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
ian@0 294 }
ian@0 295 memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
ian@0 296 }
ian@0 297
ian@0 298 /*
ian@0 299 ** Copy in the new table entries
ian@0 300 */
ian@0 301 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
ian@0 302 rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
ian@0 303 MapP = &p->RIOConnectTable[Entry];
ian@0 304
ian@0 305 /*
ian@0 306 ** Now, if it is an empty slot ignore it!
ian@0 307 */
ian@0 308 if (MapP->HostUniqueNum == 0)
ian@0 309 continue;
ian@0 310
ian@0 311 /*
ian@0 312 ** we saved the host number earlier, so grab it back
ian@0 313 */
ian@0 314 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
ian@0 315
ian@0 316 /*
ian@0 317 ** If it is a host, then we only need to fill in the name field.
ian@0 318 */
ian@0 319 if (MapP->ID == 0) {
ian@0 320 rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
ian@0 321 memcpy(HostP->Name, MapP->Name, MAX_NAME_LEN);
ian@0 322 continue;
ian@0 323 }
ian@0 324
ian@0 325 /*
ian@0 326 ** Its an RTA entry, so fill in the host mapping entries for it
ian@0 327 ** and the port mapping entries. Notice that entry zero is for
ian@0 328 ** ID one.
ian@0 329 */
ian@0 330 HostMapP = &HostP->Mapping[MapP->ID - 1];
ian@0 331
ian@0 332 if (MapP->Flags & SLOT_IN_USE) {
ian@0 333 rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
ian@0 334 /*
ian@0 335 ** structure assign, then sort out the bits we shouldn't have done
ian@0 336 */
ian@0 337 *HostMapP = *MapP;
ian@0 338
ian@0 339 HostMapP->Flags = SLOT_IN_USE;
ian@0 340 if (MapP->Flags & RTA16_SECOND_SLOT)
ian@0 341 HostMapP->Flags |= RTA16_SECOND_SLOT;
ian@0 342
ian@0 343 RIOReMapPorts(p, HostP, HostMapP);
ian@0 344 } else {
ian@0 345 rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
ian@0 346 }
ian@0 347 }
ian@0 348
ian@0 349 for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
ian@0 350 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
ian@0 351 }
ian@0 352
ian@0 353 for (Host = 0; Host < p->RIONumHosts; Host++) {
ian@0 354 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
ian@0 355 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
ian@0 356 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
ian@0 357 }
ian@0 358 for (Entry = 0; Entry < MAX_RUP; Entry++) {
ian@0 359 for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
ian@0 360 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
ian@0 361 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
ian@0 362 }
ian@0 363 }
ian@0 364 if (!p->RIOHosts[Host].Name[0]) {
ian@0 365 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
ian@0 366 p->RIOHosts[Host].Name[5] += Host;
ian@0 367 }
ian@0 368 /*
ian@0 369 ** Check that default name assigned is unique.
ian@0 370 */
ian@0 371 Host1 = Host;
ian@0 372 NameIsUnique = 0;
ian@0 373 while (!NameIsUnique) {
ian@0 374 NameIsUnique = 1;
ian@0 375 for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
ian@0 376 if (Host2 == Host)
ian@0 377 continue;
ian@0 378 if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
ian@0 379 == 0) {
ian@0 380 NameIsUnique = 0;
ian@0 381 Host1++;
ian@0 382 if (Host1 >= p->RIONumHosts)
ian@0 383 Host1 = 0;
ian@0 384 p->RIOHosts[Host].Name[5] = '1' + Host1;
ian@0 385 }
ian@0 386 }
ian@0 387 }
ian@0 388 /*
ian@0 389 ** Rename host if name already used.
ian@0 390 */
ian@0 391 if (Host1 != Host) {
ian@0 392 rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
ian@0 393 memcpy(p->RIOHosts[Host].Name, "HOST 1", 7);
ian@0 394 p->RIOHosts[Host].Name[5] += Host1;
ian@0 395 }
ian@0 396 rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
ian@0 397 }
ian@0 398 return 0;
ian@0 399 }
ian@0 400
ian@0 401 /*
ian@0 402 ** User process needs the config table - build it from first
ian@0 403 ** principles.
ian@0 404 **
ian@0 405 * FIXME: SMP locking
ian@0 406 */
ian@0 407 int RIOApel(struct rio_info *p)
ian@0 408 {
ian@0 409 int Host;
ian@0 410 int link;
ian@0 411 int Rup;
ian@0 412 int Next = 0;
ian@0 413 struct Map *MapP;
ian@0 414 struct Host *HostP;
ian@0 415 unsigned long flags;
ian@0 416
ian@0 417 rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
ian@0 418
ian@0 419 memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
ian@0 420
ian@0 421 for (Host = 0; Host < RIO_HOSTS; Host++) {
ian@0 422 rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
ian@0 423 HostP = &p->RIOHosts[Host];
ian@0 424 rio_spin_lock_irqsave(&HostP->HostLock, flags);
ian@0 425
ian@0 426 MapP = &p->RIOConnectTable[Next++];
ian@0 427 MapP->HostUniqueNum = HostP->UniqueNum;
ian@0 428 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
ian@0 429 continue;
ian@0 430 MapP->RtaUniqueNum = 0;
ian@0 431 MapP->ID = 0;
ian@0 432 MapP->Flags = SLOT_IN_USE;
ian@0 433 MapP->SysPort = NO_PORT;
ian@0 434 for (link = 0; link < LINKS_PER_UNIT; link++)
ian@0 435 MapP->Topology[link] = HostP->Topology[link];
ian@0 436 memcpy(MapP->Name, HostP->Name, MAX_NAME_LEN);
ian@0 437 for (Rup = 0; Rup < MAX_RUP; Rup++) {
ian@0 438 if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
ian@0 439 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
ian@0 440 if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
ian@0 441 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
ian@0 442 if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
ian@0 443 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
ian@0 444 if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
ian@0 445 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
ian@0 446 Next++;
ian@0 447 }
ian@0 448 }
ian@0 449 rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
ian@0 450 }
ian@0 451 return 0;
ian@0 452 }
ian@0 453
ian@0 454 /*
ian@0 455 ** config.rio has taken a dislike to one of the gross maps entries.
ian@0 456 ** if the entry is suitably inactive, then we can gob on it and remove
ian@0 457 ** it from the table.
ian@0 458 */
ian@0 459 int RIODeleteRta(struct rio_info *p, struct Map *MapP)
ian@0 460 {
ian@0 461 int host, entry, port, link;
ian@0 462 int SysPort;
ian@0 463 struct Host *HostP;
ian@0 464 struct Map *HostMapP;
ian@0 465 struct Port *PortP;
ian@0 466 int work_done = 0;
ian@0 467 unsigned long lock_flags, sem_flags;
ian@0 468
ian@0 469 rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
ian@0 470
ian@0 471 for (host = 0; host < p->RIONumHosts; host++) {
ian@0 472 HostP = &p->RIOHosts[host];
ian@0 473
ian@0 474 rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
ian@0 475
ian@0 476 if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
ian@0 477 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
ian@0 478 continue;
ian@0 479 }
ian@0 480
ian@0 481 for (entry = 0; entry < MAX_RUP; entry++) {
ian@0 482 if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
ian@0 483 HostMapP = &HostP->Mapping[entry];
ian@0 484 rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
ian@0 485
ian@0 486 /*
ian@0 487 ** Check all four links of the unit are disconnected
ian@0 488 */
ian@0 489 for (link = 0; link < LINKS_PER_UNIT; link++) {
ian@0 490 if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
ian@0 491 rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
ian@0 492 p->RIOError.Error = UNIT_IS_IN_USE;
ian@0 493 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
ian@0 494 return -EBUSY;
ian@0 495 }
ian@0 496 }
ian@0 497 /*
ian@0 498 ** Slot has been allocated, BUT not booted/routed/
ian@0 499 ** connected/selected or anything else-ed
ian@0 500 */
ian@0 501 SysPort = HostMapP->SysPort;
ian@0 502
ian@0 503 if (SysPort != NO_PORT) {
ian@0 504 for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
ian@0 505 PortP = p->RIOPortp[port];
ian@0 506 rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
ian@0 507
ian@0 508 rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
ian@0 509
ian@0 510 PortP->Mapped = 0;
ian@0 511
ian@0 512 if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
ian@0 513
ian@0 514 rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
ian@0 515 PortP->TxBufferIn = PortP->TxBufferOut = 0;
ian@0 516 /* What should I do
ian@0 517 wakeup( &PortP->TxBufferIn );
ian@0 518 wakeup( &PortP->TxBufferOut);
ian@0 519 */
ian@0 520 PortP->InUse = NOT_INUSE;
ian@0 521 /* What should I do
ian@0 522 wakeup( &PortP->InUse );
ian@0 523 signal(PortP->TtyP->t_pgrp,SIGKILL);
ian@0 524 ttyflush(PortP->TtyP,(FREAD|FWRITE));
ian@0 525 */
ian@0 526 PortP->State |= RIO_CLOSING | RIO_DELETED;
ian@0 527 }
ian@0 528
ian@0 529 /*
ian@0 530 ** For the second slot of a 16 port RTA, the
ian@0 531 ** driver needs to reset the changes made to
ian@0 532 ** the phb to port mappings in RIORouteRup.
ian@0 533 */
ian@0 534 if (PortP->SecondBlock) {
ian@0 535 u16 dest_unit = HostMapP->ID;
ian@0 536 u16 dest_port = port - SysPort;
ian@0 537 u16 __iomem *TxPktP;
ian@0 538 struct PKT __iomem *Pkt;
ian@0 539
ian@0 540 for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
ian@0 541 /*
ian@0 542 ** *TxPktP is the pointer to the
ian@0 543 ** transmit packet on the host card.
ian@0 544 ** This needs to be translated into
ian@0 545 ** a 32 bit pointer so it can be
ian@0 546 ** accessed from the driver.
ian@0 547 */
ian@0 548 Pkt = (struct PKT __iomem *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
ian@0 549 rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", readw(TxPktP), readb(&Pkt->dest_unit), readb(&Pkt->dest_port), dest_unit, dest_port);
ian@0 550 writew(dest_unit, &Pkt->dest_unit);
ian@0 551 writew(dest_port, &Pkt->dest_port);
ian@0 552 }
ian@0 553 rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, readb(&PortP->PhbP->destination) & 0xff, (readb(&PortP->PhbP->destination) >> 8) & 0xff, dest_unit, dest_port);
ian@0 554 writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
ian@0 555 }
ian@0 556 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
ian@0 557 }
ian@0 558 }
ian@0 559 rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
ian@0 560 memset(HostMapP, 0, sizeof(struct Map));
ian@0 561 work_done++;
ian@0 562 }
ian@0 563 }
ian@0 564 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
ian@0 565 }
ian@0 566
ian@0 567 /* XXXXX lock me up */
ian@0 568 for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
ian@0 569 if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
ian@0 570 memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
ian@0 571 work_done++;
ian@0 572 }
ian@0 573 if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
ian@0 574 memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
ian@0 575 work_done++;
ian@0 576 }
ian@0 577 }
ian@0 578 if (work_done)
ian@0 579 return 0;
ian@0 580
ian@0 581 rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
ian@0 582 p->RIOError.Error = COULDNT_FIND_ENTRY;
ian@0 583 return -ENXIO;
ian@0 584 }
ian@0 585
ian@0 586 int RIOAssignRta(struct rio_info *p, struct Map *MapP)
ian@0 587 {
ian@0 588 int host;
ian@0 589 struct Map *HostMapP;
ian@0 590 char *sptr;
ian@0 591 int link;
ian@0 592
ian@0 593
ian@0 594 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);
ian@0 595
ian@0 596 if ((MapP->ID != (u16) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
ian@0 597 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
ian@0 598 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
ian@0 599 return -EINVAL;
ian@0 600 }
ian@0 601 if (MapP->RtaUniqueNum == 0) {
ian@0 602 rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
ian@0 603 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
ian@0 604 return -EINVAL;
ian@0 605 }
ian@0 606 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
ian@0 607 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
ian@0 608 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
ian@0 609 return -EINVAL;
ian@0 610 }
ian@0 611 if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
ian@0 612 rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
ian@0 613 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
ian@0 614 return -EINVAL;
ian@0 615 }
ian@0 616
ian@0 617 /*
ian@0 618 ** Copy the name across to the map entry.
ian@0 619 */
ian@0 620 MapP->Name[MAX_NAME_LEN - 1] = '\0';
ian@0 621 sptr = MapP->Name;
ian@0 622 while (*sptr) {
ian@0 623 if (*sptr < ' ' || *sptr > '~') {
ian@0 624 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
ian@0 625 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
ian@0 626 return -EINVAL;
ian@0 627 }
ian@0 628 sptr++;
ian@0 629 }
ian@0 630
ian@0 631 for (host = 0; host < p->RIONumHosts; host++) {
ian@0 632 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
ian@0 633 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
ian@0 634 p->RIOError.Error = HOST_NOT_RUNNING;
ian@0 635 return -ENXIO;
ian@0 636 }
ian@0 637
ian@0 638 /*
ian@0 639 ** Now we have a host we need to allocate an ID
ian@0 640 ** if the entry does not already have one.
ian@0 641 */
ian@0 642 if (MapP->ID == (u16) - 1) {
ian@0 643 int nNewID;
ian@0 644
ian@0 645 rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
ian@0 646 /*
ian@0 647 ** The idea here is to allow RTA's to be assigned
ian@0 648 ** before they actually appear on the network.
ian@0 649 ** This allows the addition of RTA's without having
ian@0 650 ** to plug them in.
ian@0 651 ** What we do is:
ian@0 652 ** - Find a free ID and allocate it to the RTA.
ian@0 653 ** - If this map entry is the second half of a
ian@0 654 ** 16 port entry then find the other half and
ian@0 655 ** make sure the 2 cross reference each other.
ian@0 656 */
ian@0 657 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
ian@0 658 p->RIOError.Error = COULDNT_FIND_ENTRY;
ian@0 659 return -EBUSY;
ian@0 660 }
ian@0 661 MapP->ID = (u16) nNewID + 1;
ian@0 662 rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
ian@0 663 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
ian@0 664 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
ian@0 665 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
ian@0 666 HostMapP->ID = MapP->ID;
ian@0 667 for (link = 0; link < LINKS_PER_UNIT; link++) {
ian@0 668 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
ian@0 669 HostMapP->Topology[link].Link = NO_LINK;
ian@0 670 }
ian@0 671 if (MapP->Flags & RTA16_SECOND_SLOT) {
ian@0 672 int unit;
ian@0 673
ian@0 674 for (unit = 0; unit < MAX_RUP; unit++)
ian@0 675 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
ian@0 676 break;
ian@0 677 if (unit == MAX_RUP) {
ian@0 678 p->RIOError.Error = COULDNT_FIND_ENTRY;
ian@0 679 return -EBUSY;
ian@0 680 }
ian@0 681 HostMapP->Flags |= RTA16_SECOND_SLOT;
ian@0 682 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
ian@0 683 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
ian@0 684 rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
ian@0 685 }
ian@0 686 }
ian@0 687
ian@0 688 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
ian@0 689
ian@0 690 if (HostMapP->Flags & SLOT_IN_USE) {
ian@0 691 rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
ian@0 692 p->RIOError.Error = ID_ALREADY_IN_USE;
ian@0 693 return -EBUSY;
ian@0 694 }
ian@0 695
ian@0 696 /*
ian@0 697 ** Assign the sys ports and the name, and mark the slot as
ian@0 698 ** being in use.
ian@0 699 */
ian@0 700 HostMapP->SysPort = MapP->SysPort;
ian@0 701 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
ian@0 702 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
ian@0 703 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
ian@0 704 #ifdef NEED_TO_FIX
ian@0 705 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
ian@0 706 #endif
ian@0 707 if (MapP->Flags & RTA16_SECOND_SLOT)
ian@0 708 HostMapP->Flags |= RTA16_SECOND_SLOT;
ian@0 709
ian@0 710 RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
ian@0 711 /*
ian@0 712 ** Adjust 2nd block of 8 phbs
ian@0 713 */
ian@0 714 if (MapP->Flags & RTA16_SECOND_SLOT)
ian@0 715 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
ian@0 716
ian@0 717 if (HostMapP->SysPort != NO_PORT) {
ian@0 718 if (HostMapP->SysPort < p->RIOFirstPortsBooted)
ian@0 719 p->RIOFirstPortsBooted = HostMapP->SysPort;
ian@0 720 if (HostMapP->SysPort > p->RIOLastPortsBooted)
ian@0 721 p->RIOLastPortsBooted = HostMapP->SysPort;
ian@0 722 }
ian@0 723 if (MapP->Flags & RTA16_SECOND_SLOT)
ian@0 724 rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
ian@0 725 else
ian@0 726 rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
ian@0 727 return 0;
ian@0 728 }
ian@0 729 }
ian@0 730 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
ian@0 731 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
ian@0 732 return -ENXIO;
ian@0 733 }
ian@0 734
ian@0 735
ian@0 736 int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
ian@0 737 {
ian@0 738 struct Port *PortP;
ian@0 739 unsigned int SubEnt;
ian@0 740 unsigned int HostPort;
ian@0 741 unsigned int SysPort;
ian@0 742 u16 RtaType;
ian@0 743 unsigned long flags;
ian@0 744
ian@0 745 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
ian@0 746
ian@0 747 /*
ian@0 748 ** We need to tell the UnixRups which sysport the rup corresponds to
ian@0 749 */
ian@0 750 HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
ian@0 751
ian@0 752 if (HostMapP->SysPort == NO_PORT)
ian@0 753 return (0);
ian@0 754
ian@0 755 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
ian@0 756 rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
ian@0 757
ian@0 758 /*
ian@0 759 ** now map each of its eight ports
ian@0 760 */
ian@0 761 for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
ian@0 762 rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
ian@0 763 SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
ian@0 764 /* portnumber on host */
ian@0 765
ian@0 766 HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
ian@0 767
ian@0 768 rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
ian@0 769 PortP = p->RIOPortp[SysPort];
ian@0 770 rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
ian@0 771
ian@0 772 /*
ian@0 773 ** Point at all the real neat data structures
ian@0 774 */
ian@0 775 rio_spin_lock_irqsave(&PortP->portSem, flags);
ian@0 776 PortP->HostP = HostP;
ian@0 777 PortP->Caddr = HostP->Caddr;
ian@0 778
ian@0 779 /*
ian@0 780 ** The PhbP cannot be filled in yet
ian@0 781 ** unless the host has been booted
ian@0 782 */
ian@0 783 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
ian@0 784 struct PHB __iomem *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
ian@0 785 PortP->TxAdd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
ian@0 786 PortP->TxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
ian@0 787 PortP->TxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
ian@0 788 PortP->RxRemove = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
ian@0 789 PortP->RxStart = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
ian@0 790 PortP->RxEnd = (u16 __iomem *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
ian@0 791 } else
ian@0 792 PortP->PhbP = NULL;
ian@0 793
ian@0 794 /*
ian@0 795 ** port related flags
ian@0 796 */
ian@0 797 PortP->HostPort = HostPort;
ian@0 798 /*
ian@0 799 ** For each part of a 16 port RTA, RupNum is ID - 1.
ian@0 800 */
ian@0 801 PortP->RupNum = HostMapP->ID - 1;
ian@0 802 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
ian@0 803 PortP->ID2 = HostMapP->ID2 - 1;
ian@0 804 PortP->SecondBlock = 1;
ian@0 805 } else {
ian@0 806 PortP->ID2 = 0;
ian@0 807 PortP->SecondBlock = 0;
ian@0 808 }
ian@0 809 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
ian@0 810
ian@0 811 /*
ian@0 812 ** If the port was already mapped then thats all we need to do.
ian@0 813 */
ian@0 814 if (PortP->Mapped) {
ian@0 815 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
ian@0 816 continue;
ian@0 817 } else
ian@0 818 HostMapP->Flags &= ~RTA_NEWBOOT;
ian@0 819
ian@0 820 PortP->State = 0;
ian@0 821 PortP->Config = 0;
ian@0 822 /*
ian@0 823 ** Check out the module type - if it is special (read only etc.)
ian@0 824 ** then we need to set flags in the PortP->Config.
ian@0 825 ** Note: For 16 port RTA, all ports are of the same type.
ian@0 826 */
ian@0 827 if (RtaType == TYPE_RTA16) {
ian@0 828 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
ian@0 829 } else {
ian@0 830 if (SubEnt < PORTS_PER_MODULE)
ian@0 831 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
ian@0 832 else
ian@0 833 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
ian@0 834 }
ian@0 835
ian@0 836 /*
ian@0 837 ** more port related flags
ian@0 838 */
ian@0 839 PortP->PortState = 0;
ian@0 840 PortP->ModemLines = 0;
ian@0 841 PortP->ModemState = 0;
ian@0 842 PortP->CookMode = COOK_WELL;
ian@0 843 PortP->ParamSem = 0;
ian@0 844 PortP->FlushCmdBodge = 0;
ian@0 845 PortP->WflushFlag = 0;
ian@0 846 PortP->MagicFlags = 0;
ian@0 847 PortP->Lock = 0;
ian@0 848 PortP->Store = 0;
ian@0 849 PortP->FirstOpen = 1;
ian@0 850
ian@0 851 /*
ian@0 852 ** Buffers 'n things
ian@0 853 */
ian@0 854 PortP->RxDataStart = 0;
ian@0 855 PortP->Cor2Copy = 0;
ian@0 856 PortP->Name = &HostMapP->Name[0];
ian@0 857 PortP->statsGather = 0;
ian@0 858 PortP->txchars = 0;
ian@0 859 PortP->rxchars = 0;
ian@0 860 PortP->opens = 0;
ian@0 861 PortP->closes = 0;
ian@0 862 PortP->ioctls = 0;
ian@0 863 if (PortP->TxRingBuffer)
ian@0 864 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
ian@0 865 else if (p->RIOBufferSize) {
ian@0 866 PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL);
ian@0 867 memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
ian@0 868 }
ian@0 869 PortP->TxBufferOut = 0;
ian@0 870 PortP->TxBufferIn = 0;
ian@0 871 PortP->Debug = 0;
ian@0 872 /*
ian@0 873 ** LastRxTgl stores the state of the rx toggle bit for this
ian@0 874 ** port, to be compared with the state of the next pkt received.
ian@0 875 ** If the same, we have received the same rx pkt from the RTA
ian@0 876 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
ian@0 877 */
ian@0 878 PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
ian@0 879
ian@0 880 /*
ian@0 881 ** and mark the port as usable
ian@0 882 */
ian@0 883 PortP->Mapped = 1;
ian@0 884 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
ian@0 885 }
ian@0 886 if (HostMapP->SysPort < p->RIOFirstPortsMapped)
ian@0 887 p->RIOFirstPortsMapped = HostMapP->SysPort;
ian@0 888 if (HostMapP->SysPort > p->RIOLastPortsMapped)
ian@0 889 p->RIOLastPortsMapped = HostMapP->SysPort;
ian@0 890
ian@0 891 return 0;
ian@0 892 }
ian@0 893
ian@0 894 int RIOChangeName(struct rio_info *p, struct Map *MapP)
ian@0 895 {
ian@0 896 int host;
ian@0 897 struct Map *HostMapP;
ian@0 898 char *sptr;
ian@0 899
ian@0 900 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);
ian@0 901
ian@0 902 if (MapP->ID > MAX_RUP) {
ian@0 903 rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
ian@0 904 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
ian@0 905 return -EINVAL;
ian@0 906 }
ian@0 907
ian@0 908 MapP->Name[MAX_NAME_LEN - 1] = '\0';
ian@0 909 sptr = MapP->Name;
ian@0 910
ian@0 911 while (*sptr) {
ian@0 912 if (*sptr < ' ' || *sptr > '~') {
ian@0 913 rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
ian@0 914 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
ian@0 915 return -EINVAL;
ian@0 916 }
ian@0 917 sptr++;
ian@0 918 }
ian@0 919
ian@0 920 for (host = 0; host < p->RIONumHosts; host++) {
ian@0 921 if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
ian@0 922 if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
ian@0 923 p->RIOError.Error = HOST_NOT_RUNNING;
ian@0 924 return -ENXIO;
ian@0 925 }
ian@0 926 if (MapP->ID == 0) {
ian@0 927 memcpy(p->RIOHosts[host].Name, MapP->Name, MAX_NAME_LEN);
ian@0 928 return 0;
ian@0 929 }
ian@0 930
ian@0 931 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
ian@0 932
ian@0 933 if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
ian@0 934 p->RIOError.Error = RTA_NUMBER_WRONG;
ian@0 935 return -ENXIO;
ian@0 936 }
ian@0 937 memcpy(HostMapP->Name, MapP->Name, MAX_NAME_LEN);
ian@0 938 return 0;
ian@0 939 }
ian@0 940 }
ian@0 941 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
ian@0 942 rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
ian@0 943 return -ENXIO;
ian@0 944 }