qla_init.c 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_gbl.h"
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/vmalloc.h>
  12. #include "qla_devtbl.h"
  13. #ifdef CONFIG_SPARC
  14. #include <asm/prom.h>
  15. #endif
  16. #include <target/target_core_base.h>
  17. #include "qla_target.h"
  18. /*
  19. * QLogic ISP2x00 Hardware Support Function Prototypes.
  20. */
  21. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  22. static int qla2x00_setup_chip(scsi_qla_host_t *);
  23. static int qla2x00_fw_ready(scsi_qla_host_t *);
  24. static int qla2x00_configure_hba(scsi_qla_host_t *);
  25. static int qla2x00_configure_loop(scsi_qla_host_t *);
  26. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  27. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  28. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  29. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  30. uint16_t *);
  31. static int qla2x00_restart_isp(scsi_qla_host_t *);
  32. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  33. static int qla84xx_init_chip(scsi_qla_host_t *);
  34. static int qla25xx_init_queues(struct qla_hw_data *);
  35. /* SRB Extensions ---------------------------------------------------------- */
  36. void
  37. qla2x00_sp_timeout(unsigned long __data)
  38. {
  39. srb_t *sp = (srb_t *)__data;
  40. struct srb_iocb *iocb;
  41. fc_port_t *fcport = sp->fcport;
  42. struct qla_hw_data *ha = fcport->vha->hw;
  43. struct req_que *req;
  44. unsigned long flags;
  45. spin_lock_irqsave(&ha->hardware_lock, flags);
  46. req = ha->req_q_map[0];
  47. req->outstanding_cmds[sp->handle] = NULL;
  48. iocb = &sp->u.iocb_cmd;
  49. iocb->timeout(sp);
  50. sp->free(fcport->vha, sp);
  51. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  52. }
  53. void
  54. qla2x00_sp_free(void *data, void *ptr)
  55. {
  56. srb_t *sp = (srb_t *)ptr;
  57. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  58. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  59. del_timer(&iocb->timer);
  60. qla2x00_rel_sp(vha, sp);
  61. }
  62. /* Asynchronous Login/Logout Routines -------------------------------------- */
  63. unsigned long
  64. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  65. {
  66. unsigned long tmo;
  67. struct qla_hw_data *ha = vha->hw;
  68. /* Firmware should use switch negotiated r_a_tov for timeout. */
  69. tmo = ha->r_a_tov / 10 * 2;
  70. if (IS_QLAFX00(ha)) {
  71. tmo = FX00_DEF_RATOV * 2;
  72. } else if (!IS_FWI2_CAPABLE(ha)) {
  73. /*
  74. * Except for earlier ISPs where the timeout is seeded from the
  75. * initialization control block.
  76. */
  77. tmo = ha->login_timeout;
  78. }
  79. return tmo;
  80. }
  81. static void
  82. qla2x00_async_iocb_timeout(void *data)
  83. {
  84. srb_t *sp = (srb_t *)data;
  85. fc_port_t *fcport = sp->fcport;
  86. ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
  87. "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
  88. sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
  89. fcport->d_id.b.al_pa);
  90. fcport->flags &= ~FCF_ASYNC_SENT;
  91. if (sp->type == SRB_LOGIN_CMD) {
  92. struct srb_iocb *lio = &sp->u.iocb_cmd;
  93. qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
  94. /* Retry as needed. */
  95. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  96. lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  97. QLA_LOGIO_LOGIN_RETRIED : 0;
  98. qla2x00_post_async_login_done_work(fcport->vha, fcport,
  99. lio->u.logio.data);
  100. }
  101. }
  102. static void
  103. qla2x00_async_login_sp_done(void *data, void *ptr, int res)
  104. {
  105. srb_t *sp = (srb_t *)ptr;
  106. struct srb_iocb *lio = &sp->u.iocb_cmd;
  107. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  108. if (!test_bit(UNLOADING, &vha->dpc_flags))
  109. qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
  110. lio->u.logio.data);
  111. sp->free(sp->fcport->vha, sp);
  112. }
  113. int
  114. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  115. uint16_t *data)
  116. {
  117. srb_t *sp;
  118. struct srb_iocb *lio;
  119. int rval;
  120. rval = QLA_FUNCTION_FAILED;
  121. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  122. if (!sp)
  123. goto done;
  124. sp->type = SRB_LOGIN_CMD;
  125. sp->name = "login";
  126. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  127. lio = &sp->u.iocb_cmd;
  128. lio->timeout = qla2x00_async_iocb_timeout;
  129. sp->done = qla2x00_async_login_sp_done;
  130. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  131. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  132. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  133. rval = qla2x00_start_sp(sp);
  134. if (rval != QLA_SUCCESS)
  135. goto done_free_sp;
  136. ql_dbg(ql_dbg_disc, vha, 0x2072,
  137. "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
  138. "retries=%d.\n", sp->handle, fcport->loop_id,
  139. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
  140. fcport->login_retry);
  141. return rval;
  142. done_free_sp:
  143. sp->free(fcport->vha, sp);
  144. done:
  145. return rval;
  146. }
  147. static void
  148. qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
  149. {
  150. srb_t *sp = (srb_t *)ptr;
  151. struct srb_iocb *lio = &sp->u.iocb_cmd;
  152. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  153. if (!test_bit(UNLOADING, &vha->dpc_flags))
  154. qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
  155. lio->u.logio.data);
  156. sp->free(sp->fcport->vha, sp);
  157. }
  158. int
  159. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  160. {
  161. srb_t *sp;
  162. struct srb_iocb *lio;
  163. int rval;
  164. rval = QLA_FUNCTION_FAILED;
  165. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  166. if (!sp)
  167. goto done;
  168. sp->type = SRB_LOGOUT_CMD;
  169. sp->name = "logout";
  170. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  171. lio = &sp->u.iocb_cmd;
  172. lio->timeout = qla2x00_async_iocb_timeout;
  173. sp->done = qla2x00_async_logout_sp_done;
  174. rval = qla2x00_start_sp(sp);
  175. if (rval != QLA_SUCCESS)
  176. goto done_free_sp;
  177. ql_dbg(ql_dbg_disc, vha, 0x2070,
  178. "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  179. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  180. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  181. return rval;
  182. done_free_sp:
  183. sp->free(fcport->vha, sp);
  184. done:
  185. return rval;
  186. }
  187. static void
  188. qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
  189. {
  190. srb_t *sp = (srb_t *)ptr;
  191. struct srb_iocb *lio = &sp->u.iocb_cmd;
  192. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  193. if (!test_bit(UNLOADING, &vha->dpc_flags))
  194. qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
  195. lio->u.logio.data);
  196. sp->free(sp->fcport->vha, sp);
  197. }
  198. int
  199. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  200. uint16_t *data)
  201. {
  202. srb_t *sp;
  203. struct srb_iocb *lio;
  204. int rval;
  205. rval = QLA_FUNCTION_FAILED;
  206. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  207. if (!sp)
  208. goto done;
  209. sp->type = SRB_ADISC_CMD;
  210. sp->name = "adisc";
  211. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  212. lio = &sp->u.iocb_cmd;
  213. lio->timeout = qla2x00_async_iocb_timeout;
  214. sp->done = qla2x00_async_adisc_sp_done;
  215. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  216. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  217. rval = qla2x00_start_sp(sp);
  218. if (rval != QLA_SUCCESS)
  219. goto done_free_sp;
  220. ql_dbg(ql_dbg_disc, vha, 0x206f,
  221. "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
  222. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  223. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  224. return rval;
  225. done_free_sp:
  226. sp->free(fcport->vha, sp);
  227. done:
  228. return rval;
  229. }
  230. static void
  231. qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
  232. {
  233. srb_t *sp = (srb_t *)ptr;
  234. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  235. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  236. uint32_t flags;
  237. uint16_t lun;
  238. int rval;
  239. if (!test_bit(UNLOADING, &vha->dpc_flags)) {
  240. flags = iocb->u.tmf.flags;
  241. lun = (uint16_t)iocb->u.tmf.lun;
  242. /* Issue Marker IOCB */
  243. rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
  244. vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
  245. flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
  246. if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
  247. ql_dbg(ql_dbg_taskm, vha, 0x8030,
  248. "TM IOCB failed (%x).\n", rval);
  249. }
  250. }
  251. sp->free(sp->fcport->vha, sp);
  252. }
  253. int
  254. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
  255. uint32_t tag)
  256. {
  257. struct scsi_qla_host *vha = fcport->vha;
  258. srb_t *sp;
  259. struct srb_iocb *tcf;
  260. int rval;
  261. rval = QLA_FUNCTION_FAILED;
  262. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  263. if (!sp)
  264. goto done;
  265. sp->type = SRB_TM_CMD;
  266. sp->name = "tmf";
  267. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  268. tcf = &sp->u.iocb_cmd;
  269. tcf->u.tmf.flags = tm_flags;
  270. tcf->u.tmf.lun = lun;
  271. tcf->u.tmf.data = tag;
  272. tcf->timeout = qla2x00_async_iocb_timeout;
  273. sp->done = qla2x00_async_tm_cmd_done;
  274. rval = qla2x00_start_sp(sp);
  275. if (rval != QLA_SUCCESS)
  276. goto done_free_sp;
  277. ql_dbg(ql_dbg_taskm, vha, 0x802f,
  278. "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  279. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  280. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  281. return rval;
  282. done_free_sp:
  283. sp->free(fcport->vha, sp);
  284. done:
  285. return rval;
  286. }
  287. void
  288. qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  289. uint16_t *data)
  290. {
  291. int rval;
  292. switch (data[0]) {
  293. case MBS_COMMAND_COMPLETE:
  294. /*
  295. * Driver must validate login state - If PRLI not complete,
  296. * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
  297. * requests.
  298. */
  299. rval = qla2x00_get_port_database(vha, fcport, 0);
  300. if (rval == QLA_NOT_LOGGED_IN) {
  301. fcport->flags &= ~FCF_ASYNC_SENT;
  302. fcport->flags |= FCF_LOGIN_NEEDED;
  303. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  304. break;
  305. }
  306. if (rval != QLA_SUCCESS) {
  307. qla2x00_post_async_logout_work(vha, fcport, NULL);
  308. qla2x00_post_async_login_work(vha, fcport, NULL);
  309. break;
  310. }
  311. if (fcport->flags & FCF_FCP2_DEVICE) {
  312. qla2x00_post_async_adisc_work(vha, fcport, data);
  313. break;
  314. }
  315. qla2x00_update_fcport(vha, fcport);
  316. break;
  317. case MBS_COMMAND_ERROR:
  318. fcport->flags &= ~FCF_ASYNC_SENT;
  319. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  320. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  321. else
  322. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  323. break;
  324. case MBS_PORT_ID_USED:
  325. fcport->loop_id = data[1];
  326. qla2x00_post_async_logout_work(vha, fcport, NULL);
  327. qla2x00_post_async_login_work(vha, fcport, NULL);
  328. break;
  329. case MBS_LOOP_ID_USED:
  330. fcport->loop_id++;
  331. rval = qla2x00_find_new_loop_id(vha, fcport);
  332. if (rval != QLA_SUCCESS) {
  333. fcport->flags &= ~FCF_ASYNC_SENT;
  334. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  335. break;
  336. }
  337. qla2x00_post_async_login_work(vha, fcport, NULL);
  338. break;
  339. }
  340. return;
  341. }
  342. void
  343. qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  344. uint16_t *data)
  345. {
  346. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  347. return;
  348. }
  349. void
  350. qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  351. uint16_t *data)
  352. {
  353. if (data[0] == MBS_COMMAND_COMPLETE) {
  354. qla2x00_update_fcport(vha, fcport);
  355. return;
  356. }
  357. /* Retry login. */
  358. fcport->flags &= ~FCF_ASYNC_SENT;
  359. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  360. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  361. else
  362. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  363. return;
  364. }
  365. /****************************************************************************/
  366. /* QLogic ISP2x00 Hardware Support Functions. */
  367. /****************************************************************************/
  368. static int
  369. qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
  370. {
  371. int rval = QLA_SUCCESS;
  372. struct qla_hw_data *ha = vha->hw;
  373. uint32_t idc_major_ver, idc_minor_ver;
  374. uint16_t config[4];
  375. qla83xx_idc_lock(vha, 0);
  376. /* SV: TODO: Assign initialization timeout from
  377. * flash-info / other param
  378. */
  379. ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
  380. ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
  381. /* Set our fcoe function presence */
  382. if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
  383. ql_dbg(ql_dbg_p3p, vha, 0xb077,
  384. "Error while setting DRV-Presence.\n");
  385. rval = QLA_FUNCTION_FAILED;
  386. goto exit;
  387. }
  388. /* Decide the reset ownership */
  389. qla83xx_reset_ownership(vha);
  390. /*
  391. * On first protocol driver load:
  392. * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
  393. * register.
  394. * Others: Check compatibility with current IDC Major version.
  395. */
  396. qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
  397. if (ha->flags.nic_core_reset_owner) {
  398. /* Set IDC Major version */
  399. idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
  400. qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
  401. /* Clearing IDC-Lock-Recovery register */
  402. qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
  403. } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
  404. /*
  405. * Clear further IDC participation if we are not compatible with
  406. * the current IDC Major Version.
  407. */
  408. ql_log(ql_log_warn, vha, 0xb07d,
  409. "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
  410. idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
  411. __qla83xx_clear_drv_presence(vha);
  412. rval = QLA_FUNCTION_FAILED;
  413. goto exit;
  414. }
  415. /* Each function sets its supported Minor version. */
  416. qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
  417. idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
  418. qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
  419. if (ha->flags.nic_core_reset_owner) {
  420. memset(config, 0, sizeof(config));
  421. if (!qla81xx_get_port_config(vha, config))
  422. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  423. QLA8XXX_DEV_READY);
  424. }
  425. rval = qla83xx_idc_state_handler(vha);
  426. exit:
  427. qla83xx_idc_unlock(vha, 0);
  428. return rval;
  429. }
  430. /*
  431. * qla2x00_initialize_adapter
  432. * Initialize board.
  433. *
  434. * Input:
  435. * ha = adapter block pointer.
  436. *
  437. * Returns:
  438. * 0 = success
  439. */
  440. int
  441. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  442. {
  443. int rval;
  444. struct qla_hw_data *ha = vha->hw;
  445. struct req_que *req = ha->req_q_map[0];
  446. /* Clear adapter flags. */
  447. vha->flags.online = 0;
  448. ha->flags.chip_reset_done = 0;
  449. vha->flags.reset_active = 0;
  450. ha->flags.pci_channel_io_perm_failure = 0;
  451. ha->flags.eeh_busy = 0;
  452. ha->thermal_support = THERMAL_SUPPORT_I2C|THERMAL_SUPPORT_ISP;
  453. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  454. atomic_set(&vha->loop_state, LOOP_DOWN);
  455. vha->device_flags = DFLG_NO_CABLE;
  456. vha->dpc_flags = 0;
  457. vha->flags.management_server_logged_in = 0;
  458. vha->marker_needed = 0;
  459. ha->isp_abort_cnt = 0;
  460. ha->beacon_blink_led = 0;
  461. set_bit(0, ha->req_qid_map);
  462. set_bit(0, ha->rsp_qid_map);
  463. ql_dbg(ql_dbg_init, vha, 0x0040,
  464. "Configuring PCI space...\n");
  465. rval = ha->isp_ops->pci_config(vha);
  466. if (rval) {
  467. ql_log(ql_log_warn, vha, 0x0044,
  468. "Unable to configure PCI space.\n");
  469. return (rval);
  470. }
  471. ha->isp_ops->reset_chip(vha);
  472. rval = qla2xxx_get_flash_info(vha);
  473. if (rval) {
  474. ql_log(ql_log_fatal, vha, 0x004f,
  475. "Unable to validate FLASH data.\n");
  476. return (rval);
  477. }
  478. ha->isp_ops->get_flash_version(vha, req->ring);
  479. ql_dbg(ql_dbg_init, vha, 0x0061,
  480. "Configure NVRAM parameters...\n");
  481. ha->isp_ops->nvram_config(vha);
  482. if (ha->flags.disable_serdes) {
  483. /* Mask HBA via NVRAM settings? */
  484. ql_log(ql_log_info, vha, 0x0077,
  485. "Masking HBA WWPN "
  486. "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
  487. vha->port_name[0], vha->port_name[1],
  488. vha->port_name[2], vha->port_name[3],
  489. vha->port_name[4], vha->port_name[5],
  490. vha->port_name[6], vha->port_name[7]);
  491. return QLA_FUNCTION_FAILED;
  492. }
  493. ql_dbg(ql_dbg_init, vha, 0x0078,
  494. "Verifying loaded RISC code...\n");
  495. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  496. rval = ha->isp_ops->chip_diag(vha);
  497. if (rval)
  498. return (rval);
  499. rval = qla2x00_setup_chip(vha);
  500. if (rval)
  501. return (rval);
  502. }
  503. if (IS_QLA84XX(ha)) {
  504. ha->cs84xx = qla84xx_get_chip(vha);
  505. if (!ha->cs84xx) {
  506. ql_log(ql_log_warn, vha, 0x00d0,
  507. "Unable to configure ISP84XX.\n");
  508. return QLA_FUNCTION_FAILED;
  509. }
  510. }
  511. if (qla_ini_mode_enabled(vha))
  512. rval = qla2x00_init_rings(vha);
  513. ha->flags.chip_reset_done = 1;
  514. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  515. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  516. rval = qla84xx_init_chip(vha);
  517. if (rval != QLA_SUCCESS) {
  518. ql_log(ql_log_warn, vha, 0x00d4,
  519. "Unable to initialize ISP84XX.\n");
  520. qla84xx_put_chip(vha);
  521. }
  522. }
  523. /* Load the NIC Core f/w if we are the first protocol driver. */
  524. if (IS_QLA8031(ha)) {
  525. rval = qla83xx_nic_core_fw_load(vha);
  526. if (rval)
  527. ql_log(ql_log_warn, vha, 0x0124,
  528. "Error in initializing NIC Core f/w.\n");
  529. }
  530. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  531. qla24xx_read_fcp_prio_cfg(vha);
  532. return (rval);
  533. }
  534. /**
  535. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  536. * @ha: HA context
  537. *
  538. * Returns 0 on success.
  539. */
  540. int
  541. qla2100_pci_config(scsi_qla_host_t *vha)
  542. {
  543. uint16_t w;
  544. unsigned long flags;
  545. struct qla_hw_data *ha = vha->hw;
  546. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  547. pci_set_master(ha->pdev);
  548. pci_try_set_mwi(ha->pdev);
  549. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  550. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  551. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  552. pci_disable_rom(ha->pdev);
  553. /* Get PCI bus information. */
  554. spin_lock_irqsave(&ha->hardware_lock, flags);
  555. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  556. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  557. return QLA_SUCCESS;
  558. }
  559. /**
  560. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  561. * @ha: HA context
  562. *
  563. * Returns 0 on success.
  564. */
  565. int
  566. qla2300_pci_config(scsi_qla_host_t *vha)
  567. {
  568. uint16_t w;
  569. unsigned long flags = 0;
  570. uint32_t cnt;
  571. struct qla_hw_data *ha = vha->hw;
  572. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  573. pci_set_master(ha->pdev);
  574. pci_try_set_mwi(ha->pdev);
  575. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  576. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  577. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  578. w &= ~PCI_COMMAND_INTX_DISABLE;
  579. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  580. /*
  581. * If this is a 2300 card and not 2312, reset the
  582. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  583. * the 2310 also reports itself as a 2300 so we need to get the
  584. * fb revision level -- a 6 indicates it really is a 2300 and
  585. * not a 2310.
  586. */
  587. if (IS_QLA2300(ha)) {
  588. spin_lock_irqsave(&ha->hardware_lock, flags);
  589. /* Pause RISC. */
  590. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  591. for (cnt = 0; cnt < 30000; cnt++) {
  592. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  593. break;
  594. udelay(10);
  595. }
  596. /* Select FPM registers. */
  597. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  598. RD_REG_WORD(&reg->ctrl_status);
  599. /* Get the fb rev level */
  600. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  601. if (ha->fb_rev == FPM_2300)
  602. pci_clear_mwi(ha->pdev);
  603. /* Deselect FPM registers. */
  604. WRT_REG_WORD(&reg->ctrl_status, 0x0);
  605. RD_REG_WORD(&reg->ctrl_status);
  606. /* Release RISC module. */
  607. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  608. for (cnt = 0; cnt < 30000; cnt++) {
  609. if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  610. break;
  611. udelay(10);
  612. }
  613. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  614. }
  615. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  616. pci_disable_rom(ha->pdev);
  617. /* Get PCI bus information. */
  618. spin_lock_irqsave(&ha->hardware_lock, flags);
  619. ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
  620. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  621. return QLA_SUCCESS;
  622. }
  623. /**
  624. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  625. * @ha: HA context
  626. *
  627. * Returns 0 on success.
  628. */
  629. int
  630. qla24xx_pci_config(scsi_qla_host_t *vha)
  631. {
  632. uint16_t w;
  633. unsigned long flags = 0;
  634. struct qla_hw_data *ha = vha->hw;
  635. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  636. pci_set_master(ha->pdev);
  637. pci_try_set_mwi(ha->pdev);
  638. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  639. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  640. w &= ~PCI_COMMAND_INTX_DISABLE;
  641. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  642. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  643. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  644. if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
  645. pcix_set_mmrbc(ha->pdev, 2048);
  646. /* PCIe -- adjust Maximum Read Request Size (2048). */
  647. if (pci_is_pcie(ha->pdev))
  648. pcie_set_readrq(ha->pdev, 4096);
  649. pci_disable_rom(ha->pdev);
  650. ha->chip_revision = ha->pdev->revision;
  651. /* Get PCI bus information. */
  652. spin_lock_irqsave(&ha->hardware_lock, flags);
  653. ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
  654. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  655. return QLA_SUCCESS;
  656. }
  657. /**
  658. * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
  659. * @ha: HA context
  660. *
  661. * Returns 0 on success.
  662. */
  663. int
  664. qla25xx_pci_config(scsi_qla_host_t *vha)
  665. {
  666. uint16_t w;
  667. struct qla_hw_data *ha = vha->hw;
  668. pci_set_master(ha->pdev);
  669. pci_try_set_mwi(ha->pdev);
  670. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  671. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  672. w &= ~PCI_COMMAND_INTX_DISABLE;
  673. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  674. /* PCIe -- adjust Maximum Read Request Size (2048). */
  675. if (pci_is_pcie(ha->pdev))
  676. pcie_set_readrq(ha->pdev, 4096);
  677. pci_disable_rom(ha->pdev);
  678. ha->chip_revision = ha->pdev->revision;
  679. return QLA_SUCCESS;
  680. }
  681. /**
  682. * qla2x00_isp_firmware() - Choose firmware image.
  683. * @ha: HA context
  684. *
  685. * Returns 0 on success.
  686. */
  687. static int
  688. qla2x00_isp_firmware(scsi_qla_host_t *vha)
  689. {
  690. int rval;
  691. uint16_t loop_id, topo, sw_cap;
  692. uint8_t domain, area, al_pa;
  693. struct qla_hw_data *ha = vha->hw;
  694. /* Assume loading risc code */
  695. rval = QLA_FUNCTION_FAILED;
  696. if (ha->flags.disable_risc_code_load) {
  697. ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
  698. /* Verify checksum of loaded RISC code. */
  699. rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
  700. if (rval == QLA_SUCCESS) {
  701. /* And, verify we are not in ROM code. */
  702. rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
  703. &area, &domain, &topo, &sw_cap);
  704. }
  705. }
  706. if (rval)
  707. ql_dbg(ql_dbg_init, vha, 0x007a,
  708. "**** Load RISC code ****.\n");
  709. return (rval);
  710. }
  711. /**
  712. * qla2x00_reset_chip() - Reset ISP chip.
  713. * @ha: HA context
  714. *
  715. * Returns 0 on success.
  716. */
  717. void
  718. qla2x00_reset_chip(scsi_qla_host_t *vha)
  719. {
  720. unsigned long flags = 0;
  721. struct qla_hw_data *ha = vha->hw;
  722. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  723. uint32_t cnt;
  724. uint16_t cmd;
  725. if (unlikely(pci_channel_offline(ha->pdev)))
  726. return;
  727. ha->isp_ops->disable_intrs(ha);
  728. spin_lock_irqsave(&ha->hardware_lock, flags);
  729. /* Turn off master enable */
  730. cmd = 0;
  731. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  732. cmd &= ~PCI_COMMAND_MASTER;
  733. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  734. if (!IS_QLA2100(ha)) {
  735. /* Pause RISC. */
  736. WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
  737. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  738. for (cnt = 0; cnt < 30000; cnt++) {
  739. if ((RD_REG_WORD(&reg->hccr) &
  740. HCCR_RISC_PAUSE) != 0)
  741. break;
  742. udelay(100);
  743. }
  744. } else {
  745. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  746. udelay(10);
  747. }
  748. /* Select FPM registers. */
  749. WRT_REG_WORD(&reg->ctrl_status, 0x20);
  750. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  751. /* FPM Soft Reset. */
  752. WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
  753. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  754. /* Toggle Fpm Reset. */
  755. if (!IS_QLA2200(ha)) {
  756. WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
  757. RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
  758. }
  759. /* Select frame buffer registers. */
  760. WRT_REG_WORD(&reg->ctrl_status, 0x10);
  761. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  762. /* Reset frame buffer FIFOs. */
  763. if (IS_QLA2200(ha)) {
  764. WRT_FB_CMD_REG(ha, reg, 0xa000);
  765. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  766. } else {
  767. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  768. /* Read back fb_cmd until zero or 3 seconds max */
  769. for (cnt = 0; cnt < 3000; cnt++) {
  770. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  771. break;
  772. udelay(100);
  773. }
  774. }
  775. /* Select RISC module registers. */
  776. WRT_REG_WORD(&reg->ctrl_status, 0);
  777. RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
  778. /* Reset RISC processor. */
  779. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  780. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  781. /* Release RISC processor. */
  782. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  783. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  784. }
  785. WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
  786. WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
  787. /* Reset ISP chip. */
  788. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  789. /* Wait for RISC to recover from reset. */
  790. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  791. /*
  792. * It is necessary to for a delay here since the card doesn't
  793. * respond to PCI reads during a reset. On some architectures
  794. * this will result in an MCA.
  795. */
  796. udelay(20);
  797. for (cnt = 30000; cnt; cnt--) {
  798. if ((RD_REG_WORD(&reg->ctrl_status) &
  799. CSR_ISP_SOFT_RESET) == 0)
  800. break;
  801. udelay(100);
  802. }
  803. } else
  804. udelay(10);
  805. /* Reset RISC processor. */
  806. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  807. WRT_REG_WORD(&reg->semaphore, 0);
  808. /* Release RISC processor. */
  809. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  810. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  811. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  812. for (cnt = 0; cnt < 30000; cnt++) {
  813. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
  814. break;
  815. udelay(100);
  816. }
  817. } else
  818. udelay(100);
  819. /* Turn on master enable */
  820. cmd |= PCI_COMMAND_MASTER;
  821. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  822. /* Disable RISC pause on FPM parity error. */
  823. if (!IS_QLA2100(ha)) {
  824. WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  825. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  826. }
  827. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  828. }
  829. /**
  830. * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
  831. *
  832. * Returns 0 on success.
  833. */
  834. static int
  835. qla81xx_reset_mpi(scsi_qla_host_t *vha)
  836. {
  837. uint16_t mb[4] = {0x1010, 0, 1, 0};
  838. if (!IS_QLA81XX(vha->hw))
  839. return QLA_SUCCESS;
  840. return qla81xx_write_mpi_register(vha, mb);
  841. }
  842. /**
  843. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  844. * @ha: HA context
  845. *
  846. * Returns 0 on success.
  847. */
  848. static inline void
  849. qla24xx_reset_risc(scsi_qla_host_t *vha)
  850. {
  851. unsigned long flags = 0;
  852. struct qla_hw_data *ha = vha->hw;
  853. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  854. uint32_t cnt, d2;
  855. uint16_t wd;
  856. static int abts_cnt; /* ISP abort retry counts */
  857. spin_lock_irqsave(&ha->hardware_lock, flags);
  858. /* Reset RISC. */
  859. WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  860. for (cnt = 0; cnt < 30000; cnt++) {
  861. if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  862. break;
  863. udelay(10);
  864. }
  865. WRT_REG_DWORD(&reg->ctrl_status,
  866. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  867. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  868. udelay(100);
  869. /* Wait for firmware to complete NVRAM accesses. */
  870. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  871. for (cnt = 10000 ; cnt && d2; cnt--) {
  872. udelay(5);
  873. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  874. barrier();
  875. }
  876. /* Wait for soft-reset to complete. */
  877. d2 = RD_REG_DWORD(&reg->ctrl_status);
  878. for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
  879. udelay(5);
  880. d2 = RD_REG_DWORD(&reg->ctrl_status);
  881. barrier();
  882. }
  883. /* If required, do an MPI FW reset now */
  884. if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
  885. if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
  886. if (++abts_cnt < 5) {
  887. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  888. set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
  889. } else {
  890. /*
  891. * We exhausted the ISP abort retries. We have to
  892. * set the board offline.
  893. */
  894. abts_cnt = 0;
  895. vha->flags.online = 0;
  896. }
  897. }
  898. }
  899. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  900. RD_REG_DWORD(&reg->hccr);
  901. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  902. RD_REG_DWORD(&reg->hccr);
  903. WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
  904. RD_REG_DWORD(&reg->hccr);
  905. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  906. for (cnt = 6000000 ; cnt && d2; cnt--) {
  907. udelay(5);
  908. d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
  909. barrier();
  910. }
  911. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  912. if (IS_NOPOLLING_TYPE(ha))
  913. ha->isp_ops->enable_intrs(ha);
  914. }
  915. static void
  916. qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
  917. {
  918. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  919. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  920. *data = RD_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET);
  921. }
  922. static void
  923. qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
  924. {
  925. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  926. WRT_REG_DWORD(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  927. WRT_REG_DWORD(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
  928. }
  929. static void
  930. qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
  931. {
  932. struct qla_hw_data *ha = vha->hw;
  933. uint32_t wd32 = 0;
  934. uint delta_msec = 100;
  935. uint elapsed_msec = 0;
  936. uint timeout_msec;
  937. ulong n;
  938. if (!IS_QLA25XX(ha) && !IS_QLA2031(ha))
  939. return;
  940. attempt:
  941. timeout_msec = TIMEOUT_SEMAPHORE;
  942. n = timeout_msec / delta_msec;
  943. while (n--) {
  944. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
  945. qla25xx_read_risc_sema_reg(vha, &wd32);
  946. if (wd32 & RISC_SEMAPHORE)
  947. break;
  948. msleep(delta_msec);
  949. elapsed_msec += delta_msec;
  950. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  951. goto force;
  952. }
  953. if (!(wd32 & RISC_SEMAPHORE))
  954. goto force;
  955. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  956. goto acquired;
  957. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
  958. timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
  959. n = timeout_msec / delta_msec;
  960. while (n--) {
  961. qla25xx_read_risc_sema_reg(vha, &wd32);
  962. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  963. break;
  964. msleep(delta_msec);
  965. elapsed_msec += delta_msec;
  966. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  967. goto force;
  968. }
  969. if (wd32 & RISC_SEMAPHORE_FORCE)
  970. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
  971. goto attempt;
  972. force:
  973. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
  974. acquired:
  975. return;
  976. }
  977. /**
  978. * qla24xx_reset_chip() - Reset ISP24xx chip.
  979. * @ha: HA context
  980. *
  981. * Returns 0 on success.
  982. */
  983. void
  984. qla24xx_reset_chip(scsi_qla_host_t *vha)
  985. {
  986. struct qla_hw_data *ha = vha->hw;
  987. if (pci_channel_offline(ha->pdev) &&
  988. ha->flags.pci_channel_io_perm_failure) {
  989. return;
  990. }
  991. ha->isp_ops->disable_intrs(ha);
  992. qla25xx_manipulate_risc_semaphore(vha);
  993. /* Perform RISC reset. */
  994. qla24xx_reset_risc(vha);
  995. }
  996. /**
  997. * qla2x00_chip_diag() - Test chip for proper operation.
  998. * @ha: HA context
  999. *
  1000. * Returns 0 on success.
  1001. */
  1002. int
  1003. qla2x00_chip_diag(scsi_qla_host_t *vha)
  1004. {
  1005. int rval;
  1006. struct qla_hw_data *ha = vha->hw;
  1007. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1008. unsigned long flags = 0;
  1009. uint16_t data;
  1010. uint32_t cnt;
  1011. uint16_t mb[5];
  1012. struct req_que *req = ha->req_q_map[0];
  1013. /* Assume a failed state */
  1014. rval = QLA_FUNCTION_FAILED;
  1015. ql_dbg(ql_dbg_init, vha, 0x007b,
  1016. "Testing device at %lx.\n", (u_long)&reg->flash_address);
  1017. spin_lock_irqsave(&ha->hardware_lock, flags);
  1018. /* Reset ISP chip. */
  1019. WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  1020. /*
  1021. * We need to have a delay here since the card will not respond while
  1022. * in reset causing an MCA on some architectures.
  1023. */
  1024. udelay(20);
  1025. data = qla2x00_debounce_register(&reg->ctrl_status);
  1026. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  1027. udelay(5);
  1028. data = RD_REG_WORD(&reg->ctrl_status);
  1029. barrier();
  1030. }
  1031. if (!cnt)
  1032. goto chip_diag_failed;
  1033. ql_dbg(ql_dbg_init, vha, 0x007c,
  1034. "Reset register cleared by chip reset.\n");
  1035. /* Reset RISC processor. */
  1036. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  1037. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  1038. /* Workaround for QLA2312 PCI parity error */
  1039. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  1040. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  1041. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  1042. udelay(5);
  1043. data = RD_MAILBOX_REG(ha, reg, 0);
  1044. barrier();
  1045. }
  1046. } else
  1047. udelay(10);
  1048. if (!cnt)
  1049. goto chip_diag_failed;
  1050. /* Check product ID of chip */
  1051. ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product Id of chip.\n");
  1052. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  1053. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  1054. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  1055. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  1056. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  1057. mb[3] != PROD_ID_3) {
  1058. ql_log(ql_log_warn, vha, 0x0062,
  1059. "Wrong product ID = 0x%x,0x%x,0x%x.\n",
  1060. mb[1], mb[2], mb[3]);
  1061. goto chip_diag_failed;
  1062. }
  1063. ha->product_id[0] = mb[1];
  1064. ha->product_id[1] = mb[2];
  1065. ha->product_id[2] = mb[3];
  1066. ha->product_id[3] = mb[4];
  1067. /* Adjust fw RISC transfer size */
  1068. if (req->length > 1024)
  1069. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  1070. else
  1071. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  1072. req->length;
  1073. if (IS_QLA2200(ha) &&
  1074. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  1075. /* Limit firmware transfer size with a 2200A */
  1076. ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
  1077. ha->device_type |= DT_ISP2200A;
  1078. ha->fw_transfer_size = 128;
  1079. }
  1080. /* Wrap Incoming Mailboxes Test. */
  1081. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1082. ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
  1083. rval = qla2x00_mbx_reg_test(vha);
  1084. if (rval)
  1085. ql_log(ql_log_warn, vha, 0x0080,
  1086. "Failed mailbox send register test.\n");
  1087. else
  1088. /* Flag a successful rval */
  1089. rval = QLA_SUCCESS;
  1090. spin_lock_irqsave(&ha->hardware_lock, flags);
  1091. chip_diag_failed:
  1092. if (rval)
  1093. ql_log(ql_log_info, vha, 0x0081,
  1094. "Chip diagnostics **** FAILED ****.\n");
  1095. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1096. return (rval);
  1097. }
  1098. /**
  1099. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  1100. * @ha: HA context
  1101. *
  1102. * Returns 0 on success.
  1103. */
  1104. int
  1105. qla24xx_chip_diag(scsi_qla_host_t *vha)
  1106. {
  1107. int rval;
  1108. struct qla_hw_data *ha = vha->hw;
  1109. struct req_que *req = ha->req_q_map[0];
  1110. if (IS_QLA82XX(ha))
  1111. return QLA_SUCCESS;
  1112. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
  1113. rval = qla2x00_mbx_reg_test(vha);
  1114. if (rval) {
  1115. ql_log(ql_log_warn, vha, 0x0082,
  1116. "Failed mailbox send register test.\n");
  1117. } else {
  1118. /* Flag a successful rval */
  1119. rval = QLA_SUCCESS;
  1120. }
  1121. return rval;
  1122. }
  1123. void
  1124. qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
  1125. {
  1126. int rval;
  1127. uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
  1128. eft_size, fce_size, mq_size;
  1129. dma_addr_t tc_dma;
  1130. void *tc;
  1131. struct qla_hw_data *ha = vha->hw;
  1132. struct req_que *req = ha->req_q_map[0];
  1133. struct rsp_que *rsp = ha->rsp_q_map[0];
  1134. if (ha->fw_dump) {
  1135. ql_dbg(ql_dbg_init, vha, 0x00bd,
  1136. "Firmware dump already allocated.\n");
  1137. return;
  1138. }
  1139. ha->fw_dumped = 0;
  1140. fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
  1141. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1142. fixed_size = sizeof(struct qla2100_fw_dump);
  1143. } else if (IS_QLA23XX(ha)) {
  1144. fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
  1145. mem_size = (ha->fw_memory_size - 0x11000 + 1) *
  1146. sizeof(uint16_t);
  1147. } else if (IS_FWI2_CAPABLE(ha)) {
  1148. if (IS_QLA83XX(ha))
  1149. fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
  1150. else if (IS_QLA81XX(ha))
  1151. fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
  1152. else if (IS_QLA25XX(ha))
  1153. fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
  1154. else
  1155. fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
  1156. mem_size = (ha->fw_memory_size - 0x100000 + 1) *
  1157. sizeof(uint32_t);
  1158. if (ha->mqenable) {
  1159. if (!IS_QLA83XX(ha))
  1160. mq_size = sizeof(struct qla2xxx_mq_chain);
  1161. /*
  1162. * Allocate maximum buffer size for all queues.
  1163. * Resizing must be done at end-of-dump processing.
  1164. */
  1165. mq_size += ha->max_req_queues *
  1166. (req->length * sizeof(request_t));
  1167. mq_size += ha->max_rsp_queues *
  1168. (rsp->length * sizeof(response_t));
  1169. }
  1170. if (ha->tgt.atio_ring)
  1171. mq_size += ha->tgt.atio_q_length * sizeof(request_t);
  1172. /* Allocate memory for Fibre Channel Event Buffer. */
  1173. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  1174. goto try_eft;
  1175. tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
  1176. GFP_KERNEL);
  1177. if (!tc) {
  1178. ql_log(ql_log_warn, vha, 0x00be,
  1179. "Unable to allocate (%d KB) for FCE.\n",
  1180. FCE_SIZE / 1024);
  1181. goto try_eft;
  1182. }
  1183. memset(tc, 0, FCE_SIZE);
  1184. rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
  1185. ha->fce_mb, &ha->fce_bufs);
  1186. if (rval) {
  1187. ql_log(ql_log_warn, vha, 0x00bf,
  1188. "Unable to initialize FCE (%d).\n", rval);
  1189. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
  1190. tc_dma);
  1191. ha->flags.fce_enabled = 0;
  1192. goto try_eft;
  1193. }
  1194. ql_dbg(ql_dbg_init, vha, 0x00c0,
  1195. "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
  1196. fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
  1197. ha->flags.fce_enabled = 1;
  1198. ha->fce_dma = tc_dma;
  1199. ha->fce = tc;
  1200. try_eft:
  1201. /* Allocate memory for Extended Trace Buffer. */
  1202. tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
  1203. GFP_KERNEL);
  1204. if (!tc) {
  1205. ql_log(ql_log_warn, vha, 0x00c1,
  1206. "Unable to allocate (%d KB) for EFT.\n",
  1207. EFT_SIZE / 1024);
  1208. goto cont_alloc;
  1209. }
  1210. memset(tc, 0, EFT_SIZE);
  1211. rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
  1212. if (rval) {
  1213. ql_log(ql_log_warn, vha, 0x00c2,
  1214. "Unable to initialize EFT (%d).\n", rval);
  1215. dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
  1216. tc_dma);
  1217. goto cont_alloc;
  1218. }
  1219. ql_dbg(ql_dbg_init, vha, 0x00c3,
  1220. "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
  1221. eft_size = EFT_SIZE;
  1222. ha->eft_dma = tc_dma;
  1223. ha->eft = tc;
  1224. }
  1225. cont_alloc:
  1226. req_q_size = req->length * sizeof(request_t);
  1227. rsp_q_size = rsp->length * sizeof(response_t);
  1228. dump_size = offsetof(struct qla2xxx_fw_dump, isp);
  1229. dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
  1230. ha->chain_offset = dump_size;
  1231. dump_size += mq_size + fce_size;
  1232. ha->fw_dump = vmalloc(dump_size);
  1233. if (!ha->fw_dump) {
  1234. ql_log(ql_log_warn, vha, 0x00c4,
  1235. "Unable to allocate (%d KB) for firmware dump.\n",
  1236. dump_size / 1024);
  1237. if (ha->fce) {
  1238. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  1239. ha->fce_dma);
  1240. ha->fce = NULL;
  1241. ha->fce_dma = 0;
  1242. }
  1243. if (ha->eft) {
  1244. dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
  1245. ha->eft_dma);
  1246. ha->eft = NULL;
  1247. ha->eft_dma = 0;
  1248. }
  1249. return;
  1250. }
  1251. ql_dbg(ql_dbg_init, vha, 0x00c5,
  1252. "Allocated (%d KB) for firmware dump.\n", dump_size / 1024);
  1253. ha->fw_dump_len = dump_size;
  1254. ha->fw_dump->signature[0] = 'Q';
  1255. ha->fw_dump->signature[1] = 'L';
  1256. ha->fw_dump->signature[2] = 'G';
  1257. ha->fw_dump->signature[3] = 'C';
  1258. ha->fw_dump->version = __constant_htonl(1);
  1259. ha->fw_dump->fixed_size = htonl(fixed_size);
  1260. ha->fw_dump->mem_size = htonl(mem_size);
  1261. ha->fw_dump->req_q_size = htonl(req_q_size);
  1262. ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
  1263. ha->fw_dump->eft_size = htonl(eft_size);
  1264. ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
  1265. ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
  1266. ha->fw_dump->header_size =
  1267. htonl(offsetof(struct qla2xxx_fw_dump, isp));
  1268. }
  1269. static int
  1270. qla81xx_mpi_sync(scsi_qla_host_t *vha)
  1271. {
  1272. #define MPS_MASK 0xe0
  1273. int rval;
  1274. uint16_t dc;
  1275. uint32_t dw;
  1276. if (!IS_QLA81XX(vha->hw))
  1277. return QLA_SUCCESS;
  1278. rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
  1279. if (rval != QLA_SUCCESS) {
  1280. ql_log(ql_log_warn, vha, 0x0105,
  1281. "Unable to acquire semaphore.\n");
  1282. goto done;
  1283. }
  1284. pci_read_config_word(vha->hw->pdev, 0x54, &dc);
  1285. rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
  1286. if (rval != QLA_SUCCESS) {
  1287. ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
  1288. goto done_release;
  1289. }
  1290. dc &= MPS_MASK;
  1291. if (dc == (dw & MPS_MASK))
  1292. goto done_release;
  1293. dw &= ~MPS_MASK;
  1294. dw |= dc;
  1295. rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
  1296. if (rval != QLA_SUCCESS) {
  1297. ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
  1298. }
  1299. done_release:
  1300. rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
  1301. if (rval != QLA_SUCCESS) {
  1302. ql_log(ql_log_warn, vha, 0x006d,
  1303. "Unable to release semaphore.\n");
  1304. }
  1305. done:
  1306. return rval;
  1307. }
  1308. int
  1309. qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
  1310. {
  1311. /* Don't try to reallocate the array */
  1312. if (req->outstanding_cmds)
  1313. return QLA_SUCCESS;
  1314. if (!IS_FWI2_CAPABLE(ha) || (ha->mqiobase &&
  1315. (ql2xmultique_tag || ql2xmaxqueues > 1)))
  1316. req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
  1317. else {
  1318. if (ha->fw_xcb_count <= ha->fw_iocb_count)
  1319. req->num_outstanding_cmds = ha->fw_xcb_count;
  1320. else
  1321. req->num_outstanding_cmds = ha->fw_iocb_count;
  1322. }
  1323. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1324. req->num_outstanding_cmds, GFP_KERNEL);
  1325. if (!req->outstanding_cmds) {
  1326. /*
  1327. * Try to allocate a minimal size just so we can get through
  1328. * initialization.
  1329. */
  1330. req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
  1331. req->outstanding_cmds = kzalloc(sizeof(srb_t *) *
  1332. req->num_outstanding_cmds, GFP_KERNEL);
  1333. if (!req->outstanding_cmds) {
  1334. ql_log(ql_log_fatal, NULL, 0x0126,
  1335. "Failed to allocate memory for "
  1336. "outstanding_cmds for req_que %p.\n", req);
  1337. req->num_outstanding_cmds = 0;
  1338. return QLA_FUNCTION_FAILED;
  1339. }
  1340. }
  1341. return QLA_SUCCESS;
  1342. }
  1343. /**
  1344. * qla2x00_setup_chip() - Load and start RISC firmware.
  1345. * @ha: HA context
  1346. *
  1347. * Returns 0 on success.
  1348. */
  1349. static int
  1350. qla2x00_setup_chip(scsi_qla_host_t *vha)
  1351. {
  1352. int rval;
  1353. uint32_t srisc_address = 0;
  1354. struct qla_hw_data *ha = vha->hw;
  1355. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1356. unsigned long flags;
  1357. uint16_t fw_major_version;
  1358. if (IS_QLA82XX(ha)) {
  1359. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1360. if (rval == QLA_SUCCESS) {
  1361. qla2x00_stop_firmware(vha);
  1362. goto enable_82xx_npiv;
  1363. } else
  1364. goto failed;
  1365. }
  1366. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1367. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  1368. spin_lock_irqsave(&ha->hardware_lock, flags);
  1369. WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  1370. RD_REG_WORD(&reg->hccr);
  1371. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1372. }
  1373. qla81xx_mpi_sync(vha);
  1374. /* Load firmware sequences */
  1375. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  1376. if (rval == QLA_SUCCESS) {
  1377. ql_dbg(ql_dbg_init, vha, 0x00c9,
  1378. "Verifying Checksum of loaded RISC code.\n");
  1379. rval = qla2x00_verify_checksum(vha, srisc_address);
  1380. if (rval == QLA_SUCCESS) {
  1381. /* Start firmware execution. */
  1382. ql_dbg(ql_dbg_init, vha, 0x00ca,
  1383. "Starting firmware.\n");
  1384. rval = qla2x00_execute_fw(vha, srisc_address);
  1385. /* Retrieve firmware information. */
  1386. if (rval == QLA_SUCCESS) {
  1387. enable_82xx_npiv:
  1388. fw_major_version = ha->fw_major_version;
  1389. if (IS_QLA82XX(ha))
  1390. qla82xx_check_md_needed(vha);
  1391. else
  1392. rval = qla2x00_get_fw_version(vha);
  1393. if (rval != QLA_SUCCESS)
  1394. goto failed;
  1395. ha->flags.npiv_supported = 0;
  1396. if (IS_QLA2XXX_MIDTYPE(ha) &&
  1397. (ha->fw_attributes & BIT_2)) {
  1398. ha->flags.npiv_supported = 1;
  1399. if ((!ha->max_npiv_vports) ||
  1400. ((ha->max_npiv_vports + 1) %
  1401. MIN_MULTI_ID_FABRIC))
  1402. ha->max_npiv_vports =
  1403. MIN_MULTI_ID_FABRIC - 1;
  1404. }
  1405. qla2x00_get_resource_cnts(vha, NULL,
  1406. &ha->fw_xcb_count, NULL, &ha->fw_iocb_count,
  1407. &ha->max_npiv_vports, NULL);
  1408. /*
  1409. * Allocate the array of outstanding commands
  1410. * now that we know the firmware resources.
  1411. */
  1412. rval = qla2x00_alloc_outstanding_cmds(ha,
  1413. vha->req);
  1414. if (rval != QLA_SUCCESS)
  1415. goto failed;
  1416. if (!fw_major_version && ql2xallocfwdump
  1417. && !IS_QLA82XX(ha))
  1418. qla2x00_alloc_fw_dump(vha);
  1419. }
  1420. } else {
  1421. ql_log(ql_log_fatal, vha, 0x00cd,
  1422. "ISP Firmware failed checksum.\n");
  1423. goto failed;
  1424. }
  1425. } else
  1426. goto failed;
  1427. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  1428. /* Enable proper parity. */
  1429. spin_lock_irqsave(&ha->hardware_lock, flags);
  1430. if (IS_QLA2300(ha))
  1431. /* SRAM parity */
  1432. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
  1433. else
  1434. /* SRAM, Instruction RAM and GP RAM parity */
  1435. WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
  1436. RD_REG_WORD(&reg->hccr);
  1437. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1438. }
  1439. if (IS_QLA83XX(ha))
  1440. goto skip_fac_check;
  1441. if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
  1442. uint32_t size;
  1443. rval = qla81xx_fac_get_sector_size(vha, &size);
  1444. if (rval == QLA_SUCCESS) {
  1445. ha->flags.fac_supported = 1;
  1446. ha->fdt_block_size = size << 2;
  1447. } else {
  1448. ql_log(ql_log_warn, vha, 0x00ce,
  1449. "Unsupported FAC firmware (%d.%02d.%02d).\n",
  1450. ha->fw_major_version, ha->fw_minor_version,
  1451. ha->fw_subminor_version);
  1452. skip_fac_check:
  1453. if (IS_QLA83XX(ha)) {
  1454. ha->flags.fac_supported = 0;
  1455. rval = QLA_SUCCESS;
  1456. }
  1457. }
  1458. }
  1459. failed:
  1460. if (rval) {
  1461. ql_log(ql_log_fatal, vha, 0x00cf,
  1462. "Setup chip ****FAILED****.\n");
  1463. }
  1464. return (rval);
  1465. }
  1466. /**
  1467. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  1468. * @ha: HA context
  1469. *
  1470. * Beginning of request ring has initialization control block already built
  1471. * by nvram config routine.
  1472. *
  1473. * Returns 0 on success.
  1474. */
  1475. void
  1476. qla2x00_init_response_q_entries(struct rsp_que *rsp)
  1477. {
  1478. uint16_t cnt;
  1479. response_t *pkt;
  1480. rsp->ring_ptr = rsp->ring;
  1481. rsp->ring_index = 0;
  1482. rsp->status_srb = NULL;
  1483. pkt = rsp->ring_ptr;
  1484. for (cnt = 0; cnt < rsp->length; cnt++) {
  1485. pkt->signature = RESPONSE_PROCESSED;
  1486. pkt++;
  1487. }
  1488. }
  1489. /**
  1490. * qla2x00_update_fw_options() - Read and process firmware options.
  1491. * @ha: HA context
  1492. *
  1493. * Returns 0 on success.
  1494. */
  1495. void
  1496. qla2x00_update_fw_options(scsi_qla_host_t *vha)
  1497. {
  1498. uint16_t swing, emphasis, tx_sens, rx_sens;
  1499. struct qla_hw_data *ha = vha->hw;
  1500. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  1501. qla2x00_get_fw_options(vha, ha->fw_options);
  1502. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1503. return;
  1504. /* Serial Link options. */
  1505. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
  1506. "Serial link options.\n");
  1507. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
  1508. (uint8_t *)&ha->fw_seriallink_options,
  1509. sizeof(ha->fw_seriallink_options));
  1510. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  1511. if (ha->fw_seriallink_options[3] & BIT_2) {
  1512. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  1513. /* 1G settings */
  1514. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  1515. emphasis = (ha->fw_seriallink_options[2] &
  1516. (BIT_4 | BIT_3)) >> 3;
  1517. tx_sens = ha->fw_seriallink_options[0] &
  1518. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1519. rx_sens = (ha->fw_seriallink_options[0] &
  1520. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1521. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  1522. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1523. if (rx_sens == 0x0)
  1524. rx_sens = 0x3;
  1525. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  1526. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1527. ha->fw_options[10] |= BIT_5 |
  1528. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1529. (tx_sens & (BIT_1 | BIT_0));
  1530. /* 2G settings */
  1531. swing = (ha->fw_seriallink_options[2] &
  1532. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  1533. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  1534. tx_sens = ha->fw_seriallink_options[1] &
  1535. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1536. rx_sens = (ha->fw_seriallink_options[1] &
  1537. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  1538. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  1539. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  1540. if (rx_sens == 0x0)
  1541. rx_sens = 0x3;
  1542. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  1543. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1544. ha->fw_options[11] |= BIT_5 |
  1545. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  1546. (tx_sens & (BIT_1 | BIT_0));
  1547. }
  1548. /* FCP2 options. */
  1549. /* Return command IOCBs without waiting for an ABTS to complete. */
  1550. ha->fw_options[3] |= BIT_13;
  1551. /* LED scheme. */
  1552. if (ha->flags.enable_led_scheme)
  1553. ha->fw_options[2] |= BIT_12;
  1554. /* Detect ISP6312. */
  1555. if (IS_QLA6312(ha))
  1556. ha->fw_options[2] |= BIT_13;
  1557. /* Update firmware options. */
  1558. qla2x00_set_fw_options(vha, ha->fw_options);
  1559. }
  1560. void
  1561. qla24xx_update_fw_options(scsi_qla_host_t *vha)
  1562. {
  1563. int rval;
  1564. struct qla_hw_data *ha = vha->hw;
  1565. if (IS_QLA82XX(ha))
  1566. return;
  1567. /* Update Serial Link options. */
  1568. if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
  1569. return;
  1570. rval = qla2x00_set_serdes_params(vha,
  1571. le16_to_cpu(ha->fw_seriallink_options24[1]),
  1572. le16_to_cpu(ha->fw_seriallink_options24[2]),
  1573. le16_to_cpu(ha->fw_seriallink_options24[3]));
  1574. if (rval != QLA_SUCCESS) {
  1575. ql_log(ql_log_warn, vha, 0x0104,
  1576. "Unable to update Serial Link options (%x).\n", rval);
  1577. }
  1578. }
  1579. void
  1580. qla2x00_config_rings(struct scsi_qla_host *vha)
  1581. {
  1582. struct qla_hw_data *ha = vha->hw;
  1583. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1584. struct req_que *req = ha->req_q_map[0];
  1585. struct rsp_que *rsp = ha->rsp_q_map[0];
  1586. /* Setup ring parameters in initialization control block. */
  1587. ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
  1588. ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
  1589. ha->init_cb->request_q_length = cpu_to_le16(req->length);
  1590. ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
  1591. ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1592. ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1593. ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1594. ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1595. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
  1596. WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
  1597. WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
  1598. WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
  1599. RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  1600. }
  1601. void
  1602. qla24xx_config_rings(struct scsi_qla_host *vha)
  1603. {
  1604. struct qla_hw_data *ha = vha->hw;
  1605. device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
  1606. struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
  1607. struct qla_msix_entry *msix;
  1608. struct init_cb_24xx *icb;
  1609. uint16_t rid = 0;
  1610. struct req_que *req = ha->req_q_map[0];
  1611. struct rsp_que *rsp = ha->rsp_q_map[0];
  1612. /* Setup ring parameters in initialization control block. */
  1613. icb = (struct init_cb_24xx *)ha->init_cb;
  1614. icb->request_q_outpointer = __constant_cpu_to_le16(0);
  1615. icb->response_q_inpointer = __constant_cpu_to_le16(0);
  1616. icb->request_q_length = cpu_to_le16(req->length);
  1617. icb->response_q_length = cpu_to_le16(rsp->length);
  1618. icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
  1619. icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
  1620. icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
  1621. icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
  1622. /* Setup ATIO queue dma pointers for target mode */
  1623. icb->atio_q_inpointer = __constant_cpu_to_le16(0);
  1624. icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
  1625. icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
  1626. icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
  1627. if (ha->mqenable || IS_QLA83XX(ha)) {
  1628. icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
  1629. icb->rid = __constant_cpu_to_le16(rid);
  1630. if (ha->flags.msix_enabled) {
  1631. msix = &ha->msix_entries[1];
  1632. ql_dbg(ql_dbg_init, vha, 0x00fd,
  1633. "Registering vector 0x%x for base que.\n",
  1634. msix->entry);
  1635. icb->msix = cpu_to_le16(msix->entry);
  1636. }
  1637. /* Use alternate PCI bus number */
  1638. if (MSB(rid))
  1639. icb->firmware_options_2 |=
  1640. __constant_cpu_to_le32(BIT_19);
  1641. /* Use alternate PCI devfn */
  1642. if (LSB(rid))
  1643. icb->firmware_options_2 |=
  1644. __constant_cpu_to_le32(BIT_18);
  1645. /* Use Disable MSIX Handshake mode for capable adapters */
  1646. if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
  1647. (ha->flags.msix_enabled)) {
  1648. icb->firmware_options_2 &=
  1649. __constant_cpu_to_le32(~BIT_22);
  1650. ha->flags.disable_msix_handshake = 1;
  1651. ql_dbg(ql_dbg_init, vha, 0x00fe,
  1652. "MSIX Handshake Disable Mode turned on.\n");
  1653. } else {
  1654. icb->firmware_options_2 |=
  1655. __constant_cpu_to_le32(BIT_22);
  1656. }
  1657. icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
  1658. WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
  1659. WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
  1660. WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
  1661. WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
  1662. } else {
  1663. WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
  1664. WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
  1665. WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
  1666. WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
  1667. }
  1668. qlt_24xx_config_rings(vha);
  1669. /* PCI posting */
  1670. RD_REG_DWORD(&ioreg->hccr);
  1671. }
  1672. /**
  1673. * qla2x00_init_rings() - Initializes firmware.
  1674. * @ha: HA context
  1675. *
  1676. * Beginning of request ring has initialization control block already built
  1677. * by nvram config routine.
  1678. *
  1679. * Returns 0 on success.
  1680. */
  1681. int
  1682. qla2x00_init_rings(scsi_qla_host_t *vha)
  1683. {
  1684. int rval;
  1685. unsigned long flags = 0;
  1686. int cnt, que;
  1687. struct qla_hw_data *ha = vha->hw;
  1688. struct req_que *req;
  1689. struct rsp_que *rsp;
  1690. struct mid_init_cb_24xx *mid_init_cb =
  1691. (struct mid_init_cb_24xx *) ha->init_cb;
  1692. spin_lock_irqsave(&ha->hardware_lock, flags);
  1693. /* Clear outstanding commands array. */
  1694. for (que = 0; que < ha->max_req_queues; que++) {
  1695. req = ha->req_q_map[que];
  1696. if (!req)
  1697. continue;
  1698. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
  1699. req->outstanding_cmds[cnt] = NULL;
  1700. req->current_outstanding_cmd = 1;
  1701. /* Initialize firmware. */
  1702. req->ring_ptr = req->ring;
  1703. req->ring_index = 0;
  1704. req->cnt = req->length;
  1705. }
  1706. for (que = 0; que < ha->max_rsp_queues; que++) {
  1707. rsp = ha->rsp_q_map[que];
  1708. if (!rsp)
  1709. continue;
  1710. /* Initialize response queue entries */
  1711. if (IS_QLAFX00(ha))
  1712. qlafx00_init_response_q_entries(rsp);
  1713. else
  1714. qla2x00_init_response_q_entries(rsp);
  1715. }
  1716. ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
  1717. ha->tgt.atio_ring_index = 0;
  1718. /* Initialize ATIO queue entries */
  1719. qlt_init_atio_q_entries(vha);
  1720. ha->isp_ops->config_rings(vha);
  1721. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1722. ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
  1723. if (IS_QLAFX00(ha)) {
  1724. rval = qlafx00_init_firmware(vha, ha->init_cb_size);
  1725. goto next_check;
  1726. }
  1727. /* Update any ISP specific firmware options before initialization. */
  1728. ha->isp_ops->update_fw_options(vha);
  1729. if (ha->flags.npiv_supported) {
  1730. if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
  1731. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  1732. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  1733. }
  1734. if (IS_FWI2_CAPABLE(ha)) {
  1735. mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
  1736. mid_init_cb->init_cb.execution_throttle =
  1737. cpu_to_le16(ha->fw_xcb_count);
  1738. }
  1739. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  1740. next_check:
  1741. if (rval) {
  1742. ql_log(ql_log_fatal, vha, 0x00d2,
  1743. "Init Firmware **** FAILED ****.\n");
  1744. } else {
  1745. ql_dbg(ql_dbg_init, vha, 0x00d3,
  1746. "Init Firmware -- success.\n");
  1747. }
  1748. return (rval);
  1749. }
  1750. /**
  1751. * qla2x00_fw_ready() - Waits for firmware ready.
  1752. * @ha: HA context
  1753. *
  1754. * Returns 0 on success.
  1755. */
  1756. static int
  1757. qla2x00_fw_ready(scsi_qla_host_t *vha)
  1758. {
  1759. int rval;
  1760. unsigned long wtime, mtime, cs84xx_time;
  1761. uint16_t min_wait; /* Minimum wait time if loop is down */
  1762. uint16_t wait_time; /* Wait time if loop is coming ready */
  1763. uint16_t state[5];
  1764. struct qla_hw_data *ha = vha->hw;
  1765. if (IS_QLAFX00(vha->hw))
  1766. return qlafx00_fw_ready(vha);
  1767. rval = QLA_SUCCESS;
  1768. /* 20 seconds for loop down. */
  1769. min_wait = 20;
  1770. /*
  1771. * Firmware should take at most one RATOV to login, plus 5 seconds for
  1772. * our own processing.
  1773. */
  1774. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  1775. wait_time = min_wait;
  1776. }
  1777. /* Min wait time if loop down */
  1778. mtime = jiffies + (min_wait * HZ);
  1779. /* wait time before firmware ready */
  1780. wtime = jiffies + (wait_time * HZ);
  1781. /* Wait for ISP to finish LIP */
  1782. if (!vha->flags.init_done)
  1783. ql_log(ql_log_info, vha, 0x801e,
  1784. "Waiting for LIP to complete.\n");
  1785. do {
  1786. memset(state, -1, sizeof(state));
  1787. rval = qla2x00_get_firmware_state(vha, state);
  1788. if (rval == QLA_SUCCESS) {
  1789. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  1790. vha->device_flags &= ~DFLG_NO_CABLE;
  1791. }
  1792. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  1793. ql_dbg(ql_dbg_taskm, vha, 0x801f,
  1794. "fw_state=%x 84xx=%x.\n", state[0],
  1795. state[2]);
  1796. if ((state[2] & FSTATE_LOGGED_IN) &&
  1797. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  1798. ql_dbg(ql_dbg_taskm, vha, 0x8028,
  1799. "Sending verify iocb.\n");
  1800. cs84xx_time = jiffies;
  1801. rval = qla84xx_init_chip(vha);
  1802. if (rval != QLA_SUCCESS) {
  1803. ql_log(ql_log_warn,
  1804. vha, 0x8007,
  1805. "Init chip failed.\n");
  1806. break;
  1807. }
  1808. /* Add time taken to initialize. */
  1809. cs84xx_time = jiffies - cs84xx_time;
  1810. wtime += cs84xx_time;
  1811. mtime += cs84xx_time;
  1812. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  1813. "Increasing wait time by %ld. "
  1814. "New time %ld.\n", cs84xx_time,
  1815. wtime);
  1816. }
  1817. } else if (state[0] == FSTATE_READY) {
  1818. ql_dbg(ql_dbg_taskm, vha, 0x8037,
  1819. "F/W Ready - OK.\n");
  1820. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  1821. &ha->login_timeout, &ha->r_a_tov);
  1822. rval = QLA_SUCCESS;
  1823. break;
  1824. }
  1825. rval = QLA_FUNCTION_FAILED;
  1826. if (atomic_read(&vha->loop_down_timer) &&
  1827. state[0] != FSTATE_READY) {
  1828. /* Loop down. Timeout on min_wait for states
  1829. * other than Wait for Login.
  1830. */
  1831. if (time_after_eq(jiffies, mtime)) {
  1832. ql_log(ql_log_info, vha, 0x8038,
  1833. "Cable is unplugged...\n");
  1834. vha->device_flags |= DFLG_NO_CABLE;
  1835. break;
  1836. }
  1837. }
  1838. } else {
  1839. /* Mailbox cmd failed. Timeout on min_wait. */
  1840. if (time_after_eq(jiffies, mtime) ||
  1841. ha->flags.isp82xx_fw_hung)
  1842. break;
  1843. }
  1844. if (time_after_eq(jiffies, wtime))
  1845. break;
  1846. /* Delay for a while */
  1847. msleep(500);
  1848. } while (1);
  1849. ql_dbg(ql_dbg_taskm, vha, 0x803a,
  1850. "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
  1851. state[1], state[2], state[3], state[4], jiffies);
  1852. if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
  1853. ql_log(ql_log_warn, vha, 0x803b,
  1854. "Firmware ready **** FAILED ****.\n");
  1855. }
  1856. return (rval);
  1857. }
  1858. /*
  1859. * qla2x00_configure_hba
  1860. * Setup adapter context.
  1861. *
  1862. * Input:
  1863. * ha = adapter state pointer.
  1864. *
  1865. * Returns:
  1866. * 0 = success
  1867. *
  1868. * Context:
  1869. * Kernel context.
  1870. */
  1871. static int
  1872. qla2x00_configure_hba(scsi_qla_host_t *vha)
  1873. {
  1874. int rval;
  1875. uint16_t loop_id;
  1876. uint16_t topo;
  1877. uint16_t sw_cap;
  1878. uint8_t al_pa;
  1879. uint8_t area;
  1880. uint8_t domain;
  1881. char connect_type[22];
  1882. struct qla_hw_data *ha = vha->hw;
  1883. unsigned long flags;
  1884. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1885. /* Get host addresses. */
  1886. rval = qla2x00_get_adapter_id(vha,
  1887. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  1888. if (rval != QLA_SUCCESS) {
  1889. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  1890. IS_CNA_CAPABLE(ha) ||
  1891. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  1892. ql_dbg(ql_dbg_disc, vha, 0x2008,
  1893. "Loop is in a transition state.\n");
  1894. } else {
  1895. ql_log(ql_log_warn, vha, 0x2009,
  1896. "Unable to get host loop ID.\n");
  1897. if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
  1898. (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
  1899. ql_log(ql_log_warn, vha, 0x1151,
  1900. "Doing link init.\n");
  1901. if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
  1902. return rval;
  1903. }
  1904. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1905. }
  1906. return (rval);
  1907. }
  1908. if (topo == 4) {
  1909. ql_log(ql_log_info, vha, 0x200a,
  1910. "Cannot get topology - retrying.\n");
  1911. return (QLA_FUNCTION_FAILED);
  1912. }
  1913. vha->loop_id = loop_id;
  1914. /* initialize */
  1915. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  1916. ha->operating_mode = LOOP;
  1917. ha->switch_cap = 0;
  1918. switch (topo) {
  1919. case 0:
  1920. ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
  1921. ha->current_topology = ISP_CFG_NL;
  1922. strcpy(connect_type, "(Loop)");
  1923. break;
  1924. case 1:
  1925. ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
  1926. ha->switch_cap = sw_cap;
  1927. ha->current_topology = ISP_CFG_FL;
  1928. strcpy(connect_type, "(FL_Port)");
  1929. break;
  1930. case 2:
  1931. ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
  1932. ha->operating_mode = P2P;
  1933. ha->current_topology = ISP_CFG_N;
  1934. strcpy(connect_type, "(N_Port-to-N_Port)");
  1935. break;
  1936. case 3:
  1937. ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
  1938. ha->switch_cap = sw_cap;
  1939. ha->operating_mode = P2P;
  1940. ha->current_topology = ISP_CFG_F;
  1941. strcpy(connect_type, "(F_Port)");
  1942. break;
  1943. default:
  1944. ql_dbg(ql_dbg_disc, vha, 0x200f,
  1945. "HBA in unknown topology %x, using NL.\n", topo);
  1946. ha->current_topology = ISP_CFG_NL;
  1947. strcpy(connect_type, "(Loop)");
  1948. break;
  1949. }
  1950. /* Save Host port and loop ID. */
  1951. /* byte order - Big Endian */
  1952. vha->d_id.b.domain = domain;
  1953. vha->d_id.b.area = area;
  1954. vha->d_id.b.al_pa = al_pa;
  1955. spin_lock_irqsave(&ha->vport_slock, flags);
  1956. qlt_update_vp_map(vha, SET_AL_PA);
  1957. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1958. if (!vha->flags.init_done)
  1959. ql_log(ql_log_info, vha, 0x2010,
  1960. "Topology - %s, Host Loop address 0x%x.\n",
  1961. connect_type, vha->loop_id);
  1962. if (rval) {
  1963. ql_log(ql_log_warn, vha, 0x2011,
  1964. "%s FAILED\n", __func__);
  1965. } else {
  1966. ql_dbg(ql_dbg_disc, vha, 0x2012,
  1967. "%s success\n", __func__);
  1968. }
  1969. return(rval);
  1970. }
  1971. inline void
  1972. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  1973. char *def)
  1974. {
  1975. char *st, *en;
  1976. uint16_t index;
  1977. struct qla_hw_data *ha = vha->hw;
  1978. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  1979. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
  1980. if (memcmp(model, BINZERO, len) != 0) {
  1981. strncpy(ha->model_number, model, len);
  1982. st = en = ha->model_number;
  1983. en += len - 1;
  1984. while (en > st) {
  1985. if (*en != 0x20 && *en != 0x00)
  1986. break;
  1987. *en-- = '\0';
  1988. }
  1989. index = (ha->pdev->subsystem_device & 0xff);
  1990. if (use_tbl &&
  1991. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  1992. index < QLA_MODEL_NAMES)
  1993. strncpy(ha->model_desc,
  1994. qla2x00_model_name[index * 2 + 1],
  1995. sizeof(ha->model_desc) - 1);
  1996. } else {
  1997. index = (ha->pdev->subsystem_device & 0xff);
  1998. if (use_tbl &&
  1999. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  2000. index < QLA_MODEL_NAMES) {
  2001. strcpy(ha->model_number,
  2002. qla2x00_model_name[index * 2]);
  2003. strncpy(ha->model_desc,
  2004. qla2x00_model_name[index * 2 + 1],
  2005. sizeof(ha->model_desc) - 1);
  2006. } else {
  2007. strcpy(ha->model_number, def);
  2008. }
  2009. }
  2010. if (IS_FWI2_CAPABLE(ha))
  2011. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  2012. sizeof(ha->model_desc));
  2013. }
  2014. /* On sparc systems, obtain port and node WWN from firmware
  2015. * properties.
  2016. */
  2017. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  2018. {
  2019. #ifdef CONFIG_SPARC
  2020. struct qla_hw_data *ha = vha->hw;
  2021. struct pci_dev *pdev = ha->pdev;
  2022. struct device_node *dp = pci_device_to_OF_node(pdev);
  2023. const u8 *val;
  2024. int len;
  2025. val = of_get_property(dp, "port-wwn", &len);
  2026. if (val && len >= WWN_SIZE)
  2027. memcpy(nv->port_name, val, WWN_SIZE);
  2028. val = of_get_property(dp, "node-wwn", &len);
  2029. if (val && len >= WWN_SIZE)
  2030. memcpy(nv->node_name, val, WWN_SIZE);
  2031. #endif
  2032. }
  2033. /*
  2034. * NVRAM configuration for ISP 2xxx
  2035. *
  2036. * Input:
  2037. * ha = adapter block pointer.
  2038. *
  2039. * Output:
  2040. * initialization control block in response_ring
  2041. * host adapters parameters in host adapter block
  2042. *
  2043. * Returns:
  2044. * 0 = success.
  2045. */
  2046. int
  2047. qla2x00_nvram_config(scsi_qla_host_t *vha)
  2048. {
  2049. int rval;
  2050. uint8_t chksum = 0;
  2051. uint16_t cnt;
  2052. uint8_t *dptr1, *dptr2;
  2053. struct qla_hw_data *ha = vha->hw;
  2054. init_cb_t *icb = ha->init_cb;
  2055. nvram_t *nv = ha->nvram;
  2056. uint8_t *ptr = ha->nvram;
  2057. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2058. rval = QLA_SUCCESS;
  2059. /* Determine NVRAM starting address. */
  2060. ha->nvram_size = sizeof(nvram_t);
  2061. ha->nvram_base = 0;
  2062. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  2063. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  2064. ha->nvram_base = 0x80;
  2065. /* Get NVRAM data and calculate checksum. */
  2066. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  2067. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  2068. chksum += *ptr++;
  2069. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
  2070. "Contents of NVRAM.\n");
  2071. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
  2072. (uint8_t *)nv, ha->nvram_size);
  2073. /* Bad NVRAM data, set defaults parameters. */
  2074. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  2075. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  2076. /* Reset NVRAM data. */
  2077. ql_log(ql_log_warn, vha, 0x0064,
  2078. "Inconsistent NVRAM "
  2079. "detected: checksum=0x%x id=%c version=0x%x.\n",
  2080. chksum, nv->id[0], nv->nvram_version);
  2081. ql_log(ql_log_warn, vha, 0x0065,
  2082. "Falling back to "
  2083. "functioning (yet invalid -- WWPN) defaults.\n");
  2084. /*
  2085. * Set default initialization control block.
  2086. */
  2087. memset(nv, 0, ha->nvram_size);
  2088. nv->parameter_block_version = ICB_VERSION;
  2089. if (IS_QLA23XX(ha)) {
  2090. nv->firmware_options[0] = BIT_2 | BIT_1;
  2091. nv->firmware_options[1] = BIT_7 | BIT_5;
  2092. nv->add_firmware_options[0] = BIT_5;
  2093. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2094. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  2095. nv->special_options[1] = BIT_7;
  2096. } else if (IS_QLA2200(ha)) {
  2097. nv->firmware_options[0] = BIT_2 | BIT_1;
  2098. nv->firmware_options[1] = BIT_7 | BIT_5;
  2099. nv->add_firmware_options[0] = BIT_5;
  2100. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2101. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  2102. } else if (IS_QLA2100(ha)) {
  2103. nv->firmware_options[0] = BIT_3 | BIT_1;
  2104. nv->firmware_options[1] = BIT_5;
  2105. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  2106. }
  2107. nv->max_iocb_allocation = __constant_cpu_to_le16(256);
  2108. nv->execution_throttle = __constant_cpu_to_le16(16);
  2109. nv->retry_count = 8;
  2110. nv->retry_delay = 1;
  2111. nv->port_name[0] = 33;
  2112. nv->port_name[3] = 224;
  2113. nv->port_name[4] = 139;
  2114. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  2115. nv->login_timeout = 4;
  2116. /*
  2117. * Set default host adapter parameters
  2118. */
  2119. nv->host_p[1] = BIT_2;
  2120. nv->reset_delay = 5;
  2121. nv->port_down_retry_count = 8;
  2122. nv->max_luns_per_target = __constant_cpu_to_le16(8);
  2123. nv->link_down_timeout = 60;
  2124. rval = 1;
  2125. }
  2126. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2127. /*
  2128. * The SN2 does not provide BIOS emulation which means you can't change
  2129. * potentially bogus BIOS settings. Force the use of default settings
  2130. * for link rate and frame size. Hope that the rest of the settings
  2131. * are valid.
  2132. */
  2133. if (ia64_platform_is("sn2")) {
  2134. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  2135. if (IS_QLA23XX(ha))
  2136. nv->special_options[1] = BIT_7;
  2137. }
  2138. #endif
  2139. /* Reset Initialization control block */
  2140. memset(icb, 0, ha->init_cb_size);
  2141. /*
  2142. * Setup driver NVRAM options.
  2143. */
  2144. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  2145. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  2146. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  2147. nv->firmware_options[1] &= ~BIT_4;
  2148. if (IS_QLA23XX(ha)) {
  2149. nv->firmware_options[0] |= BIT_2;
  2150. nv->firmware_options[0] &= ~BIT_3;
  2151. nv->special_options[0] &= ~BIT_6;
  2152. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  2153. if (IS_QLA2300(ha)) {
  2154. if (ha->fb_rev == FPM_2310) {
  2155. strcpy(ha->model_number, "QLA2310");
  2156. } else {
  2157. strcpy(ha->model_number, "QLA2300");
  2158. }
  2159. } else {
  2160. qla2x00_set_model_info(vha, nv->model_number,
  2161. sizeof(nv->model_number), "QLA23xx");
  2162. }
  2163. } else if (IS_QLA2200(ha)) {
  2164. nv->firmware_options[0] |= BIT_2;
  2165. /*
  2166. * 'Point-to-point preferred, else loop' is not a safe
  2167. * connection mode setting.
  2168. */
  2169. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  2170. (BIT_5 | BIT_4)) {
  2171. /* Force 'loop preferred, else point-to-point'. */
  2172. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  2173. nv->add_firmware_options[0] |= BIT_5;
  2174. }
  2175. strcpy(ha->model_number, "QLA22xx");
  2176. } else /*if (IS_QLA2100(ha))*/ {
  2177. strcpy(ha->model_number, "QLA2100");
  2178. }
  2179. /*
  2180. * Copy over NVRAM RISC parameter block to initialization control block.
  2181. */
  2182. dptr1 = (uint8_t *)icb;
  2183. dptr2 = (uint8_t *)&nv->parameter_block_version;
  2184. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  2185. while (cnt--)
  2186. *dptr1++ = *dptr2++;
  2187. /* Copy 2nd half. */
  2188. dptr1 = (uint8_t *)icb->add_firmware_options;
  2189. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  2190. while (cnt--)
  2191. *dptr1++ = *dptr2++;
  2192. /* Use alternate WWN? */
  2193. if (nv->host_p[1] & BIT_7) {
  2194. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  2195. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  2196. }
  2197. /* Prepare nodename */
  2198. if ((icb->firmware_options[1] & BIT_6) == 0) {
  2199. /*
  2200. * Firmware will apply the following mask if the nodename was
  2201. * not provided.
  2202. */
  2203. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2204. icb->node_name[0] &= 0xF0;
  2205. }
  2206. /*
  2207. * Set host adapter parameters.
  2208. */
  2209. /*
  2210. * BIT_7 in the host-parameters section allows for modification to
  2211. * internal driver logging.
  2212. */
  2213. if (nv->host_p[0] & BIT_7)
  2214. ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
  2215. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  2216. /* Always load RISC code on non ISP2[12]00 chips. */
  2217. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2218. ha->flags.disable_risc_code_load = 0;
  2219. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  2220. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  2221. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  2222. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  2223. ha->flags.disable_serdes = 0;
  2224. ha->operating_mode =
  2225. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2226. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  2227. sizeof(ha->fw_seriallink_options));
  2228. /* save HBA serial number */
  2229. ha->serial0 = icb->port_name[5];
  2230. ha->serial1 = icb->port_name[6];
  2231. ha->serial2 = icb->port_name[7];
  2232. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  2233. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  2234. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  2235. ha->retry_count = nv->retry_count;
  2236. /* Set minimum login_timeout to 4 seconds. */
  2237. if (nv->login_timeout != ql2xlogintimeout)
  2238. nv->login_timeout = ql2xlogintimeout;
  2239. if (nv->login_timeout < 4)
  2240. nv->login_timeout = 4;
  2241. ha->login_timeout = nv->login_timeout;
  2242. icb->login_timeout = nv->login_timeout;
  2243. /* Set minimum RATOV to 100 tenths of a second. */
  2244. ha->r_a_tov = 100;
  2245. ha->loop_reset_delay = nv->reset_delay;
  2246. /* Link Down Timeout = 0:
  2247. *
  2248. * When Port Down timer expires we will start returning
  2249. * I/O's to OS with "DID_NO_CONNECT".
  2250. *
  2251. * Link Down Timeout != 0:
  2252. *
  2253. * The driver waits for the link to come up after link down
  2254. * before returning I/Os to OS with "DID_NO_CONNECT".
  2255. */
  2256. if (nv->link_down_timeout == 0) {
  2257. ha->loop_down_abort_time =
  2258. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2259. } else {
  2260. ha->link_down_timeout = nv->link_down_timeout;
  2261. ha->loop_down_abort_time =
  2262. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2263. }
  2264. /*
  2265. * Need enough time to try and get the port back.
  2266. */
  2267. ha->port_down_retry_count = nv->port_down_retry_count;
  2268. if (qlport_down_retry)
  2269. ha->port_down_retry_count = qlport_down_retry;
  2270. /* Set login_retry_count */
  2271. ha->login_retry_count = nv->retry_count;
  2272. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  2273. ha->port_down_retry_count > 3)
  2274. ha->login_retry_count = ha->port_down_retry_count;
  2275. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2276. ha->login_retry_count = ha->port_down_retry_count;
  2277. if (ql2xloginretrycount)
  2278. ha->login_retry_count = ql2xloginretrycount;
  2279. icb->lun_enables = __constant_cpu_to_le16(0);
  2280. icb->command_resource_count = 0;
  2281. icb->immediate_notify_resource_count = 0;
  2282. icb->timeout = __constant_cpu_to_le16(0);
  2283. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2284. /* Enable RIO */
  2285. icb->firmware_options[0] &= ~BIT_3;
  2286. icb->add_firmware_options[0] &=
  2287. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2288. icb->add_firmware_options[0] |= BIT_2;
  2289. icb->response_accumulation_timer = 3;
  2290. icb->interrupt_delay_timer = 5;
  2291. vha->flags.process_response_queue = 1;
  2292. } else {
  2293. /* Enable ZIO. */
  2294. if (!vha->flags.init_done) {
  2295. ha->zio_mode = icb->add_firmware_options[0] &
  2296. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2297. ha->zio_timer = icb->interrupt_delay_timer ?
  2298. icb->interrupt_delay_timer: 2;
  2299. }
  2300. icb->add_firmware_options[0] &=
  2301. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2302. vha->flags.process_response_queue = 0;
  2303. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  2304. ha->zio_mode = QLA_ZIO_MODE_6;
  2305. ql_log(ql_log_info, vha, 0x0068,
  2306. "ZIO mode %d enabled; timer delay (%d us).\n",
  2307. ha->zio_mode, ha->zio_timer * 100);
  2308. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  2309. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  2310. vha->flags.process_response_queue = 1;
  2311. }
  2312. }
  2313. if (rval) {
  2314. ql_log(ql_log_warn, vha, 0x0069,
  2315. "NVRAM configuration failed.\n");
  2316. }
  2317. return (rval);
  2318. }
  2319. static void
  2320. qla2x00_rport_del(void *data)
  2321. {
  2322. fc_port_t *fcport = data;
  2323. struct fc_rport *rport;
  2324. scsi_qla_host_t *vha = fcport->vha;
  2325. unsigned long flags;
  2326. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2327. rport = fcport->drport ? fcport->drport: fcport->rport;
  2328. fcport->drport = NULL;
  2329. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2330. if (rport) {
  2331. fc_remote_port_delete(rport);
  2332. /*
  2333. * Release the target mode FC NEXUS in qla_target.c code
  2334. * if target mod is enabled.
  2335. */
  2336. qlt_fc_port_deleted(vha, fcport);
  2337. }
  2338. }
  2339. /**
  2340. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  2341. * @ha: HA context
  2342. * @flags: allocation flags
  2343. *
  2344. * Returns a pointer to the allocated fcport, or NULL, if none available.
  2345. */
  2346. fc_port_t *
  2347. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  2348. {
  2349. fc_port_t *fcport;
  2350. fcport = kzalloc(sizeof(fc_port_t), flags);
  2351. if (!fcport)
  2352. return NULL;
  2353. /* Setup fcport template structure. */
  2354. fcport->vha = vha;
  2355. fcport->port_type = FCT_UNKNOWN;
  2356. fcport->loop_id = FC_NO_LOOP_ID;
  2357. qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
  2358. fcport->supported_classes = FC_COS_UNSPECIFIED;
  2359. return fcport;
  2360. }
  2361. /*
  2362. * qla2x00_configure_loop
  2363. * Updates Fibre Channel Device Database with what is actually on loop.
  2364. *
  2365. * Input:
  2366. * ha = adapter block pointer.
  2367. *
  2368. * Returns:
  2369. * 0 = success.
  2370. * 1 = error.
  2371. * 2 = database was full and device was not configured.
  2372. */
  2373. static int
  2374. qla2x00_configure_loop(scsi_qla_host_t *vha)
  2375. {
  2376. int rval;
  2377. unsigned long flags, save_flags;
  2378. struct qla_hw_data *ha = vha->hw;
  2379. rval = QLA_SUCCESS;
  2380. /* Get Initiator ID */
  2381. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  2382. rval = qla2x00_configure_hba(vha);
  2383. if (rval != QLA_SUCCESS) {
  2384. ql_dbg(ql_dbg_disc, vha, 0x2013,
  2385. "Unable to configure HBA.\n");
  2386. return (rval);
  2387. }
  2388. }
  2389. save_flags = flags = vha->dpc_flags;
  2390. ql_dbg(ql_dbg_disc, vha, 0x2014,
  2391. "Configure loop -- dpc flags = 0x%lx.\n", flags);
  2392. /*
  2393. * If we have both an RSCN and PORT UPDATE pending then handle them
  2394. * both at the same time.
  2395. */
  2396. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2397. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  2398. qla2x00_get_data_rate(vha);
  2399. /* Determine what we need to do */
  2400. if (ha->current_topology == ISP_CFG_FL &&
  2401. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2402. set_bit(RSCN_UPDATE, &flags);
  2403. } else if (ha->current_topology == ISP_CFG_F &&
  2404. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2405. set_bit(RSCN_UPDATE, &flags);
  2406. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  2407. } else if (ha->current_topology == ISP_CFG_N) {
  2408. clear_bit(RSCN_UPDATE, &flags);
  2409. } else if (!vha->flags.online ||
  2410. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  2411. set_bit(RSCN_UPDATE, &flags);
  2412. set_bit(LOCAL_LOOP_UPDATE, &flags);
  2413. }
  2414. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  2415. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2416. ql_dbg(ql_dbg_disc, vha, 0x2015,
  2417. "Loop resync needed, failing.\n");
  2418. rval = QLA_FUNCTION_FAILED;
  2419. } else
  2420. rval = qla2x00_configure_local_loop(vha);
  2421. }
  2422. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  2423. if (LOOP_TRANSITION(vha)) {
  2424. ql_dbg(ql_dbg_disc, vha, 0x201e,
  2425. "Needs RSCN update and loop transition.\n");
  2426. rval = QLA_FUNCTION_FAILED;
  2427. }
  2428. else
  2429. rval = qla2x00_configure_fabric(vha);
  2430. }
  2431. if (rval == QLA_SUCCESS) {
  2432. if (atomic_read(&vha->loop_down_timer) ||
  2433. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2434. rval = QLA_FUNCTION_FAILED;
  2435. } else {
  2436. atomic_set(&vha->loop_state, LOOP_READY);
  2437. ql_dbg(ql_dbg_disc, vha, 0x2069,
  2438. "LOOP READY.\n");
  2439. }
  2440. }
  2441. if (rval) {
  2442. ql_dbg(ql_dbg_disc, vha, 0x206a,
  2443. "%s *** FAILED ***.\n", __func__);
  2444. } else {
  2445. ql_dbg(ql_dbg_disc, vha, 0x206b,
  2446. "%s: exiting normally.\n", __func__);
  2447. }
  2448. /* Restore state if a resync event occurred during processing */
  2449. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2450. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  2451. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2452. if (test_bit(RSCN_UPDATE, &save_flags)) {
  2453. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2454. }
  2455. }
  2456. return (rval);
  2457. }
  2458. /*
  2459. * qla2x00_configure_local_loop
  2460. * Updates Fibre Channel Device Database with local loop devices.
  2461. *
  2462. * Input:
  2463. * ha = adapter block pointer.
  2464. *
  2465. * Returns:
  2466. * 0 = success.
  2467. */
  2468. static int
  2469. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  2470. {
  2471. int rval, rval2;
  2472. int found_devs;
  2473. int found;
  2474. fc_port_t *fcport, *new_fcport;
  2475. uint16_t index;
  2476. uint16_t entries;
  2477. char *id_iter;
  2478. uint16_t loop_id;
  2479. uint8_t domain, area, al_pa;
  2480. struct qla_hw_data *ha = vha->hw;
  2481. found_devs = 0;
  2482. new_fcport = NULL;
  2483. entries = MAX_FIBRE_DEVICES_LOOP;
  2484. /* Get list of logged in devices. */
  2485. memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
  2486. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  2487. &entries);
  2488. if (rval != QLA_SUCCESS)
  2489. goto cleanup_allocation;
  2490. ql_dbg(ql_dbg_disc, vha, 0x2017,
  2491. "Entries in ID list (%d).\n", entries);
  2492. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
  2493. (uint8_t *)ha->gid_list,
  2494. entries * sizeof(struct gid_list_info));
  2495. /* Allocate temporary fcport for any new fcports discovered. */
  2496. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2497. if (new_fcport == NULL) {
  2498. ql_log(ql_log_warn, vha, 0x2018,
  2499. "Memory allocation failed for fcport.\n");
  2500. rval = QLA_MEMORY_ALLOC_FAILED;
  2501. goto cleanup_allocation;
  2502. }
  2503. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2504. /*
  2505. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  2506. */
  2507. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2508. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2509. fcport->port_type != FCT_BROADCAST &&
  2510. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2511. ql_dbg(ql_dbg_disc, vha, 0x2019,
  2512. "Marking port lost loop_id=0x%04x.\n",
  2513. fcport->loop_id);
  2514. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2515. }
  2516. }
  2517. /* Add devices to port list. */
  2518. id_iter = (char *)ha->gid_list;
  2519. for (index = 0; index < entries; index++) {
  2520. domain = ((struct gid_list_info *)id_iter)->domain;
  2521. area = ((struct gid_list_info *)id_iter)->area;
  2522. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  2523. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2524. loop_id = (uint16_t)
  2525. ((struct gid_list_info *)id_iter)->loop_id_2100;
  2526. else
  2527. loop_id = le16_to_cpu(
  2528. ((struct gid_list_info *)id_iter)->loop_id);
  2529. id_iter += ha->gid_list_info_size;
  2530. /* Bypass reserved domain fields. */
  2531. if ((domain & 0xf0) == 0xf0)
  2532. continue;
  2533. /* Bypass if not same domain and area of adapter. */
  2534. if (area && domain &&
  2535. (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
  2536. continue;
  2537. /* Bypass invalid local loop ID. */
  2538. if (loop_id > LAST_LOCAL_LOOP_ID)
  2539. continue;
  2540. memset(new_fcport, 0, sizeof(fc_port_t));
  2541. /* Fill in member data. */
  2542. new_fcport->d_id.b.domain = domain;
  2543. new_fcport->d_id.b.area = area;
  2544. new_fcport->d_id.b.al_pa = al_pa;
  2545. new_fcport->loop_id = loop_id;
  2546. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  2547. if (rval2 != QLA_SUCCESS) {
  2548. ql_dbg(ql_dbg_disc, vha, 0x201a,
  2549. "Failed to retrieve fcport information "
  2550. "-- get_port_database=%x, loop_id=0x%04x.\n",
  2551. rval2, new_fcport->loop_id);
  2552. ql_dbg(ql_dbg_disc, vha, 0x201b,
  2553. "Scheduling resync.\n");
  2554. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2555. continue;
  2556. }
  2557. /* Check for matching device in port list. */
  2558. found = 0;
  2559. fcport = NULL;
  2560. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2561. if (memcmp(new_fcport->port_name, fcport->port_name,
  2562. WWN_SIZE))
  2563. continue;
  2564. fcport->flags &= ~FCF_FABRIC_DEVICE;
  2565. fcport->loop_id = new_fcport->loop_id;
  2566. fcport->port_type = new_fcport->port_type;
  2567. fcport->d_id.b24 = new_fcport->d_id.b24;
  2568. memcpy(fcport->node_name, new_fcport->node_name,
  2569. WWN_SIZE);
  2570. found++;
  2571. break;
  2572. }
  2573. if (!found) {
  2574. /* New device, add to fcports list. */
  2575. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  2576. /* Allocate a new replacement fcport. */
  2577. fcport = new_fcport;
  2578. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2579. if (new_fcport == NULL) {
  2580. ql_log(ql_log_warn, vha, 0x201c,
  2581. "Failed to allocate memory for fcport.\n");
  2582. rval = QLA_MEMORY_ALLOC_FAILED;
  2583. goto cleanup_allocation;
  2584. }
  2585. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2586. }
  2587. /* Base iIDMA settings on HBA port speed. */
  2588. fcport->fp_speed = ha->link_data_rate;
  2589. qla2x00_update_fcport(vha, fcport);
  2590. found_devs++;
  2591. }
  2592. cleanup_allocation:
  2593. kfree(new_fcport);
  2594. if (rval != QLA_SUCCESS) {
  2595. ql_dbg(ql_dbg_disc, vha, 0x201d,
  2596. "Configure local loop error exit: rval=%x.\n", rval);
  2597. }
  2598. return (rval);
  2599. }
  2600. static void
  2601. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2602. {
  2603. int rval;
  2604. uint16_t mb[4];
  2605. struct qla_hw_data *ha = vha->hw;
  2606. if (!IS_IIDMA_CAPABLE(ha))
  2607. return;
  2608. if (atomic_read(&fcport->state) != FCS_ONLINE)
  2609. return;
  2610. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  2611. fcport->fp_speed > ha->link_data_rate)
  2612. return;
  2613. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  2614. mb);
  2615. if (rval != QLA_SUCCESS) {
  2616. ql_dbg(ql_dbg_disc, vha, 0x2004,
  2617. "Unable to adjust iIDMA "
  2618. "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
  2619. "%04x.\n", fcport->port_name[0], fcport->port_name[1],
  2620. fcport->port_name[2], fcport->port_name[3],
  2621. fcport->port_name[4], fcport->port_name[5],
  2622. fcport->port_name[6], fcport->port_name[7], rval,
  2623. fcport->fp_speed, mb[0], mb[1]);
  2624. } else {
  2625. ql_dbg(ql_dbg_disc, vha, 0x2005,
  2626. "iIDMA adjusted to %s GB/s "
  2627. "on %02x%02x%02x%02x%02x%02x%02x%02x.\n",
  2628. qla2x00_get_link_speed_str(ha, fcport->fp_speed),
  2629. fcport->port_name[0], fcport->port_name[1],
  2630. fcport->port_name[2], fcport->port_name[3],
  2631. fcport->port_name[4], fcport->port_name[5],
  2632. fcport->port_name[6], fcport->port_name[7]);
  2633. }
  2634. }
  2635. static void
  2636. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  2637. {
  2638. struct fc_rport_identifiers rport_ids;
  2639. struct fc_rport *rport;
  2640. unsigned long flags;
  2641. qla2x00_rport_del(fcport);
  2642. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  2643. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  2644. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  2645. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  2646. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2647. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  2648. if (!rport) {
  2649. ql_log(ql_log_warn, vha, 0x2006,
  2650. "Unable to allocate fc remote port.\n");
  2651. return;
  2652. }
  2653. /*
  2654. * Create target mode FC NEXUS in qla_target.c if target mode is
  2655. * enabled..
  2656. */
  2657. qlt_fc_port_added(vha, fcport);
  2658. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2659. *((fc_port_t **)rport->dd_data) = fcport;
  2660. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2661. rport->supported_classes = fcport->supported_classes;
  2662. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2663. if (fcport->port_type == FCT_INITIATOR)
  2664. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2665. if (fcport->port_type == FCT_TARGET)
  2666. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2667. fc_remote_port_rolechg(rport, rport_ids.roles);
  2668. }
  2669. /*
  2670. * qla2x00_update_fcport
  2671. * Updates device on list.
  2672. *
  2673. * Input:
  2674. * ha = adapter block pointer.
  2675. * fcport = port structure pointer.
  2676. *
  2677. * Return:
  2678. * 0 - Success
  2679. * BIT_0 - error
  2680. *
  2681. * Context:
  2682. * Kernel context.
  2683. */
  2684. void
  2685. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2686. {
  2687. fcport->vha = vha;
  2688. if (IS_QLAFX00(vha->hw)) {
  2689. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2690. qla2x00_reg_remote_port(vha, fcport);
  2691. return;
  2692. }
  2693. fcport->login_retry = 0;
  2694. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  2695. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2696. qla2x00_iidma_fcport(vha, fcport);
  2697. qla24xx_update_fcport_fcp_prio(vha, fcport);
  2698. qla2x00_reg_remote_port(vha, fcport);
  2699. }
  2700. /*
  2701. * qla2x00_configure_fabric
  2702. * Setup SNS devices with loop ID's.
  2703. *
  2704. * Input:
  2705. * ha = adapter block pointer.
  2706. *
  2707. * Returns:
  2708. * 0 = success.
  2709. * BIT_0 = error
  2710. */
  2711. static int
  2712. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  2713. {
  2714. int rval;
  2715. fc_port_t *fcport, *fcptemp;
  2716. uint16_t next_loopid;
  2717. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2718. uint16_t loop_id;
  2719. LIST_HEAD(new_fcports);
  2720. struct qla_hw_data *ha = vha->hw;
  2721. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2722. /* If FL port exists, then SNS is present */
  2723. if (IS_FWI2_CAPABLE(ha))
  2724. loop_id = NPH_F_PORT;
  2725. else
  2726. loop_id = SNS_FL_PORT;
  2727. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  2728. if (rval != QLA_SUCCESS) {
  2729. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2730. "MBX_GET_PORT_NAME failed, No FL Port.\n");
  2731. vha->device_flags &= ~SWITCH_FOUND;
  2732. return (QLA_SUCCESS);
  2733. }
  2734. vha->device_flags |= SWITCH_FOUND;
  2735. do {
  2736. /* FDMI support. */
  2737. if (ql2xfdmienable &&
  2738. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  2739. qla2x00_fdmi_register(vha);
  2740. /* Ensure we are logged into the SNS. */
  2741. if (IS_FWI2_CAPABLE(ha))
  2742. loop_id = NPH_SNS;
  2743. else
  2744. loop_id = SIMPLE_NAME_SERVER;
  2745. rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  2746. 0xfc, mb, BIT_1|BIT_0);
  2747. if (rval != QLA_SUCCESS) {
  2748. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2749. return rval;
  2750. }
  2751. if (mb[0] != MBS_COMMAND_COMPLETE) {
  2752. ql_dbg(ql_dbg_disc, vha, 0x2042,
  2753. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
  2754. "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
  2755. mb[2], mb[6], mb[7]);
  2756. return (QLA_SUCCESS);
  2757. }
  2758. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  2759. if (qla2x00_rft_id(vha)) {
  2760. /* EMPTY */
  2761. ql_dbg(ql_dbg_disc, vha, 0x2045,
  2762. "Register FC-4 TYPE failed.\n");
  2763. }
  2764. if (qla2x00_rff_id(vha)) {
  2765. /* EMPTY */
  2766. ql_dbg(ql_dbg_disc, vha, 0x2049,
  2767. "Register FC-4 Features failed.\n");
  2768. }
  2769. if (qla2x00_rnn_id(vha)) {
  2770. /* EMPTY */
  2771. ql_dbg(ql_dbg_disc, vha, 0x204f,
  2772. "Register Node Name failed.\n");
  2773. } else if (qla2x00_rsnn_nn(vha)) {
  2774. /* EMPTY */
  2775. ql_dbg(ql_dbg_disc, vha, 0x2053,
  2776. "Register Symobilic Node Name failed.\n");
  2777. }
  2778. }
  2779. #define QLA_FCPORT_SCAN 1
  2780. #define QLA_FCPORT_FOUND 2
  2781. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2782. fcport->scan_state = QLA_FCPORT_SCAN;
  2783. }
  2784. rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
  2785. if (rval != QLA_SUCCESS)
  2786. break;
  2787. /*
  2788. * Logout all previous fabric devices marked lost, except
  2789. * FCP2 devices.
  2790. */
  2791. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2792. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2793. break;
  2794. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  2795. continue;
  2796. if (fcport->scan_state == QLA_FCPORT_SCAN &&
  2797. atomic_read(&fcport->state) == FCS_ONLINE) {
  2798. qla2x00_mark_device_lost(vha, fcport,
  2799. ql2xplogiabsentdevice, 0);
  2800. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2801. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  2802. fcport->port_type != FCT_INITIATOR &&
  2803. fcport->port_type != FCT_BROADCAST) {
  2804. ha->isp_ops->fabric_logout(vha,
  2805. fcport->loop_id,
  2806. fcport->d_id.b.domain,
  2807. fcport->d_id.b.area,
  2808. fcport->d_id.b.al_pa);
  2809. fcport->loop_id = FC_NO_LOOP_ID;
  2810. }
  2811. }
  2812. }
  2813. /* Starting free loop ID. */
  2814. next_loopid = ha->min_external_loopid;
  2815. /*
  2816. * Scan through our port list and login entries that need to be
  2817. * logged in.
  2818. */
  2819. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2820. if (atomic_read(&vha->loop_down_timer) ||
  2821. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2822. break;
  2823. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  2824. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  2825. continue;
  2826. if (fcport->loop_id == FC_NO_LOOP_ID) {
  2827. fcport->loop_id = next_loopid;
  2828. rval = qla2x00_find_new_loop_id(
  2829. base_vha, fcport);
  2830. if (rval != QLA_SUCCESS) {
  2831. /* Ran out of IDs to use */
  2832. break;
  2833. }
  2834. }
  2835. /* Login and update database */
  2836. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2837. }
  2838. /* Exit if out of loop IDs. */
  2839. if (rval != QLA_SUCCESS) {
  2840. break;
  2841. }
  2842. /*
  2843. * Login and add the new devices to our port list.
  2844. */
  2845. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2846. if (atomic_read(&vha->loop_down_timer) ||
  2847. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2848. break;
  2849. /* Find a new loop ID to use. */
  2850. fcport->loop_id = next_loopid;
  2851. rval = qla2x00_find_new_loop_id(base_vha, fcport);
  2852. if (rval != QLA_SUCCESS) {
  2853. /* Ran out of IDs to use */
  2854. break;
  2855. }
  2856. /* Login and update database */
  2857. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2858. list_move_tail(&fcport->list, &vha->vp_fcports);
  2859. }
  2860. } while (0);
  2861. /* Free all new device structures not processed. */
  2862. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2863. list_del(&fcport->list);
  2864. kfree(fcport);
  2865. }
  2866. if (rval) {
  2867. ql_dbg(ql_dbg_disc, vha, 0x2068,
  2868. "Configure fabric error exit rval=%d.\n", rval);
  2869. }
  2870. return (rval);
  2871. }
  2872. /*
  2873. * qla2x00_find_all_fabric_devs
  2874. *
  2875. * Input:
  2876. * ha = adapter block pointer.
  2877. * dev = database device entry pointer.
  2878. *
  2879. * Returns:
  2880. * 0 = success.
  2881. *
  2882. * Context:
  2883. * Kernel context.
  2884. */
  2885. static int
  2886. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
  2887. struct list_head *new_fcports)
  2888. {
  2889. int rval;
  2890. uint16_t loop_id;
  2891. fc_port_t *fcport, *new_fcport, *fcptemp;
  2892. int found;
  2893. sw_info_t *swl;
  2894. int swl_idx;
  2895. int first_dev, last_dev;
  2896. port_id_t wrap = {}, nxt_d_id;
  2897. struct qla_hw_data *ha = vha->hw;
  2898. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2899. rval = QLA_SUCCESS;
  2900. /* Try GID_PT to get device list, else GAN. */
  2901. if (!ha->swl)
  2902. ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
  2903. GFP_KERNEL);
  2904. swl = ha->swl;
  2905. if (!swl) {
  2906. /*EMPTY*/
  2907. ql_dbg(ql_dbg_disc, vha, 0x2054,
  2908. "GID_PT allocations failed, fallback on GA_NXT.\n");
  2909. } else {
  2910. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  2911. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  2912. swl = NULL;
  2913. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  2914. swl = NULL;
  2915. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  2916. swl = NULL;
  2917. } else if (ql2xiidmaenable &&
  2918. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  2919. qla2x00_gpsc(vha, swl);
  2920. }
  2921. /* If other queries succeeded probe for FC-4 type */
  2922. if (swl)
  2923. qla2x00_gff_id(vha, swl);
  2924. }
  2925. swl_idx = 0;
  2926. /* Allocate temporary fcport for any new fcports discovered. */
  2927. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2928. if (new_fcport == NULL) {
  2929. ql_log(ql_log_warn, vha, 0x205e,
  2930. "Failed to allocate memory for fcport.\n");
  2931. return (QLA_MEMORY_ALLOC_FAILED);
  2932. }
  2933. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2934. /* Set start port ID scan at adapter ID. */
  2935. first_dev = 1;
  2936. last_dev = 0;
  2937. /* Starting free loop ID. */
  2938. loop_id = ha->min_external_loopid;
  2939. for (; loop_id <= ha->max_loop_id; loop_id++) {
  2940. if (qla2x00_is_reserved_id(vha, loop_id))
  2941. continue;
  2942. if (ha->current_topology == ISP_CFG_FL &&
  2943. (atomic_read(&vha->loop_down_timer) ||
  2944. LOOP_TRANSITION(vha))) {
  2945. atomic_set(&vha->loop_down_timer, 0);
  2946. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2947. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2948. break;
  2949. }
  2950. if (swl != NULL) {
  2951. if (last_dev) {
  2952. wrap.b24 = new_fcport->d_id.b24;
  2953. } else {
  2954. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  2955. memcpy(new_fcport->node_name,
  2956. swl[swl_idx].node_name, WWN_SIZE);
  2957. memcpy(new_fcport->port_name,
  2958. swl[swl_idx].port_name, WWN_SIZE);
  2959. memcpy(new_fcport->fabric_port_name,
  2960. swl[swl_idx].fabric_port_name, WWN_SIZE);
  2961. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  2962. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  2963. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  2964. last_dev = 1;
  2965. }
  2966. swl_idx++;
  2967. }
  2968. } else {
  2969. /* Send GA_NXT to the switch */
  2970. rval = qla2x00_ga_nxt(vha, new_fcport);
  2971. if (rval != QLA_SUCCESS) {
  2972. ql_log(ql_log_warn, vha, 0x2064,
  2973. "SNS scan failed -- assuming "
  2974. "zero-entry result.\n");
  2975. list_for_each_entry_safe(fcport, fcptemp,
  2976. new_fcports, list) {
  2977. list_del(&fcport->list);
  2978. kfree(fcport);
  2979. }
  2980. rval = QLA_SUCCESS;
  2981. break;
  2982. }
  2983. }
  2984. /* If wrap on switch device list, exit. */
  2985. if (first_dev) {
  2986. wrap.b24 = new_fcport->d_id.b24;
  2987. first_dev = 0;
  2988. } else if (new_fcport->d_id.b24 == wrap.b24) {
  2989. ql_dbg(ql_dbg_disc, vha, 0x2065,
  2990. "Device wrap (%02x%02x%02x).\n",
  2991. new_fcport->d_id.b.domain,
  2992. new_fcport->d_id.b.area,
  2993. new_fcport->d_id.b.al_pa);
  2994. break;
  2995. }
  2996. /* Bypass if same physical adapter. */
  2997. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  2998. continue;
  2999. /* Bypass virtual ports of the same host. */
  3000. if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
  3001. continue;
  3002. /* Bypass if same domain and area of adapter. */
  3003. if (((new_fcport->d_id.b24 & 0xffff00) ==
  3004. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  3005. ISP_CFG_FL)
  3006. continue;
  3007. /* Bypass reserved domain fields. */
  3008. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  3009. continue;
  3010. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  3011. if (ql2xgffidenable &&
  3012. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  3013. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  3014. continue;
  3015. /* Locate matching device in database. */
  3016. found = 0;
  3017. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3018. if (memcmp(new_fcport->port_name, fcport->port_name,
  3019. WWN_SIZE))
  3020. continue;
  3021. fcport->scan_state = QLA_FCPORT_FOUND;
  3022. found++;
  3023. /* Update port state. */
  3024. memcpy(fcport->fabric_port_name,
  3025. new_fcport->fabric_port_name, WWN_SIZE);
  3026. fcport->fp_speed = new_fcport->fp_speed;
  3027. /*
  3028. * If address the same and state FCS_ONLINE, nothing
  3029. * changed.
  3030. */
  3031. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  3032. atomic_read(&fcport->state) == FCS_ONLINE) {
  3033. break;
  3034. }
  3035. /*
  3036. * If device was not a fabric device before.
  3037. */
  3038. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3039. fcport->d_id.b24 = new_fcport->d_id.b24;
  3040. qla2x00_clear_loop_id(fcport);
  3041. fcport->flags |= (FCF_FABRIC_DEVICE |
  3042. FCF_LOGIN_NEEDED);
  3043. break;
  3044. }
  3045. /*
  3046. * Port ID changed or device was marked to be updated;
  3047. * Log it out if still logged in and mark it for
  3048. * relogin later.
  3049. */
  3050. fcport->d_id.b24 = new_fcport->d_id.b24;
  3051. fcport->flags |= FCF_LOGIN_NEEDED;
  3052. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3053. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3054. (fcport->flags & FCF_ASYNC_SENT) == 0 &&
  3055. fcport->port_type != FCT_INITIATOR &&
  3056. fcport->port_type != FCT_BROADCAST) {
  3057. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3058. fcport->d_id.b.domain, fcport->d_id.b.area,
  3059. fcport->d_id.b.al_pa);
  3060. qla2x00_clear_loop_id(fcport);
  3061. }
  3062. break;
  3063. }
  3064. if (found)
  3065. continue;
  3066. /* If device was not in our fcports list, then add it. */
  3067. list_add_tail(&new_fcport->list, new_fcports);
  3068. /* Allocate a new replacement fcport. */
  3069. nxt_d_id.b24 = new_fcport->d_id.b24;
  3070. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3071. if (new_fcport == NULL) {
  3072. ql_log(ql_log_warn, vha, 0x2066,
  3073. "Memory allocation failed for fcport.\n");
  3074. return (QLA_MEMORY_ALLOC_FAILED);
  3075. }
  3076. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3077. new_fcport->d_id.b24 = nxt_d_id.b24;
  3078. }
  3079. kfree(new_fcport);
  3080. return (rval);
  3081. }
  3082. /*
  3083. * qla2x00_find_new_loop_id
  3084. * Scan through our port list and find a new usable loop ID.
  3085. *
  3086. * Input:
  3087. * ha: adapter state pointer.
  3088. * dev: port structure pointer.
  3089. *
  3090. * Returns:
  3091. * qla2x00 local function return status code.
  3092. *
  3093. * Context:
  3094. * Kernel context.
  3095. */
  3096. int
  3097. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  3098. {
  3099. int rval;
  3100. struct qla_hw_data *ha = vha->hw;
  3101. unsigned long flags = 0;
  3102. rval = QLA_SUCCESS;
  3103. spin_lock_irqsave(&ha->vport_slock, flags);
  3104. dev->loop_id = find_first_zero_bit(ha->loop_id_map,
  3105. LOOPID_MAP_SIZE);
  3106. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  3107. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  3108. dev->loop_id = FC_NO_LOOP_ID;
  3109. rval = QLA_FUNCTION_FAILED;
  3110. } else
  3111. set_bit(dev->loop_id, ha->loop_id_map);
  3112. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3113. if (rval == QLA_SUCCESS)
  3114. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  3115. "Assigning new loopid=%x, portid=%x.\n",
  3116. dev->loop_id, dev->d_id.b24);
  3117. else
  3118. ql_log(ql_log_warn, dev->vha, 0x2087,
  3119. "No loop_id's available, portid=%x.\n",
  3120. dev->d_id.b24);
  3121. return (rval);
  3122. }
  3123. /*
  3124. * qla2x00_fabric_dev_login
  3125. * Login fabric target device and update FC port database.
  3126. *
  3127. * Input:
  3128. * ha: adapter state pointer.
  3129. * fcport: port structure list pointer.
  3130. * next_loopid: contains value of a new loop ID that can be used
  3131. * by the next login attempt.
  3132. *
  3133. * Returns:
  3134. * qla2x00 local function return status code.
  3135. *
  3136. * Context:
  3137. * Kernel context.
  3138. */
  3139. static int
  3140. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3141. uint16_t *next_loopid)
  3142. {
  3143. int rval;
  3144. int retry;
  3145. uint8_t opts;
  3146. struct qla_hw_data *ha = vha->hw;
  3147. rval = QLA_SUCCESS;
  3148. retry = 0;
  3149. if (IS_ALOGIO_CAPABLE(ha)) {
  3150. if (fcport->flags & FCF_ASYNC_SENT)
  3151. return rval;
  3152. fcport->flags |= FCF_ASYNC_SENT;
  3153. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3154. if (!rval)
  3155. return rval;
  3156. }
  3157. fcport->flags &= ~FCF_ASYNC_SENT;
  3158. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3159. if (rval == QLA_SUCCESS) {
  3160. /* Send an ADISC to FCP2 devices.*/
  3161. opts = 0;
  3162. if (fcport->flags & FCF_FCP2_DEVICE)
  3163. opts |= BIT_1;
  3164. rval = qla2x00_get_port_database(vha, fcport, opts);
  3165. if (rval != QLA_SUCCESS) {
  3166. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3167. fcport->d_id.b.domain, fcport->d_id.b.area,
  3168. fcport->d_id.b.al_pa);
  3169. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3170. } else {
  3171. qla2x00_update_fcport(vha, fcport);
  3172. }
  3173. } else {
  3174. /* Retry Login. */
  3175. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3176. }
  3177. return (rval);
  3178. }
  3179. /*
  3180. * qla2x00_fabric_login
  3181. * Issue fabric login command.
  3182. *
  3183. * Input:
  3184. * ha = adapter block pointer.
  3185. * device = pointer to FC device type structure.
  3186. *
  3187. * Returns:
  3188. * 0 - Login successfully
  3189. * 1 - Login failed
  3190. * 2 - Initiator device
  3191. * 3 - Fatal error
  3192. */
  3193. int
  3194. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3195. uint16_t *next_loopid)
  3196. {
  3197. int rval;
  3198. int retry;
  3199. uint16_t tmp_loopid;
  3200. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3201. struct qla_hw_data *ha = vha->hw;
  3202. retry = 0;
  3203. tmp_loopid = 0;
  3204. for (;;) {
  3205. ql_dbg(ql_dbg_disc, vha, 0x2000,
  3206. "Trying Fabric Login w/loop id 0x%04x for port "
  3207. "%02x%02x%02x.\n",
  3208. fcport->loop_id, fcport->d_id.b.domain,
  3209. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3210. /* Login fcport on switch. */
  3211. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3212. fcport->d_id.b.domain, fcport->d_id.b.area,
  3213. fcport->d_id.b.al_pa, mb, BIT_0);
  3214. if (rval != QLA_SUCCESS) {
  3215. return rval;
  3216. }
  3217. if (mb[0] == MBS_PORT_ID_USED) {
  3218. /*
  3219. * Device has another loop ID. The firmware team
  3220. * recommends the driver perform an implicit login with
  3221. * the specified ID again. The ID we just used is save
  3222. * here so we return with an ID that can be tried by
  3223. * the next login.
  3224. */
  3225. retry++;
  3226. tmp_loopid = fcport->loop_id;
  3227. fcport->loop_id = mb[1];
  3228. ql_dbg(ql_dbg_disc, vha, 0x2001,
  3229. "Fabric Login: port in use - next loop "
  3230. "id=0x%04x, port id= %02x%02x%02x.\n",
  3231. fcport->loop_id, fcport->d_id.b.domain,
  3232. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3233. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3234. /*
  3235. * Login succeeded.
  3236. */
  3237. if (retry) {
  3238. /* A retry occurred before. */
  3239. *next_loopid = tmp_loopid;
  3240. } else {
  3241. /*
  3242. * No retry occurred before. Just increment the
  3243. * ID value for next login.
  3244. */
  3245. *next_loopid = (fcport->loop_id + 1);
  3246. }
  3247. if (mb[1] & BIT_0) {
  3248. fcport->port_type = FCT_INITIATOR;
  3249. } else {
  3250. fcport->port_type = FCT_TARGET;
  3251. if (mb[1] & BIT_1) {
  3252. fcport->flags |= FCF_FCP2_DEVICE;
  3253. }
  3254. }
  3255. if (mb[10] & BIT_0)
  3256. fcport->supported_classes |= FC_COS_CLASS2;
  3257. if (mb[10] & BIT_1)
  3258. fcport->supported_classes |= FC_COS_CLASS3;
  3259. if (IS_FWI2_CAPABLE(ha)) {
  3260. if (mb[10] & BIT_7)
  3261. fcport->flags |=
  3262. FCF_CONF_COMP_SUPPORTED;
  3263. }
  3264. rval = QLA_SUCCESS;
  3265. break;
  3266. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3267. /*
  3268. * Loop ID already used, try next loop ID.
  3269. */
  3270. fcport->loop_id++;
  3271. rval = qla2x00_find_new_loop_id(vha, fcport);
  3272. if (rval != QLA_SUCCESS) {
  3273. /* Ran out of loop IDs to use */
  3274. break;
  3275. }
  3276. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3277. /*
  3278. * Firmware possibly timed out during login. If NO
  3279. * retries are left to do then the device is declared
  3280. * dead.
  3281. */
  3282. *next_loopid = fcport->loop_id;
  3283. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3284. fcport->d_id.b.domain, fcport->d_id.b.area,
  3285. fcport->d_id.b.al_pa);
  3286. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3287. rval = 1;
  3288. break;
  3289. } else {
  3290. /*
  3291. * unrecoverable / not handled error
  3292. */
  3293. ql_dbg(ql_dbg_disc, vha, 0x2002,
  3294. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  3295. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  3296. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  3297. fcport->loop_id, jiffies);
  3298. *next_loopid = fcport->loop_id;
  3299. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3300. fcport->d_id.b.domain, fcport->d_id.b.area,
  3301. fcport->d_id.b.al_pa);
  3302. qla2x00_clear_loop_id(fcport);
  3303. fcport->login_retry = 0;
  3304. rval = 3;
  3305. break;
  3306. }
  3307. }
  3308. return (rval);
  3309. }
  3310. /*
  3311. * qla2x00_local_device_login
  3312. * Issue local device login command.
  3313. *
  3314. * Input:
  3315. * ha = adapter block pointer.
  3316. * loop_id = loop id of device to login to.
  3317. *
  3318. * Returns (Where's the #define!!!!):
  3319. * 0 - Login successfully
  3320. * 1 - Login failed
  3321. * 3 - Fatal error
  3322. */
  3323. int
  3324. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3325. {
  3326. int rval;
  3327. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3328. memset(mb, 0, sizeof(mb));
  3329. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3330. if (rval == QLA_SUCCESS) {
  3331. /* Interrogate mailbox registers for any errors */
  3332. if (mb[0] == MBS_COMMAND_ERROR)
  3333. rval = 1;
  3334. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3335. /* device not in PCB table */
  3336. rval = 3;
  3337. }
  3338. return (rval);
  3339. }
  3340. /*
  3341. * qla2x00_loop_resync
  3342. * Resync with fibre channel devices.
  3343. *
  3344. * Input:
  3345. * ha = adapter block pointer.
  3346. *
  3347. * Returns:
  3348. * 0 = success
  3349. */
  3350. int
  3351. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3352. {
  3353. int rval = QLA_SUCCESS;
  3354. uint32_t wait_time;
  3355. struct req_que *req;
  3356. struct rsp_que *rsp;
  3357. if (vha->hw->flags.cpu_affinity_enabled)
  3358. req = vha->hw->req_q_map[0];
  3359. else
  3360. req = vha->req;
  3361. rsp = req->rsp;
  3362. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3363. if (vha->flags.online) {
  3364. if (!(rval = qla2x00_fw_ready(vha))) {
  3365. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3366. wait_time = 256;
  3367. do {
  3368. if (!IS_QLAFX00(vha->hw)) {
  3369. /*
  3370. * Issue a marker after FW becomes
  3371. * ready.
  3372. */
  3373. qla2x00_marker(vha, req, rsp, 0, 0,
  3374. MK_SYNC_ALL);
  3375. vha->marker_needed = 0;
  3376. }
  3377. /* Remap devices on Loop. */
  3378. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3379. if (IS_QLAFX00(vha->hw))
  3380. qlafx00_configure_devices(vha);
  3381. else
  3382. qla2x00_configure_loop(vha);
  3383. wait_time--;
  3384. } while (!atomic_read(&vha->loop_down_timer) &&
  3385. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3386. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3387. &vha->dpc_flags)));
  3388. }
  3389. }
  3390. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3391. return (QLA_FUNCTION_FAILED);
  3392. if (rval)
  3393. ql_dbg(ql_dbg_disc, vha, 0x206c,
  3394. "%s *** FAILED ***.\n", __func__);
  3395. return (rval);
  3396. }
  3397. /*
  3398. * qla2x00_perform_loop_resync
  3399. * Description: This function will set the appropriate flags and call
  3400. * qla2x00_loop_resync. If successful loop will be resynced
  3401. * Arguments : scsi_qla_host_t pointer
  3402. * returm : Success or Failure
  3403. */
  3404. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3405. {
  3406. int32_t rval = 0;
  3407. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3408. /*Configure the flags so that resync happens properly*/
  3409. atomic_set(&ha->loop_down_timer, 0);
  3410. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3411. atomic_set(&ha->loop_state, LOOP_UP);
  3412. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3413. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3414. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3415. rval = qla2x00_loop_resync(ha);
  3416. } else
  3417. atomic_set(&ha->loop_state, LOOP_DEAD);
  3418. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3419. }
  3420. return rval;
  3421. }
  3422. void
  3423. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3424. {
  3425. fc_port_t *fcport;
  3426. struct scsi_qla_host *vha;
  3427. struct qla_hw_data *ha = base_vha->hw;
  3428. unsigned long flags;
  3429. spin_lock_irqsave(&ha->vport_slock, flags);
  3430. /* Go with deferred removal of rport references. */
  3431. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3432. atomic_inc(&vha->vref_count);
  3433. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3434. if (fcport->drport &&
  3435. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3436. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3437. qla2x00_rport_del(fcport);
  3438. spin_lock_irqsave(&ha->vport_slock, flags);
  3439. }
  3440. }
  3441. atomic_dec(&vha->vref_count);
  3442. }
  3443. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3444. }
  3445. /* Assumes idc_lock always held on entry */
  3446. void
  3447. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  3448. {
  3449. struct qla_hw_data *ha = vha->hw;
  3450. uint32_t drv_presence, drv_presence_mask;
  3451. uint32_t dev_part_info1, dev_part_info2, class_type;
  3452. uint32_t class_type_mask = 0x3;
  3453. uint16_t fcoe_other_function = 0xffff, i;
  3454. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3455. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  3456. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  3457. for (i = 0; i < 8; i++) {
  3458. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  3459. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3460. (i != ha->portnum)) {
  3461. fcoe_other_function = i;
  3462. break;
  3463. }
  3464. }
  3465. if (fcoe_other_function == 0xffff) {
  3466. for (i = 0; i < 8; i++) {
  3467. class_type = ((dev_part_info2 >> (i * 4)) &
  3468. class_type_mask);
  3469. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3470. ((i + 8) != ha->portnum)) {
  3471. fcoe_other_function = i + 8;
  3472. break;
  3473. }
  3474. }
  3475. }
  3476. /*
  3477. * Prepare drv-presence mask based on fcoe functions present.
  3478. * However consider only valid physical fcoe function numbers (0-15).
  3479. */
  3480. drv_presence_mask = ~((1 << (ha->portnum)) |
  3481. ((fcoe_other_function == 0xffff) ?
  3482. 0 : (1 << (fcoe_other_function))));
  3483. /* We are the reset owner iff:
  3484. * - No other protocol drivers present.
  3485. * - This is the lowest among fcoe functions. */
  3486. if (!(drv_presence & drv_presence_mask) &&
  3487. (ha->portnum < fcoe_other_function)) {
  3488. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  3489. "This host is Reset owner.\n");
  3490. ha->flags.nic_core_reset_owner = 1;
  3491. }
  3492. }
  3493. static int
  3494. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  3495. {
  3496. int rval = QLA_SUCCESS;
  3497. struct qla_hw_data *ha = vha->hw;
  3498. uint32_t drv_ack;
  3499. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3500. if (rval == QLA_SUCCESS) {
  3501. drv_ack |= (1 << ha->portnum);
  3502. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3503. }
  3504. return rval;
  3505. }
  3506. static int
  3507. __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
  3508. {
  3509. int rval = QLA_SUCCESS;
  3510. struct qla_hw_data *ha = vha->hw;
  3511. uint32_t drv_ack;
  3512. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3513. if (rval == QLA_SUCCESS) {
  3514. drv_ack &= ~(1 << ha->portnum);
  3515. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3516. }
  3517. return rval;
  3518. }
  3519. static const char *
  3520. qla83xx_dev_state_to_string(uint32_t dev_state)
  3521. {
  3522. switch (dev_state) {
  3523. case QLA8XXX_DEV_COLD:
  3524. return "COLD/RE-INIT";
  3525. case QLA8XXX_DEV_INITIALIZING:
  3526. return "INITIALIZING";
  3527. case QLA8XXX_DEV_READY:
  3528. return "READY";
  3529. case QLA8XXX_DEV_NEED_RESET:
  3530. return "NEED RESET";
  3531. case QLA8XXX_DEV_NEED_QUIESCENT:
  3532. return "NEED QUIESCENT";
  3533. case QLA8XXX_DEV_FAILED:
  3534. return "FAILED";
  3535. case QLA8XXX_DEV_QUIESCENT:
  3536. return "QUIESCENT";
  3537. default:
  3538. return "Unknown";
  3539. }
  3540. }
  3541. /* Assumes idc-lock always held on entry */
  3542. void
  3543. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  3544. {
  3545. struct qla_hw_data *ha = vha->hw;
  3546. uint32_t idc_audit_reg = 0, duration_secs = 0;
  3547. switch (audit_type) {
  3548. case IDC_AUDIT_TIMESTAMP:
  3549. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  3550. idc_audit_reg = (ha->portnum) |
  3551. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  3552. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3553. break;
  3554. case IDC_AUDIT_COMPLETION:
  3555. duration_secs = ((jiffies_to_msecs(jiffies) -
  3556. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  3557. idc_audit_reg = (ha->portnum) |
  3558. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  3559. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3560. break;
  3561. default:
  3562. ql_log(ql_log_warn, vha, 0xb078,
  3563. "Invalid audit type specified.\n");
  3564. break;
  3565. }
  3566. }
  3567. /* Assumes idc_lock always held on entry */
  3568. static int
  3569. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  3570. {
  3571. struct qla_hw_data *ha = vha->hw;
  3572. uint32_t idc_control, dev_state;
  3573. __qla83xx_get_idc_control(vha, &idc_control);
  3574. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  3575. ql_log(ql_log_info, vha, 0xb080,
  3576. "NIC Core reset has been disabled. idc-control=0x%x\n",
  3577. idc_control);
  3578. return QLA_FUNCTION_FAILED;
  3579. }
  3580. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  3581. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3582. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  3583. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  3584. QLA8XXX_DEV_NEED_RESET);
  3585. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  3586. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  3587. } else {
  3588. const char *state = qla83xx_dev_state_to_string(dev_state);
  3589. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
  3590. /* SV: XXX: Is timeout required here? */
  3591. /* Wait for IDC state change READY -> NEED_RESET */
  3592. while (dev_state == QLA8XXX_DEV_READY) {
  3593. qla83xx_idc_unlock(vha, 0);
  3594. msleep(200);
  3595. qla83xx_idc_lock(vha, 0);
  3596. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3597. }
  3598. }
  3599. /* Send IDC ack by writing to drv-ack register */
  3600. __qla83xx_set_drv_ack(vha);
  3601. return QLA_SUCCESS;
  3602. }
  3603. int
  3604. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  3605. {
  3606. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3607. }
  3608. int
  3609. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  3610. {
  3611. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3612. }
  3613. static int
  3614. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  3615. {
  3616. uint32_t drv_presence = 0;
  3617. struct qla_hw_data *ha = vha->hw;
  3618. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3619. if (drv_presence & (1 << ha->portnum))
  3620. return QLA_SUCCESS;
  3621. else
  3622. return QLA_TEST_FAILED;
  3623. }
  3624. int
  3625. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  3626. {
  3627. int rval = QLA_SUCCESS;
  3628. struct qla_hw_data *ha = vha->hw;
  3629. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  3630. "Entered %s().\n", __func__);
  3631. if (vha->device_flags & DFLG_DEV_FAILED) {
  3632. ql_log(ql_log_warn, vha, 0xb059,
  3633. "Device in unrecoverable FAILED state.\n");
  3634. return QLA_FUNCTION_FAILED;
  3635. }
  3636. qla83xx_idc_lock(vha, 0);
  3637. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  3638. ql_log(ql_log_warn, vha, 0xb05a,
  3639. "Function=0x%x has been removed from IDC participation.\n",
  3640. ha->portnum);
  3641. rval = QLA_FUNCTION_FAILED;
  3642. goto exit;
  3643. }
  3644. qla83xx_reset_ownership(vha);
  3645. rval = qla83xx_initiating_reset(vha);
  3646. /*
  3647. * Perform reset if we are the reset-owner,
  3648. * else wait till IDC state changes to READY/FAILED.
  3649. */
  3650. if (rval == QLA_SUCCESS) {
  3651. rval = qla83xx_idc_state_handler(vha);
  3652. if (rval == QLA_SUCCESS)
  3653. ha->flags.nic_core_hung = 0;
  3654. __qla83xx_clear_drv_ack(vha);
  3655. }
  3656. exit:
  3657. qla83xx_idc_unlock(vha, 0);
  3658. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  3659. return rval;
  3660. }
  3661. int
  3662. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  3663. {
  3664. struct qla_hw_data *ha = vha->hw;
  3665. int rval = QLA_FUNCTION_FAILED;
  3666. if (!IS_MCTP_CAPABLE(ha)) {
  3667. /* This message can be removed from the final version */
  3668. ql_log(ql_log_info, vha, 0x506d,
  3669. "This board is not MCTP capable\n");
  3670. return rval;
  3671. }
  3672. if (!ha->mctp_dump) {
  3673. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  3674. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  3675. if (!ha->mctp_dump) {
  3676. ql_log(ql_log_warn, vha, 0x506e,
  3677. "Failed to allocate memory for mctp dump\n");
  3678. return rval;
  3679. }
  3680. }
  3681. #define MCTP_DUMP_STR_ADDR 0x00000000
  3682. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  3683. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  3684. if (rval != QLA_SUCCESS) {
  3685. ql_log(ql_log_warn, vha, 0x506f,
  3686. "Failed to capture mctp dump\n");
  3687. } else {
  3688. ql_log(ql_log_info, vha, 0x5070,
  3689. "Mctp dump capture for host (%ld/%p).\n",
  3690. vha->host_no, ha->mctp_dump);
  3691. ha->mctp_dumped = 1;
  3692. }
  3693. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  3694. ha->flags.nic_core_reset_hdlr_active = 1;
  3695. rval = qla83xx_restart_nic_firmware(vha);
  3696. if (rval)
  3697. /* NIC Core reset failed. */
  3698. ql_log(ql_log_warn, vha, 0x5071,
  3699. "Failed to restart nic firmware\n");
  3700. else
  3701. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  3702. "Restarted NIC firmware successfully.\n");
  3703. ha->flags.nic_core_reset_hdlr_active = 0;
  3704. }
  3705. return rval;
  3706. }
  3707. /*
  3708. * qla2x00_quiesce_io
  3709. * Description: This function will block the new I/Os
  3710. * Its not aborting any I/Os as context
  3711. * is not destroyed during quiescence
  3712. * Arguments: scsi_qla_host_t
  3713. * return : void
  3714. */
  3715. void
  3716. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  3717. {
  3718. struct qla_hw_data *ha = vha->hw;
  3719. struct scsi_qla_host *vp;
  3720. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  3721. "Quiescing I/O - ha=%p.\n", ha);
  3722. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  3723. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3724. atomic_set(&vha->loop_state, LOOP_DOWN);
  3725. qla2x00_mark_all_devices_lost(vha, 0);
  3726. list_for_each_entry(vp, &ha->vp_list, list)
  3727. qla2x00_mark_all_devices_lost(vp, 0);
  3728. } else {
  3729. if (!atomic_read(&vha->loop_down_timer))
  3730. atomic_set(&vha->loop_down_timer,
  3731. LOOP_DOWN_TIME);
  3732. }
  3733. /* Wait for pending cmds to complete */
  3734. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  3735. }
  3736. void
  3737. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  3738. {
  3739. struct qla_hw_data *ha = vha->hw;
  3740. struct scsi_qla_host *vp;
  3741. unsigned long flags;
  3742. fc_port_t *fcport;
  3743. /* For ISP82XX, driver waits for completion of the commands.
  3744. * online flag should be set.
  3745. */
  3746. if (!IS_QLA82XX(ha))
  3747. vha->flags.online = 0;
  3748. ha->flags.chip_reset_done = 0;
  3749. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  3750. vha->qla_stats.total_isp_aborts++;
  3751. ql_log(ql_log_info, vha, 0x00af,
  3752. "Performing ISP error recovery - ha=%p.\n", ha);
  3753. /* For ISP82XX, reset_chip is just disabling interrupts.
  3754. * Driver waits for the completion of the commands.
  3755. * the interrupts need to be enabled.
  3756. */
  3757. if (!IS_QLA82XX(ha))
  3758. ha->isp_ops->reset_chip(vha);
  3759. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  3760. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3761. atomic_set(&vha->loop_state, LOOP_DOWN);
  3762. qla2x00_mark_all_devices_lost(vha, 0);
  3763. spin_lock_irqsave(&ha->vport_slock, flags);
  3764. list_for_each_entry(vp, &ha->vp_list, list) {
  3765. atomic_inc(&vp->vref_count);
  3766. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3767. qla2x00_mark_all_devices_lost(vp, 0);
  3768. spin_lock_irqsave(&ha->vport_slock, flags);
  3769. atomic_dec(&vp->vref_count);
  3770. }
  3771. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3772. } else {
  3773. if (!atomic_read(&vha->loop_down_timer))
  3774. atomic_set(&vha->loop_down_timer,
  3775. LOOP_DOWN_TIME);
  3776. }
  3777. /* Clear all async request states across all VPs. */
  3778. list_for_each_entry(fcport, &vha->vp_fcports, list)
  3779. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3780. spin_lock_irqsave(&ha->vport_slock, flags);
  3781. list_for_each_entry(vp, &ha->vp_list, list) {
  3782. atomic_inc(&vp->vref_count);
  3783. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3784. list_for_each_entry(fcport, &vp->vp_fcports, list)
  3785. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3786. spin_lock_irqsave(&ha->vport_slock, flags);
  3787. atomic_dec(&vp->vref_count);
  3788. }
  3789. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3790. if (!ha->flags.eeh_busy) {
  3791. /* Make sure for ISP 82XX IO DMA is complete */
  3792. if (IS_QLA82XX(ha)) {
  3793. qla82xx_chip_reset_cleanup(vha);
  3794. ql_log(ql_log_info, vha, 0x00b4,
  3795. "Done chip reset cleanup.\n");
  3796. /* Done waiting for pending commands.
  3797. * Reset the online flag.
  3798. */
  3799. vha->flags.online = 0;
  3800. }
  3801. /* Requeue all commands in outstanding command list. */
  3802. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3803. }
  3804. }
  3805. /*
  3806. * qla2x00_abort_isp
  3807. * Resets ISP and aborts all outstanding commands.
  3808. *
  3809. * Input:
  3810. * ha = adapter block pointer.
  3811. *
  3812. * Returns:
  3813. * 0 = success
  3814. */
  3815. int
  3816. qla2x00_abort_isp(scsi_qla_host_t *vha)
  3817. {
  3818. int rval;
  3819. uint8_t status = 0;
  3820. struct qla_hw_data *ha = vha->hw;
  3821. struct scsi_qla_host *vp;
  3822. struct req_que *req = ha->req_q_map[0];
  3823. unsigned long flags;
  3824. if (vha->flags.online) {
  3825. qla2x00_abort_isp_cleanup(vha);
  3826. if (IS_QLA8031(ha)) {
  3827. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  3828. "Clearing fcoe driver presence.\n");
  3829. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  3830. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  3831. "Error while clearing DRV-Presence.\n");
  3832. }
  3833. if (unlikely(pci_channel_offline(ha->pdev) &&
  3834. ha->flags.pci_channel_io_perm_failure)) {
  3835. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3836. status = 0;
  3837. return status;
  3838. }
  3839. ha->isp_ops->get_flash_version(vha, req->ring);
  3840. ha->isp_ops->nvram_config(vha);
  3841. if (!qla2x00_restart_isp(vha)) {
  3842. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3843. if (!atomic_read(&vha->loop_down_timer)) {
  3844. /*
  3845. * Issue marker command only when we are going
  3846. * to start the I/O .
  3847. */
  3848. vha->marker_needed = 1;
  3849. }
  3850. vha->flags.online = 1;
  3851. ha->isp_ops->enable_intrs(ha);
  3852. ha->isp_abort_cnt = 0;
  3853. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3854. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  3855. qla2x00_get_fw_version(vha);
  3856. if (ha->fce) {
  3857. ha->flags.fce_enabled = 1;
  3858. memset(ha->fce, 0,
  3859. fce_calc_size(ha->fce_bufs));
  3860. rval = qla2x00_enable_fce_trace(vha,
  3861. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  3862. &ha->fce_bufs);
  3863. if (rval) {
  3864. ql_log(ql_log_warn, vha, 0x8033,
  3865. "Unable to reinitialize FCE "
  3866. "(%d).\n", rval);
  3867. ha->flags.fce_enabled = 0;
  3868. }
  3869. }
  3870. if (ha->eft) {
  3871. memset(ha->eft, 0, EFT_SIZE);
  3872. rval = qla2x00_enable_eft_trace(vha,
  3873. ha->eft_dma, EFT_NUM_BUFFERS);
  3874. if (rval) {
  3875. ql_log(ql_log_warn, vha, 0x8034,
  3876. "Unable to reinitialize EFT "
  3877. "(%d).\n", rval);
  3878. }
  3879. }
  3880. } else { /* failed the ISP abort */
  3881. vha->flags.online = 1;
  3882. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  3883. if (ha->isp_abort_cnt == 0) {
  3884. ql_log(ql_log_fatal, vha, 0x8035,
  3885. "ISP error recover failed - "
  3886. "board disabled.\n");
  3887. /*
  3888. * The next call disables the board
  3889. * completely.
  3890. */
  3891. ha->isp_ops->reset_adapter(vha);
  3892. vha->flags.online = 0;
  3893. clear_bit(ISP_ABORT_RETRY,
  3894. &vha->dpc_flags);
  3895. status = 0;
  3896. } else { /* schedule another ISP abort */
  3897. ha->isp_abort_cnt--;
  3898. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  3899. "ISP abort - retry remaining %d.\n",
  3900. ha->isp_abort_cnt);
  3901. status = 1;
  3902. }
  3903. } else {
  3904. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  3905. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  3906. "ISP error recovery - retrying (%d) "
  3907. "more times.\n", ha->isp_abort_cnt);
  3908. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3909. status = 1;
  3910. }
  3911. }
  3912. }
  3913. if (!status) {
  3914. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  3915. spin_lock_irqsave(&ha->vport_slock, flags);
  3916. list_for_each_entry(vp, &ha->vp_list, list) {
  3917. if (vp->vp_idx) {
  3918. atomic_inc(&vp->vref_count);
  3919. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3920. qla2x00_vp_abort_isp(vp);
  3921. spin_lock_irqsave(&ha->vport_slock, flags);
  3922. atomic_dec(&vp->vref_count);
  3923. }
  3924. }
  3925. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3926. if (IS_QLA8031(ha)) {
  3927. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  3928. "Setting back fcoe driver presence.\n");
  3929. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  3930. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  3931. "Error while setting DRV-Presence.\n");
  3932. }
  3933. } else {
  3934. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  3935. __func__);
  3936. }
  3937. return(status);
  3938. }
  3939. /*
  3940. * qla2x00_restart_isp
  3941. * restarts the ISP after a reset
  3942. *
  3943. * Input:
  3944. * ha = adapter block pointer.
  3945. *
  3946. * Returns:
  3947. * 0 = success
  3948. */
  3949. static int
  3950. qla2x00_restart_isp(scsi_qla_host_t *vha)
  3951. {
  3952. int status = 0;
  3953. uint32_t wait_time;
  3954. struct qla_hw_data *ha = vha->hw;
  3955. struct req_que *req = ha->req_q_map[0];
  3956. struct rsp_que *rsp = ha->rsp_q_map[0];
  3957. unsigned long flags;
  3958. /* If firmware needs to be loaded */
  3959. if (qla2x00_isp_firmware(vha)) {
  3960. vha->flags.online = 0;
  3961. status = ha->isp_ops->chip_diag(vha);
  3962. if (!status)
  3963. status = qla2x00_setup_chip(vha);
  3964. }
  3965. if (!status && !(status = qla2x00_init_rings(vha))) {
  3966. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3967. ha->flags.chip_reset_done = 1;
  3968. /* Initialize the queues in use */
  3969. qla25xx_init_queues(ha);
  3970. status = qla2x00_fw_ready(vha);
  3971. if (!status) {
  3972. ql_dbg(ql_dbg_taskm, vha, 0x8031,
  3973. "Start configure loop status = %d.\n", status);
  3974. /* Issue a marker after FW becomes ready. */
  3975. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  3976. vha->flags.online = 1;
  3977. /*
  3978. * Process any ATIO queue entries that came in
  3979. * while we weren't online.
  3980. */
  3981. spin_lock_irqsave(&ha->hardware_lock, flags);
  3982. if (qla_tgt_mode_enabled(vha))
  3983. qlt_24xx_process_atio_queue(vha);
  3984. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3985. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3986. wait_time = 256;
  3987. do {
  3988. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3989. qla2x00_configure_loop(vha);
  3990. wait_time--;
  3991. } while (!atomic_read(&vha->loop_down_timer) &&
  3992. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3993. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3994. &vha->dpc_flags)));
  3995. }
  3996. /* if no cable then assume it's good */
  3997. if ((vha->device_flags & DFLG_NO_CABLE))
  3998. status = 0;
  3999. ql_dbg(ql_dbg_taskm, vha, 0x8032,
  4000. "Configure loop done, status = 0x%x.\n", status);
  4001. }
  4002. return (status);
  4003. }
  4004. static int
  4005. qla25xx_init_queues(struct qla_hw_data *ha)
  4006. {
  4007. struct rsp_que *rsp = NULL;
  4008. struct req_que *req = NULL;
  4009. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4010. int ret = -1;
  4011. int i;
  4012. for (i = 1; i < ha->max_rsp_queues; i++) {
  4013. rsp = ha->rsp_q_map[i];
  4014. if (rsp) {
  4015. rsp->options &= ~BIT_0;
  4016. ret = qla25xx_init_rsp_que(base_vha, rsp);
  4017. if (ret != QLA_SUCCESS)
  4018. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  4019. "%s Rsp que: %d init failed.\n",
  4020. __func__, rsp->id);
  4021. else
  4022. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  4023. "%s Rsp que: %d inited.\n",
  4024. __func__, rsp->id);
  4025. }
  4026. }
  4027. for (i = 1; i < ha->max_req_queues; i++) {
  4028. req = ha->req_q_map[i];
  4029. if (req) {
  4030. /* Clear outstanding commands array. */
  4031. req->options &= ~BIT_0;
  4032. ret = qla25xx_init_req_que(base_vha, req);
  4033. if (ret != QLA_SUCCESS)
  4034. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  4035. "%s Req que: %d init failed.\n",
  4036. __func__, req->id);
  4037. else
  4038. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  4039. "%s Req que: %d inited.\n",
  4040. __func__, req->id);
  4041. }
  4042. }
  4043. return ret;
  4044. }
  4045. /*
  4046. * qla2x00_reset_adapter
  4047. * Reset adapter.
  4048. *
  4049. * Input:
  4050. * ha = adapter block pointer.
  4051. */
  4052. void
  4053. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  4054. {
  4055. unsigned long flags = 0;
  4056. struct qla_hw_data *ha = vha->hw;
  4057. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4058. vha->flags.online = 0;
  4059. ha->isp_ops->disable_intrs(ha);
  4060. spin_lock_irqsave(&ha->hardware_lock, flags);
  4061. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  4062. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4063. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  4064. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4065. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4066. }
  4067. void
  4068. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  4069. {
  4070. unsigned long flags = 0;
  4071. struct qla_hw_data *ha = vha->hw;
  4072. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  4073. if (IS_QLA82XX(ha))
  4074. return;
  4075. vha->flags.online = 0;
  4076. ha->isp_ops->disable_intrs(ha);
  4077. spin_lock_irqsave(&ha->hardware_lock, flags);
  4078. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  4079. RD_REG_DWORD(&reg->hccr);
  4080. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  4081. RD_REG_DWORD(&reg->hccr);
  4082. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4083. if (IS_NOPOLLING_TYPE(ha))
  4084. ha->isp_ops->enable_intrs(ha);
  4085. }
  4086. /* On sparc systems, obtain port and node WWN from firmware
  4087. * properties.
  4088. */
  4089. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  4090. struct nvram_24xx *nv)
  4091. {
  4092. #ifdef CONFIG_SPARC
  4093. struct qla_hw_data *ha = vha->hw;
  4094. struct pci_dev *pdev = ha->pdev;
  4095. struct device_node *dp = pci_device_to_OF_node(pdev);
  4096. const u8 *val;
  4097. int len;
  4098. val = of_get_property(dp, "port-wwn", &len);
  4099. if (val && len >= WWN_SIZE)
  4100. memcpy(nv->port_name, val, WWN_SIZE);
  4101. val = of_get_property(dp, "node-wwn", &len);
  4102. if (val && len >= WWN_SIZE)
  4103. memcpy(nv->node_name, val, WWN_SIZE);
  4104. #endif
  4105. }
  4106. int
  4107. qla24xx_nvram_config(scsi_qla_host_t *vha)
  4108. {
  4109. int rval;
  4110. struct init_cb_24xx *icb;
  4111. struct nvram_24xx *nv;
  4112. uint32_t *dptr;
  4113. uint8_t *dptr1, *dptr2;
  4114. uint32_t chksum;
  4115. uint16_t cnt;
  4116. struct qla_hw_data *ha = vha->hw;
  4117. rval = QLA_SUCCESS;
  4118. icb = (struct init_cb_24xx *)ha->init_cb;
  4119. nv = ha->nvram;
  4120. /* Determine NVRAM starting address. */
  4121. if (ha->flags.port0) {
  4122. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  4123. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  4124. } else {
  4125. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  4126. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  4127. }
  4128. ha->nvram_size = sizeof(struct nvram_24xx);
  4129. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4130. if (IS_QLA82XX(ha))
  4131. ha->vpd_size = FA_VPD_SIZE_82XX;
  4132. /* Get VPD data into cache */
  4133. ha->vpd = ha->nvram + VPD_OFFSET;
  4134. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  4135. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  4136. /* Get NVRAM data into cache and calculate checksum. */
  4137. dptr = (uint32_t *)nv;
  4138. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  4139. ha->nvram_size);
  4140. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4141. chksum += le32_to_cpu(*dptr++);
  4142. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  4143. "Contents of NVRAM\n");
  4144. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  4145. (uint8_t *)nv, ha->nvram_size);
  4146. /* Bad NVRAM data, set defaults parameters. */
  4147. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4148. || nv->id[3] != ' ' ||
  4149. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4150. /* Reset NVRAM data. */
  4151. ql_log(ql_log_warn, vha, 0x006b,
  4152. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4153. "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
  4154. ql_log(ql_log_warn, vha, 0x006c,
  4155. "Falling back to functioning (yet invalid -- WWPN) "
  4156. "defaults.\n");
  4157. /*
  4158. * Set default initialization control block.
  4159. */
  4160. memset(nv, 0, ha->nvram_size);
  4161. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4162. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4163. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4164. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4165. nv->exchange_count = __constant_cpu_to_le16(0);
  4166. nv->hard_address = __constant_cpu_to_le16(124);
  4167. nv->port_name[0] = 0x21;
  4168. nv->port_name[1] = 0x00 + ha->port_no;
  4169. nv->port_name[2] = 0x00;
  4170. nv->port_name[3] = 0xe0;
  4171. nv->port_name[4] = 0x8b;
  4172. nv->port_name[5] = 0x1c;
  4173. nv->port_name[6] = 0x55;
  4174. nv->port_name[7] = 0x86;
  4175. nv->node_name[0] = 0x20;
  4176. nv->node_name[1] = 0x00;
  4177. nv->node_name[2] = 0x00;
  4178. nv->node_name[3] = 0xe0;
  4179. nv->node_name[4] = 0x8b;
  4180. nv->node_name[5] = 0x1c;
  4181. nv->node_name[6] = 0x55;
  4182. nv->node_name[7] = 0x86;
  4183. qla24xx_nvram_wwn_from_ofw(vha, nv);
  4184. nv->login_retry_count = __constant_cpu_to_le16(8);
  4185. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4186. nv->login_timeout = __constant_cpu_to_le16(0);
  4187. nv->firmware_options_1 =
  4188. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4189. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4190. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4191. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4192. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4193. nv->efi_parameters = __constant_cpu_to_le32(0);
  4194. nv->reset_delay = 5;
  4195. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4196. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4197. nv->link_down_timeout = __constant_cpu_to_le16(30);
  4198. rval = 1;
  4199. }
  4200. if (!qla_ini_mode_enabled(vha)) {
  4201. /* Don't enable full login after initial LIP */
  4202. nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
  4203. /* Don't enable LIP full login for initiator */
  4204. nv->host_p &= __constant_cpu_to_le32(~BIT_10);
  4205. }
  4206. qlt_24xx_config_nvram_stage1(vha, nv);
  4207. /* Reset Initialization control block */
  4208. memset(icb, 0, ha->init_cb_size);
  4209. /* Copy 1st segment. */
  4210. dptr1 = (uint8_t *)icb;
  4211. dptr2 = (uint8_t *)&nv->version;
  4212. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4213. while (cnt--)
  4214. *dptr1++ = *dptr2++;
  4215. icb->login_retry_count = nv->login_retry_count;
  4216. icb->link_down_on_nos = nv->link_down_on_nos;
  4217. /* Copy 2nd segment. */
  4218. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4219. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4220. cnt = (uint8_t *)&icb->reserved_3 -
  4221. (uint8_t *)&icb->interrupt_delay_timer;
  4222. while (cnt--)
  4223. *dptr1++ = *dptr2++;
  4224. /*
  4225. * Setup driver NVRAM options.
  4226. */
  4227. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4228. "QLA2462");
  4229. qlt_24xx_config_nvram_stage2(vha, icb);
  4230. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4231. /* Use alternate WWN? */
  4232. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4233. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4234. }
  4235. /* Prepare nodename */
  4236. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4237. /*
  4238. * Firmware will apply the following mask if the nodename was
  4239. * not provided.
  4240. */
  4241. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4242. icb->node_name[0] &= 0xF0;
  4243. }
  4244. /* Set host adapter parameters. */
  4245. ha->flags.disable_risc_code_load = 0;
  4246. ha->flags.enable_lip_reset = 0;
  4247. ha->flags.enable_lip_full_login =
  4248. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4249. ha->flags.enable_target_reset =
  4250. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4251. ha->flags.enable_led_scheme = 0;
  4252. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4253. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4254. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4255. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  4256. sizeof(ha->fw_seriallink_options24));
  4257. /* save HBA serial number */
  4258. ha->serial0 = icb->port_name[5];
  4259. ha->serial1 = icb->port_name[6];
  4260. ha->serial2 = icb->port_name[7];
  4261. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4262. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4263. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4264. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4265. /* Set minimum login_timeout to 4 seconds. */
  4266. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4267. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4268. if (le16_to_cpu(nv->login_timeout) < 4)
  4269. nv->login_timeout = __constant_cpu_to_le16(4);
  4270. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4271. icb->login_timeout = nv->login_timeout;
  4272. /* Set minimum RATOV to 100 tenths of a second. */
  4273. ha->r_a_tov = 100;
  4274. ha->loop_reset_delay = nv->reset_delay;
  4275. /* Link Down Timeout = 0:
  4276. *
  4277. * When Port Down timer expires we will start returning
  4278. * I/O's to OS with "DID_NO_CONNECT".
  4279. *
  4280. * Link Down Timeout != 0:
  4281. *
  4282. * The driver waits for the link to come up after link down
  4283. * before returning I/Os to OS with "DID_NO_CONNECT".
  4284. */
  4285. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4286. ha->loop_down_abort_time =
  4287. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4288. } else {
  4289. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4290. ha->loop_down_abort_time =
  4291. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4292. }
  4293. /* Need enough time to try and get the port back. */
  4294. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4295. if (qlport_down_retry)
  4296. ha->port_down_retry_count = qlport_down_retry;
  4297. /* Set login_retry_count */
  4298. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4299. if (ha->port_down_retry_count ==
  4300. le16_to_cpu(nv->port_down_retry_count) &&
  4301. ha->port_down_retry_count > 3)
  4302. ha->login_retry_count = ha->port_down_retry_count;
  4303. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4304. ha->login_retry_count = ha->port_down_retry_count;
  4305. if (ql2xloginretrycount)
  4306. ha->login_retry_count = ql2xloginretrycount;
  4307. /* Enable ZIO. */
  4308. if (!vha->flags.init_done) {
  4309. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4310. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4311. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4312. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4313. }
  4314. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4315. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4316. vha->flags.process_response_queue = 0;
  4317. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4318. ha->zio_mode = QLA_ZIO_MODE_6;
  4319. ql_log(ql_log_info, vha, 0x006f,
  4320. "ZIO mode %d enabled; timer delay (%d us).\n",
  4321. ha->zio_mode, ha->zio_timer * 100);
  4322. icb->firmware_options_2 |= cpu_to_le32(
  4323. (uint32_t)ha->zio_mode);
  4324. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4325. vha->flags.process_response_queue = 1;
  4326. }
  4327. if (rval) {
  4328. ql_log(ql_log_warn, vha, 0x0070,
  4329. "NVRAM configuration failed.\n");
  4330. }
  4331. return (rval);
  4332. }
  4333. static int
  4334. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  4335. uint32_t faddr)
  4336. {
  4337. int rval = QLA_SUCCESS;
  4338. int segments, fragment;
  4339. uint32_t *dcode, dlen;
  4340. uint32_t risc_addr;
  4341. uint32_t risc_size;
  4342. uint32_t i;
  4343. struct qla_hw_data *ha = vha->hw;
  4344. struct req_que *req = ha->req_q_map[0];
  4345. ql_dbg(ql_dbg_init, vha, 0x008b,
  4346. "FW: Loading firmware from flash (%x).\n", faddr);
  4347. rval = QLA_SUCCESS;
  4348. segments = FA_RISC_CODE_SEGMENTS;
  4349. dcode = (uint32_t *)req->ring;
  4350. *srisc_addr = 0;
  4351. /* Validate firmware image by checking version. */
  4352. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  4353. for (i = 0; i < 4; i++)
  4354. dcode[i] = be32_to_cpu(dcode[i]);
  4355. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4356. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4357. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4358. dcode[3] == 0)) {
  4359. ql_log(ql_log_fatal, vha, 0x008c,
  4360. "Unable to verify the integrity of flash firmware "
  4361. "image.\n");
  4362. ql_log(ql_log_fatal, vha, 0x008d,
  4363. "Firmware data: %08x %08x %08x %08x.\n",
  4364. dcode[0], dcode[1], dcode[2], dcode[3]);
  4365. return QLA_FUNCTION_FAILED;
  4366. }
  4367. while (segments && rval == QLA_SUCCESS) {
  4368. /* Read segment's load information. */
  4369. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  4370. risc_addr = be32_to_cpu(dcode[2]);
  4371. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4372. risc_size = be32_to_cpu(dcode[3]);
  4373. fragment = 0;
  4374. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4375. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4376. if (dlen > risc_size)
  4377. dlen = risc_size;
  4378. ql_dbg(ql_dbg_init, vha, 0x008e,
  4379. "Loading risc segment@ risc addr %x "
  4380. "number of dwords 0x%x offset 0x%x.\n",
  4381. risc_addr, dlen, faddr);
  4382. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4383. for (i = 0; i < dlen; i++)
  4384. dcode[i] = swab32(dcode[i]);
  4385. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4386. dlen);
  4387. if (rval) {
  4388. ql_log(ql_log_fatal, vha, 0x008f,
  4389. "Failed to load segment %d of firmware.\n",
  4390. fragment);
  4391. break;
  4392. }
  4393. faddr += dlen;
  4394. risc_addr += dlen;
  4395. risc_size -= dlen;
  4396. fragment++;
  4397. }
  4398. /* Next segment. */
  4399. segments--;
  4400. }
  4401. return rval;
  4402. }
  4403. #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
  4404. int
  4405. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4406. {
  4407. int rval;
  4408. int i, fragment;
  4409. uint16_t *wcode, *fwcode;
  4410. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4411. struct fw_blob *blob;
  4412. struct qla_hw_data *ha = vha->hw;
  4413. struct req_que *req = ha->req_q_map[0];
  4414. /* Load firmware blob. */
  4415. blob = qla2x00_request_firmware(vha);
  4416. if (!blob) {
  4417. ql_log(ql_log_info, vha, 0x0083,
  4418. "Fimware image unavailable.\n");
  4419. ql_log(ql_log_info, vha, 0x0084,
  4420. "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
  4421. return QLA_FUNCTION_FAILED;
  4422. }
  4423. rval = QLA_SUCCESS;
  4424. wcode = (uint16_t *)req->ring;
  4425. *srisc_addr = 0;
  4426. fwcode = (uint16_t *)blob->fw->data;
  4427. fwclen = 0;
  4428. /* Validate firmware image by checking version. */
  4429. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4430. ql_log(ql_log_fatal, vha, 0x0085,
  4431. "Unable to verify integrity of firmware image (%Zd).\n",
  4432. blob->fw->size);
  4433. goto fail_fw_integrity;
  4434. }
  4435. for (i = 0; i < 4; i++)
  4436. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4437. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4438. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4439. wcode[2] == 0 && wcode[3] == 0)) {
  4440. ql_log(ql_log_fatal, vha, 0x0086,
  4441. "Unable to verify integrity of firmware image.\n");
  4442. ql_log(ql_log_fatal, vha, 0x0087,
  4443. "Firmware data: %04x %04x %04x %04x.\n",
  4444. wcode[0], wcode[1], wcode[2], wcode[3]);
  4445. goto fail_fw_integrity;
  4446. }
  4447. seg = blob->segs;
  4448. while (*seg && rval == QLA_SUCCESS) {
  4449. risc_addr = *seg;
  4450. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4451. risc_size = be16_to_cpu(fwcode[3]);
  4452. /* Validate firmware image size. */
  4453. fwclen += risc_size * sizeof(uint16_t);
  4454. if (blob->fw->size < fwclen) {
  4455. ql_log(ql_log_fatal, vha, 0x0088,
  4456. "Unable to verify integrity of firmware image "
  4457. "(%Zd).\n", blob->fw->size);
  4458. goto fail_fw_integrity;
  4459. }
  4460. fragment = 0;
  4461. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4462. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4463. if (wlen > risc_size)
  4464. wlen = risc_size;
  4465. ql_dbg(ql_dbg_init, vha, 0x0089,
  4466. "Loading risc segment@ risc addr %x number of "
  4467. "words 0x%x.\n", risc_addr, wlen);
  4468. for (i = 0; i < wlen; i++)
  4469. wcode[i] = swab16(fwcode[i]);
  4470. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4471. wlen);
  4472. if (rval) {
  4473. ql_log(ql_log_fatal, vha, 0x008a,
  4474. "Failed to load segment %d of firmware.\n",
  4475. fragment);
  4476. break;
  4477. }
  4478. fwcode += wlen;
  4479. risc_addr += wlen;
  4480. risc_size -= wlen;
  4481. fragment++;
  4482. }
  4483. /* Next segment. */
  4484. seg++;
  4485. }
  4486. return rval;
  4487. fail_fw_integrity:
  4488. return QLA_FUNCTION_FAILED;
  4489. }
  4490. static int
  4491. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4492. {
  4493. int rval;
  4494. int segments, fragment;
  4495. uint32_t *dcode, dlen;
  4496. uint32_t risc_addr;
  4497. uint32_t risc_size;
  4498. uint32_t i;
  4499. struct fw_blob *blob;
  4500. uint32_t *fwcode, fwclen;
  4501. struct qla_hw_data *ha = vha->hw;
  4502. struct req_que *req = ha->req_q_map[0];
  4503. /* Load firmware blob. */
  4504. blob = qla2x00_request_firmware(vha);
  4505. if (!blob) {
  4506. ql_log(ql_log_warn, vha, 0x0090,
  4507. "Fimware image unavailable.\n");
  4508. ql_log(ql_log_warn, vha, 0x0091,
  4509. "Firmware images can be retrieved from: "
  4510. QLA_FW_URL ".\n");
  4511. return QLA_FUNCTION_FAILED;
  4512. }
  4513. ql_dbg(ql_dbg_init, vha, 0x0092,
  4514. "FW: Loading via request-firmware.\n");
  4515. rval = QLA_SUCCESS;
  4516. segments = FA_RISC_CODE_SEGMENTS;
  4517. dcode = (uint32_t *)req->ring;
  4518. *srisc_addr = 0;
  4519. fwcode = (uint32_t *)blob->fw->data;
  4520. fwclen = 0;
  4521. /* Validate firmware image by checking version. */
  4522. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4523. ql_log(ql_log_fatal, vha, 0x0093,
  4524. "Unable to verify integrity of firmware image (%Zd).\n",
  4525. blob->fw->size);
  4526. goto fail_fw_integrity;
  4527. }
  4528. for (i = 0; i < 4; i++)
  4529. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4530. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4531. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4532. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4533. dcode[3] == 0)) {
  4534. ql_log(ql_log_fatal, vha, 0x0094,
  4535. "Unable to verify integrity of firmware image (%Zd).\n",
  4536. blob->fw->size);
  4537. ql_log(ql_log_fatal, vha, 0x0095,
  4538. "Firmware data: %08x %08x %08x %08x.\n",
  4539. dcode[0], dcode[1], dcode[2], dcode[3]);
  4540. goto fail_fw_integrity;
  4541. }
  4542. while (segments && rval == QLA_SUCCESS) {
  4543. risc_addr = be32_to_cpu(fwcode[2]);
  4544. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4545. risc_size = be32_to_cpu(fwcode[3]);
  4546. /* Validate firmware image size. */
  4547. fwclen += risc_size * sizeof(uint32_t);
  4548. if (blob->fw->size < fwclen) {
  4549. ql_log(ql_log_fatal, vha, 0x0096,
  4550. "Unable to verify integrity of firmware image "
  4551. "(%Zd).\n", blob->fw->size);
  4552. goto fail_fw_integrity;
  4553. }
  4554. fragment = 0;
  4555. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4556. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4557. if (dlen > risc_size)
  4558. dlen = risc_size;
  4559. ql_dbg(ql_dbg_init, vha, 0x0097,
  4560. "Loading risc segment@ risc addr %x "
  4561. "number of dwords 0x%x.\n", risc_addr, dlen);
  4562. for (i = 0; i < dlen; i++)
  4563. dcode[i] = swab32(fwcode[i]);
  4564. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4565. dlen);
  4566. if (rval) {
  4567. ql_log(ql_log_fatal, vha, 0x0098,
  4568. "Failed to load segment %d of firmware.\n",
  4569. fragment);
  4570. break;
  4571. }
  4572. fwcode += dlen;
  4573. risc_addr += dlen;
  4574. risc_size -= dlen;
  4575. fragment++;
  4576. }
  4577. /* Next segment. */
  4578. segments--;
  4579. }
  4580. return rval;
  4581. fail_fw_integrity:
  4582. return QLA_FUNCTION_FAILED;
  4583. }
  4584. int
  4585. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4586. {
  4587. int rval;
  4588. if (ql2xfwloadbin == 1)
  4589. return qla81xx_load_risc(vha, srisc_addr);
  4590. /*
  4591. * FW Load priority:
  4592. * 1) Firmware via request-firmware interface (.bin file).
  4593. * 2) Firmware residing in flash.
  4594. */
  4595. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4596. if (rval == QLA_SUCCESS)
  4597. return rval;
  4598. return qla24xx_load_risc_flash(vha, srisc_addr,
  4599. vha->hw->flt_region_fw);
  4600. }
  4601. int
  4602. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4603. {
  4604. int rval;
  4605. struct qla_hw_data *ha = vha->hw;
  4606. if (ql2xfwloadbin == 2)
  4607. goto try_blob_fw;
  4608. /*
  4609. * FW Load priority:
  4610. * 1) Firmware residing in flash.
  4611. * 2) Firmware via request-firmware interface (.bin file).
  4612. * 3) Golden-Firmware residing in flash -- limited operation.
  4613. */
  4614. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  4615. if (rval == QLA_SUCCESS)
  4616. return rval;
  4617. try_blob_fw:
  4618. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4619. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  4620. return rval;
  4621. ql_log(ql_log_info, vha, 0x0099,
  4622. "Attempting to fallback to golden firmware.\n");
  4623. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  4624. if (rval != QLA_SUCCESS)
  4625. return rval;
  4626. ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
  4627. ha->flags.running_gold_fw = 1;
  4628. return rval;
  4629. }
  4630. void
  4631. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  4632. {
  4633. int ret, retries;
  4634. struct qla_hw_data *ha = vha->hw;
  4635. if (ha->flags.pci_channel_io_perm_failure)
  4636. return;
  4637. if (!IS_FWI2_CAPABLE(ha))
  4638. return;
  4639. if (!ha->fw_major_version)
  4640. return;
  4641. ret = qla2x00_stop_firmware(vha);
  4642. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  4643. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  4644. ha->isp_ops->reset_chip(vha);
  4645. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  4646. continue;
  4647. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  4648. continue;
  4649. ql_log(ql_log_info, vha, 0x8015,
  4650. "Attempting retry of stop-firmware command.\n");
  4651. ret = qla2x00_stop_firmware(vha);
  4652. }
  4653. }
  4654. int
  4655. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  4656. {
  4657. int rval = QLA_SUCCESS;
  4658. int rval2;
  4659. uint16_t mb[MAILBOX_REGISTER_COUNT];
  4660. struct qla_hw_data *ha = vha->hw;
  4661. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4662. struct req_que *req;
  4663. struct rsp_que *rsp;
  4664. if (!vha->vp_idx)
  4665. return -EINVAL;
  4666. rval = qla2x00_fw_ready(base_vha);
  4667. if (ha->flags.cpu_affinity_enabled)
  4668. req = ha->req_q_map[0];
  4669. else
  4670. req = vha->req;
  4671. rsp = req->rsp;
  4672. if (rval == QLA_SUCCESS) {
  4673. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4674. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4675. }
  4676. vha->flags.management_server_logged_in = 0;
  4677. /* Login to SNS first */
  4678. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  4679. BIT_1);
  4680. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  4681. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  4682. ql_dbg(ql_dbg_init, vha, 0x0120,
  4683. "Failed SNS login: loop_id=%x, rval2=%d\n",
  4684. NPH_SNS, rval2);
  4685. else
  4686. ql_dbg(ql_dbg_init, vha, 0x0103,
  4687. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  4688. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  4689. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  4690. return (QLA_FUNCTION_FAILED);
  4691. }
  4692. atomic_set(&vha->loop_down_timer, 0);
  4693. atomic_set(&vha->loop_state, LOOP_UP);
  4694. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4695. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4696. rval = qla2x00_loop_resync(base_vha);
  4697. return rval;
  4698. }
  4699. /* 84XX Support **************************************************************/
  4700. static LIST_HEAD(qla_cs84xx_list);
  4701. static DEFINE_MUTEX(qla_cs84xx_mutex);
  4702. static struct qla_chip_state_84xx *
  4703. qla84xx_get_chip(struct scsi_qla_host *vha)
  4704. {
  4705. struct qla_chip_state_84xx *cs84xx;
  4706. struct qla_hw_data *ha = vha->hw;
  4707. mutex_lock(&qla_cs84xx_mutex);
  4708. /* Find any shared 84xx chip. */
  4709. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  4710. if (cs84xx->bus == ha->pdev->bus) {
  4711. kref_get(&cs84xx->kref);
  4712. goto done;
  4713. }
  4714. }
  4715. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  4716. if (!cs84xx)
  4717. goto done;
  4718. kref_init(&cs84xx->kref);
  4719. spin_lock_init(&cs84xx->access_lock);
  4720. mutex_init(&cs84xx->fw_update_mutex);
  4721. cs84xx->bus = ha->pdev->bus;
  4722. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  4723. done:
  4724. mutex_unlock(&qla_cs84xx_mutex);
  4725. return cs84xx;
  4726. }
  4727. static void
  4728. __qla84xx_chip_release(struct kref *kref)
  4729. {
  4730. struct qla_chip_state_84xx *cs84xx =
  4731. container_of(kref, struct qla_chip_state_84xx, kref);
  4732. mutex_lock(&qla_cs84xx_mutex);
  4733. list_del(&cs84xx->list);
  4734. mutex_unlock(&qla_cs84xx_mutex);
  4735. kfree(cs84xx);
  4736. }
  4737. void
  4738. qla84xx_put_chip(struct scsi_qla_host *vha)
  4739. {
  4740. struct qla_hw_data *ha = vha->hw;
  4741. if (ha->cs84xx)
  4742. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  4743. }
  4744. static int
  4745. qla84xx_init_chip(scsi_qla_host_t *vha)
  4746. {
  4747. int rval;
  4748. uint16_t status[2];
  4749. struct qla_hw_data *ha = vha->hw;
  4750. mutex_lock(&ha->cs84xx->fw_update_mutex);
  4751. rval = qla84xx_verify_chip(vha, status);
  4752. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  4753. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  4754. QLA_SUCCESS;
  4755. }
  4756. /* 81XX Support **************************************************************/
  4757. int
  4758. qla81xx_nvram_config(scsi_qla_host_t *vha)
  4759. {
  4760. int rval;
  4761. struct init_cb_81xx *icb;
  4762. struct nvram_81xx *nv;
  4763. uint32_t *dptr;
  4764. uint8_t *dptr1, *dptr2;
  4765. uint32_t chksum;
  4766. uint16_t cnt;
  4767. struct qla_hw_data *ha = vha->hw;
  4768. rval = QLA_SUCCESS;
  4769. icb = (struct init_cb_81xx *)ha->init_cb;
  4770. nv = ha->nvram;
  4771. /* Determine NVRAM starting address. */
  4772. ha->nvram_size = sizeof(struct nvram_81xx);
  4773. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4774. /* Get VPD data into cache */
  4775. ha->vpd = ha->nvram + VPD_OFFSET;
  4776. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  4777. ha->vpd_size);
  4778. /* Get NVRAM data into cache and calculate checksum. */
  4779. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  4780. ha->nvram_size);
  4781. dptr = (uint32_t *)nv;
  4782. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4783. chksum += le32_to_cpu(*dptr++);
  4784. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  4785. "Contents of NVRAM:\n");
  4786. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  4787. (uint8_t *)nv, ha->nvram_size);
  4788. /* Bad NVRAM data, set defaults parameters. */
  4789. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4790. || nv->id[3] != ' ' ||
  4791. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4792. /* Reset NVRAM data. */
  4793. ql_log(ql_log_info, vha, 0x0073,
  4794. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4795. "version=0x%x.\n", chksum, nv->id[0],
  4796. le16_to_cpu(nv->nvram_version));
  4797. ql_log(ql_log_info, vha, 0x0074,
  4798. "Falling back to functioning (yet invalid -- WWPN) "
  4799. "defaults.\n");
  4800. /*
  4801. * Set default initialization control block.
  4802. */
  4803. memset(nv, 0, ha->nvram_size);
  4804. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4805. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4806. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4807. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4808. nv->exchange_count = __constant_cpu_to_le16(0);
  4809. nv->port_name[0] = 0x21;
  4810. nv->port_name[1] = 0x00 + ha->port_no;
  4811. nv->port_name[2] = 0x00;
  4812. nv->port_name[3] = 0xe0;
  4813. nv->port_name[4] = 0x8b;
  4814. nv->port_name[5] = 0x1c;
  4815. nv->port_name[6] = 0x55;
  4816. nv->port_name[7] = 0x86;
  4817. nv->node_name[0] = 0x20;
  4818. nv->node_name[1] = 0x00;
  4819. nv->node_name[2] = 0x00;
  4820. nv->node_name[3] = 0xe0;
  4821. nv->node_name[4] = 0x8b;
  4822. nv->node_name[5] = 0x1c;
  4823. nv->node_name[6] = 0x55;
  4824. nv->node_name[7] = 0x86;
  4825. nv->login_retry_count = __constant_cpu_to_le16(8);
  4826. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4827. nv->login_timeout = __constant_cpu_to_le16(0);
  4828. nv->firmware_options_1 =
  4829. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4830. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4831. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4832. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4833. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4834. nv->efi_parameters = __constant_cpu_to_le32(0);
  4835. nv->reset_delay = 5;
  4836. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4837. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4838. nv->link_down_timeout = __constant_cpu_to_le16(180);
  4839. nv->enode_mac[0] = 0x00;
  4840. nv->enode_mac[1] = 0xC0;
  4841. nv->enode_mac[2] = 0xDD;
  4842. nv->enode_mac[3] = 0x04;
  4843. nv->enode_mac[4] = 0x05;
  4844. nv->enode_mac[5] = 0x06 + ha->port_no;
  4845. rval = 1;
  4846. }
  4847. if (IS_T10_PI_CAPABLE(ha))
  4848. nv->frame_payload_size &= ~7;
  4849. qlt_81xx_config_nvram_stage1(vha, nv);
  4850. /* Reset Initialization control block */
  4851. memset(icb, 0, ha->init_cb_size);
  4852. /* Copy 1st segment. */
  4853. dptr1 = (uint8_t *)icb;
  4854. dptr2 = (uint8_t *)&nv->version;
  4855. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4856. while (cnt--)
  4857. *dptr1++ = *dptr2++;
  4858. icb->login_retry_count = nv->login_retry_count;
  4859. /* Copy 2nd segment. */
  4860. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4861. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4862. cnt = (uint8_t *)&icb->reserved_5 -
  4863. (uint8_t *)&icb->interrupt_delay_timer;
  4864. while (cnt--)
  4865. *dptr1++ = *dptr2++;
  4866. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  4867. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  4868. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  4869. icb->enode_mac[0] = 0x00;
  4870. icb->enode_mac[1] = 0xC0;
  4871. icb->enode_mac[2] = 0xDD;
  4872. icb->enode_mac[3] = 0x04;
  4873. icb->enode_mac[4] = 0x05;
  4874. icb->enode_mac[5] = 0x06 + ha->port_no;
  4875. }
  4876. /* Use extended-initialization control block. */
  4877. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  4878. /*
  4879. * Setup driver NVRAM options.
  4880. */
  4881. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4882. "QLE8XXX");
  4883. qlt_81xx_config_nvram_stage2(vha, icb);
  4884. /* Use alternate WWN? */
  4885. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4886. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4887. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4888. }
  4889. /* Prepare nodename */
  4890. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4891. /*
  4892. * Firmware will apply the following mask if the nodename was
  4893. * not provided.
  4894. */
  4895. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4896. icb->node_name[0] &= 0xF0;
  4897. }
  4898. /* Set host adapter parameters. */
  4899. ha->flags.disable_risc_code_load = 0;
  4900. ha->flags.enable_lip_reset = 0;
  4901. ha->flags.enable_lip_full_login =
  4902. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4903. ha->flags.enable_target_reset =
  4904. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4905. ha->flags.enable_led_scheme = 0;
  4906. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4907. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4908. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4909. /* save HBA serial number */
  4910. ha->serial0 = icb->port_name[5];
  4911. ha->serial1 = icb->port_name[6];
  4912. ha->serial2 = icb->port_name[7];
  4913. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4914. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4915. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4916. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4917. /* Set minimum login_timeout to 4 seconds. */
  4918. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4919. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4920. if (le16_to_cpu(nv->login_timeout) < 4)
  4921. nv->login_timeout = __constant_cpu_to_le16(4);
  4922. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4923. icb->login_timeout = nv->login_timeout;
  4924. /* Set minimum RATOV to 100 tenths of a second. */
  4925. ha->r_a_tov = 100;
  4926. ha->loop_reset_delay = nv->reset_delay;
  4927. /* Link Down Timeout = 0:
  4928. *
  4929. * When Port Down timer expires we will start returning
  4930. * I/O's to OS with "DID_NO_CONNECT".
  4931. *
  4932. * Link Down Timeout != 0:
  4933. *
  4934. * The driver waits for the link to come up after link down
  4935. * before returning I/Os to OS with "DID_NO_CONNECT".
  4936. */
  4937. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4938. ha->loop_down_abort_time =
  4939. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4940. } else {
  4941. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4942. ha->loop_down_abort_time =
  4943. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4944. }
  4945. /* Need enough time to try and get the port back. */
  4946. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4947. if (qlport_down_retry)
  4948. ha->port_down_retry_count = qlport_down_retry;
  4949. /* Set login_retry_count */
  4950. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4951. if (ha->port_down_retry_count ==
  4952. le16_to_cpu(nv->port_down_retry_count) &&
  4953. ha->port_down_retry_count > 3)
  4954. ha->login_retry_count = ha->port_down_retry_count;
  4955. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4956. ha->login_retry_count = ha->port_down_retry_count;
  4957. if (ql2xloginretrycount)
  4958. ha->login_retry_count = ql2xloginretrycount;
  4959. /* if not running MSI-X we need handshaking on interrupts */
  4960. if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
  4961. icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
  4962. /* Enable ZIO. */
  4963. if (!vha->flags.init_done) {
  4964. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4965. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4966. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4967. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4968. }
  4969. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4970. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4971. vha->flags.process_response_queue = 0;
  4972. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4973. ha->zio_mode = QLA_ZIO_MODE_6;
  4974. ql_log(ql_log_info, vha, 0x0075,
  4975. "ZIO mode %d enabled; timer delay (%d us).\n",
  4976. ha->zio_mode,
  4977. ha->zio_timer * 100);
  4978. icb->firmware_options_2 |= cpu_to_le32(
  4979. (uint32_t)ha->zio_mode);
  4980. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4981. vha->flags.process_response_queue = 1;
  4982. }
  4983. if (rval) {
  4984. ql_log(ql_log_warn, vha, 0x0076,
  4985. "NVRAM configuration failed.\n");
  4986. }
  4987. return (rval);
  4988. }
  4989. int
  4990. qla82xx_restart_isp(scsi_qla_host_t *vha)
  4991. {
  4992. int status, rval;
  4993. uint32_t wait_time;
  4994. struct qla_hw_data *ha = vha->hw;
  4995. struct req_que *req = ha->req_q_map[0];
  4996. struct rsp_que *rsp = ha->rsp_q_map[0];
  4997. struct scsi_qla_host *vp;
  4998. unsigned long flags;
  4999. status = qla2x00_init_rings(vha);
  5000. if (!status) {
  5001. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5002. ha->flags.chip_reset_done = 1;
  5003. status = qla2x00_fw_ready(vha);
  5004. if (!status) {
  5005. ql_log(ql_log_info, vha, 0x803c,
  5006. "Start configure loop, status =%d.\n", status);
  5007. /* Issue a marker after FW becomes ready. */
  5008. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  5009. vha->flags.online = 1;
  5010. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  5011. wait_time = 256;
  5012. do {
  5013. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5014. qla2x00_configure_loop(vha);
  5015. wait_time--;
  5016. } while (!atomic_read(&vha->loop_down_timer) &&
  5017. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
  5018. wait_time &&
  5019. (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
  5020. }
  5021. /* if no cable then assume it's good */
  5022. if ((vha->device_flags & DFLG_NO_CABLE))
  5023. status = 0;
  5024. ql_log(ql_log_info, vha, 0x8000,
  5025. "Configure loop done, status = 0x%x.\n", status);
  5026. }
  5027. if (!status) {
  5028. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5029. if (!atomic_read(&vha->loop_down_timer)) {
  5030. /*
  5031. * Issue marker command only when we are going
  5032. * to start the I/O .
  5033. */
  5034. vha->marker_needed = 1;
  5035. }
  5036. vha->flags.online = 1;
  5037. ha->isp_ops->enable_intrs(ha);
  5038. ha->isp_abort_cnt = 0;
  5039. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5040. /* Update the firmware version */
  5041. status = qla82xx_check_md_needed(vha);
  5042. if (ha->fce) {
  5043. ha->flags.fce_enabled = 1;
  5044. memset(ha->fce, 0,
  5045. fce_calc_size(ha->fce_bufs));
  5046. rval = qla2x00_enable_fce_trace(vha,
  5047. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  5048. &ha->fce_bufs);
  5049. if (rval) {
  5050. ql_log(ql_log_warn, vha, 0x8001,
  5051. "Unable to reinitialize FCE (%d).\n",
  5052. rval);
  5053. ha->flags.fce_enabled = 0;
  5054. }
  5055. }
  5056. if (ha->eft) {
  5057. memset(ha->eft, 0, EFT_SIZE);
  5058. rval = qla2x00_enable_eft_trace(vha,
  5059. ha->eft_dma, EFT_NUM_BUFFERS);
  5060. if (rval) {
  5061. ql_log(ql_log_warn, vha, 0x8010,
  5062. "Unable to reinitialize EFT (%d).\n",
  5063. rval);
  5064. }
  5065. }
  5066. }
  5067. if (!status) {
  5068. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  5069. "qla82xx_restart_isp succeeded.\n");
  5070. spin_lock_irqsave(&ha->vport_slock, flags);
  5071. list_for_each_entry(vp, &ha->vp_list, list) {
  5072. if (vp->vp_idx) {
  5073. atomic_inc(&vp->vref_count);
  5074. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5075. qla2x00_vp_abort_isp(vp);
  5076. spin_lock_irqsave(&ha->vport_slock, flags);
  5077. atomic_dec(&vp->vref_count);
  5078. }
  5079. }
  5080. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5081. } else {
  5082. ql_log(ql_log_warn, vha, 0x8016,
  5083. "qla82xx_restart_isp **** FAILED ****.\n");
  5084. }
  5085. return status;
  5086. }
  5087. void
  5088. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  5089. {
  5090. struct qla_hw_data *ha = vha->hw;
  5091. if (!ql2xetsenable)
  5092. return;
  5093. /* Enable ETS Burst. */
  5094. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  5095. ha->fw_options[2] |= BIT_9;
  5096. qla2x00_set_fw_options(vha, ha->fw_options);
  5097. }
  5098. /*
  5099. * qla24xx_get_fcp_prio
  5100. * Gets the fcp cmd priority value for the logged in port.
  5101. * Looks for a match of the port descriptors within
  5102. * each of the fcp prio config entries. If a match is found,
  5103. * the tag (priority) value is returned.
  5104. *
  5105. * Input:
  5106. * vha = scsi host structure pointer.
  5107. * fcport = port structure pointer.
  5108. *
  5109. * Return:
  5110. * non-zero (if found)
  5111. * -1 (if not found)
  5112. *
  5113. * Context:
  5114. * Kernel context
  5115. */
  5116. static int
  5117. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5118. {
  5119. int i, entries;
  5120. uint8_t pid_match, wwn_match;
  5121. int priority;
  5122. uint32_t pid1, pid2;
  5123. uint64_t wwn1, wwn2;
  5124. struct qla_fcp_prio_entry *pri_entry;
  5125. struct qla_hw_data *ha = vha->hw;
  5126. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  5127. return -1;
  5128. priority = -1;
  5129. entries = ha->fcp_prio_cfg->num_entries;
  5130. pri_entry = &ha->fcp_prio_cfg->entry[0];
  5131. for (i = 0; i < entries; i++) {
  5132. pid_match = wwn_match = 0;
  5133. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  5134. pri_entry++;
  5135. continue;
  5136. }
  5137. /* check source pid for a match */
  5138. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  5139. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  5140. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  5141. if (pid1 == INVALID_PORT_ID)
  5142. pid_match++;
  5143. else if (pid1 == pid2)
  5144. pid_match++;
  5145. }
  5146. /* check destination pid for a match */
  5147. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  5148. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  5149. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  5150. if (pid1 == INVALID_PORT_ID)
  5151. pid_match++;
  5152. else if (pid1 == pid2)
  5153. pid_match++;
  5154. }
  5155. /* check source WWN for a match */
  5156. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  5157. wwn1 = wwn_to_u64(vha->port_name);
  5158. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  5159. if (wwn2 == (uint64_t)-1)
  5160. wwn_match++;
  5161. else if (wwn1 == wwn2)
  5162. wwn_match++;
  5163. }
  5164. /* check destination WWN for a match */
  5165. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  5166. wwn1 = wwn_to_u64(fcport->port_name);
  5167. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  5168. if (wwn2 == (uint64_t)-1)
  5169. wwn_match++;
  5170. else if (wwn1 == wwn2)
  5171. wwn_match++;
  5172. }
  5173. if (pid_match == 2 || wwn_match == 2) {
  5174. /* Found a matching entry */
  5175. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  5176. priority = pri_entry->tag;
  5177. break;
  5178. }
  5179. pri_entry++;
  5180. }
  5181. return priority;
  5182. }
  5183. /*
  5184. * qla24xx_update_fcport_fcp_prio
  5185. * Activates fcp priority for the logged in fc port
  5186. *
  5187. * Input:
  5188. * vha = scsi host structure pointer.
  5189. * fcp = port structure pointer.
  5190. *
  5191. * Return:
  5192. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5193. *
  5194. * Context:
  5195. * Kernel context.
  5196. */
  5197. int
  5198. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5199. {
  5200. int ret;
  5201. int priority;
  5202. uint16_t mb[5];
  5203. if (fcport->port_type != FCT_TARGET ||
  5204. fcport->loop_id == FC_NO_LOOP_ID)
  5205. return QLA_FUNCTION_FAILED;
  5206. priority = qla24xx_get_fcp_prio(vha, fcport);
  5207. if (priority < 0)
  5208. return QLA_FUNCTION_FAILED;
  5209. if (IS_QLA82XX(vha->hw)) {
  5210. fcport->fcp_prio = priority & 0xf;
  5211. return QLA_SUCCESS;
  5212. }
  5213. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  5214. if (ret == QLA_SUCCESS) {
  5215. if (fcport->fcp_prio != priority)
  5216. ql_dbg(ql_dbg_user, vha, 0x709e,
  5217. "Updated FCP_CMND priority - value=%d loop_id=%d "
  5218. "port_id=%02x%02x%02x.\n", priority,
  5219. fcport->loop_id, fcport->d_id.b.domain,
  5220. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5221. fcport->fcp_prio = priority & 0xf;
  5222. } else
  5223. ql_dbg(ql_dbg_user, vha, 0x704f,
  5224. "Unable to update FCP_CMND priority - ret=0x%x for "
  5225. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  5226. fcport->d_id.b.domain, fcport->d_id.b.area,
  5227. fcport->d_id.b.al_pa);
  5228. return ret;
  5229. }
  5230. /*
  5231. * qla24xx_update_all_fcp_prio
  5232. * Activates fcp priority for all the logged in ports
  5233. *
  5234. * Input:
  5235. * ha = adapter block pointer.
  5236. *
  5237. * Return:
  5238. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5239. *
  5240. * Context:
  5241. * Kernel context.
  5242. */
  5243. int
  5244. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  5245. {
  5246. int ret;
  5247. fc_port_t *fcport;
  5248. ret = QLA_FUNCTION_FAILED;
  5249. /* We need to set priority for all logged in ports */
  5250. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5251. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  5252. return ret;
  5253. }