qla_init.c 156 KB

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