sym_fw2.h 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  1. /*
  2. * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
  3. * of PCI-SCSI IO processors.
  4. *
  5. * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
  6. *
  7. * This driver is derived from the Linux sym53c8xx driver.
  8. * Copyright (C) 1998-2000 Gerard Roudier
  9. *
  10. * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
  11. * a port of the FreeBSD ncr driver to Linux-1.2.13.
  12. *
  13. * The original ncr driver has been written for 386bsd and FreeBSD by
  14. * Wolfgang Stanglmeier <wolf@cologne.de>
  15. * Stefan Esser <se@mi.Uni-Koeln.de>
  16. * Copyright (C) 1994 Wolfgang Stanglmeier
  17. *
  18. * Other major contributions:
  19. *
  20. * NVRAM detection and reading.
  21. * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
  22. *
  23. *-----------------------------------------------------------------------------
  24. *
  25. * This program is free software; you can redistribute it and/or modify
  26. * it under the terms of the GNU General Public License as published by
  27. * the Free Software Foundation; either version 2 of the License, or
  28. * (at your option) any later version.
  29. *
  30. * This program is distributed in the hope that it will be useful,
  31. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33. * GNU General Public License for more details.
  34. *
  35. * You should have received a copy of the GNU General Public License
  36. * along with this program; if not, write to the Free Software
  37. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  38. */
  39. /*
  40. * Scripts for SYMBIOS-Processor
  41. *
  42. * We have to know the offsets of all labels before we reach
  43. * them (for forward jumps). Therefore we declare a struct
  44. * here. If you make changes inside the script,
  45. *
  46. * DONT FORGET TO CHANGE THE LENGTHS HERE!
  47. */
  48. /*
  49. * Script fragments which are loaded into the on-chip RAM
  50. * of 825A, 875, 876, 895, 895A, 896 and 1010 chips.
  51. * Must not exceed 4K bytes.
  52. */
  53. struct SYM_FWA_SCR {
  54. u32 start [ 14];
  55. u32 getjob_begin [ 4];
  56. u32 getjob_end [ 4];
  57. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  58. u32 select [ 6];
  59. #else
  60. u32 select [ 4];
  61. #endif
  62. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  63. u32 is_dmap_dirty [ 4];
  64. #endif
  65. u32 wf_sel_done [ 2];
  66. u32 sel_done [ 2];
  67. u32 send_ident [ 2];
  68. #ifdef SYM_CONF_IARB_SUPPORT
  69. u32 select2 [ 8];
  70. #else
  71. u32 select2 [ 2];
  72. #endif
  73. u32 command [ 2];
  74. u32 dispatch [ 28];
  75. u32 sel_no_cmd [ 10];
  76. u32 init [ 6];
  77. u32 clrack [ 4];
  78. u32 datai_done [ 10];
  79. u32 datai_done_wsr [ 20];
  80. u32 datao_done [ 10];
  81. u32 datao_done_wss [ 6];
  82. u32 datai_phase [ 4];
  83. u32 datao_phase [ 6];
  84. u32 msg_in [ 2];
  85. u32 msg_in2 [ 10];
  86. #ifdef SYM_CONF_IARB_SUPPORT
  87. u32 status [ 14];
  88. #else
  89. u32 status [ 10];
  90. #endif
  91. u32 complete [ 6];
  92. u32 complete2 [ 12];
  93. u32 done [ 14];
  94. u32 done_end [ 2];
  95. u32 complete_error [ 4];
  96. u32 save_dp [ 12];
  97. u32 restore_dp [ 8];
  98. u32 disconnect [ 12];
  99. #ifdef SYM_CONF_IARB_SUPPORT
  100. u32 idle [ 4];
  101. #else
  102. u32 idle [ 2];
  103. #endif
  104. #ifdef SYM_CONF_IARB_SUPPORT
  105. u32 ungetjob [ 6];
  106. #else
  107. u32 ungetjob [ 4];
  108. #endif
  109. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  110. u32 reselect [ 4];
  111. #else
  112. u32 reselect [ 2];
  113. #endif
  114. u32 reselected [ 22];
  115. u32 resel_scntl4 [ 20];
  116. u32 resel_lun0 [ 6];
  117. #if SYM_CONF_MAX_TASK*4 > 512
  118. u32 resel_tag [ 26];
  119. #elif SYM_CONF_MAX_TASK*4 > 256
  120. u32 resel_tag [ 20];
  121. #else
  122. u32 resel_tag [ 16];
  123. #endif
  124. u32 resel_dsa [ 2];
  125. u32 resel_dsa1 [ 4];
  126. u32 resel_no_tag [ 6];
  127. u32 data_in [SYM_CONF_MAX_SG * 2];
  128. u32 data_in2 [ 4];
  129. u32 data_out [SYM_CONF_MAX_SG * 2];
  130. u32 data_out2 [ 4];
  131. u32 pm0_data [ 12];
  132. u32 pm0_data_out [ 6];
  133. u32 pm0_data_end [ 6];
  134. u32 pm1_data [ 12];
  135. u32 pm1_data_out [ 6];
  136. u32 pm1_data_end [ 6];
  137. };
  138. /*
  139. * Script fragments which stay in main memory for all chips
  140. * except for chips that support 8K on-chip RAM.
  141. */
  142. struct SYM_FWB_SCR {
  143. u32 start64 [ 2];
  144. u32 no_data [ 2];
  145. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  146. u32 sel_for_abort [ 18];
  147. #else
  148. u32 sel_for_abort [ 16];
  149. #endif
  150. u32 sel_for_abort_1 [ 2];
  151. u32 msg_in_etc [ 12];
  152. u32 msg_received [ 4];
  153. u32 msg_weird_seen [ 4];
  154. u32 msg_extended [ 20];
  155. u32 msg_bad [ 6];
  156. u32 msg_weird [ 4];
  157. u32 msg_weird1 [ 8];
  158. u32 wdtr_resp [ 6];
  159. u32 send_wdtr [ 4];
  160. u32 sdtr_resp [ 6];
  161. u32 send_sdtr [ 4];
  162. u32 ppr_resp [ 6];
  163. u32 send_ppr [ 4];
  164. u32 nego_bad_phase [ 4];
  165. u32 msg_out [ 4];
  166. u32 msg_out_done [ 4];
  167. u32 data_ovrun [ 2];
  168. u32 data_ovrun1 [ 22];
  169. u32 data_ovrun2 [ 8];
  170. u32 abort_resel [ 16];
  171. u32 resend_ident [ 4];
  172. u32 ident_break [ 4];
  173. u32 ident_break_atn [ 4];
  174. u32 sdata_in [ 6];
  175. u32 resel_bad_lun [ 4];
  176. u32 bad_i_t_l [ 4];
  177. u32 bad_i_t_l_q [ 4];
  178. u32 bad_status [ 6];
  179. u32 pm_handle [ 20];
  180. u32 pm_handle1 [ 4];
  181. u32 pm_save [ 4];
  182. u32 pm0_save [ 12];
  183. u32 pm_save_end [ 4];
  184. u32 pm1_save [ 14];
  185. /* WSR handling */
  186. u32 pm_wsr_handle [ 38];
  187. u32 wsr_ma_helper [ 4];
  188. #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
  189. /* Unknown direction handling */
  190. u32 data_io [ 2];
  191. u32 data_io_in [ 2];
  192. u32 data_io_com [ 6];
  193. u32 data_io_out [ 8];
  194. #endif
  195. /* Data area */
  196. u32 zero [ 1];
  197. u32 scratch [ 1];
  198. u32 pm0_data_addr [ 1];
  199. u32 pm1_data_addr [ 1];
  200. u32 done_pos [ 1];
  201. u32 startpos [ 1];
  202. u32 targtbl [ 1];
  203. };
  204. /*
  205. * Script fragments used at initialisations.
  206. * Only runs out of main memory.
  207. */
  208. struct SYM_FWZ_SCR {
  209. u32 snooptest [ 6];
  210. u32 snoopend [ 2];
  211. };
  212. static struct SYM_FWA_SCR SYM_FWA_SCR = {
  213. /*--------------------------< START >----------------------------*/ {
  214. /*
  215. * Switch the LED on.
  216. * Will be patched with a NO_OP if LED
  217. * not needed or not desired.
  218. */
  219. SCR_REG_REG (gpreg, SCR_AND, 0xfe),
  220. 0,
  221. /*
  222. * Clear SIGP.
  223. */
  224. SCR_FROM_REG (ctest2),
  225. 0,
  226. /*
  227. * Stop here if the C code wants to perform
  228. * some error recovery procedure manually.
  229. * (Indicate this by setting SEM in ISTAT)
  230. */
  231. SCR_FROM_REG (istat),
  232. 0,
  233. /*
  234. * Report to the C code the next position in
  235. * the start queue the SCRIPTS will schedule.
  236. * The C code must not change SCRATCHA.
  237. */
  238. SCR_LOAD_ABS (scratcha, 4),
  239. PADDR_B (startpos),
  240. SCR_INT ^ IFTRUE (MASK (SEM, SEM)),
  241. SIR_SCRIPT_STOPPED,
  242. /*
  243. * Start the next job.
  244. *
  245. * @DSA = start point for this job.
  246. * SCRATCHA = address of this job in the start queue.
  247. *
  248. * We will restore startpos with SCRATCHA if we fails the
  249. * arbitration or if it is the idle job.
  250. *
  251. * The below GETJOB_BEGIN to GETJOB_END section of SCRIPTS
  252. * is a critical path. If it is partially executed, it then
  253. * may happen that the job address is not yet in the DSA
  254. * and the next queue position points to the next JOB.
  255. */
  256. SCR_LOAD_ABS (dsa, 4),
  257. PADDR_B (startpos),
  258. SCR_LOAD_REL (temp, 4),
  259. 4,
  260. }/*-------------------------< GETJOB_BEGIN >---------------------*/,{
  261. SCR_STORE_ABS (temp, 4),
  262. PADDR_B (startpos),
  263. SCR_LOAD_REL (dsa, 4),
  264. 0,
  265. }/*-------------------------< GETJOB_END >-----------------------*/,{
  266. SCR_LOAD_REL (temp, 4),
  267. 0,
  268. SCR_RETURN,
  269. 0,
  270. }/*-------------------------< SELECT >---------------------------*/,{
  271. /*
  272. * DSA contains the address of a scheduled
  273. * data structure.
  274. *
  275. * SCRATCHA contains the address of the start queue
  276. * entry which points to the next job.
  277. *
  278. * Set Initiator mode.
  279. *
  280. * (Target mode is left as an exercise for the reader)
  281. */
  282. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  283. SCR_CLR (SCR_TRG),
  284. 0,
  285. #endif
  286. /*
  287. * And try to select this target.
  288. */
  289. SCR_SEL_TBL_ATN ^ offsetof (struct sym_dsb, select),
  290. PADDR_A (ungetjob),
  291. /*
  292. * Now there are 4 possibilities:
  293. *
  294. * (1) The chip loses arbitration.
  295. * This is ok, because it will try again,
  296. * when the bus becomes idle.
  297. * (But beware of the timeout function!)
  298. *
  299. * (2) The chip is reselected.
  300. * Then the script processor takes the jump
  301. * to the RESELECT label.
  302. *
  303. * (3) The chip wins arbitration.
  304. * Then it will execute SCRIPTS instruction until
  305. * the next instruction that checks SCSI phase.
  306. * Then will stop and wait for selection to be
  307. * complete or selection time-out to occur.
  308. *
  309. * After having won arbitration, the SCRIPTS
  310. * processor is able to execute instructions while
  311. * the SCSI core is performing SCSI selection.
  312. */
  313. /*
  314. * Initialize the status registers
  315. */
  316. SCR_LOAD_REL (scr0, 4),
  317. offsetof (struct sym_ccb, phys.head.status),
  318. /*
  319. * We may need help from CPU if the DMA segment
  320. * registers aren't up-to-date for this IO.
  321. * Patched with NOOP for chips that donnot
  322. * support DAC addressing.
  323. */
  324. #if SYM_CONF_DMA_ADDRESSING_MODE == 2
  325. }/*-------------------------< IS_DMAP_DIRTY >--------------------*/,{
  326. SCR_FROM_REG (HX_REG),
  327. 0,
  328. SCR_INT ^ IFTRUE (MASK (HX_DMAP_DIRTY, HX_DMAP_DIRTY)),
  329. SIR_DMAP_DIRTY,
  330. #endif
  331. }/*-------------------------< WF_SEL_DONE >----------------------*/,{
  332. SCR_INT ^ IFFALSE (WHEN (SCR_MSG_OUT)),
  333. SIR_SEL_ATN_NO_MSG_OUT,
  334. }/*-------------------------< SEL_DONE >-------------------------*/,{
  335. /*
  336. * C1010-33 errata work-around.
  337. * Due to a race, the SCSI core may not have
  338. * loaded SCNTL3 on SEL_TBL instruction.
  339. * We reload it once phase is stable.
  340. * Patched with a NOOP for other chips.
  341. */
  342. SCR_LOAD_REL (scntl3, 1),
  343. offsetof(struct sym_dsb, select.sel_scntl3),
  344. }/*-------------------------< SEND_IDENT >-----------------------*/,{
  345. /*
  346. * Selection complete.
  347. * Send the IDENTIFY and possibly the TAG message
  348. * and negotiation message if present.
  349. */
  350. SCR_MOVE_TBL ^ SCR_MSG_OUT,
  351. offsetof (struct sym_dsb, smsg),
  352. }/*-------------------------< SELECT2 >--------------------------*/,{
  353. #ifdef SYM_CONF_IARB_SUPPORT
  354. /*
  355. * Set IMMEDIATE ARBITRATION if we have been given
  356. * a hint to do so. (Some job to do after this one).
  357. */
  358. SCR_FROM_REG (HF_REG),
  359. 0,
  360. SCR_JUMPR ^ IFFALSE (MASK (HF_HINT_IARB, HF_HINT_IARB)),
  361. 8,
  362. SCR_REG_REG (scntl1, SCR_OR, IARB),
  363. 0,
  364. #endif
  365. /*
  366. * Anticipate the COMMAND phase.
  367. * This is the PHASE we expect at this point.
  368. */
  369. SCR_JUMP ^ IFFALSE (WHEN (SCR_COMMAND)),
  370. PADDR_A (sel_no_cmd),
  371. }/*-------------------------< COMMAND >--------------------------*/,{
  372. /*
  373. * ... and send the command
  374. */
  375. SCR_MOVE_TBL ^ SCR_COMMAND,
  376. offsetof (struct sym_dsb, cmd),
  377. }/*-------------------------< DISPATCH >-------------------------*/,{
  378. /*
  379. * MSG_IN is the only phase that shall be
  380. * entered at least once for each (re)selection.
  381. * So we test it first.
  382. */
  383. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
  384. PADDR_A (msg_in),
  385. SCR_JUMP ^ IFTRUE (IF (SCR_DATA_OUT)),
  386. PADDR_A (datao_phase),
  387. SCR_JUMP ^ IFTRUE (IF (SCR_DATA_IN)),
  388. PADDR_A (datai_phase),
  389. SCR_JUMP ^ IFTRUE (IF (SCR_STATUS)),
  390. PADDR_A (status),
  391. SCR_JUMP ^ IFTRUE (IF (SCR_COMMAND)),
  392. PADDR_A (command),
  393. SCR_JUMP ^ IFTRUE (IF (SCR_MSG_OUT)),
  394. PADDR_B (msg_out),
  395. /*
  396. * Discard as many illegal phases as
  397. * required and tell the C code about.
  398. */
  399. SCR_JUMPR ^ IFFALSE (WHEN (SCR_ILG_OUT)),
  400. 16,
  401. SCR_MOVE_ABS (1) ^ SCR_ILG_OUT,
  402. HADDR_1 (scratch),
  403. SCR_JUMPR ^ IFTRUE (WHEN (SCR_ILG_OUT)),
  404. -16,
  405. SCR_JUMPR ^ IFFALSE (WHEN (SCR_ILG_IN)),
  406. 16,
  407. SCR_MOVE_ABS (1) ^ SCR_ILG_IN,
  408. HADDR_1 (scratch),
  409. SCR_JUMPR ^ IFTRUE (WHEN (SCR_ILG_IN)),
  410. -16,
  411. SCR_INT,
  412. SIR_BAD_PHASE,
  413. SCR_JUMP,
  414. PADDR_A (dispatch),
  415. }/*-------------------------< SEL_NO_CMD >-----------------------*/,{
  416. /*
  417. * The target does not switch to command
  418. * phase after IDENTIFY has been sent.
  419. *
  420. * If it stays in MSG OUT phase send it
  421. * the IDENTIFY again.
  422. */
  423. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
  424. PADDR_B (resend_ident),
  425. /*
  426. * If target does not switch to MSG IN phase
  427. * and we sent a negotiation, assert the
  428. * failure immediately.
  429. */
  430. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
  431. PADDR_A (dispatch),
  432. SCR_FROM_REG (HS_REG),
  433. 0,
  434. SCR_INT ^ IFTRUE (DATA (HS_NEGOTIATE)),
  435. SIR_NEGO_FAILED,
  436. /*
  437. * Jump to dispatcher.
  438. */
  439. SCR_JUMP,
  440. PADDR_A (dispatch),
  441. }/*-------------------------< INIT >-----------------------------*/,{
  442. /*
  443. * Wait for the SCSI RESET signal to be
  444. * inactive before restarting operations,
  445. * since the chip may hang on SEL_ATN
  446. * if SCSI RESET is active.
  447. */
  448. SCR_FROM_REG (sstat0),
  449. 0,
  450. SCR_JUMPR ^ IFTRUE (MASK (IRST, IRST)),
  451. -16,
  452. SCR_JUMP,
  453. PADDR_A (start),
  454. }/*-------------------------< CLRACK >---------------------------*/,{
  455. /*
  456. * Terminate possible pending message phase.
  457. */
  458. SCR_CLR (SCR_ACK),
  459. 0,
  460. SCR_JUMP,
  461. PADDR_A (dispatch),
  462. }/*-------------------------< DATAI_DONE >-----------------------*/,{
  463. /*
  464. * Save current pointer to LASTP.
  465. */
  466. SCR_STORE_REL (temp, 4),
  467. offsetof (struct sym_ccb, phys.head.lastp),
  468. /*
  469. * If the SWIDE is not full, jump to dispatcher.
  470. * We anticipate a STATUS phase.
  471. */
  472. SCR_FROM_REG (scntl2),
  473. 0,
  474. SCR_JUMP ^ IFTRUE (MASK (WSR, WSR)),
  475. PADDR_A (datai_done_wsr),
  476. SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)),
  477. PADDR_A (status),
  478. SCR_JUMP,
  479. PADDR_A (dispatch),
  480. }/*-------------------------< DATAI_DONE_WSR >-------------------*/,{
  481. /*
  482. * The SWIDE is full.
  483. * Clear this condition.
  484. */
  485. SCR_REG_REG (scntl2, SCR_OR, WSR),
  486. 0,
  487. /*
  488. * We are expecting an IGNORE RESIDUE message
  489. * from the device, otherwise we are in data
  490. * overrun condition. Check against MSG_IN phase.
  491. */
  492. SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
  493. SIR_SWIDE_OVERRUN,
  494. SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
  495. PADDR_A (dispatch),
  496. /*
  497. * We are in MSG_IN phase,
  498. * Read the first byte of the message.
  499. * If it is not an IGNORE RESIDUE message,
  500. * signal overrun and jump to message
  501. * processing.
  502. */
  503. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  504. HADDR_1 (msgin[0]),
  505. SCR_INT ^ IFFALSE (DATA (M_IGN_RESIDUE)),
  506. SIR_SWIDE_OVERRUN,
  507. SCR_JUMP ^ IFFALSE (DATA (M_IGN_RESIDUE)),
  508. PADDR_A (msg_in2),
  509. /*
  510. * We got the message we expected.
  511. * Read the 2nd byte, and jump to dispatcher.
  512. */
  513. SCR_CLR (SCR_ACK),
  514. 0,
  515. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  516. HADDR_1 (msgin[1]),
  517. SCR_CLR (SCR_ACK),
  518. 0,
  519. SCR_JUMP,
  520. PADDR_A (dispatch),
  521. }/*-------------------------< DATAO_DONE >-----------------------*/,{
  522. /*
  523. * Save current pointer to LASTP.
  524. */
  525. SCR_STORE_REL (temp, 4),
  526. offsetof (struct sym_ccb, phys.head.lastp),
  527. /*
  528. * If the SODL is not full jump to dispatcher.
  529. * We anticipate a STATUS phase.
  530. */
  531. SCR_FROM_REG (scntl2),
  532. 0,
  533. SCR_JUMP ^ IFTRUE (MASK (WSS, WSS)),
  534. PADDR_A (datao_done_wss),
  535. SCR_JUMP ^ IFTRUE (WHEN (SCR_STATUS)),
  536. PADDR_A (status),
  537. SCR_JUMP,
  538. PADDR_A (dispatch),
  539. }/*-------------------------< DATAO_DONE_WSS >-------------------*/,{
  540. /*
  541. * The SODL is full, clear this condition.
  542. */
  543. SCR_REG_REG (scntl2, SCR_OR, WSS),
  544. 0,
  545. /*
  546. * And signal a DATA UNDERRUN condition
  547. * to the C code.
  548. */
  549. SCR_INT,
  550. SIR_SODL_UNDERRUN,
  551. SCR_JUMP,
  552. PADDR_A (dispatch),
  553. }/*-------------------------< DATAI_PHASE >----------------------*/,{
  554. /*
  555. * Jump to current pointer.
  556. */
  557. SCR_LOAD_REL (temp, 4),
  558. offsetof (struct sym_ccb, phys.head.lastp),
  559. SCR_RETURN,
  560. 0,
  561. }/*-------------------------< DATAO_PHASE >----------------------*/,{
  562. /*
  563. * C1010-66 errata work-around.
  564. * Extra clocks of data hold must be inserted
  565. * in DATA OUT phase on 33 MHz PCI BUS.
  566. * Patched with a NOOP for other chips.
  567. */
  568. SCR_REG_REG (scntl4, SCR_OR, (XCLKH_DT|XCLKH_ST)),
  569. 0,
  570. /*
  571. * Jump to current pointer.
  572. */
  573. SCR_LOAD_REL (temp, 4),
  574. offsetof (struct sym_ccb, phys.head.lastp),
  575. SCR_RETURN,
  576. 0,
  577. }/*-------------------------< MSG_IN >---------------------------*/,{
  578. /*
  579. * Get the first byte of the message.
  580. *
  581. * The script processor doesn't negate the
  582. * ACK signal after this transfer.
  583. */
  584. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  585. HADDR_1 (msgin[0]),
  586. }/*-------------------------< MSG_IN2 >--------------------------*/,{
  587. /*
  588. * Check first against 1 byte messages
  589. * that we handle from SCRIPTS.
  590. */
  591. SCR_JUMP ^ IFTRUE (DATA (M_COMPLETE)),
  592. PADDR_A (complete),
  593. SCR_JUMP ^ IFTRUE (DATA (M_DISCONNECT)),
  594. PADDR_A (disconnect),
  595. SCR_JUMP ^ IFTRUE (DATA (M_SAVE_DP)),
  596. PADDR_A (save_dp),
  597. SCR_JUMP ^ IFTRUE (DATA (M_RESTORE_DP)),
  598. PADDR_A (restore_dp),
  599. /*
  600. * We handle all other messages from the
  601. * C code, so no need to waste on-chip RAM
  602. * for those ones.
  603. */
  604. SCR_JUMP,
  605. PADDR_B (msg_in_etc),
  606. }/*-------------------------< STATUS >---------------------------*/,{
  607. /*
  608. * get the status
  609. */
  610. SCR_MOVE_ABS (1) ^ SCR_STATUS,
  611. HADDR_1 (scratch),
  612. #ifdef SYM_CONF_IARB_SUPPORT
  613. /*
  614. * If STATUS is not GOOD, clear IMMEDIATE ARBITRATION,
  615. * since we may have to tamper the start queue from
  616. * the C code.
  617. */
  618. SCR_JUMPR ^ IFTRUE (DATA (S_GOOD)),
  619. 8,
  620. SCR_REG_REG (scntl1, SCR_AND, ~IARB),
  621. 0,
  622. #endif
  623. /*
  624. * save status to scsi_status.
  625. * mark as complete.
  626. */
  627. SCR_TO_REG (SS_REG),
  628. 0,
  629. SCR_LOAD_REG (HS_REG, HS_COMPLETE),
  630. 0,
  631. /*
  632. * Anticipate the MESSAGE PHASE for
  633. * the TASK COMPLETE message.
  634. */
  635. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
  636. PADDR_A (msg_in),
  637. SCR_JUMP,
  638. PADDR_A (dispatch),
  639. }/*-------------------------< COMPLETE >-------------------------*/,{
  640. /*
  641. * Complete message.
  642. *
  643. * When we terminate the cycle by clearing ACK,
  644. * the target may disconnect immediately.
  645. *
  646. * We don't want to be told of an "unexpected disconnect",
  647. * so we disable this feature.
  648. */
  649. SCR_REG_REG (scntl2, SCR_AND, 0x7f),
  650. 0,
  651. /*
  652. * Terminate cycle ...
  653. */
  654. SCR_CLR (SCR_ACK|SCR_ATN),
  655. 0,
  656. /*
  657. * ... and wait for the disconnect.
  658. */
  659. SCR_WAIT_DISC,
  660. 0,
  661. }/*-------------------------< COMPLETE2 >------------------------*/,{
  662. /*
  663. * Save host status.
  664. */
  665. SCR_STORE_REL (scr0, 4),
  666. offsetof (struct sym_ccb, phys.head.status),
  667. /*
  668. * Some bridges may reorder DMA writes to memory.
  669. * We donnot want the CPU to deal with completions
  670. * without all the posted write having been flushed
  671. * to memory. This DUMMY READ should flush posted
  672. * buffers prior to the CPU having to deal with
  673. * completions.
  674. */
  675. SCR_LOAD_REL (scr0, 4), /* DUMMY READ */
  676. offsetof (struct sym_ccb, phys.head.status),
  677. /*
  678. * If command resulted in not GOOD status,
  679. * call the C code if needed.
  680. */
  681. SCR_FROM_REG (SS_REG),
  682. 0,
  683. SCR_CALL ^ IFFALSE (DATA (S_GOOD)),
  684. PADDR_B (bad_status),
  685. /*
  686. * If we performed an auto-sense, call
  687. * the C code to synchronyze task aborts
  688. * with UNIT ATTENTION conditions.
  689. */
  690. SCR_FROM_REG (HF_REG),
  691. 0,
  692. SCR_JUMP ^ IFFALSE (MASK (0 ,(HF_SENSE|HF_EXT_ERR))),
  693. PADDR_A (complete_error),
  694. }/*-------------------------< DONE >-----------------------------*/,{
  695. /*
  696. * Copy the DSA to the DONE QUEUE and
  697. * signal completion to the host.
  698. * If we are interrupted between DONE
  699. * and DONE_END, we must reset, otherwise
  700. * the completed CCB may be lost.
  701. */
  702. SCR_STORE_ABS (dsa, 4),
  703. PADDR_B (scratch),
  704. SCR_LOAD_ABS (dsa, 4),
  705. PADDR_B (done_pos),
  706. SCR_LOAD_ABS (scratcha, 4),
  707. PADDR_B (scratch),
  708. SCR_STORE_REL (scratcha, 4),
  709. 0,
  710. /*
  711. * The instruction below reads the DONE QUEUE next
  712. * free position from memory.
  713. * In addition it ensures that all PCI posted writes
  714. * are flushed and so the DSA value of the done
  715. * CCB is visible by the CPU before INTFLY is raised.
  716. */
  717. SCR_LOAD_REL (scratcha, 4),
  718. 4,
  719. SCR_INT_FLY,
  720. 0,
  721. SCR_STORE_ABS (scratcha, 4),
  722. PADDR_B (done_pos),
  723. }/*-------------------------< DONE_END >-------------------------*/,{
  724. SCR_JUMP,
  725. PADDR_A (start),
  726. }/*-------------------------< COMPLETE_ERROR >-------------------*/,{
  727. SCR_LOAD_ABS (scratcha, 4),
  728. PADDR_B (startpos),
  729. SCR_INT,
  730. SIR_COMPLETE_ERROR,
  731. }/*-------------------------< SAVE_DP >--------------------------*/,{
  732. /*
  733. * Clear ACK immediately.
  734. * No need to delay it.
  735. */
  736. SCR_CLR (SCR_ACK),
  737. 0,
  738. /*
  739. * Keep track we received a SAVE DP, so
  740. * we will switch to the other PM context
  741. * on the next PM since the DP may point
  742. * to the current PM context.
  743. */
  744. SCR_REG_REG (HF_REG, SCR_OR, HF_DP_SAVED),
  745. 0,
  746. /*
  747. * SAVE_DP message:
  748. * Copy LASTP to SAVEP.
  749. */
  750. SCR_LOAD_REL (scratcha, 4),
  751. offsetof (struct sym_ccb, phys.head.lastp),
  752. SCR_STORE_REL (scratcha, 4),
  753. offsetof (struct sym_ccb, phys.head.savep),
  754. /*
  755. * Anticipate the MESSAGE PHASE for
  756. * the DISCONNECT message.
  757. */
  758. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_IN)),
  759. PADDR_A (msg_in),
  760. SCR_JUMP,
  761. PADDR_A (dispatch),
  762. }/*-------------------------< RESTORE_DP >-----------------------*/,{
  763. /*
  764. * Clear ACK immediately.
  765. * No need to delay it.
  766. */
  767. SCR_CLR (SCR_ACK),
  768. 0,
  769. /*
  770. * Copy SAVEP to LASTP.
  771. */
  772. SCR_LOAD_REL (scratcha, 4),
  773. offsetof (struct sym_ccb, phys.head.savep),
  774. SCR_STORE_REL (scratcha, 4),
  775. offsetof (struct sym_ccb, phys.head.lastp),
  776. SCR_JUMP,
  777. PADDR_A (dispatch),
  778. }/*-------------------------< DISCONNECT >-----------------------*/,{
  779. /*
  780. * DISCONNECTing ...
  781. *
  782. * disable the "unexpected disconnect" feature,
  783. * and remove the ACK signal.
  784. */
  785. SCR_REG_REG (scntl2, SCR_AND, 0x7f),
  786. 0,
  787. SCR_CLR (SCR_ACK|SCR_ATN),
  788. 0,
  789. /*
  790. * Wait for the disconnect.
  791. */
  792. SCR_WAIT_DISC,
  793. 0,
  794. /*
  795. * Status is: DISCONNECTED.
  796. */
  797. SCR_LOAD_REG (HS_REG, HS_DISCONNECT),
  798. 0,
  799. /*
  800. * Save host status.
  801. */
  802. SCR_STORE_REL (scr0, 4),
  803. offsetof (struct sym_ccb, phys.head.status),
  804. SCR_JUMP,
  805. PADDR_A (start),
  806. }/*-------------------------< IDLE >-----------------------------*/,{
  807. /*
  808. * Nothing to do?
  809. * Switch the LED off and wait for reselect.
  810. * Will be patched with a NO_OP if LED
  811. * not needed or not desired.
  812. */
  813. SCR_REG_REG (gpreg, SCR_OR, 0x01),
  814. 0,
  815. #ifdef SYM_CONF_IARB_SUPPORT
  816. SCR_JUMPR,
  817. 8,
  818. #endif
  819. }/*-------------------------< UNGETJOB >-------------------------*/,{
  820. #ifdef SYM_CONF_IARB_SUPPORT
  821. /*
  822. * Set IMMEDIATE ARBITRATION, for the next time.
  823. * This will give us better chance to win arbitration
  824. * for the job we just wanted to do.
  825. */
  826. SCR_REG_REG (scntl1, SCR_OR, IARB),
  827. 0,
  828. #endif
  829. /*
  830. * We are not able to restart the SCRIPTS if we are
  831. * interrupted and these instruction haven't been
  832. * all executed. BTW, this is very unlikely to
  833. * happen, but we check that from the C code.
  834. */
  835. SCR_LOAD_REG (dsa, 0xff),
  836. 0,
  837. SCR_STORE_ABS (scratcha, 4),
  838. PADDR_B (startpos),
  839. }/*-------------------------< RESELECT >-------------------------*/,{
  840. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  841. /*
  842. * Make sure we are in initiator mode.
  843. */
  844. SCR_CLR (SCR_TRG),
  845. 0,
  846. #endif
  847. /*
  848. * Sleep waiting for a reselection.
  849. */
  850. SCR_WAIT_RESEL,
  851. PADDR_A(start),
  852. }/*-------------------------< RESELECTED >-----------------------*/,{
  853. /*
  854. * Switch the LED on.
  855. * Will be patched with a NO_OP if LED
  856. * not needed or not desired.
  857. */
  858. SCR_REG_REG (gpreg, SCR_AND, 0xfe),
  859. 0,
  860. /*
  861. * load the target id into the sdid
  862. */
  863. SCR_REG_SFBR (ssid, SCR_AND, 0x8F),
  864. 0,
  865. SCR_TO_REG (sdid),
  866. 0,
  867. /*
  868. * Load the target control block address
  869. */
  870. SCR_LOAD_ABS (dsa, 4),
  871. PADDR_B (targtbl),
  872. SCR_SFBR_REG (dsa, SCR_SHL, 0),
  873. 0,
  874. SCR_REG_REG (dsa, SCR_SHL, 0),
  875. 0,
  876. SCR_REG_REG (dsa, SCR_AND, 0x3c),
  877. 0,
  878. SCR_LOAD_REL (dsa, 4),
  879. 0,
  880. /*
  881. * We expect MESSAGE IN phase.
  882. * If not, get help from the C code.
  883. */
  884. SCR_INT ^ IFFALSE (WHEN (SCR_MSG_IN)),
  885. SIR_RESEL_NO_MSG_IN,
  886. /*
  887. * Load the legacy synchronous transfer registers.
  888. */
  889. SCR_LOAD_REL (scntl3, 1),
  890. offsetof(struct sym_tcb, head.wval),
  891. SCR_LOAD_REL (sxfer, 1),
  892. offsetof(struct sym_tcb, head.sval),
  893. }/*-------------------------< RESEL_SCNTL4 >---------------------*/,{
  894. /*
  895. * The C1010 uses a new synchronous timing scheme.
  896. * Will be patched with a NO_OP if not a C1010.
  897. */
  898. SCR_LOAD_REL (scntl4, 1),
  899. offsetof(struct sym_tcb, head.uval),
  900. /*
  901. * Get the IDENTIFY message.
  902. */
  903. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  904. HADDR_1 (msgin),
  905. /*
  906. * If IDENTIFY LUN #0, use a faster path
  907. * to find the LCB structure.
  908. */
  909. SCR_JUMP ^ IFTRUE (MASK (0x80, 0xbf)),
  910. PADDR_A (resel_lun0),
  911. /*
  912. * If message isn't an IDENTIFY,
  913. * tell the C code about.
  914. */
  915. SCR_INT ^ IFFALSE (MASK (0x80, 0x80)),
  916. SIR_RESEL_NO_IDENTIFY,
  917. /*
  918. * It is an IDENTIFY message,
  919. * Load the LUN control block address.
  920. */
  921. SCR_LOAD_REL (dsa, 4),
  922. offsetof(struct sym_tcb, head.luntbl_sa),
  923. SCR_SFBR_REG (dsa, SCR_SHL, 0),
  924. 0,
  925. SCR_REG_REG (dsa, SCR_SHL, 0),
  926. 0,
  927. SCR_REG_REG (dsa, SCR_AND, 0xfc),
  928. 0,
  929. SCR_LOAD_REL (dsa, 4),
  930. 0,
  931. SCR_JUMPR,
  932. 8,
  933. }/*-------------------------< RESEL_LUN0 >-----------------------*/,{
  934. /*
  935. * LUN 0 special case (but usual one :))
  936. */
  937. SCR_LOAD_REL (dsa, 4),
  938. offsetof(struct sym_tcb, head.lun0_sa),
  939. /*
  940. * Jump indirectly to the reselect action for this LUN.
  941. */
  942. SCR_LOAD_REL (temp, 4),
  943. offsetof(struct sym_lcb, head.resel_sa),
  944. SCR_RETURN,
  945. 0,
  946. /* In normal situations, we jump to RESEL_TAG or RESEL_NO_TAG */
  947. }/*-------------------------< RESEL_TAG >------------------------*/,{
  948. /*
  949. * ACK the IDENTIFY previously received.
  950. */
  951. SCR_CLR (SCR_ACK),
  952. 0,
  953. /*
  954. * It shall be a tagged command.
  955. * Read SIMPLE+TAG.
  956. * The C code will deal with errors.
  957. * Agressive optimization, is'nt it? :)
  958. */
  959. SCR_MOVE_ABS (2) ^ SCR_MSG_IN,
  960. HADDR_1 (msgin),
  961. /*
  962. * Load the pointer to the tagged task
  963. * table for this LUN.
  964. */
  965. SCR_LOAD_REL (dsa, 4),
  966. offsetof(struct sym_lcb, head.itlq_tbl_sa),
  967. /*
  968. * The SIDL still contains the TAG value.
  969. * Agressive optimization, isn't it? :):)
  970. */
  971. SCR_REG_SFBR (sidl, SCR_SHL, 0),
  972. 0,
  973. #if SYM_CONF_MAX_TASK*4 > 512
  974. SCR_JUMPR ^ IFFALSE (CARRYSET),
  975. 8,
  976. SCR_REG_REG (dsa1, SCR_OR, 2),
  977. 0,
  978. SCR_REG_REG (sfbr, SCR_SHL, 0),
  979. 0,
  980. SCR_JUMPR ^ IFFALSE (CARRYSET),
  981. 8,
  982. SCR_REG_REG (dsa1, SCR_OR, 1),
  983. 0,
  984. #elif SYM_CONF_MAX_TASK*4 > 256
  985. SCR_JUMPR ^ IFFALSE (CARRYSET),
  986. 8,
  987. SCR_REG_REG (dsa1, SCR_OR, 1),
  988. 0,
  989. #endif
  990. /*
  991. * Retrieve the DSA of this task.
  992. * JUMP indirectly to the restart point of the CCB.
  993. */
  994. SCR_SFBR_REG (dsa, SCR_AND, 0xfc),
  995. 0,
  996. SCR_LOAD_REL (dsa, 4),
  997. 0,
  998. SCR_LOAD_REL (temp, 4),
  999. offsetof(struct sym_ccb, phys.head.go.restart),
  1000. SCR_RETURN,
  1001. 0,
  1002. /* In normal situations we branch to RESEL_DSA */
  1003. }/*-------------------------< RESEL_DSA >------------------------*/,{
  1004. /*
  1005. * ACK the IDENTIFY or TAG previously received.
  1006. */
  1007. SCR_CLR (SCR_ACK),
  1008. 0,
  1009. }/*-------------------------< RESEL_DSA1 >-----------------------*/,{
  1010. /*
  1011. * Initialize the status registers
  1012. */
  1013. SCR_LOAD_REL (scr0, 4),
  1014. offsetof (struct sym_ccb, phys.head.status),
  1015. /*
  1016. * Jump to dispatcher.
  1017. */
  1018. SCR_JUMP,
  1019. PADDR_A (dispatch),
  1020. }/*-------------------------< RESEL_NO_TAG >---------------------*/,{
  1021. /*
  1022. * Load the DSA with the unique ITL task.
  1023. */
  1024. SCR_LOAD_REL (dsa, 4),
  1025. offsetof(struct sym_lcb, head.itl_task_sa),
  1026. /*
  1027. * JUMP indirectly to the restart point of the CCB.
  1028. */
  1029. SCR_LOAD_REL (temp, 4),
  1030. offsetof(struct sym_ccb, phys.head.go.restart),
  1031. SCR_RETURN,
  1032. 0,
  1033. /* In normal situations we branch to RESEL_DSA */
  1034. }/*-------------------------< DATA_IN >--------------------------*/,{
  1035. /*
  1036. * Because the size depends on the
  1037. * #define SYM_CONF_MAX_SG parameter,
  1038. * it is filled in at runtime.
  1039. *
  1040. * ##===========< i=0; i<SYM_CONF_MAX_SG >=========
  1041. * || SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1042. * || offsetof (struct sym_dsb, data[ i]),
  1043. * ##==========================================
  1044. */
  1045. 0
  1046. }/*-------------------------< DATA_IN2 >-------------------------*/,{
  1047. SCR_CALL,
  1048. PADDR_A (datai_done),
  1049. SCR_JUMP,
  1050. PADDR_B (data_ovrun),
  1051. }/*-------------------------< DATA_OUT >-------------------------*/,{
  1052. /*
  1053. * Because the size depends on the
  1054. * #define SYM_CONF_MAX_SG parameter,
  1055. * it is filled in at runtime.
  1056. *
  1057. * ##===========< i=0; i<SYM_CONF_MAX_SG >=========
  1058. * || SCR_CHMOV_TBL ^ SCR_DATA_OUT,
  1059. * || offsetof (struct sym_dsb, data[ i]),
  1060. * ##==========================================
  1061. */
  1062. 0
  1063. }/*-------------------------< DATA_OUT2 >------------------------*/,{
  1064. SCR_CALL,
  1065. PADDR_A (datao_done),
  1066. SCR_JUMP,
  1067. PADDR_B (data_ovrun),
  1068. }/*-------------------------< PM0_DATA >-------------------------*/,{
  1069. /*
  1070. * Read our host flags to SFBR, so we will be able
  1071. * to check against the data direction we expect.
  1072. */
  1073. SCR_FROM_REG (HF_REG),
  1074. 0,
  1075. /*
  1076. * Check against actual DATA PHASE.
  1077. */
  1078. SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
  1079. PADDR_A (pm0_data_out),
  1080. /*
  1081. * Actual phase is DATA IN.
  1082. * Check against expected direction.
  1083. */
  1084. SCR_JUMP ^ IFFALSE (MASK (HF_DATA_IN, HF_DATA_IN)),
  1085. PADDR_B (data_ovrun),
  1086. /*
  1087. * Keep track we are moving data from the
  1088. * PM0 DATA mini-script.
  1089. */
  1090. SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM0),
  1091. 0,
  1092. /*
  1093. * Move the data to memory.
  1094. */
  1095. SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1096. offsetof (struct sym_ccb, phys.pm0.sg),
  1097. SCR_JUMP,
  1098. PADDR_A (pm0_data_end),
  1099. }/*-------------------------< PM0_DATA_OUT >---------------------*/,{
  1100. /*
  1101. * Actual phase is DATA OUT.
  1102. * Check against expected direction.
  1103. */
  1104. SCR_JUMP ^ IFTRUE (MASK (HF_DATA_IN, HF_DATA_IN)),
  1105. PADDR_B (data_ovrun),
  1106. /*
  1107. * Keep track we are moving data from the
  1108. * PM0 DATA mini-script.
  1109. */
  1110. SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM0),
  1111. 0,
  1112. /*
  1113. * Move the data from memory.
  1114. */
  1115. SCR_CHMOV_TBL ^ SCR_DATA_OUT,
  1116. offsetof (struct sym_ccb, phys.pm0.sg),
  1117. }/*-------------------------< PM0_DATA_END >---------------------*/,{
  1118. /*
  1119. * Clear the flag that told we were moving
  1120. * data from the PM0 DATA mini-script.
  1121. */
  1122. SCR_REG_REG (HF_REG, SCR_AND, (~HF_IN_PM0)),
  1123. 0,
  1124. /*
  1125. * Return to the previous DATA script which
  1126. * is guaranteed by design (if no bug) to be
  1127. * the main DATA script for this transfer.
  1128. */
  1129. SCR_LOAD_REL (temp, 4),
  1130. offsetof (struct sym_ccb, phys.pm0.ret),
  1131. SCR_RETURN,
  1132. 0,
  1133. }/*-------------------------< PM1_DATA >-------------------------*/,{
  1134. /*
  1135. * Read our host flags to SFBR, so we will be able
  1136. * to check against the data direction we expect.
  1137. */
  1138. SCR_FROM_REG (HF_REG),
  1139. 0,
  1140. /*
  1141. * Check against actual DATA PHASE.
  1142. */
  1143. SCR_JUMP ^ IFFALSE (WHEN (SCR_DATA_IN)),
  1144. PADDR_A (pm1_data_out),
  1145. /*
  1146. * Actual phase is DATA IN.
  1147. * Check against expected direction.
  1148. */
  1149. SCR_JUMP ^ IFFALSE (MASK (HF_DATA_IN, HF_DATA_IN)),
  1150. PADDR_B (data_ovrun),
  1151. /*
  1152. * Keep track we are moving data from the
  1153. * PM1 DATA mini-script.
  1154. */
  1155. SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM1),
  1156. 0,
  1157. /*
  1158. * Move the data to memory.
  1159. */
  1160. SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1161. offsetof (struct sym_ccb, phys.pm1.sg),
  1162. SCR_JUMP,
  1163. PADDR_A (pm1_data_end),
  1164. }/*-------------------------< PM1_DATA_OUT >---------------------*/,{
  1165. /*
  1166. * Actual phase is DATA OUT.
  1167. * Check against expected direction.
  1168. */
  1169. SCR_JUMP ^ IFTRUE (MASK (HF_DATA_IN, HF_DATA_IN)),
  1170. PADDR_B (data_ovrun),
  1171. /*
  1172. * Keep track we are moving data from the
  1173. * PM1 DATA mini-script.
  1174. */
  1175. SCR_REG_REG (HF_REG, SCR_OR, HF_IN_PM1),
  1176. 0,
  1177. /*
  1178. * Move the data from memory.
  1179. */
  1180. SCR_CHMOV_TBL ^ SCR_DATA_OUT,
  1181. offsetof (struct sym_ccb, phys.pm1.sg),
  1182. }/*-------------------------< PM1_DATA_END >---------------------*/,{
  1183. /*
  1184. * Clear the flag that told we were moving
  1185. * data from the PM1 DATA mini-script.
  1186. */
  1187. SCR_REG_REG (HF_REG, SCR_AND, (~HF_IN_PM1)),
  1188. 0,
  1189. /*
  1190. * Return to the previous DATA script which
  1191. * is guaranteed by design (if no bug) to be
  1192. * the main DATA script for this transfer.
  1193. */
  1194. SCR_LOAD_REL (temp, 4),
  1195. offsetof (struct sym_ccb, phys.pm1.ret),
  1196. SCR_RETURN,
  1197. 0,
  1198. }/*-------------------------<>-----------------------------------*/
  1199. };
  1200. static struct SYM_FWB_SCR SYM_FWB_SCR = {
  1201. /*--------------------------< START64 >--------------------------*/ {
  1202. /*
  1203. * SCRIPT entry point for the 895A, 896 and 1010.
  1204. * For now, there is no specific stuff for those
  1205. * chips at this point, but this may come.
  1206. */
  1207. SCR_JUMP,
  1208. PADDR_A (init),
  1209. }/*-------------------------< NO_DATA >--------------------------*/,{
  1210. SCR_JUMP,
  1211. PADDR_B (data_ovrun),
  1212. }/*-------------------------< SEL_FOR_ABORT >--------------------*/,{
  1213. /*
  1214. * We are jumped here by the C code, if we have
  1215. * some target to reset or some disconnected
  1216. * job to abort. Since error recovery is a serious
  1217. * busyness, we will really reset the SCSI BUS, if
  1218. * case of a SCSI interrupt occurring in this path.
  1219. */
  1220. #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
  1221. /*
  1222. * Set initiator mode.
  1223. */
  1224. SCR_CLR (SCR_TRG),
  1225. 0,
  1226. #endif
  1227. /*
  1228. * And try to select this target.
  1229. */
  1230. SCR_SEL_TBL_ATN ^ offsetof (struct sym_hcb, abrt_sel),
  1231. PADDR_A (reselect),
  1232. /*
  1233. * Wait for the selection to complete or
  1234. * the selection to time out.
  1235. */
  1236. SCR_JUMPR ^ IFFALSE (WHEN (SCR_MSG_OUT)),
  1237. -8,
  1238. /*
  1239. * Call the C code.
  1240. */
  1241. SCR_INT,
  1242. SIR_TARGET_SELECTED,
  1243. /*
  1244. * The C code should let us continue here.
  1245. * Send the 'kiss of death' message.
  1246. * We expect an immediate disconnect once
  1247. * the target has eaten the message.
  1248. */
  1249. SCR_REG_REG (scntl2, SCR_AND, 0x7f),
  1250. 0,
  1251. SCR_MOVE_TBL ^ SCR_MSG_OUT,
  1252. offsetof (struct sym_hcb, abrt_tbl),
  1253. SCR_CLR (SCR_ACK|SCR_ATN),
  1254. 0,
  1255. SCR_WAIT_DISC,
  1256. 0,
  1257. /*
  1258. * Tell the C code that we are done.
  1259. */
  1260. SCR_INT,
  1261. SIR_ABORT_SENT,
  1262. }/*-------------------------< SEL_FOR_ABORT_1 >------------------*/,{
  1263. /*
  1264. * Jump at scheduler.
  1265. */
  1266. SCR_JUMP,
  1267. PADDR_A (start),
  1268. }/*-------------------------< MSG_IN_ETC >-----------------------*/,{
  1269. /*
  1270. * If it is an EXTENDED (variable size message)
  1271. * Handle it.
  1272. */
  1273. SCR_JUMP ^ IFTRUE (DATA (M_EXTENDED)),
  1274. PADDR_B (msg_extended),
  1275. /*
  1276. * Let the C code handle any other
  1277. * 1 byte message.
  1278. */
  1279. SCR_JUMP ^ IFTRUE (MASK (0x00, 0xf0)),
  1280. PADDR_B (msg_received),
  1281. SCR_JUMP ^ IFTRUE (MASK (0x10, 0xf0)),
  1282. PADDR_B (msg_received),
  1283. /*
  1284. * We donnot handle 2 bytes messages from SCRIPTS.
  1285. * So, let the C code deal with these ones too.
  1286. */
  1287. SCR_JUMP ^ IFFALSE (MASK (0x20, 0xf0)),
  1288. PADDR_B (msg_weird_seen),
  1289. SCR_CLR (SCR_ACK),
  1290. 0,
  1291. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  1292. HADDR_1 (msgin[1]),
  1293. }/*-------------------------< MSG_RECEIVED >---------------------*/,{
  1294. SCR_LOAD_REL (scratcha, 4), /* DUMMY READ */
  1295. 0,
  1296. SCR_INT,
  1297. SIR_MSG_RECEIVED,
  1298. }/*-------------------------< MSG_WEIRD_SEEN >-------------------*/,{
  1299. SCR_LOAD_REL (scratcha, 4), /* DUMMY READ */
  1300. 0,
  1301. SCR_INT,
  1302. SIR_MSG_WEIRD,
  1303. }/*-------------------------< MSG_EXTENDED >---------------------*/,{
  1304. /*
  1305. * Clear ACK and get the next byte
  1306. * assumed to be the message length.
  1307. */
  1308. SCR_CLR (SCR_ACK),
  1309. 0,
  1310. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  1311. HADDR_1 (msgin[1]),
  1312. /*
  1313. * Try to catch some unlikely situations as 0 length
  1314. * or too large the length.
  1315. */
  1316. SCR_JUMP ^ IFTRUE (DATA (0)),
  1317. PADDR_B (msg_weird_seen),
  1318. SCR_TO_REG (scratcha),
  1319. 0,
  1320. SCR_REG_REG (sfbr, SCR_ADD, (256-8)),
  1321. 0,
  1322. SCR_JUMP ^ IFTRUE (CARRYSET),
  1323. PADDR_B (msg_weird_seen),
  1324. /*
  1325. * We donnot handle extended messages from SCRIPTS.
  1326. * Read the amount of data correponding to the
  1327. * message length and call the C code.
  1328. */
  1329. SCR_STORE_REL (scratcha, 1),
  1330. offsetof (struct sym_dsb, smsg_ext.size),
  1331. SCR_CLR (SCR_ACK),
  1332. 0,
  1333. SCR_MOVE_TBL ^ SCR_MSG_IN,
  1334. offsetof (struct sym_dsb, smsg_ext),
  1335. SCR_JUMP,
  1336. PADDR_B (msg_received),
  1337. }/*-------------------------< MSG_BAD >--------------------------*/,{
  1338. /*
  1339. * unimplemented message - reject it.
  1340. */
  1341. SCR_INT,
  1342. SIR_REJECT_TO_SEND,
  1343. SCR_SET (SCR_ATN),
  1344. 0,
  1345. SCR_JUMP,
  1346. PADDR_A (clrack),
  1347. }/*-------------------------< MSG_WEIRD >------------------------*/,{
  1348. /*
  1349. * weird message received
  1350. * ignore all MSG IN phases and reject it.
  1351. */
  1352. SCR_INT,
  1353. SIR_REJECT_TO_SEND,
  1354. SCR_SET (SCR_ATN),
  1355. 0,
  1356. }/*-------------------------< MSG_WEIRD1 >-----------------------*/,{
  1357. SCR_CLR (SCR_ACK),
  1358. 0,
  1359. SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_IN)),
  1360. PADDR_A (dispatch),
  1361. SCR_MOVE_ABS (1) ^ SCR_MSG_IN,
  1362. HADDR_1 (scratch),
  1363. SCR_JUMP,
  1364. PADDR_B (msg_weird1),
  1365. }/*-------------------------< WDTR_RESP >------------------------*/,{
  1366. /*
  1367. * let the target fetch our answer.
  1368. */
  1369. SCR_SET (SCR_ATN),
  1370. 0,
  1371. SCR_CLR (SCR_ACK),
  1372. 0,
  1373. SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
  1374. PADDR_B (nego_bad_phase),
  1375. }/*-------------------------< SEND_WDTR >------------------------*/,{
  1376. /*
  1377. * Send the M_X_WIDE_REQ
  1378. */
  1379. SCR_MOVE_ABS (4) ^ SCR_MSG_OUT,
  1380. HADDR_1 (msgout),
  1381. SCR_JUMP,
  1382. PADDR_B (msg_out_done),
  1383. }/*-------------------------< SDTR_RESP >------------------------*/,{
  1384. /*
  1385. * let the target fetch our answer.
  1386. */
  1387. SCR_SET (SCR_ATN),
  1388. 0,
  1389. SCR_CLR (SCR_ACK),
  1390. 0,
  1391. SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
  1392. PADDR_B (nego_bad_phase),
  1393. }/*-------------------------< SEND_SDTR >------------------------*/,{
  1394. /*
  1395. * Send the M_X_SYNC_REQ
  1396. */
  1397. SCR_MOVE_ABS (5) ^ SCR_MSG_OUT,
  1398. HADDR_1 (msgout),
  1399. SCR_JUMP,
  1400. PADDR_B (msg_out_done),
  1401. }/*-------------------------< PPR_RESP >-------------------------*/,{
  1402. /*
  1403. * let the target fetch our answer.
  1404. */
  1405. SCR_SET (SCR_ATN),
  1406. 0,
  1407. SCR_CLR (SCR_ACK),
  1408. 0,
  1409. SCR_JUMP ^ IFFALSE (WHEN (SCR_MSG_OUT)),
  1410. PADDR_B (nego_bad_phase),
  1411. }/*-------------------------< SEND_PPR >-------------------------*/,{
  1412. /*
  1413. * Send the M_X_PPR_REQ
  1414. */
  1415. SCR_MOVE_ABS (8) ^ SCR_MSG_OUT,
  1416. HADDR_1 (msgout),
  1417. SCR_JUMP,
  1418. PADDR_B (msg_out_done),
  1419. }/*-------------------------< NEGO_BAD_PHASE >-------------------*/,{
  1420. SCR_INT,
  1421. SIR_NEGO_PROTO,
  1422. SCR_JUMP,
  1423. PADDR_A (dispatch),
  1424. }/*-------------------------< MSG_OUT >--------------------------*/,{
  1425. /*
  1426. * The target requests a message.
  1427. * We donnot send messages that may
  1428. * require the device to go to bus free.
  1429. */
  1430. SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
  1431. HADDR_1 (msgout),
  1432. /*
  1433. * ... wait for the next phase
  1434. * if it's a message out, send it again, ...
  1435. */
  1436. SCR_JUMP ^ IFTRUE (WHEN (SCR_MSG_OUT)),
  1437. PADDR_B (msg_out),
  1438. }/*-------------------------< MSG_OUT_DONE >---------------------*/,{
  1439. /*
  1440. * Let the C code be aware of the
  1441. * sent message and clear the message.
  1442. */
  1443. SCR_INT,
  1444. SIR_MSG_OUT_DONE,
  1445. /*
  1446. * ... and process the next phase
  1447. */
  1448. SCR_JUMP,
  1449. PADDR_A (dispatch),
  1450. }/*-------------------------< DATA_OVRUN >-----------------------*/,{
  1451. /*
  1452. * Use scratcha to count the extra bytes.
  1453. */
  1454. SCR_LOAD_ABS (scratcha, 4),
  1455. PADDR_B (zero),
  1456. }/*-------------------------< DATA_OVRUN1 >----------------------*/,{
  1457. /*
  1458. * The target may want to transfer too much data.
  1459. *
  1460. * If phase is DATA OUT write 1 byte and count it.
  1461. */
  1462. SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_OUT)),
  1463. 16,
  1464. SCR_CHMOV_ABS (1) ^ SCR_DATA_OUT,
  1465. HADDR_1 (scratch),
  1466. SCR_JUMP,
  1467. PADDR_B (data_ovrun2),
  1468. /*
  1469. * If WSR is set, clear this condition, and
  1470. * count this byte.
  1471. */
  1472. SCR_FROM_REG (scntl2),
  1473. 0,
  1474. SCR_JUMPR ^ IFFALSE (MASK (WSR, WSR)),
  1475. 16,
  1476. SCR_REG_REG (scntl2, SCR_OR, WSR),
  1477. 0,
  1478. SCR_JUMP,
  1479. PADDR_B (data_ovrun2),
  1480. /*
  1481. * Finally check against DATA IN phase.
  1482. * Signal data overrun to the C code
  1483. * and jump to dispatcher if not so.
  1484. * Read 1 byte otherwise and count it.
  1485. */
  1486. SCR_JUMPR ^ IFTRUE (WHEN (SCR_DATA_IN)),
  1487. 16,
  1488. SCR_INT,
  1489. SIR_DATA_OVERRUN,
  1490. SCR_JUMP,
  1491. PADDR_A (dispatch),
  1492. SCR_CHMOV_ABS (1) ^ SCR_DATA_IN,
  1493. HADDR_1 (scratch),
  1494. }/*-------------------------< DATA_OVRUN2 >----------------------*/,{
  1495. /*
  1496. * Count this byte.
  1497. * This will allow to return a negative
  1498. * residual to user.
  1499. */
  1500. SCR_REG_REG (scratcha, SCR_ADD, 0x01),
  1501. 0,
  1502. SCR_REG_REG (scratcha1, SCR_ADDC, 0),
  1503. 0,
  1504. SCR_REG_REG (scratcha2, SCR_ADDC, 0),
  1505. 0,
  1506. /*
  1507. * .. and repeat as required.
  1508. */
  1509. SCR_JUMP,
  1510. PADDR_B (data_ovrun1),
  1511. }/*-------------------------< ABORT_RESEL >----------------------*/,{
  1512. SCR_SET (SCR_ATN),
  1513. 0,
  1514. SCR_CLR (SCR_ACK),
  1515. 0,
  1516. /*
  1517. * send the abort/abortag/reset message
  1518. * we expect an immediate disconnect
  1519. */
  1520. SCR_REG_REG (scntl2, SCR_AND, 0x7f),
  1521. 0,
  1522. SCR_MOVE_ABS (1) ^ SCR_MSG_OUT,
  1523. HADDR_1 (msgout),
  1524. SCR_CLR (SCR_ACK|SCR_ATN),
  1525. 0,
  1526. SCR_WAIT_DISC,
  1527. 0,
  1528. SCR_INT,
  1529. SIR_RESEL_ABORTED,
  1530. SCR_JUMP,
  1531. PADDR_A (start),
  1532. }/*-------------------------< RESEND_IDENT >---------------------*/,{
  1533. /*
  1534. * The target stays in MSG OUT phase after having acked
  1535. * Identify [+ Tag [+ Extended message ]]. Targets shall
  1536. * behave this way on parity error.
  1537. * We must send it again all the messages.
  1538. */
  1539. SCR_SET (SCR_ATN), /* Shall be asserted 2 deskew delays before the */
  1540. 0, /* 1rst ACK = 90 ns. Hope the chip isn't too fast */
  1541. SCR_JUMP,
  1542. PADDR_A (send_ident),
  1543. }/*-------------------------< IDENT_BREAK >----------------------*/,{
  1544. SCR_CLR (SCR_ATN),
  1545. 0,
  1546. SCR_JUMP,
  1547. PADDR_A (select2),
  1548. }/*-------------------------< IDENT_BREAK_ATN >------------------*/,{
  1549. SCR_SET (SCR_ATN),
  1550. 0,
  1551. SCR_JUMP,
  1552. PADDR_A (select2),
  1553. }/*-------------------------< SDATA_IN >-------------------------*/,{
  1554. SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1555. offsetof (struct sym_dsb, sense),
  1556. SCR_CALL,
  1557. PADDR_A (datai_done),
  1558. SCR_JUMP,
  1559. PADDR_B (data_ovrun),
  1560. }/*-------------------------< RESEL_BAD_LUN >--------------------*/,{
  1561. /*
  1562. * Message is an IDENTIFY, but lun is unknown.
  1563. * Signal problem to C code for logging the event.
  1564. * Send a M_ABORT to clear all pending tasks.
  1565. */
  1566. SCR_INT,
  1567. SIR_RESEL_BAD_LUN,
  1568. SCR_JUMP,
  1569. PADDR_B (abort_resel),
  1570. }/*-------------------------< BAD_I_T_L >------------------------*/,{
  1571. /*
  1572. * We donnot have a task for that I_T_L.
  1573. * Signal problem to C code for logging the event.
  1574. * Send a M_ABORT message.
  1575. */
  1576. SCR_INT,
  1577. SIR_RESEL_BAD_I_T_L,
  1578. SCR_JUMP,
  1579. PADDR_B (abort_resel),
  1580. }/*-------------------------< BAD_I_T_L_Q >----------------------*/,{
  1581. /*
  1582. * We donnot have a task that matches the tag.
  1583. * Signal problem to C code for logging the event.
  1584. * Send a M_ABORTTAG message.
  1585. */
  1586. SCR_INT,
  1587. SIR_RESEL_BAD_I_T_L_Q,
  1588. SCR_JUMP,
  1589. PADDR_B (abort_resel),
  1590. }/*-------------------------< BAD_STATUS >-----------------------*/,{
  1591. /*
  1592. * Anything different from INTERMEDIATE
  1593. * CONDITION MET should be a bad SCSI status,
  1594. * given that GOOD status has already been tested.
  1595. * Call the C code.
  1596. */
  1597. SCR_LOAD_ABS (scratcha, 4),
  1598. PADDR_B (startpos),
  1599. SCR_INT ^ IFFALSE (DATA (S_COND_MET)),
  1600. SIR_BAD_SCSI_STATUS,
  1601. SCR_RETURN,
  1602. 0,
  1603. }/*-------------------------< PM_HANDLE >------------------------*/,{
  1604. /*
  1605. * Phase mismatch handling.
  1606. *
  1607. * Since we have to deal with 2 SCSI data pointers
  1608. * (current and saved), we need at least 2 contexts.
  1609. * Each context (pm0 and pm1) has a saved area, a
  1610. * SAVE mini-script and a DATA phase mini-script.
  1611. */
  1612. /*
  1613. * Get the PM handling flags.
  1614. */
  1615. SCR_FROM_REG (HF_REG),
  1616. 0,
  1617. /*
  1618. * If no flags (1rst PM for example), avoid
  1619. * all the below heavy flags testing.
  1620. * This makes the normal case a bit faster.
  1621. */
  1622. SCR_JUMP ^ IFTRUE (MASK (0, (HF_IN_PM0 | HF_IN_PM1 | HF_DP_SAVED))),
  1623. PADDR_B (pm_handle1),
  1624. /*
  1625. * If we received a SAVE DP, switch to the
  1626. * other PM context since the savep may point
  1627. * to the current PM context.
  1628. */
  1629. SCR_JUMPR ^ IFFALSE (MASK (HF_DP_SAVED, HF_DP_SAVED)),
  1630. 8,
  1631. SCR_REG_REG (sfbr, SCR_XOR, HF_ACT_PM),
  1632. 0,
  1633. /*
  1634. * If we have been interrupt in a PM DATA mini-script,
  1635. * we take the return address from the corresponding
  1636. * saved area.
  1637. * This ensure the return address always points to the
  1638. * main DATA script for this transfer.
  1639. */
  1640. SCR_JUMP ^ IFTRUE (MASK (0, (HF_IN_PM0 | HF_IN_PM1))),
  1641. PADDR_B (pm_handle1),
  1642. SCR_JUMPR ^ IFFALSE (MASK (HF_IN_PM0, HF_IN_PM0)),
  1643. 16,
  1644. SCR_LOAD_REL (ia, 4),
  1645. offsetof(struct sym_ccb, phys.pm0.ret),
  1646. SCR_JUMP,
  1647. PADDR_B (pm_save),
  1648. SCR_LOAD_REL (ia, 4),
  1649. offsetof(struct sym_ccb, phys.pm1.ret),
  1650. SCR_JUMP,
  1651. PADDR_B (pm_save),
  1652. }/*-------------------------< PM_HANDLE1 >-----------------------*/,{
  1653. /*
  1654. * Normal case.
  1655. * Update the return address so that it
  1656. * will point after the interrupted MOVE.
  1657. */
  1658. SCR_REG_REG (ia, SCR_ADD, 8),
  1659. 0,
  1660. SCR_REG_REG (ia1, SCR_ADDC, 0),
  1661. 0,
  1662. }/*-------------------------< PM_SAVE >--------------------------*/,{
  1663. /*
  1664. * Clear all the flags that told us if we were
  1665. * interrupted in a PM DATA mini-script and/or
  1666. * we received a SAVE DP.
  1667. */
  1668. SCR_SFBR_REG (HF_REG, SCR_AND, (~(HF_IN_PM0|HF_IN_PM1|HF_DP_SAVED))),
  1669. 0,
  1670. /*
  1671. * Choose the current PM context.
  1672. */
  1673. SCR_JUMP ^ IFTRUE (MASK (HF_ACT_PM, HF_ACT_PM)),
  1674. PADDR_B (pm1_save),
  1675. }/*-------------------------< PM0_SAVE >-------------------------*/,{
  1676. SCR_STORE_REL (ia, 4),
  1677. offsetof(struct sym_ccb, phys.pm0.ret),
  1678. /*
  1679. * If WSR bit is set, either UA and RBC may
  1680. * have to be changed whether the device wants
  1681. * to ignore this residue or not.
  1682. */
  1683. SCR_FROM_REG (scntl2),
  1684. 0,
  1685. SCR_CALL ^ IFTRUE (MASK (WSR, WSR)),
  1686. PADDR_B (pm_wsr_handle),
  1687. /*
  1688. * Save the remaining byte count, the updated
  1689. * address and the return address.
  1690. */
  1691. SCR_STORE_REL (rbc, 4),
  1692. offsetof(struct sym_ccb, phys.pm0.sg.size),
  1693. SCR_STORE_REL (ua, 4),
  1694. offsetof(struct sym_ccb, phys.pm0.sg.addr),
  1695. /*
  1696. * Set the current pointer at the PM0 DATA mini-script.
  1697. */
  1698. SCR_LOAD_ABS (ia, 4),
  1699. PADDR_B (pm0_data_addr),
  1700. }/*-------------------------< PM_SAVE_END >----------------------*/,{
  1701. SCR_STORE_REL (ia, 4),
  1702. offsetof(struct sym_ccb, phys.head.lastp),
  1703. SCR_JUMP,
  1704. PADDR_A (dispatch),
  1705. }/*-------------------------< PM1_SAVE >-------------------------*/,{
  1706. SCR_STORE_REL (ia, 4),
  1707. offsetof(struct sym_ccb, phys.pm1.ret),
  1708. /*
  1709. * If WSR bit is set, either UA and RBC may
  1710. * have to be changed whether the device wants
  1711. * to ignore this residue or not.
  1712. */
  1713. SCR_FROM_REG (scntl2),
  1714. 0,
  1715. SCR_CALL ^ IFTRUE (MASK (WSR, WSR)),
  1716. PADDR_B (pm_wsr_handle),
  1717. /*
  1718. * Save the remaining byte count, the updated
  1719. * address and the return address.
  1720. */
  1721. SCR_STORE_REL (rbc, 4),
  1722. offsetof(struct sym_ccb, phys.pm1.sg.size),
  1723. SCR_STORE_REL (ua, 4),
  1724. offsetof(struct sym_ccb, phys.pm1.sg.addr),
  1725. /*
  1726. * Set the current pointer at the PM1 DATA mini-script.
  1727. */
  1728. SCR_LOAD_ABS (ia, 4),
  1729. PADDR_B (pm1_data_addr),
  1730. SCR_JUMP,
  1731. PADDR_B (pm_save_end),
  1732. }/*-------------------------< PM_WSR_HANDLE >--------------------*/,{
  1733. /*
  1734. * Phase mismatch handling from SCRIPT with WSR set.
  1735. * Such a condition can occur if the chip wants to
  1736. * execute a CHMOV(size > 1) when the WSR bit is
  1737. * set and the target changes PHASE.
  1738. *
  1739. * We must move the residual byte to memory.
  1740. *
  1741. * UA contains bit 0..31 of the address to
  1742. * move the residual byte.
  1743. * Move it to the table indirect.
  1744. */
  1745. SCR_STORE_REL (ua, 4),
  1746. offsetof (struct sym_ccb, phys.wresid.addr),
  1747. /*
  1748. * Increment UA (move address to next position).
  1749. */
  1750. SCR_REG_REG (ua, SCR_ADD, 1),
  1751. 0,
  1752. SCR_REG_REG (ua1, SCR_ADDC, 0),
  1753. 0,
  1754. SCR_REG_REG (ua2, SCR_ADDC, 0),
  1755. 0,
  1756. SCR_REG_REG (ua3, SCR_ADDC, 0),
  1757. 0,
  1758. /*
  1759. * Compute SCRATCHA as:
  1760. * - size to transfer = 1 byte.
  1761. * - bit 24..31 = high address bit [32...39].
  1762. */
  1763. SCR_LOAD_ABS (scratcha, 4),
  1764. PADDR_B (zero),
  1765. SCR_REG_REG (scratcha, SCR_OR, 1),
  1766. 0,
  1767. SCR_FROM_REG (rbc3),
  1768. 0,
  1769. SCR_TO_REG (scratcha3),
  1770. 0,
  1771. /*
  1772. * Move this value to the table indirect.
  1773. */
  1774. SCR_STORE_REL (scratcha, 4),
  1775. offsetof (struct sym_ccb, phys.wresid.size),
  1776. /*
  1777. * Wait for a valid phase.
  1778. * While testing with bogus QUANTUM drives, the C1010
  1779. * sometimes raised a spurious phase mismatch with
  1780. * WSR and the CHMOV(1) triggered another PM.
  1781. * Waiting explicitely for the PHASE seemed to avoid
  1782. * the nested phase mismatch. Btw, this didn't happen
  1783. * using my IBM drives.
  1784. */
  1785. SCR_JUMPR ^ IFFALSE (WHEN (SCR_DATA_IN)),
  1786. 0,
  1787. /*
  1788. * Perform the move of the residual byte.
  1789. */
  1790. SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1791. offsetof (struct sym_ccb, phys.wresid),
  1792. /*
  1793. * We can now handle the phase mismatch with UA fixed.
  1794. * RBC[0..23]=0 is a special case that does not require
  1795. * a PM context. The C code also checks against this.
  1796. */
  1797. SCR_FROM_REG (rbc),
  1798. 0,
  1799. SCR_RETURN ^ IFFALSE (DATA (0)),
  1800. 0,
  1801. SCR_FROM_REG (rbc1),
  1802. 0,
  1803. SCR_RETURN ^ IFFALSE (DATA (0)),
  1804. 0,
  1805. SCR_FROM_REG (rbc2),
  1806. 0,
  1807. SCR_RETURN ^ IFFALSE (DATA (0)),
  1808. 0,
  1809. /*
  1810. * RBC[0..23]=0.
  1811. * Not only we donnot need a PM context, but this would
  1812. * lead to a bogus CHMOV(0). This condition means that
  1813. * the residual was the last byte to move from this CHMOV.
  1814. * So, we just have to move the current data script pointer
  1815. * (i.e. TEMP) to the SCRIPTS address following the
  1816. * interrupted CHMOV and jump to dispatcher.
  1817. * IA contains the data pointer to save.
  1818. */
  1819. SCR_JUMP,
  1820. PADDR_B (pm_save_end),
  1821. }/*-------------------------< WSR_MA_HELPER >--------------------*/,{
  1822. /*
  1823. * Helper for the C code when WSR bit is set.
  1824. * Perform the move of the residual byte.
  1825. */
  1826. SCR_CHMOV_TBL ^ SCR_DATA_IN,
  1827. offsetof (struct sym_ccb, phys.wresid),
  1828. SCR_JUMP,
  1829. PADDR_A (dispatch),
  1830. #ifdef SYM_OPT_HANDLE_DIR_UNKNOWN
  1831. }/*-------------------------< DATA_IO >--------------------------*/,{
  1832. /*
  1833. * We jump here if the data direction was unknown at the
  1834. * time we had to queue the command to the scripts processor.
  1835. * Pointers had been set as follow in this situation:
  1836. * savep --> DATA_IO
  1837. * lastp --> start pointer when DATA_IN
  1838. * wlastp --> start pointer when DATA_OUT
  1839. * This script sets savep and lastp according to the
  1840. * direction chosen by the target.
  1841. */
  1842. SCR_JUMP ^ IFTRUE (WHEN (SCR_DATA_OUT)),
  1843. PADDR_B (data_io_out),
  1844. }/*-------------------------< DATA_IO_IN >-----------------------*/,{
  1845. /*
  1846. * Direction is DATA IN.
  1847. */
  1848. SCR_LOAD_REL (scratcha, 4),
  1849. offsetof (struct sym_ccb, phys.head.lastp),
  1850. }/*-------------------------< DATA_IO_COM >----------------------*/,{
  1851. SCR_STORE_REL (scratcha, 4),
  1852. offsetof (struct sym_ccb, phys.head.savep),
  1853. /*
  1854. * Jump to the SCRIPTS according to actual direction.
  1855. */
  1856. SCR_LOAD_REL (temp, 4),
  1857. offsetof (struct sym_ccb, phys.head.savep),
  1858. SCR_RETURN,
  1859. 0,
  1860. }/*-------------------------< DATA_IO_OUT >----------------------*/,{
  1861. /*
  1862. * Direction is DATA OUT.
  1863. */
  1864. SCR_REG_REG (HF_REG, SCR_AND, (~HF_DATA_IN)),
  1865. 0,
  1866. SCR_LOAD_REL (scratcha, 4),
  1867. offsetof (struct sym_ccb, phys.head.wlastp),
  1868. SCR_STORE_REL (scratcha, 4),
  1869. offsetof (struct sym_ccb, phys.head.lastp),
  1870. SCR_JUMP,
  1871. PADDR_B(data_io_com),
  1872. #endif /* SYM_OPT_HANDLE_DIR_UNKNOWN */
  1873. }/*-------------------------< ZERO >-----------------------------*/,{
  1874. SCR_DATA_ZERO,
  1875. }/*-------------------------< SCRATCH >--------------------------*/,{
  1876. SCR_DATA_ZERO,
  1877. }/*-------------------------< PM0_DATA_ADDR >--------------------*/,{
  1878. SCR_DATA_ZERO,
  1879. }/*-------------------------< PM1_DATA_ADDR >--------------------*/,{
  1880. SCR_DATA_ZERO,
  1881. }/*-------------------------< DONE_POS >-------------------------*/,{
  1882. SCR_DATA_ZERO,
  1883. }/*-------------------------< STARTPOS >-------------------------*/,{
  1884. SCR_DATA_ZERO,
  1885. }/*-------------------------< TARGTBL >--------------------------*/,{
  1886. SCR_DATA_ZERO,
  1887. }/*-------------------------<>-----------------------------------*/
  1888. };
  1889. static struct SYM_FWZ_SCR SYM_FWZ_SCR = {
  1890. /*-------------------------< SNOOPTEST >------------------------*/{
  1891. /*
  1892. * Read the variable from memory.
  1893. */
  1894. SCR_LOAD_REL (scratcha, 4),
  1895. offsetof(struct sym_hcb, scratch),
  1896. /*
  1897. * Write the variable to memory.
  1898. */
  1899. SCR_STORE_REL (temp, 4),
  1900. offsetof(struct sym_hcb, scratch),
  1901. /*
  1902. * Read back the variable from memory.
  1903. */
  1904. SCR_LOAD_REL (temp, 4),
  1905. offsetof(struct sym_hcb, scratch),
  1906. }/*-------------------------< SNOOPEND >-------------------------*/,{
  1907. /*
  1908. * And stop.
  1909. */
  1910. SCR_INT,
  1911. 99,
  1912. }/*-------------------------<>-----------------------------------*/
  1913. };