aha152x.c 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* aha152x.c -- Adaptec AHA-152x driver
  3. * Author: Jürgen E. Fischer, [email protected]
  4. * Copyright 1993-2004 Jürgen E. Fischer
  5. *
  6. * $Id: aha152x.c,v 2.7 2004/01/24 11:42:59 fischer Exp $
  7. *
  8. * $Log: aha152x.c,v $
  9. * Revision 2.7 2004/01/24 11:42:59 fischer
  10. * - gather code that is not used by PCMCIA at the end
  11. * - move request_region for !PCMCIA case to detection
  12. * - migration to new scsi host api (remove legacy code)
  13. * - free host scribble before scsi_done
  14. * - fix error handling
  15. * - one isapnp device added to id_table
  16. *
  17. * Revision 2.6 2003/10/30 20:52:47 fischer
  18. * - interfaces changes for kernel 2.6
  19. * - aha152x_probe_one introduced for pcmcia stub
  20. * - fixed pnpdev handling
  21. * - instead of allocation a new one, reuse command for request sense after check condition and reset
  22. * - fixes race in is_complete
  23. *
  24. * Revision 2.5 2002/04/14 11:24:53 fischer
  25. * - isapnp support
  26. * - abort fixed
  27. * - 2.5 support
  28. *
  29. * Revision 2.4 2000/12/16 12:53:56 fischer
  30. * - allow REQUEST SENSE to be queued
  31. * - handle shared PCI interrupts
  32. *
  33. * Revision 2.3 2000/11/04 16:40:26 fischer
  34. * - handle data overruns
  35. * - extend timeout for data phases
  36. *
  37. * Revision 2.2 2000/08/08 19:54:53 fischer
  38. * - minor changes
  39. *
  40. * Revision 2.1 2000/05/17 16:23:17 fischer
  41. * - signature update
  42. * - fix for data out w/o scatter gather
  43. *
  44. * Revision 2.0 1999/12/25 15:07:32 fischer
  45. * - interrupt routine completly reworked
  46. * - basic support for new eh code
  47. *
  48. * Revision 1.21 1999/11/10 23:46:36 fischer
  49. * - default to synchronous operation
  50. * - synchronous negotiation fixed
  51. * - added timeout to loops
  52. * - debugging output can be controlled through procfs
  53. *
  54. * Revision 1.20 1999/11/07 18:37:31 fischer
  55. * - synchronous operation works
  56. * - resid support for sg driver
  57. *
  58. * Revision 1.19 1999/11/02 22:39:59 fischer
  59. * - moved leading comments to README.aha152x
  60. * - new additional module parameters
  61. * - updates for 2.3
  62. * - support for the Tripace TC1550 controller
  63. * - interrupt handling changed
  64. *
  65. * Revision 1.18 1996/09/07 20:10:40 fischer
  66. * - fixed can_queue handling (multiple outstanding commands working again)
  67. *
  68. * Revision 1.17 1996/08/17 16:05:14 fischer
  69. * - biosparam improved
  70. * - interrupt verification
  71. * - updated documentation
  72. * - cleanups
  73. *
  74. * Revision 1.16 1996/06/09 00:04:56 root
  75. * - added configuration symbols for insmod (aha152x/aha152x1)
  76. *
  77. * Revision 1.15 1996/04/30 14:52:06 fischer
  78. * - proc info fixed
  79. * - support for extended translation for >1GB disks
  80. *
  81. * Revision 1.14 1996/01/17 15:11:20 fischer
  82. * - fixed lockup in MESSAGE IN phase after reconnection
  83. *
  84. * Revision 1.13 1996/01/09 02:15:53 fischer
  85. * - some cleanups
  86. * - moved request_irq behind controller initialization
  87. * (to avoid spurious interrupts)
  88. *
  89. * Revision 1.12 1995/12/16 12:26:07 fischer
  90. * - barrier()s added
  91. * - configurable RESET delay added
  92. *
  93. * Revision 1.11 1995/12/06 21:18:35 fischer
  94. * - some minor updates
  95. *
  96. * Revision 1.10 1995/07/22 19:18:45 fischer
  97. * - support for 2 controllers
  98. * - started synchronous data transfers (not working yet)
  99. *
  100. * Revision 1.9 1995/03/18 09:20:24 root
  101. * - patches for PCMCIA and modules
  102. *
  103. * Revision 1.8 1995/01/21 22:07:19 root
  104. * - snarf_region => request_region
  105. * - aha152x_intr interface change
  106. *
  107. * Revision 1.7 1995/01/02 23:19:36 root
  108. * - updated COMMAND_SIZE to cmd_len
  109. * - changed sti() to restore_flags()
  110. * - fixed some #ifdef which generated warnings
  111. *
  112. * Revision 1.6 1994/11/24 20:35:27 root
  113. * - problem with odd number of bytes in fifo fixed
  114. *
  115. * Revision 1.5 1994/10/30 14:39:56 root
  116. * - abort code fixed
  117. * - debugging improved
  118. *
  119. * Revision 1.4 1994/09/12 11:33:01 root
  120. * - irqaction to request_irq
  121. * - abortion updated
  122. *
  123. * Revision 1.3 1994/08/04 13:53:05 root
  124. * - updates for mid-level-driver changes
  125. * - accept unexpected BUSFREE phase as error condition
  126. * - parity check now configurable
  127. *
  128. * Revision 1.2 1994/07/03 12:56:36 root
  129. * - cleaned up debugging code
  130. * - more tweaking on reset delays
  131. * - updated abort/reset code (pretty untested...)
  132. *
  133. * Revision 1.1 1994/05/28 21:18:49 root
  134. * - update for mid-level interface change (abort-reset)
  135. * - delays after resets adjusted for some slow devices
  136. *
  137. * Revision 1.0 1994/03/25 12:52:00 root
  138. * - Fixed "more data than expected" problem
  139. * - added new BIOS signatures
  140. *
  141. * Revision 0.102 1994/01/31 20:44:12 root
  142. * - minor changes in insw/outsw handling
  143. *
  144. * Revision 0.101 1993/12/13 01:16:27 root
  145. * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
  146. * fixes problems with CD-ROM sector size detection & media change)
  147. *
  148. * Revision 0.100 1993/12/10 16:58:47 root
  149. * - fix for unsuccessful selections in case of non-continuous id assignments
  150. * on the scsi bus.
  151. *
  152. * Revision 0.99 1993/10/24 16:19:59 root
  153. * - fixed DATA IN (rare read errors gone)
  154. *
  155. * Revision 0.98 1993/10/17 12:54:44 root
  156. * - fixed some recent fixes (shame on me)
  157. * - moved initialization of scratch area to aha152x_queue
  158. *
  159. * Revision 0.97 1993/10/09 18:53:53 root
  160. * - DATA IN fixed. Rarely left data in the fifo.
  161. *
  162. * Revision 0.96 1993/10/03 00:53:59 root
  163. * - minor changes on DATA IN
  164. *
  165. * Revision 0.95 1993/09/24 10:36:01 root
  166. * - change handling of MSGI after reselection
  167. * - fixed sti/cli
  168. * - minor changes
  169. *
  170. * Revision 0.94 1993/09/18 14:08:22 root
  171. * - fixed bug in multiple outstanding command code
  172. * - changed detection
  173. * - support for kernel command line configuration
  174. * - reset corrected
  175. * - changed message handling
  176. *
  177. * Revision 0.93 1993/09/15 20:41:19 root
  178. * - fixed bugs with multiple outstanding commands
  179. *
  180. * Revision 0.92 1993/09/13 02:46:33 root
  181. * - multiple outstanding commands work (no problems with IBM drive)
  182. *
  183. * Revision 0.91 1993/09/12 20:51:46 root
  184. * added multiple outstanding commands
  185. * (some problem with this $%&? IBM device remain)
  186. *
  187. * Revision 0.9 1993/09/12 11:11:22 root
  188. * - corrected auto-configuration
  189. * - changed the auto-configuration (added some '#define's)
  190. * - added support for dis-/reconnection
  191. *
  192. * Revision 0.8 1993/09/06 23:09:39 root
  193. * - added support for the drive activity light
  194. * - minor changes
  195. *
  196. * Revision 0.7 1993/09/05 14:30:15 root
  197. * - improved phase detection
  198. * - now using the new snarf_region code of 0.99pl13
  199. *
  200. * Revision 0.6 1993/09/02 11:01:38 root
  201. * first public release; added some signatures and biosparam()
  202. *
  203. * Revision 0.5 1993/08/30 10:23:30 root
  204. * fixed timing problems with my IBM drive
  205. *
  206. * Revision 0.4 1993/08/29 14:06:52 root
  207. * fixed some problems with timeouts due incomplete commands
  208. *
  209. * Revision 0.3 1993/08/28 15:55:03 root
  210. * writing data works too. mounted and worked on a dos partition
  211. *
  212. * Revision 0.2 1993/08/27 22:42:07 root
  213. * reading data works. Mounted a msdos partition.
  214. *
  215. * Revision 0.1 1993/08/25 13:38:30 root
  216. * first "damn thing doesn't work" version
  217. *
  218. * Revision 0.0 1993/08/14 19:54:25 root
  219. * empty function bodies; detect() works.
  220. *
  221. **************************************************************************
  222. see Documentation/scsi/aha152x.rst for configuration details
  223. **************************************************************************/
  224. #include <linux/module.h>
  225. #include <asm/irq.h>
  226. #include <linux/io.h>
  227. #include <linux/blkdev.h>
  228. #include <linux/completion.h>
  229. #include <linux/errno.h>
  230. #include <linux/string.h>
  231. #include <linux/wait.h>
  232. #include <linux/ioport.h>
  233. #include <linux/delay.h>
  234. #include <linux/proc_fs.h>
  235. #include <linux/interrupt.h>
  236. #include <linux/init.h>
  237. #include <linux/kernel.h>
  238. #include <linux/isapnp.h>
  239. #include <linux/spinlock.h>
  240. #include <linux/workqueue.h>
  241. #include <linux/list.h>
  242. #include <linux/slab.h>
  243. #include <scsi/scsi.h>
  244. #include <scsi/scsi_cmnd.h>
  245. #include <scsi/scsi_dbg.h>
  246. #include <scsi/scsi_device.h>
  247. #include <scsi/scsi_eh.h>
  248. #include <scsi/scsi_host.h>
  249. #include <scsi/scsi_tcq.h>
  250. #include <scsi/scsi_transport_spi.h>
  251. #include <scsi/scsicam.h>
  252. #include "aha152x.h"
  253. static LIST_HEAD(aha152x_host_list);
  254. /* DEFINES */
  255. /* For PCMCIA cards, always use AUTOCONF */
  256. #if defined(AHA152X_PCMCIA) || defined(MODULE)
  257. #if !defined(AUTOCONF)
  258. #define AUTOCONF
  259. #endif
  260. #endif
  261. #if !defined(AUTOCONF) && !defined(SETUP0)
  262. #error define AUTOCONF or SETUP0
  263. #endif
  264. #define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
  265. #define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
  266. #define LEAD "(scsi%d:%d:%d) "
  267. #define INFO_LEAD KERN_INFO LEAD
  268. #define CMDINFO(cmd) \
  269. (cmd) ? ((cmd)->device->host->host_no) : -1, \
  270. (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
  271. (cmd) ? ((u8)(cmd)->device->lun & 0x07) : -1
  272. static inline void
  273. CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
  274. {
  275. scsi_set_resid(cmd, scsi_get_resid(cmd) + inc);
  276. }
  277. #define DELAY_DEFAULT 1000
  278. #if defined(AHA152X_PCMCIA)
  279. #define IRQ_MIN 0
  280. #define IRQ_MAX 16
  281. #else
  282. #define IRQ_MIN 9
  283. #if defined(__PPC)
  284. #define IRQ_MAX (nr_irqs-1)
  285. #else
  286. #define IRQ_MAX 12
  287. #endif
  288. #endif
  289. enum {
  290. not_issued = 0x0001, /* command not yet issued */
  291. selecting = 0x0002, /* target is being selected */
  292. identified = 0x0004, /* IDENTIFY was sent */
  293. disconnected = 0x0008, /* target disconnected */
  294. completed = 0x0010, /* target sent COMMAND COMPLETE */
  295. aborted = 0x0020, /* ABORT was sent */
  296. resetted = 0x0040, /* BUS DEVICE RESET was sent */
  297. spiordy = 0x0080, /* waiting for SPIORDY to raise */
  298. syncneg = 0x0100, /* synchronous negotiation in progress */
  299. aborting = 0x0200, /* ABORT is pending */
  300. resetting = 0x0400, /* BUS DEVICE RESET is pending */
  301. check_condition = 0x0800, /* requesting sense after CHECK CONDITION */
  302. };
  303. struct aha152x_cmd_priv {
  304. char *ptr;
  305. int this_residual;
  306. struct scatterlist *buffer;
  307. int status;
  308. int message;
  309. int sent_command;
  310. int phase;
  311. };
  312. static struct aha152x_cmd_priv *aha152x_priv(struct scsi_cmnd *cmd)
  313. {
  314. return scsi_cmd_priv(cmd);
  315. }
  316. MODULE_AUTHOR("Jürgen Fischer");
  317. MODULE_DESCRIPTION(AHA152X_REVID);
  318. MODULE_LICENSE("GPL");
  319. #if !defined(AHA152X_PCMCIA)
  320. #if defined(MODULE)
  321. static int io[] = {0, 0};
  322. module_param_hw_array(io, int, ioport, NULL, 0);
  323. MODULE_PARM_DESC(io,"base io address of controller");
  324. static int irq[] = {0, 0};
  325. module_param_hw_array(irq, int, irq, NULL, 0);
  326. MODULE_PARM_DESC(irq,"interrupt for controller");
  327. static int scsiid[] = {7, 7};
  328. module_param_array(scsiid, int, NULL, 0);
  329. MODULE_PARM_DESC(scsiid,"scsi id of controller");
  330. static int reconnect[] = {1, 1};
  331. module_param_array(reconnect, int, NULL, 0);
  332. MODULE_PARM_DESC(reconnect,"allow targets to disconnect");
  333. static int parity[] = {1, 1};
  334. module_param_array(parity, int, NULL, 0);
  335. MODULE_PARM_DESC(parity,"use scsi parity");
  336. static int sync[] = {1, 1};
  337. module_param_array(sync, int, NULL, 0);
  338. MODULE_PARM_DESC(sync,"use synchronous transfers");
  339. static int delay[] = {DELAY_DEFAULT, DELAY_DEFAULT};
  340. module_param_array(delay, int, NULL, 0);
  341. MODULE_PARM_DESC(delay,"scsi reset delay");
  342. static int exttrans[] = {0, 0};
  343. module_param_array(exttrans, int, NULL, 0);
  344. MODULE_PARM_DESC(exttrans,"use extended translation");
  345. static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
  346. module_param_array(aha152x, int, NULL, 0);
  347. MODULE_PARM_DESC(aha152x, "parameters for first controller");
  348. static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
  349. module_param_array(aha152x1, int, NULL, 0);
  350. MODULE_PARM_DESC(aha152x1, "parameters for second controller");
  351. #endif /* MODULE */
  352. #ifdef __ISAPNP__
  353. static struct isapnp_device_id id_table[] = {
  354. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1502), 0 },
  355. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1505), 0 },
  356. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1510), 0 },
  357. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1515), 0 },
  358. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1520), 0 },
  359. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2015), 0 },
  360. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1522), 0 },
  361. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x2215), 0 },
  362. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1530), 0 },
  363. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3015), 0 },
  364. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x1532), 0 },
  365. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x3215), 0 },
  366. { ISAPNP_ANY_ID, ISAPNP_ANY_ID, ISAPNP_VENDOR('A', 'D', 'P'), ISAPNP_FUNCTION(0x6360), 0 },
  367. { ISAPNP_DEVICE_SINGLE_END, }
  368. };
  369. MODULE_DEVICE_TABLE(isapnp, id_table);
  370. #endif /* ISAPNP */
  371. #endif /* !AHA152X_PCMCIA */
  372. static struct scsi_host_template aha152x_driver_template;
  373. /*
  374. * internal states of the host
  375. *
  376. */
  377. enum aha152x_state {
  378. idle=0,
  379. unknown,
  380. seldo,
  381. seldi,
  382. selto,
  383. busfree,
  384. msgo,
  385. cmd,
  386. msgi,
  387. status,
  388. datai,
  389. datao,
  390. parerr,
  391. rsti,
  392. maxstate
  393. };
  394. /*
  395. * current state information of the host
  396. *
  397. */
  398. struct aha152x_hostdata {
  399. struct scsi_cmnd *issue_SC;
  400. /* pending commands to issue */
  401. struct scsi_cmnd *current_SC;
  402. /* current command on the bus */
  403. struct scsi_cmnd *disconnected_SC;
  404. /* commands that disconnected */
  405. struct scsi_cmnd *done_SC;
  406. /* command that was completed */
  407. spinlock_t lock;
  408. /* host lock */
  409. #if defined(AHA152X_STAT)
  410. int total_commands;
  411. int disconnections;
  412. int busfree_without_any_action;
  413. int busfree_without_old_command;
  414. int busfree_without_new_command;
  415. int busfree_without_done_command;
  416. int busfree_with_check_condition;
  417. int count[maxstate];
  418. int count_trans[maxstate];
  419. unsigned long time[maxstate];
  420. #endif
  421. int commands; /* current number of commands */
  422. int reconnect; /* disconnection allowed */
  423. int parity; /* parity checking enabled */
  424. int synchronous; /* synchronous transferes enabled */
  425. int delay; /* reset out delay */
  426. int ext_trans; /* extended translation enabled */
  427. int swint; /* software-interrupt was fired during detect() */
  428. int service; /* bh needs to be run */
  429. int in_intr; /* bh is running */
  430. /* current state,
  431. previous state,
  432. last state different from current state */
  433. enum aha152x_state state, prevstate, laststate;
  434. int target;
  435. /* reconnecting target */
  436. unsigned char syncrate[8];
  437. /* current synchronous transfer agreements */
  438. unsigned char syncneg[8];
  439. /* 0: no negotiation;
  440. * 1: negotiation in progress;
  441. * 2: negotiation completed
  442. */
  443. int cmd_i;
  444. /* number of sent bytes of current command */
  445. int msgi_len;
  446. /* number of received message bytes */
  447. unsigned char msgi[256];
  448. /* received message bytes */
  449. int msgo_i, msgo_len;
  450. /* number of sent bytes and length of current messages */
  451. unsigned char msgo[256];
  452. /* pending messages */
  453. int data_len;
  454. /* number of sent/received bytes in dataphase */
  455. unsigned long io_port0;
  456. unsigned long io_port1;
  457. #ifdef __ISAPNP__
  458. struct pnp_dev *pnpdev;
  459. #endif
  460. struct list_head host_list;
  461. };
  462. /*
  463. * host specific command extension
  464. *
  465. */
  466. struct aha152x_scdata {
  467. struct scsi_cmnd *next; /* next sc in queue */
  468. struct completion *done;/* semaphore to block on */
  469. struct scsi_eh_save ses;
  470. };
  471. /* access macros for hostdata */
  472. #define HOSTDATA(shpnt) ((struct aha152x_hostdata *) &shpnt->hostdata)
  473. #define HOSTNO ((shpnt)->host_no)
  474. #define CURRENT_SC (HOSTDATA(shpnt)->current_SC)
  475. #define DONE_SC (HOSTDATA(shpnt)->done_SC)
  476. #define ISSUE_SC (HOSTDATA(shpnt)->issue_SC)
  477. #define DISCONNECTED_SC (HOSTDATA(shpnt)->disconnected_SC)
  478. #define QLOCK (HOSTDATA(shpnt)->lock)
  479. #define QLOCKER (HOSTDATA(shpnt)->locker)
  480. #define QLOCKERL (HOSTDATA(shpnt)->lockerl)
  481. #define STATE (HOSTDATA(shpnt)->state)
  482. #define PREVSTATE (HOSTDATA(shpnt)->prevstate)
  483. #define LASTSTATE (HOSTDATA(shpnt)->laststate)
  484. #define RECONN_TARGET (HOSTDATA(shpnt)->target)
  485. #define CMD_I (HOSTDATA(shpnt)->cmd_i)
  486. #define MSGO(i) (HOSTDATA(shpnt)->msgo[i])
  487. #define MSGO_I (HOSTDATA(shpnt)->msgo_i)
  488. #define MSGOLEN (HOSTDATA(shpnt)->msgo_len)
  489. #define ADDMSGO(x) (MSGOLEN<256 ? (void)(MSGO(MSGOLEN++)=x) : aha152x_error(shpnt,"MSGO overflow"))
  490. #define MSGI(i) (HOSTDATA(shpnt)->msgi[i])
  491. #define MSGILEN (HOSTDATA(shpnt)->msgi_len)
  492. #define ADDMSGI(x) (MSGILEN<256 ? (void)(MSGI(MSGILEN++)=x) : aha152x_error(shpnt,"MSGI overflow"))
  493. #define DATA_LEN (HOSTDATA(shpnt)->data_len)
  494. #define SYNCRATE (HOSTDATA(shpnt)->syncrate[CURRENT_SC->device->id])
  495. #define SYNCNEG (HOSTDATA(shpnt)->syncneg[CURRENT_SC->device->id])
  496. #define DELAY (HOSTDATA(shpnt)->delay)
  497. #define EXT_TRANS (HOSTDATA(shpnt)->ext_trans)
  498. #define TC1550 (HOSTDATA(shpnt)->tc1550)
  499. #define RECONNECT (HOSTDATA(shpnt)->reconnect)
  500. #define PARITY (HOSTDATA(shpnt)->parity)
  501. #define SYNCHRONOUS (HOSTDATA(shpnt)->synchronous)
  502. #define HOSTIOPORT0 (HOSTDATA(shpnt)->io_port0)
  503. #define HOSTIOPORT1 (HOSTDATA(shpnt)->io_port1)
  504. #define SCDATA(SCpnt) ((struct aha152x_scdata *) (SCpnt)->host_scribble)
  505. #define SCNEXT(SCpnt) SCDATA(SCpnt)->next
  506. #define SCSEM(SCpnt) SCDATA(SCpnt)->done
  507. #define SG_ADDRESS(buffer) ((char *) sg_virt((buffer)))
  508. /* state handling */
  509. static void seldi_run(struct Scsi_Host *shpnt);
  510. static void seldo_run(struct Scsi_Host *shpnt);
  511. static void selto_run(struct Scsi_Host *shpnt);
  512. static void busfree_run(struct Scsi_Host *shpnt);
  513. static void msgo_init(struct Scsi_Host *shpnt);
  514. static void msgo_run(struct Scsi_Host *shpnt);
  515. static void msgo_end(struct Scsi_Host *shpnt);
  516. static void cmd_init(struct Scsi_Host *shpnt);
  517. static void cmd_run(struct Scsi_Host *shpnt);
  518. static void cmd_end(struct Scsi_Host *shpnt);
  519. static void datai_init(struct Scsi_Host *shpnt);
  520. static void datai_run(struct Scsi_Host *shpnt);
  521. static void datai_end(struct Scsi_Host *shpnt);
  522. static void datao_init(struct Scsi_Host *shpnt);
  523. static void datao_run(struct Scsi_Host *shpnt);
  524. static void datao_end(struct Scsi_Host *shpnt);
  525. static void status_run(struct Scsi_Host *shpnt);
  526. static void msgi_run(struct Scsi_Host *shpnt);
  527. static void msgi_end(struct Scsi_Host *shpnt);
  528. static void parerr_run(struct Scsi_Host *shpnt);
  529. static void rsti_run(struct Scsi_Host *shpnt);
  530. static void is_complete(struct Scsi_Host *shpnt);
  531. /*
  532. * driver states
  533. *
  534. */
  535. static struct {
  536. char *name;
  537. void (*init)(struct Scsi_Host *);
  538. void (*run)(struct Scsi_Host *);
  539. void (*end)(struct Scsi_Host *);
  540. int spio;
  541. } states[] = {
  542. { "idle", NULL, NULL, NULL, 0},
  543. { "unknown", NULL, NULL, NULL, 0},
  544. { "seldo", NULL, seldo_run, NULL, 0},
  545. { "seldi", NULL, seldi_run, NULL, 0},
  546. { "selto", NULL, selto_run, NULL, 0},
  547. { "busfree", NULL, busfree_run, NULL, 0},
  548. { "msgo", msgo_init, msgo_run, msgo_end, 1},
  549. { "cmd", cmd_init, cmd_run, cmd_end, 1},
  550. { "msgi", NULL, msgi_run, msgi_end, 1},
  551. { "status", NULL, status_run, NULL, 1},
  552. { "datai", datai_init, datai_run, datai_end, 0},
  553. { "datao", datao_init, datao_run, datao_end, 0},
  554. { "parerr", NULL, parerr_run, NULL, 0},
  555. { "rsti", NULL, rsti_run, NULL, 0},
  556. };
  557. /* setup & interrupt */
  558. static irqreturn_t intr(int irq, void *dev_id);
  559. static void reset_ports(struct Scsi_Host *shpnt);
  560. static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
  561. static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
  562. unsigned char host_byte);
  563. /* diagnostics */
  564. static void show_command(struct scsi_cmnd * ptr);
  565. static void show_queues(struct Scsi_Host *shpnt);
  566. static void disp_enintr(struct Scsi_Host *shpnt);
  567. /*
  568. * queue services:
  569. *
  570. */
  571. static inline void append_SC(struct scsi_cmnd **SC, struct scsi_cmnd *new_SC)
  572. {
  573. struct scsi_cmnd *end;
  574. SCNEXT(new_SC) = NULL;
  575. if (!*SC)
  576. *SC = new_SC;
  577. else {
  578. for (end = *SC; SCNEXT(end); end = SCNEXT(end))
  579. ;
  580. SCNEXT(end) = new_SC;
  581. }
  582. }
  583. static inline struct scsi_cmnd *remove_first_SC(struct scsi_cmnd ** SC)
  584. {
  585. struct scsi_cmnd *ptr;
  586. ptr = *SC;
  587. if (ptr) {
  588. *SC = SCNEXT(*SC);
  589. SCNEXT(ptr)=NULL;
  590. }
  591. return ptr;
  592. }
  593. static inline struct scsi_cmnd *remove_lun_SC(struct scsi_cmnd ** SC,
  594. int target, int lun)
  595. {
  596. struct scsi_cmnd *ptr, *prev;
  597. for (ptr = *SC, prev = NULL;
  598. ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
  599. prev = ptr, ptr = SCNEXT(ptr))
  600. ;
  601. if (ptr) {
  602. if (prev)
  603. SCNEXT(prev) = SCNEXT(ptr);
  604. else
  605. *SC = SCNEXT(ptr);
  606. SCNEXT(ptr)=NULL;
  607. }
  608. return ptr;
  609. }
  610. static inline struct scsi_cmnd *remove_SC(struct scsi_cmnd **SC,
  611. struct scsi_cmnd *SCp)
  612. {
  613. struct scsi_cmnd *ptr, *prev;
  614. for (ptr = *SC, prev = NULL;
  615. ptr && SCp!=ptr;
  616. prev = ptr, ptr = SCNEXT(ptr))
  617. ;
  618. if (ptr) {
  619. if (prev)
  620. SCNEXT(prev) = SCNEXT(ptr);
  621. else
  622. *SC = SCNEXT(ptr);
  623. SCNEXT(ptr)=NULL;
  624. }
  625. return ptr;
  626. }
  627. static irqreturn_t swintr(int irqno, void *dev_id)
  628. {
  629. struct Scsi_Host *shpnt = dev_id;
  630. HOSTDATA(shpnt)->swint++;
  631. SETPORT(DMACNTRL0, INTEN);
  632. return IRQ_HANDLED;
  633. }
  634. struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
  635. {
  636. struct Scsi_Host *shpnt;
  637. shpnt = scsi_host_alloc(&aha152x_driver_template, sizeof(struct aha152x_hostdata));
  638. if (!shpnt) {
  639. printk(KERN_ERR "aha152x: scsi_host_alloc failed\n");
  640. return NULL;
  641. }
  642. memset(HOSTDATA(shpnt), 0, sizeof *HOSTDATA(shpnt));
  643. INIT_LIST_HEAD(&HOSTDATA(shpnt)->host_list);
  644. /* need to have host registered before triggering any interrupt */
  645. list_add_tail(&HOSTDATA(shpnt)->host_list, &aha152x_host_list);
  646. shpnt->io_port = setup->io_port;
  647. shpnt->n_io_port = IO_RANGE;
  648. shpnt->irq = setup->irq;
  649. if (!setup->tc1550) {
  650. HOSTIOPORT0 = setup->io_port;
  651. HOSTIOPORT1 = setup->io_port;
  652. } else {
  653. HOSTIOPORT0 = setup->io_port+0x10;
  654. HOSTIOPORT1 = setup->io_port-0x10;
  655. }
  656. spin_lock_init(&QLOCK);
  657. RECONNECT = setup->reconnect;
  658. SYNCHRONOUS = setup->synchronous;
  659. PARITY = setup->parity;
  660. DELAY = setup->delay;
  661. EXT_TRANS = setup->ext_trans;
  662. SETPORT(SCSIID, setup->scsiid << 4);
  663. shpnt->this_id = setup->scsiid;
  664. if (setup->reconnect)
  665. shpnt->can_queue = AHA152X_MAXQUEUE;
  666. /* RESET OUT */
  667. printk("aha152x: resetting bus...\n");
  668. SETPORT(SCSISEQ, SCSIRSTO);
  669. mdelay(256);
  670. SETPORT(SCSISEQ, 0);
  671. mdelay(DELAY);
  672. reset_ports(shpnt);
  673. printk(KERN_INFO
  674. "aha152x%d%s: "
  675. "vital data: rev=%x, "
  676. "io=0x%03lx (0x%03lx/0x%03lx), "
  677. "irq=%d, "
  678. "scsiid=%d, "
  679. "reconnect=%s, "
  680. "parity=%s, "
  681. "synchronous=%s, "
  682. "delay=%d, "
  683. "extended translation=%s\n",
  684. shpnt->host_no, setup->tc1550 ? " (tc1550 mode)" : "",
  685. GETPORT(REV) & 0x7,
  686. shpnt->io_port, HOSTIOPORT0, HOSTIOPORT1,
  687. shpnt->irq,
  688. shpnt->this_id,
  689. RECONNECT ? "enabled" : "disabled",
  690. PARITY ? "enabled" : "disabled",
  691. SYNCHRONOUS ? "enabled" : "disabled",
  692. DELAY,
  693. EXT_TRANS ? "enabled" : "disabled");
  694. /* not expecting any interrupts */
  695. SETPORT(SIMODE0, 0);
  696. SETPORT(SIMODE1, 0);
  697. if (request_irq(shpnt->irq, swintr, IRQF_SHARED, "aha152x", shpnt)) {
  698. printk(KERN_ERR "aha152x%d: irq %d busy.\n", shpnt->host_no, shpnt->irq);
  699. goto out_host_put;
  700. }
  701. HOSTDATA(shpnt)->swint = 0;
  702. printk(KERN_INFO "aha152x%d: trying software interrupt, ", shpnt->host_no);
  703. mb();
  704. SETPORT(DMACNTRL0, SWINT|INTEN);
  705. mdelay(1000);
  706. free_irq(shpnt->irq, shpnt);
  707. if (!HOSTDATA(shpnt)->swint) {
  708. if (TESTHI(DMASTAT, INTSTAT)) {
  709. printk("lost.\n");
  710. } else {
  711. printk("failed.\n");
  712. }
  713. SETPORT(DMACNTRL0, INTEN);
  714. printk(KERN_ERR "aha152x%d: irq %d possibly wrong. "
  715. "Please verify.\n", shpnt->host_no, shpnt->irq);
  716. goto out_host_put;
  717. }
  718. printk("ok.\n");
  719. /* clear interrupts */
  720. SETPORT(SSTAT0, 0x7f);
  721. SETPORT(SSTAT1, 0xef);
  722. if (request_irq(shpnt->irq, intr, IRQF_SHARED, "aha152x", shpnt)) {
  723. printk(KERN_ERR "aha152x%d: failed to reassign irq %d.\n", shpnt->host_no, shpnt->irq);
  724. goto out_host_put;
  725. }
  726. if( scsi_add_host(shpnt, NULL) ) {
  727. free_irq(shpnt->irq, shpnt);
  728. printk(KERN_ERR "aha152x%d: failed to add host.\n", shpnt->host_no);
  729. goto out_host_put;
  730. }
  731. scsi_scan_host(shpnt);
  732. return shpnt;
  733. out_host_put:
  734. list_del(&HOSTDATA(shpnt)->host_list);
  735. scsi_host_put(shpnt);
  736. return NULL;
  737. }
  738. void aha152x_release(struct Scsi_Host *shpnt)
  739. {
  740. if (!shpnt)
  741. return;
  742. scsi_remove_host(shpnt);
  743. if (shpnt->irq)
  744. free_irq(shpnt->irq, shpnt);
  745. #if !defined(AHA152X_PCMCIA)
  746. if (shpnt->io_port)
  747. release_region(shpnt->io_port, IO_RANGE);
  748. #endif
  749. #ifdef __ISAPNP__
  750. if (HOSTDATA(shpnt)->pnpdev)
  751. pnp_device_detach(HOSTDATA(shpnt)->pnpdev);
  752. #endif
  753. list_del(&HOSTDATA(shpnt)->host_list);
  754. scsi_host_put(shpnt);
  755. }
  756. /*
  757. * setup controller to generate interrupts depending
  758. * on current state (lock has to be acquired)
  759. *
  760. */
  761. static int setup_expected_interrupts(struct Scsi_Host *shpnt)
  762. {
  763. if(CURRENT_SC) {
  764. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  765. acp->phase |= 1 << 16;
  766. if (acp->phase & selecting) {
  767. SETPORT(SSTAT1, SELTO);
  768. SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
  769. SETPORT(SIMODE1, ENSELTIMO);
  770. } else {
  771. SETPORT(SIMODE0, (acp->phase & spiordy) ? ENSPIORDY : 0);
  772. SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
  773. }
  774. } else if(STATE==seldi) {
  775. SETPORT(SIMODE0, 0);
  776. SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
  777. } else {
  778. SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
  779. SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
  780. }
  781. if(!HOSTDATA(shpnt)->in_intr)
  782. SETBITS(DMACNTRL0, INTEN);
  783. return TESTHI(DMASTAT, INTSTAT);
  784. }
  785. /*
  786. * Queue a command and setup interrupts for a free bus.
  787. */
  788. static int aha152x_internal_queue(struct scsi_cmnd *SCpnt,
  789. struct completion *complete, int phase)
  790. {
  791. struct aha152x_cmd_priv *acp = aha152x_priv(SCpnt);
  792. struct Scsi_Host *shpnt = SCpnt->device->host;
  793. unsigned long flags;
  794. acp->phase = not_issued | phase;
  795. acp->status = 0x1; /* Illegal status by SCSI standard */
  796. acp->message = 0;
  797. acp->sent_command = 0;
  798. if (acp->phase & (resetting | check_condition)) {
  799. if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
  800. scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n");
  801. return FAILED;
  802. }
  803. } else {
  804. SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
  805. if(!SCpnt->host_scribble) {
  806. scmd_printk(KERN_ERR, SCpnt, "allocation failed\n");
  807. return FAILED;
  808. }
  809. }
  810. SCNEXT(SCpnt) = NULL;
  811. SCSEM(SCpnt) = complete;
  812. /* setup scratch area
  813. SCp.ptr : buffer pointer
  814. SCp.this_residual : buffer length
  815. SCp.buffer : next buffer
  816. SCp.phase : current state of the command */
  817. if ((phase & resetting) || !scsi_sglist(SCpnt)) {
  818. acp->ptr = NULL;
  819. acp->this_residual = 0;
  820. scsi_set_resid(SCpnt, 0);
  821. acp->buffer = NULL;
  822. } else {
  823. scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
  824. acp->buffer = scsi_sglist(SCpnt);
  825. acp->ptr = SG_ADDRESS(acp->buffer);
  826. acp->this_residual = acp->buffer->length;
  827. }
  828. DO_LOCK(flags);
  829. #if defined(AHA152X_STAT)
  830. HOSTDATA(shpnt)->total_commands++;
  831. #endif
  832. /* Turn led on, when this is the first command. */
  833. HOSTDATA(shpnt)->commands++;
  834. if (HOSTDATA(shpnt)->commands==1)
  835. SETPORT(PORTA, 1);
  836. append_SC(&ISSUE_SC, SCpnt);
  837. if(!HOSTDATA(shpnt)->in_intr)
  838. setup_expected_interrupts(shpnt);
  839. DO_UNLOCK(flags);
  840. return 0;
  841. }
  842. /*
  843. * queue a command
  844. *
  845. */
  846. static int aha152x_queue_lck(struct scsi_cmnd *SCpnt)
  847. {
  848. return aha152x_internal_queue(SCpnt, NULL, 0);
  849. }
  850. static DEF_SCSI_QCMD(aha152x_queue)
  851. /*
  852. *
  853. */
  854. static void reset_done(struct scsi_cmnd *SCpnt)
  855. {
  856. if(SCSEM(SCpnt)) {
  857. complete(SCSEM(SCpnt));
  858. } else {
  859. printk(KERN_ERR "aha152x: reset_done w/o completion\n");
  860. }
  861. }
  862. static void aha152x_scsi_done(struct scsi_cmnd *SCpnt)
  863. {
  864. if (aha152x_priv(SCpnt)->phase & resetting)
  865. reset_done(SCpnt);
  866. else
  867. scsi_done(SCpnt);
  868. }
  869. /*
  870. * Abort a command
  871. *
  872. */
  873. static int aha152x_abort(struct scsi_cmnd *SCpnt)
  874. {
  875. struct Scsi_Host *shpnt = SCpnt->device->host;
  876. struct scsi_cmnd *ptr;
  877. unsigned long flags;
  878. DO_LOCK(flags);
  879. ptr=remove_SC(&ISSUE_SC, SCpnt);
  880. if(ptr) {
  881. HOSTDATA(shpnt)->commands--;
  882. if (!HOSTDATA(shpnt)->commands)
  883. SETPORT(PORTA, 0);
  884. DO_UNLOCK(flags);
  885. kfree(SCpnt->host_scribble);
  886. SCpnt->host_scribble=NULL;
  887. return SUCCESS;
  888. }
  889. DO_UNLOCK(flags);
  890. /*
  891. * FIXME:
  892. * for current command: queue ABORT for message out and raise ATN
  893. * for disconnected command: pseudo SC with ABORT message or ABORT on reselection?
  894. *
  895. */
  896. scmd_printk(KERN_ERR, SCpnt,
  897. "cannot abort running or disconnected command\n");
  898. return FAILED;
  899. }
  900. /*
  901. * Reset a device
  902. *
  903. */
  904. static int aha152x_device_reset(struct scsi_cmnd * SCpnt)
  905. {
  906. struct Scsi_Host *shpnt = SCpnt->device->host;
  907. DECLARE_COMPLETION(done);
  908. int ret, issued, disconnected;
  909. unsigned char old_cmd_len = SCpnt->cmd_len;
  910. unsigned long flags;
  911. unsigned long timeleft;
  912. if(CURRENT_SC==SCpnt) {
  913. scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n");
  914. return FAILED;
  915. }
  916. DO_LOCK(flags);
  917. issued = remove_SC(&ISSUE_SC, SCpnt) == NULL;
  918. disconnected = issued && remove_SC(&DISCONNECTED_SC, SCpnt);
  919. DO_UNLOCK(flags);
  920. SCpnt->cmd_len = 0;
  921. aha152x_internal_queue(SCpnt, &done, resetting);
  922. timeleft = wait_for_completion_timeout(&done, 100*HZ);
  923. if (!timeleft) {
  924. /* remove command from issue queue */
  925. DO_LOCK(flags);
  926. remove_SC(&ISSUE_SC, SCpnt);
  927. DO_UNLOCK(flags);
  928. }
  929. SCpnt->cmd_len = old_cmd_len;
  930. DO_LOCK(flags);
  931. if (aha152x_priv(SCpnt)->phase & resetted) {
  932. HOSTDATA(shpnt)->commands--;
  933. if (!HOSTDATA(shpnt)->commands)
  934. SETPORT(PORTA, 0);
  935. kfree(SCpnt->host_scribble);
  936. SCpnt->host_scribble=NULL;
  937. ret = SUCCESS;
  938. } else {
  939. /* requeue */
  940. if(!issued) {
  941. append_SC(&ISSUE_SC, SCpnt);
  942. } else if(disconnected) {
  943. append_SC(&DISCONNECTED_SC, SCpnt);
  944. }
  945. ret = FAILED;
  946. }
  947. DO_UNLOCK(flags);
  948. return ret;
  949. }
  950. static void free_hard_reset_SCs(struct Scsi_Host *shpnt,
  951. struct scsi_cmnd **SCs)
  952. {
  953. struct scsi_cmnd *ptr;
  954. ptr=*SCs;
  955. while(ptr) {
  956. struct scsi_cmnd *next;
  957. if(SCDATA(ptr)) {
  958. next = SCNEXT(ptr);
  959. } else {
  960. scmd_printk(KERN_DEBUG, ptr,
  961. "queue corrupted at %p\n", ptr);
  962. next = NULL;
  963. }
  964. if (!ptr->device->soft_reset) {
  965. remove_SC(SCs, ptr);
  966. HOSTDATA(shpnt)->commands--;
  967. kfree(ptr->host_scribble);
  968. ptr->host_scribble=NULL;
  969. }
  970. ptr = next;
  971. }
  972. }
  973. /*
  974. * Reset the bus
  975. *
  976. * AIC-6260 has a hard reset (MRST signal), but apparently
  977. * one cannot trigger it via software. So live with
  978. * a soft reset; no-one seemed to have cared.
  979. */
  980. static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
  981. {
  982. unsigned long flags;
  983. DO_LOCK(flags);
  984. free_hard_reset_SCs(shpnt, &ISSUE_SC);
  985. free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
  986. SETPORT(SCSISEQ, SCSIRSTO);
  987. mdelay(256);
  988. SETPORT(SCSISEQ, 0);
  989. mdelay(DELAY);
  990. setup_expected_interrupts(shpnt);
  991. if(HOSTDATA(shpnt)->commands==0)
  992. SETPORT(PORTA, 0);
  993. DO_UNLOCK(flags);
  994. return SUCCESS;
  995. }
  996. /*
  997. * Reset the bus
  998. *
  999. */
  1000. static int aha152x_bus_reset(struct scsi_cmnd *SCpnt)
  1001. {
  1002. return aha152x_bus_reset_host(SCpnt->device->host);
  1003. }
  1004. /*
  1005. * Restore default values to the AIC-6260 registers and reset the fifos
  1006. *
  1007. */
  1008. static void reset_ports(struct Scsi_Host *shpnt)
  1009. {
  1010. unsigned long flags;
  1011. /* disable interrupts */
  1012. SETPORT(DMACNTRL0, RSTFIFO);
  1013. SETPORT(SCSISEQ, 0);
  1014. SETPORT(SXFRCTL1, 0);
  1015. SETPORT(SCSISIG, 0);
  1016. SETRATE(0);
  1017. /* clear all interrupt conditions */
  1018. SETPORT(SSTAT0, 0x7f);
  1019. SETPORT(SSTAT1, 0xef);
  1020. SETPORT(SSTAT4, SYNCERR | FWERR | FRERR);
  1021. SETPORT(DMACNTRL0, 0);
  1022. SETPORT(DMACNTRL1, 0);
  1023. SETPORT(BRSTCNTRL, 0xf1);
  1024. /* clear SCSI fifos and transfer count */
  1025. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  1026. SETPORT(SXFRCTL0, CH1);
  1027. DO_LOCK(flags);
  1028. setup_expected_interrupts(shpnt);
  1029. DO_UNLOCK(flags);
  1030. }
  1031. /*
  1032. * Reset the host (bus and controller)
  1033. *
  1034. */
  1035. int aha152x_host_reset_host(struct Scsi_Host *shpnt)
  1036. {
  1037. aha152x_bus_reset_host(shpnt);
  1038. reset_ports(shpnt);
  1039. return SUCCESS;
  1040. }
  1041. /*
  1042. * Return the "logical geometry"
  1043. *
  1044. */
  1045. static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  1046. sector_t capacity, int *info_array)
  1047. {
  1048. struct Scsi_Host *shpnt = sdev->host;
  1049. /* try default translation */
  1050. info_array[0] = 64;
  1051. info_array[1] = 32;
  1052. info_array[2] = (unsigned long)capacity / (64 * 32);
  1053. /* for disks >1GB do some guessing */
  1054. if (info_array[2] >= 1024) {
  1055. int info[3];
  1056. /* try to figure out the geometry from the partition table */
  1057. if (scsicam_bios_param(bdev, capacity, info) < 0 ||
  1058. !((info[0] == 64 && info[1] == 32) || (info[0] == 255 && info[1] == 63))) {
  1059. if (EXT_TRANS) {
  1060. printk(KERN_NOTICE
  1061. "aha152x: unable to verify geometry for disk with >1GB.\n"
  1062. " using extended translation.\n");
  1063. info_array[0] = 255;
  1064. info_array[1] = 63;
  1065. info_array[2] = (unsigned long)capacity / (255 * 63);
  1066. } else {
  1067. printk(KERN_NOTICE
  1068. "aha152x: unable to verify geometry for disk with >1GB.\n"
  1069. " Using default translation. Please verify yourself.\n"
  1070. " Perhaps you need to enable extended translation in the driver.\n"
  1071. " See Documentation/scsi/aha152x.rst for details.\n");
  1072. }
  1073. } else {
  1074. info_array[0] = info[0];
  1075. info_array[1] = info[1];
  1076. info_array[2] = info[2];
  1077. if (info[0] == 255 && !EXT_TRANS) {
  1078. printk(KERN_NOTICE
  1079. "aha152x: current partition table is using extended translation.\n"
  1080. " using it also, although it's not explicitly enabled.\n");
  1081. }
  1082. }
  1083. }
  1084. return 0;
  1085. }
  1086. /*
  1087. * Internal done function
  1088. *
  1089. */
  1090. static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
  1091. unsigned char host_byte)
  1092. {
  1093. if (CURRENT_SC) {
  1094. if(DONE_SC)
  1095. scmd_printk(KERN_ERR, CURRENT_SC,
  1096. "there's already a completed command %p "
  1097. "- will cause abort\n", DONE_SC);
  1098. DONE_SC = CURRENT_SC;
  1099. CURRENT_SC = NULL;
  1100. set_status_byte(DONE_SC, status_byte);
  1101. set_host_byte(DONE_SC, host_byte);
  1102. } else
  1103. printk(KERN_ERR "aha152x: done() called outside of command\n");
  1104. }
  1105. static struct work_struct aha152x_tq;
  1106. /*
  1107. * Run service completions on the card with interrupts enabled.
  1108. *
  1109. */
  1110. static void run(struct work_struct *work)
  1111. {
  1112. struct aha152x_hostdata *hd;
  1113. list_for_each_entry(hd, &aha152x_host_list, host_list) {
  1114. struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
  1115. is_complete(shost);
  1116. }
  1117. }
  1118. /*
  1119. * Interrupt handler
  1120. *
  1121. */
  1122. static irqreturn_t intr(int irqno, void *dev_id)
  1123. {
  1124. struct Scsi_Host *shpnt = dev_id;
  1125. unsigned long flags;
  1126. unsigned char rev, dmacntrl0;
  1127. /*
  1128. * Read a couple of registers that are known to not be all 1's. If
  1129. * we read all 1's (-1), that means that either:
  1130. *
  1131. * a. The host adapter chip has gone bad, and we cannot control it,
  1132. * OR
  1133. * b. The host adapter is a PCMCIA card that has been ejected
  1134. *
  1135. * In either case, we cannot do anything with the host adapter at
  1136. * this point in time. So just ignore the interrupt and return.
  1137. * In the latter case, the interrupt might actually be meant for
  1138. * someone else sharing this IRQ, and that driver will handle it.
  1139. */
  1140. rev = GETPORT(REV);
  1141. dmacntrl0 = GETPORT(DMACNTRL0);
  1142. if ((rev == 0xFF) && (dmacntrl0 == 0xFF))
  1143. return IRQ_NONE;
  1144. if( TESTLO(DMASTAT, INTSTAT) )
  1145. return IRQ_NONE;
  1146. /* no more interrupts from the controller, while we're busy.
  1147. INTEN is restored by the BH handler */
  1148. CLRBITS(DMACNTRL0, INTEN);
  1149. DO_LOCK(flags);
  1150. if( HOSTDATA(shpnt)->service==0 ) {
  1151. HOSTDATA(shpnt)->service=1;
  1152. /* Poke the BH handler */
  1153. INIT_WORK(&aha152x_tq, run);
  1154. schedule_work(&aha152x_tq);
  1155. }
  1156. DO_UNLOCK(flags);
  1157. return IRQ_HANDLED;
  1158. }
  1159. /*
  1160. * busfree phase
  1161. * - handle completition/disconnection/error of current command
  1162. * - start selection for next command (if any)
  1163. */
  1164. static void busfree_run(struct Scsi_Host *shpnt)
  1165. {
  1166. unsigned long flags;
  1167. #if defined(AHA152X_STAT)
  1168. int action=0;
  1169. #endif
  1170. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  1171. SETPORT(SXFRCTL0, CH1);
  1172. SETPORT(SSTAT1, CLRBUSFREE);
  1173. if(CURRENT_SC) {
  1174. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1175. #if defined(AHA152X_STAT)
  1176. action++;
  1177. #endif
  1178. acp->phase &= ~syncneg;
  1179. if (acp->phase & completed) {
  1180. /* target sent COMMAND COMPLETE */
  1181. done(shpnt, acp->status, DID_OK);
  1182. } else if (acp->phase & aborted) {
  1183. done(shpnt, acp->status, DID_ABORT);
  1184. } else if (acp->phase & resetted) {
  1185. done(shpnt, acp->status, DID_RESET);
  1186. } else if (acp->phase & disconnected) {
  1187. /* target sent DISCONNECT */
  1188. #if defined(AHA152X_STAT)
  1189. HOSTDATA(shpnt)->disconnections++;
  1190. #endif
  1191. append_SC(&DISCONNECTED_SC, CURRENT_SC);
  1192. acp->phase |= 1 << 16;
  1193. CURRENT_SC = NULL;
  1194. } else {
  1195. done(shpnt, SAM_STAT_GOOD, DID_ERROR);
  1196. }
  1197. #if defined(AHA152X_STAT)
  1198. } else {
  1199. HOSTDATA(shpnt)->busfree_without_old_command++;
  1200. #endif
  1201. }
  1202. DO_LOCK(flags);
  1203. if(DONE_SC) {
  1204. #if defined(AHA152X_STAT)
  1205. action++;
  1206. #endif
  1207. if (aha152x_priv(DONE_SC)->phase & check_condition) {
  1208. struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
  1209. struct aha152x_scdata *sc = SCDATA(cmd);
  1210. scsi_eh_restore_cmnd(cmd, &sc->ses);
  1211. aha152x_priv(cmd)->status = SAM_STAT_CHECK_CONDITION;
  1212. HOSTDATA(shpnt)->commands--;
  1213. if (!HOSTDATA(shpnt)->commands)
  1214. SETPORT(PORTA, 0); /* turn led off */
  1215. } else if (aha152x_priv(DONE_SC)->status == SAM_STAT_CHECK_CONDITION) {
  1216. #if defined(AHA152X_STAT)
  1217. HOSTDATA(shpnt)->busfree_with_check_condition++;
  1218. #endif
  1219. if (!(aha152x_priv(DONE_SC)->phase & not_issued)) {
  1220. struct aha152x_scdata *sc;
  1221. struct scsi_cmnd *ptr = DONE_SC;
  1222. DONE_SC=NULL;
  1223. sc = SCDATA(ptr);
  1224. /* It was allocated in aha152x_internal_queue? */
  1225. BUG_ON(!sc);
  1226. scsi_eh_prep_cmnd(ptr, &sc->ses, NULL, 0, ~0);
  1227. DO_UNLOCK(flags);
  1228. aha152x_internal_queue(ptr, NULL, check_condition);
  1229. DO_LOCK(flags);
  1230. }
  1231. }
  1232. if (DONE_SC) {
  1233. struct scsi_cmnd *ptr = DONE_SC;
  1234. DONE_SC=NULL;
  1235. /* turn led off, when no commands are in the driver */
  1236. HOSTDATA(shpnt)->commands--;
  1237. if (!HOSTDATA(shpnt)->commands)
  1238. SETPORT(PORTA, 0); /* turn led off */
  1239. if (!(aha152x_priv(ptr)->phase & resetting)) {
  1240. kfree(ptr->host_scribble);
  1241. ptr->host_scribble=NULL;
  1242. }
  1243. DO_UNLOCK(flags);
  1244. aha152x_scsi_done(ptr);
  1245. DO_LOCK(flags);
  1246. }
  1247. DONE_SC=NULL;
  1248. #if defined(AHA152X_STAT)
  1249. } else {
  1250. HOSTDATA(shpnt)->busfree_without_done_command++;
  1251. #endif
  1252. }
  1253. if(ISSUE_SC)
  1254. CURRENT_SC = remove_first_SC(&ISSUE_SC);
  1255. DO_UNLOCK(flags);
  1256. if(CURRENT_SC) {
  1257. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1258. #if defined(AHA152X_STAT)
  1259. action++;
  1260. #endif
  1261. acp->phase |= selecting;
  1262. /* clear selection timeout */
  1263. SETPORT(SSTAT1, SELTO);
  1264. SETPORT(SCSIID, (shpnt->this_id << OID_) | CURRENT_SC->device->id);
  1265. SETPORT(SXFRCTL1, (PARITY ? ENSPCHK : 0 ) | ENSTIMER);
  1266. SETPORT(SCSISEQ, ENSELO | ENAUTOATNO | (DISCONNECTED_SC ? ENRESELI : 0));
  1267. } else {
  1268. #if defined(AHA152X_STAT)
  1269. HOSTDATA(shpnt)->busfree_without_new_command++;
  1270. #endif
  1271. SETPORT(SCSISEQ, DISCONNECTED_SC ? ENRESELI : 0);
  1272. }
  1273. #if defined(AHA152X_STAT)
  1274. if(!action)
  1275. HOSTDATA(shpnt)->busfree_without_any_action++;
  1276. #endif
  1277. }
  1278. /*
  1279. * Selection done (OUT)
  1280. * - queue IDENTIFY message and SDTR to selected target for message out
  1281. * (ATN asserted automagically via ENAUTOATNO in busfree())
  1282. */
  1283. static void seldo_run(struct Scsi_Host *shpnt)
  1284. {
  1285. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1286. SETPORT(SCSISIG, 0);
  1287. SETPORT(SSTAT1, CLRBUSFREE);
  1288. SETPORT(SSTAT1, CLRPHASECHG);
  1289. acp->phase &= ~(selecting | not_issued);
  1290. SETPORT(SCSISEQ, 0);
  1291. if (TESTLO(SSTAT0, SELDO)) {
  1292. scmd_printk(KERN_ERR, CURRENT_SC,
  1293. "aha152x: passing bus free condition\n");
  1294. done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
  1295. return;
  1296. }
  1297. SETPORT(SSTAT0, CLRSELDO);
  1298. ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
  1299. if (acp->phase & aborting) {
  1300. ADDMSGO(ABORT);
  1301. } else if (acp->phase & resetting) {
  1302. ADDMSGO(BUS_DEVICE_RESET);
  1303. } else if (SYNCNEG==0 && SYNCHRONOUS) {
  1304. acp->phase |= syncneg;
  1305. MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
  1306. SYNCNEG=1; /* negotiation in progress */
  1307. }
  1308. SETRATE(SYNCRATE);
  1309. }
  1310. /*
  1311. * Selection timeout
  1312. * - return command to mid-level with failure cause
  1313. *
  1314. */
  1315. static void selto_run(struct Scsi_Host *shpnt)
  1316. {
  1317. struct aha152x_cmd_priv *acp;
  1318. SETPORT(SCSISEQ, 0);
  1319. SETPORT(SSTAT1, CLRSELTIMO);
  1320. if (!CURRENT_SC)
  1321. return;
  1322. acp = aha152x_priv(CURRENT_SC);
  1323. acp->phase &= ~selecting;
  1324. if (acp->phase & aborted)
  1325. done(shpnt, SAM_STAT_GOOD, DID_ABORT);
  1326. else if (TESTLO(SSTAT0, SELINGO))
  1327. done(shpnt, SAM_STAT_GOOD, DID_BUS_BUSY);
  1328. else
  1329. /* ARBITRATION won, but SELECTION failed */
  1330. done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
  1331. }
  1332. /*
  1333. * Selection in done
  1334. * - put current command back to issue queue
  1335. * (reconnection of a disconnected nexus instead
  1336. * of successful selection out)
  1337. *
  1338. */
  1339. static void seldi_run(struct Scsi_Host *shpnt)
  1340. {
  1341. int selid;
  1342. int target;
  1343. unsigned long flags;
  1344. SETPORT(SCSISIG, 0);
  1345. SETPORT(SSTAT0, CLRSELDI);
  1346. SETPORT(SSTAT1, CLRBUSFREE);
  1347. SETPORT(SSTAT1, CLRPHASECHG);
  1348. if(CURRENT_SC) {
  1349. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1350. if (!(acp->phase & not_issued))
  1351. scmd_printk(KERN_ERR, CURRENT_SC,
  1352. "command should not have been issued yet\n");
  1353. DO_LOCK(flags);
  1354. append_SC(&ISSUE_SC, CURRENT_SC);
  1355. DO_UNLOCK(flags);
  1356. CURRENT_SC = NULL;
  1357. }
  1358. if (!DISCONNECTED_SC)
  1359. return;
  1360. RECONN_TARGET=-1;
  1361. selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
  1362. if (selid==0) {
  1363. shost_printk(KERN_INFO, shpnt,
  1364. "target id unknown (%02x)\n", selid);
  1365. return;
  1366. }
  1367. for(target=7; !(selid & (1 << target)); target--)
  1368. ;
  1369. if(selid & ~(1 << target)) {
  1370. shost_printk(KERN_INFO, shpnt,
  1371. "multiple targets reconnected (%02x)\n", selid);
  1372. }
  1373. SETPORT(SCSIID, (shpnt->this_id << OID_) | target);
  1374. SETPORT(SCSISEQ, 0);
  1375. SETRATE(HOSTDATA(shpnt)->syncrate[target]);
  1376. RECONN_TARGET=target;
  1377. }
  1378. /*
  1379. * message in phase
  1380. * - handle initial message after reconnection to identify
  1381. * reconnecting nexus
  1382. * - queue command on DISCONNECTED_SC on DISCONNECT message
  1383. * - set completed flag on COMMAND COMPLETE
  1384. * (other completition code moved to busfree_run)
  1385. * - handle response to SDTR
  1386. * - clear synchronous transfer agreements on BUS RESET
  1387. *
  1388. * FIXME: what about SAVE POINTERS, RESTORE POINTERS?
  1389. *
  1390. */
  1391. static void msgi_run(struct Scsi_Host *shpnt)
  1392. {
  1393. for(;;) {
  1394. struct aha152x_cmd_priv *acp;
  1395. int sstat1 = GETPORT(SSTAT1);
  1396. if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
  1397. return;
  1398. if (TESTLO(SSTAT0, SPIORDY))
  1399. return;
  1400. ADDMSGI(GETPORT(SCSIDAT));
  1401. if(!CURRENT_SC) {
  1402. if(LASTSTATE!=seldi) {
  1403. shost_printk(KERN_ERR, shpnt,
  1404. "message in w/o current command"
  1405. " not after reselection\n");
  1406. }
  1407. /*
  1408. * Handle reselection
  1409. */
  1410. if(!(MSGI(0) & IDENTIFY_BASE)) {
  1411. shost_printk(KERN_ERR, shpnt,
  1412. "target didn't identify after reselection\n");
  1413. continue;
  1414. }
  1415. CURRENT_SC = remove_lun_SC(&DISCONNECTED_SC, RECONN_TARGET, MSGI(0) & 0x3f);
  1416. if (!CURRENT_SC) {
  1417. show_queues(shpnt);
  1418. shost_printk(KERN_ERR, shpnt,
  1419. "no disconnected command"
  1420. " for target %d/%d\n",
  1421. RECONN_TARGET, MSGI(0) & 0x3f);
  1422. continue;
  1423. }
  1424. acp = aha152x_priv(CURRENT_SC);
  1425. acp->message = MSGI(0);
  1426. acp->phase &= ~disconnected;
  1427. MSGILEN=0;
  1428. /* next message if any */
  1429. continue;
  1430. }
  1431. acp = aha152x_priv(CURRENT_SC);
  1432. acp->message = MSGI(0);
  1433. switch (MSGI(0)) {
  1434. case DISCONNECT:
  1435. if (!RECONNECT)
  1436. scmd_printk(KERN_WARNING, CURRENT_SC,
  1437. "target was not allowed to disconnect\n");
  1438. acp->phase |= disconnected;
  1439. break;
  1440. case COMMAND_COMPLETE:
  1441. acp->phase |= completed;
  1442. break;
  1443. case MESSAGE_REJECT:
  1444. if (SYNCNEG==1) {
  1445. scmd_printk(KERN_INFO, CURRENT_SC,
  1446. "Synchronous Data Transfer Request"
  1447. " was rejected\n");
  1448. SYNCNEG=2; /* negotiation completed */
  1449. } else
  1450. scmd_printk(KERN_INFO, CURRENT_SC,
  1451. "inbound message (MESSAGE REJECT)\n");
  1452. break;
  1453. case SAVE_POINTERS:
  1454. break;
  1455. case RESTORE_POINTERS:
  1456. break;
  1457. case EXTENDED_MESSAGE:
  1458. if(MSGILEN<2 || MSGILEN<MSGI(1)+2) {
  1459. /* not yet completed */
  1460. continue;
  1461. }
  1462. switch (MSGI(2)) {
  1463. case EXTENDED_SDTR:
  1464. {
  1465. long ticks;
  1466. if (MSGI(1) != 3) {
  1467. scmd_printk(KERN_ERR, CURRENT_SC,
  1468. "SDTR message length!=3\n");
  1469. break;
  1470. }
  1471. if (!HOSTDATA(shpnt)->synchronous)
  1472. break;
  1473. printk(INFO_LEAD, CMDINFO(CURRENT_SC));
  1474. spi_print_msg(&MSGI(0));
  1475. printk("\n");
  1476. ticks = (MSGI(3) * 4 + 49) / 50;
  1477. if (syncneg) {
  1478. /* negotiation in progress */
  1479. if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
  1480. ADDMSGO(MESSAGE_REJECT);
  1481. scmd_printk(KERN_INFO,
  1482. CURRENT_SC,
  1483. "received Synchronous Data Transfer Request invalid - rejected\n");
  1484. break;
  1485. }
  1486. SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
  1487. } else if (ticks <= 9 && MSGI(4) >= 1) {
  1488. ADDMSGO(EXTENDED_MESSAGE);
  1489. ADDMSGO(3);
  1490. ADDMSGO(EXTENDED_SDTR);
  1491. if (ticks < 4) {
  1492. ticks = 4;
  1493. ADDMSGO(50);
  1494. } else
  1495. ADDMSGO(MSGI(3));
  1496. if (MSGI(4) > 8)
  1497. MSGI(4) = 8;
  1498. ADDMSGO(MSGI(4));
  1499. SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
  1500. } else {
  1501. /* requested SDTR is too slow, do it asynchronously */
  1502. scmd_printk(KERN_INFO,
  1503. CURRENT_SC,
  1504. "Synchronous Data Transfer Request too slow - Rejecting\n");
  1505. ADDMSGO(MESSAGE_REJECT);
  1506. }
  1507. /* negotiation completed */
  1508. SYNCNEG=2;
  1509. SETRATE(SYNCRATE);
  1510. }
  1511. break;
  1512. case BUS_DEVICE_RESET:
  1513. {
  1514. int i;
  1515. for(i=0; i<8; i++) {
  1516. HOSTDATA(shpnt)->syncrate[i]=0;
  1517. HOSTDATA(shpnt)->syncneg[i]=0;
  1518. }
  1519. }
  1520. break;
  1521. case EXTENDED_MODIFY_DATA_POINTER:
  1522. case EXTENDED_EXTENDED_IDENTIFY:
  1523. case EXTENDED_WDTR:
  1524. default:
  1525. ADDMSGO(MESSAGE_REJECT);
  1526. break;
  1527. }
  1528. break;
  1529. }
  1530. MSGILEN=0;
  1531. }
  1532. }
  1533. static void msgi_end(struct Scsi_Host *shpnt)
  1534. {
  1535. if(MSGILEN>0)
  1536. scmd_printk(KERN_WARNING, CURRENT_SC,
  1537. "target left before message completed (%d)\n",
  1538. MSGILEN);
  1539. if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE))
  1540. SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
  1541. }
  1542. /*
  1543. * message out phase
  1544. *
  1545. */
  1546. static void msgo_init(struct Scsi_Host *shpnt)
  1547. {
  1548. if(MSGOLEN==0) {
  1549. if ((aha152x_priv(CURRENT_SC)->phase & syncneg) &&
  1550. SYNCNEG == 2 && SYNCRATE == 0) {
  1551. ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
  1552. } else {
  1553. scmd_printk(KERN_INFO, CURRENT_SC,
  1554. "unexpected MESSAGE OUT phase; rejecting\n");
  1555. ADDMSGO(MESSAGE_REJECT);
  1556. }
  1557. }
  1558. }
  1559. /*
  1560. * message out phase
  1561. *
  1562. */
  1563. static void msgo_run(struct Scsi_Host *shpnt)
  1564. {
  1565. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1566. while(MSGO_I<MSGOLEN) {
  1567. if (TESTLO(SSTAT0, SPIORDY))
  1568. return;
  1569. if (MSGO_I==MSGOLEN-1) {
  1570. /* Leave MESSAGE OUT after transfer */
  1571. SETPORT(SSTAT1, CLRATNO);
  1572. }
  1573. if (MSGO(MSGO_I) & IDENTIFY_BASE)
  1574. acp->phase |= identified;
  1575. if (MSGO(MSGO_I)==ABORT)
  1576. acp->phase |= aborted;
  1577. if (MSGO(MSGO_I)==BUS_DEVICE_RESET)
  1578. acp->phase |= resetted;
  1579. SETPORT(SCSIDAT, MSGO(MSGO_I++));
  1580. }
  1581. }
  1582. static void msgo_end(struct Scsi_Host *shpnt)
  1583. {
  1584. if(MSGO_I<MSGOLEN) {
  1585. scmd_printk(KERN_ERR, CURRENT_SC,
  1586. "message sent incompletely (%d/%d)\n",
  1587. MSGO_I, MSGOLEN);
  1588. if(SYNCNEG==1) {
  1589. scmd_printk(KERN_INFO, CURRENT_SC,
  1590. "Synchronous Data Transfer Request was rejected\n");
  1591. SYNCNEG=2;
  1592. }
  1593. }
  1594. MSGO_I = 0;
  1595. MSGOLEN = 0;
  1596. }
  1597. /*
  1598. * command phase
  1599. *
  1600. */
  1601. static void cmd_init(struct Scsi_Host *shpnt)
  1602. {
  1603. if (aha152x_priv(CURRENT_SC)->sent_command) {
  1604. scmd_printk(KERN_ERR, CURRENT_SC,
  1605. "command already sent\n");
  1606. done(shpnt, SAM_STAT_GOOD, DID_ERROR);
  1607. return;
  1608. }
  1609. CMD_I=0;
  1610. }
  1611. /*
  1612. * command phase
  1613. *
  1614. */
  1615. static void cmd_run(struct Scsi_Host *shpnt)
  1616. {
  1617. while(CMD_I<CURRENT_SC->cmd_len) {
  1618. if (TESTLO(SSTAT0, SPIORDY))
  1619. return;
  1620. SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
  1621. }
  1622. }
  1623. static void cmd_end(struct Scsi_Host *shpnt)
  1624. {
  1625. if(CMD_I<CURRENT_SC->cmd_len)
  1626. scmd_printk(KERN_ERR, CURRENT_SC,
  1627. "command sent incompletely (%d/%d)\n",
  1628. CMD_I, CURRENT_SC->cmd_len);
  1629. else
  1630. aha152x_priv(CURRENT_SC)->sent_command++;
  1631. }
  1632. /*
  1633. * status phase
  1634. *
  1635. */
  1636. static void status_run(struct Scsi_Host *shpnt)
  1637. {
  1638. if (TESTLO(SSTAT0, SPIORDY))
  1639. return;
  1640. aha152x_priv(CURRENT_SC)->status = GETPORT(SCSIDAT);
  1641. }
  1642. /*
  1643. * data in phase
  1644. *
  1645. */
  1646. static void datai_init(struct Scsi_Host *shpnt)
  1647. {
  1648. SETPORT(DMACNTRL0, RSTFIFO);
  1649. SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
  1650. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1651. SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
  1652. SETPORT(SIMODE0, 0);
  1653. SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
  1654. DATA_LEN=0;
  1655. }
  1656. static void datai_run(struct Scsi_Host *shpnt)
  1657. {
  1658. struct aha152x_cmd_priv *acp;
  1659. unsigned long the_time;
  1660. int fifodata, data_count;
  1661. /*
  1662. * loop while the phase persists or the fifos are not empty
  1663. *
  1664. */
  1665. while(TESTLO(DMASTAT, INTSTAT) || TESTLO(DMASTAT, DFIFOEMP) || TESTLO(SSTAT2, SEMPTY)) {
  1666. /* FIXME: maybe this should be done by setting up
  1667. * STCNT to trigger ENSWRAP interrupt, instead of
  1668. * polling for DFIFOFULL
  1669. */
  1670. the_time=jiffies + 100*HZ;
  1671. while(TESTLO(DMASTAT, DFIFOFULL|INTSTAT) && time_before(jiffies,the_time))
  1672. barrier();
  1673. if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
  1674. scmd_printk(KERN_ERR, CURRENT_SC, "datai timeout\n");
  1675. break;
  1676. }
  1677. if(TESTHI(DMASTAT, DFIFOFULL)) {
  1678. fifodata = 128;
  1679. } else {
  1680. the_time=jiffies + 100*HZ;
  1681. while(TESTLO(SSTAT2, SEMPTY) && time_before(jiffies,the_time))
  1682. barrier();
  1683. if(TESTLO(SSTAT2, SEMPTY)) {
  1684. scmd_printk(KERN_ERR, CURRENT_SC,
  1685. "datai sempty timeout");
  1686. break;
  1687. }
  1688. fifodata = GETPORT(FIFOSTAT);
  1689. }
  1690. acp = aha152x_priv(CURRENT_SC);
  1691. if (acp->this_residual > 0) {
  1692. while (fifodata > 0 && acp->this_residual > 0) {
  1693. data_count = fifodata > acp->this_residual ?
  1694. acp->this_residual : fifodata;
  1695. fifodata -= data_count;
  1696. if (data_count & 1) {
  1697. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1698. *acp->ptr++ = GETPORT(DATAPORT);
  1699. acp->this_residual--;
  1700. DATA_LEN++;
  1701. SETPORT(DMACNTRL0, ENDMA);
  1702. }
  1703. if (data_count > 1) {
  1704. data_count >>= 1;
  1705. insw(DATAPORT, acp->ptr, data_count);
  1706. acp->ptr += 2 * data_count;
  1707. acp->this_residual -= 2 * data_count;
  1708. DATA_LEN += 2 * data_count;
  1709. }
  1710. if (acp->this_residual == 0 &&
  1711. !sg_is_last(acp->buffer)) {
  1712. /* advance to next buffer */
  1713. acp->buffer = sg_next(acp->buffer);
  1714. acp->ptr = SG_ADDRESS(acp->buffer);
  1715. acp->this_residual = acp->buffer->length;
  1716. }
  1717. }
  1718. } else if (fifodata > 0) {
  1719. scmd_printk(KERN_ERR, CURRENT_SC,
  1720. "no buffers left for %d(%d) bytes"
  1721. " (data overrun!?)\n",
  1722. fifodata, GETPORT(FIFOSTAT));
  1723. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1724. while(fifodata>0) {
  1725. GETPORT(DATAPORT);
  1726. fifodata--;
  1727. DATA_LEN++;
  1728. }
  1729. SETPORT(DMACNTRL0, ENDMA|_8BIT);
  1730. }
  1731. }
  1732. if(TESTLO(DMASTAT, INTSTAT) ||
  1733. TESTLO(DMASTAT, DFIFOEMP) ||
  1734. TESTLO(SSTAT2, SEMPTY) ||
  1735. GETPORT(FIFOSTAT)>0) {
  1736. /*
  1737. * something went wrong, if there's something left in the fifos
  1738. * or the phase didn't change
  1739. */
  1740. scmd_printk(KERN_ERR, CURRENT_SC,
  1741. "fifos should be empty and phase should have changed\n");
  1742. }
  1743. if(DATA_LEN!=GETSTCNT()) {
  1744. scmd_printk(KERN_ERR, CURRENT_SC,
  1745. "manual transfer count differs from automatic "
  1746. "(count=%d;stcnt=%d;diff=%d;fifostat=%d)",
  1747. DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN,
  1748. GETPORT(FIFOSTAT));
  1749. mdelay(10000);
  1750. }
  1751. }
  1752. static void datai_end(struct Scsi_Host *shpnt)
  1753. {
  1754. CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
  1755. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1756. SETPORT(DMACNTRL0, 0);
  1757. }
  1758. /*
  1759. * data out phase
  1760. *
  1761. */
  1762. static void datao_init(struct Scsi_Host *shpnt)
  1763. {
  1764. SETPORT(DMACNTRL0, WRITE_READ | RSTFIFO);
  1765. SETPORT(DMACNTRL0, WRITE_READ | ENDMA);
  1766. SETPORT(SXFRCTL0, CH1|CLRSTCNT);
  1767. SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN);
  1768. SETPORT(SIMODE0, 0);
  1769. SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
  1770. DATA_LEN = scsi_get_resid(CURRENT_SC);
  1771. }
  1772. static void datao_run(struct Scsi_Host *shpnt)
  1773. {
  1774. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1775. unsigned long the_time;
  1776. int data_count;
  1777. /* until phase changes or all data sent */
  1778. while (TESTLO(DMASTAT, INTSTAT) && acp->this_residual > 0) {
  1779. data_count = 128;
  1780. if (data_count > acp->this_residual)
  1781. data_count = acp->this_residual;
  1782. if(TESTLO(DMASTAT, DFIFOEMP)) {
  1783. scmd_printk(KERN_ERR, CURRENT_SC,
  1784. "datao fifo not empty (%d)",
  1785. GETPORT(FIFOSTAT));
  1786. break;
  1787. }
  1788. if(data_count & 1) {
  1789. SETPORT(DMACNTRL0,WRITE_READ|ENDMA|_8BIT);
  1790. SETPORT(DATAPORT, *acp->ptr++);
  1791. acp->this_residual--;
  1792. CMD_INC_RESID(CURRENT_SC, -1);
  1793. SETPORT(DMACNTRL0,WRITE_READ|ENDMA);
  1794. }
  1795. if(data_count > 1) {
  1796. data_count >>= 1;
  1797. outsw(DATAPORT, acp->ptr, data_count);
  1798. acp->ptr += 2 * data_count;
  1799. acp->this_residual -= 2 * data_count;
  1800. CMD_INC_RESID(CURRENT_SC, -2 * data_count);
  1801. }
  1802. if (acp->this_residual == 0 && !sg_is_last(acp->buffer)) {
  1803. /* advance to next buffer */
  1804. acp->buffer = sg_next(acp->buffer);
  1805. acp->ptr = SG_ADDRESS(acp->buffer);
  1806. acp->this_residual = acp->buffer->length;
  1807. }
  1808. the_time=jiffies + 100*HZ;
  1809. while(TESTLO(DMASTAT, DFIFOEMP|INTSTAT) && time_before(jiffies,the_time))
  1810. barrier();
  1811. if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
  1812. scmd_printk(KERN_ERR, CURRENT_SC, "dataout timeout\n");
  1813. break;
  1814. }
  1815. }
  1816. }
  1817. static void datao_end(struct Scsi_Host *shpnt)
  1818. {
  1819. struct aha152x_cmd_priv *acp = aha152x_priv(CURRENT_SC);
  1820. if(TESTLO(DMASTAT, DFIFOEMP)) {
  1821. u32 datao_cnt = GETSTCNT();
  1822. int datao_out = DATA_LEN - scsi_get_resid(CURRENT_SC);
  1823. int done;
  1824. struct scatterlist *sg = scsi_sglist(CURRENT_SC);
  1825. CMD_INC_RESID(CURRENT_SC, datao_out - datao_cnt);
  1826. done = scsi_bufflen(CURRENT_SC) - scsi_get_resid(CURRENT_SC);
  1827. /* Locate the first SG entry not yet sent */
  1828. while (done > 0 && !sg_is_last(sg)) {
  1829. if (done < sg->length)
  1830. break;
  1831. done -= sg->length;
  1832. sg = sg_next(sg);
  1833. }
  1834. acp->buffer = sg;
  1835. acp->ptr = SG_ADDRESS(acp->buffer) + done;
  1836. acp->this_residual = acp->buffer->length - done;
  1837. }
  1838. SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
  1839. SETPORT(SXFRCTL0, CH1);
  1840. SETPORT(DMACNTRL0, 0);
  1841. }
  1842. /*
  1843. * figure out what state we're in
  1844. *
  1845. */
  1846. static int update_state(struct Scsi_Host *shpnt)
  1847. {
  1848. int dataphase=0;
  1849. unsigned int stat0 = GETPORT(SSTAT0);
  1850. unsigned int stat1 = GETPORT(SSTAT1);
  1851. PREVSTATE = STATE;
  1852. STATE=unknown;
  1853. if(stat1 & SCSIRSTI) {
  1854. STATE=rsti;
  1855. SETPORT(SCSISEQ,0);
  1856. SETPORT(SSTAT1,SCSIRSTI);
  1857. } else if (stat0 & SELDI && PREVSTATE == busfree) {
  1858. STATE=seldi;
  1859. } else if (stat0 & SELDO && CURRENT_SC &&
  1860. (aha152x_priv(CURRENT_SC)->phase & selecting)) {
  1861. STATE=seldo;
  1862. } else if(stat1 & SELTO) {
  1863. STATE=selto;
  1864. } else if(stat1 & BUSFREE) {
  1865. STATE=busfree;
  1866. SETPORT(SSTAT1,BUSFREE);
  1867. } else if(stat1 & SCSIPERR) {
  1868. STATE=parerr;
  1869. SETPORT(SSTAT1,SCSIPERR);
  1870. } else if(stat1 & REQINIT) {
  1871. switch(GETPORT(SCSISIG) & P_MASK) {
  1872. case P_MSGI: STATE=msgi; break;
  1873. case P_MSGO: STATE=msgo; break;
  1874. case P_DATAO: STATE=datao; break;
  1875. case P_DATAI: STATE=datai; break;
  1876. case P_STATUS: STATE=status; break;
  1877. case P_CMD: STATE=cmd; break;
  1878. }
  1879. dataphase=1;
  1880. }
  1881. if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
  1882. scmd_printk(KERN_INFO, CURRENT_SC, "reselection missed?");
  1883. }
  1884. if(STATE!=PREVSTATE) {
  1885. LASTSTATE=PREVSTATE;
  1886. }
  1887. return dataphase;
  1888. }
  1889. /*
  1890. * handle parity error
  1891. *
  1892. * FIXME: in which phase?
  1893. *
  1894. */
  1895. static void parerr_run(struct Scsi_Host *shpnt)
  1896. {
  1897. scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
  1898. done(shpnt, SAM_STAT_GOOD, DID_PARITY);
  1899. }
  1900. /*
  1901. * handle reset in
  1902. *
  1903. */
  1904. static void rsti_run(struct Scsi_Host *shpnt)
  1905. {
  1906. struct scsi_cmnd *ptr;
  1907. shost_printk(KERN_NOTICE, shpnt, "scsi reset in\n");
  1908. ptr=DISCONNECTED_SC;
  1909. while(ptr) {
  1910. struct scsi_cmnd *next = SCNEXT(ptr);
  1911. if (!ptr->device->soft_reset) {
  1912. remove_SC(&DISCONNECTED_SC, ptr);
  1913. kfree(ptr->host_scribble);
  1914. ptr->host_scribble=NULL;
  1915. set_host_byte(ptr, DID_RESET);
  1916. aha152x_scsi_done(ptr);
  1917. }
  1918. ptr = next;
  1919. }
  1920. if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
  1921. done(shpnt, SAM_STAT_GOOD, DID_RESET);
  1922. }
  1923. /*
  1924. * bottom-half handler
  1925. *
  1926. */
  1927. static void is_complete(struct Scsi_Host *shpnt)
  1928. {
  1929. int dataphase;
  1930. unsigned long flags;
  1931. int pending;
  1932. if(!shpnt)
  1933. return;
  1934. DO_LOCK(flags);
  1935. if( HOSTDATA(shpnt)->service==0 ) {
  1936. DO_UNLOCK(flags);
  1937. return;
  1938. }
  1939. HOSTDATA(shpnt)->service = 0;
  1940. if(HOSTDATA(shpnt)->in_intr) {
  1941. DO_UNLOCK(flags);
  1942. /* aha152x_error never returns.. */
  1943. aha152x_error(shpnt, "bottom-half already running!?");
  1944. }
  1945. HOSTDATA(shpnt)->in_intr++;
  1946. /*
  1947. * loop while there are interrupt conditions pending
  1948. *
  1949. */
  1950. do {
  1951. unsigned long start = jiffies;
  1952. DO_UNLOCK(flags);
  1953. dataphase=update_state(shpnt);
  1954. /*
  1955. * end previous state
  1956. *
  1957. */
  1958. if(PREVSTATE!=STATE && states[PREVSTATE].end)
  1959. states[PREVSTATE].end(shpnt);
  1960. /*
  1961. * disable SPIO mode if previous phase used it
  1962. * and this one doesn't
  1963. *
  1964. */
  1965. if(states[PREVSTATE].spio && !states[STATE].spio) {
  1966. SETPORT(SXFRCTL0, CH1);
  1967. SETPORT(DMACNTRL0, 0);
  1968. if(CURRENT_SC)
  1969. aha152x_priv(CURRENT_SC)->phase &= ~spiordy;
  1970. }
  1971. /*
  1972. * accept current dataphase phase
  1973. *
  1974. */
  1975. if(dataphase) {
  1976. SETPORT(SSTAT0, REQINIT);
  1977. SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
  1978. SETPORT(SSTAT1, PHASECHG);
  1979. }
  1980. /*
  1981. * enable SPIO mode if previous didn't use it
  1982. * and this one does
  1983. *
  1984. */
  1985. if(!states[PREVSTATE].spio && states[STATE].spio) {
  1986. SETPORT(DMACNTRL0, 0);
  1987. SETPORT(SXFRCTL0, CH1|SPIOEN);
  1988. if(CURRENT_SC)
  1989. aha152x_priv(CURRENT_SC)->phase |= spiordy;
  1990. }
  1991. /*
  1992. * initialize for new state
  1993. *
  1994. */
  1995. if(PREVSTATE!=STATE && states[STATE].init)
  1996. states[STATE].init(shpnt);
  1997. /*
  1998. * handle current state
  1999. *
  2000. */
  2001. if(states[STATE].run)
  2002. states[STATE].run(shpnt);
  2003. else
  2004. scmd_printk(KERN_ERR, CURRENT_SC,
  2005. "unexpected state (%x)\n", STATE);
  2006. /*
  2007. * setup controller to interrupt on
  2008. * the next expected condition and
  2009. * loop if it's already there
  2010. *
  2011. */
  2012. DO_LOCK(flags);
  2013. pending=setup_expected_interrupts(shpnt);
  2014. #if defined(AHA152X_STAT)
  2015. HOSTDATA(shpnt)->count[STATE]++;
  2016. if(PREVSTATE!=STATE)
  2017. HOSTDATA(shpnt)->count_trans[STATE]++;
  2018. HOSTDATA(shpnt)->time[STATE] += jiffies-start;
  2019. #endif
  2020. } while(pending);
  2021. /*
  2022. * enable interrupts and leave bottom-half
  2023. *
  2024. */
  2025. HOSTDATA(shpnt)->in_intr--;
  2026. SETBITS(DMACNTRL0, INTEN);
  2027. DO_UNLOCK(flags);
  2028. }
  2029. /*
  2030. * Dump the current driver status and panic
  2031. */
  2032. static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
  2033. {
  2034. shost_printk(KERN_EMERG, shpnt, "%s\n", msg);
  2035. show_queues(shpnt);
  2036. panic("aha152x panic\n");
  2037. }
  2038. /*
  2039. * display enabled interrupts
  2040. */
  2041. static void disp_enintr(struct Scsi_Host *shpnt)
  2042. {
  2043. int s0, s1;
  2044. s0 = GETPORT(SIMODE0);
  2045. s1 = GETPORT(SIMODE1);
  2046. shost_printk(KERN_DEBUG, shpnt,
  2047. "enabled interrupts (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
  2048. (s0 & ENSELDO) ? "ENSELDO " : "",
  2049. (s0 & ENSELDI) ? "ENSELDI " : "",
  2050. (s0 & ENSELINGO) ? "ENSELINGO " : "",
  2051. (s0 & ENSWRAP) ? "ENSWRAP " : "",
  2052. (s0 & ENSDONE) ? "ENSDONE " : "",
  2053. (s0 & ENSPIORDY) ? "ENSPIORDY " : "",
  2054. (s0 & ENDMADONE) ? "ENDMADONE " : "",
  2055. (s1 & ENSELTIMO) ? "ENSELTIMO " : "",
  2056. (s1 & ENATNTARG) ? "ENATNTARG " : "",
  2057. (s1 & ENPHASEMIS) ? "ENPHASEMIS " : "",
  2058. (s1 & ENBUSFREE) ? "ENBUSFREE " : "",
  2059. (s1 & ENSCSIPERR) ? "ENSCSIPERR " : "",
  2060. (s1 & ENPHASECHG) ? "ENPHASECHG " : "",
  2061. (s1 & ENREQINIT) ? "ENREQINIT " : "");
  2062. }
  2063. /*
  2064. * Show the command data of a command
  2065. */
  2066. static void show_command(struct scsi_cmnd *ptr)
  2067. {
  2068. const int phase = aha152x_priv(ptr)->phase;
  2069. scsi_print_command(ptr);
  2070. scmd_printk(KERN_DEBUG, ptr,
  2071. "request_bufflen=%d; resid=%d; "
  2072. "phase |%s%s%s%s%s%s%s%s%s; next=0x%p",
  2073. scsi_bufflen(ptr), scsi_get_resid(ptr),
  2074. phase & not_issued ? "not issued|" : "",
  2075. phase & selecting ? "selecting|" : "",
  2076. phase & identified ? "identified|" : "",
  2077. phase & disconnected ? "disconnected|" : "",
  2078. phase & completed ? "completed|" : "",
  2079. phase & spiordy ? "spiordy|" : "",
  2080. phase & syncneg ? "syncneg|" : "",
  2081. phase & aborted ? "aborted|" : "",
  2082. phase & resetted ? "resetted|" : "",
  2083. SCDATA(ptr) ? SCNEXT(ptr) : NULL);
  2084. }
  2085. /*
  2086. * Dump the queued data
  2087. */
  2088. static void show_queues(struct Scsi_Host *shpnt)
  2089. {
  2090. struct scsi_cmnd *ptr;
  2091. unsigned long flags;
  2092. DO_LOCK(flags);
  2093. printk(KERN_DEBUG "\nqueue status:\nissue_SC:\n");
  2094. for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
  2095. show_command(ptr);
  2096. DO_UNLOCK(flags);
  2097. printk(KERN_DEBUG "current_SC:\n");
  2098. if (CURRENT_SC)
  2099. show_command(CURRENT_SC);
  2100. else
  2101. printk(KERN_DEBUG "none\n");
  2102. printk(KERN_DEBUG "disconnected_SC:\n");
  2103. for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
  2104. show_command(ptr);
  2105. disp_enintr(shpnt);
  2106. }
  2107. static void get_command(struct seq_file *m, struct scsi_cmnd * ptr)
  2108. {
  2109. struct aha152x_cmd_priv *acp = aha152x_priv(ptr);
  2110. const int phase = acp->phase;
  2111. int i;
  2112. seq_printf(m, "%p: target=%d; lun=%d; cmnd=( ",
  2113. ptr, ptr->device->id, (u8)ptr->device->lun);
  2114. for (i = 0; i < COMMAND_SIZE(ptr->cmnd[0]); i++)
  2115. seq_printf(m, "0x%02x ", ptr->cmnd[i]);
  2116. seq_printf(m, "); resid=%d; residual=%d; buffers=%d; phase |",
  2117. scsi_get_resid(ptr), acp->this_residual,
  2118. sg_nents(acp->buffer) - 1);
  2119. if (phase & not_issued)
  2120. seq_puts(m, "not issued|");
  2121. if (phase & selecting)
  2122. seq_puts(m, "selecting|");
  2123. if (phase & disconnected)
  2124. seq_puts(m, "disconnected|");
  2125. if (phase & aborted)
  2126. seq_puts(m, "aborted|");
  2127. if (phase & identified)
  2128. seq_puts(m, "identified|");
  2129. if (phase & completed)
  2130. seq_puts(m, "completed|");
  2131. if (phase & spiordy)
  2132. seq_puts(m, "spiordy|");
  2133. if (phase & syncneg)
  2134. seq_puts(m, "syncneg|");
  2135. seq_printf(m, "; next=0x%p\n", SCNEXT(ptr));
  2136. }
  2137. static void get_ports(struct seq_file *m, struct Scsi_Host *shpnt)
  2138. {
  2139. int s;
  2140. seq_printf(m, "\n%s: %s(%s) ", CURRENT_SC ? "on bus" : "waiting", states[STATE].name, states[PREVSTATE].name);
  2141. s = GETPORT(SCSISEQ);
  2142. seq_puts(m, "SCSISEQ( ");
  2143. if (s & TEMODEO)
  2144. seq_puts(m, "TARGET MODE ");
  2145. if (s & ENSELO)
  2146. seq_puts(m, "SELO ");
  2147. if (s & ENSELI)
  2148. seq_puts(m, "SELI ");
  2149. if (s & ENRESELI)
  2150. seq_puts(m, "RESELI ");
  2151. if (s & ENAUTOATNO)
  2152. seq_puts(m, "AUTOATNO ");
  2153. if (s & ENAUTOATNI)
  2154. seq_puts(m, "AUTOATNI ");
  2155. if (s & ENAUTOATNP)
  2156. seq_puts(m, "AUTOATNP ");
  2157. if (s & SCSIRSTO)
  2158. seq_puts(m, "SCSIRSTO ");
  2159. seq_puts(m, ");");
  2160. seq_puts(m, " SCSISIG(");
  2161. s = GETPORT(SCSISIG);
  2162. switch (s & P_MASK) {
  2163. case P_DATAO:
  2164. seq_puts(m, "DATA OUT");
  2165. break;
  2166. case P_DATAI:
  2167. seq_puts(m, "DATA IN");
  2168. break;
  2169. case P_CMD:
  2170. seq_puts(m, "COMMAND");
  2171. break;
  2172. case P_STATUS:
  2173. seq_puts(m, "STATUS");
  2174. break;
  2175. case P_MSGO:
  2176. seq_puts(m, "MESSAGE OUT");
  2177. break;
  2178. case P_MSGI:
  2179. seq_puts(m, "MESSAGE IN");
  2180. break;
  2181. default:
  2182. seq_puts(m, "*invalid*");
  2183. break;
  2184. }
  2185. seq_puts(m, "); ");
  2186. seq_printf(m, "INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
  2187. seq_puts(m, "SSTAT( ");
  2188. s = GETPORT(SSTAT0);
  2189. if (s & TARGET)
  2190. seq_puts(m, "TARGET ");
  2191. if (s & SELDO)
  2192. seq_puts(m, "SELDO ");
  2193. if (s & SELDI)
  2194. seq_puts(m, "SELDI ");
  2195. if (s & SELINGO)
  2196. seq_puts(m, "SELINGO ");
  2197. if (s & SWRAP)
  2198. seq_puts(m, "SWRAP ");
  2199. if (s & SDONE)
  2200. seq_puts(m, "SDONE ");
  2201. if (s & SPIORDY)
  2202. seq_puts(m, "SPIORDY ");
  2203. if (s & DMADONE)
  2204. seq_puts(m, "DMADONE ");
  2205. s = GETPORT(SSTAT1);
  2206. if (s & SELTO)
  2207. seq_puts(m, "SELTO ");
  2208. if (s & ATNTARG)
  2209. seq_puts(m, "ATNTARG ");
  2210. if (s & SCSIRSTI)
  2211. seq_puts(m, "SCSIRSTI ");
  2212. if (s & PHASEMIS)
  2213. seq_puts(m, "PHASEMIS ");
  2214. if (s & BUSFREE)
  2215. seq_puts(m, "BUSFREE ");
  2216. if (s & SCSIPERR)
  2217. seq_puts(m, "SCSIPERR ");
  2218. if (s & PHASECHG)
  2219. seq_puts(m, "PHASECHG ");
  2220. if (s & REQINIT)
  2221. seq_puts(m, "REQINIT ");
  2222. seq_puts(m, "); ");
  2223. seq_puts(m, "SSTAT( ");
  2224. s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
  2225. if (s & TARGET)
  2226. seq_puts(m, "TARGET ");
  2227. if (s & SELDO)
  2228. seq_puts(m, "SELDO ");
  2229. if (s & SELDI)
  2230. seq_puts(m, "SELDI ");
  2231. if (s & SELINGO)
  2232. seq_puts(m, "SELINGO ");
  2233. if (s & SWRAP)
  2234. seq_puts(m, "SWRAP ");
  2235. if (s & SDONE)
  2236. seq_puts(m, "SDONE ");
  2237. if (s & SPIORDY)
  2238. seq_puts(m, "SPIORDY ");
  2239. if (s & DMADONE)
  2240. seq_puts(m, "DMADONE ");
  2241. s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
  2242. if (s & SELTO)
  2243. seq_puts(m, "SELTO ");
  2244. if (s & ATNTARG)
  2245. seq_puts(m, "ATNTARG ");
  2246. if (s & SCSIRSTI)
  2247. seq_puts(m, "SCSIRSTI ");
  2248. if (s & PHASEMIS)
  2249. seq_puts(m, "PHASEMIS ");
  2250. if (s & BUSFREE)
  2251. seq_puts(m, "BUSFREE ");
  2252. if (s & SCSIPERR)
  2253. seq_puts(m, "SCSIPERR ");
  2254. if (s & PHASECHG)
  2255. seq_puts(m, "PHASECHG ");
  2256. if (s & REQINIT)
  2257. seq_puts(m, "REQINIT ");
  2258. seq_puts(m, "); ");
  2259. seq_puts(m, "SXFRCTL0( ");
  2260. s = GETPORT(SXFRCTL0);
  2261. if (s & SCSIEN)
  2262. seq_puts(m, "SCSIEN ");
  2263. if (s & DMAEN)
  2264. seq_puts(m, "DMAEN ");
  2265. if (s & CH1)
  2266. seq_puts(m, "CH1 ");
  2267. if (s & CLRSTCNT)
  2268. seq_puts(m, "CLRSTCNT ");
  2269. if (s & SPIOEN)
  2270. seq_puts(m, "SPIOEN ");
  2271. if (s & CLRCH1)
  2272. seq_puts(m, "CLRCH1 ");
  2273. seq_puts(m, "); ");
  2274. seq_puts(m, "SIGNAL( ");
  2275. s = GETPORT(SCSISIG);
  2276. if (s & SIG_ATNI)
  2277. seq_puts(m, "ATNI ");
  2278. if (s & SIG_SELI)
  2279. seq_puts(m, "SELI ");
  2280. if (s & SIG_BSYI)
  2281. seq_puts(m, "BSYI ");
  2282. if (s & SIG_REQI)
  2283. seq_puts(m, "REQI ");
  2284. if (s & SIG_ACKI)
  2285. seq_puts(m, "ACKI ");
  2286. seq_puts(m, "); ");
  2287. seq_printf(m, "SELID(%02x), ", GETPORT(SELID));
  2288. seq_printf(m, "STCNT(%d), ", GETSTCNT());
  2289. seq_puts(m, "SSTAT2( ");
  2290. s = GETPORT(SSTAT2);
  2291. if (s & SOFFSET)
  2292. seq_puts(m, "SOFFSET ");
  2293. if (s & SEMPTY)
  2294. seq_puts(m, "SEMPTY ");
  2295. if (s & SFULL)
  2296. seq_puts(m, "SFULL ");
  2297. seq_printf(m, "); SFCNT (%d); ", s & (SFULL | SFCNT));
  2298. s = GETPORT(SSTAT3);
  2299. seq_printf(m, "SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
  2300. seq_puts(m, "SSTAT4( ");
  2301. s = GETPORT(SSTAT4);
  2302. if (s & SYNCERR)
  2303. seq_puts(m, "SYNCERR ");
  2304. if (s & FWERR)
  2305. seq_puts(m, "FWERR ");
  2306. if (s & FRERR)
  2307. seq_puts(m, "FRERR ");
  2308. seq_puts(m, "); ");
  2309. seq_puts(m, "DMACNTRL0( ");
  2310. s = GETPORT(DMACNTRL0);
  2311. seq_printf(m, "%s ", s & _8BIT ? "8BIT" : "16BIT");
  2312. seq_printf(m, "%s ", s & DMA ? "DMA" : "PIO");
  2313. seq_printf(m, "%s ", s & WRITE_READ ? "WRITE" : "READ");
  2314. if (s & ENDMA)
  2315. seq_puts(m, "ENDMA ");
  2316. if (s & INTEN)
  2317. seq_puts(m, "INTEN ");
  2318. if (s & RSTFIFO)
  2319. seq_puts(m, "RSTFIFO ");
  2320. if (s & SWINT)
  2321. seq_puts(m, "SWINT ");
  2322. seq_puts(m, "); ");
  2323. seq_puts(m, "DMASTAT( ");
  2324. s = GETPORT(DMASTAT);
  2325. if (s & ATDONE)
  2326. seq_puts(m, "ATDONE ");
  2327. if (s & WORDRDY)
  2328. seq_puts(m, "WORDRDY ");
  2329. if (s & DFIFOFULL)
  2330. seq_puts(m, "DFIFOFULL ");
  2331. if (s & DFIFOEMP)
  2332. seq_puts(m, "DFIFOEMP ");
  2333. seq_puts(m, ")\n");
  2334. seq_puts(m, "enabled interrupts( ");
  2335. s = GETPORT(SIMODE0);
  2336. if (s & ENSELDO)
  2337. seq_puts(m, "ENSELDO ");
  2338. if (s & ENSELDI)
  2339. seq_puts(m, "ENSELDI ");
  2340. if (s & ENSELINGO)
  2341. seq_puts(m, "ENSELINGO ");
  2342. if (s & ENSWRAP)
  2343. seq_puts(m, "ENSWRAP ");
  2344. if (s & ENSDONE)
  2345. seq_puts(m, "ENSDONE ");
  2346. if (s & ENSPIORDY)
  2347. seq_puts(m, "ENSPIORDY ");
  2348. if (s & ENDMADONE)
  2349. seq_puts(m, "ENDMADONE ");
  2350. s = GETPORT(SIMODE1);
  2351. if (s & ENSELTIMO)
  2352. seq_puts(m, "ENSELTIMO ");
  2353. if (s & ENATNTARG)
  2354. seq_puts(m, "ENATNTARG ");
  2355. if (s & ENPHASEMIS)
  2356. seq_puts(m, "ENPHASEMIS ");
  2357. if (s & ENBUSFREE)
  2358. seq_puts(m, "ENBUSFREE ");
  2359. if (s & ENSCSIPERR)
  2360. seq_puts(m, "ENSCSIPERR ");
  2361. if (s & ENPHASECHG)
  2362. seq_puts(m, "ENPHASECHG ");
  2363. if (s & ENREQINIT)
  2364. seq_puts(m, "ENREQINIT ");
  2365. seq_puts(m, ")\n");
  2366. }
  2367. static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
  2368. {
  2369. if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
  2370. return -EINVAL;
  2371. #if defined(AHA152X_STAT)
  2372. if(length>13 && strncmp("reset", buffer+8, 5)==0) {
  2373. int i;
  2374. HOSTDATA(shpnt)->total_commands=0;
  2375. HOSTDATA(shpnt)->disconnections=0;
  2376. HOSTDATA(shpnt)->busfree_without_any_action=0;
  2377. HOSTDATA(shpnt)->busfree_without_old_command=0;
  2378. HOSTDATA(shpnt)->busfree_without_new_command=0;
  2379. HOSTDATA(shpnt)->busfree_without_done_command=0;
  2380. HOSTDATA(shpnt)->busfree_with_check_condition=0;
  2381. for (i = idle; i<maxstate; i++) {
  2382. HOSTDATA(shpnt)->count[i]=0;
  2383. HOSTDATA(shpnt)->count_trans[i]=0;
  2384. HOSTDATA(shpnt)->time[i]=0;
  2385. }
  2386. shost_printk(KERN_INFO, shpnt, "aha152x: stats reset.\n");
  2387. } else
  2388. #endif
  2389. {
  2390. return -EINVAL;
  2391. }
  2392. return length;
  2393. }
  2394. static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
  2395. {
  2396. int i;
  2397. struct scsi_cmnd *ptr;
  2398. unsigned long flags;
  2399. seq_puts(m, AHA152X_REVID "\n");
  2400. seq_printf(m, "ioports 0x%04lx to 0x%04lx\n",
  2401. shpnt->io_port, shpnt->io_port + shpnt->n_io_port - 1);
  2402. seq_printf(m, "interrupt 0x%02x\n", shpnt->irq);
  2403. seq_printf(m, "disconnection/reconnection %s\n",
  2404. RECONNECT ? "enabled" : "disabled");
  2405. seq_printf(m, "parity checking %s\n",
  2406. PARITY ? "enabled" : "disabled");
  2407. seq_printf(m, "synchronous transfers %s\n",
  2408. SYNCHRONOUS ? "enabled" : "disabled");
  2409. seq_printf(m, "%d commands currently queued\n", HOSTDATA(shpnt)->commands);
  2410. if(SYNCHRONOUS) {
  2411. seq_puts(m, "synchronously operating targets (tick=50 ns):\n");
  2412. for (i = 0; i < 8; i++)
  2413. if (HOSTDATA(shpnt)->syncrate[i] & 0x7f)
  2414. seq_printf(m, "target %d: period %dT/%dns; req/ack offset %d\n",
  2415. i,
  2416. (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2),
  2417. (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
  2418. HOSTDATA(shpnt)->syncrate[i] & 0x0f);
  2419. }
  2420. seq_puts(m, "\nqueue status:\n");
  2421. DO_LOCK(flags);
  2422. if (ISSUE_SC) {
  2423. seq_puts(m, "not yet issued commands:\n");
  2424. for (ptr = ISSUE_SC; ptr; ptr = SCNEXT(ptr))
  2425. get_command(m, ptr);
  2426. } else
  2427. seq_puts(m, "no not yet issued commands\n");
  2428. DO_UNLOCK(flags);
  2429. if (CURRENT_SC) {
  2430. seq_puts(m, "current command:\n");
  2431. get_command(m, CURRENT_SC);
  2432. } else
  2433. seq_puts(m, "no current command\n");
  2434. if (DISCONNECTED_SC) {
  2435. seq_puts(m, "disconnected commands:\n");
  2436. for (ptr = DISCONNECTED_SC; ptr; ptr = SCNEXT(ptr))
  2437. get_command(m, ptr);
  2438. } else
  2439. seq_puts(m, "no disconnected commands\n");
  2440. get_ports(m, shpnt);
  2441. #if defined(AHA152X_STAT)
  2442. seq_printf(m, "statistics:\n"
  2443. "total commands: %d\n"
  2444. "disconnections: %d\n"
  2445. "busfree with check condition: %d\n"
  2446. "busfree without old command: %d\n"
  2447. "busfree without new command: %d\n"
  2448. "busfree without done command: %d\n"
  2449. "busfree without any action: %d\n"
  2450. "state "
  2451. "transitions "
  2452. "count "
  2453. "time\n",
  2454. HOSTDATA(shpnt)->total_commands,
  2455. HOSTDATA(shpnt)->disconnections,
  2456. HOSTDATA(shpnt)->busfree_with_check_condition,
  2457. HOSTDATA(shpnt)->busfree_without_old_command,
  2458. HOSTDATA(shpnt)->busfree_without_new_command,
  2459. HOSTDATA(shpnt)->busfree_without_done_command,
  2460. HOSTDATA(shpnt)->busfree_without_any_action);
  2461. for(i=0; i<maxstate; i++) {
  2462. seq_printf(m, "%-10s %-12d %-12d %-12ld\n",
  2463. states[i].name,
  2464. HOSTDATA(shpnt)->count_trans[i],
  2465. HOSTDATA(shpnt)->count[i],
  2466. HOSTDATA(shpnt)->time[i]);
  2467. }
  2468. #endif
  2469. return 0;
  2470. }
  2471. static int aha152x_adjust_queue(struct scsi_device *device)
  2472. {
  2473. blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
  2474. return 0;
  2475. }
  2476. static struct scsi_host_template aha152x_driver_template = {
  2477. .module = THIS_MODULE,
  2478. .name = AHA152X_REVID,
  2479. .proc_name = "aha152x",
  2480. .show_info = aha152x_show_info,
  2481. .write_info = aha152x_set_info,
  2482. .queuecommand = aha152x_queue,
  2483. .eh_abort_handler = aha152x_abort,
  2484. .eh_device_reset_handler = aha152x_device_reset,
  2485. .eh_bus_reset_handler = aha152x_bus_reset,
  2486. .bios_param = aha152x_biosparam,
  2487. .can_queue = 1,
  2488. .this_id = 7,
  2489. .sg_tablesize = SG_ALL,
  2490. .dma_boundary = PAGE_SIZE - 1,
  2491. .slave_alloc = aha152x_adjust_queue,
  2492. .cmd_size = sizeof(struct aha152x_cmd_priv),
  2493. };
  2494. #if !defined(AHA152X_PCMCIA)
  2495. static int setup_count;
  2496. static struct aha152x_setup setup[2];
  2497. /* possible i/o addresses for the AIC-6260; default first */
  2498. static unsigned short ports[] = { 0x340, 0x140 };
  2499. #if !defined(SKIP_BIOSTEST)
  2500. /* possible locations for the Adaptec BIOS; defaults first */
  2501. static unsigned int addresses[] =
  2502. {
  2503. 0xdc000, /* default first */
  2504. 0xc8000,
  2505. 0xcc000,
  2506. 0xd0000,
  2507. 0xd4000,
  2508. 0xd8000,
  2509. 0xe0000,
  2510. 0xeb800, /* VTech Platinum SMP */
  2511. 0xf0000,
  2512. };
  2513. /* signatures for various AIC-6[23]60 based controllers.
  2514. The point in detecting signatures is to avoid useless and maybe
  2515. harmful probes on ports. I'm not sure that all listed boards pass
  2516. auto-configuration. For those which fail the BIOS signature is
  2517. obsolete, because user intervention to supply the configuration is
  2518. needed anyway. May be an information whether or not the BIOS supports
  2519. extended translation could be also useful here. */
  2520. static struct signature {
  2521. unsigned char *signature;
  2522. int sig_offset;
  2523. int sig_length;
  2524. } signatures[] =
  2525. {
  2526. { "Adaptec AHA-1520 BIOS", 0x102e, 21 },
  2527. /* Adaptec 152x */
  2528. { "Adaptec AHA-1520B", 0x000b, 17 },
  2529. /* Adaptec 152x rev B */
  2530. { "Adaptec AHA-1520B", 0x0026, 17 },
  2531. /* Iomega Jaz Jet ISA (AIC6370Q) */
  2532. { "Adaptec ASW-B626 BIOS", 0x1029, 21 },
  2533. /* on-board controller */
  2534. { "Adaptec BIOS: ASW-B626", 0x000f, 22 },
  2535. /* on-board controller */
  2536. { "Adaptec ASW-B626 S2", 0x2e6c, 19 },
  2537. /* on-board controller */
  2538. { "Adaptec BIOS:AIC-6360", 0x000c, 21 },
  2539. /* on-board controller */
  2540. { "ScsiPro SP-360 BIOS", 0x2873, 19 },
  2541. /* ScsiPro-Controller */
  2542. { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },
  2543. /* Gigabyte Local-Bus-SCSI */
  2544. { "Adaptec BIOS:AVA-282X", 0x000c, 21 },
  2545. /* Adaptec 282x */
  2546. { "Adaptec IBM Dock II SCSI", 0x2edd, 24 },
  2547. /* IBM Thinkpad Dock II */
  2548. { "Adaptec BIOS:AHA-1532P", 0x001c, 22 },
  2549. /* IBM Thinkpad Dock II SCSI */
  2550. { "DTC3520A Host Adapter BIOS", 0x318a, 26 },
  2551. /* DTC 3520A ISA SCSI */
  2552. };
  2553. #endif /* !SKIP_BIOSTEST */
  2554. /*
  2555. * Test, if port_base is valid.
  2556. *
  2557. */
  2558. static int aha152x_porttest(int io_port)
  2559. {
  2560. int i;
  2561. SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
  2562. for (i = 0; i < 16; i++)
  2563. SETPORT(io_port + O_STACK, i);
  2564. SETPORT(io_port + O_DMACNTRL1, 0); /* reset stack pointer */
  2565. for (i = 0; i < 16 && GETPORT(io_port + O_STACK) == i; i++)
  2566. ;
  2567. return (i == 16);
  2568. }
  2569. static int tc1550_porttest(int io_port)
  2570. {
  2571. int i;
  2572. SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
  2573. for (i = 0; i < 16; i++)
  2574. SETPORT(io_port + O_STACK, i);
  2575. SETPORT(io_port + O_TC_DMACNTRL1, 0); /* reset stack pointer */
  2576. for (i = 0; i < 16 && GETPORT(io_port + O_TC_STACK) == i; i++)
  2577. ;
  2578. return (i == 16);
  2579. }
  2580. static int checksetup(struct aha152x_setup *setup)
  2581. {
  2582. int i;
  2583. for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
  2584. ;
  2585. if (i == ARRAY_SIZE(ports))
  2586. return 0;
  2587. if (!request_region(setup->io_port, IO_RANGE, "aha152x")) {
  2588. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup->io_port);
  2589. return 0;
  2590. }
  2591. if( aha152x_porttest(setup->io_port) ) {
  2592. setup->tc1550=0;
  2593. } else if( tc1550_porttest(setup->io_port) ) {
  2594. setup->tc1550=1;
  2595. } else {
  2596. release_region(setup->io_port, IO_RANGE);
  2597. return 0;
  2598. }
  2599. release_region(setup->io_port, IO_RANGE);
  2600. if ((setup->irq < IRQ_MIN) || (setup->irq > IRQ_MAX))
  2601. return 0;
  2602. if ((setup->scsiid < 0) || (setup->scsiid > 7))
  2603. return 0;
  2604. if ((setup->reconnect < 0) || (setup->reconnect > 1))
  2605. return 0;
  2606. if ((setup->parity < 0) || (setup->parity > 1))
  2607. return 0;
  2608. if ((setup->synchronous < 0) || (setup->synchronous > 1))
  2609. return 0;
  2610. if ((setup->ext_trans < 0) || (setup->ext_trans > 1))
  2611. return 0;
  2612. return 1;
  2613. }
  2614. static int __init aha152x_init(void)
  2615. {
  2616. int i, j, ok;
  2617. #if defined(AUTOCONF)
  2618. aha152x_config conf;
  2619. #endif
  2620. #ifdef __ISAPNP__
  2621. struct pnp_dev *dev=NULL, *pnpdev[2] = {NULL, NULL};
  2622. #endif
  2623. if ( setup_count ) {
  2624. printk(KERN_INFO "aha152x: processing commandline: ");
  2625. for (i = 0; i<setup_count; i++) {
  2626. if (!checksetup(&setup[i])) {
  2627. printk(KERN_ERR "\naha152x: %s\n", setup[i].conf);
  2628. printk(KERN_ERR "aha152x: invalid line\n");
  2629. }
  2630. }
  2631. printk("ok\n");
  2632. }
  2633. #if defined(SETUP0)
  2634. if (setup_count < ARRAY_SIZE(setup)) {
  2635. struct aha152x_setup override = SETUP0;
  2636. if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
  2637. if (!checksetup(&override)) {
  2638. printk(KERN_ERR "\naha152x: invalid override SETUP0={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
  2639. override.io_port,
  2640. override.irq,
  2641. override.scsiid,
  2642. override.reconnect,
  2643. override.parity,
  2644. override.synchronous,
  2645. override.delay,
  2646. override.ext_trans);
  2647. } else
  2648. setup[setup_count++] = override;
  2649. }
  2650. }
  2651. #endif
  2652. #if defined(SETUP1)
  2653. if (setup_count < ARRAY_SIZE(setup)) {
  2654. struct aha152x_setup override = SETUP1;
  2655. if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
  2656. if (!checksetup(&override)) {
  2657. printk(KERN_ERR "\naha152x: invalid override SETUP1={0x%x,%d,%d,%d,%d,%d,%d,%d}\n",
  2658. override.io_port,
  2659. override.irq,
  2660. override.scsiid,
  2661. override.reconnect,
  2662. override.parity,
  2663. override.synchronous,
  2664. override.delay,
  2665. override.ext_trans);
  2666. } else
  2667. setup[setup_count++] = override;
  2668. }
  2669. }
  2670. #endif
  2671. #if defined(MODULE)
  2672. if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
  2673. if(aha152x[0]!=0) {
  2674. setup[setup_count].conf = "";
  2675. setup[setup_count].io_port = aha152x[0];
  2676. setup[setup_count].irq = aha152x[1];
  2677. setup[setup_count].scsiid = aha152x[2];
  2678. setup[setup_count].reconnect = aha152x[3];
  2679. setup[setup_count].parity = aha152x[4];
  2680. setup[setup_count].synchronous = aha152x[5];
  2681. setup[setup_count].delay = aha152x[6];
  2682. setup[setup_count].ext_trans = aha152x[7];
  2683. } else if (io[0] != 0 || irq[0] != 0) {
  2684. if(io[0]!=0) setup[setup_count].io_port = io[0];
  2685. if(irq[0]!=0) setup[setup_count].irq = irq[0];
  2686. setup[setup_count].scsiid = scsiid[0];
  2687. setup[setup_count].reconnect = reconnect[0];
  2688. setup[setup_count].parity = parity[0];
  2689. setup[setup_count].synchronous = sync[0];
  2690. setup[setup_count].delay = delay[0];
  2691. setup[setup_count].ext_trans = exttrans[0];
  2692. }
  2693. if (checksetup(&setup[setup_count]))
  2694. setup_count++;
  2695. else
  2696. printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
  2697. setup[setup_count].io_port,
  2698. setup[setup_count].irq,
  2699. setup[setup_count].scsiid,
  2700. setup[setup_count].reconnect,
  2701. setup[setup_count].parity,
  2702. setup[setup_count].synchronous,
  2703. setup[setup_count].delay,
  2704. setup[setup_count].ext_trans);
  2705. }
  2706. if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
  2707. if(aha152x1[0]!=0) {
  2708. setup[setup_count].conf = "";
  2709. setup[setup_count].io_port = aha152x1[0];
  2710. setup[setup_count].irq = aha152x1[1];
  2711. setup[setup_count].scsiid = aha152x1[2];
  2712. setup[setup_count].reconnect = aha152x1[3];
  2713. setup[setup_count].parity = aha152x1[4];
  2714. setup[setup_count].synchronous = aha152x1[5];
  2715. setup[setup_count].delay = aha152x1[6];
  2716. setup[setup_count].ext_trans = aha152x1[7];
  2717. } else if (io[1] != 0 || irq[1] != 0) {
  2718. if(io[1]!=0) setup[setup_count].io_port = io[1];
  2719. if(irq[1]!=0) setup[setup_count].irq = irq[1];
  2720. setup[setup_count].scsiid = scsiid[1];
  2721. setup[setup_count].reconnect = reconnect[1];
  2722. setup[setup_count].parity = parity[1];
  2723. setup[setup_count].synchronous = sync[1];
  2724. setup[setup_count].delay = delay[1];
  2725. setup[setup_count].ext_trans = exttrans[1];
  2726. }
  2727. if (checksetup(&setup[setup_count]))
  2728. setup_count++;
  2729. else
  2730. printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
  2731. setup[setup_count].io_port,
  2732. setup[setup_count].irq,
  2733. setup[setup_count].scsiid,
  2734. setup[setup_count].reconnect,
  2735. setup[setup_count].parity,
  2736. setup[setup_count].synchronous,
  2737. setup[setup_count].delay,
  2738. setup[setup_count].ext_trans);
  2739. }
  2740. #endif
  2741. #ifdef __ISAPNP__
  2742. for(i=0; setup_count<ARRAY_SIZE(setup) && id_table[i].vendor; i++) {
  2743. while ( setup_count<ARRAY_SIZE(setup) &&
  2744. (dev=pnp_find_dev(NULL, id_table[i].vendor, id_table[i].function, dev)) ) {
  2745. if (pnp_device_attach(dev) < 0)
  2746. continue;
  2747. if (pnp_activate_dev(dev) < 0) {
  2748. pnp_device_detach(dev);
  2749. continue;
  2750. }
  2751. if (!pnp_port_valid(dev, 0)) {
  2752. pnp_device_detach(dev);
  2753. continue;
  2754. }
  2755. if (setup_count==1 && pnp_port_start(dev, 0)==setup[0].io_port) {
  2756. pnp_device_detach(dev);
  2757. continue;
  2758. }
  2759. setup[setup_count].io_port = pnp_port_start(dev, 0);
  2760. setup[setup_count].irq = pnp_irq(dev, 0);
  2761. setup[setup_count].scsiid = 7;
  2762. setup[setup_count].reconnect = 1;
  2763. setup[setup_count].parity = 1;
  2764. setup[setup_count].synchronous = 1;
  2765. setup[setup_count].delay = DELAY_DEFAULT;
  2766. setup[setup_count].ext_trans = 0;
  2767. #if defined(__ISAPNP__)
  2768. pnpdev[setup_count] = dev;
  2769. #endif
  2770. printk (KERN_INFO
  2771. "aha152x: found ISAPnP adapter at io=0x%03x, irq=%d\n",
  2772. setup[setup_count].io_port, setup[setup_count].irq);
  2773. setup_count++;
  2774. }
  2775. }
  2776. #endif
  2777. #if defined(AUTOCONF)
  2778. if (setup_count<ARRAY_SIZE(setup)) {
  2779. #if !defined(SKIP_BIOSTEST)
  2780. ok = 0;
  2781. for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++) {
  2782. void __iomem *p = ioremap(addresses[i], 0x4000);
  2783. if (!p)
  2784. continue;
  2785. for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
  2786. ok = check_signature(p + signatures[j].sig_offset,
  2787. signatures[j].signature, signatures[j].sig_length);
  2788. iounmap(p);
  2789. }
  2790. if (!ok && setup_count == 0)
  2791. return -ENODEV;
  2792. printk(KERN_INFO "aha152x: BIOS test: passed, ");
  2793. #else
  2794. printk(KERN_INFO "aha152x: ");
  2795. #endif /* !SKIP_BIOSTEST */
  2796. ok = 0;
  2797. for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
  2798. if ((setup_count == 1) && (setup[0].io_port == ports[i]))
  2799. continue;
  2800. if (!request_region(ports[i], IO_RANGE, "aha152x")) {
  2801. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", ports[i]);
  2802. continue;
  2803. }
  2804. if (aha152x_porttest(ports[i])) {
  2805. setup[setup_count].tc1550 = 0;
  2806. conf.cf_port =
  2807. (GETPORT(ports[i] + O_PORTA) << 8) + GETPORT(ports[i] + O_PORTB);
  2808. } else if (tc1550_porttest(ports[i])) {
  2809. setup[setup_count].tc1550 = 1;
  2810. conf.cf_port =
  2811. (GETPORT(ports[i] + O_TC_PORTA) << 8) + GETPORT(ports[i] + O_TC_PORTB);
  2812. } else {
  2813. release_region(ports[i], IO_RANGE);
  2814. continue;
  2815. }
  2816. release_region(ports[i], IO_RANGE);
  2817. ok++;
  2818. setup[setup_count].io_port = ports[i];
  2819. setup[setup_count].irq = IRQ_MIN + conf.cf_irq;
  2820. setup[setup_count].scsiid = conf.cf_id;
  2821. setup[setup_count].reconnect = conf.cf_tardisc;
  2822. setup[setup_count].parity = !conf.cf_parity;
  2823. setup[setup_count].synchronous = conf.cf_syncneg;
  2824. setup[setup_count].delay = DELAY_DEFAULT;
  2825. setup[setup_count].ext_trans = 0;
  2826. setup_count++;
  2827. }
  2828. if (ok)
  2829. printk("auto configuration: ok, ");
  2830. }
  2831. #endif
  2832. printk("%d controller(s) configured\n", setup_count);
  2833. for (i=0; i<setup_count; i++) {
  2834. if ( request_region(setup[i].io_port, IO_RANGE, "aha152x") ) {
  2835. struct Scsi_Host *shpnt = aha152x_probe_one(&setup[i]);
  2836. if( !shpnt ) {
  2837. release_region(setup[i].io_port, IO_RANGE);
  2838. #if defined(__ISAPNP__)
  2839. } else if( pnpdev[i] ) {
  2840. HOSTDATA(shpnt)->pnpdev=pnpdev[i];
  2841. pnpdev[i]=NULL;
  2842. #endif
  2843. }
  2844. } else {
  2845. printk(KERN_ERR "aha152x: io port 0x%x busy.\n", setup[i].io_port);
  2846. }
  2847. #if defined(__ISAPNP__)
  2848. if( pnpdev[i] )
  2849. pnp_device_detach(pnpdev[i]);
  2850. #endif
  2851. }
  2852. return 0;
  2853. }
  2854. static void __exit aha152x_exit(void)
  2855. {
  2856. struct aha152x_hostdata *hd, *tmp;
  2857. list_for_each_entry_safe(hd, tmp, &aha152x_host_list, host_list) {
  2858. struct Scsi_Host *shost = container_of((void *)hd, struct Scsi_Host, hostdata);
  2859. aha152x_release(shost);
  2860. }
  2861. }
  2862. module_init(aha152x_init);
  2863. module_exit(aha152x_exit);
  2864. #if !defined(MODULE)
  2865. static int __init aha152x_setup(char *str)
  2866. {
  2867. int ints[10];
  2868. get_options(str, ARRAY_SIZE(ints), ints);
  2869. if(setup_count>=ARRAY_SIZE(setup)) {
  2870. printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
  2871. return 1;
  2872. }
  2873. setup[setup_count].conf = str;
  2874. setup[setup_count].io_port = ints[0] >= 1 ? ints[1] : 0x340;
  2875. setup[setup_count].irq = ints[0] >= 2 ? ints[2] : 11;
  2876. setup[setup_count].scsiid = ints[0] >= 3 ? ints[3] : 7;
  2877. setup[setup_count].reconnect = ints[0] >= 4 ? ints[4] : 1;
  2878. setup[setup_count].parity = ints[0] >= 5 ? ints[5] : 1;
  2879. setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
  2880. setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
  2881. setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
  2882. if (ints[0] > 8)
  2883. printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
  2884. "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
  2885. else
  2886. setup_count++;
  2887. return 1;
  2888. }
  2889. __setup("aha152x=", aha152x_setup);
  2890. #endif
  2891. #endif /* !AHA152X_PCMCIA */