aic79xx_osm.c 76 KB

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