aic79xx_osm.c 77 KB

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