aic7xxx_osm.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625
  1. /*
  2. * Adaptec AIC7xxx device driver for Linux.
  3. *
  4. * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_osm.c#235 $
  5. *
  6. * Copyright (c) 1994 John Aycock
  7. * The University of Calgary Department of Computer Science.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; see the file COPYING. If not, write to
  21. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. * Sources include the Adaptec 1740 driver (aha1740.c), the Ultrastor 24F
  24. * driver (ultrastor.c), various Linux kernel source, the Adaptec EISA
  25. * config file (!adp7771.cfg), the Adaptec AHA-2740A Series User's Guide,
  26. * the Linux Kernel Hacker's Guide, Writing a SCSI Device Driver for Linux,
  27. * the Adaptec 1542 driver (aha1542.c), the Adaptec EISA overlay file
  28. * (adp7770.ovl), the Adaptec AHA-2740 Series Technical Reference Manual,
  29. * the Adaptec AIC-7770 Data Book, the ANSI SCSI specification, the
  30. * ANSI SCSI-2 specification (draft 10c), ...
  31. *
  32. * --------------------------------------------------------------------------
  33. *
  34. * Modifications by Daniel M. Eischen (deischen@iworks.InterWorks.org):
  35. *
  36. * Substantially modified to include support for wide and twin bus
  37. * adapters, DMAing of SCBs, tagged queueing, IRQ sharing, bug fixes,
  38. * SCB paging, and other rework of the code.
  39. *
  40. * --------------------------------------------------------------------------
  41. * Copyright (c) 1994-2000 Justin T. Gibbs.
  42. * Copyright (c) 2000-2001 Adaptec Inc.
  43. * All rights reserved.
  44. *
  45. * Redistribution and use in source and binary forms, with or without
  46. * modification, are permitted provided that the following conditions
  47. * are met:
  48. * 1. Redistributions of source code must retain the above copyright
  49. * notice, this list of conditions, and the following disclaimer,
  50. * without modification.
  51. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  52. * substantially similar to the "NO WARRANTY" disclaimer below
  53. * ("Disclaimer") and any redistribution must be conditioned upon
  54. * including a substantially similar Disclaimer requirement for further
  55. * binary redistribution.
  56. * 3. Neither the names of the above-listed copyright holders nor the names
  57. * of any contributors may be used to endorse or promote products derived
  58. * from this software without specific prior written permission.
  59. *
  60. * Alternatively, this software may be distributed under the terms of the
  61. * GNU General Public License ("GPL") version 2 as published by the Free
  62. * Software Foundation.
  63. *
  64. * NO WARRANTY
  65. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  66. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  67. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  68. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  69. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  70. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  71. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  72. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  73. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  74. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  75. * POSSIBILITY OF SUCH DAMAGES.
  76. *
  77. *---------------------------------------------------------------------------
  78. *
  79. * Thanks also go to (in alphabetical order) the following:
  80. *
  81. * Rory Bolt - Sequencer bug fixes
  82. * Jay Estabrook - Initial DEC Alpha support
  83. * Doug Ledford - Much needed abort/reset bug fixes
  84. * Kai Makisara - DMAing of SCBs
  85. *
  86. * A Boot time option was also added for not resetting the scsi bus.
  87. *
  88. * Form: aic7xxx=extended
  89. * aic7xxx=no_reset
  90. * aic7xxx=verbose
  91. *
  92. * Daniel M. Eischen, deischen@iworks.InterWorks.org, 1/23/97
  93. *
  94. * Id: aic7xxx.c,v 4.1 1997/06/12 08:23:42 deang Exp
  95. */
  96. /*
  97. * Further driver modifications made by Doug Ledford <dledford@redhat.com>
  98. *
  99. * Copyright (c) 1997-1999 Doug Ledford
  100. *
  101. * These changes are released under the same licensing terms as the FreeBSD
  102. * driver written by Justin Gibbs. Please see his Copyright notice above
  103. * for the exact terms and conditions covering my changes as well as the
  104. * warranty statement.
  105. *
  106. * Modifications made to the aic7xxx.c,v 4.1 driver from Dan Eischen include
  107. * but are not limited to:
  108. *
  109. * 1: Import of the latest FreeBSD sequencer code for this driver
  110. * 2: Modification of kernel code to accommodate different sequencer semantics
  111. * 3: Extensive changes throughout kernel portion of driver to improve
  112. * abort/reset processing and error hanndling
  113. * 4: Other work contributed by various people on the Internet
  114. * 5: Changes to printk information and verbosity selection code
  115. * 6: General reliability related changes, especially in IRQ management
  116. * 7: Modifications to the default probe/attach order for supported cards
  117. * 8: SMP friendliness has been improved
  118. *
  119. */
  120. #include "aic7xxx_osm.h"
  121. #include "aic7xxx_inline.h"
  122. #include <scsi/scsicam.h>
  123. static struct scsi_transport_template *ahc_linux_transport_template = NULL;
  124. #include <linux/init.h> /* __setup */
  125. #include <linux/mm.h> /* For fetching system memory size */
  126. #include <linux/blkdev.h> /* For block_size() */
  127. #include <linux/delay.h> /* For ssleep/msleep */
  128. #include <linux/slab.h>
  129. /*
  130. * Set this to the delay in seconds after SCSI bus reset.
  131. * Note, we honor this only for the initial bus reset.
  132. * The scsi error recovery code performs its own bus settle
  133. * delay handling for error recovery actions.
  134. */
  135. #ifdef CONFIG_AIC7XXX_RESET_DELAY_MS
  136. #define AIC7XXX_RESET_DELAY CONFIG_AIC7XXX_RESET_DELAY_MS
  137. #else
  138. #define AIC7XXX_RESET_DELAY 5000
  139. #endif
  140. /*
  141. * Control collection of SCSI transfer statistics for the /proc filesystem.
  142. *
  143. * NOTE: Do NOT enable this when running on kernels version 1.2.x and below.
  144. * NOTE: This does affect performance since it has to maintain statistics.
  145. */
  146. #ifdef CONFIG_AIC7XXX_PROC_STATS
  147. #define AIC7XXX_PROC_STATS
  148. #endif
  149. /*
  150. * To change the default number of tagged transactions allowed per-device,
  151. * add a line to the lilo.conf file like:
  152. * append="aic7xxx=verbose,tag_info:{{32,32,32,32},{32,32,32,32}}"
  153. * which will result in the first four devices on the first two
  154. * controllers being set to a tagged queue depth of 32.
  155. *
  156. * The tag_commands is an array of 16 to allow for wide and twin adapters.
  157. * Twin adapters will use indexes 0-7 for channel 0, and indexes 8-15
  158. * for channel 1.
  159. */
  160. typedef struct {
  161. uint8_t tag_commands[16]; /* Allow for wide/twin adapters. */
  162. } adapter_tag_info_t;
  163. /*
  164. * Modify this as you see fit for your system.
  165. *
  166. * 0 tagged queuing disabled
  167. * 1 <= n <= 253 n == max tags ever dispatched.
  168. *
  169. * The driver will throttle the number of commands dispatched to a
  170. * device if it returns queue full. For devices with a fixed maximum
  171. * queue depth, the driver will eventually determine this depth and
  172. * lock it in (a console message is printed to indicate that a lock
  173. * has occurred). On some devices, queue full is returned for a temporary
  174. * resource shortage. These devices will return queue full at varying
  175. * depths. The driver will throttle back when the queue fulls occur and
  176. * attempt to slowly increase the depth over time as the device recovers
  177. * from the resource shortage.
  178. *
  179. * In this example, the first line will disable tagged queueing for all
  180. * the devices on the first probed aic7xxx adapter.
  181. *
  182. * The second line enables tagged queueing with 4 commands/LUN for IDs
  183. * (0, 2-11, 13-15), disables tagged queueing for ID 12, and tells the
  184. * driver to attempt to use up to 64 tags for ID 1.
  185. *
  186. * The third line is the same as the first line.
  187. *
  188. * The fourth line disables tagged queueing for devices 0 and 3. It
  189. * enables tagged queueing for the other IDs, with 16 commands/LUN
  190. * for IDs 1 and 4, 127 commands/LUN for ID 8, and 4 commands/LUN for
  191. * IDs 2, 5-7, and 9-15.
  192. */
  193. /*
  194. * NOTE: The below structure is for reference only, the actual structure
  195. * to modify in order to change things is just below this comment block.
  196. adapter_tag_info_t aic7xxx_tag_info[] =
  197. {
  198. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  199. {{4, 64, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4}},
  200. {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
  201. {{0, 16, 4, 0, 16, 4, 4, 4, 127, 4, 4, 4, 4, 4, 4, 4}}
  202. };
  203. */
  204. #ifdef CONFIG_AIC7XXX_CMDS_PER_DEVICE
  205. #define AIC7XXX_CMDS_PER_DEVICE CONFIG_AIC7XXX_CMDS_PER_DEVICE
  206. #else
  207. #define AIC7XXX_CMDS_PER_DEVICE AHC_MAX_QUEUE
  208. #endif
  209. #define AIC7XXX_CONFIGED_TAG_COMMANDS { \
  210. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  211. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  212. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  213. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  214. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  215. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  216. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE, \
  217. AIC7XXX_CMDS_PER_DEVICE, AIC7XXX_CMDS_PER_DEVICE \
  218. }
  219. /*
  220. * By default, use the number of commands specified by
  221. * the users kernel configuration.
  222. */
  223. static adapter_tag_info_t aic7xxx_tag_info[] =
  224. {
  225. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  226. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  227. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  228. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  229. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  230. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  231. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  232. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  233. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  234. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  235. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  236. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  237. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  238. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  239. {AIC7XXX_CONFIGED_TAG_COMMANDS},
  240. {AIC7XXX_CONFIGED_TAG_COMMANDS}
  241. };
  242. /*
  243. * There should be a specific return value for this in scsi.h, but
  244. * it seems that most drivers ignore it.
  245. */
  246. #define DID_UNDERFLOW DID_ERROR
  247. void
  248. ahc_print_path(struct ahc_softc *ahc, struct scb *scb)
  249. {
  250. printk("(scsi%d:%c:%d:%d): ",
  251. ahc->platform_data->host->host_no,
  252. scb != NULL ? SCB_GET_CHANNEL(ahc, scb) : 'X',
  253. scb != NULL ? SCB_GET_TARGET(ahc, scb) : -1,
  254. scb != NULL ? SCB_GET_LUN(scb) : -1);
  255. }
  256. /*
  257. * XXX - these options apply unilaterally to _all_ 274x/284x/294x
  258. * cards in the system. This should be fixed. Exceptions to this
  259. * rule are noted in the comments.
  260. */
  261. /*
  262. * Skip the scsi bus reset. Non 0 make us skip the reset at startup. This
  263. * has no effect on any later resets that might occur due to things like
  264. * SCSI bus timeouts.
  265. */
  266. static uint32_t aic7xxx_no_reset;
  267. /*
  268. * Should we force EXTENDED translation on a controller.
  269. * 0 == Use whatever is in the SEEPROM or default to off
  270. * 1 == Use whatever is in the SEEPROM or default to on
  271. */
  272. static uint32_t aic7xxx_extended;
  273. /*
  274. * PCI bus parity checking of the Adaptec controllers. This is somewhat
  275. * dubious at best. To my knowledge, this option has never actually
  276. * solved a PCI parity problem, but on certain machines with broken PCI
  277. * chipset configurations where stray PCI transactions with bad parity are
  278. * the norm rather than the exception, the error messages can be overwhelming.
  279. * It's included in the driver for completeness.
  280. * 0 = Shut off PCI parity check
  281. * non-0 = reverse polarity pci parity checking
  282. */
  283. static uint32_t aic7xxx_pci_parity = ~0;
  284. /*
  285. * There are lots of broken chipsets in the world. Some of them will
  286. * violate the PCI spec when we issue byte sized memory writes to our
  287. * controller. I/O mapped register access, if allowed by the given
  288. * platform, will work in almost all cases.
  289. */
  290. uint32_t aic7xxx_allow_memio = ~0;
  291. /*
  292. * So that we can set how long each device is given as a selection timeout.
  293. * The table of values goes like this:
  294. * 0 - 256ms
  295. * 1 - 128ms
  296. * 2 - 64ms
  297. * 3 - 32ms
  298. * We default to 256ms because some older devices need a longer time
  299. * to respond to initial selection.
  300. */
  301. static uint32_t aic7xxx_seltime;
  302. /*
  303. * Certain devices do not perform any aging on commands. Should the
  304. * device be saturated by commands in one portion of the disk, it is
  305. * possible for transactions on far away sectors to never be serviced.
  306. * To handle these devices, we can periodically send an ordered tag to
  307. * force all outstanding transactions to be serviced prior to a new
  308. * transaction.
  309. */
  310. static uint32_t aic7xxx_periodic_otag;
  311. /*
  312. * Module information and settable options.
  313. */
  314. static char *aic7xxx = NULL;
  315. MODULE_AUTHOR("Maintainer: Hannes Reinecke <hare@suse.de>");
  316. MODULE_DESCRIPTION("Adaptec AIC77XX/78XX SCSI Host Bus Adapter driver");
  317. MODULE_LICENSE("Dual BSD/GPL");
  318. MODULE_VERSION(AIC7XXX_DRIVER_VERSION);
  319. module_param(aic7xxx, charp, 0444);
  320. MODULE_PARM_DESC(aic7xxx,
  321. "period-delimited options string:\n"
  322. " verbose Enable verbose/diagnostic logging\n"
  323. " allow_memio Allow device registers to be memory mapped\n"
  324. " debug Bitmask of debug values to enable\n"
  325. " no_probe Toggle EISA/VLB controller probing\n"
  326. " probe_eisa_vl Toggle EISA/VLB controller probing\n"
  327. " no_reset Suppress initial bus resets\n"
  328. " extended Enable extended geometry on all controllers\n"
  329. " periodic_otag Send an ordered tagged transaction\n"
  330. " periodically to prevent tag starvation.\n"
  331. " This may be required by some older disk\n"
  332. " drives or RAID arrays.\n"
  333. " tag_info:<tag_str> Set per-target tag depth\n"
  334. " global_tag_depth:<int> Global tag depth for every target\n"
  335. " on every bus\n"
  336. " seltime:<int> Selection Timeout\n"
  337. " (0/256ms,1/128ms,2/64ms,3/32ms)\n"
  338. "\n"
  339. " Sample /etc/modprobe.conf line:\n"
  340. " Toggle EISA/VLB probing\n"
  341. " Set tag depth on Controller 1/Target 1 to 10 tags\n"
  342. " Shorten the selection timeout to 128ms\n"
  343. "\n"
  344. " options aic7xxx 'aic7xxx=probe_eisa_vl.tag_info:{{}.{.10}}.seltime:1'\n"
  345. );
  346. static void ahc_linux_handle_scsi_status(struct ahc_softc *,
  347. struct scsi_device *,
  348. struct scb *);
  349. static void ahc_linux_queue_cmd_complete(struct ahc_softc *ahc,
  350. struct scsi_cmnd *cmd);
  351. static void ahc_linux_freeze_simq(struct ahc_softc *ahc);
  352. static void ahc_linux_release_simq(struct ahc_softc *ahc);
  353. static int ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag);
  354. static void ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc);
  355. static u_int ahc_linux_user_tagdepth(struct ahc_softc *ahc,
  356. struct ahc_devinfo *devinfo);
  357. static void ahc_linux_device_queue_depth(struct scsi_device *);
  358. static int ahc_linux_run_command(struct ahc_softc*,
  359. struct ahc_linux_device *,
  360. struct scsi_cmnd *);
  361. static void ahc_linux_setup_tag_info_global(char *p);
  362. static int aic7xxx_setup(char *s);
  363. static int ahc_linux_unit;
  364. /************************** OS Utility Wrappers *******************************/
  365. void
  366. ahc_delay(long usec)
  367. {
  368. /*
  369. * udelay on Linux can have problems for
  370. * multi-millisecond waits. Wait at most
  371. * 1024us per call.
  372. */
  373. while (usec > 0) {
  374. udelay(usec % 1024);
  375. usec -= 1024;
  376. }
  377. }
  378. /***************************** Low Level I/O **********************************/
  379. uint8_t
  380. ahc_inb(struct ahc_softc * ahc, long port)
  381. {
  382. uint8_t x;
  383. if (ahc->tag == BUS_SPACE_MEMIO) {
  384. x = readb(ahc->bsh.maddr + port);
  385. } else {
  386. x = inb(ahc->bsh.ioport + port);
  387. }
  388. mb();
  389. return (x);
  390. }
  391. void
  392. ahc_outb(struct ahc_softc * ahc, long port, uint8_t val)
  393. {
  394. if (ahc->tag == BUS_SPACE_MEMIO) {
  395. writeb(val, ahc->bsh.maddr + port);
  396. } else {
  397. outb(val, ahc->bsh.ioport + port);
  398. }
  399. mb();
  400. }
  401. void
  402. ahc_outsb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  403. {
  404. int i;
  405. /*
  406. * There is probably a more efficient way to do this on Linux
  407. * but we don't use this for anything speed critical and this
  408. * should work.
  409. */
  410. for (i = 0; i < count; i++)
  411. ahc_outb(ahc, port, *array++);
  412. }
  413. void
  414. ahc_insb(struct ahc_softc * ahc, long port, uint8_t *array, int count)
  415. {
  416. int i;
  417. /*
  418. * There is probably a more efficient way to do this on Linux
  419. * but we don't use this for anything speed critical and this
  420. * should work.
  421. */
  422. for (i = 0; i < count; i++)
  423. *array++ = ahc_inb(ahc, port);
  424. }
  425. /********************************* Inlines ************************************/
  426. static void ahc_linux_unmap_scb(struct ahc_softc*, struct scb*);
  427. static int ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
  428. struct ahc_dma_seg *sg,
  429. dma_addr_t addr, bus_size_t len);
  430. static void
  431. ahc_linux_unmap_scb(struct ahc_softc *ahc, struct scb *scb)
  432. {
  433. struct scsi_cmnd *cmd;
  434. cmd = scb->io_ctx;
  435. ahc_sync_sglist(ahc, scb, BUS_DMASYNC_POSTWRITE);
  436. scsi_dma_unmap(cmd);
  437. }
  438. static int
  439. ahc_linux_map_seg(struct ahc_softc *ahc, struct scb *scb,
  440. struct ahc_dma_seg *sg, dma_addr_t addr, bus_size_t len)
  441. {
  442. int consumed;
  443. if ((scb->sg_count + 1) > AHC_NSEG)
  444. panic("Too few segs for dma mapping. "
  445. "Increase AHC_NSEG\n");
  446. consumed = 1;
  447. sg->addr = ahc_htole32(addr & 0xFFFFFFFF);
  448. scb->platform_data->xfer_len += len;
  449. if (sizeof(dma_addr_t) > 4
  450. && (ahc->flags & AHC_39BIT_ADDRESSING) != 0)
  451. len |= (addr >> 8) & AHC_SG_HIGH_ADDR_MASK;
  452. sg->len = ahc_htole32(len);
  453. return (consumed);
  454. }
  455. /*
  456. * Return a string describing the driver.
  457. */
  458. static const char *
  459. ahc_linux_info(struct Scsi_Host *host)
  460. {
  461. static char buffer[512];
  462. char ahc_info[256];
  463. char *bp;
  464. struct ahc_softc *ahc;
  465. bp = &buffer[0];
  466. ahc = *(struct ahc_softc **)host->hostdata;
  467. memset(bp, 0, sizeof(buffer));
  468. strcpy(bp, "Adaptec AIC7XXX EISA/VLB/PCI SCSI HBA DRIVER, Rev " AIC7XXX_DRIVER_VERSION "\n"
  469. " <");
  470. strcat(bp, ahc->description);
  471. strcat(bp, ">\n"
  472. " ");
  473. ahc_controller_info(ahc, ahc_info);
  474. strcat(bp, ahc_info);
  475. strcat(bp, "\n");
  476. return (bp);
  477. }
  478. /*
  479. * Queue an SCB to the controller.
  480. */
  481. static int
  482. ahc_linux_queue_lck(struct scsi_cmnd * cmd, void (*scsi_done) (struct scsi_cmnd *))
  483. {
  484. struct ahc_softc *ahc;
  485. struct ahc_linux_device *dev = scsi_transport_device_data(cmd->device);
  486. int rtn = SCSI_MLQUEUE_HOST_BUSY;
  487. unsigned long flags;
  488. ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
  489. ahc_lock(ahc, &flags);
  490. if (ahc->platform_data->qfrozen == 0) {
  491. cmd->scsi_done = scsi_done;
  492. cmd->result = CAM_REQ_INPROG << 16;
  493. rtn = ahc_linux_run_command(ahc, dev, cmd);
  494. }
  495. ahc_unlock(ahc, &flags);
  496. return rtn;
  497. }
  498. static DEF_SCSI_QCMD(ahc_linux_queue)
  499. static inline struct scsi_target **
  500. ahc_linux_target_in_softc(struct scsi_target *starget)
  501. {
  502. struct ahc_softc *ahc =
  503. *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
  504. unsigned int target_offset;
  505. target_offset = starget->id;
  506. if (starget->channel != 0)
  507. target_offset += 8;
  508. return &ahc->platform_data->starget[target_offset];
  509. }
  510. static int
  511. ahc_linux_target_alloc(struct scsi_target *starget)
  512. {
  513. struct ahc_softc *ahc =
  514. *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
  515. struct seeprom_config *sc = ahc->seep_config;
  516. unsigned long flags;
  517. struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
  518. unsigned short scsirate;
  519. struct ahc_devinfo devinfo;
  520. struct ahc_initiator_tinfo *tinfo;
  521. struct ahc_tmode_tstate *tstate;
  522. char channel = starget->channel + 'A';
  523. unsigned int our_id = ahc->our_id;
  524. unsigned int target_offset;
  525. target_offset = starget->id;
  526. if (starget->channel != 0)
  527. target_offset += 8;
  528. if (starget->channel)
  529. our_id = ahc->our_id_b;
  530. ahc_lock(ahc, &flags);
  531. BUG_ON(*ahc_targp != NULL);
  532. *ahc_targp = starget;
  533. if (sc) {
  534. int maxsync = AHC_SYNCRATE_DT;
  535. int ultra = 0;
  536. int flags = sc->device_flags[target_offset];
  537. if (ahc->flags & AHC_NEWEEPROM_FMT) {
  538. if (flags & CFSYNCHISULTRA)
  539. ultra = 1;
  540. } else if (flags & CFULTRAEN)
  541. ultra = 1;
  542. /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04
  543. * change it to ultra=0, CFXFER = 0 */
  544. if(ultra && (flags & CFXFER) == 0x04) {
  545. ultra = 0;
  546. flags &= ~CFXFER;
  547. }
  548. if ((ahc->features & AHC_ULTRA2) != 0) {
  549. scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0);
  550. } else {
  551. scsirate = (flags & CFXFER) << 4;
  552. maxsync = ultra ? AHC_SYNCRATE_ULTRA :
  553. AHC_SYNCRATE_FAST;
  554. }
  555. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  556. if (!(flags & CFSYNCH))
  557. spi_max_offset(starget) = 0;
  558. spi_min_period(starget) =
  559. ahc_find_period(ahc, scsirate, maxsync);
  560. tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
  561. starget->id, &tstate);
  562. }
  563. ahc_compile_devinfo(&devinfo, our_id, starget->id,
  564. CAM_LUN_WILDCARD, channel,
  565. ROLE_INITIATOR);
  566. ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
  567. AHC_TRANS_GOAL, /*paused*/FALSE);
  568. ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  569. AHC_TRANS_GOAL, /*paused*/FALSE);
  570. ahc_unlock(ahc, &flags);
  571. return 0;
  572. }
  573. static void
  574. ahc_linux_target_destroy(struct scsi_target *starget)
  575. {
  576. struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
  577. *ahc_targp = NULL;
  578. }
  579. static int
  580. ahc_linux_slave_alloc(struct scsi_device *sdev)
  581. {
  582. struct ahc_softc *ahc =
  583. *((struct ahc_softc **)sdev->host->hostdata);
  584. struct scsi_target *starget = sdev->sdev_target;
  585. struct ahc_linux_device *dev;
  586. if (bootverbose)
  587. printk("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id);
  588. dev = scsi_transport_device_data(sdev);
  589. memset(dev, 0, sizeof(*dev));
  590. /*
  591. * We start out life using untagged
  592. * transactions of which we allow one.
  593. */
  594. dev->openings = 1;
  595. /*
  596. * Set maxtags to 0. This will be changed if we
  597. * later determine that we are dealing with
  598. * a tagged queuing capable device.
  599. */
  600. dev->maxtags = 0;
  601. spi_period(starget) = 0;
  602. return 0;
  603. }
  604. static int
  605. ahc_linux_slave_configure(struct scsi_device *sdev)
  606. {
  607. struct ahc_softc *ahc;
  608. ahc = *((struct ahc_softc **)sdev->host->hostdata);
  609. if (bootverbose)
  610. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  611. ahc_linux_device_queue_depth(sdev);
  612. /* Initial Domain Validation */
  613. if (!spi_initial_dv(sdev->sdev_target))
  614. spi_dv_device(sdev);
  615. return 0;
  616. }
  617. #if defined(__i386__)
  618. /*
  619. * Return the disk geometry for the given SCSI device.
  620. */
  621. static int
  622. ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  623. sector_t capacity, int geom[])
  624. {
  625. uint8_t *bh;
  626. int heads;
  627. int sectors;
  628. int cylinders;
  629. int ret;
  630. int extended;
  631. struct ahc_softc *ahc;
  632. u_int channel;
  633. ahc = *((struct ahc_softc **)sdev->host->hostdata);
  634. channel = sdev_channel(sdev);
  635. bh = scsi_bios_ptable(bdev);
  636. if (bh) {
  637. ret = scsi_partsize(bh, capacity,
  638. &geom[2], &geom[0], &geom[1]);
  639. kfree(bh);
  640. if (ret != -1)
  641. return (ret);
  642. }
  643. heads = 64;
  644. sectors = 32;
  645. cylinders = aic_sector_div(capacity, heads, sectors);
  646. if (aic7xxx_extended != 0)
  647. extended = 1;
  648. else if (channel == 0)
  649. extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0;
  650. else
  651. extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0;
  652. if (extended && cylinders >= 1024) {
  653. heads = 255;
  654. sectors = 63;
  655. cylinders = aic_sector_div(capacity, heads, sectors);
  656. }
  657. geom[0] = heads;
  658. geom[1] = sectors;
  659. geom[2] = cylinders;
  660. return (0);
  661. }
  662. #endif
  663. /*
  664. * Abort the current SCSI command(s).
  665. */
  666. static int
  667. ahc_linux_abort(struct scsi_cmnd *cmd)
  668. {
  669. int error;
  670. error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT);
  671. if (error != 0)
  672. printk("aic7xxx_abort returns 0x%x\n", error);
  673. return (error);
  674. }
  675. /*
  676. * Attempt to send a target reset message to the device that timed out.
  677. */
  678. static int
  679. ahc_linux_dev_reset(struct scsi_cmnd *cmd)
  680. {
  681. int error;
  682. error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
  683. if (error != 0)
  684. printk("aic7xxx_dev_reset returns 0x%x\n", error);
  685. return (error);
  686. }
  687. /*
  688. * Reset the SCSI bus.
  689. */
  690. static int
  691. ahc_linux_bus_reset(struct scsi_cmnd *cmd)
  692. {
  693. struct ahc_softc *ahc;
  694. int found;
  695. unsigned long flags;
  696. ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
  697. ahc_lock(ahc, &flags);
  698. found = ahc_reset_channel(ahc, scmd_channel(cmd) + 'A',
  699. /*initiate reset*/TRUE);
  700. ahc_unlock(ahc, &flags);
  701. if (bootverbose)
  702. printk("%s: SCSI bus reset delivered. "
  703. "%d SCBs aborted.\n", ahc_name(ahc), found);
  704. return SUCCESS;
  705. }
  706. struct scsi_host_template aic7xxx_driver_template = {
  707. .module = THIS_MODULE,
  708. .name = "aic7xxx",
  709. .proc_name = "aic7xxx",
  710. .proc_info = ahc_linux_proc_info,
  711. .info = ahc_linux_info,
  712. .queuecommand = ahc_linux_queue,
  713. .eh_abort_handler = ahc_linux_abort,
  714. .eh_device_reset_handler = ahc_linux_dev_reset,
  715. .eh_bus_reset_handler = ahc_linux_bus_reset,
  716. #if defined(__i386__)
  717. .bios_param = ahc_linux_biosparam,
  718. #endif
  719. .can_queue = AHC_MAX_QUEUE,
  720. .this_id = -1,
  721. .max_sectors = 8192,
  722. .cmd_per_lun = 2,
  723. .use_clustering = ENABLE_CLUSTERING,
  724. .slave_alloc = ahc_linux_slave_alloc,
  725. .slave_configure = ahc_linux_slave_configure,
  726. .target_alloc = ahc_linux_target_alloc,
  727. .target_destroy = ahc_linux_target_destroy,
  728. };
  729. /**************************** Tasklet Handler *********************************/
  730. /******************************** Macros **************************************/
  731. #define BUILD_SCSIID(ahc, cmd) \
  732. ((((cmd)->device->id << TID_SHIFT) & TID) \
  733. | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
  734. | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
  735. /******************************** Bus DMA *************************************/
  736. int
  737. ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
  738. bus_size_t alignment, bus_size_t boundary,
  739. dma_addr_t lowaddr, dma_addr_t highaddr,
  740. bus_dma_filter_t *filter, void *filterarg,
  741. bus_size_t maxsize, int nsegments,
  742. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  743. {
  744. bus_dma_tag_t dmat;
  745. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  746. if (dmat == NULL)
  747. return (ENOMEM);
  748. /*
  749. * Linux is very simplistic about DMA memory. For now don't
  750. * maintain all specification information. Once Linux supplies
  751. * better facilities for doing these operations, or the
  752. * needs of this particular driver change, we might need to do
  753. * more here.
  754. */
  755. dmat->alignment = alignment;
  756. dmat->boundary = boundary;
  757. dmat->maxsize = maxsize;
  758. *ret_tag = dmat;
  759. return (0);
  760. }
  761. void
  762. ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
  763. {
  764. kfree(dmat);
  765. }
  766. int
  767. ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
  768. int flags, bus_dmamap_t *mapp)
  769. {
  770. *vaddr = pci_alloc_consistent(ahc->dev_softc,
  771. dmat->maxsize, mapp);
  772. if (*vaddr == NULL)
  773. return ENOMEM;
  774. return 0;
  775. }
  776. void
  777. ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
  778. void* vaddr, bus_dmamap_t map)
  779. {
  780. pci_free_consistent(ahc->dev_softc, dmat->maxsize,
  781. vaddr, map);
  782. }
  783. int
  784. ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
  785. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  786. void *cb_arg, int flags)
  787. {
  788. /*
  789. * Assume for now that this will only be used during
  790. * initialization and not for per-transaction buffer mapping.
  791. */
  792. bus_dma_segment_t stack_sg;
  793. stack_sg.ds_addr = map;
  794. stack_sg.ds_len = dmat->maxsize;
  795. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  796. return (0);
  797. }
  798. void
  799. ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  800. {
  801. }
  802. int
  803. ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  804. {
  805. /* Nothing to do */
  806. return (0);
  807. }
  808. static void
  809. ahc_linux_setup_tag_info_global(char *p)
  810. {
  811. int tags, i, j;
  812. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  813. printk("Setting Global Tags= %d\n", tags);
  814. for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) {
  815. for (j = 0; j < AHC_NUM_TARGETS; j++) {
  816. aic7xxx_tag_info[i].tag_commands[j] = tags;
  817. }
  818. }
  819. }
  820. static void
  821. ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  822. {
  823. if ((instance >= 0) && (targ >= 0)
  824. && (instance < ARRAY_SIZE(aic7xxx_tag_info))
  825. && (targ < AHC_NUM_TARGETS)) {
  826. aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff;
  827. if (bootverbose)
  828. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  829. }
  830. }
  831. static char *
  832. ahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  833. void (*callback)(u_long, int, int, int32_t),
  834. u_long callback_arg)
  835. {
  836. char *tok_end;
  837. char *tok_end2;
  838. int i;
  839. int instance;
  840. int targ;
  841. int done;
  842. char tok_list[] = {'.', ',', '{', '}', '\0'};
  843. /* All options use a ':' name/arg separator */
  844. if (*opt_arg != ':')
  845. return (opt_arg);
  846. opt_arg++;
  847. instance = -1;
  848. targ = -1;
  849. done = FALSE;
  850. /*
  851. * Restore separator that may be in
  852. * the middle of our option argument.
  853. */
  854. tok_end = strchr(opt_arg, '\0');
  855. if (tok_end < end)
  856. *tok_end = ',';
  857. while (!done) {
  858. switch (*opt_arg) {
  859. case '{':
  860. if (instance == -1) {
  861. instance = 0;
  862. } else {
  863. if (depth > 1) {
  864. if (targ == -1)
  865. targ = 0;
  866. } else {
  867. printk("Malformed Option %s\n",
  868. opt_name);
  869. done = TRUE;
  870. }
  871. }
  872. opt_arg++;
  873. break;
  874. case '}':
  875. if (targ != -1)
  876. targ = -1;
  877. else if (instance != -1)
  878. instance = -1;
  879. opt_arg++;
  880. break;
  881. case ',':
  882. case '.':
  883. if (instance == -1)
  884. done = TRUE;
  885. else if (targ >= 0)
  886. targ++;
  887. else if (instance >= 0)
  888. instance++;
  889. opt_arg++;
  890. break;
  891. case '\0':
  892. done = TRUE;
  893. break;
  894. default:
  895. tok_end = end;
  896. for (i = 0; tok_list[i]; i++) {
  897. tok_end2 = strchr(opt_arg, tok_list[i]);
  898. if ((tok_end2) && (tok_end2 < tok_end))
  899. tok_end = tok_end2;
  900. }
  901. callback(callback_arg, instance, targ,
  902. simple_strtol(opt_arg, NULL, 0));
  903. opt_arg = tok_end;
  904. break;
  905. }
  906. }
  907. return (opt_arg);
  908. }
  909. /*
  910. * Handle Linux boot parameters. This routine allows for assigning a value
  911. * to a parameter with a ':' between the parameter and the value.
  912. * ie. aic7xxx=stpwlev:1,extended
  913. */
  914. static int
  915. aic7xxx_setup(char *s)
  916. {
  917. int i, n;
  918. char *p;
  919. char *end;
  920. static const struct {
  921. const char *name;
  922. uint32_t *flag;
  923. } options[] = {
  924. { "extended", &aic7xxx_extended },
  925. { "no_reset", &aic7xxx_no_reset },
  926. { "verbose", &aic7xxx_verbose },
  927. { "allow_memio", &aic7xxx_allow_memio},
  928. #ifdef AHC_DEBUG
  929. { "debug", &ahc_debug },
  930. #endif
  931. { "periodic_otag", &aic7xxx_periodic_otag },
  932. { "pci_parity", &aic7xxx_pci_parity },
  933. { "seltime", &aic7xxx_seltime },
  934. { "tag_info", NULL },
  935. { "global_tag_depth", NULL },
  936. { "dv", NULL }
  937. };
  938. end = strchr(s, '\0');
  939. /*
  940. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  941. * will never be 0 in this case.
  942. */
  943. n = 0;
  944. while ((p = strsep(&s, ",.")) != NULL) {
  945. if (*p == '\0')
  946. continue;
  947. for (i = 0; i < ARRAY_SIZE(options); i++) {
  948. n = strlen(options[i].name);
  949. if (strncmp(options[i].name, p, n) == 0)
  950. break;
  951. }
  952. if (i == ARRAY_SIZE(options))
  953. continue;
  954. if (strncmp(p, "global_tag_depth", n) == 0) {
  955. ahc_linux_setup_tag_info_global(p + n);
  956. } else if (strncmp(p, "tag_info", n) == 0) {
  957. s = ahc_parse_brace_option("tag_info", p + n, end,
  958. 2, ahc_linux_setup_tag_info, 0);
  959. } else if (p[n] == ':') {
  960. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  961. } else if (strncmp(p, "verbose", n) == 0) {
  962. *(options[i].flag) = 1;
  963. } else {
  964. *(options[i].flag) ^= 0xFFFFFFFF;
  965. }
  966. }
  967. return 1;
  968. }
  969. __setup("aic7xxx=", aic7xxx_setup);
  970. uint32_t aic7xxx_verbose;
  971. int
  972. ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
  973. {
  974. char buf[80];
  975. struct Scsi_Host *host;
  976. char *new_name;
  977. u_long s;
  978. int retval;
  979. template->name = ahc->description;
  980. host = scsi_host_alloc(template, sizeof(struct ahc_softc *));
  981. if (host == NULL)
  982. return (ENOMEM);
  983. *((struct ahc_softc **)host->hostdata) = ahc;
  984. ahc->platform_data->host = host;
  985. host->can_queue = AHC_MAX_QUEUE;
  986. host->cmd_per_lun = 2;
  987. /* XXX No way to communicate the ID for multiple channels */
  988. host->this_id = ahc->our_id;
  989. host->irq = ahc->platform_data->irq;
  990. host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
  991. host->max_lun = AHC_NUM_LUNS;
  992. host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
  993. host->sg_tablesize = AHC_NSEG;
  994. ahc_lock(ahc, &s);
  995. ahc_set_unit(ahc, ahc_linux_unit++);
  996. ahc_unlock(ahc, &s);
  997. sprintf(buf, "scsi%d", host->host_no);
  998. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  999. if (new_name != NULL) {
  1000. strcpy(new_name, buf);
  1001. ahc_set_name(ahc, new_name);
  1002. }
  1003. host->unique_id = ahc->unit;
  1004. ahc_linux_initialize_scsi_bus(ahc);
  1005. ahc_intr_enable(ahc, TRUE);
  1006. host->transportt = ahc_linux_transport_template;
  1007. retval = scsi_add_host(host,
  1008. (ahc->dev_softc ? &ahc->dev_softc->dev : NULL));
  1009. if (retval) {
  1010. printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
  1011. scsi_host_put(host);
  1012. return retval;
  1013. }
  1014. scsi_scan_host(host);
  1015. return 0;
  1016. }
  1017. /*
  1018. * Place the SCSI bus into a known state by either resetting it,
  1019. * or forcing transfer negotiations on the next command to any
  1020. * target.
  1021. */
  1022. void
  1023. ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
  1024. {
  1025. int i;
  1026. int numtarg;
  1027. unsigned long s;
  1028. i = 0;
  1029. numtarg = 0;
  1030. ahc_lock(ahc, &s);
  1031. if (aic7xxx_no_reset != 0)
  1032. ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
  1033. if ((ahc->flags & AHC_RESET_BUS_A) != 0)
  1034. ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
  1035. else
  1036. numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
  1037. if ((ahc->features & AHC_TWIN) != 0) {
  1038. if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
  1039. ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
  1040. } else {
  1041. if (numtarg == 0)
  1042. i = 8;
  1043. numtarg += 8;
  1044. }
  1045. }
  1046. /*
  1047. * Force negotiation to async for all targets that
  1048. * will not see an initial bus reset.
  1049. */
  1050. for (; i < numtarg; i++) {
  1051. struct ahc_devinfo devinfo;
  1052. struct ahc_initiator_tinfo *tinfo;
  1053. struct ahc_tmode_tstate *tstate;
  1054. u_int our_id;
  1055. u_int target_id;
  1056. char channel;
  1057. channel = 'A';
  1058. our_id = ahc->our_id;
  1059. target_id = i;
  1060. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  1061. channel = 'B';
  1062. our_id = ahc->our_id_b;
  1063. target_id = i % 8;
  1064. }
  1065. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  1066. target_id, &tstate);
  1067. ahc_compile_devinfo(&devinfo, our_id, target_id,
  1068. CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
  1069. ahc_update_neg_request(ahc, &devinfo, tstate,
  1070. tinfo, AHC_NEG_ALWAYS);
  1071. }
  1072. ahc_unlock(ahc, &s);
  1073. /* Give the bus some time to recover */
  1074. if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
  1075. ahc_linux_freeze_simq(ahc);
  1076. msleep(AIC7XXX_RESET_DELAY);
  1077. ahc_linux_release_simq(ahc);
  1078. }
  1079. }
  1080. int
  1081. ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
  1082. {
  1083. ahc->platform_data =
  1084. kmalloc(sizeof(struct ahc_platform_data), GFP_ATOMIC);
  1085. if (ahc->platform_data == NULL)
  1086. return (ENOMEM);
  1087. memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
  1088. ahc->platform_data->irq = AHC_LINUX_NOIRQ;
  1089. ahc_lockinit(ahc);
  1090. ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
  1091. ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
  1092. if (aic7xxx_pci_parity == 0)
  1093. ahc->flags |= AHC_DISABLE_PCI_PERR;
  1094. return (0);
  1095. }
  1096. void
  1097. ahc_platform_free(struct ahc_softc *ahc)
  1098. {
  1099. struct scsi_target *starget;
  1100. int i;
  1101. if (ahc->platform_data != NULL) {
  1102. /* destroy all of the device and target objects */
  1103. for (i = 0; i < AHC_NUM_TARGETS; i++) {
  1104. starget = ahc->platform_data->starget[i];
  1105. if (starget != NULL) {
  1106. ahc->platform_data->starget[i] = NULL;
  1107. }
  1108. }
  1109. if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
  1110. free_irq(ahc->platform_data->irq, ahc);
  1111. if (ahc->tag == BUS_SPACE_PIO
  1112. && ahc->bsh.ioport != 0)
  1113. release_region(ahc->bsh.ioport, 256);
  1114. if (ahc->tag == BUS_SPACE_MEMIO
  1115. && ahc->bsh.maddr != NULL) {
  1116. iounmap(ahc->bsh.maddr);
  1117. release_mem_region(ahc->platform_data->mem_busaddr,
  1118. 0x1000);
  1119. }
  1120. if (ahc->platform_data->host)
  1121. scsi_host_put(ahc->platform_data->host);
  1122. kfree(ahc->platform_data);
  1123. }
  1124. }
  1125. void
  1126. ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
  1127. {
  1128. ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
  1129. SCB_GET_CHANNEL(ahc, scb),
  1130. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1131. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1132. }
  1133. void
  1134. ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
  1135. struct ahc_devinfo *devinfo, ahc_queue_alg alg)
  1136. {
  1137. struct ahc_linux_device *dev;
  1138. int was_queuing;
  1139. int now_queuing;
  1140. if (sdev == NULL)
  1141. return;
  1142. dev = scsi_transport_device_data(sdev);
  1143. was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
  1144. switch (alg) {
  1145. default:
  1146. case AHC_QUEUE_NONE:
  1147. now_queuing = 0;
  1148. break;
  1149. case AHC_QUEUE_BASIC:
  1150. now_queuing = AHC_DEV_Q_BASIC;
  1151. break;
  1152. case AHC_QUEUE_TAGGED:
  1153. now_queuing = AHC_DEV_Q_TAGGED;
  1154. break;
  1155. }
  1156. if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
  1157. && (was_queuing != now_queuing)
  1158. && (dev->active != 0)) {
  1159. dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
  1160. dev->qfrozen++;
  1161. }
  1162. dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
  1163. if (now_queuing) {
  1164. u_int usertags;
  1165. usertags = ahc_linux_user_tagdepth(ahc, devinfo);
  1166. if (!was_queuing) {
  1167. /*
  1168. * Start out aggressively and allow our
  1169. * dynamic queue depth algorithm to take
  1170. * care of the rest.
  1171. */
  1172. dev->maxtags = usertags;
  1173. dev->openings = dev->maxtags - dev->active;
  1174. }
  1175. if (dev->maxtags == 0) {
  1176. /*
  1177. * Queueing is disabled by the user.
  1178. */
  1179. dev->openings = 1;
  1180. } else if (alg == AHC_QUEUE_TAGGED) {
  1181. dev->flags |= AHC_DEV_Q_TAGGED;
  1182. if (aic7xxx_periodic_otag != 0)
  1183. dev->flags |= AHC_DEV_PERIODIC_OTAG;
  1184. } else
  1185. dev->flags |= AHC_DEV_Q_BASIC;
  1186. } else {
  1187. /* We can only have one opening. */
  1188. dev->maxtags = 0;
  1189. dev->openings = 1 - dev->active;
  1190. }
  1191. switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
  1192. case AHC_DEV_Q_BASIC:
  1193. scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
  1194. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1195. break;
  1196. case AHC_DEV_Q_TAGGED:
  1197. scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
  1198. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1199. break;
  1200. default:
  1201. /*
  1202. * We allow the OS to queue 2 untagged transactions to
  1203. * us at any time even though we can only execute them
  1204. * serially on the controller/device. This should
  1205. * remove some latency.
  1206. */
  1207. scsi_deactivate_tcq(sdev, 2);
  1208. break;
  1209. }
  1210. }
  1211. int
  1212. ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
  1213. int lun, u_int tag, role_t role, uint32_t status)
  1214. {
  1215. return 0;
  1216. }
  1217. static u_int
  1218. ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
  1219. {
  1220. static int warned_user;
  1221. u_int tags;
  1222. tags = 0;
  1223. if ((ahc->user_discenable & devinfo->target_mask) != 0) {
  1224. if (ahc->unit >= ARRAY_SIZE(aic7xxx_tag_info)) {
  1225. if (warned_user == 0) {
  1226. printk(KERN_WARNING
  1227. "aic7xxx: WARNING: Insufficient tag_info instances\n"
  1228. "aic7xxx: for installed controllers. Using defaults\n"
  1229. "aic7xxx: Please update the aic7xxx_tag_info array in\n"
  1230. "aic7xxx: the aic7xxx_osm..c source file.\n");
  1231. warned_user++;
  1232. }
  1233. tags = AHC_MAX_QUEUE;
  1234. } else {
  1235. adapter_tag_info_t *tag_info;
  1236. tag_info = &aic7xxx_tag_info[ahc->unit];
  1237. tags = tag_info->tag_commands[devinfo->target_offset];
  1238. if (tags > AHC_MAX_QUEUE)
  1239. tags = AHC_MAX_QUEUE;
  1240. }
  1241. }
  1242. return (tags);
  1243. }
  1244. /*
  1245. * Determines the queue depth for a given device.
  1246. */
  1247. static void
  1248. ahc_linux_device_queue_depth(struct scsi_device *sdev)
  1249. {
  1250. struct ahc_devinfo devinfo;
  1251. u_int tags;
  1252. struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata);
  1253. ahc_compile_devinfo(&devinfo,
  1254. sdev->sdev_target->channel == 0
  1255. ? ahc->our_id : ahc->our_id_b,
  1256. sdev->sdev_target->id, sdev->lun,
  1257. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1258. ROLE_INITIATOR);
  1259. tags = ahc_linux_user_tagdepth(ahc, &devinfo);
  1260. if (tags != 0 && sdev->tagged_supported != 0) {
  1261. ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_TAGGED);
  1262. ahc_send_async(ahc, devinfo.channel, devinfo.target,
  1263. devinfo.lun, AC_TRANSFER_NEG);
  1264. ahc_print_devinfo(ahc, &devinfo);
  1265. printk("Tagged Queuing enabled. Depth %d\n", tags);
  1266. } else {
  1267. ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_NONE);
  1268. ahc_send_async(ahc, devinfo.channel, devinfo.target,
  1269. devinfo.lun, AC_TRANSFER_NEG);
  1270. }
  1271. }
  1272. static int
  1273. ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
  1274. struct scsi_cmnd *cmd)
  1275. {
  1276. struct scb *scb;
  1277. struct hardware_scb *hscb;
  1278. struct ahc_initiator_tinfo *tinfo;
  1279. struct ahc_tmode_tstate *tstate;
  1280. uint16_t mask;
  1281. struct scb_tailq *untagged_q = NULL;
  1282. int nseg;
  1283. /*
  1284. * Schedule us to run later. The only reason we are not
  1285. * running is because the whole controller Q is frozen.
  1286. */
  1287. if (ahc->platform_data->qfrozen != 0)
  1288. return SCSI_MLQUEUE_HOST_BUSY;
  1289. /*
  1290. * We only allow one untagged transaction
  1291. * per target in the initiator role unless
  1292. * we are storing a full busy target *lun*
  1293. * table in SCB space.
  1294. */
  1295. if (!blk_rq_tagged(cmd->request)
  1296. && (ahc->features & AHC_SCB_BTT) == 0) {
  1297. int target_offset;
  1298. target_offset = cmd->device->id + cmd->device->channel * 8;
  1299. untagged_q = &(ahc->untagged_queues[target_offset]);
  1300. if (!TAILQ_EMPTY(untagged_q))
  1301. /* if we're already executing an untagged command
  1302. * we're busy to another */
  1303. return SCSI_MLQUEUE_DEVICE_BUSY;
  1304. }
  1305. nseg = scsi_dma_map(cmd);
  1306. if (nseg < 0)
  1307. return SCSI_MLQUEUE_HOST_BUSY;
  1308. /*
  1309. * Get an scb to use.
  1310. */
  1311. scb = ahc_get_scb(ahc);
  1312. if (!scb) {
  1313. scsi_dma_unmap(cmd);
  1314. return SCSI_MLQUEUE_HOST_BUSY;
  1315. }
  1316. scb->io_ctx = cmd;
  1317. scb->platform_data->dev = dev;
  1318. hscb = scb->hscb;
  1319. cmd->host_scribble = (char *)scb;
  1320. /*
  1321. * Fill out basics of the HSCB.
  1322. */
  1323. hscb->control = 0;
  1324. hscb->scsiid = BUILD_SCSIID(ahc, cmd);
  1325. hscb->lun = cmd->device->lun;
  1326. mask = SCB_GET_TARGET_MASK(ahc, scb);
  1327. tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
  1328. SCB_GET_OUR_ID(scb),
  1329. SCB_GET_TARGET(ahc, scb), &tstate);
  1330. hscb->scsirate = tinfo->scsirate;
  1331. hscb->scsioffset = tinfo->curr.offset;
  1332. if ((tstate->ultraenb & mask) != 0)
  1333. hscb->control |= ULTRAENB;
  1334. if ((ahc->user_discenable & mask) != 0)
  1335. hscb->control |= DISCENB;
  1336. if ((tstate->auto_negotiate & mask) != 0) {
  1337. scb->flags |= SCB_AUTO_NEGOTIATE;
  1338. scb->hscb->control |= MK_MESSAGE;
  1339. }
  1340. if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
  1341. int msg_bytes;
  1342. uint8_t tag_msgs[2];
  1343. msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
  1344. if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
  1345. hscb->control |= tag_msgs[0];
  1346. if (tag_msgs[0] == MSG_ORDERED_TASK)
  1347. dev->commands_since_idle_or_otag = 0;
  1348. } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
  1349. && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
  1350. hscb->control |= MSG_ORDERED_TASK;
  1351. dev->commands_since_idle_or_otag = 0;
  1352. } else {
  1353. hscb->control |= MSG_SIMPLE_TASK;
  1354. }
  1355. }
  1356. hscb->cdb_len = cmd->cmd_len;
  1357. if (hscb->cdb_len <= 12) {
  1358. memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
  1359. } else {
  1360. memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
  1361. scb->flags |= SCB_CDB32_PTR;
  1362. }
  1363. scb->platform_data->xfer_len = 0;
  1364. ahc_set_residual(scb, 0);
  1365. ahc_set_sense_residual(scb, 0);
  1366. scb->sg_count = 0;
  1367. if (nseg > 0) {
  1368. struct ahc_dma_seg *sg;
  1369. struct scatterlist *cur_seg;
  1370. int i;
  1371. /* Copy the segments into the SG list. */
  1372. sg = scb->sg_list;
  1373. /*
  1374. * The sg_count may be larger than nseg if
  1375. * a transfer crosses a 32bit page.
  1376. */
  1377. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1378. dma_addr_t addr;
  1379. bus_size_t len;
  1380. int consumed;
  1381. addr = sg_dma_address(cur_seg);
  1382. len = sg_dma_len(cur_seg);
  1383. consumed = ahc_linux_map_seg(ahc, scb,
  1384. sg, addr, len);
  1385. sg += consumed;
  1386. scb->sg_count += consumed;
  1387. }
  1388. sg--;
  1389. sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
  1390. /*
  1391. * Reset the sg list pointer.
  1392. */
  1393. scb->hscb->sgptr =
  1394. ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
  1395. /*
  1396. * Copy the first SG into the "current"
  1397. * data pointer area.
  1398. */
  1399. scb->hscb->dataptr = scb->sg_list->addr;
  1400. scb->hscb->datacnt = scb->sg_list->len;
  1401. } else {
  1402. scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
  1403. scb->hscb->dataptr = 0;
  1404. scb->hscb->datacnt = 0;
  1405. scb->sg_count = 0;
  1406. }
  1407. LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
  1408. dev->openings--;
  1409. dev->active++;
  1410. dev->commands_issued++;
  1411. if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
  1412. dev->commands_since_idle_or_otag++;
  1413. scb->flags |= SCB_ACTIVE;
  1414. if (untagged_q) {
  1415. TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
  1416. scb->flags |= SCB_UNTAGGEDQ;
  1417. }
  1418. ahc_queue_scb(ahc, scb);
  1419. return 0;
  1420. }
  1421. /*
  1422. * SCSI controller interrupt handler.
  1423. */
  1424. irqreturn_t
  1425. ahc_linux_isr(int irq, void *dev_id)
  1426. {
  1427. struct ahc_softc *ahc;
  1428. u_long flags;
  1429. int ours;
  1430. ahc = (struct ahc_softc *) dev_id;
  1431. ahc_lock(ahc, &flags);
  1432. ours = ahc_intr(ahc);
  1433. ahc_unlock(ahc, &flags);
  1434. return IRQ_RETVAL(ours);
  1435. }
  1436. void
  1437. ahc_platform_flushwork(struct ahc_softc *ahc)
  1438. {
  1439. }
  1440. void
  1441. ahc_send_async(struct ahc_softc *ahc, char channel,
  1442. u_int target, u_int lun, ac_code code)
  1443. {
  1444. switch (code) {
  1445. case AC_TRANSFER_NEG:
  1446. {
  1447. char buf[80];
  1448. struct scsi_target *starget;
  1449. struct ahc_linux_target *targ;
  1450. struct info_str info;
  1451. struct ahc_initiator_tinfo *tinfo;
  1452. struct ahc_tmode_tstate *tstate;
  1453. int target_offset;
  1454. unsigned int target_ppr_options;
  1455. BUG_ON(target == CAM_TARGET_WILDCARD);
  1456. info.buffer = buf;
  1457. info.length = sizeof(buf);
  1458. info.offset = 0;
  1459. info.pos = 0;
  1460. tinfo = ahc_fetch_transinfo(ahc, channel,
  1461. channel == 'A' ? ahc->our_id
  1462. : ahc->our_id_b,
  1463. target, &tstate);
  1464. /*
  1465. * Don't bother reporting results while
  1466. * negotiations are still pending.
  1467. */
  1468. if (tinfo->curr.period != tinfo->goal.period
  1469. || tinfo->curr.width != tinfo->goal.width
  1470. || tinfo->curr.offset != tinfo->goal.offset
  1471. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1472. if (bootverbose == 0)
  1473. break;
  1474. /*
  1475. * Don't bother reporting results that
  1476. * are identical to those last reported.
  1477. */
  1478. target_offset = target;
  1479. if (channel == 'B')
  1480. target_offset += 8;
  1481. starget = ahc->platform_data->starget[target_offset];
  1482. if (starget == NULL)
  1483. break;
  1484. targ = scsi_transport_target_data(starget);
  1485. target_ppr_options =
  1486. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1487. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1488. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0);
  1489. if (tinfo->curr.period == spi_period(starget)
  1490. && tinfo->curr.width == spi_width(starget)
  1491. && tinfo->curr.offset == spi_offset(starget)
  1492. && tinfo->curr.ppr_options == target_ppr_options)
  1493. if (bootverbose == 0)
  1494. break;
  1495. spi_period(starget) = tinfo->curr.period;
  1496. spi_width(starget) = tinfo->curr.width;
  1497. spi_offset(starget) = tinfo->curr.offset;
  1498. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1499. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1500. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1501. spi_display_xfer_agreement(starget);
  1502. break;
  1503. }
  1504. case AC_SENT_BDR:
  1505. {
  1506. WARN_ON(lun != CAM_LUN_WILDCARD);
  1507. scsi_report_device_reset(ahc->platform_data->host,
  1508. channel - 'A', target);
  1509. break;
  1510. }
  1511. case AC_BUS_RESET:
  1512. if (ahc->platform_data->host != NULL) {
  1513. scsi_report_bus_reset(ahc->platform_data->host,
  1514. channel - 'A');
  1515. }
  1516. break;
  1517. default:
  1518. panic("ahc_send_async: Unexpected async event");
  1519. }
  1520. }
  1521. /*
  1522. * Calls the higher level scsi done function and frees the scb.
  1523. */
  1524. void
  1525. ahc_done(struct ahc_softc *ahc, struct scb *scb)
  1526. {
  1527. struct scsi_cmnd *cmd;
  1528. struct ahc_linux_device *dev;
  1529. LIST_REMOVE(scb, pending_links);
  1530. if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
  1531. struct scb_tailq *untagged_q;
  1532. int target_offset;
  1533. target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
  1534. untagged_q = &(ahc->untagged_queues[target_offset]);
  1535. TAILQ_REMOVE(untagged_q, scb, links.tqe);
  1536. BUG_ON(!TAILQ_EMPTY(untagged_q));
  1537. } else if ((scb->flags & SCB_ACTIVE) == 0) {
  1538. /*
  1539. * Transactions aborted from the untagged queue may
  1540. * not have been dispatched to the controller, so
  1541. * only check the SCB_ACTIVE flag for tagged transactions.
  1542. */
  1543. printk("SCB %d done'd twice\n", scb->hscb->tag);
  1544. ahc_dump_card_state(ahc);
  1545. panic("Stopping for safety");
  1546. }
  1547. cmd = scb->io_ctx;
  1548. dev = scb->platform_data->dev;
  1549. dev->active--;
  1550. dev->openings++;
  1551. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1552. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1553. dev->qfrozen--;
  1554. }
  1555. ahc_linux_unmap_scb(ahc, scb);
  1556. /*
  1557. * Guard against stale sense data.
  1558. * The Linux mid-layer assumes that sense
  1559. * was retrieved anytime the first byte of
  1560. * the sense buffer looks "sane".
  1561. */
  1562. cmd->sense_buffer[0] = 0;
  1563. if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1564. uint32_t amount_xferred;
  1565. amount_xferred =
  1566. ahc_get_transfer_length(scb) - ahc_get_residual(scb);
  1567. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1568. #ifdef AHC_DEBUG
  1569. if ((ahc_debug & AHC_SHOW_MISC) != 0) {
  1570. ahc_print_path(ahc, scb);
  1571. printk("Set CAM_UNCOR_PARITY\n");
  1572. }
  1573. #endif
  1574. ahc_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1575. #ifdef AHC_REPORT_UNDERFLOWS
  1576. /*
  1577. * This code is disabled by default as some
  1578. * clients of the SCSI system do not properly
  1579. * initialize the underflow parameter. This
  1580. * results in spurious termination of commands
  1581. * that complete as expected (e.g. underflow is
  1582. * allowed as command can return variable amounts
  1583. * of data.
  1584. */
  1585. } else if (amount_xferred < scb->io_ctx->underflow) {
  1586. u_int i;
  1587. ahc_print_path(ahc, scb);
  1588. printk("CDB:");
  1589. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1590. printk(" 0x%x", scb->io_ctx->cmnd[i]);
  1591. printk("\n");
  1592. ahc_print_path(ahc, scb);
  1593. printk("Saw underflow (%ld of %ld bytes). "
  1594. "Treated as error\n",
  1595. ahc_get_residual(scb),
  1596. ahc_get_transfer_length(scb));
  1597. ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1598. #endif
  1599. } else {
  1600. ahc_set_transaction_status(scb, CAM_REQ_CMP);
  1601. }
  1602. } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1603. ahc_linux_handle_scsi_status(ahc, cmd->device, scb);
  1604. }
  1605. if (dev->openings == 1
  1606. && ahc_get_transaction_status(scb) == CAM_REQ_CMP
  1607. && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1608. dev->tag_success_count++;
  1609. /*
  1610. * Some devices deal with temporary internal resource
  1611. * shortages by returning queue full. When the queue
  1612. * full occurrs, we throttle back. Slowly try to get
  1613. * back to our previous queue depth.
  1614. */
  1615. if ((dev->openings + dev->active) < dev->maxtags
  1616. && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) {
  1617. dev->tag_success_count = 0;
  1618. dev->openings++;
  1619. }
  1620. if (dev->active == 0)
  1621. dev->commands_since_idle_or_otag = 0;
  1622. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1623. printk("Recovery SCB completes\n");
  1624. if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
  1625. || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1626. ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1627. if (ahc->platform_data->eh_done)
  1628. complete(ahc->platform_data->eh_done);
  1629. }
  1630. ahc_free_scb(ahc, scb);
  1631. ahc_linux_queue_cmd_complete(ahc, cmd);
  1632. }
  1633. static void
  1634. ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
  1635. struct scsi_device *sdev, struct scb *scb)
  1636. {
  1637. struct ahc_devinfo devinfo;
  1638. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  1639. ahc_compile_devinfo(&devinfo,
  1640. ahc->our_id,
  1641. sdev->sdev_target->id, sdev->lun,
  1642. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1643. ROLE_INITIATOR);
  1644. /*
  1645. * We don't currently trust the mid-layer to
  1646. * properly deal with queue full or busy. So,
  1647. * when one occurs, we tell the mid-layer to
  1648. * unconditionally requeue the command to us
  1649. * so that we can retry it ourselves. We also
  1650. * implement our own throttling mechanism so
  1651. * we don't clobber the device with too many
  1652. * commands.
  1653. */
  1654. switch (ahc_get_scsi_status(scb)) {
  1655. default:
  1656. break;
  1657. case SCSI_STATUS_CHECK_COND:
  1658. case SCSI_STATUS_CMD_TERMINATED:
  1659. {
  1660. struct scsi_cmnd *cmd;
  1661. /*
  1662. * Copy sense information to the OS's cmd
  1663. * structure if it is available.
  1664. */
  1665. cmd = scb->io_ctx;
  1666. if (scb->flags & SCB_SENSE) {
  1667. u_int sense_size;
  1668. sense_size = min(sizeof(struct scsi_sense_data)
  1669. - ahc_get_sense_residual(scb),
  1670. (u_long)SCSI_SENSE_BUFFERSIZE);
  1671. memcpy(cmd->sense_buffer,
  1672. ahc_get_sense_buf(ahc, scb), sense_size);
  1673. if (sense_size < SCSI_SENSE_BUFFERSIZE)
  1674. memset(&cmd->sense_buffer[sense_size], 0,
  1675. SCSI_SENSE_BUFFERSIZE - sense_size);
  1676. cmd->result |= (DRIVER_SENSE << 24);
  1677. #ifdef AHC_DEBUG
  1678. if (ahc_debug & AHC_SHOW_SENSE) {
  1679. int i;
  1680. printk("Copied %d bytes of sense data:",
  1681. sense_size);
  1682. for (i = 0; i < sense_size; i++) {
  1683. if ((i & 0xF) == 0)
  1684. printk("\n");
  1685. printk("0x%x ", cmd->sense_buffer[i]);
  1686. }
  1687. printk("\n");
  1688. }
  1689. #endif
  1690. }
  1691. break;
  1692. }
  1693. case SCSI_STATUS_QUEUE_FULL:
  1694. {
  1695. /*
  1696. * By the time the core driver has returned this
  1697. * command, all other commands that were queued
  1698. * to us but not the device have been returned.
  1699. * This ensures that dev->active is equal to
  1700. * the number of commands actually queued to
  1701. * the device.
  1702. */
  1703. dev->tag_success_count = 0;
  1704. if (dev->active != 0) {
  1705. /*
  1706. * Drop our opening count to the number
  1707. * of commands currently outstanding.
  1708. */
  1709. dev->openings = 0;
  1710. /*
  1711. ahc_print_path(ahc, scb);
  1712. printk("Dropping tag count to %d\n", dev->active);
  1713. */
  1714. if (dev->active == dev->tags_on_last_queuefull) {
  1715. dev->last_queuefull_same_count++;
  1716. /*
  1717. * If we repeatedly see a queue full
  1718. * at the same queue depth, this
  1719. * device has a fixed number of tag
  1720. * slots. Lock in this tag depth
  1721. * so we stop seeing queue fulls from
  1722. * this device.
  1723. */
  1724. if (dev->last_queuefull_same_count
  1725. == AHC_LOCK_TAGS_COUNT) {
  1726. dev->maxtags = dev->active;
  1727. ahc_print_path(ahc, scb);
  1728. printk("Locking max tag count at %d\n",
  1729. dev->active);
  1730. }
  1731. } else {
  1732. dev->tags_on_last_queuefull = dev->active;
  1733. dev->last_queuefull_same_count = 0;
  1734. }
  1735. ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1736. ahc_set_scsi_status(scb, SCSI_STATUS_OK);
  1737. ahc_platform_set_tags(ahc, sdev, &devinfo,
  1738. (dev->flags & AHC_DEV_Q_BASIC)
  1739. ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
  1740. break;
  1741. }
  1742. /*
  1743. * Drop down to a single opening, and treat this
  1744. * as if the target returned BUSY SCSI status.
  1745. */
  1746. dev->openings = 1;
  1747. ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
  1748. ahc_platform_set_tags(ahc, sdev, &devinfo,
  1749. (dev->flags & AHC_DEV_Q_BASIC)
  1750. ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
  1751. break;
  1752. }
  1753. }
  1754. }
  1755. static void
  1756. ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd)
  1757. {
  1758. /*
  1759. * Map CAM error codes into Linux Error codes. We
  1760. * avoid the conversion so that the DV code has the
  1761. * full error information available when making
  1762. * state change decisions.
  1763. */
  1764. {
  1765. u_int new_status;
  1766. switch (ahc_cmd_get_transaction_status(cmd)) {
  1767. case CAM_REQ_INPROG:
  1768. case CAM_REQ_CMP:
  1769. case CAM_SCSI_STATUS_ERROR:
  1770. new_status = DID_OK;
  1771. break;
  1772. case CAM_REQ_ABORTED:
  1773. new_status = DID_ABORT;
  1774. break;
  1775. case CAM_BUSY:
  1776. new_status = DID_BUS_BUSY;
  1777. break;
  1778. case CAM_REQ_INVALID:
  1779. case CAM_PATH_INVALID:
  1780. new_status = DID_BAD_TARGET;
  1781. break;
  1782. case CAM_SEL_TIMEOUT:
  1783. new_status = DID_NO_CONNECT;
  1784. break;
  1785. case CAM_SCSI_BUS_RESET:
  1786. case CAM_BDR_SENT:
  1787. new_status = DID_RESET;
  1788. break;
  1789. case CAM_UNCOR_PARITY:
  1790. new_status = DID_PARITY;
  1791. break;
  1792. case CAM_CMD_TIMEOUT:
  1793. new_status = DID_TIME_OUT;
  1794. break;
  1795. case CAM_UA_ABORT:
  1796. case CAM_REQ_CMP_ERR:
  1797. case CAM_AUTOSENSE_FAIL:
  1798. case CAM_NO_HBA:
  1799. case CAM_DATA_RUN_ERR:
  1800. case CAM_UNEXP_BUSFREE:
  1801. case CAM_SEQUENCE_FAIL:
  1802. case CAM_CCB_LEN_ERR:
  1803. case CAM_PROVIDE_FAIL:
  1804. case CAM_REQ_TERMIO:
  1805. case CAM_UNREC_HBA_ERROR:
  1806. case CAM_REQ_TOO_BIG:
  1807. new_status = DID_ERROR;
  1808. break;
  1809. case CAM_REQUEUE_REQ:
  1810. new_status = DID_REQUEUE;
  1811. break;
  1812. default:
  1813. /* We should never get here */
  1814. new_status = DID_ERROR;
  1815. break;
  1816. }
  1817. ahc_cmd_set_transaction_status(cmd, new_status);
  1818. }
  1819. cmd->scsi_done(cmd);
  1820. }
  1821. static void
  1822. ahc_linux_freeze_simq(struct ahc_softc *ahc)
  1823. {
  1824. unsigned long s;
  1825. ahc_lock(ahc, &s);
  1826. ahc->platform_data->qfrozen++;
  1827. if (ahc->platform_data->qfrozen == 1) {
  1828. scsi_block_requests(ahc->platform_data->host);
  1829. /* XXX What about Twin channels? */
  1830. ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
  1831. CAM_LUN_WILDCARD, SCB_LIST_NULL,
  1832. ROLE_INITIATOR, CAM_REQUEUE_REQ);
  1833. }
  1834. ahc_unlock(ahc, &s);
  1835. }
  1836. static void
  1837. ahc_linux_release_simq(struct ahc_softc *ahc)
  1838. {
  1839. u_long s;
  1840. int unblock_reqs;
  1841. unblock_reqs = 0;
  1842. ahc_lock(ahc, &s);
  1843. if (ahc->platform_data->qfrozen > 0)
  1844. ahc->platform_data->qfrozen--;
  1845. if (ahc->platform_data->qfrozen == 0)
  1846. unblock_reqs = 1;
  1847. ahc_unlock(ahc, &s);
  1848. /*
  1849. * There is still a race here. The mid-layer
  1850. * should keep its own freeze count and use
  1851. * a bottom half handler to run the queues
  1852. * so we can unblock with our own lock held.
  1853. */
  1854. if (unblock_reqs)
  1855. scsi_unblock_requests(ahc->platform_data->host);
  1856. }
  1857. static int
  1858. ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
  1859. {
  1860. struct ahc_softc *ahc;
  1861. struct ahc_linux_device *dev;
  1862. struct scb *pending_scb;
  1863. u_int saved_scbptr;
  1864. u_int active_scb_index;
  1865. u_int last_phase;
  1866. u_int saved_scsiid;
  1867. u_int cdb_byte;
  1868. int retval;
  1869. int was_paused;
  1870. int paused;
  1871. int wait;
  1872. int disconnected;
  1873. unsigned long flags;
  1874. pending_scb = NULL;
  1875. paused = FALSE;
  1876. wait = FALSE;
  1877. ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
  1878. scmd_printk(KERN_INFO, cmd, "Attempting to queue a%s message\n",
  1879. flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
  1880. printk("CDB:");
  1881. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1882. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  1883. printk("\n");
  1884. ahc_lock(ahc, &flags);
  1885. /*
  1886. * First determine if we currently own this command.
  1887. * Start by searching the device queue. If not found
  1888. * there, check the pending_scb list. If not found
  1889. * at all, and the system wanted us to just abort the
  1890. * command, return success.
  1891. */
  1892. dev = scsi_transport_device_data(cmd->device);
  1893. if (dev == NULL) {
  1894. /*
  1895. * No target device for this command exists,
  1896. * so we must not still own the command.
  1897. */
  1898. printk("%s:%d:%d:%d: Is not an active device\n",
  1899. ahc_name(ahc), cmd->device->channel, cmd->device->id,
  1900. cmd->device->lun);
  1901. retval = SUCCESS;
  1902. goto no_cmd;
  1903. }
  1904. if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
  1905. && ahc_search_untagged_queues(ahc, cmd, cmd->device->id,
  1906. cmd->device->channel + 'A',
  1907. cmd->device->lun,
  1908. CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) {
  1909. printk("%s:%d:%d:%d: Command found on untagged queue\n",
  1910. ahc_name(ahc), cmd->device->channel, cmd->device->id,
  1911. cmd->device->lun);
  1912. retval = SUCCESS;
  1913. goto done;
  1914. }
  1915. /*
  1916. * See if we can find a matching cmd in the pending list.
  1917. */
  1918. LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
  1919. if (pending_scb->io_ctx == cmd)
  1920. break;
  1921. }
  1922. if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
  1923. /* Any SCB for this device will do for a target reset */
  1924. LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
  1925. if (ahc_match_scb(ahc, pending_scb, scmd_id(cmd),
  1926. scmd_channel(cmd) + 'A',
  1927. CAM_LUN_WILDCARD,
  1928. SCB_LIST_NULL, ROLE_INITIATOR))
  1929. break;
  1930. }
  1931. }
  1932. if (pending_scb == NULL) {
  1933. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1934. goto no_cmd;
  1935. }
  1936. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1937. /*
  1938. * We can't queue two recovery actions using the same SCB
  1939. */
  1940. retval = FAILED;
  1941. goto done;
  1942. }
  1943. /*
  1944. * Ensure that the card doesn't do anything
  1945. * behind our back and that we didn't "just" miss
  1946. * an interrupt that would affect this cmd.
  1947. */
  1948. was_paused = ahc_is_paused(ahc);
  1949. ahc_pause_and_flushwork(ahc);
  1950. paused = TRUE;
  1951. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  1952. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  1953. goto no_cmd;
  1954. }
  1955. printk("%s: At time of recovery, card was %spaused\n",
  1956. ahc_name(ahc), was_paused ? "" : "not ");
  1957. ahc_dump_card_state(ahc);
  1958. disconnected = TRUE;
  1959. if (flag == SCB_ABORT) {
  1960. if (ahc_search_qinfifo(ahc, cmd->device->id,
  1961. cmd->device->channel + 'A',
  1962. cmd->device->lun,
  1963. pending_scb->hscb->tag,
  1964. ROLE_INITIATOR, CAM_REQ_ABORTED,
  1965. SEARCH_COMPLETE) > 0) {
  1966. printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  1967. ahc_name(ahc), cmd->device->channel,
  1968. cmd->device->id, cmd->device->lun);
  1969. retval = SUCCESS;
  1970. goto done;
  1971. }
  1972. } else if (ahc_search_qinfifo(ahc, cmd->device->id,
  1973. cmd->device->channel + 'A',
  1974. cmd->device->lun, pending_scb->hscb->tag,
  1975. ROLE_INITIATOR, /*status*/0,
  1976. SEARCH_COUNT) > 0) {
  1977. disconnected = FALSE;
  1978. }
  1979. if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  1980. struct scb *bus_scb;
  1981. bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG));
  1982. if (bus_scb == pending_scb)
  1983. disconnected = FALSE;
  1984. else if (flag != SCB_ABORT
  1985. && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid
  1986. && ahc_inb(ahc, SAVED_LUN) == SCB_GET_LUN(pending_scb))
  1987. disconnected = FALSE;
  1988. }
  1989. /*
  1990. * At this point, pending_scb is the scb associated with the
  1991. * passed in command. That command is currently active on the
  1992. * bus, is in the disconnected state, or we're hoping to find
  1993. * a command for the same target active on the bus to abuse to
  1994. * send a BDR. Queue the appropriate message based on which of
  1995. * these states we are in.
  1996. */
  1997. last_phase = ahc_inb(ahc, LASTPHASE);
  1998. saved_scbptr = ahc_inb(ahc, SCBPTR);
  1999. active_scb_index = ahc_inb(ahc, SCB_TAG);
  2000. saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
  2001. if (last_phase != P_BUSFREE
  2002. && (pending_scb->hscb->tag == active_scb_index
  2003. || (flag == SCB_DEVICE_RESET
  2004. && SCSIID_TARGET(ahc, saved_scsiid) == scmd_id(cmd)))) {
  2005. /*
  2006. * We're active on the bus, so assert ATN
  2007. * and hope that the target responds.
  2008. */
  2009. pending_scb = ahc_lookup_scb(ahc, active_scb_index);
  2010. pending_scb->flags |= SCB_RECOVERY_SCB|flag;
  2011. ahc_outb(ahc, MSG_OUT, HOST_MSG);
  2012. ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
  2013. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  2014. wait = TRUE;
  2015. } else if (disconnected) {
  2016. /*
  2017. * Actually re-queue this SCB in an attempt
  2018. * to select the device before it reconnects.
  2019. * In either case (selection or reselection),
  2020. * we will now issue the approprate message
  2021. * to the timed-out device.
  2022. *
  2023. * Set the MK_MESSAGE control bit indicating
  2024. * that we desire to send a message. We
  2025. * also set the disconnected flag since
  2026. * in the paging case there is no guarantee
  2027. * that our SCB control byte matches the
  2028. * version on the card. We don't want the
  2029. * sequencer to abort the command thinking
  2030. * an unsolicited reselection occurred.
  2031. */
  2032. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2033. pending_scb->flags |= SCB_RECOVERY_SCB|flag;
  2034. /*
  2035. * Remove any cached copy of this SCB in the
  2036. * disconnected list in preparation for the
  2037. * queuing of our abort SCB. We use the
  2038. * same element in the SCB, SCB_NEXT, for
  2039. * both the qinfifo and the disconnected list.
  2040. */
  2041. ahc_search_disc_list(ahc, cmd->device->id,
  2042. cmd->device->channel + 'A',
  2043. cmd->device->lun, pending_scb->hscb->tag,
  2044. /*stop_on_first*/TRUE,
  2045. /*remove*/TRUE,
  2046. /*save_state*/FALSE);
  2047. /*
  2048. * In the non-paging case, the sequencer will
  2049. * never re-reference the in-core SCB.
  2050. * To make sure we are notified during
  2051. * reselection, set the MK_MESSAGE flag in
  2052. * the card's copy of the SCB.
  2053. */
  2054. if ((ahc->flags & AHC_PAGESCBS) == 0) {
  2055. ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag);
  2056. ahc_outb(ahc, SCB_CONTROL,
  2057. ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE);
  2058. }
  2059. /*
  2060. * Clear out any entries in the QINFIFO first
  2061. * so we are the next SCB for this target
  2062. * to run.
  2063. */
  2064. ahc_search_qinfifo(ahc, cmd->device->id,
  2065. cmd->device->channel + 'A',
  2066. cmd->device->lun, SCB_LIST_NULL,
  2067. ROLE_INITIATOR, CAM_REQUEUE_REQ,
  2068. SEARCH_COMPLETE);
  2069. ahc_qinfifo_requeue_tail(ahc, pending_scb);
  2070. ahc_outb(ahc, SCBPTR, saved_scbptr);
  2071. ahc_print_path(ahc, pending_scb);
  2072. printk("Device is disconnected, re-queuing SCB\n");
  2073. wait = TRUE;
  2074. } else {
  2075. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2076. retval = FAILED;
  2077. goto done;
  2078. }
  2079. no_cmd:
  2080. /*
  2081. * Our assumption is that if we don't have the command, no
  2082. * recovery action was required, so we return success. Again,
  2083. * the semantics of the mid-layer recovery engine are not
  2084. * well defined, so this may change in time.
  2085. */
  2086. retval = SUCCESS;
  2087. done:
  2088. if (paused)
  2089. ahc_unpause(ahc);
  2090. if (wait) {
  2091. DECLARE_COMPLETION_ONSTACK(done);
  2092. ahc->platform_data->eh_done = &done;
  2093. ahc_unlock(ahc, &flags);
  2094. printk("Recovery code sleeping\n");
  2095. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  2096. ahc_lock(ahc, &flags);
  2097. ahc->platform_data->eh_done = NULL;
  2098. ahc_unlock(ahc, &flags);
  2099. printk("Timer Expired\n");
  2100. retval = FAILED;
  2101. }
  2102. printk("Recovery code awake\n");
  2103. } else
  2104. ahc_unlock(ahc, &flags);
  2105. return (retval);
  2106. }
  2107. void
  2108. ahc_platform_dump_card_state(struct ahc_softc *ahc)
  2109. {
  2110. }
  2111. static void ahc_linux_set_width(struct scsi_target *starget, int width)
  2112. {
  2113. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2114. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2115. struct ahc_devinfo devinfo;
  2116. unsigned long flags;
  2117. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2118. starget->channel + 'A', ROLE_INITIATOR);
  2119. ahc_lock(ahc, &flags);
  2120. ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
  2121. ahc_unlock(ahc, &flags);
  2122. }
  2123. static void ahc_linux_set_period(struct scsi_target *starget, int period)
  2124. {
  2125. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2126. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2127. struct ahc_tmode_tstate *tstate;
  2128. struct ahc_initiator_tinfo *tinfo
  2129. = ahc_fetch_transinfo(ahc,
  2130. starget->channel + 'A',
  2131. shost->this_id, starget->id, &tstate);
  2132. struct ahc_devinfo devinfo;
  2133. unsigned int ppr_options = tinfo->goal.ppr_options;
  2134. unsigned long flags;
  2135. unsigned long offset = tinfo->goal.offset;
  2136. const struct ahc_syncrate *syncrate;
  2137. if (offset == 0)
  2138. offset = MAX_OFFSET;
  2139. if (period < 9)
  2140. period = 9; /* 12.5ns is our minimum */
  2141. if (period == 9) {
  2142. if (spi_max_width(starget))
  2143. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2144. else
  2145. /* need wide for DT and need DT for 12.5 ns */
  2146. period = 10;
  2147. }
  2148. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2149. starget->channel + 'A', ROLE_INITIATOR);
  2150. /* all PPR requests apart from QAS require wide transfers */
  2151. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2152. if (spi_width(starget) == 0)
  2153. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2154. }
  2155. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2156. ahc_lock(ahc, &flags);
  2157. ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
  2158. ppr_options, AHC_TRANS_GOAL, FALSE);
  2159. ahc_unlock(ahc, &flags);
  2160. }
  2161. static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
  2162. {
  2163. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2164. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2165. struct ahc_tmode_tstate *tstate;
  2166. struct ahc_initiator_tinfo *tinfo
  2167. = ahc_fetch_transinfo(ahc,
  2168. starget->channel + 'A',
  2169. shost->this_id, starget->id, &tstate);
  2170. struct ahc_devinfo devinfo;
  2171. unsigned int ppr_options = 0;
  2172. unsigned int period = 0;
  2173. unsigned long flags;
  2174. const struct ahc_syncrate *syncrate = NULL;
  2175. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2176. starget->channel + 'A', ROLE_INITIATOR);
  2177. if (offset != 0) {
  2178. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2179. period = tinfo->goal.period;
  2180. ppr_options = tinfo->goal.ppr_options;
  2181. }
  2182. ahc_lock(ahc, &flags);
  2183. ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
  2184. ppr_options, AHC_TRANS_GOAL, FALSE);
  2185. ahc_unlock(ahc, &flags);
  2186. }
  2187. static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
  2188. {
  2189. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2190. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2191. struct ahc_tmode_tstate *tstate;
  2192. struct ahc_initiator_tinfo *tinfo
  2193. = ahc_fetch_transinfo(ahc,
  2194. starget->channel + 'A',
  2195. shost->this_id, starget->id, &tstate);
  2196. struct ahc_devinfo devinfo;
  2197. unsigned int ppr_options = tinfo->goal.ppr_options
  2198. & ~MSG_EXT_PPR_DT_REQ;
  2199. unsigned int period = tinfo->goal.period;
  2200. unsigned int width = tinfo->goal.width;
  2201. unsigned long flags;
  2202. const struct ahc_syncrate *syncrate;
  2203. if (dt && spi_max_width(starget)) {
  2204. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2205. if (!width)
  2206. ahc_linux_set_width(starget, 1);
  2207. } else if (period == 9)
  2208. period = 10; /* if resetting DT, period must be >= 25ns */
  2209. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2210. starget->channel + 'A', ROLE_INITIATOR);
  2211. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
  2212. ahc_lock(ahc, &flags);
  2213. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2214. ppr_options, AHC_TRANS_GOAL, FALSE);
  2215. ahc_unlock(ahc, &flags);
  2216. }
  2217. #if 0
  2218. /* FIXME: This code claims to support IU and QAS. However, the actual
  2219. * sequencer code and aic7xxx_core have no support for these parameters and
  2220. * will get into a bad state if they're negotiated. Do not enable this
  2221. * unless you know what you're doing */
  2222. static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
  2223. {
  2224. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2225. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2226. struct ahc_tmode_tstate *tstate;
  2227. struct ahc_initiator_tinfo *tinfo
  2228. = ahc_fetch_transinfo(ahc,
  2229. starget->channel + 'A',
  2230. shost->this_id, starget->id, &tstate);
  2231. struct ahc_devinfo devinfo;
  2232. unsigned int ppr_options = tinfo->goal.ppr_options
  2233. & ~MSG_EXT_PPR_QAS_REQ;
  2234. unsigned int period = tinfo->goal.period;
  2235. unsigned long flags;
  2236. struct ahc_syncrate *syncrate;
  2237. if (qas)
  2238. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2239. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2240. starget->channel + 'A', ROLE_INITIATOR);
  2241. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2242. ahc_lock(ahc, &flags);
  2243. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2244. ppr_options, AHC_TRANS_GOAL, FALSE);
  2245. ahc_unlock(ahc, &flags);
  2246. }
  2247. static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
  2248. {
  2249. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2250. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2251. struct ahc_tmode_tstate *tstate;
  2252. struct ahc_initiator_tinfo *tinfo
  2253. = ahc_fetch_transinfo(ahc,
  2254. starget->channel + 'A',
  2255. shost->this_id, starget->id, &tstate);
  2256. struct ahc_devinfo devinfo;
  2257. unsigned int ppr_options = tinfo->goal.ppr_options
  2258. & ~MSG_EXT_PPR_IU_REQ;
  2259. unsigned int period = tinfo->goal.period;
  2260. unsigned long flags;
  2261. struct ahc_syncrate *syncrate;
  2262. if (iu)
  2263. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2264. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2265. starget->channel + 'A', ROLE_INITIATOR);
  2266. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2267. ahc_lock(ahc, &flags);
  2268. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2269. ppr_options, AHC_TRANS_GOAL, FALSE);
  2270. ahc_unlock(ahc, &flags);
  2271. }
  2272. #endif
  2273. static void ahc_linux_get_signalling(struct Scsi_Host *shost)
  2274. {
  2275. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  2276. unsigned long flags;
  2277. u8 mode;
  2278. if (!(ahc->features & AHC_ULTRA2)) {
  2279. /* non-LVD chipset, may not have SBLKCTL reg */
  2280. spi_signalling(shost) =
  2281. ahc->features & AHC_HVD ?
  2282. SPI_SIGNAL_HVD :
  2283. SPI_SIGNAL_SE;
  2284. return;
  2285. }
  2286. ahc_lock(ahc, &flags);
  2287. ahc_pause(ahc);
  2288. mode = ahc_inb(ahc, SBLKCTL);
  2289. ahc_unpause(ahc);
  2290. ahc_unlock(ahc, &flags);
  2291. if (mode & ENAB40)
  2292. spi_signalling(shost) = SPI_SIGNAL_LVD;
  2293. else if (mode & ENAB20)
  2294. spi_signalling(shost) = SPI_SIGNAL_SE;
  2295. else
  2296. spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
  2297. }
  2298. static struct spi_function_template ahc_linux_transport_functions = {
  2299. .set_offset = ahc_linux_set_offset,
  2300. .show_offset = 1,
  2301. .set_period = ahc_linux_set_period,
  2302. .show_period = 1,
  2303. .set_width = ahc_linux_set_width,
  2304. .show_width = 1,
  2305. .set_dt = ahc_linux_set_dt,
  2306. .show_dt = 1,
  2307. #if 0
  2308. .set_iu = ahc_linux_set_iu,
  2309. .show_iu = 1,
  2310. .set_qas = ahc_linux_set_qas,
  2311. .show_qas = 1,
  2312. #endif
  2313. .get_signalling = ahc_linux_get_signalling,
  2314. };
  2315. static int __init
  2316. ahc_linux_init(void)
  2317. {
  2318. /*
  2319. * If we've been passed any parameters, process them now.
  2320. */
  2321. if (aic7xxx)
  2322. aic7xxx_setup(aic7xxx);
  2323. ahc_linux_transport_template =
  2324. spi_attach_transport(&ahc_linux_transport_functions);
  2325. if (!ahc_linux_transport_template)
  2326. return -ENODEV;
  2327. scsi_transport_reserve_device(ahc_linux_transport_template,
  2328. sizeof(struct ahc_linux_device));
  2329. ahc_linux_pci_init();
  2330. ahc_linux_eisa_init();
  2331. return 0;
  2332. }
  2333. static void
  2334. ahc_linux_exit(void)
  2335. {
  2336. ahc_linux_pci_exit();
  2337. ahc_linux_eisa_exit();
  2338. spi_release_transport(ahc_linux_transport_template);
  2339. }
  2340. module_init(ahc_linux_init);
  2341. module_exit(ahc_linux_exit);