aic79xx.seq 64 KB

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