acornscsi.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016
  1. /*
  2. * linux/drivers/acorn/scsi/acornscsi.c
  3. *
  4. * Acorn SCSI 3 driver
  5. * By R.M.King.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Abandoned using the Select and Transfer command since there were
  12. * some nasty races between our software and the target devices that
  13. * were not easy to solve, and the device errata had a lot of entries
  14. * for this command, some of them quite nasty...
  15. *
  16. * Changelog:
  17. * 26-Sep-1997 RMK Re-jigged to use the queue module.
  18. * Re-coded state machine to be based on driver
  19. * state not scsi state. Should be easier to debug.
  20. * Added acornscsi_release to clean up properly.
  21. * Updated proc/scsi reporting.
  22. * 05-Oct-1997 RMK Implemented writing to SCSI devices.
  23. * 06-Oct-1997 RMK Corrected small (non-serious) bug with the connect/
  24. * reconnect race condition causing a warning message.
  25. * 12-Oct-1997 RMK Added catch for re-entering interrupt routine.
  26. * 15-Oct-1997 RMK Improved handling of commands.
  27. * 27-Jun-1998 RMK Changed asm/delay.h to linux/delay.h.
  28. * 13-Dec-1998 RMK Better abort code and command handling. Extra state
  29. * transitions added to allow dodgy devices to work.
  30. */
  31. #define DEBUG_NO_WRITE 1
  32. #define DEBUG_QUEUES 2
  33. #define DEBUG_DMA 4
  34. #define DEBUG_ABORT 8
  35. #define DEBUG_DISCON 16
  36. #define DEBUG_CONNECT 32
  37. #define DEBUG_PHASES 64
  38. #define DEBUG_WRITE 128
  39. #define DEBUG_LINK 256
  40. #define DEBUG_MESSAGES 512
  41. #define DEBUG_RESET 1024
  42. #define DEBUG_ALL (DEBUG_RESET|DEBUG_MESSAGES|DEBUG_LINK|DEBUG_WRITE|\
  43. DEBUG_PHASES|DEBUG_CONNECT|DEBUG_DISCON|DEBUG_ABORT|\
  44. DEBUG_DMA|DEBUG_QUEUES)
  45. /* DRIVER CONFIGURATION
  46. *
  47. * SCSI-II Tagged queue support.
  48. *
  49. * I don't have any SCSI devices that support it, so it is totally untested
  50. * (except to make sure that it doesn't interfere with any non-tagging
  51. * devices). It is not fully implemented either - what happens when a
  52. * tagging device reconnects???
  53. *
  54. * You can tell if you have a device that supports tagged queueing my
  55. * cating (eg) /proc/scsi/acornscsi/0 and see if the SCSI revision is reported
  56. * as '2 TAG'.
  57. *
  58. * Also note that CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE is normally set in the config
  59. * scripts, but disabled here. Once debugged, remove the #undef, otherwise to debug,
  60. * comment out the undef.
  61. */
  62. #undef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  63. /*
  64. * SCSI-II Synchronous transfer support.
  65. *
  66. * Tried and tested...
  67. *
  68. * SDTR_SIZE - maximum number of un-acknowledged bytes (0 = off, 12 = max)
  69. * SDTR_PERIOD - period of REQ signal (min=125, max=1020)
  70. * DEFAULT_PERIOD - default REQ period.
  71. */
  72. #define SDTR_SIZE 12
  73. #define SDTR_PERIOD 125
  74. #define DEFAULT_PERIOD 500
  75. /*
  76. * Debugging information
  77. *
  78. * DEBUG - bit mask from list above
  79. * DEBUG_TARGET - is defined to the target number if you want to debug
  80. * a specific target. [only recon/write/dma].
  81. */
  82. #define DEBUG (DEBUG_RESET|DEBUG_WRITE|DEBUG_NO_WRITE)
  83. /* only allow writing to SCSI device 0 */
  84. #define NO_WRITE 0xFE
  85. /*#define DEBUG_TARGET 2*/
  86. /*
  87. * Select timeout time (in 10ms units)
  88. *
  89. * This is the timeout used between the start of selection and the WD33C93
  90. * chip deciding that the device isn't responding.
  91. */
  92. #define TIMEOUT_TIME 10
  93. /*
  94. * Define this if you want to have verbose explanation of SCSI
  95. * status/messages.
  96. */
  97. #undef CONFIG_ACORNSCSI_CONSTANTS
  98. /*
  99. * Define this if you want to use the on board DMAC [don't remove this option]
  100. * If not set, then use PIO mode (not currently supported).
  101. */
  102. #define USE_DMAC
  103. /*
  104. * ====================================================================================
  105. */
  106. #ifdef DEBUG_TARGET
  107. #define DBG(cmd,xxx...) \
  108. if (cmd->device->id == DEBUG_TARGET) { \
  109. xxx; \
  110. }
  111. #else
  112. #define DBG(cmd,xxx...) xxx
  113. #endif
  114. #include <linux/module.h>
  115. #include <linux/kernel.h>
  116. #include <linux/string.h>
  117. #include <linux/signal.h>
  118. #include <linux/errno.h>
  119. #include <linux/proc_fs.h>
  120. #include <linux/ioport.h>
  121. #include <linux/blkdev.h>
  122. #include <linux/delay.h>
  123. #include <linux/interrupt.h>
  124. #include <linux/init.h>
  125. #include <linux/bitops.h>
  126. #include <linux/stringify.h>
  127. #include <linux/io.h>
  128. #include <asm/ecard.h>
  129. #include "../scsi.h"
  130. #include <scsi/scsi_dbg.h>
  131. #include <scsi/scsi_host.h>
  132. #include <scsi/scsi_transport_spi.h>
  133. #include "acornscsi.h"
  134. #include "msgqueue.h"
  135. #include "scsi.h"
  136. #include <scsi/scsicam.h>
  137. #define VER_MAJOR 2
  138. #define VER_MINOR 0
  139. #define VER_PATCH 6
  140. #ifndef ABORT_TAG
  141. #define ABORT_TAG 0xd
  142. #else
  143. #error "Yippee! ABORT TAG is now defined! Remove this error!"
  144. #endif
  145. #ifdef USE_DMAC
  146. /*
  147. * DMAC setup parameters
  148. */
  149. #define INIT_DEVCON0 (DEVCON0_RQL|DEVCON0_EXW|DEVCON0_CMP)
  150. #define INIT_DEVCON1 (DEVCON1_BHLD)
  151. #define DMAC_READ (MODECON_READ)
  152. #define DMAC_WRITE (MODECON_WRITE)
  153. #define INIT_SBICDMA (CTRL_DMABURST)
  154. #define scsi_xferred have_data_in
  155. /*
  156. * Size of on-board DMA buffer
  157. */
  158. #define DMAC_BUFFER_SIZE 65536
  159. #endif
  160. #define STATUS_BUFFER_TO_PRINT 24
  161. unsigned int sdtr_period = SDTR_PERIOD;
  162. unsigned int sdtr_size = SDTR_SIZE;
  163. static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
  164. unsigned int result);
  165. static int acornscsi_reconnect_finish(AS_Host *host);
  166. static void acornscsi_dma_cleanup(AS_Host *host);
  167. static void acornscsi_abortcmd(AS_Host *host, unsigned char tag);
  168. /* ====================================================================================
  169. * Miscellaneous
  170. */
  171. /* Offsets from MEMC base */
  172. #define SBIC_REGIDX 0x2000
  173. #define SBIC_REGVAL 0x2004
  174. #define DMAC_OFFSET 0x3000
  175. /* Offsets from FAST IOC base */
  176. #define INT_REG 0x2000
  177. #define PAGE_REG 0x3000
  178. static inline void sbic_arm_write(AS_Host *host, unsigned int reg, unsigned int value)
  179. {
  180. writeb(reg, host->base + SBIC_REGIDX);
  181. writeb(value, host->base + SBIC_REGVAL);
  182. }
  183. static inline int sbic_arm_read(AS_Host *host, unsigned int reg)
  184. {
  185. if(reg == SBIC_ASR)
  186. return readl(host->base + SBIC_REGIDX) & 255;
  187. writeb(reg, host->base + SBIC_REGIDX);
  188. return readl(host->base + SBIC_REGVAL) & 255;
  189. }
  190. #define sbic_arm_writenext(host, val) writeb((val), (host)->base + SBIC_REGVAL)
  191. #define sbic_arm_readnext(host) readb((host)->base + SBIC_REGVAL)
  192. #ifdef USE_DMAC
  193. #define dmac_read(host,reg) \
  194. readb((host)->base + DMAC_OFFSET + ((reg) << 2))
  195. #define dmac_write(host,reg,value) \
  196. ({ writeb((value), (host)->base + DMAC_OFFSET + ((reg) << 2)); })
  197. #define dmac_clearintr(host) writeb(0, (host)->fast + INT_REG)
  198. static inline unsigned int dmac_address(AS_Host *host)
  199. {
  200. return dmac_read(host, DMAC_TXADRHI) << 16 |
  201. dmac_read(host, DMAC_TXADRMD) << 8 |
  202. dmac_read(host, DMAC_TXADRLO);
  203. }
  204. static
  205. void acornscsi_dumpdma(AS_Host *host, char *where)
  206. {
  207. unsigned int mode, addr, len;
  208. mode = dmac_read(host, DMAC_MODECON);
  209. addr = dmac_address(host);
  210. len = dmac_read(host, DMAC_TXCNTHI) << 8 |
  211. dmac_read(host, DMAC_TXCNTLO);
  212. printk("scsi%d: %s: DMAC %02x @%06x+%04x msk %02x, ",
  213. host->host->host_no, where,
  214. mode, addr, (len + 1) & 0xffff,
  215. dmac_read(host, DMAC_MASKREG));
  216. printk("DMA @%06x, ", host->dma.start_addr);
  217. printk("BH @%p +%04x, ", host->scsi.SCp.ptr,
  218. host->scsi.SCp.this_residual);
  219. printk("DT @+%04x ST @+%04x", host->dma.transferred,
  220. host->scsi.SCp.scsi_xferred);
  221. printk("\n");
  222. }
  223. #endif
  224. static
  225. unsigned long acornscsi_sbic_xfcount(AS_Host *host)
  226. {
  227. unsigned long length;
  228. length = sbic_arm_read(host, SBIC_TRANSCNTH) << 16;
  229. length |= sbic_arm_readnext(host) << 8;
  230. length |= sbic_arm_readnext(host);
  231. return length;
  232. }
  233. static int
  234. acornscsi_sbic_wait(AS_Host *host, int stat_mask, int stat, int timeout, char *msg)
  235. {
  236. int asr;
  237. do {
  238. asr = sbic_arm_read(host, SBIC_ASR);
  239. if ((asr & stat_mask) == stat)
  240. return 0;
  241. udelay(1);
  242. } while (--timeout);
  243. printk("scsi%d: timeout while %s\n", host->host->host_no, msg);
  244. return -1;
  245. }
  246. static
  247. int acornscsi_sbic_issuecmd(AS_Host *host, int command)
  248. {
  249. if (acornscsi_sbic_wait(host, ASR_CIP, 0, 1000, "issuing command"))
  250. return -1;
  251. sbic_arm_write(host, SBIC_CMND, command);
  252. return 0;
  253. }
  254. static void
  255. acornscsi_csdelay(unsigned int cs)
  256. {
  257. unsigned long target_jiffies, flags;
  258. target_jiffies = jiffies + 1 + cs * HZ / 100;
  259. local_save_flags(flags);
  260. local_irq_enable();
  261. while (time_before(jiffies, target_jiffies)) barrier();
  262. local_irq_restore(flags);
  263. }
  264. static
  265. void acornscsi_resetcard(AS_Host *host)
  266. {
  267. unsigned int i, timeout;
  268. /* assert reset line */
  269. host->card.page_reg = 0x80;
  270. writeb(host->card.page_reg, host->fast + PAGE_REG);
  271. /* wait 3 cs. SCSI standard says 25ms. */
  272. acornscsi_csdelay(3);
  273. host->card.page_reg = 0;
  274. writeb(host->card.page_reg, host->fast + PAGE_REG);
  275. /*
  276. * Should get a reset from the card
  277. */
  278. timeout = 1000;
  279. do {
  280. if (readb(host->fast + INT_REG) & 8)
  281. break;
  282. udelay(1);
  283. } while (--timeout);
  284. if (timeout == 0)
  285. printk("scsi%d: timeout while resetting card\n",
  286. host->host->host_no);
  287. sbic_arm_read(host, SBIC_ASR);
  288. sbic_arm_read(host, SBIC_SSR);
  289. /* setup sbic - WD33C93A */
  290. sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
  291. sbic_arm_write(host, SBIC_CMND, CMND_RESET);
  292. /*
  293. * Command should cause a reset interrupt
  294. */
  295. timeout = 1000;
  296. do {
  297. if (readb(host->fast + INT_REG) & 8)
  298. break;
  299. udelay(1);
  300. } while (--timeout);
  301. if (timeout == 0)
  302. printk("scsi%d: timeout while resetting card\n",
  303. host->host->host_no);
  304. sbic_arm_read(host, SBIC_ASR);
  305. if (sbic_arm_read(host, SBIC_SSR) != 0x01)
  306. printk(KERN_CRIT "scsi%d: WD33C93A didn't give enhanced reset interrupt\n",
  307. host->host->host_no);
  308. sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
  309. sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
  310. sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
  311. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  312. host->card.page_reg = 0x40;
  313. writeb(host->card.page_reg, host->fast + PAGE_REG);
  314. /* setup dmac - uPC71071 */
  315. dmac_write(host, DMAC_INIT, 0);
  316. #ifdef USE_DMAC
  317. dmac_write(host, DMAC_INIT, INIT_8BIT);
  318. dmac_write(host, DMAC_CHANNEL, CHANNEL_0);
  319. dmac_write(host, DMAC_DEVCON0, INIT_DEVCON0);
  320. dmac_write(host, DMAC_DEVCON1, INIT_DEVCON1);
  321. #endif
  322. host->SCpnt = NULL;
  323. host->scsi.phase = PHASE_IDLE;
  324. host->scsi.disconnectable = 0;
  325. memset(host->busyluns, 0, sizeof(host->busyluns));
  326. for (i = 0; i < 8; i++) {
  327. host->device[i].sync_state = SYNC_NEGOCIATE;
  328. host->device[i].disconnect_ok = 1;
  329. }
  330. /* wait 25 cs. SCSI standard says 250ms. */
  331. acornscsi_csdelay(25);
  332. }
  333. /*=============================================================================================
  334. * Utility routines (eg. debug)
  335. */
  336. #ifdef CONFIG_ACORNSCSI_CONSTANTS
  337. static char *acornscsi_interrupttype[] = {
  338. "rst", "suc", "p/a", "3",
  339. "term", "5", "6", "7",
  340. "serv", "9", "a", "b",
  341. "c", "d", "e", "f"
  342. };
  343. static signed char acornscsi_map[] = {
  344. 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  345. -1, 2, -1, -1, -1, -1, 3, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  346. 12, 13, 14, -1, -1, -1, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  347. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  348. 15, 16, 17, 18, 19, -1, -1, 20, 4, 5, 6, 7, 8, 9, 10, 11,
  349. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  350. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  351. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  352. 21, 22, -1, -1, -1, 23, -1, -1, 4, 5, 6, 7, 8, 9, 10, 11,
  353. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  354. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  355. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  356. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  357. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  358. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  359. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  360. };
  361. static char *acornscsi_interruptcode[] = {
  362. /* 0 */
  363. "reset - normal mode", /* 00 */
  364. "reset - advanced mode", /* 01 */
  365. /* 2 */
  366. "sel", /* 11 */
  367. "sel+xfer", /* 16 */
  368. "data-out", /* 18 */
  369. "data-in", /* 19 */
  370. "cmd", /* 1A */
  371. "stat", /* 1B */
  372. "??-out", /* 1C */
  373. "??-in", /* 1D */
  374. "msg-out", /* 1E */
  375. "msg-in", /* 1F */
  376. /* 12 */
  377. "/ACK asserted", /* 20 */
  378. "save-data-ptr", /* 21 */
  379. "{re}sel", /* 22 */
  380. /* 15 */
  381. "inv cmd", /* 40 */
  382. "unexpected disconnect", /* 41 */
  383. "sel timeout", /* 42 */
  384. "P err", /* 43 */
  385. "P err+ATN", /* 44 */
  386. "bad status byte", /* 47 */
  387. /* 21 */
  388. "resel, no id", /* 80 */
  389. "resel", /* 81 */
  390. "discon", /* 85 */
  391. };
  392. static
  393. void print_scsi_status(unsigned int ssr)
  394. {
  395. if (acornscsi_map[ssr] != -1)
  396. printk("%s:%s",
  397. acornscsi_interrupttype[(ssr >> 4)],
  398. acornscsi_interruptcode[acornscsi_map[ssr]]);
  399. else
  400. printk("%X:%X", ssr >> 4, ssr & 0x0f);
  401. }
  402. #endif
  403. static
  404. void print_sbic_status(int asr, int ssr, int cmdphase)
  405. {
  406. #ifdef CONFIG_ACORNSCSI_CONSTANTS
  407. printk("sbic: %c%c%c%c%c%c ",
  408. asr & ASR_INT ? 'I' : 'i',
  409. asr & ASR_LCI ? 'L' : 'l',
  410. asr & ASR_BSY ? 'B' : 'b',
  411. asr & ASR_CIP ? 'C' : 'c',
  412. asr & ASR_PE ? 'P' : 'p',
  413. asr & ASR_DBR ? 'D' : 'd');
  414. printk("scsi: ");
  415. print_scsi_status(ssr);
  416. printk(" ph %02X\n", cmdphase);
  417. #else
  418. printk("sbic: %02X scsi: %X:%X ph: %02X\n",
  419. asr, (ssr & 0xf0)>>4, ssr & 0x0f, cmdphase);
  420. #endif
  421. }
  422. static void
  423. acornscsi_dumplogline(AS_Host *host, int target, int line)
  424. {
  425. unsigned long prev;
  426. signed int ptr;
  427. ptr = host->status_ptr[target] - STATUS_BUFFER_TO_PRINT;
  428. if (ptr < 0)
  429. ptr += STATUS_BUFFER_SIZE;
  430. printk("%c: %3s:", target == 8 ? 'H' : '0' + target,
  431. line == 0 ? "ph" : line == 1 ? "ssr" : "int");
  432. prev = host->status[target][ptr].when;
  433. for (; ptr != host->status_ptr[target]; ptr = (ptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
  434. unsigned long time_diff;
  435. if (!host->status[target][ptr].when)
  436. continue;
  437. switch (line) {
  438. case 0:
  439. printk("%c%02X", host->status[target][ptr].irq ? '-' : ' ',
  440. host->status[target][ptr].ph);
  441. break;
  442. case 1:
  443. printk(" %02X", host->status[target][ptr].ssr);
  444. break;
  445. case 2:
  446. time_diff = host->status[target][ptr].when - prev;
  447. prev = host->status[target][ptr].when;
  448. if (time_diff == 0)
  449. printk("==^");
  450. else if (time_diff >= 100)
  451. printk(" ");
  452. else
  453. printk(" %02ld", time_diff);
  454. break;
  455. }
  456. }
  457. printk("\n");
  458. }
  459. static
  460. void acornscsi_dumplog(AS_Host *host, int target)
  461. {
  462. do {
  463. acornscsi_dumplogline(host, target, 0);
  464. acornscsi_dumplogline(host, target, 1);
  465. acornscsi_dumplogline(host, target, 2);
  466. if (target == 8)
  467. break;
  468. target = 8;
  469. } while (1);
  470. }
  471. static
  472. char acornscsi_target(AS_Host *host)
  473. {
  474. if (host->SCpnt)
  475. return '0' + host->SCpnt->device->id;
  476. return 'H';
  477. }
  478. /*
  479. * Prototype: cmdtype_t acornscsi_cmdtype(int command)
  480. * Purpose : differentiate READ from WRITE from other commands
  481. * Params : command - command to interpret
  482. * Returns : CMD_READ - command reads data,
  483. * CMD_WRITE - command writes data,
  484. * CMD_MISC - everything else
  485. */
  486. static inline
  487. cmdtype_t acornscsi_cmdtype(int command)
  488. {
  489. switch (command) {
  490. case WRITE_6: case WRITE_10: case WRITE_12:
  491. return CMD_WRITE;
  492. case READ_6: case READ_10: case READ_12:
  493. return CMD_READ;
  494. default:
  495. return CMD_MISC;
  496. }
  497. }
  498. /*
  499. * Prototype: int acornscsi_datadirection(int command)
  500. * Purpose : differentiate between commands that have a DATA IN phase
  501. * and a DATA OUT phase
  502. * Params : command - command to interpret
  503. * Returns : DATADIR_OUT - data out phase expected
  504. * DATADIR_IN - data in phase expected
  505. */
  506. static
  507. datadir_t acornscsi_datadirection(int command)
  508. {
  509. switch (command) {
  510. case CHANGE_DEFINITION: case COMPARE: case COPY:
  511. case COPY_VERIFY: case LOG_SELECT: case MODE_SELECT:
  512. case MODE_SELECT_10: case SEND_DIAGNOSTIC: case WRITE_BUFFER:
  513. case FORMAT_UNIT: case REASSIGN_BLOCKS: case RESERVE:
  514. case SEARCH_EQUAL: case SEARCH_HIGH: case SEARCH_LOW:
  515. case WRITE_6: case WRITE_10: case WRITE_VERIFY:
  516. case UPDATE_BLOCK: case WRITE_LONG: case WRITE_SAME:
  517. case SEARCH_HIGH_12: case SEARCH_EQUAL_12: case SEARCH_LOW_12:
  518. case WRITE_12: case WRITE_VERIFY_12: case SET_WINDOW:
  519. case MEDIUM_SCAN: case SEND_VOLUME_TAG: case 0xea:
  520. return DATADIR_OUT;
  521. default:
  522. return DATADIR_IN;
  523. }
  524. }
  525. /*
  526. * Purpose : provide values for synchronous transfers with 33C93.
  527. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  528. * Modified by Russell King for 8MHz WD33C93A
  529. */
  530. static struct sync_xfer_tbl {
  531. unsigned int period_ns;
  532. unsigned char reg_value;
  533. } sync_xfer_table[] = {
  534. { 1, 0x20 }, { 249, 0x20 }, { 374, 0x30 },
  535. { 499, 0x40 }, { 624, 0x50 }, { 749, 0x60 },
  536. { 874, 0x70 }, { 999, 0x00 }, { 0, 0 }
  537. };
  538. /*
  539. * Prototype: int acornscsi_getperiod(unsigned char syncxfer)
  540. * Purpose : period for the synchronous transfer setting
  541. * Params : syncxfer SYNCXFER register value
  542. * Returns : period in ns.
  543. */
  544. static
  545. int acornscsi_getperiod(unsigned char syncxfer)
  546. {
  547. int i;
  548. syncxfer &= 0xf0;
  549. if (syncxfer == 0x10)
  550. syncxfer = 0;
  551. for (i = 1; sync_xfer_table[i].period_ns; i++)
  552. if (syncxfer == sync_xfer_table[i].reg_value)
  553. return sync_xfer_table[i].period_ns;
  554. return 0;
  555. }
  556. /*
  557. * Prototype: int round_period(unsigned int period)
  558. * Purpose : return index into above table for a required REQ period
  559. * Params : period - time (ns) for REQ
  560. * Returns : table index
  561. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  562. */
  563. static inline
  564. int round_period(unsigned int period)
  565. {
  566. int i;
  567. for (i = 1; sync_xfer_table[i].period_ns; i++) {
  568. if ((period <= sync_xfer_table[i].period_ns) &&
  569. (period > sync_xfer_table[i - 1].period_ns))
  570. return i;
  571. }
  572. return 7;
  573. }
  574. /*
  575. * Prototype: unsigned char calc_sync_xfer(unsigned int period, unsigned int offset)
  576. * Purpose : calculate value for 33c93s SYNC register
  577. * Params : period - time (ns) for REQ
  578. * offset - offset in bytes between REQ/ACK
  579. * Returns : value for SYNC register
  580. * Copyright: Copyright (c) 1996 John Shifflett, GeoLog Consulting
  581. */
  582. static
  583. unsigned char __maybe_unused calc_sync_xfer(unsigned int period,
  584. unsigned int offset)
  585. {
  586. return sync_xfer_table[round_period(period)].reg_value |
  587. ((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
  588. }
  589. /* ====================================================================================
  590. * Command functions
  591. */
  592. /*
  593. * Function: acornscsi_kick(AS_Host *host)
  594. * Purpose : kick next command to interface
  595. * Params : host - host to send command to
  596. * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
  597. * Notes : interrupts are always disabled!
  598. */
  599. static
  600. intr_ret_t acornscsi_kick(AS_Host *host)
  601. {
  602. int from_queue = 0;
  603. struct scsi_cmnd *SCpnt;
  604. /* first check to see if a command is waiting to be executed */
  605. SCpnt = host->origSCpnt;
  606. host->origSCpnt = NULL;
  607. /* retrieve next command */
  608. if (!SCpnt) {
  609. SCpnt = queue_remove_exclude(&host->queues.issue, host->busyluns);
  610. if (!SCpnt)
  611. return INTR_IDLE;
  612. from_queue = 1;
  613. }
  614. if (host->scsi.disconnectable && host->SCpnt) {
  615. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  616. host->scsi.disconnectable = 0;
  617. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  618. DBG(host->SCpnt, printk("scsi%d.%c: moved command to disconnected queue\n",
  619. host->host->host_no, acornscsi_target(host)));
  620. #endif
  621. host->SCpnt = NULL;
  622. }
  623. /*
  624. * If we have an interrupt pending, then we may have been reselected.
  625. * In this case, we don't want to write to the registers
  626. */
  627. if (!(sbic_arm_read(host, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
  628. sbic_arm_write(host, SBIC_DESTID, SCpnt->device->id);
  629. sbic_arm_write(host, SBIC_CMND, CMND_SELWITHATN);
  630. }
  631. /*
  632. * claim host busy - all of these must happen atomically wrt
  633. * our interrupt routine. Failure means command loss.
  634. */
  635. host->scsi.phase = PHASE_CONNECTING;
  636. host->SCpnt = SCpnt;
  637. host->scsi.SCp = SCpnt->SCp;
  638. host->dma.xfer_setup = 0;
  639. host->dma.xfer_required = 0;
  640. host->dma.xfer_done = 0;
  641. #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
  642. DBG(SCpnt,printk("scsi%d.%c: starting cmd %02X\n",
  643. host->host->host_no, '0' + SCpnt->device->id,
  644. SCpnt->cmnd[0]));
  645. #endif
  646. if (from_queue) {
  647. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  648. /*
  649. * tagged queueing - allocate a new tag to this command
  650. */
  651. if (SCpnt->device->simple_tags) {
  652. SCpnt->device->current_tag += 1;
  653. if (SCpnt->device->current_tag == 0)
  654. SCpnt->device->current_tag = 1;
  655. SCpnt->tag = SCpnt->device->current_tag;
  656. } else
  657. #endif
  658. set_bit(SCpnt->device->id * 8 +
  659. (u8)(SCpnt->device->lun & 0x07), host->busyluns);
  660. host->stats.removes += 1;
  661. switch (acornscsi_cmdtype(SCpnt->cmnd[0])) {
  662. case CMD_WRITE:
  663. host->stats.writes += 1;
  664. break;
  665. case CMD_READ:
  666. host->stats.reads += 1;
  667. break;
  668. case CMD_MISC:
  669. host->stats.miscs += 1;
  670. break;
  671. }
  672. }
  673. return INTR_PROCESSING;
  674. }
  675. /*
  676. * Function: void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, unsigned int result)
  677. * Purpose : complete processing for command
  678. * Params : host - interface that completed
  679. * result - driver byte of result
  680. */
  681. static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
  682. unsigned int result)
  683. {
  684. struct scsi_cmnd *SCpnt = *SCpntp;
  685. /* clean up */
  686. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  687. host->stats.fins += 1;
  688. if (SCpnt) {
  689. *SCpntp = NULL;
  690. acornscsi_dma_cleanup(host);
  691. SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
  692. /*
  693. * In theory, this should not happen. In practice, it seems to.
  694. * Only trigger an error if the device attempts to report all happy
  695. * but with untransferred buffers... If we don't do something, then
  696. * data loss will occur. Should we check SCpnt->underflow here?
  697. * It doesn't appear to be set to something meaningful by the higher
  698. * levels all the time.
  699. */
  700. if (result == DID_OK) {
  701. int xfer_warn = 0;
  702. if (SCpnt->underflow == 0) {
  703. if (host->scsi.SCp.ptr &&
  704. acornscsi_cmdtype(SCpnt->cmnd[0]) != CMD_MISC)
  705. xfer_warn = 1;
  706. } else {
  707. if (host->scsi.SCp.scsi_xferred < SCpnt->underflow ||
  708. host->scsi.SCp.scsi_xferred != host->dma.transferred)
  709. xfer_warn = 1;
  710. }
  711. /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
  712. * Targets which break data transfers into multiple
  713. * connections shall end each successful connection
  714. * (except possibly the last) with a SAVE DATA
  715. * POINTER - DISCONNECT message sequence.
  716. *
  717. * This makes it difficult to ensure that a transfer has
  718. * completed. If we reach the end of a transfer during
  719. * the command, then we can only have finished the transfer.
  720. * therefore, if we seem to have some data remaining, this
  721. * is not a problem.
  722. */
  723. if (host->dma.xfer_done)
  724. xfer_warn = 0;
  725. if (xfer_warn) {
  726. switch (status_byte(SCpnt->result)) {
  727. case CHECK_CONDITION:
  728. case COMMAND_TERMINATED:
  729. case BUSY:
  730. case QUEUE_FULL:
  731. case RESERVATION_CONFLICT:
  732. break;
  733. default:
  734. scmd_printk(KERN_ERR, SCpnt,
  735. "incomplete data transfer detected: "
  736. "result=%08X", SCpnt->result);
  737. scsi_print_command(SCpnt);
  738. acornscsi_dumpdma(host, "done");
  739. acornscsi_dumplog(host, SCpnt->device->id);
  740. set_host_byte(SCpnt, DID_ERROR);
  741. }
  742. }
  743. }
  744. if (!SCpnt->scsi_done)
  745. panic("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
  746. clear_bit(SCpnt->device->id * 8 +
  747. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  748. SCpnt->scsi_done(SCpnt);
  749. } else
  750. printk("scsi%d: null command in acornscsi_done", host->host->host_no);
  751. host->scsi.phase = PHASE_IDLE;
  752. }
  753. /* ====================================================================================
  754. * DMA routines
  755. */
  756. /*
  757. * Purpose : update SCSI Data Pointer
  758. * Notes : this will only be one SG entry or less
  759. */
  760. static
  761. void acornscsi_data_updateptr(AS_Host *host, struct scsi_pointer *SCp, unsigned int length)
  762. {
  763. SCp->ptr += length;
  764. SCp->this_residual -= length;
  765. if (SCp->this_residual == 0 && next_SCp(SCp) == 0)
  766. host->dma.xfer_done = 1;
  767. }
  768. /*
  769. * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
  770. * unsigned int start_addr, unsigned int length)
  771. * Purpose : read data from DMA RAM
  772. * Params : host - host to transfer from
  773. * ptr - DRAM address
  774. * start_addr - host mem address
  775. * length - number of bytes to transfer
  776. * Notes : this will only be one SG entry or less
  777. */
  778. static
  779. void acornscsi_data_read(AS_Host *host, char *ptr,
  780. unsigned int start_addr, unsigned int length)
  781. {
  782. extern void __acornscsi_in(void __iomem *, char *buf, int len);
  783. unsigned int page, offset, len = length;
  784. page = (start_addr >> 12);
  785. offset = start_addr & ((1 << 12) - 1);
  786. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  787. while (len > 0) {
  788. unsigned int this_len;
  789. if (len + offset > (1 << 12))
  790. this_len = (1 << 12) - offset;
  791. else
  792. this_len = len;
  793. __acornscsi_in(host->base + (offset << 1), ptr, this_len);
  794. offset += this_len;
  795. ptr += this_len;
  796. len -= this_len;
  797. if (offset == (1 << 12)) {
  798. offset = 0;
  799. page ++;
  800. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  801. }
  802. }
  803. writeb(host->card.page_reg, host->fast + PAGE_REG);
  804. }
  805. /*
  806. * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
  807. * unsigned int start_addr, unsigned int length)
  808. * Purpose : write data to DMA RAM
  809. * Params : host - host to transfer from
  810. * ptr - DRAM address
  811. * start_addr - host mem address
  812. * length - number of bytes to transfer
  813. * Notes : this will only be one SG entry or less
  814. */
  815. static
  816. void acornscsi_data_write(AS_Host *host, char *ptr,
  817. unsigned int start_addr, unsigned int length)
  818. {
  819. extern void __acornscsi_out(void __iomem *, char *buf, int len);
  820. unsigned int page, offset, len = length;
  821. page = (start_addr >> 12);
  822. offset = start_addr & ((1 << 12) - 1);
  823. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  824. while (len > 0) {
  825. unsigned int this_len;
  826. if (len + offset > (1 << 12))
  827. this_len = (1 << 12) - offset;
  828. else
  829. this_len = len;
  830. __acornscsi_out(host->base + (offset << 1), ptr, this_len);
  831. offset += this_len;
  832. ptr += this_len;
  833. len -= this_len;
  834. if (offset == (1 << 12)) {
  835. offset = 0;
  836. page ++;
  837. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  838. }
  839. }
  840. writeb(host->card.page_reg, host->fast + PAGE_REG);
  841. }
  842. /* =========================================================================================
  843. * On-board DMA routines
  844. */
  845. #ifdef USE_DMAC
  846. /*
  847. * Prototype: void acornscsi_dmastop(AS_Host *host)
  848. * Purpose : stop all DMA
  849. * Params : host - host on which to stop DMA
  850. * Notes : This is called when leaving DATA IN/OUT phase,
  851. * or when interface is RESET
  852. */
  853. static inline
  854. void acornscsi_dma_stop(AS_Host *host)
  855. {
  856. dmac_write(host, DMAC_MASKREG, MASK_ON);
  857. dmac_clearintr(host);
  858. #if (DEBUG & DEBUG_DMA)
  859. DBG(host->SCpnt, acornscsi_dumpdma(host, "stop"));
  860. #endif
  861. }
  862. /*
  863. * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  864. * Purpose : setup DMA controller for data transfer
  865. * Params : host - host to setup
  866. * direction - data transfer direction
  867. * Notes : This is called when entering DATA I/O phase, not
  868. * while we're in a DATA I/O phase
  869. */
  870. static
  871. void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  872. {
  873. unsigned int address, length, mode;
  874. host->dma.direction = direction;
  875. dmac_write(host, DMAC_MASKREG, MASK_ON);
  876. if (direction == DMA_OUT) {
  877. #if (DEBUG & DEBUG_NO_WRITE)
  878. if (NO_WRITE & (1 << host->SCpnt->device->id)) {
  879. printk(KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
  880. host->host->host_no, acornscsi_target(host));
  881. return;
  882. }
  883. #endif
  884. mode = DMAC_WRITE;
  885. } else
  886. mode = DMAC_READ;
  887. /*
  888. * Allocate some buffer space, limited to half the buffer size
  889. */
  890. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  891. if (length) {
  892. host->dma.start_addr = address = host->dma.free_addr;
  893. host->dma.free_addr = (host->dma.free_addr + length) &
  894. (DMAC_BUFFER_SIZE - 1);
  895. /*
  896. * Transfer data to DMA memory
  897. */
  898. if (direction == DMA_OUT)
  899. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  900. length);
  901. length -= 1;
  902. dmac_write(host, DMAC_TXCNTLO, length);
  903. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  904. dmac_write(host, DMAC_TXADRLO, address);
  905. dmac_write(host, DMAC_TXADRMD, address >> 8);
  906. dmac_write(host, DMAC_TXADRHI, 0);
  907. dmac_write(host, DMAC_MODECON, mode);
  908. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  909. #if (DEBUG & DEBUG_DMA)
  910. DBG(host->SCpnt, acornscsi_dumpdma(host, "strt"));
  911. #endif
  912. host->dma.xfer_setup = 1;
  913. }
  914. }
  915. /*
  916. * Function: void acornscsi_dma_cleanup(AS_Host *host)
  917. * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
  918. * Params : host - host to finish
  919. * Notes : This is called when a command is:
  920. * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
  921. * : This must not return until all transfers are completed.
  922. */
  923. static
  924. void acornscsi_dma_cleanup(AS_Host *host)
  925. {
  926. dmac_write(host, DMAC_MASKREG, MASK_ON);
  927. dmac_clearintr(host);
  928. /*
  929. * Check for a pending transfer
  930. */
  931. if (host->dma.xfer_required) {
  932. host->dma.xfer_required = 0;
  933. if (host->dma.direction == DMA_IN)
  934. acornscsi_data_read(host, host->dma.xfer_ptr,
  935. host->dma.xfer_start, host->dma.xfer_length);
  936. }
  937. /*
  938. * Has a transfer been setup?
  939. */
  940. if (host->dma.xfer_setup) {
  941. unsigned int transferred;
  942. host->dma.xfer_setup = 0;
  943. #if (DEBUG & DEBUG_DMA)
  944. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupi"));
  945. #endif
  946. /*
  947. * Calculate number of bytes transferred from DMA.
  948. */
  949. transferred = dmac_address(host) - host->dma.start_addr;
  950. host->dma.transferred += transferred;
  951. if (host->dma.direction == DMA_IN)
  952. acornscsi_data_read(host, host->scsi.SCp.ptr,
  953. host->dma.start_addr, transferred);
  954. /*
  955. * Update SCSI pointers
  956. */
  957. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  958. #if (DEBUG & DEBUG_DMA)
  959. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupo"));
  960. #endif
  961. }
  962. }
  963. /*
  964. * Function: void acornscsi_dmacintr(AS_Host *host)
  965. * Purpose : handle interrupts from DMAC device
  966. * Params : host - host to process
  967. * Notes : If reading, we schedule the read to main memory &
  968. * allow the transfer to continue.
  969. * : If writing, we fill the onboard DMA memory from main
  970. * memory.
  971. * : Called whenever DMAC finished it's current transfer.
  972. */
  973. static
  974. void acornscsi_dma_intr(AS_Host *host)
  975. {
  976. unsigned int address, length, transferred;
  977. #if (DEBUG & DEBUG_DMA)
  978. DBG(host->SCpnt, acornscsi_dumpdma(host, "inti"));
  979. #endif
  980. dmac_write(host, DMAC_MASKREG, MASK_ON);
  981. dmac_clearintr(host);
  982. /*
  983. * Calculate amount transferred via DMA
  984. */
  985. transferred = dmac_address(host) - host->dma.start_addr;
  986. host->dma.transferred += transferred;
  987. /*
  988. * Schedule DMA transfer off board
  989. */
  990. if (host->dma.direction == DMA_IN) {
  991. host->dma.xfer_start = host->dma.start_addr;
  992. host->dma.xfer_length = transferred;
  993. host->dma.xfer_ptr = host->scsi.SCp.ptr;
  994. host->dma.xfer_required = 1;
  995. }
  996. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  997. /*
  998. * Allocate some buffer space, limited to half the on-board RAM size
  999. */
  1000. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  1001. if (length) {
  1002. host->dma.start_addr = address = host->dma.free_addr;
  1003. host->dma.free_addr = (host->dma.free_addr + length) &
  1004. (DMAC_BUFFER_SIZE - 1);
  1005. /*
  1006. * Transfer data to DMA memory
  1007. */
  1008. if (host->dma.direction == DMA_OUT)
  1009. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  1010. length);
  1011. length -= 1;
  1012. dmac_write(host, DMAC_TXCNTLO, length);
  1013. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  1014. dmac_write(host, DMAC_TXADRLO, address);
  1015. dmac_write(host, DMAC_TXADRMD, address >> 8);
  1016. dmac_write(host, DMAC_TXADRHI, 0);
  1017. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1018. #if (DEBUG & DEBUG_DMA)
  1019. DBG(host->SCpnt, acornscsi_dumpdma(host, "into"));
  1020. #endif
  1021. } else {
  1022. host->dma.xfer_setup = 0;
  1023. #if 0
  1024. /*
  1025. * If the interface still wants more, then this is an error.
  1026. * We give it another byte, but we also attempt to raise an
  1027. * attention condition. We continue giving one byte until
  1028. * the device recognises the attention.
  1029. */
  1030. if (dmac_read(host, DMAC_STATUS) & STATUS_RQ0) {
  1031. acornscsi_abortcmd(host, host->SCpnt->tag);
  1032. dmac_write(host, DMAC_TXCNTLO, 0);
  1033. dmac_write(host, DMAC_TXCNTHI, 0);
  1034. dmac_write(host, DMAC_TXADRLO, 0);
  1035. dmac_write(host, DMAC_TXADRMD, 0);
  1036. dmac_write(host, DMAC_TXADRHI, 0);
  1037. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1038. }
  1039. #endif
  1040. }
  1041. }
  1042. /*
  1043. * Function: void acornscsi_dma_xfer(AS_Host *host)
  1044. * Purpose : transfer data between AcornSCSI and memory
  1045. * Params : host - host to process
  1046. */
  1047. static
  1048. void acornscsi_dma_xfer(AS_Host *host)
  1049. {
  1050. host->dma.xfer_required = 0;
  1051. if (host->dma.direction == DMA_IN)
  1052. acornscsi_data_read(host, host->dma.xfer_ptr,
  1053. host->dma.xfer_start, host->dma.xfer_length);
  1054. }
  1055. /*
  1056. * Function: void acornscsi_dma_adjust(AS_Host *host)
  1057. * Purpose : adjust DMA pointers & count for bytes transferred to
  1058. * SBIC but not SCSI bus.
  1059. * Params : host - host to adjust DMA count for
  1060. */
  1061. static
  1062. void acornscsi_dma_adjust(AS_Host *host)
  1063. {
  1064. if (host->dma.xfer_setup) {
  1065. signed long transferred;
  1066. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1067. DBG(host->SCpnt, acornscsi_dumpdma(host, "adji"));
  1068. #endif
  1069. /*
  1070. * Calculate correct DMA address - DMA is ahead of SCSI bus while
  1071. * writing.
  1072. * host->scsi.SCp.scsi_xferred is the number of bytes
  1073. * actually transferred to/from the SCSI bus.
  1074. * host->dma.transferred is the number of bytes transferred
  1075. * over DMA since host->dma.start_addr was last set.
  1076. *
  1077. * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
  1078. * - host->dma.transferred
  1079. */
  1080. transferred = host->scsi.SCp.scsi_xferred - host->dma.transferred;
  1081. if (transferred < 0)
  1082. printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
  1083. host->host->host_no, acornscsi_target(host), transferred);
  1084. else if (transferred == 0)
  1085. host->dma.xfer_setup = 0;
  1086. else {
  1087. transferred += host->dma.start_addr;
  1088. dmac_write(host, DMAC_TXADRLO, transferred);
  1089. dmac_write(host, DMAC_TXADRMD, transferred >> 8);
  1090. dmac_write(host, DMAC_TXADRHI, transferred >> 16);
  1091. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1092. DBG(host->SCpnt, acornscsi_dumpdma(host, "adjo"));
  1093. #endif
  1094. }
  1095. }
  1096. }
  1097. #endif
  1098. /* =========================================================================================
  1099. * Data I/O
  1100. */
  1101. static int
  1102. acornscsi_write_pio(AS_Host *host, char *bytes, int *ptr, int len, unsigned int max_timeout)
  1103. {
  1104. unsigned int asr, timeout = max_timeout;
  1105. int my_ptr = *ptr;
  1106. while (my_ptr < len) {
  1107. asr = sbic_arm_read(host, SBIC_ASR);
  1108. if (asr & ASR_DBR) {
  1109. timeout = max_timeout;
  1110. sbic_arm_write(host, SBIC_DATA, bytes[my_ptr++]);
  1111. } else if (asr & ASR_INT)
  1112. break;
  1113. else if (--timeout == 0)
  1114. break;
  1115. udelay(1);
  1116. }
  1117. *ptr = my_ptr;
  1118. return (timeout == 0) ? -1 : 0;
  1119. }
  1120. /*
  1121. * Function: void acornscsi_sendcommand(AS_Host *host)
  1122. * Purpose : send a command to a target
  1123. * Params : host - host which is connected to target
  1124. */
  1125. static void
  1126. acornscsi_sendcommand(AS_Host *host)
  1127. {
  1128. struct scsi_cmnd *SCpnt = host->SCpnt;
  1129. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1130. sbic_arm_writenext(host, 0);
  1131. sbic_arm_writenext(host, SCpnt->cmd_len - host->scsi.SCp.sent_command);
  1132. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1133. if (acornscsi_write_pio(host, SCpnt->cmnd,
  1134. (int *)&host->scsi.SCp.sent_command, SCpnt->cmd_len, 1000000))
  1135. printk("scsi%d: timeout while sending command\n", host->host->host_no);
  1136. host->scsi.phase = PHASE_COMMAND;
  1137. }
  1138. static
  1139. void acornscsi_sendmessage(AS_Host *host)
  1140. {
  1141. unsigned int message_length = msgqueue_msglength(&host->scsi.msgs);
  1142. unsigned int msgnr;
  1143. struct message *msg;
  1144. #if (DEBUG & DEBUG_MESSAGES)
  1145. printk("scsi%d.%c: sending message ",
  1146. host->host->host_no, acornscsi_target(host));
  1147. #endif
  1148. switch (message_length) {
  1149. case 0:
  1150. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1151. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 1");
  1152. sbic_arm_write(host, SBIC_DATA, NOP);
  1153. host->scsi.last_message = NOP;
  1154. #if (DEBUG & DEBUG_MESSAGES)
  1155. printk("NOP");
  1156. #endif
  1157. break;
  1158. case 1:
  1159. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1160. msg = msgqueue_getmsg(&host->scsi.msgs, 0);
  1161. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 2");
  1162. sbic_arm_write(host, SBIC_DATA, msg->msg[0]);
  1163. host->scsi.last_message = msg->msg[0];
  1164. #if (DEBUG & DEBUG_MESSAGES)
  1165. spi_print_msg(msg->msg);
  1166. #endif
  1167. break;
  1168. default:
  1169. /*
  1170. * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
  1171. * 'When a target sends this (MESSAGE_REJECT) message, it
  1172. * shall change to MESSAGE IN phase and send this message
  1173. * prior to requesting additional message bytes from the
  1174. * initiator. This provides an interlock so that the
  1175. * initiator can determine which message byte is rejected.
  1176. */
  1177. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1178. sbic_arm_writenext(host, 0);
  1179. sbic_arm_writenext(host, message_length);
  1180. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1181. msgnr = 0;
  1182. while ((msg = msgqueue_getmsg(&host->scsi.msgs, msgnr++)) != NULL) {
  1183. unsigned int i;
  1184. #if (DEBUG & DEBUG_MESSAGES)
  1185. spi_print_msg(msg);
  1186. #endif
  1187. i = 0;
  1188. if (acornscsi_write_pio(host, msg->msg, &i, msg->length, 1000000))
  1189. printk("scsi%d: timeout while sending message\n", host->host->host_no);
  1190. host->scsi.last_message = msg->msg[0];
  1191. if (msg->msg[0] == EXTENDED_MESSAGE)
  1192. host->scsi.last_message |= msg->msg[2] << 8;
  1193. if (i != msg->length)
  1194. break;
  1195. }
  1196. break;
  1197. }
  1198. #if (DEBUG & DEBUG_MESSAGES)
  1199. printk("\n");
  1200. #endif
  1201. }
  1202. /*
  1203. * Function: void acornscsi_readstatusbyte(AS_Host *host)
  1204. * Purpose : Read status byte from connected target
  1205. * Params : host - host connected to target
  1206. */
  1207. static
  1208. void acornscsi_readstatusbyte(AS_Host *host)
  1209. {
  1210. acornscsi_sbic_issuecmd(host, CMND_XFERINFO|CMND_SBT);
  1211. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "reading status byte");
  1212. host->scsi.SCp.Status = sbic_arm_read(host, SBIC_DATA);
  1213. }
  1214. /*
  1215. * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1216. * Purpose : Read one message byte from connected target
  1217. * Params : host - host connected to target
  1218. */
  1219. static
  1220. unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1221. {
  1222. unsigned char message;
  1223. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1224. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "for message byte");
  1225. message = sbic_arm_read(host, SBIC_DATA);
  1226. /* wait for MSGIN-XFER-PAUSED */
  1227. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after message byte");
  1228. sbic_arm_read(host, SBIC_SSR);
  1229. return message;
  1230. }
  1231. /*
  1232. * Function: void acornscsi_message(AS_Host *host)
  1233. * Purpose : Read complete message from connected target & action message
  1234. * Params : host - host connected to target
  1235. */
  1236. static
  1237. void acornscsi_message(AS_Host *host)
  1238. {
  1239. unsigned char message[16];
  1240. unsigned int msgidx = 0, msglen = 1;
  1241. do {
  1242. message[msgidx] = acornscsi_readmessagebyte(host);
  1243. switch (msgidx) {
  1244. case 0:
  1245. if (message[0] == EXTENDED_MESSAGE ||
  1246. (message[0] >= 0x20 && message[0] <= 0x2f))
  1247. msglen = 2;
  1248. break;
  1249. case 1:
  1250. if (message[0] == EXTENDED_MESSAGE)
  1251. msglen += message[msgidx];
  1252. break;
  1253. }
  1254. msgidx += 1;
  1255. if (msgidx < msglen) {
  1256. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1257. /* wait for next msg-in */
  1258. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after negate ack");
  1259. sbic_arm_read(host, SBIC_SSR);
  1260. }
  1261. } while (msgidx < msglen);
  1262. #if (DEBUG & DEBUG_MESSAGES)
  1263. printk("scsi%d.%c: message in: ",
  1264. host->host->host_no, acornscsi_target(host));
  1265. spi_print_msg(message);
  1266. printk("\n");
  1267. #endif
  1268. if (host->scsi.phase == PHASE_RECONNECTED) {
  1269. /*
  1270. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1271. * 'Whenever a target reconnects to an initiator to continue
  1272. * a tagged I/O process, the SIMPLE QUEUE TAG message shall
  1273. * be sent immediately following the IDENTIFY message...'
  1274. */
  1275. if (message[0] == SIMPLE_QUEUE_TAG)
  1276. host->scsi.reconnected.tag = message[1];
  1277. if (acornscsi_reconnect_finish(host))
  1278. host->scsi.phase = PHASE_MSGIN;
  1279. }
  1280. switch (message[0]) {
  1281. case ABORT:
  1282. case ABORT_TAG:
  1283. case COMMAND_COMPLETE:
  1284. if (host->scsi.phase != PHASE_STATUSIN) {
  1285. printk(KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
  1286. host->host->host_no, acornscsi_target(host));
  1287. acornscsi_dumplog(host, host->SCpnt->device->id);
  1288. }
  1289. host->scsi.phase = PHASE_DONE;
  1290. host->scsi.SCp.Message = message[0];
  1291. break;
  1292. case SAVE_POINTERS:
  1293. /*
  1294. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
  1295. * 'The SAVE DATA POINTER message is sent from a target to
  1296. * direct the initiator to copy the active data pointer to
  1297. * the saved data pointer for the current I/O process.
  1298. */
  1299. acornscsi_dma_cleanup(host);
  1300. host->SCpnt->SCp = host->scsi.SCp;
  1301. host->SCpnt->SCp.sent_command = 0;
  1302. host->scsi.phase = PHASE_MSGIN;
  1303. break;
  1304. case RESTORE_POINTERS:
  1305. /*
  1306. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
  1307. * 'The RESTORE POINTERS message is sent from a target to
  1308. * direct the initiator to copy the most recently saved
  1309. * command, data, and status pointers for the I/O process
  1310. * to the corresponding active pointers. The command and
  1311. * status pointers shall be restored to the beginning of
  1312. * the present command and status areas.'
  1313. */
  1314. acornscsi_dma_cleanup(host);
  1315. host->scsi.SCp = host->SCpnt->SCp;
  1316. host->scsi.phase = PHASE_MSGIN;
  1317. break;
  1318. case DISCONNECT:
  1319. /*
  1320. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
  1321. * 'On those occasions when an error or exception condition occurs
  1322. * and the target elects to repeat the information transfer, the
  1323. * target may repeat the transfer either issuing a RESTORE POINTERS
  1324. * message or by disconnecting without issuing a SAVE POINTERS
  1325. * message. When reconnection is completed, the most recent
  1326. * saved pointer values are restored.'
  1327. */
  1328. acornscsi_dma_cleanup(host);
  1329. host->scsi.phase = PHASE_DISCONNECT;
  1330. break;
  1331. case MESSAGE_REJECT:
  1332. #if 0 /* this isn't needed any more */
  1333. /*
  1334. * If we were negociating sync transfer, we don't yet know if
  1335. * this REJECT is for the sync transfer or for the tagged queue/wide
  1336. * transfer. Re-initiate sync transfer negotiation now, and if
  1337. * we got a REJECT in response to SDTR, then it'll be set to DONE.
  1338. */
  1339. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST)
  1340. host->device[host->SCpnt->device->id].sync_state = SYNC_NEGOCIATE;
  1341. #endif
  1342. /*
  1343. * If we have any messages waiting to go out, then assert ATN now
  1344. */
  1345. if (msgqueue_msglength(&host->scsi.msgs))
  1346. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1347. switch (host->scsi.last_message) {
  1348. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1349. case HEAD_OF_QUEUE_TAG:
  1350. case ORDERED_QUEUE_TAG:
  1351. case SIMPLE_QUEUE_TAG:
  1352. /*
  1353. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1354. * If a target does not implement tagged queuing and a queue tag
  1355. * message is received, it shall respond with a MESSAGE REJECT
  1356. * message and accept the I/O process as if it were untagged.
  1357. */
  1358. printk(KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
  1359. host->host->host_no, acornscsi_target(host));
  1360. host->SCpnt->device->simple_tags = 0;
  1361. set_bit(host->SCpnt->device->id * 8 +
  1362. (u8)(host->SCpnt->device->lun & 0x7), host->busyluns);
  1363. break;
  1364. #endif
  1365. case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
  1366. /*
  1367. * Target can't handle synchronous transfers
  1368. */
  1369. printk(KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
  1370. host->host->host_no, acornscsi_target(host));
  1371. host->device[host->SCpnt->device->id].sync_xfer = SYNCHTRANSFER_2DBA;
  1372. host->device[host->SCpnt->device->id].sync_state = SYNC_ASYNCHRONOUS;
  1373. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1374. break;
  1375. default:
  1376. break;
  1377. }
  1378. break;
  1379. case QUEUE_FULL:
  1380. /* TODO: target queue is full */
  1381. break;
  1382. case SIMPLE_QUEUE_TAG:
  1383. /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
  1384. printk("scsi%d.%c: reconnect queue tag %02X\n",
  1385. host->host->host_no, acornscsi_target(host),
  1386. message[1]);
  1387. break;
  1388. case EXTENDED_MESSAGE:
  1389. switch (message[2]) {
  1390. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1391. case EXTENDED_SDTR:
  1392. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST) {
  1393. /*
  1394. * We requested synchronous transfers. This isn't quite right...
  1395. * We can only say if this succeeded if we proceed on to execute the
  1396. * command from this message. If we get a MESSAGE PARITY ERROR,
  1397. * and the target retries fail, then we fallback to asynchronous mode
  1398. */
  1399. host->device[host->SCpnt->device->id].sync_state = SYNC_COMPLETED;
  1400. printk(KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
  1401. host->host->host_no, acornscsi_target(host),
  1402. message[4], message[3] * 4);
  1403. host->device[host->SCpnt->device->id].sync_xfer =
  1404. calc_sync_xfer(message[3] * 4, message[4]);
  1405. } else {
  1406. unsigned char period, length;
  1407. /*
  1408. * Target requested synchronous transfers. The agreement is only
  1409. * to be in operation AFTER the target leaves message out phase.
  1410. */
  1411. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1412. period = max_t(unsigned int, message[3], sdtr_period / 4);
  1413. length = min_t(unsigned int, message[4], sdtr_size);
  1414. msgqueue_addmsg(&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
  1415. EXTENDED_SDTR, period, length);
  1416. host->device[host->SCpnt->device->id].sync_xfer =
  1417. calc_sync_xfer(period * 4, length);
  1418. }
  1419. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1420. break;
  1421. #else
  1422. /* We do not accept synchronous transfers. Respond with a
  1423. * MESSAGE_REJECT.
  1424. */
  1425. #endif
  1426. case EXTENDED_WDTR:
  1427. /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
  1428. * to a wide data transfer request.
  1429. */
  1430. default:
  1431. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1432. msgqueue_flush(&host->scsi.msgs);
  1433. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1434. break;
  1435. }
  1436. break;
  1437. default: /* reject message */
  1438. printk(KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
  1439. host->host->host_no, acornscsi_target(host),
  1440. message[0]);
  1441. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1442. msgqueue_flush(&host->scsi.msgs);
  1443. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1444. host->scsi.phase = PHASE_MSGIN;
  1445. break;
  1446. }
  1447. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1448. }
  1449. /*
  1450. * Function: int acornscsi_buildmessages(AS_Host *host)
  1451. * Purpose : build the connection messages for a host
  1452. * Params : host - host to add messages to
  1453. */
  1454. static
  1455. void acornscsi_buildmessages(AS_Host *host)
  1456. {
  1457. #if 0
  1458. /* does the device need resetting? */
  1459. if (cmd_reset) {
  1460. msgqueue_addmsg(&host->scsi.msgs, 1, BUS_DEVICE_RESET);
  1461. return;
  1462. }
  1463. #endif
  1464. msgqueue_addmsg(&host->scsi.msgs, 1,
  1465. IDENTIFY(host->device[host->SCpnt->device->id].disconnect_ok,
  1466. host->SCpnt->device->lun));
  1467. #if 0
  1468. /* does the device need the current command aborted */
  1469. if (cmd_aborted) {
  1470. acornscsi_abortcmd(host->SCpnt->tag);
  1471. return;
  1472. }
  1473. #endif
  1474. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1475. if (host->SCpnt->tag) {
  1476. unsigned int tag_type;
  1477. if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
  1478. host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
  1479. host->SCpnt->cmnd[0] == INQUIRY)
  1480. tag_type = HEAD_OF_QUEUE_TAG;
  1481. else
  1482. tag_type = SIMPLE_QUEUE_TAG;
  1483. msgqueue_addmsg(&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
  1484. }
  1485. #endif
  1486. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1487. if (host->device[host->SCpnt->device->id].sync_state == SYNC_NEGOCIATE) {
  1488. host->device[host->SCpnt->device->id].sync_state = SYNC_SENT_REQUEST;
  1489. msgqueue_addmsg(&host->scsi.msgs, 5,
  1490. EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
  1491. sdtr_period / 4, sdtr_size);
  1492. }
  1493. #endif
  1494. }
  1495. /*
  1496. * Function: int acornscsi_starttransfer(AS_Host *host)
  1497. * Purpose : transfer data to/from connected target
  1498. * Params : host - host to which target is connected
  1499. * Returns : 0 if failure
  1500. */
  1501. static
  1502. int acornscsi_starttransfer(AS_Host *host)
  1503. {
  1504. int residual;
  1505. if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
  1506. printk(KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
  1507. host->host->host_no, acornscsi_target(host));
  1508. return 0;
  1509. }
  1510. residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
  1511. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1512. sbic_arm_writenext(host, residual >> 16);
  1513. sbic_arm_writenext(host, residual >> 8);
  1514. sbic_arm_writenext(host, residual);
  1515. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1516. return 1;
  1517. }
  1518. /* =========================================================================================
  1519. * Connection & Disconnection
  1520. */
  1521. /*
  1522. * Function : acornscsi_reconnect(AS_Host *host)
  1523. * Purpose : reconnect a previously disconnected command
  1524. * Params : host - host specific data
  1525. * Remarks : SCSI spec says:
  1526. * 'The set of active pointers is restored from the set
  1527. * of saved pointers upon reconnection of the I/O process'
  1528. */
  1529. static
  1530. int acornscsi_reconnect(AS_Host *host)
  1531. {
  1532. unsigned int target, lun, ok = 0;
  1533. target = sbic_arm_read(host, SBIC_SOURCEID);
  1534. if (!(target & 8))
  1535. printk(KERN_ERR "scsi%d: invalid source id after reselection "
  1536. "- device fault?\n",
  1537. host->host->host_no);
  1538. target &= 7;
  1539. if (host->SCpnt && !host->scsi.disconnectable) {
  1540. printk(KERN_ERR "scsi%d.%d: reconnected while command in "
  1541. "progress to target %d?\n",
  1542. host->host->host_no, target, host->SCpnt->device->id);
  1543. host->SCpnt = NULL;
  1544. }
  1545. lun = sbic_arm_read(host, SBIC_DATA) & 7;
  1546. host->scsi.reconnected.target = target;
  1547. host->scsi.reconnected.lun = lun;
  1548. host->scsi.reconnected.tag = 0;
  1549. if (host->scsi.disconnectable && host->SCpnt &&
  1550. host->SCpnt->device->id == target && host->SCpnt->device->lun == lun)
  1551. ok = 1;
  1552. if (!ok && queue_probetgtlun(&host->queues.disconnected, target, lun))
  1553. ok = 1;
  1554. ADD_STATUS(target, 0x81, host->scsi.phase, 0);
  1555. if (ok) {
  1556. host->scsi.phase = PHASE_RECONNECTED;
  1557. } else {
  1558. /* this doesn't seem to work */
  1559. printk(KERN_ERR "scsi%d.%c: reselected with no command "
  1560. "to reconnect with\n",
  1561. host->host->host_no, '0' + target);
  1562. acornscsi_dumplog(host, target);
  1563. acornscsi_abortcmd(host, 0);
  1564. if (host->SCpnt) {
  1565. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1566. host->SCpnt = NULL;
  1567. }
  1568. }
  1569. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1570. return !ok;
  1571. }
  1572. /*
  1573. * Function: int acornscsi_reconect_finish(AS_Host *host)
  1574. * Purpose : finish reconnecting a command
  1575. * Params : host - host to complete
  1576. * Returns : 0 if failed
  1577. */
  1578. static
  1579. int acornscsi_reconnect_finish(AS_Host *host)
  1580. {
  1581. if (host->scsi.disconnectable && host->SCpnt) {
  1582. host->scsi.disconnectable = 0;
  1583. if (host->SCpnt->device->id == host->scsi.reconnected.target &&
  1584. host->SCpnt->device->lun == host->scsi.reconnected.lun &&
  1585. host->SCpnt->tag == host->scsi.reconnected.tag) {
  1586. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1587. DBG(host->SCpnt, printk("scsi%d.%c: reconnected",
  1588. host->host->host_no, acornscsi_target(host)));
  1589. #endif
  1590. } else {
  1591. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1592. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1593. DBG(host->SCpnt, printk("scsi%d.%c: had to move command "
  1594. "to disconnected queue\n",
  1595. host->host->host_no, acornscsi_target(host)));
  1596. #endif
  1597. host->SCpnt = NULL;
  1598. }
  1599. }
  1600. if (!host->SCpnt) {
  1601. host->SCpnt = queue_remove_tgtluntag(&host->queues.disconnected,
  1602. host->scsi.reconnected.target,
  1603. host->scsi.reconnected.lun,
  1604. host->scsi.reconnected.tag);
  1605. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1606. DBG(host->SCpnt, printk("scsi%d.%c: had to get command",
  1607. host->host->host_no, acornscsi_target(host)));
  1608. #endif
  1609. }
  1610. if (!host->SCpnt)
  1611. acornscsi_abortcmd(host, host->scsi.reconnected.tag);
  1612. else {
  1613. /*
  1614. * Restore data pointer from SAVED pointers.
  1615. */
  1616. host->scsi.SCp = host->SCpnt->SCp;
  1617. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1618. printk(", data pointers: [%p, %X]",
  1619. host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
  1620. #endif
  1621. }
  1622. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1623. printk("\n");
  1624. #endif
  1625. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1626. return host->SCpnt != NULL;
  1627. }
  1628. /*
  1629. * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
  1630. * Purpose : handle an unexpected disconnect
  1631. * Params : host - host on which disconnect occurred
  1632. */
  1633. static
  1634. void acornscsi_disconnect_unexpected(AS_Host *host)
  1635. {
  1636. printk(KERN_ERR "scsi%d.%c: unexpected disconnect\n",
  1637. host->host->host_no, acornscsi_target(host));
  1638. #if (DEBUG & DEBUG_ABORT)
  1639. acornscsi_dumplog(host, 8);
  1640. #endif
  1641. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1642. }
  1643. /*
  1644. * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
  1645. * Purpose : abort a currently executing command
  1646. * Params : host - host with connected command to abort
  1647. * tag - tag to abort
  1648. */
  1649. static
  1650. void acornscsi_abortcmd(AS_Host *host, unsigned char tag)
  1651. {
  1652. host->scsi.phase = PHASE_ABORTED;
  1653. sbic_arm_write(host, SBIC_CMND, CMND_ASSERTATN);
  1654. msgqueue_flush(&host->scsi.msgs);
  1655. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1656. if (tag)
  1657. msgqueue_addmsg(&host->scsi.msgs, 2, ABORT_TAG, tag);
  1658. else
  1659. #endif
  1660. msgqueue_addmsg(&host->scsi.msgs, 1, ABORT);
  1661. }
  1662. /* ==========================================================================================
  1663. * Interrupt routines.
  1664. */
  1665. /*
  1666. * Function: int acornscsi_sbicintr(AS_Host *host)
  1667. * Purpose : handle interrupts from SCSI device
  1668. * Params : host - host to process
  1669. * Returns : INTR_PROCESS if expecting another SBIC interrupt
  1670. * INTR_IDLE if no interrupt
  1671. * INTR_NEXT_COMMAND if we have finished processing the command
  1672. */
  1673. static
  1674. intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
  1675. {
  1676. unsigned int asr, ssr;
  1677. asr = sbic_arm_read(host, SBIC_ASR);
  1678. if (!(asr & ASR_INT))
  1679. return INTR_IDLE;
  1680. ssr = sbic_arm_read(host, SBIC_SSR);
  1681. #if (DEBUG & DEBUG_PHASES)
  1682. print_sbic_status(asr, ssr, host->scsi.phase);
  1683. #endif
  1684. ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
  1685. if (host->SCpnt && !host->scsi.disconnectable)
  1686. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1687. switch (ssr) {
  1688. case 0x00: /* reset state - not advanced */
  1689. printk(KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
  1690. host->host->host_no);
  1691. /* setup sbic - WD33C93A */
  1692. sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
  1693. sbic_arm_write(host, SBIC_CMND, CMND_RESET);
  1694. return INTR_IDLE;
  1695. case 0x01: /* reset state - advanced */
  1696. sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
  1697. sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
  1698. sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
  1699. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  1700. msgqueue_flush(&host->scsi.msgs);
  1701. return INTR_IDLE;
  1702. case 0x41: /* unexpected disconnect aborted command */
  1703. acornscsi_disconnect_unexpected(host);
  1704. return INTR_NEXT_COMMAND;
  1705. }
  1706. switch (host->scsi.phase) {
  1707. case PHASE_CONNECTING: /* STATE: command removed from issue queue */
  1708. switch (ssr) {
  1709. case 0x11: /* -> PHASE_CONNECTED */
  1710. /* BUS FREE -> SELECTION */
  1711. host->scsi.phase = PHASE_CONNECTED;
  1712. msgqueue_flush(&host->scsi.msgs);
  1713. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1714. /* 33C93 gives next interrupt indicating bus phase */
  1715. asr = sbic_arm_read(host, SBIC_ASR);
  1716. if (!(asr & ASR_INT))
  1717. break;
  1718. ssr = sbic_arm_read(host, SBIC_SSR);
  1719. ADD_STATUS(8, ssr, host->scsi.phase, 1);
  1720. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, 1);
  1721. goto connected;
  1722. case 0x42: /* select timed out */
  1723. /* -> PHASE_IDLE */
  1724. acornscsi_done(host, &host->SCpnt, DID_NO_CONNECT);
  1725. return INTR_NEXT_COMMAND;
  1726. case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1727. /* BUS FREE -> RESELECTION */
  1728. host->origSCpnt = host->SCpnt;
  1729. host->SCpnt = NULL;
  1730. msgqueue_flush(&host->scsi.msgs);
  1731. acornscsi_reconnect(host);
  1732. break;
  1733. default:
  1734. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
  1735. host->host->host_no, acornscsi_target(host), ssr);
  1736. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1737. acornscsi_abortcmd(host, host->SCpnt->tag);
  1738. }
  1739. return INTR_PROCESSING;
  1740. connected:
  1741. case PHASE_CONNECTED: /* STATE: device selected ok */
  1742. switch (ssr) {
  1743. #ifdef NONSTANDARD
  1744. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1745. /* SELECTION -> COMMAND */
  1746. acornscsi_sendcommand(host);
  1747. break;
  1748. case 0x8b: /* -> PHASE_STATUS */
  1749. /* SELECTION -> STATUS */
  1750. acornscsi_readstatusbyte(host);
  1751. host->scsi.phase = PHASE_STATUSIN;
  1752. break;
  1753. #endif
  1754. case 0x8e: /* -> PHASE_MSGOUT */
  1755. /* SELECTION ->MESSAGE OUT */
  1756. host->scsi.phase = PHASE_MSGOUT;
  1757. acornscsi_buildmessages(host);
  1758. acornscsi_sendmessage(host);
  1759. break;
  1760. /* these should not happen */
  1761. case 0x85: /* target disconnected */
  1762. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1763. break;
  1764. default:
  1765. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
  1766. host->host->host_no, acornscsi_target(host), ssr);
  1767. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1768. acornscsi_abortcmd(host, host->SCpnt->tag);
  1769. }
  1770. return INTR_PROCESSING;
  1771. case PHASE_MSGOUT: /* STATE: connected & sent IDENTIFY message */
  1772. /*
  1773. * SCSI standard says that MESSAGE OUT phases can be followed by a
  1774. * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
  1775. */
  1776. switch (ssr) {
  1777. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1778. case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1779. /* MESSAGE OUT -> COMMAND */
  1780. acornscsi_sendcommand(host);
  1781. break;
  1782. case 0x8b: /* -> PHASE_STATUS */
  1783. case 0x1b: /* -> PHASE_STATUS */
  1784. /* MESSAGE OUT -> STATUS */
  1785. acornscsi_readstatusbyte(host);
  1786. host->scsi.phase = PHASE_STATUSIN;
  1787. break;
  1788. case 0x8e: /* -> PHASE_MSGOUT */
  1789. /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
  1790. acornscsi_sendmessage(host);
  1791. break;
  1792. case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1793. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1794. /* MESSAGE OUT -> MESSAGE IN */
  1795. acornscsi_message(host);
  1796. break;
  1797. default:
  1798. printk(KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
  1799. host->host->host_no, acornscsi_target(host), ssr);
  1800. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1801. }
  1802. return INTR_PROCESSING;
  1803. case PHASE_COMMAND: /* STATE: connected & command sent */
  1804. switch (ssr) {
  1805. case 0x18: /* -> PHASE_DATAOUT */
  1806. /* COMMAND -> DATA OUT */
  1807. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1808. acornscsi_abortcmd(host, host->SCpnt->tag);
  1809. acornscsi_dma_setup(host, DMA_OUT);
  1810. if (!acornscsi_starttransfer(host))
  1811. acornscsi_abortcmd(host, host->SCpnt->tag);
  1812. host->scsi.phase = PHASE_DATAOUT;
  1813. return INTR_IDLE;
  1814. case 0x19: /* -> PHASE_DATAIN */
  1815. /* COMMAND -> DATA IN */
  1816. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1817. acornscsi_abortcmd(host, host->SCpnt->tag);
  1818. acornscsi_dma_setup(host, DMA_IN);
  1819. if (!acornscsi_starttransfer(host))
  1820. acornscsi_abortcmd(host, host->SCpnt->tag);
  1821. host->scsi.phase = PHASE_DATAIN;
  1822. return INTR_IDLE;
  1823. case 0x1b: /* -> PHASE_STATUS */
  1824. /* COMMAND -> STATUS */
  1825. acornscsi_readstatusbyte(host);
  1826. host->scsi.phase = PHASE_STATUSIN;
  1827. break;
  1828. case 0x1e: /* -> PHASE_MSGOUT */
  1829. /* COMMAND -> MESSAGE OUT */
  1830. acornscsi_sendmessage(host);
  1831. break;
  1832. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1833. /* COMMAND -> MESSAGE IN */
  1834. acornscsi_message(host);
  1835. break;
  1836. default:
  1837. printk(KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
  1838. host->host->host_no, acornscsi_target(host), ssr);
  1839. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1840. }
  1841. return INTR_PROCESSING;
  1842. case PHASE_DISCONNECT: /* STATE: connected, received DISCONNECT msg */
  1843. if (ssr == 0x85) { /* -> PHASE_IDLE */
  1844. host->scsi.disconnectable = 1;
  1845. host->scsi.reconnected.tag = 0;
  1846. host->scsi.phase = PHASE_IDLE;
  1847. host->stats.disconnects += 1;
  1848. } else {
  1849. printk(KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
  1850. host->host->host_no, acornscsi_target(host), ssr);
  1851. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1852. }
  1853. return INTR_NEXT_COMMAND;
  1854. case PHASE_IDLE: /* STATE: disconnected */
  1855. if (ssr == 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1856. acornscsi_reconnect(host);
  1857. else {
  1858. printk(KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
  1859. host->host->host_no, acornscsi_target(host), ssr);
  1860. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1861. }
  1862. return INTR_PROCESSING;
  1863. case PHASE_RECONNECTED: /* STATE: device reconnected to initiator */
  1864. /*
  1865. * Command reconnected - if MESGIN, get message - it may be
  1866. * the tag. If not, get command out of disconnected queue
  1867. */
  1868. /*
  1869. * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
  1870. * reconnect I_T_L command
  1871. */
  1872. if (ssr != 0x8f && !acornscsi_reconnect_finish(host))
  1873. return INTR_IDLE;
  1874. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1875. switch (ssr) {
  1876. case 0x88: /* data out phase */
  1877. /* -> PHASE_DATAOUT */
  1878. /* MESSAGE IN -> DATA OUT */
  1879. acornscsi_dma_setup(host, DMA_OUT);
  1880. if (!acornscsi_starttransfer(host))
  1881. acornscsi_abortcmd(host, host->SCpnt->tag);
  1882. host->scsi.phase = PHASE_DATAOUT;
  1883. return INTR_IDLE;
  1884. case 0x89: /* data in phase */
  1885. /* -> PHASE_DATAIN */
  1886. /* MESSAGE IN -> DATA IN */
  1887. acornscsi_dma_setup(host, DMA_IN);
  1888. if (!acornscsi_starttransfer(host))
  1889. acornscsi_abortcmd(host, host->SCpnt->tag);
  1890. host->scsi.phase = PHASE_DATAIN;
  1891. return INTR_IDLE;
  1892. case 0x8a: /* command out */
  1893. /* MESSAGE IN -> COMMAND */
  1894. acornscsi_sendcommand(host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1895. break;
  1896. case 0x8b: /* status in */
  1897. /* -> PHASE_STATUSIN */
  1898. /* MESSAGE IN -> STATUS */
  1899. acornscsi_readstatusbyte(host);
  1900. host->scsi.phase = PHASE_STATUSIN;
  1901. break;
  1902. case 0x8e: /* message out */
  1903. /* -> PHASE_MSGOUT */
  1904. /* MESSAGE IN -> MESSAGE OUT */
  1905. acornscsi_sendmessage(host);
  1906. break;
  1907. case 0x8f: /* message in */
  1908. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1909. break;
  1910. default:
  1911. printk(KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
  1912. host->host->host_no, acornscsi_target(host), ssr);
  1913. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1914. }
  1915. return INTR_PROCESSING;
  1916. case PHASE_DATAIN: /* STATE: transferred data in */
  1917. /*
  1918. * This is simple - if we disconnect then the DMA address & count is
  1919. * correct.
  1920. */
  1921. switch (ssr) {
  1922. case 0x19: /* -> PHASE_DATAIN */
  1923. case 0x89: /* -> PHASE_DATAIN */
  1924. acornscsi_abortcmd(host, host->SCpnt->tag);
  1925. return INTR_IDLE;
  1926. case 0x1b: /* -> PHASE_STATUSIN */
  1927. case 0x4b: /* -> PHASE_STATUSIN */
  1928. case 0x8b: /* -> PHASE_STATUSIN */
  1929. /* DATA IN -> STATUS */
  1930. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1931. acornscsi_sbic_xfcount(host);
  1932. acornscsi_dma_stop(host);
  1933. acornscsi_readstatusbyte(host);
  1934. host->scsi.phase = PHASE_STATUSIN;
  1935. break;
  1936. case 0x1e: /* -> PHASE_MSGOUT */
  1937. case 0x4e: /* -> PHASE_MSGOUT */
  1938. case 0x8e: /* -> PHASE_MSGOUT */
  1939. /* DATA IN -> MESSAGE OUT */
  1940. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1941. acornscsi_sbic_xfcount(host);
  1942. acornscsi_dma_stop(host);
  1943. acornscsi_sendmessage(host);
  1944. break;
  1945. case 0x1f: /* message in */
  1946. case 0x4f: /* message in */
  1947. case 0x8f: /* message in */
  1948. /* DATA IN -> MESSAGE IN */
  1949. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1950. acornscsi_sbic_xfcount(host);
  1951. acornscsi_dma_stop(host);
  1952. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1953. break;
  1954. default:
  1955. printk(KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
  1956. host->host->host_no, acornscsi_target(host), ssr);
  1957. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1958. }
  1959. return INTR_PROCESSING;
  1960. case PHASE_DATAOUT: /* STATE: transferred data out */
  1961. /*
  1962. * This is more complicated - if we disconnect, the DMA could be 12
  1963. * bytes ahead of us. We need to correct this.
  1964. */
  1965. switch (ssr) {
  1966. case 0x18: /* -> PHASE_DATAOUT */
  1967. case 0x88: /* -> PHASE_DATAOUT */
  1968. acornscsi_abortcmd(host, host->SCpnt->tag);
  1969. return INTR_IDLE;
  1970. case 0x1b: /* -> PHASE_STATUSIN */
  1971. case 0x4b: /* -> PHASE_STATUSIN */
  1972. case 0x8b: /* -> PHASE_STATUSIN */
  1973. /* DATA OUT -> STATUS */
  1974. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1975. acornscsi_sbic_xfcount(host);
  1976. acornscsi_dma_stop(host);
  1977. acornscsi_dma_adjust(host);
  1978. acornscsi_readstatusbyte(host);
  1979. host->scsi.phase = PHASE_STATUSIN;
  1980. break;
  1981. case 0x1e: /* -> PHASE_MSGOUT */
  1982. case 0x4e: /* -> PHASE_MSGOUT */
  1983. case 0x8e: /* -> PHASE_MSGOUT */
  1984. /* DATA OUT -> MESSAGE OUT */
  1985. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1986. acornscsi_sbic_xfcount(host);
  1987. acornscsi_dma_stop(host);
  1988. acornscsi_dma_adjust(host);
  1989. acornscsi_sendmessage(host);
  1990. break;
  1991. case 0x1f: /* message in */
  1992. case 0x4f: /* message in */
  1993. case 0x8f: /* message in */
  1994. /* DATA OUT -> MESSAGE IN */
  1995. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1996. acornscsi_sbic_xfcount(host);
  1997. acornscsi_dma_stop(host);
  1998. acornscsi_dma_adjust(host);
  1999. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  2000. break;
  2001. default:
  2002. printk(KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
  2003. host->host->host_no, acornscsi_target(host), ssr);
  2004. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2005. }
  2006. return INTR_PROCESSING;
  2007. case PHASE_STATUSIN: /* STATE: status in complete */
  2008. switch (ssr) {
  2009. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2010. case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2011. /* STATUS -> MESSAGE IN */
  2012. acornscsi_message(host);
  2013. break;
  2014. case 0x1e: /* -> PHASE_MSGOUT */
  2015. case 0x8e: /* -> PHASE_MSGOUT */
  2016. /* STATUS -> MESSAGE OUT */
  2017. acornscsi_sendmessage(host);
  2018. break;
  2019. default:
  2020. printk(KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
  2021. host->host->host_no, acornscsi_target(host), ssr);
  2022. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2023. }
  2024. return INTR_PROCESSING;
  2025. case PHASE_MSGIN: /* STATE: message in */
  2026. switch (ssr) {
  2027. case 0x1e: /* -> PHASE_MSGOUT */
  2028. case 0x4e: /* -> PHASE_MSGOUT */
  2029. case 0x8e: /* -> PHASE_MSGOUT */
  2030. /* MESSAGE IN -> MESSAGE OUT */
  2031. acornscsi_sendmessage(host);
  2032. break;
  2033. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2034. case 0x2f:
  2035. case 0x4f:
  2036. case 0x8f:
  2037. acornscsi_message(host);
  2038. break;
  2039. case 0x85:
  2040. printk("scsi%d.%c: strange message in disconnection\n",
  2041. host->host->host_no, acornscsi_target(host));
  2042. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2043. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  2044. break;
  2045. default:
  2046. printk(KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
  2047. host->host->host_no, acornscsi_target(host), ssr);
  2048. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2049. }
  2050. return INTR_PROCESSING;
  2051. case PHASE_DONE: /* STATE: received status & message */
  2052. switch (ssr) {
  2053. case 0x85: /* -> PHASE_IDLE */
  2054. acornscsi_done(host, &host->SCpnt, DID_OK);
  2055. return INTR_NEXT_COMMAND;
  2056. case 0x1e:
  2057. case 0x8e:
  2058. acornscsi_sendmessage(host);
  2059. break;
  2060. default:
  2061. printk(KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
  2062. host->host->host_no, acornscsi_target(host), ssr);
  2063. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2064. }
  2065. return INTR_PROCESSING;
  2066. case PHASE_ABORTED:
  2067. switch (ssr) {
  2068. case 0x85:
  2069. if (host->SCpnt)
  2070. acornscsi_done(host, &host->SCpnt, DID_ABORT);
  2071. else {
  2072. clear_bit(host->scsi.reconnected.target * 8 + host->scsi.reconnected.lun,
  2073. host->busyluns);
  2074. host->scsi.phase = PHASE_IDLE;
  2075. }
  2076. return INTR_NEXT_COMMAND;
  2077. case 0x1e:
  2078. case 0x2e:
  2079. case 0x4e:
  2080. case 0x8e:
  2081. acornscsi_sendmessage(host);
  2082. break;
  2083. default:
  2084. printk(KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
  2085. host->host->host_no, acornscsi_target(host), ssr);
  2086. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2087. }
  2088. return INTR_PROCESSING;
  2089. default:
  2090. printk(KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
  2091. host->host->host_no, acornscsi_target(host), ssr);
  2092. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2093. }
  2094. return INTR_PROCESSING;
  2095. }
  2096. /*
  2097. * Prototype: void acornscsi_intr(int irq, void *dev_id)
  2098. * Purpose : handle interrupts from Acorn SCSI card
  2099. * Params : irq - interrupt number
  2100. * dev_id - device specific data (AS_Host structure)
  2101. */
  2102. static irqreturn_t
  2103. acornscsi_intr(int irq, void *dev_id)
  2104. {
  2105. AS_Host *host = (AS_Host *)dev_id;
  2106. intr_ret_t ret;
  2107. int iostatus;
  2108. int in_irq = 0;
  2109. do {
  2110. ret = INTR_IDLE;
  2111. iostatus = readb(host->fast + INT_REG);
  2112. if (iostatus & 2) {
  2113. acornscsi_dma_intr(host);
  2114. iostatus = readb(host->fast + INT_REG);
  2115. }
  2116. if (iostatus & 8)
  2117. ret = acornscsi_sbicintr(host, in_irq);
  2118. /*
  2119. * If we have a transfer pending, start it.
  2120. * Only start it if the interface has already started transferring
  2121. * it's data
  2122. */
  2123. if (host->dma.xfer_required)
  2124. acornscsi_dma_xfer(host);
  2125. if (ret == INTR_NEXT_COMMAND)
  2126. ret = acornscsi_kick(host);
  2127. in_irq = 1;
  2128. } while (ret != INTR_IDLE);
  2129. return IRQ_HANDLED;
  2130. }
  2131. /*=============================================================================================
  2132. * Interfaces between interrupt handler and rest of scsi code
  2133. */
  2134. /*
  2135. * Function : acornscsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  2136. * Purpose : queues a SCSI command
  2137. * Params : cmd - SCSI command
  2138. * done - function called on completion, with pointer to command descriptor
  2139. * Returns : 0, or < 0 on error.
  2140. */
  2141. static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
  2142. void (*done)(struct scsi_cmnd *))
  2143. {
  2144. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2145. if (!done) {
  2146. /* there should be some way of rejecting errors like this without panicing... */
  2147. panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
  2148. host->host->host_no, SCpnt);
  2149. return -EINVAL;
  2150. }
  2151. #if (DEBUG & DEBUG_NO_WRITE)
  2152. if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) {
  2153. printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
  2154. host->host->host_no, '0' + SCpnt->device->id);
  2155. SCpnt->result = DID_NO_CONNECT << 16;
  2156. done(SCpnt);
  2157. return 0;
  2158. }
  2159. #endif
  2160. SCpnt->scsi_done = done;
  2161. SCpnt->host_scribble = NULL;
  2162. SCpnt->result = 0;
  2163. SCpnt->tag = 0;
  2164. SCpnt->SCp.phase = (int)acornscsi_datadirection(SCpnt->cmnd[0]);
  2165. SCpnt->SCp.sent_command = 0;
  2166. SCpnt->SCp.scsi_xferred = 0;
  2167. init_SCp(SCpnt);
  2168. host->stats.queues += 1;
  2169. {
  2170. unsigned long flags;
  2171. if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) {
  2172. SCpnt->result = DID_ERROR << 16;
  2173. done(SCpnt);
  2174. return 0;
  2175. }
  2176. local_irq_save(flags);
  2177. if (host->scsi.phase == PHASE_IDLE)
  2178. acornscsi_kick(host);
  2179. local_irq_restore(flags);
  2180. }
  2181. return 0;
  2182. }
  2183. DEF_SCSI_QCMD(acornscsi_queuecmd)
  2184. /*
  2185. * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
  2186. * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
  2187. * Params : SCpntp1 - pointer to command to return
  2188. * SCpntp2 - pointer to command to check
  2189. * result - result to pass back to mid-level done function
  2190. * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
  2191. */
  2192. static inline void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1,
  2193. struct scsi_cmnd **SCpntp2,
  2194. int result)
  2195. {
  2196. struct scsi_cmnd *SCpnt = *SCpntp1;
  2197. if (SCpnt) {
  2198. *SCpntp1 = NULL;
  2199. SCpnt->result = result;
  2200. SCpnt->scsi_done(SCpnt);
  2201. }
  2202. if (SCpnt == *SCpntp2)
  2203. *SCpntp2 = NULL;
  2204. }
  2205. enum res_abort { res_not_running, res_success, res_success_clear, res_snooze };
  2206. /*
  2207. * Prototype: enum res acornscsi_do_abort(struct scsi_cmnd *SCpnt)
  2208. * Purpose : abort a command on this host
  2209. * Params : SCpnt - command to abort
  2210. * Returns : our abort status
  2211. */
  2212. static enum res_abort acornscsi_do_abort(AS_Host *host, struct scsi_cmnd *SCpnt)
  2213. {
  2214. enum res_abort res = res_not_running;
  2215. if (queue_remove_cmd(&host->queues.issue, SCpnt)) {
  2216. /*
  2217. * The command was on the issue queue, and has not been
  2218. * issued yet. We can remove the command from the queue,
  2219. * and acknowledge the abort. Neither the devices nor the
  2220. * interface know about the command.
  2221. */
  2222. //#if (DEBUG & DEBUG_ABORT)
  2223. printk("on issue queue ");
  2224. //#endif
  2225. res = res_success;
  2226. } else if (queue_remove_cmd(&host->queues.disconnected, SCpnt)) {
  2227. /*
  2228. * The command was on the disconnected queue. Simply
  2229. * acknowledge the abort condition, and when the target
  2230. * reconnects, we will give it an ABORT message. The
  2231. * target should then disconnect, and we will clear
  2232. * the busylun bit.
  2233. */
  2234. //#if (DEBUG & DEBUG_ABORT)
  2235. printk("on disconnected queue ");
  2236. //#endif
  2237. res = res_success;
  2238. } else if (host->SCpnt == SCpnt) {
  2239. unsigned long flags;
  2240. //#if (DEBUG & DEBUG_ABORT)
  2241. printk("executing ");
  2242. //#endif
  2243. local_irq_save(flags);
  2244. switch (host->scsi.phase) {
  2245. /*
  2246. * If the interface is idle, and the command is 'disconnectable',
  2247. * then it is the same as on the disconnected queue. We simply
  2248. * remove all traces of the command. When the target reconnects,
  2249. * we will give it an ABORT message since the command could not
  2250. * be found. When the target finally disconnects, we will clear
  2251. * the busylun bit.
  2252. */
  2253. case PHASE_IDLE:
  2254. if (host->scsi.disconnectable) {
  2255. host->scsi.disconnectable = 0;
  2256. host->SCpnt = NULL;
  2257. res = res_success;
  2258. }
  2259. break;
  2260. /*
  2261. * If the command has connected and done nothing further,
  2262. * simply force a disconnect. We also need to clear the
  2263. * busylun bit.
  2264. */
  2265. case PHASE_CONNECTED:
  2266. sbic_arm_write(host, SBIC_CMND, CMND_DISCONNECT);
  2267. host->SCpnt = NULL;
  2268. res = res_success_clear;
  2269. break;
  2270. default:
  2271. acornscsi_abortcmd(host, host->SCpnt->tag);
  2272. res = res_snooze;
  2273. }
  2274. local_irq_restore(flags);
  2275. } else if (host->origSCpnt == SCpnt) {
  2276. /*
  2277. * The command will be executed next, but a command
  2278. * is currently using the interface. This is similar to
  2279. * being on the issue queue, except the busylun bit has
  2280. * been set.
  2281. */
  2282. host->origSCpnt = NULL;
  2283. //#if (DEBUG & DEBUG_ABORT)
  2284. printk("waiting for execution ");
  2285. //#endif
  2286. res = res_success_clear;
  2287. } else
  2288. printk("unknown ");
  2289. return res;
  2290. }
  2291. /*
  2292. * Prototype: int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2293. * Purpose : abort a command on this host
  2294. * Params : SCpnt - command to abort
  2295. * Returns : one of SCSI_ABORT_ macros
  2296. */
  2297. int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2298. {
  2299. AS_Host *host = (AS_Host *) SCpnt->device->host->hostdata;
  2300. int result;
  2301. host->stats.aborts += 1;
  2302. #if (DEBUG & DEBUG_ABORT)
  2303. {
  2304. int asr, ssr;
  2305. asr = sbic_arm_read(host, SBIC_ASR);
  2306. ssr = sbic_arm_read(host, SBIC_SSR);
  2307. printk(KERN_WARNING "acornscsi_abort: ");
  2308. print_sbic_status(asr, ssr, host->scsi.phase);
  2309. acornscsi_dumplog(host, SCpnt->device->id);
  2310. }
  2311. #endif
  2312. printk("scsi%d: ", host->host->host_no);
  2313. switch (acornscsi_do_abort(host, SCpnt)) {
  2314. /*
  2315. * We managed to find the command and cleared it out.
  2316. * We do not expect the command to be executing on the
  2317. * target, but we have set the busylun bit.
  2318. */
  2319. case res_success_clear:
  2320. //#if (DEBUG & DEBUG_ABORT)
  2321. printk("clear ");
  2322. //#endif
  2323. clear_bit(SCpnt->device->id * 8 +
  2324. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  2325. /*
  2326. * We found the command, and cleared it out. Either
  2327. * the command is still known to be executing on the
  2328. * target, or the busylun bit is not set.
  2329. */
  2330. case res_success:
  2331. //#if (DEBUG & DEBUG_ABORT)
  2332. printk("success\n");
  2333. //#endif
  2334. result = SUCCESS;
  2335. break;
  2336. /*
  2337. * We did find the command, but unfortunately we couldn't
  2338. * unhook it from ourselves. Wait some more, and if it
  2339. * still doesn't complete, reset the interface.
  2340. */
  2341. case res_snooze:
  2342. //#if (DEBUG & DEBUG_ABORT)
  2343. printk("snooze\n");
  2344. //#endif
  2345. result = FAILED;
  2346. break;
  2347. /*
  2348. * The command could not be found (either because it completed,
  2349. * or it got dropped.
  2350. */
  2351. default:
  2352. case res_not_running:
  2353. acornscsi_dumplog(host, SCpnt->device->id);
  2354. result = FAILED;
  2355. //#if (DEBUG & DEBUG_ABORT)
  2356. printk("not running\n");
  2357. //#endif
  2358. break;
  2359. }
  2360. return result;
  2361. }
  2362. /*
  2363. * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt)
  2364. * Purpose : reset a command on this host/reset this host
  2365. * Params : SCpnt - command causing reset
  2366. * Returns : one of SCSI_RESET_ macros
  2367. */
  2368. int acornscsi_bus_reset(struct scsi_cmnd *SCpnt)
  2369. {
  2370. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2371. struct scsi_cmnd *SCptr;
  2372. host->stats.resets += 1;
  2373. #if (DEBUG & DEBUG_RESET)
  2374. {
  2375. int asr, ssr;
  2376. asr = sbic_arm_read(host, SBIC_ASR);
  2377. ssr = sbic_arm_read(host, SBIC_SSR);
  2378. printk(KERN_WARNING "acornscsi_reset: ");
  2379. print_sbic_status(asr, ssr, host->scsi.phase);
  2380. acornscsi_dumplog(host, SCpnt->device->id);
  2381. }
  2382. #endif
  2383. acornscsi_dma_stop(host);
  2384. /*
  2385. * do hard reset. This resets all devices on this host, and so we
  2386. * must set the reset status on all commands.
  2387. */
  2388. acornscsi_resetcard(host);
  2389. while ((SCptr = queue_remove(&host->queues.disconnected)) != NULL)
  2390. ;
  2391. return SUCCESS;
  2392. }
  2393. /*==============================================================================================
  2394. * initialisation & miscellaneous support
  2395. */
  2396. /*
  2397. * Function: char *acornscsi_info(struct Scsi_Host *host)
  2398. * Purpose : return a string describing this interface
  2399. * Params : host - host to give information on
  2400. * Returns : a constant string
  2401. */
  2402. const
  2403. char *acornscsi_info(struct Scsi_Host *host)
  2404. {
  2405. static char string[100], *p;
  2406. p = string;
  2407. p += sprintf(string, "%s at port %08lX irq %d v%d.%d.%d"
  2408. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2409. " SYNC"
  2410. #endif
  2411. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2412. " TAG"
  2413. #endif
  2414. #if (DEBUG & DEBUG_NO_WRITE)
  2415. " NOWRITE (" __stringify(NO_WRITE) ")"
  2416. #endif
  2417. , host->hostt->name, host->io_port, host->irq,
  2418. VER_MAJOR, VER_MINOR, VER_PATCH);
  2419. return string;
  2420. }
  2421. static int acornscsi_show_info(struct seq_file *m, struct Scsi_Host *instance)
  2422. {
  2423. int devidx;
  2424. struct scsi_device *scd;
  2425. AS_Host *host;
  2426. host = (AS_Host *)instance->hostdata;
  2427. seq_printf(m, "AcornSCSI driver v%d.%d.%d"
  2428. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2429. " SYNC"
  2430. #endif
  2431. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2432. " TAG"
  2433. #endif
  2434. #if (DEBUG & DEBUG_NO_WRITE)
  2435. " NOWRITE (" __stringify(NO_WRITE) ")"
  2436. #endif
  2437. "\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
  2438. seq_printf(m, "SBIC: WD33C93A Address: %p IRQ : %d\n",
  2439. host->base + SBIC_REGIDX, host->scsi.irq);
  2440. #ifdef USE_DMAC
  2441. seq_printf(m, "DMAC: uPC71071 Address: %p IRQ : %d\n\n",
  2442. host->base + DMAC_OFFSET, host->scsi.irq);
  2443. #endif
  2444. seq_printf(m, "Statistics:\n"
  2445. "Queued commands: %-10u Issued commands: %-10u\n"
  2446. "Done commands : %-10u Reads : %-10u\n"
  2447. "Writes : %-10u Others : %-10u\n"
  2448. "Disconnects : %-10u Aborts : %-10u\n"
  2449. "Resets : %-10u\n\nLast phases:",
  2450. host->stats.queues, host->stats.removes,
  2451. host->stats.fins, host->stats.reads,
  2452. host->stats.writes, host->stats.miscs,
  2453. host->stats.disconnects, host->stats.aborts,
  2454. host->stats.resets);
  2455. for (devidx = 0; devidx < 9; devidx ++) {
  2456. unsigned int statptr, prev;
  2457. seq_printf(m, "\n%c:", devidx == 8 ? 'H' : ('0' + devidx));
  2458. statptr = host->status_ptr[devidx] - 10;
  2459. if ((signed int)statptr < 0)
  2460. statptr += STATUS_BUFFER_SIZE;
  2461. prev = host->status[devidx][statptr].when;
  2462. for (; statptr != host->status_ptr[devidx]; statptr = (statptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
  2463. if (host->status[devidx][statptr].when) {
  2464. seq_printf(m, "%c%02X:%02X+%2ld",
  2465. host->status[devidx][statptr].irq ? '-' : ' ',
  2466. host->status[devidx][statptr].ph,
  2467. host->status[devidx][statptr].ssr,
  2468. (host->status[devidx][statptr].when - prev) < 100 ?
  2469. (host->status[devidx][statptr].when - prev) : 99);
  2470. prev = host->status[devidx][statptr].when;
  2471. }
  2472. }
  2473. }
  2474. seq_printf(m, "\nAttached devices:\n");
  2475. shost_for_each_device(scd, instance) {
  2476. seq_printf(m, "Device/Lun TaggedQ Sync\n");
  2477. seq_printf(m, " %d/%llu ", scd->id, scd->lun);
  2478. if (scd->tagged_supported)
  2479. seq_printf(m, "%3sabled(%3d) ",
  2480. scd->simple_tags ? "en" : "dis",
  2481. scd->current_tag);
  2482. else
  2483. seq_printf(m, "unsupported ");
  2484. if (host->device[scd->id].sync_xfer & 15)
  2485. seq_printf(m, "offset %d, %d ns\n",
  2486. host->device[scd->id].sync_xfer & 15,
  2487. acornscsi_getperiod(host->device[scd->id].sync_xfer));
  2488. else
  2489. seq_printf(m, "async\n");
  2490. }
  2491. return 0;
  2492. }
  2493. static struct scsi_host_template acornscsi_template = {
  2494. .module = THIS_MODULE,
  2495. .show_info = acornscsi_show_info,
  2496. .name = "AcornSCSI",
  2497. .info = acornscsi_info,
  2498. .queuecommand = acornscsi_queuecmd,
  2499. .eh_abort_handler = acornscsi_abort,
  2500. .eh_bus_reset_handler = acornscsi_bus_reset,
  2501. .can_queue = 16,
  2502. .this_id = 7,
  2503. .sg_tablesize = SG_ALL,
  2504. .cmd_per_lun = 2,
  2505. .use_clustering = DISABLE_CLUSTERING,
  2506. .proc_name = "acornscsi",
  2507. };
  2508. static int acornscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  2509. {
  2510. struct Scsi_Host *host;
  2511. AS_Host *ashost;
  2512. int ret;
  2513. ret = ecard_request_resources(ec);
  2514. if (ret)
  2515. goto out;
  2516. host = scsi_host_alloc(&acornscsi_template, sizeof(AS_Host));
  2517. if (!host) {
  2518. ret = -ENOMEM;
  2519. goto out_release;
  2520. }
  2521. ashost = (AS_Host *)host->hostdata;
  2522. ashost->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
  2523. ashost->fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  2524. if (!ashost->base || !ashost->fast)
  2525. goto out_put;
  2526. host->irq = ec->irq;
  2527. ashost->host = host;
  2528. ashost->scsi.irq = host->irq;
  2529. ec->irqaddr = ashost->fast + INT_REG;
  2530. ec->irqmask = 0x0a;
  2531. ret = request_irq(host->irq, acornscsi_intr, 0, "acornscsi", ashost);
  2532. if (ret) {
  2533. printk(KERN_CRIT "scsi%d: IRQ%d not free: %d\n",
  2534. host->host_no, ashost->scsi.irq, ret);
  2535. goto out_put;
  2536. }
  2537. memset(&ashost->stats, 0, sizeof (ashost->stats));
  2538. queue_initialise(&ashost->queues.issue);
  2539. queue_initialise(&ashost->queues.disconnected);
  2540. msgqueue_initialise(&ashost->scsi.msgs);
  2541. acornscsi_resetcard(ashost);
  2542. ret = scsi_add_host(host, &ec->dev);
  2543. if (ret)
  2544. goto out_irq;
  2545. scsi_scan_host(host);
  2546. goto out;
  2547. out_irq:
  2548. free_irq(host->irq, ashost);
  2549. msgqueue_free(&ashost->scsi.msgs);
  2550. queue_free(&ashost->queues.disconnected);
  2551. queue_free(&ashost->queues.issue);
  2552. out_put:
  2553. ecardm_iounmap(ec, ashost->fast);
  2554. ecardm_iounmap(ec, ashost->base);
  2555. scsi_host_put(host);
  2556. out_release:
  2557. ecard_release_resources(ec);
  2558. out:
  2559. return ret;
  2560. }
  2561. static void acornscsi_remove(struct expansion_card *ec)
  2562. {
  2563. struct Scsi_Host *host = ecard_get_drvdata(ec);
  2564. AS_Host *ashost = (AS_Host *)host->hostdata;
  2565. ecard_set_drvdata(ec, NULL);
  2566. scsi_remove_host(host);
  2567. /*
  2568. * Put card into RESET state
  2569. */
  2570. writeb(0x80, ashost->fast + PAGE_REG);
  2571. free_irq(host->irq, ashost);
  2572. msgqueue_free(&ashost->scsi.msgs);
  2573. queue_free(&ashost->queues.disconnected);
  2574. queue_free(&ashost->queues.issue);
  2575. ecardm_iounmap(ec, ashost->fast);
  2576. ecardm_iounmap(ec, ashost->base);
  2577. scsi_host_put(host);
  2578. ecard_release_resources(ec);
  2579. }
  2580. static const struct ecard_id acornscsi_cids[] = {
  2581. { MANU_ACORN, PROD_ACORN_SCSI },
  2582. { 0xffff, 0xffff },
  2583. };
  2584. static struct ecard_driver acornscsi_driver = {
  2585. .probe = acornscsi_probe,
  2586. .remove = acornscsi_remove,
  2587. .id_table = acornscsi_cids,
  2588. .drv = {
  2589. .name = "acornscsi",
  2590. },
  2591. };
  2592. static int __init acornscsi_init(void)
  2593. {
  2594. return ecard_register_driver(&acornscsi_driver);
  2595. }
  2596. static void __exit acornscsi_exit(void)
  2597. {
  2598. ecard_remove_driver(&acornscsi_driver);
  2599. }
  2600. module_init(acornscsi_init);
  2601. module_exit(acornscsi_exit);
  2602. MODULE_AUTHOR("Russell King");
  2603. MODULE_DESCRIPTION("AcornSCSI driver");
  2604. MODULE_LICENSE("GPL");