aha152x.c 99 KB

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