qla_init.c 159 KB

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