aic79xx_osm.c 76 KB

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