qla1280.c 125 KB

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