aic79xx_osm.c 78 KB

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