aic79xx_osm.c 77 KB

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