aic79xx_osm.c 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901
  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 /etc/modprobe.conf line:\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(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 struct scsi_target **
  537. ahd_linux_target_in_softc(struct scsi_target *starget)
  538. {
  539. struct ahd_softc *ahd =
  540. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  541. unsigned int target_offset;
  542. target_offset = starget->id;
  543. if (starget->channel != 0)
  544. target_offset += 8;
  545. return &ahd->platform_data->starget[target_offset];
  546. }
  547. static int
  548. ahd_linux_target_alloc(struct scsi_target *starget)
  549. {
  550. struct ahd_softc *ahd =
  551. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  552. struct seeprom_config *sc = ahd->seep_config;
  553. unsigned long flags;
  554. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  555. struct ahd_devinfo devinfo;
  556. struct ahd_initiator_tinfo *tinfo;
  557. struct ahd_tmode_tstate *tstate;
  558. char channel = starget->channel + 'A';
  559. ahd_lock(ahd, &flags);
  560. BUG_ON(*ahd_targp != NULL);
  561. *ahd_targp = starget;
  562. if (sc) {
  563. int flags = sc->device_flags[starget->id];
  564. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  565. starget->id, &tstate);
  566. if ((flags & CFPACKETIZED) == 0) {
  567. /* don't negotiate packetized (IU) transfers */
  568. spi_max_iu(starget) = 0;
  569. } else {
  570. if ((ahd->features & AHD_RTI) == 0)
  571. spi_rti(starget) = 0;
  572. }
  573. if ((flags & CFQAS) == 0)
  574. spi_max_qas(starget) = 0;
  575. /* Transinfo values have been set to BIOS settings */
  576. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  577. spi_min_period(starget) = tinfo->user.period;
  578. spi_max_offset(starget) = tinfo->user.offset;
  579. }
  580. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  581. starget->id, &tstate);
  582. ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
  583. CAM_LUN_WILDCARD, channel,
  584. ROLE_INITIATOR);
  585. ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
  586. AHD_TRANS_GOAL, /*paused*/FALSE);
  587. ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  588. AHD_TRANS_GOAL, /*paused*/FALSE);
  589. ahd_unlock(ahd, &flags);
  590. return 0;
  591. }
  592. static void
  593. ahd_linux_target_destroy(struct scsi_target *starget)
  594. {
  595. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  596. *ahd_targp = NULL;
  597. }
  598. static int
  599. ahd_linux_slave_alloc(struct scsi_device *sdev)
  600. {
  601. struct ahd_softc *ahd =
  602. *((struct ahd_softc **)sdev->host->hostdata);
  603. struct ahd_linux_device *dev;
  604. if (bootverbose)
  605. printk("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
  606. dev = scsi_transport_device_data(sdev);
  607. memset(dev, 0, sizeof(*dev));
  608. /*
  609. * We start out life using untagged
  610. * transactions of which we allow one.
  611. */
  612. dev->openings = 1;
  613. /*
  614. * Set maxtags to 0. This will be changed if we
  615. * later determine that we are dealing with
  616. * a tagged queuing capable device.
  617. */
  618. dev->maxtags = 0;
  619. return (0);
  620. }
  621. static int
  622. ahd_linux_slave_configure(struct scsi_device *sdev)
  623. {
  624. struct ahd_softc *ahd;
  625. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  626. if (bootverbose)
  627. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  628. ahd_linux_device_queue_depth(sdev);
  629. /* Initial Domain Validation */
  630. if (!spi_initial_dv(sdev->sdev_target))
  631. spi_dv_device(sdev);
  632. return 0;
  633. }
  634. #if defined(__i386__)
  635. /*
  636. * Return the disk geometry for the given SCSI device.
  637. */
  638. static int
  639. ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  640. sector_t capacity, int geom[])
  641. {
  642. uint8_t *bh;
  643. int heads;
  644. int sectors;
  645. int cylinders;
  646. int ret;
  647. int extended;
  648. struct ahd_softc *ahd;
  649. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  650. bh = scsi_bios_ptable(bdev);
  651. if (bh) {
  652. ret = scsi_partsize(bh, capacity,
  653. &geom[2], &geom[0], &geom[1]);
  654. kfree(bh);
  655. if (ret != -1)
  656. return (ret);
  657. }
  658. heads = 64;
  659. sectors = 32;
  660. cylinders = aic_sector_div(capacity, heads, sectors);
  661. if (aic79xx_extended != 0)
  662. extended = 1;
  663. else
  664. extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
  665. if (extended && cylinders >= 1024) {
  666. heads = 255;
  667. sectors = 63;
  668. cylinders = aic_sector_div(capacity, heads, sectors);
  669. }
  670. geom[0] = heads;
  671. geom[1] = sectors;
  672. geom[2] = cylinders;
  673. return (0);
  674. }
  675. #endif
  676. /*
  677. * Abort the current SCSI command(s).
  678. */
  679. static int
  680. ahd_linux_abort(struct scsi_cmnd *cmd)
  681. {
  682. int error;
  683. error = ahd_linux_queue_abort_cmd(cmd);
  684. return error;
  685. }
  686. /*
  687. * Attempt to send a target reset message to the device that timed out.
  688. */
  689. static int
  690. ahd_linux_dev_reset(struct scsi_cmnd *cmd)
  691. {
  692. struct ahd_softc *ahd;
  693. struct ahd_linux_device *dev;
  694. struct scb *reset_scb;
  695. u_int cdb_byte;
  696. int retval = SUCCESS;
  697. int paused;
  698. int wait;
  699. struct ahd_initiator_tinfo *tinfo;
  700. struct ahd_tmode_tstate *tstate;
  701. unsigned long flags;
  702. DECLARE_COMPLETION_ONSTACK(done);
  703. reset_scb = NULL;
  704. paused = FALSE;
  705. wait = FALSE;
  706. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  707. scmd_printk(KERN_INFO, cmd,
  708. "Attempting to queue a TARGET RESET message:");
  709. printk("CDB:");
  710. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  711. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  712. printk("\n");
  713. /*
  714. * Determine if we currently own this command.
  715. */
  716. dev = scsi_transport_device_data(cmd->device);
  717. if (dev == NULL) {
  718. /*
  719. * No target device for this command exists,
  720. * so we must not still own the command.
  721. */
  722. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  723. return SUCCESS;
  724. }
  725. /*
  726. * Generate us a new SCB
  727. */
  728. reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX);
  729. if (!reset_scb) {
  730. scmd_printk(KERN_INFO, cmd, "No SCB available\n");
  731. return FAILED;
  732. }
  733. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  734. cmd->device->id, &tstate);
  735. reset_scb->io_ctx = cmd;
  736. reset_scb->platform_data->dev = dev;
  737. reset_scb->sg_count = 0;
  738. ahd_set_residual(reset_scb, 0);
  739. ahd_set_sense_residual(reset_scb, 0);
  740. reset_scb->platform_data->xfer_len = 0;
  741. reset_scb->hscb->control = 0;
  742. reset_scb->hscb->scsiid = BUILD_SCSIID(ahd,cmd);
  743. reset_scb->hscb->lun = cmd->device->lun;
  744. reset_scb->hscb->cdb_len = 0;
  745. reset_scb->hscb->task_management = SIU_TASKMGMT_LUN_RESET;
  746. reset_scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
  747. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  748. reset_scb->flags |= SCB_PACKETIZED;
  749. } else {
  750. reset_scb->hscb->control |= MK_MESSAGE;
  751. }
  752. dev->openings--;
  753. dev->active++;
  754. dev->commands_issued++;
  755. ahd_lock(ahd, &flags);
  756. LIST_INSERT_HEAD(&ahd->pending_scbs, reset_scb, pending_links);
  757. ahd_queue_scb(ahd, reset_scb);
  758. ahd->platform_data->eh_done = &done;
  759. ahd_unlock(ahd, &flags);
  760. printk("%s: Device reset code sleeping\n", ahd_name(ahd));
  761. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  762. ahd_lock(ahd, &flags);
  763. ahd->platform_data->eh_done = NULL;
  764. ahd_unlock(ahd, &flags);
  765. printk("%s: Device reset timer expired (active %d)\n",
  766. ahd_name(ahd), dev->active);
  767. retval = FAILED;
  768. }
  769. printk("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
  770. return (retval);
  771. }
  772. /*
  773. * Reset the SCSI bus.
  774. */
  775. static int
  776. ahd_linux_bus_reset(struct scsi_cmnd *cmd)
  777. {
  778. struct ahd_softc *ahd;
  779. int found;
  780. unsigned long flags;
  781. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  782. #ifdef AHD_DEBUG
  783. if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
  784. printk("%s: Bus reset called for cmd %p\n",
  785. ahd_name(ahd), cmd);
  786. #endif
  787. ahd_lock(ahd, &flags);
  788. found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
  789. /*initiate reset*/TRUE);
  790. ahd_unlock(ahd, &flags);
  791. if (bootverbose)
  792. printk("%s: SCSI bus reset delivered. "
  793. "%d SCBs aborted.\n", ahd_name(ahd), found);
  794. return (SUCCESS);
  795. }
  796. struct scsi_host_template aic79xx_driver_template = {
  797. .module = THIS_MODULE,
  798. .name = "aic79xx",
  799. .proc_name = "aic79xx",
  800. .proc_info = ahd_linux_proc_info,
  801. .info = ahd_linux_info,
  802. .queuecommand = ahd_linux_queue,
  803. .eh_abort_handler = ahd_linux_abort,
  804. .eh_device_reset_handler = ahd_linux_dev_reset,
  805. .eh_bus_reset_handler = ahd_linux_bus_reset,
  806. #if defined(__i386__)
  807. .bios_param = ahd_linux_biosparam,
  808. #endif
  809. .can_queue = AHD_MAX_QUEUE,
  810. .this_id = -1,
  811. .max_sectors = 8192,
  812. .cmd_per_lun = 2,
  813. .use_clustering = ENABLE_CLUSTERING,
  814. .slave_alloc = ahd_linux_slave_alloc,
  815. .slave_configure = ahd_linux_slave_configure,
  816. .target_alloc = ahd_linux_target_alloc,
  817. .target_destroy = ahd_linux_target_destroy,
  818. };
  819. /******************************** Bus DMA *************************************/
  820. int
  821. ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
  822. bus_size_t alignment, bus_size_t boundary,
  823. dma_addr_t lowaddr, dma_addr_t highaddr,
  824. bus_dma_filter_t *filter, void *filterarg,
  825. bus_size_t maxsize, int nsegments,
  826. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  827. {
  828. bus_dma_tag_t dmat;
  829. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  830. if (dmat == NULL)
  831. return (ENOMEM);
  832. /*
  833. * Linux is very simplistic about DMA memory. For now don't
  834. * maintain all specification information. Once Linux supplies
  835. * better facilities for doing these operations, or the
  836. * needs of this particular driver change, we might need to do
  837. * more here.
  838. */
  839. dmat->alignment = alignment;
  840. dmat->boundary = boundary;
  841. dmat->maxsize = maxsize;
  842. *ret_tag = dmat;
  843. return (0);
  844. }
  845. void
  846. ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
  847. {
  848. kfree(dmat);
  849. }
  850. int
  851. ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
  852. int flags, bus_dmamap_t *mapp)
  853. {
  854. *vaddr = pci_alloc_consistent(ahd->dev_softc,
  855. dmat->maxsize, mapp);
  856. if (*vaddr == NULL)
  857. return (ENOMEM);
  858. return(0);
  859. }
  860. void
  861. ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
  862. void* vaddr, bus_dmamap_t map)
  863. {
  864. pci_free_consistent(ahd->dev_softc, dmat->maxsize,
  865. vaddr, map);
  866. }
  867. int
  868. ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
  869. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  870. void *cb_arg, int flags)
  871. {
  872. /*
  873. * Assume for now that this will only be used during
  874. * initialization and not for per-transaction buffer mapping.
  875. */
  876. bus_dma_segment_t stack_sg;
  877. stack_sg.ds_addr = map;
  878. stack_sg.ds_len = dmat->maxsize;
  879. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  880. return (0);
  881. }
  882. void
  883. ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  884. {
  885. }
  886. int
  887. ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  888. {
  889. /* Nothing to do */
  890. return (0);
  891. }
  892. /********************* Platform Dependent Functions ***************************/
  893. static void
  894. ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
  895. {
  896. if ((instance >= 0)
  897. && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
  898. uint8_t *iocell_info;
  899. iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
  900. iocell_info[index] = value & 0xFFFF;
  901. if (bootverbose)
  902. printk("iocell[%d:%ld] = %d\n", instance, index, value);
  903. }
  904. }
  905. static void
  906. ahd_linux_setup_tag_info_global(char *p)
  907. {
  908. int tags, i, j;
  909. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  910. printk("Setting Global Tags= %d\n", tags);
  911. for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
  912. for (j = 0; j < AHD_NUM_TARGETS; j++) {
  913. aic79xx_tag_info[i].tag_commands[j] = tags;
  914. }
  915. }
  916. }
  917. static void
  918. ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  919. {
  920. if ((instance >= 0) && (targ >= 0)
  921. && (instance < ARRAY_SIZE(aic79xx_tag_info))
  922. && (targ < AHD_NUM_TARGETS)) {
  923. aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
  924. if (bootverbose)
  925. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  926. }
  927. }
  928. static char *
  929. ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  930. void (*callback)(u_long, int, int, int32_t),
  931. u_long callback_arg)
  932. {
  933. char *tok_end;
  934. char *tok_end2;
  935. int i;
  936. int instance;
  937. int targ;
  938. int done;
  939. char tok_list[] = {'.', ',', '{', '}', '\0'};
  940. /* All options use a ':' name/arg separator */
  941. if (*opt_arg != ':')
  942. return (opt_arg);
  943. opt_arg++;
  944. instance = -1;
  945. targ = -1;
  946. done = FALSE;
  947. /*
  948. * Restore separator that may be in
  949. * the middle of our option argument.
  950. */
  951. tok_end = strchr(opt_arg, '\0');
  952. if (tok_end < end)
  953. *tok_end = ',';
  954. while (!done) {
  955. switch (*opt_arg) {
  956. case '{':
  957. if (instance == -1) {
  958. instance = 0;
  959. } else {
  960. if (depth > 1) {
  961. if (targ == -1)
  962. targ = 0;
  963. } else {
  964. printk("Malformed Option %s\n",
  965. opt_name);
  966. done = TRUE;
  967. }
  968. }
  969. opt_arg++;
  970. break;
  971. case '}':
  972. if (targ != -1)
  973. targ = -1;
  974. else if (instance != -1)
  975. instance = -1;
  976. opt_arg++;
  977. break;
  978. case ',':
  979. case '.':
  980. if (instance == -1)
  981. done = TRUE;
  982. else if (targ >= 0)
  983. targ++;
  984. else if (instance >= 0)
  985. instance++;
  986. opt_arg++;
  987. break;
  988. case '\0':
  989. done = TRUE;
  990. break;
  991. default:
  992. tok_end = end;
  993. for (i = 0; tok_list[i]; i++) {
  994. tok_end2 = strchr(opt_arg, tok_list[i]);
  995. if ((tok_end2) && (tok_end2 < tok_end))
  996. tok_end = tok_end2;
  997. }
  998. callback(callback_arg, instance, targ,
  999. simple_strtol(opt_arg, NULL, 0));
  1000. opt_arg = tok_end;
  1001. break;
  1002. }
  1003. }
  1004. return (opt_arg);
  1005. }
  1006. /*
  1007. * Handle Linux boot parameters. This routine allows for assigning a value
  1008. * to a parameter with a ':' between the parameter and the value.
  1009. * ie. aic79xx=stpwlev:1,extended
  1010. */
  1011. static int
  1012. aic79xx_setup(char *s)
  1013. {
  1014. int i, n;
  1015. char *p;
  1016. char *end;
  1017. static const struct {
  1018. const char *name;
  1019. uint32_t *flag;
  1020. } options[] = {
  1021. { "extended", &aic79xx_extended },
  1022. { "no_reset", &aic79xx_no_reset },
  1023. { "verbose", &aic79xx_verbose },
  1024. { "allow_memio", &aic79xx_allow_memio},
  1025. #ifdef AHD_DEBUG
  1026. { "debug", &ahd_debug },
  1027. #endif
  1028. { "periodic_otag", &aic79xx_periodic_otag },
  1029. { "pci_parity", &aic79xx_pci_parity },
  1030. { "seltime", &aic79xx_seltime },
  1031. { "tag_info", NULL },
  1032. { "global_tag_depth", NULL},
  1033. { "slewrate", NULL },
  1034. { "precomp", NULL },
  1035. { "amplitude", NULL },
  1036. { "slowcrc", &aic79xx_slowcrc },
  1037. };
  1038. end = strchr(s, '\0');
  1039. /*
  1040. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  1041. * will never be 0 in this case.
  1042. */
  1043. n = 0;
  1044. while ((p = strsep(&s, ",.")) != NULL) {
  1045. if (*p == '\0')
  1046. continue;
  1047. for (i = 0; i < ARRAY_SIZE(options); i++) {
  1048. n = strlen(options[i].name);
  1049. if (strncmp(options[i].name, p, n) == 0)
  1050. break;
  1051. }
  1052. if (i == ARRAY_SIZE(options))
  1053. continue;
  1054. if (strncmp(p, "global_tag_depth", n) == 0) {
  1055. ahd_linux_setup_tag_info_global(p + n);
  1056. } else if (strncmp(p, "tag_info", n) == 0) {
  1057. s = ahd_parse_brace_option("tag_info", p + n, end,
  1058. 2, ahd_linux_setup_tag_info, 0);
  1059. } else if (strncmp(p, "slewrate", n) == 0) {
  1060. s = ahd_parse_brace_option("slewrate",
  1061. p + n, end, 1, ahd_linux_setup_iocell_info,
  1062. AIC79XX_SLEWRATE_INDEX);
  1063. } else if (strncmp(p, "precomp", n) == 0) {
  1064. s = ahd_parse_brace_option("precomp",
  1065. p + n, end, 1, ahd_linux_setup_iocell_info,
  1066. AIC79XX_PRECOMP_INDEX);
  1067. } else if (strncmp(p, "amplitude", n) == 0) {
  1068. s = ahd_parse_brace_option("amplitude",
  1069. p + n, end, 1, ahd_linux_setup_iocell_info,
  1070. AIC79XX_AMPLITUDE_INDEX);
  1071. } else if (p[n] == ':') {
  1072. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1073. } else if (!strncmp(p, "verbose", n)) {
  1074. *(options[i].flag) = 1;
  1075. } else {
  1076. *(options[i].flag) ^= 0xFFFFFFFF;
  1077. }
  1078. }
  1079. return 1;
  1080. }
  1081. __setup("aic79xx=", aic79xx_setup);
  1082. uint32_t aic79xx_verbose;
  1083. int
  1084. ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
  1085. {
  1086. char buf[80];
  1087. struct Scsi_Host *host;
  1088. char *new_name;
  1089. u_long s;
  1090. int retval;
  1091. template->name = ahd->description;
  1092. host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
  1093. if (host == NULL)
  1094. return (ENOMEM);
  1095. *((struct ahd_softc **)host->hostdata) = ahd;
  1096. ahd->platform_data->host = host;
  1097. host->can_queue = AHD_MAX_QUEUE;
  1098. host->cmd_per_lun = 2;
  1099. host->sg_tablesize = AHD_NSEG;
  1100. host->this_id = ahd->our_id;
  1101. host->irq = ahd->platform_data->irq;
  1102. host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
  1103. host->max_lun = AHD_NUM_LUNS;
  1104. host->max_channel = 0;
  1105. host->sg_tablesize = AHD_NSEG;
  1106. ahd_lock(ahd, &s);
  1107. ahd_set_unit(ahd, ahd_linux_unit++);
  1108. ahd_unlock(ahd, &s);
  1109. sprintf(buf, "scsi%d", host->host_no);
  1110. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  1111. if (new_name != NULL) {
  1112. strcpy(new_name, buf);
  1113. ahd_set_name(ahd, new_name);
  1114. }
  1115. host->unique_id = ahd->unit;
  1116. ahd_linux_initialize_scsi_bus(ahd);
  1117. ahd_intr_enable(ahd, TRUE);
  1118. host->transportt = ahd_linux_transport_template;
  1119. retval = scsi_add_host(host, &ahd->dev_softc->dev);
  1120. if (retval) {
  1121. printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
  1122. scsi_host_put(host);
  1123. return retval;
  1124. }
  1125. scsi_scan_host(host);
  1126. return 0;
  1127. }
  1128. /*
  1129. * Place the SCSI bus into a known state by either resetting it,
  1130. * or forcing transfer negotiations on the next command to any
  1131. * target.
  1132. */
  1133. static void
  1134. ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
  1135. {
  1136. u_int target_id;
  1137. u_int numtarg;
  1138. unsigned long s;
  1139. target_id = 0;
  1140. numtarg = 0;
  1141. if (aic79xx_no_reset != 0)
  1142. ahd->flags &= ~AHD_RESET_BUS_A;
  1143. if ((ahd->flags & AHD_RESET_BUS_A) != 0)
  1144. ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
  1145. else
  1146. numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
  1147. ahd_lock(ahd, &s);
  1148. /*
  1149. * Force negotiation to async for all targets that
  1150. * will not see an initial bus reset.
  1151. */
  1152. for (; target_id < numtarg; target_id++) {
  1153. struct ahd_devinfo devinfo;
  1154. struct ahd_initiator_tinfo *tinfo;
  1155. struct ahd_tmode_tstate *tstate;
  1156. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1157. target_id, &tstate);
  1158. ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
  1159. CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
  1160. ahd_update_neg_request(ahd, &devinfo, tstate,
  1161. tinfo, AHD_NEG_ALWAYS);
  1162. }
  1163. ahd_unlock(ahd, &s);
  1164. /* Give the bus some time to recover */
  1165. if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
  1166. ahd_freeze_simq(ahd);
  1167. msleep(AIC79XX_RESET_DELAY);
  1168. ahd_release_simq(ahd);
  1169. }
  1170. }
  1171. int
  1172. ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
  1173. {
  1174. ahd->platform_data =
  1175. kmalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
  1176. if (ahd->platform_data == NULL)
  1177. return (ENOMEM);
  1178. memset(ahd->platform_data, 0, sizeof(struct ahd_platform_data));
  1179. ahd->platform_data->irq = AHD_LINUX_NOIRQ;
  1180. ahd_lockinit(ahd);
  1181. ahd->seltime = (aic79xx_seltime & 0x3) << 4;
  1182. return (0);
  1183. }
  1184. void
  1185. ahd_platform_free(struct ahd_softc *ahd)
  1186. {
  1187. struct scsi_target *starget;
  1188. int i;
  1189. if (ahd->platform_data != NULL) {
  1190. /* destroy all of the device and target objects */
  1191. for (i = 0; i < AHD_NUM_TARGETS; i++) {
  1192. starget = ahd->platform_data->starget[i];
  1193. if (starget != NULL) {
  1194. ahd->platform_data->starget[i] = NULL;
  1195. }
  1196. }
  1197. if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
  1198. free_irq(ahd->platform_data->irq, ahd);
  1199. if (ahd->tags[0] == BUS_SPACE_PIO
  1200. && ahd->bshs[0].ioport != 0)
  1201. release_region(ahd->bshs[0].ioport, 256);
  1202. if (ahd->tags[1] == BUS_SPACE_PIO
  1203. && ahd->bshs[1].ioport != 0)
  1204. release_region(ahd->bshs[1].ioport, 256);
  1205. if (ahd->tags[0] == BUS_SPACE_MEMIO
  1206. && ahd->bshs[0].maddr != NULL) {
  1207. iounmap(ahd->bshs[0].maddr);
  1208. release_mem_region(ahd->platform_data->mem_busaddr,
  1209. 0x1000);
  1210. }
  1211. if (ahd->platform_data->host)
  1212. scsi_host_put(ahd->platform_data->host);
  1213. kfree(ahd->platform_data);
  1214. }
  1215. }
  1216. void
  1217. ahd_platform_init(struct ahd_softc *ahd)
  1218. {
  1219. /*
  1220. * Lookup and commit any modified IO Cell options.
  1221. */
  1222. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  1223. const struct ahd_linux_iocell_opts *iocell_opts;
  1224. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  1225. if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
  1226. AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
  1227. if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
  1228. AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
  1229. if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
  1230. AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
  1231. }
  1232. }
  1233. void
  1234. ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
  1235. {
  1236. ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
  1237. SCB_GET_CHANNEL(ahd, scb),
  1238. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1239. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1240. }
  1241. void
  1242. ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
  1243. struct ahd_devinfo *devinfo, ahd_queue_alg alg)
  1244. {
  1245. struct ahd_linux_device *dev;
  1246. int was_queuing;
  1247. int now_queuing;
  1248. if (sdev == NULL)
  1249. return;
  1250. dev = scsi_transport_device_data(sdev);
  1251. if (dev == NULL)
  1252. return;
  1253. was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
  1254. switch (alg) {
  1255. default:
  1256. case AHD_QUEUE_NONE:
  1257. now_queuing = 0;
  1258. break;
  1259. case AHD_QUEUE_BASIC:
  1260. now_queuing = AHD_DEV_Q_BASIC;
  1261. break;
  1262. case AHD_QUEUE_TAGGED:
  1263. now_queuing = AHD_DEV_Q_TAGGED;
  1264. break;
  1265. }
  1266. if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
  1267. && (was_queuing != now_queuing)
  1268. && (dev->active != 0)) {
  1269. dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
  1270. dev->qfrozen++;
  1271. }
  1272. dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
  1273. if (now_queuing) {
  1274. u_int usertags;
  1275. usertags = ahd_linux_user_tagdepth(ahd, devinfo);
  1276. if (!was_queuing) {
  1277. /*
  1278. * Start out agressively and allow our
  1279. * dynamic queue depth algorithm to take
  1280. * care of the rest.
  1281. */
  1282. dev->maxtags = usertags;
  1283. dev->openings = dev->maxtags - dev->active;
  1284. }
  1285. if (dev->maxtags == 0) {
  1286. /*
  1287. * Queueing is disabled by the user.
  1288. */
  1289. dev->openings = 1;
  1290. } else if (alg == AHD_QUEUE_TAGGED) {
  1291. dev->flags |= AHD_DEV_Q_TAGGED;
  1292. if (aic79xx_periodic_otag != 0)
  1293. dev->flags |= AHD_DEV_PERIODIC_OTAG;
  1294. } else
  1295. dev->flags |= AHD_DEV_Q_BASIC;
  1296. } else {
  1297. /* We can only have one opening. */
  1298. dev->maxtags = 0;
  1299. dev->openings = 1 - dev->active;
  1300. }
  1301. switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
  1302. case AHD_DEV_Q_BASIC:
  1303. scsi_set_tag_type(sdev, MSG_SIMPLE_TASK);
  1304. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1305. break;
  1306. case AHD_DEV_Q_TAGGED:
  1307. scsi_set_tag_type(sdev, MSG_ORDERED_TASK);
  1308. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1309. break;
  1310. default:
  1311. /*
  1312. * We allow the OS to queue 2 untagged transactions to
  1313. * us at any time even though we can only execute them
  1314. * serially on the controller/device. This should
  1315. * remove some latency.
  1316. */
  1317. scsi_deactivate_tcq(sdev, 1);
  1318. break;
  1319. }
  1320. }
  1321. int
  1322. ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
  1323. int lun, u_int tag, role_t role, uint32_t status)
  1324. {
  1325. return 0;
  1326. }
  1327. static u_int
  1328. ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
  1329. {
  1330. static int warned_user;
  1331. u_int tags;
  1332. tags = 0;
  1333. if ((ahd->user_discenable & devinfo->target_mask) != 0) {
  1334. if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
  1335. if (warned_user == 0) {
  1336. printk(KERN_WARNING
  1337. "aic79xx: WARNING: Insufficient tag_info instances\n"
  1338. "aic79xx: for installed controllers. Using defaults\n"
  1339. "aic79xx: Please update the aic79xx_tag_info array in\n"
  1340. "aic79xx: the aic79xx_osm.c source file.\n");
  1341. warned_user++;
  1342. }
  1343. tags = AHD_MAX_QUEUE;
  1344. } else {
  1345. adapter_tag_info_t *tag_info;
  1346. tag_info = &aic79xx_tag_info[ahd->unit];
  1347. tags = tag_info->tag_commands[devinfo->target_offset];
  1348. if (tags > AHD_MAX_QUEUE)
  1349. tags = AHD_MAX_QUEUE;
  1350. }
  1351. }
  1352. return (tags);
  1353. }
  1354. /*
  1355. * Determines the queue depth for a given device.
  1356. */
  1357. static void
  1358. ahd_linux_device_queue_depth(struct scsi_device *sdev)
  1359. {
  1360. struct ahd_devinfo devinfo;
  1361. u_int tags;
  1362. struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
  1363. ahd_compile_devinfo(&devinfo,
  1364. ahd->our_id,
  1365. sdev->sdev_target->id, sdev->lun,
  1366. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1367. ROLE_INITIATOR);
  1368. tags = ahd_linux_user_tagdepth(ahd, &devinfo);
  1369. if (tags != 0 && sdev->tagged_supported != 0) {
  1370. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
  1371. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1372. devinfo.lun, AC_TRANSFER_NEG);
  1373. ahd_print_devinfo(ahd, &devinfo);
  1374. printk("Tagged Queuing enabled. Depth %d\n", tags);
  1375. } else {
  1376. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
  1377. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1378. devinfo.lun, AC_TRANSFER_NEG);
  1379. }
  1380. }
  1381. static int
  1382. ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
  1383. struct scsi_cmnd *cmd)
  1384. {
  1385. struct scb *scb;
  1386. struct hardware_scb *hscb;
  1387. struct ahd_initiator_tinfo *tinfo;
  1388. struct ahd_tmode_tstate *tstate;
  1389. u_int col_idx;
  1390. uint16_t mask;
  1391. unsigned long flags;
  1392. int nseg;
  1393. nseg = scsi_dma_map(cmd);
  1394. if (nseg < 0)
  1395. return SCSI_MLQUEUE_HOST_BUSY;
  1396. ahd_lock(ahd, &flags);
  1397. /*
  1398. * Get an scb to use.
  1399. */
  1400. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1401. cmd->device->id, &tstate);
  1402. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
  1403. || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  1404. col_idx = AHD_NEVER_COL_IDX;
  1405. } else {
  1406. col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
  1407. cmd->device->lun);
  1408. }
  1409. if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
  1410. ahd->flags |= AHD_RESOURCE_SHORTAGE;
  1411. ahd_unlock(ahd, &flags);
  1412. scsi_dma_unmap(cmd);
  1413. return SCSI_MLQUEUE_HOST_BUSY;
  1414. }
  1415. scb->io_ctx = cmd;
  1416. scb->platform_data->dev = dev;
  1417. hscb = scb->hscb;
  1418. cmd->host_scribble = (char *)scb;
  1419. /*
  1420. * Fill out basics of the HSCB.
  1421. */
  1422. hscb->control = 0;
  1423. hscb->scsiid = BUILD_SCSIID(ahd, cmd);
  1424. hscb->lun = cmd->device->lun;
  1425. scb->hscb->task_management = 0;
  1426. mask = SCB_GET_TARGET_MASK(ahd, scb);
  1427. if ((ahd->user_discenable & mask) != 0)
  1428. hscb->control |= DISCENB;
  1429. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
  1430. scb->flags |= SCB_PACKETIZED;
  1431. if ((tstate->auto_negotiate & mask) != 0) {
  1432. scb->flags |= SCB_AUTO_NEGOTIATE;
  1433. scb->hscb->control |= MK_MESSAGE;
  1434. }
  1435. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
  1436. int msg_bytes;
  1437. uint8_t tag_msgs[2];
  1438. msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
  1439. if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
  1440. hscb->control |= tag_msgs[0];
  1441. if (tag_msgs[0] == MSG_ORDERED_TASK)
  1442. dev->commands_since_idle_or_otag = 0;
  1443. } else
  1444. if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
  1445. && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
  1446. hscb->control |= MSG_ORDERED_TASK;
  1447. dev->commands_since_idle_or_otag = 0;
  1448. } else {
  1449. hscb->control |= MSG_SIMPLE_TASK;
  1450. }
  1451. }
  1452. hscb->cdb_len = cmd->cmd_len;
  1453. memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
  1454. scb->platform_data->xfer_len = 0;
  1455. ahd_set_residual(scb, 0);
  1456. ahd_set_sense_residual(scb, 0);
  1457. scb->sg_count = 0;
  1458. if (nseg > 0) {
  1459. void *sg = scb->sg_list;
  1460. struct scatterlist *cur_seg;
  1461. int i;
  1462. scb->platform_data->xfer_len = 0;
  1463. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1464. dma_addr_t addr;
  1465. bus_size_t len;
  1466. addr = sg_dma_address(cur_seg);
  1467. len = sg_dma_len(cur_seg);
  1468. scb->platform_data->xfer_len += len;
  1469. sg = ahd_sg_setup(ahd, scb, sg, addr, len,
  1470. i == (nseg - 1));
  1471. }
  1472. }
  1473. LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
  1474. dev->openings--;
  1475. dev->active++;
  1476. dev->commands_issued++;
  1477. if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
  1478. dev->commands_since_idle_or_otag++;
  1479. scb->flags |= SCB_ACTIVE;
  1480. ahd_queue_scb(ahd, scb);
  1481. ahd_unlock(ahd, &flags);
  1482. return 0;
  1483. }
  1484. /*
  1485. * SCSI controller interrupt handler.
  1486. */
  1487. irqreturn_t
  1488. ahd_linux_isr(int irq, void *dev_id)
  1489. {
  1490. struct ahd_softc *ahd;
  1491. u_long flags;
  1492. int ours;
  1493. ahd = (struct ahd_softc *) dev_id;
  1494. ahd_lock(ahd, &flags);
  1495. ours = ahd_intr(ahd);
  1496. ahd_unlock(ahd, &flags);
  1497. return IRQ_RETVAL(ours);
  1498. }
  1499. void
  1500. ahd_send_async(struct ahd_softc *ahd, char channel,
  1501. u_int target, u_int lun, ac_code code)
  1502. {
  1503. switch (code) {
  1504. case AC_TRANSFER_NEG:
  1505. {
  1506. char buf[80];
  1507. struct scsi_target *starget;
  1508. struct info_str info;
  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. info.buffer = buf;
  1514. info.length = sizeof(buf);
  1515. info.offset = 0;
  1516. info.pos = 0;
  1517. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  1518. target, &tstate);
  1519. /*
  1520. * Don't bother reporting results while
  1521. * negotiations are still pending.
  1522. */
  1523. if (tinfo->curr.period != tinfo->goal.period
  1524. || tinfo->curr.width != tinfo->goal.width
  1525. || tinfo->curr.offset != tinfo->goal.offset
  1526. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1527. if (bootverbose == 0)
  1528. break;
  1529. /*
  1530. * Don't bother reporting results that
  1531. * are identical to those last reported.
  1532. */
  1533. starget = ahd->platform_data->starget[target];
  1534. if (starget == NULL)
  1535. break;
  1536. target_ppr_options =
  1537. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1538. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1539. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
  1540. + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
  1541. + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
  1542. + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
  1543. + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
  1544. + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
  1545. if (tinfo->curr.period == spi_period(starget)
  1546. && tinfo->curr.width == spi_width(starget)
  1547. && tinfo->curr.offset == spi_offset(starget)
  1548. && tinfo->curr.ppr_options == target_ppr_options)
  1549. if (bootverbose == 0)
  1550. break;
  1551. spi_period(starget) = tinfo->curr.period;
  1552. spi_width(starget) = tinfo->curr.width;
  1553. spi_offset(starget) = tinfo->curr.offset;
  1554. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1555. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1556. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1557. spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
  1558. spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
  1559. spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
  1560. spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
  1561. spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
  1562. spi_display_xfer_agreement(starget);
  1563. break;
  1564. }
  1565. case AC_SENT_BDR:
  1566. {
  1567. WARN_ON(lun != CAM_LUN_WILDCARD);
  1568. scsi_report_device_reset(ahd->platform_data->host,
  1569. channel - 'A', target);
  1570. break;
  1571. }
  1572. case AC_BUS_RESET:
  1573. if (ahd->platform_data->host != NULL) {
  1574. scsi_report_bus_reset(ahd->platform_data->host,
  1575. channel - 'A');
  1576. }
  1577. break;
  1578. default:
  1579. panic("ahd_send_async: Unexpected async event");
  1580. }
  1581. }
  1582. /*
  1583. * Calls the higher level scsi done function and frees the scb.
  1584. */
  1585. void
  1586. ahd_done(struct ahd_softc *ahd, struct scb *scb)
  1587. {
  1588. struct scsi_cmnd *cmd;
  1589. struct ahd_linux_device *dev;
  1590. if ((scb->flags & SCB_ACTIVE) == 0) {
  1591. printk("SCB %d done'd twice\n", SCB_GET_TAG(scb));
  1592. ahd_dump_card_state(ahd);
  1593. panic("Stopping for safety");
  1594. }
  1595. LIST_REMOVE(scb, pending_links);
  1596. cmd = scb->io_ctx;
  1597. dev = scb->platform_data->dev;
  1598. dev->active--;
  1599. dev->openings++;
  1600. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1601. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1602. dev->qfrozen--;
  1603. }
  1604. ahd_linux_unmap_scb(ahd, scb);
  1605. /*
  1606. * Guard against stale sense data.
  1607. * The Linux mid-layer assumes that sense
  1608. * was retrieved anytime the first byte of
  1609. * the sense buffer looks "sane".
  1610. */
  1611. cmd->sense_buffer[0] = 0;
  1612. if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1613. uint32_t amount_xferred;
  1614. amount_xferred =
  1615. ahd_get_transfer_length(scb) - ahd_get_residual(scb);
  1616. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1617. #ifdef AHD_DEBUG
  1618. if ((ahd_debug & AHD_SHOW_MISC) != 0) {
  1619. ahd_print_path(ahd, scb);
  1620. printk("Set CAM_UNCOR_PARITY\n");
  1621. }
  1622. #endif
  1623. ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1624. #ifdef AHD_REPORT_UNDERFLOWS
  1625. /*
  1626. * This code is disabled by default as some
  1627. * clients of the SCSI system do not properly
  1628. * initialize the underflow parameter. This
  1629. * results in spurious termination of commands
  1630. * that complete as expected (e.g. underflow is
  1631. * allowed as command can return variable amounts
  1632. * of data.
  1633. */
  1634. } else if (amount_xferred < scb->io_ctx->underflow) {
  1635. u_int i;
  1636. ahd_print_path(ahd, scb);
  1637. printk("CDB:");
  1638. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1639. printk(" 0x%x", scb->io_ctx->cmnd[i]);
  1640. printk("\n");
  1641. ahd_print_path(ahd, scb);
  1642. printk("Saw underflow (%ld of %ld bytes). "
  1643. "Treated as error\n",
  1644. ahd_get_residual(scb),
  1645. ahd_get_transfer_length(scb));
  1646. ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1647. #endif
  1648. } else {
  1649. ahd_set_transaction_status(scb, CAM_REQ_CMP);
  1650. }
  1651. } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1652. ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
  1653. }
  1654. if (dev->openings == 1
  1655. && ahd_get_transaction_status(scb) == CAM_REQ_CMP
  1656. && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1657. dev->tag_success_count++;
  1658. /*
  1659. * Some devices deal with temporary internal resource
  1660. * shortages by returning queue full. When the queue
  1661. * full occurrs, we throttle back. Slowly try to get
  1662. * back to our previous queue depth.
  1663. */
  1664. if ((dev->openings + dev->active) < dev->maxtags
  1665. && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
  1666. dev->tag_success_count = 0;
  1667. dev->openings++;
  1668. }
  1669. if (dev->active == 0)
  1670. dev->commands_since_idle_or_otag = 0;
  1671. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1672. printk("Recovery SCB completes\n");
  1673. if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
  1674. || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1675. ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1676. if (ahd->platform_data->eh_done)
  1677. complete(ahd->platform_data->eh_done);
  1678. }
  1679. ahd_free_scb(ahd, scb);
  1680. ahd_linux_queue_cmd_complete(ahd, cmd);
  1681. }
  1682. static void
  1683. ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
  1684. struct scsi_device *sdev, struct scb *scb)
  1685. {
  1686. struct ahd_devinfo devinfo;
  1687. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  1688. ahd_compile_devinfo(&devinfo,
  1689. ahd->our_id,
  1690. sdev->sdev_target->id, sdev->lun,
  1691. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1692. ROLE_INITIATOR);
  1693. /*
  1694. * We don't currently trust the mid-layer to
  1695. * properly deal with queue full or busy. So,
  1696. * when one occurs, we tell the mid-layer to
  1697. * unconditionally requeue the command to us
  1698. * so that we can retry it ourselves. We also
  1699. * implement our own throttling mechanism so
  1700. * we don't clobber the device with too many
  1701. * commands.
  1702. */
  1703. switch (ahd_get_scsi_status(scb)) {
  1704. default:
  1705. break;
  1706. case SCSI_STATUS_CHECK_COND:
  1707. case SCSI_STATUS_CMD_TERMINATED:
  1708. {
  1709. struct scsi_cmnd *cmd;
  1710. /*
  1711. * Copy sense information to the OS's cmd
  1712. * structure if it is available.
  1713. */
  1714. cmd = scb->io_ctx;
  1715. if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
  1716. struct scsi_status_iu_header *siu;
  1717. u_int sense_size;
  1718. u_int sense_offset;
  1719. if (scb->flags & SCB_SENSE) {
  1720. sense_size = min(sizeof(struct scsi_sense_data)
  1721. - ahd_get_sense_residual(scb),
  1722. (u_long)SCSI_SENSE_BUFFERSIZE);
  1723. sense_offset = 0;
  1724. } else {
  1725. /*
  1726. * Copy only the sense data into the provided
  1727. * buffer.
  1728. */
  1729. siu = (struct scsi_status_iu_header *)
  1730. scb->sense_data;
  1731. sense_size = min_t(size_t,
  1732. scsi_4btoul(siu->sense_length),
  1733. SCSI_SENSE_BUFFERSIZE);
  1734. sense_offset = SIU_SENSE_OFFSET(siu);
  1735. }
  1736. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  1737. memcpy(cmd->sense_buffer,
  1738. ahd_get_sense_buf(ahd, scb)
  1739. + sense_offset, sense_size);
  1740. cmd->result |= (DRIVER_SENSE << 24);
  1741. #ifdef AHD_DEBUG
  1742. if (ahd_debug & AHD_SHOW_SENSE) {
  1743. int i;
  1744. printk("Copied %d bytes of sense data at %d:",
  1745. sense_size, sense_offset);
  1746. for (i = 0; i < sense_size; i++) {
  1747. if ((i & 0xF) == 0)
  1748. printk("\n");
  1749. printk("0x%x ", cmd->sense_buffer[i]);
  1750. }
  1751. printk("\n");
  1752. }
  1753. #endif
  1754. }
  1755. break;
  1756. }
  1757. case SCSI_STATUS_QUEUE_FULL:
  1758. /*
  1759. * By the time the core driver has returned this
  1760. * command, all other commands that were queued
  1761. * to us but not the device have been returned.
  1762. * This ensures that dev->active is equal to
  1763. * the number of commands actually queued to
  1764. * the device.
  1765. */
  1766. dev->tag_success_count = 0;
  1767. if (dev->active != 0) {
  1768. /*
  1769. * Drop our opening count to the number
  1770. * of commands currently outstanding.
  1771. */
  1772. dev->openings = 0;
  1773. #ifdef AHD_DEBUG
  1774. if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
  1775. ahd_print_path(ahd, scb);
  1776. printk("Dropping tag count to %d\n",
  1777. dev->active);
  1778. }
  1779. #endif
  1780. if (dev->active == dev->tags_on_last_queuefull) {
  1781. dev->last_queuefull_same_count++;
  1782. /*
  1783. * If we repeatedly see a queue full
  1784. * at the same queue depth, this
  1785. * device has a fixed number of tag
  1786. * slots. Lock in this tag depth
  1787. * so we stop seeing queue fulls from
  1788. * this device.
  1789. */
  1790. if (dev->last_queuefull_same_count
  1791. == AHD_LOCK_TAGS_COUNT) {
  1792. dev->maxtags = dev->active;
  1793. ahd_print_path(ahd, scb);
  1794. printk("Locking max tag count at %d\n",
  1795. dev->active);
  1796. }
  1797. } else {
  1798. dev->tags_on_last_queuefull = dev->active;
  1799. dev->last_queuefull_same_count = 0;
  1800. }
  1801. ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1802. ahd_set_scsi_status(scb, SCSI_STATUS_OK);
  1803. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1804. (dev->flags & AHD_DEV_Q_BASIC)
  1805. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1806. break;
  1807. }
  1808. /*
  1809. * Drop down to a single opening, and treat this
  1810. * as if the target returned BUSY SCSI status.
  1811. */
  1812. dev->openings = 1;
  1813. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1814. (dev->flags & AHD_DEV_Q_BASIC)
  1815. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1816. ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
  1817. }
  1818. }
  1819. static void
  1820. ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
  1821. {
  1822. int status;
  1823. int new_status = DID_OK;
  1824. int do_fallback = 0;
  1825. int scsi_status;
  1826. /*
  1827. * Map CAM error codes into Linux Error codes. We
  1828. * avoid the conversion so that the DV code has the
  1829. * full error information available when making
  1830. * state change decisions.
  1831. */
  1832. status = ahd_cmd_get_transaction_status(cmd);
  1833. switch (status) {
  1834. case CAM_REQ_INPROG:
  1835. case CAM_REQ_CMP:
  1836. new_status = DID_OK;
  1837. break;
  1838. case CAM_AUTOSENSE_FAIL:
  1839. new_status = DID_ERROR;
  1840. /* Fallthrough */
  1841. case CAM_SCSI_STATUS_ERROR:
  1842. scsi_status = ahd_cmd_get_scsi_status(cmd);
  1843. switch(scsi_status) {
  1844. case SCSI_STATUS_CMD_TERMINATED:
  1845. case SCSI_STATUS_CHECK_COND:
  1846. if ((cmd->result >> 24) != DRIVER_SENSE) {
  1847. do_fallback = 1;
  1848. } else {
  1849. struct scsi_sense_data *sense;
  1850. sense = (struct scsi_sense_data *)
  1851. cmd->sense_buffer;
  1852. if (sense->extra_len >= 5 &&
  1853. (sense->add_sense_code == 0x47
  1854. || sense->add_sense_code == 0x48))
  1855. do_fallback = 1;
  1856. }
  1857. break;
  1858. default:
  1859. break;
  1860. }
  1861. break;
  1862. case CAM_REQ_ABORTED:
  1863. new_status = DID_ABORT;
  1864. break;
  1865. case CAM_BUSY:
  1866. new_status = DID_BUS_BUSY;
  1867. break;
  1868. case CAM_REQ_INVALID:
  1869. case CAM_PATH_INVALID:
  1870. new_status = DID_BAD_TARGET;
  1871. break;
  1872. case CAM_SEL_TIMEOUT:
  1873. new_status = DID_NO_CONNECT;
  1874. break;
  1875. case CAM_SCSI_BUS_RESET:
  1876. case CAM_BDR_SENT:
  1877. new_status = DID_RESET;
  1878. break;
  1879. case CAM_UNCOR_PARITY:
  1880. new_status = DID_PARITY;
  1881. do_fallback = 1;
  1882. break;
  1883. case CAM_CMD_TIMEOUT:
  1884. new_status = DID_TIME_OUT;
  1885. do_fallback = 1;
  1886. break;
  1887. case CAM_REQ_CMP_ERR:
  1888. case CAM_UNEXP_BUSFREE:
  1889. case CAM_DATA_RUN_ERR:
  1890. new_status = DID_ERROR;
  1891. do_fallback = 1;
  1892. break;
  1893. case CAM_UA_ABORT:
  1894. case CAM_NO_HBA:
  1895. case CAM_SEQUENCE_FAIL:
  1896. case CAM_CCB_LEN_ERR:
  1897. case CAM_PROVIDE_FAIL:
  1898. case CAM_REQ_TERMIO:
  1899. case CAM_UNREC_HBA_ERROR:
  1900. case CAM_REQ_TOO_BIG:
  1901. new_status = DID_ERROR;
  1902. break;
  1903. case CAM_REQUEUE_REQ:
  1904. new_status = DID_REQUEUE;
  1905. break;
  1906. default:
  1907. /* We should never get here */
  1908. new_status = DID_ERROR;
  1909. break;
  1910. }
  1911. if (do_fallback) {
  1912. printk("%s: device overrun (status %x) on %d:%d:%d\n",
  1913. ahd_name(ahd), status, cmd->device->channel,
  1914. cmd->device->id, cmd->device->lun);
  1915. }
  1916. ahd_cmd_set_transaction_status(cmd, new_status);
  1917. cmd->scsi_done(cmd);
  1918. }
  1919. static void
  1920. ahd_freeze_simq(struct ahd_softc *ahd)
  1921. {
  1922. scsi_block_requests(ahd->platform_data->host);
  1923. }
  1924. static void
  1925. ahd_release_simq(struct ahd_softc *ahd)
  1926. {
  1927. scsi_unblock_requests(ahd->platform_data->host);
  1928. }
  1929. static int
  1930. ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd)
  1931. {
  1932. struct ahd_softc *ahd;
  1933. struct ahd_linux_device *dev;
  1934. struct scb *pending_scb;
  1935. u_int saved_scbptr;
  1936. u_int active_scbptr;
  1937. u_int last_phase;
  1938. u_int saved_scsiid;
  1939. u_int cdb_byte;
  1940. int retval;
  1941. int was_paused;
  1942. int paused;
  1943. int wait;
  1944. int disconnected;
  1945. ahd_mode_state saved_modes;
  1946. unsigned long flags;
  1947. pending_scb = NULL;
  1948. paused = FALSE;
  1949. wait = FALSE;
  1950. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  1951. scmd_printk(KERN_INFO, cmd,
  1952. "Attempting to queue an ABORT message:");
  1953. printk("CDB:");
  1954. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1955. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  1956. printk("\n");
  1957. ahd_lock(ahd, &flags);
  1958. /*
  1959. * First determine if we currently own this command.
  1960. * Start by searching the device queue. If not found
  1961. * there, check the pending_scb list. If not found
  1962. * at all, and the system wanted us to just abort the
  1963. * command, return success.
  1964. */
  1965. dev = scsi_transport_device_data(cmd->device);
  1966. if (dev == NULL) {
  1967. /*
  1968. * No target device for this command exists,
  1969. * so we must not still own the command.
  1970. */
  1971. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  1972. retval = SUCCESS;
  1973. goto no_cmd;
  1974. }
  1975. /*
  1976. * See if we can find a matching cmd in the pending list.
  1977. */
  1978. LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
  1979. if (pending_scb->io_ctx == cmd)
  1980. break;
  1981. }
  1982. if (pending_scb == NULL) {
  1983. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1984. goto no_cmd;
  1985. }
  1986. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1987. /*
  1988. * We can't queue two recovery actions using the same SCB
  1989. */
  1990. retval = FAILED;
  1991. goto done;
  1992. }
  1993. /*
  1994. * Ensure that the card doesn't do anything
  1995. * behind our back. Also make sure that we
  1996. * didn't "just" miss an interrupt that would
  1997. * affect this cmd.
  1998. */
  1999. was_paused = ahd_is_paused(ahd);
  2000. ahd_pause_and_flushwork(ahd);
  2001. paused = TRUE;
  2002. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  2003. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  2004. goto no_cmd;
  2005. }
  2006. printk("%s: At time of recovery, card was %spaused\n",
  2007. ahd_name(ahd), was_paused ? "" : "not ");
  2008. ahd_dump_card_state(ahd);
  2009. disconnected = TRUE;
  2010. if (ahd_search_qinfifo(ahd, cmd->device->id,
  2011. cmd->device->channel + 'A',
  2012. cmd->device->lun,
  2013. pending_scb->hscb->tag,
  2014. ROLE_INITIATOR, CAM_REQ_ABORTED,
  2015. SEARCH_COMPLETE) > 0) {
  2016. printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  2017. ahd_name(ahd), cmd->device->channel,
  2018. cmd->device->id, cmd->device->lun);
  2019. retval = SUCCESS;
  2020. goto done;
  2021. }
  2022. saved_modes = ahd_save_modes(ahd);
  2023. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  2024. last_phase = ahd_inb(ahd, LASTPHASE);
  2025. saved_scbptr = ahd_get_scbptr(ahd);
  2026. active_scbptr = saved_scbptr;
  2027. if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  2028. struct scb *bus_scb;
  2029. bus_scb = ahd_lookup_scb(ahd, active_scbptr);
  2030. if (bus_scb == pending_scb)
  2031. disconnected = FALSE;
  2032. }
  2033. /*
  2034. * At this point, pending_scb is the scb associated with the
  2035. * passed in command. That command is currently active on the
  2036. * bus or is in the disconnected state.
  2037. */
  2038. saved_scsiid = ahd_inb(ahd, SAVED_SCSIID);
  2039. if (last_phase != P_BUSFREE
  2040. && SCB_GET_TAG(pending_scb) == active_scbptr) {
  2041. /*
  2042. * We're active on the bus, so assert ATN
  2043. * and hope that the target responds.
  2044. */
  2045. pending_scb = ahd_lookup_scb(ahd, active_scbptr);
  2046. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2047. ahd_outb(ahd, MSG_OUT, HOST_MSG);
  2048. ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
  2049. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  2050. wait = TRUE;
  2051. } else if (disconnected) {
  2052. /*
  2053. * Actually re-queue this SCB in an attempt
  2054. * to select the device before it reconnects.
  2055. */
  2056. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2057. ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
  2058. pending_scb->hscb->cdb_len = 0;
  2059. pending_scb->hscb->task_attribute = 0;
  2060. pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
  2061. if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
  2062. /*
  2063. * Mark the SCB has having an outstanding
  2064. * task management function. Should the command
  2065. * complete normally before the task management
  2066. * function can be sent, the host will be notified
  2067. * to abort our requeued SCB.
  2068. */
  2069. ahd_outb(ahd, SCB_TASK_MANAGEMENT,
  2070. pending_scb->hscb->task_management);
  2071. } else {
  2072. /*
  2073. * If non-packetized, set the MK_MESSAGE control
  2074. * bit indicating that we desire to send a message.
  2075. * We also set the disconnected flag since there is
  2076. * no guarantee that our SCB control byte matches
  2077. * the version on the card. We don't want the
  2078. * sequencer to abort the command thinking an
  2079. * unsolicited reselection occurred.
  2080. */
  2081. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2082. /*
  2083. * The sequencer will never re-reference the
  2084. * in-core SCB. To make sure we are notified
  2085. * during reselection, set the MK_MESSAGE flag in
  2086. * the card's copy of the SCB.
  2087. */
  2088. ahd_outb(ahd, SCB_CONTROL,
  2089. ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
  2090. }
  2091. /*
  2092. * Clear out any entries in the QINFIFO first
  2093. * so we are the next SCB for this target
  2094. * to run.
  2095. */
  2096. ahd_search_qinfifo(ahd, cmd->device->id,
  2097. cmd->device->channel + 'A', cmd->device->lun,
  2098. SCB_LIST_NULL, ROLE_INITIATOR,
  2099. CAM_REQUEUE_REQ, SEARCH_COMPLETE);
  2100. ahd_qinfifo_requeue_tail(ahd, pending_scb);
  2101. ahd_set_scbptr(ahd, saved_scbptr);
  2102. ahd_print_path(ahd, pending_scb);
  2103. printk("Device is disconnected, re-queuing SCB\n");
  2104. wait = TRUE;
  2105. } else {
  2106. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2107. retval = FAILED;
  2108. goto done;
  2109. }
  2110. no_cmd:
  2111. /*
  2112. * Our assumption is that if we don't have the command, no
  2113. * recovery action was required, so we return success. Again,
  2114. * the semantics of the mid-layer recovery engine are not
  2115. * well defined, so this may change in time.
  2116. */
  2117. retval = SUCCESS;
  2118. done:
  2119. if (paused)
  2120. ahd_unpause(ahd);
  2121. if (wait) {
  2122. DECLARE_COMPLETION_ONSTACK(done);
  2123. ahd->platform_data->eh_done = &done;
  2124. ahd_unlock(ahd, &flags);
  2125. printk("%s: Recovery code sleeping\n", ahd_name(ahd));
  2126. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  2127. ahd_lock(ahd, &flags);
  2128. ahd->platform_data->eh_done = NULL;
  2129. ahd_unlock(ahd, &flags);
  2130. printk("%s: Timer Expired (active %d)\n",
  2131. ahd_name(ahd), dev->active);
  2132. retval = FAILED;
  2133. }
  2134. printk("Recovery code awake\n");
  2135. } else
  2136. ahd_unlock(ahd, &flags);
  2137. if (retval != SUCCESS)
  2138. printk("%s: Command abort returning 0x%x\n",
  2139. ahd_name(ahd), retval);
  2140. return retval;
  2141. }
  2142. static void ahd_linux_set_width(struct scsi_target *starget, int width)
  2143. {
  2144. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2145. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2146. struct ahd_devinfo devinfo;
  2147. unsigned long flags;
  2148. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2149. starget->channel + 'A', ROLE_INITIATOR);
  2150. ahd_lock(ahd, &flags);
  2151. ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
  2152. ahd_unlock(ahd, &flags);
  2153. }
  2154. static void ahd_linux_set_period(struct scsi_target *starget, int period)
  2155. {
  2156. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2157. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2158. struct ahd_tmode_tstate *tstate;
  2159. struct ahd_initiator_tinfo *tinfo
  2160. = ahd_fetch_transinfo(ahd,
  2161. starget->channel + 'A',
  2162. shost->this_id, starget->id, &tstate);
  2163. struct ahd_devinfo devinfo;
  2164. unsigned int ppr_options = tinfo->goal.ppr_options;
  2165. unsigned int dt;
  2166. unsigned long flags;
  2167. unsigned long offset = tinfo->goal.offset;
  2168. #ifdef AHD_DEBUG
  2169. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2170. printk("%s: set period to %d\n", ahd_name(ahd), period);
  2171. #endif
  2172. if (offset == 0)
  2173. offset = MAX_OFFSET;
  2174. if (period < 8)
  2175. period = 8;
  2176. if (period < 10) {
  2177. if (spi_max_width(starget)) {
  2178. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2179. if (period == 8)
  2180. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2181. } else
  2182. period = 10;
  2183. }
  2184. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2185. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2186. starget->channel + 'A', ROLE_INITIATOR);
  2187. /* all PPR requests apart from QAS require wide transfers */
  2188. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2189. if (spi_width(starget) == 0)
  2190. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2191. }
  2192. ahd_find_syncrate(ahd, &period, &ppr_options,
  2193. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2194. ahd_lock(ahd, &flags);
  2195. ahd_set_syncrate(ahd, &devinfo, period, offset,
  2196. ppr_options, AHD_TRANS_GOAL, FALSE);
  2197. ahd_unlock(ahd, &flags);
  2198. }
  2199. static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
  2200. {
  2201. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2202. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2203. struct ahd_tmode_tstate *tstate;
  2204. struct ahd_initiator_tinfo *tinfo
  2205. = ahd_fetch_transinfo(ahd,
  2206. starget->channel + 'A',
  2207. shost->this_id, starget->id, &tstate);
  2208. struct ahd_devinfo devinfo;
  2209. unsigned int ppr_options = 0;
  2210. unsigned int period = 0;
  2211. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2212. unsigned long flags;
  2213. #ifdef AHD_DEBUG
  2214. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2215. printk("%s: set offset to %d\n", ahd_name(ahd), offset);
  2216. #endif
  2217. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2218. starget->channel + 'A', ROLE_INITIATOR);
  2219. if (offset != 0) {
  2220. period = tinfo->goal.period;
  2221. ppr_options = tinfo->goal.ppr_options;
  2222. ahd_find_syncrate(ahd, &period, &ppr_options,
  2223. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2224. }
  2225. ahd_lock(ahd, &flags);
  2226. ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
  2227. AHD_TRANS_GOAL, FALSE);
  2228. ahd_unlock(ahd, &flags);
  2229. }
  2230. static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
  2231. {
  2232. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2233. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2234. struct ahd_tmode_tstate *tstate;
  2235. struct ahd_initiator_tinfo *tinfo
  2236. = ahd_fetch_transinfo(ahd,
  2237. starget->channel + 'A',
  2238. shost->this_id, starget->id, &tstate);
  2239. struct ahd_devinfo devinfo;
  2240. unsigned int ppr_options = tinfo->goal.ppr_options
  2241. & ~MSG_EXT_PPR_DT_REQ;
  2242. unsigned int period = tinfo->goal.period;
  2243. unsigned int width = tinfo->goal.width;
  2244. unsigned long flags;
  2245. #ifdef AHD_DEBUG
  2246. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2247. printk("%s: %s DT\n", ahd_name(ahd),
  2248. dt ? "enabling" : "disabling");
  2249. #endif
  2250. if (dt && spi_max_width(starget)) {
  2251. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2252. if (!width)
  2253. ahd_linux_set_width(starget, 1);
  2254. } else {
  2255. if (period <= 9)
  2256. period = 10; /* If resetting DT, period must be >= 25ns */
  2257. /* IU is invalid without DT set */
  2258. ppr_options &= ~MSG_EXT_PPR_IU_REQ;
  2259. }
  2260. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2261. starget->channel + 'A', ROLE_INITIATOR);
  2262. ahd_find_syncrate(ahd, &period, &ppr_options,
  2263. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2264. ahd_lock(ahd, &flags);
  2265. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2266. ppr_options, AHD_TRANS_GOAL, FALSE);
  2267. ahd_unlock(ahd, &flags);
  2268. }
  2269. static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
  2270. {
  2271. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2272. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2273. struct ahd_tmode_tstate *tstate;
  2274. struct ahd_initiator_tinfo *tinfo
  2275. = ahd_fetch_transinfo(ahd,
  2276. starget->channel + 'A',
  2277. shost->this_id, starget->id, &tstate);
  2278. struct ahd_devinfo devinfo;
  2279. unsigned int ppr_options = tinfo->goal.ppr_options
  2280. & ~MSG_EXT_PPR_QAS_REQ;
  2281. unsigned int period = tinfo->goal.period;
  2282. unsigned int dt;
  2283. unsigned long flags;
  2284. #ifdef AHD_DEBUG
  2285. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2286. printk("%s: %s QAS\n", ahd_name(ahd),
  2287. qas ? "enabling" : "disabling");
  2288. #endif
  2289. if (qas) {
  2290. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2291. }
  2292. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2293. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2294. starget->channel + 'A', ROLE_INITIATOR);
  2295. ahd_find_syncrate(ahd, &period, &ppr_options,
  2296. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2297. ahd_lock(ahd, &flags);
  2298. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2299. ppr_options, AHD_TRANS_GOAL, FALSE);
  2300. ahd_unlock(ahd, &flags);
  2301. }
  2302. static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
  2303. {
  2304. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2305. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2306. struct ahd_tmode_tstate *tstate;
  2307. struct ahd_initiator_tinfo *tinfo
  2308. = ahd_fetch_transinfo(ahd,
  2309. starget->channel + 'A',
  2310. shost->this_id, starget->id, &tstate);
  2311. struct ahd_devinfo devinfo;
  2312. unsigned int ppr_options = tinfo->goal.ppr_options
  2313. & ~MSG_EXT_PPR_IU_REQ;
  2314. unsigned int period = tinfo->goal.period;
  2315. unsigned int dt;
  2316. unsigned long flags;
  2317. #ifdef AHD_DEBUG
  2318. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2319. printk("%s: %s IU\n", ahd_name(ahd),
  2320. iu ? "enabling" : "disabling");
  2321. #endif
  2322. if (iu && spi_max_width(starget)) {
  2323. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2324. ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
  2325. }
  2326. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2327. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2328. starget->channel + 'A', ROLE_INITIATOR);
  2329. ahd_find_syncrate(ahd, &period, &ppr_options,
  2330. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2331. ahd_lock(ahd, &flags);
  2332. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2333. ppr_options, AHD_TRANS_GOAL, FALSE);
  2334. ahd_unlock(ahd, &flags);
  2335. }
  2336. static void ahd_linux_set_rd_strm(struct scsi_target *starget, int rdstrm)
  2337. {
  2338. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2339. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2340. struct ahd_tmode_tstate *tstate;
  2341. struct ahd_initiator_tinfo *tinfo
  2342. = ahd_fetch_transinfo(ahd,
  2343. starget->channel + 'A',
  2344. shost->this_id, starget->id, &tstate);
  2345. struct ahd_devinfo devinfo;
  2346. unsigned int ppr_options = tinfo->goal.ppr_options
  2347. & ~MSG_EXT_PPR_RD_STRM;
  2348. unsigned int period = tinfo->goal.period;
  2349. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2350. unsigned long flags;
  2351. #ifdef AHD_DEBUG
  2352. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2353. printk("%s: %s Read Streaming\n", ahd_name(ahd),
  2354. rdstrm ? "enabling" : "disabling");
  2355. #endif
  2356. if (rdstrm && spi_max_width(starget))
  2357. ppr_options |= MSG_EXT_PPR_RD_STRM;
  2358. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2359. starget->channel + 'A', ROLE_INITIATOR);
  2360. ahd_find_syncrate(ahd, &period, &ppr_options,
  2361. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2362. ahd_lock(ahd, &flags);
  2363. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2364. ppr_options, AHD_TRANS_GOAL, FALSE);
  2365. ahd_unlock(ahd, &flags);
  2366. }
  2367. static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
  2368. {
  2369. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2370. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2371. struct ahd_tmode_tstate *tstate;
  2372. struct ahd_initiator_tinfo *tinfo
  2373. = ahd_fetch_transinfo(ahd,
  2374. starget->channel + 'A',
  2375. shost->this_id, starget->id, &tstate);
  2376. struct ahd_devinfo devinfo;
  2377. unsigned int ppr_options = tinfo->goal.ppr_options
  2378. & ~MSG_EXT_PPR_WR_FLOW;
  2379. unsigned int period = tinfo->goal.period;
  2380. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2381. unsigned long flags;
  2382. #ifdef AHD_DEBUG
  2383. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2384. printk("%s: %s Write Flow Control\n", ahd_name(ahd),
  2385. wrflow ? "enabling" : "disabling");
  2386. #endif
  2387. if (wrflow && spi_max_width(starget))
  2388. ppr_options |= MSG_EXT_PPR_WR_FLOW;
  2389. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2390. starget->channel + 'A', ROLE_INITIATOR);
  2391. ahd_find_syncrate(ahd, &period, &ppr_options,
  2392. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2393. ahd_lock(ahd, &flags);
  2394. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2395. ppr_options, AHD_TRANS_GOAL, FALSE);
  2396. ahd_unlock(ahd, &flags);
  2397. }
  2398. static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
  2399. {
  2400. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2401. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2402. struct ahd_tmode_tstate *tstate;
  2403. struct ahd_initiator_tinfo *tinfo
  2404. = ahd_fetch_transinfo(ahd,
  2405. starget->channel + 'A',
  2406. shost->this_id, starget->id, &tstate);
  2407. struct ahd_devinfo devinfo;
  2408. unsigned int ppr_options = tinfo->goal.ppr_options
  2409. & ~MSG_EXT_PPR_RTI;
  2410. unsigned int period = tinfo->goal.period;
  2411. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2412. unsigned long flags;
  2413. if ((ahd->features & AHD_RTI) == 0) {
  2414. #ifdef AHD_DEBUG
  2415. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2416. printk("%s: RTI not available\n", ahd_name(ahd));
  2417. #endif
  2418. return;
  2419. }
  2420. #ifdef AHD_DEBUG
  2421. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2422. printk("%s: %s RTI\n", ahd_name(ahd),
  2423. rti ? "enabling" : "disabling");
  2424. #endif
  2425. if (rti && spi_max_width(starget))
  2426. ppr_options |= MSG_EXT_PPR_RTI;
  2427. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2428. starget->channel + 'A', ROLE_INITIATOR);
  2429. ahd_find_syncrate(ahd, &period, &ppr_options,
  2430. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2431. ahd_lock(ahd, &flags);
  2432. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2433. ppr_options, AHD_TRANS_GOAL, FALSE);
  2434. ahd_unlock(ahd, &flags);
  2435. }
  2436. static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
  2437. {
  2438. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2439. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2440. struct ahd_tmode_tstate *tstate;
  2441. struct ahd_initiator_tinfo *tinfo
  2442. = ahd_fetch_transinfo(ahd,
  2443. starget->channel + 'A',
  2444. shost->this_id, starget->id, &tstate);
  2445. struct ahd_devinfo devinfo;
  2446. unsigned int ppr_options = tinfo->goal.ppr_options
  2447. & ~MSG_EXT_PPR_PCOMP_EN;
  2448. unsigned int period = tinfo->goal.period;
  2449. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2450. unsigned long flags;
  2451. #ifdef AHD_DEBUG
  2452. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2453. printk("%s: %s Precompensation\n", ahd_name(ahd),
  2454. pcomp ? "Enable" : "Disable");
  2455. #endif
  2456. if (pcomp && spi_max_width(starget)) {
  2457. uint8_t precomp;
  2458. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  2459. const struct ahd_linux_iocell_opts *iocell_opts;
  2460. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  2461. precomp = iocell_opts->precomp;
  2462. } else {
  2463. precomp = AIC79XX_DEFAULT_PRECOMP;
  2464. }
  2465. ppr_options |= MSG_EXT_PPR_PCOMP_EN;
  2466. AHD_SET_PRECOMP(ahd, precomp);
  2467. } else {
  2468. AHD_SET_PRECOMP(ahd, 0);
  2469. }
  2470. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2471. starget->channel + 'A', ROLE_INITIATOR);
  2472. ahd_find_syncrate(ahd, &period, &ppr_options,
  2473. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2474. ahd_lock(ahd, &flags);
  2475. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2476. ppr_options, AHD_TRANS_GOAL, FALSE);
  2477. ahd_unlock(ahd, &flags);
  2478. }
  2479. static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
  2480. {
  2481. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2482. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2483. struct ahd_tmode_tstate *tstate;
  2484. struct ahd_initiator_tinfo *tinfo
  2485. = ahd_fetch_transinfo(ahd,
  2486. starget->channel + 'A',
  2487. shost->this_id, starget->id, &tstate);
  2488. struct ahd_devinfo devinfo;
  2489. unsigned int ppr_options = tinfo->goal.ppr_options
  2490. & ~MSG_EXT_PPR_HOLD_MCS;
  2491. unsigned int period = tinfo->goal.period;
  2492. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2493. unsigned long flags;
  2494. if (hold && spi_max_width(starget))
  2495. ppr_options |= MSG_EXT_PPR_HOLD_MCS;
  2496. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2497. starget->channel + 'A', ROLE_INITIATOR);
  2498. ahd_find_syncrate(ahd, &period, &ppr_options,
  2499. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2500. ahd_lock(ahd, &flags);
  2501. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2502. ppr_options, AHD_TRANS_GOAL, FALSE);
  2503. ahd_unlock(ahd, &flags);
  2504. }
  2505. static void ahd_linux_get_signalling(struct Scsi_Host *shost)
  2506. {
  2507. struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
  2508. unsigned long flags;
  2509. u8 mode;
  2510. ahd_lock(ahd, &flags);
  2511. ahd_pause(ahd);
  2512. mode = ahd_inb(ahd, SBLKCTL);
  2513. ahd_unpause(ahd);
  2514. ahd_unlock(ahd, &flags);
  2515. if (mode & ENAB40)
  2516. spi_signalling(shost) = SPI_SIGNAL_LVD;
  2517. else if (mode & ENAB20)
  2518. spi_signalling(shost) = SPI_SIGNAL_SE;
  2519. else
  2520. spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
  2521. }
  2522. static struct spi_function_template ahd_linux_transport_functions = {
  2523. .set_offset = ahd_linux_set_offset,
  2524. .show_offset = 1,
  2525. .set_period = ahd_linux_set_period,
  2526. .show_period = 1,
  2527. .set_width = ahd_linux_set_width,
  2528. .show_width = 1,
  2529. .set_dt = ahd_linux_set_dt,
  2530. .show_dt = 1,
  2531. .set_iu = ahd_linux_set_iu,
  2532. .show_iu = 1,
  2533. .set_qas = ahd_linux_set_qas,
  2534. .show_qas = 1,
  2535. .set_rd_strm = ahd_linux_set_rd_strm,
  2536. .show_rd_strm = 1,
  2537. .set_wr_flow = ahd_linux_set_wr_flow,
  2538. .show_wr_flow = 1,
  2539. .set_rti = ahd_linux_set_rti,
  2540. .show_rti = 1,
  2541. .set_pcomp_en = ahd_linux_set_pcomp_en,
  2542. .show_pcomp_en = 1,
  2543. .set_hold_mcs = ahd_linux_set_hold_mcs,
  2544. .show_hold_mcs = 1,
  2545. .get_signalling = ahd_linux_get_signalling,
  2546. };
  2547. static int __init
  2548. ahd_linux_init(void)
  2549. {
  2550. int error = 0;
  2551. /*
  2552. * If we've been passed any parameters, process them now.
  2553. */
  2554. if (aic79xx)
  2555. aic79xx_setup(aic79xx);
  2556. ahd_linux_transport_template =
  2557. spi_attach_transport(&ahd_linux_transport_functions);
  2558. if (!ahd_linux_transport_template)
  2559. return -ENODEV;
  2560. scsi_transport_reserve_device(ahd_linux_transport_template,
  2561. sizeof(struct ahd_linux_device));
  2562. error = ahd_linux_pci_init();
  2563. if (error)
  2564. spi_release_transport(ahd_linux_transport_template);
  2565. return error;
  2566. }
  2567. static void __exit
  2568. ahd_linux_exit(void)
  2569. {
  2570. ahd_linux_pci_exit();
  2571. spi_release_transport(ahd_linux_transport_template);
  2572. }
  2573. module_init(ahd_linux_init);
  2574. module_exit(ahd_linux_exit);