aic7xxx_osm.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622
  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 overwelming.
  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(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 inline struct scsi_target **
  499. ahc_linux_target_in_softc(struct scsi_target *starget)
  500. {
  501. struct ahc_softc *ahc =
  502. *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
  503. unsigned int target_offset;
  504. target_offset = starget->id;
  505. if (starget->channel != 0)
  506. target_offset += 8;
  507. return &ahc->platform_data->starget[target_offset];
  508. }
  509. static int
  510. ahc_linux_target_alloc(struct scsi_target *starget)
  511. {
  512. struct ahc_softc *ahc =
  513. *((struct ahc_softc **)dev_to_shost(&starget->dev)->hostdata);
  514. struct seeprom_config *sc = ahc->seep_config;
  515. unsigned long flags;
  516. struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
  517. unsigned short scsirate;
  518. struct ahc_devinfo devinfo;
  519. struct ahc_initiator_tinfo *tinfo;
  520. struct ahc_tmode_tstate *tstate;
  521. char channel = starget->channel + 'A';
  522. unsigned int our_id = ahc->our_id;
  523. unsigned int target_offset;
  524. target_offset = starget->id;
  525. if (starget->channel != 0)
  526. target_offset += 8;
  527. if (starget->channel)
  528. our_id = ahc->our_id_b;
  529. ahc_lock(ahc, &flags);
  530. BUG_ON(*ahc_targp != NULL);
  531. *ahc_targp = starget;
  532. if (sc) {
  533. int maxsync = AHC_SYNCRATE_DT;
  534. int ultra = 0;
  535. int flags = sc->device_flags[target_offset];
  536. if (ahc->flags & AHC_NEWEEPROM_FMT) {
  537. if (flags & CFSYNCHISULTRA)
  538. ultra = 1;
  539. } else if (flags & CFULTRAEN)
  540. ultra = 1;
  541. /* AIC nutcase; 10MHz appears as ultra = 1, CFXFER = 0x04
  542. * change it to ultra=0, CFXFER = 0 */
  543. if(ultra && (flags & CFXFER) == 0x04) {
  544. ultra = 0;
  545. flags &= ~CFXFER;
  546. }
  547. if ((ahc->features & AHC_ULTRA2) != 0) {
  548. scsirate = (flags & CFXFER) | (ultra ? 0x8 : 0);
  549. } else {
  550. scsirate = (flags & CFXFER) << 4;
  551. maxsync = ultra ? AHC_SYNCRATE_ULTRA :
  552. AHC_SYNCRATE_FAST;
  553. }
  554. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  555. if (!(flags & CFSYNCH))
  556. spi_max_offset(starget) = 0;
  557. spi_min_period(starget) =
  558. ahc_find_period(ahc, scsirate, maxsync);
  559. tinfo = ahc_fetch_transinfo(ahc, channel, ahc->our_id,
  560. starget->id, &tstate);
  561. }
  562. ahc_compile_devinfo(&devinfo, our_id, starget->id,
  563. CAM_LUN_WILDCARD, channel,
  564. ROLE_INITIATOR);
  565. ahc_set_syncrate(ahc, &devinfo, NULL, 0, 0, 0,
  566. AHC_TRANS_GOAL, /*paused*/FALSE);
  567. ahc_set_width(ahc, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  568. AHC_TRANS_GOAL, /*paused*/FALSE);
  569. ahc_unlock(ahc, &flags);
  570. return 0;
  571. }
  572. static void
  573. ahc_linux_target_destroy(struct scsi_target *starget)
  574. {
  575. struct scsi_target **ahc_targp = ahc_linux_target_in_softc(starget);
  576. *ahc_targp = NULL;
  577. }
  578. static int
  579. ahc_linux_slave_alloc(struct scsi_device *sdev)
  580. {
  581. struct ahc_softc *ahc =
  582. *((struct ahc_softc **)sdev->host->hostdata);
  583. struct scsi_target *starget = sdev->sdev_target;
  584. struct ahc_linux_device *dev;
  585. if (bootverbose)
  586. printf("%s: Slave Alloc %d\n", ahc_name(ahc), sdev->id);
  587. dev = scsi_transport_device_data(sdev);
  588. memset(dev, 0, sizeof(*dev));
  589. /*
  590. * We start out life using untagged
  591. * transactions of which we allow one.
  592. */
  593. dev->openings = 1;
  594. /*
  595. * Set maxtags to 0. This will be changed if we
  596. * later determine that we are dealing with
  597. * a tagged queuing capable device.
  598. */
  599. dev->maxtags = 0;
  600. spi_period(starget) = 0;
  601. return 0;
  602. }
  603. static int
  604. ahc_linux_slave_configure(struct scsi_device *sdev)
  605. {
  606. struct ahc_softc *ahc;
  607. ahc = *((struct ahc_softc **)sdev->host->hostdata);
  608. if (bootverbose)
  609. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  610. ahc_linux_device_queue_depth(sdev);
  611. /* Initial Domain Validation */
  612. if (!spi_initial_dv(sdev->sdev_target))
  613. spi_dv_device(sdev);
  614. return 0;
  615. }
  616. #if defined(__i386__)
  617. /*
  618. * Return the disk geometry for the given SCSI device.
  619. */
  620. static int
  621. ahc_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  622. sector_t capacity, int geom[])
  623. {
  624. uint8_t *bh;
  625. int heads;
  626. int sectors;
  627. int cylinders;
  628. int ret;
  629. int extended;
  630. struct ahc_softc *ahc;
  631. u_int channel;
  632. ahc = *((struct ahc_softc **)sdev->host->hostdata);
  633. channel = sdev_channel(sdev);
  634. bh = scsi_bios_ptable(bdev);
  635. if (bh) {
  636. ret = scsi_partsize(bh, capacity,
  637. &geom[2], &geom[0], &geom[1]);
  638. kfree(bh);
  639. if (ret != -1)
  640. return (ret);
  641. }
  642. heads = 64;
  643. sectors = 32;
  644. cylinders = aic_sector_div(capacity, heads, sectors);
  645. if (aic7xxx_extended != 0)
  646. extended = 1;
  647. else if (channel == 0)
  648. extended = (ahc->flags & AHC_EXTENDED_TRANS_A) != 0;
  649. else
  650. extended = (ahc->flags & AHC_EXTENDED_TRANS_B) != 0;
  651. if (extended && cylinders >= 1024) {
  652. heads = 255;
  653. sectors = 63;
  654. cylinders = aic_sector_div(capacity, heads, sectors);
  655. }
  656. geom[0] = heads;
  657. geom[1] = sectors;
  658. geom[2] = cylinders;
  659. return (0);
  660. }
  661. #endif
  662. /*
  663. * Abort the current SCSI command(s).
  664. */
  665. static int
  666. ahc_linux_abort(struct scsi_cmnd *cmd)
  667. {
  668. int error;
  669. error = ahc_linux_queue_recovery_cmd(cmd, SCB_ABORT);
  670. if (error != 0)
  671. printf("aic7xxx_abort returns 0x%x\n", error);
  672. return (error);
  673. }
  674. /*
  675. * Attempt to send a target reset message to the device that timed out.
  676. */
  677. static int
  678. ahc_linux_dev_reset(struct scsi_cmnd *cmd)
  679. {
  680. int error;
  681. error = ahc_linux_queue_recovery_cmd(cmd, SCB_DEVICE_RESET);
  682. if (error != 0)
  683. printf("aic7xxx_dev_reset returns 0x%x\n", error);
  684. return (error);
  685. }
  686. /*
  687. * Reset the SCSI bus.
  688. */
  689. static int
  690. ahc_linux_bus_reset(struct scsi_cmnd *cmd)
  691. {
  692. struct ahc_softc *ahc;
  693. int found;
  694. unsigned long flags;
  695. ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
  696. ahc_lock(ahc, &flags);
  697. found = ahc_reset_channel(ahc, scmd_channel(cmd) + 'A',
  698. /*initiate reset*/TRUE);
  699. ahc_unlock(ahc, &flags);
  700. if (bootverbose)
  701. printf("%s: SCSI bus reset delivered. "
  702. "%d SCBs aborted.\n", ahc_name(ahc), found);
  703. return SUCCESS;
  704. }
  705. struct scsi_host_template aic7xxx_driver_template = {
  706. .module = THIS_MODULE,
  707. .name = "aic7xxx",
  708. .proc_name = "aic7xxx",
  709. .proc_info = ahc_linux_proc_info,
  710. .info = ahc_linux_info,
  711. .queuecommand = ahc_linux_queue,
  712. .eh_abort_handler = ahc_linux_abort,
  713. .eh_device_reset_handler = ahc_linux_dev_reset,
  714. .eh_bus_reset_handler = ahc_linux_bus_reset,
  715. #if defined(__i386__)
  716. .bios_param = ahc_linux_biosparam,
  717. #endif
  718. .can_queue = AHC_MAX_QUEUE,
  719. .this_id = -1,
  720. .max_sectors = 8192,
  721. .cmd_per_lun = 2,
  722. .use_clustering = ENABLE_CLUSTERING,
  723. .slave_alloc = ahc_linux_slave_alloc,
  724. .slave_configure = ahc_linux_slave_configure,
  725. .target_alloc = ahc_linux_target_alloc,
  726. .target_destroy = ahc_linux_target_destroy,
  727. };
  728. /**************************** Tasklet Handler *********************************/
  729. /******************************** Macros **************************************/
  730. #define BUILD_SCSIID(ahc, cmd) \
  731. ((((cmd)->device->id << TID_SHIFT) & TID) \
  732. | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
  733. | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
  734. /******************************** Bus DMA *************************************/
  735. int
  736. ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
  737. bus_size_t alignment, bus_size_t boundary,
  738. dma_addr_t lowaddr, dma_addr_t highaddr,
  739. bus_dma_filter_t *filter, void *filterarg,
  740. bus_size_t maxsize, int nsegments,
  741. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  742. {
  743. bus_dma_tag_t dmat;
  744. dmat = malloc(sizeof(*dmat), M_DEVBUF, M_NOWAIT);
  745. if (dmat == NULL)
  746. return (ENOMEM);
  747. /*
  748. * Linux is very simplistic about DMA memory. For now don't
  749. * maintain all specification information. Once Linux supplies
  750. * better facilities for doing these operations, or the
  751. * needs of this particular driver change, we might need to do
  752. * more here.
  753. */
  754. dmat->alignment = alignment;
  755. dmat->boundary = boundary;
  756. dmat->maxsize = maxsize;
  757. *ret_tag = dmat;
  758. return (0);
  759. }
  760. void
  761. ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
  762. {
  763. free(dmat, M_DEVBUF);
  764. }
  765. int
  766. ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
  767. int flags, bus_dmamap_t *mapp)
  768. {
  769. *vaddr = pci_alloc_consistent(ahc->dev_softc,
  770. dmat->maxsize, mapp);
  771. if (*vaddr == NULL)
  772. return ENOMEM;
  773. return 0;
  774. }
  775. void
  776. ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
  777. void* vaddr, bus_dmamap_t map)
  778. {
  779. pci_free_consistent(ahc->dev_softc, dmat->maxsize,
  780. vaddr, map);
  781. }
  782. int
  783. ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
  784. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  785. void *cb_arg, int flags)
  786. {
  787. /*
  788. * Assume for now that this will only be used during
  789. * initialization and not for per-transaction buffer mapping.
  790. */
  791. bus_dma_segment_t stack_sg;
  792. stack_sg.ds_addr = map;
  793. stack_sg.ds_len = dmat->maxsize;
  794. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  795. return (0);
  796. }
  797. void
  798. ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  799. {
  800. }
  801. int
  802. ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  803. {
  804. /* Nothing to do */
  805. return (0);
  806. }
  807. static void
  808. ahc_linux_setup_tag_info_global(char *p)
  809. {
  810. int tags, i, j;
  811. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  812. printf("Setting Global Tags= %d\n", tags);
  813. for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) {
  814. for (j = 0; j < AHC_NUM_TARGETS; j++) {
  815. aic7xxx_tag_info[i].tag_commands[j] = tags;
  816. }
  817. }
  818. }
  819. static void
  820. ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  821. {
  822. if ((instance >= 0) && (targ >= 0)
  823. && (instance < ARRAY_SIZE(aic7xxx_tag_info))
  824. && (targ < AHC_NUM_TARGETS)) {
  825. aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff;
  826. if (bootverbose)
  827. printf("tag_info[%d:%d] = %d\n", instance, targ, value);
  828. }
  829. }
  830. static char *
  831. ahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  832. void (*callback)(u_long, int, int, int32_t),
  833. u_long callback_arg)
  834. {
  835. char *tok_end;
  836. char *tok_end2;
  837. int i;
  838. int instance;
  839. int targ;
  840. int done;
  841. char tok_list[] = {'.', ',', '{', '}', '\0'};
  842. /* All options use a ':' name/arg separator */
  843. if (*opt_arg != ':')
  844. return (opt_arg);
  845. opt_arg++;
  846. instance = -1;
  847. targ = -1;
  848. done = FALSE;
  849. /*
  850. * Restore separator that may be in
  851. * the middle of our option argument.
  852. */
  853. tok_end = strchr(opt_arg, '\0');
  854. if (tok_end < end)
  855. *tok_end = ',';
  856. while (!done) {
  857. switch (*opt_arg) {
  858. case '{':
  859. if (instance == -1) {
  860. instance = 0;
  861. } else {
  862. if (depth > 1) {
  863. if (targ == -1)
  864. targ = 0;
  865. } else {
  866. printf("Malformed Option %s\n",
  867. opt_name);
  868. done = TRUE;
  869. }
  870. }
  871. opt_arg++;
  872. break;
  873. case '}':
  874. if (targ != -1)
  875. targ = -1;
  876. else if (instance != -1)
  877. instance = -1;
  878. opt_arg++;
  879. break;
  880. case ',':
  881. case '.':
  882. if (instance == -1)
  883. done = TRUE;
  884. else if (targ >= 0)
  885. targ++;
  886. else if (instance >= 0)
  887. instance++;
  888. opt_arg++;
  889. break;
  890. case '\0':
  891. done = TRUE;
  892. break;
  893. default:
  894. tok_end = end;
  895. for (i = 0; tok_list[i]; i++) {
  896. tok_end2 = strchr(opt_arg, tok_list[i]);
  897. if ((tok_end2) && (tok_end2 < tok_end))
  898. tok_end = tok_end2;
  899. }
  900. callback(callback_arg, instance, targ,
  901. simple_strtol(opt_arg, NULL, 0));
  902. opt_arg = tok_end;
  903. break;
  904. }
  905. }
  906. return (opt_arg);
  907. }
  908. /*
  909. * Handle Linux boot parameters. This routine allows for assigning a value
  910. * to a parameter with a ':' between the parameter and the value.
  911. * ie. aic7xxx=stpwlev:1,extended
  912. */
  913. static int
  914. aic7xxx_setup(char *s)
  915. {
  916. int i, n;
  917. char *p;
  918. char *end;
  919. static const struct {
  920. const char *name;
  921. uint32_t *flag;
  922. } options[] = {
  923. { "extended", &aic7xxx_extended },
  924. { "no_reset", &aic7xxx_no_reset },
  925. { "verbose", &aic7xxx_verbose },
  926. { "allow_memio", &aic7xxx_allow_memio},
  927. #ifdef AHC_DEBUG
  928. { "debug", &ahc_debug },
  929. #endif
  930. { "periodic_otag", &aic7xxx_periodic_otag },
  931. { "pci_parity", &aic7xxx_pci_parity },
  932. { "seltime", &aic7xxx_seltime },
  933. { "tag_info", NULL },
  934. { "global_tag_depth", NULL },
  935. { "dv", NULL }
  936. };
  937. end = strchr(s, '\0');
  938. /*
  939. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  940. * will never be 0 in this case.
  941. */
  942. n = 0;
  943. while ((p = strsep(&s, ",.")) != NULL) {
  944. if (*p == '\0')
  945. continue;
  946. for (i = 0; i < ARRAY_SIZE(options); i++) {
  947. n = strlen(options[i].name);
  948. if (strncmp(options[i].name, p, n) == 0)
  949. break;
  950. }
  951. if (i == ARRAY_SIZE(options))
  952. continue;
  953. if (strncmp(p, "global_tag_depth", n) == 0) {
  954. ahc_linux_setup_tag_info_global(p + n);
  955. } else if (strncmp(p, "tag_info", n) == 0) {
  956. s = ahc_parse_brace_option("tag_info", p + n, end,
  957. 2, ahc_linux_setup_tag_info, 0);
  958. } else if (p[n] == ':') {
  959. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  960. } else if (strncmp(p, "verbose", n) == 0) {
  961. *(options[i].flag) = 1;
  962. } else {
  963. *(options[i].flag) ^= 0xFFFFFFFF;
  964. }
  965. }
  966. return 1;
  967. }
  968. __setup("aic7xxx=", aic7xxx_setup);
  969. uint32_t aic7xxx_verbose;
  970. int
  971. ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
  972. {
  973. char buf[80];
  974. struct Scsi_Host *host;
  975. char *new_name;
  976. u_long s;
  977. int retval;
  978. template->name = ahc->description;
  979. host = scsi_host_alloc(template, sizeof(struct ahc_softc *));
  980. if (host == NULL)
  981. return (ENOMEM);
  982. *((struct ahc_softc **)host->hostdata) = ahc;
  983. ahc->platform_data->host = host;
  984. host->can_queue = AHC_MAX_QUEUE;
  985. host->cmd_per_lun = 2;
  986. /* XXX No way to communicate the ID for multiple channels */
  987. host->this_id = ahc->our_id;
  988. host->irq = ahc->platform_data->irq;
  989. host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
  990. host->max_lun = AHC_NUM_LUNS;
  991. host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
  992. host->sg_tablesize = AHC_NSEG;
  993. ahc_lock(ahc, &s);
  994. ahc_set_unit(ahc, ahc_linux_unit++);
  995. ahc_unlock(ahc, &s);
  996. sprintf(buf, "scsi%d", host->host_no);
  997. new_name = malloc(strlen(buf) + 1, M_DEVBUF, M_NOWAIT);
  998. if (new_name != NULL) {
  999. strcpy(new_name, buf);
  1000. ahc_set_name(ahc, new_name);
  1001. }
  1002. host->unique_id = ahc->unit;
  1003. ahc_linux_initialize_scsi_bus(ahc);
  1004. ahc_intr_enable(ahc, TRUE);
  1005. host->transportt = ahc_linux_transport_template;
  1006. retval = scsi_add_host(host,
  1007. (ahc->dev_softc ? &ahc->dev_softc->dev : NULL));
  1008. if (retval) {
  1009. printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
  1010. scsi_host_put(host);
  1011. return retval;
  1012. }
  1013. scsi_scan_host(host);
  1014. return 0;
  1015. }
  1016. /*
  1017. * Place the SCSI bus into a known state by either resetting it,
  1018. * or forcing transfer negotiations on the next command to any
  1019. * target.
  1020. */
  1021. void
  1022. ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
  1023. {
  1024. int i;
  1025. int numtarg;
  1026. unsigned long s;
  1027. i = 0;
  1028. numtarg = 0;
  1029. ahc_lock(ahc, &s);
  1030. if (aic7xxx_no_reset != 0)
  1031. ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
  1032. if ((ahc->flags & AHC_RESET_BUS_A) != 0)
  1033. ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
  1034. else
  1035. numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
  1036. if ((ahc->features & AHC_TWIN) != 0) {
  1037. if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
  1038. ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
  1039. } else {
  1040. if (numtarg == 0)
  1041. i = 8;
  1042. numtarg += 8;
  1043. }
  1044. }
  1045. /*
  1046. * Force negotiation to async for all targets that
  1047. * will not see an initial bus reset.
  1048. */
  1049. for (; i < numtarg; i++) {
  1050. struct ahc_devinfo devinfo;
  1051. struct ahc_initiator_tinfo *tinfo;
  1052. struct ahc_tmode_tstate *tstate;
  1053. u_int our_id;
  1054. u_int target_id;
  1055. char channel;
  1056. channel = 'A';
  1057. our_id = ahc->our_id;
  1058. target_id = i;
  1059. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  1060. channel = 'B';
  1061. our_id = ahc->our_id_b;
  1062. target_id = i % 8;
  1063. }
  1064. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  1065. target_id, &tstate);
  1066. ahc_compile_devinfo(&devinfo, our_id, target_id,
  1067. CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
  1068. ahc_update_neg_request(ahc, &devinfo, tstate,
  1069. tinfo, AHC_NEG_ALWAYS);
  1070. }
  1071. ahc_unlock(ahc, &s);
  1072. /* Give the bus some time to recover */
  1073. if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
  1074. ahc_linux_freeze_simq(ahc);
  1075. msleep(AIC7XXX_RESET_DELAY);
  1076. ahc_linux_release_simq(ahc);
  1077. }
  1078. }
  1079. int
  1080. ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
  1081. {
  1082. ahc->platform_data =
  1083. malloc(sizeof(struct ahc_platform_data), M_DEVBUF, M_NOWAIT);
  1084. if (ahc->platform_data == NULL)
  1085. return (ENOMEM);
  1086. memset(ahc->platform_data, 0, sizeof(struct ahc_platform_data));
  1087. ahc->platform_data->irq = AHC_LINUX_NOIRQ;
  1088. ahc_lockinit(ahc);
  1089. ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
  1090. ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
  1091. if (aic7xxx_pci_parity == 0)
  1092. ahc->flags |= AHC_DISABLE_PCI_PERR;
  1093. return (0);
  1094. }
  1095. void
  1096. ahc_platform_free(struct ahc_softc *ahc)
  1097. {
  1098. struct scsi_target *starget;
  1099. int i;
  1100. if (ahc->platform_data != NULL) {
  1101. /* destroy all of the device and target objects */
  1102. for (i = 0; i < AHC_NUM_TARGETS; i++) {
  1103. starget = ahc->platform_data->starget[i];
  1104. if (starget != NULL) {
  1105. ahc->platform_data->starget[i] = NULL;
  1106. }
  1107. }
  1108. if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
  1109. free_irq(ahc->platform_data->irq, ahc);
  1110. if (ahc->tag == BUS_SPACE_PIO
  1111. && ahc->bsh.ioport != 0)
  1112. release_region(ahc->bsh.ioport, 256);
  1113. if (ahc->tag == BUS_SPACE_MEMIO
  1114. && ahc->bsh.maddr != NULL) {
  1115. iounmap(ahc->bsh.maddr);
  1116. release_mem_region(ahc->platform_data->mem_busaddr,
  1117. 0x1000);
  1118. }
  1119. if (ahc->platform_data->host)
  1120. scsi_host_put(ahc->platform_data->host);
  1121. free(ahc->platform_data, M_DEVBUF);
  1122. }
  1123. }
  1124. void
  1125. ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
  1126. {
  1127. ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
  1128. SCB_GET_CHANNEL(ahc, scb),
  1129. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1130. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1131. }
  1132. void
  1133. ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
  1134. struct ahc_devinfo *devinfo, ahc_queue_alg alg)
  1135. {
  1136. struct ahc_linux_device *dev;
  1137. int was_queuing;
  1138. int now_queuing;
  1139. if (sdev == NULL)
  1140. return;
  1141. dev = scsi_transport_device_data(sdev);
  1142. was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
  1143. switch (alg) {
  1144. default:
  1145. case AHC_QUEUE_NONE:
  1146. now_queuing = 0;
  1147. break;
  1148. case AHC_QUEUE_BASIC:
  1149. now_queuing = AHC_DEV_Q_BASIC;
  1150. break;
  1151. case AHC_QUEUE_TAGGED:
  1152. now_queuing = AHC_DEV_Q_TAGGED;
  1153. break;
  1154. }
  1155. if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
  1156. && (was_queuing != now_queuing)
  1157. && (dev->active != 0)) {
  1158. dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
  1159. dev->qfrozen++;
  1160. }
  1161. dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
  1162. if (now_queuing) {
  1163. u_int usertags;
  1164. usertags = ahc_linux_user_tagdepth(ahc, devinfo);
  1165. if (!was_queuing) {
  1166. /*
  1167. * Start out agressively and allow our
  1168. * dynamic queue depth algorithm to take
  1169. * care of the rest.
  1170. */
  1171. dev->maxtags = usertags;
  1172. dev->openings = dev->maxtags - dev->active;
  1173. }
  1174. if (dev->maxtags == 0) {
  1175. /*
  1176. * Queueing is disabled by the user.
  1177. */
  1178. dev->openings = 1;
  1179. } else if (alg == AHC_QUEUE_TAGGED) {
  1180. dev->flags |= AHC_DEV_Q_TAGGED;
  1181. if (aic7xxx_periodic_otag != 0)
  1182. dev->flags |= AHC_DEV_PERIODIC_OTAG;
  1183. } else
  1184. dev->flags |= AHC_DEV_Q_BASIC;
  1185. } else {
  1186. /* We can only have one opening. */
  1187. dev->maxtags = 0;
  1188. dev->openings = 1 - dev->active;
  1189. }
  1190. switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
  1191. case AHC_DEV_Q_BASIC:
  1192. scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
  1193. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1194. break;
  1195. case AHC_DEV_Q_TAGGED:
  1196. scsi_set_tag_type(sdev, MSG_ORDERED_TAG);
  1197. scsi_activate_tcq(sdev, dev->openings + dev->active);
  1198. break;
  1199. default:
  1200. /*
  1201. * We allow the OS to queue 2 untagged transactions to
  1202. * us at any time even though we can only execute them
  1203. * serially on the controller/device. This should
  1204. * remove some latency.
  1205. */
  1206. scsi_deactivate_tcq(sdev, 2);
  1207. break;
  1208. }
  1209. }
  1210. int
  1211. ahc_platform_abort_scbs(struct ahc_softc *ahc, int target, char channel,
  1212. int lun, u_int tag, role_t role, uint32_t status)
  1213. {
  1214. return 0;
  1215. }
  1216. static u_int
  1217. ahc_linux_user_tagdepth(struct ahc_softc *ahc, struct ahc_devinfo *devinfo)
  1218. {
  1219. static int warned_user;
  1220. u_int tags;
  1221. tags = 0;
  1222. if ((ahc->user_discenable & devinfo->target_mask) != 0) {
  1223. if (ahc->unit >= ARRAY_SIZE(aic7xxx_tag_info)) {
  1224. if (warned_user == 0) {
  1225. printf(KERN_WARNING
  1226. "aic7xxx: WARNING: Insufficient tag_info instances\n"
  1227. "aic7xxx: for installed controllers. Using defaults\n"
  1228. "aic7xxx: Please update the aic7xxx_tag_info array in\n"
  1229. "aic7xxx: the aic7xxx_osm..c source file.\n");
  1230. warned_user++;
  1231. }
  1232. tags = AHC_MAX_QUEUE;
  1233. } else {
  1234. adapter_tag_info_t *tag_info;
  1235. tag_info = &aic7xxx_tag_info[ahc->unit];
  1236. tags = tag_info->tag_commands[devinfo->target_offset];
  1237. if (tags > AHC_MAX_QUEUE)
  1238. tags = AHC_MAX_QUEUE;
  1239. }
  1240. }
  1241. return (tags);
  1242. }
  1243. /*
  1244. * Determines the queue depth for a given device.
  1245. */
  1246. static void
  1247. ahc_linux_device_queue_depth(struct scsi_device *sdev)
  1248. {
  1249. struct ahc_devinfo devinfo;
  1250. u_int tags;
  1251. struct ahc_softc *ahc = *((struct ahc_softc **)sdev->host->hostdata);
  1252. ahc_compile_devinfo(&devinfo,
  1253. sdev->sdev_target->channel == 0
  1254. ? ahc->our_id : ahc->our_id_b,
  1255. sdev->sdev_target->id, sdev->lun,
  1256. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1257. ROLE_INITIATOR);
  1258. tags = ahc_linux_user_tagdepth(ahc, &devinfo);
  1259. if (tags != 0 && sdev->tagged_supported != 0) {
  1260. ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_TAGGED);
  1261. ahc_send_async(ahc, devinfo.channel, devinfo.target,
  1262. devinfo.lun, AC_TRANSFER_NEG);
  1263. ahc_print_devinfo(ahc, &devinfo);
  1264. printf("Tagged Queuing enabled. Depth %d\n", tags);
  1265. } else {
  1266. ahc_platform_set_tags(ahc, sdev, &devinfo, AHC_QUEUE_NONE);
  1267. ahc_send_async(ahc, devinfo.channel, devinfo.target,
  1268. devinfo.lun, AC_TRANSFER_NEG);
  1269. }
  1270. }
  1271. static int
  1272. ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
  1273. struct scsi_cmnd *cmd)
  1274. {
  1275. struct scb *scb;
  1276. struct hardware_scb *hscb;
  1277. struct ahc_initiator_tinfo *tinfo;
  1278. struct ahc_tmode_tstate *tstate;
  1279. uint16_t mask;
  1280. struct scb_tailq *untagged_q = NULL;
  1281. int nseg;
  1282. /*
  1283. * Schedule us to run later. The only reason we are not
  1284. * running is because the whole controller Q is frozen.
  1285. */
  1286. if (ahc->platform_data->qfrozen != 0)
  1287. return SCSI_MLQUEUE_HOST_BUSY;
  1288. /*
  1289. * We only allow one untagged transaction
  1290. * per target in the initiator role unless
  1291. * we are storing a full busy target *lun*
  1292. * table in SCB space.
  1293. */
  1294. if (!blk_rq_tagged(cmd->request)
  1295. && (ahc->features & AHC_SCB_BTT) == 0) {
  1296. int target_offset;
  1297. target_offset = cmd->device->id + cmd->device->channel * 8;
  1298. untagged_q = &(ahc->untagged_queues[target_offset]);
  1299. if (!TAILQ_EMPTY(untagged_q))
  1300. /* if we're already executing an untagged command
  1301. * we're busy to another */
  1302. return SCSI_MLQUEUE_DEVICE_BUSY;
  1303. }
  1304. nseg = scsi_dma_map(cmd);
  1305. if (nseg < 0)
  1306. return SCSI_MLQUEUE_HOST_BUSY;
  1307. /*
  1308. * Get an scb to use.
  1309. */
  1310. scb = ahc_get_scb(ahc);
  1311. if (!scb) {
  1312. scsi_dma_unmap(cmd);
  1313. return SCSI_MLQUEUE_HOST_BUSY;
  1314. }
  1315. scb->io_ctx = cmd;
  1316. scb->platform_data->dev = dev;
  1317. hscb = scb->hscb;
  1318. cmd->host_scribble = (char *)scb;
  1319. /*
  1320. * Fill out basics of the HSCB.
  1321. */
  1322. hscb->control = 0;
  1323. hscb->scsiid = BUILD_SCSIID(ahc, cmd);
  1324. hscb->lun = cmd->device->lun;
  1325. mask = SCB_GET_TARGET_MASK(ahc, scb);
  1326. tinfo = ahc_fetch_transinfo(ahc, SCB_GET_CHANNEL(ahc, scb),
  1327. SCB_GET_OUR_ID(scb),
  1328. SCB_GET_TARGET(ahc, scb), &tstate);
  1329. hscb->scsirate = tinfo->scsirate;
  1330. hscb->scsioffset = tinfo->curr.offset;
  1331. if ((tstate->ultraenb & mask) != 0)
  1332. hscb->control |= ULTRAENB;
  1333. if ((ahc->user_discenable & mask) != 0)
  1334. hscb->control |= DISCENB;
  1335. if ((tstate->auto_negotiate & mask) != 0) {
  1336. scb->flags |= SCB_AUTO_NEGOTIATE;
  1337. scb->hscb->control |= MK_MESSAGE;
  1338. }
  1339. if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
  1340. int msg_bytes;
  1341. uint8_t tag_msgs[2];
  1342. msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
  1343. if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
  1344. hscb->control |= tag_msgs[0];
  1345. if (tag_msgs[0] == MSG_ORDERED_TASK)
  1346. dev->commands_since_idle_or_otag = 0;
  1347. } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
  1348. && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
  1349. hscb->control |= MSG_ORDERED_TASK;
  1350. dev->commands_since_idle_or_otag = 0;
  1351. } else {
  1352. hscb->control |= MSG_SIMPLE_TASK;
  1353. }
  1354. }
  1355. hscb->cdb_len = cmd->cmd_len;
  1356. if (hscb->cdb_len <= 12) {
  1357. memcpy(hscb->shared_data.cdb, cmd->cmnd, hscb->cdb_len);
  1358. } else {
  1359. memcpy(hscb->cdb32, cmd->cmnd, hscb->cdb_len);
  1360. scb->flags |= SCB_CDB32_PTR;
  1361. }
  1362. scb->platform_data->xfer_len = 0;
  1363. ahc_set_residual(scb, 0);
  1364. ahc_set_sense_residual(scb, 0);
  1365. scb->sg_count = 0;
  1366. if (nseg > 0) {
  1367. struct ahc_dma_seg *sg;
  1368. struct scatterlist *cur_seg;
  1369. int i;
  1370. /* Copy the segments into the SG list. */
  1371. sg = scb->sg_list;
  1372. /*
  1373. * The sg_count may be larger than nseg if
  1374. * a transfer crosses a 32bit page.
  1375. */
  1376. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1377. dma_addr_t addr;
  1378. bus_size_t len;
  1379. int consumed;
  1380. addr = sg_dma_address(cur_seg);
  1381. len = sg_dma_len(cur_seg);
  1382. consumed = ahc_linux_map_seg(ahc, scb,
  1383. sg, addr, len);
  1384. sg += consumed;
  1385. scb->sg_count += consumed;
  1386. }
  1387. sg--;
  1388. sg->len |= ahc_htole32(AHC_DMA_LAST_SEG);
  1389. /*
  1390. * Reset the sg list pointer.
  1391. */
  1392. scb->hscb->sgptr =
  1393. ahc_htole32(scb->sg_list_phys | SG_FULL_RESID);
  1394. /*
  1395. * Copy the first SG into the "current"
  1396. * data pointer area.
  1397. */
  1398. scb->hscb->dataptr = scb->sg_list->addr;
  1399. scb->hscb->datacnt = scb->sg_list->len;
  1400. } else {
  1401. scb->hscb->sgptr = ahc_htole32(SG_LIST_NULL);
  1402. scb->hscb->dataptr = 0;
  1403. scb->hscb->datacnt = 0;
  1404. scb->sg_count = 0;
  1405. }
  1406. LIST_INSERT_HEAD(&ahc->pending_scbs, scb, pending_links);
  1407. dev->openings--;
  1408. dev->active++;
  1409. dev->commands_issued++;
  1410. if ((dev->flags & AHC_DEV_PERIODIC_OTAG) != 0)
  1411. dev->commands_since_idle_or_otag++;
  1412. scb->flags |= SCB_ACTIVE;
  1413. if (untagged_q) {
  1414. TAILQ_INSERT_TAIL(untagged_q, scb, links.tqe);
  1415. scb->flags |= SCB_UNTAGGEDQ;
  1416. }
  1417. ahc_queue_scb(ahc, scb);
  1418. return 0;
  1419. }
  1420. /*
  1421. * SCSI controller interrupt handler.
  1422. */
  1423. irqreturn_t
  1424. ahc_linux_isr(int irq, void *dev_id)
  1425. {
  1426. struct ahc_softc *ahc;
  1427. u_long flags;
  1428. int ours;
  1429. ahc = (struct ahc_softc *) dev_id;
  1430. ahc_lock(ahc, &flags);
  1431. ours = ahc_intr(ahc);
  1432. ahc_unlock(ahc, &flags);
  1433. return IRQ_RETVAL(ours);
  1434. }
  1435. void
  1436. ahc_platform_flushwork(struct ahc_softc *ahc)
  1437. {
  1438. }
  1439. void
  1440. ahc_send_async(struct ahc_softc *ahc, char channel,
  1441. u_int target, u_int lun, ac_code code)
  1442. {
  1443. switch (code) {
  1444. case AC_TRANSFER_NEG:
  1445. {
  1446. char buf[80];
  1447. struct scsi_target *starget;
  1448. struct ahc_linux_target *targ;
  1449. struct info_str info;
  1450. struct ahc_initiator_tinfo *tinfo;
  1451. struct ahc_tmode_tstate *tstate;
  1452. int target_offset;
  1453. unsigned int target_ppr_options;
  1454. BUG_ON(target == CAM_TARGET_WILDCARD);
  1455. info.buffer = buf;
  1456. info.length = sizeof(buf);
  1457. info.offset = 0;
  1458. info.pos = 0;
  1459. tinfo = ahc_fetch_transinfo(ahc, channel,
  1460. channel == 'A' ? ahc->our_id
  1461. : ahc->our_id_b,
  1462. target, &tstate);
  1463. /*
  1464. * Don't bother reporting results while
  1465. * negotiations are still pending.
  1466. */
  1467. if (tinfo->curr.period != tinfo->goal.period
  1468. || tinfo->curr.width != tinfo->goal.width
  1469. || tinfo->curr.offset != tinfo->goal.offset
  1470. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1471. if (bootverbose == 0)
  1472. break;
  1473. /*
  1474. * Don't bother reporting results that
  1475. * are identical to those last reported.
  1476. */
  1477. target_offset = target;
  1478. if (channel == 'B')
  1479. target_offset += 8;
  1480. starget = ahc->platform_data->starget[target_offset];
  1481. if (starget == NULL)
  1482. break;
  1483. targ = scsi_transport_target_data(starget);
  1484. target_ppr_options =
  1485. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1486. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1487. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0);
  1488. if (tinfo->curr.period == spi_period(starget)
  1489. && tinfo->curr.width == spi_width(starget)
  1490. && tinfo->curr.offset == spi_offset(starget)
  1491. && tinfo->curr.ppr_options == target_ppr_options)
  1492. if (bootverbose == 0)
  1493. break;
  1494. spi_period(starget) = tinfo->curr.period;
  1495. spi_width(starget) = tinfo->curr.width;
  1496. spi_offset(starget) = tinfo->curr.offset;
  1497. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1498. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1499. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1500. spi_display_xfer_agreement(starget);
  1501. break;
  1502. }
  1503. case AC_SENT_BDR:
  1504. {
  1505. WARN_ON(lun != CAM_LUN_WILDCARD);
  1506. scsi_report_device_reset(ahc->platform_data->host,
  1507. channel - 'A', target);
  1508. break;
  1509. }
  1510. case AC_BUS_RESET:
  1511. if (ahc->platform_data->host != NULL) {
  1512. scsi_report_bus_reset(ahc->platform_data->host,
  1513. channel - 'A');
  1514. }
  1515. break;
  1516. default:
  1517. panic("ahc_send_async: Unexpected async event");
  1518. }
  1519. }
  1520. /*
  1521. * Calls the higher level scsi done function and frees the scb.
  1522. */
  1523. void
  1524. ahc_done(struct ahc_softc *ahc, struct scb *scb)
  1525. {
  1526. struct scsi_cmnd *cmd;
  1527. struct ahc_linux_device *dev;
  1528. LIST_REMOVE(scb, pending_links);
  1529. if ((scb->flags & SCB_UNTAGGEDQ) != 0) {
  1530. struct scb_tailq *untagged_q;
  1531. int target_offset;
  1532. target_offset = SCB_GET_TARGET_OFFSET(ahc, scb);
  1533. untagged_q = &(ahc->untagged_queues[target_offset]);
  1534. TAILQ_REMOVE(untagged_q, scb, links.tqe);
  1535. BUG_ON(!TAILQ_EMPTY(untagged_q));
  1536. } else if ((scb->flags & SCB_ACTIVE) == 0) {
  1537. /*
  1538. * Transactions aborted from the untagged queue may
  1539. * not have been dispatched to the controller, so
  1540. * only check the SCB_ACTIVE flag for tagged transactions.
  1541. */
  1542. printf("SCB %d done'd twice\n", scb->hscb->tag);
  1543. ahc_dump_card_state(ahc);
  1544. panic("Stopping for safety");
  1545. }
  1546. cmd = scb->io_ctx;
  1547. dev = scb->platform_data->dev;
  1548. dev->active--;
  1549. dev->openings++;
  1550. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1551. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1552. dev->qfrozen--;
  1553. }
  1554. ahc_linux_unmap_scb(ahc, scb);
  1555. /*
  1556. * Guard against stale sense data.
  1557. * The Linux mid-layer assumes that sense
  1558. * was retrieved anytime the first byte of
  1559. * the sense buffer looks "sane".
  1560. */
  1561. cmd->sense_buffer[0] = 0;
  1562. if (ahc_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1563. uint32_t amount_xferred;
  1564. amount_xferred =
  1565. ahc_get_transfer_length(scb) - ahc_get_residual(scb);
  1566. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1567. #ifdef AHC_DEBUG
  1568. if ((ahc_debug & AHC_SHOW_MISC) != 0) {
  1569. ahc_print_path(ahc, scb);
  1570. printf("Set CAM_UNCOR_PARITY\n");
  1571. }
  1572. #endif
  1573. ahc_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1574. #ifdef AHC_REPORT_UNDERFLOWS
  1575. /*
  1576. * This code is disabled by default as some
  1577. * clients of the SCSI system do not properly
  1578. * initialize the underflow parameter. This
  1579. * results in spurious termination of commands
  1580. * that complete as expected (e.g. underflow is
  1581. * allowed as command can return variable amounts
  1582. * of data.
  1583. */
  1584. } else if (amount_xferred < scb->io_ctx->underflow) {
  1585. u_int i;
  1586. ahc_print_path(ahc, scb);
  1587. printf("CDB:");
  1588. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1589. printf(" 0x%x", scb->io_ctx->cmnd[i]);
  1590. printf("\n");
  1591. ahc_print_path(ahc, scb);
  1592. printf("Saw underflow (%ld of %ld bytes). "
  1593. "Treated as error\n",
  1594. ahc_get_residual(scb),
  1595. ahc_get_transfer_length(scb));
  1596. ahc_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1597. #endif
  1598. } else {
  1599. ahc_set_transaction_status(scb, CAM_REQ_CMP);
  1600. }
  1601. } else if (ahc_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1602. ahc_linux_handle_scsi_status(ahc, cmd->device, scb);
  1603. }
  1604. if (dev->openings == 1
  1605. && ahc_get_transaction_status(scb) == CAM_REQ_CMP
  1606. && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
  1607. dev->tag_success_count++;
  1608. /*
  1609. * Some devices deal with temporary internal resource
  1610. * shortages by returning queue full. When the queue
  1611. * full occurrs, we throttle back. Slowly try to get
  1612. * back to our previous queue depth.
  1613. */
  1614. if ((dev->openings + dev->active) < dev->maxtags
  1615. && dev->tag_success_count > AHC_TAG_SUCCESS_INTERVAL) {
  1616. dev->tag_success_count = 0;
  1617. dev->openings++;
  1618. }
  1619. if (dev->active == 0)
  1620. dev->commands_since_idle_or_otag = 0;
  1621. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1622. printf("Recovery SCB completes\n");
  1623. if (ahc_get_transaction_status(scb) == CAM_BDR_SENT
  1624. || ahc_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1625. ahc_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1626. if (ahc->platform_data->eh_done)
  1627. complete(ahc->platform_data->eh_done);
  1628. }
  1629. ahc_free_scb(ahc, scb);
  1630. ahc_linux_queue_cmd_complete(ahc, cmd);
  1631. }
  1632. static void
  1633. ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
  1634. struct scsi_device *sdev, struct scb *scb)
  1635. {
  1636. struct ahc_devinfo devinfo;
  1637. struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
  1638. ahc_compile_devinfo(&devinfo,
  1639. ahc->our_id,
  1640. sdev->sdev_target->id, sdev->lun,
  1641. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1642. ROLE_INITIATOR);
  1643. /*
  1644. * We don't currently trust the mid-layer to
  1645. * properly deal with queue full or busy. So,
  1646. * when one occurs, we tell the mid-layer to
  1647. * unconditionally requeue the command to us
  1648. * so that we can retry it ourselves. We also
  1649. * implement our own throttling mechanism so
  1650. * we don't clobber the device with too many
  1651. * commands.
  1652. */
  1653. switch (ahc_get_scsi_status(scb)) {
  1654. default:
  1655. break;
  1656. case SCSI_STATUS_CHECK_COND:
  1657. case SCSI_STATUS_CMD_TERMINATED:
  1658. {
  1659. struct scsi_cmnd *cmd;
  1660. /*
  1661. * Copy sense information to the OS's cmd
  1662. * structure if it is available.
  1663. */
  1664. cmd = scb->io_ctx;
  1665. if (scb->flags & SCB_SENSE) {
  1666. u_int sense_size;
  1667. sense_size = min(sizeof(struct scsi_sense_data)
  1668. - ahc_get_sense_residual(scb),
  1669. (u_long)SCSI_SENSE_BUFFERSIZE);
  1670. memcpy(cmd->sense_buffer,
  1671. ahc_get_sense_buf(ahc, scb), sense_size);
  1672. if (sense_size < SCSI_SENSE_BUFFERSIZE)
  1673. memset(&cmd->sense_buffer[sense_size], 0,
  1674. SCSI_SENSE_BUFFERSIZE - sense_size);
  1675. cmd->result |= (DRIVER_SENSE << 24);
  1676. #ifdef AHC_DEBUG
  1677. if (ahc_debug & AHC_SHOW_SENSE) {
  1678. int i;
  1679. printf("Copied %d bytes of sense data:",
  1680. sense_size);
  1681. for (i = 0; i < sense_size; i++) {
  1682. if ((i & 0xF) == 0)
  1683. printf("\n");
  1684. printf("0x%x ", cmd->sense_buffer[i]);
  1685. }
  1686. printf("\n");
  1687. }
  1688. #endif
  1689. }
  1690. break;
  1691. }
  1692. case SCSI_STATUS_QUEUE_FULL:
  1693. {
  1694. /*
  1695. * By the time the core driver has returned this
  1696. * command, all other commands that were queued
  1697. * to us but not the device have been returned.
  1698. * This ensures that dev->active is equal to
  1699. * the number of commands actually queued to
  1700. * the device.
  1701. */
  1702. dev->tag_success_count = 0;
  1703. if (dev->active != 0) {
  1704. /*
  1705. * Drop our opening count to the number
  1706. * of commands currently outstanding.
  1707. */
  1708. dev->openings = 0;
  1709. /*
  1710. ahc_print_path(ahc, scb);
  1711. printf("Dropping tag count to %d\n", dev->active);
  1712. */
  1713. if (dev->active == dev->tags_on_last_queuefull) {
  1714. dev->last_queuefull_same_count++;
  1715. /*
  1716. * If we repeatedly see a queue full
  1717. * at the same queue depth, this
  1718. * device has a fixed number of tag
  1719. * slots. Lock in this tag depth
  1720. * so we stop seeing queue fulls from
  1721. * this device.
  1722. */
  1723. if (dev->last_queuefull_same_count
  1724. == AHC_LOCK_TAGS_COUNT) {
  1725. dev->maxtags = dev->active;
  1726. ahc_print_path(ahc, scb);
  1727. printf("Locking max tag count at %d\n",
  1728. dev->active);
  1729. }
  1730. } else {
  1731. dev->tags_on_last_queuefull = dev->active;
  1732. dev->last_queuefull_same_count = 0;
  1733. }
  1734. ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1735. ahc_set_scsi_status(scb, SCSI_STATUS_OK);
  1736. ahc_platform_set_tags(ahc, sdev, &devinfo,
  1737. (dev->flags & AHC_DEV_Q_BASIC)
  1738. ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
  1739. break;
  1740. }
  1741. /*
  1742. * Drop down to a single opening, and treat this
  1743. * as if the target returned BUSY SCSI status.
  1744. */
  1745. dev->openings = 1;
  1746. ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
  1747. ahc_platform_set_tags(ahc, sdev, &devinfo,
  1748. (dev->flags & AHC_DEV_Q_BASIC)
  1749. ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
  1750. break;
  1751. }
  1752. }
  1753. }
  1754. static void
  1755. ahc_linux_queue_cmd_complete(struct ahc_softc *ahc, struct scsi_cmnd *cmd)
  1756. {
  1757. /*
  1758. * Map CAM error codes into Linux Error codes. We
  1759. * avoid the conversion so that the DV code has the
  1760. * full error information available when making
  1761. * state change decisions.
  1762. */
  1763. {
  1764. u_int new_status;
  1765. switch (ahc_cmd_get_transaction_status(cmd)) {
  1766. case CAM_REQ_INPROG:
  1767. case CAM_REQ_CMP:
  1768. case CAM_SCSI_STATUS_ERROR:
  1769. new_status = DID_OK;
  1770. break;
  1771. case CAM_REQ_ABORTED:
  1772. new_status = DID_ABORT;
  1773. break;
  1774. case CAM_BUSY:
  1775. new_status = DID_BUS_BUSY;
  1776. break;
  1777. case CAM_REQ_INVALID:
  1778. case CAM_PATH_INVALID:
  1779. new_status = DID_BAD_TARGET;
  1780. break;
  1781. case CAM_SEL_TIMEOUT:
  1782. new_status = DID_NO_CONNECT;
  1783. break;
  1784. case CAM_SCSI_BUS_RESET:
  1785. case CAM_BDR_SENT:
  1786. new_status = DID_RESET;
  1787. break;
  1788. case CAM_UNCOR_PARITY:
  1789. new_status = DID_PARITY;
  1790. break;
  1791. case CAM_CMD_TIMEOUT:
  1792. new_status = DID_TIME_OUT;
  1793. break;
  1794. case CAM_UA_ABORT:
  1795. case CAM_REQ_CMP_ERR:
  1796. case CAM_AUTOSENSE_FAIL:
  1797. case CAM_NO_HBA:
  1798. case CAM_DATA_RUN_ERR:
  1799. case CAM_UNEXP_BUSFREE:
  1800. case CAM_SEQUENCE_FAIL:
  1801. case CAM_CCB_LEN_ERR:
  1802. case CAM_PROVIDE_FAIL:
  1803. case CAM_REQ_TERMIO:
  1804. case CAM_UNREC_HBA_ERROR:
  1805. case CAM_REQ_TOO_BIG:
  1806. new_status = DID_ERROR;
  1807. break;
  1808. case CAM_REQUEUE_REQ:
  1809. new_status = DID_REQUEUE;
  1810. break;
  1811. default:
  1812. /* We should never get here */
  1813. new_status = DID_ERROR;
  1814. break;
  1815. }
  1816. ahc_cmd_set_transaction_status(cmd, new_status);
  1817. }
  1818. cmd->scsi_done(cmd);
  1819. }
  1820. static void
  1821. ahc_linux_freeze_simq(struct ahc_softc *ahc)
  1822. {
  1823. unsigned long s;
  1824. ahc_lock(ahc, &s);
  1825. ahc->platform_data->qfrozen++;
  1826. if (ahc->platform_data->qfrozen == 1) {
  1827. scsi_block_requests(ahc->platform_data->host);
  1828. /* XXX What about Twin channels? */
  1829. ahc_platform_abort_scbs(ahc, CAM_TARGET_WILDCARD, ALL_CHANNELS,
  1830. CAM_LUN_WILDCARD, SCB_LIST_NULL,
  1831. ROLE_INITIATOR, CAM_REQUEUE_REQ);
  1832. }
  1833. ahc_unlock(ahc, &s);
  1834. }
  1835. static void
  1836. ahc_linux_release_simq(struct ahc_softc *ahc)
  1837. {
  1838. u_long s;
  1839. int unblock_reqs;
  1840. unblock_reqs = 0;
  1841. ahc_lock(ahc, &s);
  1842. if (ahc->platform_data->qfrozen > 0)
  1843. ahc->platform_data->qfrozen--;
  1844. if (ahc->platform_data->qfrozen == 0)
  1845. unblock_reqs = 1;
  1846. ahc_unlock(ahc, &s);
  1847. /*
  1848. * There is still a race here. The mid-layer
  1849. * should keep its own freeze count and use
  1850. * a bottom half handler to run the queues
  1851. * so we can unblock with our own lock held.
  1852. */
  1853. if (unblock_reqs)
  1854. scsi_unblock_requests(ahc->platform_data->host);
  1855. }
  1856. static int
  1857. ahc_linux_queue_recovery_cmd(struct scsi_cmnd *cmd, scb_flag flag)
  1858. {
  1859. struct ahc_softc *ahc;
  1860. struct ahc_linux_device *dev;
  1861. struct scb *pending_scb;
  1862. u_int saved_scbptr;
  1863. u_int active_scb_index;
  1864. u_int last_phase;
  1865. u_int saved_scsiid;
  1866. u_int cdb_byte;
  1867. int retval;
  1868. int was_paused;
  1869. int paused;
  1870. int wait;
  1871. int disconnected;
  1872. unsigned long flags;
  1873. pending_scb = NULL;
  1874. paused = FALSE;
  1875. wait = FALSE;
  1876. ahc = *(struct ahc_softc **)cmd->device->host->hostdata;
  1877. scmd_printk(KERN_INFO, cmd, "Attempting to queue a%s message\n",
  1878. flag == SCB_ABORT ? "n ABORT" : " TARGET RESET");
  1879. printf("CDB:");
  1880. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1881. printf(" 0x%x", cmd->cmnd[cdb_byte]);
  1882. printf("\n");
  1883. ahc_lock(ahc, &flags);
  1884. /*
  1885. * First determine if we currently own this command.
  1886. * Start by searching the device queue. If not found
  1887. * there, check the pending_scb list. If not found
  1888. * at all, and the system wanted us to just abort the
  1889. * command, return success.
  1890. */
  1891. dev = scsi_transport_device_data(cmd->device);
  1892. if (dev == NULL) {
  1893. /*
  1894. * No target device for this command exists,
  1895. * so we must not still own the command.
  1896. */
  1897. printf("%s:%d:%d:%d: Is not an active device\n",
  1898. ahc_name(ahc), cmd->device->channel, cmd->device->id,
  1899. cmd->device->lun);
  1900. retval = SUCCESS;
  1901. goto no_cmd;
  1902. }
  1903. if ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED)) == 0
  1904. && ahc_search_untagged_queues(ahc, cmd, cmd->device->id,
  1905. cmd->device->channel + 'A',
  1906. cmd->device->lun,
  1907. CAM_REQ_ABORTED, SEARCH_COMPLETE) != 0) {
  1908. printf("%s:%d:%d:%d: Command found on untagged queue\n",
  1909. ahc_name(ahc), cmd->device->channel, cmd->device->id,
  1910. cmd->device->lun);
  1911. retval = SUCCESS;
  1912. goto done;
  1913. }
  1914. /*
  1915. * See if we can find a matching cmd in the pending list.
  1916. */
  1917. LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
  1918. if (pending_scb->io_ctx == cmd)
  1919. break;
  1920. }
  1921. if (pending_scb == NULL && flag == SCB_DEVICE_RESET) {
  1922. /* Any SCB for this device will do for a target reset */
  1923. LIST_FOREACH(pending_scb, &ahc->pending_scbs, pending_links) {
  1924. if (ahc_match_scb(ahc, pending_scb, scmd_id(cmd),
  1925. scmd_channel(cmd) + 'A',
  1926. CAM_LUN_WILDCARD,
  1927. SCB_LIST_NULL, ROLE_INITIATOR))
  1928. break;
  1929. }
  1930. }
  1931. if (pending_scb == NULL) {
  1932. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1933. goto no_cmd;
  1934. }
  1935. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1936. /*
  1937. * We can't queue two recovery actions using the same SCB
  1938. */
  1939. retval = FAILED;
  1940. goto done;
  1941. }
  1942. /*
  1943. * Ensure that the card doesn't do anything
  1944. * behind our back and that we didn't "just" miss
  1945. * an interrupt that would affect this cmd.
  1946. */
  1947. was_paused = ahc_is_paused(ahc);
  1948. ahc_pause_and_flushwork(ahc);
  1949. paused = TRUE;
  1950. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  1951. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  1952. goto no_cmd;
  1953. }
  1954. printf("%s: At time of recovery, card was %spaused\n",
  1955. ahc_name(ahc), was_paused ? "" : "not ");
  1956. ahc_dump_card_state(ahc);
  1957. disconnected = TRUE;
  1958. if (flag == SCB_ABORT) {
  1959. if (ahc_search_qinfifo(ahc, cmd->device->id,
  1960. cmd->device->channel + 'A',
  1961. cmd->device->lun,
  1962. pending_scb->hscb->tag,
  1963. ROLE_INITIATOR, CAM_REQ_ABORTED,
  1964. SEARCH_COMPLETE) > 0) {
  1965. printf("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  1966. ahc_name(ahc), cmd->device->channel,
  1967. cmd->device->id, cmd->device->lun);
  1968. retval = SUCCESS;
  1969. goto done;
  1970. }
  1971. } else if (ahc_search_qinfifo(ahc, cmd->device->id,
  1972. cmd->device->channel + 'A',
  1973. cmd->device->lun, pending_scb->hscb->tag,
  1974. ROLE_INITIATOR, /*status*/0,
  1975. SEARCH_COUNT) > 0) {
  1976. disconnected = FALSE;
  1977. }
  1978. if (disconnected && (ahc_inb(ahc, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  1979. struct scb *bus_scb;
  1980. bus_scb = ahc_lookup_scb(ahc, ahc_inb(ahc, SCB_TAG));
  1981. if (bus_scb == pending_scb)
  1982. disconnected = FALSE;
  1983. else if (flag != SCB_ABORT
  1984. && ahc_inb(ahc, SAVED_SCSIID) == pending_scb->hscb->scsiid
  1985. && ahc_inb(ahc, SAVED_LUN) == SCB_GET_LUN(pending_scb))
  1986. disconnected = FALSE;
  1987. }
  1988. /*
  1989. * At this point, pending_scb is the scb associated with the
  1990. * passed in command. That command is currently active on the
  1991. * bus, is in the disconnected state, or we're hoping to find
  1992. * a command for the same target active on the bus to abuse to
  1993. * send a BDR. Queue the appropriate message based on which of
  1994. * these states we are in.
  1995. */
  1996. last_phase = ahc_inb(ahc, LASTPHASE);
  1997. saved_scbptr = ahc_inb(ahc, SCBPTR);
  1998. active_scb_index = ahc_inb(ahc, SCB_TAG);
  1999. saved_scsiid = ahc_inb(ahc, SAVED_SCSIID);
  2000. if (last_phase != P_BUSFREE
  2001. && (pending_scb->hscb->tag == active_scb_index
  2002. || (flag == SCB_DEVICE_RESET
  2003. && SCSIID_TARGET(ahc, saved_scsiid) == scmd_id(cmd)))) {
  2004. /*
  2005. * We're active on the bus, so assert ATN
  2006. * and hope that the target responds.
  2007. */
  2008. pending_scb = ahc_lookup_scb(ahc, active_scb_index);
  2009. pending_scb->flags |= SCB_RECOVERY_SCB|flag;
  2010. ahc_outb(ahc, MSG_OUT, HOST_MSG);
  2011. ahc_outb(ahc, SCSISIGO, last_phase|ATNO);
  2012. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  2013. wait = TRUE;
  2014. } else if (disconnected) {
  2015. /*
  2016. * Actually re-queue this SCB in an attempt
  2017. * to select the device before it reconnects.
  2018. * In either case (selection or reselection),
  2019. * we will now issue the approprate message
  2020. * to the timed-out device.
  2021. *
  2022. * Set the MK_MESSAGE control bit indicating
  2023. * that we desire to send a message. We
  2024. * also set the disconnected flag since
  2025. * in the paging case there is no guarantee
  2026. * that our SCB control byte matches the
  2027. * version on the card. We don't want the
  2028. * sequencer to abort the command thinking
  2029. * an unsolicited reselection occurred.
  2030. */
  2031. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2032. pending_scb->flags |= SCB_RECOVERY_SCB|flag;
  2033. /*
  2034. * Remove any cached copy of this SCB in the
  2035. * disconnected list in preparation for the
  2036. * queuing of our abort SCB. We use the
  2037. * same element in the SCB, SCB_NEXT, for
  2038. * both the qinfifo and the disconnected list.
  2039. */
  2040. ahc_search_disc_list(ahc, cmd->device->id,
  2041. cmd->device->channel + 'A',
  2042. cmd->device->lun, pending_scb->hscb->tag,
  2043. /*stop_on_first*/TRUE,
  2044. /*remove*/TRUE,
  2045. /*save_state*/FALSE);
  2046. /*
  2047. * In the non-paging case, the sequencer will
  2048. * never re-reference the in-core SCB.
  2049. * To make sure we are notified during
  2050. * reselection, set the MK_MESSAGE flag in
  2051. * the card's copy of the SCB.
  2052. */
  2053. if ((ahc->flags & AHC_PAGESCBS) == 0) {
  2054. ahc_outb(ahc, SCBPTR, pending_scb->hscb->tag);
  2055. ahc_outb(ahc, SCB_CONTROL,
  2056. ahc_inb(ahc, SCB_CONTROL)|MK_MESSAGE);
  2057. }
  2058. /*
  2059. * Clear out any entries in the QINFIFO first
  2060. * so we are the next SCB for this target
  2061. * to run.
  2062. */
  2063. ahc_search_qinfifo(ahc, cmd->device->id,
  2064. cmd->device->channel + 'A',
  2065. cmd->device->lun, SCB_LIST_NULL,
  2066. ROLE_INITIATOR, CAM_REQUEUE_REQ,
  2067. SEARCH_COMPLETE);
  2068. ahc_qinfifo_requeue_tail(ahc, pending_scb);
  2069. ahc_outb(ahc, SCBPTR, saved_scbptr);
  2070. ahc_print_path(ahc, pending_scb);
  2071. printf("Device is disconnected, re-queuing SCB\n");
  2072. wait = TRUE;
  2073. } else {
  2074. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2075. retval = FAILED;
  2076. goto done;
  2077. }
  2078. no_cmd:
  2079. /*
  2080. * Our assumption is that if we don't have the command, no
  2081. * recovery action was required, so we return success. Again,
  2082. * the semantics of the mid-layer recovery engine are not
  2083. * well defined, so this may change in time.
  2084. */
  2085. retval = SUCCESS;
  2086. done:
  2087. if (paused)
  2088. ahc_unpause(ahc);
  2089. if (wait) {
  2090. DECLARE_COMPLETION_ONSTACK(done);
  2091. ahc->platform_data->eh_done = &done;
  2092. ahc_unlock(ahc, &flags);
  2093. printf("Recovery code sleeping\n");
  2094. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  2095. ahc_lock(ahc, &flags);
  2096. ahc->platform_data->eh_done = NULL;
  2097. ahc_unlock(ahc, &flags);
  2098. printf("Timer Expired\n");
  2099. retval = FAILED;
  2100. }
  2101. printf("Recovery code awake\n");
  2102. } else
  2103. ahc_unlock(ahc, &flags);
  2104. return (retval);
  2105. }
  2106. void
  2107. ahc_platform_dump_card_state(struct ahc_softc *ahc)
  2108. {
  2109. }
  2110. static void ahc_linux_set_width(struct scsi_target *starget, int width)
  2111. {
  2112. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2113. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2114. struct ahc_devinfo devinfo;
  2115. unsigned long flags;
  2116. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2117. starget->channel + 'A', ROLE_INITIATOR);
  2118. ahc_lock(ahc, &flags);
  2119. ahc_set_width(ahc, &devinfo, width, AHC_TRANS_GOAL, FALSE);
  2120. ahc_unlock(ahc, &flags);
  2121. }
  2122. static void ahc_linux_set_period(struct scsi_target *starget, int period)
  2123. {
  2124. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2125. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2126. struct ahc_tmode_tstate *tstate;
  2127. struct ahc_initiator_tinfo *tinfo
  2128. = ahc_fetch_transinfo(ahc,
  2129. starget->channel + 'A',
  2130. shost->this_id, starget->id, &tstate);
  2131. struct ahc_devinfo devinfo;
  2132. unsigned int ppr_options = tinfo->goal.ppr_options;
  2133. unsigned long flags;
  2134. unsigned long offset = tinfo->goal.offset;
  2135. const struct ahc_syncrate *syncrate;
  2136. if (offset == 0)
  2137. offset = MAX_OFFSET;
  2138. if (period < 9)
  2139. period = 9; /* 12.5ns is our minimum */
  2140. if (period == 9) {
  2141. if (spi_max_width(starget))
  2142. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2143. else
  2144. /* need wide for DT and need DT for 12.5 ns */
  2145. period = 10;
  2146. }
  2147. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2148. starget->channel + 'A', ROLE_INITIATOR);
  2149. /* all PPR requests apart from QAS require wide transfers */
  2150. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2151. if (spi_width(starget) == 0)
  2152. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2153. }
  2154. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2155. ahc_lock(ahc, &flags);
  2156. ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
  2157. ppr_options, AHC_TRANS_GOAL, FALSE);
  2158. ahc_unlock(ahc, &flags);
  2159. }
  2160. static void ahc_linux_set_offset(struct scsi_target *starget, int offset)
  2161. {
  2162. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2163. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2164. struct ahc_tmode_tstate *tstate;
  2165. struct ahc_initiator_tinfo *tinfo
  2166. = ahc_fetch_transinfo(ahc,
  2167. starget->channel + 'A',
  2168. shost->this_id, starget->id, &tstate);
  2169. struct ahc_devinfo devinfo;
  2170. unsigned int ppr_options = 0;
  2171. unsigned int period = 0;
  2172. unsigned long flags;
  2173. const struct ahc_syncrate *syncrate = NULL;
  2174. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2175. starget->channel + 'A', ROLE_INITIATOR);
  2176. if (offset != 0) {
  2177. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2178. period = tinfo->goal.period;
  2179. ppr_options = tinfo->goal.ppr_options;
  2180. }
  2181. ahc_lock(ahc, &flags);
  2182. ahc_set_syncrate(ahc, &devinfo, syncrate, period, offset,
  2183. ppr_options, AHC_TRANS_GOAL, FALSE);
  2184. ahc_unlock(ahc, &flags);
  2185. }
  2186. static void ahc_linux_set_dt(struct scsi_target *starget, int dt)
  2187. {
  2188. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2189. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2190. struct ahc_tmode_tstate *tstate;
  2191. struct ahc_initiator_tinfo *tinfo
  2192. = ahc_fetch_transinfo(ahc,
  2193. starget->channel + 'A',
  2194. shost->this_id, starget->id, &tstate);
  2195. struct ahc_devinfo devinfo;
  2196. unsigned int ppr_options = tinfo->goal.ppr_options
  2197. & ~MSG_EXT_PPR_DT_REQ;
  2198. unsigned int period = tinfo->goal.period;
  2199. unsigned int width = tinfo->goal.width;
  2200. unsigned long flags;
  2201. const struct ahc_syncrate *syncrate;
  2202. if (dt && spi_max_width(starget)) {
  2203. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2204. if (!width)
  2205. ahc_linux_set_width(starget, 1);
  2206. } else if (period == 9)
  2207. period = 10; /* if resetting DT, period must be >= 25ns */
  2208. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2209. starget->channel + 'A', ROLE_INITIATOR);
  2210. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options,AHC_SYNCRATE_DT);
  2211. ahc_lock(ahc, &flags);
  2212. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2213. ppr_options, AHC_TRANS_GOAL, FALSE);
  2214. ahc_unlock(ahc, &flags);
  2215. }
  2216. #if 0
  2217. /* FIXME: This code claims to support IU and QAS. However, the actual
  2218. * sequencer code and aic7xxx_core have no support for these parameters and
  2219. * will get into a bad state if they're negotiated. Do not enable this
  2220. * unless you know what you're doing */
  2221. static void ahc_linux_set_qas(struct scsi_target *starget, int qas)
  2222. {
  2223. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2224. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2225. struct ahc_tmode_tstate *tstate;
  2226. struct ahc_initiator_tinfo *tinfo
  2227. = ahc_fetch_transinfo(ahc,
  2228. starget->channel + 'A',
  2229. shost->this_id, starget->id, &tstate);
  2230. struct ahc_devinfo devinfo;
  2231. unsigned int ppr_options = tinfo->goal.ppr_options
  2232. & ~MSG_EXT_PPR_QAS_REQ;
  2233. unsigned int period = tinfo->goal.period;
  2234. unsigned long flags;
  2235. struct ahc_syncrate *syncrate;
  2236. if (qas)
  2237. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2238. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2239. starget->channel + 'A', ROLE_INITIATOR);
  2240. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2241. ahc_lock(ahc, &flags);
  2242. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2243. ppr_options, AHC_TRANS_GOAL, FALSE);
  2244. ahc_unlock(ahc, &flags);
  2245. }
  2246. static void ahc_linux_set_iu(struct scsi_target *starget, int iu)
  2247. {
  2248. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2249. struct ahc_softc *ahc = *((struct ahc_softc **)shost->hostdata);
  2250. struct ahc_tmode_tstate *tstate;
  2251. struct ahc_initiator_tinfo *tinfo
  2252. = ahc_fetch_transinfo(ahc,
  2253. starget->channel + 'A',
  2254. shost->this_id, starget->id, &tstate);
  2255. struct ahc_devinfo devinfo;
  2256. unsigned int ppr_options = tinfo->goal.ppr_options
  2257. & ~MSG_EXT_PPR_IU_REQ;
  2258. unsigned int period = tinfo->goal.period;
  2259. unsigned long flags;
  2260. struct ahc_syncrate *syncrate;
  2261. if (iu)
  2262. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2263. ahc_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2264. starget->channel + 'A', ROLE_INITIATOR);
  2265. syncrate = ahc_find_syncrate(ahc, &period, &ppr_options, AHC_SYNCRATE_DT);
  2266. ahc_lock(ahc, &flags);
  2267. ahc_set_syncrate(ahc, &devinfo, syncrate, period, tinfo->goal.offset,
  2268. ppr_options, AHC_TRANS_GOAL, FALSE);
  2269. ahc_unlock(ahc, &flags);
  2270. }
  2271. #endif
  2272. static void ahc_linux_get_signalling(struct Scsi_Host *shost)
  2273. {
  2274. struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
  2275. unsigned long flags;
  2276. u8 mode;
  2277. if (!(ahc->features & AHC_ULTRA2)) {
  2278. /* non-LVD chipset, may not have SBLKCTL reg */
  2279. spi_signalling(shost) =
  2280. ahc->features & AHC_HVD ?
  2281. SPI_SIGNAL_HVD :
  2282. SPI_SIGNAL_SE;
  2283. return;
  2284. }
  2285. ahc_lock(ahc, &flags);
  2286. ahc_pause(ahc);
  2287. mode = ahc_inb(ahc, SBLKCTL);
  2288. ahc_unpause(ahc);
  2289. ahc_unlock(ahc, &flags);
  2290. if (mode & ENAB40)
  2291. spi_signalling(shost) = SPI_SIGNAL_LVD;
  2292. else if (mode & ENAB20)
  2293. spi_signalling(shost) = SPI_SIGNAL_SE;
  2294. else
  2295. spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
  2296. }
  2297. static struct spi_function_template ahc_linux_transport_functions = {
  2298. .set_offset = ahc_linux_set_offset,
  2299. .show_offset = 1,
  2300. .set_period = ahc_linux_set_period,
  2301. .show_period = 1,
  2302. .set_width = ahc_linux_set_width,
  2303. .show_width = 1,
  2304. .set_dt = ahc_linux_set_dt,
  2305. .show_dt = 1,
  2306. #if 0
  2307. .set_iu = ahc_linux_set_iu,
  2308. .show_iu = 1,
  2309. .set_qas = ahc_linux_set_qas,
  2310. .show_qas = 1,
  2311. #endif
  2312. .get_signalling = ahc_linux_get_signalling,
  2313. };
  2314. static int __init
  2315. ahc_linux_init(void)
  2316. {
  2317. /*
  2318. * If we've been passed any parameters, process them now.
  2319. */
  2320. if (aic7xxx)
  2321. aic7xxx_setup(aic7xxx);
  2322. ahc_linux_transport_template =
  2323. spi_attach_transport(&ahc_linux_transport_functions);
  2324. if (!ahc_linux_transport_template)
  2325. return -ENODEV;
  2326. scsi_transport_reserve_device(ahc_linux_transport_template,
  2327. sizeof(struct ahc_linux_device));
  2328. ahc_linux_pci_init();
  2329. ahc_linux_eisa_init();
  2330. return 0;
  2331. }
  2332. static void
  2333. ahc_linux_exit(void)
  2334. {
  2335. ahc_linux_pci_exit();
  2336. ahc_linux_eisa_exit();
  2337. spi_release_transport(ahc_linux_transport_template);
  2338. }
  2339. module_init(ahc_linux_init);
  2340. module_exit(ahc_linux_exit);