qla_init.c 155 KB

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