aic79xx_osm.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898
  1. /*
  2. * Adaptec AIC79xx device driver for Linux.
  3. *
  4. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_osm.c#171 $
  5. *
  6. * --------------------------------------------------------------------------
  7. * Copyright (c) 1994-2000 Justin T. Gibbs.
  8. * Copyright (c) 1997-1999 Doug Ledford
  9. * Copyright (c) 2000-2003 Adaptec Inc.
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions
  14. * are met:
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions, and the following disclaimer,
  17. * without modification.
  18. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  19. * substantially similar to the "NO WARRANTY" disclaimer below
  20. * ("Disclaimer") and any redistribution must be conditioned upon
  21. * including a substantially similar Disclaimer requirement for further
  22. * binary redistribution.
  23. * 3. Neither the names of the above-listed copyright holders nor the names
  24. * of any contributors may be used to endorse or promote products derived
  25. * from this software without specific prior written permission.
  26. *
  27. * Alternatively, this software may be distributed under the terms of the
  28. * GNU General Public License ("GPL") version 2 as published by the Free
  29. * Software Foundation.
  30. *
  31. * NO WARRANTY
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  33. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  34. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  35. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  36. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  37. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  38. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  41. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  42. * POSSIBILITY OF SUCH DAMAGES.
  43. */
  44. #include "aic79xx_osm.h"
  45. #include "aic79xx_inline.h"
  46. #include <scsi/scsicam.h>
  47. static struct scsi_transport_template *ahd_linux_transport_template = NULL;
  48. #include <linux/init.h> /* __setup */
  49. #include <linux/mm.h> /* For fetching system memory size */
  50. #include <linux/blkdev.h> /* For block_size() */
  51. #include <linux/delay.h> /* For ssleep/msleep */
  52. #include <linux/device.h>
  53. #include <linux/slab.h>
  54. /*
  55. * Bucket size for counting good commands in between bad ones.
  56. */
  57. #define AHD_LINUX_ERR_THRESH 1000
  58. /*
  59. * Set this to the delay in seconds after SCSI bus reset.
  60. * Note, we honor this only for the initial bus reset.
  61. * The scsi error recovery code performs its own bus settle
  62. * delay handling for error recovery actions.
  63. */
  64. #ifdef CONFIG_AIC79XX_RESET_DELAY_MS
  65. #define AIC79XX_RESET_DELAY CONFIG_AIC79XX_RESET_DELAY_MS
  66. #else
  67. #define AIC79XX_RESET_DELAY 5000
  68. #endif
  69. /*
  70. * To change the default number of tagged transactions allowed per-device,
  71. * add a line to the lilo.conf file like:
  72. * append="aic79xx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
  73. * which will result in the first four devices on the first two
  74. * controllers being set to a tagged queue depth of 32.
  75. *
  76. * The tag_commands is an array of 16 to allow for wide and twin adapters.
  77. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
  78. * for channel 1.
  79. */
  80. typedef struct {
  81. uint16_t tag_commands[16]; /* Allow for wide/twin adapters. */
  82. } adapter_tag_info_t;
  83. /*
  84. * Modify this as you see fit for your system.
  85. *
  86. * 0 tagged queuing disabled
  87. * 1 <= n <= 253 n == max tags ever dispatched.
  88. *
  89. * The driver will throttle the number of commands dispatched to a
  90. * device if it returns queue full. For devices with a fixed maximum
  91. * queue depth, the driver will eventually determine this depth and
  92. * lock it in (a console message is printed to indicate that a lock
  93. * has occurred). On some devices, queue full is returned for a temporary
  94. * resource shortage. These devices will return queue full at varying
  95. * depths. The driver will throttle back when the queue fulls occur and
  96. * attempt to slowly increase the depth over time as the device recovers
  97. * from the resource shortage.
  98. *
  99. * In this example, the first line will disable tagged queueing for all
  100. * the devices on the first probed aic79xx adapter.
  101. *
  102. * The second line enables tagged queueing with 4 commands/LUN for IDs
  103. * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  104. * driver to attempt to use up to 64 tags for ID 1.
  105. *
  106. * The third line is the same as the first line.
  107. *
  108. * The fourth line disables tagged queueing for devices 0 and 3. It
  109. * enables tagged queueing for the other IDs, with 16 commands/LUN
  110. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  111. * IDs 2, 5-7, and 9-15.
  112. */
  113. /*
  114. * NOTE: The below structure is for reference only, the actual structure
  115. * to modify in order to change things is just below this comment block.
  116. adapter_tag_info_t aic79xx_tag_info[] =
  117. {
  118. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  119. {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
  120. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  121. {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  122. };
  123. */
  124. #ifdef CONFIG_AIC79XX_CMDS_PER_DEVICE
  125. #define AIC79XX_CMDS_PER_DEVICE CONFIG_AIC79XX_CMDS_PER_DEVICE
  126. #else
  127. #define AIC79XX_CMDS_PER_DEVICE AHD_MAX_QUEUE
  128. #endif
  129. #define AIC79XX_CONFIGED_TAG_COMMANDS { \
  130. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  131. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  132. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  133. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  134. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  135. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  136. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE, \
  137. AIC79XX_CMDS_PER_DEVICE, AIC79XX_CMDS_PER_DEVICE \
  138. }
  139. /*
  140. * By default, use the number of commands specified by
  141. * the users kernel configuration.
  142. */
  143. static adapter_tag_info_t aic79xx_tag_info[] =
  144. {
  145. {AIC79XX_CONFIGED_TAG_COMMANDS},
  146. {AIC79XX_CONFIGED_TAG_COMMANDS},
  147. {AIC79XX_CONFIGED_TAG_COMMANDS},
  148. {AIC79XX_CONFIGED_TAG_COMMANDS},
  149. {AIC79XX_CONFIGED_TAG_COMMANDS},
  150. {AIC79XX_CONFIGED_TAG_COMMANDS},
  151. {AIC79XX_CONFIGED_TAG_COMMANDS},
  152. {AIC79XX_CONFIGED_TAG_COMMANDS},
  153. {AIC79XX_CONFIGED_TAG_COMMANDS},
  154. {AIC79XX_CONFIGED_TAG_COMMANDS},
  155. {AIC79XX_CONFIGED_TAG_COMMANDS},
  156. {AIC79XX_CONFIGED_TAG_COMMANDS},
  157. {AIC79XX_CONFIGED_TAG_COMMANDS},
  158. {AIC79XX_CONFIGED_TAG_COMMANDS},
  159. {AIC79XX_CONFIGED_TAG_COMMANDS},
  160. {AIC79XX_CONFIGED_TAG_COMMANDS}
  161. };
  162. /*
  163. * The I/O cell on the chip is very configurable in respect to its analog
  164. * characteristics. Set the defaults here; they can be overriden with
  165. * the proper insmod parameters.
  166. */
  167. struct ahd_linux_iocell_opts
  168. {
  169. uint8_t precomp;
  170. uint8_t slewrate;
  171. uint8_t amplitude;
  172. };
  173. #define AIC79XX_DEFAULT_PRECOMP 0xFF
  174. #define AIC79XX_DEFAULT_SLEWRATE 0xFF
  175. #define AIC79XX_DEFAULT_AMPLITUDE 0xFF
  176. #define AIC79XX_DEFAULT_IOOPTS \
  177. { \
  178. AIC79XX_DEFAULT_PRECOMP, \
  179. AIC79XX_DEFAULT_SLEWRATE, \
  180. AIC79XX_DEFAULT_AMPLITUDE \
  181. }
  182. #define AIC79XX_PRECOMP_INDEX 0
  183. #define AIC79XX_SLEWRATE_INDEX 1
  184. #define AIC79XX_AMPLITUDE_INDEX 2
  185. static const struct ahd_linux_iocell_opts aic79xx_iocell_info[] =
  186. {
  187. AIC79XX_DEFAULT_IOOPTS,
  188. AIC79XX_DEFAULT_IOOPTS,
  189. AIC79XX_DEFAULT_IOOPTS,
  190. AIC79XX_DEFAULT_IOOPTS,
  191. AIC79XX_DEFAULT_IOOPTS,
  192. AIC79XX_DEFAULT_IOOPTS,
  193. AIC79XX_DEFAULT_IOOPTS,
  194. AIC79XX_DEFAULT_IOOPTS,
  195. AIC79XX_DEFAULT_IOOPTS,
  196. AIC79XX_DEFAULT_IOOPTS,
  197. AIC79XX_DEFAULT_IOOPTS,
  198. AIC79XX_DEFAULT_IOOPTS,
  199. AIC79XX_DEFAULT_IOOPTS,
  200. AIC79XX_DEFAULT_IOOPTS,
  201. AIC79XX_DEFAULT_IOOPTS,
  202. AIC79XX_DEFAULT_IOOPTS
  203. };
  204. /*
  205. * There should be a specific return value for this in scsi.h, but
  206. * it seems that most drivers ignore it.
  207. */
  208. #define DID_UNDERFLOW DID_ERROR
  209. void
  210. ahd_print_path(struct ahd_softc *ahd, struct scb *scb)
  211. {
  212. printk("(scsi%d:%c:%d:%d): ",
  213. ahd->platform_data->host->host_no,
  214. scb != NULL ? SCB_GET_CHANNEL(ahd, scb) : 'X',
  215. scb != NULL ? SCB_GET_TARGET(ahd, scb) : -1,
  216. scb != NULL ? SCB_GET_LUN(scb) : -1);
  217. }
  218. /*
  219. * XXX - these options apply unilaterally to _all_ adapters
  220. * cards in the system. This should be fixed. Exceptions to this
  221. * rule are noted in the comments.
  222. */
  223. /*
  224. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  225. * has no effect on any later resets that might occur due to things like
  226. * SCSI bus timeouts.
  227. */
  228. static uint32_t aic79xx_no_reset;
  229. /*
  230. * Should we force EXTENDED translation on a controller.
  231. * 0 == Use whatever is in the SEEPROM or default to off
  232. * 1 == Use whatever is in the SEEPROM or default to on
  233. */
  234. static uint32_t aic79xx_extended;
  235. /*
  236. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  237. * dubious at best. To my knowledge, this option has never actually
  238. * solved a PCI parity problem, but on certain machines with broken PCI
  239. * chipset configurations, it can generate tons of false error messages.
  240. * It's included in the driver for completeness.
  241. * 0 = Shut off PCI parity check
  242. * non-0 = Enable PCI parity check
  243. *
  244. * NOTE: you can't actually pass -1 on the lilo prompt. So, to set this
  245. * variable to -1 you would actually want to simply pass the variable
  246. * name without a number. That will invert the 0 which will result in
  247. * -1.
  248. */
  249. static uint32_t aic79xx_pci_parity = ~0;
  250. /*
  251. * There are lots of broken chipsets in the world. Some of them will
  252. * violate the PCI spec when we issue byte sized memory writes to our
  253. * controller. I/O mapped register access, if allowed by the given
  254. * platform, will work in almost all cases.
  255. */
  256. uint32_t aic79xx_allow_memio = ~0;
  257. /*
  258. * So that we can set how long each device is given as a selection timeout.
  259. * The table of values goes like this:
  260. * 0 - 256ms
  261. * 1 - 128ms
  262. * 2 - 64ms
  263. * 3 - 32ms
  264. * We default to 256ms because some older devices need a longer time
  265. * to respond to initial selection.
  266. */
  267. static uint32_t aic79xx_seltime;
  268. /*
  269. * Certain devices do not perform any aging on commands. Should the
  270. * device be saturated by commands in one portion of the disk, it is
  271. * possible for transactions on far away sectors to never be serviced.
  272. * To handle these devices, we can periodically send an ordered tag to
  273. * force all outstanding transactions to be serviced prior to a new
  274. * transaction.
  275. */
  276. static uint32_t aic79xx_periodic_otag;
  277. /* Some storage boxes are using an LSI chip which has a bug making it
  278. * impossible to use aic79xx Rev B chip in 320 speeds. The following
  279. * storage boxes have been reported to be buggy:
  280. * EonStor 3U 16-Bay: U16U-G3A3
  281. * EonStor 2U 12-Bay: U12U-G3A3
  282. * SentinelRAID: 2500F R5 / R6
  283. * SentinelRAID: 2500F R1
  284. * SentinelRAID: 2500F/1500F
  285. * SentinelRAID: 150F
  286. *
  287. * To get around this LSI bug, you can set your board to 160 mode
  288. * or you can enable the SLOWCRC bit.
  289. */
  290. uint32_t aic79xx_slowcrc;
  291. /*
  292. * Module information and settable options.
  293. */
  294. static char *aic79xx = NULL;
  295. MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>");
  296. MODULE_DESCRIPTION("Adaptec AIC790X U320 SCSI Host Bus Adapter driver");
  297. MODULE_LICENSE("Dual BSD/GPL");
  298. MODULE_VERSION(AIC79XX_DRIVER_VERSION);
  299. module_param(aic79xx, charp, 0444);
  300. MODULE_PARM_DESC(aic79xx,
  301. "period-delimited options string:\n"
  302. " verbose Enable verbose/diagnostic logging\n"
  303. " allow_memio Allow device registers to be memory mapped\n"
  304. " debug Bitmask of debug values to enable\n"
  305. " no_reset Suppress initial bus resets\n"
  306. " extended Enable extended geometry on all controllers\n"
  307. " periodic_otag Send an ordered tagged transaction\n"
  308. " periodically to prevent tag starvation.\n"
  309. " This may be required by some older disk\n"
  310. " or drives/RAID arrays.\n"
  311. " tag_info:<tag_str> Set per-target tag depth\n"
  312. " global_tag_depth:<int> Global tag depth for all targets on all buses\n"
  313. " slewrate:<slewrate_list>Set the signal slew rate (0-15).\n"
  314. " precomp:<pcomp_list> Set the signal precompensation (0-7).\n"
  315. " amplitude:<int> Set the signal amplitude (0-7).\n"
  316. " seltime:<int> Selection Timeout:\n"
  317. " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
  318. " slowcrc Turn on the SLOWCRC bit (Rev B only)\n"
  319. "\n"
  320. " Sample modprobe configuration file:\n"
  321. " # Enable verbose logging\n"
  322. " # Set tag depth on Controller 2/Target 2 to 10 tags\n"
  323. " # Shorten the selection timeout to 128ms\n"
  324. "\n"
  325. " options aic79xx 'aic79xx=verbose.tag_info:{{}.{}.{..10}}.seltime:1'\n"
  326. );
  327. static void ahd_linux_handle_scsi_status(struct ahd_softc *,
  328. struct scsi_device *,
  329. struct scb *);
  330. static void ahd_linux_queue_cmd_complete(struct ahd_softc *ahd,
  331. struct scsi_cmnd *cmd);
  332. static int ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd);
  333. static void ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd);
  334. static u_int ahd_linux_user_tagdepth(struct ahd_softc *ahd,
  335. struct ahd_devinfo *devinfo);
  336. static void ahd_linux_device_queue_depth(struct scsi_device *);
  337. static int ahd_linux_run_command(struct ahd_softc*,
  338. struct ahd_linux_device *,
  339. struct scsi_cmnd *);
  340. static void ahd_linux_setup_tag_info_global(char *p);
  341. static int aic79xx_setup(char *c);
  342. static void ahd_freeze_simq(struct ahd_softc *ahd);
  343. static void ahd_release_simq(struct ahd_softc *ahd);
  344. static int ahd_linux_unit;
  345. /************************** OS Utility Wrappers *******************************/
  346. void ahd_delay(long);
  347. void
  348. ahd_delay(long usec)
  349. {
  350. /*
  351. * udelay on Linux can have problems for
  352. * multi-millisecond waits. Wait at most
  353. * 1024us per call.
  354. */
  355. while (usec > 0) {
  356. udelay(usec % 1024);
  357. usec -= 1024;
  358. }
  359. }
  360. /***************************** Low Level I/O **********************************/
  361. uint8_t ahd_inb(struct ahd_softc * ahd, long port);
  362. void ahd_outb(struct ahd_softc * ahd, long port, uint8_t val);
  363. void ahd_outw_atomic(struct ahd_softc * ahd,
  364. long port, uint16_t val);
  365. void ahd_outsb(struct ahd_softc * ahd, long port,
  366. uint8_t *, int count);
  367. void ahd_insb(struct ahd_softc * ahd, long port,
  368. uint8_t *, int count);
  369. uint8_t
  370. ahd_inb(struct ahd_softc * ahd, long port)
  371. {
  372. uint8_t x;
  373. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  374. x = readb(ahd->bshs[0].maddr + port);
  375. } else {
  376. x = inb(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  377. }
  378. mb();
  379. return (x);
  380. }
  381. #if 0 /* unused */
  382. static uint16_t
  383. ahd_inw_atomic(struct ahd_softc * ahd, long port)
  384. {
  385. uint8_t x;
  386. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  387. x = readw(ahd->bshs[0].maddr + port);
  388. } else {
  389. x = inw(ahd->bshs[(port) >> 8].ioport + ((port) & 0xFF));
  390. }
  391. mb();
  392. return (x);
  393. }
  394. #endif
  395. void
  396. ahd_outb(struct ahd_softc * ahd, long port, uint8_t val)
  397. {
  398. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  399. writeb(val, ahd->bshs[0].maddr + port);
  400. } else {
  401. outb(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  402. }
  403. mb();
  404. }
  405. void
  406. ahd_outw_atomic(struct ahd_softc * ahd, long port, uint16_t val)
  407. {
  408. if (ahd->tags[0] == BUS_SPACE_MEMIO) {
  409. writew(val, ahd->bshs[0].maddr + port);
  410. } else {
  411. outw(val, ahd->bshs[(port) >> 8].ioport + (port & 0xFF));
  412. }
  413. mb();
  414. }
  415. void
  416. ahd_outsb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  417. {
  418. int i;
  419. /*
  420. * There is probably a more efficient way to do this on Linux
  421. * but we don't use this for anything speed critical and this
  422. * should work.
  423. */
  424. for (i = 0; i < count; i++)
  425. ahd_outb(ahd, port, *array++);
  426. }
  427. void
  428. ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
  429. {
  430. int i;
  431. /*
  432. * There is probably a more efficient way to do this on Linux
  433. * but we don't use this for anything speed critical and this
  434. * should work.
  435. */
  436. for (i = 0; i < count; i++)
  437. *array++ = ahd_inb(ahd, port);
  438. }
  439. /******************************* PCI Routines *********************************/
  440. uint32_t
  441. ahd_pci_read_config(ahd_dev_softc_t pci, int reg, int width)
  442. {
  443. switch (width) {
  444. case 1:
  445. {
  446. uint8_t retval;
  447. pci_read_config_byte(pci, reg, &retval);
  448. return (retval);
  449. }
  450. case 2:
  451. {
  452. uint16_t retval;
  453. pci_read_config_word(pci, reg, &retval);
  454. return (retval);
  455. }
  456. case 4:
  457. {
  458. uint32_t retval;
  459. pci_read_config_dword(pci, reg, &retval);
  460. return (retval);
  461. }
  462. default:
  463. panic("ahd_pci_read_config: Read size too big");
  464. /* NOTREACHED */
  465. return (0);
  466. }
  467. }
  468. void
  469. ahd_pci_write_config(ahd_dev_softc_t pci, int reg, uint32_t value, int width)
  470. {
  471. switch (width) {
  472. case 1:
  473. pci_write_config_byte(pci, reg, value);
  474. break;
  475. case 2:
  476. pci_write_config_word(pci, reg, value);
  477. break;
  478. case 4:
  479. pci_write_config_dword(pci, reg, value);
  480. break;
  481. default:
  482. panic("ahd_pci_write_config: Write size too big");
  483. /* NOTREACHED */
  484. }
  485. }
  486. /****************************** Inlines ***************************************/
  487. static void ahd_linux_unmap_scb(struct ahd_softc*, struct scb*);
  488. static void
  489. ahd_linux_unmap_scb(struct ahd_softc *ahd, struct scb *scb)
  490. {
  491. struct scsi_cmnd *cmd;
  492. cmd = scb->io_ctx;
  493. ahd_sync_sglist(ahd, scb, BUS_DMASYNC_POSTWRITE);
  494. scsi_dma_unmap(cmd);
  495. }
  496. /******************************** Macros **************************************/
  497. #define BUILD_SCSIID(ahd, cmd) \
  498. (((scmd_id(cmd) << TID_SHIFT) & TID) | (ahd)->our_id)
  499. /*
  500. * Return a string describing the driver.
  501. */
  502. static const char *
  503. ahd_linux_info(struct Scsi_Host *host)
  504. {
  505. static char buffer[512];
  506. char ahd_info[256];
  507. char *bp;
  508. struct ahd_softc *ahd;
  509. bp = &buffer[0];
  510. ahd = *(struct ahd_softc **)host->hostdata;
  511. memset(bp, 0, sizeof(buffer));
  512. strcpy(bp, "Adaptec AIC79XX PCI-X SCSI HBA DRIVER, Rev " AIC79XX_DRIVER_VERSION "\n"
  513. " <");
  514. strcat(bp, ahd->description);
  515. strcat(bp, ">\n"
  516. " ");
  517. ahd_controller_info(ahd, ahd_info);
  518. strcat(bp, ahd_info);
  519. return (bp);
  520. }
  521. /*
  522. * Queue an SCB to the controller.
  523. */
  524. static int
  525. ahd_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
  526. {
  527. struct ahd_softc *ahd;
  528. struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
  529. int rtn = SCSI_MLQUEUE_HOST_BUSY;
  530. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  531. cmd->scsi_done = scsi_done;
  532. cmd->result = CAM_REQ_INPROG << 16;
  533. rtn = ahd_linux_run_command(ahd, dev, cmd);
  534. return rtn;
  535. }
  536. static DEF_SCSI_QCMD(ahd_linux_queue)
  537. static struct scsi_target **
  538. ahd_linux_target_in_softc(struct scsi_target *starget)
  539. {
  540. struct ahd_softc *ahd =
  541. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  542. unsigned int target_offset;
  543. target_offset = starget->id;
  544. if (starget->channel != 0)
  545. target_offset += 8;
  546. return &ahd->platform_data->starget[target_offset];
  547. }
  548. static int
  549. ahd_linux_target_alloc(struct scsi_target *starget)
  550. {
  551. struct ahd_softc *ahd =
  552. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  553. struct seeprom_config *sc = ahd->seep_config;
  554. unsigned long flags;
  555. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  556. struct ahd_devinfo devinfo;
  557. struct ahd_initiator_tinfo *tinfo;
  558. struct ahd_tmode_tstate *tstate;
  559. char channel = starget->channel + 'A';
  560. ahd_lock(ahd, &flags);
  561. BUG_ON(*ahd_targp != NULL);
  562. *ahd_targp = starget;
  563. if (sc) {
  564. int flags = sc->device_flags[starget->id];
  565. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  566. starget->id, &tstate);
  567. if ((flags & CFPACKETIZED) == 0) {
  568. /* don't negotiate packetized (IU) transfers */
  569. spi_max_iu(starget) = 0;
  570. } else {
  571. if ((ahd->features & AHD_RTI) == 0)
  572. spi_rti(starget) = 0;
  573. }
  574. if ((flags & CFQAS) == 0)
  575. spi_max_qas(starget) = 0;
  576. /* Transinfo values have been set to BIOS settings */
  577. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  578. spi_min_period(starget) = tinfo->user.period;
  579. spi_max_offset(starget) = tinfo->user.offset;
  580. }
  581. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  582. starget->id, &tstate);
  583. ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
  584. CAM_LUN_WILDCARD, channel,
  585. ROLE_INITIATOR);
  586. ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
  587. AHD_TRANS_GOAL, /*paused*/FALSE);
  588. ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  589. AHD_TRANS_GOAL, /*paused*/FALSE);
  590. ahd_unlock(ahd, &flags);
  591. return 0;
  592. }
  593. static void
  594. ahd_linux_target_destroy(struct scsi_target *starget)
  595. {
  596. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  597. *ahd_targp = NULL;
  598. }
  599. static int
  600. ahd_linux_slave_alloc(struct scsi_device *sdev)
  601. {
  602. struct ahd_softc *ahd =
  603. *((struct ahd_softc **)sdev->host->hostdata);
  604. struct ahd_linux_device *dev;
  605. if (bootverbose)
  606. printk("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
  607. dev = scsi_transport_device_data(sdev);
  608. memset(dev, 0, sizeof(*dev));
  609. /*
  610. * We start out life using untagged
  611. * transactions of which we allow one.
  612. */
  613. dev->openings = 1;
  614. /*
  615. * Set maxtags to 0. This will be changed if we
  616. * later determine that we are dealing with
  617. * a tagged queuing capable device.
  618. */
  619. dev->maxtags = 0;
  620. return (0);
  621. }
  622. static int
  623. ahd_linux_slave_configure(struct scsi_device *sdev)
  624. {
  625. struct ahd_softc *ahd;
  626. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  627. if (bootverbose)
  628. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  629. ahd_linux_device_queue_depth(sdev);
  630. /* Initial Domain Validation */
  631. if (!spi_initial_dv(sdev->sdev_target))
  632. spi_dv_device(sdev);
  633. return 0;
  634. }
  635. #if defined(__i386__)
  636. /*
  637. * Return the disk geometry for the given SCSI device.
  638. */
  639. static int
  640. ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  641. sector_t capacity, int geom[])
  642. {
  643. uint8_t *bh;
  644. int heads;
  645. int sectors;
  646. int cylinders;
  647. int ret;
  648. int extended;
  649. struct ahd_softc *ahd;
  650. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  651. bh = scsi_bios_ptable(bdev);
  652. if (bh) {
  653. ret = scsi_partsize(bh, capacity,
  654. &geom[2], &geom[0], &geom[1]);
  655. kfree(bh);
  656. if (ret != -1)
  657. return (ret);
  658. }
  659. heads = 64;
  660. sectors = 32;
  661. cylinders = aic_sector_div(capacity, heads, sectors);
  662. if (aic79xx_extended != 0)
  663. extended = 1;
  664. else
  665. extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
  666. if (extended && cylinders >= 1024) {
  667. heads = 255;
  668. sectors = 63;
  669. cylinders = aic_sector_div(capacity, heads, sectors);
  670. }
  671. geom[0] = heads;
  672. geom[1] = sectors;
  673. geom[2] = cylinders;
  674. return (0);
  675. }
  676. #endif
  677. /*
  678. * Abort the current SCSI command(s).
  679. */
  680. static int
  681. ahd_linux_abort(struct scsi_cmnd *cmd)
  682. {
  683. int error;
  684. error = ahd_linux_queue_abort_cmd(cmd);
  685. return error;
  686. }
  687. /*
  688. * Attempt to send a target reset message to the device that timed out.
  689. */
  690. static int
  691. ahd_linux_dev_reset(struct scsi_cmnd *cmd)
  692. {
  693. struct ahd_softc *ahd;
  694. struct ahd_linux_device *dev;
  695. struct scb *reset_scb;
  696. u_int cdb_byte;
  697. int retval = SUCCESS;
  698. int paused;
  699. int wait;
  700. struct ahd_initiator_tinfo *tinfo;
  701. struct ahd_tmode_tstate *tstate;
  702. unsigned long flags;
  703. DECLARE_COMPLETION_ONSTACK(done);
  704. reset_scb = NULL;
  705. paused = FALSE;
  706. wait = FALSE;
  707. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  708. scmd_printk(KERN_INFO, cmd,
  709. "Attempting to queue a TARGET RESET message:");
  710. printk("CDB:");
  711. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  712. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  713. printk("\n");
  714. /*
  715. * Determine if we currently own this command.
  716. */
  717. dev = scsi_transport_device_data(cmd->device);
  718. if (dev == NULL) {
  719. /*
  720. * No target device for this command exists,
  721. * so we must not still own the command.
  722. */
  723. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  724. return SUCCESS;
  725. }
  726. /*
  727. * Generate us a new SCB
  728. */
  729. reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX);
  730. if (!reset_scb) {
  731. scmd_printk(KERN_INFO, cmd, "No SCB available\n");
  732. return FAILED;
  733. }
  734. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  735. cmd->device->id, &tstate);
  736. reset_scb->io_ctx = cmd;
  737. reset_scb->platform_data->dev = dev;
  738. reset_scb->sg_count = 0;
  739. ahd_set_residual(reset_scb, 0);
  740. ahd_set_sense_residual(reset_scb, 0);
  741. reset_scb->platform_data->xfer_len = 0;
  742. reset_scb->hscb->control = 0;
  743. reset_scb->hscb->scsiid = BUILD_SCSIID(ahd,cmd);
  744. reset_scb->hscb->lun = cmd->device->lun;
  745. reset_scb->hscb->cdb_len = 0;
  746. reset_scb->hscb->task_management = SIU_TASKMGMT_LUN_RESET;
  747. reset_scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
  748. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  749. reset_scb->flags |= SCB_PACKETIZED;
  750. } else {
  751. reset_scb->hscb->control |= MK_MESSAGE;
  752. }
  753. dev->openings--;
  754. dev->active++;
  755. dev->commands_issued++;
  756. ahd_lock(ahd, &flags);
  757. LIST_INSERT_HEAD(&ahd->pending_scbs, reset_scb, pending_links);
  758. ahd_queue_scb(ahd, reset_scb);
  759. ahd->platform_data->eh_done = &done;
  760. ahd_unlock(ahd, &flags);
  761. printk("%s: Device reset code sleeping\n", ahd_name(ahd));
  762. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  763. ahd_lock(ahd, &flags);
  764. ahd->platform_data->eh_done = NULL;
  765. ahd_unlock(ahd, &flags);
  766. printk("%s: Device reset timer expired (active %d)\n",
  767. ahd_name(ahd), dev->active);
  768. retval = FAILED;
  769. }
  770. printk("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
  771. return (retval);
  772. }
  773. /*
  774. * Reset the SCSI bus.
  775. */
  776. static int
  777. ahd_linux_bus_reset(struct scsi_cmnd *cmd)
  778. {
  779. struct ahd_softc *ahd;
  780. int found;
  781. unsigned long flags;
  782. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  783. #ifdef AHD_DEBUG
  784. if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
  785. printk("%s: Bus reset called for cmd %p\n",
  786. ahd_name(ahd), cmd);
  787. #endif
  788. ahd_lock(ahd, &flags);
  789. found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
  790. /*initiate reset*/TRUE);
  791. ahd_unlock(ahd, &flags);
  792. if (bootverbose)
  793. printk("%s: SCSI bus reset delivered. "
  794. "%d SCBs aborted.\n", ahd_name(ahd), found);
  795. return (SUCCESS);
  796. }
  797. struct scsi_host_template aic79xx_driver_template = {
  798. .module = THIS_MODULE,
  799. .name = "aic79xx",
  800. .proc_name = "aic79xx",
  801. .show_info = ahd_linux_show_info,
  802. .write_info = ahd_proc_write_seeprom,
  803. .info = ahd_linux_info,
  804. .queuecommand = ahd_linux_queue,
  805. .eh_abort_handler = ahd_linux_abort,
  806. .eh_device_reset_handler = ahd_linux_dev_reset,
  807. .eh_bus_reset_handler = ahd_linux_bus_reset,
  808. #if defined(__i386__)
  809. .bios_param = ahd_linux_biosparam,
  810. #endif
  811. .can_queue = AHD_MAX_QUEUE,
  812. .this_id = -1,
  813. .max_sectors = 8192,
  814. .cmd_per_lun = 2,
  815. .use_clustering = ENABLE_CLUSTERING,
  816. .slave_alloc = ahd_linux_slave_alloc,
  817. .slave_configure = ahd_linux_slave_configure,
  818. .target_alloc = ahd_linux_target_alloc,
  819. .target_destroy = ahd_linux_target_destroy,
  820. };
  821. /******************************** Bus DMA *************************************/
  822. int
  823. ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
  824. bus_size_t alignment, bus_size_t boundary,
  825. dma_addr_t lowaddr, dma_addr_t highaddr,
  826. bus_dma_filter_t *filter, void *filterarg,
  827. bus_size_t maxsize, int nsegments,
  828. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  829. {
  830. bus_dma_tag_t dmat;
  831. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  832. if (dmat == NULL)
  833. return (ENOMEM);
  834. /*
  835. * Linux is very simplistic about DMA memory. For now don't
  836. * maintain all specification information. Once Linux supplies
  837. * better facilities for doing these operations, or the
  838. * needs of this particular driver change, we might need to do
  839. * more here.
  840. */
  841. dmat->alignment = alignment;
  842. dmat->boundary = boundary;
  843. dmat->maxsize = maxsize;
  844. *ret_tag = dmat;
  845. return (0);
  846. }
  847. void
  848. ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
  849. {
  850. kfree(dmat);
  851. }
  852. int
  853. ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
  854. int flags, bus_dmamap_t *mapp)
  855. {
  856. *vaddr = pci_alloc_consistent(ahd->dev_softc,
  857. dmat->maxsize, mapp);
  858. if (*vaddr == NULL)
  859. return (ENOMEM);
  860. return(0);
  861. }
  862. void
  863. ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
  864. void* vaddr, bus_dmamap_t map)
  865. {
  866. pci_free_consistent(ahd->dev_softc, dmat->maxsize,
  867. vaddr, map);
  868. }
  869. int
  870. ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
  871. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  872. void *cb_arg, int flags)
  873. {
  874. /*
  875. * Assume for now that this will only be used during
  876. * initialization and not for per-transaction buffer mapping.
  877. */
  878. bus_dma_segment_t stack_sg;
  879. stack_sg.ds_addr = map;
  880. stack_sg.ds_len = dmat->maxsize;
  881. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  882. return (0);
  883. }
  884. void
  885. ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  886. {
  887. }
  888. int
  889. ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  890. {
  891. /* Nothing to do */
  892. return (0);
  893. }
  894. /********************* Platform Dependent Functions ***************************/
  895. static void
  896. ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
  897. {
  898. if ((instance >= 0)
  899. && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
  900. uint8_t *iocell_info;
  901. iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
  902. iocell_info[index] = value & 0xFFFF;
  903. if (bootverbose)
  904. printk("iocell[%d:%ld] = %d\n", instance, index, value);
  905. }
  906. }
  907. static void
  908. ahd_linux_setup_tag_info_global(char *p)
  909. {
  910. int tags, i, j;
  911. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  912. printk("Setting Global Tags= %d\n", tags);
  913. for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
  914. for (j = 0; j < AHD_NUM_TARGETS; j++) {
  915. aic79xx_tag_info[i].tag_commands[j] = tags;
  916. }
  917. }
  918. }
  919. static void
  920. ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  921. {
  922. if ((instance >= 0) && (targ >= 0)
  923. && (instance < ARRAY_SIZE(aic79xx_tag_info))
  924. && (targ < AHD_NUM_TARGETS)) {
  925. aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
  926. if (bootverbose)
  927. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  928. }
  929. }
  930. static char *
  931. ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  932. void (*callback)(u_long, int, int, int32_t),
  933. u_long callback_arg)
  934. {
  935. char *tok_end;
  936. char *tok_end2;
  937. int i;
  938. int instance;
  939. int targ;
  940. int done;
  941. char tok_list[] = {'.', ',', '{', '}', '\0'};
  942. /* All options use a ':' name/arg separator */
  943. if (*opt_arg != ':')
  944. return (opt_arg);
  945. opt_arg++;
  946. instance = -1;
  947. targ = -1;
  948. done = FALSE;
  949. /*
  950. * Restore separator that may be in
  951. * the middle of our option argument.
  952. */
  953. tok_end = strchr(opt_arg, '\0');
  954. if (tok_end < end)
  955. *tok_end = ',';
  956. while (!done) {
  957. switch (*opt_arg) {
  958. case '{':
  959. if (instance == -1) {
  960. instance = 0;
  961. } else {
  962. if (depth > 1) {
  963. if (targ == -1)
  964. targ = 0;
  965. } else {
  966. printk("Malformed Option %s\n",
  967. opt_name);
  968. done = TRUE;
  969. }
  970. }
  971. opt_arg++;
  972. break;
  973. case '}':
  974. if (targ != -1)
  975. targ = -1;
  976. else if (instance != -1)
  977. instance = -1;
  978. opt_arg++;
  979. break;
  980. case ',':
  981. case '.':
  982. if (instance == -1)
  983. done = TRUE;
  984. else if (targ >= 0)
  985. targ++;
  986. else if (instance >= 0)
  987. instance++;
  988. opt_arg++;
  989. break;
  990. case '\0':
  991. done = TRUE;
  992. break;
  993. default:
  994. tok_end = end;
  995. for (i = 0; tok_list[i]; i++) {
  996. tok_end2 = strchr(opt_arg, tok_list[i]);
  997. if ((tok_end2) && (tok_end2 < tok_end))
  998. tok_end = tok_end2;
  999. }
  1000. callback(callback_arg, instance, targ,
  1001. simple_strtol(opt_arg, NULL, 0));
  1002. opt_arg = tok_end;
  1003. break;
  1004. }
  1005. }
  1006. return (opt_arg);
  1007. }
  1008. /*
  1009. * Handle Linux boot parameters. This routine allows for assigning a value
  1010. * to a parameter with a ':' between the parameter and the value.
  1011. * ie. aic79xx=stpwlev:1,extended
  1012. */
  1013. static int
  1014. aic79xx_setup(char *s)
  1015. {
  1016. int i, n;
  1017. char *p;
  1018. char *end;
  1019. static const struct {
  1020. const char *name;
  1021. uint32_t *flag;
  1022. } options[] = {
  1023. { "extended", &aic79xx_extended },
  1024. { "no_reset", &aic79xx_no_reset },
  1025. { "verbose", &aic79xx_verbose },
  1026. { "allow_memio", &aic79xx_allow_memio},
  1027. #ifdef AHD_DEBUG
  1028. { "debug", &ahd_debug },
  1029. #endif
  1030. { "periodic_otag", &aic79xx_periodic_otag },
  1031. { "pci_parity", &aic79xx_pci_parity },
  1032. { "seltime", &aic79xx_seltime },
  1033. { "tag_info", NULL },
  1034. { "global_tag_depth", NULL},
  1035. { "slewrate", NULL },
  1036. { "precomp", NULL },
  1037. { "amplitude", NULL },
  1038. { "slowcrc", &aic79xx_slowcrc },
  1039. };
  1040. end = strchr(s, '\0');
  1041. /*
  1042. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  1043. * will never be 0 in this case.
  1044. */
  1045. n = 0;
  1046. while ((p = strsep(&s, ",.")) != NULL) {
  1047. if (*p == '\0')
  1048. continue;
  1049. for (i = 0; i < ARRAY_SIZE(options); i++) {
  1050. n = strlen(options[i].name);
  1051. if (strncmp(options[i].name, p, n) == 0)
  1052. break;
  1053. }
  1054. if (i == ARRAY_SIZE(options))
  1055. continue;
  1056. if (strncmp(p, "global_tag_depth", n) == 0) {
  1057. ahd_linux_setup_tag_info_global(p + n);
  1058. } else if (strncmp(p, "tag_info", n) == 0) {
  1059. s = ahd_parse_brace_option("tag_info", p + n, end,
  1060. 2, ahd_linux_setup_tag_info, 0);
  1061. } else if (strncmp(p, "slewrate", n) == 0) {
  1062. s = ahd_parse_brace_option("slewrate",
  1063. p + n, end, 1, ahd_linux_setup_iocell_info,
  1064. AIC79XX_SLEWRATE_INDEX);
  1065. } else if (strncmp(p, "precomp", n) == 0) {
  1066. s = ahd_parse_brace_option("precomp",
  1067. p + n, end, 1, ahd_linux_setup_iocell_info,
  1068. AIC79XX_PRECOMP_INDEX);
  1069. } else if (strncmp(p, "amplitude", n) == 0) {
  1070. s = ahd_parse_brace_option("amplitude",
  1071. p + n, end, 1, ahd_linux_setup_iocell_info,
  1072. AIC79XX_AMPLITUDE_INDEX);
  1073. } else if (p[n] == ':') {
  1074. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1075. } else if (!strncmp(p, "verbose", n)) {
  1076. *(options[i].flag) = 1;
  1077. } else {
  1078. *(options[i].flag) ^= 0xFFFFFFFF;
  1079. }
  1080. }
  1081. return 1;
  1082. }
  1083. __setup("aic79xx=", aic79xx_setup);
  1084. uint32_t aic79xx_verbose;
  1085. int
  1086. ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
  1087. {
  1088. char buf[80];
  1089. struct Scsi_Host *host;
  1090. char *new_name;
  1091. u_long s;
  1092. int retval;
  1093. template->name = ahd->description;
  1094. host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
  1095. if (host == NULL)
  1096. return (ENOMEM);
  1097. *((struct ahd_softc **)host->hostdata) = ahd;
  1098. ahd->platform_data->host = host;
  1099. host->can_queue = AHD_MAX_QUEUE;
  1100. host->cmd_per_lun = 2;
  1101. host->sg_tablesize = AHD_NSEG;
  1102. host->this_id = ahd->our_id;
  1103. host->irq = ahd->platform_data->irq;
  1104. host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
  1105. host->max_lun = AHD_NUM_LUNS;
  1106. host->max_channel = 0;
  1107. host->sg_tablesize = AHD_NSEG;
  1108. ahd_lock(ahd, &s);
  1109. ahd_set_unit(ahd, ahd_linux_unit++);
  1110. ahd_unlock(ahd, &s);
  1111. sprintf(buf, "scsi%d", host->host_no);
  1112. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  1113. if (new_name != NULL) {
  1114. strcpy(new_name, buf);
  1115. ahd_set_name(ahd, new_name);
  1116. }
  1117. host->unique_id = ahd->unit;
  1118. ahd_linux_initialize_scsi_bus(ahd);
  1119. ahd_intr_enable(ahd, TRUE);
  1120. host->transportt = ahd_linux_transport_template;
  1121. retval = scsi_add_host(host, &ahd->dev_softc->dev);
  1122. if (retval) {
  1123. printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
  1124. scsi_host_put(host);
  1125. return retval;
  1126. }
  1127. scsi_scan_host(host);
  1128. return 0;
  1129. }
  1130. /*
  1131. * Place the SCSI bus into a known state by either resetting it,
  1132. * or forcing transfer negotiations on the next command to any
  1133. * target.
  1134. */
  1135. static void
  1136. ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
  1137. {
  1138. u_int target_id;
  1139. u_int numtarg;
  1140. unsigned long s;
  1141. target_id = 0;
  1142. numtarg = 0;
  1143. if (aic79xx_no_reset != 0)
  1144. ahd->flags &= ~AHD_RESET_BUS_A;
  1145. if ((ahd->flags & AHD_RESET_BUS_A) != 0)
  1146. ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
  1147. else
  1148. numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
  1149. ahd_lock(ahd, &s);
  1150. /*
  1151. * Force negotiation to async for all targets that
  1152. * will not see an initial bus reset.
  1153. */
  1154. for (; target_id < numtarg; target_id++) {
  1155. struct ahd_devinfo devinfo;
  1156. struct ahd_initiator_tinfo *tinfo;
  1157. struct ahd_tmode_tstate *tstate;
  1158. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1159. target_id, &tstate);
  1160. ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
  1161. CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
  1162. ahd_update_neg_request(ahd, &devinfo, tstate,
  1163. tinfo, AHD_NEG_ALWAYS);
  1164. }
  1165. ahd_unlock(ahd, &s);
  1166. /* Give the bus some time to recover */
  1167. if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
  1168. ahd_freeze_simq(ahd);
  1169. msleep(AIC79XX_RESET_DELAY);
  1170. ahd_release_simq(ahd);
  1171. }
  1172. }
  1173. int
  1174. ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
  1175. {
  1176. ahd->platform_data =
  1177. kmalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
  1178. if (ahd->platform_data == NULL)
  1179. return (ENOMEM);
  1180. memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
  1181. ahd->platform_data->irq = AHD_LINUX_NOIRQ;
  1182. ahd_lockinit(ahd);
  1183. ahd->seltime = (aic79xx_seltime & 0x3) << 4;
  1184. return (0);
  1185. }
  1186. void
  1187. ahd_platform_free(struct ahd_softc *ahd)
  1188. {
  1189. struct scsi_target *starget;
  1190. int i;
  1191. if (ahd->platform_data != NULL) {
  1192. /* destroy all of the device and target objects */
  1193. for (i = 0; i < AHD_NUM_TARGETS; i++) {
  1194. starget = ahd->platform_data->starget[i];
  1195. if (starget != NULL) {
  1196. ahd->platform_data->starget[i] = NULL;
  1197. }
  1198. }
  1199. if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
  1200. free_irq(ahd->platform_data->irq, ahd);
  1201. if (ahd->tags[0] == BUS_SPACE_PIO
  1202. && ahd->bshs[0].ioport != 0)
  1203. release_region(ahd->bshs[0].ioport, 256);
  1204. if (ahd->tags[1] == BUS_SPACE_PIO
  1205. && ahd->bshs[1].ioport != 0)
  1206. release_region(ahd->bshs[1].ioport, 256);
  1207. if (ahd->tags[0] == BUS_SPACE_MEMIO
  1208. && ahd->bshs[0].maddr != NULL) {
  1209. iounmap(ahd->bshs[0].maddr);
  1210. release_mem_region(ahd->platform_data->mem_busaddr,
  1211. 0x1000);
  1212. }
  1213. if (ahd->platform_data->host)
  1214. scsi_host_put(ahd->platform_data->host);
  1215. kfree(ahd->platform_data);
  1216. }
  1217. }
  1218. void
  1219. ahd_platform_init(struct ahd_softc *ahd)
  1220. {
  1221. /*
  1222. * Lookup and commit any modified IO Cell options.
  1223. */
  1224. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  1225. const struct ahd_linux_iocell_opts *iocell_opts;
  1226. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  1227. if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
  1228. AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
  1229. if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
  1230. AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
  1231. if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
  1232. AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
  1233. }
  1234. }
  1235. void
  1236. ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
  1237. {
  1238. ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
  1239. SCB_GET_CHANNEL(ahd, scb),
  1240. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1241. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1242. }
  1243. void
  1244. ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
  1245. struct ahd_devinfo *devinfo, ahd_queue_alg alg)
  1246. {
  1247. struct ahd_linux_device *dev;
  1248. int was_queuing;
  1249. int now_queuing;
  1250. if (sdev == NULL)
  1251. return;
  1252. dev = scsi_transport_device_data(sdev);
  1253. if (dev == NULL)
  1254. return;
  1255. was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
  1256. switch (alg) {
  1257. default:
  1258. case AHD_QUEUE_NONE:
  1259. now_queuing = 0;
  1260. break;
  1261. case AHD_QUEUE_BASIC:
  1262. now_queuing = AHD_DEV_Q_BASIC;
  1263. break;
  1264. case AHD_QUEUE_TAGGED:
  1265. now_queuing = AHD_DEV_Q_TAGGED;
  1266. break;
  1267. }
  1268. if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
  1269. && (was_queuing != now_queuing)
  1270. && (dev->active != 0)) {
  1271. dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
  1272. dev->qfrozen++;
  1273. }
  1274. dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
  1275. if (now_queuing) {
  1276. u_int usertags;
  1277. usertags = ahd_linux_user_tagdepth(ahd, devinfo);
  1278. if (!was_queuing) {
  1279. /*
  1280. * Start out aggressively and allow our
  1281. * dynamic queue depth algorithm to take
  1282. * care of the rest.
  1283. */
  1284. dev->maxtags = usertags;
  1285. dev->openings = dev->maxtags - dev->active;
  1286. }
  1287. if (dev->maxtags == 0) {
  1288. /*
  1289. * Queueing is disabled by the user.
  1290. */
  1291. dev->openings = 1;
  1292. } else if (alg == AHD_QUEUE_TAGGED) {
  1293. dev->flags |= AHD_DEV_Q_TAGGED;
  1294. if (aic79xx_periodic_otag != 0)
  1295. dev->flags |= AHD_DEV_PERIODIC_OTAG;
  1296. } else
  1297. dev->flags |= AHD_DEV_Q_BASIC;
  1298. } else {
  1299. /* We can only have one opening. */
  1300. dev->maxtags = 0;
  1301. dev->openings = 1 - dev->active;
  1302. }
  1303. switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
  1304. case AHD_DEV_Q_BASIC:
  1305. scsi_set_tag_type(sdev, MSG_SIMPLE_TASK);
  1306. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1307. break;
  1308. case AHD_DEV_Q_TAGGED:
  1309. scsi_set_tag_type(sdev, MSG_ORDERED_TASK);
  1310. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1311. break;
  1312. default:
  1313. /*
  1314. * We allow the OS to queue 2 untagged transactions to
  1315. * us at any time even though we can only execute them
  1316. * serially on the controller/device. This should
  1317. * remove some latency.
  1318. */
  1319. scsi_deactivate_tcq(sdev, 1);
  1320. break;
  1321. }
  1322. }
  1323. int
  1324. ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
  1325. int lun, u_int tag, role_t role, uint32_t status)
  1326. {
  1327. return 0;
  1328. }
  1329. static u_int
  1330. ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
  1331. {
  1332. static int warned_user;
  1333. u_int tags;
  1334. tags = 0;
  1335. if ((ahd->user_discenable & devinfo->target_mask) != 0) {
  1336. if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
  1337. if (warned_user == 0) {
  1338. printk(KERN_WARNING
  1339. "aic79xx: WARNING: Insufficient tag_info instances\n"
  1340. "aic79xx: for installed controllers. Using defaults\n"
  1341. "aic79xx: Please update the aic79xx_tag_info array in\n"
  1342. "aic79xx: the aic79xx_osm.c source file.\n");
  1343. warned_user++;
  1344. }
  1345. tags = AHD_MAX_QUEUE;
  1346. } else {
  1347. adapter_tag_info_t *tag_info;
  1348. tag_info = &aic79xx_tag_info[ahd->unit];
  1349. tags = tag_info->tag_commands[devinfo->target_offset];
  1350. if (tags > AHD_MAX_QUEUE)
  1351. tags = AHD_MAX_QUEUE;
  1352. }
  1353. }
  1354. return (tags);
  1355. }
  1356. /*
  1357. * Determines the queue depth for a given device.
  1358. */
  1359. static void
  1360. ahd_linux_device_queue_depth(struct scsi_device *sdev)
  1361. {
  1362. struct ahd_devinfo devinfo;
  1363. u_int tags;
  1364. struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
  1365. ahd_compile_devinfo(&devinfo,
  1366. ahd->our_id,
  1367. sdev->sdev_target->id, sdev->lun,
  1368. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1369. ROLE_INITIATOR);
  1370. tags = ahd_linux_user_tagdepth(ahd, &devinfo);
  1371. if (tags != 0 && sdev->tagged_supported != 0) {
  1372. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
  1373. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1374. devinfo.lun, AC_TRANSFER_NEG);
  1375. ahd_print_devinfo(ahd, &devinfo);
  1376. printk("Tagged Queuing enabled. Depth %d\n", tags);
  1377. } else {
  1378. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
  1379. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1380. devinfo.lun, AC_TRANSFER_NEG);
  1381. }
  1382. }
  1383. static int
  1384. ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
  1385. struct scsi_cmnd *cmd)
  1386. {
  1387. struct scb *scb;
  1388. struct hardware_scb *hscb;
  1389. struct ahd_initiator_tinfo *tinfo;
  1390. struct ahd_tmode_tstate *tstate;
  1391. u_int col_idx;
  1392. uint16_t mask;
  1393. unsigned long flags;
  1394. int nseg;
  1395. nseg = scsi_dma_map(cmd);
  1396. if (nseg < 0)
  1397. return SCSI_MLQUEUE_HOST_BUSY;
  1398. ahd_lock(ahd, &flags);
  1399. /*
  1400. * Get an scb to use.
  1401. */
  1402. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1403. cmd->device->id, &tstate);
  1404. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
  1405. || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  1406. col_idx = AHD_NEVER_COL_IDX;
  1407. } else {
  1408. col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
  1409. cmd->device->lun);
  1410. }
  1411. if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
  1412. ahd->flags |= AHD_RESOURCE_SHORTAGE;
  1413. ahd_unlock(ahd, &flags);
  1414. scsi_dma_unmap(cmd);
  1415. return SCSI_MLQUEUE_HOST_BUSY;
  1416. }
  1417. scb->io_ctx = cmd;
  1418. scb->platform_data->dev = dev;
  1419. hscb = scb->hscb;
  1420. cmd->host_scribble = (char *)scb;
  1421. /*
  1422. * Fill out basics of the HSCB.
  1423. */
  1424. hscb->control = 0;
  1425. hscb->scsiid = BUILD_SCSIID(ahd, cmd);
  1426. hscb->lun = cmd->device->lun;
  1427. scb->hscb->task_management = 0;
  1428. mask = SCB_GET_TARGET_MASK(ahd, scb);
  1429. if ((ahd->user_discenable & mask) != 0)
  1430. hscb->control |= DISCENB;
  1431. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
  1432. scb->flags |= SCB_PACKETIZED;
  1433. if ((tstate->auto_negotiate & mask) != 0) {
  1434. scb->flags |= SCB_AUTO_NEGOTIATE;
  1435. scb->hscb->control |= MK_MESSAGE;
  1436. }
  1437. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
  1438. int msg_bytes;
  1439. uint8_t tag_msgs[2];
  1440. msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
  1441. if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
  1442. hscb->control |= tag_msgs[0];
  1443. if (tag_msgs[0] == MSG_ORDERED_TASK)
  1444. dev->commands_since_idle_or_otag = 0;
  1445. } else
  1446. if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
  1447. && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
  1448. hscb->control |= MSG_ORDERED_TASK;
  1449. dev->commands_since_idle_or_otag = 0;
  1450. } else {
  1451. hscb->control |= MSG_SIMPLE_TASK;
  1452. }
  1453. }
  1454. hscb->cdb_len = cmd->cmd_len;
  1455. memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
  1456. scb->platform_data->xfer_len = 0;
  1457. ahd_set_residual(scb, 0);
  1458. ahd_set_sense_residual(scb, 0);
  1459. scb->sg_count = 0;
  1460. if (nseg > 0) {
  1461. void *sg = scb->sg_list;
  1462. struct scatterlist *cur_seg;
  1463. int i;
  1464. scb->platform_data->xfer_len = 0;
  1465. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1466. dma_addr_t addr;
  1467. bus_size_t len;
  1468. addr = sg_dma_address(cur_seg);
  1469. len = sg_dma_len(cur_seg);
  1470. scb->platform_data->xfer_len += len;
  1471. sg = ahd_sg_setup(ahd, scb, sg, addr, len,
  1472. i == (nseg - 1));
  1473. }
  1474. }
  1475. LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
  1476. dev->openings--;
  1477. dev->active++;
  1478. dev->commands_issued++;
  1479. if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
  1480. dev->commands_since_idle_or_otag++;
  1481. scb->flags |= SCB_ACTIVE;
  1482. ahd_queue_scb(ahd, scb);
  1483. ahd_unlock(ahd, &flags);
  1484. return 0;
  1485. }
  1486. /*
  1487. * SCSI controller interrupt handler.
  1488. */
  1489. irqreturn_t
  1490. ahd_linux_isr(int irq, void *dev_id)
  1491. {
  1492. struct ahd_softc *ahd;
  1493. u_long flags;
  1494. int ours;
  1495. ahd = (struct ahd_softc *) dev_id;
  1496. ahd_lock(ahd, &flags);
  1497. ours = ahd_intr(ahd);
  1498. ahd_unlock(ahd, &flags);
  1499. return IRQ_RETVAL(ours);
  1500. }
  1501. void
  1502. ahd_send_async(struct ahd_softc *ahd, char channel,
  1503. u_int target, u_int lun, ac_code code)
  1504. {
  1505. switch (code) {
  1506. case AC_TRANSFER_NEG:
  1507. {
  1508. struct scsi_target *starget;
  1509. struct ahd_initiator_tinfo *tinfo;
  1510. struct ahd_tmode_tstate *tstate;
  1511. unsigned int target_ppr_options;
  1512. BUG_ON(target == CAM_TARGET_WILDCARD);
  1513. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  1514. target, &tstate);
  1515. /*
  1516. * Don't bother reporting results while
  1517. * negotiations are still pending.
  1518. */
  1519. if (tinfo->curr.period != tinfo->goal.period
  1520. || tinfo->curr.width != tinfo->goal.width
  1521. || tinfo->curr.offset != tinfo->goal.offset
  1522. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1523. if (bootverbose == 0)
  1524. break;
  1525. /*
  1526. * Don't bother reporting results that
  1527. * are identical to those last reported.
  1528. */
  1529. starget = ahd->platform_data->starget[target];
  1530. if (starget == NULL)
  1531. break;
  1532. target_ppr_options =
  1533. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1534. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1535. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
  1536. + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
  1537. + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
  1538. + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
  1539. + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
  1540. + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
  1541. if (tinfo->curr.period == spi_period(starget)
  1542. && tinfo->curr.width == spi_width(starget)
  1543. && tinfo->curr.offset == spi_offset(starget)
  1544. && tinfo->curr.ppr_options == target_ppr_options)
  1545. if (bootverbose == 0)
  1546. break;
  1547. spi_period(starget) = tinfo->curr.period;
  1548. spi_width(starget) = tinfo->curr.width;
  1549. spi_offset(starget) = tinfo->curr.offset;
  1550. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1551. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1552. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1553. spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
  1554. spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
  1555. spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
  1556. spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
  1557. spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
  1558. spi_display_xfer_agreement(starget);
  1559. break;
  1560. }
  1561. case AC_SENT_BDR:
  1562. {
  1563. WARN_ON(lun != CAM_LUN_WILDCARD);
  1564. scsi_report_device_reset(ahd->platform_data->host,
  1565. channel - 'A', target);
  1566. break;
  1567. }
  1568. case AC_BUS_RESET:
  1569. if (ahd->platform_data->host != NULL) {
  1570. scsi_report_bus_reset(ahd->platform_data->host,
  1571. channel - 'A');
  1572. }
  1573. break;
  1574. default:
  1575. panic("ahd_send_async: Unexpected async event");
  1576. }
  1577. }
  1578. /*
  1579. * Calls the higher level scsi done function and frees the scb.
  1580. */
  1581. void
  1582. ahd_done(struct ahd_softc *ahd, struct scb *scb)
  1583. {
  1584. struct scsi_cmnd *cmd;
  1585. struct ahd_linux_device *dev;
  1586. if ((scb->flags & SCB_ACTIVE) == 0) {
  1587. printk("SCB %d done'd twice\n", SCB_GET_TAG(scb));
  1588. ahd_dump_card_state(ahd);
  1589. panic("Stopping for safety");
  1590. }
  1591. LIST_REMOVE(scb, pending_links);
  1592. cmd = scb->io_ctx;
  1593. dev = scb->platform_data->dev;
  1594. dev->active--;
  1595. dev->openings++;
  1596. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1597. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1598. dev->qfrozen--;
  1599. }
  1600. ahd_linux_unmap_scb(ahd, scb);
  1601. /*
  1602. * Guard against stale sense data.
  1603. * The Linux mid-layer assumes that sense
  1604. * was retrieved anytime the first byte of
  1605. * the sense buffer looks "sane".
  1606. */
  1607. cmd->sense_buffer[0] = 0;
  1608. if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1609. uint32_t amount_xferred;
  1610. amount_xferred =
  1611. ahd_get_transfer_length(scb) - ahd_get_residual(scb);
  1612. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1613. #ifdef AHD_DEBUG
  1614. if ((ahd_debug & AHD_SHOW_MISC) != 0) {
  1615. ahd_print_path(ahd, scb);
  1616. printk("Set CAM_UNCOR_PARITY\n");
  1617. }
  1618. #endif
  1619. ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1620. #ifdef AHD_REPORT_UNDERFLOWS
  1621. /*
  1622. * This code is disabled by default as some
  1623. * clients of the SCSI system do not properly
  1624. * initialize the underflow parameter. This
  1625. * results in spurious termination of commands
  1626. * that complete as expected (e.g. underflow is
  1627. * allowed as command can return variable amounts
  1628. * of data.
  1629. */
  1630. } else if (amount_xferred < scb->io_ctx->underflow) {
  1631. u_int i;
  1632. ahd_print_path(ahd, scb);
  1633. printk("CDB:");
  1634. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1635. printk(" 0x%x", scb->io_ctx->cmnd[i]);
  1636. printk("\n");
  1637. ahd_print_path(ahd, scb);
  1638. printk("Saw underflow (%ld of %ld bytes). "
  1639. "Treated as error\n",
  1640. ahd_get_residual(scb),
  1641. ahd_get_transfer_length(scb));
  1642. ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1643. #endif
  1644. } else {
  1645. ahd_set_transaction_status(scb, CAM_REQ_CMP);
  1646. }
  1647. } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1648. ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
  1649. }
  1650. if (dev->openings == 1
  1651. && ahd_get_transaction_status(scb) == CAM_REQ_CMP
  1652. && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1653. dev->tag_success_count++;
  1654. /*
  1655. * Some devices deal with temporary internal resource
  1656. * shortages by returning queue full. When the queue
  1657. * full occurrs, we throttle back. Slowly try to get
  1658. * back to our previous queue depth.
  1659. */
  1660. if ((dev->openings + dev->active) < dev->maxtags
  1661. && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
  1662. dev->tag_success_count = 0;
  1663. dev->openings++;
  1664. }
  1665. if (dev->active == 0)
  1666. dev->commands_since_idle_or_otag = 0;
  1667. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1668. printk("Recovery SCB completes\n");
  1669. if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
  1670. || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1671. ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1672. if (ahd->platform_data->eh_done)
  1673. complete(ahd->platform_data->eh_done);
  1674. }
  1675. ahd_free_scb(ahd, scb);
  1676. ahd_linux_queue_cmd_complete(ahd, cmd);
  1677. }
  1678. static void
  1679. ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
  1680. struct scsi_device *sdev, struct scb *scb)
  1681. {
  1682. struct ahd_devinfo devinfo;
  1683. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  1684. ahd_compile_devinfo(&devinfo,
  1685. ahd->our_id,
  1686. sdev->sdev_target->id, sdev->lun,
  1687. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1688. ROLE_INITIATOR);
  1689. /*
  1690. * We don't currently trust the mid-layer to
  1691. * properly deal with queue full or busy. So,
  1692. * when one occurs, we tell the mid-layer to
  1693. * unconditionally requeue the command to us
  1694. * so that we can retry it ourselves. We also
  1695. * implement our own throttling mechanism so
  1696. * we don't clobber the device with too many
  1697. * commands.
  1698. */
  1699. switch (ahd_get_scsi_status(scb)) {
  1700. default:
  1701. break;
  1702. case SCSI_STATUS_CHECK_COND:
  1703. case SCSI_STATUS_CMD_TERMINATED:
  1704. {
  1705. struct scsi_cmnd *cmd;
  1706. /*
  1707. * Copy sense information to the OS's cmd
  1708. * structure if it is available.
  1709. */
  1710. cmd = scb->io_ctx;
  1711. if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
  1712. struct scsi_status_iu_header *siu;
  1713. u_int sense_size;
  1714. u_int sense_offset;
  1715. if (scb->flags & SCB_SENSE) {
  1716. sense_size = min(sizeof(struct scsi_sense_data)
  1717. - ahd_get_sense_residual(scb),
  1718. (u_long)SCSI_SENSE_BUFFERSIZE);
  1719. sense_offset = 0;
  1720. } else {
  1721. /*
  1722. * Copy only the sense data into the provided
  1723. * buffer.
  1724. */
  1725. siu = (struct scsi_status_iu_header *)
  1726. scb->sense_data;
  1727. sense_size = min_t(size_t,
  1728. scsi_4btoul(siu->sense_length),
  1729. SCSI_SENSE_BUFFERSIZE);
  1730. sense_offset = SIU_SENSE_OFFSET(siu);
  1731. }
  1732. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  1733. memcpy(cmd->sense_buffer,
  1734. ahd_get_sense_buf(ahd, scb)
  1735. + sense_offset, sense_size);
  1736. cmd->result |= (DRIVER_SENSE << 24);
  1737. #ifdef AHD_DEBUG
  1738. if (ahd_debug & AHD_SHOW_SENSE) {
  1739. int i;
  1740. printk("Copied %d bytes of sense data at %d:",
  1741. sense_size, sense_offset);
  1742. for (i = 0; i < sense_size; i++) {
  1743. if ((i & 0xF) == 0)
  1744. printk("\n");
  1745. printk("0x%x ", cmd->sense_buffer[i]);
  1746. }
  1747. printk("\n");
  1748. }
  1749. #endif
  1750. }
  1751. break;
  1752. }
  1753. case SCSI_STATUS_QUEUE_FULL:
  1754. /*
  1755. * By the time the core driver has returned this
  1756. * command, all other commands that were queued
  1757. * to us but not the device have been returned.
  1758. * This ensures that dev->active is equal to
  1759. * the number of commands actually queued to
  1760. * the device.
  1761. */
  1762. dev->tag_success_count = 0;
  1763. if (dev->active != 0) {
  1764. /*
  1765. * Drop our opening count to the number
  1766. * of commands currently outstanding.
  1767. */
  1768. dev->openings = 0;
  1769. #ifdef AHD_DEBUG
  1770. if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
  1771. ahd_print_path(ahd, scb);
  1772. printk("Dropping tag count to %d\n",
  1773. dev->active);
  1774. }
  1775. #endif
  1776. if (dev->active == dev->tags_on_last_queuefull) {
  1777. dev->last_queuefull_same_count++;
  1778. /*
  1779. * If we repeatedly see a queue full
  1780. * at the same queue depth, this
  1781. * device has a fixed number of tag
  1782. * slots. Lock in this tag depth
  1783. * so we stop seeing queue fulls from
  1784. * this device.
  1785. */
  1786. if (dev->last_queuefull_same_count
  1787. == AHD_LOCK_TAGS_COUNT) {
  1788. dev->maxtags = dev->active;
  1789. ahd_print_path(ahd, scb);
  1790. printk("Locking max tag count at %d\n",
  1791. dev->active);
  1792. }
  1793. } else {
  1794. dev->tags_on_last_queuefull = dev->active;
  1795. dev->last_queuefull_same_count = 0;
  1796. }
  1797. ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1798. ahd_set_scsi_status(scb, SCSI_STATUS_OK);
  1799. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1800. (dev->flags & AHD_DEV_Q_BASIC)
  1801. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1802. break;
  1803. }
  1804. /*
  1805. * Drop down to a single opening, and treat this
  1806. * as if the target returned BUSY SCSI status.
  1807. */
  1808. dev->openings = 1;
  1809. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1810. (dev->flags & AHD_DEV_Q_BASIC)
  1811. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1812. ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
  1813. }
  1814. }
  1815. static void
  1816. ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
  1817. {
  1818. int status;
  1819. int new_status = DID_OK;
  1820. int do_fallback = 0;
  1821. int scsi_status;
  1822. /*
  1823. * Map CAM error codes into Linux Error codes. We
  1824. * avoid the conversion so that the DV code has the
  1825. * full error information available when making
  1826. * state change decisions.
  1827. */
  1828. status = ahd_cmd_get_transaction_status(cmd);
  1829. switch (status) {
  1830. case CAM_REQ_INPROG:
  1831. case CAM_REQ_CMP:
  1832. new_status = DID_OK;
  1833. break;
  1834. case CAM_AUTOSENSE_FAIL:
  1835. new_status = DID_ERROR;
  1836. /* Fallthrough */
  1837. case CAM_SCSI_STATUS_ERROR:
  1838. scsi_status = ahd_cmd_get_scsi_status(cmd);
  1839. switch(scsi_status) {
  1840. case SCSI_STATUS_CMD_TERMINATED:
  1841. case SCSI_STATUS_CHECK_COND:
  1842. if ((cmd->result >> 24) != DRIVER_SENSE) {
  1843. do_fallback = 1;
  1844. } else {
  1845. struct scsi_sense_data *sense;
  1846. sense = (struct scsi_sense_data *)
  1847. cmd->sense_buffer;
  1848. if (sense->extra_len >= 5 &&
  1849. (sense->add_sense_code == 0x47
  1850. || sense->add_sense_code == 0x48))
  1851. do_fallback = 1;
  1852. }
  1853. break;
  1854. default:
  1855. break;
  1856. }
  1857. break;
  1858. case CAM_REQ_ABORTED:
  1859. new_status = DID_ABORT;
  1860. break;
  1861. case CAM_BUSY:
  1862. new_status = DID_BUS_BUSY;
  1863. break;
  1864. case CAM_REQ_INVALID:
  1865. case CAM_PATH_INVALID:
  1866. new_status = DID_BAD_TARGET;
  1867. break;
  1868. case CAM_SEL_TIMEOUT:
  1869. new_status = DID_NO_CONNECT;
  1870. break;
  1871. case CAM_SCSI_BUS_RESET:
  1872. case CAM_BDR_SENT:
  1873. new_status = DID_RESET;
  1874. break;
  1875. case CAM_UNCOR_PARITY:
  1876. new_status = DID_PARITY;
  1877. do_fallback = 1;
  1878. break;
  1879. case CAM_CMD_TIMEOUT:
  1880. new_status = DID_TIME_OUT;
  1881. do_fallback = 1;
  1882. break;
  1883. case CAM_REQ_CMP_ERR:
  1884. case CAM_UNEXP_BUSFREE:
  1885. case CAM_DATA_RUN_ERR:
  1886. new_status = DID_ERROR;
  1887. do_fallback = 1;
  1888. break;
  1889. case CAM_UA_ABORT:
  1890. case CAM_NO_HBA:
  1891. case CAM_SEQUENCE_FAIL:
  1892. case CAM_CCB_LEN_ERR:
  1893. case CAM_PROVIDE_FAIL:
  1894. case CAM_REQ_TERMIO:
  1895. case CAM_UNREC_HBA_ERROR:
  1896. case CAM_REQ_TOO_BIG:
  1897. new_status = DID_ERROR;
  1898. break;
  1899. case CAM_REQUEUE_REQ:
  1900. new_status = DID_REQUEUE;
  1901. break;
  1902. default:
  1903. /* We should never get here */
  1904. new_status = DID_ERROR;
  1905. break;
  1906. }
  1907. if (do_fallback) {
  1908. printk("%s: device overrun (status %x) on %d:%d:%d\n",
  1909. ahd_name(ahd), status, cmd->device->channel,
  1910. cmd->device->id, cmd->device->lun);
  1911. }
  1912. ahd_cmd_set_transaction_status(cmd, new_status);
  1913. cmd->scsi_done(cmd);
  1914. }
  1915. static void
  1916. ahd_freeze_simq(struct ahd_softc *ahd)
  1917. {
  1918. scsi_block_requests(ahd->platform_data->host);
  1919. }
  1920. static void
  1921. ahd_release_simq(struct ahd_softc *ahd)
  1922. {
  1923. scsi_unblock_requests(ahd->platform_data->host);
  1924. }
  1925. static int
  1926. ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd)
  1927. {
  1928. struct ahd_softc *ahd;
  1929. struct ahd_linux_device *dev;
  1930. struct scb *pending_scb;
  1931. u_int saved_scbptr;
  1932. u_int active_scbptr;
  1933. u_int last_phase;
  1934. u_int saved_scsiid;
  1935. u_int cdb_byte;
  1936. int retval;
  1937. int was_paused;
  1938. int paused;
  1939. int wait;
  1940. int disconnected;
  1941. ahd_mode_state saved_modes;
  1942. unsigned long flags;
  1943. pending_scb = NULL;
  1944. paused = FALSE;
  1945. wait = FALSE;
  1946. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  1947. scmd_printk(KERN_INFO, cmd,
  1948. "Attempting to queue an ABORT message:");
  1949. printk("CDB:");
  1950. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1951. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  1952. printk("\n");
  1953. ahd_lock(ahd, &flags);
  1954. /*
  1955. * First determine if we currently own this command.
  1956. * Start by searching the device queue. If not found
  1957. * there, check the pending_scb list. If not found
  1958. * at all, and the system wanted us to just abort the
  1959. * command, return success.
  1960. */
  1961. dev = scsi_transport_device_data(cmd->device);
  1962. if (dev == NULL) {
  1963. /*
  1964. * No target device for this command exists,
  1965. * so we must not still own the command.
  1966. */
  1967. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  1968. retval = SUCCESS;
  1969. goto no_cmd;
  1970. }
  1971. /*
  1972. * See if we can find a matching cmd in the pending list.
  1973. */
  1974. LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
  1975. if (pending_scb->io_ctx == cmd)
  1976. break;
  1977. }
  1978. if (pending_scb == NULL) {
  1979. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1980. goto no_cmd;
  1981. }
  1982. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1983. /*
  1984. * We can't queue two recovery actions using the same SCB
  1985. */
  1986. retval = FAILED;
  1987. goto done;
  1988. }
  1989. /*
  1990. * Ensure that the card doesn't do anything
  1991. * behind our back. Also make sure that we
  1992. * didn't "just" miss an interrupt that would
  1993. * affect this cmd.
  1994. */
  1995. was_paused = ahd_is_paused(ahd);
  1996. ahd_pause_and_flushwork(ahd);
  1997. paused = TRUE;
  1998. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  1999. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  2000. goto no_cmd;
  2001. }
  2002. printk("%s: At time of recovery, card was %spaused\n",
  2003. ahd_name(ahd), was_paused ? "" : "not ");
  2004. ahd_dump_card_state(ahd);
  2005. disconnected = TRUE;
  2006. if (ahd_search_qinfifo(ahd, cmd->device->id,
  2007. cmd->device->channel + 'A',
  2008. cmd->device->lun,
  2009. pending_scb->hscb->tag,
  2010. ROLE_INITIATOR, CAM_REQ_ABORTED,
  2011. SEARCH_COMPLETE) > 0) {
  2012. printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  2013. ahd_name(ahd), cmd->device->channel,
  2014. cmd->device->id, cmd->device->lun);
  2015. retval = SUCCESS;
  2016. goto done;
  2017. }
  2018. saved_modes = ahd_save_modes(ahd);
  2019. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  2020. last_phase = ahd_inb(ahd, LASTPHASE);
  2021. saved_scbptr = ahd_get_scbptr(ahd);
  2022. active_scbptr = saved_scbptr;
  2023. if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  2024. struct scb *bus_scb;
  2025. bus_scb = ahd_lookup_scb(ahd, active_scbptr);
  2026. if (bus_scb == pending_scb)
  2027. disconnected = FALSE;
  2028. }
  2029. /*
  2030. * At this point, pending_scb is the scb associated with the
  2031. * passed in command. That command is currently active on the
  2032. * bus or is in the disconnected state.
  2033. */
  2034. saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
  2035. if (last_phase != P_BUSFREE
  2036. && SCB_GET_TAG(pending_scb) == active_scbptr) {
  2037. /*
  2038. * We're active on the bus, so assert ATN
  2039. * and hope that the target responds.
  2040. */
  2041. pending_scb = ahd_lookup_scb(ahd, active_scbptr);
  2042. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2043. ahd_outb(ahd, MSG_OUT, HOST_MSG);
  2044. ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
  2045. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  2046. wait = TRUE;
  2047. } else if (disconnected) {
  2048. /*
  2049. * Actually re-queue this SCB in an attempt
  2050. * to select the device before it reconnects.
  2051. */
  2052. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2053. ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
  2054. pending_scb->hscb->cdb_len = 0;
  2055. pending_scb->hscb->task_attribute = 0;
  2056. pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
  2057. if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
  2058. /*
  2059. * Mark the SCB has having an outstanding
  2060. * task management function. Should the command
  2061. * complete normally before the task management
  2062. * function can be sent, the host will be notified
  2063. * to abort our requeued SCB.
  2064. */
  2065. ahd_outb(ahd, SCB_TASK_MANAGEMENT,
  2066. pending_scb->hscb->task_management);
  2067. } else {
  2068. /*
  2069. * If non-packetized, set the MK_MESSAGE control
  2070. * bit indicating that we desire to send a message.
  2071. * We also set the disconnected flag since there is
  2072. * no guarantee that our SCB control byte matches
  2073. * the version on the card. We don't want the
  2074. * sequencer to abort the command thinking an
  2075. * unsolicited reselection occurred.
  2076. */
  2077. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2078. /*
  2079. * The sequencer will never re-reference the
  2080. * in-core SCB. To make sure we are notified
  2081. * during reselection, set the MK_MESSAGE flag in
  2082. * the card's copy of the SCB.
  2083. */
  2084. ahd_outb(ahd, SCB_CONTROL,
  2085. ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
  2086. }
  2087. /*
  2088. * Clear out any entries in the QINFIFO first
  2089. * so we are the next SCB for this target
  2090. * to run.
  2091. */
  2092. ahd_search_qinfifo(ahd, cmd->device->id,
  2093. cmd->device->channel + 'A', cmd->device->lun,
  2094. SCB_LIST_NULL, ROLE_INITIATOR,
  2095. CAM_REQUEUE_REQ, SEARCH_COMPLETE);
  2096. ahd_qinfifo_requeue_tail(ahd, pending_scb);
  2097. ahd_set_scbptr(ahd, saved_scbptr);
  2098. ahd_print_path(ahd, pending_scb);
  2099. printk("Device is disconnected, re-queuing SCB\n");
  2100. wait = TRUE;
  2101. } else {
  2102. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2103. retval = FAILED;
  2104. goto done;
  2105. }
  2106. no_cmd:
  2107. /*
  2108. * Our assumption is that if we don't have the command, no
  2109. * recovery action was required, so we return success. Again,
  2110. * the semantics of the mid-layer recovery engine are not
  2111. * well defined, so this may change in time.
  2112. */
  2113. retval = SUCCESS;
  2114. done:
  2115. if (paused)
  2116. ahd_unpause(ahd);
  2117. if (wait) {
  2118. DECLARE_COMPLETION_ONSTACK(done);
  2119. ahd->platform_data->eh_done = &done;
  2120. ahd_unlock(ahd, &flags);
  2121. printk("%s: Recovery code sleeping\n", ahd_name(ahd));
  2122. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  2123. ahd_lock(ahd, &flags);
  2124. ahd->platform_data->eh_done = NULL;
  2125. ahd_unlock(ahd, &flags);
  2126. printk("%s: Timer Expired (active %d)\n",
  2127. ahd_name(ahd), dev->active);
  2128. retval = FAILED;
  2129. }
  2130. printk("Recovery code awake\n");
  2131. } else
  2132. ahd_unlock(ahd, &flags);
  2133. if (retval != SUCCESS)
  2134. printk("%s: Command abort returning 0x%x\n",
  2135. ahd_name(ahd), retval);
  2136. return retval;
  2137. }
  2138. static void ahd_linux_set_width(struct scsi_target *starget, int width)
  2139. {
  2140. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2141. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2142. struct ahd_devinfo devinfo;
  2143. unsigned long flags;
  2144. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2145. starget->channel + 'A', ROLE_INITIATOR);
  2146. ahd_lock(ahd, &flags);
  2147. ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
  2148. ahd_unlock(ahd, &flags);
  2149. }
  2150. static void ahd_linux_set_period(struct scsi_target *starget, int period)
  2151. {
  2152. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2153. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2154. struct ahd_tmode_tstate *tstate;
  2155. struct ahd_initiator_tinfo *tinfo
  2156. = ahd_fetch_transinfo(ahd,
  2157. starget->channel + 'A',
  2158. shost->this_id, starget->id, &tstate);
  2159. struct ahd_devinfo devinfo;
  2160. unsigned int ppr_options = tinfo->goal.ppr_options;
  2161. unsigned int dt;
  2162. unsigned long flags;
  2163. unsigned long offset = tinfo->goal.offset;
  2164. #ifdef AHD_DEBUG
  2165. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2166. printk("%s: set period to %d\n", ahd_name(ahd), period);
  2167. #endif
  2168. if (offset == 0)
  2169. offset = MAX_OFFSET;
  2170. if (period < 8)
  2171. period = 8;
  2172. if (period < 10) {
  2173. if (spi_max_width(starget)) {
  2174. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2175. if (period == 8)
  2176. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2177. } else
  2178. period = 10;
  2179. }
  2180. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2181. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2182. starget->channel + 'A', ROLE_INITIATOR);
  2183. /* all PPR requests apart from QAS require wide transfers */
  2184. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2185. if (spi_width(starget) == 0)
  2186. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2187. }
  2188. ahd_find_syncrate(ahd, &period, &ppr_options,
  2189. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2190. ahd_lock(ahd, &flags);
  2191. ahd_set_syncrate(ahd, &devinfo, period, offset,
  2192. ppr_options, AHD_TRANS_GOAL, FALSE);
  2193. ahd_unlock(ahd, &flags);
  2194. }
  2195. static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
  2196. {
  2197. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2198. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2199. struct ahd_tmode_tstate *tstate;
  2200. struct ahd_initiator_tinfo *tinfo
  2201. = ahd_fetch_transinfo(ahd,
  2202. starget->channel + 'A',
  2203. shost->this_id, starget->id, &tstate);
  2204. struct ahd_devinfo devinfo;
  2205. unsigned int ppr_options = 0;
  2206. unsigned int period = 0;
  2207. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2208. unsigned long flags;
  2209. #ifdef AHD_DEBUG
  2210. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2211. printk("%s: set offset to %d\n", ahd_name(ahd), offset);
  2212. #endif
  2213. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2214. starget->channel + 'A', ROLE_INITIATOR);
  2215. if (offset != 0) {
  2216. period = tinfo->goal.period;
  2217. ppr_options = tinfo->goal.ppr_options;
  2218. ahd_find_syncrate(ahd, &period, &ppr_options,
  2219. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2220. }
  2221. ahd_lock(ahd, &flags);
  2222. ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
  2223. AHD_TRANS_GOAL, FALSE);
  2224. ahd_unlock(ahd, &flags);
  2225. }
  2226. static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
  2227. {
  2228. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2229. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2230. struct ahd_tmode_tstate *tstate;
  2231. struct ahd_initiator_tinfo *tinfo
  2232. = ahd_fetch_transinfo(ahd,
  2233. starget->channel + 'A',
  2234. shost->this_id, starget->id, &tstate);
  2235. struct ahd_devinfo devinfo;
  2236. unsigned int ppr_options = tinfo->goal.ppr_options
  2237. & ~MSG_EXT_PPR_DT_REQ;
  2238. unsigned int period = tinfo->goal.period;
  2239. unsigned int width = tinfo->goal.width;
  2240. unsigned long flags;
  2241. #ifdef AHD_DEBUG
  2242. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2243. printk("%s: %s DT\n", ahd_name(ahd),
  2244. dt ? "enabling" : "disabling");
  2245. #endif
  2246. if (dt && spi_max_width(starget)) {
  2247. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2248. if (!width)
  2249. ahd_linux_set_width(starget, 1);
  2250. } else {
  2251. if (period <= 9)
  2252. period = 10; /* If resetting DT, period must be >= 25ns */
  2253. /* IU is invalid without DT set */
  2254. ppr_options &= ~MSG_EXT_PPR_IU_REQ;
  2255. }
  2256. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2257. starget->channel + 'A', ROLE_INITIATOR);
  2258. ahd_find_syncrate(ahd, &period, &ppr_options,
  2259. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2260. ahd_lock(ahd, &flags);
  2261. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2262. ppr_options, AHD_TRANS_GOAL, FALSE);
  2263. ahd_unlock(ahd, &flags);
  2264. }
  2265. static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
  2266. {
  2267. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2268. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2269. struct ahd_tmode_tstate *tstate;
  2270. struct ahd_initiator_tinfo *tinfo
  2271. = ahd_fetch_transinfo(ahd,
  2272. starget->channel + 'A',
  2273. shost->this_id, starget->id, &tstate);
  2274. struct ahd_devinfo devinfo;
  2275. unsigned int ppr_options = tinfo->goal.ppr_options
  2276. & ~MSG_EXT_PPR_QAS_REQ;
  2277. unsigned int period = tinfo->goal.period;
  2278. unsigned int dt;
  2279. unsigned long flags;
  2280. #ifdef AHD_DEBUG
  2281. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2282. printk("%s: %s QAS\n", ahd_name(ahd),
  2283. qas ? "enabling" : "disabling");
  2284. #endif
  2285. if (qas) {
  2286. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2287. }
  2288. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2289. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2290. starget->channel + 'A', ROLE_INITIATOR);
  2291. ahd_find_syncrate(ahd, &period, &ppr_options,
  2292. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2293. ahd_lock(ahd, &flags);
  2294. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2295. ppr_options, AHD_TRANS_GOAL, FALSE);
  2296. ahd_unlock(ahd, &flags);
  2297. }
  2298. static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
  2299. {
  2300. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2301. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2302. struct ahd_tmode_tstate *tstate;
  2303. struct ahd_initiator_tinfo *tinfo
  2304. = ahd_fetch_transinfo(ahd,
  2305. starget->channel + 'A',
  2306. shost->this_id, starget->id, &tstate);
  2307. struct ahd_devinfo devinfo;
  2308. unsigned int ppr_options = tinfo->goal.ppr_options
  2309. & ~MSG_EXT_PPR_IU_REQ;
  2310. unsigned int period = tinfo->goal.period;
  2311. unsigned int dt;
  2312. unsigned long flags;
  2313. #ifdef AHD_DEBUG
  2314. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2315. printk("%s: %s IU\n", ahd_name(ahd),
  2316. iu ? "enabling" : "disabling");
  2317. #endif
  2318. if (iu && spi_max_width(starget)) {
  2319. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2320. ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
  2321. }
  2322. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2323. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2324. starget->channel + 'A', ROLE_INITIATOR);
  2325. ahd_find_syncrate(ahd, &period, &ppr_options,
  2326. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2327. ahd_lock(ahd, &flags);
  2328. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2329. ppr_options, AHD_TRANS_GOAL, FALSE);
  2330. ahd_unlock(ahd, &flags);
  2331. }
  2332. static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm)
  2333. {
  2334. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2335. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2336. struct ahd_tmode_tstate *tstate;
  2337. struct ahd_initiator_tinfo *tinfo
  2338. = ahd_fetch_transinfo(ahd,
  2339. starget->channel + 'A',
  2340. shost->this_id, starget->id, &tstate);
  2341. struct ahd_devinfo devinfo;
  2342. unsigned int ppr_options = tinfo->goal.ppr_options
  2343. & ~MSG_EXT_PPR_RD_STRM;
  2344. unsigned int period = tinfo->goal.period;
  2345. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2346. unsigned long flags;
  2347. #ifdef AHD_DEBUG
  2348. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2349. printk("%s: %s Read Streaming\n", ahd_name(ahd),
  2350. rdstrm ? "enabling" : "disabling");
  2351. #endif
  2352. if (rdstrm && spi_max_width(starget))
  2353. ppr_options |= MSG_EXT_PPR_RD_STRM;
  2354. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2355. starget->channel + 'A', ROLE_INITIATOR);
  2356. ahd_find_syncrate(ahd, &period, &ppr_options,
  2357. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2358. ahd_lock(ahd, &flags);
  2359. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2360. ppr_options, AHD_TRANS_GOAL, FALSE);
  2361. ahd_unlock(ahd, &flags);
  2362. }
  2363. static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
  2364. {
  2365. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2366. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2367. struct ahd_tmode_tstate *tstate;
  2368. struct ahd_initiator_tinfo *tinfo
  2369. = ahd_fetch_transinfo(ahd,
  2370. starget->channel + 'A',
  2371. shost->this_id, starget->id, &tstate);
  2372. struct ahd_devinfo devinfo;
  2373. unsigned int ppr_options = tinfo->goal.ppr_options
  2374. & ~MSG_EXT_PPR_WR_FLOW;
  2375. unsigned int period = tinfo->goal.period;
  2376. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2377. unsigned long flags;
  2378. #ifdef AHD_DEBUG
  2379. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2380. printk("%s: %s Write Flow Control\n", ahd_name(ahd),
  2381. wrflow ? "enabling" : "disabling");
  2382. #endif
  2383. if (wrflow && spi_max_width(starget))
  2384. ppr_options |= MSG_EXT_PPR_WR_FLOW;
  2385. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2386. starget->channel + 'A', ROLE_INITIATOR);
  2387. ahd_find_syncrate(ahd, &period, &ppr_options,
  2388. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2389. ahd_lock(ahd, &flags);
  2390. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2391. ppr_options, AHD_TRANS_GOAL, FALSE);
  2392. ahd_unlock(ahd, &flags);
  2393. }
  2394. static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
  2395. {
  2396. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2397. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2398. struct ahd_tmode_tstate *tstate;
  2399. struct ahd_initiator_tinfo *tinfo
  2400. = ahd_fetch_transinfo(ahd,
  2401. starget->channel + 'A',
  2402. shost->this_id, starget->id, &tstate);
  2403. struct ahd_devinfo devinfo;
  2404. unsigned int ppr_options = tinfo->goal.ppr_options
  2405. & ~MSG_EXT_PPR_RTI;
  2406. unsigned int period = tinfo->goal.period;
  2407. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2408. unsigned long flags;
  2409. if ((ahd->features & AHD_RTI) == 0) {
  2410. #ifdef AHD_DEBUG
  2411. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2412. printk("%s: RTI not available\n", ahd_name(ahd));
  2413. #endif
  2414. return;
  2415. }
  2416. #ifdef AHD_DEBUG
  2417. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2418. printk("%s: %s RTI\n", ahd_name(ahd),
  2419. rti ? "enabling" : "disabling");
  2420. #endif
  2421. if (rti && spi_max_width(starget))
  2422. ppr_options |= MSG_EXT_PPR_RTI;
  2423. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2424. starget->channel + 'A', ROLE_INITIATOR);
  2425. ahd_find_syncrate(ahd, &period, &ppr_options,
  2426. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2427. ahd_lock(ahd, &flags);
  2428. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2429. ppr_options, AHD_TRANS_GOAL, FALSE);
  2430. ahd_unlock(ahd, &flags);
  2431. }
  2432. static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
  2433. {
  2434. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2435. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2436. struct ahd_tmode_tstate *tstate;
  2437. struct ahd_initiator_tinfo *tinfo
  2438. = ahd_fetch_transinfo(ahd,
  2439. starget->channel + 'A',
  2440. shost->this_id, starget->id, &tstate);
  2441. struct ahd_devinfo devinfo;
  2442. unsigned int ppr_options = tinfo->goal.ppr_options
  2443. & ~MSG_EXT_PPR_PCOMP_EN;
  2444. unsigned int period = tinfo->goal.period;
  2445. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2446. unsigned long flags;
  2447. #ifdef AHD_DEBUG
  2448. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2449. printk("%s: %s Precompensation\n", ahd_name(ahd),
  2450. pcomp ? "Enable" : "Disable");
  2451. #endif
  2452. if (pcomp && spi_max_width(starget)) {
  2453. uint8_t precomp;
  2454. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  2455. const struct ahd_linux_iocell_opts *iocell_opts;
  2456. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  2457. precomp = iocell_opts->precomp;
  2458. } else {
  2459. precomp = AIC79XX_DEFAULT_PRECOMP;
  2460. }
  2461. ppr_options |= MSG_EXT_PPR_PCOMP_EN;
  2462. AHD_SET_PRECOMP(ahd, precomp);
  2463. } else {
  2464. AHD_SET_PRECOMP(ahd, 0);
  2465. }
  2466. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2467. starget->channel + 'A', ROLE_INITIATOR);
  2468. ahd_find_syncrate(ahd, &period, &ppr_options,
  2469. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2470. ahd_lock(ahd, &flags);
  2471. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2472. ppr_options, AHD_TRANS_GOAL, FALSE);
  2473. ahd_unlock(ahd, &flags);
  2474. }
  2475. static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
  2476. {
  2477. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2478. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2479. struct ahd_tmode_tstate *tstate;
  2480. struct ahd_initiator_tinfo *tinfo
  2481. = ahd_fetch_transinfo(ahd,
  2482. starget->channel + 'A',
  2483. shost->this_id, starget->id, &tstate);
  2484. struct ahd_devinfo devinfo;
  2485. unsigned int ppr_options = tinfo->goal.ppr_options
  2486. & ~MSG_EXT_PPR_HOLD_MCS;
  2487. unsigned int period = tinfo->goal.period;
  2488. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2489. unsigned long flags;
  2490. if (hold && spi_max_width(starget))
  2491. ppr_options |= MSG_EXT_PPR_HOLD_MCS;
  2492. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2493. starget->channel + 'A', ROLE_INITIATOR);
  2494. ahd_find_syncrate(ahd, &period, &ppr_options,
  2495. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2496. ahd_lock(ahd, &flags);
  2497. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2498. ppr_options, AHD_TRANS_GOAL, FALSE);
  2499. ahd_unlock(ahd, &flags);
  2500. }
  2501. static void ahd_linux_get_signalling(struct Scsi_Host *shost)
  2502. {
  2503. struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
  2504. unsigned long flags;
  2505. u8 mode;
  2506. ahd_lock(ahd, &flags);
  2507. ahd_pause(ahd);
  2508. mode = ahd_inb(ahd, SBLKCTL);
  2509. ahd_unpause(ahd);
  2510. ahd_unlock(ahd, &flags);
  2511. if (mode & ENAB40)
  2512. spi_signalling(shost) = SPI_SIGNAL_LVD;
  2513. else if (mode & ENAB20)
  2514. spi_signalling(shost) = SPI_SIGNAL_SE;
  2515. else
  2516. spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
  2517. }
  2518. static struct spi_function_template ahd_linux_transport_functions = {
  2519. .set_offset = ahd_linux_set_offset,
  2520. .show_offset = 1,
  2521. .set_period = ahd_linux_set_period,
  2522. .show_period = 1,
  2523. .set_width = ahd_linux_set_width,
  2524. .show_width = 1,
  2525. .set_dt = ahd_linux_set_dt,
  2526. .show_dt = 1,
  2527. .set_iu = ahd_linux_set_iu,
  2528. .show_iu = 1,
  2529. .set_qas = ahd_linux_set_qas,
  2530. .show_qas = 1,
  2531. .set_rd_strm = ahd_linux_set_rd_strm,
  2532. .show_rd_strm = 1,
  2533. .set_wr_flow = ahd_linux_set_wr_flow,
  2534. .show_wr_flow = 1,
  2535. .set_rti = ahd_linux_set_rti,
  2536. .show_rti = 1,
  2537. .set_pcomp_en = ahd_linux_set_pcomp_en,
  2538. .show_pcomp_en = 1,
  2539. .set_hold_mcs = ahd_linux_set_hold_mcs,
  2540. .show_hold_mcs = 1,
  2541. .get_signalling = ahd_linux_get_signalling,
  2542. };
  2543. static int __init
  2544. ahd_linux_init(void)
  2545. {
  2546. int error = 0;
  2547. /*
  2548. * If we've been passed any parameters, process them now.
  2549. */
  2550. if (aic79xx)
  2551. aic79xx_setup(aic79xx);
  2552. ahd_linux_transport_template =
  2553. spi_attach_transport(&ahd_linux_transport_functions);
  2554. if (!ahd_linux_transport_template)
  2555. return -ENODEV;
  2556. scsi_transport_reserve_device(ahd_linux_transport_template,
  2557. sizeof(struct ahd_linux_device));
  2558. error = ahd_linux_pci_init();
  2559. if (error)
  2560. spi_release_transport(ahd_linux_transport_template);
  2561. return error;
  2562. }
  2563. static void __exit
  2564. ahd_linux_exit(void)
  2565. {
  2566. ahd_linux_pci_exit();
  2567. spi_release_transport(ahd_linux_transport_template);
  2568. }
  2569. module_init(ahd_linux_init);
  2570. module_exit(ahd_linux_exit);