aic79xx_osm.c 78 KB

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