qla_os.c 167 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2014 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <linux/kobject.h>
  14. #include <linux/slab.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/scsicam.h>
  17. #include <scsi/scsi_transport.h>
  18. #include <scsi/scsi_transport_fc.h>
  19. #include "qla_target.h"
  20. /*
  21. * Driver version
  22. */
  23. char qla2x00_version_str[40];
  24. static int apidev_major;
  25. /*
  26. * SRB allocation cache
  27. */
  28. static struct kmem_cache *srb_cachep;
  29. /*
  30. * CT6 CTX allocation cache
  31. */
  32. static struct kmem_cache *ctx_cachep;
  33. /*
  34. * error level for logging
  35. */
  36. int ql_errlev = ql_log_all;
  37. static int ql2xenableclass2;
  38. module_param(ql2xenableclass2, int, S_IRUGO|S_IRUSR);
  39. MODULE_PARM_DESC(ql2xenableclass2,
  40. "Specify if Class 2 operations are supported from the very "
  41. "beginning. Default is 0 - class 2 not supported.");
  42. int ql2xlogintimeout = 20;
  43. module_param(ql2xlogintimeout, int, S_IRUGO);
  44. MODULE_PARM_DESC(ql2xlogintimeout,
  45. "Login timeout value in seconds.");
  46. int qlport_down_retry;
  47. module_param(qlport_down_retry, int, S_IRUGO);
  48. MODULE_PARM_DESC(qlport_down_retry,
  49. "Maximum number of command retries to a port that returns "
  50. "a PORT-DOWN status.");
  51. int ql2xplogiabsentdevice;
  52. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  53. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  54. "Option to enable PLOGI to devices that are not present after "
  55. "a Fabric scan. This is needed for several broken switches. "
  56. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  57. int ql2xloginretrycount = 0;
  58. module_param(ql2xloginretrycount, int, S_IRUGO);
  59. MODULE_PARM_DESC(ql2xloginretrycount,
  60. "Specify an alternate value for the NVRAM login retry count.");
  61. int ql2xallocfwdump = 1;
  62. module_param(ql2xallocfwdump, int, S_IRUGO);
  63. MODULE_PARM_DESC(ql2xallocfwdump,
  64. "Option to enable allocation of memory for a firmware dump "
  65. "during HBA initialization. Memory allocation requirements "
  66. "vary by ISP type. Default is 1 - allocate memory.");
  67. int ql2xextended_error_logging;
  68. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  69. module_param_named(logging, ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  70. MODULE_PARM_DESC(ql2xextended_error_logging,
  71. "Option to enable extended error logging,\n"
  72. "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
  73. "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
  74. "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
  75. "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
  76. "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
  77. "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
  78. "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
  79. "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
  80. "\t\t0x00008000 - Verbose. 0x00004000 - Target.\n"
  81. "\t\t0x00002000 - Target Mgmt. 0x00001000 - Target TMF.\n"
  82. "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
  83. "\t\t0x1e400000 - Preferred value for capturing essential "
  84. "debug information (equivalent to old "
  85. "ql2xextended_error_logging=1).\n"
  86. "\t\tDo LOGICAL OR of the value to enable more than one level");
  87. int ql2xshiftctondsd = 6;
  88. module_param(ql2xshiftctondsd, int, S_IRUGO);
  89. MODULE_PARM_DESC(ql2xshiftctondsd,
  90. "Set to control shifting of command type processing "
  91. "based on total number of SG elements.");
  92. int ql2xfdmienable=1;
  93. module_param(ql2xfdmienable, int, S_IRUGO|S_IWUSR);
  94. module_param_named(fdmi, ql2xfdmienable, int, S_IRUGO|S_IWUSR);
  95. MODULE_PARM_DESC(ql2xfdmienable,
  96. "Enables FDMI registrations. "
  97. "0 - no FDMI. Default is 1 - perform FDMI.");
  98. #define MAX_Q_DEPTH 32
  99. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  100. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  101. MODULE_PARM_DESC(ql2xmaxqdepth,
  102. "Maximum queue depth to set for each LUN. "
  103. "Default is 32.");
  104. int ql2xenabledif = 2;
  105. module_param(ql2xenabledif, int, S_IRUGO);
  106. MODULE_PARM_DESC(ql2xenabledif,
  107. " Enable T10-CRC-DIF:\n"
  108. " Default is 2.\n"
  109. " 0 -- No DIF Support\n"
  110. " 1 -- Enable DIF for all types\n"
  111. " 2 -- Enable DIF for all types, except Type 0.\n");
  112. int ql2xenablehba_err_chk = 2;
  113. module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
  114. MODULE_PARM_DESC(ql2xenablehba_err_chk,
  115. " Enable T10-CRC-DIF Error isolation by HBA:\n"
  116. " Default is 2.\n"
  117. " 0 -- Error isolation disabled\n"
  118. " 1 -- Error isolation enabled only for DIX Type 0\n"
  119. " 2 -- Error isolation enabled for all Types\n");
  120. int ql2xiidmaenable=1;
  121. module_param(ql2xiidmaenable, int, S_IRUGO);
  122. MODULE_PARM_DESC(ql2xiidmaenable,
  123. "Enables iIDMA settings "
  124. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  125. int ql2xmaxqueues = 1;
  126. module_param(ql2xmaxqueues, int, S_IRUGO);
  127. MODULE_PARM_DESC(ql2xmaxqueues,
  128. "Enables MQ settings "
  129. "Default is 1 for single queue. Set it to number "
  130. "of queues in MQ mode.");
  131. int ql2xmultique_tag;
  132. module_param(ql2xmultique_tag, int, S_IRUGO);
  133. MODULE_PARM_DESC(ql2xmultique_tag,
  134. "Enables CPU affinity settings for the driver "
  135. "Default is 0 for no affinity of request and response IO. "
  136. "Set it to 1 to turn on the cpu affinity.");
  137. int ql2xfwloadbin;
  138. module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  139. module_param_named(fwload, ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
  140. MODULE_PARM_DESC(ql2xfwloadbin,
  141. "Option to specify location from which to load ISP firmware:.\n"
  142. " 2 -- load firmware via the request_firmware() (hotplug).\n"
  143. " interface.\n"
  144. " 1 -- load firmware from flash.\n"
  145. " 0 -- use default semantics.\n");
  146. int ql2xetsenable;
  147. module_param(ql2xetsenable, int, S_IRUGO);
  148. MODULE_PARM_DESC(ql2xetsenable,
  149. "Enables firmware ETS burst."
  150. "Default is 0 - skip ETS enablement.");
  151. int ql2xdbwr = 1;
  152. module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
  153. MODULE_PARM_DESC(ql2xdbwr,
  154. "Option to specify scheme for request queue posting.\n"
  155. " 0 -- Regular doorbell.\n"
  156. " 1 -- CAMRAM doorbell (faster).\n");
  157. int ql2xtargetreset = 1;
  158. module_param(ql2xtargetreset, int, S_IRUGO);
  159. MODULE_PARM_DESC(ql2xtargetreset,
  160. "Enable target reset."
  161. "Default is 1 - use hw defaults.");
  162. int ql2xgffidenable;
  163. module_param(ql2xgffidenable, int, S_IRUGO);
  164. MODULE_PARM_DESC(ql2xgffidenable,
  165. "Enables GFF_ID checks of port type. "
  166. "Default is 0 - Do not use GFF_ID information.");
  167. int ql2xasynctmfenable;
  168. module_param(ql2xasynctmfenable, int, S_IRUGO);
  169. MODULE_PARM_DESC(ql2xasynctmfenable,
  170. "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
  171. "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
  172. int ql2xdontresethba;
  173. module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
  174. MODULE_PARM_DESC(ql2xdontresethba,
  175. "Option to specify reset behaviour.\n"
  176. " 0 (Default) -- Reset on failure.\n"
  177. " 1 -- Do not reset on failure.\n");
  178. uint64_t ql2xmaxlun = MAX_LUNS;
  179. module_param(ql2xmaxlun, ullong, S_IRUGO);
  180. MODULE_PARM_DESC(ql2xmaxlun,
  181. "Defines the maximum LU number to register with the SCSI "
  182. "midlayer. Default is 65535.");
  183. int ql2xmdcapmask = 0x1F;
  184. module_param(ql2xmdcapmask, int, S_IRUGO);
  185. MODULE_PARM_DESC(ql2xmdcapmask,
  186. "Set the Minidump driver capture mask level. "
  187. "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
  188. int ql2xmdenable = 1;
  189. module_param(ql2xmdenable, int, S_IRUGO);
  190. MODULE_PARM_DESC(ql2xmdenable,
  191. "Enable/disable MiniDump. "
  192. "0 - MiniDump disabled. "
  193. "1 (Default) - MiniDump enabled.");
  194. int ql2xexlogins = 0;
  195. module_param(ql2xexlogins, uint, S_IRUGO|S_IWUSR);
  196. MODULE_PARM_DESC(ql2xexlogins,
  197. "Number of extended Logins. "
  198. "0 (Default)- Disabled.");
  199. int ql2xexchoffld = 0;
  200. module_param(ql2xexchoffld, uint, S_IRUGO|S_IWUSR);
  201. MODULE_PARM_DESC(ql2xexchoffld,
  202. "Number of exchanges to offload. "
  203. "0 (Default)- Disabled.");
  204. int ql2xfwholdabts = 0;
  205. module_param(ql2xfwholdabts, int, S_IRUGO);
  206. MODULE_PARM_DESC(ql2xfwholdabts,
  207. "Allow FW to hold status IOCB until ABTS rsp received. "
  208. "0 (Default) Do not set fw option. "
  209. "1 - Set fw option to hold ABTS.");
  210. /*
  211. * SCSI host template entry points
  212. */
  213. static int qla2xxx_slave_configure(struct scsi_device * device);
  214. static int qla2xxx_slave_alloc(struct scsi_device *);
  215. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  216. static void qla2xxx_scan_start(struct Scsi_Host *);
  217. static void qla2xxx_slave_destroy(struct scsi_device *);
  218. static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  219. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  220. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  221. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  222. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  223. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  224. static void qla2x00_clear_drv_active(struct qla_hw_data *);
  225. static void qla2x00_free_device(scsi_qla_host_t *);
  226. static void qla83xx_disable_laser(scsi_qla_host_t *vha);
  227. struct scsi_host_template qla2xxx_driver_template = {
  228. .module = THIS_MODULE,
  229. .name = QLA2XXX_DRIVER_NAME,
  230. .queuecommand = qla2xxx_queuecommand,
  231. .eh_abort_handler = qla2xxx_eh_abort,
  232. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  233. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  234. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  235. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  236. .slave_configure = qla2xxx_slave_configure,
  237. .slave_alloc = qla2xxx_slave_alloc,
  238. .slave_destroy = qla2xxx_slave_destroy,
  239. .scan_finished = qla2xxx_scan_finished,
  240. .scan_start = qla2xxx_scan_start,
  241. .change_queue_depth = scsi_change_queue_depth,
  242. .this_id = -1,
  243. .cmd_per_lun = 3,
  244. .use_clustering = ENABLE_CLUSTERING,
  245. .sg_tablesize = SG_ALL,
  246. .max_sectors = 0xFFFF,
  247. .shost_attrs = qla2x00_host_attrs,
  248. .supported_mode = MODE_INITIATOR,
  249. .track_queue_depth = 1,
  250. };
  251. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  252. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  253. /* TODO Convert to inlines
  254. *
  255. * Timer routines
  256. */
  257. __inline__ void
  258. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  259. {
  260. init_timer(&vha->timer);
  261. vha->timer.expires = jiffies + interval * HZ;
  262. vha->timer.data = (unsigned long)vha;
  263. vha->timer.function = (void (*)(unsigned long))func;
  264. add_timer(&vha->timer);
  265. vha->timer_active = 1;
  266. }
  267. static inline void
  268. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  269. {
  270. /* Currently used for 82XX only. */
  271. if (vha->device_flags & DFLG_DEV_FAILED) {
  272. ql_dbg(ql_dbg_timer, vha, 0x600d,
  273. "Device in a failed state, returning.\n");
  274. return;
  275. }
  276. mod_timer(&vha->timer, jiffies + interval * HZ);
  277. }
  278. static __inline__ void
  279. qla2x00_stop_timer(scsi_qla_host_t *vha)
  280. {
  281. del_timer_sync(&vha->timer);
  282. vha->timer_active = 0;
  283. }
  284. static int qla2x00_do_dpc(void *data);
  285. static void qla2x00_rst_aen(scsi_qla_host_t *);
  286. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  287. struct req_que **, struct rsp_que **);
  288. static void qla2x00_free_fw_dump(struct qla_hw_data *);
  289. static void qla2x00_mem_free(struct qla_hw_data *);
  290. /* -------------------------------------------------------------------------- */
  291. static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
  292. struct rsp_que *rsp)
  293. {
  294. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  295. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
  296. GFP_KERNEL);
  297. if (!ha->req_q_map) {
  298. ql_log(ql_log_fatal, vha, 0x003b,
  299. "Unable to allocate memory for request queue ptrs.\n");
  300. goto fail_req_map;
  301. }
  302. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
  303. GFP_KERNEL);
  304. if (!ha->rsp_q_map) {
  305. ql_log(ql_log_fatal, vha, 0x003c,
  306. "Unable to allocate memory for response queue ptrs.\n");
  307. goto fail_rsp_map;
  308. }
  309. /*
  310. * Make sure we record at least the request and response queue zero in
  311. * case we need to free them if part of the probe fails.
  312. */
  313. ha->rsp_q_map[0] = rsp;
  314. ha->req_q_map[0] = req;
  315. set_bit(0, ha->rsp_qid_map);
  316. set_bit(0, ha->req_qid_map);
  317. return 1;
  318. fail_rsp_map:
  319. kfree(ha->req_q_map);
  320. ha->req_q_map = NULL;
  321. fail_req_map:
  322. return -ENOMEM;
  323. }
  324. static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
  325. {
  326. if (IS_QLAFX00(ha)) {
  327. if (req && req->ring_fx00)
  328. dma_free_coherent(&ha->pdev->dev,
  329. (req->length_fx00 + 1) * sizeof(request_t),
  330. req->ring_fx00, req->dma_fx00);
  331. } else if (req && req->ring)
  332. dma_free_coherent(&ha->pdev->dev,
  333. (req->length + 1) * sizeof(request_t),
  334. req->ring, req->dma);
  335. if (req)
  336. kfree(req->outstanding_cmds);
  337. kfree(req);
  338. req = NULL;
  339. }
  340. static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
  341. {
  342. if (IS_QLAFX00(ha)) {
  343. if (rsp && rsp->ring)
  344. dma_free_coherent(&ha->pdev->dev,
  345. (rsp->length_fx00 + 1) * sizeof(request_t),
  346. rsp->ring_fx00, rsp->dma_fx00);
  347. } else if (rsp && rsp->ring) {
  348. dma_free_coherent(&ha->pdev->dev,
  349. (rsp->length + 1) * sizeof(response_t),
  350. rsp->ring, rsp->dma);
  351. }
  352. kfree(rsp);
  353. rsp = NULL;
  354. }
  355. static void qla2x00_free_queues(struct qla_hw_data *ha)
  356. {
  357. struct req_que *req;
  358. struct rsp_que *rsp;
  359. int cnt;
  360. for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
  361. if (!test_bit(cnt, ha->req_qid_map))
  362. continue;
  363. req = ha->req_q_map[cnt];
  364. qla2x00_free_req_que(ha, req);
  365. }
  366. kfree(ha->req_q_map);
  367. ha->req_q_map = NULL;
  368. for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
  369. if (!test_bit(cnt, ha->rsp_qid_map))
  370. continue;
  371. rsp = ha->rsp_q_map[cnt];
  372. qla2x00_free_rsp_que(ha, rsp);
  373. }
  374. kfree(ha->rsp_q_map);
  375. ha->rsp_q_map = NULL;
  376. }
  377. static int qla25xx_setup_mode(struct scsi_qla_host *vha)
  378. {
  379. uint16_t options = 0;
  380. int ques, req, ret;
  381. struct qla_hw_data *ha = vha->hw;
  382. if (!(ha->fw_attributes & BIT_6)) {
  383. ql_log(ql_log_warn, vha, 0x00d8,
  384. "Firmware is not multi-queue capable.\n");
  385. goto fail;
  386. }
  387. if (ql2xmultique_tag) {
  388. /* create a request queue for IO */
  389. options |= BIT_7;
  390. req = qla25xx_create_req_que(ha, options, 0, 0, -1,
  391. QLA_DEFAULT_QUE_QOS);
  392. if (!req) {
  393. ql_log(ql_log_warn, vha, 0x00e0,
  394. "Failed to create request queue.\n");
  395. goto fail;
  396. }
  397. ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
  398. vha->req = ha->req_q_map[req];
  399. options |= BIT_1;
  400. for (ques = 1; ques < ha->max_rsp_queues; ques++) {
  401. ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
  402. if (!ret) {
  403. ql_log(ql_log_warn, vha, 0x00e8,
  404. "Failed to create response queue.\n");
  405. goto fail2;
  406. }
  407. }
  408. ha->flags.cpu_affinity_enabled = 1;
  409. ql_dbg(ql_dbg_multiq, vha, 0xc007,
  410. "CPU affinity mode enabled, "
  411. "no. of response queues:%d no. of request queues:%d.\n",
  412. ha->max_rsp_queues, ha->max_req_queues);
  413. ql_dbg(ql_dbg_init, vha, 0x00e9,
  414. "CPU affinity mode enabled, "
  415. "no. of response queues:%d no. of request queues:%d.\n",
  416. ha->max_rsp_queues, ha->max_req_queues);
  417. }
  418. return 0;
  419. fail2:
  420. qla25xx_delete_queues(vha);
  421. destroy_workqueue(ha->wq);
  422. ha->wq = NULL;
  423. vha->req = ha->req_q_map[0];
  424. fail:
  425. ha->mqenable = 0;
  426. kfree(ha->req_q_map);
  427. kfree(ha->rsp_q_map);
  428. ha->max_req_queues = ha->max_rsp_queues = 1;
  429. return 1;
  430. }
  431. static char *
  432. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  433. {
  434. struct qla_hw_data *ha = vha->hw;
  435. static char *pci_bus_modes[] = {
  436. "33", "66", "100", "133",
  437. };
  438. uint16_t pci_bus;
  439. strcpy(str, "PCI");
  440. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  441. if (pci_bus) {
  442. strcat(str, "-X (");
  443. strcat(str, pci_bus_modes[pci_bus]);
  444. } else {
  445. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  446. strcat(str, " (");
  447. strcat(str, pci_bus_modes[pci_bus]);
  448. }
  449. strcat(str, " MHz)");
  450. return (str);
  451. }
  452. static char *
  453. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  454. {
  455. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  456. struct qla_hw_data *ha = vha->hw;
  457. uint32_t pci_bus;
  458. if (pci_is_pcie(ha->pdev)) {
  459. char lwstr[6];
  460. uint32_t lstat, lspeed, lwidth;
  461. pcie_capability_read_dword(ha->pdev, PCI_EXP_LNKCAP, &lstat);
  462. lspeed = lstat & PCI_EXP_LNKCAP_SLS;
  463. lwidth = (lstat & PCI_EXP_LNKCAP_MLW) >> 4;
  464. strcpy(str, "PCIe (");
  465. switch (lspeed) {
  466. case 1:
  467. strcat(str, "2.5GT/s ");
  468. break;
  469. case 2:
  470. strcat(str, "5.0GT/s ");
  471. break;
  472. case 3:
  473. strcat(str, "8.0GT/s ");
  474. break;
  475. default:
  476. strcat(str, "<unknown> ");
  477. break;
  478. }
  479. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  480. strcat(str, lwstr);
  481. return str;
  482. }
  483. strcpy(str, "PCI");
  484. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  485. if (pci_bus == 0 || pci_bus == 8) {
  486. strcat(str, " (");
  487. strcat(str, pci_bus_modes[pci_bus >> 3]);
  488. } else {
  489. strcat(str, "-X ");
  490. if (pci_bus & BIT_2)
  491. strcat(str, "Mode 2");
  492. else
  493. strcat(str, "Mode 1");
  494. strcat(str, " (");
  495. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  496. }
  497. strcat(str, " MHz)");
  498. return str;
  499. }
  500. static char *
  501. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  502. {
  503. char un_str[10];
  504. struct qla_hw_data *ha = vha->hw;
  505. snprintf(str, size, "%d.%02d.%02d ", ha->fw_major_version,
  506. ha->fw_minor_version, ha->fw_subminor_version);
  507. if (ha->fw_attributes & BIT_9) {
  508. strcat(str, "FLX");
  509. return (str);
  510. }
  511. switch (ha->fw_attributes & 0xFF) {
  512. case 0x7:
  513. strcat(str, "EF");
  514. break;
  515. case 0x17:
  516. strcat(str, "TP");
  517. break;
  518. case 0x37:
  519. strcat(str, "IP");
  520. break;
  521. case 0x77:
  522. strcat(str, "VI");
  523. break;
  524. default:
  525. sprintf(un_str, "(%x)", ha->fw_attributes);
  526. strcat(str, un_str);
  527. break;
  528. }
  529. if (ha->fw_attributes & 0x100)
  530. strcat(str, "X");
  531. return (str);
  532. }
  533. static char *
  534. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str, size_t size)
  535. {
  536. struct qla_hw_data *ha = vha->hw;
  537. snprintf(str, size, "%d.%02d.%02d (%x)", ha->fw_major_version,
  538. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  539. return str;
  540. }
  541. void
  542. qla2x00_sp_free_dma(void *vha, void *ptr)
  543. {
  544. srb_t *sp = (srb_t *)ptr;
  545. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  546. struct qla_hw_data *ha = sp->fcport->vha->hw;
  547. void *ctx = GET_CMD_CTX_SP(sp);
  548. if (sp->flags & SRB_DMA_VALID) {
  549. scsi_dma_unmap(cmd);
  550. sp->flags &= ~SRB_DMA_VALID;
  551. }
  552. if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
  553. dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  554. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  555. sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
  556. }
  557. if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
  558. /* List assured to be having elements */
  559. qla2x00_clean_dsd_pool(ha, sp, NULL);
  560. sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
  561. }
  562. if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
  563. dma_pool_free(ha->dl_dma_pool, ctx,
  564. ((struct crc_context *)ctx)->crc_ctx_dma);
  565. sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
  566. }
  567. if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
  568. struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
  569. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
  570. ctx1->fcp_cmnd_dma);
  571. list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
  572. ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
  573. ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
  574. mempool_free(ctx1, ha->ctx_mempool);
  575. ctx1 = NULL;
  576. }
  577. CMD_SP(cmd) = NULL;
  578. qla2x00_rel_sp(sp->fcport->vha, sp);
  579. }
  580. static void
  581. qla2x00_sp_compl(void *data, void *ptr, int res)
  582. {
  583. struct qla_hw_data *ha = (struct qla_hw_data *)data;
  584. srb_t *sp = (srb_t *)ptr;
  585. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  586. cmd->result = res;
  587. if (atomic_read(&sp->ref_count) == 0) {
  588. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
  589. "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
  590. sp, GET_CMD_SP(sp));
  591. if (ql2xextended_error_logging & ql_dbg_io)
  592. WARN_ON(atomic_read(&sp->ref_count) == 0);
  593. return;
  594. }
  595. if (!atomic_dec_and_test(&sp->ref_count))
  596. return;
  597. qla2x00_sp_free_dma(ha, sp);
  598. cmd->scsi_done(cmd);
  599. }
  600. /* If we are SP1 here, we need to still take and release the host_lock as SP1
  601. * does not have the changes necessary to avoid taking host->host_lock.
  602. */
  603. static int
  604. qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
  605. {
  606. scsi_qla_host_t *vha = shost_priv(host);
  607. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  608. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  609. struct qla_hw_data *ha = vha->hw;
  610. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  611. srb_t *sp;
  612. int rval;
  613. if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
  614. cmd->result = DID_NO_CONNECT << 16;
  615. goto qc24_fail_command;
  616. }
  617. if (ha->flags.eeh_busy) {
  618. if (ha->flags.pci_channel_io_perm_failure) {
  619. ql_dbg(ql_dbg_aer, vha, 0x9010,
  620. "PCI Channel IO permanent failure, exiting "
  621. "cmd=%p.\n", cmd);
  622. cmd->result = DID_NO_CONNECT << 16;
  623. } else {
  624. ql_dbg(ql_dbg_aer, vha, 0x9011,
  625. "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
  626. cmd->result = DID_REQUEUE << 16;
  627. }
  628. goto qc24_fail_command;
  629. }
  630. rval = fc_remote_port_chkready(rport);
  631. if (rval) {
  632. cmd->result = rval;
  633. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3003,
  634. "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
  635. cmd, rval);
  636. goto qc24_fail_command;
  637. }
  638. if (!vha->flags.difdix_supported &&
  639. scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
  640. ql_dbg(ql_dbg_io, vha, 0x3004,
  641. "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
  642. cmd);
  643. cmd->result = DID_NO_CONNECT << 16;
  644. goto qc24_fail_command;
  645. }
  646. if (!fcport) {
  647. cmd->result = DID_NO_CONNECT << 16;
  648. goto qc24_fail_command;
  649. }
  650. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  651. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  652. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  653. ql_dbg(ql_dbg_io, vha, 0x3005,
  654. "Returning DNC, fcport_state=%d loop_state=%d.\n",
  655. atomic_read(&fcport->state),
  656. atomic_read(&base_vha->loop_state));
  657. cmd->result = DID_NO_CONNECT << 16;
  658. goto qc24_fail_command;
  659. }
  660. goto qc24_target_busy;
  661. }
  662. /*
  663. * Return target busy if we've received a non-zero retry_delay_timer
  664. * in a FCP_RSP.
  665. */
  666. if (fcport->retry_delay_timestamp == 0) {
  667. /* retry delay not set */
  668. } else if (time_after(jiffies, fcport->retry_delay_timestamp))
  669. fcport->retry_delay_timestamp = 0;
  670. else
  671. goto qc24_target_busy;
  672. sp = qla2x00_get_sp(vha, fcport, GFP_ATOMIC);
  673. if (!sp)
  674. goto qc24_host_busy;
  675. sp->u.scmd.cmd = cmd;
  676. sp->type = SRB_SCSI_CMD;
  677. atomic_set(&sp->ref_count, 1);
  678. CMD_SP(cmd) = (void *)sp;
  679. sp->free = qla2x00_sp_free_dma;
  680. sp->done = qla2x00_sp_compl;
  681. rval = ha->isp_ops->start_scsi(sp);
  682. if (rval != QLA_SUCCESS) {
  683. ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x3013,
  684. "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
  685. goto qc24_host_busy_free_sp;
  686. }
  687. return 0;
  688. qc24_host_busy_free_sp:
  689. qla2x00_sp_free_dma(ha, sp);
  690. qc24_host_busy:
  691. return SCSI_MLQUEUE_HOST_BUSY;
  692. qc24_target_busy:
  693. return SCSI_MLQUEUE_TARGET_BUSY;
  694. qc24_fail_command:
  695. cmd->scsi_done(cmd);
  696. return 0;
  697. }
  698. /*
  699. * qla2x00_eh_wait_on_command
  700. * Waits for the command to be returned by the Firmware for some
  701. * max time.
  702. *
  703. * Input:
  704. * cmd = Scsi Command to wait on.
  705. *
  706. * Return:
  707. * Not Found : 0
  708. * Found : 1
  709. */
  710. static int
  711. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  712. {
  713. #define ABORT_POLLING_PERIOD 1000
  714. #define ABORT_WAIT_ITER ((2 * 1000) / (ABORT_POLLING_PERIOD))
  715. unsigned long wait_iter = ABORT_WAIT_ITER;
  716. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  717. struct qla_hw_data *ha = vha->hw;
  718. int ret = QLA_SUCCESS;
  719. if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
  720. ql_dbg(ql_dbg_taskm, vha, 0x8005,
  721. "Return:eh_wait.\n");
  722. return ret;
  723. }
  724. while (CMD_SP(cmd) && wait_iter--) {
  725. msleep(ABORT_POLLING_PERIOD);
  726. }
  727. if (CMD_SP(cmd))
  728. ret = QLA_FUNCTION_FAILED;
  729. return ret;
  730. }
  731. /*
  732. * qla2x00_wait_for_hba_online
  733. * Wait till the HBA is online after going through
  734. * <= MAX_RETRIES_OF_ISP_ABORT or
  735. * finally HBA is disabled ie marked offline
  736. *
  737. * Input:
  738. * ha - pointer to host adapter structure
  739. *
  740. * Note:
  741. * Does context switching-Release SPIN_LOCK
  742. * (if any) before calling this routine.
  743. *
  744. * Return:
  745. * Success (Adapter is online) : 0
  746. * Failed (Adapter is offline/disabled) : 1
  747. */
  748. int
  749. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  750. {
  751. int return_status;
  752. unsigned long wait_online;
  753. struct qla_hw_data *ha = vha->hw;
  754. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  755. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  756. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  757. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  758. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  759. ha->dpc_active) && time_before(jiffies, wait_online)) {
  760. msleep(1000);
  761. }
  762. if (base_vha->flags.online)
  763. return_status = QLA_SUCCESS;
  764. else
  765. return_status = QLA_FUNCTION_FAILED;
  766. return (return_status);
  767. }
  768. /*
  769. * qla2x00_wait_for_hba_ready
  770. * Wait till the HBA is ready before doing driver unload
  771. *
  772. * Input:
  773. * ha - pointer to host adapter structure
  774. *
  775. * Note:
  776. * Does context switching-Release SPIN_LOCK
  777. * (if any) before calling this routine.
  778. *
  779. */
  780. static void
  781. qla2x00_wait_for_hba_ready(scsi_qla_host_t *vha)
  782. {
  783. struct qla_hw_data *ha = vha->hw;
  784. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  785. while ((qla2x00_reset_active(vha) || ha->dpc_active ||
  786. ha->flags.mbox_busy) ||
  787. test_bit(FX00_RESET_RECOVERY, &vha->dpc_flags) ||
  788. test_bit(FX00_TARGET_SCAN, &vha->dpc_flags)) {
  789. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  790. break;
  791. msleep(1000);
  792. }
  793. }
  794. int
  795. qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
  796. {
  797. int return_status;
  798. unsigned long wait_reset;
  799. struct qla_hw_data *ha = vha->hw;
  800. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  801. wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  802. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  803. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  804. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  805. ha->dpc_active) && time_before(jiffies, wait_reset)) {
  806. msleep(1000);
  807. if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  808. ha->flags.chip_reset_done)
  809. break;
  810. }
  811. if (ha->flags.chip_reset_done)
  812. return_status = QLA_SUCCESS;
  813. else
  814. return_status = QLA_FUNCTION_FAILED;
  815. return return_status;
  816. }
  817. static void
  818. sp_get(struct srb *sp)
  819. {
  820. atomic_inc(&sp->ref_count);
  821. }
  822. #define ISP_REG_DISCONNECT 0xffffffffU
  823. /**************************************************************************
  824. * qla2x00_isp_reg_stat
  825. *
  826. * Description:
  827. * Read the host status register of ISP before aborting the command.
  828. *
  829. * Input:
  830. * ha = pointer to host adapter structure.
  831. *
  832. *
  833. * Returns:
  834. * Either true or false.
  835. *
  836. * Note: Return true if there is register disconnect.
  837. **************************************************************************/
  838. static inline
  839. uint32_t qla2x00_isp_reg_stat(struct qla_hw_data *ha)
  840. {
  841. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  842. struct device_reg_82xx __iomem *reg82 = &ha->iobase->isp82;
  843. if (IS_P3P_TYPE(ha))
  844. return ((RD_REG_DWORD(&reg82->host_int)) == ISP_REG_DISCONNECT);
  845. else
  846. return ((RD_REG_DWORD(&reg->host_status)) ==
  847. ISP_REG_DISCONNECT);
  848. }
  849. /**************************************************************************
  850. * qla2xxx_eh_abort
  851. *
  852. * Description:
  853. * The abort function will abort the specified command.
  854. *
  855. * Input:
  856. * cmd = Linux SCSI command packet to be aborted.
  857. *
  858. * Returns:
  859. * Either SUCCESS or FAILED.
  860. *
  861. * Note:
  862. * Only return FAILED if command not returned by firmware.
  863. **************************************************************************/
  864. static int
  865. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  866. {
  867. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  868. srb_t *sp;
  869. int ret;
  870. unsigned int id;
  871. uint64_t lun;
  872. unsigned long flags;
  873. int rval, wait = 0;
  874. struct qla_hw_data *ha = vha->hw;
  875. if (qla2x00_isp_reg_stat(ha)) {
  876. ql_log(ql_log_info, vha, 0x8042,
  877. "PCI/Register disconnect, exiting.\n");
  878. return FAILED;
  879. }
  880. if (!CMD_SP(cmd))
  881. return SUCCESS;
  882. ret = fc_block_scsi_eh(cmd);
  883. if (ret != 0)
  884. return ret;
  885. ret = SUCCESS;
  886. id = cmd->device->id;
  887. lun = cmd->device->lun;
  888. spin_lock_irqsave(&ha->hardware_lock, flags);
  889. sp = (srb_t *) CMD_SP(cmd);
  890. if (!sp) {
  891. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  892. return SUCCESS;
  893. }
  894. ql_dbg(ql_dbg_taskm, vha, 0x8002,
  895. "Aborting from RISC nexus=%ld:%d:%llu sp=%p cmd=%p handle=%x\n",
  896. vha->host_no, id, lun, sp, cmd, sp->handle);
  897. /* Get a reference to the sp and drop the lock.*/
  898. sp_get(sp);
  899. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  900. rval = ha->isp_ops->abort_command(sp);
  901. if (rval) {
  902. if (rval == QLA_FUNCTION_PARAMETER_ERROR)
  903. ret = SUCCESS;
  904. else
  905. ret = FAILED;
  906. ql_dbg(ql_dbg_taskm, vha, 0x8003,
  907. "Abort command mbx failed cmd=%p, rval=%x.\n", cmd, rval);
  908. } else {
  909. ql_dbg(ql_dbg_taskm, vha, 0x8004,
  910. "Abort command mbx success cmd=%p.\n", cmd);
  911. wait = 1;
  912. }
  913. spin_lock_irqsave(&ha->hardware_lock, flags);
  914. sp->done(ha, sp, 0);
  915. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  916. /* Did the command return during mailbox execution? */
  917. if (ret == FAILED && !CMD_SP(cmd))
  918. ret = SUCCESS;
  919. /* Wait for the command to be returned. */
  920. if (wait) {
  921. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  922. ql_log(ql_log_warn, vha, 0x8006,
  923. "Abort handler timed out cmd=%p.\n", cmd);
  924. ret = FAILED;
  925. }
  926. }
  927. ql_log(ql_log_info, vha, 0x801c,
  928. "Abort command issued nexus=%ld:%d:%llu -- %d %x.\n",
  929. vha->host_no, id, lun, wait, ret);
  930. return ret;
  931. }
  932. int
  933. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  934. uint64_t l, enum nexus_wait_type type)
  935. {
  936. int cnt, match, status;
  937. unsigned long flags;
  938. struct qla_hw_data *ha = vha->hw;
  939. struct req_que *req;
  940. srb_t *sp;
  941. struct scsi_cmnd *cmd;
  942. status = QLA_SUCCESS;
  943. spin_lock_irqsave(&ha->hardware_lock, flags);
  944. req = vha->req;
  945. for (cnt = 1; status == QLA_SUCCESS &&
  946. cnt < req->num_outstanding_cmds; cnt++) {
  947. sp = req->outstanding_cmds[cnt];
  948. if (!sp)
  949. continue;
  950. if (sp->type != SRB_SCSI_CMD)
  951. continue;
  952. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  953. continue;
  954. match = 0;
  955. cmd = GET_CMD_SP(sp);
  956. switch (type) {
  957. case WAIT_HOST:
  958. match = 1;
  959. break;
  960. case WAIT_TARGET:
  961. match = cmd->device->id == t;
  962. break;
  963. case WAIT_LUN:
  964. match = (cmd->device->id == t &&
  965. cmd->device->lun == l);
  966. break;
  967. }
  968. if (!match)
  969. continue;
  970. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  971. status = qla2x00_eh_wait_on_command(cmd);
  972. spin_lock_irqsave(&ha->hardware_lock, flags);
  973. }
  974. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  975. return status;
  976. }
  977. static char *reset_errors[] = {
  978. "HBA not online",
  979. "HBA not ready",
  980. "Task management failed",
  981. "Waiting for command completions",
  982. };
  983. static int
  984. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  985. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, uint64_t, int))
  986. {
  987. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  988. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  989. int err;
  990. if (!fcport) {
  991. return FAILED;
  992. }
  993. err = fc_block_scsi_eh(cmd);
  994. if (err != 0)
  995. return err;
  996. ql_log(ql_log_info, vha, 0x8009,
  997. "%s RESET ISSUED nexus=%ld:%d:%llu cmd=%p.\n", name, vha->host_no,
  998. cmd->device->id, cmd->device->lun, cmd);
  999. err = 0;
  1000. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1001. ql_log(ql_log_warn, vha, 0x800a,
  1002. "Wait for hba online failed for cmd=%p.\n", cmd);
  1003. goto eh_reset_failed;
  1004. }
  1005. err = 2;
  1006. if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
  1007. != QLA_SUCCESS) {
  1008. ql_log(ql_log_warn, vha, 0x800c,
  1009. "do_reset failed for cmd=%p.\n", cmd);
  1010. goto eh_reset_failed;
  1011. }
  1012. err = 3;
  1013. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  1014. cmd->device->lun, type) != QLA_SUCCESS) {
  1015. ql_log(ql_log_warn, vha, 0x800d,
  1016. "wait for pending cmds failed for cmd=%p.\n", cmd);
  1017. goto eh_reset_failed;
  1018. }
  1019. ql_log(ql_log_info, vha, 0x800e,
  1020. "%s RESET SUCCEEDED nexus:%ld:%d:%llu cmd=%p.\n", name,
  1021. vha->host_no, cmd->device->id, cmd->device->lun, cmd);
  1022. return SUCCESS;
  1023. eh_reset_failed:
  1024. ql_log(ql_log_info, vha, 0x800f,
  1025. "%s RESET FAILED: %s nexus=%ld:%d:%llu cmd=%p.\n", name,
  1026. reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
  1027. cmd);
  1028. return FAILED;
  1029. }
  1030. static int
  1031. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  1032. {
  1033. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1034. struct qla_hw_data *ha = vha->hw;
  1035. if (qla2x00_isp_reg_stat(ha)) {
  1036. ql_log(ql_log_info, vha, 0x803e,
  1037. "PCI/Register disconnect, exiting.\n");
  1038. return FAILED;
  1039. }
  1040. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  1041. ha->isp_ops->lun_reset);
  1042. }
  1043. static int
  1044. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  1045. {
  1046. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1047. struct qla_hw_data *ha = vha->hw;
  1048. if (qla2x00_isp_reg_stat(ha)) {
  1049. ql_log(ql_log_info, vha, 0x803f,
  1050. "PCI/Register disconnect, exiting.\n");
  1051. return FAILED;
  1052. }
  1053. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  1054. ha->isp_ops->target_reset);
  1055. }
  1056. /**************************************************************************
  1057. * qla2xxx_eh_bus_reset
  1058. *
  1059. * Description:
  1060. * The bus reset function will reset the bus and abort any executing
  1061. * commands.
  1062. *
  1063. * Input:
  1064. * cmd = Linux SCSI command packet of the command that cause the
  1065. * bus reset.
  1066. *
  1067. * Returns:
  1068. * SUCCESS/FAILURE (defined as macro in scsi.h).
  1069. *
  1070. **************************************************************************/
  1071. static int
  1072. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  1073. {
  1074. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1075. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  1076. int ret = FAILED;
  1077. unsigned int id;
  1078. uint64_t lun;
  1079. struct qla_hw_data *ha = vha->hw;
  1080. if (qla2x00_isp_reg_stat(ha)) {
  1081. ql_log(ql_log_info, vha, 0x8040,
  1082. "PCI/Register disconnect, exiting.\n");
  1083. return FAILED;
  1084. }
  1085. id = cmd->device->id;
  1086. lun = cmd->device->lun;
  1087. if (!fcport) {
  1088. return ret;
  1089. }
  1090. ret = fc_block_scsi_eh(cmd);
  1091. if (ret != 0)
  1092. return ret;
  1093. ret = FAILED;
  1094. ql_log(ql_log_info, vha, 0x8012,
  1095. "BUS RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1096. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1097. ql_log(ql_log_fatal, vha, 0x8013,
  1098. "Wait for hba online failed board disabled.\n");
  1099. goto eh_bus_reset_done;
  1100. }
  1101. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  1102. ret = SUCCESS;
  1103. if (ret == FAILED)
  1104. goto eh_bus_reset_done;
  1105. /* Flush outstanding commands. */
  1106. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
  1107. QLA_SUCCESS) {
  1108. ql_log(ql_log_warn, vha, 0x8014,
  1109. "Wait for pending commands failed.\n");
  1110. ret = FAILED;
  1111. }
  1112. eh_bus_reset_done:
  1113. ql_log(ql_log_warn, vha, 0x802b,
  1114. "BUS RESET %s nexus=%ld:%d:%llu.\n",
  1115. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1116. return ret;
  1117. }
  1118. /**************************************************************************
  1119. * qla2xxx_eh_host_reset
  1120. *
  1121. * Description:
  1122. * The reset function will reset the Adapter.
  1123. *
  1124. * Input:
  1125. * cmd = Linux SCSI command packet of the command that cause the
  1126. * adapter reset.
  1127. *
  1128. * Returns:
  1129. * Either SUCCESS or FAILED.
  1130. *
  1131. * Note:
  1132. **************************************************************************/
  1133. static int
  1134. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  1135. {
  1136. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  1137. struct qla_hw_data *ha = vha->hw;
  1138. int ret = FAILED;
  1139. unsigned int id;
  1140. uint64_t lun;
  1141. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1142. if (qla2x00_isp_reg_stat(ha)) {
  1143. ql_log(ql_log_info, vha, 0x8041,
  1144. "PCI/Register disconnect, exiting.\n");
  1145. schedule_work(&ha->board_disable);
  1146. return SUCCESS;
  1147. }
  1148. id = cmd->device->id;
  1149. lun = cmd->device->lun;
  1150. ql_log(ql_log_info, vha, 0x8018,
  1151. "ADAPTER RESET ISSUED nexus=%ld:%d:%llu.\n", vha->host_no, id, lun);
  1152. /*
  1153. * No point in issuing another reset if one is active. Also do not
  1154. * attempt a reset if we are updating flash.
  1155. */
  1156. if (qla2x00_reset_active(vha) || ha->optrom_state != QLA_SWAITING)
  1157. goto eh_host_reset_lock;
  1158. if (vha != base_vha) {
  1159. if (qla2x00_vp_abort_isp(vha))
  1160. goto eh_host_reset_lock;
  1161. } else {
  1162. if (IS_P3P_TYPE(vha->hw)) {
  1163. if (!qla82xx_fcoe_ctx_reset(vha)) {
  1164. /* Ctx reset success */
  1165. ret = SUCCESS;
  1166. goto eh_host_reset_lock;
  1167. }
  1168. /* fall thru if ctx reset failed */
  1169. }
  1170. if (ha->wq)
  1171. flush_workqueue(ha->wq);
  1172. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1173. if (ha->isp_ops->abort_isp(base_vha)) {
  1174. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1175. /* failed. schedule dpc to try */
  1176. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  1177. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  1178. ql_log(ql_log_warn, vha, 0x802a,
  1179. "wait for hba online failed.\n");
  1180. goto eh_host_reset_lock;
  1181. }
  1182. }
  1183. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  1184. }
  1185. /* Waiting for command to be returned to OS.*/
  1186. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
  1187. QLA_SUCCESS)
  1188. ret = SUCCESS;
  1189. eh_host_reset_lock:
  1190. ql_log(ql_log_info, vha, 0x8017,
  1191. "ADAPTER RESET %s nexus=%ld:%d:%llu.\n",
  1192. (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
  1193. return ret;
  1194. }
  1195. /*
  1196. * qla2x00_loop_reset
  1197. * Issue loop reset.
  1198. *
  1199. * Input:
  1200. * ha = adapter block pointer.
  1201. *
  1202. * Returns:
  1203. * 0 = success
  1204. */
  1205. int
  1206. qla2x00_loop_reset(scsi_qla_host_t *vha)
  1207. {
  1208. int ret;
  1209. struct fc_port *fcport;
  1210. struct qla_hw_data *ha = vha->hw;
  1211. if (IS_QLAFX00(ha)) {
  1212. return qlafx00_loop_reset(vha);
  1213. }
  1214. if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
  1215. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1216. if (fcport->port_type != FCT_TARGET)
  1217. continue;
  1218. ret = ha->isp_ops->target_reset(fcport, 0, 0);
  1219. if (ret != QLA_SUCCESS) {
  1220. ql_dbg(ql_dbg_taskm, vha, 0x802c,
  1221. "Bus Reset failed: Reset=%d "
  1222. "d_id=%x.\n", ret, fcport->d_id.b24);
  1223. }
  1224. }
  1225. }
  1226. if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
  1227. atomic_set(&vha->loop_state, LOOP_DOWN);
  1228. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  1229. qla2x00_mark_all_devices_lost(vha, 0);
  1230. ret = qla2x00_full_login_lip(vha);
  1231. if (ret != QLA_SUCCESS) {
  1232. ql_dbg(ql_dbg_taskm, vha, 0x802d,
  1233. "full_login_lip=%d.\n", ret);
  1234. }
  1235. }
  1236. if (ha->flags.enable_lip_reset) {
  1237. ret = qla2x00_lip_reset(vha);
  1238. if (ret != QLA_SUCCESS)
  1239. ql_dbg(ql_dbg_taskm, vha, 0x802e,
  1240. "lip_reset failed (%d).\n", ret);
  1241. }
  1242. /* Issue marker command only when we are going to start the I/O */
  1243. vha->marker_needed = 1;
  1244. return QLA_SUCCESS;
  1245. }
  1246. void
  1247. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  1248. {
  1249. int que, cnt;
  1250. unsigned long flags;
  1251. srb_t *sp;
  1252. struct qla_hw_data *ha = vha->hw;
  1253. struct req_que *req;
  1254. qlt_host_reset_handler(ha);
  1255. spin_lock_irqsave(&ha->hardware_lock, flags);
  1256. for (que = 0; que < ha->max_req_queues; que++) {
  1257. req = ha->req_q_map[que];
  1258. if (!req)
  1259. continue;
  1260. if (!req->outstanding_cmds)
  1261. continue;
  1262. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++) {
  1263. sp = req->outstanding_cmds[cnt];
  1264. if (sp) {
  1265. /* Don't abort commands in adapter during EEH
  1266. * recovery as it's not accessible/responding.
  1267. */
  1268. if (GET_CMD_SP(sp) && !ha->flags.eeh_busy &&
  1269. (sp->type == SRB_SCSI_CMD)) {
  1270. /* Get a reference to the sp and drop the lock.
  1271. * The reference ensures this sp->done() call
  1272. * - and not the call in qla2xxx_eh_abort() -
  1273. * ends the SCSI command (with result 'res').
  1274. */
  1275. sp_get(sp);
  1276. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1277. qla2xxx_eh_abort(GET_CMD_SP(sp));
  1278. spin_lock_irqsave(&ha->hardware_lock, flags);
  1279. }
  1280. req->outstanding_cmds[cnt] = NULL;
  1281. sp->done(vha, sp, res);
  1282. }
  1283. }
  1284. }
  1285. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1286. }
  1287. static int
  1288. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1289. {
  1290. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1291. if (!rport || fc_remote_port_chkready(rport))
  1292. return -ENXIO;
  1293. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1294. return 0;
  1295. }
  1296. static int
  1297. qla2xxx_slave_configure(struct scsi_device *sdev)
  1298. {
  1299. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1300. struct req_que *req = vha->req;
  1301. if (IS_T10_PI_CAPABLE(vha->hw))
  1302. blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
  1303. scsi_change_queue_depth(sdev, req->max_q_depth);
  1304. return 0;
  1305. }
  1306. static void
  1307. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1308. {
  1309. sdev->hostdata = NULL;
  1310. }
  1311. /**
  1312. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1313. * @ha: HA context
  1314. *
  1315. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1316. * supported addressing method.
  1317. */
  1318. static void
  1319. qla2x00_config_dma_addressing(struct qla_hw_data *ha)
  1320. {
  1321. /* Assume a 32bit DMA mask. */
  1322. ha->flags.enable_64bit_addressing = 0;
  1323. if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
  1324. /* Any upper-dword bits set? */
  1325. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1326. !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  1327. /* Ok, a 64bit DMA mask is applicable. */
  1328. ha->flags.enable_64bit_addressing = 1;
  1329. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1330. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1331. return;
  1332. }
  1333. }
  1334. dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
  1335. pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
  1336. }
  1337. static void
  1338. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1339. {
  1340. unsigned long flags = 0;
  1341. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1342. spin_lock_irqsave(&ha->hardware_lock, flags);
  1343. ha->interrupts_on = 1;
  1344. /* enable risc and host interrupts */
  1345. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1346. RD_REG_WORD(&reg->ictrl);
  1347. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1348. }
  1349. static void
  1350. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1351. {
  1352. unsigned long flags = 0;
  1353. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1354. spin_lock_irqsave(&ha->hardware_lock, flags);
  1355. ha->interrupts_on = 0;
  1356. /* disable risc and host interrupts */
  1357. WRT_REG_WORD(&reg->ictrl, 0);
  1358. RD_REG_WORD(&reg->ictrl);
  1359. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1360. }
  1361. static void
  1362. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1363. {
  1364. unsigned long flags = 0;
  1365. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1366. spin_lock_irqsave(&ha->hardware_lock, flags);
  1367. ha->interrupts_on = 1;
  1368. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1369. RD_REG_DWORD(&reg->ictrl);
  1370. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1371. }
  1372. static void
  1373. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1374. {
  1375. unsigned long flags = 0;
  1376. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1377. if (IS_NOPOLLING_TYPE(ha))
  1378. return;
  1379. spin_lock_irqsave(&ha->hardware_lock, flags);
  1380. ha->interrupts_on = 0;
  1381. WRT_REG_DWORD(&reg->ictrl, 0);
  1382. RD_REG_DWORD(&reg->ictrl);
  1383. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1384. }
  1385. static int
  1386. qla2x00_iospace_config(struct qla_hw_data *ha)
  1387. {
  1388. resource_size_t pio;
  1389. uint16_t msix;
  1390. int cpus;
  1391. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1392. QLA2XXX_DRIVER_NAME)) {
  1393. ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
  1394. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1395. pci_name(ha->pdev));
  1396. goto iospace_error_exit;
  1397. }
  1398. if (!(ha->bars & 1))
  1399. goto skip_pio;
  1400. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1401. pio = pci_resource_start(ha->pdev, 0);
  1402. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1403. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1404. ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
  1405. "Invalid pci I/O region size (%s).\n",
  1406. pci_name(ha->pdev));
  1407. pio = 0;
  1408. }
  1409. } else {
  1410. ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
  1411. "Region #0 no a PIO resource (%s).\n",
  1412. pci_name(ha->pdev));
  1413. pio = 0;
  1414. }
  1415. ha->pio_address = pio;
  1416. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
  1417. "PIO address=%llu.\n",
  1418. (unsigned long long)ha->pio_address);
  1419. skip_pio:
  1420. /* Use MMIO operations for all accesses. */
  1421. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1422. ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
  1423. "Region #1 not an MMIO resource (%s), aborting.\n",
  1424. pci_name(ha->pdev));
  1425. goto iospace_error_exit;
  1426. }
  1427. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1428. ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
  1429. "Invalid PCI mem region size (%s), aborting.\n",
  1430. pci_name(ha->pdev));
  1431. goto iospace_error_exit;
  1432. }
  1433. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1434. if (!ha->iobase) {
  1435. ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
  1436. "Cannot remap MMIO (%s), aborting.\n",
  1437. pci_name(ha->pdev));
  1438. goto iospace_error_exit;
  1439. }
  1440. /* Determine queue resources */
  1441. ha->max_req_queues = ha->max_rsp_queues = 1;
  1442. if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
  1443. (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
  1444. (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1445. goto mqiobase_exit;
  1446. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1447. pci_resource_len(ha->pdev, 3));
  1448. if (ha->mqiobase) {
  1449. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
  1450. "MQIO Base=%p.\n", ha->mqiobase);
  1451. /* Read MSIX vector size of the board */
  1452. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1453. ha->msix_count = msix;
  1454. /* Max queues are bounded by available msix vectors */
  1455. /* queue 0 uses two msix vectors */
  1456. if (ql2xmultique_tag) {
  1457. cpus = num_online_cpus();
  1458. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1459. (cpus + 1) : (ha->msix_count - 1);
  1460. ha->max_req_queues = 2;
  1461. } else if (ql2xmaxqueues > 1) {
  1462. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1463. QLA_MQ_SIZE : ql2xmaxqueues;
  1464. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
  1465. "QoS mode set, max no of request queues:%d.\n",
  1466. ha->max_req_queues);
  1467. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
  1468. "QoS mode set, max no of request queues:%d.\n",
  1469. ha->max_req_queues);
  1470. }
  1471. ql_log_pci(ql_log_info, ha->pdev, 0x001a,
  1472. "MSI-X vector count: %d.\n", msix);
  1473. } else
  1474. ql_log_pci(ql_log_info, ha->pdev, 0x001b,
  1475. "BAR 3 not enabled.\n");
  1476. mqiobase_exit:
  1477. ha->msix_count = ha->max_rsp_queues + 1;
  1478. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
  1479. "MSIX Count:%d.\n", ha->msix_count);
  1480. return (0);
  1481. iospace_error_exit:
  1482. return (-ENOMEM);
  1483. }
  1484. static int
  1485. qla83xx_iospace_config(struct qla_hw_data *ha)
  1486. {
  1487. uint16_t msix;
  1488. int cpus;
  1489. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1490. QLA2XXX_DRIVER_NAME)) {
  1491. ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
  1492. "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
  1493. pci_name(ha->pdev));
  1494. goto iospace_error_exit;
  1495. }
  1496. /* Use MMIO operations for all accesses. */
  1497. if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
  1498. ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
  1499. "Invalid pci I/O region size (%s).\n",
  1500. pci_name(ha->pdev));
  1501. goto iospace_error_exit;
  1502. }
  1503. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1504. ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
  1505. "Invalid PCI mem region size (%s), aborting\n",
  1506. pci_name(ha->pdev));
  1507. goto iospace_error_exit;
  1508. }
  1509. ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
  1510. if (!ha->iobase) {
  1511. ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
  1512. "Cannot remap MMIO (%s), aborting.\n",
  1513. pci_name(ha->pdev));
  1514. goto iospace_error_exit;
  1515. }
  1516. /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
  1517. /* 83XX 26XX always use MQ type access for queues
  1518. * - mbar 2, a.k.a region 4 */
  1519. ha->max_req_queues = ha->max_rsp_queues = 1;
  1520. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
  1521. pci_resource_len(ha->pdev, 4));
  1522. if (!ha->mqiobase) {
  1523. ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
  1524. "BAR2/region4 not enabled\n");
  1525. goto mqiobase_exit;
  1526. }
  1527. ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
  1528. pci_resource_len(ha->pdev, 2));
  1529. if (ha->msixbase) {
  1530. /* Read MSIX vector size of the board */
  1531. pci_read_config_word(ha->pdev,
  1532. QLA_83XX_PCI_MSIX_CONTROL, &msix);
  1533. ha->msix_count = msix;
  1534. /* Max queues are bounded by available msix vectors */
  1535. /* queue 0 uses two msix vectors */
  1536. if (ql2xmultique_tag) {
  1537. cpus = num_online_cpus();
  1538. ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
  1539. (cpus + 1) : (ha->msix_count - 1);
  1540. ha->max_req_queues = 2;
  1541. } else if (ql2xmaxqueues > 1) {
  1542. ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
  1543. QLA_MQ_SIZE : ql2xmaxqueues;
  1544. ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
  1545. "QoS mode set, max no of request queues:%d.\n",
  1546. ha->max_req_queues);
  1547. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
  1548. "QoS mode set, max no of request queues:%d.\n",
  1549. ha->max_req_queues);
  1550. }
  1551. ql_log_pci(ql_log_info, ha->pdev, 0x011c,
  1552. "MSI-X vector count: %d.\n", msix);
  1553. } else
  1554. ql_log_pci(ql_log_info, ha->pdev, 0x011e,
  1555. "BAR 1 not enabled.\n");
  1556. mqiobase_exit:
  1557. ha->msix_count = ha->max_rsp_queues + 1;
  1558. qlt_83xx_iospace_config(ha);
  1559. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
  1560. "MSIX Count:%d.\n", ha->msix_count);
  1561. return 0;
  1562. iospace_error_exit:
  1563. return -ENOMEM;
  1564. }
  1565. static struct isp_operations qla2100_isp_ops = {
  1566. .pci_config = qla2100_pci_config,
  1567. .reset_chip = qla2x00_reset_chip,
  1568. .chip_diag = qla2x00_chip_diag,
  1569. .config_rings = qla2x00_config_rings,
  1570. .reset_adapter = qla2x00_reset_adapter,
  1571. .nvram_config = qla2x00_nvram_config,
  1572. .update_fw_options = qla2x00_update_fw_options,
  1573. .load_risc = qla2x00_load_risc,
  1574. .pci_info_str = qla2x00_pci_info_str,
  1575. .fw_version_str = qla2x00_fw_version_str,
  1576. .intr_handler = qla2100_intr_handler,
  1577. .enable_intrs = qla2x00_enable_intrs,
  1578. .disable_intrs = qla2x00_disable_intrs,
  1579. .abort_command = qla2x00_abort_command,
  1580. .target_reset = qla2x00_abort_target,
  1581. .lun_reset = qla2x00_lun_reset,
  1582. .fabric_login = qla2x00_login_fabric,
  1583. .fabric_logout = qla2x00_fabric_logout,
  1584. .calc_req_entries = qla2x00_calc_iocbs_32,
  1585. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1586. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1587. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1588. .read_nvram = qla2x00_read_nvram_data,
  1589. .write_nvram = qla2x00_write_nvram_data,
  1590. .fw_dump = qla2100_fw_dump,
  1591. .beacon_on = NULL,
  1592. .beacon_off = NULL,
  1593. .beacon_blink = NULL,
  1594. .read_optrom = qla2x00_read_optrom_data,
  1595. .write_optrom = qla2x00_write_optrom_data,
  1596. .get_flash_version = qla2x00_get_flash_version,
  1597. .start_scsi = qla2x00_start_scsi,
  1598. .abort_isp = qla2x00_abort_isp,
  1599. .iospace_config = qla2x00_iospace_config,
  1600. .initialize_adapter = qla2x00_initialize_adapter,
  1601. };
  1602. static struct isp_operations qla2300_isp_ops = {
  1603. .pci_config = qla2300_pci_config,
  1604. .reset_chip = qla2x00_reset_chip,
  1605. .chip_diag = qla2x00_chip_diag,
  1606. .config_rings = qla2x00_config_rings,
  1607. .reset_adapter = qla2x00_reset_adapter,
  1608. .nvram_config = qla2x00_nvram_config,
  1609. .update_fw_options = qla2x00_update_fw_options,
  1610. .load_risc = qla2x00_load_risc,
  1611. .pci_info_str = qla2x00_pci_info_str,
  1612. .fw_version_str = qla2x00_fw_version_str,
  1613. .intr_handler = qla2300_intr_handler,
  1614. .enable_intrs = qla2x00_enable_intrs,
  1615. .disable_intrs = qla2x00_disable_intrs,
  1616. .abort_command = qla2x00_abort_command,
  1617. .target_reset = qla2x00_abort_target,
  1618. .lun_reset = qla2x00_lun_reset,
  1619. .fabric_login = qla2x00_login_fabric,
  1620. .fabric_logout = qla2x00_fabric_logout,
  1621. .calc_req_entries = qla2x00_calc_iocbs_32,
  1622. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1623. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1624. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1625. .read_nvram = qla2x00_read_nvram_data,
  1626. .write_nvram = qla2x00_write_nvram_data,
  1627. .fw_dump = qla2300_fw_dump,
  1628. .beacon_on = qla2x00_beacon_on,
  1629. .beacon_off = qla2x00_beacon_off,
  1630. .beacon_blink = qla2x00_beacon_blink,
  1631. .read_optrom = qla2x00_read_optrom_data,
  1632. .write_optrom = qla2x00_write_optrom_data,
  1633. .get_flash_version = qla2x00_get_flash_version,
  1634. .start_scsi = qla2x00_start_scsi,
  1635. .abort_isp = qla2x00_abort_isp,
  1636. .iospace_config = qla2x00_iospace_config,
  1637. .initialize_adapter = qla2x00_initialize_adapter,
  1638. };
  1639. static struct isp_operations qla24xx_isp_ops = {
  1640. .pci_config = qla24xx_pci_config,
  1641. .reset_chip = qla24xx_reset_chip,
  1642. .chip_diag = qla24xx_chip_diag,
  1643. .config_rings = qla24xx_config_rings,
  1644. .reset_adapter = qla24xx_reset_adapter,
  1645. .nvram_config = qla24xx_nvram_config,
  1646. .update_fw_options = qla24xx_update_fw_options,
  1647. .load_risc = qla24xx_load_risc,
  1648. .pci_info_str = qla24xx_pci_info_str,
  1649. .fw_version_str = qla24xx_fw_version_str,
  1650. .intr_handler = qla24xx_intr_handler,
  1651. .enable_intrs = qla24xx_enable_intrs,
  1652. .disable_intrs = qla24xx_disable_intrs,
  1653. .abort_command = qla24xx_abort_command,
  1654. .target_reset = qla24xx_abort_target,
  1655. .lun_reset = qla24xx_lun_reset,
  1656. .fabric_login = qla24xx_login_fabric,
  1657. .fabric_logout = qla24xx_fabric_logout,
  1658. .calc_req_entries = NULL,
  1659. .build_iocbs = NULL,
  1660. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1661. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1662. .read_nvram = qla24xx_read_nvram_data,
  1663. .write_nvram = qla24xx_write_nvram_data,
  1664. .fw_dump = qla24xx_fw_dump,
  1665. .beacon_on = qla24xx_beacon_on,
  1666. .beacon_off = qla24xx_beacon_off,
  1667. .beacon_blink = qla24xx_beacon_blink,
  1668. .read_optrom = qla24xx_read_optrom_data,
  1669. .write_optrom = qla24xx_write_optrom_data,
  1670. .get_flash_version = qla24xx_get_flash_version,
  1671. .start_scsi = qla24xx_start_scsi,
  1672. .abort_isp = qla2x00_abort_isp,
  1673. .iospace_config = qla2x00_iospace_config,
  1674. .initialize_adapter = qla2x00_initialize_adapter,
  1675. };
  1676. static struct isp_operations qla25xx_isp_ops = {
  1677. .pci_config = qla25xx_pci_config,
  1678. .reset_chip = qla24xx_reset_chip,
  1679. .chip_diag = qla24xx_chip_diag,
  1680. .config_rings = qla24xx_config_rings,
  1681. .reset_adapter = qla24xx_reset_adapter,
  1682. .nvram_config = qla24xx_nvram_config,
  1683. .update_fw_options = qla24xx_update_fw_options,
  1684. .load_risc = qla24xx_load_risc,
  1685. .pci_info_str = qla24xx_pci_info_str,
  1686. .fw_version_str = qla24xx_fw_version_str,
  1687. .intr_handler = qla24xx_intr_handler,
  1688. .enable_intrs = qla24xx_enable_intrs,
  1689. .disable_intrs = qla24xx_disable_intrs,
  1690. .abort_command = qla24xx_abort_command,
  1691. .target_reset = qla24xx_abort_target,
  1692. .lun_reset = qla24xx_lun_reset,
  1693. .fabric_login = qla24xx_login_fabric,
  1694. .fabric_logout = qla24xx_fabric_logout,
  1695. .calc_req_entries = NULL,
  1696. .build_iocbs = NULL,
  1697. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1698. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1699. .read_nvram = qla25xx_read_nvram_data,
  1700. .write_nvram = qla25xx_write_nvram_data,
  1701. .fw_dump = qla25xx_fw_dump,
  1702. .beacon_on = qla24xx_beacon_on,
  1703. .beacon_off = qla24xx_beacon_off,
  1704. .beacon_blink = qla24xx_beacon_blink,
  1705. .read_optrom = qla25xx_read_optrom_data,
  1706. .write_optrom = qla24xx_write_optrom_data,
  1707. .get_flash_version = qla24xx_get_flash_version,
  1708. .start_scsi = qla24xx_dif_start_scsi,
  1709. .abort_isp = qla2x00_abort_isp,
  1710. .iospace_config = qla2x00_iospace_config,
  1711. .initialize_adapter = qla2x00_initialize_adapter,
  1712. };
  1713. static struct isp_operations qla81xx_isp_ops = {
  1714. .pci_config = qla25xx_pci_config,
  1715. .reset_chip = qla24xx_reset_chip,
  1716. .chip_diag = qla24xx_chip_diag,
  1717. .config_rings = qla24xx_config_rings,
  1718. .reset_adapter = qla24xx_reset_adapter,
  1719. .nvram_config = qla81xx_nvram_config,
  1720. .update_fw_options = qla81xx_update_fw_options,
  1721. .load_risc = qla81xx_load_risc,
  1722. .pci_info_str = qla24xx_pci_info_str,
  1723. .fw_version_str = qla24xx_fw_version_str,
  1724. .intr_handler = qla24xx_intr_handler,
  1725. .enable_intrs = qla24xx_enable_intrs,
  1726. .disable_intrs = qla24xx_disable_intrs,
  1727. .abort_command = qla24xx_abort_command,
  1728. .target_reset = qla24xx_abort_target,
  1729. .lun_reset = qla24xx_lun_reset,
  1730. .fabric_login = qla24xx_login_fabric,
  1731. .fabric_logout = qla24xx_fabric_logout,
  1732. .calc_req_entries = NULL,
  1733. .build_iocbs = NULL,
  1734. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1735. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1736. .read_nvram = NULL,
  1737. .write_nvram = NULL,
  1738. .fw_dump = qla81xx_fw_dump,
  1739. .beacon_on = qla24xx_beacon_on,
  1740. .beacon_off = qla24xx_beacon_off,
  1741. .beacon_blink = qla83xx_beacon_blink,
  1742. .read_optrom = qla25xx_read_optrom_data,
  1743. .write_optrom = qla24xx_write_optrom_data,
  1744. .get_flash_version = qla24xx_get_flash_version,
  1745. .start_scsi = qla24xx_dif_start_scsi,
  1746. .abort_isp = qla2x00_abort_isp,
  1747. .iospace_config = qla2x00_iospace_config,
  1748. .initialize_adapter = qla2x00_initialize_adapter,
  1749. };
  1750. static struct isp_operations qla82xx_isp_ops = {
  1751. .pci_config = qla82xx_pci_config,
  1752. .reset_chip = qla82xx_reset_chip,
  1753. .chip_diag = qla24xx_chip_diag,
  1754. .config_rings = qla82xx_config_rings,
  1755. .reset_adapter = qla24xx_reset_adapter,
  1756. .nvram_config = qla81xx_nvram_config,
  1757. .update_fw_options = qla24xx_update_fw_options,
  1758. .load_risc = qla82xx_load_risc,
  1759. .pci_info_str = qla24xx_pci_info_str,
  1760. .fw_version_str = qla24xx_fw_version_str,
  1761. .intr_handler = qla82xx_intr_handler,
  1762. .enable_intrs = qla82xx_enable_intrs,
  1763. .disable_intrs = qla82xx_disable_intrs,
  1764. .abort_command = qla24xx_abort_command,
  1765. .target_reset = qla24xx_abort_target,
  1766. .lun_reset = qla24xx_lun_reset,
  1767. .fabric_login = qla24xx_login_fabric,
  1768. .fabric_logout = qla24xx_fabric_logout,
  1769. .calc_req_entries = NULL,
  1770. .build_iocbs = NULL,
  1771. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1772. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1773. .read_nvram = qla24xx_read_nvram_data,
  1774. .write_nvram = qla24xx_write_nvram_data,
  1775. .fw_dump = qla82xx_fw_dump,
  1776. .beacon_on = qla82xx_beacon_on,
  1777. .beacon_off = qla82xx_beacon_off,
  1778. .beacon_blink = NULL,
  1779. .read_optrom = qla82xx_read_optrom_data,
  1780. .write_optrom = qla82xx_write_optrom_data,
  1781. .get_flash_version = qla82xx_get_flash_version,
  1782. .start_scsi = qla82xx_start_scsi,
  1783. .abort_isp = qla82xx_abort_isp,
  1784. .iospace_config = qla82xx_iospace_config,
  1785. .initialize_adapter = qla2x00_initialize_adapter,
  1786. };
  1787. static struct isp_operations qla8044_isp_ops = {
  1788. .pci_config = qla82xx_pci_config,
  1789. .reset_chip = qla82xx_reset_chip,
  1790. .chip_diag = qla24xx_chip_diag,
  1791. .config_rings = qla82xx_config_rings,
  1792. .reset_adapter = qla24xx_reset_adapter,
  1793. .nvram_config = qla81xx_nvram_config,
  1794. .update_fw_options = qla24xx_update_fw_options,
  1795. .load_risc = qla82xx_load_risc,
  1796. .pci_info_str = qla24xx_pci_info_str,
  1797. .fw_version_str = qla24xx_fw_version_str,
  1798. .intr_handler = qla8044_intr_handler,
  1799. .enable_intrs = qla82xx_enable_intrs,
  1800. .disable_intrs = qla82xx_disable_intrs,
  1801. .abort_command = qla24xx_abort_command,
  1802. .target_reset = qla24xx_abort_target,
  1803. .lun_reset = qla24xx_lun_reset,
  1804. .fabric_login = qla24xx_login_fabric,
  1805. .fabric_logout = qla24xx_fabric_logout,
  1806. .calc_req_entries = NULL,
  1807. .build_iocbs = NULL,
  1808. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1809. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1810. .read_nvram = NULL,
  1811. .write_nvram = NULL,
  1812. .fw_dump = qla8044_fw_dump,
  1813. .beacon_on = qla82xx_beacon_on,
  1814. .beacon_off = qla82xx_beacon_off,
  1815. .beacon_blink = NULL,
  1816. .read_optrom = qla8044_read_optrom_data,
  1817. .write_optrom = qla8044_write_optrom_data,
  1818. .get_flash_version = qla82xx_get_flash_version,
  1819. .start_scsi = qla82xx_start_scsi,
  1820. .abort_isp = qla8044_abort_isp,
  1821. .iospace_config = qla82xx_iospace_config,
  1822. .initialize_adapter = qla2x00_initialize_adapter,
  1823. };
  1824. static struct isp_operations qla83xx_isp_ops = {
  1825. .pci_config = qla25xx_pci_config,
  1826. .reset_chip = qla24xx_reset_chip,
  1827. .chip_diag = qla24xx_chip_diag,
  1828. .config_rings = qla24xx_config_rings,
  1829. .reset_adapter = qla24xx_reset_adapter,
  1830. .nvram_config = qla81xx_nvram_config,
  1831. .update_fw_options = qla81xx_update_fw_options,
  1832. .load_risc = qla81xx_load_risc,
  1833. .pci_info_str = qla24xx_pci_info_str,
  1834. .fw_version_str = qla24xx_fw_version_str,
  1835. .intr_handler = qla24xx_intr_handler,
  1836. .enable_intrs = qla24xx_enable_intrs,
  1837. .disable_intrs = qla24xx_disable_intrs,
  1838. .abort_command = qla24xx_abort_command,
  1839. .target_reset = qla24xx_abort_target,
  1840. .lun_reset = qla24xx_lun_reset,
  1841. .fabric_login = qla24xx_login_fabric,
  1842. .fabric_logout = qla24xx_fabric_logout,
  1843. .calc_req_entries = NULL,
  1844. .build_iocbs = NULL,
  1845. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1846. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1847. .read_nvram = NULL,
  1848. .write_nvram = NULL,
  1849. .fw_dump = qla83xx_fw_dump,
  1850. .beacon_on = qla24xx_beacon_on,
  1851. .beacon_off = qla24xx_beacon_off,
  1852. .beacon_blink = qla83xx_beacon_blink,
  1853. .read_optrom = qla25xx_read_optrom_data,
  1854. .write_optrom = qla24xx_write_optrom_data,
  1855. .get_flash_version = qla24xx_get_flash_version,
  1856. .start_scsi = qla24xx_dif_start_scsi,
  1857. .abort_isp = qla2x00_abort_isp,
  1858. .iospace_config = qla83xx_iospace_config,
  1859. .initialize_adapter = qla2x00_initialize_adapter,
  1860. };
  1861. static struct isp_operations qlafx00_isp_ops = {
  1862. .pci_config = qlafx00_pci_config,
  1863. .reset_chip = qlafx00_soft_reset,
  1864. .chip_diag = qlafx00_chip_diag,
  1865. .config_rings = qlafx00_config_rings,
  1866. .reset_adapter = qlafx00_soft_reset,
  1867. .nvram_config = NULL,
  1868. .update_fw_options = NULL,
  1869. .load_risc = NULL,
  1870. .pci_info_str = qlafx00_pci_info_str,
  1871. .fw_version_str = qlafx00_fw_version_str,
  1872. .intr_handler = qlafx00_intr_handler,
  1873. .enable_intrs = qlafx00_enable_intrs,
  1874. .disable_intrs = qlafx00_disable_intrs,
  1875. .abort_command = qla24xx_async_abort_command,
  1876. .target_reset = qlafx00_abort_target,
  1877. .lun_reset = qlafx00_lun_reset,
  1878. .fabric_login = NULL,
  1879. .fabric_logout = NULL,
  1880. .calc_req_entries = NULL,
  1881. .build_iocbs = NULL,
  1882. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1883. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1884. .read_nvram = qla24xx_read_nvram_data,
  1885. .write_nvram = qla24xx_write_nvram_data,
  1886. .fw_dump = NULL,
  1887. .beacon_on = qla24xx_beacon_on,
  1888. .beacon_off = qla24xx_beacon_off,
  1889. .beacon_blink = NULL,
  1890. .read_optrom = qla24xx_read_optrom_data,
  1891. .write_optrom = qla24xx_write_optrom_data,
  1892. .get_flash_version = qla24xx_get_flash_version,
  1893. .start_scsi = qlafx00_start_scsi,
  1894. .abort_isp = qlafx00_abort_isp,
  1895. .iospace_config = qlafx00_iospace_config,
  1896. .initialize_adapter = qlafx00_initialize_adapter,
  1897. };
  1898. static struct isp_operations qla27xx_isp_ops = {
  1899. .pci_config = qla25xx_pci_config,
  1900. .reset_chip = qla24xx_reset_chip,
  1901. .chip_diag = qla24xx_chip_diag,
  1902. .config_rings = qla24xx_config_rings,
  1903. .reset_adapter = qla24xx_reset_adapter,
  1904. .nvram_config = qla81xx_nvram_config,
  1905. .update_fw_options = qla81xx_update_fw_options,
  1906. .load_risc = qla81xx_load_risc,
  1907. .pci_info_str = qla24xx_pci_info_str,
  1908. .fw_version_str = qla24xx_fw_version_str,
  1909. .intr_handler = qla24xx_intr_handler,
  1910. .enable_intrs = qla24xx_enable_intrs,
  1911. .disable_intrs = qla24xx_disable_intrs,
  1912. .abort_command = qla24xx_abort_command,
  1913. .target_reset = qla24xx_abort_target,
  1914. .lun_reset = qla24xx_lun_reset,
  1915. .fabric_login = qla24xx_login_fabric,
  1916. .fabric_logout = qla24xx_fabric_logout,
  1917. .calc_req_entries = NULL,
  1918. .build_iocbs = NULL,
  1919. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1920. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1921. .read_nvram = NULL,
  1922. .write_nvram = NULL,
  1923. .fw_dump = qla27xx_fwdump,
  1924. .beacon_on = qla24xx_beacon_on,
  1925. .beacon_off = qla24xx_beacon_off,
  1926. .beacon_blink = qla83xx_beacon_blink,
  1927. .read_optrom = qla25xx_read_optrom_data,
  1928. .write_optrom = qla24xx_write_optrom_data,
  1929. .get_flash_version = qla24xx_get_flash_version,
  1930. .start_scsi = qla24xx_dif_start_scsi,
  1931. .abort_isp = qla2x00_abort_isp,
  1932. .iospace_config = qla83xx_iospace_config,
  1933. .initialize_adapter = qla2x00_initialize_adapter,
  1934. };
  1935. static inline void
  1936. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1937. {
  1938. ha->device_type = DT_EXTENDED_IDS;
  1939. switch (ha->pdev->device) {
  1940. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1941. ha->isp_type |= DT_ISP2100;
  1942. ha->device_type &= ~DT_EXTENDED_IDS;
  1943. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1944. break;
  1945. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1946. ha->isp_type |= DT_ISP2200;
  1947. ha->device_type &= ~DT_EXTENDED_IDS;
  1948. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1949. break;
  1950. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1951. ha->isp_type |= DT_ISP2300;
  1952. ha->device_type |= DT_ZIO_SUPPORTED;
  1953. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1954. break;
  1955. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1956. ha->isp_type |= DT_ISP2312;
  1957. ha->device_type |= DT_ZIO_SUPPORTED;
  1958. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1959. break;
  1960. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1961. ha->isp_type |= DT_ISP2322;
  1962. ha->device_type |= DT_ZIO_SUPPORTED;
  1963. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1964. ha->pdev->subsystem_device == 0x0170)
  1965. ha->device_type |= DT_OEM_001;
  1966. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1967. break;
  1968. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1969. ha->isp_type |= DT_ISP6312;
  1970. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1971. break;
  1972. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1973. ha->isp_type |= DT_ISP6322;
  1974. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1975. break;
  1976. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1977. ha->isp_type |= DT_ISP2422;
  1978. ha->device_type |= DT_ZIO_SUPPORTED;
  1979. ha->device_type |= DT_FWI2;
  1980. ha->device_type |= DT_IIDMA;
  1981. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1982. break;
  1983. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1984. ha->isp_type |= DT_ISP2432;
  1985. ha->device_type |= DT_ZIO_SUPPORTED;
  1986. ha->device_type |= DT_FWI2;
  1987. ha->device_type |= DT_IIDMA;
  1988. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1989. break;
  1990. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1991. ha->isp_type |= DT_ISP8432;
  1992. ha->device_type |= DT_ZIO_SUPPORTED;
  1993. ha->device_type |= DT_FWI2;
  1994. ha->device_type |= DT_IIDMA;
  1995. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1996. break;
  1997. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1998. ha->isp_type |= DT_ISP5422;
  1999. ha->device_type |= DT_FWI2;
  2000. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2001. break;
  2002. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  2003. ha->isp_type |= DT_ISP5432;
  2004. ha->device_type |= DT_FWI2;
  2005. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2006. break;
  2007. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  2008. ha->isp_type |= DT_ISP2532;
  2009. ha->device_type |= DT_ZIO_SUPPORTED;
  2010. ha->device_type |= DT_FWI2;
  2011. ha->device_type |= DT_IIDMA;
  2012. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2013. break;
  2014. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  2015. ha->isp_type |= DT_ISP8001;
  2016. ha->device_type |= DT_ZIO_SUPPORTED;
  2017. ha->device_type |= DT_FWI2;
  2018. ha->device_type |= DT_IIDMA;
  2019. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2020. break;
  2021. case PCI_DEVICE_ID_QLOGIC_ISP8021:
  2022. ha->isp_type |= DT_ISP8021;
  2023. ha->device_type |= DT_ZIO_SUPPORTED;
  2024. ha->device_type |= DT_FWI2;
  2025. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2026. /* Initialize 82XX ISP flags */
  2027. qla82xx_init_flags(ha);
  2028. break;
  2029. case PCI_DEVICE_ID_QLOGIC_ISP8044:
  2030. ha->isp_type |= DT_ISP8044;
  2031. ha->device_type |= DT_ZIO_SUPPORTED;
  2032. ha->device_type |= DT_FWI2;
  2033. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2034. /* Initialize 82XX ISP flags */
  2035. qla82xx_init_flags(ha);
  2036. break;
  2037. case PCI_DEVICE_ID_QLOGIC_ISP2031:
  2038. ha->isp_type |= DT_ISP2031;
  2039. ha->device_type |= DT_ZIO_SUPPORTED;
  2040. ha->device_type |= DT_FWI2;
  2041. ha->device_type |= DT_IIDMA;
  2042. ha->device_type |= DT_T10_PI;
  2043. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2044. break;
  2045. case PCI_DEVICE_ID_QLOGIC_ISP8031:
  2046. ha->isp_type |= DT_ISP8031;
  2047. ha->device_type |= DT_ZIO_SUPPORTED;
  2048. ha->device_type |= DT_FWI2;
  2049. ha->device_type |= DT_IIDMA;
  2050. ha->device_type |= DT_T10_PI;
  2051. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2052. break;
  2053. case PCI_DEVICE_ID_QLOGIC_ISPF001:
  2054. ha->isp_type |= DT_ISPFX00;
  2055. break;
  2056. case PCI_DEVICE_ID_QLOGIC_ISP2071:
  2057. ha->isp_type |= DT_ISP2071;
  2058. ha->device_type |= DT_ZIO_SUPPORTED;
  2059. ha->device_type |= DT_FWI2;
  2060. ha->device_type |= DT_IIDMA;
  2061. ha->device_type |= DT_T10_PI;
  2062. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2063. break;
  2064. case PCI_DEVICE_ID_QLOGIC_ISP2271:
  2065. ha->isp_type |= DT_ISP2271;
  2066. ha->device_type |= DT_ZIO_SUPPORTED;
  2067. ha->device_type |= DT_FWI2;
  2068. ha->device_type |= DT_IIDMA;
  2069. ha->device_type |= DT_T10_PI;
  2070. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2071. break;
  2072. case PCI_DEVICE_ID_QLOGIC_ISP2261:
  2073. ha->isp_type |= DT_ISP2261;
  2074. ha->device_type |= DT_ZIO_SUPPORTED;
  2075. ha->device_type |= DT_FWI2;
  2076. ha->device_type |= DT_IIDMA;
  2077. ha->device_type |= DT_T10_PI;
  2078. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  2079. break;
  2080. }
  2081. if (IS_QLA82XX(ha))
  2082. ha->port_no = ha->portnum & 1;
  2083. else {
  2084. /* Get adapter physical port no from interrupt pin register. */
  2085. pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
  2086. if (IS_QLA27XX(ha))
  2087. ha->port_no--;
  2088. else
  2089. ha->port_no = !(ha->port_no & 1);
  2090. }
  2091. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
  2092. "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
  2093. ha->device_type, ha->port_no, ha->fw_srisc_address);
  2094. }
  2095. static void
  2096. qla2xxx_scan_start(struct Scsi_Host *shost)
  2097. {
  2098. scsi_qla_host_t *vha = shost_priv(shost);
  2099. if (vha->hw->flags.running_gold_fw)
  2100. return;
  2101. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2102. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2103. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2104. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  2105. }
  2106. static int
  2107. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  2108. {
  2109. scsi_qla_host_t *vha = shost_priv(shost);
  2110. if (test_bit(UNLOADING, &vha->dpc_flags))
  2111. return 1;
  2112. if (!vha->host)
  2113. return 1;
  2114. if (time > vha->hw->loop_reset_delay * HZ)
  2115. return 1;
  2116. return atomic_read(&vha->loop_state) == LOOP_READY;
  2117. }
  2118. /*
  2119. * PCI driver interface
  2120. */
  2121. static int
  2122. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2123. {
  2124. int ret = -ENODEV;
  2125. struct Scsi_Host *host;
  2126. scsi_qla_host_t *base_vha = NULL;
  2127. struct qla_hw_data *ha;
  2128. char pci_info[30];
  2129. char fw_str[30], wq_name[30];
  2130. struct scsi_host_template *sht;
  2131. int bars, mem_only = 0;
  2132. uint16_t req_length = 0, rsp_length = 0;
  2133. struct req_que *req = NULL;
  2134. struct rsp_que *rsp = NULL;
  2135. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  2136. sht = &qla2xxx_driver_template;
  2137. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  2138. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  2139. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  2140. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  2141. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  2142. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  2143. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
  2144. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
  2145. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
  2146. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031 ||
  2147. pdev->device == PCI_DEVICE_ID_QLOGIC_ISPF001 ||
  2148. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8044 ||
  2149. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2071 ||
  2150. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2271 ||
  2151. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2261) {
  2152. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  2153. mem_only = 1;
  2154. ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
  2155. "Mem only adapter.\n");
  2156. }
  2157. ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
  2158. "Bars=%d.\n", bars);
  2159. if (mem_only) {
  2160. if (pci_enable_device_mem(pdev))
  2161. return ret;
  2162. } else {
  2163. if (pci_enable_device(pdev))
  2164. return ret;
  2165. }
  2166. /* This may fail but that's ok */
  2167. pci_enable_pcie_error_reporting(pdev);
  2168. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  2169. if (!ha) {
  2170. ql_log_pci(ql_log_fatal, pdev, 0x0009,
  2171. "Unable to allocate memory for ha.\n");
  2172. goto disable_device;
  2173. }
  2174. ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
  2175. "Memory allocated for ha=%p.\n", ha);
  2176. ha->pdev = pdev;
  2177. ha->tgt.enable_class_2 = ql2xenableclass2;
  2178. INIT_LIST_HEAD(&ha->tgt.q_full_list);
  2179. spin_lock_init(&ha->tgt.q_full_lock);
  2180. spin_lock_init(&ha->tgt.sess_lock);
  2181. spin_lock_init(&ha->tgt.atio_lock);
  2182. /* Clear our data area */
  2183. ha->bars = bars;
  2184. ha->mem_only = mem_only;
  2185. spin_lock_init(&ha->hardware_lock);
  2186. spin_lock_init(&ha->vport_slock);
  2187. mutex_init(&ha->selflogin_lock);
  2188. mutex_init(&ha->optrom_mutex);
  2189. /* Set ISP-type information. */
  2190. qla2x00_set_isp_flags(ha);
  2191. /* Set EEH reset type to fundamental if required by hba */
  2192. if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha) ||
  2193. IS_QLA83XX(ha) || IS_QLA27XX(ha))
  2194. pdev->needs_freset = 1;
  2195. ha->prev_topology = 0;
  2196. ha->init_cb_size = sizeof(init_cb_t);
  2197. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  2198. ha->optrom_size = OPTROM_SIZE_2300;
  2199. /* Assign ISP specific operations. */
  2200. if (IS_QLA2100(ha)) {
  2201. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2202. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  2203. req_length = REQUEST_ENTRY_CNT_2100;
  2204. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2205. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2206. ha->gid_list_info_size = 4;
  2207. ha->flash_conf_off = ~0;
  2208. ha->flash_data_off = ~0;
  2209. ha->nvram_conf_off = ~0;
  2210. ha->nvram_data_off = ~0;
  2211. ha->isp_ops = &qla2100_isp_ops;
  2212. } else if (IS_QLA2200(ha)) {
  2213. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2214. ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
  2215. req_length = REQUEST_ENTRY_CNT_2200;
  2216. rsp_length = RESPONSE_ENTRY_CNT_2100;
  2217. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  2218. ha->gid_list_info_size = 4;
  2219. ha->flash_conf_off = ~0;
  2220. ha->flash_data_off = ~0;
  2221. ha->nvram_conf_off = ~0;
  2222. ha->nvram_data_off = ~0;
  2223. ha->isp_ops = &qla2100_isp_ops;
  2224. } else if (IS_QLA23XX(ha)) {
  2225. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2100;
  2226. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2227. req_length = REQUEST_ENTRY_CNT_2200;
  2228. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2229. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2230. ha->gid_list_info_size = 6;
  2231. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2232. ha->optrom_size = OPTROM_SIZE_2322;
  2233. ha->flash_conf_off = ~0;
  2234. ha->flash_data_off = ~0;
  2235. ha->nvram_conf_off = ~0;
  2236. ha->nvram_data_off = ~0;
  2237. ha->isp_ops = &qla2300_isp_ops;
  2238. } else if (IS_QLA24XX_TYPE(ha)) {
  2239. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2240. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2241. req_length = REQUEST_ENTRY_CNT_24XX;
  2242. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2243. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2244. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2245. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2246. ha->gid_list_info_size = 8;
  2247. ha->optrom_size = OPTROM_SIZE_24XX;
  2248. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  2249. ha->isp_ops = &qla24xx_isp_ops;
  2250. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2251. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2252. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2253. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2254. } else if (IS_QLA25XX(ha)) {
  2255. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2256. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2257. req_length = REQUEST_ENTRY_CNT_24XX;
  2258. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2259. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2260. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2261. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  2262. ha->gid_list_info_size = 8;
  2263. ha->optrom_size = OPTROM_SIZE_25XX;
  2264. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2265. ha->isp_ops = &qla25xx_isp_ops;
  2266. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2267. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2268. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2269. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2270. } else if (IS_QLA81XX(ha)) {
  2271. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2272. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2273. req_length = REQUEST_ENTRY_CNT_24XX;
  2274. rsp_length = RESPONSE_ENTRY_CNT_2300;
  2275. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2276. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2277. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2278. ha->gid_list_info_size = 8;
  2279. ha->optrom_size = OPTROM_SIZE_81XX;
  2280. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2281. ha->isp_ops = &qla81xx_isp_ops;
  2282. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2283. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2284. ha->nvram_conf_off = ~0;
  2285. ha->nvram_data_off = ~0;
  2286. } else if (IS_QLA82XX(ha)) {
  2287. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2288. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2289. req_length = REQUEST_ENTRY_CNT_82XX;
  2290. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2291. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2292. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2293. ha->gid_list_info_size = 8;
  2294. ha->optrom_size = OPTROM_SIZE_82XX;
  2295. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2296. ha->isp_ops = &qla82xx_isp_ops;
  2297. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2298. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2299. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2300. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2301. } else if (IS_QLA8044(ha)) {
  2302. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2303. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2304. req_length = REQUEST_ENTRY_CNT_82XX;
  2305. rsp_length = RESPONSE_ENTRY_CNT_82XX;
  2306. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2307. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2308. ha->gid_list_info_size = 8;
  2309. ha->optrom_size = OPTROM_SIZE_83XX;
  2310. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2311. ha->isp_ops = &qla8044_isp_ops;
  2312. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  2313. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  2314. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  2315. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  2316. } else if (IS_QLA83XX(ha)) {
  2317. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2318. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2319. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2320. req_length = REQUEST_ENTRY_CNT_83XX;
  2321. rsp_length = RESPONSE_ENTRY_CNT_83XX;
  2322. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2323. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2324. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2325. ha->gid_list_info_size = 8;
  2326. ha->optrom_size = OPTROM_SIZE_83XX;
  2327. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2328. ha->isp_ops = &qla83xx_isp_ops;
  2329. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2330. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2331. ha->nvram_conf_off = ~0;
  2332. ha->nvram_data_off = ~0;
  2333. } else if (IS_QLAFX00(ha)) {
  2334. ha->max_fibre_devices = MAX_FIBRE_DEVICES_FX00;
  2335. ha->mbx_count = MAILBOX_REGISTER_COUNT_FX00;
  2336. ha->aen_mbx_count = AEN_MAILBOX_REGISTER_COUNT_FX00;
  2337. req_length = REQUEST_ENTRY_CNT_FX00;
  2338. rsp_length = RESPONSE_ENTRY_CNT_FX00;
  2339. ha->isp_ops = &qlafx00_isp_ops;
  2340. ha->port_down_retry_count = 30; /* default value */
  2341. ha->mr.fw_hbt_cnt = QLAFX00_HEARTBEAT_INTERVAL;
  2342. ha->mr.fw_reset_timer_tick = QLAFX00_RESET_INTERVAL;
  2343. ha->mr.fw_critemp_timer_tick = QLAFX00_CRITEMP_INTERVAL;
  2344. ha->mr.fw_hbt_en = 1;
  2345. ha->mr.host_info_resend = false;
  2346. ha->mr.hinfo_resend_timer_tick = QLAFX00_HINFO_RESEND_INTERVAL;
  2347. } else if (IS_QLA27XX(ha)) {
  2348. ha->portnum = PCI_FUNC(ha->pdev->devfn);
  2349. ha->max_fibre_devices = MAX_FIBRE_DEVICES_2400;
  2350. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  2351. req_length = REQUEST_ENTRY_CNT_83XX;
  2352. rsp_length = RESPONSE_ENTRY_CNT_83XX;
  2353. ha->tgt.atio_q_length = ATIO_ENTRY_CNT_24XX;
  2354. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  2355. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  2356. ha->gid_list_info_size = 8;
  2357. ha->optrom_size = OPTROM_SIZE_83XX;
  2358. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  2359. ha->isp_ops = &qla27xx_isp_ops;
  2360. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  2361. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  2362. ha->nvram_conf_off = ~0;
  2363. ha->nvram_data_off = ~0;
  2364. }
  2365. ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
  2366. "mbx_count=%d, req_length=%d, "
  2367. "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
  2368. "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, "
  2369. "max_fibre_devices=%d.\n",
  2370. ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
  2371. ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
  2372. ha->nvram_npiv_size, ha->max_fibre_devices);
  2373. ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
  2374. "isp_ops=%p, flash_conf_off=%d, "
  2375. "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
  2376. ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
  2377. ha->nvram_conf_off, ha->nvram_data_off);
  2378. /* Configure PCI I/O space */
  2379. ret = ha->isp_ops->iospace_config(ha);
  2380. if (ret)
  2381. goto iospace_config_failed;
  2382. ql_log_pci(ql_log_info, pdev, 0x001d,
  2383. "Found an ISP%04X irq %d iobase 0x%p.\n",
  2384. pdev->device, pdev->irq, ha->iobase);
  2385. mutex_init(&ha->vport_lock);
  2386. init_completion(&ha->mbx_cmd_comp);
  2387. complete(&ha->mbx_cmd_comp);
  2388. init_completion(&ha->mbx_intr_comp);
  2389. init_completion(&ha->dcbx_comp);
  2390. init_completion(&ha->lb_portup_comp);
  2391. set_bit(0, (unsigned long *) ha->vp_idx_map);
  2392. qla2x00_config_dma_addressing(ha);
  2393. ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
  2394. "64 Bit addressing is %s.\n",
  2395. ha->flags.enable_64bit_addressing ? "enable" :
  2396. "disable");
  2397. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  2398. if (ret) {
  2399. ql_log_pci(ql_log_fatal, pdev, 0x0031,
  2400. "Failed to allocate memory for adapter, aborting.\n");
  2401. goto probe_hw_failed;
  2402. }
  2403. req->max_q_depth = MAX_Q_DEPTH;
  2404. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  2405. req->max_q_depth = ql2xmaxqdepth;
  2406. base_vha = qla2x00_create_host(sht, ha);
  2407. if (!base_vha) {
  2408. ret = -ENOMEM;
  2409. qla2x00_mem_free(ha);
  2410. qla2x00_free_req_que(ha, req);
  2411. qla2x00_free_rsp_que(ha, rsp);
  2412. goto probe_hw_failed;
  2413. }
  2414. pci_set_drvdata(pdev, base_vha);
  2415. set_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2416. host = base_vha->host;
  2417. base_vha->req = req;
  2418. if (IS_QLA2XXX_MIDTYPE(ha))
  2419. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  2420. else
  2421. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  2422. base_vha->vp_idx;
  2423. /* Setup fcport template structure. */
  2424. ha->mr.fcport.vha = base_vha;
  2425. ha->mr.fcport.port_type = FCT_UNKNOWN;
  2426. ha->mr.fcport.loop_id = FC_NO_LOOP_ID;
  2427. qla2x00_set_fcport_state(&ha->mr.fcport, FCS_UNCONFIGURED);
  2428. ha->mr.fcport.supported_classes = FC_COS_UNSPECIFIED;
  2429. ha->mr.fcport.scan_state = 1;
  2430. /* Set the SG table size based on ISP type */
  2431. if (!IS_FWI2_CAPABLE(ha)) {
  2432. if (IS_QLA2100(ha))
  2433. host->sg_tablesize = 32;
  2434. } else {
  2435. if (!IS_QLA82XX(ha))
  2436. host->sg_tablesize = QLA_SG_ALL;
  2437. }
  2438. host->max_id = ha->max_fibre_devices;
  2439. host->cmd_per_lun = 3;
  2440. host->unique_id = host->host_no;
  2441. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
  2442. host->max_cmd_len = 32;
  2443. else
  2444. host->max_cmd_len = MAX_CMDSZ;
  2445. host->max_channel = MAX_BUSES - 1;
  2446. /* Older HBAs support only 16-bit LUNs */
  2447. if (!IS_QLAFX00(ha) && !IS_FWI2_CAPABLE(ha) &&
  2448. ql2xmaxlun > 0xffff)
  2449. host->max_lun = 0xffff;
  2450. else
  2451. host->max_lun = ql2xmaxlun;
  2452. host->transportt = qla2xxx_transport_template;
  2453. sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
  2454. ql_dbg(ql_dbg_init, base_vha, 0x0033,
  2455. "max_id=%d this_id=%d "
  2456. "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
  2457. "max_lun=%llu transportt=%p, vendor_id=%llu.\n", host->max_id,
  2458. host->this_id, host->cmd_per_lun, host->unique_id,
  2459. host->max_cmd_len, host->max_channel, host->max_lun,
  2460. host->transportt, sht->vendor_id);
  2461. que_init:
  2462. /* Alloc arrays of request and response ring ptrs */
  2463. if (!qla2x00_alloc_queues(ha, req, rsp)) {
  2464. ql_log(ql_log_fatal, base_vha, 0x003d,
  2465. "Failed to allocate memory for queue pointers..."
  2466. "aborting.\n");
  2467. goto probe_init_failed;
  2468. }
  2469. qlt_probe_one_stage1(base_vha, ha);
  2470. /* Set up the irqs */
  2471. ret = qla2x00_request_irqs(ha, rsp);
  2472. if (ret)
  2473. goto probe_init_failed;
  2474. pci_save_state(pdev);
  2475. /* Assign back pointers */
  2476. rsp->req = req;
  2477. req->rsp = rsp;
  2478. if (IS_QLAFX00(ha)) {
  2479. ha->rsp_q_map[0] = rsp;
  2480. ha->req_q_map[0] = req;
  2481. set_bit(0, ha->req_qid_map);
  2482. set_bit(0, ha->rsp_qid_map);
  2483. }
  2484. /* FWI2-capable only. */
  2485. req->req_q_in = &ha->iobase->isp24.req_q_in;
  2486. req->req_q_out = &ha->iobase->isp24.req_q_out;
  2487. rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
  2488. rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
  2489. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
  2490. req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
  2491. req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
  2492. rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
  2493. rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
  2494. }
  2495. if (IS_QLAFX00(ha)) {
  2496. req->req_q_in = &ha->iobase->ispfx00.req_q_in;
  2497. req->req_q_out = &ha->iobase->ispfx00.req_q_out;
  2498. rsp->rsp_q_in = &ha->iobase->ispfx00.rsp_q_in;
  2499. rsp->rsp_q_out = &ha->iobase->ispfx00.rsp_q_out;
  2500. }
  2501. if (IS_P3P_TYPE(ha)) {
  2502. req->req_q_out = &ha->iobase->isp82.req_q_out[0];
  2503. rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
  2504. rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
  2505. }
  2506. ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
  2507. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2508. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2509. ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
  2510. "req->req_q_in=%p req->req_q_out=%p "
  2511. "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2512. req->req_q_in, req->req_q_out,
  2513. rsp->rsp_q_in, rsp->rsp_q_out);
  2514. ql_dbg(ql_dbg_init, base_vha, 0x003e,
  2515. "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
  2516. ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
  2517. ql_dbg(ql_dbg_init, base_vha, 0x003f,
  2518. "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
  2519. req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
  2520. if (ha->isp_ops->initialize_adapter(base_vha)) {
  2521. ql_log(ql_log_fatal, base_vha, 0x00d6,
  2522. "Failed to initialize adapter - Adapter flags %x.\n",
  2523. base_vha->device_flags);
  2524. if (IS_QLA82XX(ha)) {
  2525. qla82xx_idc_lock(ha);
  2526. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  2527. QLA8XXX_DEV_FAILED);
  2528. qla82xx_idc_unlock(ha);
  2529. ql_log(ql_log_fatal, base_vha, 0x00d7,
  2530. "HW State: FAILED.\n");
  2531. } else if (IS_QLA8044(ha)) {
  2532. qla8044_idc_lock(ha);
  2533. qla8044_wr_direct(base_vha,
  2534. QLA8044_CRB_DEV_STATE_INDEX,
  2535. QLA8XXX_DEV_FAILED);
  2536. qla8044_idc_unlock(ha);
  2537. ql_log(ql_log_fatal, base_vha, 0x0150,
  2538. "HW State: FAILED.\n");
  2539. }
  2540. ret = -ENODEV;
  2541. goto probe_failed;
  2542. }
  2543. if (IS_QLAFX00(ha))
  2544. host->can_queue = QLAFX00_MAX_CANQUEUE;
  2545. else
  2546. host->can_queue = req->num_outstanding_cmds - 10;
  2547. ql_dbg(ql_dbg_init, base_vha, 0x0032,
  2548. "can_queue=%d, req=%p, mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
  2549. host->can_queue, base_vha->req,
  2550. base_vha->mgmt_svr_loop_id, host->sg_tablesize);
  2551. if (ha->mqenable) {
  2552. if (qla25xx_setup_mode(base_vha)) {
  2553. ql_log(ql_log_warn, base_vha, 0x00ec,
  2554. "Failed to create queues, falling back to single queue mode.\n");
  2555. goto que_init;
  2556. }
  2557. }
  2558. if (ha->flags.running_gold_fw)
  2559. goto skip_dpc;
  2560. /*
  2561. * Startup the kernel thread for this host adapter
  2562. */
  2563. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  2564. "%s_dpc", base_vha->host_str);
  2565. if (IS_ERR(ha->dpc_thread)) {
  2566. ql_log(ql_log_fatal, base_vha, 0x00ed,
  2567. "Failed to start DPC thread.\n");
  2568. ret = PTR_ERR(ha->dpc_thread);
  2569. goto probe_failed;
  2570. }
  2571. ql_dbg(ql_dbg_init, base_vha, 0x00ee,
  2572. "DPC thread started successfully.\n");
  2573. /*
  2574. * If we're not coming up in initiator mode, we might sit for
  2575. * a while without waking up the dpc thread, which leads to a
  2576. * stuck process warning. So just kick the dpc once here and
  2577. * let the kthread start (and go back to sleep in qla2x00_do_dpc).
  2578. */
  2579. qla2xxx_wake_dpc(base_vha);
  2580. INIT_WORK(&ha->board_disable, qla2x00_disable_board_on_pci_error);
  2581. if (IS_QLA8031(ha) || IS_MCTP_CAPABLE(ha)) {
  2582. sprintf(wq_name, "qla2xxx_%lu_dpc_lp_wq", base_vha->host_no);
  2583. ha->dpc_lp_wq = create_singlethread_workqueue(wq_name);
  2584. INIT_WORK(&ha->idc_aen, qla83xx_service_idc_aen);
  2585. sprintf(wq_name, "qla2xxx_%lu_dpc_hp_wq", base_vha->host_no);
  2586. ha->dpc_hp_wq = create_singlethread_workqueue(wq_name);
  2587. INIT_WORK(&ha->nic_core_reset, qla83xx_nic_core_reset_work);
  2588. INIT_WORK(&ha->idc_state_handler,
  2589. qla83xx_idc_state_handler_work);
  2590. INIT_WORK(&ha->nic_core_unrecoverable,
  2591. qla83xx_nic_core_unrecoverable_work);
  2592. }
  2593. skip_dpc:
  2594. list_add_tail(&base_vha->list, &ha->vp_list);
  2595. base_vha->host->irq = ha->pdev->irq;
  2596. /* Initialized the timer */
  2597. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  2598. ql_dbg(ql_dbg_init, base_vha, 0x00ef,
  2599. "Started qla2x00_timer with "
  2600. "interval=%d.\n", WATCH_INTERVAL);
  2601. ql_dbg(ql_dbg_init, base_vha, 0x00f0,
  2602. "Detected hba at address=%p.\n",
  2603. ha);
  2604. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  2605. if (ha->fw_attributes & BIT_4) {
  2606. int prot = 0, guard;
  2607. base_vha->flags.difdix_supported = 1;
  2608. ql_dbg(ql_dbg_init, base_vha, 0x00f1,
  2609. "Registering for DIF/DIX type 1 and 3 protection.\n");
  2610. if (ql2xenabledif == 1)
  2611. prot = SHOST_DIX_TYPE0_PROTECTION;
  2612. scsi_host_set_prot(host,
  2613. prot | SHOST_DIF_TYPE1_PROTECTION
  2614. | SHOST_DIF_TYPE2_PROTECTION
  2615. | SHOST_DIF_TYPE3_PROTECTION
  2616. | SHOST_DIX_TYPE1_PROTECTION
  2617. | SHOST_DIX_TYPE2_PROTECTION
  2618. | SHOST_DIX_TYPE3_PROTECTION);
  2619. guard = SHOST_DIX_GUARD_CRC;
  2620. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  2621. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  2622. guard |= SHOST_DIX_GUARD_IP;
  2623. scsi_host_set_guard(host, guard);
  2624. } else
  2625. base_vha->flags.difdix_supported = 0;
  2626. }
  2627. ha->isp_ops->enable_intrs(ha);
  2628. if (IS_QLAFX00(ha)) {
  2629. ret = qlafx00_fx_disc(base_vha,
  2630. &base_vha->hw->mr.fcport, FXDISC_GET_CONFIG_INFO);
  2631. host->sg_tablesize = (ha->mr.extended_io_enabled) ?
  2632. QLA_SG_ALL : 128;
  2633. }
  2634. ret = scsi_add_host(host, &pdev->dev);
  2635. if (ret)
  2636. goto probe_failed;
  2637. base_vha->flags.init_done = 1;
  2638. base_vha->flags.online = 1;
  2639. ha->prev_minidump_failed = 0;
  2640. ql_dbg(ql_dbg_init, base_vha, 0x00f2,
  2641. "Init done and hba is online.\n");
  2642. if (qla_ini_mode_enabled(base_vha))
  2643. scsi_scan_host(host);
  2644. else
  2645. ql_dbg(ql_dbg_init, base_vha, 0x0122,
  2646. "skipping scsi_scan_host() for non-initiator port\n");
  2647. qla2x00_alloc_sysfs_attr(base_vha);
  2648. if (IS_QLAFX00(ha)) {
  2649. ret = qlafx00_fx_disc(base_vha,
  2650. &base_vha->hw->mr.fcport, FXDISC_GET_PORT_INFO);
  2651. /* Register system information */
  2652. ret = qlafx00_fx_disc(base_vha,
  2653. &base_vha->hw->mr.fcport, FXDISC_REG_HOST_INFO);
  2654. }
  2655. qla2x00_init_host_attr(base_vha);
  2656. qla2x00_dfs_setup(base_vha);
  2657. ql_log(ql_log_info, base_vha, 0x00fb,
  2658. "QLogic %s - %s.\n", ha->model_number, ha->model_desc);
  2659. ql_log(ql_log_info, base_vha, 0x00fc,
  2660. "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
  2661. pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
  2662. pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
  2663. base_vha->host_no,
  2664. ha->isp_ops->fw_version_str(base_vha, fw_str, sizeof(fw_str)));
  2665. qlt_add_target(ha, base_vha);
  2666. clear_bit(PFLG_DRIVER_PROBING, &base_vha->pci_flags);
  2667. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  2668. return -ENODEV;
  2669. return 0;
  2670. probe_init_failed:
  2671. qla2x00_free_req_que(ha, req);
  2672. ha->req_q_map[0] = NULL;
  2673. clear_bit(0, ha->req_qid_map);
  2674. qla2x00_free_rsp_que(ha, rsp);
  2675. ha->rsp_q_map[0] = NULL;
  2676. clear_bit(0, ha->rsp_qid_map);
  2677. ha->max_req_queues = ha->max_rsp_queues = 0;
  2678. probe_failed:
  2679. if (base_vha->timer_active)
  2680. qla2x00_stop_timer(base_vha);
  2681. base_vha->flags.online = 0;
  2682. if (ha->dpc_thread) {
  2683. struct task_struct *t = ha->dpc_thread;
  2684. ha->dpc_thread = NULL;
  2685. kthread_stop(t);
  2686. }
  2687. qla2x00_free_device(base_vha);
  2688. scsi_host_put(base_vha->host);
  2689. probe_hw_failed:
  2690. qla2x00_clear_drv_active(ha);
  2691. iospace_config_failed:
  2692. if (IS_P3P_TYPE(ha)) {
  2693. if (!ha->nx_pcibase)
  2694. iounmap((device_reg_t *)ha->nx_pcibase);
  2695. if (!ql2xdbwr)
  2696. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2697. } else {
  2698. if (ha->iobase)
  2699. iounmap(ha->iobase);
  2700. if (ha->cregbase)
  2701. iounmap(ha->cregbase);
  2702. }
  2703. pci_release_selected_regions(ha->pdev, ha->bars);
  2704. kfree(ha);
  2705. ha = NULL;
  2706. disable_device:
  2707. pci_disable_device(pdev);
  2708. return ret;
  2709. }
  2710. static void
  2711. qla2x00_shutdown(struct pci_dev *pdev)
  2712. {
  2713. scsi_qla_host_t *vha;
  2714. struct qla_hw_data *ha;
  2715. if (!atomic_read(&pdev->enable_cnt))
  2716. return;
  2717. vha = pci_get_drvdata(pdev);
  2718. ha = vha->hw;
  2719. /* Notify ISPFX00 firmware */
  2720. if (IS_QLAFX00(ha))
  2721. qlafx00_driver_shutdown(vha, 20);
  2722. /* Turn-off FCE trace */
  2723. if (ha->flags.fce_enabled) {
  2724. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2725. ha->flags.fce_enabled = 0;
  2726. }
  2727. /* Turn-off EFT trace */
  2728. if (ha->eft)
  2729. qla2x00_disable_eft_trace(vha);
  2730. /* Stop currently executing firmware. */
  2731. qla2x00_try_to_stop_firmware(vha);
  2732. /* Turn adapter off line */
  2733. vha->flags.online = 0;
  2734. /* turn-off interrupts on the card */
  2735. if (ha->interrupts_on) {
  2736. vha->flags.init_done = 0;
  2737. ha->isp_ops->disable_intrs(ha);
  2738. }
  2739. qla2x00_free_irqs(vha);
  2740. qla2x00_free_fw_dump(ha);
  2741. pci_disable_pcie_error_reporting(pdev);
  2742. pci_disable_device(pdev);
  2743. }
  2744. /* Deletes all the virtual ports for a given ha */
  2745. static void
  2746. qla2x00_delete_all_vps(struct qla_hw_data *ha, scsi_qla_host_t *base_vha)
  2747. {
  2748. scsi_qla_host_t *vha;
  2749. unsigned long flags;
  2750. mutex_lock(&ha->vport_lock);
  2751. while (ha->cur_vport_count) {
  2752. spin_lock_irqsave(&ha->vport_slock, flags);
  2753. BUG_ON(base_vha->list.next == &ha->vp_list);
  2754. /* This assumes first entry in ha->vp_list is always base vha */
  2755. vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
  2756. scsi_host_get(vha->host);
  2757. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2758. mutex_unlock(&ha->vport_lock);
  2759. fc_vport_terminate(vha->fc_vport);
  2760. scsi_host_put(vha->host);
  2761. mutex_lock(&ha->vport_lock);
  2762. }
  2763. mutex_unlock(&ha->vport_lock);
  2764. }
  2765. /* Stops all deferred work threads */
  2766. static void
  2767. qla2x00_destroy_deferred_work(struct qla_hw_data *ha)
  2768. {
  2769. /* Flush the work queue and remove it */
  2770. if (ha->wq) {
  2771. flush_workqueue(ha->wq);
  2772. destroy_workqueue(ha->wq);
  2773. ha->wq = NULL;
  2774. }
  2775. /* Cancel all work and destroy DPC workqueues */
  2776. if (ha->dpc_lp_wq) {
  2777. cancel_work_sync(&ha->idc_aen);
  2778. destroy_workqueue(ha->dpc_lp_wq);
  2779. ha->dpc_lp_wq = NULL;
  2780. }
  2781. if (ha->dpc_hp_wq) {
  2782. cancel_work_sync(&ha->nic_core_reset);
  2783. cancel_work_sync(&ha->idc_state_handler);
  2784. cancel_work_sync(&ha->nic_core_unrecoverable);
  2785. destroy_workqueue(ha->dpc_hp_wq);
  2786. ha->dpc_hp_wq = NULL;
  2787. }
  2788. /* Kill the kernel thread for this host */
  2789. if (ha->dpc_thread) {
  2790. struct task_struct *t = ha->dpc_thread;
  2791. /*
  2792. * qla2xxx_wake_dpc checks for ->dpc_thread
  2793. * so we need to zero it out.
  2794. */
  2795. ha->dpc_thread = NULL;
  2796. kthread_stop(t);
  2797. }
  2798. }
  2799. static void
  2800. qla2x00_unmap_iobases(struct qla_hw_data *ha)
  2801. {
  2802. if (IS_QLA82XX(ha)) {
  2803. iounmap((device_reg_t *)ha->nx_pcibase);
  2804. if (!ql2xdbwr)
  2805. iounmap((device_reg_t *)ha->nxdb_wr_ptr);
  2806. } else {
  2807. if (ha->iobase)
  2808. iounmap(ha->iobase);
  2809. if (ha->cregbase)
  2810. iounmap(ha->cregbase);
  2811. if (ha->mqiobase)
  2812. iounmap(ha->mqiobase);
  2813. if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) && ha->msixbase)
  2814. iounmap(ha->msixbase);
  2815. }
  2816. }
  2817. static void
  2818. qla2x00_clear_drv_active(struct qla_hw_data *ha)
  2819. {
  2820. if (IS_QLA8044(ha)) {
  2821. qla8044_idc_lock(ha);
  2822. qla8044_clear_drv_active(ha);
  2823. qla8044_idc_unlock(ha);
  2824. } else if (IS_QLA82XX(ha)) {
  2825. qla82xx_idc_lock(ha);
  2826. qla82xx_clear_drv_active(ha);
  2827. qla82xx_idc_unlock(ha);
  2828. }
  2829. }
  2830. static void
  2831. qla2x00_remove_one(struct pci_dev *pdev)
  2832. {
  2833. scsi_qla_host_t *base_vha;
  2834. struct qla_hw_data *ha;
  2835. base_vha = pci_get_drvdata(pdev);
  2836. ha = base_vha->hw;
  2837. /* Indicate device removal to prevent future board_disable and wait
  2838. * until any pending board_disable has completed. */
  2839. set_bit(PFLG_DRIVER_REMOVING, &base_vha->pci_flags);
  2840. cancel_work_sync(&ha->board_disable);
  2841. /*
  2842. * If the PCI device is disabled then there was a PCI-disconnect and
  2843. * qla2x00_disable_board_on_pci_error has taken care of most of the
  2844. * resources.
  2845. */
  2846. if (!atomic_read(&pdev->enable_cnt)) {
  2847. scsi_host_put(base_vha->host);
  2848. kfree(ha);
  2849. pci_set_drvdata(pdev, NULL);
  2850. return;
  2851. }
  2852. qla2x00_wait_for_hba_ready(base_vha);
  2853. /* if UNLOAD flag is already set, then continue unload,
  2854. * where it was set first.
  2855. */
  2856. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  2857. return;
  2858. set_bit(UNLOADING, &base_vha->dpc_flags);
  2859. if (IS_QLAFX00(ha))
  2860. qlafx00_driver_shutdown(base_vha, 20);
  2861. qla2x00_delete_all_vps(ha, base_vha);
  2862. if (IS_QLA8031(ha)) {
  2863. ql_dbg(ql_dbg_p3p, base_vha, 0xb07e,
  2864. "Clearing fcoe driver presence.\n");
  2865. if (qla83xx_clear_drv_presence(base_vha) != QLA_SUCCESS)
  2866. ql_dbg(ql_dbg_p3p, base_vha, 0xb079,
  2867. "Error while clearing DRV-Presence.\n");
  2868. }
  2869. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  2870. qla2x00_dfs_remove(base_vha);
  2871. qla84xx_put_chip(base_vha);
  2872. /* Laser should be disabled only for ISP2031 */
  2873. if (IS_QLA2031(ha))
  2874. qla83xx_disable_laser(base_vha);
  2875. /* Disable timer */
  2876. if (base_vha->timer_active)
  2877. qla2x00_stop_timer(base_vha);
  2878. base_vha->flags.online = 0;
  2879. /* free DMA memory */
  2880. if (ha->exlogin_buf)
  2881. qla2x00_free_exlogin_buffer(ha);
  2882. /* free DMA memory */
  2883. if (ha->exchoffld_buf)
  2884. qla2x00_free_exchoffld_buffer(ha);
  2885. qla2x00_destroy_deferred_work(ha);
  2886. qlt_remove_target(ha, base_vha);
  2887. qla2x00_free_sysfs_attr(base_vha, true);
  2888. fc_remove_host(base_vha->host);
  2889. scsi_remove_host(base_vha->host);
  2890. qla2x00_free_device(base_vha);
  2891. qla2x00_clear_drv_active(ha);
  2892. scsi_host_put(base_vha->host);
  2893. qla2x00_unmap_iobases(ha);
  2894. pci_release_selected_regions(ha->pdev, ha->bars);
  2895. kfree(ha);
  2896. ha = NULL;
  2897. pci_disable_pcie_error_reporting(pdev);
  2898. pci_disable_device(pdev);
  2899. }
  2900. static void
  2901. qla2x00_free_device(scsi_qla_host_t *vha)
  2902. {
  2903. struct qla_hw_data *ha = vha->hw;
  2904. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  2905. /* Disable timer */
  2906. if (vha->timer_active)
  2907. qla2x00_stop_timer(vha);
  2908. qla25xx_delete_queues(vha);
  2909. if (ha->flags.fce_enabled)
  2910. qla2x00_disable_fce_trace(vha, NULL, NULL);
  2911. if (ha->eft)
  2912. qla2x00_disable_eft_trace(vha);
  2913. /* Stop currently executing firmware. */
  2914. qla2x00_try_to_stop_firmware(vha);
  2915. vha->flags.online = 0;
  2916. /* turn-off interrupts on the card */
  2917. if (ha->interrupts_on) {
  2918. vha->flags.init_done = 0;
  2919. ha->isp_ops->disable_intrs(ha);
  2920. }
  2921. qla2x00_free_irqs(vha);
  2922. qla2x00_free_fcports(vha);
  2923. qla2x00_mem_free(ha);
  2924. qla82xx_md_free(vha);
  2925. qla2x00_free_queues(ha);
  2926. }
  2927. void qla2x00_free_fcports(struct scsi_qla_host *vha)
  2928. {
  2929. fc_port_t *fcport, *tfcport;
  2930. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  2931. list_del(&fcport->list);
  2932. qla2x00_clear_loop_id(fcport);
  2933. kfree(fcport);
  2934. fcport = NULL;
  2935. }
  2936. }
  2937. static inline void
  2938. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  2939. int defer)
  2940. {
  2941. struct fc_rport *rport;
  2942. scsi_qla_host_t *base_vha;
  2943. unsigned long flags;
  2944. if (!fcport->rport)
  2945. return;
  2946. rport = fcport->rport;
  2947. if (defer) {
  2948. base_vha = pci_get_drvdata(vha->hw->pdev);
  2949. spin_lock_irqsave(vha->host->host_lock, flags);
  2950. fcport->drport = rport;
  2951. spin_unlock_irqrestore(vha->host->host_lock, flags);
  2952. qlt_do_generation_tick(vha, &base_vha->total_fcport_update_gen);
  2953. set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2954. qla2xxx_wake_dpc(base_vha);
  2955. } else {
  2956. int now;
  2957. if (rport)
  2958. fc_remote_port_delete(rport);
  2959. qlt_do_generation_tick(vha, &now);
  2960. qlt_fc_port_deleted(vha, fcport, now);
  2961. }
  2962. }
  2963. /*
  2964. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  2965. *
  2966. * Input: ha = adapter block pointer. fcport = port structure pointer.
  2967. *
  2968. * Return: None.
  2969. *
  2970. * Context:
  2971. */
  2972. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  2973. int do_login, int defer)
  2974. {
  2975. if (IS_QLAFX00(vha->hw)) {
  2976. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2977. qla2x00_schedule_rport_del(vha, fcport, defer);
  2978. return;
  2979. }
  2980. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2981. vha->vp_idx == fcport->vha->vp_idx) {
  2982. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2983. qla2x00_schedule_rport_del(vha, fcport, defer);
  2984. }
  2985. /*
  2986. * We may need to retry the login, so don't change the state of the
  2987. * port but do the retries.
  2988. */
  2989. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  2990. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2991. if (!do_login)
  2992. return;
  2993. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2994. if (fcport->login_retry == 0) {
  2995. fcport->login_retry = vha->hw->login_retry_count;
  2996. ql_dbg(ql_dbg_disc, vha, 0x2067,
  2997. "Port login retry %8phN, id = 0x%04x retry cnt=%d.\n",
  2998. fcport->port_name, fcport->loop_id, fcport->login_retry);
  2999. }
  3000. }
  3001. /*
  3002. * qla2x00_mark_all_devices_lost
  3003. * Updates fcport state when device goes offline.
  3004. *
  3005. * Input:
  3006. * ha = adapter block pointer.
  3007. * fcport = port structure pointer.
  3008. *
  3009. * Return:
  3010. * None.
  3011. *
  3012. * Context:
  3013. */
  3014. void
  3015. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  3016. {
  3017. fc_port_t *fcport;
  3018. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3019. if (vha->vp_idx != 0 && vha->vp_idx != fcport->vha->vp_idx)
  3020. continue;
  3021. /*
  3022. * No point in marking the device as lost, if the device is
  3023. * already DEAD.
  3024. */
  3025. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  3026. continue;
  3027. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  3028. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  3029. if (defer)
  3030. qla2x00_schedule_rport_del(vha, fcport, defer);
  3031. else if (vha->vp_idx == fcport->vha->vp_idx)
  3032. qla2x00_schedule_rport_del(vha, fcport, defer);
  3033. }
  3034. }
  3035. }
  3036. /*
  3037. * qla2x00_mem_alloc
  3038. * Allocates adapter memory.
  3039. *
  3040. * Returns:
  3041. * 0 = success.
  3042. * !0 = failure.
  3043. */
  3044. static int
  3045. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  3046. struct req_que **req, struct rsp_que **rsp)
  3047. {
  3048. char name[16];
  3049. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  3050. &ha->init_cb_dma, GFP_KERNEL);
  3051. if (!ha->init_cb)
  3052. goto fail;
  3053. if (qlt_mem_alloc(ha) < 0)
  3054. goto fail_free_init_cb;
  3055. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev,
  3056. qla2x00_gid_list_size(ha), &ha->gid_list_dma, GFP_KERNEL);
  3057. if (!ha->gid_list)
  3058. goto fail_free_tgt_mem;
  3059. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  3060. if (!ha->srb_mempool)
  3061. goto fail_free_gid_list;
  3062. if (IS_P3P_TYPE(ha)) {
  3063. /* Allocate cache for CT6 Ctx. */
  3064. if (!ctx_cachep) {
  3065. ctx_cachep = kmem_cache_create("qla2xxx_ctx",
  3066. sizeof(struct ct6_dsd), 0,
  3067. SLAB_HWCACHE_ALIGN, NULL);
  3068. if (!ctx_cachep)
  3069. goto fail_free_srb_mempool;
  3070. }
  3071. ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
  3072. ctx_cachep);
  3073. if (!ha->ctx_mempool)
  3074. goto fail_free_srb_mempool;
  3075. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
  3076. "ctx_cachep=%p ctx_mempool=%p.\n",
  3077. ctx_cachep, ha->ctx_mempool);
  3078. }
  3079. /* Get memory for cached NVRAM */
  3080. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  3081. if (!ha->nvram)
  3082. goto fail_free_ctx_mempool;
  3083. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  3084. ha->pdev->device);
  3085. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3086. DMA_POOL_SIZE, 8, 0);
  3087. if (!ha->s_dma_pool)
  3088. goto fail_free_nvram;
  3089. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
  3090. "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
  3091. ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
  3092. if (IS_P3P_TYPE(ha) || ql2xenabledif) {
  3093. ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3094. DSD_LIST_DMA_POOL_SIZE, 8, 0);
  3095. if (!ha->dl_dma_pool) {
  3096. ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
  3097. "Failed to allocate memory for dl_dma_pool.\n");
  3098. goto fail_s_dma_pool;
  3099. }
  3100. ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  3101. FCP_CMND_DMA_POOL_SIZE, 8, 0);
  3102. if (!ha->fcp_cmnd_dma_pool) {
  3103. ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
  3104. "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
  3105. goto fail_dl_dma_pool;
  3106. }
  3107. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
  3108. "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
  3109. ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
  3110. }
  3111. /* Allocate memory for SNS commands */
  3112. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3113. /* Get consistent memory allocated for SNS commands */
  3114. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  3115. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  3116. if (!ha->sns_cmd)
  3117. goto fail_dma_pool;
  3118. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
  3119. "sns_cmd: %p.\n", ha->sns_cmd);
  3120. } else {
  3121. /* Get consistent memory allocated for MS IOCB */
  3122. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3123. &ha->ms_iocb_dma);
  3124. if (!ha->ms_iocb)
  3125. goto fail_dma_pool;
  3126. /* Get consistent memory allocated for CT SNS commands */
  3127. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  3128. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  3129. if (!ha->ct_sns)
  3130. goto fail_free_ms_iocb;
  3131. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
  3132. "ms_iocb=%p ct_sns=%p.\n",
  3133. ha->ms_iocb, ha->ct_sns);
  3134. }
  3135. /* Allocate memory for request ring */
  3136. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  3137. if (!*req) {
  3138. ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
  3139. "Failed to allocate memory for req.\n");
  3140. goto fail_req;
  3141. }
  3142. (*req)->length = req_len;
  3143. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3144. ((*req)->length + 1) * sizeof(request_t),
  3145. &(*req)->dma, GFP_KERNEL);
  3146. if (!(*req)->ring) {
  3147. ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
  3148. "Failed to allocate memory for req_ring.\n");
  3149. goto fail_req_ring;
  3150. }
  3151. /* Allocate memory for response ring */
  3152. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  3153. if (!*rsp) {
  3154. ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
  3155. "Failed to allocate memory for rsp.\n");
  3156. goto fail_rsp;
  3157. }
  3158. (*rsp)->hw = ha;
  3159. (*rsp)->length = rsp_len;
  3160. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  3161. ((*rsp)->length + 1) * sizeof(response_t),
  3162. &(*rsp)->dma, GFP_KERNEL);
  3163. if (!(*rsp)->ring) {
  3164. ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
  3165. "Failed to allocate memory for rsp_ring.\n");
  3166. goto fail_rsp_ring;
  3167. }
  3168. (*req)->rsp = *rsp;
  3169. (*rsp)->req = *req;
  3170. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
  3171. "req=%p req->length=%d req->ring=%p rsp=%p "
  3172. "rsp->length=%d rsp->ring=%p.\n",
  3173. *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
  3174. (*rsp)->ring);
  3175. /* Allocate memory for NVRAM data for vports */
  3176. if (ha->nvram_npiv_size) {
  3177. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  3178. ha->nvram_npiv_size, GFP_KERNEL);
  3179. if (!ha->npiv_info) {
  3180. ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
  3181. "Failed to allocate memory for npiv_info.\n");
  3182. goto fail_npiv_info;
  3183. }
  3184. } else
  3185. ha->npiv_info = NULL;
  3186. /* Get consistent memory allocated for EX-INIT-CB. */
  3187. if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha)) {
  3188. ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3189. &ha->ex_init_cb_dma);
  3190. if (!ha->ex_init_cb)
  3191. goto fail_ex_init_cb;
  3192. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
  3193. "ex_init_cb=%p.\n", ha->ex_init_cb);
  3194. }
  3195. INIT_LIST_HEAD(&ha->gbl_dsd_list);
  3196. /* Get consistent memory allocated for Async Port-Database. */
  3197. if (!IS_FWI2_CAPABLE(ha)) {
  3198. ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  3199. &ha->async_pd_dma);
  3200. if (!ha->async_pd)
  3201. goto fail_async_pd;
  3202. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
  3203. "async_pd=%p.\n", ha->async_pd);
  3204. }
  3205. INIT_LIST_HEAD(&ha->vp_list);
  3206. /* Allocate memory for our loop_id bitmap */
  3207. ha->loop_id_map = kzalloc(BITS_TO_LONGS(LOOPID_MAP_SIZE) * sizeof(long),
  3208. GFP_KERNEL);
  3209. if (!ha->loop_id_map)
  3210. goto fail_loop_id_map;
  3211. else {
  3212. qla2x00_set_reserved_loop_ids(ha);
  3213. ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0123,
  3214. "loop_id_map=%p.\n", ha->loop_id_map);
  3215. }
  3216. return 0;
  3217. fail_loop_id_map:
  3218. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3219. fail_async_pd:
  3220. dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
  3221. fail_ex_init_cb:
  3222. kfree(ha->npiv_info);
  3223. fail_npiv_info:
  3224. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  3225. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  3226. (*rsp)->ring = NULL;
  3227. (*rsp)->dma = 0;
  3228. fail_rsp_ring:
  3229. kfree(*rsp);
  3230. fail_rsp:
  3231. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  3232. sizeof(request_t), (*req)->ring, (*req)->dma);
  3233. (*req)->ring = NULL;
  3234. (*req)->dma = 0;
  3235. fail_req_ring:
  3236. kfree(*req);
  3237. fail_req:
  3238. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3239. ha->ct_sns, ha->ct_sns_dma);
  3240. ha->ct_sns = NULL;
  3241. ha->ct_sns_dma = 0;
  3242. fail_free_ms_iocb:
  3243. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3244. ha->ms_iocb = NULL;
  3245. ha->ms_iocb_dma = 0;
  3246. if (ha->sns_cmd)
  3247. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3248. ha->sns_cmd, ha->sns_cmd_dma);
  3249. fail_dma_pool:
  3250. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3251. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3252. ha->fcp_cmnd_dma_pool = NULL;
  3253. }
  3254. fail_dl_dma_pool:
  3255. if (IS_QLA82XX(ha) || ql2xenabledif) {
  3256. dma_pool_destroy(ha->dl_dma_pool);
  3257. ha->dl_dma_pool = NULL;
  3258. }
  3259. fail_s_dma_pool:
  3260. dma_pool_destroy(ha->s_dma_pool);
  3261. ha->s_dma_pool = NULL;
  3262. fail_free_nvram:
  3263. kfree(ha->nvram);
  3264. ha->nvram = NULL;
  3265. fail_free_ctx_mempool:
  3266. if (ha->ctx_mempool)
  3267. mempool_destroy(ha->ctx_mempool);
  3268. ha->ctx_mempool = NULL;
  3269. fail_free_srb_mempool:
  3270. if (ha->srb_mempool)
  3271. mempool_destroy(ha->srb_mempool);
  3272. ha->srb_mempool = NULL;
  3273. fail_free_gid_list:
  3274. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3275. ha->gid_list,
  3276. ha->gid_list_dma);
  3277. ha->gid_list = NULL;
  3278. ha->gid_list_dma = 0;
  3279. fail_free_tgt_mem:
  3280. qlt_mem_free(ha);
  3281. fail_free_init_cb:
  3282. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  3283. ha->init_cb_dma);
  3284. ha->init_cb = NULL;
  3285. ha->init_cb_dma = 0;
  3286. fail:
  3287. ql_log(ql_log_fatal, NULL, 0x0030,
  3288. "Memory allocation failure.\n");
  3289. return -ENOMEM;
  3290. }
  3291. int
  3292. qla2x00_set_exlogins_buffer(scsi_qla_host_t *vha)
  3293. {
  3294. int rval;
  3295. uint16_t size, max_cnt, temp;
  3296. struct qla_hw_data *ha = vha->hw;
  3297. /* Return if we don't need to alloacate any extended logins */
  3298. if (!ql2xexlogins)
  3299. return QLA_SUCCESS;
  3300. ql_log(ql_log_info, vha, 0xd021, "EXLOGIN count: %d.\n", ql2xexlogins);
  3301. max_cnt = 0;
  3302. rval = qla_get_exlogin_status(vha, &size, &max_cnt);
  3303. if (rval != QLA_SUCCESS) {
  3304. ql_log_pci(ql_log_fatal, ha->pdev, 0xd029,
  3305. "Failed to get exlogin status.\n");
  3306. return rval;
  3307. }
  3308. temp = (ql2xexlogins > max_cnt) ? max_cnt : ql2xexlogins;
  3309. ha->exlogin_size = (size * temp);
  3310. ql_log(ql_log_info, vha, 0xd024,
  3311. "EXLOGIN: max_logins=%d, portdb=0x%x, total=%d.\n",
  3312. max_cnt, size, temp);
  3313. ql_log(ql_log_info, vha, 0xd025, "EXLOGIN: requested size=0x%x\n",
  3314. ha->exlogin_size);
  3315. /* Get consistent memory for extended logins */
  3316. ha->exlogin_buf = dma_alloc_coherent(&ha->pdev->dev,
  3317. ha->exlogin_size, &ha->exlogin_buf_dma, GFP_KERNEL);
  3318. if (!ha->exlogin_buf) {
  3319. ql_log_pci(ql_log_fatal, ha->pdev, 0xd02a,
  3320. "Failed to allocate memory for exlogin_buf_dma.\n");
  3321. return -ENOMEM;
  3322. }
  3323. /* Now configure the dma buffer */
  3324. rval = qla_set_exlogin_mem_cfg(vha, ha->exlogin_buf_dma);
  3325. if (rval) {
  3326. ql_log(ql_log_fatal, vha, 0x00cf,
  3327. "Setup extended login buffer ****FAILED****.\n");
  3328. qla2x00_free_exlogin_buffer(ha);
  3329. }
  3330. return rval;
  3331. }
  3332. /*
  3333. * qla2x00_free_exlogin_buffer
  3334. *
  3335. * Input:
  3336. * ha = adapter block pointer
  3337. */
  3338. void
  3339. qla2x00_free_exlogin_buffer(struct qla_hw_data *ha)
  3340. {
  3341. if (ha->exlogin_buf) {
  3342. dma_free_coherent(&ha->pdev->dev, ha->exlogin_size,
  3343. ha->exlogin_buf, ha->exlogin_buf_dma);
  3344. ha->exlogin_buf = NULL;
  3345. ha->exlogin_size = 0;
  3346. }
  3347. }
  3348. int
  3349. qla2x00_set_exchoffld_buffer(scsi_qla_host_t *vha)
  3350. {
  3351. int rval;
  3352. uint16_t size, max_cnt, temp;
  3353. struct qla_hw_data *ha = vha->hw;
  3354. /* Return if we don't need to alloacate any extended logins */
  3355. if (!ql2xexchoffld)
  3356. return QLA_SUCCESS;
  3357. ql_log(ql_log_info, vha, 0xd014,
  3358. "Exchange offload count: %d.\n", ql2xexlogins);
  3359. max_cnt = 0;
  3360. rval = qla_get_exchoffld_status(vha, &size, &max_cnt);
  3361. if (rval != QLA_SUCCESS) {
  3362. ql_log_pci(ql_log_fatal, ha->pdev, 0xd012,
  3363. "Failed to get exlogin status.\n");
  3364. return rval;
  3365. }
  3366. temp = (ql2xexchoffld > max_cnt) ? max_cnt : ql2xexchoffld;
  3367. ha->exchoffld_size = (size * temp);
  3368. ql_log(ql_log_info, vha, 0xd016,
  3369. "Exchange offload: max_count=%d, buffers=0x%x, total=%d.\n",
  3370. max_cnt, size, temp);
  3371. ql_log(ql_log_info, vha, 0xd017,
  3372. "Exchange Buffers requested size = 0x%x\n", ha->exchoffld_size);
  3373. /* Get consistent memory for extended logins */
  3374. ha->exchoffld_buf = dma_alloc_coherent(&ha->pdev->dev,
  3375. ha->exchoffld_size, &ha->exchoffld_buf_dma, GFP_KERNEL);
  3376. if (!ha->exchoffld_buf) {
  3377. ql_log_pci(ql_log_fatal, ha->pdev, 0xd013,
  3378. "Failed to allocate memory for exchoffld_buf_dma.\n");
  3379. return -ENOMEM;
  3380. }
  3381. /* Now configure the dma buffer */
  3382. rval = qla_set_exchoffld_mem_cfg(vha, ha->exchoffld_buf_dma);
  3383. if (rval) {
  3384. ql_log(ql_log_fatal, vha, 0xd02e,
  3385. "Setup exchange offload buffer ****FAILED****.\n");
  3386. qla2x00_free_exchoffld_buffer(ha);
  3387. }
  3388. return rval;
  3389. }
  3390. /*
  3391. * qla2x00_free_exchoffld_buffer
  3392. *
  3393. * Input:
  3394. * ha = adapter block pointer
  3395. */
  3396. void
  3397. qla2x00_free_exchoffld_buffer(struct qla_hw_data *ha)
  3398. {
  3399. if (ha->exchoffld_buf) {
  3400. dma_free_coherent(&ha->pdev->dev, ha->exchoffld_size,
  3401. ha->exchoffld_buf, ha->exchoffld_buf_dma);
  3402. ha->exchoffld_buf = NULL;
  3403. ha->exchoffld_size = 0;
  3404. }
  3405. }
  3406. /*
  3407. * qla2x00_free_fw_dump
  3408. * Frees fw dump stuff.
  3409. *
  3410. * Input:
  3411. * ha = adapter block pointer
  3412. */
  3413. static void
  3414. qla2x00_free_fw_dump(struct qla_hw_data *ha)
  3415. {
  3416. if (ha->fce)
  3417. dma_free_coherent(&ha->pdev->dev,
  3418. FCE_SIZE, ha->fce, ha->fce_dma);
  3419. if (ha->eft)
  3420. dma_free_coherent(&ha->pdev->dev,
  3421. EFT_SIZE, ha->eft, ha->eft_dma);
  3422. if (ha->fw_dump)
  3423. vfree(ha->fw_dump);
  3424. if (ha->fw_dump_template)
  3425. vfree(ha->fw_dump_template);
  3426. ha->fce = NULL;
  3427. ha->fce_dma = 0;
  3428. ha->eft = NULL;
  3429. ha->eft_dma = 0;
  3430. ha->fw_dumped = 0;
  3431. ha->fw_dump_cap_flags = 0;
  3432. ha->fw_dump_reading = 0;
  3433. ha->fw_dump = NULL;
  3434. ha->fw_dump_len = 0;
  3435. ha->fw_dump_template = NULL;
  3436. ha->fw_dump_template_len = 0;
  3437. }
  3438. /*
  3439. * qla2x00_mem_free
  3440. * Frees all adapter allocated memory.
  3441. *
  3442. * Input:
  3443. * ha = adapter block pointer.
  3444. */
  3445. static void
  3446. qla2x00_mem_free(struct qla_hw_data *ha)
  3447. {
  3448. qla2x00_free_fw_dump(ha);
  3449. if (ha->mctp_dump)
  3450. dma_free_coherent(&ha->pdev->dev, MCTP_DUMP_SIZE, ha->mctp_dump,
  3451. ha->mctp_dump_dma);
  3452. if (ha->srb_mempool)
  3453. mempool_destroy(ha->srb_mempool);
  3454. if (ha->dcbx_tlv)
  3455. dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  3456. ha->dcbx_tlv, ha->dcbx_tlv_dma);
  3457. if (ha->xgmac_data)
  3458. dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  3459. ha->xgmac_data, ha->xgmac_data_dma);
  3460. if (ha->sns_cmd)
  3461. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  3462. ha->sns_cmd, ha->sns_cmd_dma);
  3463. if (ha->ct_sns)
  3464. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  3465. ha->ct_sns, ha->ct_sns_dma);
  3466. if (ha->sfp_data)
  3467. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  3468. if (ha->ms_iocb)
  3469. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  3470. if (ha->ex_init_cb)
  3471. dma_pool_free(ha->s_dma_pool,
  3472. ha->ex_init_cb, ha->ex_init_cb_dma);
  3473. if (ha->async_pd)
  3474. dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
  3475. if (ha->s_dma_pool)
  3476. dma_pool_destroy(ha->s_dma_pool);
  3477. if (ha->gid_list)
  3478. dma_free_coherent(&ha->pdev->dev, qla2x00_gid_list_size(ha),
  3479. ha->gid_list, ha->gid_list_dma);
  3480. if (IS_QLA82XX(ha)) {
  3481. if (!list_empty(&ha->gbl_dsd_list)) {
  3482. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  3483. /* clean up allocated prev pool */
  3484. list_for_each_entry_safe(dsd_ptr,
  3485. tdsd_ptr, &ha->gbl_dsd_list, list) {
  3486. dma_pool_free(ha->dl_dma_pool,
  3487. dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
  3488. list_del(&dsd_ptr->list);
  3489. kfree(dsd_ptr);
  3490. }
  3491. }
  3492. }
  3493. if (ha->dl_dma_pool)
  3494. dma_pool_destroy(ha->dl_dma_pool);
  3495. if (ha->fcp_cmnd_dma_pool)
  3496. dma_pool_destroy(ha->fcp_cmnd_dma_pool);
  3497. if (ha->ctx_mempool)
  3498. mempool_destroy(ha->ctx_mempool);
  3499. qlt_mem_free(ha);
  3500. if (ha->init_cb)
  3501. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  3502. ha->init_cb, ha->init_cb_dma);
  3503. vfree(ha->optrom_buffer);
  3504. kfree(ha->nvram);
  3505. kfree(ha->npiv_info);
  3506. kfree(ha->swl);
  3507. kfree(ha->loop_id_map);
  3508. ha->srb_mempool = NULL;
  3509. ha->ctx_mempool = NULL;
  3510. ha->sns_cmd = NULL;
  3511. ha->sns_cmd_dma = 0;
  3512. ha->ct_sns = NULL;
  3513. ha->ct_sns_dma = 0;
  3514. ha->ms_iocb = NULL;
  3515. ha->ms_iocb_dma = 0;
  3516. ha->init_cb = NULL;
  3517. ha->init_cb_dma = 0;
  3518. ha->ex_init_cb = NULL;
  3519. ha->ex_init_cb_dma = 0;
  3520. ha->async_pd = NULL;
  3521. ha->async_pd_dma = 0;
  3522. ha->s_dma_pool = NULL;
  3523. ha->dl_dma_pool = NULL;
  3524. ha->fcp_cmnd_dma_pool = NULL;
  3525. ha->gid_list = NULL;
  3526. ha->gid_list_dma = 0;
  3527. ha->tgt.atio_ring = NULL;
  3528. ha->tgt.atio_dma = 0;
  3529. ha->tgt.tgt_vp_map = NULL;
  3530. }
  3531. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  3532. struct qla_hw_data *ha)
  3533. {
  3534. struct Scsi_Host *host;
  3535. struct scsi_qla_host *vha = NULL;
  3536. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  3537. if (host == NULL) {
  3538. ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
  3539. "Failed to allocate host from the scsi layer, aborting.\n");
  3540. goto fail;
  3541. }
  3542. /* Clear our data area */
  3543. vha = shost_priv(host);
  3544. memset(vha, 0, sizeof(scsi_qla_host_t));
  3545. vha->host = host;
  3546. vha->host_no = host->host_no;
  3547. vha->hw = ha;
  3548. INIT_LIST_HEAD(&vha->vp_fcports);
  3549. INIT_LIST_HEAD(&vha->work_list);
  3550. INIT_LIST_HEAD(&vha->list);
  3551. INIT_LIST_HEAD(&vha->qla_cmd_list);
  3552. INIT_LIST_HEAD(&vha->qla_sess_op_cmd_list);
  3553. INIT_LIST_HEAD(&vha->logo_list);
  3554. INIT_LIST_HEAD(&vha->plogi_ack_list);
  3555. spin_lock_init(&vha->work_lock);
  3556. spin_lock_init(&vha->cmd_list_lock);
  3557. init_waitqueue_head(&vha->vref_waitq);
  3558. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  3559. ql_dbg(ql_dbg_init, vha, 0x0041,
  3560. "Allocated the host=%p hw=%p vha=%p dev_name=%s",
  3561. vha->host, vha->hw, vha,
  3562. dev_name(&(ha->pdev->dev)));
  3563. return vha;
  3564. fail:
  3565. return vha;
  3566. }
  3567. static struct qla_work_evt *
  3568. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
  3569. {
  3570. struct qla_work_evt *e;
  3571. uint8_t bail;
  3572. QLA_VHA_MARK_BUSY(vha, bail);
  3573. if (bail)
  3574. return NULL;
  3575. e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
  3576. if (!e) {
  3577. QLA_VHA_MARK_NOT_BUSY(vha);
  3578. return NULL;
  3579. }
  3580. INIT_LIST_HEAD(&e->list);
  3581. e->type = type;
  3582. e->flags = QLA_EVT_FLAG_FREE;
  3583. return e;
  3584. }
  3585. static int
  3586. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
  3587. {
  3588. unsigned long flags;
  3589. spin_lock_irqsave(&vha->work_lock, flags);
  3590. list_add_tail(&e->list, &vha->work_list);
  3591. spin_unlock_irqrestore(&vha->work_lock, flags);
  3592. qla2xxx_wake_dpc(vha);
  3593. return QLA_SUCCESS;
  3594. }
  3595. int
  3596. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  3597. u32 data)
  3598. {
  3599. struct qla_work_evt *e;
  3600. e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
  3601. if (!e)
  3602. return QLA_FUNCTION_FAILED;
  3603. e->u.aen.code = code;
  3604. e->u.aen.data = data;
  3605. return qla2x00_post_work(vha, e);
  3606. }
  3607. int
  3608. qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
  3609. {
  3610. struct qla_work_evt *e;
  3611. e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
  3612. if (!e)
  3613. return QLA_FUNCTION_FAILED;
  3614. memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
  3615. return qla2x00_post_work(vha, e);
  3616. }
  3617. #define qla2x00_post_async_work(name, type) \
  3618. int qla2x00_post_async_##name##_work( \
  3619. struct scsi_qla_host *vha, \
  3620. fc_port_t *fcport, uint16_t *data) \
  3621. { \
  3622. struct qla_work_evt *e; \
  3623. \
  3624. e = qla2x00_alloc_work(vha, type); \
  3625. if (!e) \
  3626. return QLA_FUNCTION_FAILED; \
  3627. \
  3628. e->u.logio.fcport = fcport; \
  3629. if (data) { \
  3630. e->u.logio.data[0] = data[0]; \
  3631. e->u.logio.data[1] = data[1]; \
  3632. } \
  3633. return qla2x00_post_work(vha, e); \
  3634. }
  3635. qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
  3636. qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
  3637. qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
  3638. qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
  3639. qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
  3640. qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
  3641. int
  3642. qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
  3643. {
  3644. struct qla_work_evt *e;
  3645. e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
  3646. if (!e)
  3647. return QLA_FUNCTION_FAILED;
  3648. e->u.uevent.code = code;
  3649. return qla2x00_post_work(vha, e);
  3650. }
  3651. static void
  3652. qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
  3653. {
  3654. char event_string[40];
  3655. char *envp[] = { event_string, NULL };
  3656. switch (code) {
  3657. case QLA_UEVENT_CODE_FW_DUMP:
  3658. snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
  3659. vha->host_no);
  3660. break;
  3661. default:
  3662. /* do nothing */
  3663. break;
  3664. }
  3665. kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
  3666. }
  3667. int
  3668. qlafx00_post_aenfx_work(struct scsi_qla_host *vha, uint32_t evtcode,
  3669. uint32_t *data, int cnt)
  3670. {
  3671. struct qla_work_evt *e;
  3672. e = qla2x00_alloc_work(vha, QLA_EVT_AENFX);
  3673. if (!e)
  3674. return QLA_FUNCTION_FAILED;
  3675. e->u.aenfx.evtcode = evtcode;
  3676. e->u.aenfx.count = cnt;
  3677. memcpy(e->u.aenfx.mbx, data, sizeof(*data) * cnt);
  3678. return qla2x00_post_work(vha, e);
  3679. }
  3680. void
  3681. qla2x00_do_work(struct scsi_qla_host *vha)
  3682. {
  3683. struct qla_work_evt *e, *tmp;
  3684. unsigned long flags;
  3685. LIST_HEAD(work);
  3686. spin_lock_irqsave(&vha->work_lock, flags);
  3687. list_splice_init(&vha->work_list, &work);
  3688. spin_unlock_irqrestore(&vha->work_lock, flags);
  3689. list_for_each_entry_safe(e, tmp, &work, list) {
  3690. list_del_init(&e->list);
  3691. switch (e->type) {
  3692. case QLA_EVT_AEN:
  3693. fc_host_post_event(vha->host, fc_get_event_number(),
  3694. e->u.aen.code, e->u.aen.data);
  3695. break;
  3696. case QLA_EVT_IDC_ACK:
  3697. qla81xx_idc_ack(vha, e->u.idc_ack.mb);
  3698. break;
  3699. case QLA_EVT_ASYNC_LOGIN:
  3700. qla2x00_async_login(vha, e->u.logio.fcport,
  3701. e->u.logio.data);
  3702. break;
  3703. case QLA_EVT_ASYNC_LOGIN_DONE:
  3704. qla2x00_async_login_done(vha, e->u.logio.fcport,
  3705. e->u.logio.data);
  3706. break;
  3707. case QLA_EVT_ASYNC_LOGOUT:
  3708. qla2x00_async_logout(vha, e->u.logio.fcport);
  3709. break;
  3710. case QLA_EVT_ASYNC_LOGOUT_DONE:
  3711. qla2x00_async_logout_done(vha, e->u.logio.fcport,
  3712. e->u.logio.data);
  3713. break;
  3714. case QLA_EVT_ASYNC_ADISC:
  3715. qla2x00_async_adisc(vha, e->u.logio.fcport,
  3716. e->u.logio.data);
  3717. break;
  3718. case QLA_EVT_ASYNC_ADISC_DONE:
  3719. qla2x00_async_adisc_done(vha, e->u.logio.fcport,
  3720. e->u.logio.data);
  3721. break;
  3722. case QLA_EVT_UEVENT:
  3723. qla2x00_uevent_emit(vha, e->u.uevent.code);
  3724. break;
  3725. case QLA_EVT_AENFX:
  3726. qlafx00_process_aen(vha, e);
  3727. break;
  3728. }
  3729. if (e->flags & QLA_EVT_FLAG_FREE)
  3730. kfree(e);
  3731. /* For each work completed decrement vha ref count */
  3732. QLA_VHA_MARK_NOT_BUSY(vha);
  3733. }
  3734. }
  3735. /* Relogins all the fcports of a vport
  3736. * Context: dpc thread
  3737. */
  3738. void qla2x00_relogin(struct scsi_qla_host *vha)
  3739. {
  3740. fc_port_t *fcport;
  3741. int status;
  3742. uint16_t next_loopid = 0;
  3743. struct qla_hw_data *ha = vha->hw;
  3744. uint16_t data[2];
  3745. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3746. /*
  3747. * If the port is not ONLINE then try to login
  3748. * to it if we haven't run out of retries.
  3749. */
  3750. if (atomic_read(&fcport->state) != FCS_ONLINE &&
  3751. fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
  3752. fcport->login_retry--;
  3753. if (fcport->flags & FCF_FABRIC_DEVICE) {
  3754. if (fcport->flags & FCF_FCP2_DEVICE)
  3755. ha->isp_ops->fabric_logout(vha,
  3756. fcport->loop_id,
  3757. fcport->d_id.b.domain,
  3758. fcport->d_id.b.area,
  3759. fcport->d_id.b.al_pa);
  3760. if (fcport->loop_id == FC_NO_LOOP_ID) {
  3761. fcport->loop_id = next_loopid =
  3762. ha->min_external_loopid;
  3763. status = qla2x00_find_new_loop_id(
  3764. vha, fcport);
  3765. if (status != QLA_SUCCESS) {
  3766. /* Ran out of IDs to use */
  3767. break;
  3768. }
  3769. }
  3770. if (IS_ALOGIO_CAPABLE(ha)) {
  3771. fcport->flags |= FCF_ASYNC_SENT;
  3772. data[0] = 0;
  3773. data[1] = QLA_LOGIO_LOGIN_RETRIED;
  3774. status = qla2x00_post_async_login_work(
  3775. vha, fcport, data);
  3776. if (status == QLA_SUCCESS)
  3777. continue;
  3778. /* Attempt a retry. */
  3779. status = 1;
  3780. } else {
  3781. status = qla2x00_fabric_login(vha,
  3782. fcport, &next_loopid);
  3783. if (status == QLA_SUCCESS) {
  3784. int status2;
  3785. uint8_t opts;
  3786. opts = 0;
  3787. if (fcport->flags &
  3788. FCF_FCP2_DEVICE)
  3789. opts |= BIT_1;
  3790. status2 =
  3791. qla2x00_get_port_database(
  3792. vha, fcport, opts);
  3793. if (status2 != QLA_SUCCESS)
  3794. status = 1;
  3795. }
  3796. }
  3797. } else
  3798. status = qla2x00_local_device_login(vha,
  3799. fcport);
  3800. if (status == QLA_SUCCESS) {
  3801. fcport->old_loop_id = fcport->loop_id;
  3802. ql_dbg(ql_dbg_disc, vha, 0x2003,
  3803. "Port login OK: logged in ID 0x%x.\n",
  3804. fcport->loop_id);
  3805. qla2x00_update_fcport(vha, fcport);
  3806. } else if (status == 1) {
  3807. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  3808. /* retry the login again */
  3809. ql_dbg(ql_dbg_disc, vha, 0x2007,
  3810. "Retrying %d login again loop_id 0x%x.\n",
  3811. fcport->login_retry, fcport->loop_id);
  3812. } else {
  3813. fcport->login_retry = 0;
  3814. }
  3815. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  3816. qla2x00_clear_loop_id(fcport);
  3817. }
  3818. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  3819. break;
  3820. }
  3821. }
  3822. /* Schedule work on any of the dpc-workqueues */
  3823. void
  3824. qla83xx_schedule_work(scsi_qla_host_t *base_vha, int work_code)
  3825. {
  3826. struct qla_hw_data *ha = base_vha->hw;
  3827. switch (work_code) {
  3828. case MBA_IDC_AEN: /* 0x8200 */
  3829. if (ha->dpc_lp_wq)
  3830. queue_work(ha->dpc_lp_wq, &ha->idc_aen);
  3831. break;
  3832. case QLA83XX_NIC_CORE_RESET: /* 0x1 */
  3833. if (!ha->flags.nic_core_reset_hdlr_active) {
  3834. if (ha->dpc_hp_wq)
  3835. queue_work(ha->dpc_hp_wq, &ha->nic_core_reset);
  3836. } else
  3837. ql_dbg(ql_dbg_p3p, base_vha, 0xb05e,
  3838. "NIC Core reset is already active. Skip "
  3839. "scheduling it again.\n");
  3840. break;
  3841. case QLA83XX_IDC_STATE_HANDLER: /* 0x2 */
  3842. if (ha->dpc_hp_wq)
  3843. queue_work(ha->dpc_hp_wq, &ha->idc_state_handler);
  3844. break;
  3845. case QLA83XX_NIC_CORE_UNRECOVERABLE: /* 0x3 */
  3846. if (ha->dpc_hp_wq)
  3847. queue_work(ha->dpc_hp_wq, &ha->nic_core_unrecoverable);
  3848. break;
  3849. default:
  3850. ql_log(ql_log_warn, base_vha, 0xb05f,
  3851. "Unknown work-code=0x%x.\n", work_code);
  3852. }
  3853. return;
  3854. }
  3855. /* Work: Perform NIC Core Unrecoverable state handling */
  3856. void
  3857. qla83xx_nic_core_unrecoverable_work(struct work_struct *work)
  3858. {
  3859. struct qla_hw_data *ha =
  3860. container_of(work, struct qla_hw_data, nic_core_unrecoverable);
  3861. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3862. uint32_t dev_state = 0;
  3863. qla83xx_idc_lock(base_vha, 0);
  3864. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3865. qla83xx_reset_ownership(base_vha);
  3866. if (ha->flags.nic_core_reset_owner) {
  3867. ha->flags.nic_core_reset_owner = 0;
  3868. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3869. QLA8XXX_DEV_FAILED);
  3870. ql_log(ql_log_info, base_vha, 0xb060, "HW State: FAILED.\n");
  3871. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3872. }
  3873. qla83xx_idc_unlock(base_vha, 0);
  3874. }
  3875. /* Work: Execute IDC state handler */
  3876. void
  3877. qla83xx_idc_state_handler_work(struct work_struct *work)
  3878. {
  3879. struct qla_hw_data *ha =
  3880. container_of(work, struct qla_hw_data, idc_state_handler);
  3881. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3882. uint32_t dev_state = 0;
  3883. qla83xx_idc_lock(base_vha, 0);
  3884. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3885. if (dev_state == QLA8XXX_DEV_FAILED ||
  3886. dev_state == QLA8XXX_DEV_NEED_QUIESCENT)
  3887. qla83xx_idc_state_handler(base_vha);
  3888. qla83xx_idc_unlock(base_vha, 0);
  3889. }
  3890. static int
  3891. qla83xx_check_nic_core_fw_alive(scsi_qla_host_t *base_vha)
  3892. {
  3893. int rval = QLA_SUCCESS;
  3894. unsigned long heart_beat_wait = jiffies + (1 * HZ);
  3895. uint32_t heart_beat_counter1, heart_beat_counter2;
  3896. do {
  3897. if (time_after(jiffies, heart_beat_wait)) {
  3898. ql_dbg(ql_dbg_p3p, base_vha, 0xb07c,
  3899. "Nic Core f/w is not alive.\n");
  3900. rval = QLA_FUNCTION_FAILED;
  3901. break;
  3902. }
  3903. qla83xx_idc_lock(base_vha, 0);
  3904. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3905. &heart_beat_counter1);
  3906. qla83xx_idc_unlock(base_vha, 0);
  3907. msleep(100);
  3908. qla83xx_idc_lock(base_vha, 0);
  3909. qla83xx_rd_reg(base_vha, QLA83XX_FW_HEARTBEAT,
  3910. &heart_beat_counter2);
  3911. qla83xx_idc_unlock(base_vha, 0);
  3912. } while (heart_beat_counter1 == heart_beat_counter2);
  3913. return rval;
  3914. }
  3915. /* Work: Perform NIC Core Reset handling */
  3916. void
  3917. qla83xx_nic_core_reset_work(struct work_struct *work)
  3918. {
  3919. struct qla_hw_data *ha =
  3920. container_of(work, struct qla_hw_data, nic_core_reset);
  3921. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3922. uint32_t dev_state = 0;
  3923. if (IS_QLA2031(ha)) {
  3924. if (qla2xxx_mctp_dump(base_vha) != QLA_SUCCESS)
  3925. ql_log(ql_log_warn, base_vha, 0xb081,
  3926. "Failed to dump mctp\n");
  3927. return;
  3928. }
  3929. if (!ha->flags.nic_core_reset_hdlr_active) {
  3930. if (qla83xx_check_nic_core_fw_alive(base_vha) == QLA_SUCCESS) {
  3931. qla83xx_idc_lock(base_vha, 0);
  3932. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  3933. &dev_state);
  3934. qla83xx_idc_unlock(base_vha, 0);
  3935. if (dev_state != QLA8XXX_DEV_NEED_RESET) {
  3936. ql_dbg(ql_dbg_p3p, base_vha, 0xb07a,
  3937. "Nic Core f/w is alive.\n");
  3938. return;
  3939. }
  3940. }
  3941. ha->flags.nic_core_reset_hdlr_active = 1;
  3942. if (qla83xx_nic_core_reset(base_vha)) {
  3943. /* NIC Core reset failed. */
  3944. ql_dbg(ql_dbg_p3p, base_vha, 0xb061,
  3945. "NIC Core reset failed.\n");
  3946. }
  3947. ha->flags.nic_core_reset_hdlr_active = 0;
  3948. }
  3949. }
  3950. /* Work: Handle 8200 IDC aens */
  3951. void
  3952. qla83xx_service_idc_aen(struct work_struct *work)
  3953. {
  3954. struct qla_hw_data *ha =
  3955. container_of(work, struct qla_hw_data, idc_aen);
  3956. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  3957. uint32_t dev_state, idc_control;
  3958. qla83xx_idc_lock(base_vha, 0);
  3959. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3960. qla83xx_rd_reg(base_vha, QLA83XX_IDC_CONTROL, &idc_control);
  3961. qla83xx_idc_unlock(base_vha, 0);
  3962. if (dev_state == QLA8XXX_DEV_NEED_RESET) {
  3963. if (idc_control & QLA83XX_IDC_GRACEFUL_RESET) {
  3964. ql_dbg(ql_dbg_p3p, base_vha, 0xb062,
  3965. "Application requested NIC Core Reset.\n");
  3966. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3967. } else if (qla83xx_check_nic_core_fw_alive(base_vha) ==
  3968. QLA_SUCCESS) {
  3969. ql_dbg(ql_dbg_p3p, base_vha, 0xb07b,
  3970. "Other protocol driver requested NIC Core Reset.\n");
  3971. qla83xx_schedule_work(base_vha, QLA83XX_NIC_CORE_RESET);
  3972. }
  3973. } else if (dev_state == QLA8XXX_DEV_FAILED ||
  3974. dev_state == QLA8XXX_DEV_NEED_QUIESCENT) {
  3975. qla83xx_schedule_work(base_vha, QLA83XX_IDC_STATE_HANDLER);
  3976. }
  3977. }
  3978. static void
  3979. qla83xx_wait_logic(void)
  3980. {
  3981. int i;
  3982. /* Yield CPU */
  3983. if (!in_interrupt()) {
  3984. /*
  3985. * Wait about 200ms before retrying again.
  3986. * This controls the number of retries for single
  3987. * lock operation.
  3988. */
  3989. msleep(100);
  3990. schedule();
  3991. } else {
  3992. for (i = 0; i < 20; i++)
  3993. cpu_relax(); /* This a nop instr on i386 */
  3994. }
  3995. }
  3996. static int
  3997. qla83xx_force_lock_recovery(scsi_qla_host_t *base_vha)
  3998. {
  3999. int rval;
  4000. uint32_t data;
  4001. uint32_t idc_lck_rcvry_stage_mask = 0x3;
  4002. uint32_t idc_lck_rcvry_owner_mask = 0x3c;
  4003. struct qla_hw_data *ha = base_vha->hw;
  4004. ql_dbg(ql_dbg_p3p, base_vha, 0xb086,
  4005. "Trying force recovery of the IDC lock.\n");
  4006. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY, &data);
  4007. if (rval)
  4008. return rval;
  4009. if ((data & idc_lck_rcvry_stage_mask) > 0) {
  4010. return QLA_SUCCESS;
  4011. } else {
  4012. data = (IDC_LOCK_RECOVERY_STAGE1) | (ha->portnum << 2);
  4013. rval = qla83xx_wr_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  4014. data);
  4015. if (rval)
  4016. return rval;
  4017. msleep(200);
  4018. rval = qla83xx_rd_reg(base_vha, QLA83XX_IDC_LOCK_RECOVERY,
  4019. &data);
  4020. if (rval)
  4021. return rval;
  4022. if (((data & idc_lck_rcvry_owner_mask) >> 2) == ha->portnum) {
  4023. data &= (IDC_LOCK_RECOVERY_STAGE2 |
  4024. ~(idc_lck_rcvry_stage_mask));
  4025. rval = qla83xx_wr_reg(base_vha,
  4026. QLA83XX_IDC_LOCK_RECOVERY, data);
  4027. if (rval)
  4028. return rval;
  4029. /* Forcefully perform IDC UnLock */
  4030. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK,
  4031. &data);
  4032. if (rval)
  4033. return rval;
  4034. /* Clear lock-id by setting 0xff */
  4035. rval = qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4036. 0xff);
  4037. if (rval)
  4038. return rval;
  4039. /* Clear lock-recovery by setting 0x0 */
  4040. rval = qla83xx_wr_reg(base_vha,
  4041. QLA83XX_IDC_LOCK_RECOVERY, 0x0);
  4042. if (rval)
  4043. return rval;
  4044. } else
  4045. return QLA_SUCCESS;
  4046. }
  4047. return rval;
  4048. }
  4049. static int
  4050. qla83xx_idc_lock_recovery(scsi_qla_host_t *base_vha)
  4051. {
  4052. int rval = QLA_SUCCESS;
  4053. uint32_t o_drv_lockid, n_drv_lockid;
  4054. unsigned long lock_recovery_timeout;
  4055. lock_recovery_timeout = jiffies + QLA83XX_MAX_LOCK_RECOVERY_WAIT;
  4056. retry_lockid:
  4057. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &o_drv_lockid);
  4058. if (rval)
  4059. goto exit;
  4060. /* MAX wait time before forcing IDC Lock recovery = 2 secs */
  4061. if (time_after_eq(jiffies, lock_recovery_timeout)) {
  4062. if (qla83xx_force_lock_recovery(base_vha) == QLA_SUCCESS)
  4063. return QLA_SUCCESS;
  4064. else
  4065. return QLA_FUNCTION_FAILED;
  4066. }
  4067. rval = qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &n_drv_lockid);
  4068. if (rval)
  4069. goto exit;
  4070. if (o_drv_lockid == n_drv_lockid) {
  4071. qla83xx_wait_logic();
  4072. goto retry_lockid;
  4073. } else
  4074. return QLA_SUCCESS;
  4075. exit:
  4076. return rval;
  4077. }
  4078. void
  4079. qla83xx_idc_lock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  4080. {
  4081. uint16_t options = (requester_id << 15) | BIT_6;
  4082. uint32_t data;
  4083. uint32_t lock_owner;
  4084. struct qla_hw_data *ha = base_vha->hw;
  4085. /* IDC-lock implementation using driver-lock/lock-id remote registers */
  4086. retry_lock:
  4087. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCK, &data)
  4088. == QLA_SUCCESS) {
  4089. if (data) {
  4090. /* Setting lock-id to our function-number */
  4091. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4092. ha->portnum);
  4093. } else {
  4094. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID,
  4095. &lock_owner);
  4096. ql_dbg(ql_dbg_p3p, base_vha, 0xb063,
  4097. "Failed to acquire IDC lock, acquired by %d, "
  4098. "retrying...\n", lock_owner);
  4099. /* Retry/Perform IDC-Lock recovery */
  4100. if (qla83xx_idc_lock_recovery(base_vha)
  4101. == QLA_SUCCESS) {
  4102. qla83xx_wait_logic();
  4103. goto retry_lock;
  4104. } else
  4105. ql_log(ql_log_warn, base_vha, 0xb075,
  4106. "IDC Lock recovery FAILED.\n");
  4107. }
  4108. }
  4109. return;
  4110. /* XXX: IDC-lock implementation using access-control mbx */
  4111. retry_lock2:
  4112. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  4113. ql_dbg(ql_dbg_p3p, base_vha, 0xb072,
  4114. "Failed to acquire IDC lock. retrying...\n");
  4115. /* Retry/Perform IDC-Lock recovery */
  4116. if (qla83xx_idc_lock_recovery(base_vha) == QLA_SUCCESS) {
  4117. qla83xx_wait_logic();
  4118. goto retry_lock2;
  4119. } else
  4120. ql_log(ql_log_warn, base_vha, 0xb076,
  4121. "IDC Lock recovery FAILED.\n");
  4122. }
  4123. return;
  4124. }
  4125. void
  4126. qla83xx_idc_unlock(scsi_qla_host_t *base_vha, uint16_t requester_id)
  4127. {
  4128. #if 0
  4129. uint16_t options = (requester_id << 15) | BIT_7;
  4130. #endif
  4131. uint16_t retry;
  4132. uint32_t data;
  4133. struct qla_hw_data *ha = base_vha->hw;
  4134. /* IDC-unlock implementation using driver-unlock/lock-id
  4135. * remote registers
  4136. */
  4137. retry = 0;
  4138. retry_unlock:
  4139. if (qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_LOCKID, &data)
  4140. == QLA_SUCCESS) {
  4141. if (data == ha->portnum) {
  4142. qla83xx_rd_reg(base_vha, QLA83XX_DRIVER_UNLOCK, &data);
  4143. /* Clearing lock-id by setting 0xff */
  4144. qla83xx_wr_reg(base_vha, QLA83XX_DRIVER_LOCKID, 0xff);
  4145. } else if (retry < 10) {
  4146. /* SV: XXX: IDC unlock retrying needed here? */
  4147. /* Retry for IDC-unlock */
  4148. qla83xx_wait_logic();
  4149. retry++;
  4150. ql_dbg(ql_dbg_p3p, base_vha, 0xb064,
  4151. "Failed to release IDC lock, retrying=%d\n", retry);
  4152. goto retry_unlock;
  4153. }
  4154. } else if (retry < 10) {
  4155. /* Retry for IDC-unlock */
  4156. qla83xx_wait_logic();
  4157. retry++;
  4158. ql_dbg(ql_dbg_p3p, base_vha, 0xb065,
  4159. "Failed to read drv-lockid, retrying=%d\n", retry);
  4160. goto retry_unlock;
  4161. }
  4162. return;
  4163. #if 0
  4164. /* XXX: IDC-unlock implementation using access-control mbx */
  4165. retry = 0;
  4166. retry_unlock2:
  4167. if (qla83xx_access_control(base_vha, options, 0, 0, NULL)) {
  4168. if (retry < 10) {
  4169. /* Retry for IDC-unlock */
  4170. qla83xx_wait_logic();
  4171. retry++;
  4172. ql_dbg(ql_dbg_p3p, base_vha, 0xb066,
  4173. "Failed to release IDC lock, retrying=%d\n", retry);
  4174. goto retry_unlock2;
  4175. }
  4176. }
  4177. return;
  4178. #endif
  4179. }
  4180. int
  4181. __qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  4182. {
  4183. int rval = QLA_SUCCESS;
  4184. struct qla_hw_data *ha = vha->hw;
  4185. uint32_t drv_presence;
  4186. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4187. if (rval == QLA_SUCCESS) {
  4188. drv_presence |= (1 << ha->portnum);
  4189. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4190. drv_presence);
  4191. }
  4192. return rval;
  4193. }
  4194. int
  4195. qla83xx_set_drv_presence(scsi_qla_host_t *vha)
  4196. {
  4197. int rval = QLA_SUCCESS;
  4198. qla83xx_idc_lock(vha, 0);
  4199. rval = __qla83xx_set_drv_presence(vha);
  4200. qla83xx_idc_unlock(vha, 0);
  4201. return rval;
  4202. }
  4203. int
  4204. __qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  4205. {
  4206. int rval = QLA_SUCCESS;
  4207. struct qla_hw_data *ha = vha->hw;
  4208. uint32_t drv_presence;
  4209. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4210. if (rval == QLA_SUCCESS) {
  4211. drv_presence &= ~(1 << ha->portnum);
  4212. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4213. drv_presence);
  4214. }
  4215. return rval;
  4216. }
  4217. int
  4218. qla83xx_clear_drv_presence(scsi_qla_host_t *vha)
  4219. {
  4220. int rval = QLA_SUCCESS;
  4221. qla83xx_idc_lock(vha, 0);
  4222. rval = __qla83xx_clear_drv_presence(vha);
  4223. qla83xx_idc_unlock(vha, 0);
  4224. return rval;
  4225. }
  4226. static void
  4227. qla83xx_need_reset_handler(scsi_qla_host_t *vha)
  4228. {
  4229. struct qla_hw_data *ha = vha->hw;
  4230. uint32_t drv_ack, drv_presence;
  4231. unsigned long ack_timeout;
  4232. /* Wait for IDC ACK from all functions (DRV-ACK == DRV-PRESENCE) */
  4233. ack_timeout = jiffies + (ha->fcoe_reset_timeout * HZ);
  4234. while (1) {
  4235. qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  4236. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  4237. if ((drv_ack & drv_presence) == drv_presence)
  4238. break;
  4239. if (time_after_eq(jiffies, ack_timeout)) {
  4240. ql_log(ql_log_warn, vha, 0xb067,
  4241. "RESET ACK TIMEOUT! drv_presence=0x%x "
  4242. "drv_ack=0x%x\n", drv_presence, drv_ack);
  4243. /*
  4244. * The function(s) which did not ack in time are forced
  4245. * to withdraw any further participation in the IDC
  4246. * reset.
  4247. */
  4248. if (drv_ack != drv_presence)
  4249. qla83xx_wr_reg(vha, QLA83XX_IDC_DRV_PRESENCE,
  4250. drv_ack);
  4251. break;
  4252. }
  4253. qla83xx_idc_unlock(vha, 0);
  4254. msleep(1000);
  4255. qla83xx_idc_lock(vha, 0);
  4256. }
  4257. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_COLD);
  4258. ql_log(ql_log_info, vha, 0xb068, "HW State: COLD/RE-INIT.\n");
  4259. }
  4260. static int
  4261. qla83xx_device_bootstrap(scsi_qla_host_t *vha)
  4262. {
  4263. int rval = QLA_SUCCESS;
  4264. uint32_t idc_control;
  4265. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_INITIALIZING);
  4266. ql_log(ql_log_info, vha, 0xb069, "HW State: INITIALIZING.\n");
  4267. /* Clearing IDC-Control Graceful-Reset Bit before resetting f/w */
  4268. __qla83xx_get_idc_control(vha, &idc_control);
  4269. idc_control &= ~QLA83XX_IDC_GRACEFUL_RESET;
  4270. __qla83xx_set_idc_control(vha, 0);
  4271. qla83xx_idc_unlock(vha, 0);
  4272. rval = qla83xx_restart_nic_firmware(vha);
  4273. qla83xx_idc_lock(vha, 0);
  4274. if (rval != QLA_SUCCESS) {
  4275. ql_log(ql_log_fatal, vha, 0xb06a,
  4276. "Failed to restart NIC f/w.\n");
  4277. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_FAILED);
  4278. ql_log(ql_log_info, vha, 0xb06b, "HW State: FAILED.\n");
  4279. } else {
  4280. ql_dbg(ql_dbg_p3p, vha, 0xb06c,
  4281. "Success in restarting nic f/w.\n");
  4282. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE, QLA8XXX_DEV_READY);
  4283. ql_log(ql_log_info, vha, 0xb06d, "HW State: READY.\n");
  4284. }
  4285. return rval;
  4286. }
  4287. /* Assumes idc_lock always held on entry */
  4288. int
  4289. qla83xx_idc_state_handler(scsi_qla_host_t *base_vha)
  4290. {
  4291. struct qla_hw_data *ha = base_vha->hw;
  4292. int rval = QLA_SUCCESS;
  4293. unsigned long dev_init_timeout;
  4294. uint32_t dev_state;
  4295. /* Wait for MAX-INIT-TIMEOUT for the device to go ready */
  4296. dev_init_timeout = jiffies + (ha->fcoe_dev_init_timeout * HZ);
  4297. while (1) {
  4298. if (time_after_eq(jiffies, dev_init_timeout)) {
  4299. ql_log(ql_log_warn, base_vha, 0xb06e,
  4300. "Initialization TIMEOUT!\n");
  4301. /* Init timeout. Disable further NIC Core
  4302. * communication.
  4303. */
  4304. qla83xx_wr_reg(base_vha, QLA83XX_IDC_DEV_STATE,
  4305. QLA8XXX_DEV_FAILED);
  4306. ql_log(ql_log_info, base_vha, 0xb06f,
  4307. "HW State: FAILED.\n");
  4308. }
  4309. qla83xx_rd_reg(base_vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  4310. switch (dev_state) {
  4311. case QLA8XXX_DEV_READY:
  4312. if (ha->flags.nic_core_reset_owner)
  4313. qla83xx_idc_audit(base_vha,
  4314. IDC_AUDIT_COMPLETION);
  4315. ha->flags.nic_core_reset_owner = 0;
  4316. ql_dbg(ql_dbg_p3p, base_vha, 0xb070,
  4317. "Reset_owner reset by 0x%x.\n",
  4318. ha->portnum);
  4319. goto exit;
  4320. case QLA8XXX_DEV_COLD:
  4321. if (ha->flags.nic_core_reset_owner)
  4322. rval = qla83xx_device_bootstrap(base_vha);
  4323. else {
  4324. /* Wait for AEN to change device-state */
  4325. qla83xx_idc_unlock(base_vha, 0);
  4326. msleep(1000);
  4327. qla83xx_idc_lock(base_vha, 0);
  4328. }
  4329. break;
  4330. case QLA8XXX_DEV_INITIALIZING:
  4331. /* Wait for AEN to change device-state */
  4332. qla83xx_idc_unlock(base_vha, 0);
  4333. msleep(1000);
  4334. qla83xx_idc_lock(base_vha, 0);
  4335. break;
  4336. case QLA8XXX_DEV_NEED_RESET:
  4337. if (!ql2xdontresethba && ha->flags.nic_core_reset_owner)
  4338. qla83xx_need_reset_handler(base_vha);
  4339. else {
  4340. /* Wait for AEN to change device-state */
  4341. qla83xx_idc_unlock(base_vha, 0);
  4342. msleep(1000);
  4343. qla83xx_idc_lock(base_vha, 0);
  4344. }
  4345. /* reset timeout value after need reset handler */
  4346. dev_init_timeout = jiffies +
  4347. (ha->fcoe_dev_init_timeout * HZ);
  4348. break;
  4349. case QLA8XXX_DEV_NEED_QUIESCENT:
  4350. /* XXX: DEBUG for now */
  4351. qla83xx_idc_unlock(base_vha, 0);
  4352. msleep(1000);
  4353. qla83xx_idc_lock(base_vha, 0);
  4354. break;
  4355. case QLA8XXX_DEV_QUIESCENT:
  4356. /* XXX: DEBUG for now */
  4357. if (ha->flags.quiesce_owner)
  4358. goto exit;
  4359. qla83xx_idc_unlock(base_vha, 0);
  4360. msleep(1000);
  4361. qla83xx_idc_lock(base_vha, 0);
  4362. dev_init_timeout = jiffies +
  4363. (ha->fcoe_dev_init_timeout * HZ);
  4364. break;
  4365. case QLA8XXX_DEV_FAILED:
  4366. if (ha->flags.nic_core_reset_owner)
  4367. qla83xx_idc_audit(base_vha,
  4368. IDC_AUDIT_COMPLETION);
  4369. ha->flags.nic_core_reset_owner = 0;
  4370. __qla83xx_clear_drv_presence(base_vha);
  4371. qla83xx_idc_unlock(base_vha, 0);
  4372. qla8xxx_dev_failed_handler(base_vha);
  4373. rval = QLA_FUNCTION_FAILED;
  4374. qla83xx_idc_lock(base_vha, 0);
  4375. goto exit;
  4376. case QLA8XXX_BAD_VALUE:
  4377. qla83xx_idc_unlock(base_vha, 0);
  4378. msleep(1000);
  4379. qla83xx_idc_lock(base_vha, 0);
  4380. break;
  4381. default:
  4382. ql_log(ql_log_warn, base_vha, 0xb071,
  4383. "Unknown Device State: %x.\n", dev_state);
  4384. qla83xx_idc_unlock(base_vha, 0);
  4385. qla8xxx_dev_failed_handler(base_vha);
  4386. rval = QLA_FUNCTION_FAILED;
  4387. qla83xx_idc_lock(base_vha, 0);
  4388. goto exit;
  4389. }
  4390. }
  4391. exit:
  4392. return rval;
  4393. }
  4394. void
  4395. qla2x00_disable_board_on_pci_error(struct work_struct *work)
  4396. {
  4397. struct qla_hw_data *ha = container_of(work, struct qla_hw_data,
  4398. board_disable);
  4399. struct pci_dev *pdev = ha->pdev;
  4400. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4401. /* if UNLOAD flag is already set, then continue unload,
  4402. * where it was set first.
  4403. */
  4404. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  4405. return;
  4406. ql_log(ql_log_warn, base_vha, 0x015b,
  4407. "Disabling adapter.\n");
  4408. set_bit(UNLOADING, &base_vha->dpc_flags);
  4409. qla2x00_delete_all_vps(ha, base_vha);
  4410. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4411. qla2x00_dfs_remove(base_vha);
  4412. qla84xx_put_chip(base_vha);
  4413. if (base_vha->timer_active)
  4414. qla2x00_stop_timer(base_vha);
  4415. base_vha->flags.online = 0;
  4416. qla2x00_destroy_deferred_work(ha);
  4417. /*
  4418. * Do not try to stop beacon blink as it will issue a mailbox
  4419. * command.
  4420. */
  4421. qla2x00_free_sysfs_attr(base_vha, false);
  4422. fc_remove_host(base_vha->host);
  4423. scsi_remove_host(base_vha->host);
  4424. base_vha->flags.init_done = 0;
  4425. qla25xx_delete_queues(base_vha);
  4426. qla2x00_free_irqs(base_vha);
  4427. qla2x00_free_fcports(base_vha);
  4428. qla2x00_mem_free(ha);
  4429. qla82xx_md_free(base_vha);
  4430. qla2x00_free_queues(ha);
  4431. qla2x00_unmap_iobases(ha);
  4432. pci_release_selected_regions(ha->pdev, ha->bars);
  4433. pci_disable_pcie_error_reporting(pdev);
  4434. pci_disable_device(pdev);
  4435. /*
  4436. * Let qla2x00_remove_one cleanup qla_hw_data on device removal.
  4437. */
  4438. }
  4439. /**************************************************************************
  4440. * qla2x00_do_dpc
  4441. * This kernel thread is a task that is schedule by the interrupt handler
  4442. * to perform the background processing for interrupts.
  4443. *
  4444. * Notes:
  4445. * This task always run in the context of a kernel thread. It
  4446. * is kick-off by the driver's detect code and starts up
  4447. * up one per adapter. It immediately goes to sleep and waits for
  4448. * some fibre event. When either the interrupt handler or
  4449. * the timer routine detects a event it will one of the task
  4450. * bits then wake us up.
  4451. **************************************************************************/
  4452. static int
  4453. qla2x00_do_dpc(void *data)
  4454. {
  4455. scsi_qla_host_t *base_vha;
  4456. struct qla_hw_data *ha;
  4457. ha = (struct qla_hw_data *)data;
  4458. base_vha = pci_get_drvdata(ha->pdev);
  4459. set_user_nice(current, MIN_NICE);
  4460. set_current_state(TASK_INTERRUPTIBLE);
  4461. while (!kthread_should_stop()) {
  4462. ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
  4463. "DPC handler sleeping.\n");
  4464. schedule();
  4465. if (!base_vha->flags.init_done || ha->flags.mbox_busy)
  4466. goto end_loop;
  4467. if (ha->flags.eeh_busy) {
  4468. ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
  4469. "eeh_busy=%d.\n", ha->flags.eeh_busy);
  4470. goto end_loop;
  4471. }
  4472. ha->dpc_active = 1;
  4473. ql_dbg(ql_dbg_dpc + ql_dbg_verbose, base_vha, 0x4001,
  4474. "DPC handler waking up, dpc_flags=0x%lx.\n",
  4475. base_vha->dpc_flags);
  4476. if (test_bit(UNLOADING, &base_vha->dpc_flags))
  4477. break;
  4478. qla2x00_do_work(base_vha);
  4479. if (IS_P3P_TYPE(ha)) {
  4480. if (IS_QLA8044(ha)) {
  4481. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4482. &base_vha->dpc_flags)) {
  4483. qla8044_idc_lock(ha);
  4484. qla8044_wr_direct(base_vha,
  4485. QLA8044_CRB_DEV_STATE_INDEX,
  4486. QLA8XXX_DEV_FAILED);
  4487. qla8044_idc_unlock(ha);
  4488. ql_log(ql_log_info, base_vha, 0x4004,
  4489. "HW State: FAILED.\n");
  4490. qla8044_device_state_handler(base_vha);
  4491. continue;
  4492. }
  4493. } else {
  4494. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4495. &base_vha->dpc_flags)) {
  4496. qla82xx_idc_lock(ha);
  4497. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  4498. QLA8XXX_DEV_FAILED);
  4499. qla82xx_idc_unlock(ha);
  4500. ql_log(ql_log_info, base_vha, 0x0151,
  4501. "HW State: FAILED.\n");
  4502. qla82xx_device_state_handler(base_vha);
  4503. continue;
  4504. }
  4505. }
  4506. if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
  4507. &base_vha->dpc_flags)) {
  4508. ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
  4509. "FCoE context reset scheduled.\n");
  4510. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4511. &base_vha->dpc_flags))) {
  4512. if (qla82xx_fcoe_ctx_reset(base_vha)) {
  4513. /* FCoE-ctx reset failed.
  4514. * Escalate to chip-reset
  4515. */
  4516. set_bit(ISP_ABORT_NEEDED,
  4517. &base_vha->dpc_flags);
  4518. }
  4519. clear_bit(ABORT_ISP_ACTIVE,
  4520. &base_vha->dpc_flags);
  4521. }
  4522. ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
  4523. "FCoE context reset end.\n");
  4524. }
  4525. } else if (IS_QLAFX00(ha)) {
  4526. if (test_and_clear_bit(ISP_UNRECOVERABLE,
  4527. &base_vha->dpc_flags)) {
  4528. ql_dbg(ql_dbg_dpc, base_vha, 0x4020,
  4529. "Firmware Reset Recovery\n");
  4530. if (qlafx00_reset_initialize(base_vha)) {
  4531. /* Failed. Abort isp later. */
  4532. if (!test_bit(UNLOADING,
  4533. &base_vha->dpc_flags)) {
  4534. set_bit(ISP_UNRECOVERABLE,
  4535. &base_vha->dpc_flags);
  4536. ql_dbg(ql_dbg_dpc, base_vha,
  4537. 0x4021,
  4538. "Reset Recovery Failed\n");
  4539. }
  4540. }
  4541. }
  4542. if (test_and_clear_bit(FX00_TARGET_SCAN,
  4543. &base_vha->dpc_flags)) {
  4544. ql_dbg(ql_dbg_dpc, base_vha, 0x4022,
  4545. "ISPFx00 Target Scan scheduled\n");
  4546. if (qlafx00_rescan_isp(base_vha)) {
  4547. if (!test_bit(UNLOADING,
  4548. &base_vha->dpc_flags))
  4549. set_bit(ISP_UNRECOVERABLE,
  4550. &base_vha->dpc_flags);
  4551. ql_dbg(ql_dbg_dpc, base_vha, 0x401e,
  4552. "ISPFx00 Target Scan Failed\n");
  4553. }
  4554. ql_dbg(ql_dbg_dpc, base_vha, 0x401f,
  4555. "ISPFx00 Target Scan End\n");
  4556. }
  4557. if (test_and_clear_bit(FX00_HOST_INFO_RESEND,
  4558. &base_vha->dpc_flags)) {
  4559. ql_dbg(ql_dbg_dpc, base_vha, 0x4023,
  4560. "ISPFx00 Host Info resend scheduled\n");
  4561. qlafx00_fx_disc(base_vha,
  4562. &base_vha->hw->mr.fcport,
  4563. FXDISC_REG_HOST_INFO);
  4564. }
  4565. }
  4566. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  4567. &base_vha->dpc_flags)) {
  4568. ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
  4569. "ISP abort scheduled.\n");
  4570. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  4571. &base_vha->dpc_flags))) {
  4572. if (ha->isp_ops->abort_isp(base_vha)) {
  4573. /* failed. retry later */
  4574. set_bit(ISP_ABORT_NEEDED,
  4575. &base_vha->dpc_flags);
  4576. }
  4577. clear_bit(ABORT_ISP_ACTIVE,
  4578. &base_vha->dpc_flags);
  4579. }
  4580. ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
  4581. "ISP abort end.\n");
  4582. }
  4583. if (test_and_clear_bit(FCPORT_UPDATE_NEEDED,
  4584. &base_vha->dpc_flags)) {
  4585. qla2x00_update_fcports(base_vha);
  4586. }
  4587. if (test_bit(SCR_PENDING, &base_vha->dpc_flags)) {
  4588. int ret;
  4589. ret = qla2x00_send_change_request(base_vha, 0x3, 0);
  4590. if (ret != QLA_SUCCESS)
  4591. ql_log(ql_log_warn, base_vha, 0x121,
  4592. "Failed to enable receiving of RSCN "
  4593. "requests: 0x%x.\n", ret);
  4594. clear_bit(SCR_PENDING, &base_vha->dpc_flags);
  4595. }
  4596. if (IS_QLAFX00(ha))
  4597. goto loop_resync_check;
  4598. if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
  4599. ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
  4600. "Quiescence mode scheduled.\n");
  4601. if (IS_P3P_TYPE(ha)) {
  4602. if (IS_QLA82XX(ha))
  4603. qla82xx_device_state_handler(base_vha);
  4604. if (IS_QLA8044(ha))
  4605. qla8044_device_state_handler(base_vha);
  4606. clear_bit(ISP_QUIESCE_NEEDED,
  4607. &base_vha->dpc_flags);
  4608. if (!ha->flags.quiesce_owner) {
  4609. qla2x00_perform_loop_resync(base_vha);
  4610. if (IS_QLA82XX(ha)) {
  4611. qla82xx_idc_lock(ha);
  4612. qla82xx_clear_qsnt_ready(
  4613. base_vha);
  4614. qla82xx_idc_unlock(ha);
  4615. } else if (IS_QLA8044(ha)) {
  4616. qla8044_idc_lock(ha);
  4617. qla8044_clear_qsnt_ready(
  4618. base_vha);
  4619. qla8044_idc_unlock(ha);
  4620. }
  4621. }
  4622. } else {
  4623. clear_bit(ISP_QUIESCE_NEEDED,
  4624. &base_vha->dpc_flags);
  4625. qla2x00_quiesce_io(base_vha);
  4626. }
  4627. ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
  4628. "Quiescence mode end.\n");
  4629. }
  4630. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  4631. &base_vha->dpc_flags) &&
  4632. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  4633. ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
  4634. "Reset marker scheduled.\n");
  4635. qla2x00_rst_aen(base_vha);
  4636. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  4637. ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
  4638. "Reset marker end.\n");
  4639. }
  4640. /* Retry each device up to login retry count */
  4641. if ((test_and_clear_bit(RELOGIN_NEEDED,
  4642. &base_vha->dpc_flags)) &&
  4643. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  4644. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  4645. ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
  4646. "Relogin scheduled.\n");
  4647. qla2x00_relogin(base_vha);
  4648. ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
  4649. "Relogin end.\n");
  4650. }
  4651. loop_resync_check:
  4652. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  4653. &base_vha->dpc_flags)) {
  4654. ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
  4655. "Loop resync scheduled.\n");
  4656. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  4657. &base_vha->dpc_flags))) {
  4658. qla2x00_loop_resync(base_vha);
  4659. clear_bit(LOOP_RESYNC_ACTIVE,
  4660. &base_vha->dpc_flags);
  4661. }
  4662. ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
  4663. "Loop resync end.\n");
  4664. }
  4665. if (IS_QLAFX00(ha))
  4666. goto intr_on_check;
  4667. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  4668. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  4669. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  4670. qla2xxx_flash_npiv_conf(base_vha);
  4671. }
  4672. intr_on_check:
  4673. if (!ha->interrupts_on)
  4674. ha->isp_ops->enable_intrs(ha);
  4675. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  4676. &base_vha->dpc_flags)) {
  4677. if (ha->beacon_blink_led == 1)
  4678. ha->isp_ops->beacon_blink(base_vha);
  4679. }
  4680. if (!IS_QLAFX00(ha))
  4681. qla2x00_do_dpc_all_vps(base_vha);
  4682. ha->dpc_active = 0;
  4683. end_loop:
  4684. set_current_state(TASK_INTERRUPTIBLE);
  4685. } /* End of while(1) */
  4686. __set_current_state(TASK_RUNNING);
  4687. ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
  4688. "DPC handler exiting.\n");
  4689. /*
  4690. * Make sure that nobody tries to wake us up again.
  4691. */
  4692. ha->dpc_active = 0;
  4693. /* Cleanup any residual CTX SRBs. */
  4694. qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
  4695. return 0;
  4696. }
  4697. void
  4698. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  4699. {
  4700. struct qla_hw_data *ha = vha->hw;
  4701. struct task_struct *t = ha->dpc_thread;
  4702. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  4703. wake_up_process(t);
  4704. }
  4705. /*
  4706. * qla2x00_rst_aen
  4707. * Processes asynchronous reset.
  4708. *
  4709. * Input:
  4710. * ha = adapter block pointer.
  4711. */
  4712. static void
  4713. qla2x00_rst_aen(scsi_qla_host_t *vha)
  4714. {
  4715. if (vha->flags.online && !vha->flags.reset_active &&
  4716. !atomic_read(&vha->loop_down_timer) &&
  4717. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  4718. do {
  4719. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4720. /*
  4721. * Issue marker command only when we are going to start
  4722. * the I/O.
  4723. */
  4724. vha->marker_needed = 1;
  4725. } while (!atomic_read(&vha->loop_down_timer) &&
  4726. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  4727. }
  4728. }
  4729. /**************************************************************************
  4730. * qla2x00_timer
  4731. *
  4732. * Description:
  4733. * One second timer
  4734. *
  4735. * Context: Interrupt
  4736. ***************************************************************************/
  4737. void
  4738. qla2x00_timer(scsi_qla_host_t *vha)
  4739. {
  4740. unsigned long cpu_flags = 0;
  4741. int start_dpc = 0;
  4742. int index;
  4743. srb_t *sp;
  4744. uint16_t w;
  4745. struct qla_hw_data *ha = vha->hw;
  4746. struct req_que *req;
  4747. if (ha->flags.eeh_busy) {
  4748. ql_dbg(ql_dbg_timer, vha, 0x6000,
  4749. "EEH = %d, restarting timer.\n",
  4750. ha->flags.eeh_busy);
  4751. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4752. return;
  4753. }
  4754. /*
  4755. * Hardware read to raise pending EEH errors during mailbox waits. If
  4756. * the read returns -1 then disable the board.
  4757. */
  4758. if (!pci_channel_offline(ha->pdev)) {
  4759. pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
  4760. qla2x00_check_reg16_for_disconnect(vha, w);
  4761. }
  4762. /* Make sure qla82xx_watchdog is run only for physical port */
  4763. if (!vha->vp_idx && IS_P3P_TYPE(ha)) {
  4764. if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
  4765. start_dpc++;
  4766. if (IS_QLA82XX(ha))
  4767. qla82xx_watchdog(vha);
  4768. else if (IS_QLA8044(ha))
  4769. qla8044_watchdog(vha);
  4770. }
  4771. if (!vha->vp_idx && IS_QLAFX00(ha))
  4772. qlafx00_timer_routine(vha);
  4773. /* Loop down handler. */
  4774. if (atomic_read(&vha->loop_down_timer) > 0 &&
  4775. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
  4776. !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
  4777. && vha->flags.online) {
  4778. if (atomic_read(&vha->loop_down_timer) ==
  4779. vha->loop_down_abort_time) {
  4780. ql_log(ql_log_info, vha, 0x6008,
  4781. "Loop down - aborting the queues before time expires.\n");
  4782. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  4783. atomic_set(&vha->loop_state, LOOP_DEAD);
  4784. /*
  4785. * Schedule an ISP abort to return any FCP2-device
  4786. * commands.
  4787. */
  4788. /* NPIV - scan physical port only */
  4789. if (!vha->vp_idx) {
  4790. spin_lock_irqsave(&ha->hardware_lock,
  4791. cpu_flags);
  4792. req = ha->req_q_map[0];
  4793. for (index = 1;
  4794. index < req->num_outstanding_cmds;
  4795. index++) {
  4796. fc_port_t *sfcp;
  4797. sp = req->outstanding_cmds[index];
  4798. if (!sp)
  4799. continue;
  4800. if (sp->type != SRB_SCSI_CMD)
  4801. continue;
  4802. sfcp = sp->fcport;
  4803. if (!(sfcp->flags & FCF_FCP2_DEVICE))
  4804. continue;
  4805. if (IS_QLA82XX(ha))
  4806. set_bit(FCOE_CTX_RESET_NEEDED,
  4807. &vha->dpc_flags);
  4808. else
  4809. set_bit(ISP_ABORT_NEEDED,
  4810. &vha->dpc_flags);
  4811. break;
  4812. }
  4813. spin_unlock_irqrestore(&ha->hardware_lock,
  4814. cpu_flags);
  4815. }
  4816. start_dpc++;
  4817. }
  4818. /* if the loop has been down for 4 minutes, reinit adapter */
  4819. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  4820. if (!(vha->device_flags & DFLG_NO_CABLE)) {
  4821. ql_log(ql_log_warn, vha, 0x6009,
  4822. "Loop down - aborting ISP.\n");
  4823. if (IS_QLA82XX(ha))
  4824. set_bit(FCOE_CTX_RESET_NEEDED,
  4825. &vha->dpc_flags);
  4826. else
  4827. set_bit(ISP_ABORT_NEEDED,
  4828. &vha->dpc_flags);
  4829. }
  4830. }
  4831. ql_dbg(ql_dbg_timer, vha, 0x600a,
  4832. "Loop down - seconds remaining %d.\n",
  4833. atomic_read(&vha->loop_down_timer));
  4834. }
  4835. /* Check if beacon LED needs to be blinked for physical host only */
  4836. if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
  4837. /* There is no beacon_blink function for ISP82xx */
  4838. if (!IS_P3P_TYPE(ha)) {
  4839. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  4840. start_dpc++;
  4841. }
  4842. }
  4843. /* Process any deferred work. */
  4844. if (!list_empty(&vha->work_list))
  4845. start_dpc++;
  4846. /* Schedule the DPC routine if needed */
  4847. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  4848. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  4849. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  4850. start_dpc ||
  4851. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  4852. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  4853. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
  4854. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
  4855. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  4856. test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
  4857. ql_dbg(ql_dbg_timer, vha, 0x600b,
  4858. "isp_abort_needed=%d loop_resync_needed=%d "
  4859. "fcport_update_needed=%d start_dpc=%d "
  4860. "reset_marker_needed=%d",
  4861. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
  4862. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
  4863. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
  4864. start_dpc,
  4865. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
  4866. ql_dbg(ql_dbg_timer, vha, 0x600c,
  4867. "beacon_blink_needed=%d isp_unrecoverable=%d "
  4868. "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
  4869. "relogin_needed=%d.\n",
  4870. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
  4871. test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
  4872. test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
  4873. test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
  4874. test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
  4875. qla2xxx_wake_dpc(vha);
  4876. }
  4877. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  4878. }
  4879. /* Firmware interface routines. */
  4880. #define FW_BLOBS 11
  4881. #define FW_ISP21XX 0
  4882. #define FW_ISP22XX 1
  4883. #define FW_ISP2300 2
  4884. #define FW_ISP2322 3
  4885. #define FW_ISP24XX 4
  4886. #define FW_ISP25XX 5
  4887. #define FW_ISP81XX 6
  4888. #define FW_ISP82XX 7
  4889. #define FW_ISP2031 8
  4890. #define FW_ISP8031 9
  4891. #define FW_ISP27XX 10
  4892. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  4893. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  4894. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  4895. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  4896. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  4897. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  4898. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  4899. #define FW_FILE_ISP82XX "ql8200_fw.bin"
  4900. #define FW_FILE_ISP2031 "ql2600_fw.bin"
  4901. #define FW_FILE_ISP8031 "ql8300_fw.bin"
  4902. #define FW_FILE_ISP27XX "ql2700_fw.bin"
  4903. static DEFINE_MUTEX(qla_fw_lock);
  4904. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  4905. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  4906. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  4907. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  4908. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  4909. { .name = FW_FILE_ISP24XX, },
  4910. { .name = FW_FILE_ISP25XX, },
  4911. { .name = FW_FILE_ISP81XX, },
  4912. { .name = FW_FILE_ISP82XX, },
  4913. { .name = FW_FILE_ISP2031, },
  4914. { .name = FW_FILE_ISP8031, },
  4915. { .name = FW_FILE_ISP27XX, },
  4916. };
  4917. struct fw_blob *
  4918. qla2x00_request_firmware(scsi_qla_host_t *vha)
  4919. {
  4920. struct qla_hw_data *ha = vha->hw;
  4921. struct fw_blob *blob;
  4922. if (IS_QLA2100(ha)) {
  4923. blob = &qla_fw_blobs[FW_ISP21XX];
  4924. } else if (IS_QLA2200(ha)) {
  4925. blob = &qla_fw_blobs[FW_ISP22XX];
  4926. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  4927. blob = &qla_fw_blobs[FW_ISP2300];
  4928. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  4929. blob = &qla_fw_blobs[FW_ISP2322];
  4930. } else if (IS_QLA24XX_TYPE(ha)) {
  4931. blob = &qla_fw_blobs[FW_ISP24XX];
  4932. } else if (IS_QLA25XX(ha)) {
  4933. blob = &qla_fw_blobs[FW_ISP25XX];
  4934. } else if (IS_QLA81XX(ha)) {
  4935. blob = &qla_fw_blobs[FW_ISP81XX];
  4936. } else if (IS_QLA82XX(ha)) {
  4937. blob = &qla_fw_blobs[FW_ISP82XX];
  4938. } else if (IS_QLA2031(ha)) {
  4939. blob = &qla_fw_blobs[FW_ISP2031];
  4940. } else if (IS_QLA8031(ha)) {
  4941. blob = &qla_fw_blobs[FW_ISP8031];
  4942. } else if (IS_QLA27XX(ha)) {
  4943. blob = &qla_fw_blobs[FW_ISP27XX];
  4944. } else {
  4945. return NULL;
  4946. }
  4947. mutex_lock(&qla_fw_lock);
  4948. if (blob->fw)
  4949. goto out;
  4950. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  4951. ql_log(ql_log_warn, vha, 0x0063,
  4952. "Failed to load firmware image (%s).\n", blob->name);
  4953. blob->fw = NULL;
  4954. blob = NULL;
  4955. goto out;
  4956. }
  4957. out:
  4958. mutex_unlock(&qla_fw_lock);
  4959. return blob;
  4960. }
  4961. static void
  4962. qla2x00_release_firmware(void)
  4963. {
  4964. int idx;
  4965. mutex_lock(&qla_fw_lock);
  4966. for (idx = 0; idx < FW_BLOBS; idx++)
  4967. release_firmware(qla_fw_blobs[idx].fw);
  4968. mutex_unlock(&qla_fw_lock);
  4969. }
  4970. static pci_ers_result_t
  4971. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  4972. {
  4973. scsi_qla_host_t *vha = pci_get_drvdata(pdev);
  4974. struct qla_hw_data *ha = vha->hw;
  4975. ql_dbg(ql_dbg_aer, vha, 0x9000,
  4976. "PCI error detected, state %x.\n", state);
  4977. switch (state) {
  4978. case pci_channel_io_normal:
  4979. ha->flags.eeh_busy = 0;
  4980. return PCI_ERS_RESULT_CAN_RECOVER;
  4981. case pci_channel_io_frozen:
  4982. ha->flags.eeh_busy = 1;
  4983. /* For ISP82XX complete any pending mailbox cmd */
  4984. if (IS_QLA82XX(ha)) {
  4985. ha->flags.isp82xx_fw_hung = 1;
  4986. ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
  4987. qla82xx_clear_pending_mbx(vha);
  4988. }
  4989. qla2x00_free_irqs(vha);
  4990. pci_disable_device(pdev);
  4991. /* Return back all IOs */
  4992. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  4993. return PCI_ERS_RESULT_NEED_RESET;
  4994. case pci_channel_io_perm_failure:
  4995. ha->flags.pci_channel_io_perm_failure = 1;
  4996. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  4997. return PCI_ERS_RESULT_DISCONNECT;
  4998. }
  4999. return PCI_ERS_RESULT_NEED_RESET;
  5000. }
  5001. static pci_ers_result_t
  5002. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  5003. {
  5004. int risc_paused = 0;
  5005. uint32_t stat;
  5006. unsigned long flags;
  5007. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5008. struct qla_hw_data *ha = base_vha->hw;
  5009. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  5010. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  5011. if (IS_QLA82XX(ha))
  5012. return PCI_ERS_RESULT_RECOVERED;
  5013. spin_lock_irqsave(&ha->hardware_lock, flags);
  5014. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  5015. stat = RD_REG_DWORD(&reg->hccr);
  5016. if (stat & HCCR_RISC_PAUSE)
  5017. risc_paused = 1;
  5018. } else if (IS_QLA23XX(ha)) {
  5019. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  5020. if (stat & HSR_RISC_PAUSED)
  5021. risc_paused = 1;
  5022. } else if (IS_FWI2_CAPABLE(ha)) {
  5023. stat = RD_REG_DWORD(&reg24->host_status);
  5024. if (stat & HSRX_RISC_PAUSED)
  5025. risc_paused = 1;
  5026. }
  5027. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  5028. if (risc_paused) {
  5029. ql_log(ql_log_info, base_vha, 0x9003,
  5030. "RISC paused -- mmio_enabled, Dumping firmware.\n");
  5031. ha->isp_ops->fw_dump(base_vha, 0);
  5032. return PCI_ERS_RESULT_NEED_RESET;
  5033. } else
  5034. return PCI_ERS_RESULT_RECOVERED;
  5035. }
  5036. static uint32_t
  5037. qla82xx_error_recovery(scsi_qla_host_t *base_vha)
  5038. {
  5039. uint32_t rval = QLA_FUNCTION_FAILED;
  5040. uint32_t drv_active = 0;
  5041. struct qla_hw_data *ha = base_vha->hw;
  5042. int fn;
  5043. struct pci_dev *other_pdev = NULL;
  5044. ql_dbg(ql_dbg_aer, base_vha, 0x9006,
  5045. "Entered %s.\n", __func__);
  5046. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5047. if (base_vha->flags.online) {
  5048. /* Abort all outstanding commands,
  5049. * so as to be requeued later */
  5050. qla2x00_abort_isp_cleanup(base_vha);
  5051. }
  5052. fn = PCI_FUNC(ha->pdev->devfn);
  5053. while (fn > 0) {
  5054. fn--;
  5055. ql_dbg(ql_dbg_aer, base_vha, 0x9007,
  5056. "Finding pci device at function = 0x%x.\n", fn);
  5057. other_pdev =
  5058. pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
  5059. ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
  5060. fn));
  5061. if (!other_pdev)
  5062. continue;
  5063. if (atomic_read(&other_pdev->enable_cnt)) {
  5064. ql_dbg(ql_dbg_aer, base_vha, 0x9008,
  5065. "Found PCI func available and enable at 0x%x.\n",
  5066. fn);
  5067. pci_dev_put(other_pdev);
  5068. break;
  5069. }
  5070. pci_dev_put(other_pdev);
  5071. }
  5072. if (!fn) {
  5073. /* Reset owner */
  5074. ql_dbg(ql_dbg_aer, base_vha, 0x9009,
  5075. "This devfn is reset owner = 0x%x.\n",
  5076. ha->pdev->devfn);
  5077. qla82xx_idc_lock(ha);
  5078. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5079. QLA8XXX_DEV_INITIALIZING);
  5080. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
  5081. QLA82XX_IDC_VERSION);
  5082. drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
  5083. ql_dbg(ql_dbg_aer, base_vha, 0x900a,
  5084. "drv_active = 0x%x.\n", drv_active);
  5085. qla82xx_idc_unlock(ha);
  5086. /* Reset if device is not already reset
  5087. * drv_active would be 0 if a reset has already been done
  5088. */
  5089. if (drv_active)
  5090. rval = qla82xx_start_firmware(base_vha);
  5091. else
  5092. rval = QLA_SUCCESS;
  5093. qla82xx_idc_lock(ha);
  5094. if (rval != QLA_SUCCESS) {
  5095. ql_log(ql_log_info, base_vha, 0x900b,
  5096. "HW State: FAILED.\n");
  5097. qla82xx_clear_drv_active(ha);
  5098. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5099. QLA8XXX_DEV_FAILED);
  5100. } else {
  5101. ql_log(ql_log_info, base_vha, 0x900c,
  5102. "HW State: READY.\n");
  5103. qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
  5104. QLA8XXX_DEV_READY);
  5105. qla82xx_idc_unlock(ha);
  5106. ha->flags.isp82xx_fw_hung = 0;
  5107. rval = qla82xx_restart_isp(base_vha);
  5108. qla82xx_idc_lock(ha);
  5109. /* Clear driver state register */
  5110. qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
  5111. qla82xx_set_drv_active(base_vha);
  5112. }
  5113. qla82xx_idc_unlock(ha);
  5114. } else {
  5115. ql_dbg(ql_dbg_aer, base_vha, 0x900d,
  5116. "This devfn is not reset owner = 0x%x.\n",
  5117. ha->pdev->devfn);
  5118. if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
  5119. QLA8XXX_DEV_READY)) {
  5120. ha->flags.isp82xx_fw_hung = 0;
  5121. rval = qla82xx_restart_isp(base_vha);
  5122. qla82xx_idc_lock(ha);
  5123. qla82xx_set_drv_active(base_vha);
  5124. qla82xx_idc_unlock(ha);
  5125. }
  5126. }
  5127. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5128. return rval;
  5129. }
  5130. static pci_ers_result_t
  5131. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  5132. {
  5133. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  5134. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5135. struct qla_hw_data *ha = base_vha->hw;
  5136. struct rsp_que *rsp;
  5137. int rc, retries = 10;
  5138. ql_dbg(ql_dbg_aer, base_vha, 0x9004,
  5139. "Slot Reset.\n");
  5140. /* Workaround: qla2xxx driver which access hardware earlier
  5141. * needs error state to be pci_channel_io_online.
  5142. * Otherwise mailbox command timesout.
  5143. */
  5144. pdev->error_state = pci_channel_io_normal;
  5145. pci_restore_state(pdev);
  5146. /* pci_restore_state() clears the saved_state flag of the device
  5147. * save restored state which resets saved_state flag
  5148. */
  5149. pci_save_state(pdev);
  5150. if (ha->mem_only)
  5151. rc = pci_enable_device_mem(pdev);
  5152. else
  5153. rc = pci_enable_device(pdev);
  5154. if (rc) {
  5155. ql_log(ql_log_warn, base_vha, 0x9005,
  5156. "Can't re-enable PCI device after reset.\n");
  5157. goto exit_slot_reset;
  5158. }
  5159. rsp = ha->rsp_q_map[0];
  5160. if (qla2x00_request_irqs(ha, rsp))
  5161. goto exit_slot_reset;
  5162. if (ha->isp_ops->pci_config(base_vha))
  5163. goto exit_slot_reset;
  5164. if (IS_QLA82XX(ha)) {
  5165. if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
  5166. ret = PCI_ERS_RESULT_RECOVERED;
  5167. goto exit_slot_reset;
  5168. } else
  5169. goto exit_slot_reset;
  5170. }
  5171. while (ha->flags.mbox_busy && retries--)
  5172. msleep(1000);
  5173. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5174. if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
  5175. ret = PCI_ERS_RESULT_RECOVERED;
  5176. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  5177. exit_slot_reset:
  5178. ql_dbg(ql_dbg_aer, base_vha, 0x900e,
  5179. "slot_reset return %x.\n", ret);
  5180. return ret;
  5181. }
  5182. static void
  5183. qla2xxx_pci_resume(struct pci_dev *pdev)
  5184. {
  5185. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  5186. struct qla_hw_data *ha = base_vha->hw;
  5187. int ret;
  5188. ql_dbg(ql_dbg_aer, base_vha, 0x900f,
  5189. "pci_resume.\n");
  5190. ret = qla2x00_wait_for_hba_online(base_vha);
  5191. if (ret != QLA_SUCCESS) {
  5192. ql_log(ql_log_fatal, base_vha, 0x9002,
  5193. "The device failed to resume I/O from slot/link_reset.\n");
  5194. }
  5195. pci_cleanup_aer_uncorrect_error_status(pdev);
  5196. ha->flags.eeh_busy = 0;
  5197. }
  5198. static void
  5199. qla83xx_disable_laser(scsi_qla_host_t *vha)
  5200. {
  5201. uint32_t reg, data, fn;
  5202. struct qla_hw_data *ha = vha->hw;
  5203. struct device_reg_24xx __iomem *isp_reg = &ha->iobase->isp24;
  5204. /* pci func #/port # */
  5205. ql_dbg(ql_dbg_init, vha, 0x004b,
  5206. "Disabling Laser for hba: %p\n", vha);
  5207. fn = (RD_REG_DWORD(&isp_reg->ctrl_status) &
  5208. (BIT_15|BIT_14|BIT_13|BIT_12));
  5209. fn = (fn >> 12);
  5210. if (fn & 1)
  5211. reg = PORT_1_2031;
  5212. else
  5213. reg = PORT_0_2031;
  5214. data = LASER_OFF_2031;
  5215. qla83xx_wr_reg(vha, reg, data);
  5216. }
  5217. static const struct pci_error_handlers qla2xxx_err_handler = {
  5218. .error_detected = qla2xxx_pci_error_detected,
  5219. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  5220. .slot_reset = qla2xxx_pci_slot_reset,
  5221. .resume = qla2xxx_pci_resume,
  5222. };
  5223. static struct pci_device_id qla2xxx_pci_tbl[] = {
  5224. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  5225. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  5226. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  5227. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  5228. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  5229. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  5230. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  5231. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  5232. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  5233. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  5234. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  5235. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  5236. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  5237. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
  5238. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  5239. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
  5240. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8031) },
  5241. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISPF001) },
  5242. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8044) },
  5243. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2071) },
  5244. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2271) },
  5245. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2261) },
  5246. { 0 },
  5247. };
  5248. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  5249. static struct pci_driver qla2xxx_pci_driver = {
  5250. .name = QLA2XXX_DRIVER_NAME,
  5251. .driver = {
  5252. .owner = THIS_MODULE,
  5253. },
  5254. .id_table = qla2xxx_pci_tbl,
  5255. .probe = qla2x00_probe_one,
  5256. .remove = qla2x00_remove_one,
  5257. .shutdown = qla2x00_shutdown,
  5258. .err_handler = &qla2xxx_err_handler,
  5259. };
  5260. static const struct file_operations apidev_fops = {
  5261. .owner = THIS_MODULE,
  5262. .llseek = noop_llseek,
  5263. };
  5264. /**
  5265. * qla2x00_module_init - Module initialization.
  5266. **/
  5267. static int __init
  5268. qla2x00_module_init(void)
  5269. {
  5270. int ret = 0;
  5271. /* Allocate cache for SRBs. */
  5272. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  5273. SLAB_HWCACHE_ALIGN, NULL);
  5274. if (srb_cachep == NULL) {
  5275. ql_log(ql_log_fatal, NULL, 0x0001,
  5276. "Unable to allocate SRB cache...Failing load!.\n");
  5277. return -ENOMEM;
  5278. }
  5279. /* Initialize target kmem_cache and mem_pools */
  5280. ret = qlt_init();
  5281. if (ret < 0) {
  5282. kmem_cache_destroy(srb_cachep);
  5283. return ret;
  5284. } else if (ret > 0) {
  5285. /*
  5286. * If initiator mode is explictly disabled by qlt_init(),
  5287. * prevent scsi_transport_fc.c:fc_scsi_scan_rport() from
  5288. * performing scsi_scan_target() during LOOP UP event.
  5289. */
  5290. qla2xxx_transport_functions.disable_target_scan = 1;
  5291. qla2xxx_transport_vport_functions.disable_target_scan = 1;
  5292. }
  5293. /* Derive version string. */
  5294. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  5295. if (ql2xextended_error_logging)
  5296. strcat(qla2x00_version_str, "-debug");
  5297. qla2xxx_transport_template =
  5298. fc_attach_transport(&qla2xxx_transport_functions);
  5299. if (!qla2xxx_transport_template) {
  5300. kmem_cache_destroy(srb_cachep);
  5301. ql_log(ql_log_fatal, NULL, 0x0002,
  5302. "fc_attach_transport failed...Failing load!.\n");
  5303. qlt_exit();
  5304. return -ENODEV;
  5305. }
  5306. apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
  5307. if (apidev_major < 0) {
  5308. ql_log(ql_log_fatal, NULL, 0x0003,
  5309. "Unable to register char device %s.\n", QLA2XXX_APIDEV);
  5310. }
  5311. qla2xxx_transport_vport_template =
  5312. fc_attach_transport(&qla2xxx_transport_vport_functions);
  5313. if (!qla2xxx_transport_vport_template) {
  5314. kmem_cache_destroy(srb_cachep);
  5315. qlt_exit();
  5316. fc_release_transport(qla2xxx_transport_template);
  5317. ql_log(ql_log_fatal, NULL, 0x0004,
  5318. "fc_attach_transport vport failed...Failing load!.\n");
  5319. return -ENODEV;
  5320. }
  5321. ql_log(ql_log_info, NULL, 0x0005,
  5322. "QLogic Fibre Channel HBA Driver: %s.\n",
  5323. qla2x00_version_str);
  5324. ret = pci_register_driver(&qla2xxx_pci_driver);
  5325. if (ret) {
  5326. kmem_cache_destroy(srb_cachep);
  5327. qlt_exit();
  5328. fc_release_transport(qla2xxx_transport_template);
  5329. fc_release_transport(qla2xxx_transport_vport_template);
  5330. ql_log(ql_log_fatal, NULL, 0x0006,
  5331. "pci_register_driver failed...ret=%d Failing load!.\n",
  5332. ret);
  5333. }
  5334. return ret;
  5335. }
  5336. /**
  5337. * qla2x00_module_exit - Module cleanup.
  5338. **/
  5339. static void __exit
  5340. qla2x00_module_exit(void)
  5341. {
  5342. unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
  5343. pci_unregister_driver(&qla2xxx_pci_driver);
  5344. qla2x00_release_firmware();
  5345. kmem_cache_destroy(srb_cachep);
  5346. qlt_exit();
  5347. if (ctx_cachep)
  5348. kmem_cache_destroy(ctx_cachep);
  5349. fc_release_transport(qla2xxx_transport_template);
  5350. fc_release_transport(qla2xxx_transport_vport_template);
  5351. }
  5352. module_init(qla2x00_module_init);
  5353. module_exit(qla2x00_module_exit);
  5354. MODULE_AUTHOR("QLogic Corporation");
  5355. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  5356. MODULE_LICENSE("GPL");
  5357. MODULE_VERSION(QLA2XXX_VERSION);
  5358. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  5359. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  5360. MODULE_FIRMWARE(FW_FILE_ISP2300);
  5361. MODULE_FIRMWARE(FW_FILE_ISP2322);
  5362. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  5363. MODULE_FIRMWARE(FW_FILE_ISP25XX);