rioboot.c 37 KB

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