i2ellis.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  1. /*******************************************************************************
  2. *
  3. * (c) 1998 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. *
  8. * PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
  9. * serial I/O controllers.
  10. *
  11. * DESCRIPTION: Low-level interface code for the device driver
  12. * (This is included source code, not a separate compilation
  13. * module.)
  14. *
  15. *******************************************************************************/
  16. //---------------------------------------------
  17. // Function declarations private to this module
  18. //---------------------------------------------
  19. // Functions called only indirectly through i2eBordStr entries.
  20. static int iiWriteBuf16(i2eBordStrPtr, unsigned char *, int);
  21. static int iiWriteBuf8(i2eBordStrPtr, unsigned char *, int);
  22. static int iiReadBuf16(i2eBordStrPtr, unsigned char *, int);
  23. static int iiReadBuf8(i2eBordStrPtr, unsigned char *, int);
  24. static unsigned short iiReadWord16(i2eBordStrPtr);
  25. static unsigned short iiReadWord8(i2eBordStrPtr);
  26. static void iiWriteWord16(i2eBordStrPtr, unsigned short);
  27. static void iiWriteWord8(i2eBordStrPtr, unsigned short);
  28. static int iiWaitForTxEmptyII(i2eBordStrPtr, int);
  29. static int iiWaitForTxEmptyIIEX(i2eBordStrPtr, int);
  30. static int iiTxMailEmptyII(i2eBordStrPtr);
  31. static int iiTxMailEmptyIIEX(i2eBordStrPtr);
  32. static int iiTrySendMailII(i2eBordStrPtr, unsigned char);
  33. static int iiTrySendMailIIEX(i2eBordStrPtr, unsigned char);
  34. static unsigned short iiGetMailII(i2eBordStrPtr);
  35. static unsigned short iiGetMailIIEX(i2eBordStrPtr);
  36. static void iiEnableMailIrqII(i2eBordStrPtr);
  37. static void iiEnableMailIrqIIEX(i2eBordStrPtr);
  38. static void iiWriteMaskII(i2eBordStrPtr, unsigned char);
  39. static void iiWriteMaskIIEX(i2eBordStrPtr, unsigned char);
  40. static void ii2DelayTimer(unsigned int);
  41. static void ii2DelayWakeup(unsigned long id);
  42. static void ii2Nop(void);
  43. //***************
  44. //* Static Data *
  45. //***************
  46. static int ii2Safe; // Safe I/O address for delay routine
  47. static int iiDelayed; // Set when the iiResetDelay function is
  48. // called. Cleared when ANY board is reset.
  49. static struct timer_list * pDelayTimer; // Used by iiDelayTimer
  50. static wait_queue_head_t pDelayWait; // Used by iiDelayTimer
  51. static rwlock_t Dl_spinlock;
  52. //********
  53. //* Code *
  54. //********
  55. //=======================================================
  56. // Initialization Routines
  57. //
  58. // iiSetAddress
  59. // iiReset
  60. // iiResetDelay
  61. // iiInitialize
  62. //=======================================================
  63. //******************************************************************************
  64. // Function: iiEllisInit()
  65. // Parameters: None
  66. //
  67. // Returns: Nothing
  68. //
  69. // Description:
  70. //
  71. // This routine performs any required initialization of the iiEllis subsystem.
  72. //
  73. //******************************************************************************
  74. static void
  75. iiEllisInit(void)
  76. {
  77. pDelayTimer = kmalloc ( sizeof (struct timer_list), GFP_KERNEL );
  78. init_timer(pDelayTimer);
  79. init_waitqueue_head(&pDelayWait);
  80. LOCK_INIT(&Dl_spinlock);
  81. }
  82. //******************************************************************************
  83. // Function: iiEllisCleanup()
  84. // Parameters: None
  85. //
  86. // Returns: Nothing
  87. //
  88. // Description:
  89. //
  90. // This routine performs any required cleanup of the iiEllis subsystem.
  91. //
  92. //******************************************************************************
  93. static void
  94. iiEllisCleanup(void)
  95. {
  96. kfree(pDelayTimer);
  97. }
  98. //******************************************************************************
  99. // Function: iiSetAddress(pB, address, delay)
  100. // Parameters: pB - pointer to the board structure
  101. // address - the purported I/O address of the board
  102. // delay - pointer to the 1-ms delay function to use
  103. // in this and any future operations to this board
  104. //
  105. // Returns: True if everything appears copacetic.
  106. // False if there is any error: the pB->i2eError field has the error
  107. //
  108. // Description:
  109. //
  110. // This routine (roughly) checks for address validity, sets the i2eValid OK and
  111. // sets the state to II_STATE_COLD which means that we haven't even sent a reset
  112. // yet.
  113. //
  114. //******************************************************************************
  115. static int
  116. iiSetAddress( i2eBordStrPtr pB, int address, delayFunc_t delay )
  117. {
  118. // Should any failure occur before init is finished...
  119. pB->i2eValid = I2E_INCOMPLETE;
  120. // Cannot check upper limit except extremely: Might be microchannel
  121. // Address must be on an 8-byte boundary
  122. if ((unsigned int)address <= 0x100
  123. || (unsigned int)address >= 0xfff8
  124. || (address & 0x7)
  125. )
  126. {
  127. COMPLETE(pB,I2EE_BADADDR);
  128. }
  129. // Initialize accelerators
  130. pB->i2eBase = address;
  131. pB->i2eData = address + FIFO_DATA;
  132. pB->i2eStatus = address + FIFO_STATUS;
  133. pB->i2ePointer = address + FIFO_PTR;
  134. pB->i2eXMail = address + FIFO_MAIL;
  135. pB->i2eXMask = address + FIFO_MASK;
  136. // Initialize i/o address for ii2DelayIO
  137. ii2Safe = address + FIFO_NOP;
  138. // Initialize the delay routine
  139. pB->i2eDelay = ((delay != (delayFunc_t)NULL) ? delay : (delayFunc_t)ii2Nop);
  140. pB->i2eValid = I2E_MAGIC;
  141. pB->i2eState = II_STATE_COLD;
  142. COMPLETE(pB, I2EE_GOOD);
  143. }
  144. //******************************************************************************
  145. // Function: iiReset(pB)
  146. // Parameters: pB - pointer to the board structure
  147. //
  148. // Returns: True if everything appears copacetic.
  149. // False if there is any error: the pB->i2eError field has the error
  150. //
  151. // Description:
  152. //
  153. // Attempts to reset the board (see also i2hw.h). Normally, we would use this to
  154. // reset a board immediately after iiSetAddress(), but it is valid to reset a
  155. // board from any state, say, in order to change or re-load loadware. (Under
  156. // such circumstances, no reason to re-run iiSetAddress(), which is why it is a
  157. // separate routine and not included in this routine.
  158. //
  159. //******************************************************************************
  160. static int
  161. iiReset(i2eBordStrPtr pB)
  162. {
  163. // Magic number should be set, else even the address is suspect
  164. if (pB->i2eValid != I2E_MAGIC)
  165. {
  166. COMPLETE(pB, I2EE_BADMAGIC);
  167. }
  168. OUTB(pB->i2eBase + FIFO_RESET, 0); // Any data will do
  169. iiDelay(pB, 50); // Pause between resets
  170. OUTB(pB->i2eBase + FIFO_RESET, 0); // Second reset
  171. // We must wait before even attempting to read anything from the FIFO: the
  172. // board's P.O.S.T may actually attempt to read and write its end of the
  173. // FIFO in order to check flags, loop back (where supported), etc. On
  174. // completion of this testing it would reset the FIFO, and on completion
  175. // of all // P.O.S.T., write the message. We must not mistake data which
  176. // might have been sent for testing as part of the reset message. To
  177. // better utilize time, say, when resetting several boards, we allow the
  178. // delay to be performed externally; in this way the caller can reset
  179. // several boards, delay a single time, then call the initialization
  180. // routine for all.
  181. pB->i2eState = II_STATE_RESET;
  182. iiDelayed = 0; // i.e., the delay routine hasn't been called since the most
  183. // recent reset.
  184. // Ensure anything which would have been of use to standard loadware is
  185. // blanked out, since board has now forgotten everything!.
  186. pB->i2eUsingIrq = IRQ_UNDEFINED; // Not set up to use an interrupt yet
  187. pB->i2eWaitingForEmptyFifo = 0;
  188. pB->i2eOutMailWaiting = 0;
  189. pB->i2eChannelPtr = NULL;
  190. pB->i2eChannelCnt = 0;
  191. pB->i2eLeadoffWord[0] = 0;
  192. pB->i2eFifoInInts = 0;
  193. pB->i2eFifoOutInts = 0;
  194. pB->i2eFatalTrap = NULL;
  195. pB->i2eFatal = 0;
  196. COMPLETE(pB, I2EE_GOOD);
  197. }
  198. //******************************************************************************
  199. // Function: iiResetDelay(pB)
  200. // Parameters: pB - pointer to the board structure
  201. //
  202. // Returns: True if everything appears copacetic.
  203. // False if there is any error: the pB->i2eError field has the error
  204. //
  205. // Description:
  206. //
  207. // Using the delay defined in board structure, waits two seconds (for board to
  208. // reset).
  209. //
  210. //******************************************************************************
  211. static int
  212. iiResetDelay(i2eBordStrPtr pB)
  213. {
  214. if (pB->i2eValid != I2E_MAGIC) {
  215. COMPLETE(pB, I2EE_BADMAGIC);
  216. }
  217. if (pB->i2eState != II_STATE_RESET) {
  218. COMPLETE(pB, I2EE_BADSTATE);
  219. }
  220. iiDelay(pB,2000); /* Now we wait for two seconds. */
  221. iiDelayed = 1; /* Delay has been called: ok to initialize */
  222. COMPLETE(pB, I2EE_GOOD);
  223. }
  224. //******************************************************************************
  225. // Function: iiInitialize(pB)
  226. // Parameters: pB - pointer to the board structure
  227. //
  228. // Returns: True if everything appears copacetic.
  229. // False if there is any error: the pB->i2eError field has the error
  230. //
  231. // Description:
  232. //
  233. // Attempts to read the Power-on reset message. Initializes any remaining fields
  234. // in the pB structure.
  235. //
  236. // This should be called as the third step of a process beginning with
  237. // iiReset(), then iiResetDelay(). This routine checks to see that the structure
  238. // is "valid" and in the reset state, also confirms that the delay routine has
  239. // been called since the latest reset (to any board! overly strong!).
  240. //
  241. //******************************************************************************
  242. static int
  243. iiInitialize(i2eBordStrPtr pB)
  244. {
  245. int itemp;
  246. unsigned char c;
  247. unsigned short utemp;
  248. unsigned int ilimit;
  249. if (pB->i2eValid != I2E_MAGIC)
  250. {
  251. COMPLETE(pB, I2EE_BADMAGIC);
  252. }
  253. if (pB->i2eState != II_STATE_RESET || !iiDelayed)
  254. {
  255. COMPLETE(pB, I2EE_BADSTATE);
  256. }
  257. // In case there is a failure short of our completely reading the power-up
  258. // message.
  259. pB->i2eValid = I2E_INCOMPLETE;
  260. // Now attempt to read the message.
  261. for (itemp = 0; itemp < sizeof(porStr); itemp++)
  262. {
  263. // We expect the entire message is ready.
  264. if (HAS_NO_INPUT(pB))
  265. {
  266. pB->i2ePomSize = itemp;
  267. COMPLETE(pB, I2EE_PORM_SHORT);
  268. }
  269. pB->i2ePom.c[itemp] = c = BYTE_FROM(pB);
  270. // We check the magic numbers as soon as they are supposed to be read
  271. // (rather than after) to minimize effect of reading something we
  272. // already suspect can't be "us".
  273. if ( (itemp == POR_1_INDEX && c != POR_MAGIC_1) ||
  274. (itemp == POR_2_INDEX && c != POR_MAGIC_2))
  275. {
  276. pB->i2ePomSize = itemp+1;
  277. COMPLETE(pB, I2EE_BADMAGIC);
  278. }
  279. }
  280. pB->i2ePomSize = itemp;
  281. // Ensure that this was all the data...
  282. if (HAS_INPUT(pB))
  283. COMPLETE(pB, I2EE_PORM_LONG);
  284. // For now, we'll fail to initialize if P.O.S.T reports bad chip mapper:
  285. // Implying we will not be able to download any code either: That's ok: the
  286. // condition is pretty explicit.
  287. if (pB->i2ePom.e.porDiag1 & POR_BAD_MAPPER)
  288. {
  289. COMPLETE(pB, I2EE_POSTERR);
  290. }
  291. // Determine anything which must be done differently depending on the family
  292. // of boards!
  293. switch (pB->i2ePom.e.porID & POR_ID_FAMILY)
  294. {
  295. case POR_ID_FII: // IntelliPort-II
  296. pB->i2eFifoStyle = FIFO_II;
  297. pB->i2eFifoSize = 512; // 512 bytes, always
  298. pB->i2eDataWidth16 = NO;
  299. pB->i2eMaxIrq = 15; // Because board cannot tell us it is in an 8-bit
  300. // slot, we do allow it to be done (documentation!)
  301. pB->i2eGoodMap[1] =
  302. pB->i2eGoodMap[2] =
  303. pB->i2eGoodMap[3] =
  304. pB->i2eChannelMap[1] =
  305. pB->i2eChannelMap[2] =
  306. pB->i2eChannelMap[3] = 0;
  307. switch (pB->i2ePom.e.porID & POR_ID_SIZE)
  308. {
  309. case POR_ID_II_4:
  310. pB->i2eGoodMap[0] =
  311. pB->i2eChannelMap[0] = 0x0f; // four-port
  312. // Since porPorts1 is based on the Hardware ID register, the numbers
  313. // should always be consistent for IntelliPort-II. Ditto below...
  314. if (pB->i2ePom.e.porPorts1 != 4)
  315. {
  316. COMPLETE(pB, I2EE_INCONSIST);
  317. }
  318. break;
  319. case POR_ID_II_8:
  320. case POR_ID_II_8R:
  321. pB->i2eGoodMap[0] =
  322. pB->i2eChannelMap[0] = 0xff; // Eight port
  323. if (pB->i2ePom.e.porPorts1 != 8)
  324. {
  325. COMPLETE(pB, I2EE_INCONSIST);
  326. }
  327. break;
  328. case POR_ID_II_6:
  329. pB->i2eGoodMap[0] =
  330. pB->i2eChannelMap[0] = 0x3f; // Six Port
  331. if (pB->i2ePom.e.porPorts1 != 6)
  332. {
  333. COMPLETE(pB, I2EE_INCONSIST);
  334. }
  335. break;
  336. }
  337. // Fix up the "good channel list based on any errors reported.
  338. if (pB->i2ePom.e.porDiag1 & POR_BAD_UART1)
  339. {
  340. pB->i2eGoodMap[0] &= ~0x0f;
  341. }
  342. if (pB->i2ePom.e.porDiag1 & POR_BAD_UART2)
  343. {
  344. pB->i2eGoodMap[0] &= ~0xf0;
  345. }
  346. break; // POR_ID_FII case
  347. case POR_ID_FIIEX: // IntelliPort-IIEX
  348. pB->i2eFifoStyle = FIFO_IIEX;
  349. itemp = pB->i2ePom.e.porFifoSize;
  350. // Implicit assumption that fifo would not grow beyond 32k,
  351. // nor would ever be less than 256.
  352. if (itemp < 8 || itemp > 15)
  353. {
  354. COMPLETE(pB, I2EE_INCONSIST);
  355. }
  356. pB->i2eFifoSize = (1 << itemp);
  357. // These are based on what P.O.S.T thinks should be there, based on
  358. // box ID registers
  359. ilimit = pB->i2ePom.e.porNumBoxes;
  360. if (ilimit > ABS_MAX_BOXES)
  361. {
  362. ilimit = ABS_MAX_BOXES;
  363. }
  364. // For as many boxes as EXIST, gives the type of box.
  365. // Added 8/6/93: check for the ISA-4 (asic) which looks like an
  366. // expandable but for whom "8 or 16?" is not the right question.
  367. utemp = pB->i2ePom.e.porFlags;
  368. if (utemp & POR_CEX4)
  369. {
  370. pB->i2eChannelMap[0] = 0x000f;
  371. } else {
  372. utemp &= POR_BOXES;
  373. for (itemp = 0; itemp < ilimit; itemp++)
  374. {
  375. pB->i2eChannelMap[itemp] =
  376. ((utemp & POR_BOX_16) ? 0xffff : 0x00ff);
  377. utemp >>= 1;
  378. }
  379. }
  380. // These are based on what P.O.S.T actually found.
  381. utemp = (pB->i2ePom.e.porPorts2 << 8) + pB->i2ePom.e.porPorts1;
  382. for (itemp = 0; itemp < ilimit; itemp++)
  383. {
  384. pB->i2eGoodMap[itemp] = 0;
  385. if (utemp & 1) pB->i2eGoodMap[itemp] |= 0x000f;
  386. if (utemp & 2) pB->i2eGoodMap[itemp] |= 0x00f0;
  387. if (utemp & 4) pB->i2eGoodMap[itemp] |= 0x0f00;
  388. if (utemp & 8) pB->i2eGoodMap[itemp] |= 0xf000;
  389. utemp >>= 4;
  390. }
  391. // Now determine whether we should transfer in 8 or 16-bit mode.
  392. switch (pB->i2ePom.e.porBus & (POR_BUS_SLOT16 | POR_BUS_DIP16) )
  393. {
  394. case POR_BUS_SLOT16 | POR_BUS_DIP16:
  395. pB->i2eDataWidth16 = YES;
  396. pB->i2eMaxIrq = 15;
  397. break;
  398. case POR_BUS_SLOT16:
  399. pB->i2eDataWidth16 = NO;
  400. pB->i2eMaxIrq = 15;
  401. break;
  402. case 0:
  403. case POR_BUS_DIP16: // In an 8-bit slot, DIP switch don't care.
  404. default:
  405. pB->i2eDataWidth16 = NO;
  406. pB->i2eMaxIrq = 7;
  407. break;
  408. }
  409. break; // POR_ID_FIIEX case
  410. default: // Unknown type of board
  411. COMPLETE(pB, I2EE_BAD_FAMILY);
  412. break;
  413. } // End the switch based on family
  414. // Temporarily, claim there is no room in the outbound fifo.
  415. // We will maintain this whenever we check for an empty outbound FIFO.
  416. pB->i2eFifoRemains = 0;
  417. // Now, based on the bus type, should we expect to be able to re-configure
  418. // interrupts (say, for testing purposes).
  419. switch (pB->i2ePom.e.porBus & POR_BUS_TYPE)
  420. {
  421. case POR_BUS_T_ISA:
  422. case POR_BUS_T_UNK: // If the type of bus is undeclared, assume ok.
  423. pB->i2eChangeIrq = YES;
  424. break;
  425. case POR_BUS_T_MCA:
  426. case POR_BUS_T_EISA:
  427. pB->i2eChangeIrq = NO;
  428. break;
  429. default:
  430. COMPLETE(pB, I2EE_BADBUS);
  431. }
  432. if (pB->i2eDataWidth16 == YES)
  433. {
  434. pB->i2eWriteBuf = iiWriteBuf16;
  435. pB->i2eReadBuf = iiReadBuf16;
  436. pB->i2eWriteWord = iiWriteWord16;
  437. pB->i2eReadWord = iiReadWord16;
  438. } else {
  439. pB->i2eWriteBuf = iiWriteBuf8;
  440. pB->i2eReadBuf = iiReadBuf8;
  441. pB->i2eWriteWord = iiWriteWord8;
  442. pB->i2eReadWord = iiReadWord8;
  443. }
  444. switch(pB->i2eFifoStyle)
  445. {
  446. case FIFO_II:
  447. pB->i2eWaitForTxEmpty = iiWaitForTxEmptyII;
  448. pB->i2eTxMailEmpty = iiTxMailEmptyII;
  449. pB->i2eTrySendMail = iiTrySendMailII;
  450. pB->i2eGetMail = iiGetMailII;
  451. pB->i2eEnableMailIrq = iiEnableMailIrqII;
  452. pB->i2eWriteMask = iiWriteMaskII;
  453. break;
  454. case FIFO_IIEX:
  455. pB->i2eWaitForTxEmpty = iiWaitForTxEmptyIIEX;
  456. pB->i2eTxMailEmpty = iiTxMailEmptyIIEX;
  457. pB->i2eTrySendMail = iiTrySendMailIIEX;
  458. pB->i2eGetMail = iiGetMailIIEX;
  459. pB->i2eEnableMailIrq = iiEnableMailIrqIIEX;
  460. pB->i2eWriteMask = iiWriteMaskIIEX;
  461. break;
  462. default:
  463. COMPLETE(pB, I2EE_INCONSIST);
  464. }
  465. // Initialize state information.
  466. pB->i2eState = II_STATE_READY; // Ready to load loadware.
  467. // Some Final cleanup:
  468. // For some boards, the bootstrap firmware may perform some sort of test
  469. // resulting in a stray character pending in the incoming mailbox. If one is
  470. // there, it should be read and discarded, especially since for the standard
  471. // firmware, it's the mailbox that interrupts the host.
  472. pB->i2eStartMail = iiGetMail(pB);
  473. // Throw it away and clear the mailbox structure element
  474. pB->i2eStartMail = NO_MAIL_HERE;
  475. // Everything is ok now, return with good status/
  476. pB->i2eValid = I2E_MAGIC;
  477. COMPLETE(pB, I2EE_GOOD);
  478. }
  479. //=======================================================
  480. // Delay Routines
  481. //
  482. // iiDelayIO
  483. // iiNop
  484. //=======================================================
  485. static void
  486. ii2DelayWakeup(unsigned long id)
  487. {
  488. wake_up_interruptible ( &pDelayWait );
  489. }
  490. //******************************************************************************
  491. // Function: ii2DelayTimer(mseconds)
  492. // Parameters: mseconds - number of milliseconds to delay
  493. //
  494. // Returns: Nothing
  495. //
  496. // Description:
  497. //
  498. // This routine delays for approximately mseconds milliseconds and is intended
  499. // to be called indirectly through i2Delay field in i2eBordStr. It uses the
  500. // Linux timer_list mechanism.
  501. //
  502. // The Linux timers use a unit called "jiffies" which are 10mS in the Intel
  503. // architecture. This function rounds the delay period up to the next "jiffy".
  504. // In the Alpha architecture the "jiffy" is 1mS, but this driver is not intended
  505. // for Alpha platforms at this time.
  506. //
  507. //******************************************************************************
  508. static void
  509. ii2DelayTimer(unsigned int mseconds)
  510. {
  511. wait_queue_t wait;
  512. init_waitqueue_entry(&wait, current);
  513. init_timer ( pDelayTimer );
  514. add_wait_queue(&pDelayWait, &wait);
  515. set_current_state( TASK_INTERRUPTIBLE );
  516. pDelayTimer->expires = jiffies + ( mseconds + 9 ) / 10;
  517. pDelayTimer->function = ii2DelayWakeup;
  518. pDelayTimer->data = 0;
  519. add_timer ( pDelayTimer );
  520. schedule();
  521. set_current_state( TASK_RUNNING );
  522. remove_wait_queue(&pDelayWait, &wait);
  523. del_timer ( pDelayTimer );
  524. }
  525. #if 0
  526. //static void ii2DelayIO(unsigned int);
  527. //******************************************************************************
  528. // !!! Not Used, this is DOS crap, some of you young folks may be interested in
  529. // in how things were done in the stone age of caculating machines !!!
  530. // Function: ii2DelayIO(mseconds)
  531. // Parameters: mseconds - number of milliseconds to delay
  532. //
  533. // Returns: Nothing
  534. //
  535. // Description:
  536. //
  537. // This routine delays for approximately mseconds milliseconds and is intended
  538. // to be called indirectly through i2Delay field in i2eBordStr. It is intended
  539. // for use where a clock-based function is impossible: for example, DOS drivers.
  540. //
  541. // This function uses the IN instruction to place bounds on the timing and
  542. // assumes that ii2Safe has been set. This is because I/O instructions are not
  543. // subject to caching and will therefore take a certain minimum time. To ensure
  544. // the delay is at least long enough on fast machines, it is based on some
  545. // fastest-case calculations. On slower machines this may cause VERY long
  546. // delays. (3 x fastest case). In the fastest case, everything is cached except
  547. // the I/O instruction itself.
  548. //
  549. // Timing calculations:
  550. // The fastest bus speed for I/O operations is likely to be 10 MHz. The I/O
  551. // operation in question is a byte operation to an odd address. For 8-bit
  552. // operations, the architecture generally enforces two wait states. At 10 MHz, a
  553. // single cycle time is 100nS. A read operation at two wait states takes 6
  554. // cycles for a total time of 600nS. Therefore approximately 1666 iterations
  555. // would be required to generate a single millisecond delay. The worst
  556. // (reasonable) case would be an 8MHz system with no cacheing. In this case, the
  557. // I/O instruction would take 125nS x 6 cyles = 750 nS. More importantly, code
  558. // fetch of other instructions in the loop would take time (zero wait states,
  559. // however) and would be hard to estimate. This is minimized by using in-line
  560. // assembler for the in inner loop of IN instructions. This consists of just a
  561. // few bytes. So we'll guess about four code fetches per loop. Each code fetch
  562. // should take four cycles, so we have 125nS * 8 = 1000nS. Worst case then is
  563. // that what should have taken 1 mS takes instead 1666 * (1750) = 2.9 mS.
  564. //
  565. // So much for theoretical timings: results using 1666 value on some actual
  566. // machines:
  567. // IBM 286 6MHz 3.15 mS
  568. // Zenith 386 33MHz 2.45 mS
  569. // (brandX) 386 33MHz 1.90 mS (has cache)
  570. // (brandY) 486 33MHz 2.35 mS
  571. // NCR 486 ?? 1.65 mS (microchannel)
  572. //
  573. // For most machines, it is probably safe to scale this number back (remember,
  574. // for robust operation use an actual timed delay if possible), so we are using
  575. // a value of 1190. This yields 1.17 mS for the fastest machine in our sample,
  576. // 1.75 mS for typical 386 machines, and 2.25 mS the absolute slowest machine.
  577. //
  578. // 1/29/93:
  579. // The above timings are too slow. Actual cycle times might be faster. ISA cycle
  580. // times could approach 500 nS, and ...
  581. // The IBM model 77 being microchannel has no wait states for 8-bit reads and
  582. // seems to be accessing the I/O at 440 nS per access (from start of one to
  583. // start of next). This would imply we need 1000/.440 = 2272 iterations to
  584. // guarantee we are fast enough. In actual testing, we see that 2 * 1190 are in
  585. // fact enough. For diagnostics, we keep the level at 1190, but developers note
  586. // this needs tuning.
  587. //
  588. // Safe assumption: 2270 i/o reads = 1 millisecond
  589. //
  590. //******************************************************************************
  591. static int ii2DelValue = 1190; // See timing calculations below
  592. // 1666 for fastest theoretical machine
  593. // 1190 safe for most fast 386 machines
  594. // 1000 for fastest machine tested here
  595. // 540 (sic) for AT286/6Mhz
  596. static void
  597. ii2DelayIO(unsigned int mseconds)
  598. {
  599. if (!ii2Safe)
  600. return; /* Do nothing if this variable uninitialized */
  601. while(mseconds--) {
  602. int i = ii2DelValue;
  603. while ( i-- ) {
  604. INB ( ii2Safe );
  605. }
  606. }
  607. }
  608. #endif
  609. //******************************************************************************
  610. // Function: ii2Nop()
  611. // Parameters: None
  612. //
  613. // Returns: Nothing
  614. //
  615. // Description:
  616. //
  617. // iiInitialize will set i2eDelay to this if the delay parameter is NULL. This
  618. // saves checking for a NULL pointer at every call.
  619. //******************************************************************************
  620. static void
  621. ii2Nop(void)
  622. {
  623. return; // no mystery here
  624. }
  625. //=======================================================
  626. // Routines which are available in 8/16-bit versions, or
  627. // in different fifo styles. These are ALL called
  628. // indirectly through the board structure.
  629. //=======================================================
  630. //******************************************************************************
  631. // Function: iiWriteBuf16(pB, address, count)
  632. // Parameters: pB - pointer to board structure
  633. // address - address of data to write
  634. // count - number of data bytes to write
  635. //
  636. // Returns: True if everything appears copacetic.
  637. // False if there is any error: the pB->i2eError field has the error
  638. //
  639. // Description:
  640. //
  641. // Writes 'count' bytes from 'address' to the data fifo specified by the board
  642. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  643. // sent (identity unknown...). Uses 16-bit (word) operations. Is called
  644. // indirectly through pB->i2eWriteBuf.
  645. //
  646. //******************************************************************************
  647. static int
  648. iiWriteBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
  649. {
  650. // Rudimentary sanity checking here.
  651. if (pB->i2eValid != I2E_MAGIC)
  652. COMPLETE(pB, I2EE_INVALID);
  653. OUTSW ( pB->i2eData, address, count);
  654. COMPLETE(pB, I2EE_GOOD);
  655. }
  656. //******************************************************************************
  657. // Function: iiWriteBuf8(pB, address, count)
  658. // Parameters: pB - pointer to board structure
  659. // address - address of data to write
  660. // count - number of data bytes to write
  661. //
  662. // Returns: True if everything appears copacetic.
  663. // False if there is any error: the pB->i2eError field has the error
  664. //
  665. // Description:
  666. //
  667. // Writes 'count' bytes from 'address' to the data fifo specified by the board
  668. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  669. // sent (identity unknown...). This is to be consistent with the 16-bit version.
  670. // Uses 8-bit (byte) operations. Is called indirectly through pB->i2eWriteBuf.
  671. //
  672. //******************************************************************************
  673. static int
  674. iiWriteBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
  675. {
  676. /* Rudimentary sanity checking here */
  677. if (pB->i2eValid != I2E_MAGIC)
  678. COMPLETE(pB, I2EE_INVALID);
  679. OUTSB ( pB->i2eData, address, count );
  680. COMPLETE(pB, I2EE_GOOD);
  681. }
  682. //******************************************************************************
  683. // Function: iiReadBuf16(pB, address, count)
  684. // Parameters: pB - pointer to board structure
  685. // address - address to put data read
  686. // count - number of data bytes to read
  687. //
  688. // Returns: True if everything appears copacetic.
  689. // False if there is any error: the pB->i2eError field has the error
  690. //
  691. // Description:
  692. //
  693. // Reads 'count' bytes into 'address' from the data fifo specified by the board
  694. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  695. // received (identity unknown...). Uses 16-bit (word) operations. Is called
  696. // indirectly through pB->i2eReadBuf.
  697. //
  698. //******************************************************************************
  699. static int
  700. iiReadBuf16(i2eBordStrPtr pB, unsigned char *address, int count)
  701. {
  702. // Rudimentary sanity checking here.
  703. if (pB->i2eValid != I2E_MAGIC)
  704. COMPLETE(pB, I2EE_INVALID);
  705. INSW ( pB->i2eData, address, count);
  706. COMPLETE(pB, I2EE_GOOD);
  707. }
  708. //******************************************************************************
  709. // Function: iiReadBuf8(pB, address, count)
  710. // Parameters: pB - pointer to board structure
  711. // address - address to put data read
  712. // count - number of data bytes to read
  713. //
  714. // Returns: True if everything appears copacetic.
  715. // False if there is any error: the pB->i2eError field has the error
  716. //
  717. // Description:
  718. //
  719. // Reads 'count' bytes into 'address' from the data fifo specified by the board
  720. // structure pointer pB. Should count happen to be odd, an extra pad byte is
  721. // received (identity unknown...). This to match the 16-bit behaviour. Uses
  722. // 8-bit (byte) operations. Is called indirectly through pB->i2eReadBuf.
  723. //
  724. //******************************************************************************
  725. static int
  726. iiReadBuf8(i2eBordStrPtr pB, unsigned char *address, int count)
  727. {
  728. // Rudimentary sanity checking here.
  729. if (pB->i2eValid != I2E_MAGIC)
  730. COMPLETE(pB, I2EE_INVALID);
  731. INSB ( pB->i2eData, address, count);
  732. COMPLETE(pB, I2EE_GOOD);
  733. }
  734. //******************************************************************************
  735. // Function: iiReadWord16(pB)
  736. // Parameters: pB - pointer to board structure
  737. //
  738. // Returns: True if everything appears copacetic.
  739. // False if there is any error: the pB->i2eError field has the error
  740. //
  741. // Description:
  742. //
  743. // Returns the word read from the data fifo specified by the board-structure
  744. // pointer pB. Uses a 16-bit operation. Is called indirectly through
  745. // pB->i2eReadWord.
  746. //
  747. //******************************************************************************
  748. static unsigned short
  749. iiReadWord16(i2eBordStrPtr pB)
  750. {
  751. return (unsigned short)( INW(pB->i2eData) );
  752. }
  753. //******************************************************************************
  754. // Function: iiReadWord8(pB)
  755. // Parameters: pB - pointer to board structure
  756. //
  757. // Returns: True if everything appears copacetic.
  758. // False if there is any error: the pB->i2eError field has the error
  759. //
  760. // Description:
  761. //
  762. // Returns the word read from the data fifo specified by the board-structure
  763. // pointer pB. Uses two 8-bit operations. Bytes are assumed to be LSB first. Is
  764. // called indirectly through pB->i2eReadWord.
  765. //
  766. //******************************************************************************
  767. static unsigned short
  768. iiReadWord8(i2eBordStrPtr pB)
  769. {
  770. unsigned short urs;
  771. urs = INB ( pB->i2eData );
  772. return ( ( INB ( pB->i2eData ) << 8 ) | urs );
  773. }
  774. //******************************************************************************
  775. // Function: iiWriteWord16(pB, value)
  776. // Parameters: pB - pointer to board structure
  777. // value - data to write
  778. //
  779. // Returns: True if everything appears copacetic.
  780. // False if there is any error: the pB->i2eError field has the error
  781. //
  782. // Description:
  783. //
  784. // Writes the word 'value' to the data fifo specified by the board-structure
  785. // pointer pB. Uses 16-bit operation. Is called indirectly through
  786. // pB->i2eWriteWord.
  787. //
  788. //******************************************************************************
  789. static void
  790. iiWriteWord16(i2eBordStrPtr pB, unsigned short value)
  791. {
  792. WORD_TO(pB, (int)value);
  793. }
  794. //******************************************************************************
  795. // Function: iiWriteWord8(pB, value)
  796. // Parameters: pB - pointer to board structure
  797. // value - data to write
  798. //
  799. // Returns: True if everything appears copacetic.
  800. // False if there is any error: the pB->i2eError field has the error
  801. //
  802. // Description:
  803. //
  804. // Writes the word 'value' to the data fifo specified by the board-structure
  805. // pointer pB. Uses two 8-bit operations (writes LSB first). Is called
  806. // indirectly through pB->i2eWriteWord.
  807. //
  808. //******************************************************************************
  809. static void
  810. iiWriteWord8(i2eBordStrPtr pB, unsigned short value)
  811. {
  812. BYTE_TO(pB, (char)value);
  813. BYTE_TO(pB, (char)(value >> 8) );
  814. }
  815. //******************************************************************************
  816. // Function: iiWaitForTxEmptyII(pB, mSdelay)
  817. // Parameters: pB - pointer to board structure
  818. // mSdelay - period to wait before returning
  819. //
  820. // Returns: True if the FIFO is empty.
  821. // False if it not empty in the required time: the pB->i2eError
  822. // field has the error.
  823. //
  824. // Description:
  825. //
  826. // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
  827. // not empty by the required time, returns false and error in pB->i2eError,
  828. // otherwise returns true.
  829. //
  830. // mSdelay == 0 is taken to mean must be empty on the first test.
  831. //
  832. // This version operates on IntelliPort-II - style FIFO's
  833. //
  834. // Note this routine is organized so that if status is ok there is no delay at
  835. // all called either before or after the test. Is called indirectly through
  836. // pB->i2eWaitForTxEmpty.
  837. //
  838. //******************************************************************************
  839. static int
  840. iiWaitForTxEmptyII(i2eBordStrPtr pB, int mSdelay)
  841. {
  842. unsigned long flags;
  843. int itemp;
  844. for (;;)
  845. {
  846. // This routine hinges on being able to see the "other" status register
  847. // (as seen by the local processor). His incoming fifo is our outgoing
  848. // FIFO.
  849. //
  850. // By the nature of this routine, you would be using this as part of a
  851. // larger atomic context: i.e., you would use this routine to ensure the
  852. // fifo empty, then act on this information. Between these two halves,
  853. // you will generally not want to service interrupts or in any way
  854. // disrupt the assumptions implicit in the larger context.
  855. //
  856. // Even worse, however, this routine "shifts" the status register to
  857. // point to the local status register which is not the usual situation.
  858. // Therefore for extra safety, we force the critical section to be
  859. // completely atomic, and pick up after ourselves before allowing any
  860. // interrupts of any kind.
  861. WRITE_LOCK_IRQSAVE(&Dl_spinlock,flags)
  862. OUTB(pB->i2ePointer, SEL_COMMAND);
  863. OUTB(pB->i2ePointer, SEL_CMD_SH);
  864. itemp = INB(pB->i2eStatus);
  865. OUTB(pB->i2ePointer, SEL_COMMAND);
  866. OUTB(pB->i2ePointer, SEL_CMD_UNSH);
  867. if (itemp & ST_IN_EMPTY)
  868. {
  869. UPDATE_FIFO_ROOM(pB);
  870. WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags)
  871. COMPLETE(pB, I2EE_GOOD);
  872. }
  873. WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags)
  874. if (mSdelay-- == 0)
  875. break;
  876. iiDelay(pB, 1); /* 1 mS granularity on checking condition */
  877. }
  878. COMPLETE(pB, I2EE_TXE_TIME);
  879. }
  880. //******************************************************************************
  881. // Function: iiWaitForTxEmptyIIEX(pB, mSdelay)
  882. // Parameters: pB - pointer to board structure
  883. // mSdelay - period to wait before returning
  884. //
  885. // Returns: True if the FIFO is empty.
  886. // False if it not empty in the required time: the pB->i2eError
  887. // field has the error.
  888. //
  889. // Description:
  890. //
  891. // Waits up to "mSdelay" milliseconds for the outgoing FIFO to become empty; if
  892. // not empty by the required time, returns false and error in pB->i2eError,
  893. // otherwise returns true.
  894. //
  895. // mSdelay == 0 is taken to mean must be empty on the first test.
  896. //
  897. // This version operates on IntelliPort-IIEX - style FIFO's
  898. //
  899. // Note this routine is organized so that if status is ok there is no delay at
  900. // all called either before or after the test. Is called indirectly through
  901. // pB->i2eWaitForTxEmpty.
  902. //
  903. //******************************************************************************
  904. static int
  905. iiWaitForTxEmptyIIEX(i2eBordStrPtr pB, int mSdelay)
  906. {
  907. unsigned long flags;
  908. for (;;)
  909. {
  910. // By the nature of this routine, you would be using this as part of a
  911. // larger atomic context: i.e., you would use this routine to ensure the
  912. // fifo empty, then act on this information. Between these two halves,
  913. // you will generally not want to service interrupts or in any way
  914. // disrupt the assumptions implicit in the larger context.
  915. WRITE_LOCK_IRQSAVE(&Dl_spinlock,flags)
  916. if (INB(pB->i2eStatus) & STE_OUT_MT) {
  917. UPDATE_FIFO_ROOM(pB);
  918. WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags)
  919. COMPLETE(pB, I2EE_GOOD);
  920. }
  921. WRITE_UNLOCK_IRQRESTORE(&Dl_spinlock,flags)
  922. if (mSdelay-- == 0)
  923. break;
  924. iiDelay(pB, 1); // 1 mS granularity on checking condition
  925. }
  926. COMPLETE(pB, I2EE_TXE_TIME);
  927. }
  928. //******************************************************************************
  929. // Function: iiTxMailEmptyII(pB)
  930. // Parameters: pB - pointer to board structure
  931. //
  932. // Returns: True if the transmit mailbox is empty.
  933. // False if it not empty.
  934. //
  935. // Description:
  936. //
  937. // Returns true or false according to whether the transmit mailbox is empty (and
  938. // therefore able to accept more mail)
  939. //
  940. // This version operates on IntelliPort-II - style FIFO's
  941. //
  942. //******************************************************************************
  943. static int
  944. iiTxMailEmptyII(i2eBordStrPtr pB)
  945. {
  946. int port = pB->i2ePointer;
  947. OUTB ( port, SEL_OUTMAIL );
  948. return ( INB(port) == 0 );
  949. }
  950. //******************************************************************************
  951. // Function: iiTxMailEmptyIIEX(pB)
  952. // Parameters: pB - pointer to board structure
  953. //
  954. // Returns: True if the transmit mailbox is empty.
  955. // False if it not empty.
  956. //
  957. // Description:
  958. //
  959. // Returns true or false according to whether the transmit mailbox is empty (and
  960. // therefore able to accept more mail)
  961. //
  962. // This version operates on IntelliPort-IIEX - style FIFO's
  963. //
  964. //******************************************************************************
  965. static int
  966. iiTxMailEmptyIIEX(i2eBordStrPtr pB)
  967. {
  968. return !(INB(pB->i2eStatus) & STE_OUT_MAIL);
  969. }
  970. //******************************************************************************
  971. // Function: iiTrySendMailII(pB,mail)
  972. // Parameters: pB - pointer to board structure
  973. // mail - value to write to mailbox
  974. //
  975. // Returns: True if the transmit mailbox is empty, and mail is sent.
  976. // False if it not empty.
  977. //
  978. // Description:
  979. //
  980. // If outgoing mailbox is empty, sends mail and returns true. If outgoing
  981. // mailbox is not empty, returns false.
  982. //
  983. // This version operates on IntelliPort-II - style FIFO's
  984. //
  985. //******************************************************************************
  986. static int
  987. iiTrySendMailII(i2eBordStrPtr pB, unsigned char mail)
  988. {
  989. int port = pB->i2ePointer;
  990. OUTB(port, SEL_OUTMAIL);
  991. if (INB(port) == 0) {
  992. OUTB(port, SEL_OUTMAIL);
  993. OUTB(port, mail);
  994. return 1;
  995. }
  996. return 0;
  997. }
  998. //******************************************************************************
  999. // Function: iiTrySendMailIIEX(pB,mail)
  1000. // Parameters: pB - pointer to board structure
  1001. // mail - value to write to mailbox
  1002. //
  1003. // Returns: True if the transmit mailbox is empty, and mail is sent.
  1004. // False if it not empty.
  1005. //
  1006. // Description:
  1007. //
  1008. // If outgoing mailbox is empty, sends mail and returns true. If outgoing
  1009. // mailbox is not empty, returns false.
  1010. //
  1011. // This version operates on IntelliPort-IIEX - style FIFO's
  1012. //
  1013. //******************************************************************************
  1014. static int
  1015. iiTrySendMailIIEX(i2eBordStrPtr pB, unsigned char mail)
  1016. {
  1017. if(INB(pB->i2eStatus) & STE_OUT_MAIL) {
  1018. return 0;
  1019. }
  1020. OUTB(pB->i2eXMail, mail);
  1021. return 1;
  1022. }
  1023. //******************************************************************************
  1024. // Function: iiGetMailII(pB,mail)
  1025. // Parameters: pB - pointer to board structure
  1026. //
  1027. // Returns: Mailbox data or NO_MAIL_HERE.
  1028. //
  1029. // Description:
  1030. //
  1031. // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
  1032. // the mailbox, which is guaranteed != NO_MAIL_HERE.
  1033. //
  1034. // This version operates on IntelliPort-II - style FIFO's
  1035. //
  1036. //******************************************************************************
  1037. static unsigned short
  1038. iiGetMailII(i2eBordStrPtr pB)
  1039. {
  1040. if (HAS_MAIL(pB)) {
  1041. OUTB(pB->i2ePointer, SEL_INMAIL);
  1042. return INB(pB->i2ePointer);
  1043. } else {
  1044. return NO_MAIL_HERE;
  1045. }
  1046. }
  1047. //******************************************************************************
  1048. // Function: iiGetMailIIEX(pB,mail)
  1049. // Parameters: pB - pointer to board structure
  1050. //
  1051. // Returns: Mailbox data or NO_MAIL_HERE.
  1052. //
  1053. // Description:
  1054. //
  1055. // If no mail available, returns NO_MAIL_HERE otherwise returns the data from
  1056. // the mailbox, which is guaranteed != NO_MAIL_HERE.
  1057. //
  1058. // This version operates on IntelliPort-IIEX - style FIFO's
  1059. //
  1060. //******************************************************************************
  1061. static unsigned short
  1062. iiGetMailIIEX(i2eBordStrPtr pB)
  1063. {
  1064. if (HAS_MAIL(pB)) {
  1065. return INB(pB->i2eXMail);
  1066. } else {
  1067. return NO_MAIL_HERE;
  1068. }
  1069. }
  1070. //******************************************************************************
  1071. // Function: iiEnableMailIrqII(pB)
  1072. // Parameters: pB - pointer to board structure
  1073. //
  1074. // Returns: Nothing
  1075. //
  1076. // Description:
  1077. //
  1078. // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
  1079. //
  1080. // This version operates on IntelliPort-II - style FIFO's
  1081. //
  1082. //******************************************************************************
  1083. static void
  1084. iiEnableMailIrqII(i2eBordStrPtr pB)
  1085. {
  1086. OUTB(pB->i2ePointer, SEL_MASK);
  1087. OUTB(pB->i2ePointer, ST_IN_MAIL);
  1088. }
  1089. //******************************************************************************
  1090. // Function: iiEnableMailIrqIIEX(pB)
  1091. // Parameters: pB - pointer to board structure
  1092. //
  1093. // Returns: Nothing
  1094. //
  1095. // Description:
  1096. //
  1097. // Enables board to interrupt host (only) by writing to host's in-bound mailbox.
  1098. //
  1099. // This version operates on IntelliPort-IIEX - style FIFO's
  1100. //
  1101. //******************************************************************************
  1102. static void
  1103. iiEnableMailIrqIIEX(i2eBordStrPtr pB)
  1104. {
  1105. OUTB(pB->i2eXMask, MX_IN_MAIL);
  1106. }
  1107. //******************************************************************************
  1108. // Function: iiWriteMaskII(pB)
  1109. // Parameters: pB - pointer to board structure
  1110. //
  1111. // Returns: Nothing
  1112. //
  1113. // Description:
  1114. //
  1115. // Writes arbitrary value to the mask register.
  1116. //
  1117. // This version operates on IntelliPort-II - style FIFO's
  1118. //
  1119. //******************************************************************************
  1120. static void
  1121. iiWriteMaskII(i2eBordStrPtr pB, unsigned char value)
  1122. {
  1123. OUTB(pB->i2ePointer, SEL_MASK);
  1124. OUTB(pB->i2ePointer, value);
  1125. }
  1126. //******************************************************************************
  1127. // Function: iiWriteMaskIIEX(pB)
  1128. // Parameters: pB - pointer to board structure
  1129. //
  1130. // Returns: Nothing
  1131. //
  1132. // Description:
  1133. //
  1134. // Writes arbitrary value to the mask register.
  1135. //
  1136. // This version operates on IntelliPort-IIEX - style FIFO's
  1137. //
  1138. //******************************************************************************
  1139. static void
  1140. iiWriteMaskIIEX(i2eBordStrPtr pB, unsigned char value)
  1141. {
  1142. OUTB(pB->i2eXMask, value);
  1143. }
  1144. //******************************************************************************
  1145. // Function: iiDownloadBlock(pB, pSource, isStandard)
  1146. // Parameters: pB - pointer to board structure
  1147. // pSource - loadware block to download
  1148. // isStandard - True if "standard" loadware, else false.
  1149. //
  1150. // Returns: Success or Failure
  1151. //
  1152. // Description:
  1153. //
  1154. // Downloads a single block (at pSource)to the board referenced by pB. Caller
  1155. // sets isStandard to true/false according to whether the "standard" loadware is
  1156. // what's being loaded. The normal process, then, is to perform an iiInitialize
  1157. // to the board, then perform some number of iiDownloadBlocks using the returned
  1158. // state to determine when download is complete.
  1159. //
  1160. // Possible return values: (see I2ELLIS.H)
  1161. // II_DOWN_BADVALID
  1162. // II_DOWN_BADFILE
  1163. // II_DOWN_CONTINUING
  1164. // II_DOWN_GOOD
  1165. // II_DOWN_BAD
  1166. // II_DOWN_BADSTATE
  1167. // II_DOWN_TIMEOUT
  1168. //
  1169. // Uses the i2eState and i2eToLoad fields (initialized at iiInitialize) to
  1170. // determine whether this is the first block, whether to check for magic
  1171. // numbers, how many blocks there are to go...
  1172. //
  1173. //******************************************************************************
  1174. static int
  1175. iiDownloadBlock ( i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard)
  1176. {
  1177. int itemp;
  1178. int loadedFirst;
  1179. if (pB->i2eValid != I2E_MAGIC) return II_DOWN_BADVALID;
  1180. switch(pB->i2eState)
  1181. {
  1182. case II_STATE_READY:
  1183. // Loading the first block after reset. Must check the magic number of the
  1184. // loadfile, store the number of blocks we expect to load.
  1185. if (pSource->e.loadMagic != MAGIC_LOADFILE)
  1186. {
  1187. return II_DOWN_BADFILE;
  1188. }
  1189. // Next we store the total number of blocks to load, including this one.
  1190. pB->i2eToLoad = 1 + pSource->e.loadBlocksMore;
  1191. // Set the state, store the version numbers. ('Cause this may have come
  1192. // from a file - we might want to report these versions and revisions in
  1193. // case of an error!
  1194. pB->i2eState = II_STATE_LOADING;
  1195. pB->i2eLVersion = pSource->e.loadVersion;
  1196. pB->i2eLRevision = pSource->e.loadRevision;
  1197. pB->i2eLSub = pSource->e.loadSubRevision;
  1198. // The time and date of compilation is also available but don't bother
  1199. // storing it for normal purposes.
  1200. loadedFirst = 1;
  1201. break;
  1202. case II_STATE_LOADING:
  1203. loadedFirst = 0;
  1204. break;
  1205. default:
  1206. return II_DOWN_BADSTATE;
  1207. }
  1208. // Now we must be in the II_STATE_LOADING state, and we assume i2eToLoad
  1209. // must be positive still, because otherwise we would have cleaned up last
  1210. // time and set the state to II_STATE_LOADED.
  1211. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
  1212. return II_DOWN_TIMEOUT;
  1213. }
  1214. if (!iiWriteBuf(pB, pSource->c, LOADWARE_BLOCK_SIZE)) {
  1215. return II_DOWN_BADVALID;
  1216. }
  1217. // If we just loaded the first block, wait for the fifo to empty an extra
  1218. // long time to allow for any special startup code in the firmware, like
  1219. // sending status messages to the LCD's.
  1220. if (loadedFirst) {
  1221. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_START_TIME)) {
  1222. return II_DOWN_TIMEOUT;
  1223. }
  1224. }
  1225. // Determine whether this was our last block!
  1226. if (--(pB->i2eToLoad)) {
  1227. return II_DOWN_CONTINUING; // more to come...
  1228. }
  1229. // It WAS our last block: Clean up operations...
  1230. // ...Wait for last buffer to drain from the board...
  1231. if (!iiWaitForTxEmpty(pB, MAX_DLOAD_READ_TIME)) {
  1232. return II_DOWN_TIMEOUT;
  1233. }
  1234. // If there were only a single block written, this would come back
  1235. // immediately and be harmless, though not strictly necessary.
  1236. itemp = MAX_DLOAD_ACK_TIME/10;
  1237. while (--itemp) {
  1238. if (HAS_INPUT(pB)) {
  1239. switch(BYTE_FROM(pB))
  1240. {
  1241. case LOADWARE_OK:
  1242. pB->i2eState =
  1243. isStandard ? II_STATE_STDLOADED :II_STATE_LOADED;
  1244. // Some revisions of the bootstrap firmware (e.g. ISA-8 1.0.2)
  1245. // will, // if there is a debug port attached, require some
  1246. // time to send information to the debug port now. It will do
  1247. // this before // executing any of the code we just downloaded.
  1248. // It may take up to 700 milliseconds.
  1249. if (pB->i2ePom.e.porDiag2 & POR_DEBUG_PORT) {
  1250. iiDelay(pB, 700);
  1251. }
  1252. return II_DOWN_GOOD;
  1253. case LOADWARE_BAD:
  1254. default:
  1255. return II_DOWN_BAD;
  1256. }
  1257. }
  1258. iiDelay(pB, 10); // 10 mS granularity on checking condition
  1259. }
  1260. // Drop-through --> timed out waiting for firmware confirmation
  1261. pB->i2eState = II_STATE_BADLOAD;
  1262. return II_DOWN_TIMEOUT;
  1263. }
  1264. //******************************************************************************
  1265. // Function: iiDownloadAll(pB, pSource, isStandard, size)
  1266. // Parameters: pB - pointer to board structure
  1267. // pSource - loadware block to download
  1268. // isStandard - True if "standard" loadware, else false.
  1269. // size - size of data to download (in bytes)
  1270. //
  1271. // Returns: Success or Failure
  1272. //
  1273. // Description:
  1274. //
  1275. // Given a pointer to a board structure, a pointer to the beginning of some
  1276. // loadware, whether it is considered the "standard loadware", and the size of
  1277. // the array in bytes loads the entire array to the board as loadware.
  1278. //
  1279. // Assumes the board has been freshly reset and the power-up reset message read.
  1280. // (i.e., in II_STATE_READY). Complains if state is bad, or if there seems to be
  1281. // too much or too little data to load, or if iiDownloadBlock complains.
  1282. //******************************************************************************
  1283. static int
  1284. iiDownloadAll(i2eBordStrPtr pB, loadHdrStrPtr pSource, int isStandard, int size)
  1285. {
  1286. int status;
  1287. // We know (from context) board should be ready for the first block of
  1288. // download. Complain if not.
  1289. if (pB->i2eState != II_STATE_READY) return II_DOWN_BADSTATE;
  1290. while (size > 0) {
  1291. size -= LOADWARE_BLOCK_SIZE; // How much data should there be left to
  1292. // load after the following operation ?
  1293. // Note we just bump pSource by "one", because its size is actually that
  1294. // of an entire block, same as LOADWARE_BLOCK_SIZE.
  1295. status = iiDownloadBlock(pB, pSource++, isStandard);
  1296. switch(status)
  1297. {
  1298. case II_DOWN_GOOD:
  1299. return ( (size > 0) ? II_DOWN_OVER : II_DOWN_GOOD);
  1300. case II_DOWN_CONTINUING:
  1301. break;
  1302. default:
  1303. return status;
  1304. }
  1305. }
  1306. // We shouldn't drop out: it means "while" caught us with nothing left to
  1307. // download, yet the previous DownloadBlock did not return complete. Ergo,
  1308. // not enough data to match the size byte in the header.
  1309. return II_DOWN_UNDER;
  1310. }