qla1280.c 125 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493
  1. /******************************************************************************
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
  5. * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
  6. * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
  7. * Copyright (C) 2003-2004 Christoph Hellwig
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. ******************************************************************************/
  20. #define QLA1280_VERSION "3.27.1"
  21. /*****************************************************************************
  22. Revision History:
  23. Rev 3.27.1, February 8, 2010, Michael Reed
  24. - Retain firmware image for error recovery.
  25. Rev 3.27, February 10, 2009, Michael Reed
  26. - General code cleanup.
  27. - Improve error recovery.
  28. Rev 3.26, January 16, 2006 Jes Sorensen
  29. - Ditch all < 2.6 support
  30. Rev 3.25.1, February 10, 2005 Christoph Hellwig
  31. - use pci_map_single to map non-S/G requests
  32. - remove qla1280_proc_info
  33. Rev 3.25, September 28, 2004, Christoph Hellwig
  34. - add support for ISP1020/1040
  35. - don't include "scsi.h" anymore for 2.6.x
  36. Rev 3.24.4 June 7, 2004 Christoph Hellwig
  37. - restructure firmware loading, cleanup initialization code
  38. - prepare support for ISP1020/1040 chips
  39. Rev 3.24.3 January 19, 2004, Jes Sorensen
  40. - Handle PCI DMA mask settings correctly
  41. - Correct order of error handling in probe_one, free_irq should not
  42. be called if request_irq failed
  43. Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
  44. - Big endian fixes (James)
  45. - Remove bogus IOCB content on zero data transfer commands (Andrew)
  46. Rev 3.24.1 January 5, 2004, Jes Sorensen
  47. - Initialize completion queue to avoid OOPS on probe
  48. - Handle interrupts during mailbox testing
  49. Rev 3.24 November 17, 2003, Christoph Hellwig
  50. - use struct list_head for completion queue
  51. - avoid old Scsi_FOO typedefs
  52. - cleanup 2.4 compat glue a bit
  53. - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
  54. - make initialization for memory mapped vs port I/O more similar
  55. - remove broken pci config space manipulation
  56. - kill more cruft
  57. - this is an almost perfect 2.6 scsi driver now! ;)
  58. Rev 3.23.39 December 17, 2003, Jes Sorensen
  59. - Delete completion queue from srb if mailbox command failed to
  60. to avoid qla1280_done completeting qla1280_error_action's
  61. obsolete context
  62. - Reduce arguments for qla1280_done
  63. Rev 3.23.38 October 18, 2003, Christoph Hellwig
  64. - Convert to new-style hotplugable driver for 2.6
  65. - Fix missing scsi_unregister/scsi_host_put on HBA removal
  66. - Kill some more cruft
  67. Rev 3.23.37 October 1, 2003, Jes Sorensen
  68. - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
  69. random CONFIG option
  70. - Clean up locking in probe path
  71. Rev 3.23.36 October 1, 2003, Christoph Hellwig
  72. - queuecommand only ever receives new commands - clear flags
  73. - Reintegrate lost fixes from Linux 2.5
  74. Rev 3.23.35 August 14, 2003, Jes Sorensen
  75. - Build against 2.6
  76. Rev 3.23.34 July 23, 2003, Jes Sorensen
  77. - Remove pointless TRUE/FALSE macros
  78. - Clean up vchan handling
  79. Rev 3.23.33 July 3, 2003, Jes Sorensen
  80. - Don't define register access macros before define determining MMIO.
  81. This just happened to work out on ia64 but not elsewhere.
  82. - Don't try and read from the card while it is in reset as
  83. it won't respond and causes an MCA
  84. Rev 3.23.32 June 23, 2003, Jes Sorensen
  85. - Basic support for boot time arguments
  86. Rev 3.23.31 June 8, 2003, Jes Sorensen
  87. - Reduce boot time messages
  88. Rev 3.23.30 June 6, 2003, Jes Sorensen
  89. - Do not enable sync/wide/ppr before it has been determined
  90. that the target device actually supports it
  91. - Enable DMA arbitration for multi channel controllers
  92. Rev 3.23.29 June 3, 2003, Jes Sorensen
  93. - Port to 2.5.69
  94. Rev 3.23.28 June 3, 2003, Jes Sorensen
  95. - Eliminate duplicate marker commands on bus resets
  96. - Handle outstanding commands appropriately on bus/device resets
  97. Rev 3.23.27 May 28, 2003, Jes Sorensen
  98. - Remove bogus input queue code, let the Linux SCSI layer do the work
  99. - Clean up NVRAM handling, only read it once from the card
  100. - Add a number of missing default nvram parameters
  101. Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
  102. - Use completion queue for mailbox commands instead of busy wait
  103. Rev 3.23.25 Beta May 27, 2003, James Bottomley
  104. - Migrate to use new error handling code
  105. Rev 3.23.24 Beta May 21, 2003, James Bottomley
  106. - Big endian support
  107. - Cleanup data direction code
  108. Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
  109. - Switch to using MMIO instead of PIO
  110. Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
  111. - Fix PCI parity problem with 12160 during reset.
  112. Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
  113. - Use pci_map_page()/pci_unmap_page() instead of map_single version.
  114. Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
  115. - Remove < 2.4.x support
  116. - Introduce HOST_LOCK to make the spin lock changes portable.
  117. - Remove a bunch of idiotic and unnecessary typedef's
  118. - Kill all leftovers of target-mode support which never worked anyway
  119. Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
  120. - Do qla1280_pci_config() before calling request_irq() and
  121. request_region()
  122. - Use pci_dma_hi32() to handle upper word of DMA addresses instead
  123. of large shifts
  124. - Hand correct arguments to free_irq() in case of failure
  125. Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
  126. - Run source through Lindent and clean up the output
  127. Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
  128. - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
  129. Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
  130. - Rely on mailbox commands generating interrupts - do not
  131. run qla1280_isr() from ql1280_mailbox_command()
  132. - Remove device_reg_t
  133. - Integrate ql12160_set_target_parameters() with 1280 version
  134. - Make qla1280_setup() non static
  135. - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
  136. sent to the card - this command pauses the firmware!!!
  137. Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
  138. - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
  139. - Remove a pile of pointless and confusing (srb_t **) and
  140. (scsi_lu_t *) typecasts
  141. - Explicit mark that we do not use the new error handling (for now)
  142. - Remove scsi_qla_host_t and use 'struct' instead
  143. - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
  144. pci_64bit_slot flags which weren't used for anything anyway
  145. - Grab host->host_lock while calling qla1280_isr() from abort()
  146. - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
  147. do not need to save/restore flags in the interrupt handler
  148. - Enable interrupts early (before any mailbox access) in preparation
  149. for cleaning up the mailbox handling
  150. Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
  151. - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
  152. it with proper use of dprintk().
  153. - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
  154. a debug level argument to determine if data is to be printed
  155. - Add KERN_* info to printk()
  156. Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
  157. - Significant cosmetic cleanups
  158. - Change debug code to use dprintk() and remove #if mess
  159. Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
  160. - More cosmetic cleanups, fix places treating return as function
  161. - use cpu_relax() in qla1280_debounce_register()
  162. Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
  163. - Make it compile under 2.5.5
  164. Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
  165. - Do no typecast short * to long * in QL1280BoardTbl, this
  166. broke miserably on big endian boxes
  167. Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
  168. - Remove pre 2.2 hack for checking for reentrance in interrupt handler
  169. - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
  170. unsigned int to match the types from struct scsi_cmnd
  171. Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
  172. - Remove bogus timer_t typedef from qla1280.h
  173. - Remove obsolete pre 2.2 PCI setup code, use proper #define's
  174. for PCI_ values, call pci_set_master()
  175. - Fix memleak of qla1280_buffer on module unload
  176. - Only compile module parsing code #ifdef MODULE - should be
  177. changed to use individual MODULE_PARM's later
  178. - Remove dummy_buffer that was never modified nor printed
  179. - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
  180. #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
  181. - Remove \r from print statements, this is Linux, not DOS
  182. - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
  183. dummy macros
  184. - Remove C++ compile hack in header file as Linux driver are not
  185. supposed to be compiled as C++
  186. - Kill MS_64BITS macro as it makes the code more readable
  187. - Remove unnecessary flags.in_interrupts bit
  188. Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
  189. - Dont' check for set flags on q->q_flag one by one in qla1280_next()
  190. - Check whether the interrupt was generated by the QLA1280 before
  191. doing any processing
  192. - qla1280_status_entry(): Only zero out part of sense_buffer that
  193. is not being copied into
  194. - Remove more superflouous typecasts
  195. - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
  196. Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
  197. - Don't walk the entire list in qla1280_putq_t() just to directly
  198. grab the pointer to the last element afterwards
  199. Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
  200. - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver
  201. Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
  202. - Set dev->max_sectors to 1024
  203. Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
  204. - Provide compat macros for pci_enable_device(), pci_find_subsys()
  205. and scsi_set_pci_device()
  206. - Call scsi_set_pci_device() for all devices
  207. - Reduce size of kernel version dependent device probe code
  208. - Move duplicate probe/init code to separate function
  209. - Handle error if qla1280_mem_alloc() fails
  210. - Kill OFFSET() macro and use Linux's PCI definitions instead
  211. - Kill private structure defining PCI config space (struct config_reg)
  212. - Only allocate I/O port region if not in MMIO mode
  213. - Remove duplicate (unused) sanity check of sife of srb_t
  214. Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
  215. - Change home-brew memset() implementations to use memset()
  216. - Remove all references to COMTRACE() - accessing a PC's COM2 serial
  217. port directly is not legal under Linux.
  218. Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
  219. - Remove pre 2.2 kernel support
  220. - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
  221. - Fix MMIO access to use readl/writel instead of directly
  222. dereferencing pointers
  223. - Nuke MSDOS debugging code
  224. - Change true/false data types to int from uint8_t
  225. - Use int for counters instead of uint8_t etc.
  226. - Clean up size & byte order conversion macro usage
  227. Rev 3.23 Beta January 11, 2001 BN Qlogic
  228. - Added check of device_id when handling non
  229. QLA12160s during detect().
  230. Rev 3.22 Beta January 5, 2001 BN Qlogic
  231. - Changed queue_task() to schedule_task()
  232. for kernels 2.4.0 and higher.
  233. Note: 2.4.0-testxx kernels released prior to
  234. the actual 2.4.0 kernel release on January 2001
  235. will get compile/link errors with schedule_task().
  236. Please update your kernel to released 2.4.0 level,
  237. or comment lines in this file flagged with 3.22
  238. to resolve compile/link error of schedule_task().
  239. - Added -DCONFIG_SMP in addition to -D__SMP__
  240. in Makefile for 2.4.0 builds of driver as module.
  241. Rev 3.21 Beta January 4, 2001 BN Qlogic
  242. - Changed criteria of 64/32 Bit mode of HBA
  243. operation according to BITS_PER_LONG rather
  244. than HBA's NVRAM setting of >4Gig memory bit;
  245. so that the HBA auto-configures without the need
  246. to setup each system individually.
  247. Rev 3.20 Beta December 5, 2000 BN Qlogic
  248. - Added priority handling to IA-64 onboard SCSI
  249. ISP12160 chip for kernels greater than 2.3.18.
  250. - Added irqrestore for qla1280_intr_handler.
  251. - Enabled /proc/scsi/qla1280 interface.
  252. - Clear /proc/scsi/qla1280 counters in detect().
  253. Rev 3.19 Beta October 13, 2000 BN Qlogic
  254. - Declare driver_template for new kernel
  255. (2.4.0 and greater) scsi initialization scheme.
  256. - Update /proc/scsi entry for 2.3.18 kernels and
  257. above as qla1280
  258. Rev 3.18 Beta October 10, 2000 BN Qlogic
  259. - Changed scan order of adapters to map
  260. the QLA12160 followed by the QLA1280.
  261. Rev 3.17 Beta September 18, 2000 BN Qlogic
  262. - Removed warnings for 32 bit 2.4.x compiles
  263. - Corrected declared size for request and response
  264. DMA addresses that are kept in each ha
  265. Rev. 3.16 Beta August 25, 2000 BN Qlogic
  266. - Corrected 64 bit addressing issue on IA-64
  267. where the upper 32 bits were not properly
  268. passed to the RISC engine.
  269. Rev. 3.15 Beta August 22, 2000 BN Qlogic
  270. - Modified qla1280_setup_chip to properly load
  271. ISP firmware for greater that 4 Gig memory on IA-64
  272. Rev. 3.14 Beta August 16, 2000 BN Qlogic
  273. - Added setting of dma_mask to full 64 bit
  274. if flags.enable_64bit_addressing is set in NVRAM
  275. Rev. 3.13 Beta August 16, 2000 BN Qlogic
  276. - Use new PCI DMA mapping APIs for 2.4.x kernel
  277. Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
  278. - Added check of pci_enable_device to detect() for 2.3.x
  279. - Use pci_resource_start() instead of
  280. pdev->resource[0].start in detect() for 2.3.x
  281. - Updated driver version
  282. Rev. 3.11 July 14, 2000 BN Qlogic
  283. - Updated SCSI Firmware to following versions:
  284. qla1x80: 8.13.08
  285. qla1x160: 10.04.08
  286. - Updated driver version to 3.11
  287. Rev. 3.10 June 23, 2000 BN Qlogic
  288. - Added filtering of AMI SubSys Vendor ID devices
  289. Rev. 3.9
  290. - DEBUG_QLA1280 undefined and new version BN Qlogic
  291. Rev. 3.08b May 9, 2000 MD Dell
  292. - Added logic to check against AMI subsystem vendor ID
  293. Rev. 3.08 May 4, 2000 DG Qlogic
  294. - Added logic to check for PCI subsystem ID.
  295. Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
  296. - Updated SCSI Firmware to following versions:
  297. qla12160: 10.01.19
  298. qla1280: 8.09.00
  299. Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
  300. - Internal revision; not released
  301. Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
  302. - Edit correction for virt_to_bus and PROC.
  303. Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
  304. - Merge changes from ia64 port.
  305. Rev. 3.03 Mar 28, 2000 BN Qlogic
  306. - Increase version to reflect new code drop with compile fix
  307. of issue with inclusion of linux/spinlock for 2.3 kernels
  308. Rev. 3.02 Mar 15, 2000 BN Qlogic
  309. - Merge qla1280_proc_info from 2.10 code base
  310. Rev. 3.01 Feb 10, 2000 BN Qlogic
  311. - Corrected code to compile on a 2.2.x kernel.
  312. Rev. 3.00 Jan 17, 2000 DG Qlogic
  313. - Added 64-bit support.
  314. Rev. 2.07 Nov 9, 1999 DG Qlogic
  315. - Added new routine to set target parameters for ISP12160.
  316. Rev. 2.06 Sept 10, 1999 DG Qlogic
  317. - Added support for ISP12160 Ultra 3 chip.
  318. Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
  319. - Modified code to remove errors generated when compiling with
  320. Cygnus IA64 Compiler.
  321. - Changed conversion of pointers to unsigned longs instead of integers.
  322. - Changed type of I/O port variables from uint32_t to unsigned long.
  323. - Modified OFFSET macro to work with 64-bit as well as 32-bit.
  324. - Changed sprintf and printk format specifiers for pointers to %p.
  325. - Changed some int to long type casts where needed in sprintf & printk.
  326. - Added l modifiers to sprintf and printk format specifiers for longs.
  327. - Removed unused local variables.
  328. Rev. 1.20 June 8, 1999 DG, Qlogic
  329. Changes to support RedHat release 6.0 (kernel 2.2.5).
  330. - Added SCSI exclusive access lock (io_request_lock) when accessing
  331. the adapter.
  332. - Added changes for the new LINUX interface template. Some new error
  333. handling routines have been added to the template, but for now we
  334. will use the old ones.
  335. - Initial Beta Release.
  336. *****************************************************************************/
  337. #include <linux/module.h>
  338. #include <linux/types.h>
  339. #include <linux/string.h>
  340. #include <linux/errno.h>
  341. #include <linux/kernel.h>
  342. #include <linux/ioport.h>
  343. #include <linux/delay.h>
  344. #include <linux/timer.h>
  345. #include <linux/pci.h>
  346. #include <linux/proc_fs.h>
  347. #include <linux/stat.h>
  348. #include <linux/pci_ids.h>
  349. #include <linux/interrupt.h>
  350. #include <linux/init.h>
  351. #include <linux/dma-mapping.h>
  352. #include <linux/firmware.h>
  353. #include <asm/io.h>
  354. #include <asm/irq.h>
  355. #include <asm/byteorder.h>
  356. #include <asm/processor.h>
  357. #include <asm/types.h>
  358. #include <scsi/scsi.h>
  359. #include <scsi/scsi_cmnd.h>
  360. #include <scsi/scsi_device.h>
  361. #include <scsi/scsi_host.h>
  362. #include <scsi/scsi_tcq.h>
  363. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  364. #include <asm/sn/io.h>
  365. #endif
  366. /*
  367. * Compile time Options:
  368. * 0 - Disable and 1 - Enable
  369. */
  370. #define DEBUG_QLA1280_INTR 0
  371. #define DEBUG_PRINT_NVRAM 0
  372. #define DEBUG_QLA1280 0
  373. #define MEMORY_MAPPED_IO 1
  374. #include "qla1280.h"
  375. #ifndef BITS_PER_LONG
  376. #error "BITS_PER_LONG not defined!"
  377. #endif
  378. #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
  379. #define QLA_64BIT_PTR 1
  380. #endif
  381. #ifdef QLA_64BIT_PTR
  382. #define pci_dma_hi32(a) ((a >> 16) >> 16)
  383. #else
  384. #define pci_dma_hi32(a) 0
  385. #endif
  386. #define pci_dma_lo32(a) (a & 0xffffffff)
  387. #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
  388. #if defined(__ia64__) && !defined(ia64_platform_is)
  389. #define ia64_platform_is(foo) (!strcmp(x, platform_name))
  390. #endif
  391. #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
  392. #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
  393. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
  394. #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
  395. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
  396. static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
  397. static void qla1280_remove_one(struct pci_dev *);
  398. /*
  399. * QLogic Driver Support Function Prototypes.
  400. */
  401. static void qla1280_done(struct scsi_qla_host *);
  402. static int qla1280_get_token(char *);
  403. static int qla1280_setup(char *s) __init;
  404. /*
  405. * QLogic ISP1280 Hardware Support Function Prototypes.
  406. */
  407. static int qla1280_load_firmware(struct scsi_qla_host *);
  408. static int qla1280_init_rings(struct scsi_qla_host *);
  409. static int qla1280_nvram_config(struct scsi_qla_host *);
  410. static int qla1280_mailbox_command(struct scsi_qla_host *,
  411. uint8_t, uint16_t *);
  412. static int qla1280_bus_reset(struct scsi_qla_host *, int);
  413. static int qla1280_device_reset(struct scsi_qla_host *, int, int);
  414. static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
  415. static int qla1280_abort_isp(struct scsi_qla_host *);
  416. #ifdef QLA_64BIT_PTR
  417. static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
  418. #else
  419. static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
  420. #endif
  421. static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
  422. static void qla1280_poll(struct scsi_qla_host *);
  423. static void qla1280_reset_adapter(struct scsi_qla_host *);
  424. static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
  425. static void qla1280_isp_cmd(struct scsi_qla_host *);
  426. static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
  427. static void qla1280_rst_aen(struct scsi_qla_host *);
  428. static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
  429. struct list_head *);
  430. static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
  431. struct list_head *);
  432. static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
  433. static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
  434. static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
  435. static request_t *qla1280_req_pkt(struct scsi_qla_host *);
  436. static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
  437. unsigned int);
  438. static void qla1280_get_target_parameters(struct scsi_qla_host *,
  439. struct scsi_device *);
  440. static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
  441. static struct qla_driver_setup driver_setup;
  442. /*
  443. * convert scsi data direction to request_t control flags
  444. */
  445. static inline uint16_t
  446. qla1280_data_direction(struct scsi_cmnd *cmnd)
  447. {
  448. switch(cmnd->sc_data_direction) {
  449. case DMA_FROM_DEVICE:
  450. return BIT_5;
  451. case DMA_TO_DEVICE:
  452. return BIT_6;
  453. case DMA_BIDIRECTIONAL:
  454. return BIT_5 | BIT_6;
  455. /*
  456. * We could BUG() on default here if one of the four cases aren't
  457. * met, but then again if we receive something like that from the
  458. * SCSI layer we have more serious problems. This shuts up GCC.
  459. */
  460. case DMA_NONE:
  461. default:
  462. return 0;
  463. }
  464. }
  465. #if DEBUG_QLA1280
  466. static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
  467. static void __qla1280_dump_buffer(char *, int);
  468. #endif
  469. /*
  470. * insmod needs to find the variable and make it point to something
  471. */
  472. #ifdef MODULE
  473. static char *qla1280;
  474. /* insmod qla1280 options=verbose" */
  475. module_param(qla1280, charp, 0);
  476. #else
  477. __setup("qla1280=", qla1280_setup);
  478. #endif
  479. /*
  480. * We use the scsi_pointer structure that's included with each scsi_command
  481. * to overlay our struct srb over it. qla1280_init() checks that a srb is not
  482. * bigger than a scsi_pointer.
  483. */
  484. #define CMD_SP(Cmnd) &Cmnd->SCp
  485. #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
  486. #define CMD_CDBP(Cmnd) Cmnd->cmnd
  487. #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
  488. #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
  489. #define CMD_RESULT(Cmnd) Cmnd->result
  490. #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
  491. #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
  492. #define CMD_HOST(Cmnd) Cmnd->device->host
  493. #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
  494. #define SCSI_TCN_32(Cmnd) Cmnd->device->id
  495. #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
  496. /*****************************************/
  497. /* ISP Boards supported by this driver */
  498. /*****************************************/
  499. struct qla_boards {
  500. char *name; /* Board ID String */
  501. int numPorts; /* Number of SCSI ports */
  502. int fw_index; /* index into qla1280_fw_tbl for firmware */
  503. };
  504. /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
  505. static struct pci_device_id qla1280_pci_tbl[] = {
  506. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
  507. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  508. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
  509. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  510. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
  511. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  512. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
  513. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  514. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
  515. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  516. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
  517. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
  518. {0,}
  519. };
  520. MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
  521. DEFINE_MUTEX(qla1280_firmware_mutex);
  522. struct qla_fw {
  523. char *fwname;
  524. const struct firmware *fw;
  525. };
  526. #define QL_NUM_FW_IMAGES 3
  527. struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = {
  528. {"qlogic/1040.bin", NULL}, /* image 0 */
  529. {"qlogic/1280.bin", NULL}, /* image 1 */
  530. {"qlogic/12160.bin", NULL}, /* image 2 */
  531. };
  532. /* NOTE: Order of boards in this table must match order in qla1280_pci_tbl */
  533. static struct qla_boards ql1280_board_tbl[] = {
  534. {.name = "QLA12160", .numPorts = 2, .fw_index = 2},
  535. {.name = "QLA1040" , .numPorts = 1, .fw_index = 0},
  536. {.name = "QLA1080" , .numPorts = 1, .fw_index = 1},
  537. {.name = "QLA1240" , .numPorts = 2, .fw_index = 1},
  538. {.name = "QLA1280" , .numPorts = 2, .fw_index = 1},
  539. {.name = "QLA10160", .numPorts = 1, .fw_index = 2},
  540. {.name = " ", .numPorts = 0, .fw_index = -1},
  541. };
  542. static int qla1280_verbose = 1;
  543. #if DEBUG_QLA1280
  544. static int ql_debug_level = 1;
  545. #define dprintk(level, format, a...) \
  546. do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
  547. #define qla1280_dump_buffer(level, buf, size) \
  548. if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
  549. #define qla1280_print_scsi_cmd(level, cmd) \
  550. if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
  551. #else
  552. #define ql_debug_level 0
  553. #define dprintk(level, format, a...) do{}while(0)
  554. #define qla1280_dump_buffer(a, b, c) do{}while(0)
  555. #define qla1280_print_scsi_cmd(a, b) do{}while(0)
  556. #endif
  557. #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
  558. #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
  559. #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
  560. #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
  561. static int qla1280_read_nvram(struct scsi_qla_host *ha)
  562. {
  563. uint16_t *wptr;
  564. uint8_t chksum;
  565. int cnt, i;
  566. struct nvram *nv;
  567. ENTER("qla1280_read_nvram");
  568. if (driver_setup.no_nvram)
  569. return 1;
  570. printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
  571. wptr = (uint16_t *)&ha->nvram;
  572. nv = &ha->nvram;
  573. chksum = 0;
  574. for (cnt = 0; cnt < 3; cnt++) {
  575. *wptr = qla1280_get_nvram_word(ha, cnt);
  576. chksum += *wptr & 0xff;
  577. chksum += (*wptr >> 8) & 0xff;
  578. wptr++;
  579. }
  580. if (nv->id0 != 'I' || nv->id1 != 'S' ||
  581. nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
  582. dprintk(2, "Invalid nvram ID or version!\n");
  583. chksum = 1;
  584. } else {
  585. for (; cnt < sizeof(struct nvram); cnt++) {
  586. *wptr = qla1280_get_nvram_word(ha, cnt);
  587. chksum += *wptr & 0xff;
  588. chksum += (*wptr >> 8) & 0xff;
  589. wptr++;
  590. }
  591. }
  592. dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
  593. " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
  594. nv->version);
  595. if (chksum) {
  596. if (!driver_setup.no_nvram)
  597. printk(KERN_WARNING "scsi(%ld): Unable to identify or "
  598. "validate NVRAM checksum, using default "
  599. "settings\n", ha->host_no);
  600. ha->nvram_valid = 0;
  601. } else
  602. ha->nvram_valid = 1;
  603. /* The firmware interface is, um, interesting, in that the
  604. * actual firmware image on the chip is little endian, thus,
  605. * the process of taking that image to the CPU would end up
  606. * little endian. However, the firmware interface requires it
  607. * to be read a word (two bytes) at a time.
  608. *
  609. * The net result of this would be that the word (and
  610. * doubleword) quantites in the firmware would be correct, but
  611. * the bytes would be pairwise reversed. Since most of the
  612. * firmware quantites are, in fact, bytes, we do an extra
  613. * le16_to_cpu() in the firmware read routine.
  614. *
  615. * The upshot of all this is that the bytes in the firmware
  616. * are in the correct places, but the 16 and 32 bit quantites
  617. * are still in little endian format. We fix that up below by
  618. * doing extra reverses on them */
  619. nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
  620. nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
  621. for(i = 0; i < MAX_BUSES; i++) {
  622. nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
  623. nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
  624. }
  625. dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
  626. LEAVE("qla1280_read_nvram");
  627. return chksum;
  628. }
  629. /**************************************************************************
  630. * qla1280_info
  631. * Return a string describing the driver.
  632. **************************************************************************/
  633. static const char *
  634. qla1280_info(struct Scsi_Host *host)
  635. {
  636. static char qla1280_scsi_name_buffer[125];
  637. char *bp;
  638. struct scsi_qla_host *ha;
  639. struct qla_boards *bdp;
  640. bp = &qla1280_scsi_name_buffer[0];
  641. ha = (struct scsi_qla_host *)host->hostdata;
  642. bdp = &ql1280_board_tbl[ha->devnum];
  643. memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
  644. sprintf (bp,
  645. "QLogic %s PCI to SCSI Host Adapter\n"
  646. " Firmware version: %2d.%02d.%02d, Driver version %s",
  647. &bdp->name[0], ha->fwver1, ha->fwver2, ha->fwver3,
  648. QLA1280_VERSION);
  649. return bp;
  650. }
  651. /**************************************************************************
  652. * qla1280_queuecommand
  653. * Queue a command to the controller.
  654. *
  655. * Note:
  656. * The mid-level driver tries to ensures that queuecommand never gets invoked
  657. * concurrently with itself or the interrupt handler (although the
  658. * interrupt handler may call this routine as part of request-completion
  659. * handling). Unfortunely, it sometimes calls the scheduler in interrupt
  660. * context which is a big NO! NO!.
  661. **************************************************************************/
  662. static int
  663. qla1280_queuecommand_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
  664. {
  665. struct Scsi_Host *host = cmd->device->host;
  666. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  667. struct srb *sp = (struct srb *)CMD_SP(cmd);
  668. int status;
  669. cmd->scsi_done = fn;
  670. sp->cmd = cmd;
  671. sp->flags = 0;
  672. sp->wait = NULL;
  673. CMD_HANDLE(cmd) = (unsigned char *)NULL;
  674. qla1280_print_scsi_cmd(5, cmd);
  675. #ifdef QLA_64BIT_PTR
  676. /*
  677. * Using 64 bit commands if the PCI bridge doesn't support it is a
  678. * bit wasteful, however this should really only happen if one's
  679. * PCI controller is completely broken, like the BCM1250. For
  680. * sane hardware this is not an issue.
  681. */
  682. status = qla1280_64bit_start_scsi(ha, sp);
  683. #else
  684. status = qla1280_32bit_start_scsi(ha, sp);
  685. #endif
  686. return status;
  687. }
  688. static DEF_SCSI_QCMD(qla1280_queuecommand)
  689. enum action {
  690. ABORT_COMMAND,
  691. DEVICE_RESET,
  692. BUS_RESET,
  693. ADAPTER_RESET,
  694. };
  695. static void qla1280_mailbox_timeout(unsigned long __data)
  696. {
  697. struct scsi_qla_host *ha = (struct scsi_qla_host *)__data;
  698. struct device_reg __iomem *reg;
  699. reg = ha->iobase;
  700. ha->mailbox_out[0] = RD_REG_WORD(&reg->mailbox0);
  701. printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
  702. "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
  703. RD_REG_WORD(&reg->ictrl), RD_REG_WORD(&reg->istatus));
  704. complete(ha->mailbox_wait);
  705. }
  706. static int
  707. _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
  708. struct completion *wait)
  709. {
  710. int status = FAILED;
  711. struct scsi_cmnd *cmd = sp->cmd;
  712. spin_unlock_irq(ha->host->host_lock);
  713. wait_for_completion_timeout(wait, 4*HZ);
  714. spin_lock_irq(ha->host->host_lock);
  715. sp->wait = NULL;
  716. if(CMD_HANDLE(cmd) == COMPLETED_HANDLE) {
  717. status = SUCCESS;
  718. (*cmd->scsi_done)(cmd);
  719. }
  720. return status;
  721. }
  722. static int
  723. qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
  724. {
  725. DECLARE_COMPLETION_ONSTACK(wait);
  726. sp->wait = &wait;
  727. return _qla1280_wait_for_single_command(ha, sp, &wait);
  728. }
  729. static int
  730. qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
  731. {
  732. int cnt;
  733. int status;
  734. struct srb *sp;
  735. struct scsi_cmnd *cmd;
  736. status = SUCCESS;
  737. /*
  738. * Wait for all commands with the designated bus/target
  739. * to be completed by the firmware
  740. */
  741. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  742. sp = ha->outstanding_cmds[cnt];
  743. if (sp) {
  744. cmd = sp->cmd;
  745. if (bus >= 0 && SCSI_BUS_32(cmd) != bus)
  746. continue;
  747. if (target >= 0 && SCSI_TCN_32(cmd) != target)
  748. continue;
  749. status = qla1280_wait_for_single_command(ha, sp);
  750. if (status == FAILED)
  751. break;
  752. }
  753. }
  754. return status;
  755. }
  756. /**************************************************************************
  757. * qla1280_error_action
  758. * The function will attempt to perform a specified error action and
  759. * wait for the results (or time out).
  760. *
  761. * Input:
  762. * cmd = Linux SCSI command packet of the command that cause the
  763. * bus reset.
  764. * action = error action to take (see action_t)
  765. *
  766. * Returns:
  767. * SUCCESS or FAILED
  768. *
  769. **************************************************************************/
  770. static int
  771. qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
  772. {
  773. struct scsi_qla_host *ha;
  774. int bus, target, lun;
  775. struct srb *sp;
  776. int i, found;
  777. int result=FAILED;
  778. int wait_for_bus=-1;
  779. int wait_for_target = -1;
  780. DECLARE_COMPLETION_ONSTACK(wait);
  781. ENTER("qla1280_error_action");
  782. ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
  783. sp = (struct srb *)CMD_SP(cmd);
  784. bus = SCSI_BUS_32(cmd);
  785. target = SCSI_TCN_32(cmd);
  786. lun = SCSI_LUN_32(cmd);
  787. dprintk(4, "error_action %i, istatus 0x%04x\n", action,
  788. RD_REG_WORD(&ha->iobase->istatus));
  789. dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
  790. RD_REG_WORD(&ha->iobase->host_cmd),
  791. RD_REG_WORD(&ha->iobase->ictrl), jiffies);
  792. if (qla1280_verbose)
  793. printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
  794. "Handle=0x%p, action=0x%x\n",
  795. ha->host_no, cmd, CMD_HANDLE(cmd), action);
  796. /*
  797. * Check to see if we have the command in the outstanding_cmds[]
  798. * array. If not then it must have completed before this error
  799. * action was initiated. If the error_action isn't ABORT_COMMAND
  800. * then the driver must proceed with the requested action.
  801. */
  802. found = -1;
  803. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  804. if (sp == ha->outstanding_cmds[i]) {
  805. found = i;
  806. sp->wait = &wait; /* we'll wait for it to complete */
  807. break;
  808. }
  809. }
  810. if (found < 0) { /* driver doesn't have command */
  811. result = SUCCESS;
  812. if (qla1280_verbose) {
  813. printk(KERN_INFO
  814. "scsi(%ld:%d:%d:%d): specified command has "
  815. "already completed.\n", ha->host_no, bus,
  816. target, lun);
  817. }
  818. }
  819. switch (action) {
  820. case ABORT_COMMAND:
  821. dprintk(1, "qla1280: RISC aborting command\n");
  822. /*
  823. * The abort might fail due to race when the host_lock
  824. * is released to issue the abort. As such, we
  825. * don't bother to check the return status.
  826. */
  827. if (found >= 0)
  828. qla1280_abort_command(ha, sp, found);
  829. break;
  830. case DEVICE_RESET:
  831. if (qla1280_verbose)
  832. printk(KERN_INFO
  833. "scsi(%ld:%d:%d:%d): Queueing device reset "
  834. "command.\n", ha->host_no, bus, target, lun);
  835. if (qla1280_device_reset(ha, bus, target) == 0) {
  836. /* issued device reset, set wait conditions */
  837. wait_for_bus = bus;
  838. wait_for_target = target;
  839. }
  840. break;
  841. case BUS_RESET:
  842. if (qla1280_verbose)
  843. printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
  844. "reset.\n", ha->host_no, bus);
  845. if (qla1280_bus_reset(ha, bus) == 0) {
  846. /* issued bus reset, set wait conditions */
  847. wait_for_bus = bus;
  848. }
  849. break;
  850. case ADAPTER_RESET:
  851. default:
  852. if (qla1280_verbose) {
  853. printk(KERN_INFO
  854. "scsi(%ld): Issued ADAPTER RESET\n",
  855. ha->host_no);
  856. printk(KERN_INFO "scsi(%ld): I/O processing will "
  857. "continue automatically\n", ha->host_no);
  858. }
  859. ha->flags.reset_active = 1;
  860. if (qla1280_abort_isp(ha) != 0) { /* it's dead */
  861. result = FAILED;
  862. }
  863. ha->flags.reset_active = 0;
  864. }
  865. /*
  866. * At this point, the host_lock has been released and retaken
  867. * by the issuance of the mailbox command.
  868. * Wait for the command passed in by the mid-layer if it
  869. * was found by the driver. It might have been returned
  870. * between eh recovery steps, hence the check of the "found"
  871. * variable.
  872. */
  873. if (found >= 0)
  874. result = _qla1280_wait_for_single_command(ha, sp, &wait);
  875. if (action == ABORT_COMMAND && result != SUCCESS) {
  876. printk(KERN_WARNING
  877. "scsi(%li:%i:%i:%i): "
  878. "Unable to abort command!\n",
  879. ha->host_no, bus, target, lun);
  880. }
  881. /*
  882. * If the command passed in by the mid-layer has been
  883. * returned by the board, then wait for any additional
  884. * commands which are supposed to complete based upon
  885. * the error action.
  886. *
  887. * All commands are unconditionally returned during a
  888. * call to qla1280_abort_isp(), ADAPTER_RESET. No need
  889. * to wait for them.
  890. */
  891. if (result == SUCCESS && wait_for_bus >= 0) {
  892. result = qla1280_wait_for_pending_commands(ha,
  893. wait_for_bus, wait_for_target);
  894. }
  895. dprintk(1, "RESET returning %d\n", result);
  896. LEAVE("qla1280_error_action");
  897. return result;
  898. }
  899. /**************************************************************************
  900. * qla1280_abort
  901. * Abort the specified SCSI command(s).
  902. **************************************************************************/
  903. static int
  904. qla1280_eh_abort(struct scsi_cmnd * cmd)
  905. {
  906. int rc;
  907. spin_lock_irq(cmd->device->host->host_lock);
  908. rc = qla1280_error_action(cmd, ABORT_COMMAND);
  909. spin_unlock_irq(cmd->device->host->host_lock);
  910. return rc;
  911. }
  912. /**************************************************************************
  913. * qla1280_device_reset
  914. * Reset the specified SCSI device
  915. **************************************************************************/
  916. static int
  917. qla1280_eh_device_reset(struct scsi_cmnd *cmd)
  918. {
  919. int rc;
  920. spin_lock_irq(cmd->device->host->host_lock);
  921. rc = qla1280_error_action(cmd, DEVICE_RESET);
  922. spin_unlock_irq(cmd->device->host->host_lock);
  923. return rc;
  924. }
  925. /**************************************************************************
  926. * qla1280_bus_reset
  927. * Reset the specified bus.
  928. **************************************************************************/
  929. static int
  930. qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
  931. {
  932. int rc;
  933. spin_lock_irq(cmd->device->host->host_lock);
  934. rc = qla1280_error_action(cmd, BUS_RESET);
  935. spin_unlock_irq(cmd->device->host->host_lock);
  936. return rc;
  937. }
  938. /**************************************************************************
  939. * qla1280_adapter_reset
  940. * Reset the specified adapter (both channels)
  941. **************************************************************************/
  942. static int
  943. qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
  944. {
  945. int rc;
  946. spin_lock_irq(cmd->device->host->host_lock);
  947. rc = qla1280_error_action(cmd, ADAPTER_RESET);
  948. spin_unlock_irq(cmd->device->host->host_lock);
  949. return rc;
  950. }
  951. static int
  952. qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  953. sector_t capacity, int geom[])
  954. {
  955. int heads, sectors, cylinders;
  956. heads = 64;
  957. sectors = 32;
  958. cylinders = (unsigned long)capacity / (heads * sectors);
  959. if (cylinders > 1024) {
  960. heads = 255;
  961. sectors = 63;
  962. cylinders = (unsigned long)capacity / (heads * sectors);
  963. /* if (cylinders > 1023)
  964. cylinders = 1023; */
  965. }
  966. geom[0] = heads;
  967. geom[1] = sectors;
  968. geom[2] = cylinders;
  969. return 0;
  970. }
  971. /* disable risc and host interrupts */
  972. static inline void
  973. qla1280_disable_intrs(struct scsi_qla_host *ha)
  974. {
  975. WRT_REG_WORD(&ha->iobase->ictrl, 0);
  976. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  977. }
  978. /* enable risc and host interrupts */
  979. static inline void
  980. qla1280_enable_intrs(struct scsi_qla_host *ha)
  981. {
  982. WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
  983. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  984. }
  985. /**************************************************************************
  986. * qla1280_intr_handler
  987. * Handles the H/W interrupt
  988. **************************************************************************/
  989. static irqreturn_t
  990. qla1280_intr_handler(int irq, void *dev_id)
  991. {
  992. struct scsi_qla_host *ha;
  993. struct device_reg __iomem *reg;
  994. u16 data;
  995. int handled = 0;
  996. ENTER_INTR ("qla1280_intr_handler");
  997. ha = (struct scsi_qla_host *)dev_id;
  998. spin_lock(ha->host->host_lock);
  999. ha->isr_count++;
  1000. reg = ha->iobase;
  1001. qla1280_disable_intrs(ha);
  1002. data = qla1280_debounce_register(&reg->istatus);
  1003. /* Check for pending interrupts. */
  1004. if (data & RISC_INT) {
  1005. qla1280_isr(ha, &ha->done_q);
  1006. handled = 1;
  1007. }
  1008. if (!list_empty(&ha->done_q))
  1009. qla1280_done(ha);
  1010. spin_unlock(ha->host->host_lock);
  1011. qla1280_enable_intrs(ha);
  1012. LEAVE_INTR("qla1280_intr_handler");
  1013. return IRQ_RETVAL(handled);
  1014. }
  1015. static int
  1016. qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
  1017. {
  1018. uint8_t mr;
  1019. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1020. struct nvram *nv;
  1021. int status, lun;
  1022. nv = &ha->nvram;
  1023. mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
  1024. /* Set Target Parameters. */
  1025. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1026. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1027. mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
  1028. mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
  1029. mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
  1030. mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
  1031. mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
  1032. mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
  1033. mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
  1034. mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
  1035. if (IS_ISP1x160(ha)) {
  1036. mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
  1037. mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
  1038. mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
  1039. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
  1040. mr |= BIT_6;
  1041. } else {
  1042. mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
  1043. }
  1044. mb[3] |= nv->bus[bus].target[target].sync_period;
  1045. status = qla1280_mailbox_command(ha, mr, mb);
  1046. /* Set Device Queue Parameters. */
  1047. for (lun = 0; lun < MAX_LUNS; lun++) {
  1048. mb[0] = MBC_SET_DEVICE_QUEUE;
  1049. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1050. mb[1] |= lun;
  1051. mb[2] = nv->bus[bus].max_queue_depth;
  1052. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1053. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1054. }
  1055. if (status)
  1056. printk(KERN_WARNING "scsi(%ld:%i:%i): "
  1057. "qla1280_set_target_parameters() failed\n",
  1058. ha->host_no, bus, target);
  1059. return status;
  1060. }
  1061. /**************************************************************************
  1062. * qla1280_slave_configure
  1063. *
  1064. * Description:
  1065. * Determines the queue depth for a given device. There are two ways
  1066. * a queue depth can be obtained for a tagged queueing device. One
  1067. * way is the default queue depth which is determined by whether
  1068. * If it is defined, then it is used
  1069. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  1070. * default queue depth (dependent on the number of hardware SCBs).
  1071. **************************************************************************/
  1072. static int
  1073. qla1280_slave_configure(struct scsi_device *device)
  1074. {
  1075. struct scsi_qla_host *ha;
  1076. int default_depth = 3;
  1077. int bus = device->channel;
  1078. int target = device->id;
  1079. int status = 0;
  1080. struct nvram *nv;
  1081. unsigned long flags;
  1082. ha = (struct scsi_qla_host *)device->host->hostdata;
  1083. nv = &ha->nvram;
  1084. if (qla1280_check_for_dead_scsi_bus(ha, bus))
  1085. return 1;
  1086. if (device->tagged_supported &&
  1087. (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
  1088. scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
  1089. } else {
  1090. scsi_change_queue_depth(device, default_depth);
  1091. }
  1092. nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
  1093. nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
  1094. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
  1095. if (driver_setup.no_sync ||
  1096. (driver_setup.sync_mask &&
  1097. (~driver_setup.sync_mask & (1 << target))))
  1098. nv->bus[bus].target[target].parameter.enable_sync = 0;
  1099. if (driver_setup.no_wide ||
  1100. (driver_setup.wide_mask &&
  1101. (~driver_setup.wide_mask & (1 << target))))
  1102. nv->bus[bus].target[target].parameter.enable_wide = 0;
  1103. if (IS_ISP1x160(ha)) {
  1104. if (driver_setup.no_ppr ||
  1105. (driver_setup.ppr_mask &&
  1106. (~driver_setup.ppr_mask & (1 << target))))
  1107. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
  1108. }
  1109. spin_lock_irqsave(ha->host->host_lock, flags);
  1110. if (nv->bus[bus].target[target].parameter.enable_sync)
  1111. status = qla1280_set_target_parameters(ha, bus, target);
  1112. qla1280_get_target_parameters(ha, device);
  1113. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1114. return status;
  1115. }
  1116. /*
  1117. * qla1280_done
  1118. * Process completed commands.
  1119. *
  1120. * Input:
  1121. * ha = adapter block pointer.
  1122. */
  1123. static void
  1124. qla1280_done(struct scsi_qla_host *ha)
  1125. {
  1126. struct srb *sp;
  1127. struct list_head *done_q;
  1128. int bus, target, lun;
  1129. struct scsi_cmnd *cmd;
  1130. ENTER("qla1280_done");
  1131. done_q = &ha->done_q;
  1132. while (!list_empty(done_q)) {
  1133. sp = list_entry(done_q->next, struct srb, list);
  1134. list_del(&sp->list);
  1135. cmd = sp->cmd;
  1136. bus = SCSI_BUS_32(cmd);
  1137. target = SCSI_TCN_32(cmd);
  1138. lun = SCSI_LUN_32(cmd);
  1139. switch ((CMD_RESULT(cmd) >> 16)) {
  1140. case DID_RESET:
  1141. /* Issue marker command. */
  1142. if (!ha->flags.abort_isp_active)
  1143. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  1144. break;
  1145. case DID_ABORT:
  1146. sp->flags &= ~SRB_ABORT_PENDING;
  1147. sp->flags |= SRB_ABORTED;
  1148. break;
  1149. default:
  1150. break;
  1151. }
  1152. /* Release memory used for this I/O */
  1153. scsi_dma_unmap(cmd);
  1154. /* Call the mid-level driver interrupt handler */
  1155. ha->actthreads--;
  1156. if (sp->wait == NULL)
  1157. (*(cmd)->scsi_done)(cmd);
  1158. else
  1159. complete(sp->wait);
  1160. }
  1161. LEAVE("qla1280_done");
  1162. }
  1163. /*
  1164. * Translates a ISP error to a Linux SCSI error
  1165. */
  1166. static int
  1167. qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
  1168. {
  1169. int host_status = DID_ERROR;
  1170. uint16_t comp_status = le16_to_cpu(sts->comp_status);
  1171. uint16_t state_flags = le16_to_cpu(sts->state_flags);
  1172. uint32_t residual_length = le32_to_cpu(sts->residual_length);
  1173. uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
  1174. #if DEBUG_QLA1280_INTR
  1175. static char *reason[] = {
  1176. "DID_OK",
  1177. "DID_NO_CONNECT",
  1178. "DID_BUS_BUSY",
  1179. "DID_TIME_OUT",
  1180. "DID_BAD_TARGET",
  1181. "DID_ABORT",
  1182. "DID_PARITY",
  1183. "DID_ERROR",
  1184. "DID_RESET",
  1185. "DID_BAD_INTR"
  1186. };
  1187. #endif /* DEBUG_QLA1280_INTR */
  1188. ENTER("qla1280_return_status");
  1189. #if DEBUG_QLA1280_INTR
  1190. /*
  1191. dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
  1192. comp_status);
  1193. */
  1194. #endif
  1195. switch (comp_status) {
  1196. case CS_COMPLETE:
  1197. host_status = DID_OK;
  1198. break;
  1199. case CS_INCOMPLETE:
  1200. if (!(state_flags & SF_GOT_BUS))
  1201. host_status = DID_NO_CONNECT;
  1202. else if (!(state_flags & SF_GOT_TARGET))
  1203. host_status = DID_BAD_TARGET;
  1204. else if (!(state_flags & SF_SENT_CDB))
  1205. host_status = DID_ERROR;
  1206. else if (!(state_flags & SF_TRANSFERRED_DATA))
  1207. host_status = DID_ERROR;
  1208. else if (!(state_flags & SF_GOT_STATUS))
  1209. host_status = DID_ERROR;
  1210. else if (!(state_flags & SF_GOT_SENSE))
  1211. host_status = DID_ERROR;
  1212. break;
  1213. case CS_RESET:
  1214. host_status = DID_RESET;
  1215. break;
  1216. case CS_ABORTED:
  1217. host_status = DID_ABORT;
  1218. break;
  1219. case CS_TIMEOUT:
  1220. host_status = DID_TIME_OUT;
  1221. break;
  1222. case CS_DATA_OVERRUN:
  1223. dprintk(2, "Data overrun 0x%x\n", residual_length);
  1224. dprintk(2, "qla1280_return_status: response packet data\n");
  1225. qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
  1226. host_status = DID_ERROR;
  1227. break;
  1228. case CS_DATA_UNDERRUN:
  1229. if ((scsi_bufflen(cp) - residual_length) <
  1230. cp->underflow) {
  1231. printk(KERN_WARNING
  1232. "scsi: Underflow detected - retrying "
  1233. "command.\n");
  1234. host_status = DID_ERROR;
  1235. } else {
  1236. scsi_set_resid(cp, residual_length);
  1237. host_status = DID_OK;
  1238. }
  1239. break;
  1240. default:
  1241. host_status = DID_ERROR;
  1242. break;
  1243. }
  1244. #if DEBUG_QLA1280_INTR
  1245. dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
  1246. reason[host_status], scsi_status);
  1247. #endif
  1248. LEAVE("qla1280_return_status");
  1249. return (scsi_status & 0xff) | (host_status << 16);
  1250. }
  1251. /****************************************************************************/
  1252. /* QLogic ISP1280 Hardware Support Functions. */
  1253. /****************************************************************************/
  1254. /*
  1255. * qla1280_initialize_adapter
  1256. * Initialize board.
  1257. *
  1258. * Input:
  1259. * ha = adapter block pointer.
  1260. *
  1261. * Returns:
  1262. * 0 = success
  1263. */
  1264. static int
  1265. qla1280_initialize_adapter(struct scsi_qla_host *ha)
  1266. {
  1267. struct device_reg __iomem *reg;
  1268. int status;
  1269. int bus;
  1270. unsigned long flags;
  1271. ENTER("qla1280_initialize_adapter");
  1272. /* Clear adapter flags. */
  1273. ha->flags.online = 0;
  1274. ha->flags.disable_host_adapter = 0;
  1275. ha->flags.reset_active = 0;
  1276. ha->flags.abort_isp_active = 0;
  1277. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1278. if (ia64_platform_is("sn2")) {
  1279. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1280. "dual channel lockup workaround\n", ha->host_no);
  1281. ha->flags.use_pci_vchannel = 1;
  1282. driver_setup.no_nvram = 1;
  1283. }
  1284. #endif
  1285. /* TODO: implement support for the 1040 nvram format */
  1286. if (IS_ISP1040(ha))
  1287. driver_setup.no_nvram = 1;
  1288. dprintk(1, "Configure PCI space for adapter...\n");
  1289. reg = ha->iobase;
  1290. /* Insure mailbox registers are free. */
  1291. WRT_REG_WORD(&reg->semaphore, 0);
  1292. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  1293. WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
  1294. RD_REG_WORD(&reg->host_cmd);
  1295. if (qla1280_read_nvram(ha)) {
  1296. dprintk(2, "qla1280_initialize_adapter: failed to read "
  1297. "NVRAM\n");
  1298. }
  1299. /*
  1300. * It's necessary to grab the spin here as qla1280_mailbox_command
  1301. * needs to be able to drop the lock unconditionally to wait
  1302. * for completion.
  1303. */
  1304. spin_lock_irqsave(ha->host->host_lock, flags);
  1305. status = qla1280_load_firmware(ha);
  1306. if (status) {
  1307. printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
  1308. ha->host_no);
  1309. goto out;
  1310. }
  1311. /* Setup adapter based on NVRAM parameters. */
  1312. dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
  1313. qla1280_nvram_config(ha);
  1314. if (ha->flags.disable_host_adapter) {
  1315. status = 1;
  1316. goto out;
  1317. }
  1318. status = qla1280_init_rings(ha);
  1319. if (status)
  1320. goto out;
  1321. /* Issue SCSI reset, if we can't reset twice then bus is dead */
  1322. for (bus = 0; bus < ha->ports; bus++) {
  1323. if (!ha->bus_settings[bus].disable_scsi_reset &&
  1324. qla1280_bus_reset(ha, bus) &&
  1325. qla1280_bus_reset(ha, bus))
  1326. ha->bus_settings[bus].scsi_bus_dead = 1;
  1327. }
  1328. ha->flags.online = 1;
  1329. out:
  1330. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1331. if (status)
  1332. dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
  1333. LEAVE("qla1280_initialize_adapter");
  1334. return status;
  1335. }
  1336. /*
  1337. * qla1280_request_firmware
  1338. * Acquire firmware for chip. Retain in memory
  1339. * for error recovery.
  1340. *
  1341. * Input:
  1342. * ha = adapter block pointer.
  1343. *
  1344. * Returns:
  1345. * Pointer to firmware image or an error code
  1346. * cast to pointer via ERR_PTR().
  1347. */
  1348. static const struct firmware *
  1349. qla1280_request_firmware(struct scsi_qla_host *ha)
  1350. {
  1351. const struct firmware *fw;
  1352. int err;
  1353. int index;
  1354. char *fwname;
  1355. spin_unlock_irq(ha->host->host_lock);
  1356. mutex_lock(&qla1280_firmware_mutex);
  1357. index = ql1280_board_tbl[ha->devnum].fw_index;
  1358. fw = qla1280_fw_tbl[index].fw;
  1359. if (fw)
  1360. goto out;
  1361. fwname = qla1280_fw_tbl[index].fwname;
  1362. err = request_firmware(&fw, fwname, &ha->pdev->dev);
  1363. if (err) {
  1364. printk(KERN_ERR "Failed to load image \"%s\" err %d\n",
  1365. fwname, err);
  1366. fw = ERR_PTR(err);
  1367. goto unlock;
  1368. }
  1369. if ((fw->size % 2) || (fw->size < 6)) {
  1370. printk(KERN_ERR "Invalid firmware length %zu in image \"%s\"\n",
  1371. fw->size, fwname);
  1372. release_firmware(fw);
  1373. fw = ERR_PTR(-EINVAL);
  1374. goto unlock;
  1375. }
  1376. qla1280_fw_tbl[index].fw = fw;
  1377. out:
  1378. ha->fwver1 = fw->data[0];
  1379. ha->fwver2 = fw->data[1];
  1380. ha->fwver3 = fw->data[2];
  1381. unlock:
  1382. mutex_unlock(&qla1280_firmware_mutex);
  1383. spin_lock_irq(ha->host->host_lock);
  1384. return fw;
  1385. }
  1386. /*
  1387. * Chip diagnostics
  1388. * Test chip for proper operation.
  1389. *
  1390. * Input:
  1391. * ha = adapter block pointer.
  1392. *
  1393. * Returns:
  1394. * 0 = success.
  1395. */
  1396. static int
  1397. qla1280_chip_diag(struct scsi_qla_host *ha)
  1398. {
  1399. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1400. struct device_reg __iomem *reg = ha->iobase;
  1401. int status = 0;
  1402. int cnt;
  1403. uint16_t data;
  1404. dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", &reg->id_l);
  1405. dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
  1406. /* Soft reset chip and wait for it to finish. */
  1407. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  1408. /*
  1409. * We can't do a traditional PCI write flush here by reading
  1410. * back the register. The card will not respond once the reset
  1411. * is in action and we end up with a machine check exception
  1412. * instead. Nothing to do but wait and hope for the best.
  1413. * A portable pci_write_flush(pdev) call would be very useful here.
  1414. */
  1415. udelay(20);
  1416. data = qla1280_debounce_register(&reg->ictrl);
  1417. /*
  1418. * Yet another QLogic gem ;-(
  1419. */
  1420. for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
  1421. udelay(5);
  1422. data = RD_REG_WORD(&reg->ictrl);
  1423. }
  1424. if (!cnt)
  1425. goto fail;
  1426. /* Reset register cleared by chip reset. */
  1427. dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
  1428. WRT_REG_WORD(&reg->cfg_1, 0);
  1429. /* Reset RISC and disable BIOS which
  1430. allows RISC to execute out of RAM. */
  1431. WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC |
  1432. HC_RELEASE_RISC | HC_DISABLE_BIOS);
  1433. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1434. data = qla1280_debounce_register(&reg->mailbox0);
  1435. /*
  1436. * I *LOVE* this code!
  1437. */
  1438. for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
  1439. udelay(5);
  1440. data = RD_REG_WORD(&reg->mailbox0);
  1441. }
  1442. if (!cnt)
  1443. goto fail;
  1444. /* Check product ID of chip */
  1445. dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
  1446. if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
  1447. (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
  1448. RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
  1449. RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
  1450. RD_REG_WORD(&reg->mailbox4) != PROD_ID_4) {
  1451. printk(KERN_INFO "qla1280: Wrong product ID = "
  1452. "0x%x,0x%x,0x%x,0x%x\n",
  1453. RD_REG_WORD(&reg->mailbox1),
  1454. RD_REG_WORD(&reg->mailbox2),
  1455. RD_REG_WORD(&reg->mailbox3),
  1456. RD_REG_WORD(&reg->mailbox4));
  1457. goto fail;
  1458. }
  1459. /*
  1460. * Enable ints early!!!
  1461. */
  1462. qla1280_enable_intrs(ha);
  1463. dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
  1464. /* Wrap Incoming Mailboxes Test. */
  1465. mb[0] = MBC_MAILBOX_REGISTER_TEST;
  1466. mb[1] = 0xAAAA;
  1467. mb[2] = 0x5555;
  1468. mb[3] = 0xAA55;
  1469. mb[4] = 0x55AA;
  1470. mb[5] = 0xA5A5;
  1471. mb[6] = 0x5A5A;
  1472. mb[7] = 0x2525;
  1473. status = qla1280_mailbox_command(ha, 0xff, mb);
  1474. if (status)
  1475. goto fail;
  1476. if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
  1477. mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
  1478. mb[7] != 0x2525) {
  1479. printk(KERN_INFO "qla1280: Failed mbox check\n");
  1480. goto fail;
  1481. }
  1482. dprintk(3, "qla1280_chip_diag: exiting normally\n");
  1483. return 0;
  1484. fail:
  1485. dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
  1486. return status;
  1487. }
  1488. static int
  1489. qla1280_load_firmware_pio(struct scsi_qla_host *ha)
  1490. {
  1491. /* enter with host_lock acquired */
  1492. const struct firmware *fw;
  1493. const __le16 *fw_data;
  1494. uint16_t risc_address, risc_code_size;
  1495. uint16_t mb[MAILBOX_REGISTER_COUNT], i;
  1496. int err = 0;
  1497. fw = qla1280_request_firmware(ha);
  1498. if (IS_ERR(fw))
  1499. return PTR_ERR(fw);
  1500. fw_data = (const __le16 *)&fw->data[0];
  1501. ha->fwstart = __le16_to_cpu(fw_data[2]);
  1502. /* Load RISC code. */
  1503. risc_address = ha->fwstart;
  1504. fw_data = (const __le16 *)&fw->data[6];
  1505. risc_code_size = (fw->size - 6) / 2;
  1506. for (i = 0; i < risc_code_size; i++) {
  1507. mb[0] = MBC_WRITE_RAM_WORD;
  1508. mb[1] = risc_address + i;
  1509. mb[2] = __le16_to_cpu(fw_data[i]);
  1510. err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
  1511. if (err) {
  1512. printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
  1513. ha->host_no);
  1514. break;
  1515. }
  1516. }
  1517. return err;
  1518. }
  1519. #define DUMP_IT_BACK 0 /* for debug of RISC loading */
  1520. static int
  1521. qla1280_load_firmware_dma(struct scsi_qla_host *ha)
  1522. {
  1523. /* enter with host_lock acquired */
  1524. const struct firmware *fw;
  1525. const __le16 *fw_data;
  1526. uint16_t risc_address, risc_code_size;
  1527. uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
  1528. int err = 0, num, i;
  1529. #if DUMP_IT_BACK
  1530. uint8_t *sp, *tbuf;
  1531. dma_addr_t p_tbuf;
  1532. tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
  1533. if (!tbuf)
  1534. return -ENOMEM;
  1535. #endif
  1536. fw = qla1280_request_firmware(ha);
  1537. if (IS_ERR(fw))
  1538. return PTR_ERR(fw);
  1539. fw_data = (const __le16 *)&fw->data[0];
  1540. ha->fwstart = __le16_to_cpu(fw_data[2]);
  1541. /* Load RISC code. */
  1542. risc_address = ha->fwstart;
  1543. fw_data = (const __le16 *)&fw->data[6];
  1544. risc_code_size = (fw->size - 6) / 2;
  1545. dprintk(1, "%s: DMA RISC code (%i) words\n",
  1546. __func__, risc_code_size);
  1547. num = 0;
  1548. while (risc_code_size > 0) {
  1549. int warn __attribute__((unused)) = 0;
  1550. cnt = 2000 >> 1;
  1551. if (cnt > risc_code_size)
  1552. cnt = risc_code_size;
  1553. dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
  1554. "%d,%d(0x%x)\n",
  1555. fw_data, cnt, num, risc_address);
  1556. for(i = 0; i < cnt; i++)
  1557. ((__le16 *)ha->request_ring)[i] = fw_data[i];
  1558. mb[0] = MBC_LOAD_RAM;
  1559. mb[1] = risc_address;
  1560. mb[4] = cnt;
  1561. mb[3] = ha->request_dma & 0xffff;
  1562. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1563. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1564. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1565. dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
  1566. __func__, mb[0],
  1567. (void *)(long)ha->request_dma,
  1568. mb[6], mb[7], mb[2], mb[3]);
  1569. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1570. BIT_1 | BIT_0, mb);
  1571. if (err) {
  1572. printk(KERN_ERR "scsi(%li): Failed to load partial "
  1573. "segment of f\n", ha->host_no);
  1574. goto out;
  1575. }
  1576. #if DUMP_IT_BACK
  1577. mb[0] = MBC_DUMP_RAM;
  1578. mb[1] = risc_address;
  1579. mb[4] = cnt;
  1580. mb[3] = p_tbuf & 0xffff;
  1581. mb[2] = (p_tbuf >> 16) & 0xffff;
  1582. mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
  1583. mb[6] = pci_dma_hi32(p_tbuf) >> 16;
  1584. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1585. BIT_1 | BIT_0, mb);
  1586. if (err) {
  1587. printk(KERN_ERR
  1588. "Failed to dump partial segment of f/w\n");
  1589. goto out;
  1590. }
  1591. sp = (uint8_t *)ha->request_ring;
  1592. for (i = 0; i < (cnt << 1); i++) {
  1593. if (tbuf[i] != sp[i] && warn++ < 10) {
  1594. printk(KERN_ERR "%s: FW compare error @ "
  1595. "byte(0x%x) loop#=%x\n",
  1596. __func__, i, num);
  1597. printk(KERN_ERR "%s: FWbyte=%x "
  1598. "FWfromChip=%x\n",
  1599. __func__, sp[i], tbuf[i]);
  1600. /*break; */
  1601. }
  1602. }
  1603. #endif
  1604. risc_address += cnt;
  1605. risc_code_size = risc_code_size - cnt;
  1606. fw_data = fw_data + cnt;
  1607. num++;
  1608. }
  1609. out:
  1610. #if DUMP_IT_BACK
  1611. pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
  1612. #endif
  1613. return err;
  1614. }
  1615. static int
  1616. qla1280_start_firmware(struct scsi_qla_host *ha)
  1617. {
  1618. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1619. int err;
  1620. dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
  1621. __func__);
  1622. /* Verify checksum of loaded RISC code. */
  1623. mb[0] = MBC_VERIFY_CHECKSUM;
  1624. /* mb[1] = ql12_risc_code_addr01; */
  1625. mb[1] = ha->fwstart;
  1626. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1627. if (err) {
  1628. printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
  1629. return err;
  1630. }
  1631. /* Start firmware execution. */
  1632. dprintk(1, "%s: start firmware running.\n", __func__);
  1633. mb[0] = MBC_EXECUTE_FIRMWARE;
  1634. mb[1] = ha->fwstart;
  1635. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1636. if (err) {
  1637. printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
  1638. ha->host_no);
  1639. }
  1640. return err;
  1641. }
  1642. static int
  1643. qla1280_load_firmware(struct scsi_qla_host *ha)
  1644. {
  1645. /* enter with host_lock taken */
  1646. int err;
  1647. err = qla1280_chip_diag(ha);
  1648. if (err)
  1649. goto out;
  1650. if (IS_ISP1040(ha))
  1651. err = qla1280_load_firmware_pio(ha);
  1652. else
  1653. err = qla1280_load_firmware_dma(ha);
  1654. if (err)
  1655. goto out;
  1656. err = qla1280_start_firmware(ha);
  1657. out:
  1658. return err;
  1659. }
  1660. /*
  1661. * Initialize rings
  1662. *
  1663. * Input:
  1664. * ha = adapter block pointer.
  1665. * ha->request_ring = request ring virtual address
  1666. * ha->response_ring = response ring virtual address
  1667. * ha->request_dma = request ring physical address
  1668. * ha->response_dma = response ring physical address
  1669. *
  1670. * Returns:
  1671. * 0 = success.
  1672. */
  1673. static int
  1674. qla1280_init_rings(struct scsi_qla_host *ha)
  1675. {
  1676. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1677. int status = 0;
  1678. ENTER("qla1280_init_rings");
  1679. /* Clear outstanding commands array. */
  1680. memset(ha->outstanding_cmds, 0,
  1681. sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
  1682. /* Initialize request queue. */
  1683. ha->request_ring_ptr = ha->request_ring;
  1684. ha->req_ring_index = 0;
  1685. ha->req_q_cnt = REQUEST_ENTRY_CNT;
  1686. /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
  1687. mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
  1688. mb[1] = REQUEST_ENTRY_CNT;
  1689. mb[3] = ha->request_dma & 0xffff;
  1690. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1691. mb[4] = 0;
  1692. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1693. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1694. if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
  1695. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1696. &mb[0]))) {
  1697. /* Initialize response queue. */
  1698. ha->response_ring_ptr = ha->response_ring;
  1699. ha->rsp_ring_index = 0;
  1700. /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
  1701. mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
  1702. mb[1] = RESPONSE_ENTRY_CNT;
  1703. mb[3] = ha->response_dma & 0xffff;
  1704. mb[2] = (ha->response_dma >> 16) & 0xffff;
  1705. mb[5] = 0;
  1706. mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
  1707. mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
  1708. status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
  1709. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1710. &mb[0]);
  1711. }
  1712. if (status)
  1713. dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
  1714. LEAVE("qla1280_init_rings");
  1715. return status;
  1716. }
  1717. static void
  1718. qla1280_print_settings(struct nvram *nv)
  1719. {
  1720. dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
  1721. nv->bus[0].config_1.initiator_id);
  1722. dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
  1723. nv->bus[1].config_1.initiator_id);
  1724. dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
  1725. nv->bus[0].bus_reset_delay);
  1726. dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
  1727. nv->bus[1].bus_reset_delay);
  1728. dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
  1729. dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
  1730. dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
  1731. dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
  1732. dprintk(1, "qla1280 : async data setup time[0]=%d\n",
  1733. nv->bus[0].config_2.async_data_setup_time);
  1734. dprintk(1, "qla1280 : async data setup time[1]=%d\n",
  1735. nv->bus[1].config_2.async_data_setup_time);
  1736. dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
  1737. nv->bus[0].config_2.req_ack_active_negation);
  1738. dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
  1739. nv->bus[1].config_2.req_ack_active_negation);
  1740. dprintk(1, "qla1280 : data line active negation[0]=%d\n",
  1741. nv->bus[0].config_2.data_line_active_negation);
  1742. dprintk(1, "qla1280 : data line active negation[1]=%d\n",
  1743. nv->bus[1].config_2.data_line_active_negation);
  1744. dprintk(1, "qla1280 : disable loading risc code=%d\n",
  1745. nv->cntr_flags_1.disable_loading_risc_code);
  1746. dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
  1747. nv->cntr_flags_1.enable_64bit_addressing);
  1748. dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
  1749. nv->bus[0].selection_timeout);
  1750. dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
  1751. nv->bus[1].selection_timeout);
  1752. dprintk(1, "qla1280 : max queue depth[0]=%d\n",
  1753. nv->bus[0].max_queue_depth);
  1754. dprintk(1, "qla1280 : max queue depth[1]=%d\n",
  1755. nv->bus[1].max_queue_depth);
  1756. }
  1757. static void
  1758. qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
  1759. {
  1760. struct nvram *nv = &ha->nvram;
  1761. nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
  1762. nv->bus[bus].target[target].parameter.auto_request_sense = 1;
  1763. nv->bus[bus].target[target].parameter.tag_queuing = 1;
  1764. nv->bus[bus].target[target].parameter.enable_sync = 1;
  1765. #if 1 /* Some SCSI Processors do not seem to like this */
  1766. nv->bus[bus].target[target].parameter.enable_wide = 1;
  1767. #endif
  1768. nv->bus[bus].target[target].execution_throttle =
  1769. nv->bus[bus].max_queue_depth - 1;
  1770. nv->bus[bus].target[target].parameter.parity_checking = 1;
  1771. nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
  1772. if (IS_ISP1x160(ha)) {
  1773. nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
  1774. nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
  1775. nv->bus[bus].target[target].sync_period = 9;
  1776. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
  1777. nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
  1778. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
  1779. } else {
  1780. nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
  1781. nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
  1782. nv->bus[bus].target[target].sync_period = 10;
  1783. }
  1784. }
  1785. static void
  1786. qla1280_set_defaults(struct scsi_qla_host *ha)
  1787. {
  1788. struct nvram *nv = &ha->nvram;
  1789. int bus, target;
  1790. dprintk(1, "Using defaults for NVRAM: \n");
  1791. memset(nv, 0, sizeof(struct nvram));
  1792. /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
  1793. nv->firmware_feature.f.enable_fast_posting = 1;
  1794. nv->firmware_feature.f.disable_synchronous_backoff = 1;
  1795. nv->termination.scsi_bus_0_control = 3;
  1796. nv->termination.scsi_bus_1_control = 3;
  1797. nv->termination.auto_term_support = 1;
  1798. /*
  1799. * Set default FIFO magic - What appropriate values would be here
  1800. * is unknown. This is what I have found testing with 12160s.
  1801. *
  1802. * Now, I would love the magic decoder ring for this one, the
  1803. * header file provided by QLogic seems to be bogus or incomplete
  1804. * at best.
  1805. */
  1806. nv->isp_config.burst_enable = 1;
  1807. if (IS_ISP1040(ha))
  1808. nv->isp_config.fifo_threshold |= 3;
  1809. else
  1810. nv->isp_config.fifo_threshold |= 4;
  1811. if (IS_ISP1x160(ha))
  1812. nv->isp_parameter = 0x01; /* fast memory enable */
  1813. for (bus = 0; bus < MAX_BUSES; bus++) {
  1814. nv->bus[bus].config_1.initiator_id = 7;
  1815. nv->bus[bus].config_2.req_ack_active_negation = 1;
  1816. nv->bus[bus].config_2.data_line_active_negation = 1;
  1817. nv->bus[bus].selection_timeout = 250;
  1818. nv->bus[bus].max_queue_depth = 32;
  1819. if (IS_ISP1040(ha)) {
  1820. nv->bus[bus].bus_reset_delay = 3;
  1821. nv->bus[bus].config_2.async_data_setup_time = 6;
  1822. nv->bus[bus].retry_delay = 1;
  1823. } else {
  1824. nv->bus[bus].bus_reset_delay = 5;
  1825. nv->bus[bus].config_2.async_data_setup_time = 8;
  1826. }
  1827. for (target = 0; target < MAX_TARGETS; target++)
  1828. qla1280_set_target_defaults(ha, bus, target);
  1829. }
  1830. }
  1831. static int
  1832. qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
  1833. {
  1834. struct nvram *nv = &ha->nvram;
  1835. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1836. int status, lun;
  1837. uint16_t flag;
  1838. /* Set Target Parameters. */
  1839. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1840. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1841. /*
  1842. * Do not enable sync and ppr for the initial INQUIRY run. We
  1843. * enable this later if we determine the target actually
  1844. * supports it.
  1845. */
  1846. mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
  1847. | TP_WIDE | TP_PARITY | TP_DISCONNECT);
  1848. if (IS_ISP1x160(ha))
  1849. mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
  1850. else
  1851. mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
  1852. mb[3] |= nv->bus[bus].target[target].sync_period;
  1853. status = qla1280_mailbox_command(ha, 0x0f, mb);
  1854. /* Save Tag queuing enable flag. */
  1855. flag = (BIT_0 << target);
  1856. if (nv->bus[bus].target[target].parameter.tag_queuing)
  1857. ha->bus_settings[bus].qtag_enables |= flag;
  1858. /* Save Device enable flag. */
  1859. if (IS_ISP1x160(ha)) {
  1860. if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
  1861. ha->bus_settings[bus].device_enables |= flag;
  1862. ha->bus_settings[bus].lun_disables |= 0;
  1863. } else {
  1864. if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
  1865. ha->bus_settings[bus].device_enables |= flag;
  1866. /* Save LUN disable flag. */
  1867. if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
  1868. ha->bus_settings[bus].lun_disables |= flag;
  1869. }
  1870. /* Set Device Queue Parameters. */
  1871. for (lun = 0; lun < MAX_LUNS; lun++) {
  1872. mb[0] = MBC_SET_DEVICE_QUEUE;
  1873. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1874. mb[1] |= lun;
  1875. mb[2] = nv->bus[bus].max_queue_depth;
  1876. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1877. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1878. }
  1879. return status;
  1880. }
  1881. static int
  1882. qla1280_config_bus(struct scsi_qla_host *ha, int bus)
  1883. {
  1884. struct nvram *nv = &ha->nvram;
  1885. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1886. int target, status;
  1887. /* SCSI Reset Disable. */
  1888. ha->bus_settings[bus].disable_scsi_reset =
  1889. nv->bus[bus].config_1.scsi_reset_disable;
  1890. /* Initiator ID. */
  1891. ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
  1892. mb[0] = MBC_SET_INITIATOR_ID;
  1893. mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
  1894. ha->bus_settings[bus].id;
  1895. status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1896. /* Reset Delay. */
  1897. ha->bus_settings[bus].bus_reset_delay =
  1898. nv->bus[bus].bus_reset_delay;
  1899. /* Command queue depth per device. */
  1900. ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
  1901. /* Set target parameters. */
  1902. for (target = 0; target < MAX_TARGETS; target++)
  1903. status |= qla1280_config_target(ha, bus, target);
  1904. return status;
  1905. }
  1906. static int
  1907. qla1280_nvram_config(struct scsi_qla_host *ha)
  1908. {
  1909. struct device_reg __iomem *reg = ha->iobase;
  1910. struct nvram *nv = &ha->nvram;
  1911. int bus, target, status = 0;
  1912. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1913. ENTER("qla1280_nvram_config");
  1914. if (ha->nvram_valid) {
  1915. /* Always force AUTO sense for LINUX SCSI */
  1916. for (bus = 0; bus < MAX_BUSES; bus++)
  1917. for (target = 0; target < MAX_TARGETS; target++) {
  1918. nv->bus[bus].target[target].parameter.
  1919. auto_request_sense = 1;
  1920. }
  1921. } else {
  1922. qla1280_set_defaults(ha);
  1923. }
  1924. qla1280_print_settings(nv);
  1925. /* Disable RISC load of firmware. */
  1926. ha->flags.disable_risc_code_load =
  1927. nv->cntr_flags_1.disable_loading_risc_code;
  1928. if (IS_ISP1040(ha)) {
  1929. uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
  1930. hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK;
  1931. cfg1 = RD_REG_WORD(&reg->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
  1932. cdma_conf = RD_REG_WORD(&reg->cdma_cfg);
  1933. ddma_conf = RD_REG_WORD(&reg->ddma_cfg);
  1934. /* Busted fifo, says mjacob. */
  1935. if (hwrev != ISP_CFG0_1040A)
  1936. cfg1 |= nv->isp_config.fifo_threshold << 4;
  1937. cfg1 |= nv->isp_config.burst_enable << 2;
  1938. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1939. WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
  1940. WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
  1941. } else {
  1942. uint16_t cfg1, term;
  1943. /* Set ISP hardware DMA burst */
  1944. cfg1 = nv->isp_config.fifo_threshold << 4;
  1945. cfg1 |= nv->isp_config.burst_enable << 2;
  1946. /* Enable DMA arbitration on dual channel controllers */
  1947. if (ha->ports > 1)
  1948. cfg1 |= BIT_13;
  1949. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1950. /* Set SCSI termination. */
  1951. WRT_REG_WORD(&reg->gpio_enable,
  1952. BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1953. term = nv->termination.scsi_bus_1_control;
  1954. term |= nv->termination.scsi_bus_0_control << 2;
  1955. term |= nv->termination.auto_term_support << 7;
  1956. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1957. WRT_REG_WORD(&reg->gpio_data, term);
  1958. }
  1959. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1960. /* ISP parameter word. */
  1961. mb[0] = MBC_SET_SYSTEM_PARAMETER;
  1962. mb[1] = nv->isp_parameter;
  1963. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1964. if (IS_ISP1x40(ha)) {
  1965. /* clock rate - for qla1240 and older, only */
  1966. mb[0] = MBC_SET_CLOCK_RATE;
  1967. mb[1] = 40;
  1968. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1969. }
  1970. /* Firmware feature word. */
  1971. mb[0] = MBC_SET_FIRMWARE_FEATURES;
  1972. mb[1] = nv->firmware_feature.f.enable_fast_posting;
  1973. mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
  1974. mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
  1975. #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
  1976. if (ia64_platform_is("sn2")) {
  1977. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1978. "workaround\n", ha->host_no);
  1979. mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
  1980. }
  1981. #endif
  1982. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1983. /* Retry count and delay. */
  1984. mb[0] = MBC_SET_RETRY_COUNT;
  1985. mb[1] = nv->bus[0].retry_count;
  1986. mb[2] = nv->bus[0].retry_delay;
  1987. mb[6] = nv->bus[1].retry_count;
  1988. mb[7] = nv->bus[1].retry_delay;
  1989. status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
  1990. BIT_1 | BIT_0, &mb[0]);
  1991. /* ASYNC data setup time. */
  1992. mb[0] = MBC_SET_ASYNC_DATA_SETUP;
  1993. mb[1] = nv->bus[0].config_2.async_data_setup_time;
  1994. mb[2] = nv->bus[1].config_2.async_data_setup_time;
  1995. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  1996. /* Active negation states. */
  1997. mb[0] = MBC_SET_ACTIVE_NEGATION;
  1998. mb[1] = 0;
  1999. if (nv->bus[0].config_2.req_ack_active_negation)
  2000. mb[1] |= BIT_5;
  2001. if (nv->bus[0].config_2.data_line_active_negation)
  2002. mb[1] |= BIT_4;
  2003. mb[2] = 0;
  2004. if (nv->bus[1].config_2.req_ack_active_negation)
  2005. mb[2] |= BIT_5;
  2006. if (nv->bus[1].config_2.data_line_active_negation)
  2007. mb[2] |= BIT_4;
  2008. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2009. mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
  2010. mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
  2011. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  2012. /* thingy */
  2013. mb[0] = MBC_SET_PCI_CONTROL;
  2014. mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
  2015. mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
  2016. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2017. mb[0] = MBC_SET_TAG_AGE_LIMIT;
  2018. mb[1] = 8;
  2019. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  2020. /* Selection timeout. */
  2021. mb[0] = MBC_SET_SELECTION_TIMEOUT;
  2022. mb[1] = nv->bus[0].selection_timeout;
  2023. mb[2] = nv->bus[1].selection_timeout;
  2024. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2025. for (bus = 0; bus < ha->ports; bus++)
  2026. status |= qla1280_config_bus(ha, bus);
  2027. if (status)
  2028. dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
  2029. LEAVE("qla1280_nvram_config");
  2030. return status;
  2031. }
  2032. /*
  2033. * Get NVRAM data word
  2034. * Calculates word position in NVRAM and calls request routine to
  2035. * get the word from NVRAM.
  2036. *
  2037. * Input:
  2038. * ha = adapter block pointer.
  2039. * address = NVRAM word address.
  2040. *
  2041. * Returns:
  2042. * data word.
  2043. */
  2044. static uint16_t
  2045. qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
  2046. {
  2047. uint32_t nv_cmd;
  2048. uint16_t data;
  2049. nv_cmd = address << 16;
  2050. nv_cmd |= NV_READ_OP;
  2051. data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
  2052. dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
  2053. "0x%x", data);
  2054. return data;
  2055. }
  2056. /*
  2057. * NVRAM request
  2058. * Sends read command to NVRAM and gets data from NVRAM.
  2059. *
  2060. * Input:
  2061. * ha = adapter block pointer.
  2062. * nv_cmd = Bit 26 = start bit
  2063. * Bit 25, 24 = opcode
  2064. * Bit 23-16 = address
  2065. * Bit 15-0 = write data
  2066. *
  2067. * Returns:
  2068. * data word.
  2069. */
  2070. static uint16_t
  2071. qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
  2072. {
  2073. struct device_reg __iomem *reg = ha->iobase;
  2074. int cnt;
  2075. uint16_t data = 0;
  2076. uint16_t reg_data;
  2077. /* Send command to NVRAM. */
  2078. nv_cmd <<= 5;
  2079. for (cnt = 0; cnt < 11; cnt++) {
  2080. if (nv_cmd & BIT_31)
  2081. qla1280_nv_write(ha, NV_DATA_OUT);
  2082. else
  2083. qla1280_nv_write(ha, 0);
  2084. nv_cmd <<= 1;
  2085. }
  2086. /* Read data from NVRAM. */
  2087. for (cnt = 0; cnt < 16; cnt++) {
  2088. WRT_REG_WORD(&reg->nvram, (NV_SELECT | NV_CLOCK));
  2089. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2090. NVRAM_DELAY();
  2091. data <<= 1;
  2092. reg_data = RD_REG_WORD(&reg->nvram);
  2093. if (reg_data & NV_DATA_IN)
  2094. data |= BIT_0;
  2095. WRT_REG_WORD(&reg->nvram, NV_SELECT);
  2096. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2097. NVRAM_DELAY();
  2098. }
  2099. /* Deselect chip. */
  2100. WRT_REG_WORD(&reg->nvram, NV_DESELECT);
  2101. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2102. NVRAM_DELAY();
  2103. return data;
  2104. }
  2105. static void
  2106. qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
  2107. {
  2108. struct device_reg __iomem *reg = ha->iobase;
  2109. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2110. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2111. NVRAM_DELAY();
  2112. WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
  2113. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2114. NVRAM_DELAY();
  2115. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2116. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2117. NVRAM_DELAY();
  2118. }
  2119. /*
  2120. * Mailbox Command
  2121. * Issue mailbox command and waits for completion.
  2122. *
  2123. * Input:
  2124. * ha = adapter block pointer.
  2125. * mr = mailbox registers to load.
  2126. * mb = data pointer for mailbox registers.
  2127. *
  2128. * Output:
  2129. * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
  2130. *
  2131. * Returns:
  2132. * 0 = success
  2133. */
  2134. static int
  2135. qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
  2136. {
  2137. struct device_reg __iomem *reg = ha->iobase;
  2138. int status = 0;
  2139. int cnt;
  2140. uint16_t *optr, *iptr;
  2141. uint16_t __iomem *mptr;
  2142. uint16_t data;
  2143. DECLARE_COMPLETION_ONSTACK(wait);
  2144. struct timer_list timer;
  2145. ENTER("qla1280_mailbox_command");
  2146. if (ha->mailbox_wait) {
  2147. printk(KERN_ERR "Warning mailbox wait already in use!\n");
  2148. }
  2149. ha->mailbox_wait = &wait;
  2150. /*
  2151. * We really should start out by verifying that the mailbox is
  2152. * available before starting sending the command data
  2153. */
  2154. /* Load mailbox registers. */
  2155. mptr = (uint16_t __iomem *) &reg->mailbox0;
  2156. iptr = mb;
  2157. for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
  2158. if (mr & BIT_0) {
  2159. WRT_REG_WORD(mptr, (*iptr));
  2160. }
  2161. mr >>= 1;
  2162. mptr++;
  2163. iptr++;
  2164. }
  2165. /* Issue set host interrupt command. */
  2166. /* set up a timer just in case we're really jammed */
  2167. init_timer_on_stack(&timer);
  2168. timer.expires = jiffies + 20*HZ;
  2169. timer.data = (unsigned long)ha;
  2170. timer.function = qla1280_mailbox_timeout;
  2171. add_timer(&timer);
  2172. spin_unlock_irq(ha->host->host_lock);
  2173. WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
  2174. data = qla1280_debounce_register(&reg->istatus);
  2175. wait_for_completion(&wait);
  2176. del_timer_sync(&timer);
  2177. spin_lock_irq(ha->host->host_lock);
  2178. ha->mailbox_wait = NULL;
  2179. /* Check for mailbox command timeout. */
  2180. if (ha->mailbox_out[0] != MBS_CMD_CMP) {
  2181. printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
  2182. "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
  2183. "0x%04x\n",
  2184. mb[0], ha->mailbox_out[0], RD_REG_WORD(&reg->istatus));
  2185. printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
  2186. RD_REG_WORD(&reg->mailbox0), RD_REG_WORD(&reg->mailbox1),
  2187. RD_REG_WORD(&reg->mailbox2), RD_REG_WORD(&reg->mailbox3));
  2188. printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
  2189. RD_REG_WORD(&reg->mailbox4), RD_REG_WORD(&reg->mailbox5),
  2190. RD_REG_WORD(&reg->mailbox6), RD_REG_WORD(&reg->mailbox7));
  2191. status = 1;
  2192. }
  2193. /* Load return mailbox registers. */
  2194. optr = mb;
  2195. iptr = (uint16_t *) &ha->mailbox_out[0];
  2196. mr = MAILBOX_REGISTER_COUNT;
  2197. memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
  2198. if (ha->flags.reset_marker)
  2199. qla1280_rst_aen(ha);
  2200. if (status)
  2201. dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
  2202. "0x%x ****\n", mb[0]);
  2203. LEAVE("qla1280_mailbox_command");
  2204. return status;
  2205. }
  2206. /*
  2207. * qla1280_poll
  2208. * Polls ISP for interrupts.
  2209. *
  2210. * Input:
  2211. * ha = adapter block pointer.
  2212. */
  2213. static void
  2214. qla1280_poll(struct scsi_qla_host *ha)
  2215. {
  2216. struct device_reg __iomem *reg = ha->iobase;
  2217. uint16_t data;
  2218. LIST_HEAD(done_q);
  2219. /* ENTER("qla1280_poll"); */
  2220. /* Check for pending interrupts. */
  2221. data = RD_REG_WORD(&reg->istatus);
  2222. if (data & RISC_INT)
  2223. qla1280_isr(ha, &done_q);
  2224. if (!ha->mailbox_wait) {
  2225. if (ha->flags.reset_marker)
  2226. qla1280_rst_aen(ha);
  2227. }
  2228. if (!list_empty(&done_q))
  2229. qla1280_done(ha);
  2230. /* LEAVE("qla1280_poll"); */
  2231. }
  2232. /*
  2233. * qla1280_bus_reset
  2234. * Issue SCSI bus reset.
  2235. *
  2236. * Input:
  2237. * ha = adapter block pointer.
  2238. * bus = SCSI bus number.
  2239. *
  2240. * Returns:
  2241. * 0 = success
  2242. */
  2243. static int
  2244. qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
  2245. {
  2246. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2247. uint16_t reset_delay;
  2248. int status;
  2249. dprintk(3, "qla1280_bus_reset: entered\n");
  2250. if (qla1280_verbose)
  2251. printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
  2252. ha->host_no, bus);
  2253. reset_delay = ha->bus_settings[bus].bus_reset_delay;
  2254. mb[0] = MBC_BUS_RESET;
  2255. mb[1] = reset_delay;
  2256. mb[2] = (uint16_t) bus;
  2257. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2258. if (status) {
  2259. if (ha->bus_settings[bus].failed_reset_count > 2)
  2260. ha->bus_settings[bus].scsi_bus_dead = 1;
  2261. ha->bus_settings[bus].failed_reset_count++;
  2262. } else {
  2263. spin_unlock_irq(ha->host->host_lock);
  2264. ssleep(reset_delay);
  2265. spin_lock_irq(ha->host->host_lock);
  2266. ha->bus_settings[bus].scsi_bus_dead = 0;
  2267. ha->bus_settings[bus].failed_reset_count = 0;
  2268. ha->bus_settings[bus].reset_marker = 0;
  2269. /* Issue marker command. */
  2270. qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
  2271. }
  2272. /*
  2273. * We should probably call qla1280_set_target_parameters()
  2274. * here as well for all devices on the bus.
  2275. */
  2276. if (status)
  2277. dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
  2278. else
  2279. dprintk(3, "qla1280_bus_reset: exiting normally\n");
  2280. return status;
  2281. }
  2282. /*
  2283. * qla1280_device_reset
  2284. * Issue bus device reset message to the target.
  2285. *
  2286. * Input:
  2287. * ha = adapter block pointer.
  2288. * bus = SCSI BUS number.
  2289. * target = SCSI ID.
  2290. *
  2291. * Returns:
  2292. * 0 = success
  2293. */
  2294. static int
  2295. qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
  2296. {
  2297. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2298. int status;
  2299. ENTER("qla1280_device_reset");
  2300. mb[0] = MBC_ABORT_TARGET;
  2301. mb[1] = (bus ? (target | BIT_7) : target) << 8;
  2302. mb[2] = 1;
  2303. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2304. /* Issue marker command. */
  2305. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  2306. if (status)
  2307. dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
  2308. LEAVE("qla1280_device_reset");
  2309. return status;
  2310. }
  2311. /*
  2312. * qla1280_abort_command
  2313. * Abort command aborts a specified IOCB.
  2314. *
  2315. * Input:
  2316. * ha = adapter block pointer.
  2317. * sp = SB structure pointer.
  2318. *
  2319. * Returns:
  2320. * 0 = success
  2321. */
  2322. static int
  2323. qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
  2324. {
  2325. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2326. unsigned int bus, target, lun;
  2327. int status;
  2328. ENTER("qla1280_abort_command");
  2329. bus = SCSI_BUS_32(sp->cmd);
  2330. target = SCSI_TCN_32(sp->cmd);
  2331. lun = SCSI_LUN_32(sp->cmd);
  2332. sp->flags |= SRB_ABORT_PENDING;
  2333. mb[0] = MBC_ABORT_COMMAND;
  2334. mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
  2335. mb[2] = handle >> 16;
  2336. mb[3] = handle & 0xffff;
  2337. status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
  2338. if (status) {
  2339. dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
  2340. sp->flags &= ~SRB_ABORT_PENDING;
  2341. }
  2342. LEAVE("qla1280_abort_command");
  2343. return status;
  2344. }
  2345. /*
  2346. * qla1280_reset_adapter
  2347. * Reset adapter.
  2348. *
  2349. * Input:
  2350. * ha = adapter block pointer.
  2351. */
  2352. static void
  2353. qla1280_reset_adapter(struct scsi_qla_host *ha)
  2354. {
  2355. struct device_reg __iomem *reg = ha->iobase;
  2356. ENTER("qla1280_reset_adapter");
  2357. /* Disable ISP chip */
  2358. ha->flags.online = 0;
  2359. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  2360. WRT_REG_WORD(&reg->host_cmd,
  2361. HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
  2362. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2363. LEAVE("qla1280_reset_adapter");
  2364. }
  2365. /*
  2366. * Issue marker command.
  2367. * Function issues marker IOCB.
  2368. *
  2369. * Input:
  2370. * ha = adapter block pointer.
  2371. * bus = SCSI BUS number
  2372. * id = SCSI ID
  2373. * lun = SCSI LUN
  2374. * type = marker modifier
  2375. */
  2376. static void
  2377. qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
  2378. {
  2379. struct mrk_entry *pkt;
  2380. ENTER("qla1280_marker");
  2381. /* Get request packet. */
  2382. if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
  2383. pkt->entry_type = MARKER_TYPE;
  2384. pkt->lun = (uint8_t) lun;
  2385. pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
  2386. pkt->modifier = type;
  2387. pkt->entry_status = 0;
  2388. /* Issue command to ISP */
  2389. qla1280_isp_cmd(ha);
  2390. }
  2391. LEAVE("qla1280_marker");
  2392. }
  2393. /*
  2394. * qla1280_64bit_start_scsi
  2395. * The start SCSI is responsible for building request packets on
  2396. * request ring and modifying ISP input pointer.
  2397. *
  2398. * Input:
  2399. * ha = adapter block pointer.
  2400. * sp = SB structure pointer.
  2401. *
  2402. * Returns:
  2403. * 0 = success, was able to issue command.
  2404. */
  2405. #ifdef QLA_64BIT_PTR
  2406. static int
  2407. qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2408. {
  2409. struct device_reg __iomem *reg = ha->iobase;
  2410. struct scsi_cmnd *cmd = sp->cmd;
  2411. cmd_a64_entry_t *pkt;
  2412. __le32 *dword_ptr;
  2413. dma_addr_t dma_handle;
  2414. int status = 0;
  2415. int cnt;
  2416. int req_cnt;
  2417. int seg_cnt;
  2418. u8 dir;
  2419. ENTER("qla1280_64bit_start_scsi:");
  2420. /* Calculate number of entries and segments required. */
  2421. req_cnt = 1;
  2422. seg_cnt = scsi_dma_map(cmd);
  2423. if (seg_cnt > 0) {
  2424. if (seg_cnt > 2) {
  2425. req_cnt += (seg_cnt - 2) / 5;
  2426. if ((seg_cnt - 2) % 5)
  2427. req_cnt++;
  2428. }
  2429. } else if (seg_cnt < 0) {
  2430. status = 1;
  2431. goto out;
  2432. }
  2433. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2434. /* Calculate number of free request entries. */
  2435. cnt = RD_REG_WORD(&reg->mailbox4);
  2436. if (ha->req_ring_index < cnt)
  2437. ha->req_q_cnt = cnt - ha->req_ring_index;
  2438. else
  2439. ha->req_q_cnt =
  2440. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2441. }
  2442. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2443. ha->req_q_cnt, seg_cnt);
  2444. /* If room for request in request ring. */
  2445. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2446. status = SCSI_MLQUEUE_HOST_BUSY;
  2447. dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
  2448. "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
  2449. req_cnt);
  2450. goto out;
  2451. }
  2452. /* Check for room in outstanding command list. */
  2453. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2454. ha->outstanding_cmds[cnt] != NULL; cnt++);
  2455. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2456. status = SCSI_MLQUEUE_HOST_BUSY;
  2457. dprintk(2, "qla1280_start_scsi: NO ROOM IN "
  2458. "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
  2459. goto out;
  2460. }
  2461. ha->outstanding_cmds[cnt] = sp;
  2462. ha->req_q_cnt -= req_cnt;
  2463. CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
  2464. dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
  2465. cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
  2466. dprintk(2, " bus %i, target %i, lun %i\n",
  2467. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2468. qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
  2469. /*
  2470. * Build command packet.
  2471. */
  2472. pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
  2473. pkt->entry_type = COMMAND_A64_TYPE;
  2474. pkt->entry_count = (uint8_t) req_cnt;
  2475. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2476. pkt->entry_status = 0;
  2477. pkt->handle = cpu_to_le32(cnt);
  2478. /* Zero out remaining portion of packet. */
  2479. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2480. /* Set ISP command timeout. */
  2481. pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
  2482. /* Set device target ID and LUN */
  2483. pkt->lun = SCSI_LUN_32(cmd);
  2484. pkt->target = SCSI_BUS_32(cmd) ?
  2485. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2486. /* Enable simple tag queuing if device supports it. */
  2487. if (cmd->device->simple_tags)
  2488. pkt->control_flags |= cpu_to_le16(BIT_3);
  2489. /* Load SCSI command packet. */
  2490. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2491. memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
  2492. /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2493. /* Set transfer direction. */
  2494. dir = qla1280_data_direction(cmd);
  2495. pkt->control_flags |= cpu_to_le16(dir);
  2496. /* Set total data segment count. */
  2497. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2498. /*
  2499. * Load data segments.
  2500. */
  2501. if (seg_cnt) { /* If data transfer. */
  2502. struct scatterlist *sg, *s;
  2503. int remseg = seg_cnt;
  2504. sg = scsi_sglist(cmd);
  2505. /* Setup packet address segment pointer. */
  2506. dword_ptr = (u32 *)&pkt->dseg_0_address;
  2507. /* Load command entry data segments. */
  2508. for_each_sg(sg, s, seg_cnt, cnt) {
  2509. if (cnt == 2)
  2510. break;
  2511. dma_handle = sg_dma_address(s);
  2512. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2513. if (ha->flags.use_pci_vchannel)
  2514. sn_pci_set_vchan(ha->pdev,
  2515. (unsigned long *)&dma_handle,
  2516. SCSI_BUS_32(cmd));
  2517. #endif
  2518. *dword_ptr++ =
  2519. cpu_to_le32(pci_dma_lo32(dma_handle));
  2520. *dword_ptr++ =
  2521. cpu_to_le32(pci_dma_hi32(dma_handle));
  2522. *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
  2523. dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
  2524. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2525. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2526. cpu_to_le32(sg_dma_len(sg_next(s))));
  2527. remseg--;
  2528. }
  2529. dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
  2530. "command packet data - b %i, t %i, l %i \n",
  2531. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
  2532. SCSI_LUN_32(cmd));
  2533. qla1280_dump_buffer(5, (char *)pkt,
  2534. REQUEST_ENTRY_SIZE);
  2535. /*
  2536. * Build continuation packets.
  2537. */
  2538. dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
  2539. "remains\n", seg_cnt);
  2540. while (remseg > 0) {
  2541. /* Update sg start */
  2542. sg = s;
  2543. /* Adjust ring index. */
  2544. ha->req_ring_index++;
  2545. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2546. ha->req_ring_index = 0;
  2547. ha->request_ring_ptr =
  2548. ha->request_ring;
  2549. } else
  2550. ha->request_ring_ptr++;
  2551. pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
  2552. /* Zero out packet. */
  2553. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2554. /* Load packet defaults. */
  2555. ((struct cont_a64_entry *) pkt)->entry_type =
  2556. CONTINUE_A64_TYPE;
  2557. ((struct cont_a64_entry *) pkt)->entry_count = 1;
  2558. ((struct cont_a64_entry *) pkt)->sys_define =
  2559. (uint8_t)ha->req_ring_index;
  2560. /* Setup packet address segment pointer. */
  2561. dword_ptr =
  2562. (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
  2563. /* Load continuation entry data segments. */
  2564. for_each_sg(sg, s, remseg, cnt) {
  2565. if (cnt == 5)
  2566. break;
  2567. dma_handle = sg_dma_address(s);
  2568. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2569. if (ha->flags.use_pci_vchannel)
  2570. sn_pci_set_vchan(ha->pdev,
  2571. (unsigned long *)&dma_handle,
  2572. SCSI_BUS_32(cmd));
  2573. #endif
  2574. *dword_ptr++ =
  2575. cpu_to_le32(pci_dma_lo32(dma_handle));
  2576. *dword_ptr++ =
  2577. cpu_to_le32(pci_dma_hi32(dma_handle));
  2578. *dword_ptr++ =
  2579. cpu_to_le32(sg_dma_len(s));
  2580. dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
  2581. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2582. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2583. cpu_to_le32(sg_dma_len(s)));
  2584. }
  2585. remseg -= cnt;
  2586. dprintk(5, "qla1280_64bit_start_scsi: "
  2587. "continuation packet data - b %i, t "
  2588. "%i, l %i \n", SCSI_BUS_32(cmd),
  2589. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2590. qla1280_dump_buffer(5, (char *)pkt,
  2591. REQUEST_ENTRY_SIZE);
  2592. }
  2593. } else { /* No data transfer */
  2594. dprintk(5, "qla1280_64bit_start_scsi: No data, command "
  2595. "packet data - b %i, t %i, l %i \n",
  2596. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2597. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2598. }
  2599. /* Adjust ring index. */
  2600. ha->req_ring_index++;
  2601. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2602. ha->req_ring_index = 0;
  2603. ha->request_ring_ptr = ha->request_ring;
  2604. } else
  2605. ha->request_ring_ptr++;
  2606. /* Set chip new ring index. */
  2607. dprintk(2,
  2608. "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
  2609. sp->flags |= SRB_SENT;
  2610. ha->actthreads++;
  2611. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2612. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2613. mmiowb();
  2614. out:
  2615. if (status)
  2616. dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
  2617. else
  2618. dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
  2619. return status;
  2620. }
  2621. #else /* !QLA_64BIT_PTR */
  2622. /*
  2623. * qla1280_32bit_start_scsi
  2624. * The start SCSI is responsible for building request packets on
  2625. * request ring and modifying ISP input pointer.
  2626. *
  2627. * The Qlogic firmware interface allows every queue slot to have a SCSI
  2628. * command and up to 4 scatter/gather (SG) entries. If we need more
  2629. * than 4 SG entries, then continuation entries are used that can
  2630. * hold another 7 entries each. The start routine determines if there
  2631. * is eought empty slots then build the combination of requests to
  2632. * fulfill the OS request.
  2633. *
  2634. * Input:
  2635. * ha = adapter block pointer.
  2636. * sp = SCSI Request Block structure pointer.
  2637. *
  2638. * Returns:
  2639. * 0 = success, was able to issue command.
  2640. */
  2641. static int
  2642. qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2643. {
  2644. struct device_reg __iomem *reg = ha->iobase;
  2645. struct scsi_cmnd *cmd = sp->cmd;
  2646. struct cmd_entry *pkt;
  2647. __le32 *dword_ptr;
  2648. int status = 0;
  2649. int cnt;
  2650. int req_cnt;
  2651. int seg_cnt;
  2652. u8 dir;
  2653. ENTER("qla1280_32bit_start_scsi");
  2654. dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
  2655. cmd->cmnd[0]);
  2656. /* Calculate number of entries and segments required. */
  2657. req_cnt = 1;
  2658. seg_cnt = scsi_dma_map(cmd);
  2659. if (seg_cnt) {
  2660. /*
  2661. * if greater than four sg entries then we need to allocate
  2662. * continuation entries
  2663. */
  2664. if (seg_cnt > 4) {
  2665. req_cnt += (seg_cnt - 4) / 7;
  2666. if ((seg_cnt - 4) % 7)
  2667. req_cnt++;
  2668. }
  2669. dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
  2670. cmd, seg_cnt, req_cnt);
  2671. } else if (seg_cnt < 0) {
  2672. status = 1;
  2673. goto out;
  2674. }
  2675. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2676. /* Calculate number of free request entries. */
  2677. cnt = RD_REG_WORD(&reg->mailbox4);
  2678. if (ha->req_ring_index < cnt)
  2679. ha->req_q_cnt = cnt - ha->req_ring_index;
  2680. else
  2681. ha->req_q_cnt =
  2682. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2683. }
  2684. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2685. ha->req_q_cnt, seg_cnt);
  2686. /* If room for request in request ring. */
  2687. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2688. status = SCSI_MLQUEUE_HOST_BUSY;
  2689. dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
  2690. "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
  2691. ha->req_q_cnt, req_cnt);
  2692. goto out;
  2693. }
  2694. /* Check for empty slot in outstanding command list. */
  2695. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2696. (ha->outstanding_cmds[cnt] != 0); cnt++) ;
  2697. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2698. status = SCSI_MLQUEUE_HOST_BUSY;
  2699. dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
  2700. "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
  2701. goto out;
  2702. }
  2703. CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
  2704. ha->outstanding_cmds[cnt] = sp;
  2705. ha->req_q_cnt -= req_cnt;
  2706. /*
  2707. * Build command packet.
  2708. */
  2709. pkt = (struct cmd_entry *) ha->request_ring_ptr;
  2710. pkt->entry_type = COMMAND_TYPE;
  2711. pkt->entry_count = (uint8_t) req_cnt;
  2712. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2713. pkt->entry_status = 0;
  2714. pkt->handle = cpu_to_le32(cnt);
  2715. /* Zero out remaining portion of packet. */
  2716. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2717. /* Set ISP command timeout. */
  2718. pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
  2719. /* Set device target ID and LUN */
  2720. pkt->lun = SCSI_LUN_32(cmd);
  2721. pkt->target = SCSI_BUS_32(cmd) ?
  2722. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2723. /* Enable simple tag queuing if device supports it. */
  2724. if (cmd->device->simple_tags)
  2725. pkt->control_flags |= cpu_to_le16(BIT_3);
  2726. /* Load SCSI command packet. */
  2727. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2728. memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
  2729. /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2730. /* Set transfer direction. */
  2731. dir = qla1280_data_direction(cmd);
  2732. pkt->control_flags |= cpu_to_le16(dir);
  2733. /* Set total data segment count. */
  2734. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2735. /*
  2736. * Load data segments.
  2737. */
  2738. if (seg_cnt) {
  2739. struct scatterlist *sg, *s;
  2740. int remseg = seg_cnt;
  2741. sg = scsi_sglist(cmd);
  2742. /* Setup packet address segment pointer. */
  2743. dword_ptr = &pkt->dseg_0_address;
  2744. dprintk(3, "Building S/G data segments..\n");
  2745. qla1280_dump_buffer(1, (char *)sg, 4 * 16);
  2746. /* Load command entry data segments. */
  2747. for_each_sg(sg, s, seg_cnt, cnt) {
  2748. if (cnt == 4)
  2749. break;
  2750. *dword_ptr++ =
  2751. cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
  2752. *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
  2753. dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
  2754. (pci_dma_lo32(sg_dma_address(s))),
  2755. (sg_dma_len(s)));
  2756. remseg--;
  2757. }
  2758. /*
  2759. * Build continuation packets.
  2760. */
  2761. dprintk(3, "S/G Building Continuation"
  2762. "...seg_cnt=0x%x remains\n", seg_cnt);
  2763. while (remseg > 0) {
  2764. /* Continue from end point */
  2765. sg = s;
  2766. /* Adjust ring index. */
  2767. ha->req_ring_index++;
  2768. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2769. ha->req_ring_index = 0;
  2770. ha->request_ring_ptr =
  2771. ha->request_ring;
  2772. } else
  2773. ha->request_ring_ptr++;
  2774. pkt = (struct cmd_entry *)ha->request_ring_ptr;
  2775. /* Zero out packet. */
  2776. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2777. /* Load packet defaults. */
  2778. ((struct cont_entry *) pkt)->
  2779. entry_type = CONTINUE_TYPE;
  2780. ((struct cont_entry *) pkt)->entry_count = 1;
  2781. ((struct cont_entry *) pkt)->sys_define =
  2782. (uint8_t) ha->req_ring_index;
  2783. /* Setup packet address segment pointer. */
  2784. dword_ptr =
  2785. &((struct cont_entry *) pkt)->dseg_0_address;
  2786. /* Load continuation entry data segments. */
  2787. for_each_sg(sg, s, remseg, cnt) {
  2788. if (cnt == 7)
  2789. break;
  2790. *dword_ptr++ =
  2791. cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
  2792. *dword_ptr++ =
  2793. cpu_to_le32(sg_dma_len(s));
  2794. dprintk(1,
  2795. "S/G Segment Cont. phys_addr=0x%x, "
  2796. "len=0x%x\n",
  2797. cpu_to_le32(pci_dma_lo32(sg_dma_address(s))),
  2798. cpu_to_le32(sg_dma_len(s)));
  2799. }
  2800. remseg -= cnt;
  2801. dprintk(5, "qla1280_32bit_start_scsi: "
  2802. "continuation packet data - "
  2803. "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
  2804. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2805. qla1280_dump_buffer(5, (char *)pkt,
  2806. REQUEST_ENTRY_SIZE);
  2807. }
  2808. } else { /* No data transfer at all */
  2809. dprintk(5, "qla1280_32bit_start_scsi: No data, command "
  2810. "packet data - \n");
  2811. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2812. }
  2813. dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
  2814. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2815. REQUEST_ENTRY_SIZE);
  2816. /* Adjust ring index. */
  2817. ha->req_ring_index++;
  2818. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2819. ha->req_ring_index = 0;
  2820. ha->request_ring_ptr = ha->request_ring;
  2821. } else
  2822. ha->request_ring_ptr++;
  2823. /* Set chip new ring index. */
  2824. dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
  2825. "for pending command\n");
  2826. sp->flags |= SRB_SENT;
  2827. ha->actthreads++;
  2828. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2829. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2830. mmiowb();
  2831. out:
  2832. if (status)
  2833. dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
  2834. LEAVE("qla1280_32bit_start_scsi");
  2835. return status;
  2836. }
  2837. #endif
  2838. /*
  2839. * qla1280_req_pkt
  2840. * Function is responsible for locking ring and
  2841. * getting a zeroed out request packet.
  2842. *
  2843. * Input:
  2844. * ha = adapter block pointer.
  2845. *
  2846. * Returns:
  2847. * 0 = failed to get slot.
  2848. */
  2849. static request_t *
  2850. qla1280_req_pkt(struct scsi_qla_host *ha)
  2851. {
  2852. struct device_reg __iomem *reg = ha->iobase;
  2853. request_t *pkt = NULL;
  2854. int cnt;
  2855. uint32_t timer;
  2856. ENTER("qla1280_req_pkt");
  2857. /*
  2858. * This can be called from interrupt context, damn it!!!
  2859. */
  2860. /* Wait for 30 seconds for slot. */
  2861. for (timer = 15000000; timer; timer--) {
  2862. if (ha->req_q_cnt > 0) {
  2863. /* Calculate number of free request entries. */
  2864. cnt = RD_REG_WORD(&reg->mailbox4);
  2865. if (ha->req_ring_index < cnt)
  2866. ha->req_q_cnt = cnt - ha->req_ring_index;
  2867. else
  2868. ha->req_q_cnt =
  2869. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2870. }
  2871. /* Found empty request ring slot? */
  2872. if (ha->req_q_cnt > 0) {
  2873. ha->req_q_cnt--;
  2874. pkt = ha->request_ring_ptr;
  2875. /* Zero out packet. */
  2876. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2877. /*
  2878. * How can this be right when we have a ring
  2879. * size of 512???
  2880. */
  2881. /* Set system defined field. */
  2882. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2883. /* Set entry count. */
  2884. pkt->entry_count = 1;
  2885. break;
  2886. }
  2887. udelay(2); /* 10 */
  2888. /* Check for pending interrupts. */
  2889. qla1280_poll(ha);
  2890. }
  2891. if (!pkt)
  2892. dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
  2893. else
  2894. dprintk(3, "qla1280_req_pkt: exiting normally\n");
  2895. return pkt;
  2896. }
  2897. /*
  2898. * qla1280_isp_cmd
  2899. * Function is responsible for modifying ISP input pointer.
  2900. * Releases ring lock.
  2901. *
  2902. * Input:
  2903. * ha = adapter block pointer.
  2904. */
  2905. static void
  2906. qla1280_isp_cmd(struct scsi_qla_host *ha)
  2907. {
  2908. struct device_reg __iomem *reg = ha->iobase;
  2909. ENTER("qla1280_isp_cmd");
  2910. dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
  2911. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2912. REQUEST_ENTRY_SIZE);
  2913. /* Adjust ring index. */
  2914. ha->req_ring_index++;
  2915. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2916. ha->req_ring_index = 0;
  2917. ha->request_ring_ptr = ha->request_ring;
  2918. } else
  2919. ha->request_ring_ptr++;
  2920. /*
  2921. * Update request index to mailbox4 (Request Queue In).
  2922. * The mmiowb() ensures that this write is ordered with writes by other
  2923. * CPUs. Without the mmiowb(), it is possible for the following:
  2924. * CPUA posts write of index 5 to mailbox4
  2925. * CPUA releases host lock
  2926. * CPUB acquires host lock
  2927. * CPUB posts write of index 6 to mailbox4
  2928. * On PCI bus, order reverses and write of 6 posts, then index 5,
  2929. * causing chip to issue full queue of stale commands
  2930. * The mmiowb() prevents future writes from crossing the barrier.
  2931. * See Documentation/DocBook/deviceiobook.tmpl for more information.
  2932. */
  2933. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2934. mmiowb();
  2935. LEAVE("qla1280_isp_cmd");
  2936. }
  2937. /****************************************************************************/
  2938. /* Interrupt Service Routine. */
  2939. /****************************************************************************/
  2940. /****************************************************************************
  2941. * qla1280_isr
  2942. * Calls I/O done on command completion.
  2943. *
  2944. * Input:
  2945. * ha = adapter block pointer.
  2946. * done_q = done queue.
  2947. ****************************************************************************/
  2948. static void
  2949. qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
  2950. {
  2951. struct device_reg __iomem *reg = ha->iobase;
  2952. struct response *pkt;
  2953. struct srb *sp = NULL;
  2954. uint16_t mailbox[MAILBOX_REGISTER_COUNT];
  2955. uint16_t *wptr;
  2956. uint32_t index;
  2957. u16 istatus;
  2958. ENTER("qla1280_isr");
  2959. istatus = RD_REG_WORD(&reg->istatus);
  2960. if (!(istatus & (RISC_INT | PCI_INT)))
  2961. return;
  2962. /* Save mailbox register 5 */
  2963. mailbox[5] = RD_REG_WORD(&reg->mailbox5);
  2964. /* Check for mailbox interrupt. */
  2965. mailbox[0] = RD_REG_WORD_dmasync(&reg->semaphore);
  2966. if (mailbox[0] & BIT_0) {
  2967. /* Get mailbox data. */
  2968. /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
  2969. wptr = &mailbox[0];
  2970. *wptr++ = RD_REG_WORD(&reg->mailbox0);
  2971. *wptr++ = RD_REG_WORD(&reg->mailbox1);
  2972. *wptr = RD_REG_WORD(&reg->mailbox2);
  2973. if (mailbox[0] != MBA_SCSI_COMPLETION) {
  2974. wptr++;
  2975. *wptr++ = RD_REG_WORD(&reg->mailbox3);
  2976. *wptr++ = RD_REG_WORD(&reg->mailbox4);
  2977. wptr++;
  2978. *wptr++ = RD_REG_WORD(&reg->mailbox6);
  2979. *wptr = RD_REG_WORD(&reg->mailbox7);
  2980. }
  2981. /* Release mailbox registers. */
  2982. WRT_REG_WORD(&reg->semaphore, 0);
  2983. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  2984. dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
  2985. mailbox[0]);
  2986. /* Handle asynchronous event */
  2987. switch (mailbox[0]) {
  2988. case MBA_SCSI_COMPLETION: /* Response completion */
  2989. dprintk(5, "qla1280_isr: mailbox SCSI response "
  2990. "completion\n");
  2991. if (ha->flags.online) {
  2992. /* Get outstanding command index. */
  2993. index = mailbox[2] << 16 | mailbox[1];
  2994. /* Validate handle. */
  2995. if (index < MAX_OUTSTANDING_COMMANDS)
  2996. sp = ha->outstanding_cmds[index];
  2997. else
  2998. sp = NULL;
  2999. if (sp) {
  3000. /* Free outstanding command slot. */
  3001. ha->outstanding_cmds[index] = NULL;
  3002. /* Save ISP completion status */
  3003. CMD_RESULT(sp->cmd) = 0;
  3004. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  3005. /* Place block on done queue */
  3006. list_add_tail(&sp->list, done_q);
  3007. } else {
  3008. /*
  3009. * If we get here we have a real problem!
  3010. */
  3011. printk(KERN_WARNING
  3012. "qla1280: ISP invalid handle\n");
  3013. }
  3014. }
  3015. break;
  3016. case MBA_BUS_RESET: /* SCSI Bus Reset */
  3017. ha->flags.reset_marker = 1;
  3018. index = mailbox[6] & BIT_0;
  3019. ha->bus_settings[index].reset_marker = 1;
  3020. printk(KERN_DEBUG "qla1280_isr(): index %i "
  3021. "asynchronous BUS_RESET\n", index);
  3022. break;
  3023. case MBA_SYSTEM_ERR: /* System Error */
  3024. printk(KERN_WARNING
  3025. "qla1280: ISP System Error - mbx1=%xh, mbx2="
  3026. "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
  3027. mailbox[3]);
  3028. break;
  3029. case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
  3030. printk(KERN_WARNING
  3031. "qla1280: ISP Request Transfer Error\n");
  3032. break;
  3033. case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
  3034. printk(KERN_WARNING
  3035. "qla1280: ISP Response Transfer Error\n");
  3036. break;
  3037. case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
  3038. dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
  3039. break;
  3040. case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
  3041. dprintk(2,
  3042. "qla1280_isr: asynchronous TIMEOUT_RESET\n");
  3043. break;
  3044. case MBA_DEVICE_RESET: /* Bus Device Reset */
  3045. printk(KERN_INFO "qla1280_isr(): asynchronous "
  3046. "BUS_DEVICE_RESET\n");
  3047. ha->flags.reset_marker = 1;
  3048. index = mailbox[6] & BIT_0;
  3049. ha->bus_settings[index].reset_marker = 1;
  3050. break;
  3051. case MBA_BUS_MODE_CHANGE:
  3052. dprintk(2,
  3053. "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
  3054. break;
  3055. default:
  3056. /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
  3057. if (mailbox[0] < MBA_ASYNC_EVENT) {
  3058. wptr = &mailbox[0];
  3059. memcpy((uint16_t *) ha->mailbox_out, wptr,
  3060. MAILBOX_REGISTER_COUNT *
  3061. sizeof(uint16_t));
  3062. if(ha->mailbox_wait != NULL)
  3063. complete(ha->mailbox_wait);
  3064. }
  3065. break;
  3066. }
  3067. } else {
  3068. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  3069. }
  3070. /*
  3071. * We will receive interrupts during mailbox testing prior to
  3072. * the card being marked online, hence the double check.
  3073. */
  3074. if (!(ha->flags.online && !ha->mailbox_wait)) {
  3075. dprintk(2, "qla1280_isr: Response pointer Error\n");
  3076. goto out;
  3077. }
  3078. if (mailbox[5] >= RESPONSE_ENTRY_CNT)
  3079. goto out;
  3080. while (ha->rsp_ring_index != mailbox[5]) {
  3081. pkt = ha->response_ring_ptr;
  3082. dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
  3083. " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
  3084. dprintk(5,"qla1280_isr: response packet data\n");
  3085. qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
  3086. if (pkt->entry_type == STATUS_TYPE) {
  3087. if ((le16_to_cpu(pkt->scsi_status) & 0xff)
  3088. || pkt->comp_status || pkt->entry_status) {
  3089. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3090. "0x%x mailbox[5] = 0x%x, comp_status "
  3091. "= 0x%x, scsi_status = 0x%x\n",
  3092. ha->rsp_ring_index, mailbox[5],
  3093. le16_to_cpu(pkt->comp_status),
  3094. le16_to_cpu(pkt->scsi_status));
  3095. }
  3096. } else {
  3097. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3098. "0x%x, mailbox[5] = 0x%x\n",
  3099. ha->rsp_ring_index, mailbox[5]);
  3100. dprintk(2, "qla1280_isr: response packet data\n");
  3101. qla1280_dump_buffer(2, (char *)pkt,
  3102. RESPONSE_ENTRY_SIZE);
  3103. }
  3104. if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
  3105. dprintk(2, "status: Cmd %p, handle %i\n",
  3106. ha->outstanding_cmds[pkt->handle]->cmd,
  3107. pkt->handle);
  3108. if (pkt->entry_type == STATUS_TYPE)
  3109. qla1280_status_entry(ha, pkt, done_q);
  3110. else
  3111. qla1280_error_entry(ha, pkt, done_q);
  3112. /* Adjust ring index. */
  3113. ha->rsp_ring_index++;
  3114. if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
  3115. ha->rsp_ring_index = 0;
  3116. ha->response_ring_ptr = ha->response_ring;
  3117. } else
  3118. ha->response_ring_ptr++;
  3119. WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
  3120. }
  3121. }
  3122. out:
  3123. LEAVE("qla1280_isr");
  3124. }
  3125. /*
  3126. * qla1280_rst_aen
  3127. * Processes asynchronous reset.
  3128. *
  3129. * Input:
  3130. * ha = adapter block pointer.
  3131. */
  3132. static void
  3133. qla1280_rst_aen(struct scsi_qla_host *ha)
  3134. {
  3135. uint8_t bus;
  3136. ENTER("qla1280_rst_aen");
  3137. if (ha->flags.online && !ha->flags.reset_active &&
  3138. !ha->flags.abort_isp_active) {
  3139. ha->flags.reset_active = 1;
  3140. while (ha->flags.reset_marker) {
  3141. /* Issue marker command. */
  3142. ha->flags.reset_marker = 0;
  3143. for (bus = 0; bus < ha->ports &&
  3144. !ha->flags.reset_marker; bus++) {
  3145. if (ha->bus_settings[bus].reset_marker) {
  3146. ha->bus_settings[bus].reset_marker = 0;
  3147. qla1280_marker(ha, bus, 0, 0,
  3148. MK_SYNC_ALL);
  3149. }
  3150. }
  3151. }
  3152. }
  3153. LEAVE("qla1280_rst_aen");
  3154. }
  3155. /*
  3156. * qla1280_status_entry
  3157. * Processes received ISP status entry.
  3158. *
  3159. * Input:
  3160. * ha = adapter block pointer.
  3161. * pkt = entry pointer.
  3162. * done_q = done queue.
  3163. */
  3164. static void
  3165. qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
  3166. struct list_head *done_q)
  3167. {
  3168. unsigned int bus, target, lun;
  3169. int sense_sz;
  3170. struct srb *sp;
  3171. struct scsi_cmnd *cmd;
  3172. uint32_t handle = le32_to_cpu(pkt->handle);
  3173. uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
  3174. uint16_t comp_status = le16_to_cpu(pkt->comp_status);
  3175. ENTER("qla1280_status_entry");
  3176. /* Validate handle. */
  3177. if (handle < MAX_OUTSTANDING_COMMANDS)
  3178. sp = ha->outstanding_cmds[handle];
  3179. else
  3180. sp = NULL;
  3181. if (!sp) {
  3182. printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
  3183. goto out;
  3184. }
  3185. /* Free outstanding command slot. */
  3186. ha->outstanding_cmds[handle] = NULL;
  3187. cmd = sp->cmd;
  3188. /* Generate LU queue on cntrl, target, LUN */
  3189. bus = SCSI_BUS_32(cmd);
  3190. target = SCSI_TCN_32(cmd);
  3191. lun = SCSI_LUN_32(cmd);
  3192. if (comp_status || scsi_status) {
  3193. dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
  3194. "0x%x, handle = 0x%x\n", comp_status,
  3195. scsi_status, handle);
  3196. }
  3197. /* Target busy or queue full */
  3198. if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
  3199. (scsi_status & 0xFF) == SAM_STAT_BUSY) {
  3200. CMD_RESULT(cmd) = scsi_status & 0xff;
  3201. } else {
  3202. /* Save ISP completion status */
  3203. CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
  3204. if (scsi_status & SAM_STAT_CHECK_CONDITION) {
  3205. if (comp_status != CS_ARS_FAILED) {
  3206. uint16_t req_sense_length =
  3207. le16_to_cpu(pkt->req_sense_length);
  3208. if (req_sense_length < CMD_SNSLEN(cmd))
  3209. sense_sz = req_sense_length;
  3210. else
  3211. /*
  3212. * scsi_cmnd->sense_buffer is
  3213. * 64 bytes, why only copy 63?
  3214. * This looks wrong! /Jes
  3215. */
  3216. sense_sz = CMD_SNSLEN(cmd) - 1;
  3217. memcpy(cmd->sense_buffer,
  3218. &pkt->req_sense_data, sense_sz);
  3219. } else
  3220. sense_sz = 0;
  3221. memset(cmd->sense_buffer + sense_sz, 0,
  3222. SCSI_SENSE_BUFFERSIZE - sense_sz);
  3223. dprintk(2, "qla1280_status_entry: Check "
  3224. "condition Sense data, b %i, t %i, "
  3225. "l %i\n", bus, target, lun);
  3226. if (sense_sz)
  3227. qla1280_dump_buffer(2,
  3228. (char *)cmd->sense_buffer,
  3229. sense_sz);
  3230. }
  3231. }
  3232. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  3233. /* Place command on done queue. */
  3234. list_add_tail(&sp->list, done_q);
  3235. out:
  3236. LEAVE("qla1280_status_entry");
  3237. }
  3238. /*
  3239. * qla1280_error_entry
  3240. * Processes error entry.
  3241. *
  3242. * Input:
  3243. * ha = adapter block pointer.
  3244. * pkt = entry pointer.
  3245. * done_q = done queue.
  3246. */
  3247. static void
  3248. qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
  3249. struct list_head *done_q)
  3250. {
  3251. struct srb *sp;
  3252. uint32_t handle = le32_to_cpu(pkt->handle);
  3253. ENTER("qla1280_error_entry");
  3254. if (pkt->entry_status & BIT_3)
  3255. dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
  3256. else if (pkt->entry_status & BIT_2)
  3257. dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
  3258. else if (pkt->entry_status & BIT_1)
  3259. dprintk(2, "qla1280_error_entry: FULL flag error\n");
  3260. else
  3261. dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
  3262. /* Validate handle. */
  3263. if (handle < MAX_OUTSTANDING_COMMANDS)
  3264. sp = ha->outstanding_cmds[handle];
  3265. else
  3266. sp = NULL;
  3267. if (sp) {
  3268. /* Free outstanding command slot. */
  3269. ha->outstanding_cmds[handle] = NULL;
  3270. /* Bad payload or header */
  3271. if (pkt->entry_status & (BIT_3 + BIT_2)) {
  3272. /* Bad payload or header, set error status. */
  3273. /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
  3274. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3275. } else if (pkt->entry_status & BIT_1) { /* FULL flag */
  3276. CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
  3277. } else {
  3278. /* Set error status. */
  3279. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3280. }
  3281. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  3282. /* Place command on done queue. */
  3283. list_add_tail(&sp->list, done_q);
  3284. }
  3285. #ifdef QLA_64BIT_PTR
  3286. else if (pkt->entry_type == COMMAND_A64_TYPE) {
  3287. printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
  3288. }
  3289. #endif
  3290. LEAVE("qla1280_error_entry");
  3291. }
  3292. /*
  3293. * qla1280_abort_isp
  3294. * Resets ISP and aborts all outstanding commands.
  3295. *
  3296. * Input:
  3297. * ha = adapter block pointer.
  3298. *
  3299. * Returns:
  3300. * 0 = success
  3301. */
  3302. static int
  3303. qla1280_abort_isp(struct scsi_qla_host *ha)
  3304. {
  3305. struct device_reg __iomem *reg = ha->iobase;
  3306. struct srb *sp;
  3307. int status = 0;
  3308. int cnt;
  3309. int bus;
  3310. ENTER("qla1280_abort_isp");
  3311. if (ha->flags.abort_isp_active || !ha->flags.online)
  3312. goto out;
  3313. ha->flags.abort_isp_active = 1;
  3314. /* Disable ISP interrupts. */
  3315. qla1280_disable_intrs(ha);
  3316. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3317. RD_REG_WORD(&reg->id_l);
  3318. printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
  3319. ha->host_no);
  3320. /* Dequeue all commands in outstanding command list. */
  3321. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  3322. struct scsi_cmnd *cmd;
  3323. sp = ha->outstanding_cmds[cnt];
  3324. if (sp) {
  3325. cmd = sp->cmd;
  3326. CMD_RESULT(cmd) = DID_RESET << 16;
  3327. CMD_HANDLE(cmd) = COMPLETED_HANDLE;
  3328. ha->outstanding_cmds[cnt] = NULL;
  3329. list_add_tail(&sp->list, &ha->done_q);
  3330. }
  3331. }
  3332. qla1280_done(ha);
  3333. status = qla1280_load_firmware(ha);
  3334. if (status)
  3335. goto out;
  3336. /* Setup adapter based on NVRAM parameters. */
  3337. qla1280_nvram_config (ha);
  3338. status = qla1280_init_rings(ha);
  3339. if (status)
  3340. goto out;
  3341. /* Issue SCSI reset. */
  3342. for (bus = 0; bus < ha->ports; bus++)
  3343. qla1280_bus_reset(ha, bus);
  3344. ha->flags.abort_isp_active = 0;
  3345. out:
  3346. if (status) {
  3347. printk(KERN_WARNING
  3348. "qla1280: ISP error recovery failed, board disabled");
  3349. qla1280_reset_adapter(ha);
  3350. dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
  3351. }
  3352. LEAVE("qla1280_abort_isp");
  3353. return status;
  3354. }
  3355. /*
  3356. * qla1280_debounce_register
  3357. * Debounce register.
  3358. *
  3359. * Input:
  3360. * port = register address.
  3361. *
  3362. * Returns:
  3363. * register value.
  3364. */
  3365. static u16
  3366. qla1280_debounce_register(volatile u16 __iomem * addr)
  3367. {
  3368. volatile u16 ret;
  3369. volatile u16 ret2;
  3370. ret = RD_REG_WORD(addr);
  3371. ret2 = RD_REG_WORD(addr);
  3372. if (ret == ret2)
  3373. return ret;
  3374. do {
  3375. cpu_relax();
  3376. ret = RD_REG_WORD(addr);
  3377. ret2 = RD_REG_WORD(addr);
  3378. } while (ret != ret2);
  3379. return ret;
  3380. }
  3381. /************************************************************************
  3382. * qla1280_check_for_dead_scsi_bus *
  3383. * *
  3384. * This routine checks for a dead SCSI bus *
  3385. ************************************************************************/
  3386. #define SET_SXP_BANK 0x0100
  3387. #define SCSI_PHASE_INVALID 0x87FF
  3388. static int
  3389. qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
  3390. {
  3391. uint16_t config_reg, scsi_control;
  3392. struct device_reg __iomem *reg = ha->iobase;
  3393. if (ha->bus_settings[bus].scsi_bus_dead) {
  3394. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3395. config_reg = RD_REG_WORD(&reg->cfg_1);
  3396. WRT_REG_WORD(&reg->cfg_1, SET_SXP_BANK);
  3397. scsi_control = RD_REG_WORD(&reg->scsiControlPins);
  3398. WRT_REG_WORD(&reg->cfg_1, config_reg);
  3399. WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
  3400. if (scsi_control == SCSI_PHASE_INVALID) {
  3401. ha->bus_settings[bus].scsi_bus_dead = 1;
  3402. return 1; /* bus is dead */
  3403. } else {
  3404. ha->bus_settings[bus].scsi_bus_dead = 0;
  3405. ha->bus_settings[bus].failed_reset_count = 0;
  3406. }
  3407. }
  3408. return 0; /* bus is not dead */
  3409. }
  3410. static void
  3411. qla1280_get_target_parameters(struct scsi_qla_host *ha,
  3412. struct scsi_device *device)
  3413. {
  3414. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3415. int bus, target, lun;
  3416. bus = device->channel;
  3417. target = device->id;
  3418. lun = device->lun;
  3419. mb[0] = MBC_GET_TARGET_PARAMETERS;
  3420. mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
  3421. mb[1] <<= 8;
  3422. qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
  3423. &mb[0]);
  3424. printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
  3425. if (mb[3] != 0) {
  3426. printk(" Sync: period %d, offset %d",
  3427. (mb[3] & 0xff), (mb[3] >> 8));
  3428. if (mb[2] & BIT_13)
  3429. printk(", Wide");
  3430. if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
  3431. printk(", DT");
  3432. } else
  3433. printk(" Async");
  3434. if (device->simple_tags)
  3435. printk(", Tagged queuing: depth %d", device->queue_depth);
  3436. printk("\n");
  3437. }
  3438. #if DEBUG_QLA1280
  3439. static void
  3440. __qla1280_dump_buffer(char *b, int size)
  3441. {
  3442. int cnt;
  3443. u8 c;
  3444. printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
  3445. "Bh Ch Dh Eh Fh\n");
  3446. printk(KERN_DEBUG "---------------------------------------------"
  3447. "------------------\n");
  3448. for (cnt = 0; cnt < size;) {
  3449. c = *b++;
  3450. printk("0x%02x", c);
  3451. cnt++;
  3452. if (!(cnt % 16))
  3453. printk("\n");
  3454. else
  3455. printk(" ");
  3456. }
  3457. if (cnt % 16)
  3458. printk("\n");
  3459. }
  3460. /**************************************************************************
  3461. * ql1280_print_scsi_cmd
  3462. *
  3463. **************************************************************************/
  3464. static void
  3465. __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
  3466. {
  3467. struct scsi_qla_host *ha;
  3468. struct Scsi_Host *host = CMD_HOST(cmd);
  3469. struct srb *sp;
  3470. /* struct scatterlist *sg; */
  3471. int i;
  3472. ha = (struct scsi_qla_host *)host->hostdata;
  3473. sp = (struct srb *)CMD_SP(cmd);
  3474. printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
  3475. printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  3476. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
  3477. CMD_CDBLEN(cmd));
  3478. printk(" CDB = ");
  3479. for (i = 0; i < cmd->cmd_len; i++) {
  3480. printk("0x%02x ", cmd->cmnd[i]);
  3481. }
  3482. printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
  3483. printk(" request buffer=0x%p, request buffer len=0x%x\n",
  3484. scsi_sglist(cmd), scsi_bufflen(cmd));
  3485. /* if (cmd->use_sg)
  3486. {
  3487. sg = (struct scatterlist *) cmd->request_buffer;
  3488. printk(" SG buffer: \n");
  3489. qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
  3490. } */
  3491. printk(" tag=%d, transfersize=0x%x \n",
  3492. cmd->tag, cmd->transfersize);
  3493. printk(" SP=0x%p\n", CMD_SP(cmd));
  3494. printk(" underflow size = 0x%x, direction=0x%x\n",
  3495. cmd->underflow, cmd->sc_data_direction);
  3496. }
  3497. /**************************************************************************
  3498. * ql1280_dump_device
  3499. *
  3500. **************************************************************************/
  3501. static void
  3502. ql1280_dump_device(struct scsi_qla_host *ha)
  3503. {
  3504. struct scsi_cmnd *cp;
  3505. struct srb *sp;
  3506. int i;
  3507. printk(KERN_DEBUG "Outstanding Commands on controller:\n");
  3508. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  3509. if ((sp = ha->outstanding_cmds[i]) == NULL)
  3510. continue;
  3511. if ((cp = sp->cmd) == NULL)
  3512. continue;
  3513. qla1280_print_scsi_cmd(1, cp);
  3514. }
  3515. }
  3516. #endif
  3517. enum tokens {
  3518. TOKEN_NVRAM,
  3519. TOKEN_SYNC,
  3520. TOKEN_WIDE,
  3521. TOKEN_PPR,
  3522. TOKEN_VERBOSE,
  3523. TOKEN_DEBUG,
  3524. };
  3525. struct setup_tokens {
  3526. char *token;
  3527. int val;
  3528. };
  3529. static struct setup_tokens setup_token[] __initdata =
  3530. {
  3531. { "nvram", TOKEN_NVRAM },
  3532. { "sync", TOKEN_SYNC },
  3533. { "wide", TOKEN_WIDE },
  3534. { "ppr", TOKEN_PPR },
  3535. { "verbose", TOKEN_VERBOSE },
  3536. { "debug", TOKEN_DEBUG },
  3537. };
  3538. /**************************************************************************
  3539. * qla1280_setup
  3540. *
  3541. * Handle boot parameters. This really needs to be changed so one
  3542. * can specify per adapter parameters.
  3543. **************************************************************************/
  3544. static int __init
  3545. qla1280_setup(char *s)
  3546. {
  3547. char *cp, *ptr;
  3548. unsigned long val;
  3549. int toke;
  3550. cp = s;
  3551. while (cp && (ptr = strchr(cp, ':'))) {
  3552. ptr++;
  3553. if (!strcmp(ptr, "yes")) {
  3554. val = 0x10000;
  3555. ptr += 3;
  3556. } else if (!strcmp(ptr, "no")) {
  3557. val = 0;
  3558. ptr += 2;
  3559. } else
  3560. val = simple_strtoul(ptr, &ptr, 0);
  3561. switch ((toke = qla1280_get_token(cp))) {
  3562. case TOKEN_NVRAM:
  3563. if (!val)
  3564. driver_setup.no_nvram = 1;
  3565. break;
  3566. case TOKEN_SYNC:
  3567. if (!val)
  3568. driver_setup.no_sync = 1;
  3569. else if (val != 0x10000)
  3570. driver_setup.sync_mask = val;
  3571. break;
  3572. case TOKEN_WIDE:
  3573. if (!val)
  3574. driver_setup.no_wide = 1;
  3575. else if (val != 0x10000)
  3576. driver_setup.wide_mask = val;
  3577. break;
  3578. case TOKEN_PPR:
  3579. if (!val)
  3580. driver_setup.no_ppr = 1;
  3581. else if (val != 0x10000)
  3582. driver_setup.ppr_mask = val;
  3583. break;
  3584. case TOKEN_VERBOSE:
  3585. qla1280_verbose = val;
  3586. break;
  3587. default:
  3588. printk(KERN_INFO "qla1280: unknown boot option %s\n",
  3589. cp);
  3590. }
  3591. cp = strchr(ptr, ';');
  3592. if (cp)
  3593. cp++;
  3594. else {
  3595. break;
  3596. }
  3597. }
  3598. return 1;
  3599. }
  3600. static int __init
  3601. qla1280_get_token(char *str)
  3602. {
  3603. char *sep;
  3604. long ret = -1;
  3605. int i;
  3606. sep = strchr(str, ':');
  3607. if (sep) {
  3608. for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
  3609. if (!strncmp(setup_token[i].token, str, (sep - str))) {
  3610. ret = setup_token[i].val;
  3611. break;
  3612. }
  3613. }
  3614. }
  3615. return ret;
  3616. }
  3617. static struct scsi_host_template qla1280_driver_template = {
  3618. .module = THIS_MODULE,
  3619. .proc_name = "qla1280",
  3620. .name = "Qlogic ISP 1280/12160",
  3621. .info = qla1280_info,
  3622. .slave_configure = qla1280_slave_configure,
  3623. .queuecommand = qla1280_queuecommand,
  3624. .eh_abort_handler = qla1280_eh_abort,
  3625. .eh_device_reset_handler= qla1280_eh_device_reset,
  3626. .eh_bus_reset_handler = qla1280_eh_bus_reset,
  3627. .eh_host_reset_handler = qla1280_eh_adapter_reset,
  3628. .bios_param = qla1280_biosparam,
  3629. .can_queue = MAX_OUTSTANDING_COMMANDS,
  3630. .this_id = -1,
  3631. .sg_tablesize = SG_ALL,
  3632. .use_clustering = ENABLE_CLUSTERING,
  3633. };
  3634. static int
  3635. qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  3636. {
  3637. int devnum = id->driver_data;
  3638. struct qla_boards *bdp = &ql1280_board_tbl[devnum];
  3639. struct Scsi_Host *host;
  3640. struct scsi_qla_host *ha;
  3641. int error = -ENODEV;
  3642. /* Bypass all AMI SUBSYS VENDOR IDs */
  3643. if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
  3644. printk(KERN_INFO
  3645. "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
  3646. goto error;
  3647. }
  3648. printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
  3649. bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
  3650. if (pci_enable_device(pdev)) {
  3651. printk(KERN_WARNING
  3652. "qla1280: Failed to enabled pci device, aborting.\n");
  3653. goto error;
  3654. }
  3655. pci_set_master(pdev);
  3656. error = -ENOMEM;
  3657. host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
  3658. if (!host) {
  3659. printk(KERN_WARNING
  3660. "qla1280: Failed to register host, aborting.\n");
  3661. goto error_disable_device;
  3662. }
  3663. ha = (struct scsi_qla_host *)host->hostdata;
  3664. memset(ha, 0, sizeof(struct scsi_qla_host));
  3665. ha->pdev = pdev;
  3666. ha->devnum = devnum; /* specifies microcode load address */
  3667. #ifdef QLA_64BIT_PTR
  3668. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  3669. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
  3670. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3671. "suitable DMA mask - aborting\n", ha->host_no);
  3672. error = -ENODEV;
  3673. goto error_put_host;
  3674. }
  3675. } else
  3676. dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
  3677. ha->host_no);
  3678. #else
  3679. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
  3680. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3681. "suitable DMA mask - aborting\n", ha->host_no);
  3682. error = -ENODEV;
  3683. goto error_put_host;
  3684. }
  3685. #endif
  3686. ha->request_ring = pci_alloc_consistent(ha->pdev,
  3687. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3688. &ha->request_dma);
  3689. if (!ha->request_ring) {
  3690. printk(KERN_INFO "qla1280: Failed to get request memory\n");
  3691. goto error_put_host;
  3692. }
  3693. ha->response_ring = pci_alloc_consistent(ha->pdev,
  3694. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3695. &ha->response_dma);
  3696. if (!ha->response_ring) {
  3697. printk(KERN_INFO "qla1280: Failed to get response memory\n");
  3698. goto error_free_request_ring;
  3699. }
  3700. ha->ports = bdp->numPorts;
  3701. ha->host = host;
  3702. ha->host_no = host->host_no;
  3703. host->irq = pdev->irq;
  3704. host->max_channel = bdp->numPorts - 1;
  3705. host->max_lun = MAX_LUNS - 1;
  3706. host->max_id = MAX_TARGETS;
  3707. host->max_sectors = 1024;
  3708. host->unique_id = host->host_no;
  3709. error = -ENODEV;
  3710. #if MEMORY_MAPPED_IO
  3711. ha->mmpbase = pci_ioremap_bar(ha->pdev, 1);
  3712. if (!ha->mmpbase) {
  3713. printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
  3714. goto error_free_response_ring;
  3715. }
  3716. host->base = (unsigned long)ha->mmpbase;
  3717. ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
  3718. #else
  3719. host->io_port = pci_resource_start(ha->pdev, 0);
  3720. if (!request_region(host->io_port, 0xff, "qla1280")) {
  3721. printk(KERN_INFO "qla1280: Failed to reserve i/o region "
  3722. "0x%04lx-0x%04lx - already in use\n",
  3723. host->io_port, host->io_port + 0xff);
  3724. goto error_free_response_ring;
  3725. }
  3726. ha->iobase = (struct device_reg *)host->io_port;
  3727. #endif
  3728. INIT_LIST_HEAD(&ha->done_q);
  3729. /* Disable ISP interrupts. */
  3730. qla1280_disable_intrs(ha);
  3731. if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
  3732. "qla1280", ha)) {
  3733. printk("qla1280 : Failed to reserve interrupt %d already "
  3734. "in use\n", pdev->irq);
  3735. goto error_release_region;
  3736. }
  3737. /* load the F/W, read paramaters, and init the H/W */
  3738. if (qla1280_initialize_adapter(ha)) {
  3739. printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
  3740. goto error_free_irq;
  3741. }
  3742. /* set our host ID (need to do something about our two IDs) */
  3743. host->this_id = ha->bus_settings[0].id;
  3744. pci_set_drvdata(pdev, host);
  3745. error = scsi_add_host(host, &pdev->dev);
  3746. if (error)
  3747. goto error_disable_adapter;
  3748. scsi_scan_host(host);
  3749. return 0;
  3750. error_disable_adapter:
  3751. qla1280_disable_intrs(ha);
  3752. error_free_irq:
  3753. free_irq(pdev->irq, ha);
  3754. error_release_region:
  3755. #if MEMORY_MAPPED_IO
  3756. iounmap(ha->mmpbase);
  3757. #else
  3758. release_region(host->io_port, 0xff);
  3759. #endif
  3760. error_free_response_ring:
  3761. pci_free_consistent(ha->pdev,
  3762. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3763. ha->response_ring, ha->response_dma);
  3764. error_free_request_ring:
  3765. pci_free_consistent(ha->pdev,
  3766. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3767. ha->request_ring, ha->request_dma);
  3768. error_put_host:
  3769. scsi_host_put(host);
  3770. error_disable_device:
  3771. pci_disable_device(pdev);
  3772. error:
  3773. return error;
  3774. }
  3775. static void
  3776. qla1280_remove_one(struct pci_dev *pdev)
  3777. {
  3778. struct Scsi_Host *host = pci_get_drvdata(pdev);
  3779. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  3780. scsi_remove_host(host);
  3781. qla1280_disable_intrs(ha);
  3782. free_irq(pdev->irq, ha);
  3783. #if MEMORY_MAPPED_IO
  3784. iounmap(ha->mmpbase);
  3785. #else
  3786. release_region(host->io_port, 0xff);
  3787. #endif
  3788. pci_free_consistent(ha->pdev,
  3789. ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
  3790. ha->request_ring, ha->request_dma);
  3791. pci_free_consistent(ha->pdev,
  3792. ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
  3793. ha->response_ring, ha->response_dma);
  3794. pci_disable_device(pdev);
  3795. scsi_host_put(host);
  3796. }
  3797. static struct pci_driver qla1280_pci_driver = {
  3798. .name = "qla1280",
  3799. .id_table = qla1280_pci_tbl,
  3800. .probe = qla1280_probe_one,
  3801. .remove = qla1280_remove_one,
  3802. };
  3803. static int __init
  3804. qla1280_init(void)
  3805. {
  3806. if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
  3807. printk(KERN_WARNING
  3808. "qla1280: struct srb too big, aborting\n");
  3809. return -EINVAL;
  3810. }
  3811. #ifdef MODULE
  3812. /*
  3813. * If we are called as a module, the qla1280 pointer may not be null
  3814. * and it would point to our bootup string, just like on the lilo
  3815. * command line. IF not NULL, then process this config string with
  3816. * qla1280_setup
  3817. *
  3818. * Boot time Options
  3819. * To add options at boot time add a line to your lilo.conf file like:
  3820. * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
  3821. * which will result in the first four devices on the first two
  3822. * controllers being set to a tagged queue depth of 32.
  3823. */
  3824. if (qla1280)
  3825. qla1280_setup(qla1280);
  3826. #endif
  3827. return pci_register_driver(&qla1280_pci_driver);
  3828. }
  3829. static void __exit
  3830. qla1280_exit(void)
  3831. {
  3832. int i;
  3833. pci_unregister_driver(&qla1280_pci_driver);
  3834. /* release any allocated firmware images */
  3835. for (i = 0; i < QL_NUM_FW_IMAGES; i++) {
  3836. release_firmware(qla1280_fw_tbl[i].fw);
  3837. qla1280_fw_tbl[i].fw = NULL;
  3838. }
  3839. }
  3840. module_init(qla1280_init);
  3841. module_exit(qla1280_exit);
  3842. MODULE_AUTHOR("Qlogic & Jes Sorensen");
  3843. MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
  3844. MODULE_LICENSE("GPL");
  3845. MODULE_FIRMWARE("qlogic/1040.bin");
  3846. MODULE_FIRMWARE("qlogic/1280.bin");
  3847. MODULE_FIRMWARE("qlogic/12160.bin");
  3848. MODULE_VERSION(QLA1280_VERSION);
  3849. /*
  3850. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  3851. * Emacs will notice this stuff at the end of the file and automatically
  3852. * adjust the settings for this buffer only. This must remain at the end
  3853. * of the file.
  3854. * ---------------------------------------------------------------------------
  3855. * Local variables:
  3856. * c-basic-offset: 8
  3857. * tab-width: 8
  3858. * End:
  3859. */