aha152x.c 99 KB

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