aha152x.c 99 KB

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