aic79xx.seq 71 KB

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