aic79xx_osm.c 78 KB

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