qla_init.c 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111
  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_init_rings(scsi_qla_host_t *);
  24. static int qla2x00_fw_ready(scsi_qla_host_t *);
  25. static int qla2x00_configure_hba(scsi_qla_host_t *);
  26. static int qla2x00_configure_loop(scsi_qla_host_t *);
  27. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  28. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  29. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
  30. static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
  31. uint16_t *);
  32. static int qla2x00_restart_isp(scsi_qla_host_t *);
  33. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  34. static int qla84xx_init_chip(scsi_qla_host_t *);
  35. static int qla25xx_init_queues(struct qla_hw_data *);
  36. /* SRB Extensions ---------------------------------------------------------- */
  37. void
  38. qla2x00_sp_timeout(unsigned long __data)
  39. {
  40. srb_t *sp = (srb_t *)__data;
  41. struct srb_iocb *iocb;
  42. fc_port_t *fcport = sp->fcport;
  43. struct qla_hw_data *ha = fcport->vha->hw;
  44. struct req_que *req;
  45. unsigned long flags;
  46. spin_lock_irqsave(&ha->hardware_lock, flags);
  47. req = ha->req_q_map[0];
  48. req->outstanding_cmds[sp->handle] = NULL;
  49. iocb = &sp->u.iocb_cmd;
  50. iocb->timeout(sp);
  51. sp->free(fcport->vha, sp);
  52. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  53. }
  54. void
  55. qla2x00_sp_free(void *data, void *ptr)
  56. {
  57. srb_t *sp = (srb_t *)ptr;
  58. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  59. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  60. del_timer(&iocb->timer);
  61. qla2x00_rel_sp(vha, sp);
  62. }
  63. /* Asynchronous Login/Logout Routines -------------------------------------- */
  64. unsigned long
  65. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  66. {
  67. unsigned long tmo;
  68. struct qla_hw_data *ha = vha->hw;
  69. /* Firmware should use switch negotiated r_a_tov for timeout. */
  70. tmo = ha->r_a_tov / 10 * 2;
  71. if (!IS_FWI2_CAPABLE(ha)) {
  72. /*
  73. * Except for earlier ISPs where the timeout is seeded from the
  74. * initialization control block.
  75. */
  76. tmo = ha->login_timeout;
  77. }
  78. return tmo;
  79. }
  80. static void
  81. qla2x00_async_iocb_timeout(void *data)
  82. {
  83. srb_t *sp = (srb_t *)data;
  84. fc_port_t *fcport = sp->fcport;
  85. ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
  86. "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
  87. sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area,
  88. fcport->d_id.b.al_pa);
  89. fcport->flags &= ~FCF_ASYNC_SENT;
  90. if (sp->type == SRB_LOGIN_CMD) {
  91. struct srb_iocb *lio = &sp->u.iocb_cmd;
  92. qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
  93. /* Retry as needed. */
  94. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  95. lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  96. QLA_LOGIO_LOGIN_RETRIED : 0;
  97. qla2x00_post_async_login_done_work(fcport->vha, fcport,
  98. lio->u.logio.data);
  99. }
  100. }
  101. static void
  102. qla2x00_async_login_sp_done(void *data, void *ptr, int res)
  103. {
  104. srb_t *sp = (srb_t *)ptr;
  105. struct srb_iocb *lio = &sp->u.iocb_cmd;
  106. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  107. if (!test_bit(UNLOADING, &vha->dpc_flags))
  108. qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
  109. lio->u.logio.data);
  110. sp->free(sp->fcport->vha, sp);
  111. }
  112. int
  113. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  114. uint16_t *data)
  115. {
  116. srb_t *sp;
  117. struct srb_iocb *lio;
  118. int rval;
  119. rval = QLA_FUNCTION_FAILED;
  120. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  121. if (!sp)
  122. goto done;
  123. sp->type = SRB_LOGIN_CMD;
  124. sp->name = "login";
  125. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  126. lio = &sp->u.iocb_cmd;
  127. lio->timeout = qla2x00_async_iocb_timeout;
  128. sp->done = qla2x00_async_login_sp_done;
  129. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  130. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  131. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  132. rval = qla2x00_start_sp(sp);
  133. if (rval != QLA_SUCCESS)
  134. goto done_free_sp;
  135. ql_dbg(ql_dbg_disc, vha, 0x2072,
  136. "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
  137. "retries=%d.\n", sp->handle, fcport->loop_id,
  138. fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
  139. fcport->login_retry);
  140. return rval;
  141. done_free_sp:
  142. sp->free(fcport->vha, sp);
  143. done:
  144. return rval;
  145. }
  146. static void
  147. qla2x00_async_logout_sp_done(void *data, void *ptr, int res)
  148. {
  149. srb_t *sp = (srb_t *)ptr;
  150. struct srb_iocb *lio = &sp->u.iocb_cmd;
  151. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  152. if (!test_bit(UNLOADING, &vha->dpc_flags))
  153. qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
  154. lio->u.logio.data);
  155. sp->free(sp->fcport->vha, sp);
  156. }
  157. int
  158. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  159. {
  160. srb_t *sp;
  161. struct srb_iocb *lio;
  162. int rval;
  163. rval = QLA_FUNCTION_FAILED;
  164. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  165. if (!sp)
  166. goto done;
  167. sp->type = SRB_LOGOUT_CMD;
  168. sp->name = "logout";
  169. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  170. lio = &sp->u.iocb_cmd;
  171. lio->timeout = qla2x00_async_iocb_timeout;
  172. sp->done = qla2x00_async_logout_sp_done;
  173. rval = qla2x00_start_sp(sp);
  174. if (rval != QLA_SUCCESS)
  175. goto done_free_sp;
  176. ql_dbg(ql_dbg_disc, vha, 0x2070,
  177. "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  178. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  179. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  180. return rval;
  181. done_free_sp:
  182. sp->free(fcport->vha, sp);
  183. done:
  184. return rval;
  185. }
  186. static void
  187. qla2x00_async_adisc_sp_done(void *data, void *ptr, int res)
  188. {
  189. srb_t *sp = (srb_t *)ptr;
  190. struct srb_iocb *lio = &sp->u.iocb_cmd;
  191. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  192. if (!test_bit(UNLOADING, &vha->dpc_flags))
  193. qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
  194. lio->u.logio.data);
  195. sp->free(sp->fcport->vha, sp);
  196. }
  197. int
  198. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  199. uint16_t *data)
  200. {
  201. srb_t *sp;
  202. struct srb_iocb *lio;
  203. int rval;
  204. rval = QLA_FUNCTION_FAILED;
  205. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  206. if (!sp)
  207. goto done;
  208. sp->type = SRB_ADISC_CMD;
  209. sp->name = "adisc";
  210. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  211. lio = &sp->u.iocb_cmd;
  212. lio->timeout = qla2x00_async_iocb_timeout;
  213. sp->done = qla2x00_async_adisc_sp_done;
  214. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  215. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  216. rval = qla2x00_start_sp(sp);
  217. if (rval != QLA_SUCCESS)
  218. goto done_free_sp;
  219. ql_dbg(ql_dbg_disc, vha, 0x206f,
  220. "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
  221. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  222. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  223. return rval;
  224. done_free_sp:
  225. sp->free(fcport->vha, sp);
  226. done:
  227. return rval;
  228. }
  229. static void
  230. qla2x00_async_tm_cmd_done(void *data, void *ptr, int res)
  231. {
  232. srb_t *sp = (srb_t *)ptr;
  233. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  234. struct scsi_qla_host *vha = (scsi_qla_host_t *)data;
  235. uint32_t flags;
  236. uint16_t lun;
  237. int rval;
  238. if (!test_bit(UNLOADING, &vha->dpc_flags)) {
  239. flags = iocb->u.tmf.flags;
  240. lun = (uint16_t)iocb->u.tmf.lun;
  241. /* Issue Marker IOCB */
  242. rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
  243. vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
  244. flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
  245. if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
  246. ql_dbg(ql_dbg_taskm, vha, 0x8030,
  247. "TM IOCB failed (%x).\n", rval);
  248. }
  249. }
  250. sp->free(sp->fcport->vha, sp);
  251. }
  252. int
  253. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t tm_flags, uint32_t lun,
  254. uint32_t tag)
  255. {
  256. struct scsi_qla_host *vha = fcport->vha;
  257. srb_t *sp;
  258. struct srb_iocb *tcf;
  259. int rval;
  260. rval = QLA_FUNCTION_FAILED;
  261. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  262. if (!sp)
  263. goto done;
  264. sp->type = SRB_TM_CMD;
  265. sp->name = "tmf";
  266. qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
  267. tcf = &sp->u.iocb_cmd;
  268. tcf->u.tmf.flags = tm_flags;
  269. tcf->u.tmf.lun = lun;
  270. tcf->u.tmf.data = tag;
  271. tcf->timeout = qla2x00_async_iocb_timeout;
  272. sp->done = qla2x00_async_tm_cmd_done;
  273. rval = qla2x00_start_sp(sp);
  274. if (rval != QLA_SUCCESS)
  275. goto done_free_sp;
  276. ql_dbg(ql_dbg_taskm, vha, 0x802f,
  277. "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  278. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  279. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  280. return rval;
  281. done_free_sp:
  282. sp->free(fcport->vha, sp);
  283. done:
  284. return rval;
  285. }
  286. void
  287. qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  288. uint16_t *data)
  289. {
  290. int rval;
  291. switch (data[0]) {
  292. case MBS_COMMAND_COMPLETE:
  293. /*
  294. * Driver must validate login state - If PRLI not complete,
  295. * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
  296. * requests.
  297. */
  298. rval = qla2x00_get_port_database(vha, fcport, 0);
  299. if (rval == QLA_NOT_LOGGED_IN) {
  300. fcport->flags &= ~FCF_ASYNC_SENT;
  301. fcport->flags |= FCF_LOGIN_NEEDED;
  302. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  303. break;
  304. }
  305. if (rval != QLA_SUCCESS) {
  306. qla2x00_post_async_logout_work(vha, fcport, NULL);
  307. qla2x00_post_async_login_work(vha, fcport, NULL);
  308. break;
  309. }
  310. if (fcport->flags & FCF_FCP2_DEVICE) {
  311. qla2x00_post_async_adisc_work(vha, fcport, data);
  312. break;
  313. }
  314. qla2x00_update_fcport(vha, fcport);
  315. break;
  316. case MBS_COMMAND_ERROR:
  317. fcport->flags &= ~FCF_ASYNC_SENT;
  318. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  319. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  320. else
  321. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  322. break;
  323. case MBS_PORT_ID_USED:
  324. fcport->loop_id = data[1];
  325. qla2x00_post_async_logout_work(vha, fcport, NULL);
  326. qla2x00_post_async_login_work(vha, fcport, NULL);
  327. break;
  328. case MBS_LOOP_ID_USED:
  329. fcport->loop_id++;
  330. rval = qla2x00_find_new_loop_id(vha, fcport);
  331. if (rval != QLA_SUCCESS) {
  332. fcport->flags &= ~FCF_ASYNC_SENT;
  333. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  334. break;
  335. }
  336. qla2x00_post_async_login_work(vha, fcport, NULL);
  337. break;
  338. }
  339. return;
  340. }
  341. void
  342. qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  343. uint16_t *data)
  344. {
  345. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  346. return;
  347. }
  348. void
  349. qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  350. uint16_t *data)
  351. {
  352. if (data[0] == MBS_COMMAND_COMPLETE) {
  353. qla2x00_update_fcport(vha, fcport);
  354. return;
  355. }
  356. /* Retry login. */
  357. fcport->flags &= ~FCF_ASYNC_SENT;
  358. if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
  359. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  360. else
  361. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  362. return;
  363. }
  364. /****************************************************************************/
  365. /* QLogic ISP2x00 Hardware Support Functions. */
  366. /****************************************************************************/
  367. static int
  368. qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
  369. {
  370. int rval = QLA_SUCCESS;
  371. struct qla_hw_data *ha = vha->hw;
  372. uint32_t idc_major_ver, idc_minor_ver;
  373. uint16_t config[4];
  374. qla83xx_idc_lock(vha, 0);
  375. /* SV: TODO: Assign initialization timeout from
  376. * flash-info / other param
  377. */
  378. ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
  379. ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
  380. /* Set our fcoe function presence */
  381. if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
  382. ql_dbg(ql_dbg_p3p, vha, 0xb077,
  383. "Error while setting DRV-Presence.\n");
  384. rval = QLA_FUNCTION_FAILED;
  385. goto exit;
  386. }
  387. /* Decide the reset ownership */
  388. qla83xx_reset_ownership(vha);
  389. /*
  390. * On first protocol driver load:
  391. * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
  392. * register.
  393. * Others: Check compatibility with current IDC Major version.
  394. */
  395. qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
  396. if (ha->flags.nic_core_reset_owner) {
  397. /* Set IDC Major version */
  398. idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
  399. qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
  400. /* Clearing IDC-Lock-Recovery register */
  401. qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
  402. } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
  403. /*
  404. * Clear further IDC participation if we are not compatible with
  405. * the current IDC Major Version.
  406. */
  407. ql_log(ql_log_warn, vha, 0xb07d,
  408. "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
  409. idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
  410. __qla83xx_clear_drv_presence(vha);
  411. rval = QLA_FUNCTION_FAILED;
  412. goto exit;
  413. }
  414. /* Each function sets its supported Minor version. */
  415. qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
  416. idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
  417. qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
  418. if (ha->flags.nic_core_reset_owner) {
  419. memset(config, 0, sizeof(config));
  420. if (!qla81xx_get_port_config(vha, config))
  421. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  422. QLA8XXX_DEV_READY);
  423. }
  424. rval = qla83xx_idc_state_handler(vha);
  425. exit:
  426. qla83xx_idc_unlock(vha, 0);
  427. return rval;
  428. }
  429. /*
  430. * qla2x00_initialize_adapter
  431. * Initialize board.
  432. *
  433. * Input:
  434. * ha = adapter block pointer.
  435. *
  436. * Returns:
  437. * 0 = success
  438. */
  439. int
  440. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  441. {
  442. int rval;
  443. struct qla_hw_data *ha = vha->hw;
  444. struct req_que *req = ha->req_q_map[0];
  445. /* Clear adapter flags. */
  446. vha->flags.online = 0;
  447. ha->flags.chip_reset_done = 0;
  448. vha->flags.reset_active = 0;
  449. ha->flags.pci_channel_io_perm_failure = 0;
  450. ha->flags.eeh_busy = 0;
  451. ha->flags.thermal_supported = 1;
  452. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  453. atomic_set(&vha->loop_state, LOOP_DOWN);
  454. vha->device_flags = DFLG_NO_CABLE;
  455. vha->dpc_flags = 0;
  456. vha->flags.management_server_logged_in = 0;
  457. vha->marker_needed = 0;
  458. ha->isp_abort_cnt = 0;
  459. ha->beacon_blink_led = 0;
  460. set_bit(0, ha->req_qid_map);
  461. set_bit(0, ha->rsp_qid_map);
  462. ql_dbg(ql_dbg_init, vha, 0x0040,
  463. "Configuring PCI space...\n");
  464. rval = ha->isp_ops->pci_config(vha);
  465. if (rval) {
  466. ql_log(ql_log_warn, vha, 0x0044,
  467. "Unable to configure PCI space.\n");
  468. return (rval);
  469. }
  470. ha->isp_ops->reset_chip(vha);
  471. rval = qla2xxx_get_flash_info(vha);
  472. if (rval) {
  473. ql_log(ql_log_fatal, vha, 0x004f,
  474. "Unable to validate FLASH data.\n");
  475. return (rval);
  476. }
  477. ha->isp_ops->get_flash_version(vha, req->ring);
  478. ql_dbg(ql_dbg_init, vha, 0x0061,
  479. "Configure NVRAM parameters...\n");
  480. ha->isp_ops->nvram_config(vha);
  481. if (ha->flags.disable_serdes) {
  482. /* Mask HBA via NVRAM settings? */
  483. ql_log(ql_log_info, vha, 0x0077,
  484. "Masking HBA WWPN "
  485. "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
  486. vha->port_name[0], vha->port_name[1],
  487. vha->port_name[2], vha->port_name[3],
  488. vha->port_name[4], vha->port_name[5],
  489. vha->port_name[6], vha->port_name[7]);
  490. return QLA_FUNCTION_FAILED;
  491. }
  492. ql_dbg(ql_dbg_init, vha, 0x0078,
  493. "Verifying loaded RISC code...\n");
  494. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  495. rval = ha->isp_ops->chip_diag(vha);
  496. if (rval)
  497. return (rval);
  498. rval = qla2x00_setup_chip(vha);
  499. if (rval)
  500. return (rval);
  501. }
  502. if (IS_QLA84XX(ha)) {
  503. ha->cs84xx = qla84xx_get_chip(vha);
  504. if (!ha->cs84xx) {
  505. ql_log(ql_log_warn, vha, 0x00d0,
  506. "Unable to configure ISP84XX.\n");
  507. return QLA_FUNCTION_FAILED;
  508. }
  509. }
  510. if (qla_ini_mode_enabled(vha))
  511. rval = qla2x00_init_rings(vha);
  512. ha->flags.chip_reset_done = 1;
  513. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  514. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  515. rval = qla84xx_init_chip(vha);
  516. if (rval != QLA_SUCCESS) {
  517. ql_log(ql_log_warn, vha, 0x00d4,
  518. "Unable to initialize ISP84XX.\n");
  519. qla84xx_put_chip(vha);
  520. }
  521. }
  522. /* Load the NIC Core f/w if we are the first protocol driver. */
  523. if (IS_QLA8031(ha)) {
  524. rval = qla83xx_nic_core_fw_load(vha);
  525. if (rval)
  526. ql_log(ql_log_warn, vha, 0x0124,
  527. "Error in initializing NIC Core f/w.\n");
  528. }
  529. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  530. qla24xx_read_fcp_prio_cfg(vha);
  531. qla2x00_set_driver_version(vha, QLA2XXX_VERSION);
  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_q_length)
  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. static 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. qla2x00_init_response_q_entries(rsp);
  1712. }
  1713. ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
  1714. ha->tgt.atio_ring_index = 0;
  1715. /* Initialize ATIO queue entries */
  1716. qlt_init_atio_q_entries(vha);
  1717. ha->isp_ops->config_rings(vha);
  1718. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1719. /* Update any ISP specific firmware options before initialization. */
  1720. ha->isp_ops->update_fw_options(vha);
  1721. ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
  1722. if (ha->flags.npiv_supported) {
  1723. if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
  1724. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  1725. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  1726. }
  1727. if (IS_FWI2_CAPABLE(ha)) {
  1728. mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
  1729. mid_init_cb->init_cb.execution_throttle =
  1730. cpu_to_le16(ha->fw_xcb_count);
  1731. }
  1732. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  1733. if (rval) {
  1734. ql_log(ql_log_fatal, vha, 0x00d2,
  1735. "Init Firmware **** FAILED ****.\n");
  1736. } else {
  1737. ql_dbg(ql_dbg_init, vha, 0x00d3,
  1738. "Init Firmware -- success.\n");
  1739. }
  1740. return (rval);
  1741. }
  1742. /**
  1743. * qla2x00_fw_ready() - Waits for firmware ready.
  1744. * @ha: HA context
  1745. *
  1746. * Returns 0 on success.
  1747. */
  1748. static int
  1749. qla2x00_fw_ready(scsi_qla_host_t *vha)
  1750. {
  1751. int rval;
  1752. unsigned long wtime, mtime, cs84xx_time;
  1753. uint16_t min_wait; /* Minimum wait time if loop is down */
  1754. uint16_t wait_time; /* Wait time if loop is coming ready */
  1755. uint16_t state[5];
  1756. struct qla_hw_data *ha = vha->hw;
  1757. rval = QLA_SUCCESS;
  1758. /* 20 seconds for loop down. */
  1759. min_wait = 20;
  1760. /*
  1761. * Firmware should take at most one RATOV to login, plus 5 seconds for
  1762. * our own processing.
  1763. */
  1764. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  1765. wait_time = min_wait;
  1766. }
  1767. /* Min wait time if loop down */
  1768. mtime = jiffies + (min_wait * HZ);
  1769. /* wait time before firmware ready */
  1770. wtime = jiffies + (wait_time * HZ);
  1771. /* Wait for ISP to finish LIP */
  1772. if (!vha->flags.init_done)
  1773. ql_log(ql_log_info, vha, 0x801e,
  1774. "Waiting for LIP to complete.\n");
  1775. do {
  1776. memset(state, -1, sizeof(state));
  1777. rval = qla2x00_get_firmware_state(vha, state);
  1778. if (rval == QLA_SUCCESS) {
  1779. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  1780. vha->device_flags &= ~DFLG_NO_CABLE;
  1781. }
  1782. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  1783. ql_dbg(ql_dbg_taskm, vha, 0x801f,
  1784. "fw_state=%x 84xx=%x.\n", state[0],
  1785. state[2]);
  1786. if ((state[2] & FSTATE_LOGGED_IN) &&
  1787. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  1788. ql_dbg(ql_dbg_taskm, vha, 0x8028,
  1789. "Sending verify iocb.\n");
  1790. cs84xx_time = jiffies;
  1791. rval = qla84xx_init_chip(vha);
  1792. if (rval != QLA_SUCCESS) {
  1793. ql_log(ql_log_warn,
  1794. vha, 0x8007,
  1795. "Init chip failed.\n");
  1796. break;
  1797. }
  1798. /* Add time taken to initialize. */
  1799. cs84xx_time = jiffies - cs84xx_time;
  1800. wtime += cs84xx_time;
  1801. mtime += cs84xx_time;
  1802. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  1803. "Increasing wait time by %ld. "
  1804. "New time %ld.\n", cs84xx_time,
  1805. wtime);
  1806. }
  1807. } else if (state[0] == FSTATE_READY) {
  1808. ql_dbg(ql_dbg_taskm, vha, 0x8037,
  1809. "F/W Ready - OK.\n");
  1810. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  1811. &ha->login_timeout, &ha->r_a_tov);
  1812. rval = QLA_SUCCESS;
  1813. break;
  1814. }
  1815. rval = QLA_FUNCTION_FAILED;
  1816. if (atomic_read(&vha->loop_down_timer) &&
  1817. state[0] != FSTATE_READY) {
  1818. /* Loop down. Timeout on min_wait for states
  1819. * other than Wait for Login.
  1820. */
  1821. if (time_after_eq(jiffies, mtime)) {
  1822. ql_log(ql_log_info, vha, 0x8038,
  1823. "Cable is unplugged...\n");
  1824. vha->device_flags |= DFLG_NO_CABLE;
  1825. break;
  1826. }
  1827. }
  1828. } else {
  1829. /* Mailbox cmd failed. Timeout on min_wait. */
  1830. if (time_after_eq(jiffies, mtime) ||
  1831. ha->flags.isp82xx_fw_hung)
  1832. break;
  1833. }
  1834. if (time_after_eq(jiffies, wtime))
  1835. break;
  1836. /* Delay for a while */
  1837. msleep(500);
  1838. } while (1);
  1839. ql_dbg(ql_dbg_taskm, vha, 0x803a,
  1840. "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state[0],
  1841. state[1], state[2], state[3], state[4], jiffies);
  1842. if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
  1843. ql_log(ql_log_warn, vha, 0x803b,
  1844. "Firmware ready **** FAILED ****.\n");
  1845. }
  1846. return (rval);
  1847. }
  1848. /*
  1849. * qla2x00_configure_hba
  1850. * Setup adapter context.
  1851. *
  1852. * Input:
  1853. * ha = adapter state pointer.
  1854. *
  1855. * Returns:
  1856. * 0 = success
  1857. *
  1858. * Context:
  1859. * Kernel context.
  1860. */
  1861. static int
  1862. qla2x00_configure_hba(scsi_qla_host_t *vha)
  1863. {
  1864. int rval;
  1865. uint16_t loop_id;
  1866. uint16_t topo;
  1867. uint16_t sw_cap;
  1868. uint8_t al_pa;
  1869. uint8_t area;
  1870. uint8_t domain;
  1871. char connect_type[22];
  1872. struct qla_hw_data *ha = vha->hw;
  1873. unsigned long flags;
  1874. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  1875. /* Get host addresses. */
  1876. rval = qla2x00_get_adapter_id(vha,
  1877. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  1878. if (rval != QLA_SUCCESS) {
  1879. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  1880. IS_CNA_CAPABLE(ha) ||
  1881. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  1882. ql_dbg(ql_dbg_disc, vha, 0x2008,
  1883. "Loop is in a transition state.\n");
  1884. } else {
  1885. ql_log(ql_log_warn, vha, 0x2009,
  1886. "Unable to get host loop ID.\n");
  1887. if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
  1888. (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
  1889. ql_log(ql_log_warn, vha, 0x1151,
  1890. "Doing link init.\n");
  1891. if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
  1892. return rval;
  1893. }
  1894. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1895. }
  1896. return (rval);
  1897. }
  1898. if (topo == 4) {
  1899. ql_log(ql_log_info, vha, 0x200a,
  1900. "Cannot get topology - retrying.\n");
  1901. return (QLA_FUNCTION_FAILED);
  1902. }
  1903. vha->loop_id = loop_id;
  1904. /* initialize */
  1905. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  1906. ha->operating_mode = LOOP;
  1907. ha->switch_cap = 0;
  1908. switch (topo) {
  1909. case 0:
  1910. ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
  1911. ha->current_topology = ISP_CFG_NL;
  1912. strcpy(connect_type, "(Loop)");
  1913. break;
  1914. case 1:
  1915. ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
  1916. ha->switch_cap = sw_cap;
  1917. ha->current_topology = ISP_CFG_FL;
  1918. strcpy(connect_type, "(FL_Port)");
  1919. break;
  1920. case 2:
  1921. ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
  1922. ha->operating_mode = P2P;
  1923. ha->current_topology = ISP_CFG_N;
  1924. strcpy(connect_type, "(N_Port-to-N_Port)");
  1925. break;
  1926. case 3:
  1927. ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
  1928. ha->switch_cap = sw_cap;
  1929. ha->operating_mode = P2P;
  1930. ha->current_topology = ISP_CFG_F;
  1931. strcpy(connect_type, "(F_Port)");
  1932. break;
  1933. default:
  1934. ql_dbg(ql_dbg_disc, vha, 0x200f,
  1935. "HBA in unknown topology %x, using NL.\n", topo);
  1936. ha->current_topology = ISP_CFG_NL;
  1937. strcpy(connect_type, "(Loop)");
  1938. break;
  1939. }
  1940. /* Save Host port and loop ID. */
  1941. /* byte order - Big Endian */
  1942. vha->d_id.b.domain = domain;
  1943. vha->d_id.b.area = area;
  1944. vha->d_id.b.al_pa = al_pa;
  1945. spin_lock_irqsave(&ha->vport_slock, flags);
  1946. qlt_update_vp_map(vha, SET_AL_PA);
  1947. spin_unlock_irqrestore(&ha->vport_slock, flags);
  1948. if (!vha->flags.init_done)
  1949. ql_log(ql_log_info, vha, 0x2010,
  1950. "Topology - %s, Host Loop address 0x%x.\n",
  1951. connect_type, vha->loop_id);
  1952. if (rval) {
  1953. ql_log(ql_log_warn, vha, 0x2011,
  1954. "%s FAILED\n", __func__);
  1955. } else {
  1956. ql_dbg(ql_dbg_disc, vha, 0x2012,
  1957. "%s success\n", __func__);
  1958. }
  1959. return(rval);
  1960. }
  1961. inline void
  1962. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  1963. char *def)
  1964. {
  1965. char *st, *en;
  1966. uint16_t index;
  1967. struct qla_hw_data *ha = vha->hw;
  1968. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  1969. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
  1970. if (memcmp(model, BINZERO, len) != 0) {
  1971. strncpy(ha->model_number, model, len);
  1972. st = en = ha->model_number;
  1973. en += len - 1;
  1974. while (en > st) {
  1975. if (*en != 0x20 && *en != 0x00)
  1976. break;
  1977. *en-- = '\0';
  1978. }
  1979. index = (ha->pdev->subsystem_device & 0xff);
  1980. if (use_tbl &&
  1981. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  1982. index < QLA_MODEL_NAMES)
  1983. strncpy(ha->model_desc,
  1984. qla2x00_model_name[index * 2 + 1],
  1985. sizeof(ha->model_desc) - 1);
  1986. } else {
  1987. index = (ha->pdev->subsystem_device & 0xff);
  1988. if (use_tbl &&
  1989. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  1990. index < QLA_MODEL_NAMES) {
  1991. strcpy(ha->model_number,
  1992. qla2x00_model_name[index * 2]);
  1993. strncpy(ha->model_desc,
  1994. qla2x00_model_name[index * 2 + 1],
  1995. sizeof(ha->model_desc) - 1);
  1996. } else {
  1997. strcpy(ha->model_number, def);
  1998. }
  1999. }
  2000. if (IS_FWI2_CAPABLE(ha))
  2001. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  2002. sizeof(ha->model_desc));
  2003. }
  2004. /* On sparc systems, obtain port and node WWN from firmware
  2005. * properties.
  2006. */
  2007. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  2008. {
  2009. #ifdef CONFIG_SPARC
  2010. struct qla_hw_data *ha = vha->hw;
  2011. struct pci_dev *pdev = ha->pdev;
  2012. struct device_node *dp = pci_device_to_OF_node(pdev);
  2013. const u8 *val;
  2014. int len;
  2015. val = of_get_property(dp, "port-wwn", &len);
  2016. if (val && len >= WWN_SIZE)
  2017. memcpy(nv->port_name, val, WWN_SIZE);
  2018. val = of_get_property(dp, "node-wwn", &len);
  2019. if (val && len >= WWN_SIZE)
  2020. memcpy(nv->node_name, val, WWN_SIZE);
  2021. #endif
  2022. }
  2023. /*
  2024. * NVRAM configuration for ISP 2xxx
  2025. *
  2026. * Input:
  2027. * ha = adapter block pointer.
  2028. *
  2029. * Output:
  2030. * initialization control block in response_ring
  2031. * host adapters parameters in host adapter block
  2032. *
  2033. * Returns:
  2034. * 0 = success.
  2035. */
  2036. int
  2037. qla2x00_nvram_config(scsi_qla_host_t *vha)
  2038. {
  2039. int rval;
  2040. uint8_t chksum = 0;
  2041. uint16_t cnt;
  2042. uint8_t *dptr1, *dptr2;
  2043. struct qla_hw_data *ha = vha->hw;
  2044. init_cb_t *icb = ha->init_cb;
  2045. nvram_t *nv = ha->nvram;
  2046. uint8_t *ptr = ha->nvram;
  2047. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2048. rval = QLA_SUCCESS;
  2049. /* Determine NVRAM starting address. */
  2050. ha->nvram_size = sizeof(nvram_t);
  2051. ha->nvram_base = 0;
  2052. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  2053. if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
  2054. ha->nvram_base = 0x80;
  2055. /* Get NVRAM data and calculate checksum. */
  2056. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  2057. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  2058. chksum += *ptr++;
  2059. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
  2060. "Contents of NVRAM.\n");
  2061. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
  2062. (uint8_t *)nv, ha->nvram_size);
  2063. /* Bad NVRAM data, set defaults parameters. */
  2064. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
  2065. nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
  2066. /* Reset NVRAM data. */
  2067. ql_log(ql_log_warn, vha, 0x0064,
  2068. "Inconsistent NVRAM "
  2069. "detected: checksum=0x%x id=%c version=0x%x.\n",
  2070. chksum, nv->id[0], nv->nvram_version);
  2071. ql_log(ql_log_warn, vha, 0x0065,
  2072. "Falling back to "
  2073. "functioning (yet invalid -- WWPN) defaults.\n");
  2074. /*
  2075. * Set default initialization control block.
  2076. */
  2077. memset(nv, 0, ha->nvram_size);
  2078. nv->parameter_block_version = ICB_VERSION;
  2079. if (IS_QLA23XX(ha)) {
  2080. nv->firmware_options[0] = BIT_2 | BIT_1;
  2081. nv->firmware_options[1] = BIT_7 | BIT_5;
  2082. nv->add_firmware_options[0] = BIT_5;
  2083. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2084. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  2085. nv->special_options[1] = BIT_7;
  2086. } else if (IS_QLA2200(ha)) {
  2087. nv->firmware_options[0] = BIT_2 | BIT_1;
  2088. nv->firmware_options[1] = BIT_7 | BIT_5;
  2089. nv->add_firmware_options[0] = BIT_5;
  2090. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  2091. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  2092. } else if (IS_QLA2100(ha)) {
  2093. nv->firmware_options[0] = BIT_3 | BIT_1;
  2094. nv->firmware_options[1] = BIT_5;
  2095. nv->frame_payload_size = __constant_cpu_to_le16(1024);
  2096. }
  2097. nv->max_iocb_allocation = __constant_cpu_to_le16(256);
  2098. nv->execution_throttle = __constant_cpu_to_le16(16);
  2099. nv->retry_count = 8;
  2100. nv->retry_delay = 1;
  2101. nv->port_name[0] = 33;
  2102. nv->port_name[3] = 224;
  2103. nv->port_name[4] = 139;
  2104. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  2105. nv->login_timeout = 4;
  2106. /*
  2107. * Set default host adapter parameters
  2108. */
  2109. nv->host_p[1] = BIT_2;
  2110. nv->reset_delay = 5;
  2111. nv->port_down_retry_count = 8;
  2112. nv->max_luns_per_target = __constant_cpu_to_le16(8);
  2113. nv->link_down_timeout = 60;
  2114. rval = 1;
  2115. }
  2116. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2117. /*
  2118. * The SN2 does not provide BIOS emulation which means you can't change
  2119. * potentially bogus BIOS settings. Force the use of default settings
  2120. * for link rate and frame size. Hope that the rest of the settings
  2121. * are valid.
  2122. */
  2123. if (ia64_platform_is("sn2")) {
  2124. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  2125. if (IS_QLA23XX(ha))
  2126. nv->special_options[1] = BIT_7;
  2127. }
  2128. #endif
  2129. /* Reset Initialization control block */
  2130. memset(icb, 0, ha->init_cb_size);
  2131. /*
  2132. * Setup driver NVRAM options.
  2133. */
  2134. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  2135. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  2136. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  2137. nv->firmware_options[1] &= ~BIT_4;
  2138. if (IS_QLA23XX(ha)) {
  2139. nv->firmware_options[0] |= BIT_2;
  2140. nv->firmware_options[0] &= ~BIT_3;
  2141. nv->special_options[0] &= ~BIT_6;
  2142. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  2143. if (IS_QLA2300(ha)) {
  2144. if (ha->fb_rev == FPM_2310) {
  2145. strcpy(ha->model_number, "QLA2310");
  2146. } else {
  2147. strcpy(ha->model_number, "QLA2300");
  2148. }
  2149. } else {
  2150. qla2x00_set_model_info(vha, nv->model_number,
  2151. sizeof(nv->model_number), "QLA23xx");
  2152. }
  2153. } else if (IS_QLA2200(ha)) {
  2154. nv->firmware_options[0] |= BIT_2;
  2155. /*
  2156. * 'Point-to-point preferred, else loop' is not a safe
  2157. * connection mode setting.
  2158. */
  2159. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  2160. (BIT_5 | BIT_4)) {
  2161. /* Force 'loop preferred, else point-to-point'. */
  2162. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  2163. nv->add_firmware_options[0] |= BIT_5;
  2164. }
  2165. strcpy(ha->model_number, "QLA22xx");
  2166. } else /*if (IS_QLA2100(ha))*/ {
  2167. strcpy(ha->model_number, "QLA2100");
  2168. }
  2169. /*
  2170. * Copy over NVRAM RISC parameter block to initialization control block.
  2171. */
  2172. dptr1 = (uint8_t *)icb;
  2173. dptr2 = (uint8_t *)&nv->parameter_block_version;
  2174. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  2175. while (cnt--)
  2176. *dptr1++ = *dptr2++;
  2177. /* Copy 2nd half. */
  2178. dptr1 = (uint8_t *)icb->add_firmware_options;
  2179. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  2180. while (cnt--)
  2181. *dptr1++ = *dptr2++;
  2182. /* Use alternate WWN? */
  2183. if (nv->host_p[1] & BIT_7) {
  2184. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  2185. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  2186. }
  2187. /* Prepare nodename */
  2188. if ((icb->firmware_options[1] & BIT_6) == 0) {
  2189. /*
  2190. * Firmware will apply the following mask if the nodename was
  2191. * not provided.
  2192. */
  2193. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  2194. icb->node_name[0] &= 0xF0;
  2195. }
  2196. /*
  2197. * Set host adapter parameters.
  2198. */
  2199. /*
  2200. * BIT_7 in the host-parameters section allows for modification to
  2201. * internal driver logging.
  2202. */
  2203. if (nv->host_p[0] & BIT_7)
  2204. ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
  2205. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  2206. /* Always load RISC code on non ISP2[12]00 chips. */
  2207. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  2208. ha->flags.disable_risc_code_load = 0;
  2209. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  2210. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  2211. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  2212. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  2213. ha->flags.disable_serdes = 0;
  2214. ha->operating_mode =
  2215. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  2216. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  2217. sizeof(ha->fw_seriallink_options));
  2218. /* save HBA serial number */
  2219. ha->serial0 = icb->port_name[5];
  2220. ha->serial1 = icb->port_name[6];
  2221. ha->serial2 = icb->port_name[7];
  2222. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  2223. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  2224. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  2225. ha->retry_count = nv->retry_count;
  2226. /* Set minimum login_timeout to 4 seconds. */
  2227. if (nv->login_timeout != ql2xlogintimeout)
  2228. nv->login_timeout = ql2xlogintimeout;
  2229. if (nv->login_timeout < 4)
  2230. nv->login_timeout = 4;
  2231. ha->login_timeout = nv->login_timeout;
  2232. icb->login_timeout = nv->login_timeout;
  2233. /* Set minimum RATOV to 100 tenths of a second. */
  2234. ha->r_a_tov = 100;
  2235. ha->loop_reset_delay = nv->reset_delay;
  2236. /* Link Down Timeout = 0:
  2237. *
  2238. * When Port Down timer expires we will start returning
  2239. * I/O's to OS with "DID_NO_CONNECT".
  2240. *
  2241. * Link Down Timeout != 0:
  2242. *
  2243. * The driver waits for the link to come up after link down
  2244. * before returning I/Os to OS with "DID_NO_CONNECT".
  2245. */
  2246. if (nv->link_down_timeout == 0) {
  2247. ha->loop_down_abort_time =
  2248. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  2249. } else {
  2250. ha->link_down_timeout = nv->link_down_timeout;
  2251. ha->loop_down_abort_time =
  2252. (LOOP_DOWN_TIME - ha->link_down_timeout);
  2253. }
  2254. /*
  2255. * Need enough time to try and get the port back.
  2256. */
  2257. ha->port_down_retry_count = nv->port_down_retry_count;
  2258. if (qlport_down_retry)
  2259. ha->port_down_retry_count = qlport_down_retry;
  2260. /* Set login_retry_count */
  2261. ha->login_retry_count = nv->retry_count;
  2262. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  2263. ha->port_down_retry_count > 3)
  2264. ha->login_retry_count = ha->port_down_retry_count;
  2265. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  2266. ha->login_retry_count = ha->port_down_retry_count;
  2267. if (ql2xloginretrycount)
  2268. ha->login_retry_count = ql2xloginretrycount;
  2269. icb->lun_enables = __constant_cpu_to_le16(0);
  2270. icb->command_resource_count = 0;
  2271. icb->immediate_notify_resource_count = 0;
  2272. icb->timeout = __constant_cpu_to_le16(0);
  2273. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  2274. /* Enable RIO */
  2275. icb->firmware_options[0] &= ~BIT_3;
  2276. icb->add_firmware_options[0] &=
  2277. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2278. icb->add_firmware_options[0] |= BIT_2;
  2279. icb->response_accumulation_timer = 3;
  2280. icb->interrupt_delay_timer = 5;
  2281. vha->flags.process_response_queue = 1;
  2282. } else {
  2283. /* Enable ZIO. */
  2284. if (!vha->flags.init_done) {
  2285. ha->zio_mode = icb->add_firmware_options[0] &
  2286. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2287. ha->zio_timer = icb->interrupt_delay_timer ?
  2288. icb->interrupt_delay_timer: 2;
  2289. }
  2290. icb->add_firmware_options[0] &=
  2291. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  2292. vha->flags.process_response_queue = 0;
  2293. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  2294. ha->zio_mode = QLA_ZIO_MODE_6;
  2295. ql_log(ql_log_info, vha, 0x0068,
  2296. "ZIO mode %d enabled; timer delay (%d us).\n",
  2297. ha->zio_mode, ha->zio_timer * 100);
  2298. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  2299. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  2300. vha->flags.process_response_queue = 1;
  2301. }
  2302. }
  2303. if (rval) {
  2304. ql_log(ql_log_warn, vha, 0x0069,
  2305. "NVRAM configuration failed.\n");
  2306. }
  2307. return (rval);
  2308. }
  2309. static void
  2310. qla2x00_rport_del(void *data)
  2311. {
  2312. fc_port_t *fcport = data;
  2313. struct fc_rport *rport;
  2314. scsi_qla_host_t *vha = fcport->vha;
  2315. unsigned long flags;
  2316. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2317. rport = fcport->drport ? fcport->drport: fcport->rport;
  2318. fcport->drport = NULL;
  2319. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2320. if (rport) {
  2321. fc_remote_port_delete(rport);
  2322. /*
  2323. * Release the target mode FC NEXUS in qla_target.c code
  2324. * if target mod is enabled.
  2325. */
  2326. qlt_fc_port_deleted(vha, fcport);
  2327. }
  2328. }
  2329. /**
  2330. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  2331. * @ha: HA context
  2332. * @flags: allocation flags
  2333. *
  2334. * Returns a pointer to the allocated fcport, or NULL, if none available.
  2335. */
  2336. fc_port_t *
  2337. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  2338. {
  2339. fc_port_t *fcport;
  2340. fcport = kzalloc(sizeof(fc_port_t), flags);
  2341. if (!fcport)
  2342. return NULL;
  2343. /* Setup fcport template structure. */
  2344. fcport->vha = vha;
  2345. fcport->port_type = FCT_UNKNOWN;
  2346. fcport->loop_id = FC_NO_LOOP_ID;
  2347. qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
  2348. fcport->supported_classes = FC_COS_UNSPECIFIED;
  2349. return fcport;
  2350. }
  2351. /*
  2352. * qla2x00_configure_loop
  2353. * Updates Fibre Channel Device Database with what is actually on loop.
  2354. *
  2355. * Input:
  2356. * ha = adapter block pointer.
  2357. *
  2358. * Returns:
  2359. * 0 = success.
  2360. * 1 = error.
  2361. * 2 = database was full and device was not configured.
  2362. */
  2363. static int
  2364. qla2x00_configure_loop(scsi_qla_host_t *vha)
  2365. {
  2366. int rval;
  2367. unsigned long flags, save_flags;
  2368. struct qla_hw_data *ha = vha->hw;
  2369. rval = QLA_SUCCESS;
  2370. /* Get Initiator ID */
  2371. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  2372. rval = qla2x00_configure_hba(vha);
  2373. if (rval != QLA_SUCCESS) {
  2374. ql_dbg(ql_dbg_disc, vha, 0x2013,
  2375. "Unable to configure HBA.\n");
  2376. return (rval);
  2377. }
  2378. }
  2379. save_flags = flags = vha->dpc_flags;
  2380. ql_dbg(ql_dbg_disc, vha, 0x2014,
  2381. "Configure loop -- dpc flags = 0x%lx.\n", flags);
  2382. /*
  2383. * If we have both an RSCN and PORT UPDATE pending then handle them
  2384. * both at the same time.
  2385. */
  2386. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2387. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  2388. qla2x00_get_data_rate(vha);
  2389. /* Determine what we need to do */
  2390. if (ha->current_topology == ISP_CFG_FL &&
  2391. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2392. set_bit(RSCN_UPDATE, &flags);
  2393. } else if (ha->current_topology == ISP_CFG_F &&
  2394. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  2395. set_bit(RSCN_UPDATE, &flags);
  2396. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  2397. } else if (ha->current_topology == ISP_CFG_N) {
  2398. clear_bit(RSCN_UPDATE, &flags);
  2399. } else if (!vha->flags.online ||
  2400. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  2401. set_bit(RSCN_UPDATE, &flags);
  2402. set_bit(LOCAL_LOOP_UPDATE, &flags);
  2403. }
  2404. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  2405. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2406. ql_dbg(ql_dbg_disc, vha, 0x2015,
  2407. "Loop resync needed, failing.\n");
  2408. rval = QLA_FUNCTION_FAILED;
  2409. } else
  2410. rval = qla2x00_configure_local_loop(vha);
  2411. }
  2412. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  2413. if (LOOP_TRANSITION(vha)) {
  2414. ql_dbg(ql_dbg_disc, vha, 0x201e,
  2415. "Needs RSCN update and loop transition.\n");
  2416. rval = QLA_FUNCTION_FAILED;
  2417. }
  2418. else
  2419. rval = qla2x00_configure_fabric(vha);
  2420. }
  2421. if (rval == QLA_SUCCESS) {
  2422. if (atomic_read(&vha->loop_down_timer) ||
  2423. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2424. rval = QLA_FUNCTION_FAILED;
  2425. } else {
  2426. atomic_set(&vha->loop_state, LOOP_READY);
  2427. ql_dbg(ql_dbg_disc, vha, 0x2069,
  2428. "LOOP READY.\n");
  2429. }
  2430. }
  2431. if (rval) {
  2432. ql_dbg(ql_dbg_disc, vha, 0x206a,
  2433. "%s *** FAILED ***.\n", __func__);
  2434. } else {
  2435. ql_dbg(ql_dbg_disc, vha, 0x206b,
  2436. "%s: exiting normally.\n", __func__);
  2437. }
  2438. /* Restore state if a resync event occurred during processing */
  2439. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  2440. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  2441. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2442. if (test_bit(RSCN_UPDATE, &save_flags)) {
  2443. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  2444. }
  2445. }
  2446. return (rval);
  2447. }
  2448. /*
  2449. * qla2x00_configure_local_loop
  2450. * Updates Fibre Channel Device Database with local loop devices.
  2451. *
  2452. * Input:
  2453. * ha = adapter block pointer.
  2454. *
  2455. * Returns:
  2456. * 0 = success.
  2457. */
  2458. static int
  2459. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  2460. {
  2461. int rval, rval2;
  2462. int found_devs;
  2463. int found;
  2464. fc_port_t *fcport, *new_fcport;
  2465. uint16_t index;
  2466. uint16_t entries;
  2467. char *id_iter;
  2468. uint16_t loop_id;
  2469. uint8_t domain, area, al_pa;
  2470. struct qla_hw_data *ha = vha->hw;
  2471. found_devs = 0;
  2472. new_fcport = NULL;
  2473. entries = MAX_FIBRE_DEVICES_LOOP;
  2474. /* Get list of logged in devices. */
  2475. memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
  2476. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  2477. &entries);
  2478. if (rval != QLA_SUCCESS)
  2479. goto cleanup_allocation;
  2480. ql_dbg(ql_dbg_disc, vha, 0x2017,
  2481. "Entries in ID list (%d).\n", entries);
  2482. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
  2483. (uint8_t *)ha->gid_list,
  2484. entries * sizeof(struct gid_list_info));
  2485. /* Allocate temporary fcport for any new fcports discovered. */
  2486. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2487. if (new_fcport == NULL) {
  2488. ql_log(ql_log_warn, vha, 0x2018,
  2489. "Memory allocation failed for fcport.\n");
  2490. rval = QLA_MEMORY_ALLOC_FAILED;
  2491. goto cleanup_allocation;
  2492. }
  2493. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2494. /*
  2495. * Mark local devices that were present with FCF_DEVICE_LOST for now.
  2496. */
  2497. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2498. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  2499. fcport->port_type != FCT_BROADCAST &&
  2500. (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  2501. ql_dbg(ql_dbg_disc, vha, 0x2019,
  2502. "Marking port lost loop_id=0x%04x.\n",
  2503. fcport->loop_id);
  2504. qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
  2505. }
  2506. }
  2507. /* Add devices to port list. */
  2508. id_iter = (char *)ha->gid_list;
  2509. for (index = 0; index < entries; index++) {
  2510. domain = ((struct gid_list_info *)id_iter)->domain;
  2511. area = ((struct gid_list_info *)id_iter)->area;
  2512. al_pa = ((struct gid_list_info *)id_iter)->al_pa;
  2513. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2514. loop_id = (uint16_t)
  2515. ((struct gid_list_info *)id_iter)->loop_id_2100;
  2516. else
  2517. loop_id = le16_to_cpu(
  2518. ((struct gid_list_info *)id_iter)->loop_id);
  2519. id_iter += ha->gid_list_info_size;
  2520. /* Bypass reserved domain fields. */
  2521. if ((domain & 0xf0) == 0xf0)
  2522. continue;
  2523. /* Bypass if not same domain and area of adapter. */
  2524. if (area && domain &&
  2525. (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
  2526. continue;
  2527. /* Bypass invalid local loop ID. */
  2528. if (loop_id > LAST_LOCAL_LOOP_ID)
  2529. continue;
  2530. memset(new_fcport, 0, sizeof(fc_port_t));
  2531. /* Fill in member data. */
  2532. new_fcport->d_id.b.domain = domain;
  2533. new_fcport->d_id.b.area = area;
  2534. new_fcport->d_id.b.al_pa = al_pa;
  2535. new_fcport->loop_id = loop_id;
  2536. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  2537. if (rval2 != QLA_SUCCESS) {
  2538. ql_dbg(ql_dbg_disc, vha, 0x201a,
  2539. "Failed to retrieve fcport information "
  2540. "-- get_port_database=%x, loop_id=0x%04x.\n",
  2541. rval2, new_fcport->loop_id);
  2542. ql_dbg(ql_dbg_disc, vha, 0x201b,
  2543. "Scheduling resync.\n");
  2544. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2545. continue;
  2546. }
  2547. /* Check for matching device in port list. */
  2548. found = 0;
  2549. fcport = NULL;
  2550. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2551. if (memcmp(new_fcport->port_name, fcport->port_name,
  2552. WWN_SIZE))
  2553. continue;
  2554. fcport->flags &= ~FCF_FABRIC_DEVICE;
  2555. fcport->loop_id = new_fcport->loop_id;
  2556. fcport->port_type = new_fcport->port_type;
  2557. fcport->d_id.b24 = new_fcport->d_id.b24;
  2558. memcpy(fcport->node_name, new_fcport->node_name,
  2559. WWN_SIZE);
  2560. found++;
  2561. break;
  2562. }
  2563. if (!found) {
  2564. /* New device, add to fcports list. */
  2565. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  2566. /* Allocate a new replacement fcport. */
  2567. fcport = new_fcport;
  2568. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2569. if (new_fcport == NULL) {
  2570. ql_log(ql_log_warn, vha, 0x201c,
  2571. "Failed to allocate memory for fcport.\n");
  2572. rval = QLA_MEMORY_ALLOC_FAILED;
  2573. goto cleanup_allocation;
  2574. }
  2575. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  2576. }
  2577. /* Base iIDMA settings on HBA port speed. */
  2578. fcport->fp_speed = ha->link_data_rate;
  2579. qla2x00_update_fcport(vha, fcport);
  2580. found_devs++;
  2581. }
  2582. cleanup_allocation:
  2583. kfree(new_fcport);
  2584. if (rval != QLA_SUCCESS) {
  2585. ql_dbg(ql_dbg_disc, vha, 0x201d,
  2586. "Configure local loop error exit: rval=%x.\n", rval);
  2587. }
  2588. return (rval);
  2589. }
  2590. static void
  2591. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2592. {
  2593. int rval;
  2594. uint16_t mb[4];
  2595. struct qla_hw_data *ha = vha->hw;
  2596. if (!IS_IIDMA_CAPABLE(ha))
  2597. return;
  2598. if (atomic_read(&fcport->state) != FCS_ONLINE)
  2599. return;
  2600. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  2601. fcport->fp_speed > ha->link_data_rate)
  2602. return;
  2603. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  2604. mb);
  2605. if (rval != QLA_SUCCESS) {
  2606. ql_dbg(ql_dbg_disc, vha, 0x2004,
  2607. "Unable to adjust iIDMA "
  2608. "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
  2609. "%04x.\n", fcport->port_name[0], fcport->port_name[1],
  2610. fcport->port_name[2], fcport->port_name[3],
  2611. fcport->port_name[4], fcport->port_name[5],
  2612. fcport->port_name[6], fcport->port_name[7], rval,
  2613. fcport->fp_speed, mb[0], mb[1]);
  2614. } else {
  2615. ql_dbg(ql_dbg_disc, vha, 0x2005,
  2616. "iIDMA adjusted to %s GB/s "
  2617. "on %02x%02x%02x%02x%02x%02x%02x%02x.\n",
  2618. qla2x00_get_link_speed_str(ha, fcport->fp_speed),
  2619. 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]);
  2623. }
  2624. }
  2625. static void
  2626. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  2627. {
  2628. struct fc_rport_identifiers rport_ids;
  2629. struct fc_rport *rport;
  2630. unsigned long flags;
  2631. qla2x00_rport_del(fcport);
  2632. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  2633. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  2634. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  2635. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  2636. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2637. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  2638. if (!rport) {
  2639. ql_log(ql_log_warn, vha, 0x2006,
  2640. "Unable to allocate fc remote port.\n");
  2641. return;
  2642. }
  2643. /*
  2644. * Create target mode FC NEXUS in qla_target.c if target mode is
  2645. * enabled..
  2646. */
  2647. qlt_fc_port_added(vha, fcport);
  2648. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  2649. *((fc_port_t **)rport->dd_data) = fcport;
  2650. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  2651. rport->supported_classes = fcport->supported_classes;
  2652. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  2653. if (fcport->port_type == FCT_INITIATOR)
  2654. rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
  2655. if (fcport->port_type == FCT_TARGET)
  2656. rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
  2657. fc_remote_port_rolechg(rport, rport_ids.roles);
  2658. }
  2659. /*
  2660. * qla2x00_update_fcport
  2661. * Updates device on list.
  2662. *
  2663. * Input:
  2664. * ha = adapter block pointer.
  2665. * fcport = port structure pointer.
  2666. *
  2667. * Return:
  2668. * 0 - Success
  2669. * BIT_0 - error
  2670. *
  2671. * Context:
  2672. * Kernel context.
  2673. */
  2674. void
  2675. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  2676. {
  2677. fcport->vha = vha;
  2678. fcport->login_retry = 0;
  2679. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  2680. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  2681. qla2x00_iidma_fcport(vha, fcport);
  2682. qla24xx_update_fcport_fcp_prio(vha, fcport);
  2683. qla2x00_reg_remote_port(vha, fcport);
  2684. }
  2685. /*
  2686. * qla2x00_configure_fabric
  2687. * Setup SNS devices with loop ID's.
  2688. *
  2689. * Input:
  2690. * ha = adapter block pointer.
  2691. *
  2692. * Returns:
  2693. * 0 = success.
  2694. * BIT_0 = error
  2695. */
  2696. static int
  2697. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  2698. {
  2699. int rval;
  2700. fc_port_t *fcport, *fcptemp;
  2701. uint16_t next_loopid;
  2702. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2703. uint16_t loop_id;
  2704. LIST_HEAD(new_fcports);
  2705. struct qla_hw_data *ha = vha->hw;
  2706. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  2707. /* If FL port exists, then SNS is present */
  2708. if (IS_FWI2_CAPABLE(ha))
  2709. loop_id = NPH_F_PORT;
  2710. else
  2711. loop_id = SNS_FL_PORT;
  2712. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  2713. if (rval != QLA_SUCCESS) {
  2714. ql_dbg(ql_dbg_disc, vha, 0x201f,
  2715. "MBX_GET_PORT_NAME failed, No FL Port.\n");
  2716. vha->device_flags &= ~SWITCH_FOUND;
  2717. return (QLA_SUCCESS);
  2718. }
  2719. vha->device_flags |= SWITCH_FOUND;
  2720. do {
  2721. /* FDMI support. */
  2722. if (ql2xfdmienable &&
  2723. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  2724. qla2x00_fdmi_register(vha);
  2725. /* Ensure we are logged into the SNS. */
  2726. if (IS_FWI2_CAPABLE(ha))
  2727. loop_id = NPH_SNS;
  2728. else
  2729. loop_id = SIMPLE_NAME_SERVER;
  2730. rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  2731. 0xfc, mb, BIT_1|BIT_0);
  2732. if (rval != QLA_SUCCESS) {
  2733. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2734. return rval;
  2735. }
  2736. if (mb[0] != MBS_COMMAND_COMPLETE) {
  2737. ql_dbg(ql_dbg_disc, vha, 0x2042,
  2738. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
  2739. "mb[6]=%x mb[7]=%x.\n", loop_id, mb[0], mb[1],
  2740. mb[2], mb[6], mb[7]);
  2741. return (QLA_SUCCESS);
  2742. }
  2743. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  2744. if (qla2x00_rft_id(vha)) {
  2745. /* EMPTY */
  2746. ql_dbg(ql_dbg_disc, vha, 0x2045,
  2747. "Register FC-4 TYPE failed.\n");
  2748. }
  2749. if (qla2x00_rff_id(vha)) {
  2750. /* EMPTY */
  2751. ql_dbg(ql_dbg_disc, vha, 0x2049,
  2752. "Register FC-4 Features failed.\n");
  2753. }
  2754. if (qla2x00_rnn_id(vha)) {
  2755. /* EMPTY */
  2756. ql_dbg(ql_dbg_disc, vha, 0x204f,
  2757. "Register Node Name failed.\n");
  2758. } else if (qla2x00_rsnn_nn(vha)) {
  2759. /* EMPTY */
  2760. ql_dbg(ql_dbg_disc, vha, 0x2053,
  2761. "Register Symobilic Node Name failed.\n");
  2762. }
  2763. }
  2764. #define QLA_FCPORT_SCAN 1
  2765. #define QLA_FCPORT_FOUND 2
  2766. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2767. fcport->scan_state = QLA_FCPORT_SCAN;
  2768. }
  2769. rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
  2770. if (rval != QLA_SUCCESS)
  2771. break;
  2772. /*
  2773. * Logout all previous fabric devices marked lost, except
  2774. * FCP2 devices.
  2775. */
  2776. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2777. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2778. break;
  2779. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  2780. continue;
  2781. if (fcport->scan_state == QLA_FCPORT_SCAN &&
  2782. atomic_read(&fcport->state) == FCS_ONLINE) {
  2783. qla2x00_mark_device_lost(vha, fcport,
  2784. ql2xplogiabsentdevice, 0);
  2785. if (fcport->loop_id != FC_NO_LOOP_ID &&
  2786. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  2787. fcport->port_type != FCT_INITIATOR &&
  2788. fcport->port_type != FCT_BROADCAST) {
  2789. ha->isp_ops->fabric_logout(vha,
  2790. fcport->loop_id,
  2791. fcport->d_id.b.domain,
  2792. fcport->d_id.b.area,
  2793. fcport->d_id.b.al_pa);
  2794. fcport->loop_id = FC_NO_LOOP_ID;
  2795. }
  2796. }
  2797. }
  2798. /* Starting free loop ID. */
  2799. next_loopid = ha->min_external_loopid;
  2800. /*
  2801. * Scan through our port list and login entries that need to be
  2802. * logged in.
  2803. */
  2804. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2805. if (atomic_read(&vha->loop_down_timer) ||
  2806. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2807. break;
  2808. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
  2809. (fcport->flags & FCF_LOGIN_NEEDED) == 0)
  2810. continue;
  2811. if (fcport->loop_id == FC_NO_LOOP_ID) {
  2812. fcport->loop_id = next_loopid;
  2813. rval = qla2x00_find_new_loop_id(
  2814. base_vha, fcport);
  2815. if (rval != QLA_SUCCESS) {
  2816. /* Ran out of IDs to use */
  2817. break;
  2818. }
  2819. }
  2820. /* Login and update database */
  2821. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2822. }
  2823. /* Exit if out of loop IDs. */
  2824. if (rval != QLA_SUCCESS) {
  2825. break;
  2826. }
  2827. /*
  2828. * Login and add the new devices to our port list.
  2829. */
  2830. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2831. if (atomic_read(&vha->loop_down_timer) ||
  2832. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2833. break;
  2834. /* Find a new loop ID to use. */
  2835. fcport->loop_id = next_loopid;
  2836. rval = qla2x00_find_new_loop_id(base_vha, fcport);
  2837. if (rval != QLA_SUCCESS) {
  2838. /* Ran out of IDs to use */
  2839. break;
  2840. }
  2841. /* Login and update database */
  2842. qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
  2843. list_move_tail(&fcport->list, &vha->vp_fcports);
  2844. }
  2845. } while (0);
  2846. /* Free all new device structures not processed. */
  2847. list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
  2848. list_del(&fcport->list);
  2849. kfree(fcport);
  2850. }
  2851. if (rval) {
  2852. ql_dbg(ql_dbg_disc, vha, 0x2068,
  2853. "Configure fabric error exit rval=%d.\n", rval);
  2854. }
  2855. return (rval);
  2856. }
  2857. /*
  2858. * qla2x00_find_all_fabric_devs
  2859. *
  2860. * Input:
  2861. * ha = adapter block pointer.
  2862. * dev = database device entry pointer.
  2863. *
  2864. * Returns:
  2865. * 0 = success.
  2866. *
  2867. * Context:
  2868. * Kernel context.
  2869. */
  2870. static int
  2871. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
  2872. struct list_head *new_fcports)
  2873. {
  2874. int rval;
  2875. uint16_t loop_id;
  2876. fc_port_t *fcport, *new_fcport, *fcptemp;
  2877. int found;
  2878. sw_info_t *swl;
  2879. int swl_idx;
  2880. int first_dev, last_dev;
  2881. port_id_t wrap = {}, nxt_d_id;
  2882. struct qla_hw_data *ha = vha->hw;
  2883. struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
  2884. struct scsi_qla_host *tvp;
  2885. rval = QLA_SUCCESS;
  2886. /* Try GID_PT to get device list, else GAN. */
  2887. if (!ha->swl)
  2888. ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
  2889. GFP_KERNEL);
  2890. swl = ha->swl;
  2891. if (!swl) {
  2892. /*EMPTY*/
  2893. ql_dbg(ql_dbg_disc, vha, 0x2054,
  2894. "GID_PT allocations failed, fallback on GA_NXT.\n");
  2895. } else {
  2896. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  2897. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  2898. swl = NULL;
  2899. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  2900. swl = NULL;
  2901. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  2902. swl = NULL;
  2903. } else if (ql2xiidmaenable &&
  2904. qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
  2905. qla2x00_gpsc(vha, swl);
  2906. }
  2907. /* If other queries succeeded probe for FC-4 type */
  2908. if (swl)
  2909. qla2x00_gff_id(vha, swl);
  2910. }
  2911. swl_idx = 0;
  2912. /* Allocate temporary fcport for any new fcports discovered. */
  2913. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  2914. if (new_fcport == NULL) {
  2915. ql_log(ql_log_warn, vha, 0x205e,
  2916. "Failed to allocate memory for fcport.\n");
  2917. return (QLA_MEMORY_ALLOC_FAILED);
  2918. }
  2919. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  2920. /* Set start port ID scan at adapter ID. */
  2921. first_dev = 1;
  2922. last_dev = 0;
  2923. /* Starting free loop ID. */
  2924. loop_id = ha->min_external_loopid;
  2925. for (; loop_id <= ha->max_loop_id; loop_id++) {
  2926. if (qla2x00_is_reserved_id(vha, loop_id))
  2927. continue;
  2928. if (ha->current_topology == ISP_CFG_FL &&
  2929. (atomic_read(&vha->loop_down_timer) ||
  2930. LOOP_TRANSITION(vha))) {
  2931. atomic_set(&vha->loop_down_timer, 0);
  2932. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  2933. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  2934. break;
  2935. }
  2936. if (swl != NULL) {
  2937. if (last_dev) {
  2938. wrap.b24 = new_fcport->d_id.b24;
  2939. } else {
  2940. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  2941. memcpy(new_fcport->node_name,
  2942. swl[swl_idx].node_name, WWN_SIZE);
  2943. memcpy(new_fcport->port_name,
  2944. swl[swl_idx].port_name, WWN_SIZE);
  2945. memcpy(new_fcport->fabric_port_name,
  2946. swl[swl_idx].fabric_port_name, WWN_SIZE);
  2947. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  2948. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  2949. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  2950. last_dev = 1;
  2951. }
  2952. swl_idx++;
  2953. }
  2954. } else {
  2955. /* Send GA_NXT to the switch */
  2956. rval = qla2x00_ga_nxt(vha, new_fcport);
  2957. if (rval != QLA_SUCCESS) {
  2958. ql_log(ql_log_warn, vha, 0x2064,
  2959. "SNS scan failed -- assuming "
  2960. "zero-entry result.\n");
  2961. list_for_each_entry_safe(fcport, fcptemp,
  2962. new_fcports, list) {
  2963. list_del(&fcport->list);
  2964. kfree(fcport);
  2965. }
  2966. rval = QLA_SUCCESS;
  2967. break;
  2968. }
  2969. }
  2970. /* If wrap on switch device list, exit. */
  2971. if (first_dev) {
  2972. wrap.b24 = new_fcport->d_id.b24;
  2973. first_dev = 0;
  2974. } else if (new_fcport->d_id.b24 == wrap.b24) {
  2975. ql_dbg(ql_dbg_disc, vha, 0x2065,
  2976. "Device wrap (%02x%02x%02x).\n",
  2977. new_fcport->d_id.b.domain,
  2978. new_fcport->d_id.b.area,
  2979. new_fcport->d_id.b.al_pa);
  2980. break;
  2981. }
  2982. /* Bypass if same physical adapter. */
  2983. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  2984. continue;
  2985. /* Bypass virtual ports of the same host. */
  2986. found = 0;
  2987. if (ha->num_vhosts) {
  2988. unsigned long flags;
  2989. spin_lock_irqsave(&ha->vport_slock, flags);
  2990. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  2991. if (new_fcport->d_id.b24 == vp->d_id.b24) {
  2992. found = 1;
  2993. break;
  2994. }
  2995. }
  2996. spin_unlock_irqrestore(&ha->vport_slock, flags);
  2997. if (found)
  2998. continue;
  2999. }
  3000. /* Bypass if same domain and area of adapter. */
  3001. if (((new_fcport->d_id.b24 & 0xffff00) ==
  3002. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  3003. ISP_CFG_FL)
  3004. continue;
  3005. /* Bypass reserved domain fields. */
  3006. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  3007. continue;
  3008. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  3009. if (ql2xgffidenable &&
  3010. (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
  3011. new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
  3012. continue;
  3013. /* Locate matching device in database. */
  3014. found = 0;
  3015. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3016. if (memcmp(new_fcport->port_name, fcport->port_name,
  3017. WWN_SIZE))
  3018. continue;
  3019. fcport->scan_state = QLA_FCPORT_FOUND;
  3020. found++;
  3021. /* Update port state. */
  3022. memcpy(fcport->fabric_port_name,
  3023. new_fcport->fabric_port_name, WWN_SIZE);
  3024. fcport->fp_speed = new_fcport->fp_speed;
  3025. /*
  3026. * If address the same and state FCS_ONLINE, nothing
  3027. * changed.
  3028. */
  3029. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  3030. atomic_read(&fcport->state) == FCS_ONLINE) {
  3031. break;
  3032. }
  3033. /*
  3034. * If device was not a fabric device before.
  3035. */
  3036. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  3037. fcport->d_id.b24 = new_fcport->d_id.b24;
  3038. qla2x00_clear_loop_id(fcport);
  3039. fcport->flags |= (FCF_FABRIC_DEVICE |
  3040. FCF_LOGIN_NEEDED);
  3041. break;
  3042. }
  3043. /*
  3044. * Port ID changed or device was marked to be updated;
  3045. * Log it out if still logged in and mark it for
  3046. * relogin later.
  3047. */
  3048. fcport->d_id.b24 = new_fcport->d_id.b24;
  3049. fcport->flags |= FCF_LOGIN_NEEDED;
  3050. if (fcport->loop_id != FC_NO_LOOP_ID &&
  3051. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  3052. (fcport->flags & FCF_ASYNC_SENT) == 0 &&
  3053. fcport->port_type != FCT_INITIATOR &&
  3054. fcport->port_type != FCT_BROADCAST) {
  3055. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3056. fcport->d_id.b.domain, fcport->d_id.b.area,
  3057. fcport->d_id.b.al_pa);
  3058. qla2x00_clear_loop_id(fcport);
  3059. }
  3060. break;
  3061. }
  3062. if (found)
  3063. continue;
  3064. /* If device was not in our fcports list, then add it. */
  3065. list_add_tail(&new_fcport->list, new_fcports);
  3066. /* Allocate a new replacement fcport. */
  3067. nxt_d_id.b24 = new_fcport->d_id.b24;
  3068. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  3069. if (new_fcport == NULL) {
  3070. ql_log(ql_log_warn, vha, 0x2066,
  3071. "Memory allocation failed for fcport.\n");
  3072. return (QLA_MEMORY_ALLOC_FAILED);
  3073. }
  3074. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  3075. new_fcport->d_id.b24 = nxt_d_id.b24;
  3076. }
  3077. kfree(new_fcport);
  3078. return (rval);
  3079. }
  3080. /*
  3081. * qla2x00_find_new_loop_id
  3082. * Scan through our port list and find a new usable loop ID.
  3083. *
  3084. * Input:
  3085. * ha: adapter state pointer.
  3086. * dev: port structure pointer.
  3087. *
  3088. * Returns:
  3089. * qla2x00 local function return status code.
  3090. *
  3091. * Context:
  3092. * Kernel context.
  3093. */
  3094. int
  3095. qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  3096. {
  3097. int rval;
  3098. struct qla_hw_data *ha = vha->hw;
  3099. unsigned long flags = 0;
  3100. rval = QLA_SUCCESS;
  3101. spin_lock_irqsave(&ha->vport_slock, flags);
  3102. dev->loop_id = find_first_zero_bit(ha->loop_id_map,
  3103. LOOPID_MAP_SIZE);
  3104. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  3105. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  3106. dev->loop_id = FC_NO_LOOP_ID;
  3107. rval = QLA_FUNCTION_FAILED;
  3108. } else
  3109. set_bit(dev->loop_id, ha->loop_id_map);
  3110. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3111. if (rval == QLA_SUCCESS)
  3112. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  3113. "Assigning new loopid=%x, portid=%x.\n",
  3114. dev->loop_id, dev->d_id.b24);
  3115. else
  3116. ql_log(ql_log_warn, dev->vha, 0x2087,
  3117. "No loop_id's available, portid=%x.\n",
  3118. dev->d_id.b24);
  3119. return (rval);
  3120. }
  3121. /*
  3122. * qla2x00_fabric_dev_login
  3123. * Login fabric target device and update FC port database.
  3124. *
  3125. * Input:
  3126. * ha: adapter state pointer.
  3127. * fcport: port structure list pointer.
  3128. * next_loopid: contains value of a new loop ID that can be used
  3129. * by the next login attempt.
  3130. *
  3131. * Returns:
  3132. * qla2x00 local function return status code.
  3133. *
  3134. * Context:
  3135. * Kernel context.
  3136. */
  3137. static int
  3138. qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3139. uint16_t *next_loopid)
  3140. {
  3141. int rval;
  3142. int retry;
  3143. uint8_t opts;
  3144. struct qla_hw_data *ha = vha->hw;
  3145. rval = QLA_SUCCESS;
  3146. retry = 0;
  3147. if (IS_ALOGIO_CAPABLE(ha)) {
  3148. if (fcport->flags & FCF_ASYNC_SENT)
  3149. return rval;
  3150. fcport->flags |= FCF_ASYNC_SENT;
  3151. rval = qla2x00_post_async_login_work(vha, fcport, NULL);
  3152. if (!rval)
  3153. return rval;
  3154. }
  3155. fcport->flags &= ~FCF_ASYNC_SENT;
  3156. rval = qla2x00_fabric_login(vha, fcport, next_loopid);
  3157. if (rval == QLA_SUCCESS) {
  3158. /* Send an ADISC to FCP2 devices.*/
  3159. opts = 0;
  3160. if (fcport->flags & FCF_FCP2_DEVICE)
  3161. opts |= BIT_1;
  3162. rval = qla2x00_get_port_database(vha, fcport, opts);
  3163. if (rval != QLA_SUCCESS) {
  3164. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3165. fcport->d_id.b.domain, fcport->d_id.b.area,
  3166. fcport->d_id.b.al_pa);
  3167. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3168. } else {
  3169. qla2x00_update_fcport(vha, fcport);
  3170. }
  3171. } else {
  3172. /* Retry Login. */
  3173. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3174. }
  3175. return (rval);
  3176. }
  3177. /*
  3178. * qla2x00_fabric_login
  3179. * Issue fabric login command.
  3180. *
  3181. * Input:
  3182. * ha = adapter block pointer.
  3183. * device = pointer to FC device type structure.
  3184. *
  3185. * Returns:
  3186. * 0 - Login successfully
  3187. * 1 - Login failed
  3188. * 2 - Initiator device
  3189. * 3 - Fatal error
  3190. */
  3191. int
  3192. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  3193. uint16_t *next_loopid)
  3194. {
  3195. int rval;
  3196. int retry;
  3197. uint16_t tmp_loopid;
  3198. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3199. struct qla_hw_data *ha = vha->hw;
  3200. retry = 0;
  3201. tmp_loopid = 0;
  3202. for (;;) {
  3203. ql_dbg(ql_dbg_disc, vha, 0x2000,
  3204. "Trying Fabric Login w/loop id 0x%04x for port "
  3205. "%02x%02x%02x.\n",
  3206. fcport->loop_id, fcport->d_id.b.domain,
  3207. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3208. /* Login fcport on switch. */
  3209. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  3210. fcport->d_id.b.domain, fcport->d_id.b.area,
  3211. fcport->d_id.b.al_pa, mb, BIT_0);
  3212. if (rval != QLA_SUCCESS) {
  3213. return rval;
  3214. }
  3215. if (mb[0] == MBS_PORT_ID_USED) {
  3216. /*
  3217. * Device has another loop ID. The firmware team
  3218. * recommends the driver perform an implicit login with
  3219. * the specified ID again. The ID we just used is save
  3220. * here so we return with an ID that can be tried by
  3221. * the next login.
  3222. */
  3223. retry++;
  3224. tmp_loopid = fcport->loop_id;
  3225. fcport->loop_id = mb[1];
  3226. ql_dbg(ql_dbg_disc, vha, 0x2001,
  3227. "Fabric Login: port in use - next loop "
  3228. "id=0x%04x, port id= %02x%02x%02x.\n",
  3229. fcport->loop_id, fcport->d_id.b.domain,
  3230. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  3231. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  3232. /*
  3233. * Login succeeded.
  3234. */
  3235. if (retry) {
  3236. /* A retry occurred before. */
  3237. *next_loopid = tmp_loopid;
  3238. } else {
  3239. /*
  3240. * No retry occurred before. Just increment the
  3241. * ID value for next login.
  3242. */
  3243. *next_loopid = (fcport->loop_id + 1);
  3244. }
  3245. if (mb[1] & BIT_0) {
  3246. fcport->port_type = FCT_INITIATOR;
  3247. } else {
  3248. fcport->port_type = FCT_TARGET;
  3249. if (mb[1] & BIT_1) {
  3250. fcport->flags |= FCF_FCP2_DEVICE;
  3251. }
  3252. }
  3253. if (mb[10] & BIT_0)
  3254. fcport->supported_classes |= FC_COS_CLASS2;
  3255. if (mb[10] & BIT_1)
  3256. fcport->supported_classes |= FC_COS_CLASS3;
  3257. if (IS_FWI2_CAPABLE(ha)) {
  3258. if (mb[10] & BIT_7)
  3259. fcport->flags |=
  3260. FCF_CONF_COMP_SUPPORTED;
  3261. }
  3262. rval = QLA_SUCCESS;
  3263. break;
  3264. } else if (mb[0] == MBS_LOOP_ID_USED) {
  3265. /*
  3266. * Loop ID already used, try next loop ID.
  3267. */
  3268. fcport->loop_id++;
  3269. rval = qla2x00_find_new_loop_id(vha, fcport);
  3270. if (rval != QLA_SUCCESS) {
  3271. /* Ran out of loop IDs to use */
  3272. break;
  3273. }
  3274. } else if (mb[0] == MBS_COMMAND_ERROR) {
  3275. /*
  3276. * Firmware possibly timed out during login. If NO
  3277. * retries are left to do then the device is declared
  3278. * dead.
  3279. */
  3280. *next_loopid = fcport->loop_id;
  3281. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3282. fcport->d_id.b.domain, fcport->d_id.b.area,
  3283. fcport->d_id.b.al_pa);
  3284. qla2x00_mark_device_lost(vha, fcport, 1, 0);
  3285. rval = 1;
  3286. break;
  3287. } else {
  3288. /*
  3289. * unrecoverable / not handled error
  3290. */
  3291. ql_dbg(ql_dbg_disc, vha, 0x2002,
  3292. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  3293. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  3294. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  3295. fcport->loop_id, jiffies);
  3296. *next_loopid = fcport->loop_id;
  3297. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  3298. fcport->d_id.b.domain, fcport->d_id.b.area,
  3299. fcport->d_id.b.al_pa);
  3300. qla2x00_clear_loop_id(fcport);
  3301. fcport->login_retry = 0;
  3302. rval = 3;
  3303. break;
  3304. }
  3305. }
  3306. return (rval);
  3307. }
  3308. /*
  3309. * qla2x00_local_device_login
  3310. * Issue local device login command.
  3311. *
  3312. * Input:
  3313. * ha = adapter block pointer.
  3314. * loop_id = loop id of device to login to.
  3315. *
  3316. * Returns (Where's the #define!!!!):
  3317. * 0 - Login successfully
  3318. * 1 - Login failed
  3319. * 3 - Fatal error
  3320. */
  3321. int
  3322. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  3323. {
  3324. int rval;
  3325. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3326. memset(mb, 0, sizeof(mb));
  3327. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  3328. if (rval == QLA_SUCCESS) {
  3329. /* Interrogate mailbox registers for any errors */
  3330. if (mb[0] == MBS_COMMAND_ERROR)
  3331. rval = 1;
  3332. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  3333. /* device not in PCB table */
  3334. rval = 3;
  3335. }
  3336. return (rval);
  3337. }
  3338. /*
  3339. * qla2x00_loop_resync
  3340. * Resync with fibre channel devices.
  3341. *
  3342. * Input:
  3343. * ha = adapter block pointer.
  3344. *
  3345. * Returns:
  3346. * 0 = success
  3347. */
  3348. int
  3349. qla2x00_loop_resync(scsi_qla_host_t *vha)
  3350. {
  3351. int rval = QLA_SUCCESS;
  3352. uint32_t wait_time;
  3353. struct req_que *req;
  3354. struct rsp_que *rsp;
  3355. if (vha->hw->flags.cpu_affinity_enabled)
  3356. req = vha->hw->req_q_map[0];
  3357. else
  3358. req = vha->req;
  3359. rsp = req->rsp;
  3360. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3361. if (vha->flags.online) {
  3362. if (!(rval = qla2x00_fw_ready(vha))) {
  3363. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3364. wait_time = 256;
  3365. do {
  3366. /* Issue a marker after FW becomes ready. */
  3367. qla2x00_marker(vha, req, rsp, 0, 0,
  3368. MK_SYNC_ALL);
  3369. vha->marker_needed = 0;
  3370. /* Remap devices on Loop. */
  3371. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3372. qla2x00_configure_loop(vha);
  3373. wait_time--;
  3374. } while (!atomic_read(&vha->loop_down_timer) &&
  3375. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3376. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3377. &vha->dpc_flags)));
  3378. }
  3379. }
  3380. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3381. return (QLA_FUNCTION_FAILED);
  3382. if (rval)
  3383. ql_dbg(ql_dbg_disc, vha, 0x206c,
  3384. "%s *** FAILED ***.\n", __func__);
  3385. return (rval);
  3386. }
  3387. /*
  3388. * qla2x00_perform_loop_resync
  3389. * Description: This function will set the appropriate flags and call
  3390. * qla2x00_loop_resync. If successful loop will be resynced
  3391. * Arguments : scsi_qla_host_t pointer
  3392. * returm : Success or Failure
  3393. */
  3394. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  3395. {
  3396. int32_t rval = 0;
  3397. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  3398. /*Configure the flags so that resync happens properly*/
  3399. atomic_set(&ha->loop_down_timer, 0);
  3400. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  3401. atomic_set(&ha->loop_state, LOOP_UP);
  3402. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  3403. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  3404. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  3405. rval = qla2x00_loop_resync(ha);
  3406. } else
  3407. atomic_set(&ha->loop_state, LOOP_DEAD);
  3408. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  3409. }
  3410. return rval;
  3411. }
  3412. void
  3413. qla2x00_update_fcports(scsi_qla_host_t *base_vha)
  3414. {
  3415. fc_port_t *fcport;
  3416. struct scsi_qla_host *vha;
  3417. struct qla_hw_data *ha = base_vha->hw;
  3418. unsigned long flags;
  3419. spin_lock_irqsave(&ha->vport_slock, flags);
  3420. /* Go with deferred removal of rport references. */
  3421. list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
  3422. atomic_inc(&vha->vref_count);
  3423. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  3424. if (fcport->drport &&
  3425. atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
  3426. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3427. qla2x00_rport_del(fcport);
  3428. spin_lock_irqsave(&ha->vport_slock, flags);
  3429. }
  3430. }
  3431. atomic_dec(&vha->vref_count);
  3432. }
  3433. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3434. }
  3435. /* Assumes idc_lock always held on entry */
  3436. void
  3437. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  3438. {
  3439. struct qla_hw_data *ha = vha->hw;
  3440. uint32_t drv_presence, drv_presence_mask;
  3441. uint32_t dev_part_info1, dev_part_info2, class_type;
  3442. uint32_t class_type_mask = 0x3;
  3443. uint16_t fcoe_other_function = 0xffff, i;
  3444. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3445. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  3446. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  3447. for (i = 0; i < 8; i++) {
  3448. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  3449. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3450. (i != ha->portnum)) {
  3451. fcoe_other_function = i;
  3452. break;
  3453. }
  3454. }
  3455. if (fcoe_other_function == 0xffff) {
  3456. for (i = 0; i < 8; i++) {
  3457. class_type = ((dev_part_info2 >> (i * 4)) &
  3458. class_type_mask);
  3459. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  3460. ((i + 8) != ha->portnum)) {
  3461. fcoe_other_function = i + 8;
  3462. break;
  3463. }
  3464. }
  3465. }
  3466. /*
  3467. * Prepare drv-presence mask based on fcoe functions present.
  3468. * However consider only valid physical fcoe function numbers (0-15).
  3469. */
  3470. drv_presence_mask = ~((1 << (ha->portnum)) |
  3471. ((fcoe_other_function == 0xffff) ?
  3472. 0 : (1 << (fcoe_other_function))));
  3473. /* We are the reset owner iff:
  3474. * - No other protocol drivers present.
  3475. * - This is the lowest among fcoe functions. */
  3476. if (!(drv_presence & drv_presence_mask) &&
  3477. (ha->portnum < fcoe_other_function)) {
  3478. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  3479. "This host is Reset owner.\n");
  3480. ha->flags.nic_core_reset_owner = 1;
  3481. }
  3482. }
  3483. static int
  3484. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  3485. {
  3486. int rval = QLA_SUCCESS;
  3487. struct qla_hw_data *ha = vha->hw;
  3488. uint32_t drv_ack;
  3489. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3490. if (rval == QLA_SUCCESS) {
  3491. drv_ack |= (1 << ha->portnum);
  3492. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3493. }
  3494. return rval;
  3495. }
  3496. static int
  3497. __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
  3498. {
  3499. int rval = QLA_SUCCESS;
  3500. struct qla_hw_data *ha = vha->hw;
  3501. uint32_t drv_ack;
  3502. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  3503. if (rval == QLA_SUCCESS) {
  3504. drv_ack &= ~(1 << ha->portnum);
  3505. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  3506. }
  3507. return rval;
  3508. }
  3509. static const char *
  3510. qla83xx_dev_state_to_string(uint32_t dev_state)
  3511. {
  3512. switch (dev_state) {
  3513. case QLA8XXX_DEV_COLD:
  3514. return "COLD/RE-INIT";
  3515. case QLA8XXX_DEV_INITIALIZING:
  3516. return "INITIALIZING";
  3517. case QLA8XXX_DEV_READY:
  3518. return "READY";
  3519. case QLA8XXX_DEV_NEED_RESET:
  3520. return "NEED RESET";
  3521. case QLA8XXX_DEV_NEED_QUIESCENT:
  3522. return "NEED QUIESCENT";
  3523. case QLA8XXX_DEV_FAILED:
  3524. return "FAILED";
  3525. case QLA8XXX_DEV_QUIESCENT:
  3526. return "QUIESCENT";
  3527. default:
  3528. return "Unknown";
  3529. }
  3530. }
  3531. /* Assumes idc-lock always held on entry */
  3532. void
  3533. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  3534. {
  3535. struct qla_hw_data *ha = vha->hw;
  3536. uint32_t idc_audit_reg = 0, duration_secs = 0;
  3537. switch (audit_type) {
  3538. case IDC_AUDIT_TIMESTAMP:
  3539. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  3540. idc_audit_reg = (ha->portnum) |
  3541. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  3542. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3543. break;
  3544. case IDC_AUDIT_COMPLETION:
  3545. duration_secs = ((jiffies_to_msecs(jiffies) -
  3546. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  3547. idc_audit_reg = (ha->portnum) |
  3548. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  3549. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  3550. break;
  3551. default:
  3552. ql_log(ql_log_warn, vha, 0xb078,
  3553. "Invalid audit type specified.\n");
  3554. break;
  3555. }
  3556. }
  3557. /* Assumes idc_lock always held on entry */
  3558. static int
  3559. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  3560. {
  3561. struct qla_hw_data *ha = vha->hw;
  3562. uint32_t idc_control, dev_state;
  3563. __qla83xx_get_idc_control(vha, &idc_control);
  3564. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  3565. ql_log(ql_log_info, vha, 0xb080,
  3566. "NIC Core reset has been disabled. idc-control=0x%x\n",
  3567. idc_control);
  3568. return QLA_FUNCTION_FAILED;
  3569. }
  3570. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  3571. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3572. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  3573. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  3574. QLA8XXX_DEV_NEED_RESET);
  3575. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  3576. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  3577. } else {
  3578. const char *state = qla83xx_dev_state_to_string(dev_state);
  3579. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
  3580. /* SV: XXX: Is timeout required here? */
  3581. /* Wait for IDC state change READY -> NEED_RESET */
  3582. while (dev_state == QLA8XXX_DEV_READY) {
  3583. qla83xx_idc_unlock(vha, 0);
  3584. msleep(200);
  3585. qla83xx_idc_lock(vha, 0);
  3586. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  3587. }
  3588. }
  3589. /* Send IDC ack by writing to drv-ack register */
  3590. __qla83xx_set_drv_ack(vha);
  3591. return QLA_SUCCESS;
  3592. }
  3593. int
  3594. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  3595. {
  3596. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3597. }
  3598. int
  3599. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  3600. {
  3601. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  3602. }
  3603. static int
  3604. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  3605. {
  3606. uint32_t drv_presence = 0;
  3607. struct qla_hw_data *ha = vha->hw;
  3608. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  3609. if (drv_presence & (1 << ha->portnum))
  3610. return QLA_SUCCESS;
  3611. else
  3612. return QLA_TEST_FAILED;
  3613. }
  3614. int
  3615. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  3616. {
  3617. int rval = QLA_SUCCESS;
  3618. struct qla_hw_data *ha = vha->hw;
  3619. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  3620. "Entered %s().\n", __func__);
  3621. if (vha->device_flags & DFLG_DEV_FAILED) {
  3622. ql_log(ql_log_warn, vha, 0xb059,
  3623. "Device in unrecoverable FAILED state.\n");
  3624. return QLA_FUNCTION_FAILED;
  3625. }
  3626. qla83xx_idc_lock(vha, 0);
  3627. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  3628. ql_log(ql_log_warn, vha, 0xb05a,
  3629. "Function=0x%x has been removed from IDC participation.\n",
  3630. ha->portnum);
  3631. rval = QLA_FUNCTION_FAILED;
  3632. goto exit;
  3633. }
  3634. qla83xx_reset_ownership(vha);
  3635. rval = qla83xx_initiating_reset(vha);
  3636. /*
  3637. * Perform reset if we are the reset-owner,
  3638. * else wait till IDC state changes to READY/FAILED.
  3639. */
  3640. if (rval == QLA_SUCCESS) {
  3641. rval = qla83xx_idc_state_handler(vha);
  3642. if (rval == QLA_SUCCESS)
  3643. ha->flags.nic_core_hung = 0;
  3644. __qla83xx_clear_drv_ack(vha);
  3645. }
  3646. exit:
  3647. qla83xx_idc_unlock(vha, 0);
  3648. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  3649. return rval;
  3650. }
  3651. int
  3652. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  3653. {
  3654. struct qla_hw_data *ha = vha->hw;
  3655. int rval = QLA_FUNCTION_FAILED;
  3656. if (!IS_MCTP_CAPABLE(ha)) {
  3657. /* This message can be removed from the final version */
  3658. ql_log(ql_log_info, vha, 0x506d,
  3659. "This board is not MCTP capable\n");
  3660. return rval;
  3661. }
  3662. if (!ha->mctp_dump) {
  3663. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  3664. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  3665. if (!ha->mctp_dump) {
  3666. ql_log(ql_log_warn, vha, 0x506e,
  3667. "Failed to allocate memory for mctp dump\n");
  3668. return rval;
  3669. }
  3670. }
  3671. #define MCTP_DUMP_STR_ADDR 0x00000000
  3672. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  3673. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  3674. if (rval != QLA_SUCCESS) {
  3675. ql_log(ql_log_warn, vha, 0x506f,
  3676. "Failed to capture mctp dump\n");
  3677. } else {
  3678. ql_log(ql_log_info, vha, 0x5070,
  3679. "Mctp dump capture for host (%ld/%p).\n",
  3680. vha->host_no, ha->mctp_dump);
  3681. ha->mctp_dumped = 1;
  3682. }
  3683. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  3684. ha->flags.nic_core_reset_hdlr_active = 1;
  3685. rval = qla83xx_restart_nic_firmware(vha);
  3686. if (rval)
  3687. /* NIC Core reset failed. */
  3688. ql_log(ql_log_warn, vha, 0x5071,
  3689. "Failed to restart nic firmware\n");
  3690. else
  3691. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  3692. "Restarted NIC firmware successfully.\n");
  3693. ha->flags.nic_core_reset_hdlr_active = 0;
  3694. }
  3695. return rval;
  3696. }
  3697. /*
  3698. * qla2x00_quiesce_io
  3699. * Description: This function will block the new I/Os
  3700. * Its not aborting any I/Os as context
  3701. * is not destroyed during quiescence
  3702. * Arguments: scsi_qla_host_t
  3703. * return : void
  3704. */
  3705. void
  3706. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  3707. {
  3708. struct qla_hw_data *ha = vha->hw;
  3709. struct scsi_qla_host *vp;
  3710. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  3711. "Quiescing I/O - ha=%p.\n", ha);
  3712. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  3713. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3714. atomic_set(&vha->loop_state, LOOP_DOWN);
  3715. qla2x00_mark_all_devices_lost(vha, 0);
  3716. list_for_each_entry(vp, &ha->vp_list, list)
  3717. qla2x00_mark_all_devices_lost(vp, 0);
  3718. } else {
  3719. if (!atomic_read(&vha->loop_down_timer))
  3720. atomic_set(&vha->loop_down_timer,
  3721. LOOP_DOWN_TIME);
  3722. }
  3723. /* Wait for pending cmds to complete */
  3724. qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
  3725. }
  3726. void
  3727. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  3728. {
  3729. struct qla_hw_data *ha = vha->hw;
  3730. struct scsi_qla_host *vp;
  3731. unsigned long flags;
  3732. fc_port_t *fcport;
  3733. /* For ISP82XX, driver waits for completion of the commands.
  3734. * online flag should be set.
  3735. */
  3736. if (!IS_QLA82XX(ha))
  3737. vha->flags.online = 0;
  3738. ha->flags.chip_reset_done = 0;
  3739. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  3740. vha->qla_stats.total_isp_aborts++;
  3741. ql_log(ql_log_info, vha, 0x00af,
  3742. "Performing ISP error recovery - ha=%p.\n", ha);
  3743. /* For ISP82XX, reset_chip is just disabling interrupts.
  3744. * Driver waits for the completion of the commands.
  3745. * the interrupts need to be enabled.
  3746. */
  3747. if (!IS_QLA82XX(ha))
  3748. ha->isp_ops->reset_chip(vha);
  3749. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  3750. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  3751. atomic_set(&vha->loop_state, LOOP_DOWN);
  3752. qla2x00_mark_all_devices_lost(vha, 0);
  3753. spin_lock_irqsave(&ha->vport_slock, flags);
  3754. list_for_each_entry(vp, &ha->vp_list, list) {
  3755. atomic_inc(&vp->vref_count);
  3756. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3757. qla2x00_mark_all_devices_lost(vp, 0);
  3758. spin_lock_irqsave(&ha->vport_slock, flags);
  3759. atomic_dec(&vp->vref_count);
  3760. }
  3761. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3762. } else {
  3763. if (!atomic_read(&vha->loop_down_timer))
  3764. atomic_set(&vha->loop_down_timer,
  3765. LOOP_DOWN_TIME);
  3766. }
  3767. /* Clear all async request states across all VPs. */
  3768. list_for_each_entry(fcport, &vha->vp_fcports, list)
  3769. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3770. spin_lock_irqsave(&ha->vport_slock, flags);
  3771. list_for_each_entry(vp, &ha->vp_list, list) {
  3772. atomic_inc(&vp->vref_count);
  3773. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3774. list_for_each_entry(fcport, &vp->vp_fcports, list)
  3775. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  3776. spin_lock_irqsave(&ha->vport_slock, flags);
  3777. atomic_dec(&vp->vref_count);
  3778. }
  3779. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3780. if (!ha->flags.eeh_busy) {
  3781. /* Make sure for ISP 82XX IO DMA is complete */
  3782. if (IS_QLA82XX(ha)) {
  3783. qla82xx_chip_reset_cleanup(vha);
  3784. ql_log(ql_log_info, vha, 0x00b4,
  3785. "Done chip reset cleanup.\n");
  3786. /* Done waiting for pending commands.
  3787. * Reset the online flag.
  3788. */
  3789. vha->flags.online = 0;
  3790. }
  3791. /* Requeue all commands in outstanding command list. */
  3792. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  3793. }
  3794. }
  3795. /*
  3796. * qla2x00_abort_isp
  3797. * Resets ISP and aborts all outstanding commands.
  3798. *
  3799. * Input:
  3800. * ha = adapter block pointer.
  3801. *
  3802. * Returns:
  3803. * 0 = success
  3804. */
  3805. int
  3806. qla2x00_abort_isp(scsi_qla_host_t *vha)
  3807. {
  3808. int rval;
  3809. uint8_t status = 0;
  3810. struct qla_hw_data *ha = vha->hw;
  3811. struct scsi_qla_host *vp;
  3812. struct req_que *req = ha->req_q_map[0];
  3813. unsigned long flags;
  3814. if (vha->flags.online) {
  3815. qla2x00_abort_isp_cleanup(vha);
  3816. if (IS_QLA8031(ha)) {
  3817. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  3818. "Clearing fcoe driver presence.\n");
  3819. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  3820. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  3821. "Error while clearing DRV-Presence.\n");
  3822. }
  3823. if (unlikely(pci_channel_offline(ha->pdev) &&
  3824. ha->flags.pci_channel_io_perm_failure)) {
  3825. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3826. status = 0;
  3827. return status;
  3828. }
  3829. ha->isp_ops->get_flash_version(vha, req->ring);
  3830. ha->isp_ops->nvram_config(vha);
  3831. if (!qla2x00_restart_isp(vha)) {
  3832. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3833. if (!atomic_read(&vha->loop_down_timer)) {
  3834. /*
  3835. * Issue marker command only when we are going
  3836. * to start the I/O .
  3837. */
  3838. vha->marker_needed = 1;
  3839. }
  3840. vha->flags.online = 1;
  3841. ha->isp_ops->enable_intrs(ha);
  3842. ha->isp_abort_cnt = 0;
  3843. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3844. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  3845. qla2x00_get_fw_version(vha);
  3846. if (ha->fce) {
  3847. ha->flags.fce_enabled = 1;
  3848. memset(ha->fce, 0,
  3849. fce_calc_size(ha->fce_bufs));
  3850. rval = qla2x00_enable_fce_trace(vha,
  3851. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  3852. &ha->fce_bufs);
  3853. if (rval) {
  3854. ql_log(ql_log_warn, vha, 0x8033,
  3855. "Unable to reinitialize FCE "
  3856. "(%d).\n", rval);
  3857. ha->flags.fce_enabled = 0;
  3858. }
  3859. }
  3860. if (ha->eft) {
  3861. memset(ha->eft, 0, EFT_SIZE);
  3862. rval = qla2x00_enable_eft_trace(vha,
  3863. ha->eft_dma, EFT_NUM_BUFFERS);
  3864. if (rval) {
  3865. ql_log(ql_log_warn, vha, 0x8034,
  3866. "Unable to reinitialize EFT "
  3867. "(%d).\n", rval);
  3868. }
  3869. }
  3870. } else { /* failed the ISP abort */
  3871. vha->flags.online = 1;
  3872. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  3873. if (ha->isp_abort_cnt == 0) {
  3874. ql_log(ql_log_fatal, vha, 0x8035,
  3875. "ISP error recover failed - "
  3876. "board disabled.\n");
  3877. /*
  3878. * The next call disables the board
  3879. * completely.
  3880. */
  3881. ha->isp_ops->reset_adapter(vha);
  3882. vha->flags.online = 0;
  3883. clear_bit(ISP_ABORT_RETRY,
  3884. &vha->dpc_flags);
  3885. status = 0;
  3886. } else { /* schedule another ISP abort */
  3887. ha->isp_abort_cnt--;
  3888. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  3889. "ISP abort - retry remaining %d.\n",
  3890. ha->isp_abort_cnt);
  3891. status = 1;
  3892. }
  3893. } else {
  3894. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  3895. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  3896. "ISP error recovery - retrying (%d) "
  3897. "more times.\n", ha->isp_abort_cnt);
  3898. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  3899. status = 1;
  3900. }
  3901. }
  3902. }
  3903. if (!status) {
  3904. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  3905. spin_lock_irqsave(&ha->vport_slock, flags);
  3906. list_for_each_entry(vp, &ha->vp_list, list) {
  3907. if (vp->vp_idx) {
  3908. atomic_inc(&vp->vref_count);
  3909. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3910. qla2x00_vp_abort_isp(vp);
  3911. spin_lock_irqsave(&ha->vport_slock, flags);
  3912. atomic_dec(&vp->vref_count);
  3913. }
  3914. }
  3915. spin_unlock_irqrestore(&ha->vport_slock, flags);
  3916. if (IS_QLA8031(ha)) {
  3917. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  3918. "Setting back fcoe driver presence.\n");
  3919. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  3920. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  3921. "Error while setting DRV-Presence.\n");
  3922. }
  3923. } else {
  3924. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  3925. __func__);
  3926. }
  3927. return(status);
  3928. }
  3929. /*
  3930. * qla2x00_restart_isp
  3931. * restarts the ISP after a reset
  3932. *
  3933. * Input:
  3934. * ha = adapter block pointer.
  3935. *
  3936. * Returns:
  3937. * 0 = success
  3938. */
  3939. static int
  3940. qla2x00_restart_isp(scsi_qla_host_t *vha)
  3941. {
  3942. int status = 0;
  3943. uint32_t wait_time;
  3944. struct qla_hw_data *ha = vha->hw;
  3945. struct req_que *req = ha->req_q_map[0];
  3946. struct rsp_que *rsp = ha->rsp_q_map[0];
  3947. unsigned long flags;
  3948. /* If firmware needs to be loaded */
  3949. if (qla2x00_isp_firmware(vha)) {
  3950. vha->flags.online = 0;
  3951. status = ha->isp_ops->chip_diag(vha);
  3952. if (!status)
  3953. status = qla2x00_setup_chip(vha);
  3954. }
  3955. if (!status && !(status = qla2x00_init_rings(vha))) {
  3956. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  3957. ha->flags.chip_reset_done = 1;
  3958. /* Initialize the queues in use */
  3959. qla25xx_init_queues(ha);
  3960. status = qla2x00_fw_ready(vha);
  3961. if (!status) {
  3962. ql_dbg(ql_dbg_taskm, vha, 0x8031,
  3963. "Start configure loop status = %d.\n", status);
  3964. /* Issue a marker after FW becomes ready. */
  3965. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  3966. vha->flags.online = 1;
  3967. /*
  3968. * Process any ATIO queue entries that came in
  3969. * while we weren't online.
  3970. */
  3971. spin_lock_irqsave(&ha->hardware_lock, flags);
  3972. if (qla_tgt_mode_enabled(vha))
  3973. qlt_24xx_process_atio_queue(vha);
  3974. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3975. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  3976. wait_time = 256;
  3977. do {
  3978. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  3979. qla2x00_configure_loop(vha);
  3980. wait_time--;
  3981. } while (!atomic_read(&vha->loop_down_timer) &&
  3982. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  3983. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  3984. &vha->dpc_flags)));
  3985. }
  3986. /* if no cable then assume it's good */
  3987. if ((vha->device_flags & DFLG_NO_CABLE))
  3988. status = 0;
  3989. ql_dbg(ql_dbg_taskm, vha, 0x8032,
  3990. "Configure loop done, status = 0x%x.\n", status);
  3991. }
  3992. return (status);
  3993. }
  3994. static int
  3995. qla25xx_init_queues(struct qla_hw_data *ha)
  3996. {
  3997. struct rsp_que *rsp = NULL;
  3998. struct req_que *req = NULL;
  3999. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4000. int ret = -1;
  4001. int i;
  4002. for (i = 1; i < ha->max_rsp_queues; i++) {
  4003. rsp = ha->rsp_q_map[i];
  4004. if (rsp) {
  4005. rsp->options &= ~BIT_0;
  4006. ret = qla25xx_init_rsp_que(base_vha, rsp);
  4007. if (ret != QLA_SUCCESS)
  4008. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  4009. "%s Rsp que: %d init failed.\n",
  4010. __func__, rsp->id);
  4011. else
  4012. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  4013. "%s Rsp que: %d inited.\n",
  4014. __func__, rsp->id);
  4015. }
  4016. }
  4017. for (i = 1; i < ha->max_req_queues; i++) {
  4018. req = ha->req_q_map[i];
  4019. if (req) {
  4020. /* Clear outstanding commands array. */
  4021. req->options &= ~BIT_0;
  4022. ret = qla25xx_init_req_que(base_vha, req);
  4023. if (ret != QLA_SUCCESS)
  4024. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  4025. "%s Req que: %d init failed.\n",
  4026. __func__, req->id);
  4027. else
  4028. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  4029. "%s Req que: %d inited.\n",
  4030. __func__, req->id);
  4031. }
  4032. }
  4033. return ret;
  4034. }
  4035. /*
  4036. * qla2x00_reset_adapter
  4037. * Reset adapter.
  4038. *
  4039. * Input:
  4040. * ha = adapter block pointer.
  4041. */
  4042. void
  4043. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  4044. {
  4045. unsigned long flags = 0;
  4046. struct qla_hw_data *ha = vha->hw;
  4047. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4048. vha->flags.online = 0;
  4049. ha->isp_ops->disable_intrs(ha);
  4050. spin_lock_irqsave(&ha->hardware_lock, flags);
  4051. WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
  4052. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4053. WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
  4054. RD_REG_WORD(&reg->hccr); /* PCI Posting. */
  4055. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4056. }
  4057. void
  4058. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  4059. {
  4060. unsigned long flags = 0;
  4061. struct qla_hw_data *ha = vha->hw;
  4062. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  4063. if (IS_QLA82XX(ha))
  4064. return;
  4065. vha->flags.online = 0;
  4066. ha->isp_ops->disable_intrs(ha);
  4067. spin_lock_irqsave(&ha->hardware_lock, flags);
  4068. WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
  4069. RD_REG_DWORD(&reg->hccr);
  4070. WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  4071. RD_REG_DWORD(&reg->hccr);
  4072. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4073. if (IS_NOPOLLING_TYPE(ha))
  4074. ha->isp_ops->enable_intrs(ha);
  4075. }
  4076. /* On sparc systems, obtain port and node WWN from firmware
  4077. * properties.
  4078. */
  4079. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  4080. struct nvram_24xx *nv)
  4081. {
  4082. #ifdef CONFIG_SPARC
  4083. struct qla_hw_data *ha = vha->hw;
  4084. struct pci_dev *pdev = ha->pdev;
  4085. struct device_node *dp = pci_device_to_OF_node(pdev);
  4086. const u8 *val;
  4087. int len;
  4088. val = of_get_property(dp, "port-wwn", &len);
  4089. if (val && len >= WWN_SIZE)
  4090. memcpy(nv->port_name, val, WWN_SIZE);
  4091. val = of_get_property(dp, "node-wwn", &len);
  4092. if (val && len >= WWN_SIZE)
  4093. memcpy(nv->node_name, val, WWN_SIZE);
  4094. #endif
  4095. }
  4096. int
  4097. qla24xx_nvram_config(scsi_qla_host_t *vha)
  4098. {
  4099. int rval;
  4100. struct init_cb_24xx *icb;
  4101. struct nvram_24xx *nv;
  4102. uint32_t *dptr;
  4103. uint8_t *dptr1, *dptr2;
  4104. uint32_t chksum;
  4105. uint16_t cnt;
  4106. struct qla_hw_data *ha = vha->hw;
  4107. rval = QLA_SUCCESS;
  4108. icb = (struct init_cb_24xx *)ha->init_cb;
  4109. nv = ha->nvram;
  4110. /* Determine NVRAM starting address. */
  4111. if (ha->flags.port0) {
  4112. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  4113. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  4114. } else {
  4115. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  4116. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  4117. }
  4118. ha->nvram_size = sizeof(struct nvram_24xx);
  4119. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4120. if (IS_QLA82XX(ha))
  4121. ha->vpd_size = FA_VPD_SIZE_82XX;
  4122. /* Get VPD data into cache */
  4123. ha->vpd = ha->nvram + VPD_OFFSET;
  4124. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
  4125. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  4126. /* Get NVRAM data into cache and calculate checksum. */
  4127. dptr = (uint32_t *)nv;
  4128. ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
  4129. ha->nvram_size);
  4130. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4131. chksum += le32_to_cpu(*dptr++);
  4132. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  4133. "Contents of NVRAM\n");
  4134. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  4135. (uint8_t *)nv, ha->nvram_size);
  4136. /* Bad NVRAM data, set defaults parameters. */
  4137. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4138. || nv->id[3] != ' ' ||
  4139. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4140. /* Reset NVRAM data. */
  4141. ql_log(ql_log_warn, vha, 0x006b,
  4142. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4143. "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
  4144. ql_log(ql_log_warn, vha, 0x006c,
  4145. "Falling back to functioning (yet invalid -- WWPN) "
  4146. "defaults.\n");
  4147. /*
  4148. * Set default initialization control block.
  4149. */
  4150. memset(nv, 0, ha->nvram_size);
  4151. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4152. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4153. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4154. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4155. nv->exchange_count = __constant_cpu_to_le16(0);
  4156. nv->hard_address = __constant_cpu_to_le16(124);
  4157. nv->port_name[0] = 0x21;
  4158. nv->port_name[1] = 0x00 + ha->port_no;
  4159. nv->port_name[2] = 0x00;
  4160. nv->port_name[3] = 0xe0;
  4161. nv->port_name[4] = 0x8b;
  4162. nv->port_name[5] = 0x1c;
  4163. nv->port_name[6] = 0x55;
  4164. nv->port_name[7] = 0x86;
  4165. nv->node_name[0] = 0x20;
  4166. nv->node_name[1] = 0x00;
  4167. nv->node_name[2] = 0x00;
  4168. nv->node_name[3] = 0xe0;
  4169. nv->node_name[4] = 0x8b;
  4170. nv->node_name[5] = 0x1c;
  4171. nv->node_name[6] = 0x55;
  4172. nv->node_name[7] = 0x86;
  4173. qla24xx_nvram_wwn_from_ofw(vha, nv);
  4174. nv->login_retry_count = __constant_cpu_to_le16(8);
  4175. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4176. nv->login_timeout = __constant_cpu_to_le16(0);
  4177. nv->firmware_options_1 =
  4178. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4179. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4180. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4181. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4182. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4183. nv->efi_parameters = __constant_cpu_to_le32(0);
  4184. nv->reset_delay = 5;
  4185. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4186. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4187. nv->link_down_timeout = __constant_cpu_to_le16(30);
  4188. rval = 1;
  4189. }
  4190. if (!qla_ini_mode_enabled(vha)) {
  4191. /* Don't enable full login after initial LIP */
  4192. nv->firmware_options_1 &= __constant_cpu_to_le32(~BIT_13);
  4193. /* Don't enable LIP full login for initiator */
  4194. nv->host_p &= __constant_cpu_to_le32(~BIT_10);
  4195. }
  4196. qlt_24xx_config_nvram_stage1(vha, nv);
  4197. /* Reset Initialization control block */
  4198. memset(icb, 0, ha->init_cb_size);
  4199. /* Copy 1st segment. */
  4200. dptr1 = (uint8_t *)icb;
  4201. dptr2 = (uint8_t *)&nv->version;
  4202. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4203. while (cnt--)
  4204. *dptr1++ = *dptr2++;
  4205. icb->login_retry_count = nv->login_retry_count;
  4206. icb->link_down_on_nos = nv->link_down_on_nos;
  4207. /* Copy 2nd segment. */
  4208. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4209. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4210. cnt = (uint8_t *)&icb->reserved_3 -
  4211. (uint8_t *)&icb->interrupt_delay_timer;
  4212. while (cnt--)
  4213. *dptr1++ = *dptr2++;
  4214. /*
  4215. * Setup driver NVRAM options.
  4216. */
  4217. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4218. "QLA2462");
  4219. qlt_24xx_config_nvram_stage2(vha, icb);
  4220. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4221. /* Use alternate WWN? */
  4222. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4223. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4224. }
  4225. /* Prepare nodename */
  4226. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4227. /*
  4228. * Firmware will apply the following mask if the nodename was
  4229. * not provided.
  4230. */
  4231. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4232. icb->node_name[0] &= 0xF0;
  4233. }
  4234. /* Set host adapter parameters. */
  4235. ha->flags.disable_risc_code_load = 0;
  4236. ha->flags.enable_lip_reset = 0;
  4237. ha->flags.enable_lip_full_login =
  4238. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4239. ha->flags.enable_target_reset =
  4240. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4241. ha->flags.enable_led_scheme = 0;
  4242. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4243. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4244. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4245. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  4246. sizeof(ha->fw_seriallink_options24));
  4247. /* save HBA serial number */
  4248. ha->serial0 = icb->port_name[5];
  4249. ha->serial1 = icb->port_name[6];
  4250. ha->serial2 = icb->port_name[7];
  4251. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4252. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4253. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4254. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4255. /* Set minimum login_timeout to 4 seconds. */
  4256. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4257. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4258. if (le16_to_cpu(nv->login_timeout) < 4)
  4259. nv->login_timeout = __constant_cpu_to_le16(4);
  4260. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4261. icb->login_timeout = nv->login_timeout;
  4262. /* Set minimum RATOV to 100 tenths of a second. */
  4263. ha->r_a_tov = 100;
  4264. ha->loop_reset_delay = nv->reset_delay;
  4265. /* Link Down Timeout = 0:
  4266. *
  4267. * When Port Down timer expires we will start returning
  4268. * I/O's to OS with "DID_NO_CONNECT".
  4269. *
  4270. * Link Down Timeout != 0:
  4271. *
  4272. * The driver waits for the link to come up after link down
  4273. * before returning I/Os to OS with "DID_NO_CONNECT".
  4274. */
  4275. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4276. ha->loop_down_abort_time =
  4277. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4278. } else {
  4279. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4280. ha->loop_down_abort_time =
  4281. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4282. }
  4283. /* Need enough time to try and get the port back. */
  4284. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4285. if (qlport_down_retry)
  4286. ha->port_down_retry_count = qlport_down_retry;
  4287. /* Set login_retry_count */
  4288. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4289. if (ha->port_down_retry_count ==
  4290. le16_to_cpu(nv->port_down_retry_count) &&
  4291. ha->port_down_retry_count > 3)
  4292. ha->login_retry_count = ha->port_down_retry_count;
  4293. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4294. ha->login_retry_count = ha->port_down_retry_count;
  4295. if (ql2xloginretrycount)
  4296. ha->login_retry_count = ql2xloginretrycount;
  4297. /* Enable ZIO. */
  4298. if (!vha->flags.init_done) {
  4299. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4300. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4301. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4302. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4303. }
  4304. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4305. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4306. vha->flags.process_response_queue = 0;
  4307. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4308. ha->zio_mode = QLA_ZIO_MODE_6;
  4309. ql_log(ql_log_info, vha, 0x006f,
  4310. "ZIO mode %d enabled; timer delay (%d us).\n",
  4311. ha->zio_mode, ha->zio_timer * 100);
  4312. icb->firmware_options_2 |= cpu_to_le32(
  4313. (uint32_t)ha->zio_mode);
  4314. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4315. vha->flags.process_response_queue = 1;
  4316. }
  4317. if (rval) {
  4318. ql_log(ql_log_warn, vha, 0x0070,
  4319. "NVRAM configuration failed.\n");
  4320. }
  4321. return (rval);
  4322. }
  4323. static int
  4324. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  4325. uint32_t faddr)
  4326. {
  4327. int rval = QLA_SUCCESS;
  4328. int segments, fragment;
  4329. uint32_t *dcode, dlen;
  4330. uint32_t risc_addr;
  4331. uint32_t risc_size;
  4332. uint32_t i;
  4333. struct qla_hw_data *ha = vha->hw;
  4334. struct req_que *req = ha->req_q_map[0];
  4335. ql_dbg(ql_dbg_init, vha, 0x008b,
  4336. "FW: Loading firmware from flash (%x).\n", faddr);
  4337. rval = QLA_SUCCESS;
  4338. segments = FA_RISC_CODE_SEGMENTS;
  4339. dcode = (uint32_t *)req->ring;
  4340. *srisc_addr = 0;
  4341. /* Validate firmware image by checking version. */
  4342. qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
  4343. for (i = 0; i < 4; i++)
  4344. dcode[i] = be32_to_cpu(dcode[i]);
  4345. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4346. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4347. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4348. dcode[3] == 0)) {
  4349. ql_log(ql_log_fatal, vha, 0x008c,
  4350. "Unable to verify the integrity of flash firmware "
  4351. "image.\n");
  4352. ql_log(ql_log_fatal, vha, 0x008d,
  4353. "Firmware data: %08x %08x %08x %08x.\n",
  4354. dcode[0], dcode[1], dcode[2], dcode[3]);
  4355. return QLA_FUNCTION_FAILED;
  4356. }
  4357. while (segments && rval == QLA_SUCCESS) {
  4358. /* Read segment's load information. */
  4359. qla24xx_read_flash_data(vha, dcode, faddr, 4);
  4360. risc_addr = be32_to_cpu(dcode[2]);
  4361. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4362. risc_size = be32_to_cpu(dcode[3]);
  4363. fragment = 0;
  4364. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4365. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4366. if (dlen > risc_size)
  4367. dlen = risc_size;
  4368. ql_dbg(ql_dbg_init, vha, 0x008e,
  4369. "Loading risc segment@ risc addr %x "
  4370. "number of dwords 0x%x offset 0x%x.\n",
  4371. risc_addr, dlen, faddr);
  4372. qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  4373. for (i = 0; i < dlen; i++)
  4374. dcode[i] = swab32(dcode[i]);
  4375. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4376. dlen);
  4377. if (rval) {
  4378. ql_log(ql_log_fatal, vha, 0x008f,
  4379. "Failed to load segment %d of firmware.\n",
  4380. fragment);
  4381. break;
  4382. }
  4383. faddr += dlen;
  4384. risc_addr += dlen;
  4385. risc_size -= dlen;
  4386. fragment++;
  4387. }
  4388. /* Next segment. */
  4389. segments--;
  4390. }
  4391. return rval;
  4392. }
  4393. #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
  4394. int
  4395. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4396. {
  4397. int rval;
  4398. int i, fragment;
  4399. uint16_t *wcode, *fwcode;
  4400. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  4401. struct fw_blob *blob;
  4402. struct qla_hw_data *ha = vha->hw;
  4403. struct req_que *req = ha->req_q_map[0];
  4404. /* Load firmware blob. */
  4405. blob = qla2x00_request_firmware(vha);
  4406. if (!blob) {
  4407. ql_log(ql_log_info, vha, 0x0083,
  4408. "Fimware image unavailable.\n");
  4409. ql_log(ql_log_info, vha, 0x0084,
  4410. "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
  4411. return QLA_FUNCTION_FAILED;
  4412. }
  4413. rval = QLA_SUCCESS;
  4414. wcode = (uint16_t *)req->ring;
  4415. *srisc_addr = 0;
  4416. fwcode = (uint16_t *)blob->fw->data;
  4417. fwclen = 0;
  4418. /* Validate firmware image by checking version. */
  4419. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  4420. ql_log(ql_log_fatal, vha, 0x0085,
  4421. "Unable to verify integrity of firmware image (%Zd).\n",
  4422. blob->fw->size);
  4423. goto fail_fw_integrity;
  4424. }
  4425. for (i = 0; i < 4; i++)
  4426. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  4427. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  4428. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  4429. wcode[2] == 0 && wcode[3] == 0)) {
  4430. ql_log(ql_log_fatal, vha, 0x0086,
  4431. "Unable to verify integrity of firmware image.\n");
  4432. ql_log(ql_log_fatal, vha, 0x0087,
  4433. "Firmware data: %04x %04x %04x %04x.\n",
  4434. wcode[0], wcode[1], wcode[2], wcode[3]);
  4435. goto fail_fw_integrity;
  4436. }
  4437. seg = blob->segs;
  4438. while (*seg && rval == QLA_SUCCESS) {
  4439. risc_addr = *seg;
  4440. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  4441. risc_size = be16_to_cpu(fwcode[3]);
  4442. /* Validate firmware image size. */
  4443. fwclen += risc_size * sizeof(uint16_t);
  4444. if (blob->fw->size < fwclen) {
  4445. ql_log(ql_log_fatal, vha, 0x0088,
  4446. "Unable to verify integrity of firmware image "
  4447. "(%Zd).\n", blob->fw->size);
  4448. goto fail_fw_integrity;
  4449. }
  4450. fragment = 0;
  4451. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4452. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  4453. if (wlen > risc_size)
  4454. wlen = risc_size;
  4455. ql_dbg(ql_dbg_init, vha, 0x0089,
  4456. "Loading risc segment@ risc addr %x number of "
  4457. "words 0x%x.\n", risc_addr, wlen);
  4458. for (i = 0; i < wlen; i++)
  4459. wcode[i] = swab16(fwcode[i]);
  4460. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4461. wlen);
  4462. if (rval) {
  4463. ql_log(ql_log_fatal, vha, 0x008a,
  4464. "Failed to load segment %d of firmware.\n",
  4465. fragment);
  4466. break;
  4467. }
  4468. fwcode += wlen;
  4469. risc_addr += wlen;
  4470. risc_size -= wlen;
  4471. fragment++;
  4472. }
  4473. /* Next segment. */
  4474. seg++;
  4475. }
  4476. return rval;
  4477. fail_fw_integrity:
  4478. return QLA_FUNCTION_FAILED;
  4479. }
  4480. static int
  4481. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4482. {
  4483. int rval;
  4484. int segments, fragment;
  4485. uint32_t *dcode, dlen;
  4486. uint32_t risc_addr;
  4487. uint32_t risc_size;
  4488. uint32_t i;
  4489. struct fw_blob *blob;
  4490. uint32_t *fwcode, fwclen;
  4491. struct qla_hw_data *ha = vha->hw;
  4492. struct req_que *req = ha->req_q_map[0];
  4493. /* Load firmware blob. */
  4494. blob = qla2x00_request_firmware(vha);
  4495. if (!blob) {
  4496. ql_log(ql_log_warn, vha, 0x0090,
  4497. "Fimware image unavailable.\n");
  4498. ql_log(ql_log_warn, vha, 0x0091,
  4499. "Firmware images can be retrieved from: "
  4500. QLA_FW_URL ".\n");
  4501. return QLA_FUNCTION_FAILED;
  4502. }
  4503. ql_dbg(ql_dbg_init, vha, 0x0092,
  4504. "FW: Loading via request-firmware.\n");
  4505. rval = QLA_SUCCESS;
  4506. segments = FA_RISC_CODE_SEGMENTS;
  4507. dcode = (uint32_t *)req->ring;
  4508. *srisc_addr = 0;
  4509. fwcode = (uint32_t *)blob->fw->data;
  4510. fwclen = 0;
  4511. /* Validate firmware image by checking version. */
  4512. if (blob->fw->size < 8 * sizeof(uint32_t)) {
  4513. ql_log(ql_log_fatal, vha, 0x0093,
  4514. "Unable to verify integrity of firmware image (%Zd).\n",
  4515. blob->fw->size);
  4516. goto fail_fw_integrity;
  4517. }
  4518. for (i = 0; i < 4; i++)
  4519. dcode[i] = be32_to_cpu(fwcode[i + 4]);
  4520. if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
  4521. dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
  4522. (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
  4523. dcode[3] == 0)) {
  4524. ql_log(ql_log_fatal, vha, 0x0094,
  4525. "Unable to verify integrity of firmware image (%Zd).\n",
  4526. blob->fw->size);
  4527. ql_log(ql_log_fatal, vha, 0x0095,
  4528. "Firmware data: %08x %08x %08x %08x.\n",
  4529. dcode[0], dcode[1], dcode[2], dcode[3]);
  4530. goto fail_fw_integrity;
  4531. }
  4532. while (segments && rval == QLA_SUCCESS) {
  4533. risc_addr = be32_to_cpu(fwcode[2]);
  4534. *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
  4535. risc_size = be32_to_cpu(fwcode[3]);
  4536. /* Validate firmware image size. */
  4537. fwclen += risc_size * sizeof(uint32_t);
  4538. if (blob->fw->size < fwclen) {
  4539. ql_log(ql_log_fatal, vha, 0x0096,
  4540. "Unable to verify integrity of firmware image "
  4541. "(%Zd).\n", blob->fw->size);
  4542. goto fail_fw_integrity;
  4543. }
  4544. fragment = 0;
  4545. while (risc_size > 0 && rval == QLA_SUCCESS) {
  4546. dlen = (uint32_t)(ha->fw_transfer_size >> 2);
  4547. if (dlen > risc_size)
  4548. dlen = risc_size;
  4549. ql_dbg(ql_dbg_init, vha, 0x0097,
  4550. "Loading risc segment@ risc addr %x "
  4551. "number of dwords 0x%x.\n", risc_addr, dlen);
  4552. for (i = 0; i < dlen; i++)
  4553. dcode[i] = swab32(fwcode[i]);
  4554. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  4555. dlen);
  4556. if (rval) {
  4557. ql_log(ql_log_fatal, vha, 0x0098,
  4558. "Failed to load segment %d of firmware.\n",
  4559. fragment);
  4560. break;
  4561. }
  4562. fwcode += dlen;
  4563. risc_addr += dlen;
  4564. risc_size -= dlen;
  4565. fragment++;
  4566. }
  4567. /* Next segment. */
  4568. segments--;
  4569. }
  4570. return rval;
  4571. fail_fw_integrity:
  4572. return QLA_FUNCTION_FAILED;
  4573. }
  4574. int
  4575. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4576. {
  4577. int rval;
  4578. if (ql2xfwloadbin == 1)
  4579. return qla81xx_load_risc(vha, srisc_addr);
  4580. /*
  4581. * FW Load priority:
  4582. * 1) Firmware via request-firmware interface (.bin file).
  4583. * 2) Firmware residing in flash.
  4584. */
  4585. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4586. if (rval == QLA_SUCCESS)
  4587. return rval;
  4588. return qla24xx_load_risc_flash(vha, srisc_addr,
  4589. vha->hw->flt_region_fw);
  4590. }
  4591. int
  4592. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  4593. {
  4594. int rval;
  4595. struct qla_hw_data *ha = vha->hw;
  4596. if (ql2xfwloadbin == 2)
  4597. goto try_blob_fw;
  4598. /*
  4599. * FW Load priority:
  4600. * 1) Firmware residing in flash.
  4601. * 2) Firmware via request-firmware interface (.bin file).
  4602. * 3) Golden-Firmware residing in flash -- limited operation.
  4603. */
  4604. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  4605. if (rval == QLA_SUCCESS)
  4606. return rval;
  4607. try_blob_fw:
  4608. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  4609. if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
  4610. return rval;
  4611. ql_log(ql_log_info, vha, 0x0099,
  4612. "Attempting to fallback to golden firmware.\n");
  4613. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  4614. if (rval != QLA_SUCCESS)
  4615. return rval;
  4616. ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
  4617. ha->flags.running_gold_fw = 1;
  4618. return rval;
  4619. }
  4620. void
  4621. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  4622. {
  4623. int ret, retries;
  4624. struct qla_hw_data *ha = vha->hw;
  4625. if (ha->flags.pci_channel_io_perm_failure)
  4626. return;
  4627. if (!IS_FWI2_CAPABLE(ha))
  4628. return;
  4629. if (!ha->fw_major_version)
  4630. return;
  4631. ret = qla2x00_stop_firmware(vha);
  4632. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  4633. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  4634. ha->isp_ops->reset_chip(vha);
  4635. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  4636. continue;
  4637. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  4638. continue;
  4639. ql_log(ql_log_info, vha, 0x8015,
  4640. "Attempting retry of stop-firmware command.\n");
  4641. ret = qla2x00_stop_firmware(vha);
  4642. }
  4643. }
  4644. int
  4645. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  4646. {
  4647. int rval = QLA_SUCCESS;
  4648. int rval2;
  4649. uint16_t mb[MAILBOX_REGISTER_COUNT];
  4650. struct qla_hw_data *ha = vha->hw;
  4651. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  4652. struct req_que *req;
  4653. struct rsp_que *rsp;
  4654. if (!vha->vp_idx)
  4655. return -EINVAL;
  4656. rval = qla2x00_fw_ready(base_vha);
  4657. if (ha->flags.cpu_affinity_enabled)
  4658. req = ha->req_q_map[0];
  4659. else
  4660. req = vha->req;
  4661. rsp = req->rsp;
  4662. if (rval == QLA_SUCCESS) {
  4663. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4664. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4665. }
  4666. vha->flags.management_server_logged_in = 0;
  4667. /* Login to SNS first */
  4668. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  4669. BIT_1);
  4670. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  4671. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  4672. ql_dbg(ql_dbg_init, vha, 0x0120,
  4673. "Failed SNS login: loop_id=%x, rval2=%d\n",
  4674. NPH_SNS, rval2);
  4675. else
  4676. ql_dbg(ql_dbg_init, vha, 0x0103,
  4677. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  4678. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  4679. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  4680. return (QLA_FUNCTION_FAILED);
  4681. }
  4682. atomic_set(&vha->loop_down_timer, 0);
  4683. atomic_set(&vha->loop_state, LOOP_UP);
  4684. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4685. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4686. rval = qla2x00_loop_resync(base_vha);
  4687. return rval;
  4688. }
  4689. /* 84XX Support **************************************************************/
  4690. static LIST_HEAD(qla_cs84xx_list);
  4691. static DEFINE_MUTEX(qla_cs84xx_mutex);
  4692. static struct qla_chip_state_84xx *
  4693. qla84xx_get_chip(struct scsi_qla_host *vha)
  4694. {
  4695. struct qla_chip_state_84xx *cs84xx;
  4696. struct qla_hw_data *ha = vha->hw;
  4697. mutex_lock(&qla_cs84xx_mutex);
  4698. /* Find any shared 84xx chip. */
  4699. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  4700. if (cs84xx->bus == ha->pdev->bus) {
  4701. kref_get(&cs84xx->kref);
  4702. goto done;
  4703. }
  4704. }
  4705. cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
  4706. if (!cs84xx)
  4707. goto done;
  4708. kref_init(&cs84xx->kref);
  4709. spin_lock_init(&cs84xx->access_lock);
  4710. mutex_init(&cs84xx->fw_update_mutex);
  4711. cs84xx->bus = ha->pdev->bus;
  4712. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  4713. done:
  4714. mutex_unlock(&qla_cs84xx_mutex);
  4715. return cs84xx;
  4716. }
  4717. static void
  4718. __qla84xx_chip_release(struct kref *kref)
  4719. {
  4720. struct qla_chip_state_84xx *cs84xx =
  4721. container_of(kref, struct qla_chip_state_84xx, kref);
  4722. mutex_lock(&qla_cs84xx_mutex);
  4723. list_del(&cs84xx->list);
  4724. mutex_unlock(&qla_cs84xx_mutex);
  4725. kfree(cs84xx);
  4726. }
  4727. void
  4728. qla84xx_put_chip(struct scsi_qla_host *vha)
  4729. {
  4730. struct qla_hw_data *ha = vha->hw;
  4731. if (ha->cs84xx)
  4732. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  4733. }
  4734. static int
  4735. qla84xx_init_chip(scsi_qla_host_t *vha)
  4736. {
  4737. int rval;
  4738. uint16_t status[2];
  4739. struct qla_hw_data *ha = vha->hw;
  4740. mutex_lock(&ha->cs84xx->fw_update_mutex);
  4741. rval = qla84xx_verify_chip(vha, status);
  4742. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  4743. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
  4744. QLA_SUCCESS;
  4745. }
  4746. /* 81XX Support **************************************************************/
  4747. int
  4748. qla81xx_nvram_config(scsi_qla_host_t *vha)
  4749. {
  4750. int rval;
  4751. struct init_cb_81xx *icb;
  4752. struct nvram_81xx *nv;
  4753. uint32_t *dptr;
  4754. uint8_t *dptr1, *dptr2;
  4755. uint32_t chksum;
  4756. uint16_t cnt;
  4757. struct qla_hw_data *ha = vha->hw;
  4758. rval = QLA_SUCCESS;
  4759. icb = (struct init_cb_81xx *)ha->init_cb;
  4760. nv = ha->nvram;
  4761. /* Determine NVRAM starting address. */
  4762. ha->nvram_size = sizeof(struct nvram_81xx);
  4763. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  4764. /* Get VPD data into cache */
  4765. ha->vpd = ha->nvram + VPD_OFFSET;
  4766. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  4767. ha->vpd_size);
  4768. /* Get NVRAM data into cache and calculate checksum. */
  4769. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  4770. ha->nvram_size);
  4771. dptr = (uint32_t *)nv;
  4772. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
  4773. chksum += le32_to_cpu(*dptr++);
  4774. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  4775. "Contents of NVRAM:\n");
  4776. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  4777. (uint8_t *)nv, ha->nvram_size);
  4778. /* Bad NVRAM data, set defaults parameters. */
  4779. if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
  4780. || nv->id[3] != ' ' ||
  4781. nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
  4782. /* Reset NVRAM data. */
  4783. ql_log(ql_log_info, vha, 0x0073,
  4784. "Inconsistent NVRAM detected: checksum=0x%x id=%c "
  4785. "version=0x%x.\n", chksum, nv->id[0],
  4786. le16_to_cpu(nv->nvram_version));
  4787. ql_log(ql_log_info, vha, 0x0074,
  4788. "Falling back to functioning (yet invalid -- WWPN) "
  4789. "defaults.\n");
  4790. /*
  4791. * Set default initialization control block.
  4792. */
  4793. memset(nv, 0, ha->nvram_size);
  4794. nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
  4795. nv->version = __constant_cpu_to_le16(ICB_VERSION);
  4796. nv->frame_payload_size = __constant_cpu_to_le16(2048);
  4797. nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4798. nv->exchange_count = __constant_cpu_to_le16(0);
  4799. nv->port_name[0] = 0x21;
  4800. nv->port_name[1] = 0x00 + ha->port_no;
  4801. nv->port_name[2] = 0x00;
  4802. nv->port_name[3] = 0xe0;
  4803. nv->port_name[4] = 0x8b;
  4804. nv->port_name[5] = 0x1c;
  4805. nv->port_name[6] = 0x55;
  4806. nv->port_name[7] = 0x86;
  4807. nv->node_name[0] = 0x20;
  4808. nv->node_name[1] = 0x00;
  4809. nv->node_name[2] = 0x00;
  4810. nv->node_name[3] = 0xe0;
  4811. nv->node_name[4] = 0x8b;
  4812. nv->node_name[5] = 0x1c;
  4813. nv->node_name[6] = 0x55;
  4814. nv->node_name[7] = 0x86;
  4815. nv->login_retry_count = __constant_cpu_to_le16(8);
  4816. nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
  4817. nv->login_timeout = __constant_cpu_to_le16(0);
  4818. nv->firmware_options_1 =
  4819. __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  4820. nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
  4821. nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
  4822. nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
  4823. nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
  4824. nv->efi_parameters = __constant_cpu_to_le32(0);
  4825. nv->reset_delay = 5;
  4826. nv->max_luns_per_target = __constant_cpu_to_le16(128);
  4827. nv->port_down_retry_count = __constant_cpu_to_le16(30);
  4828. nv->link_down_timeout = __constant_cpu_to_le16(180);
  4829. nv->enode_mac[0] = 0x00;
  4830. nv->enode_mac[1] = 0xC0;
  4831. nv->enode_mac[2] = 0xDD;
  4832. nv->enode_mac[3] = 0x04;
  4833. nv->enode_mac[4] = 0x05;
  4834. nv->enode_mac[5] = 0x06 + ha->port_no;
  4835. rval = 1;
  4836. }
  4837. if (IS_T10_PI_CAPABLE(ha))
  4838. nv->frame_payload_size &= ~7;
  4839. qlt_81xx_config_nvram_stage1(vha, nv);
  4840. /* Reset Initialization control block */
  4841. memset(icb, 0, ha->init_cb_size);
  4842. /* Copy 1st segment. */
  4843. dptr1 = (uint8_t *)icb;
  4844. dptr2 = (uint8_t *)&nv->version;
  4845. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  4846. while (cnt--)
  4847. *dptr1++ = *dptr2++;
  4848. icb->login_retry_count = nv->login_retry_count;
  4849. /* Copy 2nd segment. */
  4850. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  4851. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  4852. cnt = (uint8_t *)&icb->reserved_5 -
  4853. (uint8_t *)&icb->interrupt_delay_timer;
  4854. while (cnt--)
  4855. *dptr1++ = *dptr2++;
  4856. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  4857. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  4858. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  4859. icb->enode_mac[0] = 0x00;
  4860. icb->enode_mac[1] = 0xC0;
  4861. icb->enode_mac[2] = 0xDD;
  4862. icb->enode_mac[3] = 0x04;
  4863. icb->enode_mac[4] = 0x05;
  4864. icb->enode_mac[5] = 0x06 + ha->port_no;
  4865. }
  4866. /* Use extended-initialization control block. */
  4867. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  4868. /*
  4869. * Setup driver NVRAM options.
  4870. */
  4871. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  4872. "QLE8XXX");
  4873. qlt_81xx_config_nvram_stage2(vha, icb);
  4874. /* Use alternate WWN? */
  4875. if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
  4876. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4877. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4878. }
  4879. /* Prepare nodename */
  4880. if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
  4881. /*
  4882. * Firmware will apply the following mask if the nodename was
  4883. * not provided.
  4884. */
  4885. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4886. icb->node_name[0] &= 0xF0;
  4887. }
  4888. /* Set host adapter parameters. */
  4889. ha->flags.disable_risc_code_load = 0;
  4890. ha->flags.enable_lip_reset = 0;
  4891. ha->flags.enable_lip_full_login =
  4892. le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
  4893. ha->flags.enable_target_reset =
  4894. le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
  4895. ha->flags.enable_led_scheme = 0;
  4896. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
  4897. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  4898. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4899. /* save HBA serial number */
  4900. ha->serial0 = icb->port_name[5];
  4901. ha->serial1 = icb->port_name[6];
  4902. ha->serial2 = icb->port_name[7];
  4903. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4904. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4905. icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
  4906. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  4907. /* Set minimum login_timeout to 4 seconds. */
  4908. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  4909. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  4910. if (le16_to_cpu(nv->login_timeout) < 4)
  4911. nv->login_timeout = __constant_cpu_to_le16(4);
  4912. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  4913. icb->login_timeout = nv->login_timeout;
  4914. /* Set minimum RATOV to 100 tenths of a second. */
  4915. ha->r_a_tov = 100;
  4916. ha->loop_reset_delay = nv->reset_delay;
  4917. /* Link Down Timeout = 0:
  4918. *
  4919. * When Port Down timer expires we will start returning
  4920. * I/O's to OS with "DID_NO_CONNECT".
  4921. *
  4922. * Link Down Timeout != 0:
  4923. *
  4924. * The driver waits for the link to come up after link down
  4925. * before returning I/Os to OS with "DID_NO_CONNECT".
  4926. */
  4927. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  4928. ha->loop_down_abort_time =
  4929. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4930. } else {
  4931. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  4932. ha->loop_down_abort_time =
  4933. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4934. }
  4935. /* Need enough time to try and get the port back. */
  4936. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  4937. if (qlport_down_retry)
  4938. ha->port_down_retry_count = qlport_down_retry;
  4939. /* Set login_retry_count */
  4940. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  4941. if (ha->port_down_retry_count ==
  4942. le16_to_cpu(nv->port_down_retry_count) &&
  4943. ha->port_down_retry_count > 3)
  4944. ha->login_retry_count = ha->port_down_retry_count;
  4945. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4946. ha->login_retry_count = ha->port_down_retry_count;
  4947. if (ql2xloginretrycount)
  4948. ha->login_retry_count = ql2xloginretrycount;
  4949. /* if not running MSI-X we need handshaking on interrupts */
  4950. if (!vha->hw->flags.msix_enabled && IS_QLA83XX(ha))
  4951. icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
  4952. /* Enable ZIO. */
  4953. if (!vha->flags.init_done) {
  4954. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  4955. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4956. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  4957. le16_to_cpu(icb->interrupt_delay_timer): 2;
  4958. }
  4959. icb->firmware_options_2 &= __constant_cpu_to_le32(
  4960. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  4961. vha->flags.process_response_queue = 0;
  4962. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4963. ha->zio_mode = QLA_ZIO_MODE_6;
  4964. ql_log(ql_log_info, vha, 0x0075,
  4965. "ZIO mode %d enabled; timer delay (%d us).\n",
  4966. ha->zio_mode,
  4967. ha->zio_timer * 100);
  4968. icb->firmware_options_2 |= cpu_to_le32(
  4969. (uint32_t)ha->zio_mode);
  4970. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  4971. vha->flags.process_response_queue = 1;
  4972. }
  4973. if (rval) {
  4974. ql_log(ql_log_warn, vha, 0x0076,
  4975. "NVRAM configuration failed.\n");
  4976. }
  4977. return (rval);
  4978. }
  4979. int
  4980. qla82xx_restart_isp(scsi_qla_host_t *vha)
  4981. {
  4982. int status, rval;
  4983. uint32_t wait_time;
  4984. struct qla_hw_data *ha = vha->hw;
  4985. struct req_que *req = ha->req_q_map[0];
  4986. struct rsp_que *rsp = ha->rsp_q_map[0];
  4987. struct scsi_qla_host *vp;
  4988. unsigned long flags;
  4989. status = qla2x00_init_rings(vha);
  4990. if (!status) {
  4991. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  4992. ha->flags.chip_reset_done = 1;
  4993. status = qla2x00_fw_ready(vha);
  4994. if (!status) {
  4995. ql_log(ql_log_info, vha, 0x803c,
  4996. "Start configure loop, status =%d.\n", status);
  4997. /* Issue a marker after FW becomes ready. */
  4998. qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
  4999. vha->flags.online = 1;
  5000. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  5001. wait_time = 256;
  5002. do {
  5003. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5004. qla2x00_configure_loop(vha);
  5005. wait_time--;
  5006. } while (!atomic_read(&vha->loop_down_timer) &&
  5007. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
  5008. wait_time &&
  5009. (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
  5010. }
  5011. /* if no cable then assume it's good */
  5012. if ((vha->device_flags & DFLG_NO_CABLE))
  5013. status = 0;
  5014. ql_log(ql_log_info, vha, 0x8000,
  5015. "Configure loop done, status = 0x%x.\n", status);
  5016. }
  5017. if (!status) {
  5018. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  5019. if (!atomic_read(&vha->loop_down_timer)) {
  5020. /*
  5021. * Issue marker command only when we are going
  5022. * to start the I/O .
  5023. */
  5024. vha->marker_needed = 1;
  5025. }
  5026. vha->flags.online = 1;
  5027. ha->isp_ops->enable_intrs(ha);
  5028. ha->isp_abort_cnt = 0;
  5029. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5030. /* Update the firmware version */
  5031. status = qla82xx_check_md_needed(vha);
  5032. if (ha->fce) {
  5033. ha->flags.fce_enabled = 1;
  5034. memset(ha->fce, 0,
  5035. fce_calc_size(ha->fce_bufs));
  5036. rval = qla2x00_enable_fce_trace(vha,
  5037. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  5038. &ha->fce_bufs);
  5039. if (rval) {
  5040. ql_log(ql_log_warn, vha, 0x8001,
  5041. "Unable to reinitialize FCE (%d).\n",
  5042. rval);
  5043. ha->flags.fce_enabled = 0;
  5044. }
  5045. }
  5046. if (ha->eft) {
  5047. memset(ha->eft, 0, EFT_SIZE);
  5048. rval = qla2x00_enable_eft_trace(vha,
  5049. ha->eft_dma, EFT_NUM_BUFFERS);
  5050. if (rval) {
  5051. ql_log(ql_log_warn, vha, 0x8010,
  5052. "Unable to reinitialize EFT (%d).\n",
  5053. rval);
  5054. }
  5055. }
  5056. }
  5057. if (!status) {
  5058. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  5059. "qla82xx_restart_isp succeeded.\n");
  5060. spin_lock_irqsave(&ha->vport_slock, flags);
  5061. list_for_each_entry(vp, &ha->vp_list, list) {
  5062. if (vp->vp_idx) {
  5063. atomic_inc(&vp->vref_count);
  5064. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5065. qla2x00_vp_abort_isp(vp);
  5066. spin_lock_irqsave(&ha->vport_slock, flags);
  5067. atomic_dec(&vp->vref_count);
  5068. }
  5069. }
  5070. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5071. } else {
  5072. ql_log(ql_log_warn, vha, 0x8016,
  5073. "qla82xx_restart_isp **** FAILED ****.\n");
  5074. }
  5075. return status;
  5076. }
  5077. void
  5078. qla81xx_update_fw_options(scsi_qla_host_t *vha)
  5079. {
  5080. struct qla_hw_data *ha = vha->hw;
  5081. if (!ql2xetsenable)
  5082. return;
  5083. /* Enable ETS Burst. */
  5084. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  5085. ha->fw_options[2] |= BIT_9;
  5086. qla2x00_set_fw_options(vha, ha->fw_options);
  5087. }
  5088. /*
  5089. * qla24xx_get_fcp_prio
  5090. * Gets the fcp cmd priority value for the logged in port.
  5091. * Looks for a match of the port descriptors within
  5092. * each of the fcp prio config entries. If a match is found,
  5093. * the tag (priority) value is returned.
  5094. *
  5095. * Input:
  5096. * vha = scsi host structure pointer.
  5097. * fcport = port structure pointer.
  5098. *
  5099. * Return:
  5100. * non-zero (if found)
  5101. * -1 (if not found)
  5102. *
  5103. * Context:
  5104. * Kernel context
  5105. */
  5106. static int
  5107. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5108. {
  5109. int i, entries;
  5110. uint8_t pid_match, wwn_match;
  5111. int priority;
  5112. uint32_t pid1, pid2;
  5113. uint64_t wwn1, wwn2;
  5114. struct qla_fcp_prio_entry *pri_entry;
  5115. struct qla_hw_data *ha = vha->hw;
  5116. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  5117. return -1;
  5118. priority = -1;
  5119. entries = ha->fcp_prio_cfg->num_entries;
  5120. pri_entry = &ha->fcp_prio_cfg->entry[0];
  5121. for (i = 0; i < entries; i++) {
  5122. pid_match = wwn_match = 0;
  5123. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  5124. pri_entry++;
  5125. continue;
  5126. }
  5127. /* check source pid for a match */
  5128. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  5129. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  5130. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  5131. if (pid1 == INVALID_PORT_ID)
  5132. pid_match++;
  5133. else if (pid1 == pid2)
  5134. pid_match++;
  5135. }
  5136. /* check destination pid for a match */
  5137. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  5138. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  5139. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  5140. if (pid1 == INVALID_PORT_ID)
  5141. pid_match++;
  5142. else if (pid1 == pid2)
  5143. pid_match++;
  5144. }
  5145. /* check source WWN for a match */
  5146. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  5147. wwn1 = wwn_to_u64(vha->port_name);
  5148. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  5149. if (wwn2 == (uint64_t)-1)
  5150. wwn_match++;
  5151. else if (wwn1 == wwn2)
  5152. wwn_match++;
  5153. }
  5154. /* check destination WWN for a match */
  5155. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  5156. wwn1 = wwn_to_u64(fcport->port_name);
  5157. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  5158. if (wwn2 == (uint64_t)-1)
  5159. wwn_match++;
  5160. else if (wwn1 == wwn2)
  5161. wwn_match++;
  5162. }
  5163. if (pid_match == 2 || wwn_match == 2) {
  5164. /* Found a matching entry */
  5165. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  5166. priority = pri_entry->tag;
  5167. break;
  5168. }
  5169. pri_entry++;
  5170. }
  5171. return priority;
  5172. }
  5173. /*
  5174. * qla24xx_update_fcport_fcp_prio
  5175. * Activates fcp priority for the logged in fc port
  5176. *
  5177. * Input:
  5178. * vha = scsi host structure pointer.
  5179. * fcp = port structure pointer.
  5180. *
  5181. * Return:
  5182. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5183. *
  5184. * Context:
  5185. * Kernel context.
  5186. */
  5187. int
  5188. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  5189. {
  5190. int ret;
  5191. int priority;
  5192. uint16_t mb[5];
  5193. if (fcport->port_type != FCT_TARGET ||
  5194. fcport->loop_id == FC_NO_LOOP_ID)
  5195. return QLA_FUNCTION_FAILED;
  5196. priority = qla24xx_get_fcp_prio(vha, fcport);
  5197. if (priority < 0)
  5198. return QLA_FUNCTION_FAILED;
  5199. if (IS_QLA82XX(vha->hw)) {
  5200. fcport->fcp_prio = priority & 0xf;
  5201. return QLA_SUCCESS;
  5202. }
  5203. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  5204. if (ret == QLA_SUCCESS) {
  5205. if (fcport->fcp_prio != priority)
  5206. ql_dbg(ql_dbg_user, vha, 0x709e,
  5207. "Updated FCP_CMND priority - value=%d loop_id=%d "
  5208. "port_id=%02x%02x%02x.\n", priority,
  5209. fcport->loop_id, fcport->d_id.b.domain,
  5210. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5211. fcport->fcp_prio = priority & 0xf;
  5212. } else
  5213. ql_dbg(ql_dbg_user, vha, 0x704f,
  5214. "Unable to update FCP_CMND priority - ret=0x%x for "
  5215. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  5216. fcport->d_id.b.domain, fcport->d_id.b.area,
  5217. fcport->d_id.b.al_pa);
  5218. return ret;
  5219. }
  5220. /*
  5221. * qla24xx_update_all_fcp_prio
  5222. * Activates fcp priority for all the logged in ports
  5223. *
  5224. * Input:
  5225. * ha = adapter block pointer.
  5226. *
  5227. * Return:
  5228. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  5229. *
  5230. * Context:
  5231. * Kernel context.
  5232. */
  5233. int
  5234. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  5235. {
  5236. int ret;
  5237. fc_port_t *fcport;
  5238. ret = QLA_FUNCTION_FAILED;
  5239. /* We need to set priority for all logged in ports */
  5240. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5241. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  5242. return ret;
  5243. }