aic7xxx_osm.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599
  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. .use_blk_tags = 1,
  721. };
  722. /**************************** Tasklet Handler *********************************/
  723. /******************************** Macros **************************************/
  724. #define BUILD_SCSIID(ahc, cmd) \
  725. ((((cmd)->device->id << TID_SHIFT) & TID) \
  726. | (((cmd)->device->channel == 0) ? (ahc)->our_id : (ahc)->our_id_b) \
  727. | (((cmd)->device->channel == 0) ? 0 : TWIN_CHNLB))
  728. /******************************** Bus DMA *************************************/
  729. int
  730. ahc_dma_tag_create(struct ahc_softc *ahc, bus_dma_tag_t parent,
  731. bus_size_t alignment, bus_size_t boundary,
  732. dma_addr_t lowaddr, dma_addr_t highaddr,
  733. bus_dma_filter_t *filter, void *filterarg,
  734. bus_size_t maxsize, int nsegments,
  735. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  736. {
  737. bus_dma_tag_t dmat;
  738. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  739. if (dmat == NULL)
  740. return (ENOMEM);
  741. /*
  742. * Linux is very simplistic about DMA memory. For now don't
  743. * maintain all specification information. Once Linux supplies
  744. * better facilities for doing these operations, or the
  745. * needs of this particular driver change, we might need to do
  746. * more here.
  747. */
  748. dmat->alignment = alignment;
  749. dmat->boundary = boundary;
  750. dmat->maxsize = maxsize;
  751. *ret_tag = dmat;
  752. return (0);
  753. }
  754. void
  755. ahc_dma_tag_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat)
  756. {
  757. kfree(dmat);
  758. }
  759. int
  760. ahc_dmamem_alloc(struct ahc_softc *ahc, bus_dma_tag_t dmat, void** vaddr,
  761. int flags, bus_dmamap_t *mapp)
  762. {
  763. *vaddr = pci_alloc_consistent(ahc->dev_softc,
  764. dmat->maxsize, mapp);
  765. if (*vaddr == NULL)
  766. return ENOMEM;
  767. return 0;
  768. }
  769. void
  770. ahc_dmamem_free(struct ahc_softc *ahc, bus_dma_tag_t dmat,
  771. void* vaddr, bus_dmamap_t map)
  772. {
  773. pci_free_consistent(ahc->dev_softc, dmat->maxsize,
  774. vaddr, map);
  775. }
  776. int
  777. ahc_dmamap_load(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map,
  778. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  779. void *cb_arg, int flags)
  780. {
  781. /*
  782. * Assume for now that this will only be used during
  783. * initialization and not for per-transaction buffer mapping.
  784. */
  785. bus_dma_segment_t stack_sg;
  786. stack_sg.ds_addr = map;
  787. stack_sg.ds_len = dmat->maxsize;
  788. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  789. return (0);
  790. }
  791. void
  792. ahc_dmamap_destroy(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  793. {
  794. }
  795. int
  796. ahc_dmamap_unload(struct ahc_softc *ahc, bus_dma_tag_t dmat, bus_dmamap_t map)
  797. {
  798. /* Nothing to do */
  799. return (0);
  800. }
  801. static void
  802. ahc_linux_setup_tag_info_global(char *p)
  803. {
  804. int tags, i, j;
  805. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  806. printk("Setting Global Tags= %d\n", tags);
  807. for (i = 0; i < ARRAY_SIZE(aic7xxx_tag_info); i++) {
  808. for (j = 0; j < AHC_NUM_TARGETS; j++) {
  809. aic7xxx_tag_info[i].tag_commands[j] = tags;
  810. }
  811. }
  812. }
  813. static void
  814. ahc_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  815. {
  816. if ((instance >= 0) && (targ >= 0)
  817. && (instance < ARRAY_SIZE(aic7xxx_tag_info))
  818. && (targ < AHC_NUM_TARGETS)) {
  819. aic7xxx_tag_info[instance].tag_commands[targ] = value & 0xff;
  820. if (bootverbose)
  821. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  822. }
  823. }
  824. static char *
  825. ahc_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  826. void (*callback)(u_long, int, int, int32_t),
  827. u_long callback_arg)
  828. {
  829. char *tok_end;
  830. char *tok_end2;
  831. int i;
  832. int instance;
  833. int targ;
  834. int done;
  835. char tok_list[] = {'.', ',', '{', '}', '\0'};
  836. /* All options use a ':' name/arg separator */
  837. if (*opt_arg != ':')
  838. return (opt_arg);
  839. opt_arg++;
  840. instance = -1;
  841. targ = -1;
  842. done = FALSE;
  843. /*
  844. * Restore separator that may be in
  845. * the middle of our option argument.
  846. */
  847. tok_end = strchr(opt_arg, '\0');
  848. if (tok_end < end)
  849. *tok_end = ',';
  850. while (!done) {
  851. switch (*opt_arg) {
  852. case '{':
  853. if (instance == -1) {
  854. instance = 0;
  855. } else {
  856. if (depth > 1) {
  857. if (targ == -1)
  858. targ = 0;
  859. } else {
  860. printk("Malformed Option %s\n",
  861. opt_name);
  862. done = TRUE;
  863. }
  864. }
  865. opt_arg++;
  866. break;
  867. case '}':
  868. if (targ != -1)
  869. targ = -1;
  870. else if (instance != -1)
  871. instance = -1;
  872. opt_arg++;
  873. break;
  874. case ',':
  875. case '.':
  876. if (instance == -1)
  877. done = TRUE;
  878. else if (targ >= 0)
  879. targ++;
  880. else if (instance >= 0)
  881. instance++;
  882. opt_arg++;
  883. break;
  884. case '\0':
  885. done = TRUE;
  886. break;
  887. default:
  888. tok_end = end;
  889. for (i = 0; tok_list[i]; i++) {
  890. tok_end2 = strchr(opt_arg, tok_list[i]);
  891. if ((tok_end2) && (tok_end2 < tok_end))
  892. tok_end = tok_end2;
  893. }
  894. callback(callback_arg, instance, targ,
  895. simple_strtol(opt_arg, NULL, 0));
  896. opt_arg = tok_end;
  897. break;
  898. }
  899. }
  900. return (opt_arg);
  901. }
  902. /*
  903. * Handle Linux boot parameters. This routine allows for assigning a value
  904. * to a parameter with a ':' between the parameter and the value.
  905. * ie. aic7xxx=stpwlev:1,extended
  906. */
  907. static int
  908. aic7xxx_setup(char *s)
  909. {
  910. int i, n;
  911. char *p;
  912. char *end;
  913. static const struct {
  914. const char *name;
  915. uint32_t *flag;
  916. } options[] = {
  917. { "extended", &aic7xxx_extended },
  918. { "no_reset", &aic7xxx_no_reset },
  919. { "verbose", &aic7xxx_verbose },
  920. { "allow_memio", &aic7xxx_allow_memio},
  921. #ifdef AHC_DEBUG
  922. { "debug", &ahc_debug },
  923. #endif
  924. { "periodic_otag", &aic7xxx_periodic_otag },
  925. { "pci_parity", &aic7xxx_pci_parity },
  926. { "seltime", &aic7xxx_seltime },
  927. { "tag_info", NULL },
  928. { "global_tag_depth", NULL },
  929. { "dv", NULL }
  930. };
  931. end = strchr(s, '\0');
  932. /*
  933. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  934. * will never be 0 in this case.
  935. */
  936. n = 0;
  937. while ((p = strsep(&s, ",.")) != NULL) {
  938. if (*p == '\0')
  939. continue;
  940. for (i = 0; i < ARRAY_SIZE(options); i++) {
  941. n = strlen(options[i].name);
  942. if (strncmp(options[i].name, p, n) == 0)
  943. break;
  944. }
  945. if (i == ARRAY_SIZE(options))
  946. continue;
  947. if (strncmp(p, "global_tag_depth", n) == 0) {
  948. ahc_linux_setup_tag_info_global(p + n);
  949. } else if (strncmp(p, "tag_info", n) == 0) {
  950. s = ahc_parse_brace_option("tag_info", p + n, end,
  951. 2, ahc_linux_setup_tag_info, 0);
  952. } else if (p[n] == ':') {
  953. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  954. } else if (strncmp(p, "verbose", n) == 0) {
  955. *(options[i].flag) = 1;
  956. } else {
  957. *(options[i].flag) ^= 0xFFFFFFFF;
  958. }
  959. }
  960. return 1;
  961. }
  962. __setup("aic7xxx=", aic7xxx_setup);
  963. uint32_t aic7xxx_verbose;
  964. int
  965. ahc_linux_register_host(struct ahc_softc *ahc, struct scsi_host_template *template)
  966. {
  967. char buf[80];
  968. struct Scsi_Host *host;
  969. char *new_name;
  970. u_long s;
  971. int retval;
  972. template->name = ahc->description;
  973. host = scsi_host_alloc(template, sizeof(struct ahc_softc *));
  974. if (host == NULL)
  975. return (ENOMEM);
  976. *((struct ahc_softc **)host->hostdata) = ahc;
  977. ahc->platform_data->host = host;
  978. host->can_queue = AHC_MAX_QUEUE;
  979. host->cmd_per_lun = 2;
  980. /* XXX No way to communicate the ID for multiple channels */
  981. host->this_id = ahc->our_id;
  982. host->irq = ahc->platform_data->irq;
  983. host->max_id = (ahc->features & AHC_WIDE) ? 16 : 8;
  984. host->max_lun = AHC_NUM_LUNS;
  985. host->max_channel = (ahc->features & AHC_TWIN) ? 1 : 0;
  986. host->sg_tablesize = AHC_NSEG;
  987. ahc_lock(ahc, &s);
  988. ahc_set_unit(ahc, ahc_linux_unit++);
  989. ahc_unlock(ahc, &s);
  990. sprintf(buf, "scsi%d", host->host_no);
  991. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  992. if (new_name != NULL) {
  993. strcpy(new_name, buf);
  994. ahc_set_name(ahc, new_name);
  995. }
  996. host->unique_id = ahc->unit;
  997. ahc_linux_initialize_scsi_bus(ahc);
  998. ahc_intr_enable(ahc, TRUE);
  999. host->transportt = ahc_linux_transport_template;
  1000. retval = scsi_add_host(host,
  1001. (ahc->dev_softc ? &ahc->dev_softc->dev : NULL));
  1002. if (retval) {
  1003. printk(KERN_WARNING "aic7xxx: scsi_add_host failed\n");
  1004. scsi_host_put(host);
  1005. return retval;
  1006. }
  1007. scsi_scan_host(host);
  1008. return 0;
  1009. }
  1010. /*
  1011. * Place the SCSI bus into a known state by either resetting it,
  1012. * or forcing transfer negotiations on the next command to any
  1013. * target.
  1014. */
  1015. void
  1016. ahc_linux_initialize_scsi_bus(struct ahc_softc *ahc)
  1017. {
  1018. int i;
  1019. int numtarg;
  1020. unsigned long s;
  1021. i = 0;
  1022. numtarg = 0;
  1023. ahc_lock(ahc, &s);
  1024. if (aic7xxx_no_reset != 0)
  1025. ahc->flags &= ~(AHC_RESET_BUS_A|AHC_RESET_BUS_B);
  1026. if ((ahc->flags & AHC_RESET_BUS_A) != 0)
  1027. ahc_reset_channel(ahc, 'A', /*initiate_reset*/TRUE);
  1028. else
  1029. numtarg = (ahc->features & AHC_WIDE) ? 16 : 8;
  1030. if ((ahc->features & AHC_TWIN) != 0) {
  1031. if ((ahc->flags & AHC_RESET_BUS_B) != 0) {
  1032. ahc_reset_channel(ahc, 'B', /*initiate_reset*/TRUE);
  1033. } else {
  1034. if (numtarg == 0)
  1035. i = 8;
  1036. numtarg += 8;
  1037. }
  1038. }
  1039. /*
  1040. * Force negotiation to async for all targets that
  1041. * will not see an initial bus reset.
  1042. */
  1043. for (; i < numtarg; i++) {
  1044. struct ahc_devinfo devinfo;
  1045. struct ahc_initiator_tinfo *tinfo;
  1046. struct ahc_tmode_tstate *tstate;
  1047. u_int our_id;
  1048. u_int target_id;
  1049. char channel;
  1050. channel = 'A';
  1051. our_id = ahc->our_id;
  1052. target_id = i;
  1053. if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
  1054. channel = 'B';
  1055. our_id = ahc->our_id_b;
  1056. target_id = i % 8;
  1057. }
  1058. tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
  1059. target_id, &tstate);
  1060. ahc_compile_devinfo(&devinfo, our_id, target_id,
  1061. CAM_LUN_WILDCARD, channel, ROLE_INITIATOR);
  1062. ahc_update_neg_request(ahc, &devinfo, tstate,
  1063. tinfo, AHC_NEG_ALWAYS);
  1064. }
  1065. ahc_unlock(ahc, &s);
  1066. /* Give the bus some time to recover */
  1067. if ((ahc->flags & (AHC_RESET_BUS_A|AHC_RESET_BUS_B)) != 0) {
  1068. ahc_linux_freeze_simq(ahc);
  1069. msleep(AIC7XXX_RESET_DELAY);
  1070. ahc_linux_release_simq(ahc);
  1071. }
  1072. }
  1073. int
  1074. ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
  1075. {
  1076. ahc->platform_data =
  1077. kzalloc(sizeof(struct ahc_platform_data), GFP_ATOMIC);
  1078. if (ahc->platform_data == NULL)
  1079. return (ENOMEM);
  1080. ahc->platform_data->irq = AHC_LINUX_NOIRQ;
  1081. ahc_lockinit(ahc);
  1082. ahc->seltime = (aic7xxx_seltime & 0x3) << 4;
  1083. ahc->seltime_b = (aic7xxx_seltime & 0x3) << 4;
  1084. if (aic7xxx_pci_parity == 0)
  1085. ahc->flags |= AHC_DISABLE_PCI_PERR;
  1086. return (0);
  1087. }
  1088. void
  1089. ahc_platform_free(struct ahc_softc *ahc)
  1090. {
  1091. struct scsi_target *starget;
  1092. int i;
  1093. if (ahc->platform_data != NULL) {
  1094. /* destroy all of the device and target objects */
  1095. for (i = 0; i < AHC_NUM_TARGETS; i++) {
  1096. starget = ahc->platform_data->starget[i];
  1097. if (starget != NULL) {
  1098. ahc->platform_data->starget[i] = NULL;
  1099. }
  1100. }
  1101. if (ahc->platform_data->irq != AHC_LINUX_NOIRQ)
  1102. free_irq(ahc->platform_data->irq, ahc);
  1103. if (ahc->tag == BUS_SPACE_PIO
  1104. && ahc->bsh.ioport != 0)
  1105. release_region(ahc->bsh.ioport, 256);
  1106. if (ahc->tag == BUS_SPACE_MEMIO
  1107. && ahc->bsh.maddr != NULL) {
  1108. iounmap(ahc->bsh.maddr);
  1109. release_mem_region(ahc->platform_data->mem_busaddr,
  1110. 0x1000);
  1111. }
  1112. if (ahc->platform_data->host)
  1113. scsi_host_put(ahc->platform_data->host);
  1114. kfree(ahc->platform_data);
  1115. }
  1116. }
  1117. void
  1118. ahc_platform_freeze_devq(struct ahc_softc *ahc, struct scb *scb)
  1119. {
  1120. ahc_platform_abort_scbs(ahc, SCB_GET_TARGET(ahc, scb),
  1121. SCB_GET_CHANNEL(ahc, scb),
  1122. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1123. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1124. }
  1125. void
  1126. ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
  1127. struct ahc_devinfo *devinfo, ahc_queue_alg alg)
  1128. {
  1129. struct ahc_linux_device *dev;
  1130. int was_queuing;
  1131. int now_queuing;
  1132. if (sdev == NULL)
  1133. return;
  1134. dev = scsi_transport_device_data(sdev);
  1135. was_queuing = dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED);
  1136. switch (alg) {
  1137. default:
  1138. case AHC_QUEUE_NONE:
  1139. now_queuing = 0;
  1140. break;
  1141. case AHC_QUEUE_BASIC:
  1142. now_queuing = AHC_DEV_Q_BASIC;
  1143. break;
  1144. case AHC_QUEUE_TAGGED:
  1145. now_queuing = AHC_DEV_Q_TAGGED;
  1146. break;
  1147. }
  1148. if ((dev->flags & AHC_DEV_FREEZE_TIL_EMPTY) == 0
  1149. && (was_queuing != now_queuing)
  1150. && (dev->active != 0)) {
  1151. dev->flags |= AHC_DEV_FREEZE_TIL_EMPTY;
  1152. dev->qfrozen++;
  1153. }
  1154. dev->flags &= ~(AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED|AHC_DEV_PERIODIC_OTAG);
  1155. if (now_queuing) {
  1156. u_int usertags;
  1157. usertags = ahc_linux_user_tagdepth(ahc, devinfo);
  1158. if (!was_queuing) {
  1159. /*
  1160. * Start out aggressively and allow our
  1161. * dynamic queue depth algorithm to take
  1162. * care of the rest.
  1163. */
  1164. dev->maxtags = usertags;
  1165. dev->openings = dev->maxtags - dev->active;
  1166. }
  1167. if (dev->maxtags == 0) {
  1168. /*
  1169. * Queueing is disabled by the user.
  1170. */
  1171. dev->openings = 1;
  1172. } else if (alg == AHC_QUEUE_TAGGED) {
  1173. dev->flags |= AHC_DEV_Q_TAGGED;
  1174. if (aic7xxx_periodic_otag != 0)
  1175. dev->flags |= AHC_DEV_PERIODIC_OTAG;
  1176. } else
  1177. dev->flags |= AHC_DEV_Q_BASIC;
  1178. } else {
  1179. /* We can only have one opening. */
  1180. dev->maxtags = 0;
  1181. dev->openings = 1 - dev->active;
  1182. }
  1183. switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
  1184. case AHC_DEV_Q_BASIC:
  1185. case AHC_DEV_Q_TAGGED:
  1186. scsi_change_queue_depth(sdev,
  1187. dev->openings + dev->active);
  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);