aha152x.c 83 KB

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