aic79xx_osm.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851
  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 struct ahd_linux_iocell_opts aic79xx_iocell_info[] __ro_after_init =
  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 <[email protected]>");
  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 ahd_linux_queue_lck(struct scsi_cmnd *cmd)
  525. {
  526. struct ahd_softc *ahd;
  527. struct ahd_linux_device *dev = scsi_transport_device_data(cmd->device);
  528. int rtn = SCSI_MLQUEUE_HOST_BUSY;
  529. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  530. cmd->result = CAM_REQ_INPROG << 16;
  531. rtn = ahd_linux_run_command(ahd, dev, cmd);
  532. return rtn;
  533. }
  534. static DEF_SCSI_QCMD(ahd_linux_queue)
  535. static struct scsi_target **
  536. ahd_linux_target_in_softc(struct scsi_target *starget)
  537. {
  538. struct ahd_softc *ahd =
  539. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  540. unsigned int target_offset;
  541. target_offset = starget->id;
  542. if (starget->channel != 0)
  543. target_offset += 8;
  544. return &ahd->platform_data->starget[target_offset];
  545. }
  546. static int
  547. ahd_linux_target_alloc(struct scsi_target *starget)
  548. {
  549. struct ahd_softc *ahd =
  550. *((struct ahd_softc **)dev_to_shost(&starget->dev)->hostdata);
  551. struct seeprom_config *sc = ahd->seep_config;
  552. unsigned long flags;
  553. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  554. struct ahd_devinfo devinfo;
  555. struct ahd_initiator_tinfo *tinfo;
  556. struct ahd_tmode_tstate *tstate;
  557. char channel = starget->channel + 'A';
  558. ahd_lock(ahd, &flags);
  559. BUG_ON(*ahd_targp != NULL);
  560. *ahd_targp = starget;
  561. if (sc) {
  562. int flags = sc->device_flags[starget->id];
  563. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  564. starget->id, &tstate);
  565. if ((flags & CFPACKETIZED) == 0) {
  566. /* don't negotiate packetized (IU) transfers */
  567. spi_max_iu(starget) = 0;
  568. } else {
  569. if ((ahd->features & AHD_RTI) == 0)
  570. spi_rti(starget) = 0;
  571. }
  572. if ((flags & CFQAS) == 0)
  573. spi_max_qas(starget) = 0;
  574. /* Transinfo values have been set to BIOS settings */
  575. spi_max_width(starget) = (flags & CFWIDEB) ? 1 : 0;
  576. spi_min_period(starget) = tinfo->user.period;
  577. spi_max_offset(starget) = tinfo->user.offset;
  578. }
  579. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  580. starget->id, &tstate);
  581. ahd_compile_devinfo(&devinfo, ahd->our_id, starget->id,
  582. CAM_LUN_WILDCARD, channel,
  583. ROLE_INITIATOR);
  584. ahd_set_syncrate(ahd, &devinfo, 0, 0, 0,
  585. AHD_TRANS_GOAL, /*paused*/FALSE);
  586. ahd_set_width(ahd, &devinfo, MSG_EXT_WDTR_BUS_8_BIT,
  587. AHD_TRANS_GOAL, /*paused*/FALSE);
  588. ahd_unlock(ahd, &flags);
  589. return 0;
  590. }
  591. static void
  592. ahd_linux_target_destroy(struct scsi_target *starget)
  593. {
  594. struct scsi_target **ahd_targp = ahd_linux_target_in_softc(starget);
  595. *ahd_targp = NULL;
  596. }
  597. static int
  598. ahd_linux_slave_alloc(struct scsi_device *sdev)
  599. {
  600. struct ahd_softc *ahd =
  601. *((struct ahd_softc **)sdev->host->hostdata);
  602. struct ahd_linux_device *dev;
  603. if (bootverbose)
  604. printk("%s: Slave Alloc %d\n", ahd_name(ahd), sdev->id);
  605. dev = scsi_transport_device_data(sdev);
  606. memset(dev, 0, sizeof(*dev));
  607. /*
  608. * We start out life using untagged
  609. * transactions of which we allow one.
  610. */
  611. dev->openings = 1;
  612. /*
  613. * Set maxtags to 0. This will be changed if we
  614. * later determine that we are dealing with
  615. * a tagged queuing capable device.
  616. */
  617. dev->maxtags = 0;
  618. return (0);
  619. }
  620. static int
  621. ahd_linux_slave_configure(struct scsi_device *sdev)
  622. {
  623. if (bootverbose)
  624. sdev_printk(KERN_INFO, sdev, "Slave Configure\n");
  625. ahd_linux_device_queue_depth(sdev);
  626. /* Initial Domain Validation */
  627. if (!spi_initial_dv(sdev->sdev_target))
  628. spi_dv_device(sdev);
  629. return 0;
  630. }
  631. #if defined(__i386__)
  632. /*
  633. * Return the disk geometry for the given SCSI device.
  634. */
  635. static int
  636. ahd_linux_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  637. sector_t capacity, int geom[])
  638. {
  639. int heads;
  640. int sectors;
  641. int cylinders;
  642. int extended;
  643. struct ahd_softc *ahd;
  644. ahd = *((struct ahd_softc **)sdev->host->hostdata);
  645. if (scsi_partsize(bdev, capacity, geom))
  646. return 0;
  647. heads = 64;
  648. sectors = 32;
  649. cylinders = aic_sector_div(capacity, heads, sectors);
  650. if (aic79xx_extended != 0)
  651. extended = 1;
  652. else
  653. extended = (ahd->flags & AHD_EXTENDED_TRANS_A) != 0;
  654. if (extended && cylinders >= 1024) {
  655. heads = 255;
  656. sectors = 63;
  657. cylinders = aic_sector_div(capacity, heads, sectors);
  658. }
  659. geom[0] = heads;
  660. geom[1] = sectors;
  661. geom[2] = cylinders;
  662. return (0);
  663. }
  664. #endif
  665. /*
  666. * Abort the current SCSI command(s).
  667. */
  668. static int
  669. ahd_linux_abort(struct scsi_cmnd *cmd)
  670. {
  671. return ahd_linux_queue_abort_cmd(cmd);
  672. }
  673. /*
  674. * Attempt to send a target reset message to the device that timed out.
  675. */
  676. static int
  677. ahd_linux_dev_reset(struct scsi_cmnd *cmd)
  678. {
  679. struct ahd_softc *ahd;
  680. struct ahd_linux_device *dev;
  681. struct scb *reset_scb;
  682. u_int cdb_byte;
  683. int retval = SUCCESS;
  684. struct ahd_initiator_tinfo *tinfo;
  685. struct ahd_tmode_tstate *tstate;
  686. unsigned long flags;
  687. DECLARE_COMPLETION_ONSTACK(done);
  688. reset_scb = NULL;
  689. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  690. scmd_printk(KERN_INFO, cmd,
  691. "Attempting to queue a TARGET RESET message:");
  692. printk("CDB:");
  693. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  694. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  695. printk("\n");
  696. /*
  697. * Determine if we currently own this command.
  698. */
  699. dev = scsi_transport_device_data(cmd->device);
  700. if (dev == NULL) {
  701. /*
  702. * No target device for this command exists,
  703. * so we must not still own the command.
  704. */
  705. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  706. return SUCCESS;
  707. }
  708. /*
  709. * Generate us a new SCB
  710. */
  711. reset_scb = ahd_get_scb(ahd, AHD_NEVER_COL_IDX);
  712. if (!reset_scb) {
  713. scmd_printk(KERN_INFO, cmd, "No SCB available\n");
  714. return FAILED;
  715. }
  716. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  717. cmd->device->id, &tstate);
  718. reset_scb->io_ctx = cmd;
  719. reset_scb->platform_data->dev = dev;
  720. reset_scb->sg_count = 0;
  721. ahd_set_residual(reset_scb, 0);
  722. ahd_set_sense_residual(reset_scb, 0);
  723. reset_scb->platform_data->xfer_len = 0;
  724. reset_scb->hscb->control = 0;
  725. reset_scb->hscb->scsiid = BUILD_SCSIID(ahd,cmd);
  726. reset_scb->hscb->lun = cmd->device->lun;
  727. reset_scb->hscb->cdb_len = 0;
  728. reset_scb->hscb->task_management = SIU_TASKMGMT_LUN_RESET;
  729. reset_scb->flags |= SCB_DEVICE_RESET|SCB_RECOVERY_SCB|SCB_ACTIVE;
  730. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  731. reset_scb->flags |= SCB_PACKETIZED;
  732. } else {
  733. reset_scb->hscb->control |= MK_MESSAGE;
  734. }
  735. dev->openings--;
  736. dev->active++;
  737. dev->commands_issued++;
  738. ahd_lock(ahd, &flags);
  739. LIST_INSERT_HEAD(&ahd->pending_scbs, reset_scb, pending_links);
  740. ahd_queue_scb(ahd, reset_scb);
  741. ahd->platform_data->eh_done = &done;
  742. ahd_unlock(ahd, &flags);
  743. printk("%s: Device reset code sleeping\n", ahd_name(ahd));
  744. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  745. ahd_lock(ahd, &flags);
  746. ahd->platform_data->eh_done = NULL;
  747. ahd_unlock(ahd, &flags);
  748. printk("%s: Device reset timer expired (active %d)\n",
  749. ahd_name(ahd), dev->active);
  750. retval = FAILED;
  751. }
  752. printk("%s: Device reset returning 0x%x\n", ahd_name(ahd), retval);
  753. return (retval);
  754. }
  755. /*
  756. * Reset the SCSI bus.
  757. */
  758. static int
  759. ahd_linux_bus_reset(struct scsi_cmnd *cmd)
  760. {
  761. struct ahd_softc *ahd;
  762. int found;
  763. unsigned long flags;
  764. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  765. #ifdef AHD_DEBUG
  766. if ((ahd_debug & AHD_SHOW_RECOVERY) != 0)
  767. printk("%s: Bus reset called for cmd %p\n",
  768. ahd_name(ahd), cmd);
  769. #endif
  770. ahd_lock(ahd, &flags);
  771. found = ahd_reset_channel(ahd, scmd_channel(cmd) + 'A',
  772. /*initiate reset*/TRUE);
  773. ahd_unlock(ahd, &flags);
  774. if (bootverbose)
  775. printk("%s: SCSI bus reset delivered. "
  776. "%d SCBs aborted.\n", ahd_name(ahd), found);
  777. return (SUCCESS);
  778. }
  779. struct scsi_host_template aic79xx_driver_template = {
  780. .module = THIS_MODULE,
  781. .name = "aic79xx",
  782. .proc_name = "aic79xx",
  783. .show_info = ahd_linux_show_info,
  784. .write_info = ahd_proc_write_seeprom,
  785. .info = ahd_linux_info,
  786. .queuecommand = ahd_linux_queue,
  787. .eh_abort_handler = ahd_linux_abort,
  788. .eh_device_reset_handler = ahd_linux_dev_reset,
  789. .eh_bus_reset_handler = ahd_linux_bus_reset,
  790. #if defined(__i386__)
  791. .bios_param = ahd_linux_biosparam,
  792. #endif
  793. .can_queue = AHD_MAX_QUEUE,
  794. .this_id = -1,
  795. .max_sectors = 8192,
  796. .cmd_per_lun = 2,
  797. .slave_alloc = ahd_linux_slave_alloc,
  798. .slave_configure = ahd_linux_slave_configure,
  799. .target_alloc = ahd_linux_target_alloc,
  800. .target_destroy = ahd_linux_target_destroy,
  801. };
  802. /******************************** Bus DMA *************************************/
  803. int
  804. ahd_dma_tag_create(struct ahd_softc *ahd, bus_dma_tag_t parent,
  805. bus_size_t alignment, bus_size_t boundary,
  806. dma_addr_t lowaddr, dma_addr_t highaddr,
  807. bus_dma_filter_t *filter, void *filterarg,
  808. bus_size_t maxsize, int nsegments,
  809. bus_size_t maxsegsz, int flags, bus_dma_tag_t *ret_tag)
  810. {
  811. bus_dma_tag_t dmat;
  812. dmat = kmalloc(sizeof(*dmat), GFP_ATOMIC);
  813. if (dmat == NULL)
  814. return (ENOMEM);
  815. /*
  816. * Linux is very simplistic about DMA memory. For now don't
  817. * maintain all specification information. Once Linux supplies
  818. * better facilities for doing these operations, or the
  819. * needs of this particular driver change, we might need to do
  820. * more here.
  821. */
  822. dmat->alignment = alignment;
  823. dmat->boundary = boundary;
  824. dmat->maxsize = maxsize;
  825. *ret_tag = dmat;
  826. return (0);
  827. }
  828. void
  829. ahd_dma_tag_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat)
  830. {
  831. kfree(dmat);
  832. }
  833. int
  834. ahd_dmamem_alloc(struct ahd_softc *ahd, bus_dma_tag_t dmat, void** vaddr,
  835. int flags, bus_dmamap_t *mapp)
  836. {
  837. *vaddr = dma_alloc_coherent(&ahd->dev_softc->dev, dmat->maxsize, mapp,
  838. GFP_ATOMIC);
  839. if (*vaddr == NULL)
  840. return (ENOMEM);
  841. return(0);
  842. }
  843. void
  844. ahd_dmamem_free(struct ahd_softc *ahd, bus_dma_tag_t dmat,
  845. void* vaddr, bus_dmamap_t map)
  846. {
  847. dma_free_coherent(&ahd->dev_softc->dev, dmat->maxsize, vaddr, map);
  848. }
  849. int
  850. ahd_dmamap_load(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map,
  851. void *buf, bus_size_t buflen, bus_dmamap_callback_t *cb,
  852. void *cb_arg, int flags)
  853. {
  854. /*
  855. * Assume for now that this will only be used during
  856. * initialization and not for per-transaction buffer mapping.
  857. */
  858. bus_dma_segment_t stack_sg;
  859. stack_sg.ds_addr = map;
  860. stack_sg.ds_len = dmat->maxsize;
  861. cb(cb_arg, &stack_sg, /*nseg*/1, /*error*/0);
  862. return (0);
  863. }
  864. void
  865. ahd_dmamap_destroy(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  866. {
  867. }
  868. int
  869. ahd_dmamap_unload(struct ahd_softc *ahd, bus_dma_tag_t dmat, bus_dmamap_t map)
  870. {
  871. /* Nothing to do */
  872. return (0);
  873. }
  874. /********************* Platform Dependent Functions ***************************/
  875. static void
  876. ahd_linux_setup_iocell_info(u_long index, int instance, int targ, int32_t value)
  877. {
  878. if ((instance >= 0)
  879. && (instance < ARRAY_SIZE(aic79xx_iocell_info))) {
  880. uint8_t *iocell_info;
  881. iocell_info = (uint8_t*)&aic79xx_iocell_info[instance];
  882. iocell_info[index] = value & 0xFFFF;
  883. if (bootverbose)
  884. printk("iocell[%d:%ld] = %d\n", instance, index, value);
  885. }
  886. }
  887. static void
  888. ahd_linux_setup_tag_info_global(char *p)
  889. {
  890. int tags, i, j;
  891. tags = simple_strtoul(p + 1, NULL, 0) & 0xff;
  892. printk("Setting Global Tags= %d\n", tags);
  893. for (i = 0; i < ARRAY_SIZE(aic79xx_tag_info); i++) {
  894. for (j = 0; j < AHD_NUM_TARGETS; j++) {
  895. aic79xx_tag_info[i].tag_commands[j] = tags;
  896. }
  897. }
  898. }
  899. static void
  900. ahd_linux_setup_tag_info(u_long arg, int instance, int targ, int32_t value)
  901. {
  902. if ((instance >= 0) && (targ >= 0)
  903. && (instance < ARRAY_SIZE(aic79xx_tag_info))
  904. && (targ < AHD_NUM_TARGETS)) {
  905. aic79xx_tag_info[instance].tag_commands[targ] = value & 0x1FF;
  906. if (bootverbose)
  907. printk("tag_info[%d:%d] = %d\n", instance, targ, value);
  908. }
  909. }
  910. static char *
  911. ahd_parse_brace_option(char *opt_name, char *opt_arg, char *end, int depth,
  912. void (*callback)(u_long, int, int, int32_t),
  913. u_long callback_arg)
  914. {
  915. char *tok_end;
  916. char *tok_end2;
  917. int i;
  918. int instance;
  919. int targ;
  920. int done;
  921. char tok_list[] = {'.', ',', '{', '}', '\0'};
  922. /* All options use a ':' name/arg separator */
  923. if (*opt_arg != ':')
  924. return (opt_arg);
  925. opt_arg++;
  926. instance = -1;
  927. targ = -1;
  928. done = FALSE;
  929. /*
  930. * Restore separator that may be in
  931. * the middle of our option argument.
  932. */
  933. tok_end = strchr(opt_arg, '\0');
  934. if (tok_end < end)
  935. *tok_end = ',';
  936. while (!done) {
  937. switch (*opt_arg) {
  938. case '{':
  939. if (instance == -1) {
  940. instance = 0;
  941. } else {
  942. if (depth > 1) {
  943. if (targ == -1)
  944. targ = 0;
  945. } else {
  946. printk("Malformed Option %s\n",
  947. opt_name);
  948. done = TRUE;
  949. }
  950. }
  951. opt_arg++;
  952. break;
  953. case '}':
  954. if (targ != -1)
  955. targ = -1;
  956. else if (instance != -1)
  957. instance = -1;
  958. opt_arg++;
  959. break;
  960. case ',':
  961. case '.':
  962. if (instance == -1)
  963. done = TRUE;
  964. else if (targ >= 0)
  965. targ++;
  966. else if (instance >= 0)
  967. instance++;
  968. opt_arg++;
  969. break;
  970. case '\0':
  971. done = TRUE;
  972. break;
  973. default:
  974. tok_end = end;
  975. for (i = 0; tok_list[i]; i++) {
  976. tok_end2 = strchr(opt_arg, tok_list[i]);
  977. if ((tok_end2) && (tok_end2 < tok_end))
  978. tok_end = tok_end2;
  979. }
  980. callback(callback_arg, instance, targ,
  981. simple_strtol(opt_arg, NULL, 0));
  982. opt_arg = tok_end;
  983. break;
  984. }
  985. }
  986. return (opt_arg);
  987. }
  988. /*
  989. * Handle Linux boot parameters. This routine allows for assigning a value
  990. * to a parameter with a ':' between the parameter and the value.
  991. * ie. aic79xx=stpwlev:1,extended
  992. */
  993. static int
  994. aic79xx_setup(char *s)
  995. {
  996. int i, n;
  997. char *p;
  998. char *end;
  999. static const struct {
  1000. const char *name;
  1001. uint32_t *flag;
  1002. } options[] = {
  1003. { "extended", &aic79xx_extended },
  1004. { "no_reset", &aic79xx_no_reset },
  1005. { "verbose", &aic79xx_verbose },
  1006. { "allow_memio", &aic79xx_allow_memio},
  1007. #ifdef AHD_DEBUG
  1008. { "debug", &ahd_debug },
  1009. #endif
  1010. { "periodic_otag", &aic79xx_periodic_otag },
  1011. { "pci_parity", &aic79xx_pci_parity },
  1012. { "seltime", &aic79xx_seltime },
  1013. { "tag_info", NULL },
  1014. { "global_tag_depth", NULL},
  1015. { "slewrate", NULL },
  1016. { "precomp", NULL },
  1017. { "amplitude", NULL },
  1018. { "slowcrc", &aic79xx_slowcrc },
  1019. };
  1020. end = strchr(s, '\0');
  1021. /*
  1022. * XXX ia64 gcc isn't smart enough to know that ARRAY_SIZE
  1023. * will never be 0 in this case.
  1024. */
  1025. n = 0;
  1026. while ((p = strsep(&s, ",.")) != NULL) {
  1027. if (*p == '\0')
  1028. continue;
  1029. for (i = 0; i < ARRAY_SIZE(options); i++) {
  1030. n = strlen(options[i].name);
  1031. if (strncmp(options[i].name, p, n) == 0)
  1032. break;
  1033. }
  1034. if (i == ARRAY_SIZE(options))
  1035. continue;
  1036. if (strncmp(p, "global_tag_depth", n) == 0) {
  1037. ahd_linux_setup_tag_info_global(p + n);
  1038. } else if (strncmp(p, "tag_info", n) == 0) {
  1039. s = ahd_parse_brace_option("tag_info", p + n, end,
  1040. 2, ahd_linux_setup_tag_info, 0);
  1041. } else if (strncmp(p, "slewrate", n) == 0) {
  1042. s = ahd_parse_brace_option("slewrate",
  1043. p + n, end, 1, ahd_linux_setup_iocell_info,
  1044. AIC79XX_SLEWRATE_INDEX);
  1045. } else if (strncmp(p, "precomp", n) == 0) {
  1046. s = ahd_parse_brace_option("precomp",
  1047. p + n, end, 1, ahd_linux_setup_iocell_info,
  1048. AIC79XX_PRECOMP_INDEX);
  1049. } else if (strncmp(p, "amplitude", n) == 0) {
  1050. s = ahd_parse_brace_option("amplitude",
  1051. p + n, end, 1, ahd_linux_setup_iocell_info,
  1052. AIC79XX_AMPLITUDE_INDEX);
  1053. } else if (p[n] == ':') {
  1054. *(options[i].flag) = simple_strtoul(p + n + 1, NULL, 0);
  1055. } else if (!strncmp(p, "verbose", n)) {
  1056. *(options[i].flag) = 1;
  1057. } else {
  1058. *(options[i].flag) ^= 0xFFFFFFFF;
  1059. }
  1060. }
  1061. return 1;
  1062. }
  1063. __setup("aic79xx=", aic79xx_setup);
  1064. uint32_t aic79xx_verbose;
  1065. int
  1066. ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *template)
  1067. {
  1068. char buf[80];
  1069. struct Scsi_Host *host;
  1070. char *new_name;
  1071. u_long s;
  1072. int retval;
  1073. template->name = ahd->description;
  1074. host = scsi_host_alloc(template, sizeof(struct ahd_softc *));
  1075. if (host == NULL)
  1076. return (ENOMEM);
  1077. *((struct ahd_softc **)host->hostdata) = ahd;
  1078. ahd->platform_data->host = host;
  1079. host->can_queue = AHD_MAX_QUEUE;
  1080. host->cmd_per_lun = 2;
  1081. host->sg_tablesize = AHD_NSEG;
  1082. host->this_id = ahd->our_id;
  1083. host->irq = ahd->platform_data->irq;
  1084. host->max_id = (ahd->features & AHD_WIDE) ? 16 : 8;
  1085. host->max_lun = AHD_NUM_LUNS;
  1086. host->max_channel = 0;
  1087. host->sg_tablesize = AHD_NSEG;
  1088. ahd_lock(ahd, &s);
  1089. ahd_set_unit(ahd, ahd_linux_unit++);
  1090. ahd_unlock(ahd, &s);
  1091. sprintf(buf, "scsi%d", host->host_no);
  1092. new_name = kmalloc(strlen(buf) + 1, GFP_ATOMIC);
  1093. if (new_name != NULL) {
  1094. strcpy(new_name, buf);
  1095. ahd_set_name(ahd, new_name);
  1096. }
  1097. host->unique_id = ahd->unit;
  1098. ahd_linux_initialize_scsi_bus(ahd);
  1099. ahd_intr_enable(ahd, TRUE);
  1100. host->transportt = ahd_linux_transport_template;
  1101. retval = scsi_add_host(host, &ahd->dev_softc->dev);
  1102. if (retval) {
  1103. printk(KERN_WARNING "aic79xx: scsi_add_host failed\n");
  1104. scsi_host_put(host);
  1105. return retval;
  1106. }
  1107. scsi_scan_host(host);
  1108. return 0;
  1109. }
  1110. /*
  1111. * Place the SCSI bus into a known state by either resetting it,
  1112. * or forcing transfer negotiations on the next command to any
  1113. * target.
  1114. */
  1115. static void
  1116. ahd_linux_initialize_scsi_bus(struct ahd_softc *ahd)
  1117. {
  1118. u_int target_id;
  1119. u_int numtarg;
  1120. unsigned long s;
  1121. target_id = 0;
  1122. numtarg = 0;
  1123. if (aic79xx_no_reset != 0)
  1124. ahd->flags &= ~AHD_RESET_BUS_A;
  1125. if ((ahd->flags & AHD_RESET_BUS_A) != 0)
  1126. ahd_reset_channel(ahd, 'A', /*initiate_reset*/TRUE);
  1127. else
  1128. numtarg = (ahd->features & AHD_WIDE) ? 16 : 8;
  1129. ahd_lock(ahd, &s);
  1130. /*
  1131. * Force negotiation to async for all targets that
  1132. * will not see an initial bus reset.
  1133. */
  1134. for (; target_id < numtarg; target_id++) {
  1135. struct ahd_devinfo devinfo;
  1136. struct ahd_initiator_tinfo *tinfo;
  1137. struct ahd_tmode_tstate *tstate;
  1138. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1139. target_id, &tstate);
  1140. ahd_compile_devinfo(&devinfo, ahd->our_id, target_id,
  1141. CAM_LUN_WILDCARD, 'A', ROLE_INITIATOR);
  1142. ahd_update_neg_request(ahd, &devinfo, tstate,
  1143. tinfo, AHD_NEG_ALWAYS);
  1144. }
  1145. ahd_unlock(ahd, &s);
  1146. /* Give the bus some time to recover */
  1147. if ((ahd->flags & AHD_RESET_BUS_A) != 0) {
  1148. ahd_freeze_simq(ahd);
  1149. msleep(AIC79XX_RESET_DELAY);
  1150. ahd_release_simq(ahd);
  1151. }
  1152. }
  1153. int
  1154. ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
  1155. {
  1156. ahd->platform_data =
  1157. kzalloc(sizeof(struct ahd_platform_data), GFP_ATOMIC);
  1158. if (ahd->platform_data == NULL)
  1159. return (ENOMEM);
  1160. ahd->platform_data->irq = AHD_LINUX_NOIRQ;
  1161. ahd_lockinit(ahd);
  1162. ahd->seltime = (aic79xx_seltime & 0x3) << 4;
  1163. return (0);
  1164. }
  1165. void
  1166. ahd_platform_free(struct ahd_softc *ahd)
  1167. {
  1168. struct scsi_target *starget;
  1169. int i;
  1170. if (ahd->platform_data != NULL) {
  1171. /* destroy all of the device and target objects */
  1172. for (i = 0; i < AHD_NUM_TARGETS; i++) {
  1173. starget = ahd->platform_data->starget[i];
  1174. if (starget != NULL) {
  1175. ahd->platform_data->starget[i] = NULL;
  1176. }
  1177. }
  1178. if (ahd->platform_data->irq != AHD_LINUX_NOIRQ)
  1179. free_irq(ahd->platform_data->irq, ahd);
  1180. if (ahd->tags[0] == BUS_SPACE_PIO
  1181. && ahd->bshs[0].ioport != 0)
  1182. release_region(ahd->bshs[0].ioport, 256);
  1183. if (ahd->tags[1] == BUS_SPACE_PIO
  1184. && ahd->bshs[1].ioport != 0)
  1185. release_region(ahd->bshs[1].ioport, 256);
  1186. if (ahd->tags[0] == BUS_SPACE_MEMIO
  1187. && ahd->bshs[0].maddr != NULL) {
  1188. iounmap(ahd->bshs[0].maddr);
  1189. release_mem_region(ahd->platform_data->mem_busaddr,
  1190. 0x1000);
  1191. }
  1192. if (ahd->platform_data->host)
  1193. scsi_host_put(ahd->platform_data->host);
  1194. kfree(ahd->platform_data);
  1195. }
  1196. }
  1197. void
  1198. ahd_platform_init(struct ahd_softc *ahd)
  1199. {
  1200. /*
  1201. * Lookup and commit any modified IO Cell options.
  1202. */
  1203. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  1204. const struct ahd_linux_iocell_opts *iocell_opts;
  1205. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  1206. if (iocell_opts->precomp != AIC79XX_DEFAULT_PRECOMP)
  1207. AHD_SET_PRECOMP(ahd, iocell_opts->precomp);
  1208. if (iocell_opts->slewrate != AIC79XX_DEFAULT_SLEWRATE)
  1209. AHD_SET_SLEWRATE(ahd, iocell_opts->slewrate);
  1210. if (iocell_opts->amplitude != AIC79XX_DEFAULT_AMPLITUDE)
  1211. AHD_SET_AMPLITUDE(ahd, iocell_opts->amplitude);
  1212. }
  1213. }
  1214. void
  1215. ahd_platform_freeze_devq(struct ahd_softc *ahd, struct scb *scb)
  1216. {
  1217. ahd_platform_abort_scbs(ahd, SCB_GET_TARGET(ahd, scb),
  1218. SCB_GET_CHANNEL(ahd, scb),
  1219. SCB_GET_LUN(scb), SCB_LIST_NULL,
  1220. ROLE_UNKNOWN, CAM_REQUEUE_REQ);
  1221. }
  1222. void
  1223. ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
  1224. struct ahd_devinfo *devinfo, ahd_queue_alg alg)
  1225. {
  1226. struct ahd_linux_device *dev;
  1227. int was_queuing;
  1228. int now_queuing;
  1229. if (sdev == NULL)
  1230. return;
  1231. dev = scsi_transport_device_data(sdev);
  1232. if (dev == NULL)
  1233. return;
  1234. was_queuing = dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED);
  1235. switch (alg) {
  1236. default:
  1237. case AHD_QUEUE_NONE:
  1238. now_queuing = 0;
  1239. break;
  1240. case AHD_QUEUE_BASIC:
  1241. now_queuing = AHD_DEV_Q_BASIC;
  1242. break;
  1243. case AHD_QUEUE_TAGGED:
  1244. now_queuing = AHD_DEV_Q_TAGGED;
  1245. break;
  1246. }
  1247. if ((dev->flags & AHD_DEV_FREEZE_TIL_EMPTY) == 0
  1248. && (was_queuing != now_queuing)
  1249. && (dev->active != 0)) {
  1250. dev->flags |= AHD_DEV_FREEZE_TIL_EMPTY;
  1251. dev->qfrozen++;
  1252. }
  1253. dev->flags &= ~(AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED|AHD_DEV_PERIODIC_OTAG);
  1254. if (now_queuing) {
  1255. u_int usertags;
  1256. usertags = ahd_linux_user_tagdepth(ahd, devinfo);
  1257. if (!was_queuing) {
  1258. /*
  1259. * Start out aggressively and allow our
  1260. * dynamic queue depth algorithm to take
  1261. * care of the rest.
  1262. */
  1263. dev->maxtags = usertags;
  1264. dev->openings = dev->maxtags - dev->active;
  1265. }
  1266. if (dev->maxtags == 0) {
  1267. /*
  1268. * Queueing is disabled by the user.
  1269. */
  1270. dev->openings = 1;
  1271. } else if (alg == AHD_QUEUE_TAGGED) {
  1272. dev->flags |= AHD_DEV_Q_TAGGED;
  1273. if (aic79xx_periodic_otag != 0)
  1274. dev->flags |= AHD_DEV_PERIODIC_OTAG;
  1275. } else
  1276. dev->flags |= AHD_DEV_Q_BASIC;
  1277. } else {
  1278. /* We can only have one opening. */
  1279. dev->maxtags = 0;
  1280. dev->openings = 1 - dev->active;
  1281. }
  1282. switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
  1283. case AHD_DEV_Q_BASIC:
  1284. case AHD_DEV_Q_TAGGED:
  1285. scsi_change_queue_depth(sdev,
  1286. dev->openings + dev->active);
  1287. break;
  1288. default:
  1289. /*
  1290. * We allow the OS to queue 2 untagged transactions to
  1291. * us at any time even though we can only execute them
  1292. * serially on the controller/device. This should
  1293. * remove some latency.
  1294. */
  1295. scsi_change_queue_depth(sdev, 1);
  1296. break;
  1297. }
  1298. }
  1299. int
  1300. ahd_platform_abort_scbs(struct ahd_softc *ahd, int target, char channel,
  1301. int lun, u_int tag, role_t role, uint32_t status)
  1302. {
  1303. return 0;
  1304. }
  1305. static u_int
  1306. ahd_linux_user_tagdepth(struct ahd_softc *ahd, struct ahd_devinfo *devinfo)
  1307. {
  1308. static int warned_user;
  1309. u_int tags;
  1310. tags = 0;
  1311. if ((ahd->user_discenable & devinfo->target_mask) != 0) {
  1312. if (ahd->unit >= ARRAY_SIZE(aic79xx_tag_info)) {
  1313. if (warned_user == 0) {
  1314. printk(KERN_WARNING
  1315. "aic79xx: WARNING: Insufficient tag_info instances\n"
  1316. "aic79xx: for installed controllers. Using defaults\n"
  1317. "aic79xx: Please update the aic79xx_tag_info array in\n"
  1318. "aic79xx: the aic79xx_osm.c source file.\n");
  1319. warned_user++;
  1320. }
  1321. tags = AHD_MAX_QUEUE;
  1322. } else {
  1323. adapter_tag_info_t *tag_info;
  1324. tag_info = &aic79xx_tag_info[ahd->unit];
  1325. tags = tag_info->tag_commands[devinfo->target_offset];
  1326. if (tags > AHD_MAX_QUEUE)
  1327. tags = AHD_MAX_QUEUE;
  1328. }
  1329. }
  1330. return (tags);
  1331. }
  1332. /*
  1333. * Determines the queue depth for a given device.
  1334. */
  1335. static void
  1336. ahd_linux_device_queue_depth(struct scsi_device *sdev)
  1337. {
  1338. struct ahd_devinfo devinfo;
  1339. u_int tags;
  1340. struct ahd_softc *ahd = *((struct ahd_softc **)sdev->host->hostdata);
  1341. ahd_compile_devinfo(&devinfo,
  1342. ahd->our_id,
  1343. sdev->sdev_target->id, sdev->lun,
  1344. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1345. ROLE_INITIATOR);
  1346. tags = ahd_linux_user_tagdepth(ahd, &devinfo);
  1347. if (tags != 0 && sdev->tagged_supported != 0) {
  1348. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_TAGGED);
  1349. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1350. devinfo.lun, AC_TRANSFER_NEG);
  1351. ahd_print_devinfo(ahd, &devinfo);
  1352. printk("Tagged Queuing enabled. Depth %d\n", tags);
  1353. } else {
  1354. ahd_platform_set_tags(ahd, sdev, &devinfo, AHD_QUEUE_NONE);
  1355. ahd_send_async(ahd, devinfo.channel, devinfo.target,
  1356. devinfo.lun, AC_TRANSFER_NEG);
  1357. }
  1358. }
  1359. static int
  1360. ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
  1361. struct scsi_cmnd *cmd)
  1362. {
  1363. struct scb *scb;
  1364. struct hardware_scb *hscb;
  1365. struct ahd_initiator_tinfo *tinfo;
  1366. struct ahd_tmode_tstate *tstate;
  1367. u_int col_idx;
  1368. uint16_t mask;
  1369. unsigned long flags;
  1370. int nseg;
  1371. nseg = scsi_dma_map(cmd);
  1372. if (nseg < 0)
  1373. return SCSI_MLQUEUE_HOST_BUSY;
  1374. ahd_lock(ahd, &flags);
  1375. /*
  1376. * Get an scb to use.
  1377. */
  1378. tinfo = ahd_fetch_transinfo(ahd, 'A', ahd->our_id,
  1379. cmd->device->id, &tstate);
  1380. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) == 0
  1381. || (tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
  1382. col_idx = AHD_NEVER_COL_IDX;
  1383. } else {
  1384. col_idx = AHD_BUILD_COL_IDX(cmd->device->id,
  1385. cmd->device->lun);
  1386. }
  1387. if ((scb = ahd_get_scb(ahd, col_idx)) == NULL) {
  1388. ahd->flags |= AHD_RESOURCE_SHORTAGE;
  1389. ahd_unlock(ahd, &flags);
  1390. scsi_dma_unmap(cmd);
  1391. return SCSI_MLQUEUE_HOST_BUSY;
  1392. }
  1393. scb->io_ctx = cmd;
  1394. scb->platform_data->dev = dev;
  1395. hscb = scb->hscb;
  1396. cmd->host_scribble = (char *)scb;
  1397. /*
  1398. * Fill out basics of the HSCB.
  1399. */
  1400. hscb->control = 0;
  1401. hscb->scsiid = BUILD_SCSIID(ahd, cmd);
  1402. hscb->lun = cmd->device->lun;
  1403. scb->hscb->task_management = 0;
  1404. mask = SCB_GET_TARGET_MASK(ahd, scb);
  1405. if ((ahd->user_discenable & mask) != 0)
  1406. hscb->control |= DISCENB;
  1407. if ((tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ) != 0)
  1408. scb->flags |= SCB_PACKETIZED;
  1409. if ((tstate->auto_negotiate & mask) != 0) {
  1410. scb->flags |= SCB_AUTO_NEGOTIATE;
  1411. scb->hscb->control |= MK_MESSAGE;
  1412. }
  1413. if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
  1414. if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
  1415. && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
  1416. hscb->control |= ORDERED_QUEUE_TAG;
  1417. dev->commands_since_idle_or_otag = 0;
  1418. } else {
  1419. hscb->control |= SIMPLE_QUEUE_TAG;
  1420. }
  1421. }
  1422. hscb->cdb_len = cmd->cmd_len;
  1423. memcpy(hscb->shared_data.idata.cdb, cmd->cmnd, hscb->cdb_len);
  1424. scb->platform_data->xfer_len = 0;
  1425. ahd_set_residual(scb, 0);
  1426. ahd_set_sense_residual(scb, 0);
  1427. scb->sg_count = 0;
  1428. if (nseg > 0) {
  1429. void *sg = scb->sg_list;
  1430. struct scatterlist *cur_seg;
  1431. int i;
  1432. scb->platform_data->xfer_len = 0;
  1433. scsi_for_each_sg(cmd, cur_seg, nseg, i) {
  1434. dma_addr_t addr;
  1435. bus_size_t len;
  1436. addr = sg_dma_address(cur_seg);
  1437. len = sg_dma_len(cur_seg);
  1438. scb->platform_data->xfer_len += len;
  1439. sg = ahd_sg_setup(ahd, scb, sg, addr, len,
  1440. i == (nseg - 1));
  1441. }
  1442. }
  1443. LIST_INSERT_HEAD(&ahd->pending_scbs, scb, pending_links);
  1444. dev->openings--;
  1445. dev->active++;
  1446. dev->commands_issued++;
  1447. if ((dev->flags & AHD_DEV_PERIODIC_OTAG) != 0)
  1448. dev->commands_since_idle_or_otag++;
  1449. scb->flags |= SCB_ACTIVE;
  1450. ahd_queue_scb(ahd, scb);
  1451. ahd_unlock(ahd, &flags);
  1452. return 0;
  1453. }
  1454. /*
  1455. * SCSI controller interrupt handler.
  1456. */
  1457. irqreturn_t
  1458. ahd_linux_isr(int irq, void *dev_id)
  1459. {
  1460. struct ahd_softc *ahd;
  1461. u_long flags;
  1462. int ours;
  1463. ahd = (struct ahd_softc *) dev_id;
  1464. ahd_lock(ahd, &flags);
  1465. ours = ahd_intr(ahd);
  1466. ahd_unlock(ahd, &flags);
  1467. return IRQ_RETVAL(ours);
  1468. }
  1469. void
  1470. ahd_send_async(struct ahd_softc *ahd, char channel,
  1471. u_int target, u_int lun, ac_code code)
  1472. {
  1473. switch (code) {
  1474. case AC_TRANSFER_NEG:
  1475. {
  1476. struct scsi_target *starget;
  1477. struct ahd_initiator_tinfo *tinfo;
  1478. struct ahd_tmode_tstate *tstate;
  1479. unsigned int target_ppr_options;
  1480. BUG_ON(target == CAM_TARGET_WILDCARD);
  1481. tinfo = ahd_fetch_transinfo(ahd, channel, ahd->our_id,
  1482. target, &tstate);
  1483. /*
  1484. * Don't bother reporting results while
  1485. * negotiations are still pending.
  1486. */
  1487. if (tinfo->curr.period != tinfo->goal.period
  1488. || tinfo->curr.width != tinfo->goal.width
  1489. || tinfo->curr.offset != tinfo->goal.offset
  1490. || tinfo->curr.ppr_options != tinfo->goal.ppr_options)
  1491. if (bootverbose == 0)
  1492. break;
  1493. /*
  1494. * Don't bother reporting results that
  1495. * are identical to those last reported.
  1496. */
  1497. starget = ahd->platform_data->starget[target];
  1498. if (starget == NULL)
  1499. break;
  1500. target_ppr_options =
  1501. (spi_dt(starget) ? MSG_EXT_PPR_DT_REQ : 0)
  1502. + (spi_qas(starget) ? MSG_EXT_PPR_QAS_REQ : 0)
  1503. + (spi_iu(starget) ? MSG_EXT_PPR_IU_REQ : 0)
  1504. + (spi_rd_strm(starget) ? MSG_EXT_PPR_RD_STRM : 0)
  1505. + (spi_pcomp_en(starget) ? MSG_EXT_PPR_PCOMP_EN : 0)
  1506. + (spi_rti(starget) ? MSG_EXT_PPR_RTI : 0)
  1507. + (spi_wr_flow(starget) ? MSG_EXT_PPR_WR_FLOW : 0)
  1508. + (spi_hold_mcs(starget) ? MSG_EXT_PPR_HOLD_MCS : 0);
  1509. if (tinfo->curr.period == spi_period(starget)
  1510. && tinfo->curr.width == spi_width(starget)
  1511. && tinfo->curr.offset == spi_offset(starget)
  1512. && tinfo->curr.ppr_options == target_ppr_options)
  1513. if (bootverbose == 0)
  1514. break;
  1515. spi_period(starget) = tinfo->curr.period;
  1516. spi_width(starget) = tinfo->curr.width;
  1517. spi_offset(starget) = tinfo->curr.offset;
  1518. spi_dt(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_DT_REQ ? 1 : 0;
  1519. spi_qas(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_QAS_REQ ? 1 : 0;
  1520. spi_iu(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_IU_REQ ? 1 : 0;
  1521. spi_rd_strm(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RD_STRM ? 1 : 0;
  1522. spi_pcomp_en(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_PCOMP_EN ? 1 : 0;
  1523. spi_rti(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_RTI ? 1 : 0;
  1524. spi_wr_flow(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_WR_FLOW ? 1 : 0;
  1525. spi_hold_mcs(starget) = tinfo->curr.ppr_options & MSG_EXT_PPR_HOLD_MCS ? 1 : 0;
  1526. spi_display_xfer_agreement(starget);
  1527. break;
  1528. }
  1529. case AC_SENT_BDR:
  1530. {
  1531. WARN_ON(lun != CAM_LUN_WILDCARD);
  1532. scsi_report_device_reset(ahd->platform_data->host,
  1533. channel - 'A', target);
  1534. break;
  1535. }
  1536. case AC_BUS_RESET:
  1537. if (ahd->platform_data->host != NULL) {
  1538. scsi_report_bus_reset(ahd->platform_data->host,
  1539. channel - 'A');
  1540. }
  1541. break;
  1542. default:
  1543. panic("ahd_send_async: Unexpected async event");
  1544. }
  1545. }
  1546. /*
  1547. * Calls the higher level scsi done function and frees the scb.
  1548. */
  1549. void
  1550. ahd_done(struct ahd_softc *ahd, struct scb *scb)
  1551. {
  1552. struct scsi_cmnd *cmd;
  1553. struct ahd_linux_device *dev;
  1554. if ((scb->flags & SCB_ACTIVE) == 0) {
  1555. printk("SCB %d done'd twice\n", SCB_GET_TAG(scb));
  1556. ahd_dump_card_state(ahd);
  1557. panic("Stopping for safety");
  1558. }
  1559. LIST_REMOVE(scb, pending_links);
  1560. cmd = scb->io_ctx;
  1561. dev = scb->platform_data->dev;
  1562. dev->active--;
  1563. dev->openings++;
  1564. if ((cmd->result & (CAM_DEV_QFRZN << 16)) != 0) {
  1565. cmd->result &= ~(CAM_DEV_QFRZN << 16);
  1566. dev->qfrozen--;
  1567. }
  1568. ahd_linux_unmap_scb(ahd, scb);
  1569. /*
  1570. * Guard against stale sense data.
  1571. * The Linux mid-layer assumes that sense
  1572. * was retrieved anytime the first byte of
  1573. * the sense buffer looks "sane".
  1574. */
  1575. cmd->sense_buffer[0] = 0;
  1576. if (ahd_get_transaction_status(scb) == CAM_REQ_INPROG) {
  1577. #ifdef AHD_REPORT_UNDERFLOWS
  1578. uint32_t amount_xferred;
  1579. amount_xferred =
  1580. ahd_get_transfer_length(scb) - ahd_get_residual(scb);
  1581. #endif
  1582. if ((scb->flags & SCB_TRANSMISSION_ERROR) != 0) {
  1583. #ifdef AHD_DEBUG
  1584. if ((ahd_debug & AHD_SHOW_MISC) != 0) {
  1585. ahd_print_path(ahd, scb);
  1586. printk("Set CAM_UNCOR_PARITY\n");
  1587. }
  1588. #endif
  1589. ahd_set_transaction_status(scb, CAM_UNCOR_PARITY);
  1590. #ifdef AHD_REPORT_UNDERFLOWS
  1591. /*
  1592. * This code is disabled by default as some
  1593. * clients of the SCSI system do not properly
  1594. * initialize the underflow parameter. This
  1595. * results in spurious termination of commands
  1596. * that complete as expected (e.g. underflow is
  1597. * allowed as command can return variable amounts
  1598. * of data.
  1599. */
  1600. } else if (amount_xferred < scb->io_ctx->underflow) {
  1601. u_int i;
  1602. ahd_print_path(ahd, scb);
  1603. printk("CDB:");
  1604. for (i = 0; i < scb->io_ctx->cmd_len; i++)
  1605. printk(" 0x%x", scb->io_ctx->cmnd[i]);
  1606. printk("\n");
  1607. ahd_print_path(ahd, scb);
  1608. printk("Saw underflow (%ld of %ld bytes). "
  1609. "Treated as error\n",
  1610. ahd_get_residual(scb),
  1611. ahd_get_transfer_length(scb));
  1612. ahd_set_transaction_status(scb, CAM_DATA_RUN_ERR);
  1613. #endif
  1614. } else {
  1615. ahd_set_transaction_status(scb, CAM_REQ_CMP);
  1616. }
  1617. } else if (ahd_get_transaction_status(scb) == CAM_SCSI_STATUS_ERROR) {
  1618. ahd_linux_handle_scsi_status(ahd, cmd->device, scb);
  1619. }
  1620. if (dev->openings == 1
  1621. && ahd_get_transaction_status(scb) == CAM_REQ_CMP
  1622. && ahd_get_scsi_status(scb) != SAM_STAT_TASK_SET_FULL)
  1623. dev->tag_success_count++;
  1624. /*
  1625. * Some devices deal with temporary internal resource
  1626. * shortages by returning queue full. When the queue
  1627. * full occurrs, we throttle back. Slowly try to get
  1628. * back to our previous queue depth.
  1629. */
  1630. if ((dev->openings + dev->active) < dev->maxtags
  1631. && dev->tag_success_count > AHD_TAG_SUCCESS_INTERVAL) {
  1632. dev->tag_success_count = 0;
  1633. dev->openings++;
  1634. }
  1635. if (dev->active == 0)
  1636. dev->commands_since_idle_or_otag = 0;
  1637. if ((scb->flags & SCB_RECOVERY_SCB) != 0) {
  1638. printk("Recovery SCB completes\n");
  1639. if (ahd_get_transaction_status(scb) == CAM_BDR_SENT
  1640. || ahd_get_transaction_status(scb) == CAM_REQ_ABORTED)
  1641. ahd_set_transaction_status(scb, CAM_CMD_TIMEOUT);
  1642. if (ahd->platform_data->eh_done)
  1643. complete(ahd->platform_data->eh_done);
  1644. }
  1645. ahd_free_scb(ahd, scb);
  1646. ahd_linux_queue_cmd_complete(ahd, cmd);
  1647. }
  1648. static void
  1649. ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
  1650. struct scsi_device *sdev, struct scb *scb)
  1651. {
  1652. struct ahd_devinfo devinfo;
  1653. struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
  1654. ahd_compile_devinfo(&devinfo,
  1655. ahd->our_id,
  1656. sdev->sdev_target->id, sdev->lun,
  1657. sdev->sdev_target->channel == 0 ? 'A' : 'B',
  1658. ROLE_INITIATOR);
  1659. /*
  1660. * We don't currently trust the mid-layer to
  1661. * properly deal with queue full or busy. So,
  1662. * when one occurs, we tell the mid-layer to
  1663. * unconditionally requeue the command to us
  1664. * so that we can retry it ourselves. We also
  1665. * implement our own throttling mechanism so
  1666. * we don't clobber the device with too many
  1667. * commands.
  1668. */
  1669. switch (ahd_get_scsi_status(scb)) {
  1670. default:
  1671. break;
  1672. case SAM_STAT_CHECK_CONDITION:
  1673. case SAM_STAT_COMMAND_TERMINATED:
  1674. {
  1675. struct scsi_cmnd *cmd;
  1676. /*
  1677. * Copy sense information to the OS's cmd
  1678. * structure if it is available.
  1679. */
  1680. cmd = scb->io_ctx;
  1681. if ((scb->flags & (SCB_SENSE|SCB_PKT_SENSE)) != 0) {
  1682. struct scsi_status_iu_header *siu;
  1683. u_int sense_size;
  1684. u_int sense_offset;
  1685. if (scb->flags & SCB_SENSE) {
  1686. sense_size = min(sizeof(struct scsi_sense_data)
  1687. - ahd_get_sense_residual(scb),
  1688. (u_long)SCSI_SENSE_BUFFERSIZE);
  1689. sense_offset = 0;
  1690. } else {
  1691. /*
  1692. * Copy only the sense data into the provided
  1693. * buffer.
  1694. */
  1695. siu = (struct scsi_status_iu_header *)
  1696. scb->sense_data;
  1697. sense_size = min_t(size_t,
  1698. scsi_4btoul(siu->sense_length),
  1699. SCSI_SENSE_BUFFERSIZE);
  1700. sense_offset = SIU_SENSE_OFFSET(siu);
  1701. }
  1702. memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  1703. memcpy(cmd->sense_buffer,
  1704. ahd_get_sense_buf(ahd, scb)
  1705. + sense_offset, sense_size);
  1706. set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
  1707. #ifdef AHD_DEBUG
  1708. if (ahd_debug & AHD_SHOW_SENSE) {
  1709. int i;
  1710. printk("Copied %d bytes of sense data at %d:",
  1711. sense_size, sense_offset);
  1712. for (i = 0; i < sense_size; i++) {
  1713. if ((i & 0xF) == 0)
  1714. printk("\n");
  1715. printk("0x%x ", cmd->sense_buffer[i]);
  1716. }
  1717. printk("\n");
  1718. }
  1719. #endif
  1720. }
  1721. break;
  1722. }
  1723. case SAM_STAT_TASK_SET_FULL:
  1724. /*
  1725. * By the time the core driver has returned this
  1726. * command, all other commands that were queued
  1727. * to us but not the device have been returned.
  1728. * This ensures that dev->active is equal to
  1729. * the number of commands actually queued to
  1730. * the device.
  1731. */
  1732. dev->tag_success_count = 0;
  1733. if (dev->active != 0) {
  1734. /*
  1735. * Drop our opening count to the number
  1736. * of commands currently outstanding.
  1737. */
  1738. dev->openings = 0;
  1739. #ifdef AHD_DEBUG
  1740. if ((ahd_debug & AHD_SHOW_QFULL) != 0) {
  1741. ahd_print_path(ahd, scb);
  1742. printk("Dropping tag count to %d\n",
  1743. dev->active);
  1744. }
  1745. #endif
  1746. if (dev->active == dev->tags_on_last_queuefull) {
  1747. dev->last_queuefull_same_count++;
  1748. /*
  1749. * If we repeatedly see a queue full
  1750. * at the same queue depth, this
  1751. * device has a fixed number of tag
  1752. * slots. Lock in this tag depth
  1753. * so we stop seeing queue fulls from
  1754. * this device.
  1755. */
  1756. if (dev->last_queuefull_same_count
  1757. == AHD_LOCK_TAGS_COUNT) {
  1758. dev->maxtags = dev->active;
  1759. ahd_print_path(ahd, scb);
  1760. printk("Locking max tag count at %d\n",
  1761. dev->active);
  1762. }
  1763. } else {
  1764. dev->tags_on_last_queuefull = dev->active;
  1765. dev->last_queuefull_same_count = 0;
  1766. }
  1767. ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
  1768. ahd_set_scsi_status(scb, SAM_STAT_GOOD);
  1769. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1770. (dev->flags & AHD_DEV_Q_BASIC)
  1771. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1772. break;
  1773. }
  1774. /*
  1775. * Drop down to a single opening, and treat this
  1776. * as if the target returned BUSY SCSI status.
  1777. */
  1778. dev->openings = 1;
  1779. ahd_platform_set_tags(ahd, sdev, &devinfo,
  1780. (dev->flags & AHD_DEV_Q_BASIC)
  1781. ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
  1782. ahd_set_scsi_status(scb, SAM_STAT_BUSY);
  1783. }
  1784. }
  1785. static void
  1786. ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
  1787. {
  1788. int status;
  1789. int new_status = DID_OK;
  1790. int do_fallback = 0;
  1791. int scsi_status;
  1792. struct scsi_sense_data *sense;
  1793. /*
  1794. * Map CAM error codes into Linux Error codes. We
  1795. * avoid the conversion so that the DV code has the
  1796. * full error information available when making
  1797. * state change decisions.
  1798. */
  1799. status = ahd_cmd_get_transaction_status(cmd);
  1800. switch (status) {
  1801. case CAM_REQ_INPROG:
  1802. case CAM_REQ_CMP:
  1803. new_status = DID_OK;
  1804. break;
  1805. case CAM_AUTOSENSE_FAIL:
  1806. new_status = DID_ERROR;
  1807. fallthrough;
  1808. case CAM_SCSI_STATUS_ERROR:
  1809. scsi_status = ahd_cmd_get_scsi_status(cmd);
  1810. switch(scsi_status) {
  1811. case SAM_STAT_COMMAND_TERMINATED:
  1812. case SAM_STAT_CHECK_CONDITION:
  1813. sense = (struct scsi_sense_data *)
  1814. cmd->sense_buffer;
  1815. if (sense->extra_len >= 5 &&
  1816. (sense->add_sense_code == 0x47
  1817. || sense->add_sense_code == 0x48))
  1818. do_fallback = 1;
  1819. break;
  1820. default:
  1821. break;
  1822. }
  1823. break;
  1824. case CAM_REQ_ABORTED:
  1825. new_status = DID_ABORT;
  1826. break;
  1827. case CAM_BUSY:
  1828. new_status = DID_BUS_BUSY;
  1829. break;
  1830. case CAM_REQ_INVALID:
  1831. case CAM_PATH_INVALID:
  1832. new_status = DID_BAD_TARGET;
  1833. break;
  1834. case CAM_SEL_TIMEOUT:
  1835. new_status = DID_NO_CONNECT;
  1836. break;
  1837. case CAM_SCSI_BUS_RESET:
  1838. case CAM_BDR_SENT:
  1839. new_status = DID_RESET;
  1840. break;
  1841. case CAM_UNCOR_PARITY:
  1842. new_status = DID_PARITY;
  1843. do_fallback = 1;
  1844. break;
  1845. case CAM_CMD_TIMEOUT:
  1846. new_status = DID_TIME_OUT;
  1847. do_fallback = 1;
  1848. break;
  1849. case CAM_REQ_CMP_ERR:
  1850. case CAM_UNEXP_BUSFREE:
  1851. case CAM_DATA_RUN_ERR:
  1852. new_status = DID_ERROR;
  1853. do_fallback = 1;
  1854. break;
  1855. case CAM_UA_ABORT:
  1856. case CAM_NO_HBA:
  1857. case CAM_SEQUENCE_FAIL:
  1858. case CAM_CCB_LEN_ERR:
  1859. case CAM_PROVIDE_FAIL:
  1860. case CAM_REQ_TERMIO:
  1861. case CAM_UNREC_HBA_ERROR:
  1862. case CAM_REQ_TOO_BIG:
  1863. new_status = DID_ERROR;
  1864. break;
  1865. case CAM_REQUEUE_REQ:
  1866. new_status = DID_REQUEUE;
  1867. break;
  1868. default:
  1869. /* We should never get here */
  1870. new_status = DID_ERROR;
  1871. break;
  1872. }
  1873. if (do_fallback) {
  1874. printk("%s: device overrun (status %x) on %d:%d:%d\n",
  1875. ahd_name(ahd), status, cmd->device->channel,
  1876. cmd->device->id, (u8)cmd->device->lun);
  1877. }
  1878. ahd_cmd_set_transaction_status(cmd, new_status);
  1879. scsi_done(cmd);
  1880. }
  1881. static void
  1882. ahd_freeze_simq(struct ahd_softc *ahd)
  1883. {
  1884. scsi_block_requests(ahd->platform_data->host);
  1885. }
  1886. static void
  1887. ahd_release_simq(struct ahd_softc *ahd)
  1888. {
  1889. scsi_unblock_requests(ahd->platform_data->host);
  1890. }
  1891. static int
  1892. ahd_linux_queue_abort_cmd(struct scsi_cmnd *cmd)
  1893. {
  1894. struct ahd_softc *ahd;
  1895. struct ahd_linux_device *dev;
  1896. struct scb *pending_scb;
  1897. u_int saved_scbptr;
  1898. u_int active_scbptr;
  1899. u_int last_phase;
  1900. u_int cdb_byte;
  1901. int retval = SUCCESS;
  1902. int was_paused;
  1903. int paused;
  1904. int wait;
  1905. int disconnected;
  1906. ahd_mode_state saved_modes;
  1907. unsigned long flags;
  1908. pending_scb = NULL;
  1909. paused = FALSE;
  1910. wait = FALSE;
  1911. ahd = *(struct ahd_softc **)cmd->device->host->hostdata;
  1912. scmd_printk(KERN_INFO, cmd,
  1913. "Attempting to queue an ABORT message:");
  1914. printk("CDB:");
  1915. for (cdb_byte = 0; cdb_byte < cmd->cmd_len; cdb_byte++)
  1916. printk(" 0x%x", cmd->cmnd[cdb_byte]);
  1917. printk("\n");
  1918. ahd_lock(ahd, &flags);
  1919. /*
  1920. * First determine if we currently own this command.
  1921. * Start by searching the device queue. If not found
  1922. * there, check the pending_scb list. If not found
  1923. * at all, and the system wanted us to just abort the
  1924. * command, return success.
  1925. */
  1926. dev = scsi_transport_device_data(cmd->device);
  1927. if (dev == NULL) {
  1928. /*
  1929. * No target device for this command exists,
  1930. * so we must not still own the command.
  1931. */
  1932. scmd_printk(KERN_INFO, cmd, "Is not an active device\n");
  1933. goto done;
  1934. }
  1935. /*
  1936. * See if we can find a matching cmd in the pending list.
  1937. */
  1938. LIST_FOREACH(pending_scb, &ahd->pending_scbs, pending_links) {
  1939. if (pending_scb->io_ctx == cmd)
  1940. break;
  1941. }
  1942. if (pending_scb == NULL) {
  1943. scmd_printk(KERN_INFO, cmd, "Command not found\n");
  1944. goto done;
  1945. }
  1946. if ((pending_scb->flags & SCB_RECOVERY_SCB) != 0) {
  1947. /*
  1948. * We can't queue two recovery actions using the same SCB
  1949. */
  1950. retval = FAILED;
  1951. goto done;
  1952. }
  1953. /*
  1954. * Ensure that the card doesn't do anything
  1955. * behind our back. Also make sure that we
  1956. * didn't "just" miss an interrupt that would
  1957. * affect this cmd.
  1958. */
  1959. was_paused = ahd_is_paused(ahd);
  1960. ahd_pause_and_flushwork(ahd);
  1961. paused = TRUE;
  1962. if ((pending_scb->flags & SCB_ACTIVE) == 0) {
  1963. scmd_printk(KERN_INFO, cmd, "Command already completed\n");
  1964. goto done;
  1965. }
  1966. printk("%s: At time of recovery, card was %spaused\n",
  1967. ahd_name(ahd), was_paused ? "" : "not ");
  1968. ahd_dump_card_state(ahd);
  1969. disconnected = TRUE;
  1970. if (ahd_search_qinfifo(ahd, cmd->device->id,
  1971. cmd->device->channel + 'A',
  1972. cmd->device->lun,
  1973. pending_scb->hscb->tag,
  1974. ROLE_INITIATOR, CAM_REQ_ABORTED,
  1975. SEARCH_COMPLETE) > 0) {
  1976. printk("%s:%d:%d:%d: Cmd aborted from QINFIFO\n",
  1977. ahd_name(ahd), cmd->device->channel,
  1978. cmd->device->id, (u8)cmd->device->lun);
  1979. goto done;
  1980. }
  1981. saved_modes = ahd_save_modes(ahd);
  1982. ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
  1983. last_phase = ahd_inb(ahd, LASTPHASE);
  1984. saved_scbptr = ahd_get_scbptr(ahd);
  1985. active_scbptr = saved_scbptr;
  1986. if (disconnected && (ahd_inb(ahd, SEQ_FLAGS) & NOT_IDENTIFIED) == 0) {
  1987. struct scb *bus_scb;
  1988. bus_scb = ahd_lookup_scb(ahd, active_scbptr);
  1989. if (bus_scb == pending_scb)
  1990. disconnected = FALSE;
  1991. }
  1992. /*
  1993. * At this point, pending_scb is the scb associated with the
  1994. * passed in command. That command is currently active on the
  1995. * bus or is in the disconnected state.
  1996. */
  1997. ahd_inb(ahd, SAVED_SCSIID);
  1998. if (last_phase != P_BUSFREE
  1999. && SCB_GET_TAG(pending_scb) == active_scbptr) {
  2000. /*
  2001. * We're active on the bus, so assert ATN
  2002. * and hope that the target responds.
  2003. */
  2004. pending_scb = ahd_lookup_scb(ahd, active_scbptr);
  2005. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2006. ahd_outb(ahd, MSG_OUT, HOST_MSG);
  2007. ahd_outb(ahd, SCSISIGO, last_phase|ATNO);
  2008. scmd_printk(KERN_INFO, cmd, "Device is active, asserting ATN\n");
  2009. wait = TRUE;
  2010. } else if (disconnected) {
  2011. /*
  2012. * Actually re-queue this SCB in an attempt
  2013. * to select the device before it reconnects.
  2014. */
  2015. pending_scb->flags |= SCB_RECOVERY_SCB|SCB_ABORT;
  2016. ahd_set_scbptr(ahd, SCB_GET_TAG(pending_scb));
  2017. pending_scb->hscb->cdb_len = 0;
  2018. pending_scb->hscb->task_attribute = 0;
  2019. pending_scb->hscb->task_management = SIU_TASKMGMT_ABORT_TASK;
  2020. if ((pending_scb->flags & SCB_PACKETIZED) != 0) {
  2021. /*
  2022. * Mark the SCB has having an outstanding
  2023. * task management function. Should the command
  2024. * complete normally before the task management
  2025. * function can be sent, the host will be notified
  2026. * to abort our requeued SCB.
  2027. */
  2028. ahd_outb(ahd, SCB_TASK_MANAGEMENT,
  2029. pending_scb->hscb->task_management);
  2030. } else {
  2031. /*
  2032. * If non-packetized, set the MK_MESSAGE control
  2033. * bit indicating that we desire to send a message.
  2034. * We also set the disconnected flag since there is
  2035. * no guarantee that our SCB control byte matches
  2036. * the version on the card. We don't want the
  2037. * sequencer to abort the command thinking an
  2038. * unsolicited reselection occurred.
  2039. */
  2040. pending_scb->hscb->control |= MK_MESSAGE|DISCONNECTED;
  2041. /*
  2042. * The sequencer will never re-reference the
  2043. * in-core SCB. To make sure we are notified
  2044. * during reselection, set the MK_MESSAGE flag in
  2045. * the card's copy of the SCB.
  2046. */
  2047. ahd_outb(ahd, SCB_CONTROL,
  2048. ahd_inb(ahd, SCB_CONTROL)|MK_MESSAGE);
  2049. }
  2050. /*
  2051. * Clear out any entries in the QINFIFO first
  2052. * so we are the next SCB for this target
  2053. * to run.
  2054. */
  2055. ahd_search_qinfifo(ahd, cmd->device->id,
  2056. cmd->device->channel + 'A', cmd->device->lun,
  2057. SCB_LIST_NULL, ROLE_INITIATOR,
  2058. CAM_REQUEUE_REQ, SEARCH_COMPLETE);
  2059. ahd_qinfifo_requeue_tail(ahd, pending_scb);
  2060. ahd_set_scbptr(ahd, saved_scbptr);
  2061. ahd_print_path(ahd, pending_scb);
  2062. printk("Device is disconnected, re-queuing SCB\n");
  2063. wait = TRUE;
  2064. } else {
  2065. scmd_printk(KERN_INFO, cmd, "Unable to deliver message\n");
  2066. retval = FAILED;
  2067. }
  2068. ahd_restore_modes(ahd, saved_modes);
  2069. done:
  2070. if (paused)
  2071. ahd_unpause(ahd);
  2072. if (wait) {
  2073. DECLARE_COMPLETION_ONSTACK(done);
  2074. ahd->platform_data->eh_done = &done;
  2075. ahd_unlock(ahd, &flags);
  2076. printk("%s: Recovery code sleeping\n", ahd_name(ahd));
  2077. if (!wait_for_completion_timeout(&done, 5 * HZ)) {
  2078. ahd_lock(ahd, &flags);
  2079. ahd->platform_data->eh_done = NULL;
  2080. ahd_unlock(ahd, &flags);
  2081. printk("%s: Timer Expired (active %d)\n",
  2082. ahd_name(ahd), dev->active);
  2083. retval = FAILED;
  2084. }
  2085. printk("Recovery code awake\n");
  2086. } else
  2087. ahd_unlock(ahd, &flags);
  2088. if (retval != SUCCESS)
  2089. printk("%s: Command abort returning 0x%x\n",
  2090. ahd_name(ahd), retval);
  2091. return retval;
  2092. }
  2093. static void ahd_linux_set_width(struct scsi_target *starget, int width)
  2094. {
  2095. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2096. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2097. struct ahd_devinfo devinfo;
  2098. unsigned long flags;
  2099. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2100. starget->channel + 'A', ROLE_INITIATOR);
  2101. ahd_lock(ahd, &flags);
  2102. ahd_set_width(ahd, &devinfo, width, AHD_TRANS_GOAL, FALSE);
  2103. ahd_unlock(ahd, &flags);
  2104. }
  2105. static void ahd_linux_set_period(struct scsi_target *starget, int period)
  2106. {
  2107. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2108. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2109. struct ahd_tmode_tstate *tstate;
  2110. struct ahd_initiator_tinfo *tinfo
  2111. = ahd_fetch_transinfo(ahd,
  2112. starget->channel + 'A',
  2113. shost->this_id, starget->id, &tstate);
  2114. struct ahd_devinfo devinfo;
  2115. unsigned int ppr_options = tinfo->goal.ppr_options;
  2116. unsigned int dt;
  2117. unsigned long flags;
  2118. unsigned long offset = tinfo->goal.offset;
  2119. #ifdef AHD_DEBUG
  2120. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2121. printk("%s: set period to %d\n", ahd_name(ahd), period);
  2122. #endif
  2123. if (offset == 0)
  2124. offset = MAX_OFFSET;
  2125. if (period < 8)
  2126. period = 8;
  2127. if (period < 10) {
  2128. if (spi_max_width(starget)) {
  2129. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2130. if (period == 8)
  2131. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2132. } else
  2133. period = 10;
  2134. }
  2135. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2136. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2137. starget->channel + 'A', ROLE_INITIATOR);
  2138. /* all PPR requests apart from QAS require wide transfers */
  2139. if (ppr_options & ~MSG_EXT_PPR_QAS_REQ) {
  2140. if (spi_width(starget) == 0)
  2141. ppr_options &= MSG_EXT_PPR_QAS_REQ;
  2142. }
  2143. ahd_find_syncrate(ahd, &period, &ppr_options,
  2144. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2145. ahd_lock(ahd, &flags);
  2146. ahd_set_syncrate(ahd, &devinfo, period, offset,
  2147. ppr_options, AHD_TRANS_GOAL, FALSE);
  2148. ahd_unlock(ahd, &flags);
  2149. }
  2150. static void ahd_linux_set_offset(struct scsi_target *starget, int offset)
  2151. {
  2152. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2153. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2154. struct ahd_tmode_tstate *tstate;
  2155. struct ahd_initiator_tinfo *tinfo
  2156. = ahd_fetch_transinfo(ahd,
  2157. starget->channel + 'A',
  2158. shost->this_id, starget->id, &tstate);
  2159. struct ahd_devinfo devinfo;
  2160. unsigned int ppr_options = 0;
  2161. unsigned int period = 0;
  2162. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2163. unsigned long flags;
  2164. #ifdef AHD_DEBUG
  2165. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2166. printk("%s: set offset to %d\n", ahd_name(ahd), offset);
  2167. #endif
  2168. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2169. starget->channel + 'A', ROLE_INITIATOR);
  2170. if (offset != 0) {
  2171. period = tinfo->goal.period;
  2172. ppr_options = tinfo->goal.ppr_options;
  2173. ahd_find_syncrate(ahd, &period, &ppr_options,
  2174. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2175. }
  2176. ahd_lock(ahd, &flags);
  2177. ahd_set_syncrate(ahd, &devinfo, period, offset, ppr_options,
  2178. AHD_TRANS_GOAL, FALSE);
  2179. ahd_unlock(ahd, &flags);
  2180. }
  2181. static void ahd_linux_set_dt(struct scsi_target *starget, int dt)
  2182. {
  2183. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2184. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2185. struct ahd_tmode_tstate *tstate;
  2186. struct ahd_initiator_tinfo *tinfo
  2187. = ahd_fetch_transinfo(ahd,
  2188. starget->channel + 'A',
  2189. shost->this_id, starget->id, &tstate);
  2190. struct ahd_devinfo devinfo;
  2191. unsigned int ppr_options = tinfo->goal.ppr_options
  2192. & ~MSG_EXT_PPR_DT_REQ;
  2193. unsigned int period = tinfo->goal.period;
  2194. unsigned int width = tinfo->goal.width;
  2195. unsigned long flags;
  2196. #ifdef AHD_DEBUG
  2197. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2198. printk("%s: %s DT\n", ahd_name(ahd),
  2199. dt ? "enabling" : "disabling");
  2200. #endif
  2201. if (dt && spi_max_width(starget)) {
  2202. ppr_options |= MSG_EXT_PPR_DT_REQ;
  2203. if (!width)
  2204. ahd_linux_set_width(starget, 1);
  2205. } else {
  2206. if (period <= 9)
  2207. period = 10; /* If resetting DT, period must be >= 25ns */
  2208. /* IU is invalid without DT set */
  2209. ppr_options &= ~MSG_EXT_PPR_IU_REQ;
  2210. }
  2211. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2212. starget->channel + 'A', ROLE_INITIATOR);
  2213. ahd_find_syncrate(ahd, &period, &ppr_options,
  2214. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2215. ahd_lock(ahd, &flags);
  2216. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2217. ppr_options, AHD_TRANS_GOAL, FALSE);
  2218. ahd_unlock(ahd, &flags);
  2219. }
  2220. static void ahd_linux_set_qas(struct scsi_target *starget, int qas)
  2221. {
  2222. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2223. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2224. struct ahd_tmode_tstate *tstate;
  2225. struct ahd_initiator_tinfo *tinfo
  2226. = ahd_fetch_transinfo(ahd,
  2227. starget->channel + 'A',
  2228. shost->this_id, starget->id, &tstate);
  2229. struct ahd_devinfo devinfo;
  2230. unsigned int ppr_options = tinfo->goal.ppr_options
  2231. & ~MSG_EXT_PPR_QAS_REQ;
  2232. unsigned int period = tinfo->goal.period;
  2233. unsigned int dt;
  2234. unsigned long flags;
  2235. #ifdef AHD_DEBUG
  2236. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2237. printk("%s: %s QAS\n", ahd_name(ahd),
  2238. qas ? "enabling" : "disabling");
  2239. #endif
  2240. if (qas) {
  2241. ppr_options |= MSG_EXT_PPR_QAS_REQ;
  2242. }
  2243. dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2244. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2245. starget->channel + 'A', ROLE_INITIATOR);
  2246. ahd_find_syncrate(ahd, &period, &ppr_options,
  2247. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2248. ahd_lock(ahd, &flags);
  2249. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2250. ppr_options, AHD_TRANS_GOAL, FALSE);
  2251. ahd_unlock(ahd, &flags);
  2252. }
  2253. static void ahd_linux_set_iu(struct scsi_target *starget, int iu)
  2254. {
  2255. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2256. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2257. struct ahd_tmode_tstate *tstate;
  2258. struct ahd_initiator_tinfo *tinfo
  2259. = ahd_fetch_transinfo(ahd,
  2260. starget->channel + 'A',
  2261. shost->this_id, starget->id, &tstate);
  2262. struct ahd_devinfo devinfo;
  2263. unsigned int ppr_options = tinfo->goal.ppr_options
  2264. & ~MSG_EXT_PPR_IU_REQ;
  2265. unsigned int period = tinfo->goal.period;
  2266. unsigned int dt;
  2267. unsigned long flags;
  2268. #ifdef AHD_DEBUG
  2269. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2270. printk("%s: %s IU\n", ahd_name(ahd),
  2271. iu ? "enabling" : "disabling");
  2272. #endif
  2273. if (iu && spi_max_width(starget)) {
  2274. ppr_options |= MSG_EXT_PPR_IU_REQ;
  2275. ppr_options |= MSG_EXT_PPR_DT_REQ; /* IU requires DT */
  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_rd_strm(struct scsi_target *starget, int rdstrm)
  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_RD_STRM;
  2299. unsigned int period = tinfo->goal.period;
  2300. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2301. unsigned long flags;
  2302. #ifdef AHD_DEBUG
  2303. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2304. printk("%s: %s Read Streaming\n", ahd_name(ahd),
  2305. rdstrm ? "enabling" : "disabling");
  2306. #endif
  2307. if (rdstrm && spi_max_width(starget))
  2308. ppr_options |= MSG_EXT_PPR_RD_STRM;
  2309. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2310. starget->channel + 'A', ROLE_INITIATOR);
  2311. ahd_find_syncrate(ahd, &period, &ppr_options,
  2312. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2313. ahd_lock(ahd, &flags);
  2314. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2315. ppr_options, AHD_TRANS_GOAL, FALSE);
  2316. ahd_unlock(ahd, &flags);
  2317. }
  2318. static void ahd_linux_set_wr_flow(struct scsi_target *starget, int wrflow)
  2319. {
  2320. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2321. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2322. struct ahd_tmode_tstate *tstate;
  2323. struct ahd_initiator_tinfo *tinfo
  2324. = ahd_fetch_transinfo(ahd,
  2325. starget->channel + 'A',
  2326. shost->this_id, starget->id, &tstate);
  2327. struct ahd_devinfo devinfo;
  2328. unsigned int ppr_options = tinfo->goal.ppr_options
  2329. & ~MSG_EXT_PPR_WR_FLOW;
  2330. unsigned int period = tinfo->goal.period;
  2331. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2332. unsigned long flags;
  2333. #ifdef AHD_DEBUG
  2334. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2335. printk("%s: %s Write Flow Control\n", ahd_name(ahd),
  2336. wrflow ? "enabling" : "disabling");
  2337. #endif
  2338. if (wrflow && spi_max_width(starget))
  2339. ppr_options |= MSG_EXT_PPR_WR_FLOW;
  2340. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2341. starget->channel + 'A', ROLE_INITIATOR);
  2342. ahd_find_syncrate(ahd, &period, &ppr_options,
  2343. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2344. ahd_lock(ahd, &flags);
  2345. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2346. ppr_options, AHD_TRANS_GOAL, FALSE);
  2347. ahd_unlock(ahd, &flags);
  2348. }
  2349. static void ahd_linux_set_rti(struct scsi_target *starget, int rti)
  2350. {
  2351. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2352. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2353. struct ahd_tmode_tstate *tstate;
  2354. struct ahd_initiator_tinfo *tinfo
  2355. = ahd_fetch_transinfo(ahd,
  2356. starget->channel + 'A',
  2357. shost->this_id, starget->id, &tstate);
  2358. struct ahd_devinfo devinfo;
  2359. unsigned int ppr_options = tinfo->goal.ppr_options
  2360. & ~MSG_EXT_PPR_RTI;
  2361. unsigned int period = tinfo->goal.period;
  2362. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2363. unsigned long flags;
  2364. if ((ahd->features & AHD_RTI) == 0) {
  2365. #ifdef AHD_DEBUG
  2366. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2367. printk("%s: RTI not available\n", ahd_name(ahd));
  2368. #endif
  2369. return;
  2370. }
  2371. #ifdef AHD_DEBUG
  2372. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2373. printk("%s: %s RTI\n", ahd_name(ahd),
  2374. rti ? "enabling" : "disabling");
  2375. #endif
  2376. if (rti && spi_max_width(starget))
  2377. ppr_options |= MSG_EXT_PPR_RTI;
  2378. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2379. starget->channel + 'A', ROLE_INITIATOR);
  2380. ahd_find_syncrate(ahd, &period, &ppr_options,
  2381. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2382. ahd_lock(ahd, &flags);
  2383. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2384. ppr_options, AHD_TRANS_GOAL, FALSE);
  2385. ahd_unlock(ahd, &flags);
  2386. }
  2387. static void ahd_linux_set_pcomp_en(struct scsi_target *starget, int pcomp)
  2388. {
  2389. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2390. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2391. struct ahd_tmode_tstate *tstate;
  2392. struct ahd_initiator_tinfo *tinfo
  2393. = ahd_fetch_transinfo(ahd,
  2394. starget->channel + 'A',
  2395. shost->this_id, starget->id, &tstate);
  2396. struct ahd_devinfo devinfo;
  2397. unsigned int ppr_options = tinfo->goal.ppr_options
  2398. & ~MSG_EXT_PPR_PCOMP_EN;
  2399. unsigned int period = tinfo->goal.period;
  2400. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2401. unsigned long flags;
  2402. #ifdef AHD_DEBUG
  2403. if ((ahd_debug & AHD_SHOW_DV) != 0)
  2404. printk("%s: %s Precompensation\n", ahd_name(ahd),
  2405. pcomp ? "Enable" : "Disable");
  2406. #endif
  2407. if (pcomp && spi_max_width(starget)) {
  2408. uint8_t precomp;
  2409. if (ahd->unit < ARRAY_SIZE(aic79xx_iocell_info)) {
  2410. const struct ahd_linux_iocell_opts *iocell_opts;
  2411. iocell_opts = &aic79xx_iocell_info[ahd->unit];
  2412. precomp = iocell_opts->precomp;
  2413. } else {
  2414. precomp = AIC79XX_DEFAULT_PRECOMP;
  2415. }
  2416. ppr_options |= MSG_EXT_PPR_PCOMP_EN;
  2417. AHD_SET_PRECOMP(ahd, precomp);
  2418. } else {
  2419. AHD_SET_PRECOMP(ahd, 0);
  2420. }
  2421. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2422. starget->channel + 'A', ROLE_INITIATOR);
  2423. ahd_find_syncrate(ahd, &period, &ppr_options,
  2424. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2425. ahd_lock(ahd, &flags);
  2426. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2427. ppr_options, AHD_TRANS_GOAL, FALSE);
  2428. ahd_unlock(ahd, &flags);
  2429. }
  2430. static void ahd_linux_set_hold_mcs(struct scsi_target *starget, int hold)
  2431. {
  2432. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2433. struct ahd_softc *ahd = *((struct ahd_softc **)shost->hostdata);
  2434. struct ahd_tmode_tstate *tstate;
  2435. struct ahd_initiator_tinfo *tinfo
  2436. = ahd_fetch_transinfo(ahd,
  2437. starget->channel + 'A',
  2438. shost->this_id, starget->id, &tstate);
  2439. struct ahd_devinfo devinfo;
  2440. unsigned int ppr_options = tinfo->goal.ppr_options
  2441. & ~MSG_EXT_PPR_HOLD_MCS;
  2442. unsigned int period = tinfo->goal.period;
  2443. unsigned int dt = ppr_options & MSG_EXT_PPR_DT_REQ;
  2444. unsigned long flags;
  2445. if (hold && spi_max_width(starget))
  2446. ppr_options |= MSG_EXT_PPR_HOLD_MCS;
  2447. ahd_compile_devinfo(&devinfo, shost->this_id, starget->id, 0,
  2448. starget->channel + 'A', ROLE_INITIATOR);
  2449. ahd_find_syncrate(ahd, &period, &ppr_options,
  2450. dt ? AHD_SYNCRATE_MAX : AHD_SYNCRATE_ULTRA2);
  2451. ahd_lock(ahd, &flags);
  2452. ahd_set_syncrate(ahd, &devinfo, period, tinfo->goal.offset,
  2453. ppr_options, AHD_TRANS_GOAL, FALSE);
  2454. ahd_unlock(ahd, &flags);
  2455. }
  2456. static void ahd_linux_get_signalling(struct Scsi_Host *shost)
  2457. {
  2458. struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
  2459. unsigned long flags;
  2460. u8 mode;
  2461. ahd_lock(ahd, &flags);
  2462. ahd_pause(ahd);
  2463. mode = ahd_inb(ahd, SBLKCTL);
  2464. ahd_unpause(ahd);
  2465. ahd_unlock(ahd, &flags);
  2466. if (mode & ENAB40)
  2467. spi_signalling(shost) = SPI_SIGNAL_LVD;
  2468. else if (mode & ENAB20)
  2469. spi_signalling(shost) = SPI_SIGNAL_SE;
  2470. else
  2471. spi_signalling(shost) = SPI_SIGNAL_UNKNOWN;
  2472. }
  2473. static struct spi_function_template ahd_linux_transport_functions = {
  2474. .set_offset = ahd_linux_set_offset,
  2475. .show_offset = 1,
  2476. .set_period = ahd_linux_set_period,
  2477. .show_period = 1,
  2478. .set_width = ahd_linux_set_width,
  2479. .show_width = 1,
  2480. .set_dt = ahd_linux_set_dt,
  2481. .show_dt = 1,
  2482. .set_iu = ahd_linux_set_iu,
  2483. .show_iu = 1,
  2484. .set_qas = ahd_linux_set_qas,
  2485. .show_qas = 1,
  2486. .set_rd_strm = ahd_linux_set_rd_strm,
  2487. .show_rd_strm = 1,
  2488. .set_wr_flow = ahd_linux_set_wr_flow,
  2489. .show_wr_flow = 1,
  2490. .set_rti = ahd_linux_set_rti,
  2491. .show_rti = 1,
  2492. .set_pcomp_en = ahd_linux_set_pcomp_en,
  2493. .show_pcomp_en = 1,
  2494. .set_hold_mcs = ahd_linux_set_hold_mcs,
  2495. .show_hold_mcs = 1,
  2496. .get_signalling = ahd_linux_get_signalling,
  2497. };
  2498. static int __init
  2499. ahd_linux_init(void)
  2500. {
  2501. int error = 0;
  2502. /*
  2503. * If we've been passed any parameters, process them now.
  2504. */
  2505. if (aic79xx)
  2506. aic79xx_setup(aic79xx);
  2507. ahd_linux_transport_template =
  2508. spi_attach_transport(&ahd_linux_transport_functions);
  2509. if (!ahd_linux_transport_template)
  2510. return -ENODEV;
  2511. scsi_transport_reserve_device(ahd_linux_transport_template,
  2512. sizeof(struct ahd_linux_device));
  2513. error = ahd_linux_pci_init();
  2514. if (error)
  2515. spi_release_transport(ahd_linux_transport_template);
  2516. return error;
  2517. }
  2518. static void __exit
  2519. ahd_linux_exit(void)
  2520. {
  2521. ahd_linux_pci_exit();
  2522. spi_release_transport(ahd_linux_transport_template);
  2523. }
  2524. module_init(ahd_linux_init);
  2525. module_exit(ahd_linux_exit);