aic79xx.seq 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291
  1. /*
  2. * Adaptec U320 device driver firmware for Linux and FreeBSD.
  3. *
  4. * Copyright (c) 1994-2001, 2004 Justin T. Gibbs.
  5. * Copyright (c) 2000-2002 Adaptec Inc.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions, and the following disclaimer,
  13. * without modification.
  14. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  15. * substantially similar to the "NO WARRANTY" disclaimer below
  16. * ("Disclaimer") and any redistribution must be conditioned upon
  17. * including a substantially similar Disclaimer requirement for further
  18. * binary redistribution.
  19. * 3. Neither the names of the above-listed copyright holders nor the names
  20. * of any contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * Alternatively, this software may be distributed under the terms of the
  24. * GNU General Public License ("GPL") version 2 as published by the Free
  25. * Software Foundation.
  26. *
  27. * NO WARRANTY
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  37. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGES.
  39. *
  40. * $FreeBSD$
  41. */
  42. VERSION = "$Id: //depot/aic7xxx/aic7xxx/aic79xx.seq#120 $"
  43. PATCH_ARG_LIST = "struct ahd_softc *ahd"
  44. PREFIX = "ahd_"
  45. #include "aic79xx.reg"
  46. #include "scsi_message.h"
  47. restart:
  48. if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
  49. test SEQINTCODE, 0xFF jz idle_loop;
  50. SET_SEQINTCODE(NO_SEQINT)
  51. }
  52. idle_loop:
  53. if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
  54. /*
  55. * Convert ERROR status into a sequencer
  56. * interrupt to handle the case of an
  57. * interrupt collision on the hardware
  58. * setting of HWERR.
  59. */
  60. test ERROR, 0xFF jz no_error_set;
  61. SET_SEQINTCODE(SAW_HWERR)
  62. no_error_set:
  63. }
  64. SET_MODE(M_SCSI, M_SCSI)
  65. test SCSISEQ0, ENSELO|ENARBO jnz idle_loop_checkbus;
  66. test SEQ_FLAGS2, SELECTOUT_QFROZEN jz check_waiting_list;
  67. /*
  68. * If the kernel has caught up with us, thaw the queue.
  69. */
  70. mov A, KERNEL_QFREEZE_COUNT;
  71. cmp QFREEZE_COUNT, A jne check_frozen_completions;
  72. mov A, KERNEL_QFREEZE_COUNT[1];
  73. cmp QFREEZE_COUNT[1], A jne check_frozen_completions;
  74. and SEQ_FLAGS2, ~SELECTOUT_QFROZEN;
  75. jmp check_waiting_list;
  76. check_frozen_completions:
  77. test SSTAT0, SELDO|SELINGO jnz idle_loop_checkbus;
  78. BEGIN_CRITICAL;
  79. /*
  80. * If we have completions stalled waiting for the qfreeze
  81. * to take effect, move them over to the complete_scb list
  82. * now that no selections are pending.
  83. */
  84. cmp COMPLETE_ON_QFREEZE_HEAD[1],SCB_LIST_NULL je idle_loop_checkbus;
  85. /*
  86. * Find the end of the qfreeze list. The first element has
  87. * to be treated specially.
  88. */
  89. bmov SCBPTR, COMPLETE_ON_QFREEZE_HEAD, 2;
  90. cmp SCB_NEXT_COMPLETE[1], SCB_LIST_NULL je join_lists;
  91. /*
  92. * Now the normal loop.
  93. */
  94. bmov SCBPTR, SCB_NEXT_COMPLETE, 2;
  95. cmp SCB_NEXT_COMPLETE[1], SCB_LIST_NULL jne . - 1;
  96. join_lists:
  97. bmov SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
  98. bmov COMPLETE_SCB_HEAD, COMPLETE_ON_QFREEZE_HEAD, 2;
  99. mvi COMPLETE_ON_QFREEZE_HEAD[1], SCB_LIST_NULL;
  100. jmp idle_loop_checkbus;
  101. check_waiting_list:
  102. cmp WAITING_TID_HEAD[1], SCB_LIST_NULL je idle_loop_checkbus;
  103. /*
  104. * ENSELO is cleared by a SELDO, so we must test for SELDO
  105. * one last time.
  106. */
  107. test SSTAT0, SELDO jnz select_out;
  108. call start_selection;
  109. idle_loop_checkbus:
  110. test SSTAT0, SELDO jnz select_out;
  111. END_CRITICAL;
  112. test SSTAT0, SELDI jnz select_in;
  113. test SCSIPHASE, ~DATA_PHASE_MASK jz idle_loop_check_nonpackreq;
  114. test SCSISIGO, ATNO jz idle_loop_check_nonpackreq;
  115. call unexpected_nonpkt_phase_find_ctxt;
  116. idle_loop_check_nonpackreq:
  117. test SSTAT2, NONPACKREQ jz . + 2;
  118. call unexpected_nonpkt_phase_find_ctxt;
  119. if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
  120. /*
  121. * On Rev A. hardware, the busy LED is only
  122. * turned on automaically during selections
  123. * and re-selections. Make the LED status
  124. * more useful by forcing it to be on so
  125. * long as one of our data FIFOs is active.
  126. */
  127. and A, FIFO0FREE|FIFO1FREE, DFFSTAT;
  128. cmp A, FIFO0FREE|FIFO1FREE jne . + 3;
  129. and SBLKCTL, ~DIAGLEDEN|DIAGLEDON;
  130. jmp . + 2;
  131. or SBLKCTL, DIAGLEDEN|DIAGLEDON;
  132. }
  133. call idle_loop_gsfifo_in_scsi_mode;
  134. call idle_loop_service_fifos;
  135. call idle_loop_cchan;
  136. jmp idle_loop;
  137. idle_loop_gsfifo:
  138. SET_MODE(M_SCSI, M_SCSI)
  139. BEGIN_CRITICAL;
  140. idle_loop_gsfifo_in_scsi_mode:
  141. test LQISTAT2, LQIGSAVAIL jz return;
  142. /*
  143. * We have received good status for this transaction. There may
  144. * still be data in our FIFOs draining to the host. Complete
  145. * the SCB only if all data has transferred to the host.
  146. */
  147. good_status_IU_done:
  148. bmov SCBPTR, GSFIFO, 2;
  149. clr SCB_SCSI_STATUS;
  150. /*
  151. * If a command completed before an attempted task management
  152. * function completed, notify the host after disabling any
  153. * pending select-outs.
  154. */
  155. test SCB_TASK_MANAGEMENT, 0xFF jz gsfifo_complete_normally;
  156. test SSTAT0, SELDO|SELINGO jnz . + 2;
  157. and SCSISEQ0, ~ENSELO;
  158. SET_SEQINTCODE(TASKMGMT_CMD_CMPLT_OKAY)
  159. gsfifo_complete_normally:
  160. or SCB_CONTROL, STATUS_RCVD;
  161. /*
  162. * Since this status did not consume a FIFO, we have to
  163. * be a bit more dilligent in how we check for FIFOs pertaining
  164. * to this transaction. There are two states that a FIFO still
  165. * transferring data may be in.
  166. *
  167. * 1) Configured and draining to the host, with a FIFO handler.
  168. * 2) Pending cfg4data, fifo not empty.
  169. *
  170. * Case 1 can be detected by noticing a non-zero FIFO active
  171. * count in the SCB. In this case, we allow the routine servicing
  172. * the FIFO to complete the SCB.
  173. *
  174. * Case 2 implies either a pending or yet to occur save data
  175. * pointers for this same context in the other FIFO. So, if
  176. * we detect case 1, we will properly defer the post of the SCB
  177. * and achieve the desired result. The pending cfg4data will
  178. * notice that status has been received and complete the SCB.
  179. */
  180. test SCB_FIFO_USE_COUNT, 0xFF jnz idle_loop_gsfifo_in_scsi_mode;
  181. call complete;
  182. END_CRITICAL;
  183. jmp idle_loop_gsfifo_in_scsi_mode;
  184. idle_loop_service_fifos:
  185. SET_MODE(M_DFF0, M_DFF0)
  186. BEGIN_CRITICAL;
  187. test LONGJMP_ADDR[1], INVALID_ADDR jnz idle_loop_next_fifo;
  188. call longjmp;
  189. END_CRITICAL;
  190. idle_loop_next_fifo:
  191. SET_MODE(M_DFF1, M_DFF1)
  192. BEGIN_CRITICAL;
  193. test LONGJMP_ADDR[1], INVALID_ADDR jz longjmp;
  194. END_CRITICAL;
  195. return:
  196. ret;
  197. idle_loop_cchan:
  198. SET_MODE(M_CCHAN, M_CCHAN)
  199. test QOFF_CTLSTA, HS_MAILBOX_ACT jz hs_mailbox_empty;
  200. or QOFF_CTLSTA, HS_MAILBOX_ACT;
  201. mov LOCAL_HS_MAILBOX, HS_MAILBOX;
  202. hs_mailbox_empty:
  203. BEGIN_CRITICAL;
  204. test CCSCBCTL, CCARREN|CCSCBEN jz scbdma_idle;
  205. test CCSCBCTL, CCSCBDIR jnz fetch_new_scb_inprog;
  206. test CCSCBCTL, CCSCBDONE jz return;
  207. /* FALLTHROUGH */
  208. scbdma_tohost_done:
  209. test CCSCBCTL, CCARREN jz fill_qoutfifo_dmadone;
  210. /*
  211. * An SCB has been successfully uploaded to the host.
  212. * If the SCB was uploaded for some reason other than
  213. * bad SCSI status (currently only for underruns), we
  214. * queue the SCB for normal completion. Otherwise, we
  215. * wait until any select-out activity has halted, and
  216. * then queue the completion.
  217. */
  218. and CCSCBCTL, ~(CCARREN|CCSCBEN);
  219. bmov COMPLETE_DMA_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
  220. cmp SCB_NEXT_COMPLETE[1], SCB_LIST_NULL jne . + 2;
  221. mvi COMPLETE_DMA_SCB_TAIL[1], SCB_LIST_NULL;
  222. test SCB_SCSI_STATUS, 0xff jz scbdma_queue_completion;
  223. bmov SCB_NEXT_COMPLETE, COMPLETE_ON_QFREEZE_HEAD, 2;
  224. bmov COMPLETE_ON_QFREEZE_HEAD, SCBPTR, 2 ret;
  225. scbdma_queue_completion:
  226. bmov SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
  227. bmov COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
  228. fill_qoutfifo_dmadone:
  229. and CCSCBCTL, ~(CCARREN|CCSCBEN);
  230. call qoutfifo_updated;
  231. mvi COMPLETE_SCB_DMAINPROG_HEAD[1], SCB_LIST_NULL;
  232. bmov QOUTFIFO_NEXT_ADDR, SCBHADDR, 4;
  233. test QOFF_CTLSTA, SDSCB_ROLLOVR jz return;
  234. bmov QOUTFIFO_NEXT_ADDR, SHARED_DATA_ADDR, 4;
  235. xor QOUTFIFO_ENTRY_VALID_TAG, QOUTFIFO_ENTRY_VALID_TOGGLE ret;
  236. END_CRITICAL;
  237. qoutfifo_updated:
  238. /*
  239. * If there are more commands waiting to be dma'ed
  240. * to the host, always coalesce. Otherwise honor the
  241. * host's wishes.
  242. */
  243. cmp COMPLETE_DMA_SCB_HEAD[1], SCB_LIST_NULL jne coalesce_by_count;
  244. cmp COMPLETE_SCB_HEAD[1], SCB_LIST_NULL jne coalesce_by_count;
  245. test LOCAL_HS_MAILBOX, ENINT_COALESCE jz issue_cmdcmplt;
  246. /*
  247. * If we have relatively few commands outstanding, don't
  248. * bother waiting for another command to complete.
  249. */
  250. test CMDS_PENDING[1], 0xFF jnz coalesce_by_count;
  251. /* Add -1 so that jnc means <= not just < */
  252. add A, -1, INT_COALESCING_MINCMDS;
  253. add NONE, A, CMDS_PENDING;
  254. jnc issue_cmdcmplt;
  255. /*
  256. * If coalescing, only coalesce up to the limit
  257. * provided by the host driver.
  258. */
  259. coalesce_by_count:
  260. mov A, INT_COALESCING_MAXCMDS;
  261. add NONE, A, INT_COALESCING_CMDCOUNT;
  262. jc issue_cmdcmplt;
  263. /*
  264. * If the timer is not currently active,
  265. * fire it up.
  266. */
  267. test INTCTL, SWTMINTMASK jz return;
  268. bmov SWTIMER, INT_COALESCING_TIMER, 2;
  269. mvi CLRSEQINTSTAT, CLRSEQ_SWTMRTO;
  270. or INTCTL, SWTMINTEN|SWTIMER_START;
  271. and INTCTL, ~SWTMINTMASK ret;
  272. issue_cmdcmplt:
  273. mvi INTSTAT, CMDCMPLT;
  274. clr INT_COALESCING_CMDCOUNT;
  275. or INTCTL, SWTMINTMASK ret;
  276. BEGIN_CRITICAL;
  277. fetch_new_scb_inprog:
  278. test CCSCBCTL, ARRDONE jz return;
  279. fetch_new_scb_done:
  280. and CCSCBCTL, ~(CCARREN|CCSCBEN);
  281. clr A;
  282. add CMDS_PENDING, 1;
  283. adc CMDS_PENDING[1], A;
  284. if ((ahd->bugs & AHD_PKT_LUN_BUG) != 0) {
  285. /*
  286. * "Short Luns" are not placed into outgoing LQ
  287. * packets in the correct byte order. Use a full
  288. * sized lun field instead and fill it with the
  289. * one byte of lun information we support.
  290. */
  291. mov SCB_PKT_LUN[6], SCB_LUN;
  292. }
  293. /*
  294. * The FIFO use count field is shared with the
  295. * tag set by the host so that our SCB dma engine
  296. * knows the correct location to store the SCB.
  297. * Set it to zero before processing the SCB.
  298. */
  299. clr SCB_FIFO_USE_COUNT;
  300. /* Update the next SCB address to download. */
  301. bmov NEXT_QUEUED_SCB_ADDR, SCB_NEXT_SCB_BUSADDR, 4;
  302. /*
  303. * NULL out the SCB links since these fields
  304. * occupy the same location as SCB_NEXT_SCB_BUSADDR.
  305. */
  306. mvi SCB_NEXT[1], SCB_LIST_NULL;
  307. mvi SCB_NEXT2[1], SCB_LIST_NULL;
  308. /* Increment our position in the QINFIFO. */
  309. mov NONE, SNSCB_QOFF;
  310. /*
  311. * Save SCBID of this SCB in REG0 since
  312. * SCBPTR will be clobbered during target
  313. * list updates. We also record the SCB's
  314. * flags so that we can refer to them even
  315. * after SCBPTR has been changed.
  316. */
  317. bmov REG0, SCBPTR, 2;
  318. mov A, SCB_CONTROL;
  319. /*
  320. * Find the tail SCB of the execution queue
  321. * for this target.
  322. */
  323. shr SINDEX, 3, SCB_SCSIID;
  324. and SINDEX, ~0x1;
  325. mvi SINDEX[1], (WAITING_SCB_TAILS >> 8);
  326. bmov DINDEX, SINDEX, 2;
  327. bmov SCBPTR, SINDIR, 2;
  328. /*
  329. * Update the tail to point to the new SCB.
  330. */
  331. bmov DINDIR, REG0, 2;
  332. /*
  333. * If the queue was empty, queue this SCB as
  334. * the first for this target.
  335. */
  336. cmp SCBPTR[1], SCB_LIST_NULL je first_new_target_scb;
  337. /*
  338. * SCBs that want to send messages must always be
  339. * at the head of their per-target queue so that
  340. * ATN can be asserted even if the current
  341. * negotiation agreement is packetized. If the
  342. * target queue is empty, the SCB can be queued
  343. * immediately. If the queue is not empty, we must
  344. * wait for it to empty before entering this SCB
  345. * into the waiting for selection queue. Otherwise
  346. * our batching and round-robin selection scheme
  347. * could allow commands to be queued out of order.
  348. * To simplify the implementation, we stop pulling
  349. * new commands from the host until the MK_MESSAGE
  350. * SCB can be queued to the waiting for selection
  351. * list.
  352. */
  353. test A, MK_MESSAGE jz batch_scb;
  354. /*
  355. * If the last SCB is also a MK_MESSAGE SCB, then
  356. * order is preserved even if we batch.
  357. */
  358. test SCB_CONTROL, MK_MESSAGE jz batch_scb;
  359. /*
  360. * Defer this SCB and stop fetching new SCBs until
  361. * it can be queued. Since the SCB_SCSIID of the
  362. * tail SCB must be the same as that of the newly
  363. * queued SCB, there is no need to restore the SCBID
  364. * here.
  365. */
  366. or SEQ_FLAGS2, PENDING_MK_MESSAGE;
  367. bmov MK_MESSAGE_SCB, REG0, 2;
  368. mov MK_MESSAGE_SCSIID, SCB_SCSIID ret;
  369. batch_scb:
  370. /*
  371. * Otherwise just update the previous tail SCB to
  372. * point to the new tail.
  373. */
  374. bmov SCB_NEXT, REG0, 2 ret;
  375. first_new_target_scb:
  376. /*
  377. * Append SCB to the tail of the waiting for
  378. * selection list.
  379. */
  380. cmp WAITING_TID_HEAD[1], SCB_LIST_NULL je first_new_scb;
  381. bmov SCBPTR, WAITING_TID_TAIL, 2;
  382. bmov SCB_NEXT2, REG0, 2;
  383. bmov WAITING_TID_TAIL, REG0, 2 ret;
  384. first_new_scb:
  385. /*
  386. * Whole list is empty, so the head of
  387. * the list must be initialized too.
  388. */
  389. bmov WAITING_TID_HEAD, REG0, 2;
  390. bmov WAITING_TID_TAIL, REG0, 2 ret;
  391. END_CRITICAL;
  392. scbdma_idle:
  393. /*
  394. * Don't bother downloading new SCBs to execute
  395. * if select-outs are currently frozen or we have
  396. * a MK_MESSAGE SCB waiting to enter the queue.
  397. */
  398. test SEQ_FLAGS2, SELECTOUT_QFROZEN|PENDING_MK_MESSAGE
  399. jnz scbdma_no_new_scbs;
  400. BEGIN_CRITICAL;
  401. test QOFF_CTLSTA, NEW_SCB_AVAIL jnz fetch_new_scb;
  402. scbdma_no_new_scbs:
  403. cmp COMPLETE_DMA_SCB_HEAD[1], SCB_LIST_NULL jne dma_complete_scb;
  404. cmp COMPLETE_SCB_HEAD[1], SCB_LIST_NULL je return;
  405. /* FALLTHROUGH */
  406. fill_qoutfifo:
  407. /*
  408. * Keep track of the SCBs we are dmaing just
  409. * in case the DMA fails or is aborted.
  410. */
  411. bmov COMPLETE_SCB_DMAINPROG_HEAD, COMPLETE_SCB_HEAD, 2;
  412. mvi CCSCBCTL, CCSCBRESET;
  413. bmov SCBHADDR, QOUTFIFO_NEXT_ADDR, 4;
  414. mov A, QOUTFIFO_NEXT_ADDR;
  415. bmov SCBPTR, COMPLETE_SCB_HEAD, 2;
  416. fill_qoutfifo_loop:
  417. bmov CCSCBRAM, SCBPTR, 2;
  418. mov CCSCBRAM, SCB_SGPTR[0];
  419. mov CCSCBRAM, QOUTFIFO_ENTRY_VALID_TAG;
  420. mov NONE, SDSCB_QOFF;
  421. inc INT_COALESCING_CMDCOUNT;
  422. add CMDS_PENDING, -1;
  423. adc CMDS_PENDING[1], -1;
  424. cmp SCB_NEXT_COMPLETE[1], SCB_LIST_NULL je fill_qoutfifo_done;
  425. cmp CCSCBADDR, CCSCBADDR_MAX je fill_qoutfifo_done;
  426. test QOFF_CTLSTA, SDSCB_ROLLOVR jnz fill_qoutfifo_done;
  427. /*
  428. * Don't cross an ADB or Cachline boundary when DMA'ing
  429. * completion entries. In PCI mode, at least in 32/33
  430. * configurations, the SCB DMA engine may lose its place
  431. * in the data-stream should the target force a retry on
  432. * something other than an 8byte aligned boundary. In
  433. * PCI-X mode, we do this to avoid split transactions since
  434. * many chipsets seem to be unable to format proper split
  435. * completions to continue the data transfer.
  436. */
  437. add SINDEX, A, CCSCBADDR;
  438. test SINDEX, CACHELINE_MASK jz fill_qoutfifo_done;
  439. bmov SCBPTR, SCB_NEXT_COMPLETE, 2;
  440. jmp fill_qoutfifo_loop;
  441. fill_qoutfifo_done:
  442. mov SCBHCNT, CCSCBADDR;
  443. mvi CCSCBCTL, CCSCBEN|CCSCBRESET;
  444. bmov COMPLETE_SCB_HEAD, SCB_NEXT_COMPLETE, 2;
  445. mvi SCB_NEXT_COMPLETE[1], SCB_LIST_NULL ret;
  446. fetch_new_scb:
  447. bmov SCBHADDR, NEXT_QUEUED_SCB_ADDR, 4;
  448. mvi CCARREN|CCSCBEN|CCSCBDIR|CCSCBRESET jmp dma_scb;
  449. dma_complete_scb:
  450. bmov SCBPTR, COMPLETE_DMA_SCB_HEAD, 2;
  451. bmov SCBHADDR, SCB_BUSADDR, 4;
  452. mvi CCARREN|CCSCBEN|CCSCBRESET jmp dma_scb;
  453. /*
  454. * Either post or fetch an SCB from host memory. The caller
  455. * is responsible for polling for transfer completion.
  456. *
  457. * Prerequisits: Mode == M_CCHAN
  458. * SINDEX contains CCSCBCTL flags
  459. * SCBHADDR set to Host SCB address
  460. * SCBPTR set to SCB src location on "push" operations
  461. */
  462. SET_SRC_MODE M_CCHAN;
  463. SET_DST_MODE M_CCHAN;
  464. dma_scb:
  465. mvi SCBHCNT, SCB_TRANSFER_SIZE;
  466. mov CCSCBCTL, SINDEX ret;
  467. setjmp:
  468. /*
  469. * At least on the A, a return in the same
  470. * instruction as the bmov results in a return
  471. * to the caller, not to the new address at the
  472. * top of the stack. Since we want the latter
  473. * (we use setjmp to register a handler from an
  474. * interrupt context but not invoke that handler
  475. * until we return to our idle loop), use a
  476. * separate ret instruction.
  477. */
  478. bmov LONGJMP_ADDR, STACK, 2;
  479. ret;
  480. setjmp_inline:
  481. bmov LONGJMP_ADDR, STACK, 2;
  482. longjmp:
  483. bmov STACK, LONGJMP_ADDR, 2 ret;
  484. END_CRITICAL;
  485. /*************************** Chip Bug Work Arounds ****************************/
  486. /*
  487. * Must disable interrupts when setting the mode pointer
  488. * register as an interrupt occurring mid update will
  489. * fail to store the new mode value for restoration on
  490. * an iret.
  491. */
  492. if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {
  493. set_mode_work_around:
  494. mvi SEQINTCTL, INTVEC1DSL;
  495. mov MODE_PTR, SINDEX;
  496. clr SEQINTCTL ret;
  497. }
  498. if ((ahd->bugs & AHD_INTCOLLISION_BUG) != 0) {
  499. set_seqint_work_around:
  500. mov SEQINTCODE, SINDEX;
  501. mvi SEQINTCODE, NO_SEQINT ret;
  502. }
  503. /************************ Packetized LongJmp Routines *************************/
  504. SET_SRC_MODE M_SCSI;
  505. SET_DST_MODE M_SCSI;
  506. start_selection:
  507. BEGIN_CRITICAL;
  508. if ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0) {
  509. /*
  510. * Razor #494
  511. * Rev A hardware fails to update LAST/CURR/NEXTSCB
  512. * correctly after a packetized selection in several
  513. * situations:
  514. *
  515. * 1) If only one command existed in the queue, the
  516. * LAST/CURR/NEXTSCB are unchanged.
  517. *
  518. * 2) In a non QAS, protocol allowed phase change,
  519. * the queue is shifted 1 too far. LASTSCB is
  520. * the last SCB that was correctly processed.
  521. *
  522. * 3) In the QAS case, if the full list of commands
  523. * was successfully sent, NEXTSCB is NULL and neither
  524. * CURRSCB nor LASTSCB can be trusted. We must
  525. * manually walk the list counting MAXCMDCNT elements
  526. * to find the last SCB that was sent correctly.
  527. *
  528. * To simplify the workaround for this bug in SELDO
  529. * handling, we initialize LASTSCB prior to enabling
  530. * selection so we can rely on it even for case #1 above.
  531. */
  532. bmov LASTSCB, WAITING_TID_HEAD, 2;
  533. }
  534. bmov CURRSCB, WAITING_TID_HEAD, 2;
  535. bmov SCBPTR, WAITING_TID_HEAD, 2;
  536. shr SELOID, 4, SCB_SCSIID;
  537. /*
  538. * If we want to send a message to the device, ensure
  539. * we are selecting with atn regardless of our packetized
  540. * agreement. Since SPI4 only allows target reset or PPR
  541. * messages if this is a packetized connection, the change
  542. * to our negotiation table entry for this selection will
  543. * be cleared when the message is acted on.
  544. */
  545. test SCB_CONTROL, MK_MESSAGE jz . + 3;
  546. mov NEGOADDR, SELOID;
  547. or NEGCONOPTS, ENAUTOATNO;
  548. or SCSISEQ0, ENSELO ret;
  549. END_CRITICAL;
  550. /*
  551. * Allocate a FIFO for a non-packetized transaction.
  552. * In RevA hardware, both FIFOs must be free before we
  553. * can allocate a FIFO for a non-packetized transaction.
  554. */
  555. allocate_fifo_loop:
  556. /*
  557. * Do whatever work is required to free a FIFO.
  558. */
  559. call idle_loop_service_fifos;
  560. SET_MODE(M_SCSI, M_SCSI)
  561. allocate_fifo:
  562. if ((ahd->bugs & AHD_NONPACKFIFO_BUG) != 0) {
  563. and A, FIFO0FREE|FIFO1FREE, DFFSTAT;
  564. cmp A, FIFO0FREE|FIFO1FREE jne allocate_fifo_loop;
  565. } else {
  566. test DFFSTAT, FIFO1FREE jnz allocate_fifo1;
  567. test DFFSTAT, FIFO0FREE jz allocate_fifo_loop;
  568. mvi DFFSTAT, B_CURRFIFO_0;
  569. SET_MODE(M_DFF0, M_DFF0)
  570. bmov SCBPTR, ALLOCFIFO_SCBPTR, 2 ret;
  571. }
  572. SET_SRC_MODE M_SCSI;
  573. SET_DST_MODE M_SCSI;
  574. allocate_fifo1:
  575. mvi DFFSTAT, CURRFIFO_1;
  576. SET_MODE(M_DFF1, M_DFF1)
  577. bmov SCBPTR, ALLOCFIFO_SCBPTR, 2 ret;
  578. /*
  579. * We have been reselected as an initiator
  580. * or selected as a target.
  581. */
  582. SET_SRC_MODE M_SCSI;
  583. SET_DST_MODE M_SCSI;
  584. select_in:
  585. if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
  586. /*
  587. * On Rev A. hardware, the busy LED is only
  588. * turned on automaically during selections
  589. * and re-selections. Make the LED status
  590. * more useful by forcing it to be on from
  591. * the point of selection until our idle
  592. * loop determines that neither of our FIFOs
  593. * are busy. This handles the non-packetized
  594. * case nicely as we will not return to the
  595. * idle loop until the busfree at the end of
  596. * each transaction.
  597. */
  598. or SBLKCTL, DIAGLEDEN|DIAGLEDON;
  599. }
  600. if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
  601. /*
  602. * Test to ensure that the bus has not
  603. * already gone free prior to clearing
  604. * any stale busfree status. This avoids
  605. * a window whereby a busfree just after
  606. * a selection could be missed.
  607. */
  608. test SCSISIGI, BSYI jz . + 2;
  609. mvi CLRSINT1,CLRBUSFREE;
  610. or SIMODE1, ENBUSFREE;
  611. }
  612. or SXFRCTL0, SPIOEN;
  613. and SAVED_SCSIID, SELID_MASK, SELID;
  614. and A, OID, IOWNID;
  615. or SAVED_SCSIID, A;
  616. mvi CLRSINT0, CLRSELDI;
  617. jmp ITloop;
  618. /*
  619. * We have successfully selected out.
  620. *
  621. * Clear SELDO.
  622. * Dequeue all SCBs sent from the waiting queue
  623. * Requeue all SCBs *not* sent to the tail of the waiting queue
  624. * Take Razor #494 into account for above.
  625. *
  626. * In Packetized Mode:
  627. * Return to the idle loop. Our interrupt handler will take
  628. * care of any incoming L_Qs.
  629. *
  630. * In Non-Packetize Mode:
  631. * Continue to our normal state machine.
  632. */
  633. SET_SRC_MODE M_SCSI;
  634. SET_DST_MODE M_SCSI;
  635. select_out:
  636. BEGIN_CRITICAL;
  637. if ((ahd->bugs & AHD_FAINT_LED_BUG) != 0) {
  638. /*
  639. * On Rev A. hardware, the busy LED is only
  640. * turned on automaically during selections
  641. * and re-selections. Make the LED status
  642. * more useful by forcing it to be on from
  643. * the point of re-selection until our idle
  644. * loop determines that neither of our FIFOs
  645. * are busy. This handles the non-packetized
  646. * case nicely as we will not return to the
  647. * idle loop until the busfree at the end of
  648. * each transaction.
  649. */
  650. or SBLKCTL, DIAGLEDEN|DIAGLEDON;
  651. }
  652. /* Clear out all SCBs that have been successfully sent. */
  653. if ((ahd->bugs & AHD_SENT_SCB_UPDATE_BUG) != 0) {
  654. /*
  655. * For packetized, the LQO manager clears ENSELO on
  656. * the assertion of SELDO. If we are non-packetized,
  657. * LASTSCB and CURRSCB are accurate.
  658. */
  659. test SCSISEQ0, ENSELO jnz use_lastscb;
  660. /*
  661. * The update is correct for LQOSTAT1 errors. All
  662. * but LQOBUSFREE are handled by kernel interrupts.
  663. * If we see LQOBUSFREE, return to the idle loop.
  664. * Once we are out of the select_out critical section,
  665. * the kernel will cleanup the LQOBUSFREE and we will
  666. * eventually restart the selection if appropriate.
  667. */
  668. test LQOSTAT1, LQOBUSFREE jnz idle_loop;
  669. /*
  670. * On a phase change oustside of packet boundaries,
  671. * LASTSCB points to the currently active SCB context
  672. * on the bus.
  673. */
  674. test LQOSTAT2, LQOPHACHGOUTPKT jnz use_lastscb;
  675. /*
  676. * If the hardware has traversed the whole list, NEXTSCB
  677. * will be NULL, CURRSCB and LASTSCB cannot be trusted,
  678. * but MAXCMDCNT is accurate. If we stop part way through
  679. * the list or only had one command to issue, NEXTSCB[1] is
  680. * not NULL and LASTSCB is the last command to go out.
  681. */
  682. cmp NEXTSCB[1], SCB_LIST_NULL jne use_lastscb;
  683. /*
  684. * Brute force walk.
  685. */
  686. bmov SCBPTR, WAITING_TID_HEAD, 2;
  687. mvi SEQINTCTL, INTVEC1DSL;
  688. mvi MODE_PTR, MK_MODE(M_CFG, M_CFG);
  689. mov A, MAXCMDCNT;
  690. mvi MODE_PTR, MK_MODE(M_SCSI, M_SCSI);
  691. clr SEQINTCTL;
  692. find_lastscb_loop:
  693. dec A;
  694. test A, 0xFF jz found_last_sent_scb;
  695. bmov SCBPTR, SCB_NEXT, 2;
  696. jmp find_lastscb_loop;
  697. use_lastscb:
  698. bmov SCBPTR, LASTSCB, 2;
  699. found_last_sent_scb:
  700. bmov CURRSCB, SCBPTR, 2;
  701. curscb_ww_done:
  702. } else {
  703. bmov SCBPTR, CURRSCB, 2;
  704. }
  705. /*
  706. * The whole list made it. Clear our tail pointer to indicate
  707. * that the per-target selection queue is now empty.
  708. */
  709. cmp SCB_NEXT[1], SCB_LIST_NULL je select_out_clear_tail;
  710. /*
  711. * Requeue any SCBs not sent, to the tail of the waiting Q.
  712. * We know that neither the per-TID list nor the list of
  713. * TIDs is empty. Use this knowledge to our advantage and
  714. * queue the remainder to the tail of the global execution
  715. * queue.
  716. */
  717. bmov REG0, SCB_NEXT, 2;
  718. select_out_queue_remainder:
  719. bmov SCBPTR, WAITING_TID_TAIL, 2;
  720. bmov SCB_NEXT2, REG0, 2;
  721. bmov WAITING_TID_TAIL, REG0, 2;
  722. jmp select_out_inc_tid_q;
  723. select_out_clear_tail:
  724. /*
  725. * Queue any pending MK_MESSAGE SCB for this target now
  726. * that the queue is empty.
  727. */
  728. test SEQ_FLAGS2, PENDING_MK_MESSAGE jz select_out_no_mk_message_scb;
  729. mov A, MK_MESSAGE_SCSIID;
  730. cmp SCB_SCSIID, A jne select_out_no_mk_message_scb;
  731. and SEQ_FLAGS2, ~PENDING_MK_MESSAGE;
  732. bmov REG0, MK_MESSAGE_SCB, 2;
  733. jmp select_out_queue_remainder;
  734. select_out_no_mk_message_scb:
  735. /*
  736. * Clear this target's execution tail and increment the queue.
  737. */
  738. shr DINDEX, 3, SCB_SCSIID;
  739. or DINDEX, 1; /* Want only the second byte */
  740. mvi DINDEX[1], ((WAITING_SCB_TAILS) >> 8);
  741. mvi DINDIR, SCB_LIST_NULL;
  742. select_out_inc_tid_q:
  743. bmov SCBPTR, WAITING_TID_HEAD, 2;
  744. bmov WAITING_TID_HEAD, SCB_NEXT2, 2;
  745. cmp WAITING_TID_HEAD[1], SCB_LIST_NULL jne . + 2;
  746. mvi WAITING_TID_TAIL[1], SCB_LIST_NULL;
  747. bmov SCBPTR, CURRSCB, 2;
  748. mvi CLRSINT0, CLRSELDO;
  749. test LQOSTAT2, LQOPHACHGOUTPKT jnz unexpected_nonpkt_mode_cleared;
  750. test LQOSTAT1, LQOPHACHGINPKT jnz unexpected_nonpkt_mode_cleared;
  751. /*
  752. * If this is a packetized connection, return to our
  753. * idle_loop and let our interrupt handler deal with
  754. * any connection setup/teardown issues. The only
  755. * exceptions are the case of MK_MESSAGE and task management
  756. * SCBs.
  757. */
  758. if ((ahd->bugs & AHD_LQO_ATNO_BUG) != 0) {
  759. /*
  760. * In the A, the LQO manager transitions to LQOSTOP0 even if
  761. * we have selected out with ATN asserted and the target
  762. * REQs in a non-packet phase.
  763. */
  764. test SCB_CONTROL, MK_MESSAGE jz select_out_no_message;
  765. test SCSISIGO, ATNO jnz select_out_non_packetized;
  766. select_out_no_message:
  767. }
  768. test LQOSTAT2, LQOSTOP0 jz select_out_non_packetized;
  769. test SCB_TASK_MANAGEMENT, 0xFF jz idle_loop;
  770. SET_SEQINTCODE(TASKMGMT_FUNC_COMPLETE)
  771. jmp idle_loop;
  772. select_out_non_packetized:
  773. /* Non packetized request. */
  774. and SCSISEQ0, ~ENSELO;
  775. if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
  776. /*
  777. * Test to ensure that the bus has not
  778. * already gone free prior to clearing
  779. * any stale busfree status. This avoids
  780. * a window whereby a busfree just after
  781. * a selection could be missed.
  782. */
  783. test SCSISIGI, BSYI jz . + 2;
  784. mvi CLRSINT1,CLRBUSFREE;
  785. or SIMODE1, ENBUSFREE;
  786. }
  787. mov SAVED_SCSIID, SCB_SCSIID;
  788. mov SAVED_LUN, SCB_LUN;
  789. mvi SEQ_FLAGS, NO_CDB_SENT;
  790. END_CRITICAL;
  791. or SXFRCTL0, SPIOEN;
  792. /*
  793. * As soon as we get a successful selection, the target
  794. * should go into the message out phase since we have ATN
  795. * asserted.
  796. */
  797. mvi MSG_OUT, MSG_IDENTIFYFLAG;
  798. /*
  799. * Main loop for information transfer phases. Wait for the
  800. * target to assert REQ before checking MSG, C/D and I/O for
  801. * the bus phase.
  802. */
  803. mesgin_phasemis:
  804. ITloop:
  805. call phase_lock;
  806. mov A, LASTPHASE;
  807. test A, ~P_DATAIN_DT jz p_data;
  808. cmp A,P_COMMAND je p_command;
  809. cmp A,P_MESGOUT je p_mesgout;
  810. cmp A,P_STATUS je p_status;
  811. cmp A,P_MESGIN je p_mesgin;
  812. SET_SEQINTCODE(BAD_PHASE)
  813. jmp ITloop; /* Try reading the bus again. */
  814. /*
  815. * Command phase. Set up the DMA registers and let 'er rip.
  816. */
  817. p_command:
  818. test SEQ_FLAGS, NOT_IDENTIFIED jz p_command_okay;
  819. SET_SEQINTCODE(PROTO_VIOLATION)
  820. p_command_okay:
  821. test MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
  822. jnz p_command_allocate_fifo;
  823. /*
  824. * Command retry. Free our current FIFO and
  825. * re-allocate a FIFO so transfer state is
  826. * reset.
  827. */
  828. SET_SRC_MODE M_DFF1;
  829. SET_DST_MODE M_DFF1;
  830. mvi DFFSXFRCTL, RSTCHN|CLRSHCNT;
  831. SET_MODE(M_SCSI, M_SCSI)
  832. p_command_allocate_fifo:
  833. bmov ALLOCFIFO_SCBPTR, SCBPTR, 2;
  834. call allocate_fifo;
  835. SET_SRC_MODE M_DFF1;
  836. SET_DST_MODE M_DFF1;
  837. add NONE, -17, SCB_CDB_LEN;
  838. jnc p_command_embedded;
  839. p_command_from_host:
  840. bmov HADDR[0], SCB_HOST_CDB_PTR, 9;
  841. mvi SG_CACHE_PRE, LAST_SEG;
  842. mvi DFCNTRL, (PRELOADEN|SCSIEN|HDMAEN);
  843. jmp p_command_xfer;
  844. p_command_embedded:
  845. bmov SHCNT[0], SCB_CDB_LEN, 1;
  846. bmov DFDAT, SCB_CDB_STORE, 16;
  847. mvi DFCNTRL, SCSIEN;
  848. p_command_xfer:
  849. and SEQ_FLAGS, ~NO_CDB_SENT;
  850. if ((ahd->features & AHD_FAST_CDB_DELIVERY) != 0) {
  851. /*
  852. * To speed up CDB delivery in Rev B, all CDB acks
  853. * are "released" to the output sync as soon as the
  854. * command phase starts. There is only one problem
  855. * with this approach. If the target changes phase
  856. * before all data are sent, we have left over acks
  857. * that can go out on the bus in a data phase. Due
  858. * to other chip contraints, this only happens if
  859. * the target goes to data-in, but if the acks go
  860. * out before we can test SDONE, we'll think that
  861. * the transfer has completed successfully. Work
  862. * around this by taking advantage of the 400ns or
  863. * 800ns dead time between command phase and the REQ
  864. * of the new phase. If the transfer has completed
  865. * successfully, SCSIEN should fall *long* before we
  866. * see a phase change. We thus treat any phasemiss
  867. * that occurs before SCSIEN falls as an incomplete
  868. * transfer.
  869. */
  870. test SSTAT1, PHASEMIS jnz p_command_xfer_failed;
  871. test DFCNTRL, SCSIEN jnz . - 1;
  872. } else {
  873. test DFCNTRL, SCSIEN jnz .;
  874. }
  875. /*
  876. * DMA Channel automatically disabled.
  877. * Don't allow a data phase if the command
  878. * was not fully transferred.
  879. */
  880. test SSTAT2, SDONE jnz ITloop;
  881. p_command_xfer_failed:
  882. or SEQ_FLAGS, NO_CDB_SENT;
  883. jmp ITloop;
  884. /*
  885. * Status phase. Wait for the data byte to appear, then read it
  886. * and store it into the SCB.
  887. */
  888. SET_SRC_MODE M_SCSI;
  889. SET_DST_MODE M_SCSI;
  890. p_status:
  891. test SEQ_FLAGS,NOT_IDENTIFIED jnz mesgin_proto_violation;
  892. p_status_okay:
  893. mov SCB_SCSI_STATUS, SCSIDAT;
  894. or SCB_CONTROL, STATUS_RCVD;
  895. jmp ITloop;
  896. /*
  897. * Message out phase. If MSG_OUT is MSG_IDENTIFYFLAG, build a full
  898. * indentify message sequence and send it to the target. The host may
  899. * override this behavior by setting the MK_MESSAGE bit in the SCB
  900. * control byte. This will cause us to interrupt the host and allow
  901. * it to handle the message phase completely on its own. If the bit
  902. * associated with this target is set, we will also interrupt the host,
  903. * thereby allowing it to send a message on the next selection regardless
  904. * of the transaction being sent.
  905. *
  906. * If MSG_OUT is == HOST_MSG, also interrupt the host and take a message.
  907. * This is done to allow the host to send messages outside of an identify
  908. * sequence while protecting the seqencer from testing the MK_MESSAGE bit
  909. * on an SCB that might not be for the current nexus. (For example, a
  910. * BDR message in response to a bad reselection would leave us pointed to
  911. * an SCB that doesn't have anything to do with the current target).
  912. *
  913. * Otherwise, treat MSG_OUT as a 1 byte message to send (abort, abort tag,
  914. * bus device reset).
  915. *
  916. * When there are no messages to send, MSG_OUT should be set to MSG_NOOP,
  917. * in case the target decides to put us in this phase for some strange
  918. * reason.
  919. */
  920. p_mesgout_retry:
  921. /* Turn on ATN for the retry */
  922. mvi SCSISIGO, ATNO;
  923. p_mesgout:
  924. mov SINDEX, MSG_OUT;
  925. cmp SINDEX, MSG_IDENTIFYFLAG jne p_mesgout_from_host;
  926. test SCB_CONTROL,MK_MESSAGE jnz host_message_loop;
  927. p_mesgout_identify:
  928. or SINDEX, MSG_IDENTIFYFLAG|DISCENB, SCB_LUN;
  929. test SCB_CONTROL, DISCENB jnz . + 2;
  930. and SINDEX, ~DISCENB;
  931. /*
  932. * Send a tag message if TAG_ENB is set in the SCB control block.
  933. * Use SCB_NONPACKET_TAG as the tag value.
  934. */
  935. p_mesgout_tag:
  936. test SCB_CONTROL,TAG_ENB jz p_mesgout_onebyte;
  937. mov SCSIDAT, SINDEX; /* Send the identify message */
  938. call phase_lock;
  939. cmp LASTPHASE, P_MESGOUT jne p_mesgout_done;
  940. and SCSIDAT,TAG_ENB|SCB_TAG_TYPE,SCB_CONTROL;
  941. call phase_lock;
  942. cmp LASTPHASE, P_MESGOUT jne p_mesgout_done;
  943. mov SCBPTR jmp p_mesgout_onebyte;
  944. /*
  945. * Interrupt the driver, and allow it to handle this message
  946. * phase and any required retries.
  947. */
  948. p_mesgout_from_host:
  949. cmp SINDEX, HOST_MSG jne p_mesgout_onebyte;
  950. jmp host_message_loop;
  951. p_mesgout_onebyte:
  952. mvi CLRSINT1, CLRATNO;
  953. mov SCSIDAT, SINDEX;
  954. /*
  955. * If the next bus phase after ATN drops is message out, it means
  956. * that the target is requesting that the last message(s) be resent.
  957. */
  958. call phase_lock;
  959. cmp LASTPHASE, P_MESGOUT je p_mesgout_retry;
  960. p_mesgout_done:
  961. mvi CLRSINT1,CLRATNO; /* Be sure to turn ATNO off */
  962. mov LAST_MSG, MSG_OUT;
  963. mvi MSG_OUT, MSG_NOOP; /* No message left */
  964. jmp ITloop;
  965. /*
  966. * Message in phase. Bytes are read using Automatic PIO mode.
  967. */
  968. p_mesgin:
  969. /* read the 1st message byte */
  970. mvi ACCUM call inb_first;
  971. test A,MSG_IDENTIFYFLAG jnz mesgin_identify;
  972. cmp A,MSG_DISCONNECT je mesgin_disconnect;
  973. cmp A,MSG_SAVEDATAPOINTER je mesgin_sdptrs;
  974. cmp ALLZEROS,A je mesgin_complete;
  975. cmp A,MSG_RESTOREPOINTERS je mesgin_rdptrs;
  976. cmp A,MSG_IGN_WIDE_RESIDUE je mesgin_ign_wide_residue;
  977. cmp A,MSG_NOOP je mesgin_done;
  978. /*
  979. * Pushed message loop to allow the kernel to
  980. * run it's own message state engine. To avoid an
  981. * extra nop instruction after signaling the kernel,
  982. * we perform the phase_lock before checking to see
  983. * if we should exit the loop and skip the phase_lock
  984. * in the ITloop. Performing back to back phase_locks
  985. * shouldn't hurt, but why do it twice...
  986. */
  987. host_message_loop:
  988. call phase_lock; /* Benign the first time through. */
  989. SET_SEQINTCODE(HOST_MSG_LOOP)
  990. cmp RETURN_1, EXIT_MSG_LOOP je ITloop;
  991. cmp RETURN_1, CONT_MSG_LOOP_WRITE jne . + 3;
  992. mov SCSIDAT, RETURN_2;
  993. jmp host_message_loop;
  994. /* Must be CONT_MSG_LOOP_READ */
  995. mov NONE, SCSIDAT; /* ACK Byte */
  996. jmp host_message_loop;
  997. mesgin_ign_wide_residue:
  998. mov SAVED_MODE, MODE_PTR;
  999. SET_MODE(M_SCSI, M_SCSI)
  1000. shr NEGOADDR, 4, SAVED_SCSIID;
  1001. mov A, NEGCONOPTS;
  1002. RESTORE_MODE(SAVED_MODE)
  1003. test A, WIDEXFER jz mesgin_reject;
  1004. /* Pull the residue byte */
  1005. mvi REG0 call inb_next;
  1006. cmp REG0, 0x01 jne mesgin_reject;
  1007. test SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz . + 2;
  1008. test SCB_TASK_ATTRIBUTE, SCB_XFERLEN_ODD jnz mesgin_done;
  1009. SET_SEQINTCODE(IGN_WIDE_RES)
  1010. jmp mesgin_done;
  1011. mesgin_proto_violation:
  1012. SET_SEQINTCODE(PROTO_VIOLATION)
  1013. jmp mesgin_done;
  1014. mesgin_reject:
  1015. mvi MSG_MESSAGE_REJECT call mk_mesg;
  1016. mesgin_done:
  1017. mov NONE,SCSIDAT; /*dummy read from latch to ACK*/
  1018. jmp ITloop;
  1019. #define INDEX_DISC_LIST(scsiid, lun) \
  1020. and A, 0xC0, scsiid; \
  1021. or SCBPTR, A, lun; \
  1022. clr SCBPTR[1]; \
  1023. and SINDEX, 0x30, scsiid; \
  1024. shr SINDEX, 3; /* Multiply by 2 */ \
  1025. add SINDEX, (SCB_DISCONNECTED_LISTS & 0xFF); \
  1026. mvi SINDEX[1], ((SCB_DISCONNECTED_LISTS >> 8) & 0xFF)
  1027. mesgin_identify:
  1028. /*
  1029. * Determine whether a target is using tagged or non-tagged
  1030. * transactions by first looking at the transaction stored in
  1031. * the per-device, disconnected array. If there is no untagged
  1032. * transaction for this target, this must be a tagged transaction.
  1033. */
  1034. and SAVED_LUN, MSG_IDENTIFY_LUNMASK, A;
  1035. INDEX_DISC_LIST(SAVED_SCSIID, SAVED_LUN);
  1036. bmov DINDEX, SINDEX, 2;
  1037. bmov REG0, SINDIR, 2;
  1038. cmp REG0[1], SCB_LIST_NULL je snoop_tag;
  1039. /* Untagged. Clear the busy table entry and setup the SCB. */
  1040. bmov DINDIR, ALLONES, 2;
  1041. bmov SCBPTR, REG0, 2;
  1042. jmp setup_SCB;
  1043. /*
  1044. * Here we "snoop" the bus looking for a SIMPLE QUEUE TAG message.
  1045. * If we get one, we use the tag returned to find the proper
  1046. * SCB. After receiving the tag, look for the SCB at SCB locations tag and
  1047. * tag + 256.
  1048. */
  1049. snoop_tag:
  1050. if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
  1051. or SEQ_FLAGS, 0x80;
  1052. }
  1053. mov NONE, SCSIDAT; /* ACK Identify MSG */
  1054. call phase_lock;
  1055. if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
  1056. or SEQ_FLAGS, 0x1;
  1057. }
  1058. cmp LASTPHASE, P_MESGIN jne not_found_ITloop;
  1059. if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
  1060. or SEQ_FLAGS, 0x2;
  1061. }
  1062. cmp SCSIBUS, MSG_SIMPLE_Q_TAG jne not_found;
  1063. get_tag:
  1064. clr SCBPTR[1];
  1065. mvi SCBPTR call inb_next; /* tag value */
  1066. verify_scb:
  1067. test SCB_CONTROL,DISCONNECTED jz verify_other_scb;
  1068. mov A, SAVED_SCSIID;
  1069. cmp SCB_SCSIID, A jne verify_other_scb;
  1070. mov A, SAVED_LUN;
  1071. cmp SCB_LUN, A je setup_SCB_disconnected;
  1072. verify_other_scb:
  1073. xor SCBPTR[1], 1;
  1074. test SCBPTR[1], 0xFF jnz verify_scb;
  1075. jmp not_found;
  1076. /*
  1077. * Ensure that the SCB the tag points to is for
  1078. * an SCB transaction to the reconnecting target.
  1079. */
  1080. setup_SCB:
  1081. if ((ahd->flags & AHD_SEQUENCER_DEBUG) != 0) {
  1082. or SEQ_FLAGS, 0x10;
  1083. }
  1084. test SCB_CONTROL,DISCONNECTED jz not_found;
  1085. setup_SCB_disconnected:
  1086. and SCB_CONTROL,~DISCONNECTED;
  1087. clr SEQ_FLAGS; /* make note of IDENTIFY */
  1088. test SCB_SGPTR, SG_LIST_NULL jnz . + 3;
  1089. bmov ALLOCFIFO_SCBPTR, SCBPTR, 2;
  1090. call allocate_fifo;
  1091. /* See if the host wants to send a message upon reconnection */
  1092. test SCB_CONTROL, MK_MESSAGE jz mesgin_done;
  1093. mvi HOST_MSG call mk_mesg;
  1094. jmp mesgin_done;
  1095. not_found:
  1096. SET_SEQINTCODE(NO_MATCH)
  1097. jmp mesgin_done;
  1098. not_found_ITloop:
  1099. SET_SEQINTCODE(NO_MATCH)
  1100. jmp ITloop;
  1101. /*
  1102. * We received a "command complete" message. Put the SCB on the complete
  1103. * queue and trigger a completion interrupt via the idle loop. Before doing
  1104. * so, check to see if there is a residual or the status byte is something
  1105. * other than STATUS_GOOD (0). In either of these conditions, we upload the
  1106. * SCB back to the host so it can process this information.
  1107. */
  1108. mesgin_complete:
  1109. /*
  1110. * If ATN is raised, we still want to give the target a message.
  1111. * Perhaps there was a parity error on this last message byte.
  1112. * Either way, the target should take us to message out phase
  1113. * and then attempt to complete the command again. We should use a
  1114. * critical section here to guard against a timeout triggering
  1115. * for this command and setting ATN while we are still processing
  1116. * the completion.
  1117. test SCSISIGI, ATNI jnz mesgin_done;
  1118. */
  1119. /*
  1120. * If we are identified and have successfully sent the CDB,
  1121. * any status will do. Optimize this fast path.
  1122. */
  1123. test SCB_CONTROL, STATUS_RCVD jz mesgin_proto_violation;
  1124. test SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT jz complete_accepted;
  1125. /*
  1126. * If the target never sent an identify message but instead went
  1127. * to mesgin to give an invalid message, let the host abort us.
  1128. */
  1129. test SEQ_FLAGS, NOT_IDENTIFIED jnz mesgin_proto_violation;
  1130. /*
  1131. * If we recevied good status but never successfully sent the
  1132. * cdb, abort the command.
  1133. */
  1134. test SCB_SCSI_STATUS,0xff jnz complete_accepted;
  1135. test SEQ_FLAGS, NO_CDB_SENT jnz mesgin_proto_violation;
  1136. complete_accepted:
  1137. /*
  1138. * See if we attempted to deliver a message but the target ingnored us.
  1139. */
  1140. test SCB_CONTROL, MK_MESSAGE jz complete_nomsg;
  1141. SET_SEQINTCODE(MKMSG_FAILED)
  1142. complete_nomsg:
  1143. call queue_scb_completion;
  1144. jmp await_busfree;
  1145. BEGIN_CRITICAL;
  1146. freeze_queue:
  1147. /* Cancel any pending select-out. */
  1148. test SSTAT0, SELDO|SELINGO jnz . + 2;
  1149. and SCSISEQ0, ~ENSELO;
  1150. mov ACCUM_SAVE, A;
  1151. clr A;
  1152. add QFREEZE_COUNT, 1;
  1153. adc QFREEZE_COUNT[1], A;
  1154. or SEQ_FLAGS2, SELECTOUT_QFROZEN;
  1155. mov A, ACCUM_SAVE ret;
  1156. END_CRITICAL;
  1157. /*
  1158. * Complete the current FIFO's SCB if data for this same
  1159. * SCB is not transferring in the other FIFO.
  1160. */
  1161. SET_SRC_MODE M_DFF1;
  1162. SET_DST_MODE M_DFF1;
  1163. pkt_complete_scb_if_fifos_idle:
  1164. bmov ARG_1, SCBPTR, 2;
  1165. mvi DFFSXFRCTL, CLRCHN;
  1166. SET_MODE(M_SCSI, M_SCSI)
  1167. bmov SCBPTR, ARG_1, 2;
  1168. test SCB_FIFO_USE_COUNT, 0xFF jnz return;
  1169. queue_scb_completion:
  1170. test SCB_SCSI_STATUS,0xff jnz bad_status;
  1171. /*
  1172. * Check for residuals
  1173. */
  1174. test SCB_SGPTR, SG_LIST_NULL jnz complete; /* No xfer */
  1175. test SCB_SGPTR, SG_FULL_RESID jnz upload_scb;/* Never xfered */
  1176. test SCB_RESIDUAL_SGPTR, SG_LIST_NULL jz upload_scb;
  1177. complete:
  1178. BEGIN_CRITICAL;
  1179. bmov SCB_NEXT_COMPLETE, COMPLETE_SCB_HEAD, 2;
  1180. bmov COMPLETE_SCB_HEAD, SCBPTR, 2 ret;
  1181. END_CRITICAL;
  1182. bad_status:
  1183. cmp SCB_SCSI_STATUS, STATUS_PKT_SENSE je upload_scb;
  1184. call freeze_queue;
  1185. upload_scb:
  1186. /*
  1187. * Restore SCB TAG since we reuse this field
  1188. * in the sequencer. We don't want to corrupt
  1189. * it on the host.
  1190. */
  1191. bmov SCB_TAG, SCBPTR, 2;
  1192. BEGIN_CRITICAL;
  1193. or SCB_SGPTR, SG_STATUS_VALID;
  1194. mvi SCB_NEXT_COMPLETE[1], SCB_LIST_NULL;
  1195. cmp COMPLETE_DMA_SCB_HEAD[1], SCB_LIST_NULL jne add_dma_scb_tail;
  1196. bmov COMPLETE_DMA_SCB_HEAD, SCBPTR, 2;
  1197. bmov COMPLETE_DMA_SCB_TAIL, SCBPTR, 2 ret;
  1198. add_dma_scb_tail:
  1199. bmov REG0, SCBPTR, 2;
  1200. bmov SCBPTR, COMPLETE_DMA_SCB_TAIL, 2;
  1201. bmov SCB_NEXT_COMPLETE, REG0, 2;
  1202. bmov COMPLETE_DMA_SCB_TAIL, REG0, 2 ret;
  1203. END_CRITICAL;
  1204. /*
  1205. * Is it a disconnect message? Set a flag in the SCB to remind us
  1206. * and await the bus going free. If this is an untagged transaction
  1207. * store the SCB id for it in our untagged target table for lookup on
  1208. * a reselection.
  1209. */
  1210. mesgin_disconnect:
  1211. /*
  1212. * If ATN is raised, we still want to give the target a message.
  1213. * Perhaps there was a parity error on this last message byte
  1214. * or we want to abort this command. Either way, the target
  1215. * should take us to message out phase and then attempt to
  1216. * disconnect again.
  1217. * XXX - Wait for more testing.
  1218. test SCSISIGI, ATNI jnz mesgin_done;
  1219. */
  1220. test SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT
  1221. jnz mesgin_proto_violation;
  1222. or SCB_CONTROL,DISCONNECTED;
  1223. test SCB_CONTROL, TAG_ENB jnz await_busfree;
  1224. queue_disc_scb:
  1225. bmov REG0, SCBPTR, 2;
  1226. INDEX_DISC_LIST(SAVED_SCSIID, SAVED_LUN);
  1227. bmov DINDEX, SINDEX, 2;
  1228. bmov DINDIR, REG0, 2;
  1229. bmov SCBPTR, REG0, 2;
  1230. /* FALLTHROUGH */
  1231. await_busfree:
  1232. and SIMODE1, ~ENBUSFREE;
  1233. if ((ahd->bugs & AHD_BUSFREEREV_BUG) == 0) {
  1234. /*
  1235. * In the BUSFREEREV_BUG case, the
  1236. * busfree status was cleared at the
  1237. * beginning of the connection.
  1238. */
  1239. mvi CLRSINT1,CLRBUSFREE;
  1240. }
  1241. mov NONE, SCSIDAT; /* Ack the last byte */
  1242. test MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
  1243. jnz await_busfree_not_m_dff;
  1244. SET_SRC_MODE M_DFF1;
  1245. SET_DST_MODE M_DFF1;
  1246. await_busfree_clrchn:
  1247. mvi DFFSXFRCTL, CLRCHN;
  1248. await_busfree_not_m_dff:
  1249. /* clear target specific flags */
  1250. mvi SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT;
  1251. test SSTAT1,REQINIT|BUSFREE jz .;
  1252. /*
  1253. * We only set BUSFREE status once either a new
  1254. * phase has been detected or we are really
  1255. * BUSFREE. This allows the driver to know
  1256. * that we are active on the bus even though
  1257. * no identified transaction exists should a
  1258. * timeout occur while awaiting busfree.
  1259. */
  1260. mvi LASTPHASE, P_BUSFREE;
  1261. test SSTAT1, BUSFREE jnz idle_loop;
  1262. SET_SEQINTCODE(MISSED_BUSFREE)
  1263. /*
  1264. * Save data pointers message:
  1265. * Copying RAM values back to SCB, for Save Data Pointers message, but
  1266. * only if we've actually been into a data phase to change them. This
  1267. * protects against bogus data in scratch ram and the residual counts
  1268. * since they are only initialized when we go into data_in or data_out.
  1269. * Ack the message as soon as possible.
  1270. */
  1271. SET_SRC_MODE M_DFF1;
  1272. SET_DST_MODE M_DFF1;
  1273. mesgin_sdptrs:
  1274. mov NONE,SCSIDAT; /*dummy read from latch to ACK*/
  1275. test SEQ_FLAGS, DPHASE jz ITloop;
  1276. call save_pointers;
  1277. jmp ITloop;
  1278. save_pointers:
  1279. /*
  1280. * If we are asked to save our position at the end of the
  1281. * transfer, just mark us at the end rather than perform a
  1282. * full save.
  1283. */
  1284. test SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz save_pointers_full;
  1285. or SCB_SGPTR, SG_LIST_NULL ret;
  1286. save_pointers_full:
  1287. /*
  1288. * The SCB_DATAPTR becomes the current SHADDR.
  1289. * All other information comes directly from our residual
  1290. * state.
  1291. */
  1292. bmov SCB_DATAPTR, SHADDR, 8;
  1293. bmov SCB_DATACNT, SCB_RESIDUAL_DATACNT, 8 ret;
  1294. /*
  1295. * Restore pointers message? Data pointers are recopied from the
  1296. * SCB anytime we enter a data phase for the first time, so all
  1297. * we need to do is clear the DPHASE flag and let the data phase
  1298. * code do the rest. We also reset/reallocate the FIFO to make
  1299. * sure we have a clean start for the next data or command phase.
  1300. */
  1301. mesgin_rdptrs:
  1302. and SEQ_FLAGS, ~DPHASE;
  1303. test MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1)) jnz msgin_rdptrs_get_fifo;
  1304. mvi DFFSXFRCTL, RSTCHN|CLRSHCNT;
  1305. SET_MODE(M_SCSI, M_SCSI)
  1306. msgin_rdptrs_get_fifo:
  1307. call allocate_fifo;
  1308. jmp mesgin_done;
  1309. phase_lock:
  1310. if ((ahd->bugs & AHD_EARLY_REQ_BUG) != 0) {
  1311. /*
  1312. * Don't ignore persistent REQ assertions just because
  1313. * they were asserted within the bus settle delay window.
  1314. * This allows us to tolerate devices like the GEM318
  1315. * that violate the SCSI spec. We are careful not to
  1316. * count REQ while we are waiting for it to fall during
  1317. * an async phase due to our asserted ACK. Each
  1318. * sequencer instruction takes ~25ns, so the REQ must
  1319. * last at least 100ns in order to be counted as a true
  1320. * REQ.
  1321. */
  1322. test SCSIPHASE, 0xFF jnz phase_locked;
  1323. test SCSISIGI, ACKI jnz phase_lock;
  1324. test SCSISIGI, REQI jz phase_lock;
  1325. test SCSIPHASE, 0xFF jnz phase_locked;
  1326. test SCSISIGI, ACKI jnz phase_lock;
  1327. test SCSISIGI, REQI jz phase_lock;
  1328. phase_locked:
  1329. } else {
  1330. test SCSIPHASE, 0xFF jz .;
  1331. }
  1332. test SSTAT1, SCSIPERR jnz phase_lock;
  1333. phase_lock_latch_phase:
  1334. and LASTPHASE, PHASE_MASK, SCSISIGI ret;
  1335. /*
  1336. * Functions to read data in Automatic PIO mode.
  1337. *
  1338. * An ACK is not sent on input from the target until SCSIDATL is read from.
  1339. * So we wait until SCSIDATL is latched (the usual way), then read the data
  1340. * byte directly off the bus using SCSIBUSL. When we have pulled the ATN
  1341. * line, or we just want to acknowledge the byte, then we do a dummy read
  1342. * from SCISDATL. The SCSI spec guarantees that the target will hold the
  1343. * data byte on the bus until we send our ACK.
  1344. *
  1345. * The assumption here is that these are called in a particular sequence,
  1346. * and that REQ is already set when inb_first is called. inb_{first,next}
  1347. * use the same calling convention as inb.
  1348. */
  1349. inb_next:
  1350. mov NONE,SCSIDAT; /*dummy read from latch to ACK*/
  1351. inb_next_wait:
  1352. /*
  1353. * If there is a parity error, wait for the kernel to
  1354. * see the interrupt and prepare our message response
  1355. * before continuing.
  1356. */
  1357. test SCSIPHASE, 0xFF jz .;
  1358. test SSTAT1, SCSIPERR jnz inb_next_wait;
  1359. inb_next_check_phase:
  1360. and LASTPHASE, PHASE_MASK, SCSISIGI;
  1361. cmp LASTPHASE, P_MESGIN jne mesgin_phasemis;
  1362. inb_first:
  1363. clr DINDEX[1];
  1364. mov DINDEX,SINDEX;
  1365. mov DINDIR,SCSIBUS ret; /*read byte directly from bus*/
  1366. inb_last:
  1367. mov NONE,SCSIDAT ret; /*dummy read from latch to ACK*/
  1368. mk_mesg:
  1369. mvi SCSISIGO, ATNO;
  1370. mov MSG_OUT,SINDEX ret;
  1371. SET_SRC_MODE M_DFF1;
  1372. SET_DST_MODE M_DFF1;
  1373. disable_ccsgen:
  1374. test SG_STATE, FETCH_INPROG jz disable_ccsgen_fetch_done;
  1375. clr CCSGCTL;
  1376. disable_ccsgen_fetch_done:
  1377. clr SG_STATE ret;
  1378. service_fifo:
  1379. /*
  1380. * Do we have any prefetch left???
  1381. */
  1382. test SG_STATE, SEGS_AVAIL jnz idle_sg_avail;
  1383. /*
  1384. * Can this FIFO have access to the S/G cache yet?
  1385. */
  1386. test CCSGCTL, SG_CACHE_AVAIL jz return;
  1387. /* Did we just finish fetching segs? */
  1388. test CCSGCTL, CCSGDONE jnz idle_sgfetch_complete;
  1389. /* Are we actively fetching segments? */
  1390. test CCSGCTL, CCSGENACK jnz return;
  1391. /*
  1392. * Should the other FIFO get the S/G cache first? If
  1393. * both FIFOs have been allocated since we last checked
  1394. * any FIFO, it is important that we service a FIFO
  1395. * that is not actively on the bus first. This guarantees
  1396. * that a FIFO will be freed to handle snapshot requests for
  1397. * any FIFO that is still on the bus. Chips with RTI do not
  1398. * perform snapshots, so don't bother with this test there.
  1399. */
  1400. if ((ahd->features & AHD_RTI) == 0) {
  1401. /*
  1402. * If we're not still receiving SCSI data,
  1403. * it is safe to allocate the S/G cache to
  1404. * this FIFO.
  1405. */
  1406. test DFCNTRL, SCSIEN jz idle_sgfetch_start;
  1407. /*
  1408. * Switch to the other FIFO. Non-RTI chips
  1409. * also have the "set mode" bug, so we must
  1410. * disable interrupts during the switch.
  1411. */
  1412. mvi SEQINTCTL, INTVEC1DSL;
  1413. xor MODE_PTR, MK_MODE(M_DFF1, M_DFF1);
  1414. /*
  1415. * If the other FIFO needs loading, then it
  1416. * must not have claimed the S/G cache yet
  1417. * (SG_CACHE_AVAIL would have been cleared in
  1418. * the original FIFO mode and we test this above).
  1419. * Return to the idle loop so we can process the
  1420. * FIFO not currently on the bus first.
  1421. */
  1422. test SG_STATE, LOADING_NEEDED jz idle_sgfetch_okay;
  1423. clr SEQINTCTL ret;
  1424. idle_sgfetch_okay:
  1425. xor MODE_PTR, MK_MODE(M_DFF1, M_DFF1);
  1426. clr SEQINTCTL;
  1427. }
  1428. idle_sgfetch_start:
  1429. /*
  1430. * We fetch a "cacheline aligned" and sized amount of data
  1431. * so we don't end up referencing a non-existent page.
  1432. * Cacheline aligned is in quotes because the kernel will
  1433. * set the prefetch amount to a reasonable level if the
  1434. * cacheline size is unknown.
  1435. */
  1436. bmov SGHADDR, SCB_RESIDUAL_SGPTR, 4;
  1437. mvi SGHCNT, SG_PREFETCH_CNT;
  1438. if ((ahd->bugs & AHD_REG_SLOW_SETTLE_BUG) != 0) {
  1439. /*
  1440. * Need two instructions between "touches" of SGHADDR.
  1441. */
  1442. nop;
  1443. }
  1444. and SGHADDR[0], SG_PREFETCH_ALIGN_MASK, SCB_RESIDUAL_SGPTR;
  1445. mvi CCSGCTL, CCSGEN|CCSGRESET;
  1446. or SG_STATE, FETCH_INPROG ret;
  1447. idle_sgfetch_complete:
  1448. /*
  1449. * Guard against SG_CACHE_AVAIL activating during sg fetch
  1450. * request in the other FIFO.
  1451. */
  1452. test SG_STATE, FETCH_INPROG jz return;
  1453. clr CCSGCTL;
  1454. and CCSGADDR, SG_PREFETCH_ADDR_MASK, SCB_RESIDUAL_SGPTR;
  1455. mvi SG_STATE, SEGS_AVAIL|LOADING_NEEDED;
  1456. idle_sg_avail:
  1457. /* Does the hardware have space for another SG entry? */
  1458. test DFSTATUS, PRELOAD_AVAIL jz return;
  1459. /*
  1460. * On the A, preloading a segment before HDMAENACK
  1461. * comes true can clobber the shadow address of the
  1462. * first segment in the S/G FIFO. Wait until it is
  1463. * safe to proceed.
  1464. */
  1465. if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) == 0) {
  1466. test DFCNTRL, HDMAENACK jz return;
  1467. }
  1468. if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
  1469. bmov HADDR, CCSGRAM, 8;
  1470. } else {
  1471. bmov HADDR, CCSGRAM, 4;
  1472. }
  1473. bmov HCNT, CCSGRAM, 3;
  1474. bmov SCB_RESIDUAL_DATACNT[3], CCSGRAM, 1;
  1475. if ((ahd->flags & AHD_39BIT_ADDRESSING) != 0) {
  1476. and HADDR[4], SG_HIGH_ADDR_BITS, SCB_RESIDUAL_DATACNT[3];
  1477. }
  1478. if ((ahd->flags & AHD_64BIT_ADDRESSING) != 0) {
  1479. /* Skip 4 bytes of pad. */
  1480. add CCSGADDR, 4;
  1481. }
  1482. sg_advance:
  1483. clr A; /* add sizeof(struct scatter) */
  1484. add SCB_RESIDUAL_SGPTR[0],SG_SIZEOF;
  1485. adc SCB_RESIDUAL_SGPTR[1],A;
  1486. adc SCB_RESIDUAL_SGPTR[2],A;
  1487. adc SCB_RESIDUAL_SGPTR[3],A;
  1488. mov SINDEX, SCB_RESIDUAL_SGPTR[0];
  1489. test SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jz . + 3;
  1490. or SINDEX, LAST_SEG;
  1491. clr SG_STATE;
  1492. mov SG_CACHE_PRE, SINDEX;
  1493. if ((ahd->features & AHD_NEW_DFCNTRL_OPTS) != 0) {
  1494. /*
  1495. * Use SCSIENWRDIS so that SCSIEN is never
  1496. * modified by this operation.
  1497. */
  1498. or DFCNTRL, PRELOADEN|HDMAEN|SCSIENWRDIS;
  1499. } else {
  1500. or DFCNTRL, PRELOADEN|HDMAEN;
  1501. }
  1502. /*
  1503. * Do we have another segment in the cache?
  1504. */
  1505. add NONE, SG_PREFETCH_CNT_LIMIT, CCSGADDR;
  1506. jnc return;
  1507. and SG_STATE, ~SEGS_AVAIL ret;
  1508. /*
  1509. * Initialize the DMA address and counter from the SCB.
  1510. */
  1511. load_first_seg:
  1512. bmov HADDR, SCB_DATAPTR, 11;
  1513. and REG_ISR, ~SG_FULL_RESID, SCB_SGPTR[0];
  1514. test SCB_DATACNT[3], SG_LAST_SEG jz . + 2;
  1515. or REG_ISR, LAST_SEG;
  1516. mov SG_CACHE_PRE, REG_ISR;
  1517. mvi DFCNTRL, (PRELOADEN|SCSIEN|HDMAEN);
  1518. /*
  1519. * Since we've are entering a data phase, we will
  1520. * rely on the SCB_RESID* fields. Initialize the
  1521. * residual and clear the full residual flag.
  1522. */
  1523. and SCB_SGPTR[0], ~SG_FULL_RESID;
  1524. bmov SCB_RESIDUAL_DATACNT[3], SCB_DATACNT[3], 5;
  1525. /* If we need more S/G elements, tell the idle loop */
  1526. test SCB_RESIDUAL_DATACNT[3], SG_LAST_SEG jnz . + 2;
  1527. mvi SG_STATE, LOADING_NEEDED ret;
  1528. clr SG_STATE ret;
  1529. p_data_handle_xfer:
  1530. call setjmp;
  1531. test SG_STATE, LOADING_NEEDED jnz service_fifo;
  1532. p_data_clear_handler:
  1533. or LONGJMP_ADDR[1], INVALID_ADDR ret;
  1534. p_data:
  1535. test SEQ_FLAGS, NOT_IDENTIFIED|NO_CDB_SENT jz p_data_allowed;
  1536. SET_SEQINTCODE(PROTO_VIOLATION)
  1537. p_data_allowed:
  1538. test SEQ_FLAGS, DPHASE jz data_phase_initialize;
  1539. /*
  1540. * If we re-enter the data phase after going through another
  1541. * phase, our transfer location has almost certainly been
  1542. * corrupted by the interveining, non-data, transfers. Ask
  1543. * the host driver to fix us up based on the transfer residual
  1544. * unless we already know that we should be bitbucketing.
  1545. */
  1546. test SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jnz p_data_bitbucket;
  1547. SET_SEQINTCODE(PDATA_REINIT)
  1548. jmp data_phase_inbounds;
  1549. p_data_bitbucket:
  1550. /*
  1551. * Turn on `Bit Bucket' mode, wait until the target takes
  1552. * us to another phase, and then notify the host.
  1553. */
  1554. mov SAVED_MODE, MODE_PTR;
  1555. test MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
  1556. jnz bitbucket_not_m_dff;
  1557. /*
  1558. * Ensure that any FIFO contents are cleared out and the
  1559. * FIFO free'd prior to starting the BITBUCKET. BITBUCKET
  1560. * doesn't discard data already in the FIFO.
  1561. */
  1562. mvi DFFSXFRCTL, RSTCHN|CLRSHCNT;
  1563. SET_MODE(M_SCSI, M_SCSI)
  1564. bitbucket_not_m_dff:
  1565. or SXFRCTL1,BITBUCKET;
  1566. /* Wait for non-data phase. */
  1567. test SCSIPHASE, ~DATA_PHASE_MASK jz .;
  1568. and SXFRCTL1, ~BITBUCKET;
  1569. RESTORE_MODE(SAVED_MODE)
  1570. SET_SRC_MODE M_DFF1;
  1571. SET_DST_MODE M_DFF1;
  1572. SET_SEQINTCODE(DATA_OVERRUN)
  1573. jmp ITloop;
  1574. data_phase_initialize:
  1575. test SCB_SGPTR[0], SG_LIST_NULL jnz p_data_bitbucket;
  1576. call load_first_seg;
  1577. data_phase_inbounds:
  1578. /* We have seen a data phase at least once. */
  1579. or SEQ_FLAGS, DPHASE;
  1580. mov SAVED_MODE, MODE_PTR;
  1581. test SG_STATE, LOADING_NEEDED jz data_group_dma_loop;
  1582. call p_data_handle_xfer;
  1583. data_group_dma_loop:
  1584. /*
  1585. * The transfer is complete if either the last segment
  1586. * completes or the target changes phase. Both conditions
  1587. * will clear SCSIEN.
  1588. */
  1589. call idle_loop_service_fifos;
  1590. call idle_loop_cchan;
  1591. call idle_loop_gsfifo;
  1592. RESTORE_MODE(SAVED_MODE)
  1593. test DFCNTRL, SCSIEN jnz data_group_dma_loop;
  1594. data_group_dmafinish:
  1595. /*
  1596. * The transfer has terminated either due to a phase
  1597. * change, and/or the completion of the last segment.
  1598. * We have two goals here. Do as much other work
  1599. * as possible while the data fifo drains on a read
  1600. * and respond as quickly as possible to the standard
  1601. * messages (save data pointers/disconnect and command
  1602. * complete) that usually follow a data phase.
  1603. */
  1604. call calc_residual;
  1605. /*
  1606. * Go ahead and shut down the DMA engine now.
  1607. */
  1608. test DFCNTRL, DIRECTION jnz data_phase_finish;
  1609. data_group_fifoflush:
  1610. if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
  1611. or DFCNTRL, FIFOFLUSH;
  1612. }
  1613. /*
  1614. * We have enabled the auto-ack feature. This means
  1615. * that the controller may have already transferred
  1616. * some overrun bytes into the data FIFO and acked them
  1617. * on the bus. The only way to detect this situation is
  1618. * to wait for LAST_SEG_DONE to come true on a completed
  1619. * transfer and then test to see if the data FIFO is
  1620. * non-empty. We know there is more data yet to transfer
  1621. * if SG_LIST_NULL is not yet set, thus there cannot be
  1622. * an overrun.
  1623. */
  1624. test SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL jz data_phase_finish;
  1625. test SG_CACHE_SHADOW, LAST_SEG_DONE jz .;
  1626. test DFSTATUS, FIFOEMP jnz data_phase_finish;
  1627. /* Overrun */
  1628. jmp p_data;
  1629. data_phase_finish:
  1630. /*
  1631. * If the target has left us in data phase, loop through
  1632. * the dma code again. We will only loop if there is a
  1633. * data overrun.
  1634. */
  1635. if ((ahd->flags & AHD_TARGETROLE) != 0) {
  1636. test SSTAT0, TARGET jnz data_phase_done;
  1637. }
  1638. if ((ahd->flags & AHD_INITIATORROLE) != 0) {
  1639. test SSTAT1, REQINIT jz .;
  1640. test SCSIPHASE, DATA_PHASE_MASK jnz p_data;
  1641. }
  1642. data_phase_done:
  1643. /* Kill off any pending prefetch */
  1644. call disable_ccsgen;
  1645. or LONGJMP_ADDR[1], INVALID_ADDR;
  1646. if ((ahd->flags & AHD_TARGETROLE) != 0) {
  1647. test SEQ_FLAGS, DPHASE_PENDING jz ITloop;
  1648. /*
  1649. and SEQ_FLAGS, ~DPHASE_PENDING;
  1650. * For data-in phases, wait for any pending acks from the
  1651. * initiator before changing phase. We only need to
  1652. * send Ignore Wide Residue messages for data-in phases.
  1653. test DFCNTRL, DIRECTION jz target_ITloop;
  1654. test SSTAT1, REQINIT jnz .;
  1655. test SCB_TASK_ATTRIBUTE, SCB_XFERLEN_ODD jz target_ITloop;
  1656. SET_MODE(M_SCSI, M_SCSI)
  1657. test NEGCONOPTS, WIDEXFER jz target_ITloop;
  1658. */
  1659. /*
  1660. * Issue an Ignore Wide Residue Message.
  1661. mvi P_MESGIN|BSYO call change_phase;
  1662. mvi MSG_IGN_WIDE_RESIDUE call target_outb;
  1663. mvi 1 call target_outb;
  1664. jmp target_ITloop;
  1665. */
  1666. } else {
  1667. jmp ITloop;
  1668. }
  1669. /*
  1670. * We assume that, even though data may still be
  1671. * transferring to the host, that the SCSI side of
  1672. * the DMA engine is now in a static state. This
  1673. * allows us to update our notion of where we are
  1674. * in this transfer.
  1675. *
  1676. * If, by chance, we stopped before being able
  1677. * to fetch additional segments for this transfer,
  1678. * yet the last S/G was completely exhausted,
  1679. * call our idle loop until it is able to load
  1680. * another segment. This will allow us to immediately
  1681. * pickup on the next segment on the next data phase.
  1682. *
  1683. * If we happened to stop on the last segment, then
  1684. * our residual information is still correct from
  1685. * the idle loop and there is no need to perform
  1686. * any fixups.
  1687. */
  1688. residual_before_last_seg:
  1689. test MDFFSTAT, SHVALID jnz sgptr_fixup;
  1690. /*
  1691. * Can never happen from an interrupt as the packetized
  1692. * hardware will only interrupt us once SHVALID or
  1693. * LAST_SEG_DONE.
  1694. */
  1695. call idle_loop_service_fifos;
  1696. RESTORE_MODE(SAVED_MODE)
  1697. /* FALLTHROUGH */
  1698. calc_residual:
  1699. test SG_CACHE_SHADOW, LAST_SEG jz residual_before_last_seg;
  1700. /* Record if we've consumed all S/G entries */
  1701. test MDFFSTAT, SHVALID jz . + 2;
  1702. bmov SCB_RESIDUAL_DATACNT, SHCNT, 3 ret;
  1703. or SCB_RESIDUAL_SGPTR[0], SG_LIST_NULL ret;
  1704. sgptr_fixup:
  1705. /*
  1706. * Fixup the residual next S/G pointer. The S/G preload
  1707. * feature of the chip allows us to load two elements
  1708. * in addition to the currently active element. We
  1709. * store the bottom byte of the next S/G pointer in
  1710. * the SG_CACHE_PTR register so we can restore the
  1711. * correct value when the DMA completes. If the next
  1712. * sg ptr value has advanced to the point where higher
  1713. * bytes in the address have been affected, fix them
  1714. * too.
  1715. */
  1716. test SG_CACHE_SHADOW, 0x80 jz sgptr_fixup_done;
  1717. test SCB_RESIDUAL_SGPTR[0], 0x80 jnz sgptr_fixup_done;
  1718. add SCB_RESIDUAL_SGPTR[1], -1;
  1719. adc SCB_RESIDUAL_SGPTR[2], -1;
  1720. adc SCB_RESIDUAL_SGPTR[3], -1;
  1721. sgptr_fixup_done:
  1722. and SCB_RESIDUAL_SGPTR[0], SG_ADDR_MASK, SG_CACHE_SHADOW;
  1723. clr SCB_RESIDUAL_DATACNT[3]; /* We are not the last seg */
  1724. bmov SCB_RESIDUAL_DATACNT, SHCNT, 3 ret;
  1725. export timer_isr:
  1726. call issue_cmdcmplt;
  1727. mvi CLRSEQINTSTAT, CLRSEQ_SWTMRTO;
  1728. if ((ahd->bugs & AHD_SET_MODE_BUG) != 0) {
  1729. /*
  1730. * In H2A4, the mode pointer is not saved
  1731. * for intvec2, but is restored on iret.
  1732. * This can lead to the restoration of a
  1733. * bogus mode ptr. Manually clear the
  1734. * intmask bits and do a normal return
  1735. * to compensate.
  1736. */
  1737. and SEQINTCTL, ~(INTMASK2|INTMASK1) ret;
  1738. } else {
  1739. or SEQINTCTL, IRET ret;
  1740. }
  1741. export seq_isr:
  1742. if ((ahd->features & AHD_RTI) == 0) {
  1743. /*
  1744. * On RevA Silicon, if the target returns us to data-out
  1745. * after we have already trained for data-out, it is
  1746. * possible for us to transition the free running clock to
  1747. * data-valid before the required 100ns P1 setup time (8 P1
  1748. * assertions in fast-160 mode). This will only happen if
  1749. * this L-Q is a continuation of a data transfer for which
  1750. * we have already prefetched data into our FIFO (LQ/Data
  1751. * followed by LQ/Data for the same write transaction).
  1752. * This can cause some target implementations to miss the
  1753. * first few data transfers on the bus. We detect this
  1754. * situation by noticing that this is the first data transfer
  1755. * after an LQ (LQIWORKONLQ true), that the data transfer is
  1756. * a continuation of a transfer already setup in our FIFO
  1757. * (SAVEPTRS interrupt), and that the transaction is a write
  1758. * (DIRECTION set in DFCNTRL). The delay is performed by
  1759. * disabling SCSIEN until we see the first REQ from the
  1760. * target.
  1761. *
  1762. * First instruction in an ISR cannot be a branch on
  1763. * Rev A. Snapshot LQISTAT2 so the status is not missed
  1764. * and deffer the test by one instruction.
  1765. */
  1766. mov REG_ISR, LQISTAT2;
  1767. test REG_ISR, LQIWORKONLQ jz main_isr;
  1768. test SEQINTSRC, SAVEPTRS jz main_isr;
  1769. test LONGJMP_ADDR[1], INVALID_ADDR jz saveptr_active_fifo;
  1770. /*
  1771. * Switch to the active FIFO after clearing the snapshot
  1772. * savepointer in the current FIFO. We do this so that
  1773. * a pending CTXTDONE or SAVEPTR is visible in the active
  1774. * FIFO. This status is the only way we can detect if we
  1775. * have lost the race (e.g. host paused us) and our attempts
  1776. * to disable the channel occurred after all REQs were
  1777. * already seen and acked (REQINIT never comes true).
  1778. */
  1779. mvi DFFSXFRCTL, CLRCHN;
  1780. xor MODE_PTR, MK_MODE(M_DFF1, M_DFF1);
  1781. test DFCNTRL, DIRECTION jz interrupt_return;
  1782. and DFCNTRL, ~SCSIEN;
  1783. snapshot_wait_data_valid:
  1784. test SEQINTSRC, (CTXTDONE|SAVEPTRS) jnz interrupt_return;
  1785. test SSTAT1, REQINIT jz snapshot_wait_data_valid;
  1786. snapshot_data_valid:
  1787. or DFCNTRL, SCSIEN;
  1788. or SEQINTCTL, IRET ret;
  1789. snapshot_saveptr:
  1790. mvi DFFSXFRCTL, CLRCHN;
  1791. or SEQINTCTL, IRET ret;
  1792. main_isr:
  1793. }
  1794. test SEQINTSRC, CFG4DATA jnz cfg4data_intr;
  1795. test SEQINTSRC, CFG4ISTAT jnz cfg4istat_intr;
  1796. test SEQINTSRC, SAVEPTRS jnz saveptr_intr;
  1797. test SEQINTSRC, CFG4ICMD jnz cfg4icmd_intr;
  1798. SET_SEQINTCODE(INVALID_SEQINT)
  1799. /*
  1800. * There are two types of save pointers interrupts:
  1801. * The first is a snapshot save pointers where the current FIFO is not
  1802. * active and contains a snapshot of the current poniter information.
  1803. * This happens between packets in a stream for a single L_Q. Since we
  1804. * are not performing a pointer save, we can safely clear the channel
  1805. * so it can be used for other transactions. On RTI capable controllers,
  1806. * where snapshots can, and are, disabled, the code to handle this type
  1807. * of snapshot is not active.
  1808. *
  1809. * The second case is a save pointers on an active FIFO which occurs
  1810. * if the target changes to a new L_Q or busfrees/QASes and the transfer
  1811. * has a residual. This should occur coincident with a ctxtdone. We
  1812. * disable the interrupt and allow our active routine to handle the
  1813. * save.
  1814. */
  1815. saveptr_intr:
  1816. if ((ahd->features & AHD_RTI) == 0) {
  1817. test LONGJMP_ADDR[1], INVALID_ADDR jnz snapshot_saveptr;
  1818. }
  1819. saveptr_active_fifo:
  1820. and SEQIMODE, ~ENSAVEPTRS;
  1821. or SEQINTCTL, IRET ret;
  1822. cfg4data_intr:
  1823. test SCB_SGPTR[0], SG_LIST_NULL jnz pkt_handle_overrun_inc_use_count;
  1824. call load_first_seg;
  1825. call pkt_handle_xfer;
  1826. inc SCB_FIFO_USE_COUNT;
  1827. interrupt_return:
  1828. or SEQINTCTL, IRET ret;
  1829. cfg4istat_intr:
  1830. call freeze_queue;
  1831. add NONE, -13, SCB_CDB_LEN;
  1832. jnc cfg4istat_have_sense_addr;
  1833. test SCB_CDB_LEN, SCB_CDB_LEN_PTR jnz cfg4istat_have_sense_addr;
  1834. /*
  1835. * Host sets up address/count and enables transfer.
  1836. */
  1837. SET_SEQINTCODE(CFG4ISTAT_INTR)
  1838. jmp cfg4istat_setup_handler;
  1839. cfg4istat_have_sense_addr:
  1840. bmov HADDR, SCB_SENSE_BUSADDR, 4;
  1841. mvi HCNT[1], (AHD_SENSE_BUFSIZE >> 8);
  1842. mvi SG_CACHE_PRE, LAST_SEG;
  1843. mvi DFCNTRL, PRELOADEN|SCSIEN|HDMAEN;
  1844. cfg4istat_setup_handler:
  1845. /*
  1846. * Status pkt is transferring to host.
  1847. * Wait in idle loop for transfer to complete.
  1848. * If a command completed before an attempted
  1849. * task management function completed, notify the host.
  1850. */
  1851. test SCB_TASK_MANAGEMENT, 0xFF jz cfg4istat_no_taskmgmt_func;
  1852. SET_SEQINTCODE(TASKMGMT_CMD_CMPLT_OKAY)
  1853. cfg4istat_no_taskmgmt_func:
  1854. call pkt_handle_status;
  1855. or SEQINTCTL, IRET ret;
  1856. cfg4icmd_intr:
  1857. /*
  1858. * In the case of DMAing a CDB from the host, the normal
  1859. * CDB buffer is formatted with an 8 byte address followed
  1860. * by a 1 byte count.
  1861. */
  1862. bmov HADDR[0], SCB_HOST_CDB_PTR, 9;
  1863. mvi SG_CACHE_PRE, LAST_SEG;
  1864. mvi DFCNTRL, (PRELOADEN|SCSIEN|HDMAEN);
  1865. call pkt_handle_cdb;
  1866. or SEQINTCTL, IRET ret;
  1867. /*
  1868. * See if the target has gone on in this context creating an
  1869. * overrun condition. For the write case, the hardware cannot
  1870. * ack bytes until data are provided. So, if the target begins
  1871. * another packet without changing contexts, implying we are
  1872. * not sitting on a packet boundary, we are in an overrun
  1873. * situation. For the read case, the hardware will continue to
  1874. * ack bytes into the FIFO, and may even ack the last overrun packet
  1875. * into the FIFO. If the FIFO should become non-empty, we are in
  1876. * a read overrun case.
  1877. */
  1878. #define check_overrun \
  1879. /* Not on a packet boundary. */ \
  1880. test MDFFSTAT, DLZERO jz pkt_handle_overrun; \
  1881. test DFSTATUS, FIFOEMP jz pkt_handle_overrun
  1882. pkt_handle_xfer:
  1883. test SG_STATE, LOADING_NEEDED jz pkt_last_seg;
  1884. call setjmp;
  1885. test SEQINTSRC, SAVEPTRS jnz pkt_saveptrs;
  1886. test SCSIPHASE, ~DATA_PHASE_MASK jz . + 2;
  1887. test SCSISIGO, ATNO jnz . + 2;
  1888. test SSTAT2, NONPACKREQ jz pkt_service_fifo;
  1889. /*
  1890. * Defer handling of this NONPACKREQ until we
  1891. * can be sure it pertains to this FIFO. SAVEPTRS
  1892. * will not be asserted if the NONPACKREQ is for us,
  1893. * so we must simulate it if shadow is valid. If
  1894. * shadow is not valid, keep running this FIFO until we
  1895. * have satisfied the transfer by loading segments and
  1896. * waiting for either shadow valid or last_seg_done.
  1897. */
  1898. test MDFFSTAT, SHVALID jnz pkt_saveptrs;
  1899. pkt_service_fifo:
  1900. test SG_STATE, LOADING_NEEDED jnz service_fifo;
  1901. pkt_last_seg:
  1902. call setjmp;
  1903. test SEQINTSRC, SAVEPTRS jnz pkt_saveptrs;
  1904. test SG_CACHE_SHADOW, LAST_SEG_DONE jnz pkt_last_seg_done;
  1905. test SCSIPHASE, ~DATA_PHASE_MASK jz . + 2;
  1906. test SCSISIGO, ATNO jnz . + 2;
  1907. test SSTAT2, NONPACKREQ jz return;
  1908. test MDFFSTAT, SHVALID jz return;
  1909. /* FALLTHROUGH */
  1910. /*
  1911. * Either a SAVEPTRS interrupt condition is pending for this FIFO
  1912. * or we have a pending NONPACKREQ for this FIFO. We differentiate
  1913. * between the two by capturing the state of the SAVEPTRS interrupt
  1914. * prior to clearing this status and executing the common code for
  1915. * these two cases.
  1916. */
  1917. pkt_saveptrs:
  1918. BEGIN_CRITICAL;
  1919. if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
  1920. or DFCNTRL, FIFOFLUSH;
  1921. }
  1922. mov REG0, SEQINTSRC;
  1923. call calc_residual;
  1924. call save_pointers;
  1925. mvi CLRSEQINTSRC, CLRSAVEPTRS;
  1926. call disable_ccsgen;
  1927. or SEQIMODE, ENSAVEPTRS;
  1928. test DFCNTRL, DIRECTION jnz pkt_saveptrs_check_status;
  1929. test DFSTATUS, FIFOEMP jnz pkt_saveptrs_check_status;
  1930. /*
  1931. * Keep a handler around for this FIFO until it drains
  1932. * to the host to guarantee that we don't complete the
  1933. * command to the host before the data arrives.
  1934. */
  1935. pkt_saveptrs_wait_fifoemp:
  1936. call setjmp;
  1937. test DFSTATUS, FIFOEMP jz return;
  1938. pkt_saveptrs_check_status:
  1939. or LONGJMP_ADDR[1], INVALID_ADDR;
  1940. test REG0, SAVEPTRS jz unexpected_nonpkt_phase;
  1941. dec SCB_FIFO_USE_COUNT;
  1942. test SCB_CONTROL, STATUS_RCVD jnz pkt_complete_scb_if_fifos_idle;
  1943. mvi DFFSXFRCTL, CLRCHN ret;
  1944. /*
  1945. * LAST_SEG_DONE status has been seen in the current FIFO.
  1946. * This indicates that all of the allowed data for this
  1947. * command has transferred across the SCSI and host buses.
  1948. * Check for overrun and see if we can complete this command.
  1949. */
  1950. pkt_last_seg_done:
  1951. /*
  1952. * Mark transfer as completed.
  1953. */
  1954. or SCB_SGPTR, SG_LIST_NULL;
  1955. /*
  1956. * Wait for the current context to finish to verify that
  1957. * no overrun condition has occurred.
  1958. */
  1959. test SEQINTSRC, CTXTDONE jnz pkt_ctxt_done;
  1960. call setjmp;
  1961. pkt_wait_ctxt_done_loop:
  1962. test SEQINTSRC, CTXTDONE jnz pkt_ctxt_done;
  1963. /*
  1964. * A sufficiently large overrun or a NONPACKREQ may
  1965. * prevent CTXTDONE from ever asserting, so we must
  1966. * poll for these statuses too.
  1967. */
  1968. check_overrun;
  1969. test SSTAT2, NONPACKREQ jz return;
  1970. test SEQINTSRC, CTXTDONE jz unexpected_nonpkt_phase;
  1971. /* FALLTHROUGH */
  1972. pkt_ctxt_done:
  1973. check_overrun;
  1974. or LONGJMP_ADDR[1], INVALID_ADDR;
  1975. /*
  1976. * If status has been received, it is safe to skip
  1977. * the check to see if another FIFO is active because
  1978. * LAST_SEG_DONE has been observed. However, we check
  1979. * the FIFO anyway since it costs us only one extra
  1980. * instruction to leverage common code to perform the
  1981. * SCB completion.
  1982. */
  1983. dec SCB_FIFO_USE_COUNT;
  1984. test SCB_CONTROL, STATUS_RCVD jnz pkt_complete_scb_if_fifos_idle;
  1985. mvi DFFSXFRCTL, CLRCHN ret;
  1986. END_CRITICAL;
  1987. /*
  1988. * Must wait until CDB xfer is over before issuing the
  1989. * clear channel.
  1990. */
  1991. pkt_handle_cdb:
  1992. call setjmp;
  1993. test SG_CACHE_SHADOW, LAST_SEG_DONE jz return;
  1994. or LONGJMP_ADDR[1], INVALID_ADDR;
  1995. mvi DFFSXFRCTL, CLRCHN ret;
  1996. /*
  1997. * Watch over the status transfer. Our host sense buffer is
  1998. * large enough to take the maximum allowed status packet.
  1999. * None-the-less, we must still catch and report overruns to
  2000. * the host. Additionally, properly catch unexpected non-packet
  2001. * phases that are typically caused by CRC errors in status packet
  2002. * transmission.
  2003. */
  2004. pkt_handle_status:
  2005. call setjmp;
  2006. test SG_CACHE_SHADOW, LAST_SEG_DONE jnz pkt_status_check_overrun;
  2007. test SEQINTSRC, CTXTDONE jz pkt_status_check_nonpackreq;
  2008. test SG_CACHE_SHADOW, LAST_SEG_DONE jnz pkt_status_check_overrun;
  2009. pkt_status_IU_done:
  2010. if ((ahd->bugs & AHD_AUTOFLUSH_BUG) != 0) {
  2011. or DFCNTRL, FIFOFLUSH;
  2012. }
  2013. test DFSTATUS, FIFOEMP jz return;
  2014. BEGIN_CRITICAL;
  2015. or LONGJMP_ADDR[1], INVALID_ADDR;
  2016. mvi SCB_SCSI_STATUS, STATUS_PKT_SENSE;
  2017. or SCB_CONTROL, STATUS_RCVD;
  2018. jmp pkt_complete_scb_if_fifos_idle;
  2019. END_CRITICAL;
  2020. pkt_status_check_overrun:
  2021. /*
  2022. * Status PKT overruns are uncerimoniously recovered with a
  2023. * bus reset. If we've overrun, let the host know so that
  2024. * recovery can be performed.
  2025. *
  2026. * LAST_SEG_DONE has been observed. If either CTXTDONE or
  2027. * a NONPACKREQ phase change have occurred and the FIFO is
  2028. * empty, there is no overrun.
  2029. */
  2030. test DFSTATUS, FIFOEMP jz pkt_status_report_overrun;
  2031. test SEQINTSRC, CTXTDONE jz . + 2;
  2032. test DFSTATUS, FIFOEMP jnz pkt_status_IU_done;
  2033. test SCSIPHASE, ~DATA_PHASE_MASK jz return;
  2034. test DFSTATUS, FIFOEMP jnz pkt_status_check_nonpackreq;
  2035. pkt_status_report_overrun:
  2036. SET_SEQINTCODE(STATUS_OVERRUN)
  2037. /* SEQUENCER RESTARTED */
  2038. pkt_status_check_nonpackreq:
  2039. /*
  2040. * CTXTDONE may be held off if a NONPACKREQ is associated with
  2041. * the current context. If a NONPACKREQ is observed, decide
  2042. * if it is for the current context. If it is for the current
  2043. * context, we must defer NONPACKREQ processing until all data
  2044. * has transferred to the host.
  2045. */
  2046. test SCSIPHASE, ~DATA_PHASE_MASK jz return;
  2047. test SCSISIGO, ATNO jnz . + 2;
  2048. test SSTAT2, NONPACKREQ jz return;
  2049. test SEQINTSRC, CTXTDONE jnz pkt_status_IU_done;
  2050. test DFSTATUS, FIFOEMP jz return;
  2051. /*
  2052. * The unexpected nonpkt phase handler assumes that any
  2053. * data channel use will have a FIFO reference count. It
  2054. * turns out that the status handler doesn't need a references
  2055. * count since the status received flag, and thus completion
  2056. * processing, cannot be set until the handler is finished.
  2057. * We increment the count here to make the nonpkt handler
  2058. * happy.
  2059. */
  2060. inc SCB_FIFO_USE_COUNT;
  2061. /* FALLTHROUGH */
  2062. /*
  2063. * Nonpackreq is a polled status. It can come true in three situations:
  2064. * we have received an L_Q, we have sent one or more L_Qs, or there is no
  2065. * L_Q context associated with this REQ (REQ occurs immediately after a
  2066. * (re)selection). Routines that know that the context responsible for this
  2067. * nonpackreq call directly into unexpected_nonpkt_phase. In the case of the
  2068. * top level idle loop, we exhaust all active contexts prior to determining that
  2069. * we simply do not have the full I_T_L_Q for this phase.
  2070. */
  2071. unexpected_nonpkt_phase_find_ctxt:
  2072. /*
  2073. * This nonpackreq is most likely associated with one of the tags
  2074. * in a FIFO or an outgoing LQ. Only treat it as an I_T only
  2075. * nonpackreq if we've cleared out the FIFOs and handled any
  2076. * pending SELDO.
  2077. */
  2078. SET_SRC_MODE M_SCSI;
  2079. SET_DST_MODE M_SCSI;
  2080. and A, FIFO1FREE|FIFO0FREE, DFFSTAT;
  2081. cmp A, FIFO1FREE|FIFO0FREE jne return;
  2082. test SSTAT0, SELDO jnz return;
  2083. mvi SCBPTR[1], SCB_LIST_NULL;
  2084. unexpected_nonpkt_phase:
  2085. test MODE_PTR, ~(MK_MODE(M_DFF1, M_DFF1))
  2086. jnz unexpected_nonpkt_mode_cleared;
  2087. SET_SRC_MODE M_DFF0;
  2088. SET_DST_MODE M_DFF0;
  2089. or LONGJMP_ADDR[1], INVALID_ADDR;
  2090. dec SCB_FIFO_USE_COUNT;
  2091. mvi DFFSXFRCTL, CLRCHN;
  2092. unexpected_nonpkt_mode_cleared:
  2093. mvi CLRSINT2, CLRNONPACKREQ;
  2094. if ((ahd->bugs & AHD_BUSFREEREV_BUG) != 0) {
  2095. /*
  2096. * Test to ensure that the bus has not
  2097. * already gone free prior to clearing
  2098. * any stale busfree status. This avoids
  2099. * a window whereby a busfree just after
  2100. * a selection could be missed.
  2101. */
  2102. test SCSISIGI, BSYI jz . + 2;
  2103. mvi CLRSINT1,CLRBUSFREE;
  2104. or SIMODE1, ENBUSFREE;
  2105. }
  2106. test SCSIPHASE, ~(MSG_IN_PHASE|MSG_OUT_PHASE) jnz illegal_phase;
  2107. SET_SEQINTCODE(ENTERING_NONPACK)
  2108. jmp ITloop;
  2109. illegal_phase:
  2110. SET_SEQINTCODE(ILLEGAL_PHASE)
  2111. jmp ITloop;
  2112. /*
  2113. * We have entered an overrun situation. If we have working
  2114. * BITBUCKET, flip that on and let the hardware eat any overrun
  2115. * data. Otherwise use an overrun buffer in the host to simulate
  2116. * BITBUCKET.
  2117. */
  2118. pkt_handle_overrun_inc_use_count:
  2119. inc SCB_FIFO_USE_COUNT;
  2120. pkt_handle_overrun:
  2121. SET_SEQINTCODE(CFG4OVERRUN)
  2122. call freeze_queue;
  2123. if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) == 0) {
  2124. or DFFSXFRCTL, DFFBITBUCKET;
  2125. SET_SRC_MODE M_DFF1;
  2126. SET_DST_MODE M_DFF1;
  2127. } else {
  2128. call load_overrun_buf;
  2129. mvi DFCNTRL, (HDMAEN|SCSIEN|PRELOADEN);
  2130. }
  2131. call setjmp;
  2132. if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
  2133. test DFSTATUS, PRELOAD_AVAIL jz overrun_load_done;
  2134. call load_overrun_buf;
  2135. or DFCNTRL, PRELOADEN;
  2136. overrun_load_done:
  2137. test SEQINTSRC, CTXTDONE jnz pkt_overrun_end;
  2138. } else {
  2139. test DFFSXFRCTL, DFFBITBUCKET jz pkt_overrun_end;
  2140. }
  2141. test SSTAT2, NONPACKREQ jz return;
  2142. pkt_overrun_end:
  2143. or SCB_RESIDUAL_SGPTR, SG_OVERRUN_RESID;
  2144. test SEQINTSRC, CTXTDONE jz unexpected_nonpkt_phase;
  2145. dec SCB_FIFO_USE_COUNT;
  2146. or LONGJMP_ADDR[1], INVALID_ADDR;
  2147. test SCB_CONTROL, STATUS_RCVD jnz pkt_complete_scb_if_fifos_idle;
  2148. mvi DFFSXFRCTL, CLRCHN ret;
  2149. if ((ahd->bugs & AHD_PKT_BITBUCKET_BUG) != 0) {
  2150. load_overrun_buf:
  2151. /*
  2152. * Load a dummy segment if preload space is available.
  2153. */
  2154. mov HADDR[0], SHARED_DATA_ADDR;
  2155. add HADDR[1], PKT_OVERRUN_BUFOFFSET, SHARED_DATA_ADDR[1];
  2156. mov ACCUM_SAVE, A;
  2157. clr A;
  2158. adc HADDR[2], A, SHARED_DATA_ADDR[2];
  2159. adc HADDR[3], A, SHARED_DATA_ADDR[3];
  2160. mov A, ACCUM_SAVE;
  2161. bmov HADDR[4], ALLZEROS, 4;
  2162. /* PKT_OVERRUN_BUFSIZE is a multiple of 256 */
  2163. clr HCNT[0];
  2164. mvi HCNT[1], ((PKT_OVERRUN_BUFSIZE >> 8) & 0xFF);
  2165. clr HCNT[2] ret;
  2166. }