]> err.no Git - linux-2.6/blob - drivers/char/rio/rioboot.c
[PATCH] rioboot: post-Lindent
[linux-2.6] / drivers / char / rio / rioboot.c
1 /*
2 ** -----------------------------------------------------------------------------
3 **
4 **  Perle Specialix driver for Linux
5 **  Ported from existing RIO Driver for SCO sources.
6  *
7  *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
8  *
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.
13  *
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.
18  *
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.
22 **
23 **      Module          : rioboot.c
24 **      SID             : 1.3
25 **      Last Modified   : 11/6/98 10:33:36
26 **      Retrieved       : 11/6/98 10:33:48
27 **
28 **  ident @(#)rioboot.c 1.3
29 **
30 ** -----------------------------------------------------------------------------
31 */
32
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/termios.h>
36 #include <linux/serial.h>
37 #include <asm/semaphore.h>
38 #include <linux/generic_serial.h>
39 #include <linux/errno.h>
40 #include <linux/interrupt.h>
41 #include <linux/delay.h>
42 #include <asm/io.h>
43 #include <asm/system.h>
44 #include <asm/string.h>
45 #include <asm/uaccess.h>
46
47
48 #include "linux_compat.h"
49 #include "rio_linux.h"
50 #include "typdef.h"
51 #include "pkt.h"
52 #include "daemon.h"
53 #include "rio.h"
54 #include "riospace.h"
55 #include "top.h"
56 #include "cmdpkt.h"
57 #include "map.h"
58 #include "riotypes.h"
59 #include "rup.h"
60 #include "port.h"
61 #include "riodrvr.h"
62 #include "rioinfo.h"
63 #include "func.h"
64 #include "errors.h"
65 #include "pci.h"
66
67 #include "parmmap.h"
68 #include "unixrup.h"
69 #include "board.h"
70 #include "host.h"
71 #include "error.h"
72 #include "phb.h"
73 #include "link.h"
74 #include "cmdblk.h"
75 #include "route.h"
76
77 static int RIOBootComplete(struct rio_info *p, struct Host *HostP, unsigned int Rup, struct PktCmd *PktCmdP);
78
79 static const unsigned char RIOAtVec2Ctrl[] = {
80         /* 0 */ INTERRUPT_DISABLE,
81         /* 1 */ INTERRUPT_DISABLE,
82         /* 2 */ INTERRUPT_DISABLE,
83         /* 3 */ INTERRUPT_DISABLE,
84         /* 4 */ INTERRUPT_DISABLE,
85         /* 5 */ INTERRUPT_DISABLE,
86         /* 6 */ INTERRUPT_DISABLE,
87         /* 7 */ INTERRUPT_DISABLE,
88         /* 8 */ INTERRUPT_DISABLE,
89         /* 9 */ IRQ_9 | INTERRUPT_ENABLE,
90         /* 10 */ INTERRUPT_DISABLE,
91         /* 11 */ IRQ_11 | INTERRUPT_ENABLE,
92         /* 12 */ IRQ_12 | INTERRUPT_ENABLE,
93         /* 13 */ INTERRUPT_DISABLE,
94         /* 14 */ INTERRUPT_DISABLE,
95         /* 15 */ IRQ_15 | INTERRUPT_ENABLE
96 };
97
98 /**
99  *      RIOBootCodeRTA          -       Load RTA boot code
100  *      @p: RIO to load
101  *      @rbp: Download descriptor
102  *
103  *      Called when the user process initiates booting of the card firmware.
104  *      Lads the firmware
105  */
106
107 int RIOBootCodeRTA(struct rio_info *p, struct DownLoad * rbp)
108 {
109         int offset;
110
111         func_enter();
112
113         rio_dprintk(RIO_DEBUG_BOOT, "Data at user address %p\n", rbp->DataP);
114
115         /*
116          ** Check that we have set asside enough memory for this
117          */
118         if (rbp->Count > SIXTY_FOUR_K) {
119                 rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot Code Too Large!\n");
120                 p->RIOError.Error = HOST_FILE_TOO_LARGE;
121                 func_exit();
122                 return -ENOMEM;
123         }
124
125         if (p->RIOBooting) {
126                 rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot Code : BUSY BUSY BUSY!\n");
127                 p->RIOError.Error = BOOT_IN_PROGRESS;
128                 func_exit();
129                 return -EBUSY;
130         }
131
132         /*
133          ** The data we load in must end on a (RTA_BOOT_DATA_SIZE) byte boundary,
134          ** so calculate how far we have to move the data up the buffer
135          ** to achieve this.
136          */
137         offset = (RTA_BOOT_DATA_SIZE - (rbp->Count % RTA_BOOT_DATA_SIZE)) % RTA_BOOT_DATA_SIZE;
138
139         /*
140          ** Be clean, and clear the 'unused' portion of the boot buffer,
141          ** because it will (eventually) be part of the Rta run time environment
142          ** and so should be zeroed.
143          */
144         memset(p->RIOBootPackets, 0, offset);
145
146         /*
147          ** Copy the data from user space into the array
148          */
149
150         if (copy_from_user(((u8 *)p->RIOBootPackets) + offset, rbp->DataP, rbp->Count)) {
151                 rio_dprintk(RIO_DEBUG_BOOT, "Bad data copy from user space\n");
152                 p->RIOError.Error = COPYIN_FAILED;
153                 func_exit();
154                 return -EFAULT;
155         }
156
157         /*
158          ** Make sure that our copy of the size includes that offset we discussed
159          ** earlier.
160          */
161         p->RIONumBootPkts = (rbp->Count + offset) / RTA_BOOT_DATA_SIZE;
162         p->RIOBootCount = rbp->Count;
163
164         func_exit();
165         return 0;
166 }
167
168 /**
169  *      rio_start_card_running          -       host card start
170  *      @HostP: The RIO to kick off
171  *
172  *      Start a RIO processor unit running. Encapsulates the knowledge
173  *      of the card type.
174  */
175
176 void rio_start_card_running(struct Host *HostP)
177 {
178         switch (HostP->Type) {
179         case RIO_AT:
180                 rio_dprintk(RIO_DEBUG_BOOT, "Start ISA card running\n");
181                 writeb(BOOT_FROM_RAM | EXTERNAL_BUS_ON | HostP->Mode | RIOAtVec2Ctrl[HostP->Ivec & 0xF], &HostP->Control);
182                 break;
183         case RIO_PCI:
184                 /*
185                  ** PCI is much the same as MCA. Everything is once again memory
186                  ** mapped, so we are writing to memory registers instead of io
187                  ** ports.
188                  */
189                 rio_dprintk(RIO_DEBUG_BOOT, "Start PCI card running\n");
190                 writeb(PCITpBootFromRam | PCITpBusEnable | HostP->Mode, &HostP->Control);
191                 break;
192         default:
193                 rio_dprintk(RIO_DEBUG_BOOT, "Unknown host type %d\n", HostP->Type);
194                 break;
195         }
196         return;
197 }
198
199 /*
200 ** Load in the host boot code - load it directly onto all halted hosts
201 ** of the correct type.
202 **
203 ** Put your rubber pants on before messing with this code - even the magic
204 ** numbers have trouble understanding what they are doing here.
205 */
206
207 int RIOBootCodeHOST(struct rio_info *p, struct DownLoad *rbp)
208 {
209         struct Host *HostP;
210         u8 *Cad;
211         PARM_MAP *ParmMapP;
212         int RupN;
213         int PortN;
214         unsigned int host;
215         u8 *StartP;
216         u8 *DestP;
217         int wait_count;
218         u16 OldParmMap;
219         u16 offset;             /* It is very important that this is a u16 */
220         u8 *DownCode = NULL;
221         unsigned long flags;
222
223         HostP = NULL;           /* Assure the compiler we've initialized it */
224
225
226         /* Walk the hosts */
227         for (host = 0; host < p->RIONumHosts; host++) {
228                 rio_dprintk(RIO_DEBUG_BOOT, "Attempt to boot host %d\n", host);
229                 HostP = &p->RIOHosts[host];
230
231                 rio_dprintk(RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n", HostP->Type, HostP->Mode, HostP->Ivec);
232
233                 /* Don't boot hosts already running */
234                 if ((HostP->Flags & RUN_STATE) != RC_WAITING) {
235                         rio_dprintk(RIO_DEBUG_BOOT, "%s %d already running\n", "Host", host);
236                         continue;
237                 }
238
239                 /*
240                  ** Grab a pointer to the card (ioremapped)
241                  */
242                 Cad = HostP->Caddr;
243
244                 /*
245                  ** We are going to (try) and load in rbp->Count bytes.
246                  ** The last byte will reside at p->RIOConf.HostLoadBase-1;
247                  ** Therefore, we need to start copying at address
248                  ** (caddr+p->RIOConf.HostLoadBase-rbp->Count)
249                  */
250                 StartP = &Cad[p->RIOConf.HostLoadBase - rbp->Count];
251
252                 rio_dprintk(RIO_DEBUG_BOOT, "kernel virtual address for host is %p\n", Cad);
253                 rio_dprintk(RIO_DEBUG_BOOT, "kernel virtual address for download is %p\n", StartP);
254                 rio_dprintk(RIO_DEBUG_BOOT, "host loadbase is 0x%x\n", p->RIOConf.HostLoadBase);
255                 rio_dprintk(RIO_DEBUG_BOOT, "size of download is 0x%x\n", rbp->Count);
256
257                 /* Make sure it fits */
258                 if (p->RIOConf.HostLoadBase < rbp->Count) {
259                         rio_dprintk(RIO_DEBUG_BOOT, "Bin too large\n");
260                         p->RIOError.Error = HOST_FILE_TOO_LARGE;
261                         func_exit();
262                         return -EFBIG;
263                 }
264                 /*
265                  ** Ensure that the host really is stopped.
266                  ** Disable it's external bus & twang its reset line.
267                  */
268                 RIOHostReset(HostP->Type, (struct DpRam *) HostP->CardP, HostP->Slot);
269
270                 /*
271                  ** Copy the data directly from user space to the SRAM.
272                  ** This ain't going to be none too clever if the download
273                  ** code is bigger than this segment.
274                  */
275                 rio_dprintk(RIO_DEBUG_BOOT, "Copy in code\n");
276
277                 /* Buffer to local memory as we want to use I/O space and
278                    some cards only do 8 or 16 bit I/O */
279
280                 DownCode = vmalloc(rbp->Count);
281                 if (!DownCode) {
282                         p->RIOError.Error = NOT_ENOUGH_CORE_FOR_PCI_COPY;
283                         func_exit();
284                         return -ENOMEM;
285                 }
286                 if (copy_from_user(rbp->DataP, DownCode, rbp->Count)) {
287                         kfree(DownCode);
288                         p->RIOError.Error = COPYIN_FAILED;
289                         func_exit();
290                         return -EFAULT;
291                 }
292                 HostP->Copy(DownCode, StartP, rbp->Count);
293                 vfree(DownCode);
294
295                 rio_dprintk(RIO_DEBUG_BOOT, "Copy completed\n");
296
297                 /*
298                  **                     S T O P !
299                  **
300                  ** Upto this point the code has been fairly rational, and possibly
301                  ** even straight forward. What follows is a pile of crud that will
302                  ** magically turn into six bytes of transputer assembler. Normally
303                  ** you would expect an array or something, but, being me, I have
304                  ** chosen [been told] to use a technique whereby the startup code
305                  ** will be correct if we change the loadbase for the code. Which
306                  ** brings us onto another issue - the loadbase is the *end* of the
307                  ** code, not the start.
308                  **
309                  ** If I were you I wouldn't start from here.
310                  */
311
312                 /*
313                  ** We now need to insert a short boot section into
314                  ** the memory at the end of Sram2. This is normally (de)composed
315                  ** of the last eight bytes of the download code. The
316                  ** download has been assembled/compiled to expect to be
317                  ** loaded from 0x7FFF downwards. We have loaded it
318                  ** at some other address. The startup code goes into the small
319                  ** ram window at Sram2, in the last 8 bytes, which are really
320                  ** at addresses 0x7FF8-0x7FFF.
321                  **
322                  ** If the loadbase is, say, 0x7C00, then we need to branch to
323                  ** address 0x7BFE to run the host.bin startup code. We assemble
324                  ** this jump manually.
325                  **
326                  ** The two byte sequence 60 08 is loaded into memory at address
327                  ** 0x7FFE,F. This is a local branch to location 0x7FF8 (60 is nfix 0,
328                  ** which adds '0' to the .O register, complements .O, and then shifts
329                  ** it left by 4 bit positions, 08 is a jump .O+8 instruction. This will
330                  ** add 8 to .O (which was 0xFFF0), and will branch RELATIVE to the new
331                  ** location. Now, the branch starts from the value of .PC (or .IP or
332                  ** whatever the bloody register is called on this chip), and the .PC
333                  ** will be pointing to the location AFTER the branch, in this case
334                  ** .PC == 0x8000, so the branch will be to 0x8000+0xFFF8 = 0x7FF8.
335                  **
336                  ** A long branch is coded at 0x7FF8. This consists of loading a four
337                  ** byte offset into .O using nfix (as above) and pfix operators. The
338                  ** pfix operates in exactly the same way as the nfix operator, but
339                  ** without the complement operation. The offset, of course, must be
340                  ** relative to the address of the byte AFTER the branch instruction,
341                  ** which will be (urm) 0x7FFC, so, our final destination of the branch
342                  ** (loadbase-2), has to be reached from here. Imagine that the loadbase
343                  ** is 0x7C00 (which it is), then we will need to branch to 0x7BFE (which
344                  ** is the first byte of the initial two byte short local branch of the
345                  ** download code).
346                  **
347                  ** To code a jump from 0x7FFC (which is where the branch will start
348                  ** from) to 0x7BFE, we will need to branch 0xFC02 bytes (0x7FFC+0xFC02)=
349                  ** 0x7BFE.
350                  ** This will be coded as four bytes:
351                  ** 60 2C 20 02
352                  ** being nfix .O+0
353                  **        pfix .O+C
354                  **        pfix .O+0
355                  **        jump .O+2
356                  **
357                  ** The nfix operator is used, so that the startup code will be
358                  ** compatible with the whole Tp family. (lies, damn lies, it'll never
359                  ** work in a month of Sundays).
360                  **
361                  ** The nfix nyble is the 1s complement of the nyble value you
362                  ** want to load - in this case we wanted 'F' so we nfix loaded '0'.
363                  */
364
365
366                 /*
367                  ** Dest points to the top 8 bytes of Sram2. The Tp jumps
368                  ** to 0x7FFE at reset time, and starts executing. This is
369                  ** a short branch to 0x7FF8, where a long branch is coded.
370                  */
371
372                 DestP = (u8 *) &Cad[0x7FF8];    /* <<<---- READ THE ABOVE COMMENTS */
373
374 #define NFIX(N) (0x60 | (N))    /* .O  = (~(.O + N))<<4 */
375 #define PFIX(N) (0x20 | (N))    /* .O  =   (.O + N)<<4  */
376 #define JUMP(N) (0x00 | (N))    /* .PC =   .PC + .O      */
377
378                 /*
379                  ** 0x7FFC is the address of the location following the last byte of
380                  ** the four byte jump instruction.
381                  ** READ THE ABOVE COMMENTS
382                  **
383                  ** offset is (TO-FROM) % MEMSIZE, but with compound buggering about.
384                  ** Memsize is 64K for this range of Tp, so offset is a short (unsigned,
385                  ** cos I don't understand 2's complement).
386                  */
387                 offset = (p->RIOConf.HostLoadBase - 2) - 0x7FFC;
388
389                 writeb(NFIX(((ushort) (~offset) >> (ushort) 12) & 0xF), DestP);
390                 writeb(PFIX((offset >> 8) & 0xF), DestP + 1);
391                 writeb(PFIX((offset >> 4) & 0xF), DestP + 2);
392                 writeb(JUMP(offset & 0xF), DestP + 3);
393
394                 writeb(NFIX(0), DestP + 6);
395                 writeb(JUMP(8), DestP + 7);
396
397                 rio_dprintk(RIO_DEBUG_BOOT, "host loadbase is 0x%x\n", p->RIOConf.HostLoadBase);
398                 rio_dprintk(RIO_DEBUG_BOOT, "startup offset is 0x%x\n", offset);
399
400                 /*
401                  ** Flag what is going on
402                  */
403                 HostP->Flags &= ~RUN_STATE;
404                 HostP->Flags |= RC_STARTUP;
405
406                 /*
407                  ** Grab a copy of the current ParmMap pointer, so we
408                  ** can tell when it has changed.
409                  */
410                 OldParmMap = readw(&HostP->__ParmMapR);
411
412                 rio_dprintk(RIO_DEBUG_BOOT, "Original parmmap is 0x%x\n", OldParmMap);
413
414                 /*
415                  ** And start it running (I hope).
416                  ** As there is nothing dodgy or obscure about the
417                  ** above code, this is guaranteed to work every time.
418                  */
419                 rio_dprintk(RIO_DEBUG_BOOT, "Host Type = 0x%x, Mode = 0x%x, IVec = 0x%x\n", HostP->Type, HostP->Mode, HostP->Ivec);
420
421                 rio_start_card_running(HostP);
422
423                 rio_dprintk(RIO_DEBUG_BOOT, "Set control port\n");
424
425                 /*
426                  ** Now, wait for upto five seconds for the Tp to setup the parmmap
427                  ** pointer:
428                  */
429                 for (wait_count = 0; (wait_count < p->RIOConf.StartupTime) && (readw(&HostP->__ParmMapR) == OldParmMap); wait_count++) {
430                         rio_dprintk(RIO_DEBUG_BOOT, "Checkout %d, 0x%x\n", wait_count, readw(&HostP->__ParmMapR));
431                         mdelay(100);
432
433                 }
434
435                 /*
436                  ** If the parmmap pointer is unchanged, then the host code
437                  ** has crashed & burned in a really spectacular way
438                  */
439                 if (readw(&HostP->__ParmMapR) == OldParmMap) {
440                         rio_dprintk(RIO_DEBUG_BOOT, "parmmap 0x%x\n", readw(&HostP->__ParmMapR));
441                         rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail\n");
442                         HostP->Flags &= ~RUN_STATE;
443                         HostP->Flags |= RC_STUFFED;
444                         RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
445                         continue;
446                 }
447
448                 rio_dprintk(RIO_DEBUG_BOOT, "Running 0x%x\n", readw(&HostP->__ParmMapR));
449
450                 /*
451                  ** Well, the board thought it was OK, and setup its parmmap
452                  ** pointer. For the time being, we will pretend that this
453                  ** board is running, and check out what the error flag says.
454                  */
455
456                 /*
457                  ** Grab a 32 bit pointer to the parmmap structure
458                  */
459                 ParmMapP = (PARM_MAP *) RIO_PTR(Cad, readw(&HostP->__ParmMapR));
460                 rio_dprintk(RIO_DEBUG_BOOT, "ParmMapP : %p\n", ParmMapP);
461                 ParmMapP = (PARM_MAP *) ((unsigned long) Cad + readw(&HostP->__ParmMapR));
462                 rio_dprintk(RIO_DEBUG_BOOT, "ParmMapP : %p\n", ParmMapP);
463
464                 /*
465                  ** The links entry should be 0xFFFF; we set it up
466                  ** with a mask to say how many PHBs to use, and
467                  ** which links to use.
468                  */
469                 if (readw(&ParmMapP->links) != 0xFFFF) {
470                         rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
471                         rio_dprintk(RIO_DEBUG_BOOT, "Links = 0x%x\n", readw(&ParmMapP->links));
472                         HostP->Flags &= ~RUN_STATE;
473                         HostP->Flags |= RC_STUFFED;
474                         RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
475                         continue;
476                 }
477
478                 writew(RIO_LINK_ENABLE, &ParmMapP->links);
479
480                 /*
481                  ** now wait for the card to set all the parmmap->XXX stuff
482                  ** this is a wait of upto two seconds....
483                  */
484                 rio_dprintk(RIO_DEBUG_BOOT, "Looking for init_done - %d ticks\n", p->RIOConf.StartupTime);
485                 HostP->timeout_id = 0;
486                 for (wait_count = 0; (wait_count < p->RIOConf.StartupTime) && !readw(&ParmMapP->init_done); wait_count++) {
487                         rio_dprintk(RIO_DEBUG_BOOT, "Waiting for init_done\n");
488                         mdelay(100);
489                 }
490                 rio_dprintk(RIO_DEBUG_BOOT, "OK! init_done!\n");
491
492                 if (readw(&ParmMapP->error) != E_NO_ERROR || !readw(&ParmMapP->init_done)) {
493                         rio_dprintk(RIO_DEBUG_BOOT, "RIO Mesg Run Fail %s\n", HostP->Name);
494                         rio_dprintk(RIO_DEBUG_BOOT, "Timedout waiting for init_done\n");
495                         HostP->Flags &= ~RUN_STATE;
496                         HostP->Flags |= RC_STUFFED;
497                         RIOHostReset( HostP->Type, (struct DpRam *)HostP->CardP, HostP->Slot );
498                         continue;
499                 }
500
501                 rio_dprintk(RIO_DEBUG_BOOT, "Got init_done\n");
502
503                 /*
504                  ** It runs! It runs!
505                  */
506                 rio_dprintk(RIO_DEBUG_BOOT, "Host ID %x Running\n", HostP->UniqueNum);
507
508                 /*
509                  ** set the time period between interrupts.
510                  */
511                 writew(p->RIOConf.Timer, &ParmMapP->timer);
512
513                 /*
514                  ** Translate all the 16 bit pointers in the __ParmMapR into
515                  ** 32 bit pointers for the driver in ioremap space.
516                  */
517                 HostP->ParmMapP = ParmMapP;
518                 HostP->PhbP = (PHB *) RIO_PTR(Cad, readw(&ParmMapP->phb_ptr));
519                 HostP->RupP = (RUP *) RIO_PTR(Cad, readw(&ParmMapP->rups));
520                 HostP->PhbNumP = (ushort *) RIO_PTR(Cad, readw(&ParmMapP->phb_num_ptr));
521                 HostP->LinkStrP = (LPB *) RIO_PTR(Cad, readw(&ParmMapP->link_str_ptr));
522
523                 /*
524                  ** point the UnixRups at the real Rups
525                  */
526                 for (RupN = 0; RupN < MAX_RUP; RupN++) {
527                         HostP->UnixRups[RupN].RupP = &HostP->RupP[RupN];
528                         HostP->UnixRups[RupN].Id = RupN + 1;
529                         HostP->UnixRups[RupN].BaseSysPort = NO_PORT;
530                         spin_lock_init(&HostP->UnixRups[RupN].RupLock);
531                 }
532
533                 for (RupN = 0; RupN < LINKS_PER_UNIT; RupN++) {
534                         HostP->UnixRups[RupN + MAX_RUP].RupP = &HostP->LinkStrP[RupN].rup;
535                         HostP->UnixRups[RupN + MAX_RUP].Id = 0;
536                         HostP->UnixRups[RupN + MAX_RUP].BaseSysPort = NO_PORT;
537                         spin_lock_init(&HostP->UnixRups[RupN + MAX_RUP].RupLock);
538                 }
539
540                 /*
541                  ** point the PortP->Phbs at the real Phbs
542                  */
543                 for (PortN = p->RIOFirstPortsMapped; PortN < p->RIOLastPortsMapped + PORTS_PER_RTA; PortN++) {
544                         if (p->RIOPortp[PortN]->HostP == HostP) {
545                                 struct Port *PortP = p->RIOPortp[PortN];
546                                 struct PHB *PhbP;
547                                 /* int oldspl; */
548
549                                 if (!PortP->Mapped)
550                                         continue;
551
552                                 PhbP = &HostP->PhbP[PortP->HostPort];
553                                 rio_spin_lock_irqsave(&PortP->portSem, flags);
554
555                                 PortP->PhbP = PhbP;
556
557                                 PortP->TxAdd = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_add));
558                                 PortP->TxStart = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_start));
559                                 PortP->TxEnd = (u16 *) RIO_PTR(Cad, readw(&PhbP->tx_end));
560                                 PortP->RxRemove = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_remove));
561                                 PortP->RxStart = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_start));
562                                 PortP->RxEnd = (u16 *) RIO_PTR(Cad, readw(&PhbP->rx_end));
563
564                                 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
565                                 /*
566                                  ** point the UnixRup at the base SysPort
567                                  */
568                                 if (!(PortN % PORTS_PER_RTA))
569                                         HostP->UnixRups[PortP->RupNum].BaseSysPort = PortN;
570                         }
571                 }
572
573                 rio_dprintk(RIO_DEBUG_BOOT, "Set the card running... \n");
574                 /*
575                  ** last thing - show the world that everything is in place
576                  */
577                 HostP->Flags &= ~RUN_STATE;
578                 HostP->Flags |= RC_RUNNING;
579         }
580         /*
581          ** MPX always uses a poller. This is actually patched into the system
582          ** configuration and called directly from each clock tick.
583          **
584          */
585         p->RIOPolling = 1;
586
587         p->RIOSystemUp++;
588
589         rio_dprintk(RIO_DEBUG_BOOT, "Done everything %x\n", HostP->Ivec);
590         func_exit();
591         return 0;
592 }
593
594
595
596 /**
597  *      RIOBootRup              -       Boot an RTA
598  *      @p: rio we are working with
599  *      @Rup: Rup number
600  *      @HostP: host object
601  *      @PacketP: packet to use
602  *
603  *      If we have successfully processed this boot, then
604  *      return 1. If we havent, then return 0.
605  */
606
607 int RIOBootRup(struct rio_info *p, unsigned int Rup, struct Host *HostP, struct PKT *PacketP)
608 {
609         struct PktCmd *PktCmdP = (struct PktCmd *) PacketP->data;
610         struct PktCmd_M *PktReplyP;
611         struct CmdBlk *CmdBlkP;
612         unsigned int sequence;
613
614         /*
615          ** If we haven't been told what to boot, we can't boot it.
616          */
617         if (p->RIONumBootPkts == 0) {
618                 rio_dprintk(RIO_DEBUG_BOOT, "No RTA code to download yet\n");
619                 return 0;
620         }
621
622         /*
623          ** Special case of boot completed - if we get one of these then we
624          ** don't need a command block. For all other cases we do, so handle
625          ** this first and then get a command block, then handle every other
626          ** case, relinquishing the command block if disaster strikes!
627          */
628         if ((readb(&PacketP->len) & PKT_CMD_BIT) && (readb(&PktCmdP->Command) == BOOT_COMPLETED))
629                 return RIOBootComplete(p, HostP, Rup, PktCmdP);
630
631         /*
632          ** Try to allocate a command block. This is in kernel space
633          */
634         if (!(CmdBlkP = RIOGetCmdBlk())) {
635                 rio_dprintk(RIO_DEBUG_BOOT, "No command blocks to boot RTA! come back later.\n");
636                 return 0;
637         }
638
639         /*
640          ** Fill in the default info on the command block
641          */
642         CmdBlkP->Packet.dest_unit = Rup < (ushort) MAX_RUP ? Rup : 0;
643         CmdBlkP->Packet.dest_port = BOOT_RUP;
644         CmdBlkP->Packet.src_unit = 0;
645         CmdBlkP->Packet.src_port = BOOT_RUP;
646
647         CmdBlkP->PreFuncP = CmdBlkP->PostFuncP = NULL;
648         PktReplyP = (struct PktCmd_M *) CmdBlkP->Packet.data;
649
650         /*
651          ** process COMMANDS on the boot rup!
652          */
653         if (readb(&PacketP->len) & PKT_CMD_BIT) {
654                 /*
655                  ** We only expect one type of command - a BOOT_REQUEST!
656                  */
657                 if (readb(&PktCmdP->Command) != BOOT_REQUEST) {
658                         rio_dprintk(RIO_DEBUG_BOOT, "Unexpected command %d on BOOT RUP %d of host %Zd\n", readb(&PktCmdP->Command), Rup, HostP - p->RIOHosts);
659                         RIOFreeCmdBlk(CmdBlkP);
660                         return 1;
661                 }
662
663                 /*
664                  ** Build a Boot Sequence command block
665                  **
666                  ** We no longer need to use "Boot Mode", we'll always allow
667                  ** boot requests - the boot will not complete if the device
668                  ** appears in the bindings table.
669                  **
670                  ** We'll just (always) set the command field in packet reply
671                  ** to allow an attempted boot sequence :
672                  */
673                 PktReplyP->Command = BOOT_SEQUENCE;
674
675                 PktReplyP->BootSequence.NumPackets = p->RIONumBootPkts;
676                 PktReplyP->BootSequence.LoadBase = p->RIOConf.RtaLoadBase;
677                 PktReplyP->BootSequence.CodeSize = p->RIOBootCount;
678
679                 CmdBlkP->Packet.len = BOOT_SEQUENCE_LEN | PKT_CMD_BIT;
680
681                 memcpy((void *) &CmdBlkP->Packet.data[BOOT_SEQUENCE_LEN], "BOOT", 4);
682
683                 rio_dprintk(RIO_DEBUG_BOOT, "Boot RTA on Host %Zd Rup %d - %d (0x%x) packets to 0x%x\n", HostP - p->RIOHosts, Rup, p->RIONumBootPkts, p->RIONumBootPkts, p->RIOConf.RtaLoadBase);
684
685                 /*
686                  ** If this host is in slave mode, send the RTA an invalid boot
687                  ** sequence command block to force it to kill the boot. We wait
688                  ** for half a second before sending this packet to prevent the RTA
689                  ** attempting to boot too often. The master host should then grab
690                  ** the RTA and make it its own.
691                  */
692                 p->RIOBooting++;
693                 RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
694                 return 1;
695         }
696
697         /*
698          ** It is a request for boot data.
699          */
700         sequence = readw(&PktCmdP->Sequence);
701
702         rio_dprintk(RIO_DEBUG_BOOT, "Boot block %d on Host %Zd Rup%d\n", sequence, HostP - p->RIOHosts, Rup);
703
704         if (sequence >= p->RIONumBootPkts) {
705                 rio_dprintk(RIO_DEBUG_BOOT, "Got a request for packet %d, max is %d\n", sequence, p->RIONumBootPkts);
706         }
707
708         PktReplyP->Sequence = sequence;
709         memcpy(PktReplyP->BootData, p->RIOBootPackets[p->RIONumBootPkts - sequence - 1], RTA_BOOT_DATA_SIZE);
710         CmdBlkP->Packet.len = PKT_MAX_DATA_LEN;
711         RIOQueueCmdBlk(HostP, Rup, CmdBlkP);
712         return 1;
713 }
714
715 /**
716  *      RIOBootComplete         -       RTA boot is done
717  *      @p: RIO we are working with
718  *      @HostP: Host structure
719  *      @Rup: RUP being used
720  *      @PktCmdP: Packet command that was used
721  *
722  *      This function is called when an RTA been booted.
723  *      If booted by a host, HostP->HostUniqueNum is the booting host.
724  *      If booted by an RTA, HostP->Mapping[Rup].RtaUniqueNum is the booting RTA.
725  *      RtaUniq is the booted RTA.
726  */
727
728 static int RIOBootComplete(struct rio_info *p, struct Host *HostP, unsigned int Rup, struct PktCmd *PktCmdP)
729 {
730         struct Map *MapP = NULL;
731         struct Map *MapP2 = NULL;
732         int Flag;
733         int found;
734         int host, rta;
735         int EmptySlot = -1;
736         int entry, entry2;
737         char *MyType, *MyName;
738         unsigned int MyLink;
739         unsigned short RtaType;
740         u32 RtaUniq = (readb(&PktCmdP->UniqNum[0])) + (readb(&PktCmdP->UniqNum[1]) << 8) + (readb(&PktCmdP->UniqNum[2]) << 16) + (readb(&PktCmdP->UniqNum[3]) << 24);
741
742         p->RIOBooting = 0;
743
744         rio_dprintk(RIO_DEBUG_BOOT, "RTA Boot completed - BootInProgress now %d\n", p->RIOBooting);
745
746         /*
747          ** Determine type of unit (16/8 port RTA).
748          */
749
750         RtaType = GetUnitType(RtaUniq);
751         if (Rup >= (ushort) MAX_RUP)
752                 rio_dprintk(RIO_DEBUG_BOOT, "RIO: Host %s has booted an RTA(%d) on link %c\n", HostP->Name, 8 * RtaType, readb(&PktCmdP->LinkNum) + 'A');
753         else
754                 rio_dprintk(RIO_DEBUG_BOOT, "RIO: RTA %s has booted an RTA(%d) on link %c\n", HostP->Mapping[Rup].Name, 8 * RtaType, readb(&PktCmdP->LinkNum) + 'A');
755
756         rio_dprintk(RIO_DEBUG_BOOT, "UniqNum is 0x%x\n", RtaUniq);
757
758         if (RtaUniq == 0x00000000 || RtaUniq == 0xffffffff) {
759                 rio_dprintk(RIO_DEBUG_BOOT, "Illegal RTA Uniq Number\n");
760                 return TRUE;
761         }
762
763         /*
764          ** If this RTA has just booted an RTA which doesn't belong to this
765          ** system, or the system is in slave mode, do not attempt to create
766          ** a new table entry for it.
767          */
768
769         if (!RIOBootOk(p, HostP, RtaUniq)) {
770                 MyLink = readb(&PktCmdP->LinkNum);
771                 if (Rup < (unsigned short) MAX_RUP) {
772                         /*
773                          ** RtaUniq was clone booted (by this RTA). Instruct this RTA
774                          ** to hold off further attempts to boot on this link for 30
775                          ** seconds.
776                          */
777                         if (RIOSuspendBootRta(HostP, HostP->Mapping[Rup].ID, MyLink)) {
778                                 rio_dprintk(RIO_DEBUG_BOOT, "RTA failed to suspend booting on link %c\n", 'A' + MyLink);
779                         }
780                 } else
781                         /*
782                          ** RtaUniq was booted by this host. Set the booting link
783                          ** to hold off for 30 seconds to give another unit a
784                          ** chance to boot it.
785                          */
786                         writew(30, &HostP->LinkStrP[MyLink].WaitNoBoot);
787                 rio_dprintk(RIO_DEBUG_BOOT, "RTA %x not owned - suspend booting down link %c on unit %x\n", RtaUniq, 'A' + MyLink, HostP->Mapping[Rup].RtaUniqueNum);
788                 return TRUE;
789         }
790
791         /*
792          ** Check for a SLOT_IN_USE entry for this RTA attached to the
793          ** current host card in the driver table.
794          **
795          ** If it exists, make a note that we have booted it. Other parts of
796          ** the driver are interested in this information at a later date,
797          ** in particular when the booting RTA asks for an ID for this unit,
798          ** we must have set the BOOTED flag, and the NEWBOOT flag is used
799          ** to force an open on any ports that where previously open on this
800          ** unit.
801          */
802         for (entry = 0; entry < MAX_RUP; entry++) {
803                 unsigned int sysport;
804
805                 if ((HostP->Mapping[entry].Flags & SLOT_IN_USE) && (HostP->Mapping[entry].RtaUniqueNum == RtaUniq)) {
806                         HostP->Mapping[entry].Flags |= RTA_BOOTED | RTA_NEWBOOT;
807                         if ((sysport = HostP->Mapping[entry].SysPort) != NO_PORT) {
808                                 if (sysport < p->RIOFirstPortsBooted)
809                                         p->RIOFirstPortsBooted = sysport;
810                                 if (sysport > p->RIOLastPortsBooted)
811                                         p->RIOLastPortsBooted = sysport;
812                                 /*
813                                  ** For a 16 port RTA, check the second bank of 8 ports
814                                  */
815                                 if (RtaType == TYPE_RTA16) {
816                                         entry2 = HostP->Mapping[entry].ID2 - 1;
817                                         HostP->Mapping[entry2].Flags |= RTA_BOOTED | RTA_NEWBOOT;
818                                         sysport = HostP->Mapping[entry2].SysPort;
819                                         if (sysport < p->RIOFirstPortsBooted)
820                                                 p->RIOFirstPortsBooted = sysport;
821                                         if (sysport > p->RIOLastPortsBooted)
822                                                 p->RIOLastPortsBooted = sysport;
823                                 }
824                         }
825                         if (RtaType == TYPE_RTA16)
826                                 rio_dprintk(RIO_DEBUG_BOOT, "RTA will be given IDs %d+%d\n", entry + 1, entry2 + 1);
827                         else
828                                 rio_dprintk(RIO_DEBUG_BOOT, "RTA will be given ID %d\n", entry + 1);
829                         return TRUE;
830                 }
831         }
832
833         rio_dprintk(RIO_DEBUG_BOOT, "RTA not configured for this host\n");
834
835         if (Rup >= (unsigned short) MAX_RUP) {
836                 /*
837                  ** It was a host that did the booting
838                  */
839                 MyType = "Host";
840                 MyName = HostP->Name;
841         } else {
842                 /*
843                  ** It was an RTA that did the booting
844                  */
845                 MyType = "RTA";
846                 MyName = HostP->Mapping[Rup].Name;
847         }
848         MyLink = readb(&PktCmdP->LinkNum);
849
850         /*
851          ** There is no SLOT_IN_USE entry for this RTA attached to the current
852          ** host card in the driver table.
853          **
854          ** Check for a SLOT_TENTATIVE entry for this RTA attached to the
855          ** current host card in the driver table.
856          **
857          ** If we find one, then we re-use that slot.
858          */
859         for (entry = 0; entry < MAX_RUP; entry++) {
860                 if ((HostP->Mapping[entry].Flags & SLOT_TENTATIVE) && (HostP->Mapping[entry].RtaUniqueNum == RtaUniq)) {
861                         if (RtaType == TYPE_RTA16) {
862                                 entry2 = HostP->Mapping[entry].ID2 - 1;
863                                 if ((HostP->Mapping[entry2].Flags & SLOT_TENTATIVE) && (HostP->Mapping[entry2].RtaUniqueNum == RtaUniq))
864                                         rio_dprintk(RIO_DEBUG_BOOT, "Found previous tentative slots (%d+%d)\n", entry, entry2);
865                                 else
866                                         continue;
867                         } else
868                                 rio_dprintk(RIO_DEBUG_BOOT, "Found previous tentative slot (%d)\n", entry);
869                         if (!p->RIONoMessage)
870                                 printk("RTA connected to %s '%s' (%c) not configured.\n", MyType, MyName, MyLink + 'A');
871                         return TRUE;
872                 }
873         }
874
875         /*
876          ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
877          ** attached to the current host card in the driver table.
878          **
879          ** Check if there is a SLOT_IN_USE or SLOT_TENTATIVE entry on another
880          ** host for this RTA in the driver table.
881          **
882          ** For a SLOT_IN_USE entry on another host, we need to delete the RTA
883          ** entry from the other host and add it to this host (using some of
884          ** the functions from table.c which do this).
885          ** For a SLOT_TENTATIVE entry on another host, we must cope with the
886          ** following scenario:
887          **
888          ** + Plug 8 port RTA into host A. (This creates SLOT_TENTATIVE entry
889          **   in table)
890          ** + Unplug RTA and plug into host B. (We now have 2 SLOT_TENTATIVE
891          **   entries)
892          ** + Configure RTA on host B. (This slot now becomes SLOT_IN_USE)
893          ** + Unplug RTA and plug back into host A.
894          ** + Configure RTA on host A. We now have the same RTA configured
895          **   with different ports on two different hosts.
896          */
897         rio_dprintk(RIO_DEBUG_BOOT, "Have we seen RTA %x before?\n", RtaUniq);
898         found = 0;
899         Flag = 0;               /* Convince the compiler this variable is initialized */
900         for (host = 0; !found && (host < p->RIONumHosts); host++) {
901                 for (rta = 0; rta < MAX_RUP; rta++) {
902                         if ((p->RIOHosts[host].Mapping[rta].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) && (p->RIOHosts[host].Mapping[rta].RtaUniqueNum == RtaUniq)) {
903                                 Flag = p->RIOHosts[host].Mapping[rta].Flags;
904                                 MapP = &p->RIOHosts[host].Mapping[rta];
905                                 if (RtaType == TYPE_RTA16) {
906                                         MapP2 = &p->RIOHosts[host].Mapping[MapP->ID2 - 1];
907                                         rio_dprintk(RIO_DEBUG_BOOT, "This RTA is units %d+%d from host %s\n", rta + 1, MapP->ID2, p->RIOHosts[host].Name);
908                                 } else
909                                         rio_dprintk(RIO_DEBUG_BOOT, "This RTA is unit %d from host %s\n", rta + 1, p->RIOHosts[host].Name);
910                                 found = 1;
911                                 break;
912                         }
913                 }
914         }
915
916         /*
917          ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
918          ** attached to the current host card in the driver table.
919          **
920          ** If we have not found a SLOT_IN_USE or SLOT_TENTATIVE entry on
921          ** another host for this RTA in the driver table...
922          **
923          ** Check for a SLOT_IN_USE entry for this RTA in the config table.
924          */
925         if (!MapP) {
926                 rio_dprintk(RIO_DEBUG_BOOT, "Look for RTA %x in RIOSavedTable\n", RtaUniq);
927                 for (rta = 0; rta < TOTAL_MAP_ENTRIES; rta++) {
928                         rio_dprintk(RIO_DEBUG_BOOT, "Check table entry %d (%x)", rta, p->RIOSavedTable[rta].RtaUniqueNum);
929
930                         if ((p->RIOSavedTable[rta].Flags & SLOT_IN_USE) && (p->RIOSavedTable[rta].RtaUniqueNum == RtaUniq)) {
931                                 MapP = &p->RIOSavedTable[rta];
932                                 Flag = p->RIOSavedTable[rta].Flags;
933                                 if (RtaType == TYPE_RTA16) {
934                                         for (entry2 = rta + 1; entry2 < TOTAL_MAP_ENTRIES; entry2++) {
935                                                 if (p->RIOSavedTable[entry2].RtaUniqueNum == RtaUniq)
936                                                         break;
937                                         }
938                                         MapP2 = &p->RIOSavedTable[entry2];
939                                         rio_dprintk(RIO_DEBUG_BOOT, "This RTA is from table entries %d+%d\n", rta, entry2);
940                                 } else
941                                         rio_dprintk(RIO_DEBUG_BOOT, "This RTA is from table entry %d\n", rta);
942                                 break;
943                         }
944                 }
945         }
946
947         /*
948          ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
949          ** attached to the current host card in the driver table.
950          **
951          ** We may have found a SLOT_IN_USE entry on another host for this
952          ** RTA in the config table, or a SLOT_IN_USE or SLOT_TENTATIVE entry
953          ** on another host for this RTA in the driver table.
954          **
955          ** Check the driver table for room to fit this newly discovered RTA.
956          ** RIOFindFreeID() first looks for free slots and if it does not
957          ** find any free slots it will then attempt to oust any
958          ** tentative entry in the table.
959          */
960         EmptySlot = 1;
961         if (RtaType == TYPE_RTA16) {
962                 if (RIOFindFreeID(p, HostP, &entry, &entry2) == 0) {
963                         RIODefaultName(p, HostP, entry);
964                         FillSlot(entry, entry2, RtaUniq, HostP);
965                         EmptySlot = 0;
966                 }
967         } else {
968                 if (RIOFindFreeID(p, HostP, &entry, NULL) == 0) {
969                         RIODefaultName(p, HostP, entry);
970                         FillSlot(entry, 0, RtaUniq, HostP);
971                         EmptySlot = 0;
972                 }
973         }
974
975         /*
976          ** There is no SLOT_IN_USE or SLOT_TENTATIVE entry for this RTA
977          ** attached to the current host card in the driver table.
978          **
979          ** If we found a SLOT_IN_USE entry on another host for this
980          ** RTA in the config or driver table, and there are enough free
981          ** slots in the driver table, then we need to move it over and
982          ** delete it from the other host.
983          ** If we found a SLOT_TENTATIVE entry on another host for this
984          ** RTA in the driver table, just delete the other host entry.
985          */
986         if (EmptySlot == 0) {
987                 if (MapP) {
988                         if (Flag & SLOT_IN_USE) {
989                                 rio_dprintk(RIO_DEBUG_BOOT, "This RTA configured on another host - move entry to current host (1)\n");
990                                 HostP->Mapping[entry].SysPort = MapP->SysPort;
991                                 memcpy(HostP->Mapping[entry].Name, MapP->Name, MAX_NAME_LEN);
992                                 HostP->Mapping[entry].Flags = SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT;
993                                 RIOReMapPorts(p, HostP, &HostP->Mapping[entry]);
994                                 if (HostP->Mapping[entry].SysPort < p->RIOFirstPortsBooted)
995                                         p->RIOFirstPortsBooted = HostP->Mapping[entry].SysPort;
996                                 if (HostP->Mapping[entry].SysPort > p->RIOLastPortsBooted)
997                                         p->RIOLastPortsBooted = HostP->Mapping[entry].SysPort;
998                                 rio_dprintk(RIO_DEBUG_BOOT, "SysPort %d, Name %s\n", (int) MapP->SysPort, MapP->Name);
999                         } else {
1000                                 rio_dprintk(RIO_DEBUG_BOOT, "This RTA has a tentative entry on another host - delete that entry (1)\n");
1001                                 HostP->Mapping[entry].Flags = SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT;
1002                         }
1003                         if (RtaType == TYPE_RTA16) {
1004                                 if (Flag & SLOT_IN_USE) {
1005                                         HostP->Mapping[entry2].Flags = SLOT_IN_USE | RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1006                                         HostP->Mapping[entry2].SysPort = MapP2->SysPort;
1007                                         /*
1008                                          ** Map second block of ttys for 16 port RTA
1009                                          */
1010                                         RIOReMapPorts(p, HostP, &HostP->Mapping[entry2]);
1011                                         if (HostP->Mapping[entry2].SysPort < p->RIOFirstPortsBooted)
1012                                                 p->RIOFirstPortsBooted = HostP->Mapping[entry2].SysPort;
1013                                         if (HostP->Mapping[entry2].SysPort > p->RIOLastPortsBooted)
1014                                                 p->RIOLastPortsBooted = HostP->Mapping[entry2].SysPort;
1015                                         rio_dprintk(RIO_DEBUG_BOOT, "SysPort %d, Name %s\n", (int) HostP->Mapping[entry2].SysPort, HostP->Mapping[entry].Name);
1016                                 } else
1017                                         HostP->Mapping[entry2].Flags = SLOT_TENTATIVE | RTA_BOOTED | RTA_NEWBOOT | RTA16_SECOND_SLOT;
1018                                 memset(MapP2, 0, sizeof(struct Map));
1019                         }
1020                         memset(MapP, 0, sizeof(struct Map));
1021                         if (!p->RIONoMessage)
1022                                 printk("An orphaned RTA has been adopted by %s '%s' (%c).\n", MyType, MyName, MyLink + 'A');
1023                 } else if (!p->RIONoMessage)
1024                         printk("RTA connected to %s '%s' (%c) not configured.\n", MyType, MyName, MyLink + 'A');
1025                 RIOSetChange(p);
1026                 return TRUE;
1027         }
1028
1029         /*
1030          ** There is no room in the driver table to make an entry for the
1031          ** booted RTA. Keep a note of its Uniq Num in the overflow table,
1032          ** so we can ignore it's ID requests.
1033          */
1034         if (!p->RIONoMessage)
1035                 printk("The RTA connected to %s '%s' (%c) cannot be configured.  You cannot configure more than 128 ports to one host card.\n", MyType, MyName, MyLink + 'A');
1036         for (entry = 0; entry < HostP->NumExtraBooted; entry++) {
1037                 if (HostP->ExtraUnits[entry] == RtaUniq) {
1038                         /*
1039                          ** already got it!
1040                          */
1041                         return TRUE;
1042                 }
1043         }
1044         /*
1045          ** If there is room, add the unit to the list of extras
1046          */
1047         if (HostP->NumExtraBooted < MAX_EXTRA_UNITS)
1048                 HostP->ExtraUnits[HostP->NumExtraBooted++] = RtaUniq;
1049         return TRUE;
1050 }
1051
1052
1053 /*
1054 ** If the RTA or its host appears in the RIOBindTab[] structure then
1055 ** we mustn't boot the RTA and should return FALSE.
1056 ** This operation is slightly different from the other drivers for RIO
1057 ** in that this is designed to work with the new utilities
1058 ** not config.rio and is FAR SIMPLER.
1059 ** We no longer support the RIOBootMode variable. It is all done from the
1060 ** "boot/noboot" field in the rio.cf file.
1061 */
1062 int RIOBootOk(struct rio_info *p, struct Host *HostP, unsigned long RtaUniq)
1063 {
1064         int Entry;
1065         unsigned int HostUniq = HostP->UniqueNum;
1066
1067         /*
1068          ** Search bindings table for RTA or its parent.
1069          ** If it exists, return 0, else 1.
1070          */
1071         for (Entry = 0; (Entry < MAX_RTA_BINDINGS) && (p->RIOBindTab[Entry] != 0); Entry++) {
1072                 if ((p->RIOBindTab[Entry] == HostUniq) || (p->RIOBindTab[Entry] == RtaUniq))
1073                         return 0;
1074         }
1075         return 1;
1076 }
1077
1078 /*
1079 ** Make an empty slot tentative. If this is a 16 port RTA, make both
1080 ** slots tentative, and the second one RTA_SECOND_SLOT as well.
1081 */
1082
1083 void FillSlot(int entry, int entry2, unsigned int RtaUniq, struct Host *HostP)
1084 {
1085         int link;
1086
1087         rio_dprintk(RIO_DEBUG_BOOT, "FillSlot(%d, %d, 0x%x...)\n", entry, entry2, RtaUniq);
1088
1089         HostP->Mapping[entry].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE);
1090         HostP->Mapping[entry].SysPort = NO_PORT;
1091         HostP->Mapping[entry].RtaUniqueNum = RtaUniq;
1092         HostP->Mapping[entry].HostUniqueNum = HostP->UniqueNum;
1093         HostP->Mapping[entry].ID = entry + 1;
1094         HostP->Mapping[entry].ID2 = 0;
1095         if (entry2) {
1096                 HostP->Mapping[entry2].Flags = (RTA_BOOTED | RTA_NEWBOOT | SLOT_TENTATIVE | RTA16_SECOND_SLOT);
1097                 HostP->Mapping[entry2].SysPort = NO_PORT;
1098                 HostP->Mapping[entry2].RtaUniqueNum = RtaUniq;
1099                 HostP->Mapping[entry2].HostUniqueNum = HostP->UniqueNum;
1100                 HostP->Mapping[entry2].Name[0] = '\0';
1101                 HostP->Mapping[entry2].ID = entry2 + 1;
1102                 HostP->Mapping[entry2].ID2 = entry + 1;
1103                 HostP->Mapping[entry].ID2 = entry2 + 1;
1104         }
1105         /*
1106          ** Must set these up, so that utilities show
1107          ** topology of 16 port RTAs correctly
1108          */
1109         for (link = 0; link < LINKS_PER_UNIT; link++) {
1110                 HostP->Mapping[entry].Topology[link].Unit = ROUTE_DISCONNECT;
1111                 HostP->Mapping[entry].Topology[link].Link = NO_LINK;
1112                 if (entry2) {
1113                         HostP->Mapping[entry2].Topology[link].Unit = ROUTE_DISCONNECT;
1114                         HostP->Mapping[entry2].Topology[link].Link = NO_LINK;
1115                 }
1116         }
1117 }