qla_init.c 168 KB

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