aic79xx.seq 68 KB

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