aic79xx_osm.c 76 KB

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