aic7xxx_osm.c 71 KB

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