qla_init.c 155 KB

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