aic79xx_osm.c 77 KB

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