acornscsi.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014
  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 calc_sync_xfer(unsigned int period, unsigned int offset)
  584. {
  585. return sync_xfer_table[round_period(period)].reg_value |
  586. ((offset < SDTR_SIZE) ? offset : SDTR_SIZE);
  587. }
  588. /* ====================================================================================
  589. * Command functions
  590. */
  591. /*
  592. * Function: acornscsi_kick(AS_Host *host)
  593. * Purpose : kick next command to interface
  594. * Params : host - host to send command to
  595. * Returns : INTR_IDLE if idle, otherwise INTR_PROCESSING
  596. * Notes : interrupts are always disabled!
  597. */
  598. static
  599. intr_ret_t acornscsi_kick(AS_Host *host)
  600. {
  601. int from_queue = 0;
  602. struct scsi_cmnd *SCpnt;
  603. /* first check to see if a command is waiting to be executed */
  604. SCpnt = host->origSCpnt;
  605. host->origSCpnt = NULL;
  606. /* retrieve next command */
  607. if (!SCpnt) {
  608. SCpnt = queue_remove_exclude(&host->queues.issue, host->busyluns);
  609. if (!SCpnt)
  610. return INTR_IDLE;
  611. from_queue = 1;
  612. }
  613. if (host->scsi.disconnectable && host->SCpnt) {
  614. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  615. host->scsi.disconnectable = 0;
  616. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  617. DBG(host->SCpnt, printk("scsi%d.%c: moved command to disconnected queue\n",
  618. host->host->host_no, acornscsi_target(host)));
  619. #endif
  620. host->SCpnt = NULL;
  621. }
  622. /*
  623. * If we have an interrupt pending, then we may have been reselected.
  624. * In this case, we don't want to write to the registers
  625. */
  626. if (!(sbic_arm_read(host, SBIC_ASR) & (ASR_INT|ASR_BSY|ASR_CIP))) {
  627. sbic_arm_write(host, SBIC_DESTID, SCpnt->device->id);
  628. sbic_arm_write(host, SBIC_CMND, CMND_SELWITHATN);
  629. }
  630. /*
  631. * claim host busy - all of these must happen atomically wrt
  632. * our interrupt routine. Failure means command loss.
  633. */
  634. host->scsi.phase = PHASE_CONNECTING;
  635. host->SCpnt = SCpnt;
  636. host->scsi.SCp = SCpnt->SCp;
  637. host->dma.xfer_setup = 0;
  638. host->dma.xfer_required = 0;
  639. host->dma.xfer_done = 0;
  640. #if (DEBUG & (DEBUG_ABORT|DEBUG_CONNECT))
  641. DBG(SCpnt,printk("scsi%d.%c: starting cmd %02X\n",
  642. host->host->host_no, '0' + SCpnt->device->id,
  643. SCpnt->cmnd[0]));
  644. #endif
  645. if (from_queue) {
  646. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  647. /*
  648. * tagged queueing - allocate a new tag to this command
  649. */
  650. if (SCpnt->device->simple_tags) {
  651. SCpnt->device->current_tag += 1;
  652. if (SCpnt->device->current_tag == 0)
  653. SCpnt->device->current_tag = 1;
  654. SCpnt->tag = SCpnt->device->current_tag;
  655. } else
  656. #endif
  657. set_bit(SCpnt->device->id * 8 +
  658. (u8)(SCpnt->device->lun & 0x07), host->busyluns);
  659. host->stats.removes += 1;
  660. switch (acornscsi_cmdtype(SCpnt->cmnd[0])) {
  661. case CMD_WRITE:
  662. host->stats.writes += 1;
  663. break;
  664. case CMD_READ:
  665. host->stats.reads += 1;
  666. break;
  667. case CMD_MISC:
  668. host->stats.miscs += 1;
  669. break;
  670. }
  671. }
  672. return INTR_PROCESSING;
  673. }
  674. /*
  675. * Function: void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, unsigned int result)
  676. * Purpose : complete processing for command
  677. * Params : host - interface that completed
  678. * result - driver byte of result
  679. */
  680. static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
  681. unsigned int result)
  682. {
  683. struct scsi_cmnd *SCpnt = *SCpntp;
  684. /* clean up */
  685. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  686. host->stats.fins += 1;
  687. if (SCpnt) {
  688. *SCpntp = NULL;
  689. acornscsi_dma_cleanup(host);
  690. SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
  691. /*
  692. * In theory, this should not happen. In practice, it seems to.
  693. * Only trigger an error if the device attempts to report all happy
  694. * but with untransferred buffers... If we don't do something, then
  695. * data loss will occur. Should we check SCpnt->underflow here?
  696. * It doesn't appear to be set to something meaningful by the higher
  697. * levels all the time.
  698. */
  699. if (result == DID_OK) {
  700. int xfer_warn = 0;
  701. if (SCpnt->underflow == 0) {
  702. if (host->scsi.SCp.ptr &&
  703. acornscsi_cmdtype(SCpnt->cmnd[0]) != CMD_MISC)
  704. xfer_warn = 1;
  705. } else {
  706. if (host->scsi.SCp.scsi_xferred < SCpnt->underflow ||
  707. host->scsi.SCp.scsi_xferred != host->dma.transferred)
  708. xfer_warn = 1;
  709. }
  710. /* ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.6)
  711. * Targets which break data transfers into multiple
  712. * connections shall end each successful connection
  713. * (except possibly the last) with a SAVE DATA
  714. * POINTER - DISCONNECT message sequence.
  715. *
  716. * This makes it difficult to ensure that a transfer has
  717. * completed. If we reach the end of a transfer during
  718. * the command, then we can only have finished the transfer.
  719. * therefore, if we seem to have some data remaining, this
  720. * is not a problem.
  721. */
  722. if (host->dma.xfer_done)
  723. xfer_warn = 0;
  724. if (xfer_warn) {
  725. switch (status_byte(SCpnt->result)) {
  726. case CHECK_CONDITION:
  727. case COMMAND_TERMINATED:
  728. case BUSY:
  729. case QUEUE_FULL:
  730. case RESERVATION_CONFLICT:
  731. break;
  732. default:
  733. scmd_printk(KERN_ERR, SCpnt,
  734. "incomplete data transfer detected: "
  735. "result=%08X", SCpnt->result);
  736. scsi_print_command(SCpnt);
  737. acornscsi_dumpdma(host, "done");
  738. acornscsi_dumplog(host, SCpnt->device->id);
  739. set_host_byte(SCpnt, DID_ERROR);
  740. }
  741. }
  742. }
  743. if (!SCpnt->scsi_done)
  744. panic("scsi%d.H: null scsi_done function in acornscsi_done", host->host->host_no);
  745. clear_bit(SCpnt->device->id * 8 +
  746. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  747. SCpnt->scsi_done(SCpnt);
  748. } else
  749. printk("scsi%d: null command in acornscsi_done", host->host->host_no);
  750. host->scsi.phase = PHASE_IDLE;
  751. }
  752. /* ====================================================================================
  753. * DMA routines
  754. */
  755. /*
  756. * Purpose : update SCSI Data Pointer
  757. * Notes : this will only be one SG entry or less
  758. */
  759. static
  760. void acornscsi_data_updateptr(AS_Host *host, struct scsi_pointer *SCp, unsigned int length)
  761. {
  762. SCp->ptr += length;
  763. SCp->this_residual -= length;
  764. if (SCp->this_residual == 0 && next_SCp(SCp) == 0)
  765. host->dma.xfer_done = 1;
  766. }
  767. /*
  768. * Prototype: void acornscsi_data_read(AS_Host *host, char *ptr,
  769. * unsigned int start_addr, unsigned int length)
  770. * Purpose : read data from DMA RAM
  771. * Params : host - host to transfer from
  772. * ptr - DRAM address
  773. * start_addr - host mem address
  774. * length - number of bytes to transfer
  775. * Notes : this will only be one SG entry or less
  776. */
  777. static
  778. void acornscsi_data_read(AS_Host *host, char *ptr,
  779. unsigned int start_addr, unsigned int length)
  780. {
  781. extern void __acornscsi_in(void __iomem *, char *buf, int len);
  782. unsigned int page, offset, len = length;
  783. page = (start_addr >> 12);
  784. offset = start_addr & ((1 << 12) - 1);
  785. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  786. while (len > 0) {
  787. unsigned int this_len;
  788. if (len + offset > (1 << 12))
  789. this_len = (1 << 12) - offset;
  790. else
  791. this_len = len;
  792. __acornscsi_in(host->base + (offset << 1), ptr, this_len);
  793. offset += this_len;
  794. ptr += this_len;
  795. len -= this_len;
  796. if (offset == (1 << 12)) {
  797. offset = 0;
  798. page ++;
  799. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  800. }
  801. }
  802. writeb(host->card.page_reg, host->fast + PAGE_REG);
  803. }
  804. /*
  805. * Prototype: void acornscsi_data_write(AS_Host *host, char *ptr,
  806. * unsigned int start_addr, unsigned int length)
  807. * Purpose : write data to DMA RAM
  808. * Params : host - host to transfer from
  809. * ptr - DRAM address
  810. * start_addr - host mem address
  811. * length - number of bytes to transfer
  812. * Notes : this will only be one SG entry or less
  813. */
  814. static
  815. void acornscsi_data_write(AS_Host *host, char *ptr,
  816. unsigned int start_addr, unsigned int length)
  817. {
  818. extern void __acornscsi_out(void __iomem *, char *buf, int len);
  819. unsigned int page, offset, len = length;
  820. page = (start_addr >> 12);
  821. offset = start_addr & ((1 << 12) - 1);
  822. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  823. while (len > 0) {
  824. unsigned int this_len;
  825. if (len + offset > (1 << 12))
  826. this_len = (1 << 12) - offset;
  827. else
  828. this_len = len;
  829. __acornscsi_out(host->base + (offset << 1), ptr, this_len);
  830. offset += this_len;
  831. ptr += this_len;
  832. len -= this_len;
  833. if (offset == (1 << 12)) {
  834. offset = 0;
  835. page ++;
  836. writeb((page & 0x3f) | host->card.page_reg, host->fast + PAGE_REG);
  837. }
  838. }
  839. writeb(host->card.page_reg, host->fast + PAGE_REG);
  840. }
  841. /* =========================================================================================
  842. * On-board DMA routines
  843. */
  844. #ifdef USE_DMAC
  845. /*
  846. * Prototype: void acornscsi_dmastop(AS_Host *host)
  847. * Purpose : stop all DMA
  848. * Params : host - host on which to stop DMA
  849. * Notes : This is called when leaving DATA IN/OUT phase,
  850. * or when interface is RESET
  851. */
  852. static inline
  853. void acornscsi_dma_stop(AS_Host *host)
  854. {
  855. dmac_write(host, DMAC_MASKREG, MASK_ON);
  856. dmac_clearintr(host);
  857. #if (DEBUG & DEBUG_DMA)
  858. DBG(host->SCpnt, acornscsi_dumpdma(host, "stop"));
  859. #endif
  860. }
  861. /*
  862. * Function: void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  863. * Purpose : setup DMA controller for data transfer
  864. * Params : host - host to setup
  865. * direction - data transfer direction
  866. * Notes : This is called when entering DATA I/O phase, not
  867. * while we're in a DATA I/O phase
  868. */
  869. static
  870. void acornscsi_dma_setup(AS_Host *host, dmadir_t direction)
  871. {
  872. unsigned int address, length, mode;
  873. host->dma.direction = direction;
  874. dmac_write(host, DMAC_MASKREG, MASK_ON);
  875. if (direction == DMA_OUT) {
  876. #if (DEBUG & DEBUG_NO_WRITE)
  877. if (NO_WRITE & (1 << host->SCpnt->device->id)) {
  878. printk(KERN_CRIT "scsi%d.%c: I can't handle DMA_OUT!\n",
  879. host->host->host_no, acornscsi_target(host));
  880. return;
  881. }
  882. #endif
  883. mode = DMAC_WRITE;
  884. } else
  885. mode = DMAC_READ;
  886. /*
  887. * Allocate some buffer space, limited to half the buffer size
  888. */
  889. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  890. if (length) {
  891. host->dma.start_addr = address = host->dma.free_addr;
  892. host->dma.free_addr = (host->dma.free_addr + length) &
  893. (DMAC_BUFFER_SIZE - 1);
  894. /*
  895. * Transfer data to DMA memory
  896. */
  897. if (direction == DMA_OUT)
  898. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  899. length);
  900. length -= 1;
  901. dmac_write(host, DMAC_TXCNTLO, length);
  902. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  903. dmac_write(host, DMAC_TXADRLO, address);
  904. dmac_write(host, DMAC_TXADRMD, address >> 8);
  905. dmac_write(host, DMAC_TXADRHI, 0);
  906. dmac_write(host, DMAC_MODECON, mode);
  907. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  908. #if (DEBUG & DEBUG_DMA)
  909. DBG(host->SCpnt, acornscsi_dumpdma(host, "strt"));
  910. #endif
  911. host->dma.xfer_setup = 1;
  912. }
  913. }
  914. /*
  915. * Function: void acornscsi_dma_cleanup(AS_Host *host)
  916. * Purpose : ensure that all DMA transfers are up-to-date & host->scsi.SCp is correct
  917. * Params : host - host to finish
  918. * Notes : This is called when a command is:
  919. * terminating, RESTORE_POINTERS, SAVE_POINTERS, DISCONECT
  920. * : This must not return until all transfers are completed.
  921. */
  922. static
  923. void acornscsi_dma_cleanup(AS_Host *host)
  924. {
  925. dmac_write(host, DMAC_MASKREG, MASK_ON);
  926. dmac_clearintr(host);
  927. /*
  928. * Check for a pending transfer
  929. */
  930. if (host->dma.xfer_required) {
  931. host->dma.xfer_required = 0;
  932. if (host->dma.direction == DMA_IN)
  933. acornscsi_data_read(host, host->dma.xfer_ptr,
  934. host->dma.xfer_start, host->dma.xfer_length);
  935. }
  936. /*
  937. * Has a transfer been setup?
  938. */
  939. if (host->dma.xfer_setup) {
  940. unsigned int transferred;
  941. host->dma.xfer_setup = 0;
  942. #if (DEBUG & DEBUG_DMA)
  943. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupi"));
  944. #endif
  945. /*
  946. * Calculate number of bytes transferred from DMA.
  947. */
  948. transferred = dmac_address(host) - host->dma.start_addr;
  949. host->dma.transferred += transferred;
  950. if (host->dma.direction == DMA_IN)
  951. acornscsi_data_read(host, host->scsi.SCp.ptr,
  952. host->dma.start_addr, transferred);
  953. /*
  954. * Update SCSI pointers
  955. */
  956. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  957. #if (DEBUG & DEBUG_DMA)
  958. DBG(host->SCpnt, acornscsi_dumpdma(host, "cupo"));
  959. #endif
  960. }
  961. }
  962. /*
  963. * Function: void acornscsi_dmacintr(AS_Host *host)
  964. * Purpose : handle interrupts from DMAC device
  965. * Params : host - host to process
  966. * Notes : If reading, we schedule the read to main memory &
  967. * allow the transfer to continue.
  968. * : If writing, we fill the onboard DMA memory from main
  969. * memory.
  970. * : Called whenever DMAC finished it's current transfer.
  971. */
  972. static
  973. void acornscsi_dma_intr(AS_Host *host)
  974. {
  975. unsigned int address, length, transferred;
  976. #if (DEBUG & DEBUG_DMA)
  977. DBG(host->SCpnt, acornscsi_dumpdma(host, "inti"));
  978. #endif
  979. dmac_write(host, DMAC_MASKREG, MASK_ON);
  980. dmac_clearintr(host);
  981. /*
  982. * Calculate amount transferred via DMA
  983. */
  984. transferred = dmac_address(host) - host->dma.start_addr;
  985. host->dma.transferred += transferred;
  986. /*
  987. * Schedule DMA transfer off board
  988. */
  989. if (host->dma.direction == DMA_IN) {
  990. host->dma.xfer_start = host->dma.start_addr;
  991. host->dma.xfer_length = transferred;
  992. host->dma.xfer_ptr = host->scsi.SCp.ptr;
  993. host->dma.xfer_required = 1;
  994. }
  995. acornscsi_data_updateptr(host, &host->scsi.SCp, transferred);
  996. /*
  997. * Allocate some buffer space, limited to half the on-board RAM size
  998. */
  999. length = min_t(unsigned int, host->scsi.SCp.this_residual, DMAC_BUFFER_SIZE / 2);
  1000. if (length) {
  1001. host->dma.start_addr = address = host->dma.free_addr;
  1002. host->dma.free_addr = (host->dma.free_addr + length) &
  1003. (DMAC_BUFFER_SIZE - 1);
  1004. /*
  1005. * Transfer data to DMA memory
  1006. */
  1007. if (host->dma.direction == DMA_OUT)
  1008. acornscsi_data_write(host, host->scsi.SCp.ptr, host->dma.start_addr,
  1009. length);
  1010. length -= 1;
  1011. dmac_write(host, DMAC_TXCNTLO, length);
  1012. dmac_write(host, DMAC_TXCNTHI, length >> 8);
  1013. dmac_write(host, DMAC_TXADRLO, address);
  1014. dmac_write(host, DMAC_TXADRMD, address >> 8);
  1015. dmac_write(host, DMAC_TXADRHI, 0);
  1016. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1017. #if (DEBUG & DEBUG_DMA)
  1018. DBG(host->SCpnt, acornscsi_dumpdma(host, "into"));
  1019. #endif
  1020. } else {
  1021. host->dma.xfer_setup = 0;
  1022. #if 0
  1023. /*
  1024. * If the interface still wants more, then this is an error.
  1025. * We give it another byte, but we also attempt to raise an
  1026. * attention condition. We continue giving one byte until
  1027. * the device recognises the attention.
  1028. */
  1029. if (dmac_read(host, DMAC_STATUS) & STATUS_RQ0) {
  1030. acornscsi_abortcmd(host, host->SCpnt->tag);
  1031. dmac_write(host, DMAC_TXCNTLO, 0);
  1032. dmac_write(host, DMAC_TXCNTHI, 0);
  1033. dmac_write(host, DMAC_TXADRLO, 0);
  1034. dmac_write(host, DMAC_TXADRMD, 0);
  1035. dmac_write(host, DMAC_TXADRHI, 0);
  1036. dmac_write(host, DMAC_MASKREG, MASK_OFF);
  1037. }
  1038. #endif
  1039. }
  1040. }
  1041. /*
  1042. * Function: void acornscsi_dma_xfer(AS_Host *host)
  1043. * Purpose : transfer data between AcornSCSI and memory
  1044. * Params : host - host to process
  1045. */
  1046. static
  1047. void acornscsi_dma_xfer(AS_Host *host)
  1048. {
  1049. host->dma.xfer_required = 0;
  1050. if (host->dma.direction == DMA_IN)
  1051. acornscsi_data_read(host, host->dma.xfer_ptr,
  1052. host->dma.xfer_start, host->dma.xfer_length);
  1053. }
  1054. /*
  1055. * Function: void acornscsi_dma_adjust(AS_Host *host)
  1056. * Purpose : adjust DMA pointers & count for bytes transferred to
  1057. * SBIC but not SCSI bus.
  1058. * Params : host - host to adjust DMA count for
  1059. */
  1060. static
  1061. void acornscsi_dma_adjust(AS_Host *host)
  1062. {
  1063. if (host->dma.xfer_setup) {
  1064. signed long transferred;
  1065. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1066. DBG(host->SCpnt, acornscsi_dumpdma(host, "adji"));
  1067. #endif
  1068. /*
  1069. * Calculate correct DMA address - DMA is ahead of SCSI bus while
  1070. * writing.
  1071. * host->scsi.SCp.scsi_xferred is the number of bytes
  1072. * actually transferred to/from the SCSI bus.
  1073. * host->dma.transferred is the number of bytes transferred
  1074. * over DMA since host->dma.start_addr was last set.
  1075. *
  1076. * real_dma_addr = host->dma.start_addr + host->scsi.SCp.scsi_xferred
  1077. * - host->dma.transferred
  1078. */
  1079. transferred = host->scsi.SCp.scsi_xferred - host->dma.transferred;
  1080. if (transferred < 0)
  1081. printk("scsi%d.%c: Ack! DMA write correction %ld < 0!\n",
  1082. host->host->host_no, acornscsi_target(host), transferred);
  1083. else if (transferred == 0)
  1084. host->dma.xfer_setup = 0;
  1085. else {
  1086. transferred += host->dma.start_addr;
  1087. dmac_write(host, DMAC_TXADRLO, transferred);
  1088. dmac_write(host, DMAC_TXADRMD, transferred >> 8);
  1089. dmac_write(host, DMAC_TXADRHI, transferred >> 16);
  1090. #if (DEBUG & (DEBUG_DMA|DEBUG_WRITE))
  1091. DBG(host->SCpnt, acornscsi_dumpdma(host, "adjo"));
  1092. #endif
  1093. }
  1094. }
  1095. }
  1096. #endif
  1097. /* =========================================================================================
  1098. * Data I/O
  1099. */
  1100. static int
  1101. acornscsi_write_pio(AS_Host *host, char *bytes, int *ptr, int len, unsigned int max_timeout)
  1102. {
  1103. unsigned int asr, timeout = max_timeout;
  1104. int my_ptr = *ptr;
  1105. while (my_ptr < len) {
  1106. asr = sbic_arm_read(host, SBIC_ASR);
  1107. if (asr & ASR_DBR) {
  1108. timeout = max_timeout;
  1109. sbic_arm_write(host, SBIC_DATA, bytes[my_ptr++]);
  1110. } else if (asr & ASR_INT)
  1111. break;
  1112. else if (--timeout == 0)
  1113. break;
  1114. udelay(1);
  1115. }
  1116. *ptr = my_ptr;
  1117. return (timeout == 0) ? -1 : 0;
  1118. }
  1119. /*
  1120. * Function: void acornscsi_sendcommand(AS_Host *host)
  1121. * Purpose : send a command to a target
  1122. * Params : host - host which is connected to target
  1123. */
  1124. static void
  1125. acornscsi_sendcommand(AS_Host *host)
  1126. {
  1127. struct scsi_cmnd *SCpnt = host->SCpnt;
  1128. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1129. sbic_arm_writenext(host, 0);
  1130. sbic_arm_writenext(host, SCpnt->cmd_len - host->scsi.SCp.sent_command);
  1131. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1132. if (acornscsi_write_pio(host, SCpnt->cmnd,
  1133. (int *)&host->scsi.SCp.sent_command, SCpnt->cmd_len, 1000000))
  1134. printk("scsi%d: timeout while sending command\n", host->host->host_no);
  1135. host->scsi.phase = PHASE_COMMAND;
  1136. }
  1137. static
  1138. void acornscsi_sendmessage(AS_Host *host)
  1139. {
  1140. unsigned int message_length = msgqueue_msglength(&host->scsi.msgs);
  1141. unsigned int msgnr;
  1142. struct message *msg;
  1143. #if (DEBUG & DEBUG_MESSAGES)
  1144. printk("scsi%d.%c: sending message ",
  1145. host->host->host_no, acornscsi_target(host));
  1146. #endif
  1147. switch (message_length) {
  1148. case 0:
  1149. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1150. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 1");
  1151. sbic_arm_write(host, SBIC_DATA, NOP);
  1152. host->scsi.last_message = NOP;
  1153. #if (DEBUG & DEBUG_MESSAGES)
  1154. printk("NOP");
  1155. #endif
  1156. break;
  1157. case 1:
  1158. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1159. msg = msgqueue_getmsg(&host->scsi.msgs, 0);
  1160. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "sending message 2");
  1161. sbic_arm_write(host, SBIC_DATA, msg->msg[0]);
  1162. host->scsi.last_message = msg->msg[0];
  1163. #if (DEBUG & DEBUG_MESSAGES)
  1164. spi_print_msg(msg->msg);
  1165. #endif
  1166. break;
  1167. default:
  1168. /*
  1169. * ANSI standard says: (SCSI-2 Rev 10c Sect 5.6.14)
  1170. * 'When a target sends this (MESSAGE_REJECT) message, it
  1171. * shall change to MESSAGE IN phase and send this message
  1172. * prior to requesting additional message bytes from the
  1173. * initiator. This provides an interlock so that the
  1174. * initiator can determine which message byte is rejected.
  1175. */
  1176. sbic_arm_write(host, SBIC_TRANSCNTH, 0);
  1177. sbic_arm_writenext(host, 0);
  1178. sbic_arm_writenext(host, message_length);
  1179. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1180. msgnr = 0;
  1181. while ((msg = msgqueue_getmsg(&host->scsi.msgs, msgnr++)) != NULL) {
  1182. unsigned int i;
  1183. #if (DEBUG & DEBUG_MESSAGES)
  1184. spi_print_msg(msg);
  1185. #endif
  1186. i = 0;
  1187. if (acornscsi_write_pio(host, msg->msg, &i, msg->length, 1000000))
  1188. printk("scsi%d: timeout while sending message\n", host->host->host_no);
  1189. host->scsi.last_message = msg->msg[0];
  1190. if (msg->msg[0] == EXTENDED_MESSAGE)
  1191. host->scsi.last_message |= msg->msg[2] << 8;
  1192. if (i != msg->length)
  1193. break;
  1194. }
  1195. break;
  1196. }
  1197. #if (DEBUG & DEBUG_MESSAGES)
  1198. printk("\n");
  1199. #endif
  1200. }
  1201. /*
  1202. * Function: void acornscsi_readstatusbyte(AS_Host *host)
  1203. * Purpose : Read status byte from connected target
  1204. * Params : host - host connected to target
  1205. */
  1206. static
  1207. void acornscsi_readstatusbyte(AS_Host *host)
  1208. {
  1209. acornscsi_sbic_issuecmd(host, CMND_XFERINFO|CMND_SBT);
  1210. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "reading status byte");
  1211. host->scsi.SCp.Status = sbic_arm_read(host, SBIC_DATA);
  1212. }
  1213. /*
  1214. * Function: unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1215. * Purpose : Read one message byte from connected target
  1216. * Params : host - host connected to target
  1217. */
  1218. static
  1219. unsigned char acornscsi_readmessagebyte(AS_Host *host)
  1220. {
  1221. unsigned char message;
  1222. acornscsi_sbic_issuecmd(host, CMND_XFERINFO | CMND_SBT);
  1223. acornscsi_sbic_wait(host, ASR_DBR, ASR_DBR, 1000, "for message byte");
  1224. message = sbic_arm_read(host, SBIC_DATA);
  1225. /* wait for MSGIN-XFER-PAUSED */
  1226. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after message byte");
  1227. sbic_arm_read(host, SBIC_SSR);
  1228. return message;
  1229. }
  1230. /*
  1231. * Function: void acornscsi_message(AS_Host *host)
  1232. * Purpose : Read complete message from connected target & action message
  1233. * Params : host - host connected to target
  1234. */
  1235. static
  1236. void acornscsi_message(AS_Host *host)
  1237. {
  1238. unsigned char message[16];
  1239. unsigned int msgidx = 0, msglen = 1;
  1240. do {
  1241. message[msgidx] = acornscsi_readmessagebyte(host);
  1242. switch (msgidx) {
  1243. case 0:
  1244. if (message[0] == EXTENDED_MESSAGE ||
  1245. (message[0] >= 0x20 && message[0] <= 0x2f))
  1246. msglen = 2;
  1247. break;
  1248. case 1:
  1249. if (message[0] == EXTENDED_MESSAGE)
  1250. msglen += message[msgidx];
  1251. break;
  1252. }
  1253. msgidx += 1;
  1254. if (msgidx < msglen) {
  1255. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1256. /* wait for next msg-in */
  1257. acornscsi_sbic_wait(host, ASR_INT, ASR_INT, 1000, "for interrupt after negate ack");
  1258. sbic_arm_read(host, SBIC_SSR);
  1259. }
  1260. } while (msgidx < msglen);
  1261. #if (DEBUG & DEBUG_MESSAGES)
  1262. printk("scsi%d.%c: message in: ",
  1263. host->host->host_no, acornscsi_target(host));
  1264. spi_print_msg(message);
  1265. printk("\n");
  1266. #endif
  1267. if (host->scsi.phase == PHASE_RECONNECTED) {
  1268. /*
  1269. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1270. * 'Whenever a target reconnects to an initiator to continue
  1271. * a tagged I/O process, the SIMPLE QUEUE TAG message shall
  1272. * be sent immediately following the IDENTIFY message...'
  1273. */
  1274. if (message[0] == SIMPLE_QUEUE_TAG)
  1275. host->scsi.reconnected.tag = message[1];
  1276. if (acornscsi_reconnect_finish(host))
  1277. host->scsi.phase = PHASE_MSGIN;
  1278. }
  1279. switch (message[0]) {
  1280. case ABORT:
  1281. case ABORT_TAG:
  1282. case COMMAND_COMPLETE:
  1283. if (host->scsi.phase != PHASE_STATUSIN) {
  1284. printk(KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
  1285. host->host->host_no, acornscsi_target(host));
  1286. acornscsi_dumplog(host, host->SCpnt->device->id);
  1287. }
  1288. host->scsi.phase = PHASE_DONE;
  1289. host->scsi.SCp.Message = message[0];
  1290. break;
  1291. case SAVE_POINTERS:
  1292. /*
  1293. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.20)
  1294. * 'The SAVE DATA POINTER message is sent from a target to
  1295. * direct the initiator to copy the active data pointer to
  1296. * the saved data pointer for the current I/O process.
  1297. */
  1298. acornscsi_dma_cleanup(host);
  1299. host->SCpnt->SCp = host->scsi.SCp;
  1300. host->SCpnt->SCp.sent_command = 0;
  1301. host->scsi.phase = PHASE_MSGIN;
  1302. break;
  1303. case RESTORE_POINTERS:
  1304. /*
  1305. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.19)
  1306. * 'The RESTORE POINTERS message is sent from a target to
  1307. * direct the initiator to copy the most recently saved
  1308. * command, data, and status pointers for the I/O process
  1309. * to the corresponding active pointers. The command and
  1310. * status pointers shall be restored to the beginning of
  1311. * the present command and status areas.'
  1312. */
  1313. acornscsi_dma_cleanup(host);
  1314. host->scsi.SCp = host->SCpnt->SCp;
  1315. host->scsi.phase = PHASE_MSGIN;
  1316. break;
  1317. case DISCONNECT:
  1318. /*
  1319. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 6.4.2)
  1320. * 'On those occasions when an error or exception condition occurs
  1321. * and the target elects to repeat the information transfer, the
  1322. * target may repeat the transfer either issuing a RESTORE POINTERS
  1323. * message or by disconnecting without issuing a SAVE POINTERS
  1324. * message. When reconnection is completed, the most recent
  1325. * saved pointer values are restored.'
  1326. */
  1327. acornscsi_dma_cleanup(host);
  1328. host->scsi.phase = PHASE_DISCONNECT;
  1329. break;
  1330. case MESSAGE_REJECT:
  1331. #if 0 /* this isn't needed any more */
  1332. /*
  1333. * If we were negociating sync transfer, we don't yet know if
  1334. * this REJECT is for the sync transfer or for the tagged queue/wide
  1335. * transfer. Re-initiate sync transfer negotiation now, and if
  1336. * we got a REJECT in response to SDTR, then it'll be set to DONE.
  1337. */
  1338. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST)
  1339. host->device[host->SCpnt->device->id].sync_state = SYNC_NEGOCIATE;
  1340. #endif
  1341. /*
  1342. * If we have any messages waiting to go out, then assert ATN now
  1343. */
  1344. if (msgqueue_msglength(&host->scsi.msgs))
  1345. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1346. switch (host->scsi.last_message) {
  1347. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1348. case HEAD_OF_QUEUE_TAG:
  1349. case ORDERED_QUEUE_TAG:
  1350. case SIMPLE_QUEUE_TAG:
  1351. /*
  1352. * ANSI standard says: (Section SCSI-2 Rev. 10c Sect 5.6.17)
  1353. * If a target does not implement tagged queuing and a queue tag
  1354. * message is received, it shall respond with a MESSAGE REJECT
  1355. * message and accept the I/O process as if it were untagged.
  1356. */
  1357. printk(KERN_NOTICE "scsi%d.%c: disabling tagged queueing\n",
  1358. host->host->host_no, acornscsi_target(host));
  1359. host->SCpnt->device->simple_tags = 0;
  1360. set_bit(host->SCpnt->device->id * 8 +
  1361. (u8)(host->SCpnt->device->lun & 0x7), host->busyluns);
  1362. break;
  1363. #endif
  1364. case EXTENDED_MESSAGE | (EXTENDED_SDTR << 8):
  1365. /*
  1366. * Target can't handle synchronous transfers
  1367. */
  1368. printk(KERN_NOTICE "scsi%d.%c: Using asynchronous transfer\n",
  1369. host->host->host_no, acornscsi_target(host));
  1370. host->device[host->SCpnt->device->id].sync_xfer = SYNCHTRANSFER_2DBA;
  1371. host->device[host->SCpnt->device->id].sync_state = SYNC_ASYNCHRONOUS;
  1372. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1373. break;
  1374. default:
  1375. break;
  1376. }
  1377. break;
  1378. case QUEUE_FULL:
  1379. /* TODO: target queue is full */
  1380. break;
  1381. case SIMPLE_QUEUE_TAG:
  1382. /* tag queue reconnect... message[1] = queue tag. Print something to indicate something happened! */
  1383. printk("scsi%d.%c: reconnect queue tag %02X\n",
  1384. host->host->host_no, acornscsi_target(host),
  1385. message[1]);
  1386. break;
  1387. case EXTENDED_MESSAGE:
  1388. switch (message[2]) {
  1389. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1390. case EXTENDED_SDTR:
  1391. if (host->device[host->SCpnt->device->id].sync_state == SYNC_SENT_REQUEST) {
  1392. /*
  1393. * We requested synchronous transfers. This isn't quite right...
  1394. * We can only say if this succeeded if we proceed on to execute the
  1395. * command from this message. If we get a MESSAGE PARITY ERROR,
  1396. * and the target retries fail, then we fallback to asynchronous mode
  1397. */
  1398. host->device[host->SCpnt->device->id].sync_state = SYNC_COMPLETED;
  1399. printk(KERN_NOTICE "scsi%d.%c: Using synchronous transfer, offset %d, %d ns\n",
  1400. host->host->host_no, acornscsi_target(host),
  1401. message[4], message[3] * 4);
  1402. host->device[host->SCpnt->device->id].sync_xfer =
  1403. calc_sync_xfer(message[3] * 4, message[4]);
  1404. } else {
  1405. unsigned char period, length;
  1406. /*
  1407. * Target requested synchronous transfers. The agreement is only
  1408. * to be in operation AFTER the target leaves message out phase.
  1409. */
  1410. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1411. period = max_t(unsigned int, message[3], sdtr_period / 4);
  1412. length = min_t(unsigned int, message[4], sdtr_size);
  1413. msgqueue_addmsg(&host->scsi.msgs, 5, EXTENDED_MESSAGE, 3,
  1414. EXTENDED_SDTR, period, length);
  1415. host->device[host->SCpnt->device->id].sync_xfer =
  1416. calc_sync_xfer(period * 4, length);
  1417. }
  1418. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1419. break;
  1420. #else
  1421. /* We do not accept synchronous transfers. Respond with a
  1422. * MESSAGE_REJECT.
  1423. */
  1424. #endif
  1425. case EXTENDED_WDTR:
  1426. /* The WD33C93A is only 8-bit. We respond with a MESSAGE_REJECT
  1427. * to a wide data transfer request.
  1428. */
  1429. default:
  1430. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1431. msgqueue_flush(&host->scsi.msgs);
  1432. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1433. break;
  1434. }
  1435. break;
  1436. default: /* reject message */
  1437. printk(KERN_ERR "scsi%d.%c: unrecognised message %02X, rejecting\n",
  1438. host->host->host_no, acornscsi_target(host),
  1439. message[0]);
  1440. acornscsi_sbic_issuecmd(host, CMND_ASSERTATN);
  1441. msgqueue_flush(&host->scsi.msgs);
  1442. msgqueue_addmsg(&host->scsi.msgs, 1, MESSAGE_REJECT);
  1443. host->scsi.phase = PHASE_MSGIN;
  1444. break;
  1445. }
  1446. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1447. }
  1448. /*
  1449. * Function: int acornscsi_buildmessages(AS_Host *host)
  1450. * Purpose : build the connection messages for a host
  1451. * Params : host - host to add messages to
  1452. */
  1453. static
  1454. void acornscsi_buildmessages(AS_Host *host)
  1455. {
  1456. #if 0
  1457. /* does the device need resetting? */
  1458. if (cmd_reset) {
  1459. msgqueue_addmsg(&host->scsi.msgs, 1, BUS_DEVICE_RESET);
  1460. return;
  1461. }
  1462. #endif
  1463. msgqueue_addmsg(&host->scsi.msgs, 1,
  1464. IDENTIFY(host->device[host->SCpnt->device->id].disconnect_ok,
  1465. host->SCpnt->device->lun));
  1466. #if 0
  1467. /* does the device need the current command aborted */
  1468. if (cmd_aborted) {
  1469. acornscsi_abortcmd(host->SCpnt->tag);
  1470. return;
  1471. }
  1472. #endif
  1473. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1474. if (host->SCpnt->tag) {
  1475. unsigned int tag_type;
  1476. if (host->SCpnt->cmnd[0] == REQUEST_SENSE ||
  1477. host->SCpnt->cmnd[0] == TEST_UNIT_READY ||
  1478. host->SCpnt->cmnd[0] == INQUIRY)
  1479. tag_type = HEAD_OF_QUEUE_TAG;
  1480. else
  1481. tag_type = SIMPLE_QUEUE_TAG;
  1482. msgqueue_addmsg(&host->scsi.msgs, 2, tag_type, host->SCpnt->tag);
  1483. }
  1484. #endif
  1485. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  1486. if (host->device[host->SCpnt->device->id].sync_state == SYNC_NEGOCIATE) {
  1487. host->device[host->SCpnt->device->id].sync_state = SYNC_SENT_REQUEST;
  1488. msgqueue_addmsg(&host->scsi.msgs, 5,
  1489. EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
  1490. sdtr_period / 4, sdtr_size);
  1491. }
  1492. #endif
  1493. }
  1494. /*
  1495. * Function: int acornscsi_starttransfer(AS_Host *host)
  1496. * Purpose : transfer data to/from connected target
  1497. * Params : host - host to which target is connected
  1498. * Returns : 0 if failure
  1499. */
  1500. static
  1501. int acornscsi_starttransfer(AS_Host *host)
  1502. {
  1503. int residual;
  1504. if (!host->scsi.SCp.ptr /*&& host->scsi.SCp.this_residual*/) {
  1505. printk(KERN_ERR "scsi%d.%c: null buffer passed to acornscsi_starttransfer\n",
  1506. host->host->host_no, acornscsi_target(host));
  1507. return 0;
  1508. }
  1509. residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
  1510. sbic_arm_write(host, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
  1511. sbic_arm_writenext(host, residual >> 16);
  1512. sbic_arm_writenext(host, residual >> 8);
  1513. sbic_arm_writenext(host, residual);
  1514. acornscsi_sbic_issuecmd(host, CMND_XFERINFO);
  1515. return 1;
  1516. }
  1517. /* =========================================================================================
  1518. * Connection & Disconnection
  1519. */
  1520. /*
  1521. * Function : acornscsi_reconnect(AS_Host *host)
  1522. * Purpose : reconnect a previously disconnected command
  1523. * Params : host - host specific data
  1524. * Remarks : SCSI spec says:
  1525. * 'The set of active pointers is restored from the set
  1526. * of saved pointers upon reconnection of the I/O process'
  1527. */
  1528. static
  1529. int acornscsi_reconnect(AS_Host *host)
  1530. {
  1531. unsigned int target, lun, ok = 0;
  1532. target = sbic_arm_read(host, SBIC_SOURCEID);
  1533. if (!(target & 8))
  1534. printk(KERN_ERR "scsi%d: invalid source id after reselection "
  1535. "- device fault?\n",
  1536. host->host->host_no);
  1537. target &= 7;
  1538. if (host->SCpnt && !host->scsi.disconnectable) {
  1539. printk(KERN_ERR "scsi%d.%d: reconnected while command in "
  1540. "progress to target %d?\n",
  1541. host->host->host_no, target, host->SCpnt->device->id);
  1542. host->SCpnt = NULL;
  1543. }
  1544. lun = sbic_arm_read(host, SBIC_DATA) & 7;
  1545. host->scsi.reconnected.target = target;
  1546. host->scsi.reconnected.lun = lun;
  1547. host->scsi.reconnected.tag = 0;
  1548. if (host->scsi.disconnectable && host->SCpnt &&
  1549. host->SCpnt->device->id == target && host->SCpnt->device->lun == lun)
  1550. ok = 1;
  1551. if (!ok && queue_probetgtlun(&host->queues.disconnected, target, lun))
  1552. ok = 1;
  1553. ADD_STATUS(target, 0x81, host->scsi.phase, 0);
  1554. if (ok) {
  1555. host->scsi.phase = PHASE_RECONNECTED;
  1556. } else {
  1557. /* this doesn't seem to work */
  1558. printk(KERN_ERR "scsi%d.%c: reselected with no command "
  1559. "to reconnect with\n",
  1560. host->host->host_no, '0' + target);
  1561. acornscsi_dumplog(host, target);
  1562. acornscsi_abortcmd(host, 0);
  1563. if (host->SCpnt) {
  1564. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1565. host->SCpnt = NULL;
  1566. }
  1567. }
  1568. acornscsi_sbic_issuecmd(host, CMND_NEGATEACK);
  1569. return !ok;
  1570. }
  1571. /*
  1572. * Function: int acornscsi_reconect_finish(AS_Host *host)
  1573. * Purpose : finish reconnecting a command
  1574. * Params : host - host to complete
  1575. * Returns : 0 if failed
  1576. */
  1577. static
  1578. int acornscsi_reconnect_finish(AS_Host *host)
  1579. {
  1580. if (host->scsi.disconnectable && host->SCpnt) {
  1581. host->scsi.disconnectable = 0;
  1582. if (host->SCpnt->device->id == host->scsi.reconnected.target &&
  1583. host->SCpnt->device->lun == host->scsi.reconnected.lun &&
  1584. host->SCpnt->tag == host->scsi.reconnected.tag) {
  1585. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1586. DBG(host->SCpnt, printk("scsi%d.%c: reconnected",
  1587. host->host->host_no, acornscsi_target(host)));
  1588. #endif
  1589. } else {
  1590. queue_add_cmd_tail(&host->queues.disconnected, host->SCpnt);
  1591. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1592. DBG(host->SCpnt, printk("scsi%d.%c: had to move command "
  1593. "to disconnected queue\n",
  1594. host->host->host_no, acornscsi_target(host)));
  1595. #endif
  1596. host->SCpnt = NULL;
  1597. }
  1598. }
  1599. if (!host->SCpnt) {
  1600. host->SCpnt = queue_remove_tgtluntag(&host->queues.disconnected,
  1601. host->scsi.reconnected.target,
  1602. host->scsi.reconnected.lun,
  1603. host->scsi.reconnected.tag);
  1604. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1605. DBG(host->SCpnt, printk("scsi%d.%c: had to get command",
  1606. host->host->host_no, acornscsi_target(host)));
  1607. #endif
  1608. }
  1609. if (!host->SCpnt)
  1610. acornscsi_abortcmd(host, host->scsi.reconnected.tag);
  1611. else {
  1612. /*
  1613. * Restore data pointer from SAVED pointers.
  1614. */
  1615. host->scsi.SCp = host->SCpnt->SCp;
  1616. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1617. printk(", data pointers: [%p, %X]",
  1618. host->scsi.SCp.ptr, host->scsi.SCp.this_residual);
  1619. #endif
  1620. }
  1621. #if (DEBUG & (DEBUG_QUEUES|DEBUG_DISCON))
  1622. printk("\n");
  1623. #endif
  1624. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1625. return host->SCpnt != NULL;
  1626. }
  1627. /*
  1628. * Function: void acornscsi_disconnect_unexpected(AS_Host *host)
  1629. * Purpose : handle an unexpected disconnect
  1630. * Params : host - host on which disconnect occurred
  1631. */
  1632. static
  1633. void acornscsi_disconnect_unexpected(AS_Host *host)
  1634. {
  1635. printk(KERN_ERR "scsi%d.%c: unexpected disconnect\n",
  1636. host->host->host_no, acornscsi_target(host));
  1637. #if (DEBUG & DEBUG_ABORT)
  1638. acornscsi_dumplog(host, 8);
  1639. #endif
  1640. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1641. }
  1642. /*
  1643. * Function: void acornscsi_abortcmd(AS_host *host, unsigned char tag)
  1644. * Purpose : abort a currently executing command
  1645. * Params : host - host with connected command to abort
  1646. * tag - tag to abort
  1647. */
  1648. static
  1649. void acornscsi_abortcmd(AS_Host *host, unsigned char tag)
  1650. {
  1651. host->scsi.phase = PHASE_ABORTED;
  1652. sbic_arm_write(host, SBIC_CMND, CMND_ASSERTATN);
  1653. msgqueue_flush(&host->scsi.msgs);
  1654. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  1655. if (tag)
  1656. msgqueue_addmsg(&host->scsi.msgs, 2, ABORT_TAG, tag);
  1657. else
  1658. #endif
  1659. msgqueue_addmsg(&host->scsi.msgs, 1, ABORT);
  1660. }
  1661. /* ==========================================================================================
  1662. * Interrupt routines.
  1663. */
  1664. /*
  1665. * Function: int acornscsi_sbicintr(AS_Host *host)
  1666. * Purpose : handle interrupts from SCSI device
  1667. * Params : host - host to process
  1668. * Returns : INTR_PROCESS if expecting another SBIC interrupt
  1669. * INTR_IDLE if no interrupt
  1670. * INTR_NEXT_COMMAND if we have finished processing the command
  1671. */
  1672. static
  1673. intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
  1674. {
  1675. unsigned int asr, ssr;
  1676. asr = sbic_arm_read(host, SBIC_ASR);
  1677. if (!(asr & ASR_INT))
  1678. return INTR_IDLE;
  1679. ssr = sbic_arm_read(host, SBIC_SSR);
  1680. #if (DEBUG & DEBUG_PHASES)
  1681. print_sbic_status(asr, ssr, host->scsi.phase);
  1682. #endif
  1683. ADD_STATUS(8, ssr, host->scsi.phase, in_irq);
  1684. if (host->SCpnt && !host->scsi.disconnectable)
  1685. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1686. switch (ssr) {
  1687. case 0x00: /* reset state - not advanced */
  1688. printk(KERN_ERR "scsi%d: reset in standard mode but wanted advanced mode.\n",
  1689. host->host->host_no);
  1690. /* setup sbic - WD33C93A */
  1691. sbic_arm_write(host, SBIC_OWNID, OWNID_EAF | host->host->this_id);
  1692. sbic_arm_write(host, SBIC_CMND, CMND_RESET);
  1693. return INTR_IDLE;
  1694. case 0x01: /* reset state - advanced */
  1695. sbic_arm_write(host, SBIC_CTRL, INIT_SBICDMA | CTRL_IDI);
  1696. sbic_arm_write(host, SBIC_TIMEOUT, TIMEOUT_TIME);
  1697. sbic_arm_write(host, SBIC_SYNCHTRANSFER, SYNCHTRANSFER_2DBA);
  1698. sbic_arm_write(host, SBIC_SOURCEID, SOURCEID_ER | SOURCEID_DSP);
  1699. msgqueue_flush(&host->scsi.msgs);
  1700. return INTR_IDLE;
  1701. case 0x41: /* unexpected disconnect aborted command */
  1702. acornscsi_disconnect_unexpected(host);
  1703. return INTR_NEXT_COMMAND;
  1704. }
  1705. switch (host->scsi.phase) {
  1706. case PHASE_CONNECTING: /* STATE: command removed from issue queue */
  1707. switch (ssr) {
  1708. case 0x11: /* -> PHASE_CONNECTED */
  1709. /* BUS FREE -> SELECTION */
  1710. host->scsi.phase = PHASE_CONNECTED;
  1711. msgqueue_flush(&host->scsi.msgs);
  1712. host->dma.transferred = host->scsi.SCp.scsi_xferred;
  1713. /* 33C93 gives next interrupt indicating bus phase */
  1714. asr = sbic_arm_read(host, SBIC_ASR);
  1715. if (!(asr & ASR_INT))
  1716. break;
  1717. ssr = sbic_arm_read(host, SBIC_SSR);
  1718. ADD_STATUS(8, ssr, host->scsi.phase, 1);
  1719. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, 1);
  1720. goto connected;
  1721. case 0x42: /* select timed out */
  1722. /* -> PHASE_IDLE */
  1723. acornscsi_done(host, &host->SCpnt, DID_NO_CONNECT);
  1724. return INTR_NEXT_COMMAND;
  1725. case 0x81: /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1726. /* BUS FREE -> RESELECTION */
  1727. host->origSCpnt = host->SCpnt;
  1728. host->SCpnt = NULL;
  1729. msgqueue_flush(&host->scsi.msgs);
  1730. acornscsi_reconnect(host);
  1731. break;
  1732. default:
  1733. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTING, SSR %02X?\n",
  1734. host->host->host_no, acornscsi_target(host), ssr);
  1735. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1736. acornscsi_abortcmd(host, host->SCpnt->tag);
  1737. }
  1738. return INTR_PROCESSING;
  1739. connected:
  1740. case PHASE_CONNECTED: /* STATE: device selected ok */
  1741. switch (ssr) {
  1742. #ifdef NONSTANDARD
  1743. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1744. /* SELECTION -> COMMAND */
  1745. acornscsi_sendcommand(host);
  1746. break;
  1747. case 0x8b: /* -> PHASE_STATUS */
  1748. /* SELECTION -> STATUS */
  1749. acornscsi_readstatusbyte(host);
  1750. host->scsi.phase = PHASE_STATUSIN;
  1751. break;
  1752. #endif
  1753. case 0x8e: /* -> PHASE_MSGOUT */
  1754. /* SELECTION ->MESSAGE OUT */
  1755. host->scsi.phase = PHASE_MSGOUT;
  1756. acornscsi_buildmessages(host);
  1757. acornscsi_sendmessage(host);
  1758. break;
  1759. /* these should not happen */
  1760. case 0x85: /* target disconnected */
  1761. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  1762. break;
  1763. default:
  1764. printk(KERN_ERR "scsi%d.%c: PHASE_CONNECTED, SSR %02X?\n",
  1765. host->host->host_no, acornscsi_target(host), ssr);
  1766. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1767. acornscsi_abortcmd(host, host->SCpnt->tag);
  1768. }
  1769. return INTR_PROCESSING;
  1770. case PHASE_MSGOUT: /* STATE: connected & sent IDENTIFY message */
  1771. /*
  1772. * SCSI standard says that MESSAGE OUT phases can be followed by a
  1773. * DATA phase, STATUS phase, MESSAGE IN phase or COMMAND phase
  1774. */
  1775. switch (ssr) {
  1776. case 0x8a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1777. case 0x1a: /* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1778. /* MESSAGE OUT -> COMMAND */
  1779. acornscsi_sendcommand(host);
  1780. break;
  1781. case 0x8b: /* -> PHASE_STATUS */
  1782. case 0x1b: /* -> PHASE_STATUS */
  1783. /* MESSAGE OUT -> STATUS */
  1784. acornscsi_readstatusbyte(host);
  1785. host->scsi.phase = PHASE_STATUSIN;
  1786. break;
  1787. case 0x8e: /* -> PHASE_MSGOUT */
  1788. /* MESSAGE_OUT(MESSAGE_IN) ->MESSAGE OUT */
  1789. acornscsi_sendmessage(host);
  1790. break;
  1791. case 0x4f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1792. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1793. /* MESSAGE OUT -> MESSAGE IN */
  1794. acornscsi_message(host);
  1795. break;
  1796. default:
  1797. printk(KERN_ERR "scsi%d.%c: PHASE_MSGOUT, SSR %02X?\n",
  1798. host->host->host_no, acornscsi_target(host), ssr);
  1799. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1800. }
  1801. return INTR_PROCESSING;
  1802. case PHASE_COMMAND: /* STATE: connected & command sent */
  1803. switch (ssr) {
  1804. case 0x18: /* -> PHASE_DATAOUT */
  1805. /* COMMAND -> DATA OUT */
  1806. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1807. acornscsi_abortcmd(host, host->SCpnt->tag);
  1808. acornscsi_dma_setup(host, DMA_OUT);
  1809. if (!acornscsi_starttransfer(host))
  1810. acornscsi_abortcmd(host, host->SCpnt->tag);
  1811. host->scsi.phase = PHASE_DATAOUT;
  1812. return INTR_IDLE;
  1813. case 0x19: /* -> PHASE_DATAIN */
  1814. /* COMMAND -> DATA IN */
  1815. if (host->scsi.SCp.sent_command != host->SCpnt->cmd_len)
  1816. acornscsi_abortcmd(host, host->SCpnt->tag);
  1817. acornscsi_dma_setup(host, DMA_IN);
  1818. if (!acornscsi_starttransfer(host))
  1819. acornscsi_abortcmd(host, host->SCpnt->tag);
  1820. host->scsi.phase = PHASE_DATAIN;
  1821. return INTR_IDLE;
  1822. case 0x1b: /* -> PHASE_STATUS */
  1823. /* COMMAND -> STATUS */
  1824. acornscsi_readstatusbyte(host);
  1825. host->scsi.phase = PHASE_STATUSIN;
  1826. break;
  1827. case 0x1e: /* -> PHASE_MSGOUT */
  1828. /* COMMAND -> MESSAGE OUT */
  1829. acornscsi_sendmessage(host);
  1830. break;
  1831. case 0x1f: /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1832. /* COMMAND -> MESSAGE IN */
  1833. acornscsi_message(host);
  1834. break;
  1835. default:
  1836. printk(KERN_ERR "scsi%d.%c: PHASE_COMMAND, SSR %02X?\n",
  1837. host->host->host_no, acornscsi_target(host), ssr);
  1838. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1839. }
  1840. return INTR_PROCESSING;
  1841. case PHASE_DISCONNECT: /* STATE: connected, received DISCONNECT msg */
  1842. if (ssr == 0x85) { /* -> PHASE_IDLE */
  1843. host->scsi.disconnectable = 1;
  1844. host->scsi.reconnected.tag = 0;
  1845. host->scsi.phase = PHASE_IDLE;
  1846. host->stats.disconnects += 1;
  1847. } else {
  1848. printk(KERN_ERR "scsi%d.%c: PHASE_DISCONNECT, SSR %02X instead of disconnect?\n",
  1849. host->host->host_no, acornscsi_target(host), ssr);
  1850. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1851. }
  1852. return INTR_NEXT_COMMAND;
  1853. case PHASE_IDLE: /* STATE: disconnected */
  1854. if (ssr == 0x81) /* -> PHASE_RECONNECTED or PHASE_ABORTED */
  1855. acornscsi_reconnect(host);
  1856. else {
  1857. printk(KERN_ERR "scsi%d.%c: PHASE_IDLE, SSR %02X while idle?\n",
  1858. host->host->host_no, acornscsi_target(host), ssr);
  1859. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1860. }
  1861. return INTR_PROCESSING;
  1862. case PHASE_RECONNECTED: /* STATE: device reconnected to initiator */
  1863. /*
  1864. * Command reconnected - if MESGIN, get message - it may be
  1865. * the tag. If not, get command out of disconnected queue
  1866. */
  1867. /*
  1868. * If we reconnected and we're not in MESSAGE IN phase after IDENTIFY,
  1869. * reconnect I_T_L command
  1870. */
  1871. if (ssr != 0x8f && !acornscsi_reconnect_finish(host))
  1872. return INTR_IDLE;
  1873. ADD_STATUS(host->SCpnt->device->id, ssr, host->scsi.phase, in_irq);
  1874. switch (ssr) {
  1875. case 0x88: /* data out phase */
  1876. /* -> PHASE_DATAOUT */
  1877. /* MESSAGE IN -> DATA OUT */
  1878. acornscsi_dma_setup(host, DMA_OUT);
  1879. if (!acornscsi_starttransfer(host))
  1880. acornscsi_abortcmd(host, host->SCpnt->tag);
  1881. host->scsi.phase = PHASE_DATAOUT;
  1882. return INTR_IDLE;
  1883. case 0x89: /* data in phase */
  1884. /* -> PHASE_DATAIN */
  1885. /* MESSAGE IN -> DATA IN */
  1886. acornscsi_dma_setup(host, DMA_IN);
  1887. if (!acornscsi_starttransfer(host))
  1888. acornscsi_abortcmd(host, host->SCpnt->tag);
  1889. host->scsi.phase = PHASE_DATAIN;
  1890. return INTR_IDLE;
  1891. case 0x8a: /* command out */
  1892. /* MESSAGE IN -> COMMAND */
  1893. acornscsi_sendcommand(host);/* -> PHASE_COMMAND, PHASE_COMMANDPAUSED */
  1894. break;
  1895. case 0x8b: /* status in */
  1896. /* -> PHASE_STATUSIN */
  1897. /* MESSAGE IN -> STATUS */
  1898. acornscsi_readstatusbyte(host);
  1899. host->scsi.phase = PHASE_STATUSIN;
  1900. break;
  1901. case 0x8e: /* message out */
  1902. /* -> PHASE_MSGOUT */
  1903. /* MESSAGE IN -> MESSAGE OUT */
  1904. acornscsi_sendmessage(host);
  1905. break;
  1906. case 0x8f: /* message in */
  1907. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1908. break;
  1909. default:
  1910. printk(KERN_ERR "scsi%d.%c: PHASE_RECONNECTED, SSR %02X after reconnect?\n",
  1911. host->host->host_no, acornscsi_target(host), ssr);
  1912. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1913. }
  1914. return INTR_PROCESSING;
  1915. case PHASE_DATAIN: /* STATE: transferred data in */
  1916. /*
  1917. * This is simple - if we disconnect then the DMA address & count is
  1918. * correct.
  1919. */
  1920. switch (ssr) {
  1921. case 0x19: /* -> PHASE_DATAIN */
  1922. case 0x89: /* -> PHASE_DATAIN */
  1923. acornscsi_abortcmd(host, host->SCpnt->tag);
  1924. return INTR_IDLE;
  1925. case 0x1b: /* -> PHASE_STATUSIN */
  1926. case 0x4b: /* -> PHASE_STATUSIN */
  1927. case 0x8b: /* -> PHASE_STATUSIN */
  1928. /* DATA IN -> STATUS */
  1929. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1930. acornscsi_sbic_xfcount(host);
  1931. acornscsi_dma_stop(host);
  1932. acornscsi_readstatusbyte(host);
  1933. host->scsi.phase = PHASE_STATUSIN;
  1934. break;
  1935. case 0x1e: /* -> PHASE_MSGOUT */
  1936. case 0x4e: /* -> PHASE_MSGOUT */
  1937. case 0x8e: /* -> PHASE_MSGOUT */
  1938. /* DATA IN -> MESSAGE OUT */
  1939. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1940. acornscsi_sbic_xfcount(host);
  1941. acornscsi_dma_stop(host);
  1942. acornscsi_sendmessage(host);
  1943. break;
  1944. case 0x1f: /* message in */
  1945. case 0x4f: /* message in */
  1946. case 0x8f: /* message in */
  1947. /* DATA IN -> MESSAGE IN */
  1948. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1949. acornscsi_sbic_xfcount(host);
  1950. acornscsi_dma_stop(host);
  1951. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1952. break;
  1953. default:
  1954. printk(KERN_ERR "scsi%d.%c: PHASE_DATAIN, SSR %02X?\n",
  1955. host->host->host_no, acornscsi_target(host), ssr);
  1956. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  1957. }
  1958. return INTR_PROCESSING;
  1959. case PHASE_DATAOUT: /* STATE: transferred data out */
  1960. /*
  1961. * This is more complicated - if we disconnect, the DMA could be 12
  1962. * bytes ahead of us. We need to correct this.
  1963. */
  1964. switch (ssr) {
  1965. case 0x18: /* -> PHASE_DATAOUT */
  1966. case 0x88: /* -> PHASE_DATAOUT */
  1967. acornscsi_abortcmd(host, host->SCpnt->tag);
  1968. return INTR_IDLE;
  1969. case 0x1b: /* -> PHASE_STATUSIN */
  1970. case 0x4b: /* -> PHASE_STATUSIN */
  1971. case 0x8b: /* -> PHASE_STATUSIN */
  1972. /* DATA OUT -> STATUS */
  1973. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1974. acornscsi_sbic_xfcount(host);
  1975. acornscsi_dma_stop(host);
  1976. acornscsi_dma_adjust(host);
  1977. acornscsi_readstatusbyte(host);
  1978. host->scsi.phase = PHASE_STATUSIN;
  1979. break;
  1980. case 0x1e: /* -> PHASE_MSGOUT */
  1981. case 0x4e: /* -> PHASE_MSGOUT */
  1982. case 0x8e: /* -> PHASE_MSGOUT */
  1983. /* DATA OUT -> MESSAGE OUT */
  1984. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1985. acornscsi_sbic_xfcount(host);
  1986. acornscsi_dma_stop(host);
  1987. acornscsi_dma_adjust(host);
  1988. acornscsi_sendmessage(host);
  1989. break;
  1990. case 0x1f: /* message in */
  1991. case 0x4f: /* message in */
  1992. case 0x8f: /* message in */
  1993. /* DATA OUT -> MESSAGE IN */
  1994. host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
  1995. acornscsi_sbic_xfcount(host);
  1996. acornscsi_dma_stop(host);
  1997. acornscsi_dma_adjust(host);
  1998. acornscsi_message(host); /* -> PHASE_MSGIN, PHASE_DISCONNECT */
  1999. break;
  2000. default:
  2001. printk(KERN_ERR "scsi%d.%c: PHASE_DATAOUT, SSR %02X?\n",
  2002. host->host->host_no, acornscsi_target(host), ssr);
  2003. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2004. }
  2005. return INTR_PROCESSING;
  2006. case PHASE_STATUSIN: /* STATE: status in complete */
  2007. switch (ssr) {
  2008. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2009. case 0x8f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2010. /* STATUS -> MESSAGE IN */
  2011. acornscsi_message(host);
  2012. break;
  2013. case 0x1e: /* -> PHASE_MSGOUT */
  2014. case 0x8e: /* -> PHASE_MSGOUT */
  2015. /* STATUS -> MESSAGE OUT */
  2016. acornscsi_sendmessage(host);
  2017. break;
  2018. default:
  2019. printk(KERN_ERR "scsi%d.%c: PHASE_STATUSIN, SSR %02X instead of MESSAGE_IN?\n",
  2020. host->host->host_no, acornscsi_target(host), ssr);
  2021. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2022. }
  2023. return INTR_PROCESSING;
  2024. case PHASE_MSGIN: /* STATE: message in */
  2025. switch (ssr) {
  2026. case 0x1e: /* -> PHASE_MSGOUT */
  2027. case 0x4e: /* -> PHASE_MSGOUT */
  2028. case 0x8e: /* -> PHASE_MSGOUT */
  2029. /* MESSAGE IN -> MESSAGE OUT */
  2030. acornscsi_sendmessage(host);
  2031. break;
  2032. case 0x1f: /* -> PHASE_MSGIN, PHASE_DONE, PHASE_DISCONNECT */
  2033. case 0x2f:
  2034. case 0x4f:
  2035. case 0x8f:
  2036. acornscsi_message(host);
  2037. break;
  2038. case 0x85:
  2039. printk("scsi%d.%c: strange message in disconnection\n",
  2040. host->host->host_no, acornscsi_target(host));
  2041. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2042. acornscsi_done(host, &host->SCpnt, DID_ERROR);
  2043. break;
  2044. default:
  2045. printk(KERN_ERR "scsi%d.%c: PHASE_MSGIN, SSR %02X after message in?\n",
  2046. host->host->host_no, acornscsi_target(host), ssr);
  2047. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2048. }
  2049. return INTR_PROCESSING;
  2050. case PHASE_DONE: /* STATE: received status & message */
  2051. switch (ssr) {
  2052. case 0x85: /* -> PHASE_IDLE */
  2053. acornscsi_done(host, &host->SCpnt, DID_OK);
  2054. return INTR_NEXT_COMMAND;
  2055. case 0x1e:
  2056. case 0x8e:
  2057. acornscsi_sendmessage(host);
  2058. break;
  2059. default:
  2060. printk(KERN_ERR "scsi%d.%c: PHASE_DONE, SSR %02X instead of disconnect?\n",
  2061. host->host->host_no, acornscsi_target(host), ssr);
  2062. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2063. }
  2064. return INTR_PROCESSING;
  2065. case PHASE_ABORTED:
  2066. switch (ssr) {
  2067. case 0x85:
  2068. if (host->SCpnt)
  2069. acornscsi_done(host, &host->SCpnt, DID_ABORT);
  2070. else {
  2071. clear_bit(host->scsi.reconnected.target * 8 + host->scsi.reconnected.lun,
  2072. host->busyluns);
  2073. host->scsi.phase = PHASE_IDLE;
  2074. }
  2075. return INTR_NEXT_COMMAND;
  2076. case 0x1e:
  2077. case 0x2e:
  2078. case 0x4e:
  2079. case 0x8e:
  2080. acornscsi_sendmessage(host);
  2081. break;
  2082. default:
  2083. printk(KERN_ERR "scsi%d.%c: PHASE_ABORTED, SSR %02X?\n",
  2084. host->host->host_no, acornscsi_target(host), ssr);
  2085. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2086. }
  2087. return INTR_PROCESSING;
  2088. default:
  2089. printk(KERN_ERR "scsi%d.%c: unknown driver phase %d\n",
  2090. host->host->host_no, acornscsi_target(host), ssr);
  2091. acornscsi_dumplog(host, host->SCpnt ? host->SCpnt->device->id : 8);
  2092. }
  2093. return INTR_PROCESSING;
  2094. }
  2095. /*
  2096. * Prototype: void acornscsi_intr(int irq, void *dev_id)
  2097. * Purpose : handle interrupts from Acorn SCSI card
  2098. * Params : irq - interrupt number
  2099. * dev_id - device specific data (AS_Host structure)
  2100. */
  2101. static irqreturn_t
  2102. acornscsi_intr(int irq, void *dev_id)
  2103. {
  2104. AS_Host *host = (AS_Host *)dev_id;
  2105. intr_ret_t ret;
  2106. int iostatus;
  2107. int in_irq = 0;
  2108. do {
  2109. ret = INTR_IDLE;
  2110. iostatus = readb(host->fast + INT_REG);
  2111. if (iostatus & 2) {
  2112. acornscsi_dma_intr(host);
  2113. iostatus = readb(host->fast + INT_REG);
  2114. }
  2115. if (iostatus & 8)
  2116. ret = acornscsi_sbicintr(host, in_irq);
  2117. /*
  2118. * If we have a transfer pending, start it.
  2119. * Only start it if the interface has already started transferring
  2120. * it's data
  2121. */
  2122. if (host->dma.xfer_required)
  2123. acornscsi_dma_xfer(host);
  2124. if (ret == INTR_NEXT_COMMAND)
  2125. ret = acornscsi_kick(host);
  2126. in_irq = 1;
  2127. } while (ret != INTR_IDLE);
  2128. return IRQ_HANDLED;
  2129. }
  2130. /*=============================================================================================
  2131. * Interfaces between interrupt handler and rest of scsi code
  2132. */
  2133. /*
  2134. * Function : acornscsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  2135. * Purpose : queues a SCSI command
  2136. * Params : cmd - SCSI command
  2137. * done - function called on completion, with pointer to command descriptor
  2138. * Returns : 0, or < 0 on error.
  2139. */
  2140. static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
  2141. void (*done)(struct scsi_cmnd *))
  2142. {
  2143. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2144. if (!done) {
  2145. /* there should be some way of rejecting errors like this without panicing... */
  2146. panic("scsi%d: queuecommand called with NULL done function [cmd=%p]",
  2147. host->host->host_no, SCpnt);
  2148. return -EINVAL;
  2149. }
  2150. #if (DEBUG & DEBUG_NO_WRITE)
  2151. if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) {
  2152. printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
  2153. host->host->host_no, '0' + SCpnt->device->id);
  2154. SCpnt->result = DID_NO_CONNECT << 16;
  2155. done(SCpnt);
  2156. return 0;
  2157. }
  2158. #endif
  2159. SCpnt->scsi_done = done;
  2160. SCpnt->host_scribble = NULL;
  2161. SCpnt->result = 0;
  2162. SCpnt->tag = 0;
  2163. SCpnt->SCp.phase = (int)acornscsi_datadirection(SCpnt->cmnd[0]);
  2164. SCpnt->SCp.sent_command = 0;
  2165. SCpnt->SCp.scsi_xferred = 0;
  2166. init_SCp(SCpnt);
  2167. host->stats.queues += 1;
  2168. {
  2169. unsigned long flags;
  2170. if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) {
  2171. SCpnt->result = DID_ERROR << 16;
  2172. done(SCpnt);
  2173. return 0;
  2174. }
  2175. local_irq_save(flags);
  2176. if (host->scsi.phase == PHASE_IDLE)
  2177. acornscsi_kick(host);
  2178. local_irq_restore(flags);
  2179. }
  2180. return 0;
  2181. }
  2182. DEF_SCSI_QCMD(acornscsi_queuecmd)
  2183. /*
  2184. * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
  2185. * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
  2186. * Params : SCpntp1 - pointer to command to return
  2187. * SCpntp2 - pointer to command to check
  2188. * result - result to pass back to mid-level done function
  2189. * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
  2190. */
  2191. static inline void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1,
  2192. struct scsi_cmnd **SCpntp2,
  2193. int result)
  2194. {
  2195. struct scsi_cmnd *SCpnt = *SCpntp1;
  2196. if (SCpnt) {
  2197. *SCpntp1 = NULL;
  2198. SCpnt->result = result;
  2199. SCpnt->scsi_done(SCpnt);
  2200. }
  2201. if (SCpnt == *SCpntp2)
  2202. *SCpntp2 = NULL;
  2203. }
  2204. enum res_abort { res_not_running, res_success, res_success_clear, res_snooze };
  2205. /*
  2206. * Prototype: enum res acornscsi_do_abort(struct scsi_cmnd *SCpnt)
  2207. * Purpose : abort a command on this host
  2208. * Params : SCpnt - command to abort
  2209. * Returns : our abort status
  2210. */
  2211. static enum res_abort acornscsi_do_abort(AS_Host *host, struct scsi_cmnd *SCpnt)
  2212. {
  2213. enum res_abort res = res_not_running;
  2214. if (queue_remove_cmd(&host->queues.issue, SCpnt)) {
  2215. /*
  2216. * The command was on the issue queue, and has not been
  2217. * issued yet. We can remove the command from the queue,
  2218. * and acknowledge the abort. Neither the devices nor the
  2219. * interface know about the command.
  2220. */
  2221. //#if (DEBUG & DEBUG_ABORT)
  2222. printk("on issue queue ");
  2223. //#endif
  2224. res = res_success;
  2225. } else if (queue_remove_cmd(&host->queues.disconnected, SCpnt)) {
  2226. /*
  2227. * The command was on the disconnected queue. Simply
  2228. * acknowledge the abort condition, and when the target
  2229. * reconnects, we will give it an ABORT message. The
  2230. * target should then disconnect, and we will clear
  2231. * the busylun bit.
  2232. */
  2233. //#if (DEBUG & DEBUG_ABORT)
  2234. printk("on disconnected queue ");
  2235. //#endif
  2236. res = res_success;
  2237. } else if (host->SCpnt == SCpnt) {
  2238. unsigned long flags;
  2239. //#if (DEBUG & DEBUG_ABORT)
  2240. printk("executing ");
  2241. //#endif
  2242. local_irq_save(flags);
  2243. switch (host->scsi.phase) {
  2244. /*
  2245. * If the interface is idle, and the command is 'disconnectable',
  2246. * then it is the same as on the disconnected queue. We simply
  2247. * remove all traces of the command. When the target reconnects,
  2248. * we will give it an ABORT message since the command could not
  2249. * be found. When the target finally disconnects, we will clear
  2250. * the busylun bit.
  2251. */
  2252. case PHASE_IDLE:
  2253. if (host->scsi.disconnectable) {
  2254. host->scsi.disconnectable = 0;
  2255. host->SCpnt = NULL;
  2256. res = res_success;
  2257. }
  2258. break;
  2259. /*
  2260. * If the command has connected and done nothing further,
  2261. * simply force a disconnect. We also need to clear the
  2262. * busylun bit.
  2263. */
  2264. case PHASE_CONNECTED:
  2265. sbic_arm_write(host, SBIC_CMND, CMND_DISCONNECT);
  2266. host->SCpnt = NULL;
  2267. res = res_success_clear;
  2268. break;
  2269. default:
  2270. acornscsi_abortcmd(host, host->SCpnt->tag);
  2271. res = res_snooze;
  2272. }
  2273. local_irq_restore(flags);
  2274. } else if (host->origSCpnt == SCpnt) {
  2275. /*
  2276. * The command will be executed next, but a command
  2277. * is currently using the interface. This is similar to
  2278. * being on the issue queue, except the busylun bit has
  2279. * been set.
  2280. */
  2281. host->origSCpnt = NULL;
  2282. //#if (DEBUG & DEBUG_ABORT)
  2283. printk("waiting for execution ");
  2284. //#endif
  2285. res = res_success_clear;
  2286. } else
  2287. printk("unknown ");
  2288. return res;
  2289. }
  2290. /*
  2291. * Prototype: int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2292. * Purpose : abort a command on this host
  2293. * Params : SCpnt - command to abort
  2294. * Returns : one of SCSI_ABORT_ macros
  2295. */
  2296. int acornscsi_abort(struct scsi_cmnd *SCpnt)
  2297. {
  2298. AS_Host *host = (AS_Host *) SCpnt->device->host->hostdata;
  2299. int result;
  2300. host->stats.aborts += 1;
  2301. #if (DEBUG & DEBUG_ABORT)
  2302. {
  2303. int asr, ssr;
  2304. asr = sbic_arm_read(host, SBIC_ASR);
  2305. ssr = sbic_arm_read(host, SBIC_SSR);
  2306. printk(KERN_WARNING "acornscsi_abort: ");
  2307. print_sbic_status(asr, ssr, host->scsi.phase);
  2308. acornscsi_dumplog(host, SCpnt->device->id);
  2309. }
  2310. #endif
  2311. printk("scsi%d: ", host->host->host_no);
  2312. switch (acornscsi_do_abort(host, SCpnt)) {
  2313. /*
  2314. * We managed to find the command and cleared it out.
  2315. * We do not expect the command to be executing on the
  2316. * target, but we have set the busylun bit.
  2317. */
  2318. case res_success_clear:
  2319. //#if (DEBUG & DEBUG_ABORT)
  2320. printk("clear ");
  2321. //#endif
  2322. clear_bit(SCpnt->device->id * 8 +
  2323. (u8)(SCpnt->device->lun & 0x7), host->busyluns);
  2324. /*
  2325. * We found the command, and cleared it out. Either
  2326. * the command is still known to be executing on the
  2327. * target, or the busylun bit is not set.
  2328. */
  2329. case res_success:
  2330. //#if (DEBUG & DEBUG_ABORT)
  2331. printk("success\n");
  2332. //#endif
  2333. result = SUCCESS;
  2334. break;
  2335. /*
  2336. * We did find the command, but unfortunately we couldn't
  2337. * unhook it from ourselves. Wait some more, and if it
  2338. * still doesn't complete, reset the interface.
  2339. */
  2340. case res_snooze:
  2341. //#if (DEBUG & DEBUG_ABORT)
  2342. printk("snooze\n");
  2343. //#endif
  2344. result = FAILED;
  2345. break;
  2346. /*
  2347. * The command could not be found (either because it completed,
  2348. * or it got dropped.
  2349. */
  2350. default:
  2351. case res_not_running:
  2352. acornscsi_dumplog(host, SCpnt->device->id);
  2353. result = FAILED;
  2354. //#if (DEBUG & DEBUG_ABORT)
  2355. printk("not running\n");
  2356. //#endif
  2357. break;
  2358. }
  2359. return result;
  2360. }
  2361. /*
  2362. * Prototype: int acornscsi_reset(struct scsi_cmnd *SCpnt)
  2363. * Purpose : reset a command on this host/reset this host
  2364. * Params : SCpnt - command causing reset
  2365. * Returns : one of SCSI_RESET_ macros
  2366. */
  2367. int acornscsi_bus_reset(struct scsi_cmnd *SCpnt)
  2368. {
  2369. AS_Host *host = (AS_Host *)SCpnt->device->host->hostdata;
  2370. struct scsi_cmnd *SCptr;
  2371. host->stats.resets += 1;
  2372. #if (DEBUG & DEBUG_RESET)
  2373. {
  2374. int asr, ssr;
  2375. asr = sbic_arm_read(host, SBIC_ASR);
  2376. ssr = sbic_arm_read(host, SBIC_SSR);
  2377. printk(KERN_WARNING "acornscsi_reset: ");
  2378. print_sbic_status(asr, ssr, host->scsi.phase);
  2379. acornscsi_dumplog(host, SCpnt->device->id);
  2380. }
  2381. #endif
  2382. acornscsi_dma_stop(host);
  2383. /*
  2384. * do hard reset. This resets all devices on this host, and so we
  2385. * must set the reset status on all commands.
  2386. */
  2387. acornscsi_resetcard(host);
  2388. while ((SCptr = queue_remove(&host->queues.disconnected)) != NULL)
  2389. ;
  2390. return SUCCESS;
  2391. }
  2392. /*==============================================================================================
  2393. * initialisation & miscellaneous support
  2394. */
  2395. /*
  2396. * Function: char *acornscsi_info(struct Scsi_Host *host)
  2397. * Purpose : return a string describing this interface
  2398. * Params : host - host to give information on
  2399. * Returns : a constant string
  2400. */
  2401. const
  2402. char *acornscsi_info(struct Scsi_Host *host)
  2403. {
  2404. static char string[100], *p;
  2405. p = string;
  2406. p += sprintf(string, "%s at port %08lX irq %d v%d.%d.%d"
  2407. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2408. " SYNC"
  2409. #endif
  2410. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2411. " TAG"
  2412. #endif
  2413. #if (DEBUG & DEBUG_NO_WRITE)
  2414. " NOWRITE (" __stringify(NO_WRITE) ")"
  2415. #endif
  2416. , host->hostt->name, host->io_port, host->irq,
  2417. VER_MAJOR, VER_MINOR, VER_PATCH);
  2418. return string;
  2419. }
  2420. static int acornscsi_show_info(struct seq_file *m, struct Scsi_Host *instance)
  2421. {
  2422. int devidx;
  2423. struct scsi_device *scd;
  2424. AS_Host *host;
  2425. host = (AS_Host *)instance->hostdata;
  2426. seq_printf(m, "AcornSCSI driver v%d.%d.%d"
  2427. #ifdef CONFIG_SCSI_ACORNSCSI_SYNC
  2428. " SYNC"
  2429. #endif
  2430. #ifdef CONFIG_SCSI_ACORNSCSI_TAGGED_QUEUE
  2431. " TAG"
  2432. #endif
  2433. #if (DEBUG & DEBUG_NO_WRITE)
  2434. " NOWRITE (" __stringify(NO_WRITE) ")"
  2435. #endif
  2436. "\n\n", VER_MAJOR, VER_MINOR, VER_PATCH);
  2437. seq_printf(m, "SBIC: WD33C93A Address: %p IRQ : %d\n",
  2438. host->base + SBIC_REGIDX, host->scsi.irq);
  2439. #ifdef USE_DMAC
  2440. seq_printf(m, "DMAC: uPC71071 Address: %p IRQ : %d\n\n",
  2441. host->base + DMAC_OFFSET, host->scsi.irq);
  2442. #endif
  2443. seq_printf(m, "Statistics:\n"
  2444. "Queued commands: %-10u Issued commands: %-10u\n"
  2445. "Done commands : %-10u Reads : %-10u\n"
  2446. "Writes : %-10u Others : %-10u\n"
  2447. "Disconnects : %-10u Aborts : %-10u\n"
  2448. "Resets : %-10u\n\nLast phases:",
  2449. host->stats.queues, host->stats.removes,
  2450. host->stats.fins, host->stats.reads,
  2451. host->stats.writes, host->stats.miscs,
  2452. host->stats.disconnects, host->stats.aborts,
  2453. host->stats.resets);
  2454. for (devidx = 0; devidx < 9; devidx ++) {
  2455. unsigned int statptr, prev;
  2456. seq_printf(m, "\n%c:", devidx == 8 ? 'H' : ('0' + devidx));
  2457. statptr = host->status_ptr[devidx] - 10;
  2458. if ((signed int)statptr < 0)
  2459. statptr += STATUS_BUFFER_SIZE;
  2460. prev = host->status[devidx][statptr].when;
  2461. for (; statptr != host->status_ptr[devidx]; statptr = (statptr + 1) & (STATUS_BUFFER_SIZE - 1)) {
  2462. if (host->status[devidx][statptr].when) {
  2463. seq_printf(m, "%c%02X:%02X+%2ld",
  2464. host->status[devidx][statptr].irq ? '-' : ' ',
  2465. host->status[devidx][statptr].ph,
  2466. host->status[devidx][statptr].ssr,
  2467. (host->status[devidx][statptr].when - prev) < 100 ?
  2468. (host->status[devidx][statptr].when - prev) : 99);
  2469. prev = host->status[devidx][statptr].when;
  2470. }
  2471. }
  2472. }
  2473. seq_printf(m, "\nAttached devices:\n");
  2474. shost_for_each_device(scd, instance) {
  2475. seq_printf(m, "Device/Lun TaggedQ Sync\n");
  2476. seq_printf(m, " %d/%llu ", scd->id, scd->lun);
  2477. if (scd->tagged_supported)
  2478. seq_printf(m, "%3sabled(%3d) ",
  2479. scd->simple_tags ? "en" : "dis",
  2480. scd->current_tag);
  2481. else
  2482. seq_printf(m, "unsupported ");
  2483. if (host->device[scd->id].sync_xfer & 15)
  2484. seq_printf(m, "offset %d, %d ns\n",
  2485. host->device[scd->id].sync_xfer & 15,
  2486. acornscsi_getperiod(host->device[scd->id].sync_xfer));
  2487. else
  2488. seq_printf(m, "async\n");
  2489. }
  2490. return 0;
  2491. }
  2492. static struct scsi_host_template acornscsi_template = {
  2493. .module = THIS_MODULE,
  2494. .show_info = acornscsi_show_info,
  2495. .name = "AcornSCSI",
  2496. .info = acornscsi_info,
  2497. .queuecommand = acornscsi_queuecmd,
  2498. .eh_abort_handler = acornscsi_abort,
  2499. .eh_bus_reset_handler = acornscsi_bus_reset,
  2500. .can_queue = 16,
  2501. .this_id = 7,
  2502. .sg_tablesize = SG_ALL,
  2503. .cmd_per_lun = 2,
  2504. .use_clustering = DISABLE_CLUSTERING,
  2505. .proc_name = "acornscsi",
  2506. };
  2507. static int acornscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  2508. {
  2509. struct Scsi_Host *host;
  2510. AS_Host *ashost;
  2511. int ret;
  2512. ret = ecard_request_resources(ec);
  2513. if (ret)
  2514. goto out;
  2515. host = scsi_host_alloc(&acornscsi_template, sizeof(AS_Host));
  2516. if (!host) {
  2517. ret = -ENOMEM;
  2518. goto out_release;
  2519. }
  2520. ashost = (AS_Host *)host->hostdata;
  2521. ashost->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
  2522. ashost->fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
  2523. if (!ashost->base || !ashost->fast)
  2524. goto out_put;
  2525. host->irq = ec->irq;
  2526. ashost->host = host;
  2527. ashost->scsi.irq = host->irq;
  2528. ec->irqaddr = ashost->fast + INT_REG;
  2529. ec->irqmask = 0x0a;
  2530. ret = request_irq(host->irq, acornscsi_intr, 0, "acornscsi", ashost);
  2531. if (ret) {
  2532. printk(KERN_CRIT "scsi%d: IRQ%d not free: %d\n",
  2533. host->host_no, ashost->scsi.irq, ret);
  2534. goto out_put;
  2535. }
  2536. memset(&ashost->stats, 0, sizeof (ashost->stats));
  2537. queue_initialise(&ashost->queues.issue);
  2538. queue_initialise(&ashost->queues.disconnected);
  2539. msgqueue_initialise(&ashost->scsi.msgs);
  2540. acornscsi_resetcard(ashost);
  2541. ret = scsi_add_host(host, &ec->dev);
  2542. if (ret)
  2543. goto out_irq;
  2544. scsi_scan_host(host);
  2545. goto out;
  2546. out_irq:
  2547. free_irq(host->irq, ashost);
  2548. msgqueue_free(&ashost->scsi.msgs);
  2549. queue_free(&ashost->queues.disconnected);
  2550. queue_free(&ashost->queues.issue);
  2551. out_put:
  2552. ecardm_iounmap(ec, ashost->fast);
  2553. ecardm_iounmap(ec, ashost->base);
  2554. scsi_host_put(host);
  2555. out_release:
  2556. ecard_release_resources(ec);
  2557. out:
  2558. return ret;
  2559. }
  2560. static void acornscsi_remove(struct expansion_card *ec)
  2561. {
  2562. struct Scsi_Host *host = ecard_get_drvdata(ec);
  2563. AS_Host *ashost = (AS_Host *)host->hostdata;
  2564. ecard_set_drvdata(ec, NULL);
  2565. scsi_remove_host(host);
  2566. /*
  2567. * Put card into RESET state
  2568. */
  2569. writeb(0x80, ashost->fast + PAGE_REG);
  2570. free_irq(host->irq, ashost);
  2571. msgqueue_free(&ashost->scsi.msgs);
  2572. queue_free(&ashost->queues.disconnected);
  2573. queue_free(&ashost->queues.issue);
  2574. ecardm_iounmap(ec, ashost->fast);
  2575. ecardm_iounmap(ec, ashost->base);
  2576. scsi_host_put(host);
  2577. ecard_release_resources(ec);
  2578. }
  2579. static const struct ecard_id acornscsi_cids[] = {
  2580. { MANU_ACORN, PROD_ACORN_SCSI },
  2581. { 0xffff, 0xffff },
  2582. };
  2583. static struct ecard_driver acornscsi_driver = {
  2584. .probe = acornscsi_probe,
  2585. .remove = acornscsi_remove,
  2586. .id_table = acornscsi_cids,
  2587. .drv = {
  2588. .name = "acornscsi",
  2589. },
  2590. };
  2591. static int __init acornscsi_init(void)
  2592. {
  2593. return ecard_register_driver(&acornscsi_driver);
  2594. }
  2595. static void __exit acornscsi_exit(void)
  2596. {
  2597. ecard_remove_driver(&acornscsi_driver);
  2598. }
  2599. module_init(acornscsi_init);
  2600. module_exit(acornscsi_exit);
  2601. MODULE_AUTHOR("Russell King");
  2602. MODULE_DESCRIPTION("AcornSCSI driver");
  2603. MODULE_LICENSE("GPL");