aic79xx_osm.c 78 KB

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