aic79xx_osm.c 76 KB

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