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