Coarsly sort out 32-bit-only, 64-bit-only and ``portable'' MIPS lib/
[linux-2.6/linux-mips.git] / drivers / char / rio / riotable.c
blob963658c5e46a352d3eca3637d23c2378ebfa3673
1 /*
2 ** -----------------------------------------------------------------------------
3 **
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
24 ** SID : 1.2
25 ** Last Modified : 11/6/98 10:33:47
26 ** Retrieved : 11/6/98 10:33:50
28 ** ident @(#)riotable.c 1.2
30 ** -----------------------------------------------------------------------------
32 #ifdef SCCS_LABELS
33 static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
34 #endif
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/errno.h>
39 #include <linux/interrupt.h>
41 #include <asm/io.h>
42 #include <asm/system.h>
43 #include <asm/string.h>
44 #include <asm/semaphore.h>
45 #include <asm/uaccess.h>
47 #include <linux/termios.h>
48 #include <linux/serial.h>
50 #include <linux/generic_serial.h>
53 #include "linux_compat.h"
54 #include "rio_linux.h"
55 #include "typdef.h"
56 #include "pkt.h"
57 #include "daemon.h"
58 #include "rio.h"
59 #include "riospace.h"
60 #include "top.h"
61 #include "cmdpkt.h"
62 #include "map.h"
63 #include "riotypes.h"
64 #include "rup.h"
65 #include "port.h"
66 #include "riodrvr.h"
67 #include "rioinfo.h"
68 #include "func.h"
69 #include "errors.h"
70 #include "pci.h"
72 #include "parmmap.h"
73 #include "unixrup.h"
74 #include "board.h"
75 #include "host.h"
76 #include "error.h"
77 #include "phb.h"
78 #include "link.h"
79 #include "cmdblk.h"
80 #include "route.h"
81 #include "control.h"
82 #include "cirrus.h"
83 #include "rioioctl.h"
84 #include "param.h"
85 #include "list.h"
86 #include "sam.h"
87 #include "protsts.h"
90 ** A configuration table has been loaded. It is now up to us
91 ** to sort it out and use the information contained therein.
93 int
94 RIONewTable(p)
95 struct rio_info * p;
97 int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
98 struct Map *MapP;
99 struct Map *HostMapP;
100 struct Host *HostP;
102 char *cptr;
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
107 ** what we have got.
110 ** Things to check:
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;
126 return -EBUSY;
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;
144 while ( *cptr ) {
145 if ( *cptr<' ' || *cptr>'~' ) {
146 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
147 p->RIOError.Entry = Entry;
148 return -ENXIO;
150 cptr++;
155 ** If the entry saved was a tentative entry then just forget
156 ** about it.
158 if ( MapP->Flags & SLOT_TENTATIVE ) {
159 MapP->HostUniqueNum = 0;
160 MapP->RtaUniqueNum = 0;
161 continue;
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;
170 return -ENXIO;
172 rio_dprintk (RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
173 continue;
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;
185 break;
189 if ( Host >= p->RIONumHosts ) {
190 rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n",
191 MapP->Name, MapP->HostUniqueNum);
192 MapP->HostUniqueNum = 0;
193 /* MapP->RtaUniqueNum = 0; */
194 /* MapP->ID = 0; */
195 /* MapP->Flags = 0; */
196 /* MapP->SysPort = 0; */
197 /* MapP->Name[0] = 0; */
198 continue;
201 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
202 if ( MapP->RtaUniqueNum ) { /* (5) */
203 if ( !MapP->ID ) {
204 rio_dprintk (RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n",
205 MapP->Name);
206 p->RIOError.Error = ZERO_RTA_ID;
207 p->RIOError.Entry = Entry;
208 return -ENXIO;
210 if ( MapP->ID > MAX_RUP ) {
211 rio_dprintk (RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an illegal ID %d\n",
212 MapP->Name, MapP->ID);
213 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
214 p->RIOError.Entry = Entry;
215 return -ENXIO;
217 for ( SubEnt=0; SubEnt<Entry; SubEnt++ ) {
218 if ( MapP->HostUniqueNum ==
219 p->RIOConnectTable[SubEnt].HostUniqueNum &&
220 MapP->ID == p->RIOConnectTable[SubEnt].ID ) {
221 rio_dprintk (RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n",
222 MapP->Name, p->RIOConnectTable[SubEnt].Name);
223 p->RIOError.Error = DUPLICATED_RTA_ID;
224 p->RIOError.Entry = Entry;
225 p->RIOError.Other = SubEnt;
226 return -ENXIO;
229 ** If the RtaUniqueNum is the same, it may be looking at both
230 ** entries for a 16 port RTA, so check the ids
232 if ((MapP->RtaUniqueNum ==
233 p->RIOConnectTable[SubEnt].RtaUniqueNum)
234 && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
235 rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n",MapP->Name);
236 rio_dprintk (RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n",
237 p->RIOConnectTable[SubEnt].Name);
238 p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
239 p->RIOError.Entry = Entry;
240 p->RIOError.Other = SubEnt;
241 return -ENXIO;
244 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
245 /* (7a) */
246 if ((MapP->SysPort != NO_PORT)&&(MapP->SysPort % PORTS_PER_RTA)) {
247 rio_dprintk (RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n",
248 (int)MapP->SysPort,MapP->Name, PORTS_PER_RTA);
249 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
250 p->RIOError.Entry = Entry;
251 return -ENXIO;
253 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
254 /* (7b) */
255 if ((MapP->SysPort != NO_PORT)&&(MapP->SysPort >= RIO_PORTS)) {
256 rio_dprintk (RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n",
257 (int)MapP->SysPort, MapP->Name);
258 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
259 p->RIOError.Entry = Entry;
260 return -ENXIO;
262 for ( SubEnt=0; SubEnt<Entry; SubEnt++ ) {
263 if ( p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT )
264 continue;
265 if ( p->RIOConnectTable[SubEnt].RtaUniqueNum ) {
266 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
267 /* (8) */
268 if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort ==
269 p->RIOConnectTable[SubEnt].SysPort) ) {
270 rio_dprintk (RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n",
271 MapP->Name, p->RIOConnectTable[SubEnt].Name,
272 (int)MapP->SysPort);
273 p->RIOError.Error = TTY_NUMBER_IN_USE;
274 p->RIOError.Entry = Entry;
275 p->RIOError.Other = SubEnt;
276 return -ENXIO;
278 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
279 if (RIOStrCmp(MapP->Name,
280 p->RIOConnectTable[SubEnt].Name)==0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
281 rio_dprintk (RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
282 p->RIOError.Error = NAME_USED_TWICE;
283 p->RIOError.Entry = Entry;
284 p->RIOError.Other = SubEnt;
285 return -ENXIO;
290 else { /* (6) */
291 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
292 if ( MapP->ID ) {
293 rio_dprintk (RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n",
294 MapP->Name);
295 p->RIOError.Error = HOST_ID_NOT_ZERO;
296 p->RIOError.Entry = Entry;
297 return -ENXIO;
299 if ( MapP->SysPort != NO_PORT ) {
300 rio_dprintk (RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n",
301 MapP->Name);
302 p->RIOError.Error = HOST_SYSPORT_BAD;
303 p->RIOError.Entry = Entry;
304 return -ENXIO;
310 ** wow! if we get here then it's a goody!
314 ** Zero the (old) entries for each host...
316 for ( Host=0; Host<RIO_HOSTS; Host++ ) {
317 for ( Entry=0; Entry<MAX_RUP; Entry++ ) {
318 bzero((caddr_t)&p->RIOHosts[Host].Mapping[Entry],
319 sizeof(struct Map));
321 bzero((caddr_t)&p->RIOHosts[Host].Name[0],
322 sizeof(p->RIOHosts[Host].Name) );
326 ** Copy in the new table entries
328 for ( Entry=0; Entry< TOTAL_MAP_ENTRIES; Entry++ ) {
329 rio_dprintk (RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
330 MapP = &p->RIOConnectTable[Entry];
333 ** Now, if it is an empty slot ignore it!
335 if ( MapP->HostUniqueNum==0 )
336 continue;
339 ** we saved the host number earlier, so grab it back
341 HostP = &p->RIOHosts[MapP->Topology[0].Unit];
344 ** If it is a host, then we only need to fill in the name field.
346 if ( MapP->ID==0 ) {
347 rio_dprintk (RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
348 bcopy(MapP->Name,HostP->Name,MAX_NAME_LEN);
349 continue;
353 ** Its an RTA entry, so fill in the host mapping entries for it
354 ** and the port mapping entries. Notice that entry zero is for
355 ** ID one.
357 HostMapP = &HostP->Mapping[MapP->ID-1];
359 if (MapP->Flags & SLOT_IN_USE) {
360 rio_dprintk (RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
362 ** structure assign, then sort out the bits we shouldn't have done
364 *HostMapP = *MapP;
366 HostMapP->Flags = SLOT_IN_USE;
367 if (MapP->Flags & RTA16_SECOND_SLOT)
368 HostMapP->Flags |= RTA16_SECOND_SLOT;
370 RIOReMapPorts(p, HostP, HostMapP );
372 else {
373 rio_dprintk (RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
377 for ( Entry=0; Entry< TOTAL_MAP_ENTRIES; Entry++ ) {
378 p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
381 for ( Host=0; Host<p->RIONumHosts; Host++ ) {
382 for ( SubEnt=0; SubEnt<LINKS_PER_UNIT; SubEnt++ ) {
383 p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
384 p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
386 for ( Entry=0; Entry<MAX_RUP; Entry++ ) {
387 for ( SubEnt=0; SubEnt<LINKS_PER_UNIT; SubEnt++ ) {
388 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit =
389 ROUTE_DISCONNECT;
390 p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link =
391 NO_LINK;
394 if ( !p->RIOHosts[Host].Name[0] ) {
395 bcopy("HOST 1",p->RIOHosts[Host].Name,7);
396 p->RIOHosts[Host].Name[5] += Host;
399 ** Check that default name assigned is unique.
401 Host1 = Host;
402 NameIsUnique = 0;
403 while (!NameIsUnique) {
404 NameIsUnique = 1;
405 for ( Host2=0; Host2<p->RIONumHosts; Host2++ ) {
406 if (Host2 == Host)
407 continue;
408 if (RIOStrCmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
409 == 0) {
410 NameIsUnique = 0;
411 Host1++;
412 if (Host1 >= p->RIONumHosts)
413 Host1 = 0;
414 p->RIOHosts[Host].Name[5] = '1' + Host1;
419 ** Rename host if name already used.
421 if (Host1 != Host)
423 rio_dprintk (RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
424 bcopy("HOST 1",p->RIOHosts[Host].Name,7);
425 p->RIOHosts[Host].Name[5] += Host1;
427 rio_dprintk (RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
429 return 0;
433 ** User process needs the config table - build it from first
434 ** principles.
437 RIOApel(p)
438 struct rio_info * p;
440 int Host;
441 int link;
442 int Rup;
443 int Next = 0;
444 struct Map *MapP;
445 struct Host *HostP;
446 long oldspl;
448 disable(oldspl); /* strange but true! */
450 rio_dprintk (RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
452 bzero((caddr_t)&p->RIOConnectTable[0],
453 sizeof(struct Map) * TOTAL_MAP_ENTRIES );
455 for ( Host=0; Host<RIO_HOSTS; Host++ ) {
456 rio_dprintk (RIO_DEBUG_TABLE, "Processing host %d\n", Host);
457 HostP = &p->RIOHosts[Host];
458 MapP = &p->RIOConnectTable[Next++];
459 MapP->HostUniqueNum = HostP->UniqueNum;
460 if ( (HostP->Flags & RUN_STATE) != RC_RUNNING )
461 continue;
462 MapP->RtaUniqueNum = 0;
463 MapP->ID = 0;
464 MapP->Flags = SLOT_IN_USE;
465 MapP->SysPort = NO_PORT;
466 for ( link=0; link<LINKS_PER_UNIT; link++ )
467 MapP->Topology[link] = HostP->Topology[link];
468 bcopy(HostP->Name,MapP->Name,MAX_NAME_LEN);
469 for ( Rup=0; Rup<MAX_RUP; Rup++ ) {
470 if ( HostP->Mapping[Rup].Flags & (SLOT_IN_USE|SLOT_TENTATIVE) ) {
471 p->RIOConnectTable[Next] = HostP->Mapping[Rup];
472 if ( HostP->Mapping[Rup].Flags & SLOT_IN_USE)
473 p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
474 if ( HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
475 p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
476 if ( HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT )
477 p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
478 Next++;
482 restore(oldspl);
483 return 0;
487 ** config.rio has taken a dislike to one of the gross maps entries.
488 ** if the entry is suitably inactive, then we can gob on it and remove
489 ** it from the table.
492 RIODeleteRta(p, MapP)
493 struct rio_info *p;
494 struct Map *MapP;
496 int host, entry, port, link;
497 int SysPort;
498 struct Host *HostP;
499 struct Map *HostMapP;
500 struct Port *PortP;
501 int work_done = 0;
502 unsigned long lock_flags, sem_flags;
504 rio_dprintk (RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n",
505 MapP->HostUniqueNum, MapP->RtaUniqueNum);
507 for ( host=0; host < p->RIONumHosts; host++ ) {
508 HostP = &p->RIOHosts[host];
510 rio_spin_lock_irqsave( &HostP->HostLock, lock_flags );
512 if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
513 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
514 continue;
517 for ( entry=0; entry<MAX_RUP; entry++ ) {
518 if ( MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum ) {
519 HostMapP = &HostP->Mapping[entry];
520 rio_dprintk (RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n",
521 entry, HostP->Name);
524 ** Check all four links of the unit are disconnected
526 for ( link=0; link< LINKS_PER_UNIT; link++ ) {
527 if ( HostMapP->Topology[link].Unit != ROUTE_DISCONNECT ) {
528 rio_dprintk (RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
529 p->RIOError.Error = UNIT_IS_IN_USE;
530 rio_spin_unlock_irqrestore( &HostP->HostLock, lock_flags);
531 return -EBUSY;
535 ** Slot has been allocated, BUT not booted/routed/
536 ** connected/selected or anything else-ed
538 SysPort = HostMapP->SysPort;
540 if ( SysPort != NO_PORT ) {
541 for (port=SysPort; port < SysPort+PORTS_PER_RTA; port++) {
542 PortP = p->RIOPortp[port];
543 rio_dprintk (RIO_DEBUG_TABLE, "Unmap port\n");
545 rio_spin_lock_irqsave( &PortP->portSem, sem_flags );
547 PortP->Mapped = 0;
549 if ( PortP->State & (RIO_MOPEN|RIO_LOPEN) ) {
551 rio_dprintk (RIO_DEBUG_TABLE, "Gob on port\n");
552 PortP->TxBufferIn = PortP->TxBufferOut = 0;
553 /* What should I do
554 wakeup( &PortP->TxBufferIn );
555 wakeup( &PortP->TxBufferOut);
557 PortP->InUse = NOT_INUSE;
558 /* What should I do
559 wakeup( &PortP->InUse );
560 signal(PortP->TtyP->t_pgrp,SIGKILL);
561 ttyflush(PortP->TtyP,(FREAD|FWRITE));
563 PortP->State |= RIO_CLOSING | RIO_DELETED;
567 ** For the second slot of a 16 port RTA, the
568 ** driver needs to reset the changes made to
569 ** the phb to port mappings in RIORouteRup.
571 if (PortP->SecondBlock) {
572 ushort dest_unit = HostMapP->ID;
573 ushort dest_port = port - SysPort;
574 WORD *TxPktP;
575 PKT *Pkt;
577 for (TxPktP = PortP->TxStart;
578 TxPktP <= PortP->TxEnd; TxPktP++) {
580 ** *TxPktP is the pointer to the
581 ** transmit packet on the host card.
582 ** This needs to be translated into
583 ** a 32 bit pointer so it can be
584 ** accessed from the driver.
586 Pkt = (PKT *) RIO_PTR(HostP->Caddr,
587 RWORD(*TxPktP));
588 rio_dprintk (RIO_DEBUG_TABLE,
589 "Tx packet (%x) destination: Old %x:%x New %x:%x\n",
590 *TxPktP, Pkt->dest_unit,
591 Pkt->dest_port, dest_unit, dest_port);
592 WWORD(Pkt->dest_unit, dest_unit);
593 WWORD(Pkt->dest_port, dest_port);
595 rio_dprintk (RIO_DEBUG_TABLE,
596 "Port %d phb destination: Old %x:%x New %x:%x\n",
597 port, PortP->PhbP->destination & 0xff,
598 (PortP->PhbP->destination >> 8) & 0xff,
599 dest_unit, dest_port);
600 WWORD(PortP->PhbP->destination,
601 dest_unit + (dest_port << 8));
603 rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
606 rio_dprintk (RIO_DEBUG_TABLE, "Entry nulled.\n");
607 bzero((char *)HostMapP,sizeof(struct Map));
608 work_done++;
611 rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
614 /* XXXXX lock me up */
615 for ( entry=0; entry< TOTAL_MAP_ENTRIES; entry++ ) {
616 if ( p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum ) {
617 bzero((char *)&p->RIOSavedTable[entry],sizeof(struct Map));
618 work_done++;
620 if ( p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum ) {
621 bzero((char *)&p->RIOConnectTable[entry],sizeof(struct Map));
622 work_done++;
625 if ( work_done )
626 return 0;
628 rio_dprintk (RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
629 p->RIOError.Error = COULDNT_FIND_ENTRY;
630 return -ENXIO;
633 int RIOAssignRta( struct rio_info *p, struct Map *MapP )
635 int host;
636 struct Map *HostMapP;
637 char *sptr;
638 int link;
641 rio_dprintk (RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n",
642 MapP->HostUniqueNum,MapP->RtaUniqueNum,
643 MapP->ID, (int)MapP->SysPort);
645 if ((MapP->ID != (ushort)-1) &&
646 ((int)MapP->ID < (int)1 || (int)MapP->ID > MAX_RUP ))
648 rio_dprintk (RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
649 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
650 return -EINVAL;
652 if (MapP->RtaUniqueNum == 0)
654 rio_dprintk (RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
655 p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
656 return -EINVAL;
658 if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA) )
660 rio_dprintk (RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n",(int)MapP->SysPort,PORTS_PER_RTA);
661 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
662 return -EINVAL;
664 if ( (MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS) )
666 rio_dprintk (RIO_DEBUG_TABLE, "Port %d not valid!\n",(int)MapP->SysPort);
667 p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
668 return -EINVAL;
672 ** Copy the name across to the map entry.
674 MapP->Name[MAX_NAME_LEN-1] = '\0';
675 sptr = MapP->Name;
676 while ( *sptr )
678 if ( *sptr<' ' || *sptr>'~' )
680 rio_dprintk (RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
681 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
682 return -EINVAL;
684 sptr++;
687 for ( host=0; host < p->RIONumHosts; host++ )
689 if ( MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum )
691 if ( (p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING )
693 p->RIOError.Error = HOST_NOT_RUNNING;
694 return -ENXIO;
698 ** Now we have a host we need to allocate an ID
699 ** if the entry does not already have one.
701 if (MapP->ID == (ushort)-1)
703 int nNewID;
705 rio_dprintk (RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n",
706 MapP->Name);
708 ** The idea here is to allow RTA's to be assigned
709 ** before they actually appear on the network.
710 ** This allows the addition of RTA's without having
711 ** to plug them in.
712 ** What we do is:
713 ** - Find a free ID and allocate it to the RTA.
714 ** - If this map entry is the second half of a
715 ** 16 port entry then find the other half and
716 ** make sure the 2 cross reference each other.
718 if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0)
720 p->RIOError.Error = COULDNT_FIND_ENTRY;
721 return -EBUSY;
723 MapP->ID = (ushort)nNewID + 1;
724 rio_dprintk (RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
725 HostMapP = &p->RIOHosts[host].Mapping[nNewID];
726 HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
727 HostMapP->HostUniqueNum = MapP->HostUniqueNum;
728 HostMapP->ID = MapP->ID;
729 for (link = 0; link < LINKS_PER_UNIT; link++)
731 HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
732 HostMapP->Topology[link].Link = NO_LINK;
734 if (MapP->Flags & RTA16_SECOND_SLOT)
736 int unit;
738 for (unit = 0; unit < MAX_RUP; unit++)
739 if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum ==
740 MapP->RtaUniqueNum)
741 break;
742 if (unit == MAX_RUP)
744 p->RIOError.Error = COULDNT_FIND_ENTRY;
745 return -EBUSY;
747 HostMapP->Flags |= RTA16_SECOND_SLOT;
748 HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
749 p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
750 rio_dprintk (RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n",
751 MapP->ID,
752 p->RIOHosts[host].Mapping[unit].ID);
756 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID-1];
758 if ( HostMapP->Flags & SLOT_IN_USE )
760 rio_dprintk (RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
761 p->RIOError.Error = ID_ALREADY_IN_USE;
762 return -EBUSY;
766 ** Assign the sys ports and the name, and mark the slot as
767 ** being in use.
769 HostMapP->SysPort = MapP->SysPort;
770 if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
771 CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN );
772 HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
773 #if NEED_TO_FIX
774 RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID-1]);
775 #endif
776 if (MapP->Flags & RTA16_SECOND_SLOT)
777 HostMapP->Flags |= RTA16_SECOND_SLOT;
779 RIOReMapPorts( p, &p->RIOHosts[host], HostMapP );
781 ** Adjust 2nd block of 8 phbs
783 if (MapP->Flags & RTA16_SECOND_SLOT)
784 RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
786 if ( HostMapP->SysPort != NO_PORT )
788 if ( HostMapP->SysPort < p->RIOFirstPortsBooted )
789 p->RIOFirstPortsBooted = HostMapP->SysPort;
790 if ( HostMapP->SysPort > p->RIOLastPortsBooted )
791 p->RIOLastPortsBooted = HostMapP->SysPort;
793 if (MapP->Flags & RTA16_SECOND_SLOT)
794 rio_dprintk (RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n",
795 p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
796 else
797 rio_dprintk (RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
798 return 0;
801 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
802 rio_dprintk (RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
803 return -ENXIO;
808 RIOReMapPorts(p, HostP, HostMapP)
809 struct rio_info * p;
810 struct Host *HostP;
811 struct Map *HostMapP;
813 register struct Port *PortP;
814 uint SubEnt;
815 uint HostPort;
816 uint SysPort;
817 ushort RtaType;
818 unsigned long flags;
820 #ifdef CHECK
821 CheckHostP( HostP );
822 CheckHostMapP( HostMapP );
823 #endif
825 rio_dprintk (RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int)HostMapP->SysPort, HostMapP->ID);
828 ** We need to tell the UnixRups which sysport the rup corresponds to
830 HostP->UnixRups[HostMapP->ID-1].BaseSysPort = HostMapP->SysPort;
832 if ( HostMapP->SysPort == NO_PORT )
833 return(0);
835 RtaType = GetUnitType(HostMapP->RtaUniqueNum);
836 rio_dprintk (RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n",
837 (int)HostMapP->SysPort, (int)HostMapP->SysPort+PORTS_PER_RTA-1);
840 ** now map each of its eight ports
842 for ( SubEnt=0; SubEnt<PORTS_PER_RTA; SubEnt++) {
843 rio_dprintk (RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n",
844 SubEnt, (int)HostMapP->SysPort);
845 SysPort = HostMapP->SysPort+SubEnt; /* portnumber within system */
846 /* portnumber on host */
848 HostPort = (HostMapP->ID-1)*PORTS_PER_RTA+SubEnt;
850 rio_dprintk (RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
851 PortP = p->RIOPortp[SysPort];
852 #if 0
853 PortP->TtyP = &p->channel[SysPort];
854 #endif
855 rio_dprintk (RIO_DEBUG_TABLE, "Map port\n");
858 ** Point at all the real neat data structures
860 rio_spin_lock_irqsave(&PortP->portSem, flags);
861 PortP->HostP = HostP;
862 PortP->Caddr = HostP->Caddr;
865 ** The PhbP cannot be filled in yet
866 ** unless the host has been booted
868 if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
869 struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
870 PortP->TxAdd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_add));
871 PortP->TxStart =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_start));
872 PortP->TxEnd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->tx_end));
873 PortP->RxRemove=(WORD *)RIO_PTR(HostP->Caddr,
874 RWORD(PhbP->rx_remove));
875 PortP->RxStart =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->rx_start));
876 PortP->RxEnd =(WORD *)RIO_PTR(HostP->Caddr,RWORD(PhbP->rx_end));
878 else
879 PortP->PhbP = NULL;
882 ** port related flags
884 PortP->HostPort = HostPort;
886 ** For each part of a 16 port RTA, RupNum is ID - 1.
888 PortP->RupNum = HostMapP->ID - 1;
889 if (HostMapP->Flags & RTA16_SECOND_SLOT) {
890 PortP->ID2 = HostMapP->ID2 - 1;
891 PortP->SecondBlock = TRUE;
893 else {
894 PortP->ID2 = 0;
895 PortP->SecondBlock = FALSE;
897 PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
900 ** If the port was already mapped then thats all we need to do.
902 if (PortP->Mapped) {
903 rio_spin_unlock_irqrestore( &PortP->portSem, flags);
904 continue;
906 else HostMapP->Flags &= ~RTA_NEWBOOT;
908 PortP->State = 0;
909 PortP->Config = 0;
911 ** Check out the module type - if it is special (read only etc.)
912 ** then we need to set flags in the PortP->Config.
913 ** Note: For 16 port RTA, all ports are of the same type.
915 if (RtaType == TYPE_RTA16) {
916 PortP->Config |= p->RIOModuleTypes[HostP->UnixRups
917 [HostMapP->ID-1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
918 } else {
919 if ( SubEnt < PORTS_PER_MODULE )
920 PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups
921 [HostMapP->ID-1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
922 else
923 PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups
924 [HostMapP->ID-1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
928 ** more port related flags
930 PortP->PortState = 0;
931 PortP->ModemLines = 0;
932 PortP->ModemState = 0;
933 PortP->CookMode = COOK_WELL;
934 PortP->ParamSem = 0;
935 PortP->FlushCmdBodge= 0;
936 PortP->WflushFlag = 0;
937 PortP->MagicFlags = 0;
938 PortP->Lock = 0;
939 PortP->Store = 0;
940 PortP->FirstOpen = 1;
943 ** handle the xprint issues
945 #ifdef XPRINT_SUPPORT
946 PortP->Xprint.XpActive = 0;
947 PortP->Xprint.XttyP = &riox_tty[SysPort];
948 /* TO FROM MAXLEN */
949 RIOStrNCpy( PortP->Xprint.XpOn, RIOConf.XpOn, MAX_XP_CTRL_LEN );
950 RIOStrNCpy( PortP->Xprint.XpOff, RIOConf.XpOff, MAX_XP_CTRL_LEN );
951 PortP->Xprint.XpCps = RIOConf.XpCps;
952 PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn)+
953 RIOStrlen(PortP->Xprint.XpOff);
954 #endif
957 ** Buffers 'n things
959 PortP->RxDataStart = 0;
960 PortP->Cor2Copy = 0;
961 PortP->Name = &HostMapP->Name[0];
962 #ifdef STATS
963 bzero( (caddr_t)&PortP->Stat, sizeof(struct RIOStats) );
964 #endif
965 PortP->statsGather = 0;
966 PortP->txchars = 0;
967 PortP->rxchars = 0;
968 PortP->opens = 0;
969 PortP->closes = 0;
970 PortP->ioctls = 0;
971 if ( PortP->TxRingBuffer )
972 bzero( PortP->TxRingBuffer, p->RIOBufferSize );
973 else if ( p->RIOBufferSize ) {
974 PortP->TxRingBuffer = sysbrk(p->RIOBufferSize);
975 bzero( PortP->TxRingBuffer, p->RIOBufferSize );
977 PortP->TxBufferOut = 0;
978 PortP->TxBufferIn = 0;
979 PortP->Debug = 0;
981 ** LastRxTgl stores the state of the rx toggle bit for this
982 ** port, to be compared with the state of the next pkt received.
983 ** If the same, we have received the same rx pkt from the RTA
984 ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
986 PortP->LastRxTgl = ~(uchar)PHB_RX_TGL;
989 ** and mark the port as usable
991 PortP->Mapped = 1;
992 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
994 if ( HostMapP->SysPort < p->RIOFirstPortsMapped )
995 p->RIOFirstPortsMapped = HostMapP->SysPort;
996 if ( HostMapP->SysPort > p->RIOLastPortsMapped )
997 p->RIOLastPortsMapped = HostMapP->SysPort;
999 return 0;
1003 RIOChangeName(p, MapP)
1004 struct rio_info *p;
1005 struct Map* MapP;
1007 int host;
1008 struct Map *HostMapP;
1009 char *sptr;
1011 rio_dprintk (RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n",
1012 MapP->HostUniqueNum,MapP->RtaUniqueNum,
1013 MapP->ID, (int)MapP->SysPort);
1015 if ( MapP->ID > MAX_RUP ) {
1016 rio_dprintk (RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
1017 p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
1018 return -EINVAL;
1021 MapP->Name[MAX_NAME_LEN-1] = '\0';
1022 sptr = MapP->Name;
1024 while ( *sptr ) {
1025 if ( *sptr<' ' || *sptr>'~' ) {
1026 rio_dprintk (RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
1027 p->RIOError.Error = BAD_CHARACTER_IN_NAME;
1028 return -EINVAL;
1030 sptr++;
1033 for ( host=0; host < p->RIONumHosts; host++ ) {
1034 if ( MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum ) {
1035 if ( (p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING ) {
1036 p->RIOError.Error = HOST_NOT_RUNNING;
1037 return -ENXIO;
1039 if ( MapP->ID==0 ) {
1040 CCOPY( MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN );
1041 return 0;
1044 HostMapP = &p->RIOHosts[host].Mapping[MapP->ID-1];
1046 if ( HostMapP->RtaUniqueNum != MapP->RtaUniqueNum ) {
1047 p->RIOError.Error = RTA_NUMBER_WRONG;
1048 return -ENXIO;
1050 CCOPY( MapP->Name, HostMapP->Name, MAX_NAME_LEN );
1051 return 0;
1054 p->RIOError.Error = UNKNOWN_HOST_NUMBER;
1055 rio_dprintk (RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
1056 return -ENXIO;