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