aic79xx_osm.c 78 KB

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