i2ellis.c 46 KB

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