qla_init.c 158 KB

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