aha152x.c 98 KB

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