aic79xx_osm.c 75 KB

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