aic79xx_osm.c 78 KB

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