rioboot.c 37 KB

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