aic79xx_osm.c 75 KB

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