aic79xx_osm.c 77 KB

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