aic79xx_osm.c 75 KB

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