qla_init.c 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * QLogic Fibre Channel HBA Driver
  4. * Copyright (c) 2003-2014 QLogic Corporation
  5. */
  6. #include "qla_def.h"
  7. #include "qla_gbl.h"
  8. #include <linux/delay.h>
  9. #include <linux/slab.h>
  10. #include <linux/vmalloc.h>
  11. #include "qla_devtbl.h"
  12. #ifdef CONFIG_SPARC
  13. #include <asm/prom.h>
  14. #endif
  15. #include "qla_target.h"
  16. /*
  17. * QLogic ISP2x00 Hardware Support Function Prototypes.
  18. */
  19. static int qla2x00_isp_firmware(scsi_qla_host_t *);
  20. static int qla2x00_setup_chip(scsi_qla_host_t *);
  21. static int qla2x00_fw_ready(scsi_qla_host_t *);
  22. static int qla2x00_configure_hba(scsi_qla_host_t *);
  23. static int qla2x00_configure_loop(scsi_qla_host_t *);
  24. static int qla2x00_configure_local_loop(scsi_qla_host_t *);
  25. static int qla2x00_configure_fabric(scsi_qla_host_t *);
  26. static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
  27. static int qla2x00_restart_isp(scsi_qla_host_t *);
  28. static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
  29. static int qla84xx_init_chip(scsi_qla_host_t *);
  30. static int qla25xx_init_queues(struct qla_hw_data *);
  31. static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
  32. struct event_arg *ea);
  33. static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
  34. struct event_arg *);
  35. static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
  36. /* SRB Extensions ---------------------------------------------------------- */
  37. void
  38. qla2x00_sp_timeout(struct timer_list *t)
  39. {
  40. srb_t *sp = timer_container_of(sp, t, u.iocb_cmd.timer);
  41. struct srb_iocb *iocb;
  42. scsi_qla_host_t *vha = sp->vha;
  43. WARN_ON(irqs_disabled());
  44. iocb = &sp->u.iocb_cmd;
  45. iocb->timeout(sp);
  46. /* ref: TMR */
  47. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  48. if (vha && qla2x00_isp_reg_stat(vha->hw)) {
  49. ql_log(ql_log_info, vha, 0x9008,
  50. "PCI/Register disconnect.\n");
  51. qla_pci_set_eeh_busy(vha);
  52. }
  53. }
  54. void qla2x00_sp_free(srb_t *sp)
  55. {
  56. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  57. timer_delete(&iocb->timer);
  58. qla2x00_rel_sp(sp);
  59. }
  60. void qla2xxx_rel_done_warning(srb_t *sp, int res)
  61. {
  62. WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp);
  63. }
  64. void qla2xxx_rel_free_warning(srb_t *sp)
  65. {
  66. WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp);
  67. }
  68. /* Asynchronous Login/Logout Routines -------------------------------------- */
  69. unsigned long
  70. qla2x00_get_async_timeout(struct scsi_qla_host *vha)
  71. {
  72. unsigned long tmo;
  73. struct qla_hw_data *ha = vha->hw;
  74. /* Firmware should use switch negotiated r_a_tov for timeout. */
  75. tmo = ha->r_a_tov / 10 * 2;
  76. if (IS_QLAFX00(ha)) {
  77. tmo = FX00_DEF_RATOV * 2;
  78. } else if (!IS_FWI2_CAPABLE(ha)) {
  79. /*
  80. * Except for earlier ISPs where the timeout is seeded from the
  81. * initialization control block.
  82. */
  83. tmo = ha->login_timeout;
  84. }
  85. return tmo;
  86. }
  87. static void qla24xx_abort_iocb_timeout(void *data)
  88. {
  89. srb_t *sp = data;
  90. struct srb_iocb *abt = &sp->u.iocb_cmd;
  91. struct qla_qpair *qpair = sp->qpair;
  92. u32 handle;
  93. unsigned long flags;
  94. int sp_found = 0, cmdsp_found = 0;
  95. if (sp->cmd_sp)
  96. ql_dbg(ql_dbg_async, sp->vha, 0x507c,
  97. "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
  98. sp->cmd_sp->handle, sp->cmd_sp->type,
  99. sp->handle, sp->type);
  100. else
  101. ql_dbg(ql_dbg_async, sp->vha, 0x507c,
  102. "Abort timeout 2 - hdl=%x, type=%x\n",
  103. sp->handle, sp->type);
  104. spin_lock_irqsave(qpair->qp_lock_ptr, flags);
  105. for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
  106. if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
  107. sp->cmd_sp)) {
  108. qpair->req->outstanding_cmds[handle] = NULL;
  109. cmdsp_found = 1;
  110. qla_put_fw_resources(qpair, &sp->cmd_sp->iores);
  111. }
  112. /* removing the abort */
  113. if (qpair->req->outstanding_cmds[handle] == sp) {
  114. qpair->req->outstanding_cmds[handle] = NULL;
  115. sp_found = 1;
  116. qla_put_fw_resources(qpair, &sp->iores);
  117. break;
  118. }
  119. }
  120. spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
  121. if (cmdsp_found && sp->cmd_sp) {
  122. /*
  123. * This done function should take care of
  124. * original command ref: INIT
  125. */
  126. sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
  127. }
  128. if (sp_found) {
  129. abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
  130. sp->done(sp, QLA_OS_TIMER_EXPIRED);
  131. }
  132. }
  133. static void qla24xx_abort_sp_done(srb_t *sp, int res)
  134. {
  135. struct srb_iocb *abt = &sp->u.iocb_cmd;
  136. srb_t *orig_sp = sp->cmd_sp;
  137. if (orig_sp)
  138. qla_wait_nvme_release_cmd_kref(orig_sp);
  139. if (sp->flags & SRB_WAKEUP_ON_COMP)
  140. complete(&abt->u.abt.comp);
  141. else
  142. /* ref: INIT */
  143. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  144. }
  145. int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
  146. {
  147. scsi_qla_host_t *vha = cmd_sp->vha;
  148. struct srb_iocb *abt_iocb;
  149. srb_t *sp;
  150. int rval = QLA_FUNCTION_FAILED;
  151. /* ref: INIT for ABTS command */
  152. sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
  153. GFP_ATOMIC);
  154. if (!sp)
  155. return QLA_MEMORY_ALLOC_FAILED;
  156. qla_vha_mark_busy(vha);
  157. abt_iocb = &sp->u.iocb_cmd;
  158. sp->type = SRB_ABT_CMD;
  159. sp->name = "abort";
  160. sp->qpair = cmd_sp->qpair;
  161. sp->cmd_sp = cmd_sp;
  162. if (wait)
  163. sp->flags = SRB_WAKEUP_ON_COMP;
  164. init_completion(&abt_iocb->u.abt.comp);
  165. /* FW can send 2 x ABTS's timeout/20s */
  166. qla2x00_init_async_sp(sp, 42, qla24xx_abort_sp_done);
  167. sp->u.iocb_cmd.timeout = qla24xx_abort_iocb_timeout;
  168. abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
  169. abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
  170. ql_dbg(ql_dbg_async, vha, 0x507c,
  171. "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
  172. cmd_sp->type);
  173. rval = qla2x00_start_sp(sp);
  174. if (rval != QLA_SUCCESS) {
  175. /* ref: INIT */
  176. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  177. return rval;
  178. }
  179. if (wait) {
  180. wait_for_completion(&abt_iocb->u.abt.comp);
  181. rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
  182. QLA_SUCCESS : QLA_ERR_FROM_FW;
  183. /* ref: INIT */
  184. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  185. }
  186. return rval;
  187. }
  188. void
  189. qla2x00_async_iocb_timeout(void *data)
  190. {
  191. srb_t *sp = data;
  192. fc_port_t *fcport = sp->fcport;
  193. struct srb_iocb *lio = &sp->u.iocb_cmd;
  194. int rc, h;
  195. unsigned long flags;
  196. if (fcport) {
  197. ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
  198. "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
  199. sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
  200. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  201. } else {
  202. pr_info("Async-%s timeout - hdl=%x.\n",
  203. sp->name, sp->handle);
  204. }
  205. switch (sp->type) {
  206. case SRB_LOGIN_CMD:
  207. rc = qla24xx_async_abort_cmd(sp, false);
  208. if (rc) {
  209. /* Retry as needed. */
  210. lio->u.logio.data[0] = MBS_COMMAND_ERROR;
  211. lio->u.logio.data[1] =
  212. lio->u.logio.flags & SRB_LOGIN_RETRIED ?
  213. QLA_LOGIO_LOGIN_RETRIED : 0;
  214. spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
  215. for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
  216. h++) {
  217. if (sp->qpair->req->outstanding_cmds[h] ==
  218. sp) {
  219. sp->qpair->req->outstanding_cmds[h] =
  220. NULL;
  221. break;
  222. }
  223. }
  224. spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
  225. sp->done(sp, QLA_FUNCTION_TIMEOUT);
  226. }
  227. break;
  228. case SRB_LOGOUT_CMD:
  229. case SRB_CT_PTHRU_CMD:
  230. case SRB_MB_IOCB:
  231. case SRB_NACK_PLOGI:
  232. case SRB_NACK_PRLI:
  233. case SRB_NACK_LOGO:
  234. case SRB_CTRL_VP:
  235. default:
  236. rc = qla24xx_async_abort_cmd(sp, false);
  237. if (rc) {
  238. spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
  239. for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
  240. h++) {
  241. if (sp->qpair->req->outstanding_cmds[h] ==
  242. sp) {
  243. sp->qpair->req->outstanding_cmds[h] =
  244. NULL;
  245. break;
  246. }
  247. }
  248. spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
  249. sp->done(sp, QLA_FUNCTION_TIMEOUT);
  250. }
  251. break;
  252. }
  253. }
  254. static void qla2x00_async_login_sp_done(srb_t *sp, int res)
  255. {
  256. struct scsi_qla_host *vha = sp->vha;
  257. struct srb_iocb *lio = &sp->u.iocb_cmd;
  258. struct event_arg ea;
  259. ql_dbg(ql_dbg_disc, vha, 0x20dd,
  260. "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
  261. sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  262. if (!test_bit(UNLOADING, &vha->dpc_flags)) {
  263. memset(&ea, 0, sizeof(ea));
  264. ea.fcport = sp->fcport;
  265. ea.data[0] = lio->u.logio.data[0];
  266. ea.data[1] = lio->u.logio.data[1];
  267. ea.iop[0] = lio->u.logio.iop[0];
  268. ea.iop[1] = lio->u.logio.iop[1];
  269. ea.sp = sp;
  270. if (res)
  271. ea.data[0] = MBS_COMMAND_ERROR;
  272. qla24xx_handle_plogi_done_event(vha, &ea);
  273. }
  274. /* ref: INIT */
  275. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  276. }
  277. int
  278. qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
  279. uint16_t *data)
  280. {
  281. srb_t *sp;
  282. struct srb_iocb *lio;
  283. int rval = QLA_FUNCTION_FAILED;
  284. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
  285. fcport->loop_id == FC_NO_LOOP_ID) {
  286. ql_log(ql_log_warn, vha, 0xffff,
  287. "%s: %8phC - not sending command.\n",
  288. __func__, fcport->port_name);
  289. return rval;
  290. }
  291. /* ref: INIT */
  292. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  293. if (!sp)
  294. goto done;
  295. qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
  296. fcport->flags |= FCF_ASYNC_SENT;
  297. fcport->logout_completed = 0;
  298. sp->type = SRB_LOGIN_CMD;
  299. sp->name = "login";
  300. sp->gen1 = fcport->rscn_gen;
  301. sp->gen2 = fcport->login_gen;
  302. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  303. qla2x00_async_login_sp_done);
  304. lio = &sp->u.iocb_cmd;
  305. if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
  306. lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
  307. } else {
  308. if (vha->hw->flags.edif_enabled &&
  309. DBELL_ACTIVE(vha)) {
  310. lio->u.logio.flags |=
  311. (SRB_LOGIN_FCSP | SRB_LOGIN_SKIP_PRLI);
  312. } else {
  313. lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
  314. }
  315. }
  316. if (NVME_TARGET(vha->hw, fcport))
  317. lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
  318. rval = qla2x00_start_sp(sp);
  319. ql_dbg(ql_dbg_disc, vha, 0x2072,
  320. "Async-login - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
  321. fcport->port_name, sp->handle, fcport->loop_id,
  322. fcport->d_id.b24, fcport->login_retry,
  323. lio->u.logio.flags & SRB_LOGIN_FCSP ? "FCSP" : "");
  324. if (rval != QLA_SUCCESS) {
  325. fcport->flags |= FCF_LOGIN_NEEDED;
  326. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  327. goto done_free_sp;
  328. }
  329. return rval;
  330. done_free_sp:
  331. /* ref: INIT */
  332. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  333. fcport->flags &= ~FCF_ASYNC_SENT;
  334. done:
  335. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  336. /*
  337. * async login failed. Could be due to iocb/exchange resource
  338. * being low. Set state DELETED for re-login process to start again.
  339. */
  340. qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
  341. return rval;
  342. }
  343. static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
  344. {
  345. sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  346. sp->fcport->login_gen++;
  347. qlt_logo_completion_handler(sp->fcport, sp->u.iocb_cmd.u.logio.data[0]);
  348. /* ref: INIT */
  349. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  350. }
  351. int
  352. qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
  353. {
  354. srb_t *sp;
  355. int rval = QLA_FUNCTION_FAILED;
  356. fcport->flags |= FCF_ASYNC_SENT;
  357. /* ref: INIT */
  358. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  359. if (!sp)
  360. goto done;
  361. sp->type = SRB_LOGOUT_CMD;
  362. sp->name = "logout";
  363. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  364. qla2x00_async_logout_sp_done);
  365. ql_dbg(ql_dbg_disc, vha, 0x2070,
  366. "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC explicit %d.\n",
  367. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  368. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  369. fcport->port_name, fcport->explicit_logout);
  370. rval = qla2x00_start_sp(sp);
  371. if (rval != QLA_SUCCESS)
  372. goto done_free_sp;
  373. return rval;
  374. done_free_sp:
  375. /* ref: INIT */
  376. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  377. done:
  378. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  379. return rval;
  380. }
  381. void
  382. qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
  383. uint16_t *data)
  384. {
  385. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  386. /* Don't re-login in target mode */
  387. if (!fcport->tgt_session)
  388. qla2x00_mark_device_lost(vha, fcport, 1);
  389. qlt_logo_completion_handler(fcport, data[0]);
  390. }
  391. static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
  392. {
  393. struct srb_iocb *lio = &sp->u.iocb_cmd;
  394. struct scsi_qla_host *vha = sp->vha;
  395. sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
  396. if (!test_bit(UNLOADING, &vha->dpc_flags))
  397. qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
  398. lio->u.logio.data);
  399. /* ref: INIT */
  400. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  401. }
  402. int
  403. qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
  404. {
  405. srb_t *sp;
  406. int rval;
  407. rval = QLA_FUNCTION_FAILED;
  408. /* ref: INIT */
  409. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  410. if (!sp)
  411. goto done;
  412. sp->type = SRB_PRLO_CMD;
  413. sp->name = "prlo";
  414. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  415. qla2x00_async_prlo_sp_done);
  416. ql_dbg(ql_dbg_disc, vha, 0x2070,
  417. "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
  418. sp->handle, fcport->loop_id, fcport->d_id.b.domain,
  419. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  420. rval = qla2x00_start_sp(sp);
  421. if (rval != QLA_SUCCESS)
  422. goto done_free_sp;
  423. return rval;
  424. done_free_sp:
  425. /* ref: INIT */
  426. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  427. done:
  428. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  429. return rval;
  430. }
  431. static
  432. void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
  433. {
  434. struct fc_port *fcport = ea->fcport;
  435. unsigned long flags;
  436. ql_dbg(ql_dbg_disc, vha, 0x20d2,
  437. "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
  438. __func__, fcport->port_name, fcport->disc_state,
  439. fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
  440. fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
  441. WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
  442. ea->data[0]);
  443. if (ea->data[0] != MBS_COMMAND_COMPLETE) {
  444. ql_dbg(ql_dbg_disc, vha, 0x2066,
  445. "%s %8phC: adisc fail: post delete\n",
  446. __func__, ea->fcport->port_name);
  447. spin_lock_irqsave(&vha->work_lock, flags);
  448. /* deleted = 0 & logout_on_delete = force fw cleanup */
  449. if (fcport->deleted == QLA_SESS_DELETED)
  450. fcport->deleted = 0;
  451. fcport->logout_on_delete = 1;
  452. spin_unlock_irqrestore(&vha->work_lock, flags);
  453. qlt_schedule_sess_for_deletion(ea->fcport);
  454. return;
  455. }
  456. if (ea->fcport->disc_state == DSC_DELETE_PEND)
  457. return;
  458. if (ea->sp->gen2 != ea->fcport->login_gen) {
  459. /* target side must have changed it. */
  460. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  461. "%s %8phC generation changed\n",
  462. __func__, ea->fcport->port_name);
  463. return;
  464. } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
  465. qla_rscn_replay(fcport);
  466. qlt_schedule_sess_for_deletion(fcport);
  467. return;
  468. }
  469. __qla24xx_handle_gpdb_event(vha, ea);
  470. }
  471. static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  472. {
  473. struct qla_work_evt *e;
  474. e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
  475. if (!e)
  476. return QLA_FUNCTION_FAILED;
  477. e->u.fcport.fcport = fcport;
  478. fcport->flags |= FCF_ASYNC_ACTIVE;
  479. qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
  480. return qla2x00_post_work(vha, e);
  481. }
  482. static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
  483. {
  484. struct scsi_qla_host *vha = sp->vha;
  485. struct event_arg ea;
  486. struct srb_iocb *lio = &sp->u.iocb_cmd;
  487. ql_dbg(ql_dbg_disc, vha, 0x2066,
  488. "Async done-%s res %x %8phC\n",
  489. sp->name, res, sp->fcport->port_name);
  490. sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  491. memset(&ea, 0, sizeof(ea));
  492. ea.rc = res;
  493. ea.data[0] = lio->u.logio.data[0];
  494. ea.data[1] = lio->u.logio.data[1];
  495. ea.iop[0] = lio->u.logio.iop[0];
  496. ea.iop[1] = lio->u.logio.iop[1];
  497. ea.fcport = sp->fcport;
  498. ea.sp = sp;
  499. if (res)
  500. ea.data[0] = MBS_COMMAND_ERROR;
  501. qla24xx_handle_adisc_event(vha, &ea);
  502. /* ref: INIT */
  503. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  504. }
  505. int
  506. qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
  507. uint16_t *data)
  508. {
  509. srb_t *sp;
  510. struct srb_iocb *lio;
  511. int rval = QLA_FUNCTION_FAILED;
  512. if (IS_SESSION_DELETED(fcport)) {
  513. ql_log(ql_log_warn, vha, 0xffff,
  514. "%s: %8phC is being delete - not sending command.\n",
  515. __func__, fcport->port_name);
  516. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  517. return rval;
  518. }
  519. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  520. return rval;
  521. fcport->flags |= FCF_ASYNC_SENT;
  522. /* ref: INIT */
  523. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  524. if (!sp)
  525. goto done;
  526. sp->type = SRB_ADISC_CMD;
  527. sp->name = "adisc";
  528. sp->gen1 = fcport->rscn_gen;
  529. sp->gen2 = fcport->login_gen;
  530. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  531. qla2x00_async_adisc_sp_done);
  532. if (data[1] & QLA_LOGIO_LOGIN_RETRIED) {
  533. lio = &sp->u.iocb_cmd;
  534. lio->u.logio.flags |= SRB_LOGIN_RETRIED;
  535. }
  536. ql_dbg(ql_dbg_disc, vha, 0x206f,
  537. "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
  538. sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
  539. rval = qla2x00_start_sp(sp);
  540. if (rval != QLA_SUCCESS)
  541. goto done_free_sp;
  542. return rval;
  543. done_free_sp:
  544. /* ref: INIT */
  545. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  546. done:
  547. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  548. qla2x00_post_async_adisc_work(vha, fcport, data);
  549. return rval;
  550. }
  551. static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
  552. {
  553. struct qla_hw_data *ha = vha->hw;
  554. if (IS_FWI2_CAPABLE(ha))
  555. return loop_id > NPH_LAST_HANDLE;
  556. return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
  557. loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
  558. }
  559. /**
  560. * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
  561. * @vha: adapter state pointer.
  562. * @dev: port structure pointer.
  563. *
  564. * Returns:
  565. * qla2x00 local function return status code.
  566. *
  567. * Context:
  568. * Kernel context.
  569. */
  570. static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
  571. {
  572. int rval;
  573. struct qla_hw_data *ha = vha->hw;
  574. unsigned long flags = 0;
  575. rval = QLA_SUCCESS;
  576. spin_lock_irqsave(&ha->vport_slock, flags);
  577. dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
  578. if (dev->loop_id >= LOOPID_MAP_SIZE ||
  579. qla2x00_is_reserved_id(vha, dev->loop_id)) {
  580. dev->loop_id = FC_NO_LOOP_ID;
  581. rval = QLA_FUNCTION_FAILED;
  582. } else {
  583. set_bit(dev->loop_id, ha->loop_id_map);
  584. }
  585. spin_unlock_irqrestore(&ha->vport_slock, flags);
  586. if (rval == QLA_SUCCESS)
  587. ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
  588. "Assigning new loopid=%x, portid=%x.\n",
  589. dev->loop_id, dev->d_id.b24);
  590. else
  591. ql_log(ql_log_warn, dev->vha, 0x2087,
  592. "No loop_id's available, portid=%x.\n",
  593. dev->d_id.b24);
  594. return rval;
  595. }
  596. void qla2x00_clear_loop_id(fc_port_t *fcport)
  597. {
  598. struct qla_hw_data *ha = fcport->vha->hw;
  599. if (fcport->loop_id == FC_NO_LOOP_ID ||
  600. qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
  601. return;
  602. clear_bit(fcport->loop_id, ha->loop_id_map);
  603. fcport->loop_id = FC_NO_LOOP_ID;
  604. }
  605. static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
  606. struct event_arg *ea)
  607. {
  608. fc_port_t *fcport, *conflict_fcport;
  609. struct get_name_list_extended *e;
  610. u16 i, n, found = 0, loop_id;
  611. port_id_t id;
  612. u64 wwn;
  613. u16 data[2];
  614. u8 current_login_state, nvme_cls;
  615. fcport = ea->fcport;
  616. ql_dbg(ql_dbg_disc, vha, 0xffff,
  617. "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d edif %d\n",
  618. __func__, fcport->port_name, fcport->disc_state,
  619. fcport->fw_login_state, ea->rc,
  620. fcport->login_gen, fcport->last_login_gen,
  621. fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id, fcport->edif.enable);
  622. if (fcport->disc_state == DSC_DELETE_PEND)
  623. return;
  624. if (ea->rc) { /* rval */
  625. if (fcport->login_retry == 0) {
  626. ql_dbg(ql_dbg_disc, vha, 0x20de,
  627. "GNL failed Port login retry %8phN, retry cnt=%d.\n",
  628. fcport->port_name, fcport->login_retry);
  629. }
  630. return;
  631. }
  632. if (fcport->last_rscn_gen != fcport->rscn_gen) {
  633. qla_rscn_replay(fcport);
  634. qlt_schedule_sess_for_deletion(fcport);
  635. return;
  636. } else if (fcport->last_login_gen != fcport->login_gen) {
  637. ql_dbg(ql_dbg_disc, vha, 0x20e0,
  638. "%s %8phC login gen changed\n",
  639. __func__, fcport->port_name);
  640. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  641. return;
  642. }
  643. n = ea->data[0] / sizeof(struct get_name_list_extended);
  644. ql_dbg(ql_dbg_disc, vha, 0x20e1,
  645. "%s %d %8phC n %d %02x%02x%02x lid %d \n",
  646. __func__, __LINE__, fcport->port_name, n,
  647. fcport->d_id.b.domain, fcport->d_id.b.area,
  648. fcport->d_id.b.al_pa, fcport->loop_id);
  649. for (i = 0; i < n; i++) {
  650. e = &vha->gnl.l[i];
  651. wwn = wwn_to_u64(e->port_name);
  652. id.b.domain = e->port_id[2];
  653. id.b.area = e->port_id[1];
  654. id.b.al_pa = e->port_id[0];
  655. id.b.rsvd_1 = 0;
  656. if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
  657. continue;
  658. if (IS_SW_RESV_ADDR(id))
  659. continue;
  660. found = 1;
  661. loop_id = le16_to_cpu(e->nport_handle);
  662. loop_id = (loop_id & 0x7fff);
  663. nvme_cls = e->current_login_state >> 4;
  664. current_login_state = e->current_login_state & 0xf;
  665. if (PRLI_PHASE(nvme_cls)) {
  666. current_login_state = nvme_cls;
  667. fcport->fc4_type &= ~FS_FC4TYPE_FCP;
  668. fcport->fc4_type |= FS_FC4TYPE_NVME;
  669. } else if (PRLI_PHASE(current_login_state)) {
  670. fcport->fc4_type |= FS_FC4TYPE_FCP;
  671. fcport->fc4_type &= ~FS_FC4TYPE_NVME;
  672. }
  673. ql_dbg(ql_dbg_disc, vha, 0x20e2,
  674. "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
  675. __func__, fcport->port_name,
  676. e->current_login_state, fcport->fw_login_state,
  677. fcport->fc4_type, id.b24, fcport->d_id.b24,
  678. loop_id, fcport->loop_id);
  679. switch (fcport->disc_state) {
  680. case DSC_DELETE_PEND:
  681. case DSC_DELETED:
  682. break;
  683. default:
  684. if ((id.b24 != fcport->d_id.b24 &&
  685. fcport->d_id.b24 &&
  686. fcport->loop_id != FC_NO_LOOP_ID) ||
  687. (fcport->loop_id != FC_NO_LOOP_ID &&
  688. fcport->loop_id != loop_id)) {
  689. ql_dbg(ql_dbg_disc, vha, 0x20e3,
  690. "%s %d %8phC post del sess\n",
  691. __func__, __LINE__, fcport->port_name);
  692. if (fcport->n2n_flag)
  693. fcport->d_id.b24 = 0;
  694. qlt_schedule_sess_for_deletion(fcport);
  695. return;
  696. }
  697. break;
  698. }
  699. fcport->loop_id = loop_id;
  700. if (fcport->n2n_flag)
  701. fcport->d_id.b24 = id.b24;
  702. wwn = wwn_to_u64(fcport->port_name);
  703. qlt_find_sess_invalidate_other(vha, wwn,
  704. id, loop_id, &conflict_fcport);
  705. if (conflict_fcport) {
  706. /*
  707. * Another share fcport share the same loop_id &
  708. * nport id. Conflict fcport needs to finish
  709. * cleanup before this fcport can proceed to login.
  710. */
  711. conflict_fcport->conflict = fcport;
  712. fcport->login_pause = 1;
  713. }
  714. switch (vha->hw->current_topology) {
  715. default:
  716. switch (current_login_state) {
  717. case DSC_LS_PRLI_COMP:
  718. ql_dbg(ql_dbg_disc,
  719. vha, 0x20e4, "%s %d %8phC post gpdb\n",
  720. __func__, __LINE__, fcport->port_name);
  721. if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
  722. fcport->port_type = FCT_INITIATOR;
  723. else
  724. fcport->port_type = FCT_TARGET;
  725. data[0] = data[1] = 0;
  726. qla2x00_post_async_adisc_work(vha, fcport,
  727. data);
  728. break;
  729. case DSC_LS_PLOGI_COMP:
  730. if (vha->hw->flags.edif_enabled) {
  731. /* check to see if App support Secure */
  732. qla24xx_post_gpdb_work(vha, fcport, 0);
  733. break;
  734. }
  735. fallthrough;
  736. case DSC_LS_PORT_UNAVAIL:
  737. default:
  738. if (fcport->loop_id == FC_NO_LOOP_ID) {
  739. qla2x00_find_new_loop_id(vha, fcport);
  740. fcport->fw_login_state =
  741. DSC_LS_PORT_UNAVAIL;
  742. }
  743. ql_dbg(ql_dbg_disc, vha, 0x20e5,
  744. "%s %d %8phC\n", __func__, __LINE__,
  745. fcport->port_name);
  746. qla24xx_fcport_handle_login(vha, fcport);
  747. break;
  748. }
  749. break;
  750. case ISP_CFG_N:
  751. fcport->fw_login_state = current_login_state;
  752. fcport->d_id = id;
  753. switch (current_login_state) {
  754. case DSC_LS_PRLI_PEND:
  755. /*
  756. * In the middle of PRLI. Let it finish.
  757. * Allow relogin code to recheck state again
  758. * with GNL. Push disc_state back to DELETED
  759. * so GNL can go out again
  760. */
  761. qla2x00_set_fcport_disc_state(fcport,
  762. DSC_DELETED);
  763. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  764. break;
  765. case DSC_LS_PRLI_COMP:
  766. if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
  767. fcport->port_type = FCT_INITIATOR;
  768. else
  769. fcport->port_type = FCT_TARGET;
  770. data[0] = data[1] = 0;
  771. qla2x00_post_async_adisc_work(vha, fcport,
  772. data);
  773. break;
  774. case DSC_LS_PLOGI_COMP:
  775. if (vha->hw->flags.edif_enabled &&
  776. DBELL_ACTIVE(vha)) {
  777. /* check to see if App support secure or not */
  778. qla24xx_post_gpdb_work(vha, fcport, 0);
  779. break;
  780. }
  781. if (fcport_is_bigger(fcport)) {
  782. /* local adapter is smaller */
  783. if (fcport->loop_id != FC_NO_LOOP_ID)
  784. qla2x00_clear_loop_id(fcport);
  785. fcport->loop_id = loop_id;
  786. qla24xx_fcport_handle_login(vha,
  787. fcport);
  788. break;
  789. }
  790. fallthrough;
  791. default:
  792. if (fcport_is_smaller(fcport)) {
  793. /* local adapter is bigger */
  794. if (fcport->loop_id != FC_NO_LOOP_ID)
  795. qla2x00_clear_loop_id(fcport);
  796. fcport->loop_id = loop_id;
  797. qla24xx_fcport_handle_login(vha,
  798. fcport);
  799. }
  800. break;
  801. }
  802. break;
  803. } /* switch (ha->current_topology) */
  804. }
  805. if (!found) {
  806. switch (vha->hw->current_topology) {
  807. case ISP_CFG_F:
  808. case ISP_CFG_FL:
  809. for (i = 0; i < n; i++) {
  810. e = &vha->gnl.l[i];
  811. id.b.domain = e->port_id[0];
  812. id.b.area = e->port_id[1];
  813. id.b.al_pa = e->port_id[2];
  814. id.b.rsvd_1 = 0;
  815. loop_id = le16_to_cpu(e->nport_handle);
  816. if (fcport->d_id.b24 == id.b24) {
  817. conflict_fcport =
  818. qla2x00_find_fcport_by_wwpn(vha,
  819. e->port_name, 0);
  820. if (conflict_fcport) {
  821. ql_dbg(ql_dbg_disc + ql_dbg_verbose,
  822. vha, 0x20e5,
  823. "%s %d %8phC post del sess\n",
  824. __func__, __LINE__,
  825. conflict_fcport->port_name);
  826. qlt_schedule_sess_for_deletion
  827. (conflict_fcport);
  828. }
  829. }
  830. /*
  831. * FW already picked this loop id for
  832. * another fcport
  833. */
  834. if (fcport->loop_id == loop_id)
  835. fcport->loop_id = FC_NO_LOOP_ID;
  836. }
  837. qla24xx_fcport_handle_login(vha, fcport);
  838. break;
  839. case ISP_CFG_N:
  840. qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
  841. if (time_after_eq(jiffies, fcport->dm_login_expire)) {
  842. if (fcport->n2n_link_reset_cnt < 2) {
  843. fcport->n2n_link_reset_cnt++;
  844. /*
  845. * remote port is not sending PLOGI.
  846. * Reset link to kick start his state
  847. * machine
  848. */
  849. set_bit(N2N_LINK_RESET,
  850. &vha->dpc_flags);
  851. } else {
  852. if (fcport->n2n_chip_reset < 1) {
  853. ql_log(ql_log_info, vha, 0x705d,
  854. "Chip reset to bring laser down");
  855. set_bit(ISP_ABORT_NEEDED,
  856. &vha->dpc_flags);
  857. fcport->n2n_chip_reset++;
  858. } else {
  859. ql_log(ql_log_info, vha, 0x705d,
  860. "Remote port %8ph is not coming back\n",
  861. fcport->port_name);
  862. fcport->scan_state = 0;
  863. }
  864. }
  865. qla2xxx_wake_dpc(vha);
  866. } else {
  867. /*
  868. * report port suppose to do PLOGI. Give him
  869. * more time. FW will catch it.
  870. */
  871. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  872. }
  873. break;
  874. case ISP_CFG_NL:
  875. qla24xx_fcport_handle_login(vha, fcport);
  876. break;
  877. default:
  878. break;
  879. }
  880. }
  881. } /* gnl_event */
  882. static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
  883. {
  884. struct scsi_qla_host *vha = sp->vha;
  885. unsigned long flags;
  886. struct fc_port *fcport = NULL, *tf;
  887. u16 i, n = 0, loop_id;
  888. struct event_arg ea;
  889. struct get_name_list_extended *e;
  890. u64 wwn;
  891. struct list_head h;
  892. bool found = false;
  893. ql_dbg(ql_dbg_disc, vha, 0x20e7,
  894. "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
  895. sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
  896. sp->u.iocb_cmd.u.mbx.in_mb[2]);
  897. sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
  898. memset(&ea, 0, sizeof(ea));
  899. ea.sp = sp;
  900. ea.rc = res;
  901. if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
  902. sizeof(struct get_name_list_extended)) {
  903. n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
  904. sizeof(struct get_name_list_extended);
  905. ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
  906. }
  907. for (i = 0; i < n; i++) {
  908. e = &vha->gnl.l[i];
  909. loop_id = le16_to_cpu(e->nport_handle);
  910. /* mask out reserve bit */
  911. loop_id = (loop_id & 0x7fff);
  912. set_bit(loop_id, vha->hw->loop_id_map);
  913. wwn = wwn_to_u64(e->port_name);
  914. ql_dbg(ql_dbg_disc, vha, 0x20e8,
  915. "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
  916. __func__, &wwn, e->port_id[2], e->port_id[1],
  917. e->port_id[0], e->current_login_state, e->last_login_state,
  918. (loop_id & 0x7fff));
  919. }
  920. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  921. INIT_LIST_HEAD(&h);
  922. fcport = tf = NULL;
  923. if (!list_empty(&vha->gnl.fcports))
  924. list_splice_init(&vha->gnl.fcports, &h);
  925. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  926. list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
  927. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  928. list_del_init(&fcport->gnl_entry);
  929. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  930. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  931. ea.fcport = fcport;
  932. qla24xx_handle_gnl_done_event(vha, &ea);
  933. }
  934. /* create new fcport if fw has knowledge of new sessions */
  935. for (i = 0; i < n; i++) {
  936. port_id_t id;
  937. u64 wwnn;
  938. e = &vha->gnl.l[i];
  939. wwn = wwn_to_u64(e->port_name);
  940. found = false;
  941. list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
  942. if (!memcmp((u8 *)&wwn, fcport->port_name,
  943. WWN_SIZE)) {
  944. found = true;
  945. break;
  946. }
  947. }
  948. id.b.domain = e->port_id[2];
  949. id.b.area = e->port_id[1];
  950. id.b.al_pa = e->port_id[0];
  951. id.b.rsvd_1 = 0;
  952. if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
  953. ql_dbg(ql_dbg_disc, vha, 0x2065,
  954. "%s %d %8phC %06x post new sess\n",
  955. __func__, __LINE__, (u8 *)&wwn, id.b24);
  956. wwnn = wwn_to_u64(e->node_name);
  957. qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
  958. (u8 *)&wwnn, NULL, 0);
  959. }
  960. }
  961. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  962. vha->gnl.sent = 0;
  963. if (!list_empty(&vha->gnl.fcports)) {
  964. /* retrigger gnl */
  965. list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
  966. gnl_entry) {
  967. list_del_init(&fcport->gnl_entry);
  968. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  969. if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
  970. break;
  971. }
  972. }
  973. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  974. /* ref: INIT */
  975. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  976. }
  977. int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
  978. {
  979. srb_t *sp;
  980. int rval = QLA_FUNCTION_FAILED;
  981. unsigned long flags;
  982. u16 *mb;
  983. if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
  984. goto done;
  985. ql_dbg(ql_dbg_disc, vha, 0x20d9,
  986. "Async-gnlist WWPN %8phC \n", fcport->port_name);
  987. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  988. fcport->flags |= FCF_ASYNC_SENT;
  989. qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
  990. fcport->last_rscn_gen = fcport->rscn_gen;
  991. fcport->last_login_gen = fcport->login_gen;
  992. list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
  993. if (vha->gnl.sent) {
  994. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  995. return QLA_SUCCESS;
  996. }
  997. vha->gnl.sent = 1;
  998. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  999. /* ref: INIT */
  1000. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1001. if (!sp)
  1002. goto done;
  1003. sp->type = SRB_MB_IOCB;
  1004. sp->name = "gnlist";
  1005. sp->gen1 = fcport->rscn_gen;
  1006. sp->gen2 = fcport->login_gen;
  1007. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  1008. qla24xx_async_gnl_sp_done);
  1009. mb = sp->u.iocb_cmd.u.mbx.out_mb;
  1010. mb[0] = MBC_PORT_NODE_NAME_LIST;
  1011. mb[1] = BIT_2 | BIT_3;
  1012. mb[2] = MSW(vha->gnl.ldma);
  1013. mb[3] = LSW(vha->gnl.ldma);
  1014. mb[6] = MSW(MSD(vha->gnl.ldma));
  1015. mb[7] = LSW(MSD(vha->gnl.ldma));
  1016. mb[8] = vha->gnl.size;
  1017. mb[9] = vha->vp_idx;
  1018. ql_dbg(ql_dbg_disc, vha, 0x20da,
  1019. "Async-%s - OUT WWPN %8phC hndl %x\n",
  1020. sp->name, fcport->port_name, sp->handle);
  1021. rval = qla2x00_start_sp(sp);
  1022. if (rval != QLA_SUCCESS)
  1023. goto done_free_sp;
  1024. return rval;
  1025. done_free_sp:
  1026. /*
  1027. * use qla24xx_async_gnl_sp_done to purge all pending gnl request.
  1028. * kref_put is call behind the scene.
  1029. */
  1030. sp->u.iocb_cmd.u.mbx.in_mb[0] = MBS_COMMAND_ERROR;
  1031. qla24xx_async_gnl_sp_done(sp, QLA_COMMAND_ERROR);
  1032. fcport->flags &= ~(FCF_ASYNC_SENT);
  1033. done:
  1034. fcport->flags &= ~(FCF_ASYNC_ACTIVE);
  1035. return rval;
  1036. }
  1037. int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  1038. {
  1039. struct qla_work_evt *e;
  1040. e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
  1041. if (!e)
  1042. return QLA_FUNCTION_FAILED;
  1043. e->u.fcport.fcport = fcport;
  1044. fcport->flags |= FCF_ASYNC_ACTIVE;
  1045. return qla2x00_post_work(vha, e);
  1046. }
  1047. static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
  1048. {
  1049. struct scsi_qla_host *vha = sp->vha;
  1050. struct qla_hw_data *ha = vha->hw;
  1051. fc_port_t *fcport = sp->fcport;
  1052. u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
  1053. struct event_arg ea;
  1054. ql_dbg(ql_dbg_disc, vha, 0x20db,
  1055. "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
  1056. sp->name, res, fcport->port_name, mb[1], mb[2]);
  1057. fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
  1058. if (res == QLA_FUNCTION_TIMEOUT)
  1059. goto done;
  1060. memset(&ea, 0, sizeof(ea));
  1061. ea.fcport = fcport;
  1062. ea.sp = sp;
  1063. qla24xx_handle_gpdb_event(vha, &ea);
  1064. done:
  1065. dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
  1066. sp->u.iocb_cmd.u.mbx.in_dma);
  1067. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1068. }
  1069. int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  1070. {
  1071. struct qla_work_evt *e;
  1072. if (vha->host->active_mode == MODE_TARGET)
  1073. return QLA_FUNCTION_FAILED;
  1074. e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
  1075. if (!e)
  1076. return QLA_FUNCTION_FAILED;
  1077. e->u.fcport.fcport = fcport;
  1078. return qla2x00_post_work(vha, e);
  1079. }
  1080. static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
  1081. {
  1082. struct scsi_qla_host *vha = sp->vha;
  1083. struct srb_iocb *lio = &sp->u.iocb_cmd;
  1084. struct event_arg ea;
  1085. ql_dbg(ql_dbg_disc, vha, 0x2129,
  1086. "%s %8phC res %x\n", __func__,
  1087. sp->fcport->port_name, res);
  1088. sp->fcport->flags &= ~FCF_ASYNC_SENT;
  1089. if (!test_bit(UNLOADING, &vha->dpc_flags)) {
  1090. memset(&ea, 0, sizeof(ea));
  1091. ea.fcport = sp->fcport;
  1092. ea.data[0] = lio->u.logio.data[0];
  1093. ea.data[1] = lio->u.logio.data[1];
  1094. ea.iop[0] = lio->u.logio.iop[0];
  1095. ea.iop[1] = lio->u.logio.iop[1];
  1096. ea.sp = sp;
  1097. if (res == QLA_OS_TIMER_EXPIRED)
  1098. ea.data[0] = QLA_OS_TIMER_EXPIRED;
  1099. else if (res)
  1100. ea.data[0] = MBS_COMMAND_ERROR;
  1101. qla24xx_handle_prli_done_event(vha, &ea);
  1102. }
  1103. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1104. }
  1105. int
  1106. qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
  1107. {
  1108. srb_t *sp;
  1109. struct srb_iocb *lio;
  1110. int rval = QLA_FUNCTION_FAILED;
  1111. if (!vha->flags.online) {
  1112. ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
  1113. __func__, __LINE__, fcport->port_name);
  1114. return rval;
  1115. }
  1116. if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
  1117. fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
  1118. qla_dual_mode_enabled(vha)) {
  1119. ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
  1120. __func__, __LINE__, fcport->port_name);
  1121. return rval;
  1122. }
  1123. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1124. if (!sp)
  1125. return rval;
  1126. fcport->flags |= FCF_ASYNC_SENT;
  1127. fcport->logout_completed = 0;
  1128. sp->type = SRB_PRLI_CMD;
  1129. sp->name = "prli";
  1130. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  1131. qla2x00_async_prli_sp_done);
  1132. lio = &sp->u.iocb_cmd;
  1133. lio->u.logio.flags = 0;
  1134. if (NVME_TARGET(vha->hw, fcport))
  1135. lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
  1136. ql_dbg(ql_dbg_disc, vha, 0x211b,
  1137. "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
  1138. fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
  1139. fcport->login_retry, fcport->fc4_type, vha->hw->fc4_type_priority,
  1140. NVME_TARGET(vha->hw, fcport) ? "nvme" : "fcp");
  1141. rval = qla2x00_start_sp(sp);
  1142. if (rval != QLA_SUCCESS) {
  1143. fcport->flags |= FCF_LOGIN_NEEDED;
  1144. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1145. goto done_free_sp;
  1146. }
  1147. return rval;
  1148. done_free_sp:
  1149. /* ref: INIT */
  1150. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1151. fcport->flags &= ~FCF_ASYNC_SENT;
  1152. return rval;
  1153. }
  1154. int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
  1155. {
  1156. struct qla_work_evt *e;
  1157. e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
  1158. if (!e)
  1159. return QLA_FUNCTION_FAILED;
  1160. e->u.fcport.fcport = fcport;
  1161. e->u.fcport.opt = opt;
  1162. fcport->flags |= FCF_ASYNC_ACTIVE;
  1163. return qla2x00_post_work(vha, e);
  1164. }
  1165. int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
  1166. {
  1167. srb_t *sp;
  1168. struct srb_iocb *mbx;
  1169. int rval = QLA_FUNCTION_FAILED;
  1170. u16 *mb;
  1171. dma_addr_t pd_dma;
  1172. struct port_database_24xx *pd;
  1173. struct qla_hw_data *ha = vha->hw;
  1174. if (IS_SESSION_DELETED(fcport)) {
  1175. ql_log(ql_log_warn, vha, 0xffff,
  1176. "%s: %8phC is being delete - not sending command.\n",
  1177. __func__, fcport->port_name);
  1178. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  1179. return rval;
  1180. }
  1181. if (!vha->flags.online || fcport->flags & FCF_ASYNC_SENT) {
  1182. ql_log(ql_log_warn, vha, 0xffff,
  1183. "%s: %8phC online %d flags %x - not sending command.\n",
  1184. __func__, fcport->port_name, vha->flags.online, fcport->flags);
  1185. goto done;
  1186. }
  1187. sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
  1188. if (!sp)
  1189. goto done;
  1190. qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
  1191. fcport->flags |= FCF_ASYNC_SENT;
  1192. sp->type = SRB_MB_IOCB;
  1193. sp->name = "gpdb";
  1194. sp->gen1 = fcport->rscn_gen;
  1195. sp->gen2 = fcport->login_gen;
  1196. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha) + 2,
  1197. qla24xx_async_gpdb_sp_done);
  1198. pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  1199. if (pd == NULL) {
  1200. ql_log(ql_log_warn, vha, 0xd043,
  1201. "Failed to allocate port database structure.\n");
  1202. goto done_free_sp;
  1203. }
  1204. mb = sp->u.iocb_cmd.u.mbx.out_mb;
  1205. mb[0] = MBC_GET_PORT_DATABASE;
  1206. mb[1] = fcport->loop_id;
  1207. mb[2] = MSW(pd_dma);
  1208. mb[3] = LSW(pd_dma);
  1209. mb[6] = MSW(MSD(pd_dma));
  1210. mb[7] = LSW(MSD(pd_dma));
  1211. mb[9] = vha->vp_idx;
  1212. mb[10] = opt;
  1213. mbx = &sp->u.iocb_cmd;
  1214. mbx->u.mbx.in = (void *)pd;
  1215. mbx->u.mbx.in_dma = pd_dma;
  1216. ql_dbg(ql_dbg_disc, vha, 0x20dc,
  1217. "Async-%s %8phC hndl %x opt %x\n",
  1218. sp->name, fcport->port_name, sp->handle, opt);
  1219. rval = qla2x00_start_sp(sp);
  1220. if (rval != QLA_SUCCESS)
  1221. goto done_free_sp;
  1222. return rval;
  1223. done_free_sp:
  1224. if (pd)
  1225. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1226. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1227. fcport->flags &= ~FCF_ASYNC_SENT;
  1228. done:
  1229. fcport->flags &= ~FCF_ASYNC_ACTIVE;
  1230. qla24xx_post_gpdb_work(vha, fcport, opt);
  1231. return rval;
  1232. }
  1233. static
  1234. void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
  1235. {
  1236. unsigned long flags;
  1237. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  1238. ea->fcport->login_gen++;
  1239. ea->fcport->logout_on_delete = 1;
  1240. if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
  1241. vha->fcport_count++;
  1242. ea->fcport->login_succ = 1;
  1243. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  1244. qla24xx_sched_upd_fcport(ea->fcport);
  1245. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  1246. } else if (ea->fcport->login_succ) {
  1247. /*
  1248. * We have an existing session. A late RSCN delivery
  1249. * must have triggered the session to be re-validate.
  1250. * Session is still valid.
  1251. */
  1252. ql_dbg(ql_dbg_disc, vha, 0x20d6,
  1253. "%s %d %8phC session revalidate success\n",
  1254. __func__, __LINE__, ea->fcport->port_name);
  1255. qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
  1256. }
  1257. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  1258. }
  1259. static int qla_chk_secure_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  1260. struct port_database_24xx *pd)
  1261. {
  1262. int rc = 0;
  1263. if (pd->secure_login) {
  1264. ql_dbg(ql_dbg_disc, vha, 0x104d,
  1265. "Secure Login established on %8phC\n",
  1266. fcport->port_name);
  1267. fcport->flags |= FCF_FCSP_DEVICE;
  1268. } else {
  1269. ql_dbg(ql_dbg_disc, vha, 0x104d,
  1270. "non-Secure Login %8phC",
  1271. fcport->port_name);
  1272. fcport->flags &= ~FCF_FCSP_DEVICE;
  1273. }
  1274. if (vha->hw->flags.edif_enabled) {
  1275. if (fcport->flags & FCF_FCSP_DEVICE) {
  1276. qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_AUTH_PEND);
  1277. /* Start edif prli timer & ring doorbell for app */
  1278. fcport->edif.rx_sa_set = 0;
  1279. fcport->edif.tx_sa_set = 0;
  1280. fcport->edif.rx_sa_pending = 0;
  1281. fcport->edif.tx_sa_pending = 0;
  1282. qla2x00_post_aen_work(vha, FCH_EVT_PORT_ONLINE,
  1283. fcport->d_id.b24);
  1284. if (DBELL_ACTIVE(vha)) {
  1285. ql_dbg(ql_dbg_disc, vha, 0x20ef,
  1286. "%s %d %8phC EDIF: post DB_AUTH: AUTH needed\n",
  1287. __func__, __LINE__, fcport->port_name);
  1288. fcport->edif.app_sess_online = 1;
  1289. qla_edb_eventcreate(vha, VND_CMD_AUTH_STATE_NEEDED,
  1290. fcport->d_id.b24, 0, fcport);
  1291. }
  1292. rc = 1;
  1293. } else if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
  1294. ql_dbg(ql_dbg_disc, vha, 0x2117,
  1295. "%s %d %8phC post prli\n",
  1296. __func__, __LINE__, fcport->port_name);
  1297. qla24xx_post_prli_work(vha, fcport);
  1298. rc = 1;
  1299. }
  1300. }
  1301. return rc;
  1302. }
  1303. static
  1304. void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
  1305. {
  1306. fc_port_t *fcport = ea->fcport;
  1307. struct port_database_24xx *pd;
  1308. struct srb *sp = ea->sp;
  1309. uint8_t ls;
  1310. pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
  1311. fcport->flags &= ~FCF_ASYNC_SENT;
  1312. ql_dbg(ql_dbg_disc, vha, 0x20d2,
  1313. "%s %8phC DS %d LS %x fc4_type %x rc %x\n", __func__,
  1314. fcport->port_name, fcport->disc_state, pd->current_login_state,
  1315. fcport->fc4_type, ea->rc);
  1316. if (fcport->disc_state == DSC_DELETE_PEND) {
  1317. ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC\n",
  1318. __func__, __LINE__, fcport->port_name);
  1319. return;
  1320. }
  1321. if (NVME_TARGET(vha->hw, fcport))
  1322. ls = pd->current_login_state >> 4;
  1323. else
  1324. ls = pd->current_login_state & 0xf;
  1325. if (ea->sp->gen2 != fcport->login_gen) {
  1326. /* target side must have changed it. */
  1327. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  1328. "%s %8phC generation changed\n",
  1329. __func__, fcport->port_name);
  1330. return;
  1331. } else if (ea->sp->gen1 != fcport->rscn_gen) {
  1332. qla_rscn_replay(fcport);
  1333. qlt_schedule_sess_for_deletion(fcport);
  1334. ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
  1335. __func__, __LINE__, fcport->port_name, ls);
  1336. return;
  1337. }
  1338. switch (ls) {
  1339. case PDS_PRLI_COMPLETE:
  1340. __qla24xx_parse_gpdb(vha, fcport, pd);
  1341. break;
  1342. case PDS_PLOGI_COMPLETE:
  1343. if (qla_chk_secure_login(vha, fcport, pd)) {
  1344. ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
  1345. __func__, __LINE__, fcport->port_name, ls);
  1346. return;
  1347. }
  1348. fallthrough;
  1349. case PDS_PLOGI_PENDING:
  1350. case PDS_PRLI_PENDING:
  1351. case PDS_PRLI2_PENDING:
  1352. /* Set discovery state back to GNL to Relogin attempt */
  1353. if (qla_dual_mode_enabled(vha) ||
  1354. qla_ini_mode_enabled(vha)) {
  1355. qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
  1356. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1357. }
  1358. ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC, ls %x\n",
  1359. __func__, __LINE__, fcport->port_name, ls);
  1360. return;
  1361. case PDS_LOGO_PENDING:
  1362. case PDS_PORT_UNAVAILABLE:
  1363. default:
  1364. ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
  1365. __func__, __LINE__, fcport->port_name);
  1366. qlt_schedule_sess_for_deletion(fcport);
  1367. return;
  1368. }
  1369. __qla24xx_handle_gpdb_event(vha, ea);
  1370. } /* gpdb event */
  1371. static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
  1372. {
  1373. u8 login = 0;
  1374. int rc;
  1375. ql_dbg(ql_dbg_disc, vha, 0x307b,
  1376. "%s %8phC DS %d LS %d lid %d retries=%d\n",
  1377. __func__, fcport->port_name, fcport->disc_state,
  1378. fcport->fw_login_state, fcport->loop_id, fcport->login_retry);
  1379. if (qla_tgt_mode_enabled(vha))
  1380. return;
  1381. if (qla_dual_mode_enabled(vha)) {
  1382. if (N2N_TOPO(vha->hw)) {
  1383. u64 mywwn, wwn;
  1384. mywwn = wwn_to_u64(vha->port_name);
  1385. wwn = wwn_to_u64(fcport->port_name);
  1386. if (mywwn > wwn)
  1387. login = 1;
  1388. else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
  1389. && time_after_eq(jiffies,
  1390. fcport->plogi_nack_done_deadline))
  1391. login = 1;
  1392. } else {
  1393. login = 1;
  1394. }
  1395. } else {
  1396. /* initiator mode */
  1397. login = 1;
  1398. }
  1399. if (login && fcport->login_retry) {
  1400. fcport->login_retry--;
  1401. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1402. fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
  1403. rc = qla2x00_find_new_loop_id(vha, fcport);
  1404. if (rc) {
  1405. ql_dbg(ql_dbg_disc, vha, 0x20e6,
  1406. "%s %d %8phC post del sess - out of loopid\n",
  1407. __func__, __LINE__, fcport->port_name);
  1408. fcport->scan_state = 0;
  1409. qlt_schedule_sess_for_deletion(fcport);
  1410. return;
  1411. }
  1412. }
  1413. ql_dbg(ql_dbg_disc, vha, 0x20bf,
  1414. "%s %d %8phC post login\n",
  1415. __func__, __LINE__, fcport->port_name);
  1416. qla2x00_post_async_login_work(vha, fcport, NULL);
  1417. }
  1418. }
  1419. int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
  1420. {
  1421. u16 data[2];
  1422. u16 sec;
  1423. ql_dbg(ql_dbg_disc, vha, 0x20d8,
  1424. "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d fc4type %x\n",
  1425. __func__, fcport->port_name, fcport->disc_state,
  1426. fcport->fw_login_state, fcport->login_pause, fcport->flags,
  1427. fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
  1428. fcport->login_gen, fcport->loop_id, fcport->scan_state,
  1429. fcport->fc4_type);
  1430. if (fcport->scan_state != QLA_FCPORT_FOUND ||
  1431. fcport->disc_state == DSC_DELETE_PEND)
  1432. return 0;
  1433. if ((fcport->loop_id != FC_NO_LOOP_ID) &&
  1434. qla_dual_mode_enabled(vha) &&
  1435. ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
  1436. (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
  1437. return 0;
  1438. if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
  1439. !N2N_TOPO(vha->hw)) {
  1440. if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
  1441. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1442. return 0;
  1443. }
  1444. }
  1445. /* Target won't initiate port login if fabric is present */
  1446. if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
  1447. return 0;
  1448. if (fcport->flags & (FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE)) {
  1449. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1450. return 0;
  1451. }
  1452. switch (fcport->disc_state) {
  1453. case DSC_DELETED:
  1454. switch (vha->hw->current_topology) {
  1455. case ISP_CFG_N:
  1456. if (fcport_is_smaller(fcport)) {
  1457. /* this adapter is bigger */
  1458. if (fcport->login_retry) {
  1459. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1460. qla2x00_find_new_loop_id(vha,
  1461. fcport);
  1462. fcport->fw_login_state =
  1463. DSC_LS_PORT_UNAVAIL;
  1464. }
  1465. fcport->login_retry--;
  1466. qla_post_els_plogi_work(vha, fcport);
  1467. } else {
  1468. ql_log(ql_log_info, vha, 0x705d,
  1469. "Unable to reach remote port %8phC",
  1470. fcport->port_name);
  1471. }
  1472. } else {
  1473. qla24xx_post_gnl_work(vha, fcport);
  1474. }
  1475. break;
  1476. default:
  1477. if (fcport->loop_id == FC_NO_LOOP_ID) {
  1478. ql_dbg(ql_dbg_disc, vha, 0x20bd,
  1479. "%s %d %8phC post gnl\n",
  1480. __func__, __LINE__, fcport->port_name);
  1481. qla24xx_post_gnl_work(vha, fcport);
  1482. } else {
  1483. qla_chk_n2n_b4_login(vha, fcport);
  1484. }
  1485. break;
  1486. }
  1487. break;
  1488. case DSC_GNL:
  1489. switch (vha->hw->current_topology) {
  1490. case ISP_CFG_N:
  1491. if ((fcport->current_login_state & 0xf) == 0x6) {
  1492. ql_dbg(ql_dbg_disc, vha, 0x2118,
  1493. "%s %d %8phC post GPDB work\n",
  1494. __func__, __LINE__, fcport->port_name);
  1495. fcport->chip_reset =
  1496. vha->hw->base_qpair->chip_reset;
  1497. qla24xx_post_gpdb_work(vha, fcport, 0);
  1498. } else {
  1499. ql_dbg(ql_dbg_disc, vha, 0x2118,
  1500. "%s %d %8phC post %s PRLI\n",
  1501. __func__, __LINE__, fcport->port_name,
  1502. NVME_TARGET(vha->hw, fcport) ? "NVME" :
  1503. "FC");
  1504. qla24xx_post_prli_work(vha, fcport);
  1505. }
  1506. break;
  1507. default:
  1508. if (fcport->login_pause) {
  1509. ql_dbg(ql_dbg_disc, vha, 0x20d8,
  1510. "%s %d %8phC exit\n",
  1511. __func__, __LINE__,
  1512. fcport->port_name);
  1513. fcport->last_rscn_gen = fcport->rscn_gen;
  1514. fcport->last_login_gen = fcport->login_gen;
  1515. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1516. break;
  1517. }
  1518. qla_chk_n2n_b4_login(vha, fcport);
  1519. break;
  1520. }
  1521. break;
  1522. case DSC_LOGIN_FAILED:
  1523. if (N2N_TOPO(vha->hw))
  1524. qla_chk_n2n_b4_login(vha, fcport);
  1525. else
  1526. qlt_schedule_sess_for_deletion(fcport);
  1527. break;
  1528. case DSC_LOGIN_COMPLETE:
  1529. /* recheck login state */
  1530. data[0] = data[1] = 0;
  1531. qla2x00_post_async_adisc_work(vha, fcport, data);
  1532. break;
  1533. case DSC_LOGIN_PEND:
  1534. if (vha->hw->flags.edif_enabled)
  1535. break;
  1536. if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
  1537. ql_dbg(ql_dbg_disc, vha, 0x2118,
  1538. "%s %d %8phC post %s PRLI\n",
  1539. __func__, __LINE__, fcport->port_name,
  1540. NVME_TARGET(vha->hw, fcport) ? "NVME" : "FC");
  1541. qla24xx_post_prli_work(vha, fcport);
  1542. }
  1543. break;
  1544. case DSC_UPD_FCPORT:
  1545. sec = jiffies_to_msecs(jiffies -
  1546. fcport->jiffies_at_registration)/1000;
  1547. if (fcport->sec_since_registration < sec && sec &&
  1548. !(sec % 60)) {
  1549. fcport->sec_since_registration = sec;
  1550. ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
  1551. "%s %8phC - Slow Rport registration(%d Sec)\n",
  1552. __func__, fcport->port_name, sec);
  1553. }
  1554. if (fcport->next_disc_state != DSC_DELETE_PEND)
  1555. fcport->next_disc_state = DSC_ADISC;
  1556. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1557. break;
  1558. default:
  1559. break;
  1560. }
  1561. return 0;
  1562. }
  1563. int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
  1564. u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
  1565. {
  1566. struct qla_work_evt *e;
  1567. e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
  1568. if (!e)
  1569. return QLA_FUNCTION_FAILED;
  1570. e->u.new_sess.id = *id;
  1571. e->u.new_sess.pla = pla;
  1572. e->u.new_sess.fc4_type = fc4_type;
  1573. memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
  1574. if (node_name)
  1575. memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
  1576. return qla2x00_post_work(vha, e);
  1577. }
  1578. static void qla_rscn_gen_tick(scsi_qla_host_t *vha, u32 *ret_rscn_gen)
  1579. {
  1580. *ret_rscn_gen = atomic_inc_return(&vha->rscn_gen);
  1581. /* memory barrier */
  1582. wmb();
  1583. }
  1584. void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
  1585. {
  1586. fc_port_t *fcport;
  1587. unsigned long flags;
  1588. u32 rscn_gen;
  1589. switch (ea->id.b.rsvd_1) {
  1590. case RSCN_PORT_ADDR:
  1591. fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
  1592. if (fcport) {
  1593. if (vha->hw->flags.edif_enabled && DBELL_ACTIVE(vha)) {
  1594. /*
  1595. * On ipsec start by remote port, Target port
  1596. * may use RSCN to trigger initiator to
  1597. * relogin. If driver is already in the
  1598. * process of a relogin, then ignore the RSCN
  1599. * and allow the current relogin to continue.
  1600. * This reduces thrashing of the connection.
  1601. */
  1602. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  1603. /*
  1604. * If state = online, then set scan_needed=1 to do relogin.
  1605. * Otherwise we're already in the middle of a relogin
  1606. */
  1607. fcport->scan_needed = 1;
  1608. qla_rscn_gen_tick(vha, &fcport->rscn_gen);
  1609. }
  1610. } else {
  1611. fcport->scan_needed = 1;
  1612. qla_rscn_gen_tick(vha, &fcport->rscn_gen);
  1613. }
  1614. }
  1615. break;
  1616. case RSCN_AREA_ADDR:
  1617. qla_rscn_gen_tick(vha, &rscn_gen);
  1618. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1619. if (fcport->flags & FCF_FCP2_DEVICE &&
  1620. atomic_read(&fcport->state) == FCS_ONLINE)
  1621. continue;
  1622. if ((ea->id.b24 & 0xffff00) == (fcport->d_id.b24 & 0xffff00)) {
  1623. fcport->scan_needed = 1;
  1624. fcport->rscn_gen = rscn_gen;
  1625. }
  1626. }
  1627. break;
  1628. case RSCN_DOM_ADDR:
  1629. qla_rscn_gen_tick(vha, &rscn_gen);
  1630. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1631. if (fcport->flags & FCF_FCP2_DEVICE &&
  1632. atomic_read(&fcport->state) == FCS_ONLINE)
  1633. continue;
  1634. if ((ea->id.b24 & 0xff0000) == (fcport->d_id.b24 & 0xff0000)) {
  1635. fcport->scan_needed = 1;
  1636. fcport->rscn_gen = rscn_gen;
  1637. }
  1638. }
  1639. break;
  1640. case RSCN_FAB_ADDR:
  1641. default:
  1642. qla_rscn_gen_tick(vha, &rscn_gen);
  1643. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1644. if (fcport->flags & FCF_FCP2_DEVICE &&
  1645. atomic_read(&fcport->state) == FCS_ONLINE)
  1646. continue;
  1647. fcport->scan_needed = 1;
  1648. fcport->rscn_gen = rscn_gen;
  1649. }
  1650. break;
  1651. }
  1652. spin_lock_irqsave(&vha->work_lock, flags);
  1653. if (vha->scan.scan_flags == 0) {
  1654. ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
  1655. vha->scan.scan_flags |= SF_QUEUED;
  1656. vha->scan.rscn_gen_start = atomic_read(&vha->rscn_gen);
  1657. schedule_delayed_work(&vha->scan.scan_work, 5);
  1658. }
  1659. spin_unlock_irqrestore(&vha->work_lock, flags);
  1660. }
  1661. void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
  1662. struct event_arg *ea)
  1663. {
  1664. fc_port_t *fcport = ea->fcport;
  1665. if (test_bit(UNLOADING, &vha->dpc_flags))
  1666. return;
  1667. ql_dbg(ql_dbg_disc, vha, 0x2102,
  1668. "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
  1669. __func__, fcport->port_name, fcport->disc_state,
  1670. fcport->fw_login_state, fcport->login_pause,
  1671. fcport->deleted, fcport->conflict,
  1672. fcport->last_rscn_gen, fcport->rscn_gen,
  1673. fcport->last_login_gen, fcport->login_gen,
  1674. fcport->flags);
  1675. if (fcport->last_rscn_gen != fcport->rscn_gen) {
  1676. ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
  1677. __func__, __LINE__, fcport->port_name);
  1678. qla24xx_post_gnl_work(vha, fcport);
  1679. return;
  1680. }
  1681. qla24xx_fcport_handle_login(vha, fcport);
  1682. }
  1683. void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
  1684. struct event_arg *ea)
  1685. {
  1686. if (N2N_TOPO(vha->hw) && fcport_is_smaller(ea->fcport) &&
  1687. vha->hw->flags.edif_enabled) {
  1688. /* check to see if App support Secure */
  1689. qla24xx_post_gpdb_work(vha, ea->fcport, 0);
  1690. return;
  1691. }
  1692. /* for pure Target Mode, PRLI will not be initiated */
  1693. if (vha->host->active_mode == MODE_TARGET)
  1694. return;
  1695. ql_dbg(ql_dbg_disc, vha, 0x2118,
  1696. "%s %d %8phC post PRLI\n",
  1697. __func__, __LINE__, ea->fcport->port_name);
  1698. qla24xx_post_prli_work(vha, ea->fcport);
  1699. }
  1700. /*
  1701. * RSCN(s) came in for this fcport, but the RSCN(s) was not able
  1702. * to be consumed by the fcport
  1703. */
  1704. void qla_rscn_replay(fc_port_t *fcport)
  1705. {
  1706. struct event_arg ea;
  1707. switch (fcport->disc_state) {
  1708. case DSC_DELETE_PEND:
  1709. return;
  1710. default:
  1711. break;
  1712. }
  1713. if (fcport->scan_needed) {
  1714. memset(&ea, 0, sizeof(ea));
  1715. ea.id = fcport->d_id;
  1716. ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
  1717. qla2x00_handle_rscn(fcport->vha, &ea);
  1718. }
  1719. }
  1720. static void
  1721. qla2x00_tmf_iocb_timeout(void *data)
  1722. {
  1723. srb_t *sp = data;
  1724. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  1725. int rc, h;
  1726. unsigned long flags;
  1727. if (sp->type == SRB_MARKER)
  1728. rc = QLA_FUNCTION_FAILED;
  1729. else
  1730. rc = qla24xx_async_abort_cmd(sp, false);
  1731. if (rc) {
  1732. spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
  1733. for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
  1734. if (sp->qpair->req->outstanding_cmds[h] == sp) {
  1735. sp->qpair->req->outstanding_cmds[h] = NULL;
  1736. qla_put_fw_resources(sp->qpair, &sp->iores);
  1737. break;
  1738. }
  1739. }
  1740. spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
  1741. tmf->u.tmf.comp_status = cpu_to_le16(CS_TIMEOUT);
  1742. tmf->u.tmf.data = QLA_FUNCTION_FAILED;
  1743. complete(&tmf->u.tmf.comp);
  1744. }
  1745. }
  1746. static void qla_marker_sp_done(srb_t *sp, int res)
  1747. {
  1748. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  1749. if (res != QLA_SUCCESS)
  1750. ql_dbg(ql_dbg_taskm, sp->vha, 0x8004,
  1751. "Async-marker fail hdl=%x portid=%06x ctrl=%x lun=%lld qp=%d.\n",
  1752. sp->handle, sp->fcport->d_id.b24, sp->u.iocb_cmd.u.tmf.flags,
  1753. sp->u.iocb_cmd.u.tmf.lun, sp->qpair->id);
  1754. sp->u.iocb_cmd.u.tmf.data = res;
  1755. complete(&tmf->u.tmf.comp);
  1756. }
  1757. #define START_SP_W_RETRIES(_sp, _rval, _chip_gen, _login_gen) \
  1758. {\
  1759. int cnt = 5; \
  1760. do { \
  1761. if (_chip_gen != sp->vha->hw->chip_reset || _login_gen != sp->fcport->login_gen) {\
  1762. _rval = -EINVAL; \
  1763. break; \
  1764. } \
  1765. _rval = qla2x00_start_sp(_sp); \
  1766. if (_rval == -EAGAIN) \
  1767. msleep(1); \
  1768. else \
  1769. break; \
  1770. cnt--; \
  1771. } while (cnt); \
  1772. }
  1773. /**
  1774. * qla26xx_marker: send marker IOCB and wait for the completion of it.
  1775. * @arg: pointer to argument list.
  1776. * It is assume caller will provide an fcport pointer and modifier
  1777. */
  1778. static int
  1779. qla26xx_marker(struct tmf_arg *arg)
  1780. {
  1781. struct scsi_qla_host *vha = arg->vha;
  1782. struct srb_iocb *tm_iocb;
  1783. srb_t *sp;
  1784. int rval = QLA_FUNCTION_FAILED;
  1785. fc_port_t *fcport = arg->fcport;
  1786. u32 chip_gen, login_gen;
  1787. if (TMF_NOT_READY(arg->fcport)) {
  1788. ql_dbg(ql_dbg_taskm, vha, 0x8039,
  1789. "FC port not ready for marker loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
  1790. fcport->loop_id, fcport->d_id.b24,
  1791. arg->modifier, arg->lun, arg->qpair->id);
  1792. return QLA_SUSPENDED;
  1793. }
  1794. chip_gen = vha->hw->chip_reset;
  1795. login_gen = fcport->login_gen;
  1796. /* ref: INIT */
  1797. sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
  1798. if (!sp)
  1799. goto done;
  1800. sp->type = SRB_MARKER;
  1801. sp->name = "marker";
  1802. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha), qla_marker_sp_done);
  1803. sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
  1804. tm_iocb = &sp->u.iocb_cmd;
  1805. init_completion(&tm_iocb->u.tmf.comp);
  1806. tm_iocb->u.tmf.modifier = arg->modifier;
  1807. tm_iocb->u.tmf.lun = arg->lun;
  1808. tm_iocb->u.tmf.loop_id = fcport->loop_id;
  1809. tm_iocb->u.tmf.vp_index = vha->vp_idx;
  1810. START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
  1811. ql_dbg(ql_dbg_taskm, vha, 0x8006,
  1812. "Async-marker hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
  1813. sp->handle, fcport->loop_id, fcport->d_id.b24,
  1814. arg->modifier, arg->lun, sp->qpair->id, rval);
  1815. if (rval != QLA_SUCCESS) {
  1816. ql_log(ql_log_warn, vha, 0x8031,
  1817. "Marker IOCB send failure (%x).\n", rval);
  1818. goto done_free_sp;
  1819. }
  1820. wait_for_completion(&tm_iocb->u.tmf.comp);
  1821. rval = tm_iocb->u.tmf.data;
  1822. if (rval != QLA_SUCCESS) {
  1823. ql_log(ql_log_warn, vha, 0x8019,
  1824. "Marker failed hdl=%x loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d rval %d.\n",
  1825. sp->handle, fcport->loop_id, fcport->d_id.b24,
  1826. arg->modifier, arg->lun, sp->qpair->id, rval);
  1827. }
  1828. done_free_sp:
  1829. /* ref: INIT */
  1830. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1831. done:
  1832. return rval;
  1833. }
  1834. static void qla2x00_tmf_sp_done(srb_t *sp, int res)
  1835. {
  1836. struct srb_iocb *tmf = &sp->u.iocb_cmd;
  1837. if (res)
  1838. tmf->u.tmf.data = res;
  1839. complete(&tmf->u.tmf.comp);
  1840. }
  1841. static int qla_tmf_wait(struct tmf_arg *arg)
  1842. {
  1843. /* there are only 2 types of error handling that reaches here, lun or target reset */
  1844. if (arg->flags & (TCF_LUN_RESET | TCF_ABORT_TASK_SET | TCF_CLEAR_TASK_SET))
  1845. return qla2x00_eh_wait_for_pending_commands(arg->vha,
  1846. arg->fcport->d_id.b24, arg->lun, WAIT_LUN);
  1847. else
  1848. return qla2x00_eh_wait_for_pending_commands(arg->vha,
  1849. arg->fcport->d_id.b24, arg->lun, WAIT_TARGET);
  1850. }
  1851. static int
  1852. __qla2x00_async_tm_cmd(struct tmf_arg *arg)
  1853. {
  1854. struct scsi_qla_host *vha = arg->vha;
  1855. struct srb_iocb *tm_iocb;
  1856. srb_t *sp;
  1857. int rval = QLA_FUNCTION_FAILED;
  1858. fc_port_t *fcport = arg->fcport;
  1859. u32 chip_gen, login_gen;
  1860. u64 jif;
  1861. if (TMF_NOT_READY(arg->fcport)) {
  1862. ql_dbg(ql_dbg_taskm, vha, 0x8032,
  1863. "FC port not ready for TM command loop-id=%x portid=%06x modifier=%x lun=%lld qp=%d.\n",
  1864. fcport->loop_id, fcport->d_id.b24,
  1865. arg->modifier, arg->lun, arg->qpair->id);
  1866. return QLA_SUSPENDED;
  1867. }
  1868. chip_gen = vha->hw->chip_reset;
  1869. login_gen = fcport->login_gen;
  1870. /* ref: INIT */
  1871. sp = qla2xxx_get_qpair_sp(vha, arg->qpair, fcport, GFP_KERNEL);
  1872. if (!sp)
  1873. goto done;
  1874. qla_vha_mark_busy(vha);
  1875. sp->type = SRB_TM_CMD;
  1876. sp->name = "tmf";
  1877. qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
  1878. qla2x00_tmf_sp_done);
  1879. sp->u.iocb_cmd.timeout = qla2x00_tmf_iocb_timeout;
  1880. tm_iocb = &sp->u.iocb_cmd;
  1881. init_completion(&tm_iocb->u.tmf.comp);
  1882. tm_iocb->u.tmf.flags = arg->flags;
  1883. tm_iocb->u.tmf.lun = arg->lun;
  1884. START_SP_W_RETRIES(sp, rval, chip_gen, login_gen);
  1885. ql_dbg(ql_dbg_taskm, vha, 0x802f,
  1886. "Async-tmf hdl=%x loop-id=%x portid=%06x ctrl=%x lun=%lld qp=%d rval=%x.\n",
  1887. sp->handle, fcport->loop_id, fcport->d_id.b24,
  1888. arg->flags, arg->lun, sp->qpair->id, rval);
  1889. if (rval != QLA_SUCCESS)
  1890. goto done_free_sp;
  1891. wait_for_completion(&tm_iocb->u.tmf.comp);
  1892. rval = tm_iocb->u.tmf.data;
  1893. if (rval != QLA_SUCCESS) {
  1894. ql_log(ql_log_warn, vha, 0x8030,
  1895. "TM IOCB failed (%x).\n", rval);
  1896. }
  1897. if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
  1898. jif = jiffies;
  1899. if (qla_tmf_wait(arg)) {
  1900. ql_log(ql_log_info, vha, 0x803e,
  1901. "Waited %u ms Nexus=%ld:%06x:%llu.\n",
  1902. jiffies_to_msecs(jiffies - jif), vha->host_no,
  1903. fcport->d_id.b24, arg->lun);
  1904. }
  1905. if (chip_gen == vha->hw->chip_reset && login_gen == fcport->login_gen) {
  1906. rval = qla26xx_marker(arg);
  1907. } else {
  1908. ql_log(ql_log_info, vha, 0x803e,
  1909. "Skip Marker due to disruption. Nexus=%ld:%06x:%llu.\n",
  1910. vha->host_no, fcport->d_id.b24, arg->lun);
  1911. rval = QLA_FUNCTION_FAILED;
  1912. }
  1913. }
  1914. if (tm_iocb->u.tmf.data)
  1915. rval = tm_iocb->u.tmf.data;
  1916. done_free_sp:
  1917. /* ref: INIT */
  1918. kref_put(&sp->cmd_kref, qla2x00_sp_release);
  1919. done:
  1920. return rval;
  1921. }
  1922. static void qla_put_tmf(struct tmf_arg *arg)
  1923. {
  1924. struct scsi_qla_host *vha = arg->vha;
  1925. struct qla_hw_data *ha = vha->hw;
  1926. unsigned long flags;
  1927. spin_lock_irqsave(&ha->tgt.sess_lock, flags);
  1928. ha->active_tmf--;
  1929. list_del(&arg->tmf_elem);
  1930. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  1931. }
  1932. static
  1933. int qla_get_tmf(struct tmf_arg *arg)
  1934. {
  1935. struct scsi_qla_host *vha = arg->vha;
  1936. struct qla_hw_data *ha = vha->hw;
  1937. unsigned long flags;
  1938. fc_port_t *fcport = arg->fcport;
  1939. int rc = 0;
  1940. struct tmf_arg *t;
  1941. spin_lock_irqsave(&ha->tgt.sess_lock, flags);
  1942. list_for_each_entry(t, &ha->tmf_active, tmf_elem) {
  1943. if (t->fcport == arg->fcport && t->lun == arg->lun) {
  1944. /* reject duplicate TMF */
  1945. ql_log(ql_log_warn, vha, 0x802c,
  1946. "found duplicate TMF. Nexus=%ld:%06x:%llu.\n",
  1947. vha->host_no, fcport->d_id.b24, arg->lun);
  1948. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  1949. return -EINVAL;
  1950. }
  1951. }
  1952. list_add_tail(&arg->tmf_elem, &ha->tmf_pending);
  1953. while (ha->active_tmf >= MAX_ACTIVE_TMF) {
  1954. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  1955. msleep(1);
  1956. spin_lock_irqsave(&ha->tgt.sess_lock, flags);
  1957. if (TMF_NOT_READY(fcport)) {
  1958. ql_log(ql_log_warn, vha, 0x802c,
  1959. "Unable to acquire TM resource due to disruption.\n");
  1960. rc = EIO;
  1961. break;
  1962. }
  1963. if (ha->active_tmf < MAX_ACTIVE_TMF &&
  1964. list_is_first(&arg->tmf_elem, &ha->tmf_pending))
  1965. break;
  1966. }
  1967. list_del(&arg->tmf_elem);
  1968. if (!rc) {
  1969. ha->active_tmf++;
  1970. list_add_tail(&arg->tmf_elem, &ha->tmf_active);
  1971. }
  1972. spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
  1973. return rc;
  1974. }
  1975. int
  1976. qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint64_t lun,
  1977. uint32_t tag)
  1978. {
  1979. struct scsi_qla_host *vha = fcport->vha;
  1980. struct tmf_arg a;
  1981. int rval = QLA_SUCCESS;
  1982. if (TMF_NOT_READY(fcport))
  1983. return QLA_SUSPENDED;
  1984. a.vha = fcport->vha;
  1985. a.fcport = fcport;
  1986. a.lun = lun;
  1987. a.flags = flags;
  1988. INIT_LIST_HEAD(&a.tmf_elem);
  1989. if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) {
  1990. a.modifier = MK_SYNC_ID_LUN;
  1991. } else {
  1992. a.modifier = MK_SYNC_ID;
  1993. }
  1994. if (qla_get_tmf(&a))
  1995. return QLA_FUNCTION_FAILED;
  1996. a.qpair = vha->hw->base_qpair;
  1997. rval = __qla2x00_async_tm_cmd(&a);
  1998. qla_put_tmf(&a);
  1999. return rval;
  2000. }
  2001. int
  2002. qla24xx_async_abort_command(srb_t *sp)
  2003. {
  2004. unsigned long flags = 0;
  2005. uint32_t handle;
  2006. fc_port_t *fcport = sp->fcport;
  2007. struct qla_qpair *qpair = sp->qpair;
  2008. struct scsi_qla_host *vha = fcport->vha;
  2009. struct req_que *req = qpair->req;
  2010. spin_lock_irqsave(qpair->qp_lock_ptr, flags);
  2011. for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
  2012. if (req->outstanding_cmds[handle] == sp)
  2013. break;
  2014. }
  2015. spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
  2016. if (handle == req->num_outstanding_cmds) {
  2017. /* Command not found. */
  2018. return QLA_ERR_NOT_FOUND;
  2019. }
  2020. if (sp->type == SRB_FXIOCB_DCMD)
  2021. return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
  2022. FXDISC_ABORT_IOCTL);
  2023. return qla24xx_async_abort_cmd(sp, true);
  2024. }
  2025. static void
  2026. qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
  2027. {
  2028. struct srb *sp;
  2029. WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
  2030. ea->data[0]);
  2031. switch (ea->data[0]) {
  2032. case MBS_COMMAND_COMPLETE:
  2033. ql_dbg(ql_dbg_disc, vha, 0x2118,
  2034. "%s %d %8phC post gpdb\n",
  2035. __func__, __LINE__, ea->fcport->port_name);
  2036. ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
  2037. ea->fcport->logout_on_delete = 1;
  2038. ea->fcport->nvme_prli_service_param = ea->iop[0];
  2039. if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
  2040. ea->fcport->nvme_first_burst_size =
  2041. (ea->iop[1] & 0xffff) * 512;
  2042. else
  2043. ea->fcport->nvme_first_burst_size = 0;
  2044. qla24xx_post_gpdb_work(vha, ea->fcport, 0);
  2045. break;
  2046. default:
  2047. sp = ea->sp;
  2048. ql_dbg(ql_dbg_disc, vha, 0x2118,
  2049. "%s %d %8phC priority %s, fc4type %x prev try %s\n",
  2050. __func__, __LINE__, ea->fcport->port_name,
  2051. vha->hw->fc4_type_priority == FC4_PRIORITY_FCP ?
  2052. "FCP" : "NVMe", ea->fcport->fc4_type,
  2053. (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI) ?
  2054. "NVME" : "FCP");
  2055. if (NVME_FCP_TARGET(ea->fcport)) {
  2056. if (sp->u.iocb_cmd.u.logio.flags & SRB_LOGIN_NVME_PRLI)
  2057. ea->fcport->do_prli_nvme = 0;
  2058. else
  2059. ea->fcport->do_prli_nvme = 1;
  2060. } else {
  2061. ea->fcport->do_prli_nvme = 0;
  2062. }
  2063. if (N2N_TOPO(vha->hw)) {
  2064. if (ea->fcport->n2n_link_reset_cnt ==
  2065. vha->hw->login_retry_count &&
  2066. ea->fcport->flags & FCF_FCSP_DEVICE) {
  2067. /* remote authentication app just started */
  2068. ea->fcport->n2n_link_reset_cnt = 0;
  2069. }
  2070. if (ea->fcport->n2n_link_reset_cnt <
  2071. vha->hw->login_retry_count) {
  2072. ea->fcport->n2n_link_reset_cnt++;
  2073. vha->relogin_jif = jiffies + 2 * HZ;
  2074. /*
  2075. * PRLI failed. Reset link to kick start
  2076. * state machine
  2077. */
  2078. set_bit(N2N_LINK_RESET, &vha->dpc_flags);
  2079. qla2xxx_wake_dpc(vha);
  2080. } else {
  2081. ql_log(ql_log_warn, vha, 0x2119,
  2082. "%s %d %8phC Unable to reconnect\n",
  2083. __func__, __LINE__,
  2084. ea->fcport->port_name);
  2085. }
  2086. } else {
  2087. /*
  2088. * switch connect. login failed. Take connection down
  2089. * and allow relogin to retrigger
  2090. */
  2091. ea->fcport->flags &= ~FCF_ASYNC_SENT;
  2092. ea->fcport->keep_nport_handle = 0;
  2093. ea->fcport->logout_on_delete = 1;
  2094. qlt_schedule_sess_for_deletion(ea->fcport);
  2095. }
  2096. break;
  2097. }
  2098. }
  2099. void
  2100. qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
  2101. {
  2102. port_id_t cid; /* conflict Nport id */
  2103. u16 lid;
  2104. struct fc_port *conflict_fcport;
  2105. unsigned long flags;
  2106. struct fc_port *fcport = ea->fcport;
  2107. ql_dbg(ql_dbg_disc, vha, 0xffff,
  2108. "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
  2109. __func__, fcport->port_name, fcport->disc_state,
  2110. fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
  2111. ea->sp->gen1, fcport->rscn_gen,
  2112. ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
  2113. if (fcport->fw_login_state == DSC_LS_PLOGI_PEND) {
  2114. ql_dbg(ql_dbg_disc, vha, 0x20ea,
  2115. "%s %d %8phC Remote is trying to login\n",
  2116. __func__, __LINE__, fcport->port_name);
  2117. /*
  2118. * If we get here, there is port thats already logged in,
  2119. * but it's state has not moved ahead. Recheck with FW on
  2120. * what state it is in and proceed ahead
  2121. */
  2122. if (!N2N_TOPO(vha->hw)) {
  2123. fcport->fw_login_state = DSC_LS_PRLI_COMP;
  2124. qla24xx_post_gpdb_work(vha, fcport, 0);
  2125. }
  2126. return;
  2127. }
  2128. if (fcport->fw_login_state == DSC_LS_PRLI_PEND) {
  2129. ql_dbg(ql_dbg_disc, vha, 0x20ea,
  2130. "%s %d %8phC Remote is trying to login\n",
  2131. __func__, __LINE__, fcport->port_name);
  2132. return;
  2133. }
  2134. if ((fcport->disc_state == DSC_DELETE_PEND) ||
  2135. (fcport->disc_state == DSC_DELETED)) {
  2136. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2137. return;
  2138. }
  2139. if (ea->sp->gen2 != fcport->login_gen) {
  2140. /* target side must have changed it. */
  2141. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  2142. "%s %8phC generation changed\n",
  2143. __func__, fcport->port_name);
  2144. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2145. return;
  2146. } else if (ea->sp->gen1 != fcport->rscn_gen) {
  2147. ql_dbg(ql_dbg_disc, vha, 0x20d3,
  2148. "%s %8phC RSCN generation changed\n",
  2149. __func__, fcport->port_name);
  2150. qla_rscn_replay(fcport);
  2151. qlt_schedule_sess_for_deletion(fcport);
  2152. return;
  2153. }
  2154. WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
  2155. ea->data[0]);
  2156. switch (ea->data[0]) {
  2157. case MBS_COMMAND_COMPLETE:
  2158. /*
  2159. * Driver must validate login state - If PRLI not complete,
  2160. * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
  2161. * requests.
  2162. */
  2163. if (vha->hw->flags.edif_enabled) {
  2164. set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
  2165. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  2166. ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
  2167. ea->fcport->logout_on_delete = 1;
  2168. ea->fcport->send_els_logo = 0;
  2169. ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
  2170. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  2171. qla24xx_post_gpdb_work(vha, ea->fcport, 0);
  2172. } else {
  2173. if (NVME_TARGET(vha->hw, fcport)) {
  2174. ql_dbg(ql_dbg_disc, vha, 0x2117,
  2175. "%s %d %8phC post prli\n",
  2176. __func__, __LINE__, fcport->port_name);
  2177. qla24xx_post_prli_work(vha, fcport);
  2178. } else {
  2179. ql_dbg(ql_dbg_disc, vha, 0x20ea,
  2180. "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
  2181. __func__, __LINE__, fcport->port_name,
  2182. fcport->loop_id, fcport->d_id.b24);
  2183. set_bit(fcport->loop_id, vha->hw->loop_id_map);
  2184. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  2185. fcport->chip_reset = vha->hw->base_qpair->chip_reset;
  2186. fcport->logout_on_delete = 1;
  2187. fcport->send_els_logo = 0;
  2188. fcport->fw_login_state = DSC_LS_PRLI_COMP;
  2189. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  2190. qla24xx_post_gpdb_work(vha, fcport, 0);
  2191. }
  2192. }
  2193. break;
  2194. case MBS_COMMAND_ERROR:
  2195. ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
  2196. __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
  2197. qlt_schedule_sess_for_deletion(ea->fcport);
  2198. break;
  2199. case MBS_LOOP_ID_USED:
  2200. /* data[1] = IO PARAM 1 = nport ID */
  2201. cid.b.domain = (ea->iop[1] >> 16) & 0xff;
  2202. cid.b.area = (ea->iop[1] >> 8) & 0xff;
  2203. cid.b.al_pa = ea->iop[1] & 0xff;
  2204. cid.b.rsvd_1 = 0;
  2205. ql_dbg(ql_dbg_disc, vha, 0x20ec,
  2206. "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
  2207. __func__, __LINE__, ea->fcport->port_name,
  2208. ea->fcport->loop_id, cid.b24);
  2209. set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
  2210. ea->fcport->loop_id = FC_NO_LOOP_ID;
  2211. qla24xx_post_gnl_work(vha, ea->fcport);
  2212. break;
  2213. case MBS_PORT_ID_USED:
  2214. lid = ea->iop[1] & 0xffff;
  2215. qlt_find_sess_invalidate_other(vha,
  2216. wwn_to_u64(ea->fcport->port_name),
  2217. ea->fcport->d_id, lid, &conflict_fcport);
  2218. if (conflict_fcport) {
  2219. /*
  2220. * Another fcport share the same loop_id/nport id.
  2221. * Conflict fcport needs to finish cleanup before this
  2222. * fcport can proceed to login.
  2223. */
  2224. conflict_fcport->conflict = ea->fcport;
  2225. ea->fcport->login_pause = 1;
  2226. ql_dbg(ql_dbg_disc, vha, 0x20ed,
  2227. "%s %d %8phC NPortId %06x inuse with loopid 0x%x.\n",
  2228. __func__, __LINE__, ea->fcport->port_name,
  2229. ea->fcport->d_id.b24, lid);
  2230. } else {
  2231. ql_dbg(ql_dbg_disc, vha, 0x20ed,
  2232. "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
  2233. __func__, __LINE__, ea->fcport->port_name,
  2234. ea->fcport->d_id.b24, lid);
  2235. qla2x00_clear_loop_id(ea->fcport);
  2236. set_bit(lid, vha->hw->loop_id_map);
  2237. ea->fcport->loop_id = lid;
  2238. ea->fcport->keep_nport_handle = 0;
  2239. ea->fcport->logout_on_delete = 1;
  2240. qlt_schedule_sess_for_deletion(ea->fcport);
  2241. }
  2242. break;
  2243. }
  2244. return;
  2245. }
  2246. /****************************************************************************/
  2247. /* QLogic ISP2x00 Hardware Support Functions. */
  2248. /****************************************************************************/
  2249. static int
  2250. qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
  2251. {
  2252. int rval = QLA_SUCCESS;
  2253. struct qla_hw_data *ha = vha->hw;
  2254. uint32_t idc_major_ver, idc_minor_ver;
  2255. uint16_t config[4];
  2256. qla83xx_idc_lock(vha, 0);
  2257. /* SV: TODO: Assign initialization timeout from
  2258. * flash-info / other param
  2259. */
  2260. ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
  2261. ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
  2262. /* Set our fcoe function presence */
  2263. if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
  2264. ql_dbg(ql_dbg_p3p, vha, 0xb077,
  2265. "Error while setting DRV-Presence.\n");
  2266. rval = QLA_FUNCTION_FAILED;
  2267. goto exit;
  2268. }
  2269. /* Decide the reset ownership */
  2270. qla83xx_reset_ownership(vha);
  2271. /*
  2272. * On first protocol driver load:
  2273. * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
  2274. * register.
  2275. * Others: Check compatibility with current IDC Major version.
  2276. */
  2277. qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
  2278. if (ha->flags.nic_core_reset_owner) {
  2279. /* Set IDC Major version */
  2280. idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
  2281. qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
  2282. /* Clearing IDC-Lock-Recovery register */
  2283. qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
  2284. } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
  2285. /*
  2286. * Clear further IDC participation if we are not compatible with
  2287. * the current IDC Major Version.
  2288. */
  2289. ql_log(ql_log_warn, vha, 0xb07d,
  2290. "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
  2291. idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
  2292. __qla83xx_clear_drv_presence(vha);
  2293. rval = QLA_FUNCTION_FAILED;
  2294. goto exit;
  2295. }
  2296. /* Each function sets its supported Minor version. */
  2297. qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
  2298. idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
  2299. qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
  2300. if (ha->flags.nic_core_reset_owner) {
  2301. memset(config, 0, sizeof(config));
  2302. if (!qla81xx_get_port_config(vha, config))
  2303. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  2304. QLA8XXX_DEV_READY);
  2305. }
  2306. rval = qla83xx_idc_state_handler(vha);
  2307. exit:
  2308. qla83xx_idc_unlock(vha, 0);
  2309. return rval;
  2310. }
  2311. void qla_enable_fce_trace(scsi_qla_host_t *vha)
  2312. {
  2313. int rval;
  2314. struct qla_hw_data *ha = vha->hw;
  2315. if (ha->fce) {
  2316. ha->flags.fce_enabled = 1;
  2317. memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
  2318. rval = qla2x00_enable_fce_trace(vha,
  2319. ha->fce_dma, ha->fce_bufs, ha->fce_mb, &ha->fce_bufs);
  2320. if (rval) {
  2321. ql_log(ql_log_warn, vha, 0x8033,
  2322. "Unable to reinitialize FCE (%d).\n", rval);
  2323. ha->flags.fce_enabled = 0;
  2324. }
  2325. }
  2326. }
  2327. static void qla_enable_eft_trace(scsi_qla_host_t *vha)
  2328. {
  2329. int rval;
  2330. struct qla_hw_data *ha = vha->hw;
  2331. if (ha->eft) {
  2332. memset(ha->eft, 0, EFT_SIZE);
  2333. rval = qla2x00_enable_eft_trace(vha, ha->eft_dma, EFT_NUM_BUFFERS);
  2334. if (rval) {
  2335. ql_log(ql_log_warn, vha, 0x8034,
  2336. "Unable to reinitialize EFT (%d).\n", rval);
  2337. }
  2338. }
  2339. }
  2340. /*
  2341. * qla2x00_initialize_adapter
  2342. * Initialize board.
  2343. *
  2344. * Input:
  2345. * ha = adapter block pointer.
  2346. *
  2347. * Returns:
  2348. * 0 = success
  2349. */
  2350. int
  2351. qla2x00_initialize_adapter(scsi_qla_host_t *vha)
  2352. {
  2353. int rval;
  2354. struct qla_hw_data *ha = vha->hw;
  2355. struct req_que *req = ha->req_q_map[0];
  2356. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  2357. memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
  2358. memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
  2359. /* Clear adapter flags. */
  2360. vha->flags.online = 0;
  2361. ha->flags.chip_reset_done = 0;
  2362. vha->flags.reset_active = 0;
  2363. ha->flags.pci_channel_io_perm_failure = 0;
  2364. ha->flags.eeh_busy = 0;
  2365. vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
  2366. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  2367. atomic_set(&vha->loop_state, LOOP_DOWN);
  2368. vha->device_flags = DFLG_NO_CABLE;
  2369. vha->dpc_flags = 0;
  2370. vha->flags.management_server_logged_in = 0;
  2371. vha->marker_needed = 0;
  2372. ha->isp_abort_cnt = 0;
  2373. ha->beacon_blink_led = 0;
  2374. set_bit(0, ha->req_qid_map);
  2375. set_bit(0, ha->rsp_qid_map);
  2376. ql_dbg(ql_dbg_init, vha, 0x0040,
  2377. "Configuring PCI space...\n");
  2378. rval = ha->isp_ops->pci_config(vha);
  2379. if (rval) {
  2380. ql_log(ql_log_warn, vha, 0x0044,
  2381. "Unable to configure PCI space.\n");
  2382. return (rval);
  2383. }
  2384. ha->isp_ops->reset_chip(vha);
  2385. /* Check for secure flash support */
  2386. if (IS_QLA28XX(ha)) {
  2387. if (rd_reg_word(&reg->mailbox12) & BIT_0)
  2388. ha->flags.secure_adapter = 1;
  2389. ql_log(ql_log_info, vha, 0xffff, "Secure Adapter: %s\n",
  2390. (ha->flags.secure_adapter) ? "Yes" : "No");
  2391. }
  2392. rval = qla2xxx_get_flash_info(vha);
  2393. if (rval) {
  2394. ql_log(ql_log_fatal, vha, 0x004f,
  2395. "Unable to validate FLASH data.\n");
  2396. return rval;
  2397. }
  2398. if (IS_QLA8044(ha)) {
  2399. qla8044_read_reset_template(vha);
  2400. /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
  2401. * If DONRESET_BIT0 is set, drivers should not set dev_state
  2402. * to NEED_RESET. But if NEED_RESET is set, drivers should
  2403. * should honor the reset. */
  2404. if (ql2xdontresethba == 1)
  2405. qla8044_set_idc_dontreset(vha);
  2406. }
  2407. ha->isp_ops->get_flash_version(vha, req->ring);
  2408. ql_dbg(ql_dbg_init, vha, 0x0061,
  2409. "Configure NVRAM parameters...\n");
  2410. /* Let priority default to FCP, can be overridden by nvram_config */
  2411. ha->fc4_type_priority = FC4_PRIORITY_FCP;
  2412. ha->isp_ops->nvram_config(vha);
  2413. if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
  2414. ha->fc4_type_priority != FC4_PRIORITY_NVME)
  2415. ha->fc4_type_priority = FC4_PRIORITY_FCP;
  2416. ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
  2417. ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
  2418. if (ha->flags.disable_serdes) {
  2419. /* Mask HBA via NVRAM settings? */
  2420. ql_log(ql_log_info, vha, 0x0077,
  2421. "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
  2422. return QLA_FUNCTION_FAILED;
  2423. }
  2424. ql_dbg(ql_dbg_init, vha, 0x0078,
  2425. "Verifying loaded RISC code...\n");
  2426. /* If smartsan enabled then require fdmi and rdp enabled */
  2427. if (ql2xsmartsan) {
  2428. ql2xfdmienable = 1;
  2429. ql2xrdpenable = 1;
  2430. }
  2431. if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
  2432. rval = ha->isp_ops->chip_diag(vha);
  2433. if (rval)
  2434. return (rval);
  2435. rval = qla2x00_setup_chip(vha);
  2436. if (rval)
  2437. return (rval);
  2438. }
  2439. if (IS_QLA84XX(ha)) {
  2440. ha->cs84xx = qla84xx_get_chip(vha);
  2441. if (!ha->cs84xx) {
  2442. ql_log(ql_log_warn, vha, 0x00d0,
  2443. "Unable to configure ISP84XX.\n");
  2444. return QLA_FUNCTION_FAILED;
  2445. }
  2446. }
  2447. if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
  2448. rval = qla2x00_init_rings(vha);
  2449. /* No point in continuing if firmware initialization failed. */
  2450. if (rval != QLA_SUCCESS)
  2451. return rval;
  2452. ha->flags.chip_reset_done = 1;
  2453. if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
  2454. /* Issue verify 84xx FW IOCB to complete 84xx initialization */
  2455. rval = qla84xx_init_chip(vha);
  2456. if (rval != QLA_SUCCESS) {
  2457. ql_log(ql_log_warn, vha, 0x00d4,
  2458. "Unable to initialize ISP84XX.\n");
  2459. qla84xx_put_chip(vha);
  2460. }
  2461. }
  2462. /* Load the NIC Core f/w if we are the first protocol driver. */
  2463. if (IS_QLA8031(ha)) {
  2464. rval = qla83xx_nic_core_fw_load(vha);
  2465. if (rval)
  2466. ql_log(ql_log_warn, vha, 0x0124,
  2467. "Error in initializing NIC Core f/w.\n");
  2468. }
  2469. if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
  2470. qla24xx_read_fcp_prio_cfg(vha);
  2471. if (IS_P3P_TYPE(ha))
  2472. qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
  2473. else
  2474. qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
  2475. return (rval);
  2476. }
  2477. /**
  2478. * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
  2479. * @vha: HA context
  2480. *
  2481. * Returns 0 on success.
  2482. */
  2483. int
  2484. qla2100_pci_config(scsi_qla_host_t *vha)
  2485. {
  2486. uint16_t w;
  2487. unsigned long flags;
  2488. struct qla_hw_data *ha = vha->hw;
  2489. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2490. pci_set_master(ha->pdev);
  2491. pci_try_set_mwi(ha->pdev);
  2492. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  2493. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  2494. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  2495. pci_disable_rom(ha->pdev);
  2496. /* Get PCI bus information. */
  2497. spin_lock_irqsave(&ha->hardware_lock, flags);
  2498. ha->pci_attr = rd_reg_word(&reg->ctrl_status);
  2499. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2500. return QLA_SUCCESS;
  2501. }
  2502. /**
  2503. * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
  2504. * @vha: HA context
  2505. *
  2506. * Returns 0 on success.
  2507. */
  2508. int
  2509. qla2300_pci_config(scsi_qla_host_t *vha)
  2510. {
  2511. uint16_t w;
  2512. unsigned long flags = 0;
  2513. uint32_t cnt;
  2514. struct qla_hw_data *ha = vha->hw;
  2515. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2516. pci_set_master(ha->pdev);
  2517. pci_try_set_mwi(ha->pdev);
  2518. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  2519. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  2520. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  2521. w &= ~PCI_COMMAND_INTX_DISABLE;
  2522. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  2523. /*
  2524. * If this is a 2300 card and not 2312, reset the
  2525. * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
  2526. * the 2310 also reports itself as a 2300 so we need to get the
  2527. * fb revision level -- a 6 indicates it really is a 2300 and
  2528. * not a 2310.
  2529. */
  2530. if (IS_QLA2300(ha)) {
  2531. spin_lock_irqsave(&ha->hardware_lock, flags);
  2532. /* Pause RISC. */
  2533. wrt_reg_word(&reg->hccr, HCCR_PAUSE_RISC);
  2534. for (cnt = 0; cnt < 30000; cnt++) {
  2535. if ((rd_reg_word(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
  2536. break;
  2537. udelay(10);
  2538. }
  2539. /* Select FPM registers. */
  2540. wrt_reg_word(&reg->ctrl_status, 0x20);
  2541. rd_reg_word(&reg->ctrl_status);
  2542. /* Get the fb rev level */
  2543. ha->fb_rev = RD_FB_CMD_REG(ha, reg);
  2544. if (ha->fb_rev == FPM_2300)
  2545. pci_clear_mwi(ha->pdev);
  2546. /* Deselect FPM registers. */
  2547. wrt_reg_word(&reg->ctrl_status, 0x0);
  2548. rd_reg_word(&reg->ctrl_status);
  2549. /* Release RISC module. */
  2550. wrt_reg_word(&reg->hccr, HCCR_RELEASE_RISC);
  2551. for (cnt = 0; cnt < 30000; cnt++) {
  2552. if ((rd_reg_word(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
  2553. break;
  2554. udelay(10);
  2555. }
  2556. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2557. }
  2558. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  2559. pci_disable_rom(ha->pdev);
  2560. /* Get PCI bus information. */
  2561. spin_lock_irqsave(&ha->hardware_lock, flags);
  2562. ha->pci_attr = rd_reg_word(&reg->ctrl_status);
  2563. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2564. return QLA_SUCCESS;
  2565. }
  2566. /**
  2567. * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
  2568. * @vha: HA context
  2569. *
  2570. * Returns 0 on success.
  2571. */
  2572. int
  2573. qla24xx_pci_config(scsi_qla_host_t *vha)
  2574. {
  2575. uint16_t w;
  2576. unsigned long flags = 0;
  2577. struct qla_hw_data *ha = vha->hw;
  2578. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  2579. pci_set_master(ha->pdev);
  2580. pci_try_set_mwi(ha->pdev);
  2581. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  2582. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  2583. w &= ~PCI_COMMAND_INTX_DISABLE;
  2584. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  2585. pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
  2586. /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
  2587. if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
  2588. pcix_set_mmrbc(ha->pdev, 2048);
  2589. /* PCIe -- adjust Maximum Read Request Size (2048). */
  2590. if (pci_is_pcie(ha->pdev))
  2591. pcie_set_readrq(ha->pdev, 4096);
  2592. pci_disable_rom(ha->pdev);
  2593. ha->chip_revision = ha->pdev->revision;
  2594. /* Get PCI bus information. */
  2595. spin_lock_irqsave(&ha->hardware_lock, flags);
  2596. ha->pci_attr = rd_reg_dword(&reg->ctrl_status);
  2597. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2598. return QLA_SUCCESS;
  2599. }
  2600. /**
  2601. * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
  2602. * @vha: HA context
  2603. *
  2604. * Returns 0 on success.
  2605. */
  2606. int
  2607. qla25xx_pci_config(scsi_qla_host_t *vha)
  2608. {
  2609. uint16_t w;
  2610. struct qla_hw_data *ha = vha->hw;
  2611. pci_set_master(ha->pdev);
  2612. pci_try_set_mwi(ha->pdev);
  2613. pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
  2614. w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
  2615. w &= ~PCI_COMMAND_INTX_DISABLE;
  2616. pci_write_config_word(ha->pdev, PCI_COMMAND, w);
  2617. /* PCIe -- adjust Maximum Read Request Size (2048). */
  2618. if (pci_is_pcie(ha->pdev))
  2619. pcie_set_readrq(ha->pdev, 4096);
  2620. pci_disable_rom(ha->pdev);
  2621. ha->chip_revision = ha->pdev->revision;
  2622. return QLA_SUCCESS;
  2623. }
  2624. /**
  2625. * qla2x00_isp_firmware() - Choose firmware image.
  2626. * @vha: HA context
  2627. *
  2628. * Returns 0 on success.
  2629. */
  2630. static int
  2631. qla2x00_isp_firmware(scsi_qla_host_t *vha)
  2632. {
  2633. int rval;
  2634. uint16_t loop_id, topo, sw_cap;
  2635. uint8_t domain, area, al_pa;
  2636. struct qla_hw_data *ha = vha->hw;
  2637. /* Assume loading risc code */
  2638. rval = QLA_FUNCTION_FAILED;
  2639. if (ha->flags.disable_risc_code_load) {
  2640. ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
  2641. /* Verify checksum of loaded RISC code. */
  2642. rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
  2643. if (rval == QLA_SUCCESS) {
  2644. /* And, verify we are not in ROM code. */
  2645. rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
  2646. &area, &domain, &topo, &sw_cap);
  2647. }
  2648. }
  2649. if (rval)
  2650. ql_dbg(ql_dbg_init, vha, 0x007a,
  2651. "**** Load RISC code ****.\n");
  2652. return (rval);
  2653. }
  2654. /**
  2655. * qla2x00_reset_chip() - Reset ISP chip.
  2656. * @vha: HA context
  2657. *
  2658. * Returns 0 on success.
  2659. */
  2660. int
  2661. qla2x00_reset_chip(scsi_qla_host_t *vha)
  2662. {
  2663. unsigned long flags = 0;
  2664. struct qla_hw_data *ha = vha->hw;
  2665. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2666. uint32_t cnt;
  2667. uint16_t cmd;
  2668. int rval = QLA_FUNCTION_FAILED;
  2669. if (unlikely(pci_channel_offline(ha->pdev)))
  2670. return rval;
  2671. ha->isp_ops->disable_intrs(ha);
  2672. spin_lock_irqsave(&ha->hardware_lock, flags);
  2673. /* Turn off master enable */
  2674. cmd = 0;
  2675. pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
  2676. cmd &= ~PCI_COMMAND_MASTER;
  2677. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  2678. if (!IS_QLA2100(ha)) {
  2679. /* Pause RISC. */
  2680. wrt_reg_word(&reg->hccr, HCCR_PAUSE_RISC);
  2681. if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
  2682. for (cnt = 0; cnt < 30000; cnt++) {
  2683. if ((rd_reg_word(&reg->hccr) &
  2684. HCCR_RISC_PAUSE) != 0)
  2685. break;
  2686. udelay(100);
  2687. }
  2688. } else {
  2689. rd_reg_word(&reg->hccr); /* PCI Posting. */
  2690. udelay(10);
  2691. }
  2692. /* Select FPM registers. */
  2693. wrt_reg_word(&reg->ctrl_status, 0x20);
  2694. rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
  2695. /* FPM Soft Reset. */
  2696. wrt_reg_word(&reg->fpm_diag_config, 0x100);
  2697. rd_reg_word(&reg->fpm_diag_config); /* PCI Posting. */
  2698. /* Toggle Fpm Reset. */
  2699. if (!IS_QLA2200(ha)) {
  2700. wrt_reg_word(&reg->fpm_diag_config, 0x0);
  2701. rd_reg_word(&reg->fpm_diag_config); /* PCI Posting. */
  2702. }
  2703. /* Select frame buffer registers. */
  2704. wrt_reg_word(&reg->ctrl_status, 0x10);
  2705. rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
  2706. /* Reset frame buffer FIFOs. */
  2707. if (IS_QLA2200(ha)) {
  2708. WRT_FB_CMD_REG(ha, reg, 0xa000);
  2709. RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
  2710. } else {
  2711. WRT_FB_CMD_REG(ha, reg, 0x00fc);
  2712. /* Read back fb_cmd until zero or 3 seconds max */
  2713. for (cnt = 0; cnt < 3000; cnt++) {
  2714. if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
  2715. break;
  2716. udelay(100);
  2717. }
  2718. }
  2719. /* Select RISC module registers. */
  2720. wrt_reg_word(&reg->ctrl_status, 0);
  2721. rd_reg_word(&reg->ctrl_status); /* PCI Posting. */
  2722. /* Reset RISC processor. */
  2723. wrt_reg_word(&reg->hccr, HCCR_RESET_RISC);
  2724. rd_reg_word(&reg->hccr); /* PCI Posting. */
  2725. /* Release RISC processor. */
  2726. wrt_reg_word(&reg->hccr, HCCR_RELEASE_RISC);
  2727. rd_reg_word(&reg->hccr); /* PCI Posting. */
  2728. }
  2729. wrt_reg_word(&reg->hccr, HCCR_CLR_RISC_INT);
  2730. wrt_reg_word(&reg->hccr, HCCR_CLR_HOST_INT);
  2731. /* Reset ISP chip. */
  2732. wrt_reg_word(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  2733. /* Wait for RISC to recover from reset. */
  2734. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  2735. /*
  2736. * It is necessary to for a delay here since the card doesn't
  2737. * respond to PCI reads during a reset. On some architectures
  2738. * this will result in an MCA.
  2739. */
  2740. udelay(20);
  2741. for (cnt = 30000; cnt; cnt--) {
  2742. if ((rd_reg_word(&reg->ctrl_status) &
  2743. CSR_ISP_SOFT_RESET) == 0)
  2744. break;
  2745. udelay(100);
  2746. }
  2747. } else
  2748. udelay(10);
  2749. /* Reset RISC processor. */
  2750. wrt_reg_word(&reg->hccr, HCCR_RESET_RISC);
  2751. wrt_reg_word(&reg->semaphore, 0);
  2752. /* Release RISC processor. */
  2753. wrt_reg_word(&reg->hccr, HCCR_RELEASE_RISC);
  2754. rd_reg_word(&reg->hccr); /* PCI Posting. */
  2755. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  2756. for (cnt = 0; cnt < 30000; cnt++) {
  2757. if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
  2758. break;
  2759. udelay(100);
  2760. }
  2761. } else
  2762. udelay(100);
  2763. /* Turn on master enable */
  2764. cmd |= PCI_COMMAND_MASTER;
  2765. pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
  2766. /* Disable RISC pause on FPM parity error. */
  2767. if (!IS_QLA2100(ha)) {
  2768. wrt_reg_word(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
  2769. rd_reg_word(&reg->hccr); /* PCI Posting. */
  2770. }
  2771. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2772. return QLA_SUCCESS;
  2773. }
  2774. /**
  2775. * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
  2776. * @vha: HA context
  2777. *
  2778. * Returns 0 on success.
  2779. */
  2780. static int
  2781. qla81xx_reset_mpi(scsi_qla_host_t *vha)
  2782. {
  2783. uint16_t mb[4] = {0x1010, 0, 1, 0};
  2784. if (!IS_QLA81XX(vha->hw))
  2785. return QLA_SUCCESS;
  2786. return qla81xx_write_mpi_register(vha, mb);
  2787. }
  2788. static int
  2789. qla_chk_risc_recovery(scsi_qla_host_t *vha)
  2790. {
  2791. struct qla_hw_data *ha = vha->hw;
  2792. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  2793. __le16 __iomem *mbptr = &reg->mailbox0;
  2794. int i;
  2795. u16 mb[32];
  2796. int rc = QLA_SUCCESS;
  2797. if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
  2798. return rc;
  2799. /* this check is only valid after RISC reset */
  2800. mb[0] = rd_reg_word(mbptr);
  2801. mbptr++;
  2802. if (mb[0] == 0xf) {
  2803. rc = QLA_FUNCTION_FAILED;
  2804. for (i = 1; i < 32; i++) {
  2805. mb[i] = rd_reg_word(mbptr);
  2806. mbptr++;
  2807. }
  2808. ql_log(ql_log_warn, vha, 0x1015,
  2809. "RISC reset failed. mb[0-7] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
  2810. mb[0], mb[1], mb[2], mb[3], mb[4], mb[5], mb[6], mb[7]);
  2811. ql_log(ql_log_warn, vha, 0x1015,
  2812. "RISC reset failed. mb[8-15] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
  2813. mb[8], mb[9], mb[10], mb[11], mb[12], mb[13], mb[14],
  2814. mb[15]);
  2815. ql_log(ql_log_warn, vha, 0x1015,
  2816. "RISC reset failed. mb[16-23] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
  2817. mb[16], mb[17], mb[18], mb[19], mb[20], mb[21], mb[22],
  2818. mb[23]);
  2819. ql_log(ql_log_warn, vha, 0x1015,
  2820. "RISC reset failed. mb[24-31] %04xh %04xh %04xh %04xh %04xh %04xh %04xh %04xh\n",
  2821. mb[24], mb[25], mb[26], mb[27], mb[28], mb[29], mb[30],
  2822. mb[31]);
  2823. }
  2824. return rc;
  2825. }
  2826. /**
  2827. * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
  2828. * @vha: HA context
  2829. *
  2830. * Returns 0 on success.
  2831. */
  2832. static inline int
  2833. qla24xx_reset_risc(scsi_qla_host_t *vha)
  2834. {
  2835. unsigned long flags = 0;
  2836. struct qla_hw_data *ha = vha->hw;
  2837. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  2838. uint32_t cnt;
  2839. uint16_t wd;
  2840. static int abts_cnt; /* ISP abort retry counts */
  2841. int rval = QLA_SUCCESS;
  2842. int print = 1;
  2843. spin_lock_irqsave(&ha->hardware_lock, flags);
  2844. /* Reset RISC. */
  2845. wrt_reg_dword(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  2846. for (cnt = 0; cnt < 30000; cnt++) {
  2847. if ((rd_reg_dword(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
  2848. break;
  2849. udelay(10);
  2850. }
  2851. if (!(rd_reg_dword(&reg->ctrl_status) & CSRX_DMA_ACTIVE))
  2852. set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
  2853. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
  2854. "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
  2855. rd_reg_dword(&reg->hccr),
  2856. rd_reg_dword(&reg->ctrl_status),
  2857. (rd_reg_dword(&reg->ctrl_status) & CSRX_DMA_ACTIVE));
  2858. wrt_reg_dword(&reg->ctrl_status,
  2859. CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
  2860. pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
  2861. udelay(100);
  2862. /* Wait for firmware to complete NVRAM accesses. */
  2863. rd_reg_word(&reg->mailbox0);
  2864. for (cnt = 10000; rd_reg_word(&reg->mailbox0) != 0 &&
  2865. rval == QLA_SUCCESS; cnt--) {
  2866. barrier();
  2867. if (cnt)
  2868. udelay(5);
  2869. else
  2870. rval = QLA_FUNCTION_TIMEOUT;
  2871. }
  2872. if (rval == QLA_SUCCESS)
  2873. set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
  2874. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
  2875. "HCCR: 0x%x, MailBox0 Status 0x%x\n",
  2876. rd_reg_dword(&reg->hccr),
  2877. rd_reg_word(&reg->mailbox0));
  2878. /* Wait for soft-reset to complete. */
  2879. rd_reg_dword(&reg->ctrl_status);
  2880. for (cnt = 0; cnt < 60; cnt++) {
  2881. barrier();
  2882. if ((rd_reg_dword(&reg->ctrl_status) &
  2883. CSRX_ISP_SOFT_RESET) == 0)
  2884. break;
  2885. udelay(5);
  2886. }
  2887. if (!(rd_reg_dword(&reg->ctrl_status) & CSRX_ISP_SOFT_RESET))
  2888. set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
  2889. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
  2890. "HCCR: 0x%x, Soft Reset status: 0x%x\n",
  2891. rd_reg_dword(&reg->hccr),
  2892. rd_reg_dword(&reg->ctrl_status));
  2893. /* If required, do an MPI FW reset now */
  2894. if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
  2895. if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
  2896. if (++abts_cnt < 5) {
  2897. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2898. set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
  2899. } else {
  2900. /*
  2901. * We exhausted the ISP abort retries. We have to
  2902. * set the board offline.
  2903. */
  2904. abts_cnt = 0;
  2905. vha->flags.online = 0;
  2906. }
  2907. }
  2908. }
  2909. wrt_reg_dword(&reg->hccr, HCCRX_SET_RISC_RESET);
  2910. rd_reg_dword(&reg->hccr);
  2911. wrt_reg_dword(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  2912. rd_reg_dword(&reg->hccr);
  2913. wrt_reg_dword(&reg->hccr, HCCRX_CLR_RISC_RESET);
  2914. mdelay(10);
  2915. rd_reg_dword(&reg->hccr);
  2916. wd = rd_reg_word(&reg->mailbox0);
  2917. for (cnt = 300; wd != 0 && rval == QLA_SUCCESS; cnt--) {
  2918. barrier();
  2919. if (cnt) {
  2920. mdelay(1);
  2921. if (print && qla_chk_risc_recovery(vha))
  2922. print = 0;
  2923. wd = rd_reg_word(&reg->mailbox0);
  2924. } else {
  2925. rval = QLA_FUNCTION_TIMEOUT;
  2926. ql_log(ql_log_warn, vha, 0x015e,
  2927. "RISC reset timeout\n");
  2928. }
  2929. }
  2930. if (rval == QLA_SUCCESS)
  2931. set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
  2932. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
  2933. "Host Risc 0x%x, mailbox0 0x%x\n",
  2934. rd_reg_dword(&reg->hccr),
  2935. rd_reg_word(&reg->mailbox0));
  2936. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2937. ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
  2938. "Driver in %s mode\n",
  2939. IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
  2940. if (IS_NOPOLLING_TYPE(ha))
  2941. ha->isp_ops->enable_intrs(ha);
  2942. return rval;
  2943. }
  2944. static void
  2945. qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
  2946. {
  2947. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  2948. wrt_reg_dword(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  2949. *data = rd_reg_dword(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFSET);
  2950. }
  2951. static void
  2952. qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
  2953. {
  2954. struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
  2955. wrt_reg_dword(&reg->iobase_addr, RISC_REGISTER_BASE_OFFSET);
  2956. wrt_reg_dword(&reg->iobase_window + RISC_REGISTER_WINDOW_OFFSET, data);
  2957. }
  2958. static void
  2959. qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
  2960. {
  2961. uint32_t wd32 = 0;
  2962. uint delta_msec = 100;
  2963. uint elapsed_msec = 0;
  2964. uint timeout_msec;
  2965. ulong n;
  2966. if (vha->hw->pdev->subsystem_device != 0x0175 &&
  2967. vha->hw->pdev->subsystem_device != 0x0240)
  2968. return;
  2969. wrt_reg_dword(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
  2970. udelay(100);
  2971. attempt:
  2972. timeout_msec = TIMEOUT_SEMAPHORE;
  2973. n = timeout_msec / delta_msec;
  2974. while (n--) {
  2975. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
  2976. qla25xx_read_risc_sema_reg(vha, &wd32);
  2977. if (wd32 & RISC_SEMAPHORE)
  2978. break;
  2979. msleep(delta_msec);
  2980. elapsed_msec += delta_msec;
  2981. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  2982. goto force;
  2983. }
  2984. if (!(wd32 & RISC_SEMAPHORE))
  2985. goto force;
  2986. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  2987. goto acquired;
  2988. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
  2989. timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
  2990. n = timeout_msec / delta_msec;
  2991. while (n--) {
  2992. qla25xx_read_risc_sema_reg(vha, &wd32);
  2993. if (!(wd32 & RISC_SEMAPHORE_FORCE))
  2994. break;
  2995. msleep(delta_msec);
  2996. elapsed_msec += delta_msec;
  2997. if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
  2998. goto force;
  2999. }
  3000. if (wd32 & RISC_SEMAPHORE_FORCE)
  3001. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
  3002. goto attempt;
  3003. force:
  3004. qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
  3005. acquired:
  3006. return;
  3007. }
  3008. /**
  3009. * qla24xx_reset_chip() - Reset ISP24xx chip.
  3010. * @vha: HA context
  3011. *
  3012. * Returns 0 on success.
  3013. */
  3014. int
  3015. qla24xx_reset_chip(scsi_qla_host_t *vha)
  3016. {
  3017. struct qla_hw_data *ha = vha->hw;
  3018. int rval = QLA_FUNCTION_FAILED;
  3019. if (pci_channel_offline(ha->pdev) &&
  3020. ha->flags.pci_channel_io_perm_failure) {
  3021. return rval;
  3022. }
  3023. ha->isp_ops->disable_intrs(ha);
  3024. qla25xx_manipulate_risc_semaphore(vha);
  3025. /* Perform RISC reset. */
  3026. rval = qla24xx_reset_risc(vha);
  3027. return rval;
  3028. }
  3029. /**
  3030. * qla2x00_chip_diag() - Test chip for proper operation.
  3031. * @vha: HA context
  3032. *
  3033. * Returns 0 on success.
  3034. */
  3035. int
  3036. qla2x00_chip_diag(scsi_qla_host_t *vha)
  3037. {
  3038. int rval;
  3039. struct qla_hw_data *ha = vha->hw;
  3040. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3041. unsigned long flags = 0;
  3042. uint16_t data;
  3043. uint32_t cnt;
  3044. uint16_t mb[5];
  3045. struct req_que *req = ha->req_q_map[0];
  3046. /* Assume a failed state */
  3047. rval = QLA_FUNCTION_FAILED;
  3048. ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
  3049. &reg->flash_address);
  3050. spin_lock_irqsave(&ha->hardware_lock, flags);
  3051. /* Reset ISP chip. */
  3052. wrt_reg_word(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
  3053. /*
  3054. * We need to have a delay here since the card will not respond while
  3055. * in reset causing an MCA on some architectures.
  3056. */
  3057. udelay(20);
  3058. data = qla2x00_debounce_register(&reg->ctrl_status);
  3059. for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
  3060. udelay(5);
  3061. data = rd_reg_word(&reg->ctrl_status);
  3062. barrier();
  3063. }
  3064. if (!cnt)
  3065. goto chip_diag_failed;
  3066. ql_dbg(ql_dbg_init, vha, 0x007c,
  3067. "Reset register cleared by chip reset.\n");
  3068. /* Reset RISC processor. */
  3069. wrt_reg_word(&reg->hccr, HCCR_RESET_RISC);
  3070. wrt_reg_word(&reg->hccr, HCCR_RELEASE_RISC);
  3071. /* Workaround for QLA2312 PCI parity error */
  3072. if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
  3073. data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
  3074. for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
  3075. udelay(5);
  3076. data = RD_MAILBOX_REG(ha, reg, 0);
  3077. barrier();
  3078. }
  3079. } else
  3080. udelay(10);
  3081. if (!cnt)
  3082. goto chip_diag_failed;
  3083. /* Check product ID of chip */
  3084. ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
  3085. mb[1] = RD_MAILBOX_REG(ha, reg, 1);
  3086. mb[2] = RD_MAILBOX_REG(ha, reg, 2);
  3087. mb[3] = RD_MAILBOX_REG(ha, reg, 3);
  3088. mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
  3089. if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
  3090. mb[3] != PROD_ID_3) {
  3091. ql_log(ql_log_warn, vha, 0x0062,
  3092. "Wrong product ID = 0x%x,0x%x,0x%x.\n",
  3093. mb[1], mb[2], mb[3]);
  3094. goto chip_diag_failed;
  3095. }
  3096. ha->product_id[0] = mb[1];
  3097. ha->product_id[1] = mb[2];
  3098. ha->product_id[2] = mb[3];
  3099. ha->product_id[3] = mb[4];
  3100. /* Adjust fw RISC transfer size */
  3101. if (req->length > 1024)
  3102. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
  3103. else
  3104. ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
  3105. req->length;
  3106. if (IS_QLA2200(ha) &&
  3107. RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
  3108. /* Limit firmware transfer size with a 2200A */
  3109. ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
  3110. ha->device_type |= DT_ISP2200A;
  3111. ha->fw_transfer_size = 128;
  3112. }
  3113. /* Wrap Incoming Mailboxes Test. */
  3114. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3115. ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
  3116. rval = qla2x00_mbx_reg_test(vha);
  3117. if (rval)
  3118. ql_log(ql_log_warn, vha, 0x0080,
  3119. "Failed mailbox send register test.\n");
  3120. else
  3121. /* Flag a successful rval */
  3122. rval = QLA_SUCCESS;
  3123. spin_lock_irqsave(&ha->hardware_lock, flags);
  3124. chip_diag_failed:
  3125. if (rval)
  3126. ql_log(ql_log_info, vha, 0x0081,
  3127. "Chip diagnostics **** FAILED ****.\n");
  3128. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3129. return (rval);
  3130. }
  3131. /**
  3132. * qla24xx_chip_diag() - Test ISP24xx for proper operation.
  3133. * @vha: HA context
  3134. *
  3135. * Returns 0 on success.
  3136. */
  3137. int
  3138. qla24xx_chip_diag(scsi_qla_host_t *vha)
  3139. {
  3140. int rval;
  3141. struct qla_hw_data *ha = vha->hw;
  3142. struct req_que *req = ha->req_q_map[0];
  3143. if (IS_P3P_TYPE(ha))
  3144. return QLA_SUCCESS;
  3145. ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
  3146. rval = qla2x00_mbx_reg_test(vha);
  3147. if (rval) {
  3148. ql_log(ql_log_warn, vha, 0x0082,
  3149. "Failed mailbox send register test.\n");
  3150. } else {
  3151. /* Flag a successful rval */
  3152. rval = QLA_SUCCESS;
  3153. }
  3154. return rval;
  3155. }
  3156. int qla2x00_alloc_fce_trace(scsi_qla_host_t *vha)
  3157. {
  3158. dma_addr_t tc_dma;
  3159. void *tc;
  3160. struct qla_hw_data *ha = vha->hw;
  3161. if (!IS_FWI2_CAPABLE(ha))
  3162. return -EINVAL;
  3163. if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
  3164. !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
  3165. return -EINVAL;
  3166. if (ha->fce) {
  3167. ql_dbg(ql_dbg_init, vha, 0x00bd,
  3168. "%s: FCE Mem is already allocated.\n",
  3169. __func__);
  3170. return -EIO;
  3171. }
  3172. /* Allocate memory for Fibre Channel Event Buffer. */
  3173. tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
  3174. GFP_KERNEL);
  3175. if (!tc) {
  3176. ql_log(ql_log_warn, vha, 0x00be,
  3177. "Unable to allocate (%d KB) for FCE.\n",
  3178. FCE_SIZE / 1024);
  3179. return -ENOMEM;
  3180. }
  3181. ql_dbg(ql_dbg_init, vha, 0x00c0,
  3182. "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
  3183. ha->fce_dma = tc_dma;
  3184. ha->fce = tc;
  3185. ha->fce_bufs = FCE_NUM_BUFFERS;
  3186. return 0;
  3187. }
  3188. void qla2x00_free_fce_trace(struct qla_hw_data *ha)
  3189. {
  3190. if (!ha->fce)
  3191. return;
  3192. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, ha->fce_dma);
  3193. ha->fce = NULL;
  3194. ha->fce_dma = 0;
  3195. }
  3196. static void
  3197. qla2x00_alloc_eft_trace(scsi_qla_host_t *vha)
  3198. {
  3199. dma_addr_t tc_dma;
  3200. void *tc;
  3201. struct qla_hw_data *ha = vha->hw;
  3202. if (!IS_FWI2_CAPABLE(ha))
  3203. return;
  3204. if (ha->eft) {
  3205. ql_dbg(ql_dbg_init, vha, 0x00bd,
  3206. "%s: EFT Mem is already allocated.\n",
  3207. __func__);
  3208. return;
  3209. }
  3210. /* Allocate memory for Extended Trace Buffer. */
  3211. tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
  3212. GFP_KERNEL);
  3213. if (!tc) {
  3214. ql_log(ql_log_warn, vha, 0x00c1,
  3215. "Unable to allocate (%d KB) for EFT.\n",
  3216. EFT_SIZE / 1024);
  3217. return;
  3218. }
  3219. ql_dbg(ql_dbg_init, vha, 0x00c3,
  3220. "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
  3221. ha->eft_dma = tc_dma;
  3222. ha->eft = tc;
  3223. }
  3224. void
  3225. qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
  3226. {
  3227. uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
  3228. eft_size, fce_size, mq_size;
  3229. struct qla_hw_data *ha = vha->hw;
  3230. struct req_que *req = ha->req_q_map[0];
  3231. struct rsp_que *rsp = ha->rsp_q_map[0];
  3232. struct qla2xxx_fw_dump *fw_dump;
  3233. if (ha->fw_dump) {
  3234. ql_dbg(ql_dbg_init, vha, 0x00bd,
  3235. "Firmware dump already allocated.\n");
  3236. return;
  3237. }
  3238. ha->fw_dumped = 0;
  3239. ha->fw_dump_cap_flags = 0;
  3240. dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
  3241. req_q_size = rsp_q_size = 0;
  3242. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  3243. fixed_size = sizeof(struct qla2100_fw_dump);
  3244. } else if (IS_QLA23XX(ha)) {
  3245. fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
  3246. mem_size = (ha->fw_memory_size - 0x11000 + 1) *
  3247. sizeof(uint16_t);
  3248. } else if (IS_FWI2_CAPABLE(ha)) {
  3249. if (IS_QLA83XX(ha))
  3250. fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
  3251. else if (IS_QLA81XX(ha))
  3252. fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
  3253. else if (IS_QLA25XX(ha))
  3254. fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
  3255. else
  3256. fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
  3257. mem_size = (ha->fw_memory_size - 0x100000 + 1) *
  3258. sizeof(uint32_t);
  3259. if (ha->mqenable) {
  3260. if (!IS_QLA83XX(ha))
  3261. mq_size = sizeof(struct qla2xxx_mq_chain);
  3262. /*
  3263. * Allocate maximum buffer size for all queues - Q0.
  3264. * Resizing must be done at end-of-dump processing.
  3265. */
  3266. mq_size += (ha->max_req_queues - 1) *
  3267. (req->length * sizeof(request_t));
  3268. mq_size += (ha->max_rsp_queues - 1) *
  3269. (rsp->length * sizeof(response_t));
  3270. }
  3271. if (ha->tgt.atio_ring)
  3272. mq_size += ha->tgt.atio_q_length * sizeof(request_t);
  3273. if (ha->fce) {
  3274. fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
  3275. ha->flags.fce_dump_buf_alloced = 1;
  3276. }
  3277. qla2x00_alloc_eft_trace(vha);
  3278. if (ha->eft)
  3279. eft_size = EFT_SIZE;
  3280. }
  3281. if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
  3282. struct fwdt *fwdt = ha->fwdt;
  3283. uint j;
  3284. for (j = 0; j < 2; j++, fwdt++) {
  3285. if (!fwdt->template) {
  3286. ql_dbg(ql_dbg_init, vha, 0x00ba,
  3287. "-> fwdt%u no template\n", j);
  3288. continue;
  3289. }
  3290. ql_dbg(ql_dbg_init, vha, 0x00fa,
  3291. "-> fwdt%u calculating fwdump size...\n", j);
  3292. fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
  3293. vha, fwdt->template);
  3294. ql_dbg(ql_dbg_init, vha, 0x00fa,
  3295. "-> fwdt%u calculated fwdump size = %#lx bytes\n",
  3296. j, fwdt->dump_size);
  3297. dump_size += fwdt->dump_size;
  3298. }
  3299. /* Add space for spare MPI fw dump. */
  3300. dump_size += ha->fwdt[1].dump_size;
  3301. } else {
  3302. req_q_size = req->length * sizeof(request_t);
  3303. rsp_q_size = rsp->length * sizeof(response_t);
  3304. dump_size = offsetof(struct qla2xxx_fw_dump, isp);
  3305. dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
  3306. + eft_size;
  3307. ha->chain_offset = dump_size;
  3308. dump_size += mq_size + fce_size;
  3309. if (ha->exchoffld_buf)
  3310. dump_size += sizeof(struct qla2xxx_offld_chain) +
  3311. ha->exchoffld_size;
  3312. if (ha->exlogin_buf)
  3313. dump_size += sizeof(struct qla2xxx_offld_chain) +
  3314. ha->exlogin_size;
  3315. }
  3316. if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
  3317. ql_dbg(ql_dbg_init, vha, 0x00c5,
  3318. "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
  3319. __func__, dump_size, ha->fw_dump_len,
  3320. ha->fw_dump_alloc_len);
  3321. fw_dump = vmalloc(dump_size);
  3322. if (!fw_dump) {
  3323. ql_log(ql_log_warn, vha, 0x00c4,
  3324. "Unable to allocate (%d KB) for firmware dump.\n",
  3325. dump_size / 1024);
  3326. } else {
  3327. mutex_lock(&ha->optrom_mutex);
  3328. if (ha->fw_dumped) {
  3329. memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
  3330. vfree(ha->fw_dump);
  3331. ha->fw_dump = fw_dump;
  3332. ha->fw_dump_alloc_len = dump_size;
  3333. ql_dbg(ql_dbg_init, vha, 0x00c5,
  3334. "Re-Allocated (%d KB) and save firmware dump.\n",
  3335. dump_size / 1024);
  3336. } else {
  3337. vfree(ha->fw_dump);
  3338. ha->fw_dump = fw_dump;
  3339. ha->fw_dump_len = ha->fw_dump_alloc_len =
  3340. dump_size;
  3341. ql_dbg(ql_dbg_init, vha, 0x00c5,
  3342. "Allocated (%d KB) for firmware dump.\n",
  3343. dump_size / 1024);
  3344. if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
  3345. ha->mpi_fw_dump = (char *)fw_dump +
  3346. ha->fwdt[1].dump_size;
  3347. mutex_unlock(&ha->optrom_mutex);
  3348. return;
  3349. }
  3350. ha->fw_dump->signature[0] = 'Q';
  3351. ha->fw_dump->signature[1] = 'L';
  3352. ha->fw_dump->signature[2] = 'G';
  3353. ha->fw_dump->signature[3] = 'C';
  3354. ha->fw_dump->version = htonl(1);
  3355. ha->fw_dump->fixed_size = htonl(fixed_size);
  3356. ha->fw_dump->mem_size = htonl(mem_size);
  3357. ha->fw_dump->req_q_size = htonl(req_q_size);
  3358. ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
  3359. ha->fw_dump->eft_size = htonl(eft_size);
  3360. ha->fw_dump->eft_addr_l =
  3361. htonl(LSD(ha->eft_dma));
  3362. ha->fw_dump->eft_addr_h =
  3363. htonl(MSD(ha->eft_dma));
  3364. ha->fw_dump->header_size =
  3365. htonl(offsetof
  3366. (struct qla2xxx_fw_dump, isp));
  3367. }
  3368. mutex_unlock(&ha->optrom_mutex);
  3369. }
  3370. }
  3371. }
  3372. static int
  3373. qla81xx_mpi_sync(scsi_qla_host_t *vha)
  3374. {
  3375. #define MPS_MASK 0xe0
  3376. int rval;
  3377. uint16_t dc;
  3378. uint32_t dw;
  3379. if (!IS_QLA81XX(vha->hw))
  3380. return QLA_SUCCESS;
  3381. rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
  3382. if (rval != QLA_SUCCESS) {
  3383. ql_log(ql_log_warn, vha, 0x0105,
  3384. "Unable to acquire semaphore.\n");
  3385. goto done;
  3386. }
  3387. pci_read_config_word(vha->hw->pdev, 0x54, &dc);
  3388. rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
  3389. if (rval != QLA_SUCCESS) {
  3390. ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
  3391. goto done_release;
  3392. }
  3393. dc &= MPS_MASK;
  3394. if (dc == (dw & MPS_MASK))
  3395. goto done_release;
  3396. dw &= ~MPS_MASK;
  3397. dw |= dc;
  3398. rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
  3399. if (rval != QLA_SUCCESS) {
  3400. ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
  3401. }
  3402. done_release:
  3403. rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
  3404. if (rval != QLA_SUCCESS) {
  3405. ql_log(ql_log_warn, vha, 0x006d,
  3406. "Unable to release semaphore.\n");
  3407. }
  3408. done:
  3409. return rval;
  3410. }
  3411. int
  3412. qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
  3413. {
  3414. /* Don't try to reallocate the array */
  3415. if (req->outstanding_cmds)
  3416. return QLA_SUCCESS;
  3417. if (!IS_FWI2_CAPABLE(ha))
  3418. req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
  3419. else {
  3420. if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
  3421. req->num_outstanding_cmds = ha->cur_fw_xcb_count;
  3422. else
  3423. req->num_outstanding_cmds = ha->cur_fw_iocb_count;
  3424. }
  3425. req->outstanding_cmds = kzalloc_objs(srb_t *, req->num_outstanding_cmds);
  3426. if (!req->outstanding_cmds) {
  3427. /*
  3428. * Try to allocate a minimal size just so we can get through
  3429. * initialization.
  3430. */
  3431. req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
  3432. req->outstanding_cmds = kzalloc_objs(srb_t *,
  3433. req->num_outstanding_cmds);
  3434. if (!req->outstanding_cmds) {
  3435. ql_log(ql_log_fatal, NULL, 0x0126,
  3436. "Failed to allocate memory for "
  3437. "outstanding_cmds for req_que %p.\n", req);
  3438. req->num_outstanding_cmds = 0;
  3439. return QLA_FUNCTION_FAILED;
  3440. }
  3441. }
  3442. return QLA_SUCCESS;
  3443. }
  3444. #define PRINT_FIELD(_field, _flag, _str) { \
  3445. if (a0->_field & _flag) {\
  3446. if (p) {\
  3447. strcat(ptr, "|");\
  3448. ptr++;\
  3449. leftover--;\
  3450. } \
  3451. len = snprintf(ptr, leftover, "%s", _str); \
  3452. p = 1;\
  3453. leftover -= len;\
  3454. ptr += len; \
  3455. } \
  3456. }
  3457. static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
  3458. {
  3459. #define STR_LEN 64
  3460. struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
  3461. u8 str[STR_LEN], *ptr, p;
  3462. int leftover, len;
  3463. ql_dbg(ql_dbg_init, vha, 0x015a,
  3464. "SFP: %.*s -> %.*s ->%s%s%s%s%s%s%s\n",
  3465. (int)sizeof(a0->vendor_name), a0->vendor_name,
  3466. (int)sizeof(a0->vendor_pn), a0->vendor_pn,
  3467. a0->fc_sp_cc10 & FC_SP_2 ? a0->fiber_channel_speed2 & FC_SP_64 ?
  3468. " 64G" : "" : "",
  3469. a0->fc_sp_cc10 & FC_SP_32 ? " 32G" : "",
  3470. a0->fc_sp_cc10 & FC_SP_16 ? " 16G" : "",
  3471. a0->fc_sp_cc10 & FC_SP_8 ? " 8G" : "",
  3472. a0->fc_sp_cc10 & FC_SP_4 ? " 4G" : "",
  3473. a0->fc_sp_cc10 & FC_SP_2 ? " 2G" : "",
  3474. a0->fc_sp_cc10 & FC_SP_1 ? " 1G" : "");
  3475. if (!(ql2xextended_error_logging & ql_dbg_verbose))
  3476. return;
  3477. memset(str, 0, STR_LEN);
  3478. snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
  3479. ql_dbg(ql_dbg_init, vha, 0x015a,
  3480. "SFP MFG Name: %s\n", str);
  3481. memset(str, 0, STR_LEN);
  3482. snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
  3483. ql_dbg(ql_dbg_init, vha, 0x015c,
  3484. "SFP Part Name: %s\n", str);
  3485. /* media */
  3486. memset(str, 0, STR_LEN);
  3487. ptr = str;
  3488. leftover = STR_LEN;
  3489. p = len = 0;
  3490. PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
  3491. PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
  3492. PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
  3493. PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
  3494. PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
  3495. PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
  3496. PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
  3497. ql_dbg(ql_dbg_init, vha, 0x0160,
  3498. "SFP Media: %s\n", str);
  3499. /* link length */
  3500. memset(str, 0, STR_LEN);
  3501. ptr = str;
  3502. leftover = STR_LEN;
  3503. p = len = 0;
  3504. PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
  3505. PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
  3506. PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
  3507. PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
  3508. PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
  3509. ql_dbg(ql_dbg_init, vha, 0x0196,
  3510. "SFP Link Length: %s\n", str);
  3511. memset(str, 0, STR_LEN);
  3512. ptr = str;
  3513. leftover = STR_LEN;
  3514. p = len = 0;
  3515. PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
  3516. PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
  3517. PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
  3518. PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
  3519. PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
  3520. ql_dbg(ql_dbg_init, vha, 0x016e,
  3521. "SFP FC Link Tech: %s\n", str);
  3522. if (a0->length_km)
  3523. ql_dbg(ql_dbg_init, vha, 0x016f,
  3524. "SFP Distant: %d km\n", a0->length_km);
  3525. if (a0->length_100m)
  3526. ql_dbg(ql_dbg_init, vha, 0x0170,
  3527. "SFP Distant: %d m\n", a0->length_100m*100);
  3528. if (a0->length_50um_10m)
  3529. ql_dbg(ql_dbg_init, vha, 0x0189,
  3530. "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
  3531. if (a0->length_62um_10m)
  3532. ql_dbg(ql_dbg_init, vha, 0x018a,
  3533. "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
  3534. if (a0->length_om4_10m)
  3535. ql_dbg(ql_dbg_init, vha, 0x0194,
  3536. "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
  3537. if (a0->length_om3_10m)
  3538. ql_dbg(ql_dbg_init, vha, 0x0195,
  3539. "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
  3540. }
  3541. /**
  3542. * qla24xx_detect_sfp()
  3543. *
  3544. * @vha: adapter state pointer.
  3545. *
  3546. * @return
  3547. * 0 -- Configure firmware to use short-range settings -- normal
  3548. * buffer-to-buffer credits.
  3549. *
  3550. * 1 -- Configure firmware to use long-range settings -- extra
  3551. * buffer-to-buffer credits should be allocated with
  3552. * ha->lr_distance containing distance settings from NVRAM or SFP
  3553. * (if supported).
  3554. */
  3555. int
  3556. qla24xx_detect_sfp(scsi_qla_host_t *vha)
  3557. {
  3558. int rc, used_nvram;
  3559. struct sff_8247_a0 *a;
  3560. struct qla_hw_data *ha = vha->hw;
  3561. struct nvram_81xx *nv = ha->nvram;
  3562. #define LR_DISTANCE_UNKNOWN 2
  3563. static const char * const types[] = { "Short", "Long" };
  3564. static const char * const lengths[] = { "(10km)", "(5km)", "" };
  3565. u8 ll = 0;
  3566. /* Seed with NVRAM settings. */
  3567. used_nvram = 0;
  3568. ha->flags.lr_detected = 0;
  3569. if (IS_BPM_RANGE_CAPABLE(ha) &&
  3570. (nv->enhanced_features & NEF_LR_DIST_ENABLE)) {
  3571. used_nvram = 1;
  3572. ha->flags.lr_detected = 1;
  3573. ha->lr_distance =
  3574. (nv->enhanced_features >> LR_DIST_NV_POS)
  3575. & LR_DIST_NV_MASK;
  3576. }
  3577. if (!IS_BPM_ENABLED(vha))
  3578. goto out;
  3579. /* Determine SR/LR capabilities of SFP/Transceiver. */
  3580. rc = qla2x00_read_sfp_dev(vha, NULL, 0);
  3581. if (rc)
  3582. goto out;
  3583. used_nvram = 0;
  3584. a = (struct sff_8247_a0 *)vha->hw->sfp_data;
  3585. qla2xxx_print_sfp_info(vha);
  3586. ha->flags.lr_detected = 0;
  3587. ll = a->fc_ll_cc7;
  3588. if (ll & FC_LL_VL || ll & FC_LL_L) {
  3589. /* Long range, track length. */
  3590. ha->flags.lr_detected = 1;
  3591. if (a->length_km > 5 || a->length_100m > 50)
  3592. ha->lr_distance = LR_DISTANCE_10K;
  3593. else
  3594. ha->lr_distance = LR_DISTANCE_5K;
  3595. }
  3596. out:
  3597. ql_dbg(ql_dbg_async, vha, 0x507b,
  3598. "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
  3599. types[ha->flags.lr_detected],
  3600. ha->flags.lr_detected ? lengths[ha->lr_distance] :
  3601. lengths[LR_DISTANCE_UNKNOWN],
  3602. used_nvram, ll, ha->flags.lr_detected, ha->lr_distance);
  3603. return ha->flags.lr_detected;
  3604. }
  3605. static void __qla_adjust_iocb_limit(struct qla_qpair *qpair)
  3606. {
  3607. u8 num_qps;
  3608. u16 limit;
  3609. struct qla_hw_data *ha = qpair->vha->hw;
  3610. num_qps = ha->num_qpairs + 1;
  3611. limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
  3612. qpair->fwres.iocbs_total = ha->orig_fw_iocb_count;
  3613. qpair->fwres.iocbs_limit = limit;
  3614. qpair->fwres.iocbs_qp_limit = limit / num_qps;
  3615. qpair->fwres.exch_total = ha->orig_fw_xcb_count;
  3616. qpair->fwres.exch_limit = (ha->orig_fw_xcb_count *
  3617. QLA_IOCB_PCT_LIMIT) / 100;
  3618. }
  3619. void qla_init_iocb_limit(scsi_qla_host_t *vha)
  3620. {
  3621. u8 i;
  3622. struct qla_hw_data *ha = vha->hw;
  3623. __qla_adjust_iocb_limit(ha->base_qpair);
  3624. ha->base_qpair->fwres.iocbs_used = 0;
  3625. ha->base_qpair->fwres.exch_used = 0;
  3626. for (i = 0; i < ha->max_qpairs; i++) {
  3627. if (ha->queue_pair_map[i]) {
  3628. __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
  3629. ha->queue_pair_map[i]->fwres.iocbs_used = 0;
  3630. ha->queue_pair_map[i]->fwres.exch_used = 0;
  3631. }
  3632. }
  3633. ha->fwres.iocb_total = ha->orig_fw_iocb_count;
  3634. ha->fwres.iocb_limit = (ha->orig_fw_iocb_count * QLA_IOCB_PCT_LIMIT) / 100;
  3635. ha->fwres.exch_total = ha->orig_fw_xcb_count;
  3636. ha->fwres.exch_limit = (ha->orig_fw_xcb_count * QLA_IOCB_PCT_LIMIT) / 100;
  3637. atomic_set(&ha->fwres.iocb_used, 0);
  3638. atomic_set(&ha->fwres.exch_used, 0);
  3639. }
  3640. void qla_adjust_iocb_limit(scsi_qla_host_t *vha)
  3641. {
  3642. u8 i;
  3643. struct qla_hw_data *ha = vha->hw;
  3644. __qla_adjust_iocb_limit(ha->base_qpair);
  3645. for (i = 0; i < ha->max_qpairs; i++) {
  3646. if (ha->queue_pair_map[i])
  3647. __qla_adjust_iocb_limit(ha->queue_pair_map[i]);
  3648. }
  3649. }
  3650. /**
  3651. * qla2x00_setup_chip() - Load and start RISC firmware.
  3652. * @vha: HA context
  3653. *
  3654. * Returns 0 on success.
  3655. */
  3656. static int
  3657. qla2x00_setup_chip(scsi_qla_host_t *vha)
  3658. {
  3659. int rval;
  3660. uint32_t srisc_address = 0;
  3661. struct qla_hw_data *ha = vha->hw;
  3662. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3663. unsigned long flags;
  3664. int done_once = 0;
  3665. if (IS_P3P_TYPE(ha)) {
  3666. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  3667. if (rval == QLA_SUCCESS) {
  3668. qla2x00_stop_firmware(vha);
  3669. goto enable_82xx_npiv;
  3670. } else
  3671. goto failed;
  3672. }
  3673. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  3674. /* Disable SRAM, Instruction RAM and GP RAM parity. */
  3675. spin_lock_irqsave(&ha->hardware_lock, flags);
  3676. wrt_reg_word(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
  3677. rd_reg_word(&reg->hccr);
  3678. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3679. }
  3680. qla81xx_mpi_sync(vha);
  3681. execute_fw_with_lr:
  3682. /* Load firmware sequences */
  3683. rval = ha->isp_ops->load_risc(vha, &srisc_address);
  3684. if (rval == QLA_SUCCESS) {
  3685. ql_dbg(ql_dbg_init, vha, 0x00c9,
  3686. "Verifying Checksum of loaded RISC code.\n");
  3687. rval = qla2x00_verify_checksum(vha, srisc_address);
  3688. if (rval == QLA_SUCCESS) {
  3689. /* Start firmware execution. */
  3690. ql_dbg(ql_dbg_init, vha, 0x00ca,
  3691. "Starting firmware.\n");
  3692. if (ql2xexlogins)
  3693. ha->flags.exlogins_enabled = 1;
  3694. if (qla_is_exch_offld_enabled(vha))
  3695. ha->flags.exchoffld_enabled = 1;
  3696. rval = qla2x00_execute_fw(vha, srisc_address);
  3697. /* Retrieve firmware information. */
  3698. if (rval == QLA_SUCCESS) {
  3699. /* Enable BPM support? */
  3700. if (!done_once++ && qla24xx_detect_sfp(vha)) {
  3701. ql_dbg(ql_dbg_init, vha, 0x00ca,
  3702. "Re-starting firmware -- BPM.\n");
  3703. /* Best-effort - re-init. */
  3704. ha->isp_ops->reset_chip(vha);
  3705. ha->isp_ops->chip_diag(vha);
  3706. goto execute_fw_with_lr;
  3707. }
  3708. if (IS_ZIO_THRESHOLD_CAPABLE(ha))
  3709. qla27xx_set_zio_threshold(vha,
  3710. ha->last_zio_threshold);
  3711. rval = qla2x00_set_exlogins_buffer(vha);
  3712. if (rval != QLA_SUCCESS)
  3713. goto failed;
  3714. rval = qla2x00_set_exchoffld_buffer(vha);
  3715. if (rval != QLA_SUCCESS)
  3716. goto failed;
  3717. enable_82xx_npiv:
  3718. if (IS_P3P_TYPE(ha))
  3719. qla82xx_check_md_needed(vha);
  3720. else
  3721. rval = qla2x00_get_fw_version(vha);
  3722. if (rval != QLA_SUCCESS)
  3723. goto failed;
  3724. ha->flags.npiv_supported = 0;
  3725. if (IS_QLA2XXX_MIDTYPE(ha) &&
  3726. (ha->fw_attributes & BIT_2)) {
  3727. ha->flags.npiv_supported = 1;
  3728. if ((!ha->max_npiv_vports) ||
  3729. ((ha->max_npiv_vports + 1) %
  3730. MIN_MULTI_ID_FABRIC))
  3731. ha->max_npiv_vports =
  3732. MIN_MULTI_ID_FABRIC - 1;
  3733. }
  3734. qlt_config_nvram_with_fw_version(vha);
  3735. qla2x00_get_resource_cnts(vha);
  3736. qla_init_iocb_limit(vha);
  3737. /*
  3738. * Allocate the array of outstanding commands
  3739. * now that we know the firmware resources.
  3740. */
  3741. rval = qla2x00_alloc_outstanding_cmds(ha,
  3742. vha->req);
  3743. if (rval != QLA_SUCCESS)
  3744. goto failed;
  3745. if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
  3746. qla2x00_alloc_fw_dump(vha);
  3747. qla_enable_fce_trace(vha);
  3748. qla_enable_eft_trace(vha);
  3749. } else {
  3750. goto failed;
  3751. }
  3752. } else {
  3753. ql_log(ql_log_fatal, vha, 0x00cd,
  3754. "ISP Firmware failed checksum.\n");
  3755. goto failed;
  3756. }
  3757. /* Enable PUREX PASSTHRU */
  3758. if (ql2xrdpenable || ha->flags.scm_supported_f ||
  3759. ha->flags.edif_enabled)
  3760. qla25xx_set_els_cmds_supported(vha);
  3761. } else
  3762. goto failed;
  3763. if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
  3764. /* Enable proper parity. */
  3765. spin_lock_irqsave(&ha->hardware_lock, flags);
  3766. if (IS_QLA2300(ha))
  3767. /* SRAM parity */
  3768. wrt_reg_word(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
  3769. else
  3770. /* SRAM, Instruction RAM and GP RAM parity */
  3771. wrt_reg_word(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
  3772. rd_reg_word(&reg->hccr);
  3773. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  3774. }
  3775. if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
  3776. ha->flags.fac_supported = 1;
  3777. else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
  3778. uint32_t size;
  3779. rval = qla81xx_fac_get_sector_size(vha, &size);
  3780. if (rval == QLA_SUCCESS) {
  3781. ha->flags.fac_supported = 1;
  3782. ha->fdt_block_size = size << 2;
  3783. } else {
  3784. ql_log(ql_log_warn, vha, 0x00ce,
  3785. "Unsupported FAC firmware (%d.%02d.%02d).\n",
  3786. ha->fw_major_version, ha->fw_minor_version,
  3787. ha->fw_subminor_version);
  3788. if (IS_QLA83XX(ha)) {
  3789. ha->flags.fac_supported = 0;
  3790. rval = QLA_SUCCESS;
  3791. }
  3792. }
  3793. }
  3794. failed:
  3795. if (rval) {
  3796. ql_log(ql_log_fatal, vha, 0x00cf,
  3797. "Setup chip ****FAILED****.\n");
  3798. }
  3799. return (rval);
  3800. }
  3801. /**
  3802. * qla2x00_init_response_q_entries() - Initializes response queue entries.
  3803. * @rsp: response queue
  3804. *
  3805. * Beginning of request ring has initialization control block already built
  3806. * by nvram config routine.
  3807. *
  3808. * Returns 0 on success.
  3809. */
  3810. void
  3811. qla2x00_init_response_q_entries(struct rsp_que *rsp)
  3812. {
  3813. uint16_t cnt;
  3814. response_t *pkt;
  3815. rsp->ring_ptr = rsp->ring;
  3816. rsp->ring_index = 0;
  3817. rsp->status_srb = NULL;
  3818. pkt = rsp->ring_ptr;
  3819. for (cnt = 0; cnt < rsp->length; cnt++) {
  3820. pkt->signature = RESPONSE_PROCESSED;
  3821. pkt++;
  3822. }
  3823. }
  3824. /**
  3825. * qla2x00_update_fw_options() - Read and process firmware options.
  3826. * @vha: HA context
  3827. *
  3828. * Returns 0 on success.
  3829. */
  3830. void
  3831. qla2x00_update_fw_options(scsi_qla_host_t *vha)
  3832. {
  3833. uint16_t swing, emphasis, tx_sens, rx_sens;
  3834. struct qla_hw_data *ha = vha->hw;
  3835. memset(ha->fw_options, 0, sizeof(ha->fw_options));
  3836. qla2x00_get_fw_options(vha, ha->fw_options);
  3837. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  3838. return;
  3839. /* Serial Link options. */
  3840. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
  3841. "Serial link options.\n");
  3842. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
  3843. ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
  3844. ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
  3845. if (ha->fw_seriallink_options[3] & BIT_2) {
  3846. ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
  3847. /* 1G settings */
  3848. swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
  3849. emphasis = (ha->fw_seriallink_options[2] &
  3850. (BIT_4 | BIT_3)) >> 3;
  3851. tx_sens = ha->fw_seriallink_options[0] &
  3852. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  3853. rx_sens = (ha->fw_seriallink_options[0] &
  3854. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  3855. ha->fw_options[10] = (emphasis << 14) | (swing << 8);
  3856. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  3857. if (rx_sens == 0x0)
  3858. rx_sens = 0x3;
  3859. ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
  3860. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  3861. ha->fw_options[10] |= BIT_5 |
  3862. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  3863. (tx_sens & (BIT_1 | BIT_0));
  3864. /* 2G settings */
  3865. swing = (ha->fw_seriallink_options[2] &
  3866. (BIT_7 | BIT_6 | BIT_5)) >> 5;
  3867. emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
  3868. tx_sens = ha->fw_seriallink_options[1] &
  3869. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  3870. rx_sens = (ha->fw_seriallink_options[1] &
  3871. (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
  3872. ha->fw_options[11] = (emphasis << 14) | (swing << 8);
  3873. if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  3874. if (rx_sens == 0x0)
  3875. rx_sens = 0x3;
  3876. ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
  3877. } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
  3878. ha->fw_options[11] |= BIT_5 |
  3879. ((rx_sens & (BIT_1 | BIT_0)) << 2) |
  3880. (tx_sens & (BIT_1 | BIT_0));
  3881. }
  3882. /* FCP2 options. */
  3883. /* Return command IOCBs without waiting for an ABTS to complete. */
  3884. ha->fw_options[3] |= BIT_13;
  3885. /* LED scheme. */
  3886. if (ha->flags.enable_led_scheme)
  3887. ha->fw_options[2] |= BIT_12;
  3888. /* Detect ISP6312. */
  3889. if (IS_QLA6312(ha))
  3890. ha->fw_options[2] |= BIT_13;
  3891. /* Set Retry FLOGI in case of P2P connection */
  3892. if (ha->operating_mode == P2P) {
  3893. ha->fw_options[2] |= BIT_3;
  3894. ql_dbg(ql_dbg_disc, vha, 0x2100,
  3895. "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
  3896. __func__, ha->fw_options[2]);
  3897. }
  3898. /* Update firmware options. */
  3899. qla2x00_set_fw_options(vha, ha->fw_options);
  3900. }
  3901. void
  3902. qla24xx_update_fw_options(scsi_qla_host_t *vha)
  3903. {
  3904. int rval;
  3905. struct qla_hw_data *ha = vha->hw;
  3906. if (IS_P3P_TYPE(ha))
  3907. return;
  3908. /* Hold status IOCBs until ABTS response received. */
  3909. if (ql2xfwholdabts)
  3910. ha->fw_options[3] |= BIT_12;
  3911. /* Set Retry FLOGI in case of P2P connection */
  3912. if (ha->operating_mode == P2P) {
  3913. ha->fw_options[2] |= BIT_3;
  3914. ql_dbg(ql_dbg_disc, vha, 0x2101,
  3915. "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
  3916. __func__, ha->fw_options[2]);
  3917. }
  3918. /* Move PUREX, ABTS RX & RIDA to ATIOQ */
  3919. if (ql2xmvasynctoatio && !ha->flags.edif_enabled &&
  3920. (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
  3921. if (qla_tgt_mode_enabled(vha) ||
  3922. qla_dual_mode_enabled(vha))
  3923. ha->fw_options[2] |= BIT_11;
  3924. else
  3925. ha->fw_options[2] &= ~BIT_11;
  3926. }
  3927. if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
  3928. IS_QLA28XX(ha)) {
  3929. /*
  3930. * Tell FW to track each exchange to prevent
  3931. * driver from using stale exchange.
  3932. */
  3933. if (qla_tgt_mode_enabled(vha) ||
  3934. qla_dual_mode_enabled(vha))
  3935. ha->fw_options[2] |= BIT_4;
  3936. else
  3937. ha->fw_options[2] &= ~(BIT_4);
  3938. /* Reserve 1/2 of emergency exchanges for ELS.*/
  3939. if (qla2xuseresexchforels)
  3940. ha->fw_options[2] |= BIT_8;
  3941. else
  3942. ha->fw_options[2] &= ~BIT_8;
  3943. /*
  3944. * N2N: set Secure=1 for PLOGI ACC and
  3945. * fw shal not send PRLI after PLOGI Acc
  3946. */
  3947. if (ha->flags.edif_enabled &&
  3948. DBELL_ACTIVE(vha)) {
  3949. ha->fw_options[3] |= BIT_15;
  3950. ha->flags.n2n_fw_acc_sec = 1;
  3951. } else {
  3952. ha->fw_options[3] &= ~BIT_15;
  3953. ha->flags.n2n_fw_acc_sec = 0;
  3954. }
  3955. }
  3956. if (ql2xrdpenable || ha->flags.scm_supported_f ||
  3957. ha->flags.edif_enabled)
  3958. ha->fw_options[1] |= ADD_FO1_ENABLE_PUREX_IOCB;
  3959. /* Enable Async 8130/8131 events -- transceiver insertion/removal */
  3960. if (IS_BPM_RANGE_CAPABLE(ha))
  3961. ha->fw_options[3] |= BIT_10;
  3962. ql_dbg(ql_dbg_init, vha, 0x00e8,
  3963. "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
  3964. __func__, ha->fw_options[1], ha->fw_options[2],
  3965. ha->fw_options[3], vha->host->active_mode);
  3966. if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
  3967. qla2x00_set_fw_options(vha, ha->fw_options);
  3968. /* Update Serial Link options. */
  3969. if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
  3970. return;
  3971. rval = qla2x00_set_serdes_params(vha,
  3972. le16_to_cpu(ha->fw_seriallink_options24[1]),
  3973. le16_to_cpu(ha->fw_seriallink_options24[2]),
  3974. le16_to_cpu(ha->fw_seriallink_options24[3]));
  3975. if (rval != QLA_SUCCESS) {
  3976. ql_log(ql_log_warn, vha, 0x0104,
  3977. "Unable to update Serial Link options (%x).\n", rval);
  3978. }
  3979. }
  3980. void
  3981. qla2x00_config_rings(struct scsi_qla_host *vha)
  3982. {
  3983. struct qla_hw_data *ha = vha->hw;
  3984. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  3985. struct req_que *req = ha->req_q_map[0];
  3986. struct rsp_que *rsp = ha->rsp_q_map[0];
  3987. /* Setup ring parameters in initialization control block. */
  3988. ha->init_cb->request_q_outpointer = cpu_to_le16(0);
  3989. ha->init_cb->response_q_inpointer = cpu_to_le16(0);
  3990. ha->init_cb->request_q_length = cpu_to_le16(req->length);
  3991. ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
  3992. put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
  3993. put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
  3994. wrt_reg_word(ISP_REQ_Q_IN(ha, reg), 0);
  3995. wrt_reg_word(ISP_REQ_Q_OUT(ha, reg), 0);
  3996. wrt_reg_word(ISP_RSP_Q_IN(ha, reg), 0);
  3997. wrt_reg_word(ISP_RSP_Q_OUT(ha, reg), 0);
  3998. rd_reg_word(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
  3999. }
  4000. void
  4001. qla24xx_config_rings(struct scsi_qla_host *vha)
  4002. {
  4003. struct qla_hw_data *ha = vha->hw;
  4004. device_reg_t *reg = ISP_QUE_REG(ha, 0);
  4005. struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
  4006. struct qla_msix_entry *msix;
  4007. struct init_cb_24xx *icb;
  4008. uint16_t rid = 0;
  4009. struct req_que *req = ha->req_q_map[0];
  4010. struct rsp_que *rsp = ha->rsp_q_map[0];
  4011. /* Setup ring parameters in initialization control block. */
  4012. icb = (struct init_cb_24xx *)ha->init_cb;
  4013. icb->request_q_outpointer = cpu_to_le16(0);
  4014. icb->response_q_inpointer = cpu_to_le16(0);
  4015. icb->request_q_length = cpu_to_le16(req->length);
  4016. icb->response_q_length = cpu_to_le16(rsp->length);
  4017. put_unaligned_le64(req->dma, &icb->request_q_address);
  4018. put_unaligned_le64(rsp->dma, &icb->response_q_address);
  4019. /* Setup ATIO queue dma pointers for target mode */
  4020. icb->atio_q_inpointer = cpu_to_le16(0);
  4021. icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
  4022. put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
  4023. if (IS_SHADOW_REG_CAPABLE(ha))
  4024. icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
  4025. if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
  4026. IS_QLA28XX(ha)) {
  4027. icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
  4028. icb->rid = cpu_to_le16(rid);
  4029. if (ha->flags.msix_enabled) {
  4030. msix = &ha->msix_entries[1];
  4031. ql_dbg(ql_dbg_init, vha, 0x0019,
  4032. "Registering vector 0x%x for base que.\n",
  4033. msix->entry);
  4034. icb->msix = cpu_to_le16(msix->entry);
  4035. }
  4036. /* Use alternate PCI bus number */
  4037. if (MSB(rid))
  4038. icb->firmware_options_2 |= cpu_to_le32(BIT_19);
  4039. /* Use alternate PCI devfn */
  4040. if (LSB(rid))
  4041. icb->firmware_options_2 |= cpu_to_le32(BIT_18);
  4042. /* Use Disable MSIX Handshake mode for capable adapters */
  4043. if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
  4044. (ha->flags.msix_enabled)) {
  4045. icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
  4046. ha->flags.disable_msix_handshake = 1;
  4047. ql_dbg(ql_dbg_init, vha, 0x00fe,
  4048. "MSIX Handshake Disable Mode turned on.\n");
  4049. } else {
  4050. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  4051. }
  4052. icb->firmware_options_2 |= cpu_to_le32(BIT_23);
  4053. wrt_reg_dword(&reg->isp25mq.req_q_in, 0);
  4054. wrt_reg_dword(&reg->isp25mq.req_q_out, 0);
  4055. wrt_reg_dword(&reg->isp25mq.rsp_q_in, 0);
  4056. wrt_reg_dword(&reg->isp25mq.rsp_q_out, 0);
  4057. } else {
  4058. wrt_reg_dword(&reg->isp24.req_q_in, 0);
  4059. wrt_reg_dword(&reg->isp24.req_q_out, 0);
  4060. wrt_reg_dword(&reg->isp24.rsp_q_in, 0);
  4061. wrt_reg_dword(&reg->isp24.rsp_q_out, 0);
  4062. }
  4063. qlt_24xx_config_rings(vha);
  4064. /* If the user has configured the speed, set it here */
  4065. if (ha->set_data_rate) {
  4066. ql_dbg(ql_dbg_init, vha, 0x00fd,
  4067. "Speed set by user : %s Gbps \n",
  4068. qla2x00_get_link_speed_str(ha, ha->set_data_rate));
  4069. icb->firmware_options_3 = cpu_to_le32(ha->set_data_rate << 13);
  4070. }
  4071. /* PCI posting */
  4072. rd_reg_word(&ioreg->hccr);
  4073. }
  4074. /**
  4075. * qla2x00_init_rings() - Initializes firmware.
  4076. * @vha: HA context
  4077. *
  4078. * Beginning of request ring has initialization control block already built
  4079. * by nvram config routine.
  4080. *
  4081. * Returns 0 on success.
  4082. */
  4083. int
  4084. qla2x00_init_rings(scsi_qla_host_t *vha)
  4085. {
  4086. int rval;
  4087. unsigned long flags = 0;
  4088. int cnt, que;
  4089. struct qla_hw_data *ha = vha->hw;
  4090. struct req_que *req;
  4091. struct rsp_que *rsp;
  4092. struct mid_init_cb_24xx *mid_init_cb =
  4093. (struct mid_init_cb_24xx *) ha->init_cb;
  4094. spin_lock_irqsave(&ha->hardware_lock, flags);
  4095. /* Clear outstanding commands array. */
  4096. for (que = 0; que < ha->max_req_queues; que++) {
  4097. req = ha->req_q_map[que];
  4098. if (!req || !test_bit(que, ha->req_qid_map))
  4099. continue;
  4100. req->out_ptr = (uint16_t *)(req->ring + req->length);
  4101. *req->out_ptr = 0;
  4102. for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
  4103. req->outstanding_cmds[cnt] = NULL;
  4104. req->current_outstanding_cmd = 1;
  4105. /* Initialize firmware. */
  4106. req->ring_ptr = req->ring;
  4107. req->ring_index = 0;
  4108. req->cnt = req->length;
  4109. }
  4110. for (que = 0; que < ha->max_rsp_queues; que++) {
  4111. rsp = ha->rsp_q_map[que];
  4112. if (!rsp || !test_bit(que, ha->rsp_qid_map))
  4113. continue;
  4114. rsp->in_ptr = (uint16_t *)(rsp->ring + rsp->length);
  4115. *rsp->in_ptr = 0;
  4116. /* Initialize response queue entries */
  4117. if (IS_QLAFX00(ha))
  4118. qlafx00_init_response_q_entries(rsp);
  4119. else
  4120. qla2x00_init_response_q_entries(rsp);
  4121. }
  4122. ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
  4123. ha->tgt.atio_ring_index = 0;
  4124. /* Initialize ATIO queue entries */
  4125. qlt_init_atio_q_entries(vha);
  4126. ha->isp_ops->config_rings(vha);
  4127. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4128. if (IS_QLAFX00(ha)) {
  4129. rval = qlafx00_init_firmware(vha, ha->init_cb_size);
  4130. goto next_check;
  4131. }
  4132. /* Update any ISP specific firmware options before initialization. */
  4133. ha->isp_ops->update_fw_options(vha);
  4134. ql_dbg(ql_dbg_init, vha, 0x00d1,
  4135. "Issue init firmware FW opt 1-3= %08x %08x %08x.\n",
  4136. le32_to_cpu(mid_init_cb->init_cb.firmware_options_1),
  4137. le32_to_cpu(mid_init_cb->init_cb.firmware_options_2),
  4138. le32_to_cpu(mid_init_cb->init_cb.firmware_options_3));
  4139. if (ha->flags.npiv_supported) {
  4140. if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
  4141. ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
  4142. mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
  4143. }
  4144. if (IS_FWI2_CAPABLE(ha)) {
  4145. mid_init_cb->options = cpu_to_le16(BIT_1);
  4146. mid_init_cb->init_cb.execution_throttle =
  4147. cpu_to_le16(ha->cur_fw_xcb_count);
  4148. ha->flags.dport_enabled =
  4149. (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
  4150. BIT_7) != 0;
  4151. ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
  4152. (ha->flags.dport_enabled) ? "enabled" : "disabled");
  4153. /* FA-WWPN Status */
  4154. ha->flags.fawwpn_enabled =
  4155. (le32_to_cpu(mid_init_cb->init_cb.firmware_options_1) &
  4156. BIT_6) != 0;
  4157. ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
  4158. (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
  4159. /* Init_cb will be reused for other command(s). Save a backup copy of port_name */
  4160. memcpy(ha->port_name, ha->init_cb->port_name, WWN_SIZE);
  4161. }
  4162. /* ELS pass through payload is limit by frame size. */
  4163. if (ha->flags.edif_enabled)
  4164. mid_init_cb->init_cb.frame_payload_size = cpu_to_le16(ELS_MAX_PAYLOAD);
  4165. QLA_FW_STARTED(ha);
  4166. rval = qla2x00_init_firmware(vha, ha->init_cb_size);
  4167. next_check:
  4168. if (rval) {
  4169. QLA_FW_STOPPED(ha);
  4170. ql_log(ql_log_fatal, vha, 0x00d2,
  4171. "Init Firmware **** FAILED ****.\n");
  4172. } else {
  4173. ql_dbg(ql_dbg_init, vha, 0x00d3,
  4174. "Init Firmware -- success.\n");
  4175. vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
  4176. }
  4177. return (rval);
  4178. }
  4179. /**
  4180. * qla2x00_fw_ready() - Waits for firmware ready.
  4181. * @vha: HA context
  4182. *
  4183. * Returns 0 on success.
  4184. */
  4185. static int
  4186. qla2x00_fw_ready(scsi_qla_host_t *vha)
  4187. {
  4188. int rval;
  4189. unsigned long wtime, mtime, cs84xx_time;
  4190. uint16_t min_wait; /* Minimum wait time if loop is down */
  4191. uint16_t wait_time; /* Wait time if loop is coming ready */
  4192. uint16_t state[6];
  4193. struct qla_hw_data *ha = vha->hw;
  4194. if (IS_QLAFX00(vha->hw))
  4195. return qlafx00_fw_ready(vha);
  4196. /* Time to wait for loop down */
  4197. if (IS_P3P_TYPE(ha))
  4198. min_wait = 30;
  4199. else
  4200. min_wait = 20;
  4201. /*
  4202. * Firmware should take at most one RATOV to login, plus 5 seconds for
  4203. * our own processing.
  4204. */
  4205. if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
  4206. wait_time = min_wait;
  4207. }
  4208. /* Min wait time if loop down */
  4209. mtime = jiffies + (min_wait * HZ);
  4210. /* wait time before firmware ready */
  4211. wtime = jiffies + (wait_time * HZ);
  4212. /* Wait for ISP to finish LIP */
  4213. if (!vha->flags.init_done)
  4214. ql_log(ql_log_info, vha, 0x801e,
  4215. "Waiting for LIP to complete.\n");
  4216. do {
  4217. memset(state, -1, sizeof(state));
  4218. rval = qla2x00_get_firmware_state(vha, state);
  4219. if (rval == QLA_SUCCESS) {
  4220. if (state[0] < FSTATE_LOSS_OF_SYNC) {
  4221. vha->device_flags &= ~DFLG_NO_CABLE;
  4222. }
  4223. if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
  4224. ql_dbg(ql_dbg_taskm, vha, 0x801f,
  4225. "fw_state=%x 84xx=%x.\n", state[0],
  4226. state[2]);
  4227. if ((state[2] & FSTATE_LOGGED_IN) &&
  4228. (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
  4229. ql_dbg(ql_dbg_taskm, vha, 0x8028,
  4230. "Sending verify iocb.\n");
  4231. cs84xx_time = jiffies;
  4232. rval = qla84xx_init_chip(vha);
  4233. if (rval != QLA_SUCCESS) {
  4234. ql_log(ql_log_warn,
  4235. vha, 0x8007,
  4236. "Init chip failed.\n");
  4237. break;
  4238. }
  4239. /* Add time taken to initialize. */
  4240. cs84xx_time = jiffies - cs84xx_time;
  4241. wtime += cs84xx_time;
  4242. mtime += cs84xx_time;
  4243. ql_dbg(ql_dbg_taskm, vha, 0x8008,
  4244. "Increasing wait time by %ld. "
  4245. "New time %ld.\n", cs84xx_time,
  4246. wtime);
  4247. }
  4248. } else if (state[0] == FSTATE_READY) {
  4249. ql_dbg(ql_dbg_taskm, vha, 0x8037,
  4250. "F/W Ready - OK.\n");
  4251. qla2x00_get_retry_cnt(vha, &ha->retry_count,
  4252. &ha->login_timeout, &ha->r_a_tov);
  4253. rval = QLA_SUCCESS;
  4254. break;
  4255. }
  4256. rval = QLA_FUNCTION_FAILED;
  4257. if (atomic_read(&vha->loop_down_timer) &&
  4258. state[0] != FSTATE_READY) {
  4259. /* Loop down. Timeout on min_wait for states
  4260. * other than Wait for Login.
  4261. */
  4262. if (time_after_eq(jiffies, mtime)) {
  4263. ql_log(ql_log_info, vha, 0x8038,
  4264. "Cable is unplugged...\n");
  4265. vha->device_flags |= DFLG_NO_CABLE;
  4266. break;
  4267. }
  4268. }
  4269. } else {
  4270. /* Mailbox cmd failed. Timeout on min_wait. */
  4271. if (time_after_eq(jiffies, mtime) ||
  4272. ha->flags.isp82xx_fw_hung)
  4273. break;
  4274. }
  4275. if (time_after_eq(jiffies, wtime))
  4276. break;
  4277. /* Delay for a while */
  4278. msleep(500);
  4279. } while (1);
  4280. ql_dbg(ql_dbg_taskm, vha, 0x803a,
  4281. "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
  4282. state[1], state[2], state[3], state[4], state[5], jiffies);
  4283. if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
  4284. ql_log(ql_log_warn, vha, 0x803b,
  4285. "Firmware ready **** FAILED ****.\n");
  4286. }
  4287. return (rval);
  4288. }
  4289. /*
  4290. * qla2x00_configure_hba
  4291. * Setup adapter context.
  4292. *
  4293. * Input:
  4294. * ha = adapter state pointer.
  4295. *
  4296. * Returns:
  4297. * 0 = success
  4298. *
  4299. * Context:
  4300. * Kernel context.
  4301. */
  4302. static int
  4303. qla2x00_configure_hba(scsi_qla_host_t *vha)
  4304. {
  4305. int rval;
  4306. uint16_t loop_id;
  4307. uint16_t topo;
  4308. uint16_t sw_cap;
  4309. uint8_t al_pa;
  4310. uint8_t area;
  4311. uint8_t domain;
  4312. char connect_type[22];
  4313. struct qla_hw_data *ha = vha->hw;
  4314. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  4315. port_id_t id;
  4316. unsigned long flags;
  4317. /* Get host addresses. */
  4318. rval = qla2x00_get_adapter_id(vha,
  4319. &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
  4320. if (rval != QLA_SUCCESS) {
  4321. if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
  4322. IS_CNA_CAPABLE(ha) ||
  4323. (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
  4324. ql_dbg(ql_dbg_disc, vha, 0x2008,
  4325. "Loop is in a transition state.\n");
  4326. } else {
  4327. ql_log(ql_log_warn, vha, 0x2009,
  4328. "Unable to get host loop ID.\n");
  4329. if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
  4330. (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
  4331. ql_log(ql_log_warn, vha, 0x1151,
  4332. "Doing link init.\n");
  4333. if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
  4334. return rval;
  4335. }
  4336. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  4337. }
  4338. return (rval);
  4339. }
  4340. if (topo == 4) {
  4341. ql_log(ql_log_info, vha, 0x200a,
  4342. "Cannot get topology - retrying.\n");
  4343. return (QLA_FUNCTION_FAILED);
  4344. }
  4345. vha->loop_id = loop_id;
  4346. /* initialize */
  4347. ha->min_external_loopid = SNS_FIRST_LOOP_ID;
  4348. ha->operating_mode = LOOP;
  4349. switch (topo) {
  4350. case 0:
  4351. ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
  4352. ha->switch_cap = 0;
  4353. ha->current_topology = ISP_CFG_NL;
  4354. strcpy(connect_type, "(Loop)");
  4355. break;
  4356. case 1:
  4357. ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
  4358. ha->switch_cap = sw_cap;
  4359. ha->current_topology = ISP_CFG_FL;
  4360. strcpy(connect_type, "(FL_Port)");
  4361. break;
  4362. case 2:
  4363. ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
  4364. ha->switch_cap = 0;
  4365. ha->operating_mode = P2P;
  4366. ha->current_topology = ISP_CFG_N;
  4367. strcpy(connect_type, "(N_Port-to-N_Port)");
  4368. break;
  4369. case 3:
  4370. ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
  4371. ha->switch_cap = sw_cap;
  4372. ha->operating_mode = P2P;
  4373. ha->current_topology = ISP_CFG_F;
  4374. strcpy(connect_type, "(F_Port)");
  4375. break;
  4376. default:
  4377. ql_dbg(ql_dbg_disc, vha, 0x200f,
  4378. "HBA in unknown topology %x, using NL.\n", topo);
  4379. ha->switch_cap = 0;
  4380. ha->current_topology = ISP_CFG_NL;
  4381. strcpy(connect_type, "(Loop)");
  4382. break;
  4383. }
  4384. /* Save Host port and loop ID. */
  4385. /* byte order - Big Endian */
  4386. id.b.domain = domain;
  4387. id.b.area = area;
  4388. id.b.al_pa = al_pa;
  4389. id.b.rsvd_1 = 0;
  4390. spin_lock_irqsave(&ha->hardware_lock, flags);
  4391. if (vha->hw->flags.edif_enabled) {
  4392. if (topo != 2)
  4393. qla_update_host_map(vha, id);
  4394. } else if (!(topo == 2 && ha->flags.n2n_bigger))
  4395. qla_update_host_map(vha, id);
  4396. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  4397. if (!vha->flags.init_done)
  4398. ql_log(ql_log_info, vha, 0x2010,
  4399. "Topology - %s, Host Loop address 0x%x.\n",
  4400. connect_type, vha->loop_id);
  4401. return(rval);
  4402. }
  4403. inline void
  4404. qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
  4405. const char *def)
  4406. {
  4407. char *st, *en;
  4408. uint16_t index;
  4409. uint64_t zero[2] = { 0 };
  4410. struct qla_hw_data *ha = vha->hw;
  4411. int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
  4412. !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
  4413. if (len > sizeof(zero))
  4414. len = sizeof(zero);
  4415. if (memcmp(model, &zero, len) != 0) {
  4416. memcpy(ha->model_number, model, len);
  4417. st = en = ha->model_number;
  4418. en += len - 1;
  4419. while (en > st) {
  4420. if (*en != 0x20 && *en != 0x00)
  4421. break;
  4422. *en-- = '\0';
  4423. }
  4424. index = (ha->pdev->subsystem_device & 0xff);
  4425. if (use_tbl &&
  4426. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  4427. index < QLA_MODEL_NAMES)
  4428. strscpy(ha->model_desc,
  4429. qla2x00_model_name[index * 2 + 1],
  4430. sizeof(ha->model_desc));
  4431. } else {
  4432. index = (ha->pdev->subsystem_device & 0xff);
  4433. if (use_tbl &&
  4434. ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
  4435. index < QLA_MODEL_NAMES) {
  4436. strscpy(ha->model_number,
  4437. qla2x00_model_name[index * 2],
  4438. sizeof(ha->model_number));
  4439. strscpy(ha->model_desc,
  4440. qla2x00_model_name[index * 2 + 1],
  4441. sizeof(ha->model_desc));
  4442. } else {
  4443. strscpy(ha->model_number, def,
  4444. sizeof(ha->model_number));
  4445. }
  4446. }
  4447. if (IS_FWI2_CAPABLE(ha))
  4448. qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
  4449. sizeof(ha->model_desc));
  4450. }
  4451. /* On sparc systems, obtain port and node WWN from firmware
  4452. * properties.
  4453. */
  4454. static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
  4455. {
  4456. #ifdef CONFIG_SPARC
  4457. struct qla_hw_data *ha = vha->hw;
  4458. struct pci_dev *pdev = ha->pdev;
  4459. struct device_node *dp = pci_device_to_OF_node(pdev);
  4460. const u8 *val;
  4461. int len;
  4462. val = of_get_property(dp, "port-wwn", &len);
  4463. if (val && len >= WWN_SIZE)
  4464. memcpy(nv->port_name, val, WWN_SIZE);
  4465. val = of_get_property(dp, "node-wwn", &len);
  4466. if (val && len >= WWN_SIZE)
  4467. memcpy(nv->node_name, val, WWN_SIZE);
  4468. #endif
  4469. }
  4470. /*
  4471. * NVRAM configuration for ISP 2xxx
  4472. *
  4473. * Input:
  4474. * ha = adapter block pointer.
  4475. *
  4476. * Output:
  4477. * initialization control block in response_ring
  4478. * host adapters parameters in host adapter block
  4479. *
  4480. * Returns:
  4481. * 0 = success.
  4482. */
  4483. int
  4484. qla2x00_nvram_config(scsi_qla_host_t *vha)
  4485. {
  4486. int rval;
  4487. uint8_t chksum = 0;
  4488. uint16_t cnt;
  4489. uint8_t *dptr1, *dptr2;
  4490. struct qla_hw_data *ha = vha->hw;
  4491. init_cb_t *icb = ha->init_cb;
  4492. nvram_t *nv = ha->nvram;
  4493. uint8_t *ptr = ha->nvram;
  4494. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  4495. rval = QLA_SUCCESS;
  4496. /* Determine NVRAM starting address. */
  4497. ha->nvram_size = sizeof(*nv);
  4498. ha->nvram_base = 0;
  4499. if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
  4500. if ((rd_reg_word(&reg->ctrl_status) >> 14) == 1)
  4501. ha->nvram_base = 0x80;
  4502. /* Get NVRAM data and calculate checksum. */
  4503. ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
  4504. for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
  4505. chksum += *ptr++;
  4506. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
  4507. "Contents of NVRAM.\n");
  4508. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
  4509. nv, ha->nvram_size);
  4510. /* Bad NVRAM data, set defaults parameters. */
  4511. if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
  4512. nv->nvram_version < 1) {
  4513. /* Reset NVRAM data. */
  4514. ql_log(ql_log_warn, vha, 0x0064,
  4515. "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
  4516. chksum, nv->id, nv->nvram_version);
  4517. ql_log(ql_log_warn, vha, 0x0065,
  4518. "Falling back to "
  4519. "functioning (yet invalid -- WWPN) defaults.\n");
  4520. /*
  4521. * Set default initialization control block.
  4522. */
  4523. memset(nv, 0, ha->nvram_size);
  4524. nv->parameter_block_version = ICB_VERSION;
  4525. if (IS_QLA23XX(ha)) {
  4526. nv->firmware_options[0] = BIT_2 | BIT_1;
  4527. nv->firmware_options[1] = BIT_7 | BIT_5;
  4528. nv->add_firmware_options[0] = BIT_5;
  4529. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  4530. nv->frame_payload_size = cpu_to_le16(2048);
  4531. nv->special_options[1] = BIT_7;
  4532. } else if (IS_QLA2200(ha)) {
  4533. nv->firmware_options[0] = BIT_2 | BIT_1;
  4534. nv->firmware_options[1] = BIT_7 | BIT_5;
  4535. nv->add_firmware_options[0] = BIT_5;
  4536. nv->add_firmware_options[1] = BIT_5 | BIT_4;
  4537. nv->frame_payload_size = cpu_to_le16(1024);
  4538. } else if (IS_QLA2100(ha)) {
  4539. nv->firmware_options[0] = BIT_3 | BIT_1;
  4540. nv->firmware_options[1] = BIT_5;
  4541. nv->frame_payload_size = cpu_to_le16(1024);
  4542. }
  4543. nv->max_iocb_allocation = cpu_to_le16(256);
  4544. nv->execution_throttle = cpu_to_le16(16);
  4545. nv->retry_count = 8;
  4546. nv->retry_delay = 1;
  4547. nv->port_name[0] = 33;
  4548. nv->port_name[3] = 224;
  4549. nv->port_name[4] = 139;
  4550. qla2xxx_nvram_wwn_from_ofw(vha, nv);
  4551. nv->login_timeout = 4;
  4552. /*
  4553. * Set default host adapter parameters
  4554. */
  4555. nv->host_p[1] = BIT_2;
  4556. nv->reset_delay = 5;
  4557. nv->port_down_retry_count = 8;
  4558. nv->max_luns_per_target = cpu_to_le16(8);
  4559. nv->link_down_timeout = 60;
  4560. rval = 1;
  4561. }
  4562. /* Reset Initialization control block */
  4563. memset(icb, 0, ha->init_cb_size);
  4564. /*
  4565. * Setup driver NVRAM options.
  4566. */
  4567. nv->firmware_options[0] |= (BIT_6 | BIT_1);
  4568. nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
  4569. nv->firmware_options[1] |= (BIT_5 | BIT_0);
  4570. nv->firmware_options[1] &= ~BIT_4;
  4571. if (IS_QLA23XX(ha)) {
  4572. nv->firmware_options[0] |= BIT_2;
  4573. nv->firmware_options[0] &= ~BIT_3;
  4574. nv->special_options[0] &= ~BIT_6;
  4575. nv->add_firmware_options[1] |= BIT_5 | BIT_4;
  4576. if (IS_QLA2300(ha)) {
  4577. if (ha->fb_rev == FPM_2310) {
  4578. strcpy(ha->model_number, "QLA2310");
  4579. } else {
  4580. strcpy(ha->model_number, "QLA2300");
  4581. }
  4582. } else {
  4583. qla2x00_set_model_info(vha, nv->model_number,
  4584. sizeof(nv->model_number), "QLA23xx");
  4585. }
  4586. } else if (IS_QLA2200(ha)) {
  4587. nv->firmware_options[0] |= BIT_2;
  4588. /*
  4589. * 'Point-to-point preferred, else loop' is not a safe
  4590. * connection mode setting.
  4591. */
  4592. if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
  4593. (BIT_5 | BIT_4)) {
  4594. /* Force 'loop preferred, else point-to-point'. */
  4595. nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
  4596. nv->add_firmware_options[0] |= BIT_5;
  4597. }
  4598. strcpy(ha->model_number, "QLA22xx");
  4599. } else /*if (IS_QLA2100(ha))*/ {
  4600. strcpy(ha->model_number, "QLA2100");
  4601. }
  4602. /*
  4603. * Copy over NVRAM RISC parameter block to initialization control block.
  4604. */
  4605. dptr1 = (uint8_t *)icb;
  4606. dptr2 = (uint8_t *)&nv->parameter_block_version;
  4607. cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
  4608. while (cnt--)
  4609. *dptr1++ = *dptr2++;
  4610. /* Copy 2nd half. */
  4611. dptr1 = (uint8_t *)icb->add_firmware_options;
  4612. cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
  4613. while (cnt--)
  4614. *dptr1++ = *dptr2++;
  4615. ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
  4616. /* Use alternate WWN? */
  4617. if (nv->host_p[1] & BIT_7) {
  4618. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  4619. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  4620. }
  4621. /* Prepare nodename */
  4622. if ((icb->firmware_options[1] & BIT_6) == 0) {
  4623. /*
  4624. * Firmware will apply the following mask if the nodename was
  4625. * not provided.
  4626. */
  4627. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  4628. icb->node_name[0] &= 0xF0;
  4629. }
  4630. /*
  4631. * Set host adapter parameters.
  4632. */
  4633. /*
  4634. * BIT_7 in the host-parameters section allows for modification to
  4635. * internal driver logging.
  4636. */
  4637. if (nv->host_p[0] & BIT_7)
  4638. ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
  4639. ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
  4640. /* Always load RISC code on non ISP2[12]00 chips. */
  4641. if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
  4642. ha->flags.disable_risc_code_load = 0;
  4643. ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
  4644. ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
  4645. ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
  4646. ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
  4647. ha->flags.disable_serdes = 0;
  4648. ha->operating_mode =
  4649. (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
  4650. memcpy(ha->fw_seriallink_options, nv->seriallink_options,
  4651. sizeof(ha->fw_seriallink_options));
  4652. /* save HBA serial number */
  4653. ha->serial0 = icb->port_name[5];
  4654. ha->serial1 = icb->port_name[6];
  4655. ha->serial2 = icb->port_name[7];
  4656. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  4657. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  4658. icb->execution_throttle = cpu_to_le16(0xFFFF);
  4659. ha->retry_count = nv->retry_count;
  4660. /* Set minimum login_timeout to 4 seconds. */
  4661. if (nv->login_timeout != ql2xlogintimeout)
  4662. nv->login_timeout = ql2xlogintimeout;
  4663. if (nv->login_timeout < 4)
  4664. nv->login_timeout = 4;
  4665. ha->login_timeout = nv->login_timeout;
  4666. /* Set minimum RATOV to 100 tenths of a second. */
  4667. ha->r_a_tov = 100;
  4668. ha->loop_reset_delay = nv->reset_delay;
  4669. /* Link Down Timeout = 0:
  4670. *
  4671. * When Port Down timer expires we will start returning
  4672. * I/O's to OS with "DID_NO_CONNECT".
  4673. *
  4674. * Link Down Timeout != 0:
  4675. *
  4676. * The driver waits for the link to come up after link down
  4677. * before returning I/Os to OS with "DID_NO_CONNECT".
  4678. */
  4679. if (nv->link_down_timeout == 0) {
  4680. ha->loop_down_abort_time =
  4681. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  4682. } else {
  4683. ha->link_down_timeout = nv->link_down_timeout;
  4684. ha->loop_down_abort_time =
  4685. (LOOP_DOWN_TIME - ha->link_down_timeout);
  4686. }
  4687. /*
  4688. * Need enough time to try and get the port back.
  4689. */
  4690. ha->port_down_retry_count = nv->port_down_retry_count;
  4691. if (qlport_down_retry)
  4692. ha->port_down_retry_count = qlport_down_retry;
  4693. /* Set login_retry_count */
  4694. ha->login_retry_count = nv->retry_count;
  4695. if (ha->port_down_retry_count == nv->port_down_retry_count &&
  4696. ha->port_down_retry_count > 3)
  4697. ha->login_retry_count = ha->port_down_retry_count;
  4698. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  4699. ha->login_retry_count = ha->port_down_retry_count;
  4700. if (ql2xloginretrycount)
  4701. ha->login_retry_count = ql2xloginretrycount;
  4702. icb->lun_enables = cpu_to_le16(0);
  4703. icb->command_resource_count = 0;
  4704. icb->immediate_notify_resource_count = 0;
  4705. icb->timeout = cpu_to_le16(0);
  4706. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  4707. /* Enable RIO */
  4708. icb->firmware_options[0] &= ~BIT_3;
  4709. icb->add_firmware_options[0] &=
  4710. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4711. icb->add_firmware_options[0] |= BIT_2;
  4712. icb->response_accumulation_timer = 3;
  4713. icb->interrupt_delay_timer = 5;
  4714. vha->flags.process_response_queue = 1;
  4715. } else {
  4716. /* Enable ZIO. */
  4717. if (!vha->flags.init_done) {
  4718. ha->zio_mode = icb->add_firmware_options[0] &
  4719. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4720. ha->zio_timer = icb->interrupt_delay_timer ?
  4721. icb->interrupt_delay_timer : 2;
  4722. }
  4723. icb->add_firmware_options[0] &=
  4724. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
  4725. vha->flags.process_response_queue = 0;
  4726. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  4727. ha->zio_mode = QLA_ZIO_MODE_6;
  4728. ql_log(ql_log_info, vha, 0x0068,
  4729. "ZIO mode %d enabled; timer delay (%d us).\n",
  4730. ha->zio_mode, ha->zio_timer * 100);
  4731. icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
  4732. icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
  4733. vha->flags.process_response_queue = 1;
  4734. }
  4735. }
  4736. if (rval) {
  4737. ql_log(ql_log_warn, vha, 0x0069,
  4738. "NVRAM configuration failed.\n");
  4739. }
  4740. return (rval);
  4741. }
  4742. void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
  4743. {
  4744. int old_state;
  4745. old_state = atomic_read(&fcport->state);
  4746. atomic_set(&fcport->state, state);
  4747. /* Don't print state transitions during initial allocation of fcport */
  4748. if (old_state && old_state != state) {
  4749. ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
  4750. "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
  4751. fcport->port_name, port_state_str[old_state],
  4752. port_state_str[state], fcport->d_id.b.domain,
  4753. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  4754. }
  4755. }
  4756. /**
  4757. * qla2x00_alloc_fcport() - Allocate a generic fcport.
  4758. * @vha: HA context
  4759. * @flags: allocation flags
  4760. *
  4761. * Returns a pointer to the allocated fcport, or NULL, if none available.
  4762. */
  4763. fc_port_t *
  4764. qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
  4765. {
  4766. fc_port_t *fcport;
  4767. fcport = kzalloc_obj(fc_port_t, flags);
  4768. if (!fcport)
  4769. return NULL;
  4770. fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
  4771. sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
  4772. flags);
  4773. if (!fcport->ct_desc.ct_sns) {
  4774. ql_log(ql_log_warn, vha, 0xd049,
  4775. "Failed to allocate ct_sns request.\n");
  4776. kfree(fcport);
  4777. return NULL;
  4778. }
  4779. /* Setup fcport template structure. */
  4780. fcport->vha = vha;
  4781. fcport->port_type = FCT_UNKNOWN;
  4782. fcport->loop_id = FC_NO_LOOP_ID;
  4783. qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
  4784. fcport->supported_classes = FC_COS_UNSPECIFIED;
  4785. fcport->fp_speed = PORT_SPEED_UNKNOWN;
  4786. fcport->disc_state = DSC_DELETED;
  4787. fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
  4788. fcport->deleted = QLA_SESS_DELETED;
  4789. fcport->login_retry = vha->hw->login_retry_count;
  4790. fcport->chip_reset = vha->hw->base_qpair->chip_reset;
  4791. fcport->logout_on_delete = 1;
  4792. fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
  4793. fcport->tgt_short_link_down_cnt = 0;
  4794. fcport->dev_loss_tmo = 0;
  4795. if (!fcport->ct_desc.ct_sns) {
  4796. ql_log(ql_log_warn, vha, 0xd049,
  4797. "Failed to allocate ct_sns request.\n");
  4798. kfree(fcport);
  4799. return NULL;
  4800. }
  4801. INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
  4802. INIT_WORK(&fcport->free_work, qlt_free_session_done);
  4803. INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
  4804. INIT_LIST_HEAD(&fcport->gnl_entry);
  4805. INIT_LIST_HEAD(&fcport->list);
  4806. INIT_LIST_HEAD(&fcport->unsol_ctx_head);
  4807. INIT_LIST_HEAD(&fcport->sess_cmd_list);
  4808. spin_lock_init(&fcport->sess_cmd_lock);
  4809. spin_lock_init(&fcport->edif.sa_list_lock);
  4810. INIT_LIST_HEAD(&fcport->edif.tx_sa_list);
  4811. INIT_LIST_HEAD(&fcport->edif.rx_sa_list);
  4812. spin_lock_init(&fcport->edif.indx_list_lock);
  4813. INIT_LIST_HEAD(&fcport->edif.edif_indx_list);
  4814. return fcport;
  4815. }
  4816. void
  4817. qla2x00_free_fcport(fc_port_t *fcport)
  4818. {
  4819. if (fcport->ct_desc.ct_sns) {
  4820. dma_free_coherent(&fcport->vha->hw->pdev->dev,
  4821. sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
  4822. fcport->ct_desc.ct_sns_dma);
  4823. fcport->ct_desc.ct_sns = NULL;
  4824. }
  4825. qla_edif_flush_sa_ctl_lists(fcport);
  4826. list_del(&fcport->list);
  4827. qla2x00_clear_loop_id(fcport);
  4828. qla_edif_list_del(fcport);
  4829. kfree(fcport);
  4830. }
  4831. static void qla_get_login_template(scsi_qla_host_t *vha)
  4832. {
  4833. struct qla_hw_data *ha = vha->hw;
  4834. int rval;
  4835. u32 *bp, sz;
  4836. __be32 *q;
  4837. memset(ha->init_cb, 0, ha->init_cb_size);
  4838. sz = min_t(int, sizeof(struct fc_els_flogi), ha->init_cb_size);
  4839. rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
  4840. ha->init_cb, sz);
  4841. if (rval != QLA_SUCCESS) {
  4842. ql_dbg(ql_dbg_init, vha, 0x00d1,
  4843. "PLOGI ELS param read fail.\n");
  4844. return;
  4845. }
  4846. q = (__be32 *)&ha->plogi_els_payld.fl_csp;
  4847. bp = (uint32_t *)ha->init_cb;
  4848. cpu_to_be32_array(q, bp, sz / 4);
  4849. ha->flags.plogi_template_valid = 1;
  4850. }
  4851. /*
  4852. * qla2x00_configure_loop
  4853. * Updates Fibre Channel Device Database with what is actually on loop.
  4854. *
  4855. * Input:
  4856. * ha = adapter block pointer.
  4857. *
  4858. * Returns:
  4859. * 0 = success.
  4860. * 1 = error.
  4861. * 2 = database was full and device was not configured.
  4862. */
  4863. static int
  4864. qla2x00_configure_loop(scsi_qla_host_t *vha)
  4865. {
  4866. int rval;
  4867. unsigned long flags, save_flags;
  4868. struct qla_hw_data *ha = vha->hw;
  4869. rval = QLA_SUCCESS;
  4870. /* Get Initiator ID */
  4871. if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
  4872. rval = qla2x00_configure_hba(vha);
  4873. if (rval != QLA_SUCCESS) {
  4874. ql_dbg(ql_dbg_disc, vha, 0x2013,
  4875. "Unable to configure HBA.\n");
  4876. return (rval);
  4877. }
  4878. }
  4879. save_flags = flags = vha->dpc_flags;
  4880. ql_dbg(ql_dbg_disc, vha, 0x2014,
  4881. "Configure loop -- dpc flags = 0x%lx.\n", flags);
  4882. /*
  4883. * If we have both an RSCN and PORT UPDATE pending then handle them
  4884. * both at the same time.
  4885. */
  4886. clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4887. clear_bit(RSCN_UPDATE, &vha->dpc_flags);
  4888. qla2x00_get_data_rate(vha);
  4889. qla_get_login_template(vha);
  4890. /* Determine what we need to do */
  4891. if ((ha->current_topology == ISP_CFG_FL ||
  4892. ha->current_topology == ISP_CFG_F) &&
  4893. (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
  4894. set_bit(RSCN_UPDATE, &flags);
  4895. clear_bit(LOCAL_LOOP_UPDATE, &flags);
  4896. } else if (ha->current_topology == ISP_CFG_NL ||
  4897. ha->current_topology == ISP_CFG_N) {
  4898. clear_bit(RSCN_UPDATE, &flags);
  4899. set_bit(LOCAL_LOOP_UPDATE, &flags);
  4900. } else if (!vha->flags.online ||
  4901. (test_bit(ABORT_ISP_ACTIVE, &flags))) {
  4902. set_bit(RSCN_UPDATE, &flags);
  4903. set_bit(LOCAL_LOOP_UPDATE, &flags);
  4904. }
  4905. if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
  4906. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  4907. ql_dbg(ql_dbg_disc, vha, 0x2015,
  4908. "Loop resync needed, failing.\n");
  4909. rval = QLA_FUNCTION_FAILED;
  4910. } else
  4911. rval = qla2x00_configure_local_loop(vha);
  4912. }
  4913. if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
  4914. if (LOOP_TRANSITION(vha)) {
  4915. ql_dbg(ql_dbg_disc, vha, 0x2099,
  4916. "Needs RSCN update and loop transition.\n");
  4917. rval = QLA_FUNCTION_FAILED;
  4918. }
  4919. else
  4920. rval = qla2x00_configure_fabric(vha);
  4921. }
  4922. if (rval == QLA_SUCCESS) {
  4923. if (atomic_read(&vha->loop_down_timer) ||
  4924. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  4925. rval = QLA_FUNCTION_FAILED;
  4926. } else {
  4927. atomic_set(&vha->loop_state, LOOP_READY);
  4928. ql_dbg(ql_dbg_disc, vha, 0x2069,
  4929. "LOOP READY.\n");
  4930. ha->flags.fw_init_done = 1;
  4931. /*
  4932. * use link up to wake up app to get ready for
  4933. * authentication.
  4934. */
  4935. if (ha->flags.edif_enabled && DBELL_INACTIVE(vha))
  4936. qla2x00_post_aen_work(vha, FCH_EVT_LINKUP,
  4937. ha->link_data_rate);
  4938. /*
  4939. * Process any ATIO queue entries that came in
  4940. * while we weren't online.
  4941. */
  4942. if (qla_tgt_mode_enabled(vha) ||
  4943. qla_dual_mode_enabled(vha)) {
  4944. spin_lock_irqsave(&ha->tgt.atio_lock, flags);
  4945. qlt_24xx_process_atio_queue(vha, 0);
  4946. spin_unlock_irqrestore(&ha->tgt.atio_lock,
  4947. flags);
  4948. }
  4949. }
  4950. }
  4951. if (rval) {
  4952. ql_dbg(ql_dbg_disc, vha, 0x206a,
  4953. "%s *** FAILED ***.\n", __func__);
  4954. } else {
  4955. ql_dbg(ql_dbg_disc, vha, 0x206b,
  4956. "%s: exiting normally. local port wwpn %8phN id %06x)\n",
  4957. __func__, vha->port_name, vha->d_id.b24);
  4958. }
  4959. /* Restore state if a resync event occurred during processing */
  4960. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
  4961. if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
  4962. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4963. if (test_bit(RSCN_UPDATE, &save_flags)) {
  4964. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  4965. }
  4966. }
  4967. return (rval);
  4968. }
  4969. static int qla2x00_configure_n2n_loop(scsi_qla_host_t *vha)
  4970. {
  4971. unsigned long flags;
  4972. fc_port_t *fcport;
  4973. ql_dbg(ql_dbg_disc, vha, 0x206a, "%s %d.\n", __func__, __LINE__);
  4974. if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags))
  4975. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  4976. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  4977. if (fcport->n2n_flag) {
  4978. qla24xx_fcport_handle_login(vha, fcport);
  4979. return QLA_SUCCESS;
  4980. }
  4981. }
  4982. spin_lock_irqsave(&vha->work_lock, flags);
  4983. vha->scan.scan_retry++;
  4984. spin_unlock_irqrestore(&vha->work_lock, flags);
  4985. if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
  4986. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  4987. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  4988. }
  4989. return QLA_FUNCTION_FAILED;
  4990. }
  4991. static void
  4992. qla_reinitialize_link(scsi_qla_host_t *vha)
  4993. {
  4994. int rval;
  4995. atomic_set(&vha->loop_state, LOOP_DOWN);
  4996. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  4997. rval = qla2x00_full_login_lip(vha);
  4998. if (rval == QLA_SUCCESS) {
  4999. ql_dbg(ql_dbg_disc, vha, 0xd050, "Link reinitialized\n");
  5000. } else {
  5001. ql_dbg(ql_dbg_disc, vha, 0xd051,
  5002. "Link reinitialization failed (%d)\n", rval);
  5003. }
  5004. }
  5005. /*
  5006. * qla2x00_configure_local_loop
  5007. * Updates Fibre Channel Device Database with local loop devices.
  5008. *
  5009. * Input:
  5010. * ha = adapter block pointer.
  5011. *
  5012. * Returns:
  5013. * 0 = success.
  5014. */
  5015. static int
  5016. qla2x00_configure_local_loop(scsi_qla_host_t *vha)
  5017. {
  5018. int rval, rval2;
  5019. int found;
  5020. fc_port_t *fcport, *new_fcport;
  5021. uint16_t index;
  5022. uint16_t entries;
  5023. struct gid_list_info *gid;
  5024. uint16_t loop_id;
  5025. uint8_t domain, area, al_pa;
  5026. struct qla_hw_data *ha = vha->hw;
  5027. unsigned long flags;
  5028. /* Inititae N2N login. */
  5029. if (N2N_TOPO(ha))
  5030. return qla2x00_configure_n2n_loop(vha);
  5031. new_fcport = NULL;
  5032. entries = MAX_FIBRE_DEVICES_LOOP;
  5033. /* Get list of logged in devices. */
  5034. memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
  5035. rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
  5036. &entries);
  5037. if (rval != QLA_SUCCESS)
  5038. goto err;
  5039. ql_dbg(ql_dbg_disc, vha, 0x2011,
  5040. "Entries in ID list (%d).\n", entries);
  5041. ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
  5042. ha->gid_list, entries * sizeof(*ha->gid_list));
  5043. if (entries == 0) {
  5044. spin_lock_irqsave(&vha->work_lock, flags);
  5045. vha->scan.scan_retry++;
  5046. spin_unlock_irqrestore(&vha->work_lock, flags);
  5047. if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
  5048. u8 loop_map_entries = 0;
  5049. int rc;
  5050. rc = qla2x00_get_fcal_position_map(vha, NULL,
  5051. &loop_map_entries);
  5052. if (rc == QLA_SUCCESS && loop_map_entries > 1) {
  5053. /*
  5054. * There are devices that are still not logged
  5055. * in. Reinitialize to give them a chance.
  5056. */
  5057. qla_reinitialize_link(vha);
  5058. return QLA_FUNCTION_FAILED;
  5059. }
  5060. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  5061. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5062. }
  5063. } else {
  5064. vha->scan.scan_retry = 0;
  5065. }
  5066. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  5067. fcport->scan_state = QLA_FCPORT_SCAN;
  5068. }
  5069. /* Allocate temporary fcport for any new fcports discovered. */
  5070. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  5071. if (new_fcport == NULL) {
  5072. ql_log(ql_log_warn, vha, 0x2012,
  5073. "Memory allocation failed for fcport.\n");
  5074. rval = QLA_MEMORY_ALLOC_FAILED;
  5075. goto err;
  5076. }
  5077. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  5078. /* Add devices to port list. */
  5079. gid = ha->gid_list;
  5080. for (index = 0; index < entries; index++) {
  5081. domain = gid->domain;
  5082. area = gid->area;
  5083. al_pa = gid->al_pa;
  5084. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  5085. loop_id = gid->loop_id_2100;
  5086. else
  5087. loop_id = le16_to_cpu(gid->loop_id);
  5088. gid = (void *)gid + ha->gid_list_info_size;
  5089. /* Bypass reserved domain fields. */
  5090. if ((domain & 0xf0) == 0xf0)
  5091. continue;
  5092. /* Bypass if not same domain and area of adapter. */
  5093. if (area && domain && ((area != vha->d_id.b.area) ||
  5094. (domain != vha->d_id.b.domain)) &&
  5095. (ha->current_topology == ISP_CFG_NL))
  5096. continue;
  5097. /* Bypass invalid local loop ID. */
  5098. if (loop_id > LAST_LOCAL_LOOP_ID)
  5099. continue;
  5100. memset(new_fcport->port_name, 0, WWN_SIZE);
  5101. /* Fill in member data. */
  5102. new_fcport->d_id.b.domain = domain;
  5103. new_fcport->d_id.b.area = area;
  5104. new_fcport->d_id.b.al_pa = al_pa;
  5105. new_fcport->loop_id = loop_id;
  5106. new_fcport->scan_state = QLA_FCPORT_FOUND;
  5107. rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
  5108. if (rval2 != QLA_SUCCESS) {
  5109. ql_dbg(ql_dbg_disc, vha, 0x2097,
  5110. "Failed to retrieve fcport information "
  5111. "-- get_port_database=%x, loop_id=0x%04x.\n",
  5112. rval2, new_fcport->loop_id);
  5113. /* Skip retry if N2N */
  5114. if (ha->current_topology != ISP_CFG_N) {
  5115. ql_dbg(ql_dbg_disc, vha, 0x2105,
  5116. "Scheduling resync.\n");
  5117. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5118. continue;
  5119. }
  5120. }
  5121. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  5122. /* Check for matching device in port list. */
  5123. found = 0;
  5124. fcport = NULL;
  5125. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  5126. if (memcmp(new_fcport->port_name, fcport->port_name,
  5127. WWN_SIZE))
  5128. continue;
  5129. fcport->flags &= ~FCF_FABRIC_DEVICE;
  5130. fcport->loop_id = new_fcport->loop_id;
  5131. fcport->port_type = new_fcport->port_type;
  5132. fcport->d_id.b24 = new_fcport->d_id.b24;
  5133. memcpy(fcport->node_name, new_fcport->node_name,
  5134. WWN_SIZE);
  5135. fcport->scan_state = QLA_FCPORT_FOUND;
  5136. if (fcport->login_retry == 0) {
  5137. fcport->login_retry = vha->hw->login_retry_count;
  5138. ql_dbg(ql_dbg_disc, vha, 0x2135,
  5139. "Port login retry %8phN, lid 0x%04x retry cnt=%d.\n",
  5140. fcport->port_name, fcport->loop_id,
  5141. fcport->login_retry);
  5142. }
  5143. found++;
  5144. break;
  5145. }
  5146. if (!found) {
  5147. /* New device, add to fcports list. */
  5148. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  5149. /* Allocate a new replacement fcport. */
  5150. fcport = new_fcport;
  5151. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  5152. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  5153. if (new_fcport == NULL) {
  5154. ql_log(ql_log_warn, vha, 0xd031,
  5155. "Failed to allocate memory for fcport.\n");
  5156. rval = QLA_MEMORY_ALLOC_FAILED;
  5157. goto err;
  5158. }
  5159. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  5160. new_fcport->flags &= ~FCF_FABRIC_DEVICE;
  5161. }
  5162. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  5163. /* Base iIDMA settings on HBA port speed. */
  5164. fcport->fp_speed = ha->link_data_rate;
  5165. }
  5166. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  5167. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5168. break;
  5169. if (fcport->scan_state == QLA_FCPORT_SCAN) {
  5170. if ((qla_dual_mode_enabled(vha) ||
  5171. qla_ini_mode_enabled(vha)) &&
  5172. atomic_read(&fcport->state) == FCS_ONLINE) {
  5173. qla2x00_mark_device_lost(vha, fcport,
  5174. ql2xplogiabsentdevice);
  5175. if (fcport->loop_id != FC_NO_LOOP_ID &&
  5176. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  5177. fcport->port_type != FCT_INITIATOR &&
  5178. fcport->port_type != FCT_BROADCAST) {
  5179. ql_dbg(ql_dbg_disc, vha, 0x20f0,
  5180. "%s %d %8phC post del sess\n",
  5181. __func__, __LINE__,
  5182. fcport->port_name);
  5183. qlt_schedule_sess_for_deletion(fcport);
  5184. continue;
  5185. }
  5186. }
  5187. }
  5188. if (fcport->scan_state == QLA_FCPORT_FOUND)
  5189. qla24xx_fcport_handle_login(vha, fcport);
  5190. }
  5191. qla2x00_free_fcport(new_fcport);
  5192. return rval;
  5193. err:
  5194. ql_dbg(ql_dbg_disc, vha, 0x2098,
  5195. "Configure local loop error exit: rval=%x.\n", rval);
  5196. return rval;
  5197. }
  5198. static void
  5199. qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  5200. {
  5201. int rval;
  5202. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5203. struct qla_hw_data *ha = vha->hw;
  5204. if (!IS_IIDMA_CAPABLE(ha))
  5205. return;
  5206. if (atomic_read(&fcport->state) != FCS_ONLINE)
  5207. return;
  5208. if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
  5209. fcport->fp_speed > ha->link_data_rate ||
  5210. !ha->flags.gpsc_supported)
  5211. return;
  5212. rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
  5213. mb);
  5214. if (rval != QLA_SUCCESS) {
  5215. ql_dbg(ql_dbg_disc, vha, 0x2004,
  5216. "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
  5217. fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
  5218. } else {
  5219. ql_dbg(ql_dbg_disc, vha, 0x2005,
  5220. "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
  5221. qla2x00_get_link_speed_str(ha, fcport->fp_speed),
  5222. fcport->fp_speed, fcport->port_name);
  5223. }
  5224. }
  5225. void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  5226. {
  5227. qla2x00_iidma_fcport(vha, fcport);
  5228. qla24xx_update_fcport_fcp_prio(vha, fcport);
  5229. }
  5230. int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
  5231. {
  5232. struct qla_work_evt *e;
  5233. e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
  5234. if (!e)
  5235. return QLA_FUNCTION_FAILED;
  5236. e->u.fcport.fcport = fcport;
  5237. return qla2x00_post_work(vha, e);
  5238. }
  5239. /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
  5240. static void
  5241. qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
  5242. {
  5243. struct fc_rport_identifiers rport_ids;
  5244. struct fc_rport *rport;
  5245. unsigned long flags;
  5246. if (atomic_read(&fcport->state) == FCS_ONLINE)
  5247. return;
  5248. rport_ids.node_name = wwn_to_u64(fcport->node_name);
  5249. rport_ids.port_name = wwn_to_u64(fcport->port_name);
  5250. rport_ids.port_id = fcport->d_id.b.domain << 16 |
  5251. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  5252. rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
  5253. fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
  5254. if (!rport) {
  5255. ql_log(ql_log_warn, vha, 0x2006,
  5256. "Unable to allocate fc remote port.\n");
  5257. return;
  5258. }
  5259. spin_lock_irqsave(fcport->vha->host->host_lock, flags);
  5260. *((fc_port_t **)rport->dd_data) = fcport;
  5261. spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
  5262. fcport->dev_loss_tmo = rport->dev_loss_tmo;
  5263. rport->supported_classes = fcport->supported_classes;
  5264. rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
  5265. if (fcport->port_type == FCT_INITIATOR)
  5266. rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
  5267. if (fcport->port_type == FCT_TARGET)
  5268. rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
  5269. if (fcport->port_type & FCT_NVME_INITIATOR)
  5270. rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
  5271. if (fcport->port_type & FCT_NVME_TARGET)
  5272. rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
  5273. if (fcport->port_type & FCT_NVME_DISCOVERY)
  5274. rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
  5275. fc_remote_port_rolechg(rport, rport_ids.roles);
  5276. ql_dbg(ql_dbg_disc, vha, 0x20ee,
  5277. "%s: %8phN. rport %ld:0:%d (%p) is %s mode\n",
  5278. __func__, fcport->port_name, vha->host_no,
  5279. rport->scsi_target_id, rport,
  5280. (fcport->port_type == FCT_TARGET) ? "tgt" :
  5281. ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
  5282. }
  5283. /*
  5284. * qla2x00_update_fcport
  5285. * Updates device on list.
  5286. *
  5287. * Input:
  5288. * ha = adapter block pointer.
  5289. * fcport = port structure pointer.
  5290. *
  5291. * Return:
  5292. * 0 - Success
  5293. * BIT_0 - error
  5294. *
  5295. * Context:
  5296. * Kernel context.
  5297. */
  5298. void
  5299. qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
  5300. {
  5301. unsigned long flags;
  5302. if (IS_SW_RESV_ADDR(fcport->d_id))
  5303. return;
  5304. ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
  5305. __func__, fcport->port_name);
  5306. qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
  5307. fcport->login_retry = vha->hw->login_retry_count;
  5308. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  5309. spin_lock_irqsave(&vha->work_lock, flags);
  5310. fcport->deleted = 0;
  5311. spin_unlock_irqrestore(&vha->work_lock, flags);
  5312. if (vha->hw->current_topology == ISP_CFG_NL)
  5313. fcport->logout_on_delete = 0;
  5314. else
  5315. fcport->logout_on_delete = 1;
  5316. fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
  5317. if (fcport->tgt_link_down_time < fcport->dev_loss_tmo) {
  5318. fcport->tgt_short_link_down_cnt++;
  5319. fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
  5320. }
  5321. switch (vha->hw->current_topology) {
  5322. case ISP_CFG_N:
  5323. case ISP_CFG_NL:
  5324. fcport->keep_nport_handle = 1;
  5325. break;
  5326. default:
  5327. break;
  5328. }
  5329. qla2x00_iidma_fcport(vha, fcport);
  5330. qla2x00_dfs_create_rport(vha, fcport);
  5331. qla24xx_update_fcport_fcp_prio(vha, fcport);
  5332. switch (vha->host->active_mode) {
  5333. case MODE_INITIATOR:
  5334. qla2x00_reg_remote_port(vha, fcport);
  5335. break;
  5336. case MODE_TARGET:
  5337. if (!vha->vha_tgt.qla_tgt->tgt_stop &&
  5338. !vha->vha_tgt.qla_tgt->tgt_stopped)
  5339. qlt_fc_port_added(vha, fcport);
  5340. break;
  5341. case MODE_DUAL:
  5342. qla2x00_reg_remote_port(vha, fcport);
  5343. if (!vha->vha_tgt.qla_tgt->tgt_stop &&
  5344. !vha->vha_tgt.qla_tgt->tgt_stopped)
  5345. qlt_fc_port_added(vha, fcport);
  5346. break;
  5347. default:
  5348. break;
  5349. }
  5350. if (NVME_TARGET(vha->hw, fcport))
  5351. qla_nvme_register_remote(vha, fcport);
  5352. qla2x00_set_fcport_state(fcport, FCS_ONLINE);
  5353. if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
  5354. if (fcport->id_changed) {
  5355. fcport->id_changed = 0;
  5356. ql_dbg(ql_dbg_disc, vha, 0x20d7,
  5357. "%s %d %8phC post gfpnid fcp_cnt %d\n",
  5358. __func__, __LINE__, fcport->port_name,
  5359. vha->fcport_count);
  5360. qla24xx_post_gfpnid_work(vha, fcport);
  5361. } else {
  5362. ql_dbg(ql_dbg_disc, vha, 0x20d7,
  5363. "%s %d %8phC post gpsc fcp_cnt %d\n",
  5364. __func__, __LINE__, fcport->port_name,
  5365. vha->fcport_count);
  5366. qla24xx_post_gpsc_work(vha, fcport);
  5367. }
  5368. }
  5369. qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
  5370. }
  5371. void qla_register_fcport_fn(struct work_struct *work)
  5372. {
  5373. fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
  5374. u32 rscn_gen = fcport->rscn_gen;
  5375. u16 data[2];
  5376. if (IS_SW_RESV_ADDR(fcport->d_id))
  5377. return;
  5378. qla2x00_update_fcport(fcport->vha, fcport);
  5379. ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
  5380. "%s rscn gen %d/%d next DS %d\n", __func__,
  5381. rscn_gen, fcport->rscn_gen, fcport->next_disc_state);
  5382. if (rscn_gen != fcport->rscn_gen) {
  5383. /* RSCN(s) came in while registration */
  5384. switch (fcport->next_disc_state) {
  5385. case DSC_DELETE_PEND:
  5386. qlt_schedule_sess_for_deletion(fcport);
  5387. break;
  5388. case DSC_ADISC:
  5389. data[0] = data[1] = 0;
  5390. qla2x00_post_async_adisc_work(fcport->vha, fcport,
  5391. data);
  5392. break;
  5393. default:
  5394. break;
  5395. }
  5396. }
  5397. }
  5398. /*
  5399. * qla2x00_configure_fabric
  5400. * Setup SNS devices with loop ID's.
  5401. *
  5402. * Input:
  5403. * ha = adapter block pointer.
  5404. *
  5405. * Returns:
  5406. * 0 = success.
  5407. * BIT_0 = error
  5408. */
  5409. static int
  5410. qla2x00_configure_fabric(scsi_qla_host_t *vha)
  5411. {
  5412. int rval;
  5413. fc_port_t *fcport;
  5414. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5415. uint16_t loop_id;
  5416. struct qla_hw_data *ha = vha->hw;
  5417. int discovery_gen;
  5418. /* If FL port exists, then SNS is present */
  5419. if (IS_FWI2_CAPABLE(ha))
  5420. loop_id = NPH_F_PORT;
  5421. else
  5422. loop_id = SNS_FL_PORT;
  5423. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
  5424. if (rval != QLA_SUCCESS) {
  5425. ql_dbg(ql_dbg_disc, vha, 0x20a0,
  5426. "MBX_GET_PORT_NAME failed, No FL Port.\n");
  5427. vha->device_flags &= ~SWITCH_FOUND;
  5428. return (QLA_SUCCESS);
  5429. }
  5430. vha->device_flags |= SWITCH_FOUND;
  5431. rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_port_name, 0);
  5432. if (rval != QLA_SUCCESS)
  5433. ql_dbg(ql_dbg_disc, vha, 0x20ff,
  5434. "Failed to get Fabric Port Name\n");
  5435. if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
  5436. rval = qla2x00_send_change_request(vha, 0x3, 0);
  5437. if (rval != QLA_SUCCESS)
  5438. ql_log(ql_log_warn, vha, 0x121,
  5439. "Failed to enable receiving of RSCN requests: 0x%x.\n",
  5440. rval);
  5441. }
  5442. do {
  5443. qla2x00_mgmt_svr_login(vha);
  5444. /* Ensure we are logged into the SNS. */
  5445. loop_id = NPH_SNS_LID(ha);
  5446. rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
  5447. 0xfc, mb, BIT_1|BIT_0);
  5448. if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  5449. ql_dbg(ql_dbg_disc, vha, 0x20a1,
  5450. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
  5451. loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
  5452. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5453. return rval;
  5454. }
  5455. /* FDMI support. */
  5456. if (ql2xfdmienable &&
  5457. test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
  5458. qla2x00_fdmi_register(vha);
  5459. if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
  5460. if (qla2x00_rft_id(vha)) {
  5461. /* EMPTY */
  5462. ql_dbg(ql_dbg_disc, vha, 0x20a2,
  5463. "Register FC-4 TYPE failed.\n");
  5464. if (test_bit(LOOP_RESYNC_NEEDED,
  5465. &vha->dpc_flags))
  5466. break;
  5467. }
  5468. if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
  5469. /* EMPTY */
  5470. ql_dbg(ql_dbg_disc, vha, 0x209a,
  5471. "Register FC-4 Features failed.\n");
  5472. if (test_bit(LOOP_RESYNC_NEEDED,
  5473. &vha->dpc_flags))
  5474. break;
  5475. }
  5476. if (vha->flags.nvme_enabled) {
  5477. if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
  5478. ql_dbg(ql_dbg_disc, vha, 0x2049,
  5479. "Register NVME FC Type Features failed.\n");
  5480. }
  5481. }
  5482. if (qla2x00_rnn_id(vha)) {
  5483. /* EMPTY */
  5484. ql_dbg(ql_dbg_disc, vha, 0x2104,
  5485. "Register Node Name failed.\n");
  5486. if (test_bit(LOOP_RESYNC_NEEDED,
  5487. &vha->dpc_flags))
  5488. break;
  5489. } else if (qla2x00_rsnn_nn(vha)) {
  5490. /* EMPTY */
  5491. ql_dbg(ql_dbg_disc, vha, 0x209b,
  5492. "Register Symbolic Node Name failed.\n");
  5493. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5494. break;
  5495. }
  5496. }
  5497. /* Mark the time right before querying FW for connected ports.
  5498. * This process is long, asynchronous and by the time it's done,
  5499. * collected information might not be accurate anymore. E.g.
  5500. * disconnected port might have re-connected and a brand new
  5501. * session has been created. In this case session's generation
  5502. * will be newer than discovery_gen. */
  5503. qlt_do_generation_tick(vha, &discovery_gen);
  5504. if (USE_ASYNC_SCAN(ha)) {
  5505. /* start of scan begins here */
  5506. vha->scan.rscn_gen_end = atomic_read(&vha->rscn_gen);
  5507. qla_fab_scan_start(vha);
  5508. } else {
  5509. list_for_each_entry(fcport, &vha->vp_fcports, list)
  5510. fcport->scan_state = QLA_FCPORT_SCAN;
  5511. rval = qla2x00_find_all_fabric_devs(vha);
  5512. }
  5513. if (rval != QLA_SUCCESS)
  5514. break;
  5515. } while (0);
  5516. if (!vha->nvme_local_port && vha->flags.nvme_enabled)
  5517. qla_nvme_register_hba(vha);
  5518. if (rval)
  5519. ql_dbg(ql_dbg_disc, vha, 0x2068,
  5520. "Configure fabric error exit rval=%d.\n", rval);
  5521. return (rval);
  5522. }
  5523. /*
  5524. * qla2x00_find_all_fabric_devs
  5525. *
  5526. * Input:
  5527. * ha = adapter block pointer.
  5528. * dev = database device entry pointer.
  5529. *
  5530. * Returns:
  5531. * 0 = success.
  5532. *
  5533. * Context:
  5534. * Kernel context.
  5535. */
  5536. static int
  5537. qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
  5538. {
  5539. int rval;
  5540. uint16_t loop_id;
  5541. fc_port_t *fcport, *new_fcport;
  5542. int found;
  5543. sw_info_t *swl;
  5544. int swl_idx;
  5545. int first_dev, last_dev;
  5546. port_id_t wrap = {}, nxt_d_id;
  5547. struct qla_hw_data *ha = vha->hw;
  5548. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  5549. unsigned long flags;
  5550. rval = QLA_SUCCESS;
  5551. /* Try GID_PT to get device list, else GAN. */
  5552. if (!ha->swl)
  5553. ha->swl = kzalloc_objs(sw_info_t, ha->max_fibre_devices);
  5554. swl = ha->swl;
  5555. if (!swl) {
  5556. /*EMPTY*/
  5557. ql_dbg(ql_dbg_disc, vha, 0x209c,
  5558. "GID_PT allocations failed, fallback on GA_NXT.\n");
  5559. } else {
  5560. memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
  5561. if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
  5562. swl = NULL;
  5563. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5564. return rval;
  5565. } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
  5566. swl = NULL;
  5567. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5568. return rval;
  5569. } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
  5570. swl = NULL;
  5571. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5572. return rval;
  5573. } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
  5574. swl = NULL;
  5575. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5576. return rval;
  5577. }
  5578. /* If other queries succeeded probe for FC-4 type */
  5579. if (swl) {
  5580. qla2x00_gff_id(vha, swl);
  5581. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5582. return rval;
  5583. }
  5584. }
  5585. swl_idx = 0;
  5586. /* Allocate temporary fcport for any new fcports discovered. */
  5587. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  5588. if (new_fcport == NULL) {
  5589. ql_log(ql_log_warn, vha, 0x209d,
  5590. "Failed to allocate memory for fcport.\n");
  5591. return (QLA_MEMORY_ALLOC_FAILED);
  5592. }
  5593. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  5594. /* Set start port ID scan at adapter ID. */
  5595. first_dev = 1;
  5596. last_dev = 0;
  5597. /* Starting free loop ID. */
  5598. loop_id = ha->min_external_loopid;
  5599. for (; loop_id <= ha->max_loop_id; loop_id++) {
  5600. if (qla2x00_is_reserved_id(vha, loop_id))
  5601. continue;
  5602. if (ha->current_topology == ISP_CFG_FL &&
  5603. (atomic_read(&vha->loop_down_timer) ||
  5604. LOOP_TRANSITION(vha))) {
  5605. atomic_set(&vha->loop_down_timer, 0);
  5606. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  5607. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  5608. break;
  5609. }
  5610. if (swl != NULL) {
  5611. if (last_dev) {
  5612. wrap.b24 = new_fcport->d_id.b24;
  5613. } else {
  5614. new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
  5615. memcpy(new_fcport->node_name,
  5616. swl[swl_idx].node_name, WWN_SIZE);
  5617. memcpy(new_fcport->port_name,
  5618. swl[swl_idx].port_name, WWN_SIZE);
  5619. memcpy(new_fcport->fabric_port_name,
  5620. swl[swl_idx].fabric_port_name, WWN_SIZE);
  5621. new_fcport->fp_speed = swl[swl_idx].fp_speed;
  5622. new_fcport->fc4_type = swl[swl_idx].fc4_type;
  5623. new_fcport->nvme_flag = 0;
  5624. if (vha->flags.nvme_enabled &&
  5625. swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
  5626. ql_log(ql_log_info, vha, 0x2131,
  5627. "FOUND: NVME port %8phC as FC Type 28h\n",
  5628. new_fcport->port_name);
  5629. }
  5630. if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
  5631. last_dev = 1;
  5632. }
  5633. swl_idx++;
  5634. }
  5635. } else {
  5636. /* Send GA_NXT to the switch */
  5637. rval = qla2x00_ga_nxt(vha, new_fcport);
  5638. if (rval != QLA_SUCCESS) {
  5639. ql_log(ql_log_warn, vha, 0x209e,
  5640. "SNS scan failed -- assuming "
  5641. "zero-entry result.\n");
  5642. rval = QLA_SUCCESS;
  5643. break;
  5644. }
  5645. }
  5646. /* If wrap on switch device list, exit. */
  5647. if (first_dev) {
  5648. wrap.b24 = new_fcport->d_id.b24;
  5649. first_dev = 0;
  5650. } else if (new_fcport->d_id.b24 == wrap.b24) {
  5651. ql_dbg(ql_dbg_disc, vha, 0x209f,
  5652. "Device wrap (%02x%02x%02x).\n",
  5653. new_fcport->d_id.b.domain,
  5654. new_fcport->d_id.b.area,
  5655. new_fcport->d_id.b.al_pa);
  5656. break;
  5657. }
  5658. /* Bypass if same physical adapter. */
  5659. if (new_fcport->d_id.b24 == base_vha->d_id.b24)
  5660. continue;
  5661. /* Bypass virtual ports of the same host. */
  5662. if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
  5663. continue;
  5664. /* Bypass if same domain and area of adapter. */
  5665. if (((new_fcport->d_id.b24 & 0xffff00) ==
  5666. (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
  5667. ISP_CFG_FL)
  5668. continue;
  5669. /* Bypass reserved domain fields. */
  5670. if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
  5671. continue;
  5672. /* Bypass ports whose FCP-4 type is not FCP_SCSI */
  5673. if (ql2xgffidenable &&
  5674. (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
  5675. new_fcport->fc4_type != 0))
  5676. continue;
  5677. spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
  5678. /* Locate matching device in database. */
  5679. found = 0;
  5680. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  5681. if (memcmp(new_fcport->port_name, fcport->port_name,
  5682. WWN_SIZE))
  5683. continue;
  5684. fcport->scan_state = QLA_FCPORT_FOUND;
  5685. found++;
  5686. /* Update port state. */
  5687. memcpy(fcport->fabric_port_name,
  5688. new_fcport->fabric_port_name, WWN_SIZE);
  5689. fcport->fp_speed = new_fcport->fp_speed;
  5690. /*
  5691. * If address the same and state FCS_ONLINE
  5692. * (or in target mode), nothing changed.
  5693. */
  5694. if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
  5695. (atomic_read(&fcport->state) == FCS_ONLINE ||
  5696. (vha->host->active_mode == MODE_TARGET))) {
  5697. break;
  5698. }
  5699. if (fcport->login_retry == 0)
  5700. fcport->login_retry =
  5701. vha->hw->login_retry_count;
  5702. /*
  5703. * If device was not a fabric device before.
  5704. */
  5705. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
  5706. fcport->d_id.b24 = new_fcport->d_id.b24;
  5707. qla2x00_clear_loop_id(fcport);
  5708. fcport->flags |= (FCF_FABRIC_DEVICE |
  5709. FCF_LOGIN_NEEDED);
  5710. break;
  5711. }
  5712. /*
  5713. * Port ID changed or device was marked to be updated;
  5714. * Log it out if still logged in and mark it for
  5715. * relogin later.
  5716. */
  5717. if (qla_tgt_mode_enabled(base_vha)) {
  5718. ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
  5719. "port changed FC ID, %8phC"
  5720. " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
  5721. fcport->port_name,
  5722. fcport->d_id.b.domain,
  5723. fcport->d_id.b.area,
  5724. fcport->d_id.b.al_pa,
  5725. fcport->loop_id,
  5726. new_fcport->d_id.b.domain,
  5727. new_fcport->d_id.b.area,
  5728. new_fcport->d_id.b.al_pa);
  5729. fcport->d_id.b24 = new_fcport->d_id.b24;
  5730. break;
  5731. }
  5732. fcport->d_id.b24 = new_fcport->d_id.b24;
  5733. fcport->flags |= FCF_LOGIN_NEEDED;
  5734. break;
  5735. }
  5736. if (found && NVME_TARGET(vha->hw, fcport)) {
  5737. if (fcport->disc_state == DSC_DELETE_PEND) {
  5738. qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
  5739. vha->fcport_count--;
  5740. fcport->login_succ = 0;
  5741. }
  5742. }
  5743. if (found) {
  5744. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  5745. continue;
  5746. }
  5747. /* If device was not in our fcports list, then add it. */
  5748. new_fcport->scan_state = QLA_FCPORT_FOUND;
  5749. list_add_tail(&new_fcport->list, &vha->vp_fcports);
  5750. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
  5751. /* Allocate a new replacement fcport. */
  5752. nxt_d_id.b24 = new_fcport->d_id.b24;
  5753. new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  5754. if (new_fcport == NULL) {
  5755. ql_log(ql_log_warn, vha, 0xd032,
  5756. "Memory allocation failed for fcport.\n");
  5757. return (QLA_MEMORY_ALLOC_FAILED);
  5758. }
  5759. new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
  5760. new_fcport->d_id.b24 = nxt_d_id.b24;
  5761. }
  5762. qla2x00_free_fcport(new_fcport);
  5763. /*
  5764. * Logout all previous fabric dev marked lost, except FCP2 devices.
  5765. */
  5766. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  5767. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  5768. break;
  5769. if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
  5770. continue;
  5771. if (fcport->scan_state == QLA_FCPORT_SCAN) {
  5772. if ((qla_dual_mode_enabled(vha) ||
  5773. qla_ini_mode_enabled(vha)) &&
  5774. atomic_read(&fcport->state) == FCS_ONLINE) {
  5775. qla2x00_mark_device_lost(vha, fcport,
  5776. ql2xplogiabsentdevice);
  5777. if (fcport->loop_id != FC_NO_LOOP_ID &&
  5778. (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
  5779. fcport->port_type != FCT_INITIATOR &&
  5780. fcport->port_type != FCT_BROADCAST) {
  5781. ql_dbg(ql_dbg_disc, vha, 0x20f0,
  5782. "%s %d %8phC post del sess\n",
  5783. __func__, __LINE__,
  5784. fcport->port_name);
  5785. qlt_schedule_sess_for_deletion(fcport);
  5786. continue;
  5787. }
  5788. }
  5789. }
  5790. if (fcport->scan_state == QLA_FCPORT_FOUND &&
  5791. (fcport->flags & FCF_LOGIN_NEEDED) != 0)
  5792. qla24xx_fcport_handle_login(vha, fcport);
  5793. }
  5794. return (rval);
  5795. }
  5796. /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
  5797. int
  5798. qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
  5799. {
  5800. int loop_id = FC_NO_LOOP_ID;
  5801. int lid = NPH_MGMT_SERVER - vha->vp_idx;
  5802. unsigned long flags;
  5803. struct qla_hw_data *ha = vha->hw;
  5804. if (vha->vp_idx == 0) {
  5805. set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
  5806. return NPH_MGMT_SERVER;
  5807. }
  5808. /* pick id from high and work down to low */
  5809. spin_lock_irqsave(&ha->vport_slock, flags);
  5810. for (; lid > 0; lid--) {
  5811. if (!test_bit(lid, vha->hw->loop_id_map)) {
  5812. set_bit(lid, vha->hw->loop_id_map);
  5813. loop_id = lid;
  5814. break;
  5815. }
  5816. }
  5817. spin_unlock_irqrestore(&ha->vport_slock, flags);
  5818. return loop_id;
  5819. }
  5820. /*
  5821. * qla2x00_fabric_login
  5822. * Issue fabric login command.
  5823. *
  5824. * Input:
  5825. * ha = adapter block pointer.
  5826. * device = pointer to FC device type structure.
  5827. *
  5828. * Returns:
  5829. * 0 - Login successfully
  5830. * 1 - Login failed
  5831. * 2 - Initiator device
  5832. * 3 - Fatal error
  5833. */
  5834. int
  5835. qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
  5836. uint16_t *next_loopid)
  5837. {
  5838. int rval;
  5839. int retry;
  5840. uint16_t tmp_loopid;
  5841. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5842. struct qla_hw_data *ha = vha->hw;
  5843. retry = 0;
  5844. tmp_loopid = 0;
  5845. for (;;) {
  5846. ql_dbg(ql_dbg_disc, vha, 0x2000,
  5847. "Trying Fabric Login w/loop id 0x%04x for port "
  5848. "%02x%02x%02x.\n",
  5849. fcport->loop_id, fcport->d_id.b.domain,
  5850. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5851. /* Login fcport on switch. */
  5852. rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
  5853. fcport->d_id.b.domain, fcport->d_id.b.area,
  5854. fcport->d_id.b.al_pa, mb, BIT_0);
  5855. if (rval != QLA_SUCCESS) {
  5856. return rval;
  5857. }
  5858. if (mb[0] == MBS_PORT_ID_USED) {
  5859. /*
  5860. * Device has another loop ID. The firmware team
  5861. * recommends the driver perform an implicit login with
  5862. * the specified ID again. The ID we just used is save
  5863. * here so we return with an ID that can be tried by
  5864. * the next login.
  5865. */
  5866. retry++;
  5867. tmp_loopid = fcport->loop_id;
  5868. fcport->loop_id = mb[1];
  5869. ql_dbg(ql_dbg_disc, vha, 0x2001,
  5870. "Fabric Login: port in use - next loop "
  5871. "id=0x%04x, port id= %02x%02x%02x.\n",
  5872. fcport->loop_id, fcport->d_id.b.domain,
  5873. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  5874. } else if (mb[0] == MBS_COMMAND_COMPLETE) {
  5875. /*
  5876. * Login succeeded.
  5877. */
  5878. if (retry) {
  5879. /* A retry occurred before. */
  5880. *next_loopid = tmp_loopid;
  5881. } else {
  5882. /*
  5883. * No retry occurred before. Just increment the
  5884. * ID value for next login.
  5885. */
  5886. *next_loopid = (fcport->loop_id + 1);
  5887. }
  5888. if (mb[1] & BIT_0) {
  5889. fcport->port_type = FCT_INITIATOR;
  5890. } else {
  5891. fcport->port_type = FCT_TARGET;
  5892. if (mb[1] & BIT_1) {
  5893. fcport->flags |= FCF_FCP2_DEVICE;
  5894. }
  5895. }
  5896. if (mb[10] & BIT_0)
  5897. fcport->supported_classes |= FC_COS_CLASS2;
  5898. if (mb[10] & BIT_1)
  5899. fcport->supported_classes |= FC_COS_CLASS3;
  5900. if (IS_FWI2_CAPABLE(ha)) {
  5901. if (mb[10] & BIT_7)
  5902. fcport->flags |=
  5903. FCF_CONF_COMP_SUPPORTED;
  5904. }
  5905. rval = QLA_SUCCESS;
  5906. break;
  5907. } else if (mb[0] == MBS_LOOP_ID_USED) {
  5908. /*
  5909. * Loop ID already used, try next loop ID.
  5910. */
  5911. fcport->loop_id++;
  5912. rval = qla2x00_find_new_loop_id(vha, fcport);
  5913. if (rval != QLA_SUCCESS) {
  5914. /* Ran out of loop IDs to use */
  5915. break;
  5916. }
  5917. } else if (mb[0] == MBS_COMMAND_ERROR) {
  5918. /*
  5919. * Firmware possibly timed out during login. If NO
  5920. * retries are left to do then the device is declared
  5921. * dead.
  5922. */
  5923. *next_loopid = fcport->loop_id;
  5924. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  5925. fcport->d_id.b.domain, fcport->d_id.b.area,
  5926. fcport->d_id.b.al_pa);
  5927. qla2x00_mark_device_lost(vha, fcport, 1);
  5928. rval = 1;
  5929. break;
  5930. } else {
  5931. /*
  5932. * unrecoverable / not handled error
  5933. */
  5934. ql_dbg(ql_dbg_disc, vha, 0x2002,
  5935. "Failed=%x port_id=%02x%02x%02x loop_id=%x "
  5936. "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
  5937. fcport->d_id.b.area, fcport->d_id.b.al_pa,
  5938. fcport->loop_id, jiffies);
  5939. *next_loopid = fcport->loop_id;
  5940. ha->isp_ops->fabric_logout(vha, fcport->loop_id,
  5941. fcport->d_id.b.domain, fcport->d_id.b.area,
  5942. fcport->d_id.b.al_pa);
  5943. qla2x00_clear_loop_id(fcport);
  5944. fcport->login_retry = 0;
  5945. rval = 3;
  5946. break;
  5947. }
  5948. }
  5949. return (rval);
  5950. }
  5951. /*
  5952. * qla2x00_local_device_login
  5953. * Issue local device login command.
  5954. *
  5955. * Input:
  5956. * ha = adapter block pointer.
  5957. * loop_id = loop id of device to login to.
  5958. *
  5959. * Returns (Where's the #define!!!!):
  5960. * 0 - Login successfully
  5961. * 1 - Login failed
  5962. * 3 - Fatal error
  5963. */
  5964. int
  5965. qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
  5966. {
  5967. int rval;
  5968. uint16_t mb[MAILBOX_REGISTER_COUNT];
  5969. memset(mb, 0, sizeof(mb));
  5970. rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
  5971. if (rval == QLA_SUCCESS) {
  5972. /* Interrogate mailbox registers for any errors */
  5973. if (mb[0] == MBS_COMMAND_ERROR)
  5974. rval = 1;
  5975. else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
  5976. /* device not in PCB table */
  5977. rval = 3;
  5978. }
  5979. return (rval);
  5980. }
  5981. /*
  5982. * qla2x00_loop_resync
  5983. * Resync with fibre channel devices.
  5984. *
  5985. * Input:
  5986. * ha = adapter block pointer.
  5987. *
  5988. * Returns:
  5989. * 0 = success
  5990. */
  5991. int
  5992. qla2x00_loop_resync(scsi_qla_host_t *vha)
  5993. {
  5994. int rval = QLA_SUCCESS;
  5995. uint32_t wait_time;
  5996. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  5997. if (vha->flags.online) {
  5998. if (!(rval = qla2x00_fw_ready(vha))) {
  5999. /* Wait at most MAX_TARGET RSCNs for a stable link. */
  6000. wait_time = 256;
  6001. do {
  6002. if (!IS_QLAFX00(vha->hw)) {
  6003. /*
  6004. * Issue a marker after FW becomes
  6005. * ready.
  6006. */
  6007. qla2x00_marker(vha, vha->hw->base_qpair,
  6008. 0, 0, MK_SYNC_ALL);
  6009. vha->marker_needed = 0;
  6010. }
  6011. /* Remap devices on Loop. */
  6012. clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  6013. if (IS_QLAFX00(vha->hw))
  6014. qlafx00_configure_devices(vha);
  6015. else
  6016. qla2x00_configure_loop(vha);
  6017. wait_time--;
  6018. } while (!atomic_read(&vha->loop_down_timer) &&
  6019. !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  6020. && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
  6021. &vha->dpc_flags)));
  6022. }
  6023. }
  6024. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  6025. return (QLA_FUNCTION_FAILED);
  6026. if (rval)
  6027. ql_dbg(ql_dbg_disc, vha, 0x206c,
  6028. "%s *** FAILED ***.\n", __func__);
  6029. return (rval);
  6030. }
  6031. /*
  6032. * qla2x00_perform_loop_resync
  6033. * Description: This function will set the appropriate flags and call
  6034. * qla2x00_loop_resync. If successful loop will be resynced
  6035. * Arguments : scsi_qla_host_t pointer
  6036. * returm : Success or Failure
  6037. */
  6038. int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
  6039. {
  6040. int32_t rval = 0;
  6041. if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
  6042. /*Configure the flags so that resync happens properly*/
  6043. atomic_set(&ha->loop_down_timer, 0);
  6044. if (!(ha->device_flags & DFLG_NO_CABLE)) {
  6045. atomic_set(&ha->loop_state, LOOP_UP);
  6046. set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
  6047. set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
  6048. set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
  6049. rval = qla2x00_loop_resync(ha);
  6050. } else
  6051. atomic_set(&ha->loop_state, LOOP_DEAD);
  6052. clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
  6053. }
  6054. return rval;
  6055. }
  6056. /* Assumes idc_lock always held on entry */
  6057. void
  6058. qla83xx_reset_ownership(scsi_qla_host_t *vha)
  6059. {
  6060. struct qla_hw_data *ha = vha->hw;
  6061. uint32_t drv_presence, drv_presence_mask;
  6062. uint32_t dev_part_info1, dev_part_info2, class_type;
  6063. uint32_t class_type_mask = 0x3;
  6064. uint16_t fcoe_other_function = 0xffff, i;
  6065. if (IS_QLA8044(ha)) {
  6066. drv_presence = qla8044_rd_direct(vha,
  6067. QLA8044_CRB_DRV_ACTIVE_INDEX);
  6068. dev_part_info1 = qla8044_rd_direct(vha,
  6069. QLA8044_CRB_DEV_PART_INFO_INDEX);
  6070. dev_part_info2 = qla8044_rd_direct(vha,
  6071. QLA8044_CRB_DEV_PART_INFO2);
  6072. } else {
  6073. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  6074. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
  6075. qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
  6076. }
  6077. for (i = 0; i < 8; i++) {
  6078. class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
  6079. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  6080. (i != ha->portnum)) {
  6081. fcoe_other_function = i;
  6082. break;
  6083. }
  6084. }
  6085. if (fcoe_other_function == 0xffff) {
  6086. for (i = 0; i < 8; i++) {
  6087. class_type = ((dev_part_info2 >> (i * 4)) &
  6088. class_type_mask);
  6089. if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
  6090. ((i + 8) != ha->portnum)) {
  6091. fcoe_other_function = i + 8;
  6092. break;
  6093. }
  6094. }
  6095. }
  6096. /*
  6097. * Prepare drv-presence mask based on fcoe functions present.
  6098. * However consider only valid physical fcoe function numbers (0-15).
  6099. */
  6100. drv_presence_mask = ~((1 << (ha->portnum)) |
  6101. ((fcoe_other_function == 0xffff) ?
  6102. 0 : (1 << (fcoe_other_function))));
  6103. /* We are the reset owner iff:
  6104. * - No other protocol drivers present.
  6105. * - This is the lowest among fcoe functions. */
  6106. if (!(drv_presence & drv_presence_mask) &&
  6107. (ha->portnum < fcoe_other_function)) {
  6108. ql_dbg(ql_dbg_p3p, vha, 0xb07f,
  6109. "This host is Reset owner.\n");
  6110. ha->flags.nic_core_reset_owner = 1;
  6111. }
  6112. }
  6113. static int
  6114. __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
  6115. {
  6116. int rval = QLA_SUCCESS;
  6117. struct qla_hw_data *ha = vha->hw;
  6118. uint32_t drv_ack;
  6119. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  6120. if (rval == QLA_SUCCESS) {
  6121. drv_ack |= (1 << ha->portnum);
  6122. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  6123. }
  6124. return rval;
  6125. }
  6126. static int
  6127. __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
  6128. {
  6129. int rval = QLA_SUCCESS;
  6130. struct qla_hw_data *ha = vha->hw;
  6131. uint32_t drv_ack;
  6132. rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
  6133. if (rval == QLA_SUCCESS) {
  6134. drv_ack &= ~(1 << ha->portnum);
  6135. rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
  6136. }
  6137. return rval;
  6138. }
  6139. /* Assumes idc-lock always held on entry */
  6140. void
  6141. qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
  6142. {
  6143. struct qla_hw_data *ha = vha->hw;
  6144. uint32_t idc_audit_reg = 0, duration_secs = 0;
  6145. switch (audit_type) {
  6146. case IDC_AUDIT_TIMESTAMP:
  6147. ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
  6148. idc_audit_reg = (ha->portnum) |
  6149. (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
  6150. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  6151. break;
  6152. case IDC_AUDIT_COMPLETION:
  6153. duration_secs = ((jiffies_to_msecs(jiffies) -
  6154. jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
  6155. idc_audit_reg = (ha->portnum) |
  6156. (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
  6157. qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
  6158. break;
  6159. default:
  6160. ql_log(ql_log_warn, vha, 0xb078,
  6161. "Invalid audit type specified.\n");
  6162. break;
  6163. }
  6164. }
  6165. /* Assumes idc_lock always held on entry */
  6166. static int
  6167. qla83xx_initiating_reset(scsi_qla_host_t *vha)
  6168. {
  6169. struct qla_hw_data *ha = vha->hw;
  6170. uint32_t idc_control, dev_state;
  6171. __qla83xx_get_idc_control(vha, &idc_control);
  6172. if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
  6173. ql_log(ql_log_info, vha, 0xb080,
  6174. "NIC Core reset has been disabled. idc-control=0x%x\n",
  6175. idc_control);
  6176. return QLA_FUNCTION_FAILED;
  6177. }
  6178. /* Set NEED-RESET iff in READY state and we are the reset-owner */
  6179. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  6180. if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
  6181. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  6182. QLA8XXX_DEV_NEED_RESET);
  6183. ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
  6184. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  6185. } else {
  6186. ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n",
  6187. qdev_state(dev_state));
  6188. /* SV: XXX: Is timeout required here? */
  6189. /* Wait for IDC state change READY -> NEED_RESET */
  6190. while (dev_state == QLA8XXX_DEV_READY) {
  6191. qla83xx_idc_unlock(vha, 0);
  6192. msleep(200);
  6193. qla83xx_idc_lock(vha, 0);
  6194. qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
  6195. }
  6196. }
  6197. /* Send IDC ack by writing to drv-ack register */
  6198. __qla83xx_set_drv_ack(vha);
  6199. return QLA_SUCCESS;
  6200. }
  6201. int
  6202. __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
  6203. {
  6204. return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  6205. }
  6206. int
  6207. __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
  6208. {
  6209. return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
  6210. }
  6211. static int
  6212. qla83xx_check_driver_presence(scsi_qla_host_t *vha)
  6213. {
  6214. uint32_t drv_presence = 0;
  6215. struct qla_hw_data *ha = vha->hw;
  6216. qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
  6217. if (drv_presence & (1 << ha->portnum))
  6218. return QLA_SUCCESS;
  6219. else
  6220. return QLA_TEST_FAILED;
  6221. }
  6222. int
  6223. qla83xx_nic_core_reset(scsi_qla_host_t *vha)
  6224. {
  6225. int rval = QLA_SUCCESS;
  6226. struct qla_hw_data *ha = vha->hw;
  6227. ql_dbg(ql_dbg_p3p, vha, 0xb058,
  6228. "Entered %s().\n", __func__);
  6229. if (vha->device_flags & DFLG_DEV_FAILED) {
  6230. ql_log(ql_log_warn, vha, 0xb059,
  6231. "Device in unrecoverable FAILED state.\n");
  6232. return QLA_FUNCTION_FAILED;
  6233. }
  6234. qla83xx_idc_lock(vha, 0);
  6235. if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
  6236. ql_log(ql_log_warn, vha, 0xb05a,
  6237. "Function=0x%x has been removed from IDC participation.\n",
  6238. ha->portnum);
  6239. rval = QLA_FUNCTION_FAILED;
  6240. goto exit;
  6241. }
  6242. qla83xx_reset_ownership(vha);
  6243. rval = qla83xx_initiating_reset(vha);
  6244. /*
  6245. * Perform reset if we are the reset-owner,
  6246. * else wait till IDC state changes to READY/FAILED.
  6247. */
  6248. if (rval == QLA_SUCCESS) {
  6249. rval = qla83xx_idc_state_handler(vha);
  6250. if (rval == QLA_SUCCESS)
  6251. ha->flags.nic_core_hung = 0;
  6252. __qla83xx_clear_drv_ack(vha);
  6253. }
  6254. exit:
  6255. qla83xx_idc_unlock(vha, 0);
  6256. ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
  6257. return rval;
  6258. }
  6259. int
  6260. qla2xxx_mctp_dump(scsi_qla_host_t *vha)
  6261. {
  6262. struct qla_hw_data *ha = vha->hw;
  6263. int rval = QLA_FUNCTION_FAILED;
  6264. if (!IS_MCTP_CAPABLE(ha)) {
  6265. /* This message can be removed from the final version */
  6266. ql_log(ql_log_info, vha, 0x506d,
  6267. "This board is not MCTP capable\n");
  6268. return rval;
  6269. }
  6270. if (!ha->mctp_dump) {
  6271. ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
  6272. MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
  6273. if (!ha->mctp_dump) {
  6274. ql_log(ql_log_warn, vha, 0x506e,
  6275. "Failed to allocate memory for mctp dump\n");
  6276. return rval;
  6277. }
  6278. }
  6279. #define MCTP_DUMP_STR_ADDR 0x00000000
  6280. rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
  6281. MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
  6282. if (rval != QLA_SUCCESS) {
  6283. ql_log(ql_log_warn, vha, 0x506f,
  6284. "Failed to capture mctp dump\n");
  6285. } else {
  6286. ql_log(ql_log_info, vha, 0x5070,
  6287. "Mctp dump capture for host (%ld/%p).\n",
  6288. vha->host_no, ha->mctp_dump);
  6289. ha->mctp_dumped = 1;
  6290. }
  6291. if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
  6292. ha->flags.nic_core_reset_hdlr_active = 1;
  6293. rval = qla83xx_restart_nic_firmware(vha);
  6294. if (rval)
  6295. /* NIC Core reset failed. */
  6296. ql_log(ql_log_warn, vha, 0x5071,
  6297. "Failed to restart nic firmware\n");
  6298. else
  6299. ql_dbg(ql_dbg_p3p, vha, 0xb084,
  6300. "Restarted NIC firmware successfully.\n");
  6301. ha->flags.nic_core_reset_hdlr_active = 0;
  6302. }
  6303. return rval;
  6304. }
  6305. /*
  6306. * qla2x00_quiesce_io
  6307. * Description: This function will block the new I/Os
  6308. * Its not aborting any I/Os as context
  6309. * is not destroyed during quiescence
  6310. * Arguments: scsi_qla_host_t
  6311. * return : void
  6312. */
  6313. void
  6314. qla2x00_quiesce_io(scsi_qla_host_t *vha)
  6315. {
  6316. struct qla_hw_data *ha = vha->hw;
  6317. struct scsi_qla_host *vp, *tvp;
  6318. unsigned long flags;
  6319. ql_dbg(ql_dbg_dpc, vha, 0x401d,
  6320. "Quiescing I/O - ha=%p.\n", ha);
  6321. atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
  6322. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  6323. atomic_set(&vha->loop_state, LOOP_DOWN);
  6324. qla2x00_mark_all_devices_lost(vha);
  6325. spin_lock_irqsave(&ha->vport_slock, flags);
  6326. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  6327. atomic_inc(&vp->vref_count);
  6328. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6329. qla2x00_mark_all_devices_lost(vp);
  6330. spin_lock_irqsave(&ha->vport_slock, flags);
  6331. atomic_dec(&vp->vref_count);
  6332. }
  6333. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6334. } else {
  6335. if (!atomic_read(&vha->loop_down_timer))
  6336. atomic_set(&vha->loop_down_timer,
  6337. LOOP_DOWN_TIME);
  6338. }
  6339. /* Wait for pending cmds to complete */
  6340. WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
  6341. != QLA_SUCCESS);
  6342. }
  6343. void
  6344. qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
  6345. {
  6346. struct qla_hw_data *ha = vha->hw;
  6347. struct scsi_qla_host *vp, *tvp;
  6348. unsigned long flags;
  6349. fc_port_t *fcport;
  6350. u16 i;
  6351. /* For ISP82XX, driver waits for completion of the commands.
  6352. * online flag should be set.
  6353. */
  6354. if (!(IS_P3P_TYPE(ha)))
  6355. vha->flags.online = 0;
  6356. ha->flags.chip_reset_done = 0;
  6357. clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  6358. vha->qla_stats.total_isp_aborts++;
  6359. ql_log(ql_log_info, vha, 0x00af,
  6360. "Performing ISP error recovery - ha=%p.\n", ha);
  6361. ha->flags.purge_mbox = 1;
  6362. /* For ISP82XX, reset_chip is just disabling interrupts.
  6363. * Driver waits for the completion of the commands.
  6364. * the interrupts need to be enabled.
  6365. */
  6366. if (!(IS_P3P_TYPE(ha)))
  6367. ha->isp_ops->reset_chip(vha);
  6368. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  6369. SAVE_TOPO(ha);
  6370. ha->flags.rida_fmt2 = 0;
  6371. ha->flags.n2n_ae = 0;
  6372. ha->flags.lip_ae = 0;
  6373. ha->current_topology = 0;
  6374. QLA_FW_STOPPED(ha);
  6375. ha->flags.fw_init_done = 0;
  6376. ha->chip_reset++;
  6377. ha->base_qpair->chip_reset = ha->chip_reset;
  6378. ha->base_qpair->cmd_cnt = ha->base_qpair->cmd_completion_cnt = 0;
  6379. ha->base_qpair->prev_completion_cnt = 0;
  6380. for (i = 0; i < ha->max_qpairs; i++) {
  6381. if (ha->queue_pair_map[i]) {
  6382. ha->queue_pair_map[i]->chip_reset =
  6383. ha->base_qpair->chip_reset;
  6384. ha->queue_pair_map[i]->cmd_cnt =
  6385. ha->queue_pair_map[i]->cmd_completion_cnt = 0;
  6386. ha->base_qpair->prev_completion_cnt = 0;
  6387. }
  6388. }
  6389. /* purge MBox commands */
  6390. spin_lock_irqsave(&ha->hardware_lock, flags);
  6391. if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags)) {
  6392. clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  6393. complete(&ha->mbx_intr_comp);
  6394. }
  6395. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6396. i = 0;
  6397. while (atomic_read(&ha->num_pend_mbx_stage2) ||
  6398. atomic_read(&ha->num_pend_mbx_stage1)) {
  6399. msleep(20);
  6400. i++;
  6401. if (i > 50)
  6402. break;
  6403. }
  6404. ha->flags.purge_mbox = 0;
  6405. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  6406. if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
  6407. atomic_set(&vha->loop_state, LOOP_DOWN);
  6408. qla2x00_mark_all_devices_lost(vha);
  6409. spin_lock_irqsave(&ha->vport_slock, flags);
  6410. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  6411. atomic_inc(&vp->vref_count);
  6412. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6413. qla2x00_mark_all_devices_lost(vp);
  6414. spin_lock_irqsave(&ha->vport_slock, flags);
  6415. atomic_dec(&vp->vref_count);
  6416. }
  6417. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6418. } else {
  6419. if (!atomic_read(&vha->loop_down_timer))
  6420. atomic_set(&vha->loop_down_timer,
  6421. LOOP_DOWN_TIME);
  6422. }
  6423. /* Clear all async request states across all VPs. */
  6424. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  6425. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  6426. fcport->scan_state = 0;
  6427. }
  6428. spin_lock_irqsave(&ha->vport_slock, flags);
  6429. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  6430. atomic_inc(&vp->vref_count);
  6431. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6432. list_for_each_entry(fcport, &vp->vp_fcports, list)
  6433. fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
  6434. spin_lock_irqsave(&ha->vport_slock, flags);
  6435. atomic_dec(&vp->vref_count);
  6436. }
  6437. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6438. /* Make sure for ISP 82XX IO DMA is complete */
  6439. if (IS_P3P_TYPE(ha)) {
  6440. qla82xx_chip_reset_cleanup(vha);
  6441. ql_log(ql_log_info, vha, 0x00b4,
  6442. "Done chip reset cleanup.\n");
  6443. /* Done waiting for pending commands. Reset online flag */
  6444. vha->flags.online = 0;
  6445. }
  6446. /* Requeue all commands in outstanding command list. */
  6447. qla2x00_abort_all_cmds(vha, DID_RESET << 16);
  6448. /* memory barrier */
  6449. wmb();
  6450. }
  6451. /*
  6452. * qla2x00_abort_isp
  6453. * Resets ISP and aborts all outstanding commands.
  6454. *
  6455. * Input:
  6456. * ha = adapter block pointer.
  6457. *
  6458. * Returns:
  6459. * 0 = success
  6460. */
  6461. int
  6462. qla2x00_abort_isp(scsi_qla_host_t *vha)
  6463. {
  6464. uint8_t status = 0;
  6465. struct qla_hw_data *ha = vha->hw;
  6466. struct scsi_qla_host *vp, *tvp;
  6467. struct req_que *req = ha->req_q_map[0];
  6468. unsigned long flags;
  6469. fc_port_t *fcport;
  6470. if (vha->flags.online) {
  6471. qla2x00_abort_isp_cleanup(vha);
  6472. vha->dport_status |= DPORT_DIAG_CHIP_RESET_IN_PROGRESS;
  6473. vha->dport_status &= ~DPORT_DIAG_IN_PROGRESS;
  6474. if (vha->hw->flags.port_isolated)
  6475. return status;
  6476. if (qla2x00_isp_reg_stat(ha)) {
  6477. ql_log(ql_log_info, vha, 0x803f,
  6478. "ISP Abort - ISP reg disconnect, exiting.\n");
  6479. return status;
  6480. }
  6481. if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
  6482. ha->flags.chip_reset_done = 1;
  6483. vha->flags.online = 1;
  6484. status = 0;
  6485. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  6486. return status;
  6487. }
  6488. if (IS_QLA8031(ha)) {
  6489. ql_dbg(ql_dbg_p3p, vha, 0xb05c,
  6490. "Clearing fcoe driver presence.\n");
  6491. if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
  6492. ql_dbg(ql_dbg_p3p, vha, 0xb073,
  6493. "Error while clearing DRV-Presence.\n");
  6494. }
  6495. if (unlikely(pci_channel_offline(ha->pdev) &&
  6496. ha->flags.pci_channel_io_perm_failure)) {
  6497. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  6498. status = 0;
  6499. return status;
  6500. }
  6501. switch (vha->qlini_mode) {
  6502. case QLA2XXX_INI_MODE_DISABLED:
  6503. if (!qla_tgt_mode_enabled(vha))
  6504. return 0;
  6505. break;
  6506. case QLA2XXX_INI_MODE_DUAL:
  6507. if (!qla_dual_mode_enabled(vha) &&
  6508. !qla_ini_mode_enabled(vha))
  6509. return 0;
  6510. break;
  6511. case QLA2XXX_INI_MODE_ENABLED:
  6512. default:
  6513. break;
  6514. }
  6515. ha->isp_ops->get_flash_version(vha, req->ring);
  6516. if (qla2x00_isp_reg_stat(ha)) {
  6517. ql_log(ql_log_info, vha, 0x803f,
  6518. "ISP Abort - ISP reg disconnect pre nvram config, exiting.\n");
  6519. return status;
  6520. }
  6521. ha->isp_ops->nvram_config(vha);
  6522. if (qla2x00_isp_reg_stat(ha)) {
  6523. ql_log(ql_log_info, vha, 0x803f,
  6524. "ISP Abort - ISP reg disconnect post nvmram config, exiting.\n");
  6525. return status;
  6526. }
  6527. /* User may have updated [fcp|nvme] prefer in flash */
  6528. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  6529. if (NVME_PRIORITY(ha, fcport))
  6530. fcport->do_prli_nvme = 1;
  6531. else
  6532. fcport->do_prli_nvme = 0;
  6533. }
  6534. if (!qla2x00_restart_isp(vha)) {
  6535. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  6536. if (!atomic_read(&vha->loop_down_timer)) {
  6537. /*
  6538. * Issue marker command only when we are going
  6539. * to start the I/O .
  6540. */
  6541. vha->marker_needed = 1;
  6542. }
  6543. vha->flags.online = 1;
  6544. ha->isp_ops->enable_intrs(ha);
  6545. ha->isp_abort_cnt = 0;
  6546. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  6547. if (IS_QLA81XX(ha) || IS_QLA8031(ha))
  6548. qla2x00_get_fw_version(vha);
  6549. } else { /* failed the ISP abort */
  6550. vha->flags.online = 1;
  6551. if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  6552. if (ha->isp_abort_cnt == 0) {
  6553. ql_log(ql_log_fatal, vha, 0x8035,
  6554. "ISP error recover failed - "
  6555. "board disabled.\n");
  6556. /*
  6557. * The next call disables the board
  6558. * completely.
  6559. */
  6560. qla2x00_abort_isp_cleanup(vha);
  6561. vha->flags.online = 0;
  6562. clear_bit(ISP_ABORT_RETRY,
  6563. &vha->dpc_flags);
  6564. status = 0;
  6565. } else { /* schedule another ISP abort */
  6566. ha->isp_abort_cnt--;
  6567. ql_dbg(ql_dbg_taskm, vha, 0x8020,
  6568. "ISP abort - retry remaining %d.\n",
  6569. ha->isp_abort_cnt);
  6570. status = 1;
  6571. }
  6572. } else {
  6573. ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
  6574. ql_dbg(ql_dbg_taskm, vha, 0x8021,
  6575. "ISP error recovery - retrying (%d) "
  6576. "more times.\n", ha->isp_abort_cnt);
  6577. set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  6578. status = 1;
  6579. }
  6580. }
  6581. }
  6582. if (vha->hw->flags.port_isolated) {
  6583. qla2x00_abort_isp_cleanup(vha);
  6584. return status;
  6585. }
  6586. if (!status) {
  6587. ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
  6588. qla2x00_configure_hba(vha);
  6589. spin_lock_irqsave(&ha->vport_slock, flags);
  6590. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  6591. if (vp->vp_idx) {
  6592. atomic_inc(&vp->vref_count);
  6593. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6594. /* User may have updated [fcp|nvme] prefer in flash */
  6595. list_for_each_entry(fcport, &vp->vp_fcports, list) {
  6596. if (NVME_PRIORITY(ha, fcport))
  6597. fcport->do_prli_nvme = 1;
  6598. else
  6599. fcport->do_prli_nvme = 0;
  6600. }
  6601. qla2x00_vp_abort_isp(vp);
  6602. spin_lock_irqsave(&ha->vport_slock, flags);
  6603. atomic_dec(&vp->vref_count);
  6604. }
  6605. }
  6606. spin_unlock_irqrestore(&ha->vport_slock, flags);
  6607. if (IS_QLA8031(ha)) {
  6608. ql_dbg(ql_dbg_p3p, vha, 0xb05d,
  6609. "Setting back fcoe driver presence.\n");
  6610. if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
  6611. ql_dbg(ql_dbg_p3p, vha, 0xb074,
  6612. "Error while setting DRV-Presence.\n");
  6613. }
  6614. } else {
  6615. ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
  6616. __func__);
  6617. }
  6618. return(status);
  6619. }
  6620. /*
  6621. * qla2x00_restart_isp
  6622. * restarts the ISP after a reset
  6623. *
  6624. * Input:
  6625. * ha = adapter block pointer.
  6626. *
  6627. * Returns:
  6628. * 0 = success
  6629. */
  6630. static int
  6631. qla2x00_restart_isp(scsi_qla_host_t *vha)
  6632. {
  6633. int status;
  6634. struct qla_hw_data *ha = vha->hw;
  6635. /* If firmware needs to be loaded */
  6636. if (qla2x00_isp_firmware(vha)) {
  6637. vha->flags.online = 0;
  6638. status = ha->isp_ops->chip_diag(vha);
  6639. if (status)
  6640. return status;
  6641. status = qla2x00_setup_chip(vha);
  6642. if (status)
  6643. return status;
  6644. }
  6645. status = qla2x00_init_rings(vha);
  6646. if (status)
  6647. return status;
  6648. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  6649. ha->flags.chip_reset_done = 1;
  6650. /* Initialize the queues in use */
  6651. qla25xx_init_queues(ha);
  6652. status = qla2x00_fw_ready(vha);
  6653. if (status) {
  6654. /* if no cable then assume it's good */
  6655. return vha->device_flags & DFLG_NO_CABLE ? 0 : status;
  6656. }
  6657. /* Issue a marker after FW becomes ready. */
  6658. qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
  6659. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  6660. return 0;
  6661. }
  6662. static int
  6663. qla25xx_init_queues(struct qla_hw_data *ha)
  6664. {
  6665. struct rsp_que *rsp = NULL;
  6666. struct req_que *req = NULL;
  6667. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  6668. int ret = -1;
  6669. int i;
  6670. for (i = 1; i < ha->max_rsp_queues; i++) {
  6671. rsp = ha->rsp_q_map[i];
  6672. if (rsp && test_bit(i, ha->rsp_qid_map)) {
  6673. rsp->options &= ~BIT_0;
  6674. ret = qla25xx_init_rsp_que(base_vha, rsp);
  6675. if (ret != QLA_SUCCESS)
  6676. ql_dbg(ql_dbg_init, base_vha, 0x00ff,
  6677. "%s Rsp que: %d init failed.\n",
  6678. __func__, rsp->id);
  6679. else
  6680. ql_dbg(ql_dbg_init, base_vha, 0x0100,
  6681. "%s Rsp que: %d inited.\n",
  6682. __func__, rsp->id);
  6683. }
  6684. }
  6685. for (i = 1; i < ha->max_req_queues; i++) {
  6686. req = ha->req_q_map[i];
  6687. if (req && test_bit(i, ha->req_qid_map)) {
  6688. /* Clear outstanding commands array. */
  6689. req->options &= ~BIT_0;
  6690. ret = qla25xx_init_req_que(base_vha, req);
  6691. if (ret != QLA_SUCCESS)
  6692. ql_dbg(ql_dbg_init, base_vha, 0x0101,
  6693. "%s Req que: %d init failed.\n",
  6694. __func__, req->id);
  6695. else
  6696. ql_dbg(ql_dbg_init, base_vha, 0x0102,
  6697. "%s Req que: %d inited.\n",
  6698. __func__, req->id);
  6699. }
  6700. }
  6701. return ret;
  6702. }
  6703. /*
  6704. * qla2x00_reset_adapter
  6705. * Reset adapter.
  6706. *
  6707. * Input:
  6708. * ha = adapter block pointer.
  6709. */
  6710. int
  6711. qla2x00_reset_adapter(scsi_qla_host_t *vha)
  6712. {
  6713. unsigned long flags = 0;
  6714. struct qla_hw_data *ha = vha->hw;
  6715. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  6716. vha->flags.online = 0;
  6717. ha->isp_ops->disable_intrs(ha);
  6718. spin_lock_irqsave(&ha->hardware_lock, flags);
  6719. wrt_reg_word(&reg->hccr, HCCR_RESET_RISC);
  6720. rd_reg_word(&reg->hccr); /* PCI Posting. */
  6721. wrt_reg_word(&reg->hccr, HCCR_RELEASE_RISC);
  6722. rd_reg_word(&reg->hccr); /* PCI Posting. */
  6723. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6724. return QLA_SUCCESS;
  6725. }
  6726. int
  6727. qla24xx_reset_adapter(scsi_qla_host_t *vha)
  6728. {
  6729. unsigned long flags = 0;
  6730. struct qla_hw_data *ha = vha->hw;
  6731. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  6732. if (IS_P3P_TYPE(ha))
  6733. return QLA_SUCCESS;
  6734. vha->flags.online = 0;
  6735. ha->isp_ops->disable_intrs(ha);
  6736. spin_lock_irqsave(&ha->hardware_lock, flags);
  6737. wrt_reg_dword(&reg->hccr, HCCRX_SET_RISC_RESET);
  6738. rd_reg_dword(&reg->hccr);
  6739. wrt_reg_dword(&reg->hccr, HCCRX_REL_RISC_PAUSE);
  6740. rd_reg_dword(&reg->hccr);
  6741. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  6742. if (IS_NOPOLLING_TYPE(ha))
  6743. ha->isp_ops->enable_intrs(ha);
  6744. return QLA_SUCCESS;
  6745. }
  6746. /* On sparc systems, obtain port and node WWN from firmware
  6747. * properties.
  6748. */
  6749. static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
  6750. struct nvram_24xx *nv)
  6751. {
  6752. #ifdef CONFIG_SPARC
  6753. struct qla_hw_data *ha = vha->hw;
  6754. struct pci_dev *pdev = ha->pdev;
  6755. struct device_node *dp = pci_device_to_OF_node(pdev);
  6756. const u8 *val;
  6757. int len;
  6758. val = of_get_property(dp, "port-wwn", &len);
  6759. if (val && len >= WWN_SIZE)
  6760. memcpy(nv->port_name, val, WWN_SIZE);
  6761. val = of_get_property(dp, "node-wwn", &len);
  6762. if (val && len >= WWN_SIZE)
  6763. memcpy(nv->node_name, val, WWN_SIZE);
  6764. #endif
  6765. }
  6766. int
  6767. qla24xx_nvram_config(scsi_qla_host_t *vha)
  6768. {
  6769. int rval;
  6770. struct init_cb_24xx *icb;
  6771. struct nvram_24xx *nv;
  6772. __le32 *dptr;
  6773. uint8_t *dptr1, *dptr2;
  6774. uint32_t chksum;
  6775. uint16_t cnt;
  6776. struct qla_hw_data *ha = vha->hw;
  6777. rval = QLA_SUCCESS;
  6778. icb = (struct init_cb_24xx *)ha->init_cb;
  6779. nv = ha->nvram;
  6780. /* Determine NVRAM starting address. */
  6781. if (ha->port_no == 0) {
  6782. ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
  6783. ha->vpd_base = FA_NVRAM_VPD0_ADDR;
  6784. } else {
  6785. ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
  6786. ha->vpd_base = FA_NVRAM_VPD1_ADDR;
  6787. }
  6788. ha->nvram_size = sizeof(*nv);
  6789. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  6790. /* Get VPD data into cache */
  6791. ha->vpd = ha->nvram + VPD_OFFSET;
  6792. ha->isp_ops->read_nvram(vha, ha->vpd,
  6793. ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
  6794. /* Get NVRAM data into cache and calculate checksum. */
  6795. dptr = (__force __le32 *)nv;
  6796. ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
  6797. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
  6798. chksum += le32_to_cpu(*dptr);
  6799. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
  6800. "Contents of NVRAM\n");
  6801. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
  6802. nv, ha->nvram_size);
  6803. /* Bad NVRAM data, set defaults parameters. */
  6804. if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
  6805. le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
  6806. /* Reset NVRAM data. */
  6807. ql_log(ql_log_warn, vha, 0x006b,
  6808. "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
  6809. chksum, nv->id, nv->nvram_version);
  6810. ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
  6811. ql_log(ql_log_warn, vha, 0x006c,
  6812. "Falling back to functioning (yet invalid -- WWPN) "
  6813. "defaults.\n");
  6814. /*
  6815. * Set default initialization control block.
  6816. */
  6817. memset(nv, 0, ha->nvram_size);
  6818. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  6819. nv->version = cpu_to_le16(ICB_VERSION);
  6820. nv->frame_payload_size = cpu_to_le16(2048);
  6821. nv->execution_throttle = cpu_to_le16(0xFFFF);
  6822. nv->exchange_count = cpu_to_le16(0);
  6823. nv->hard_address = cpu_to_le16(124);
  6824. nv->port_name[0] = 0x21;
  6825. nv->port_name[1] = 0x00 + ha->port_no + 1;
  6826. nv->port_name[2] = 0x00;
  6827. nv->port_name[3] = 0xe0;
  6828. nv->port_name[4] = 0x8b;
  6829. nv->port_name[5] = 0x1c;
  6830. nv->port_name[6] = 0x55;
  6831. nv->port_name[7] = 0x86;
  6832. nv->node_name[0] = 0x20;
  6833. nv->node_name[1] = 0x00;
  6834. nv->node_name[2] = 0x00;
  6835. nv->node_name[3] = 0xe0;
  6836. nv->node_name[4] = 0x8b;
  6837. nv->node_name[5] = 0x1c;
  6838. nv->node_name[6] = 0x55;
  6839. nv->node_name[7] = 0x86;
  6840. qla24xx_nvram_wwn_from_ofw(vha, nv);
  6841. nv->login_retry_count = cpu_to_le16(8);
  6842. nv->interrupt_delay_timer = cpu_to_le16(0);
  6843. nv->login_timeout = cpu_to_le16(0);
  6844. nv->firmware_options_1 =
  6845. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  6846. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  6847. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  6848. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  6849. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  6850. nv->efi_parameters = cpu_to_le32(0);
  6851. nv->reset_delay = 5;
  6852. nv->max_luns_per_target = cpu_to_le16(128);
  6853. nv->port_down_retry_count = cpu_to_le16(30);
  6854. nv->link_down_timeout = cpu_to_le16(30);
  6855. rval = 1;
  6856. }
  6857. if (qla_tgt_mode_enabled(vha)) {
  6858. /* Don't enable full login after initial LIP */
  6859. nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
  6860. /* Don't enable LIP full login for initiator */
  6861. nv->host_p &= cpu_to_le32(~BIT_10);
  6862. }
  6863. qlt_24xx_config_nvram_stage1(vha, nv);
  6864. /* Reset Initialization control block */
  6865. memset(icb, 0, ha->init_cb_size);
  6866. /* Copy 1st segment. */
  6867. dptr1 = (uint8_t *)icb;
  6868. dptr2 = (uint8_t *)&nv->version;
  6869. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  6870. while (cnt--)
  6871. *dptr1++ = *dptr2++;
  6872. icb->login_retry_count = nv->login_retry_count;
  6873. icb->link_down_on_nos = nv->link_down_on_nos;
  6874. /* Copy 2nd segment. */
  6875. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  6876. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  6877. cnt = (uint8_t *)&icb->reserved_3 -
  6878. (uint8_t *)&icb->interrupt_delay_timer;
  6879. while (cnt--)
  6880. *dptr1++ = *dptr2++;
  6881. ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
  6882. /*
  6883. * Setup driver NVRAM options.
  6884. */
  6885. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  6886. "QLA2462");
  6887. qlt_24xx_config_nvram_stage2(vha, icb);
  6888. if (nv->host_p & cpu_to_le32(BIT_15)) {
  6889. /* Use alternate WWN? */
  6890. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  6891. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  6892. }
  6893. /* Prepare nodename */
  6894. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  6895. /*
  6896. * Firmware will apply the following mask if the nodename was
  6897. * not provided.
  6898. */
  6899. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  6900. icb->node_name[0] &= 0xF0;
  6901. }
  6902. /* Set host adapter parameters. */
  6903. ha->flags.disable_risc_code_load = 0;
  6904. ha->flags.enable_lip_reset = 0;
  6905. ha->flags.enable_lip_full_login =
  6906. le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
  6907. ha->flags.enable_target_reset =
  6908. le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
  6909. ha->flags.enable_led_scheme = 0;
  6910. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
  6911. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  6912. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  6913. memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
  6914. sizeof(ha->fw_seriallink_options24));
  6915. /* save HBA serial number */
  6916. ha->serial0 = icb->port_name[5];
  6917. ha->serial1 = icb->port_name[6];
  6918. ha->serial2 = icb->port_name[7];
  6919. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  6920. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  6921. icb->execution_throttle = cpu_to_le16(0xFFFF);
  6922. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  6923. /* Set minimum login_timeout to 4 seconds. */
  6924. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  6925. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  6926. if (le16_to_cpu(nv->login_timeout) < 4)
  6927. nv->login_timeout = cpu_to_le16(4);
  6928. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  6929. /* Set minimum RATOV to 100 tenths of a second. */
  6930. ha->r_a_tov = 100;
  6931. ha->loop_reset_delay = nv->reset_delay;
  6932. /* Link Down Timeout = 0:
  6933. *
  6934. * When Port Down timer expires we will start returning
  6935. * I/O's to OS with "DID_NO_CONNECT".
  6936. *
  6937. * Link Down Timeout != 0:
  6938. *
  6939. * The driver waits for the link to come up after link down
  6940. * before returning I/Os to OS with "DID_NO_CONNECT".
  6941. */
  6942. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  6943. ha->loop_down_abort_time =
  6944. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  6945. } else {
  6946. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  6947. ha->loop_down_abort_time =
  6948. (LOOP_DOWN_TIME - ha->link_down_timeout);
  6949. }
  6950. /* Need enough time to try and get the port back. */
  6951. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  6952. if (qlport_down_retry)
  6953. ha->port_down_retry_count = qlport_down_retry;
  6954. /* Set login_retry_count */
  6955. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  6956. if (ha->port_down_retry_count ==
  6957. le16_to_cpu(nv->port_down_retry_count) &&
  6958. ha->port_down_retry_count > 3)
  6959. ha->login_retry_count = ha->port_down_retry_count;
  6960. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  6961. ha->login_retry_count = ha->port_down_retry_count;
  6962. if (ql2xloginretrycount)
  6963. ha->login_retry_count = ql2xloginretrycount;
  6964. /* N2N: driver will initiate Login instead of FW */
  6965. icb->firmware_options_3 |= cpu_to_le32(BIT_8);
  6966. /* Enable ZIO. */
  6967. if (!vha->flags.init_done) {
  6968. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  6969. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  6970. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  6971. le16_to_cpu(icb->interrupt_delay_timer) : 2;
  6972. }
  6973. icb->firmware_options_2 &= cpu_to_le32(
  6974. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  6975. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  6976. ha->zio_mode = QLA_ZIO_MODE_6;
  6977. ql_log(ql_log_info, vha, 0x006f,
  6978. "ZIO mode %d enabled; timer delay (%d us).\n",
  6979. ha->zio_mode, ha->zio_timer * 100);
  6980. icb->firmware_options_2 |= cpu_to_le32(
  6981. (uint32_t)ha->zio_mode);
  6982. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  6983. }
  6984. if (rval) {
  6985. ql_log(ql_log_warn, vha, 0x0070,
  6986. "NVRAM configuration failed.\n");
  6987. }
  6988. return (rval);
  6989. }
  6990. static void
  6991. qla27xx_print_image(struct scsi_qla_host *vha, char *name,
  6992. struct qla27xx_image_status *image_status)
  6993. {
  6994. ql_dbg(ql_dbg_init, vha, 0x018b,
  6995. "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
  6996. name, "status",
  6997. image_status->image_status_mask,
  6998. le16_to_cpu(image_status->generation),
  6999. image_status->ver_major,
  7000. image_status->ver_minor,
  7001. image_status->bitmap,
  7002. le32_to_cpu(image_status->checksum),
  7003. le32_to_cpu(image_status->signature));
  7004. }
  7005. static bool
  7006. qla28xx_check_aux_image_status_signature(
  7007. struct qla27xx_image_status *image_status)
  7008. {
  7009. ulong signature = le32_to_cpu(image_status->signature);
  7010. return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
  7011. }
  7012. static bool
  7013. qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
  7014. {
  7015. ulong signature = le32_to_cpu(image_status->signature);
  7016. return
  7017. signature != QLA27XX_IMG_STATUS_SIGN &&
  7018. signature != QLA28XX_IMG_STATUS_SIGN;
  7019. }
  7020. static ulong
  7021. qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
  7022. {
  7023. __le32 *p = (__force __le32 *)image_status;
  7024. uint n = sizeof(*image_status) / sizeof(*p);
  7025. uint32_t sum = 0;
  7026. for ( ; n--; p++)
  7027. sum += le32_to_cpup(p);
  7028. return sum;
  7029. }
  7030. static inline uint
  7031. qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
  7032. {
  7033. return aux->bitmap & bitmask ?
  7034. QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
  7035. }
  7036. static void
  7037. qla28xx_component_status(
  7038. struct active_regions *active_regions, struct qla27xx_image_status *aux)
  7039. {
  7040. active_regions->aux.board_config =
  7041. qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
  7042. active_regions->aux.vpd_nvram =
  7043. qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
  7044. active_regions->aux.npiv_config_0_1 =
  7045. qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
  7046. active_regions->aux.npiv_config_2_3 =
  7047. qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
  7048. active_regions->aux.nvme_params =
  7049. qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NVME_PARAMS);
  7050. }
  7051. static int
  7052. qla27xx_compare_image_generation(
  7053. struct qla27xx_image_status *pri_image_status,
  7054. struct qla27xx_image_status *sec_image_status)
  7055. {
  7056. /* calculate generation delta as uint16 (this accounts for wrap) */
  7057. int16_t delta =
  7058. le16_to_cpu(pri_image_status->generation) -
  7059. le16_to_cpu(sec_image_status->generation);
  7060. ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
  7061. return delta;
  7062. }
  7063. void
  7064. qla28xx_get_aux_images(
  7065. struct scsi_qla_host *vha, struct active_regions *active_regions)
  7066. {
  7067. struct qla_hw_data *ha = vha->hw;
  7068. struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
  7069. bool valid_pri_image = false, valid_sec_image = false;
  7070. bool active_pri_image = false, active_sec_image = false;
  7071. int rc;
  7072. if (!ha->flt_region_aux_img_status_pri) {
  7073. ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
  7074. goto check_sec_image;
  7075. }
  7076. rc = qla24xx_read_flash_data(vha, (uint32_t *)&pri_aux_image_status,
  7077. ha->flt_region_aux_img_status_pri,
  7078. sizeof(pri_aux_image_status) >> 2);
  7079. if (rc) {
  7080. ql_log(ql_log_info, vha, 0x01a1,
  7081. "Unable to read Primary aux image(%x).\n", rc);
  7082. goto check_sec_image;
  7083. }
  7084. qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
  7085. if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
  7086. ql_dbg(ql_dbg_init, vha, 0x018b,
  7087. "Primary aux image signature (%#x) not valid\n",
  7088. le32_to_cpu(pri_aux_image_status.signature));
  7089. goto check_sec_image;
  7090. }
  7091. if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
  7092. ql_dbg(ql_dbg_init, vha, 0x018c,
  7093. "Primary aux image checksum failed\n");
  7094. goto check_sec_image;
  7095. }
  7096. valid_pri_image = true;
  7097. if (pri_aux_image_status.image_status_mask & 1) {
  7098. ql_dbg(ql_dbg_init, vha, 0x018d,
  7099. "Primary aux image is active\n");
  7100. active_pri_image = true;
  7101. }
  7102. check_sec_image:
  7103. if (!ha->flt_region_aux_img_status_sec) {
  7104. ql_dbg(ql_dbg_init, vha, 0x018a,
  7105. "Secondary aux image not addressed\n");
  7106. goto check_valid_image;
  7107. }
  7108. rc = qla24xx_read_flash_data(vha, (uint32_t *)&sec_aux_image_status,
  7109. ha->flt_region_aux_img_status_sec,
  7110. sizeof(sec_aux_image_status) >> 2);
  7111. if (rc) {
  7112. ql_log(ql_log_info, vha, 0x01a2,
  7113. "Unable to read Secondary aux image(%x).\n", rc);
  7114. goto check_valid_image;
  7115. }
  7116. qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
  7117. if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
  7118. ql_dbg(ql_dbg_init, vha, 0x018b,
  7119. "Secondary aux image signature (%#x) not valid\n",
  7120. le32_to_cpu(sec_aux_image_status.signature));
  7121. goto check_valid_image;
  7122. }
  7123. if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
  7124. ql_dbg(ql_dbg_init, vha, 0x018c,
  7125. "Secondary aux image checksum failed\n");
  7126. goto check_valid_image;
  7127. }
  7128. valid_sec_image = true;
  7129. if (sec_aux_image_status.image_status_mask & 1) {
  7130. ql_dbg(ql_dbg_init, vha, 0x018d,
  7131. "Secondary aux image is active\n");
  7132. active_sec_image = true;
  7133. }
  7134. check_valid_image:
  7135. if (valid_pri_image && active_pri_image &&
  7136. valid_sec_image && active_sec_image) {
  7137. if (qla27xx_compare_image_generation(&pri_aux_image_status,
  7138. &sec_aux_image_status) >= 0) {
  7139. qla28xx_component_status(active_regions,
  7140. &pri_aux_image_status);
  7141. } else {
  7142. qla28xx_component_status(active_regions,
  7143. &sec_aux_image_status);
  7144. }
  7145. } else if (valid_pri_image && active_pri_image) {
  7146. qla28xx_component_status(active_regions, &pri_aux_image_status);
  7147. } else if (valid_sec_image && active_sec_image) {
  7148. qla28xx_component_status(active_regions, &sec_aux_image_status);
  7149. }
  7150. ql_dbg(ql_dbg_init, vha, 0x018f,
  7151. "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u, NVME=%u\n",
  7152. active_regions->aux.board_config,
  7153. active_regions->aux.vpd_nvram,
  7154. active_regions->aux.npiv_config_0_1,
  7155. active_regions->aux.npiv_config_2_3,
  7156. active_regions->aux.nvme_params);
  7157. }
  7158. void
  7159. qla27xx_get_active_image(struct scsi_qla_host *vha,
  7160. struct active_regions *active_regions)
  7161. {
  7162. struct qla_hw_data *ha = vha->hw;
  7163. struct qla27xx_image_status pri_image_status, sec_image_status;
  7164. bool valid_pri_image = false, valid_sec_image = false;
  7165. bool active_pri_image = false, active_sec_image = false;
  7166. int rc;
  7167. if (!ha->flt_region_img_status_pri) {
  7168. ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
  7169. goto check_sec_image;
  7170. }
  7171. if (qla24xx_read_flash_data(vha, (uint32_t *)&pri_image_status,
  7172. ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
  7173. QLA_SUCCESS) {
  7174. WARN_ON_ONCE(true);
  7175. goto check_sec_image;
  7176. }
  7177. qla27xx_print_image(vha, "Primary image", &pri_image_status);
  7178. if (qla27xx_check_image_status_signature(&pri_image_status)) {
  7179. ql_dbg(ql_dbg_init, vha, 0x018b,
  7180. "Primary image signature (%#x) not valid\n",
  7181. le32_to_cpu(pri_image_status.signature));
  7182. goto check_sec_image;
  7183. }
  7184. if (qla27xx_image_status_checksum(&pri_image_status)) {
  7185. ql_dbg(ql_dbg_init, vha, 0x018c,
  7186. "Primary image checksum failed\n");
  7187. goto check_sec_image;
  7188. }
  7189. valid_pri_image = true;
  7190. if (pri_image_status.image_status_mask & 1) {
  7191. ql_dbg(ql_dbg_init, vha, 0x018d,
  7192. "Primary image is active\n");
  7193. active_pri_image = true;
  7194. }
  7195. check_sec_image:
  7196. if (!ha->flt_region_img_status_sec) {
  7197. ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
  7198. goto check_valid_image;
  7199. }
  7200. rc = qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
  7201. ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
  7202. if (rc) {
  7203. ql_log(ql_log_info, vha, 0x01a3,
  7204. "Unable to read Secondary image status(%x).\n", rc);
  7205. goto check_valid_image;
  7206. }
  7207. qla27xx_print_image(vha, "Secondary image", &sec_image_status);
  7208. if (qla27xx_check_image_status_signature(&sec_image_status)) {
  7209. ql_dbg(ql_dbg_init, vha, 0x018b,
  7210. "Secondary image signature (%#x) not valid\n",
  7211. le32_to_cpu(sec_image_status.signature));
  7212. goto check_valid_image;
  7213. }
  7214. if (qla27xx_image_status_checksum(&sec_image_status)) {
  7215. ql_dbg(ql_dbg_init, vha, 0x018c,
  7216. "Secondary image checksum failed\n");
  7217. goto check_valid_image;
  7218. }
  7219. valid_sec_image = true;
  7220. if (sec_image_status.image_status_mask & 1) {
  7221. ql_dbg(ql_dbg_init, vha, 0x018d,
  7222. "Secondary image is active\n");
  7223. active_sec_image = true;
  7224. }
  7225. check_valid_image:
  7226. if (valid_pri_image && active_pri_image)
  7227. active_regions->global = QLA27XX_PRIMARY_IMAGE;
  7228. if (valid_sec_image && active_sec_image) {
  7229. if (!active_regions->global ||
  7230. qla27xx_compare_image_generation(
  7231. &pri_image_status, &sec_image_status) < 0) {
  7232. active_regions->global = QLA27XX_SECONDARY_IMAGE;
  7233. }
  7234. }
  7235. ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
  7236. active_regions->global == QLA27XX_DEFAULT_IMAGE ?
  7237. "default (boot/fw)" :
  7238. active_regions->global == QLA27XX_PRIMARY_IMAGE ?
  7239. "primary" :
  7240. active_regions->global == QLA27XX_SECONDARY_IMAGE ?
  7241. "secondary" : "invalid",
  7242. active_regions->global);
  7243. }
  7244. bool qla24xx_risc_firmware_invalid(uint32_t *dword)
  7245. {
  7246. return
  7247. !(dword[4] | dword[5] | dword[6] | dword[7]) ||
  7248. !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
  7249. }
  7250. static int
  7251. qla28xx_get_srisc_addr(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  7252. uint32_t faddr)
  7253. {
  7254. struct qla_hw_data *ha = vha->hw;
  7255. struct req_que *req = ha->req_q_map[0];
  7256. uint32_t *dcode;
  7257. int rval;
  7258. *srisc_addr = 0;
  7259. dcode = (uint32_t *)req->ring;
  7260. rval = qla24xx_read_flash_data(vha, dcode, faddr, 10);
  7261. if (rval) {
  7262. ql_log(ql_log_fatal, vha, 0x01aa,
  7263. "-> Failed to read flash addr + size .\n");
  7264. return QLA_FUNCTION_FAILED;
  7265. }
  7266. *srisc_addr = be32_to_cpu((__force __be32)dcode[2]);
  7267. return QLA_SUCCESS;
  7268. }
  7269. static int
  7270. qla28xx_load_fw_template(scsi_qla_host_t *vha, uint32_t faddr)
  7271. {
  7272. struct qla_hw_data *ha = vha->hw;
  7273. struct fwdt *fwdt = ha->fwdt;
  7274. struct req_que *req = ha->req_q_map[0];
  7275. uint32_t risc_size, risc_attr = 0;
  7276. uint templates, segments, fragment;
  7277. uint32_t *dcode;
  7278. ulong dlen;
  7279. int rval;
  7280. uint j;
  7281. dcode = (uint32_t *)req->ring;
  7282. segments = FA_RISC_CODE_SEGMENTS;
  7283. for (j = 0; j < segments; j++) {
  7284. rval = qla24xx_read_flash_data(vha, dcode, faddr, 10);
  7285. if (rval) {
  7286. ql_log(ql_log_fatal, vha, 0x01a1,
  7287. "-> Failed to read flash addr + size .\n");
  7288. return QLA_FUNCTION_FAILED;
  7289. }
  7290. risc_size = be32_to_cpu((__force __be32)dcode[3]);
  7291. if (risc_attr == 0)
  7292. risc_attr = be32_to_cpu((__force __be32)dcode[9]);
  7293. dlen = ha->fw_transfer_size >> 2;
  7294. for (fragment = 0; fragment < risc_size; fragment++) {
  7295. if (dlen > risc_size)
  7296. dlen = risc_size;
  7297. faddr += dlen;
  7298. risc_size -= dlen;
  7299. }
  7300. }
  7301. templates = (risc_attr & BIT_9) ? 2 : 1;
  7302. ql_dbg(ql_dbg_init, vha, 0x01a1, "-> templates = %u\n", templates);
  7303. for (j = 0; j < templates; j++, fwdt++) {
  7304. vfree(fwdt->template);
  7305. fwdt->template = NULL;
  7306. fwdt->length = 0;
  7307. dcode = (uint32_t *)req->ring;
  7308. rval = qla24xx_read_flash_data(vha, dcode, faddr, 7);
  7309. if (rval) {
  7310. ql_log(ql_log_fatal, vha, 0x01a2,
  7311. "-> Unable to read template size.\n");
  7312. goto failed;
  7313. }
  7314. risc_size = be32_to_cpu((__force __be32)dcode[2]);
  7315. ql_dbg(ql_dbg_init, vha, 0x01a3,
  7316. "-> fwdt%u template array at %#x (%#x dwords)\n",
  7317. j, faddr, risc_size);
  7318. if (!risc_size || !~risc_size) {
  7319. ql_dbg(ql_dbg_init, vha, 0x01a4,
  7320. "-> fwdt%u failed to read array\n", j);
  7321. goto failed;
  7322. }
  7323. /* skip header and ignore checksum */
  7324. faddr += 7;
  7325. risc_size -= 8;
  7326. ql_dbg(ql_dbg_init, vha, 0x01a5,
  7327. "-> fwdt%u template allocate template %#x words...\n",
  7328. j, risc_size);
  7329. fwdt->template = vmalloc(risc_size * sizeof(*dcode));
  7330. if (!fwdt->template) {
  7331. ql_log(ql_log_warn, vha, 0x01a6,
  7332. "-> fwdt%u failed allocate template.\n", j);
  7333. goto failed;
  7334. }
  7335. dcode = fwdt->template;
  7336. rval = qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
  7337. if (rval || !qla27xx_fwdt_template_valid(dcode)) {
  7338. ql_log(ql_log_warn, vha, 0x01a7,
  7339. "-> fwdt%u failed template validate (rval %x)\n",
  7340. j, rval);
  7341. goto failed;
  7342. }
  7343. dlen = qla27xx_fwdt_template_size(dcode);
  7344. ql_dbg(ql_dbg_init, vha, 0x01a7,
  7345. "-> fwdt%u template size %#lx bytes (%#lx words)\n",
  7346. j, dlen, dlen / sizeof(*dcode));
  7347. if (dlen > risc_size * sizeof(*dcode)) {
  7348. ql_log(ql_log_warn, vha, 0x01a8,
  7349. "-> fwdt%u template exceeds array (%-lu bytes)\n",
  7350. j, dlen - risc_size * sizeof(*dcode));
  7351. goto failed;
  7352. }
  7353. fwdt->length = dlen;
  7354. ql_dbg(ql_dbg_init, vha, 0x01a9,
  7355. "-> fwdt%u loaded template ok\n", j);
  7356. faddr += risc_size + 1;
  7357. }
  7358. return QLA_SUCCESS;
  7359. failed:
  7360. vfree(fwdt->template);
  7361. fwdt->template = NULL;
  7362. fwdt->length = 0;
  7363. return QLA_SUCCESS;
  7364. }
  7365. static int
  7366. qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
  7367. uint32_t faddr)
  7368. {
  7369. int rval;
  7370. uint templates, segments, fragment;
  7371. ulong i;
  7372. uint j;
  7373. ulong dlen;
  7374. uint32_t *dcode;
  7375. uint32_t risc_addr, risc_size, risc_attr = 0;
  7376. struct qla_hw_data *ha = vha->hw;
  7377. struct req_que *req = ha->req_q_map[0];
  7378. struct fwdt *fwdt = ha->fwdt;
  7379. ql_dbg(ql_dbg_init, vha, 0x008b,
  7380. "FW: Loading firmware from flash (%x).\n", faddr);
  7381. dcode = (uint32_t *)req->ring;
  7382. rval = qla24xx_read_flash_data(vha, dcode, faddr, 8);
  7383. if (rval || qla24xx_risc_firmware_invalid(dcode)) {
  7384. ql_log(ql_log_fatal, vha, 0x008c,
  7385. "Unable to verify the integrity of flash firmware image (rval %x).\n", rval);
  7386. ql_log(ql_log_fatal, vha, 0x008d,
  7387. "Firmware data: %08x %08x %08x %08x.\n",
  7388. dcode[0], dcode[1], dcode[2], dcode[3]);
  7389. return QLA_FUNCTION_FAILED;
  7390. }
  7391. dcode = (uint32_t *)req->ring;
  7392. *srisc_addr = 0;
  7393. segments = FA_RISC_CODE_SEGMENTS;
  7394. for (j = 0; j < segments; j++) {
  7395. ql_dbg(ql_dbg_init, vha, 0x008d,
  7396. "-> Loading segment %u...\n", j);
  7397. rval = qla24xx_read_flash_data(vha, dcode, faddr, 10);
  7398. if (rval) {
  7399. ql_log(ql_log_fatal, vha, 0x016a,
  7400. "-> Unable to read segment addr + size .\n");
  7401. return QLA_FUNCTION_FAILED;
  7402. }
  7403. risc_addr = be32_to_cpu((__force __be32)dcode[2]);
  7404. risc_size = be32_to_cpu((__force __be32)dcode[3]);
  7405. if (!*srisc_addr) {
  7406. *srisc_addr = risc_addr;
  7407. risc_attr = be32_to_cpu((__force __be32)dcode[9]);
  7408. }
  7409. dlen = ha->fw_transfer_size >> 2;
  7410. for (fragment = 0; risc_size; fragment++) {
  7411. if (dlen > risc_size)
  7412. dlen = risc_size;
  7413. ql_dbg(ql_dbg_init, vha, 0x008e,
  7414. "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
  7415. fragment, risc_addr, faddr, dlen);
  7416. rval = qla24xx_read_flash_data(vha, dcode, faddr, dlen);
  7417. if (rval) {
  7418. ql_log(ql_log_fatal, vha, 0x016b,
  7419. "-> Unable to read fragment(faddr %#x dlen %#lx).\n",
  7420. faddr, dlen);
  7421. return QLA_FUNCTION_FAILED;
  7422. }
  7423. for (i = 0; i < dlen; i++)
  7424. dcode[i] = swab32(dcode[i]);
  7425. rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
  7426. if (rval) {
  7427. ql_log(ql_log_fatal, vha, 0x008f,
  7428. "-> Failed load firmware fragment %u.\n",
  7429. fragment);
  7430. return QLA_FUNCTION_FAILED;
  7431. }
  7432. faddr += dlen;
  7433. risc_addr += dlen;
  7434. risc_size -= dlen;
  7435. }
  7436. }
  7437. if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
  7438. return QLA_SUCCESS;
  7439. templates = (risc_attr & BIT_9) ? 2 : 1;
  7440. ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
  7441. for (j = 0; j < templates; j++, fwdt++) {
  7442. vfree(fwdt->template);
  7443. fwdt->template = NULL;
  7444. fwdt->length = 0;
  7445. dcode = (uint32_t *)req->ring;
  7446. rval = qla24xx_read_flash_data(vha, dcode, faddr, 7);
  7447. if (rval) {
  7448. ql_log(ql_log_fatal, vha, 0x016c,
  7449. "-> Unable to read template size.\n");
  7450. goto failed;
  7451. }
  7452. risc_size = be32_to_cpu((__force __be32)dcode[2]);
  7453. ql_dbg(ql_dbg_init, vha, 0x0161,
  7454. "-> fwdt%u template array at %#x (%#x dwords)\n",
  7455. j, faddr, risc_size);
  7456. if (!risc_size || !~risc_size) {
  7457. ql_dbg(ql_dbg_init, vha, 0x0162,
  7458. "-> fwdt%u failed to read array\n", j);
  7459. goto failed;
  7460. }
  7461. /* skip header and ignore checksum */
  7462. faddr += 7;
  7463. risc_size -= 8;
  7464. ql_dbg(ql_dbg_init, vha, 0x0163,
  7465. "-> fwdt%u template allocate template %#x words...\n",
  7466. j, risc_size);
  7467. fwdt->template = vmalloc_array(risc_size, sizeof(*dcode));
  7468. if (!fwdt->template) {
  7469. ql_log(ql_log_warn, vha, 0x0164,
  7470. "-> fwdt%u failed allocate template.\n", j);
  7471. goto failed;
  7472. }
  7473. dcode = fwdt->template;
  7474. rval = qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
  7475. if (rval || !qla27xx_fwdt_template_valid(dcode)) {
  7476. ql_log(ql_log_warn, vha, 0x0165,
  7477. "-> fwdt%u failed template validate (rval %x)\n",
  7478. j, rval);
  7479. goto failed;
  7480. }
  7481. dlen = qla27xx_fwdt_template_size(dcode);
  7482. ql_dbg(ql_dbg_init, vha, 0x0166,
  7483. "-> fwdt%u template size %#lx bytes (%#lx words)\n",
  7484. j, dlen, dlen / sizeof(*dcode));
  7485. if (dlen > risc_size * sizeof(*dcode)) {
  7486. ql_log(ql_log_warn, vha, 0x0167,
  7487. "-> fwdt%u template exceeds array (%-lu bytes)\n",
  7488. j, dlen - risc_size * sizeof(*dcode));
  7489. goto failed;
  7490. }
  7491. fwdt->length = dlen;
  7492. ql_dbg(ql_dbg_init, vha, 0x0168,
  7493. "-> fwdt%u loaded template ok\n", j);
  7494. faddr += risc_size + 1;
  7495. }
  7496. return QLA_SUCCESS;
  7497. failed:
  7498. vfree(fwdt->template);
  7499. fwdt->template = NULL;
  7500. fwdt->length = 0;
  7501. return QLA_SUCCESS;
  7502. }
  7503. int
  7504. qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  7505. {
  7506. int rval;
  7507. int i, fragment;
  7508. uint16_t *wcode;
  7509. __be16 *fwcode;
  7510. uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
  7511. struct fw_blob *blob;
  7512. struct qla_hw_data *ha = vha->hw;
  7513. struct req_que *req = ha->req_q_map[0];
  7514. /* Load firmware blob. */
  7515. blob = qla2x00_request_firmware(vha);
  7516. if (!blob) {
  7517. ql_log(ql_log_info, vha, 0x0083,
  7518. "Firmware image unavailable.\n");
  7519. return QLA_FUNCTION_FAILED;
  7520. }
  7521. rval = QLA_SUCCESS;
  7522. wcode = (uint16_t *)req->ring;
  7523. *srisc_addr = 0;
  7524. fwcode = (__force __be16 *)blob->fw->data;
  7525. fwclen = 0;
  7526. /* Validate firmware image by checking version. */
  7527. if (blob->fw->size < 8 * sizeof(uint16_t)) {
  7528. ql_log(ql_log_fatal, vha, 0x0085,
  7529. "Unable to verify integrity of firmware image (%zd).\n",
  7530. blob->fw->size);
  7531. goto fail_fw_integrity;
  7532. }
  7533. for (i = 0; i < 4; i++)
  7534. wcode[i] = be16_to_cpu(fwcode[i + 4]);
  7535. if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
  7536. wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
  7537. wcode[2] == 0 && wcode[3] == 0)) {
  7538. ql_log(ql_log_fatal, vha, 0x0086,
  7539. "Unable to verify integrity of firmware image.\n");
  7540. ql_log(ql_log_fatal, vha, 0x0087,
  7541. "Firmware data: %04x %04x %04x %04x.\n",
  7542. wcode[0], wcode[1], wcode[2], wcode[3]);
  7543. goto fail_fw_integrity;
  7544. }
  7545. seg = blob->segs;
  7546. while (*seg && rval == QLA_SUCCESS) {
  7547. risc_addr = *seg;
  7548. *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
  7549. risc_size = be16_to_cpu(fwcode[3]);
  7550. /* Validate firmware image size. */
  7551. fwclen += risc_size * sizeof(uint16_t);
  7552. if (blob->fw->size < fwclen) {
  7553. ql_log(ql_log_fatal, vha, 0x0088,
  7554. "Unable to verify integrity of firmware image "
  7555. "(%zd).\n", blob->fw->size);
  7556. goto fail_fw_integrity;
  7557. }
  7558. fragment = 0;
  7559. while (risc_size > 0 && rval == QLA_SUCCESS) {
  7560. wlen = (uint16_t)(ha->fw_transfer_size >> 1);
  7561. if (wlen > risc_size)
  7562. wlen = risc_size;
  7563. ql_dbg(ql_dbg_init, vha, 0x0089,
  7564. "Loading risc segment@ risc addr %x number of "
  7565. "words 0x%x.\n", risc_addr, wlen);
  7566. for (i = 0; i < wlen; i++)
  7567. wcode[i] = swab16((__force u32)fwcode[i]);
  7568. rval = qla2x00_load_ram(vha, req->dma, risc_addr,
  7569. wlen);
  7570. if (rval) {
  7571. ql_log(ql_log_fatal, vha, 0x008a,
  7572. "Failed to load segment %d of firmware.\n",
  7573. fragment);
  7574. break;
  7575. }
  7576. fwcode += wlen;
  7577. risc_addr += wlen;
  7578. risc_size -= wlen;
  7579. fragment++;
  7580. }
  7581. /* Next segment. */
  7582. seg++;
  7583. }
  7584. return rval;
  7585. fail_fw_integrity:
  7586. return QLA_FUNCTION_FAILED;
  7587. }
  7588. static int
  7589. qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  7590. {
  7591. int rval;
  7592. uint templates, segments, fragment;
  7593. uint32_t *dcode;
  7594. ulong dlen;
  7595. uint32_t risc_addr, risc_size, risc_attr = 0;
  7596. ulong i;
  7597. uint j;
  7598. struct fw_blob *blob;
  7599. __be32 *fwcode;
  7600. struct qla_hw_data *ha = vha->hw;
  7601. struct req_que *req = ha->req_q_map[0];
  7602. struct fwdt *fwdt = ha->fwdt;
  7603. ql_dbg(ql_dbg_init, vha, 0x0090,
  7604. "-> FW: Loading via request-firmware.\n");
  7605. blob = qla2x00_request_firmware(vha);
  7606. if (!blob) {
  7607. ql_log(ql_log_warn, vha, 0x0092,
  7608. "-> Firmware file not found.\n");
  7609. return QLA_FUNCTION_FAILED;
  7610. }
  7611. fwcode = (__force __be32 *)blob->fw->data;
  7612. dcode = (__force uint32_t *)fwcode;
  7613. if (qla24xx_risc_firmware_invalid(dcode)) {
  7614. ql_log(ql_log_fatal, vha, 0x0093,
  7615. "Unable to verify integrity of firmware image (%zd).\n",
  7616. blob->fw->size);
  7617. ql_log(ql_log_fatal, vha, 0x0095,
  7618. "Firmware data: %08x %08x %08x %08x.\n",
  7619. dcode[0], dcode[1], dcode[2], dcode[3]);
  7620. return QLA_FUNCTION_FAILED;
  7621. }
  7622. dcode = (uint32_t *)req->ring;
  7623. *srisc_addr = 0;
  7624. segments = FA_RISC_CODE_SEGMENTS;
  7625. for (j = 0; j < segments; j++) {
  7626. ql_dbg(ql_dbg_init, vha, 0x0096,
  7627. "-> Loading segment %u...\n", j);
  7628. risc_addr = be32_to_cpu(fwcode[2]);
  7629. risc_size = be32_to_cpu(fwcode[3]);
  7630. if (!*srisc_addr) {
  7631. *srisc_addr = risc_addr;
  7632. risc_attr = be32_to_cpu(fwcode[9]);
  7633. }
  7634. dlen = ha->fw_transfer_size >> 2;
  7635. for (fragment = 0; risc_size; fragment++) {
  7636. if (dlen > risc_size)
  7637. dlen = risc_size;
  7638. ql_dbg(ql_dbg_init, vha, 0x0097,
  7639. "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
  7640. fragment, risc_addr,
  7641. (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
  7642. dlen);
  7643. for (i = 0; i < dlen; i++)
  7644. dcode[i] = swab32((__force u32)fwcode[i]);
  7645. rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
  7646. if (rval) {
  7647. ql_log(ql_log_fatal, vha, 0x0098,
  7648. "-> Failed load firmware fragment %u.\n",
  7649. fragment);
  7650. return QLA_FUNCTION_FAILED;
  7651. }
  7652. fwcode += dlen;
  7653. risc_addr += dlen;
  7654. risc_size -= dlen;
  7655. }
  7656. }
  7657. if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
  7658. return QLA_SUCCESS;
  7659. templates = (risc_attr & BIT_9) ? 2 : 1;
  7660. ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
  7661. for (j = 0; j < templates; j++, fwdt++) {
  7662. vfree(fwdt->template);
  7663. fwdt->template = NULL;
  7664. fwdt->length = 0;
  7665. risc_size = be32_to_cpu(fwcode[2]);
  7666. ql_dbg(ql_dbg_init, vha, 0x0171,
  7667. "-> fwdt%u template array at %#x (%#x dwords)\n",
  7668. j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
  7669. risc_size);
  7670. if (!risc_size || !~risc_size) {
  7671. ql_dbg(ql_dbg_init, vha, 0x0172,
  7672. "-> fwdt%u failed to read array\n", j);
  7673. goto failed;
  7674. }
  7675. /* skip header and ignore checksum */
  7676. fwcode += 7;
  7677. risc_size -= 8;
  7678. ql_dbg(ql_dbg_init, vha, 0x0173,
  7679. "-> fwdt%u template allocate template %#x words...\n",
  7680. j, risc_size);
  7681. fwdt->template = vmalloc_array(risc_size, sizeof(*dcode));
  7682. if (!fwdt->template) {
  7683. ql_log(ql_log_warn, vha, 0x0174,
  7684. "-> fwdt%u failed allocate template.\n", j);
  7685. goto failed;
  7686. }
  7687. dcode = fwdt->template;
  7688. for (i = 0; i < risc_size; i++)
  7689. dcode[i] = (__force u32)fwcode[i];
  7690. if (!qla27xx_fwdt_template_valid(dcode)) {
  7691. ql_log(ql_log_warn, vha, 0x0175,
  7692. "-> fwdt%u failed template validate\n", j);
  7693. goto failed;
  7694. }
  7695. dlen = qla27xx_fwdt_template_size(dcode);
  7696. ql_dbg(ql_dbg_init, vha, 0x0176,
  7697. "-> fwdt%u template size %#lx bytes (%#lx words)\n",
  7698. j, dlen, dlen / sizeof(*dcode));
  7699. if (dlen > risc_size * sizeof(*dcode)) {
  7700. ql_log(ql_log_warn, vha, 0x0177,
  7701. "-> fwdt%u template exceeds array (%-lu bytes)\n",
  7702. j, dlen - risc_size * sizeof(*dcode));
  7703. goto failed;
  7704. }
  7705. fwdt->length = dlen;
  7706. ql_dbg(ql_dbg_init, vha, 0x0178,
  7707. "-> fwdt%u loaded template ok\n", j);
  7708. fwcode += risc_size + 1;
  7709. }
  7710. return QLA_SUCCESS;
  7711. failed:
  7712. vfree(fwdt->template);
  7713. fwdt->template = NULL;
  7714. fwdt->length = 0;
  7715. return QLA_SUCCESS;
  7716. }
  7717. int
  7718. qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  7719. {
  7720. int rval;
  7721. if (ql2xfwloadbin == 1)
  7722. return qla81xx_load_risc(vha, srisc_addr);
  7723. /*
  7724. * FW Load priority:
  7725. * 1) Firmware via request-firmware interface (.bin file).
  7726. * 2) Firmware residing in flash.
  7727. */
  7728. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  7729. if (rval == QLA_SUCCESS)
  7730. return rval;
  7731. return qla24xx_load_risc_flash(vha, srisc_addr,
  7732. vha->hw->flt_region_fw);
  7733. }
  7734. int
  7735. qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
  7736. {
  7737. int rval;
  7738. uint32_t f_region = 0;
  7739. struct qla_hw_data *ha = vha->hw;
  7740. struct active_regions active_regions = { };
  7741. if (ql2xfwloadbin == 2 && !IS_QLA28XX(ha))
  7742. goto try_blob_fw;
  7743. /* FW Load priority:
  7744. * 1) If 28xxx, ROM cmd to load flash firmware.
  7745. * 2) Firmware residing in flash.
  7746. * 3) Firmware via request-firmware interface (.bin file).
  7747. * 4) Golden-Firmware residing in flash -- (limited operation).
  7748. */
  7749. if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
  7750. goto try_primary_fw;
  7751. qla27xx_get_active_image(vha, &active_regions);
  7752. /* For 28XXX, always load the flash firmware using rom mbx */
  7753. if (IS_QLA28XX_SECURED(ha)) {
  7754. rval = qla28xx_load_flash_firmware(vha);
  7755. if (rval != QLA_SUCCESS) {
  7756. ql_log(ql_log_fatal, vha, 0x019e,
  7757. "Failed to load flash firmware.\n");
  7758. goto exit_load_risc;
  7759. }
  7760. f_region =
  7761. (active_regions.global != QLA27XX_SECONDARY_IMAGE) ?
  7762. ha->flt_region_fw : ha->flt_region_fw_sec;
  7763. ql_log(ql_log_info, vha, 0x019f,
  7764. "Load flash firmware successful (%s).\n",
  7765. ((active_regions.global != QLA27XX_SECONDARY_IMAGE) ?
  7766. "Primary" : "Secondary"));
  7767. rval = qla28xx_get_srisc_addr(vha, srisc_addr, f_region);
  7768. if (rval != QLA_SUCCESS) {
  7769. ql_log(ql_log_warn, vha, 0x019f,
  7770. "failed to read srisc address\n");
  7771. goto exit_load_risc;
  7772. }
  7773. rval = qla28xx_load_fw_template(vha, f_region);
  7774. if (rval != QLA_SUCCESS) {
  7775. ql_log(ql_log_warn, vha, 0x01a0,
  7776. "failed to read firmware template\n");
  7777. }
  7778. goto exit_load_risc;
  7779. }
  7780. if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
  7781. goto try_primary_fw;
  7782. ql_dbg(ql_dbg_init, vha, 0x008b,
  7783. "Loading secondary firmware image.\n");
  7784. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
  7785. if (!rval)
  7786. return rval;
  7787. try_primary_fw:
  7788. ql_dbg(ql_dbg_init, vha, 0x008b,
  7789. "Loading primary firmware image.\n");
  7790. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
  7791. if (!rval)
  7792. return rval;
  7793. try_blob_fw:
  7794. rval = qla24xx_load_risc_blob(vha, srisc_addr);
  7795. if (!rval || !ha->flt_region_gold_fw)
  7796. return rval;
  7797. ql_log(ql_log_info, vha, 0x0099,
  7798. "Attempting to fallback to golden firmware.\n");
  7799. rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
  7800. if (rval)
  7801. return rval;
  7802. ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
  7803. ha->flags.running_gold_fw = 1;
  7804. exit_load_risc:
  7805. return rval;
  7806. }
  7807. void
  7808. qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
  7809. {
  7810. int ret, retries;
  7811. struct qla_hw_data *ha = vha->hw;
  7812. if (ha->flags.pci_channel_io_perm_failure)
  7813. return;
  7814. if (!IS_FWI2_CAPABLE(ha))
  7815. return;
  7816. if (!ha->fw_major_version)
  7817. return;
  7818. if (!ha->flags.fw_started)
  7819. return;
  7820. ret = qla2x00_stop_firmware(vha);
  7821. for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
  7822. ret != QLA_INVALID_COMMAND && retries ; retries--) {
  7823. ha->isp_ops->reset_chip(vha);
  7824. if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
  7825. continue;
  7826. if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
  7827. continue;
  7828. ql_log(ql_log_info, vha, 0x8015,
  7829. "Attempting retry of stop-firmware command.\n");
  7830. ret = qla2x00_stop_firmware(vha);
  7831. }
  7832. QLA_FW_STOPPED(ha);
  7833. ha->flags.fw_init_done = 0;
  7834. }
  7835. int
  7836. qla24xx_configure_vhba(scsi_qla_host_t *vha)
  7837. {
  7838. int rval = QLA_SUCCESS;
  7839. int rval2;
  7840. uint16_t mb[MAILBOX_REGISTER_COUNT];
  7841. struct qla_hw_data *ha = vha->hw;
  7842. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  7843. if (!vha->vp_idx)
  7844. return -EINVAL;
  7845. rval = qla2x00_fw_ready(base_vha);
  7846. if (rval == QLA_SUCCESS) {
  7847. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  7848. qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
  7849. }
  7850. vha->flags.management_server_logged_in = 0;
  7851. /* Login to SNS first */
  7852. rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
  7853. BIT_1);
  7854. if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
  7855. if (rval2 == QLA_MEMORY_ALLOC_FAILED)
  7856. ql_dbg(ql_dbg_init, vha, 0x0120,
  7857. "Failed SNS login: loop_id=%x, rval2=%d\n",
  7858. NPH_SNS, rval2);
  7859. else
  7860. ql_dbg(ql_dbg_init, vha, 0x0103,
  7861. "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
  7862. "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
  7863. NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
  7864. return (QLA_FUNCTION_FAILED);
  7865. }
  7866. atomic_set(&vha->loop_down_timer, 0);
  7867. atomic_set(&vha->loop_state, LOOP_UP);
  7868. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  7869. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  7870. rval = qla2x00_loop_resync(base_vha);
  7871. return rval;
  7872. }
  7873. /* 84XX Support **************************************************************/
  7874. static LIST_HEAD(qla_cs84xx_list);
  7875. static DEFINE_MUTEX(qla_cs84xx_mutex);
  7876. static struct qla_chip_state_84xx *
  7877. qla84xx_get_chip(struct scsi_qla_host *vha)
  7878. {
  7879. struct qla_chip_state_84xx *cs84xx;
  7880. struct qla_hw_data *ha = vha->hw;
  7881. mutex_lock(&qla_cs84xx_mutex);
  7882. /* Find any shared 84xx chip. */
  7883. list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
  7884. if (cs84xx->bus == ha->pdev->bus) {
  7885. kref_get(&cs84xx->kref);
  7886. goto done;
  7887. }
  7888. }
  7889. cs84xx = kzalloc_obj(*cs84xx);
  7890. if (!cs84xx)
  7891. goto done;
  7892. kref_init(&cs84xx->kref);
  7893. spin_lock_init(&cs84xx->access_lock);
  7894. mutex_init(&cs84xx->fw_update_mutex);
  7895. cs84xx->bus = ha->pdev->bus;
  7896. list_add_tail(&cs84xx->list, &qla_cs84xx_list);
  7897. done:
  7898. mutex_unlock(&qla_cs84xx_mutex);
  7899. return cs84xx;
  7900. }
  7901. static void
  7902. __qla84xx_chip_release(struct kref *kref)
  7903. {
  7904. struct qla_chip_state_84xx *cs84xx =
  7905. container_of(kref, struct qla_chip_state_84xx, kref);
  7906. mutex_lock(&qla_cs84xx_mutex);
  7907. list_del(&cs84xx->list);
  7908. mutex_unlock(&qla_cs84xx_mutex);
  7909. kfree(cs84xx);
  7910. }
  7911. void
  7912. qla84xx_put_chip(struct scsi_qla_host *vha)
  7913. {
  7914. struct qla_hw_data *ha = vha->hw;
  7915. if (ha->cs84xx)
  7916. kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
  7917. }
  7918. static int
  7919. qla84xx_init_chip(scsi_qla_host_t *vha)
  7920. {
  7921. int rval;
  7922. uint16_t status[2];
  7923. struct qla_hw_data *ha = vha->hw;
  7924. mutex_lock(&ha->cs84xx->fw_update_mutex);
  7925. rval = qla84xx_verify_chip(vha, status);
  7926. mutex_unlock(&ha->cs84xx->fw_update_mutex);
  7927. return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
  7928. QLA_SUCCESS;
  7929. }
  7930. /* 81XX Support **************************************************************/
  7931. int
  7932. qla81xx_nvram_config(scsi_qla_host_t *vha)
  7933. {
  7934. int rval;
  7935. struct init_cb_81xx *icb;
  7936. struct nvram_81xx *nv;
  7937. __le32 *dptr;
  7938. uint8_t *dptr1, *dptr2;
  7939. uint32_t chksum;
  7940. uint16_t cnt;
  7941. struct qla_hw_data *ha = vha->hw;
  7942. uint32_t faddr;
  7943. struct active_regions active_regions = { };
  7944. rval = QLA_SUCCESS;
  7945. icb = (struct init_cb_81xx *)ha->init_cb;
  7946. nv = ha->nvram;
  7947. /* Determine NVRAM starting address. */
  7948. ha->nvram_size = sizeof(*nv);
  7949. ha->vpd_size = FA_NVRAM_VPD_SIZE;
  7950. if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
  7951. ha->vpd_size = FA_VPD_SIZE_82XX;
  7952. if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
  7953. qla28xx_get_aux_images(vha, &active_regions);
  7954. /* Get VPD data into cache */
  7955. ha->vpd = ha->nvram + VPD_OFFSET;
  7956. faddr = ha->flt_region_vpd;
  7957. if (IS_QLA28XX(ha)) {
  7958. if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
  7959. faddr = ha->flt_region_vpd_sec;
  7960. ql_dbg(ql_dbg_init, vha, 0x0110,
  7961. "Loading %s nvram image.\n",
  7962. active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
  7963. "primary" : "secondary");
  7964. }
  7965. ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
  7966. /* Get NVRAM data into cache and calculate checksum. */
  7967. faddr = ha->flt_region_nvram;
  7968. if (IS_QLA28XX(ha)) {
  7969. if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
  7970. faddr = ha->flt_region_nvram_sec;
  7971. }
  7972. ql_dbg(ql_dbg_init, vha, 0x0110,
  7973. "Loading %s nvram image.\n",
  7974. active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
  7975. "primary" : "secondary");
  7976. ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
  7977. dptr = (__force __le32 *)nv;
  7978. for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
  7979. chksum += le32_to_cpu(*dptr);
  7980. ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
  7981. "Contents of NVRAM:\n");
  7982. ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
  7983. nv, ha->nvram_size);
  7984. /* Bad NVRAM data, set defaults parameters. */
  7985. if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
  7986. le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
  7987. /* Reset NVRAM data. */
  7988. ql_log(ql_log_info, vha, 0x0073,
  7989. "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
  7990. chksum, nv->id, le16_to_cpu(nv->nvram_version));
  7991. ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
  7992. ql_log(ql_log_info, vha, 0x0074,
  7993. "Falling back to functioning (yet invalid -- WWPN) "
  7994. "defaults.\n");
  7995. /*
  7996. * Set default initialization control block.
  7997. */
  7998. memset(nv, 0, ha->nvram_size);
  7999. nv->nvram_version = cpu_to_le16(ICB_VERSION);
  8000. nv->version = cpu_to_le16(ICB_VERSION);
  8001. nv->frame_payload_size = cpu_to_le16(2048);
  8002. nv->execution_throttle = cpu_to_le16(0xFFFF);
  8003. nv->exchange_count = cpu_to_le16(0);
  8004. nv->port_name[0] = 0x21;
  8005. nv->port_name[1] = 0x00 + ha->port_no + 1;
  8006. nv->port_name[2] = 0x00;
  8007. nv->port_name[3] = 0xe0;
  8008. nv->port_name[4] = 0x8b;
  8009. nv->port_name[5] = 0x1c;
  8010. nv->port_name[6] = 0x55;
  8011. nv->port_name[7] = 0x86;
  8012. nv->node_name[0] = 0x20;
  8013. nv->node_name[1] = 0x00;
  8014. nv->node_name[2] = 0x00;
  8015. nv->node_name[3] = 0xe0;
  8016. nv->node_name[4] = 0x8b;
  8017. nv->node_name[5] = 0x1c;
  8018. nv->node_name[6] = 0x55;
  8019. nv->node_name[7] = 0x86;
  8020. nv->login_retry_count = cpu_to_le16(8);
  8021. nv->interrupt_delay_timer = cpu_to_le16(0);
  8022. nv->login_timeout = cpu_to_le16(0);
  8023. nv->firmware_options_1 =
  8024. cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
  8025. nv->firmware_options_2 = cpu_to_le32(2 << 4);
  8026. nv->firmware_options_2 |= cpu_to_le32(BIT_12);
  8027. nv->firmware_options_3 = cpu_to_le32(2 << 13);
  8028. nv->host_p = cpu_to_le32(BIT_11|BIT_10);
  8029. nv->efi_parameters = cpu_to_le32(0);
  8030. nv->reset_delay = 5;
  8031. nv->max_luns_per_target = cpu_to_le16(128);
  8032. nv->port_down_retry_count = cpu_to_le16(30);
  8033. nv->link_down_timeout = cpu_to_le16(180);
  8034. nv->enode_mac[0] = 0x00;
  8035. nv->enode_mac[1] = 0xC0;
  8036. nv->enode_mac[2] = 0xDD;
  8037. nv->enode_mac[3] = 0x04;
  8038. nv->enode_mac[4] = 0x05;
  8039. nv->enode_mac[5] = 0x06 + ha->port_no + 1;
  8040. rval = 1;
  8041. }
  8042. if (IS_T10_PI_CAPABLE(ha))
  8043. nv->frame_payload_size &= cpu_to_le16(~7);
  8044. qlt_81xx_config_nvram_stage1(vha, nv);
  8045. /* Reset Initialization control block */
  8046. memset(icb, 0, ha->init_cb_size);
  8047. /* Copy 1st segment. */
  8048. dptr1 = (uint8_t *)icb;
  8049. dptr2 = (uint8_t *)&nv->version;
  8050. cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
  8051. while (cnt--)
  8052. *dptr1++ = *dptr2++;
  8053. icb->login_retry_count = nv->login_retry_count;
  8054. /* Copy 2nd segment. */
  8055. dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
  8056. dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
  8057. cnt = (uint8_t *)&icb->reserved_5 -
  8058. (uint8_t *)&icb->interrupt_delay_timer;
  8059. while (cnt--)
  8060. *dptr1++ = *dptr2++;
  8061. memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
  8062. /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
  8063. if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
  8064. icb->enode_mac[0] = 0x00;
  8065. icb->enode_mac[1] = 0xC0;
  8066. icb->enode_mac[2] = 0xDD;
  8067. icb->enode_mac[3] = 0x04;
  8068. icb->enode_mac[4] = 0x05;
  8069. icb->enode_mac[5] = 0x06 + ha->port_no + 1;
  8070. }
  8071. /* Use extended-initialization control block. */
  8072. memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
  8073. ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
  8074. /*
  8075. * Setup driver NVRAM options.
  8076. */
  8077. qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
  8078. "QLE8XXX");
  8079. qlt_81xx_config_nvram_stage2(vha, icb);
  8080. /* Use alternate WWN? */
  8081. if (nv->host_p & cpu_to_le32(BIT_15)) {
  8082. memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
  8083. memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
  8084. }
  8085. /* Prepare nodename */
  8086. if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
  8087. /*
  8088. * Firmware will apply the following mask if the nodename was
  8089. * not provided.
  8090. */
  8091. memcpy(icb->node_name, icb->port_name, WWN_SIZE);
  8092. icb->node_name[0] &= 0xF0;
  8093. }
  8094. if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
  8095. if ((nv->enhanced_features & BIT_7) == 0)
  8096. ha->flags.scm_supported_a = 1;
  8097. }
  8098. /* Set host adapter parameters. */
  8099. ha->flags.disable_risc_code_load = 0;
  8100. ha->flags.enable_lip_reset = 0;
  8101. ha->flags.enable_lip_full_login =
  8102. le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
  8103. ha->flags.enable_target_reset =
  8104. le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
  8105. ha->flags.enable_led_scheme = 0;
  8106. ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
  8107. ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
  8108. (BIT_6 | BIT_5 | BIT_4)) >> 4;
  8109. /* save HBA serial number */
  8110. ha->serial0 = icb->port_name[5];
  8111. ha->serial1 = icb->port_name[6];
  8112. ha->serial2 = icb->port_name[7];
  8113. memcpy(vha->node_name, icb->node_name, WWN_SIZE);
  8114. memcpy(vha->port_name, icb->port_name, WWN_SIZE);
  8115. icb->execution_throttle = cpu_to_le16(0xFFFF);
  8116. ha->retry_count = le16_to_cpu(nv->login_retry_count);
  8117. /* Set minimum login_timeout to 4 seconds. */
  8118. if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
  8119. nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
  8120. if (le16_to_cpu(nv->login_timeout) < 4)
  8121. nv->login_timeout = cpu_to_le16(4);
  8122. ha->login_timeout = le16_to_cpu(nv->login_timeout);
  8123. /* Set minimum RATOV to 100 tenths of a second. */
  8124. ha->r_a_tov = 100;
  8125. ha->loop_reset_delay = nv->reset_delay;
  8126. /* Link Down Timeout = 0:
  8127. *
  8128. * When Port Down timer expires we will start returning
  8129. * I/O's to OS with "DID_NO_CONNECT".
  8130. *
  8131. * Link Down Timeout != 0:
  8132. *
  8133. * The driver waits for the link to come up after link down
  8134. * before returning I/Os to OS with "DID_NO_CONNECT".
  8135. */
  8136. if (le16_to_cpu(nv->link_down_timeout) == 0) {
  8137. ha->loop_down_abort_time =
  8138. (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
  8139. } else {
  8140. ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
  8141. ha->loop_down_abort_time =
  8142. (LOOP_DOWN_TIME - ha->link_down_timeout);
  8143. }
  8144. /* Need enough time to try and get the port back. */
  8145. ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
  8146. if (qlport_down_retry)
  8147. ha->port_down_retry_count = qlport_down_retry;
  8148. /* Set login_retry_count */
  8149. ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
  8150. if (ha->port_down_retry_count ==
  8151. le16_to_cpu(nv->port_down_retry_count) &&
  8152. ha->port_down_retry_count > 3)
  8153. ha->login_retry_count = ha->port_down_retry_count;
  8154. else if (ha->port_down_retry_count > (int)ha->login_retry_count)
  8155. ha->login_retry_count = ha->port_down_retry_count;
  8156. if (ql2xloginretrycount)
  8157. ha->login_retry_count = ql2xloginretrycount;
  8158. /* if not running MSI-X we need handshaking on interrupts */
  8159. if (!vha->hw->flags.msix_enabled &&
  8160. (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
  8161. icb->firmware_options_2 |= cpu_to_le32(BIT_22);
  8162. /* Enable ZIO. */
  8163. if (!vha->flags.init_done) {
  8164. ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
  8165. (BIT_3 | BIT_2 | BIT_1 | BIT_0);
  8166. ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
  8167. le16_to_cpu(icb->interrupt_delay_timer) : 2;
  8168. }
  8169. icb->firmware_options_2 &= cpu_to_le32(
  8170. ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
  8171. vha->flags.process_response_queue = 0;
  8172. if (ha->zio_mode != QLA_ZIO_DISABLED) {
  8173. ha->zio_mode = QLA_ZIO_MODE_6;
  8174. ql_log(ql_log_info, vha, 0x0075,
  8175. "ZIO mode %d enabled; timer delay (%d us).\n",
  8176. ha->zio_mode,
  8177. ha->zio_timer * 100);
  8178. icb->firmware_options_2 |= cpu_to_le32(
  8179. (uint32_t)ha->zio_mode);
  8180. icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
  8181. vha->flags.process_response_queue = 1;
  8182. }
  8183. /* enable RIDA Format2 */
  8184. icb->firmware_options_3 |= cpu_to_le32(BIT_0);
  8185. /* N2N: driver will initiate Login instead of FW */
  8186. icb->firmware_options_3 |= cpu_to_le32(BIT_8);
  8187. /* Determine NVMe/FCP priority for target ports */
  8188. ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
  8189. if (rval) {
  8190. ql_log(ql_log_warn, vha, 0x0076,
  8191. "NVRAM configuration failed.\n");
  8192. }
  8193. return (rval);
  8194. }
  8195. int
  8196. qla82xx_restart_isp(scsi_qla_host_t *vha)
  8197. {
  8198. int status, rval;
  8199. struct qla_hw_data *ha = vha->hw;
  8200. struct scsi_qla_host *vp, *tvp;
  8201. unsigned long flags;
  8202. status = qla2x00_init_rings(vha);
  8203. if (!status) {
  8204. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  8205. ha->flags.chip_reset_done = 1;
  8206. status = qla2x00_fw_ready(vha);
  8207. if (!status) {
  8208. /* Issue a marker after FW becomes ready. */
  8209. qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
  8210. vha->flags.online = 1;
  8211. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  8212. }
  8213. /* if no cable then assume it's good */
  8214. if ((vha->device_flags & DFLG_NO_CABLE))
  8215. status = 0;
  8216. }
  8217. if (!status) {
  8218. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  8219. if (!atomic_read(&vha->loop_down_timer)) {
  8220. /*
  8221. * Issue marker command only when we are going
  8222. * to start the I/O .
  8223. */
  8224. vha->marker_needed = 1;
  8225. }
  8226. ha->isp_ops->enable_intrs(ha);
  8227. ha->isp_abort_cnt = 0;
  8228. clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
  8229. /* Update the firmware version */
  8230. status = qla82xx_check_md_needed(vha);
  8231. if (ha->fce) {
  8232. ha->flags.fce_enabled = 1;
  8233. memset(ha->fce, 0,
  8234. fce_calc_size(ha->fce_bufs));
  8235. rval = qla2x00_enable_fce_trace(vha,
  8236. ha->fce_dma, ha->fce_bufs, ha->fce_mb,
  8237. &ha->fce_bufs);
  8238. if (rval) {
  8239. ql_log(ql_log_warn, vha, 0x8001,
  8240. "Unable to reinitialize FCE (%d).\n",
  8241. rval);
  8242. ha->flags.fce_enabled = 0;
  8243. }
  8244. }
  8245. if (ha->eft) {
  8246. memset(ha->eft, 0, EFT_SIZE);
  8247. rval = qla2x00_enable_eft_trace(vha,
  8248. ha->eft_dma, EFT_NUM_BUFFERS);
  8249. if (rval) {
  8250. ql_log(ql_log_warn, vha, 0x8010,
  8251. "Unable to reinitialize EFT (%d).\n",
  8252. rval);
  8253. }
  8254. }
  8255. }
  8256. if (!status) {
  8257. ql_dbg(ql_dbg_taskm, vha, 0x8011,
  8258. "qla82xx_restart_isp succeeded.\n");
  8259. spin_lock_irqsave(&ha->vport_slock, flags);
  8260. list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
  8261. if (vp->vp_idx) {
  8262. atomic_inc(&vp->vref_count);
  8263. spin_unlock_irqrestore(&ha->vport_slock, flags);
  8264. qla2x00_vp_abort_isp(vp);
  8265. spin_lock_irqsave(&ha->vport_slock, flags);
  8266. atomic_dec(&vp->vref_count);
  8267. }
  8268. }
  8269. spin_unlock_irqrestore(&ha->vport_slock, flags);
  8270. } else {
  8271. ql_log(ql_log_warn, vha, 0x8016,
  8272. "qla82xx_restart_isp **** FAILED ****.\n");
  8273. }
  8274. return status;
  8275. }
  8276. /*
  8277. * qla24xx_get_fcp_prio
  8278. * Gets the fcp cmd priority value for the logged in port.
  8279. * Looks for a match of the port descriptors within
  8280. * each of the fcp prio config entries. If a match is found,
  8281. * the tag (priority) value is returned.
  8282. *
  8283. * Input:
  8284. * vha = scsi host structure pointer.
  8285. * fcport = port structure pointer.
  8286. *
  8287. * Return:
  8288. * non-zero (if found)
  8289. * -1 (if not found)
  8290. *
  8291. * Context:
  8292. * Kernel context
  8293. */
  8294. static int
  8295. qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  8296. {
  8297. int i, entries;
  8298. uint8_t pid_match, wwn_match;
  8299. int priority;
  8300. uint32_t pid1, pid2;
  8301. uint64_t wwn1, wwn2;
  8302. struct qla_fcp_prio_entry *pri_entry;
  8303. struct qla_hw_data *ha = vha->hw;
  8304. if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
  8305. return -1;
  8306. priority = -1;
  8307. entries = ha->fcp_prio_cfg->num_entries;
  8308. pri_entry = &ha->fcp_prio_cfg->entry[0];
  8309. for (i = 0; i < entries; i++) {
  8310. pid_match = wwn_match = 0;
  8311. if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
  8312. pri_entry++;
  8313. continue;
  8314. }
  8315. /* check source pid for a match */
  8316. if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
  8317. pid1 = pri_entry->src_pid & INVALID_PORT_ID;
  8318. pid2 = vha->d_id.b24 & INVALID_PORT_ID;
  8319. if (pid1 == INVALID_PORT_ID)
  8320. pid_match++;
  8321. else if (pid1 == pid2)
  8322. pid_match++;
  8323. }
  8324. /* check destination pid for a match */
  8325. if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
  8326. pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
  8327. pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
  8328. if (pid1 == INVALID_PORT_ID)
  8329. pid_match++;
  8330. else if (pid1 == pid2)
  8331. pid_match++;
  8332. }
  8333. /* check source WWN for a match */
  8334. if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
  8335. wwn1 = wwn_to_u64(vha->port_name);
  8336. wwn2 = wwn_to_u64(pri_entry->src_wwpn);
  8337. if (wwn2 == (uint64_t)-1)
  8338. wwn_match++;
  8339. else if (wwn1 == wwn2)
  8340. wwn_match++;
  8341. }
  8342. /* check destination WWN for a match */
  8343. if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
  8344. wwn1 = wwn_to_u64(fcport->port_name);
  8345. wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
  8346. if (wwn2 == (uint64_t)-1)
  8347. wwn_match++;
  8348. else if (wwn1 == wwn2)
  8349. wwn_match++;
  8350. }
  8351. if (pid_match == 2 || wwn_match == 2) {
  8352. /* Found a matching entry */
  8353. if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
  8354. priority = pri_entry->tag;
  8355. break;
  8356. }
  8357. pri_entry++;
  8358. }
  8359. return priority;
  8360. }
  8361. /*
  8362. * qla24xx_update_fcport_fcp_prio
  8363. * Activates fcp priority for the logged in fc port
  8364. *
  8365. * Input:
  8366. * vha = scsi host structure pointer.
  8367. * fcp = port structure pointer.
  8368. *
  8369. * Return:
  8370. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  8371. *
  8372. * Context:
  8373. * Kernel context.
  8374. */
  8375. int
  8376. qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
  8377. {
  8378. int ret;
  8379. int priority;
  8380. uint16_t mb[5];
  8381. if (fcport->port_type != FCT_TARGET ||
  8382. fcport->loop_id == FC_NO_LOOP_ID)
  8383. return QLA_FUNCTION_FAILED;
  8384. priority = qla24xx_get_fcp_prio(vha, fcport);
  8385. if (priority < 0)
  8386. return QLA_FUNCTION_FAILED;
  8387. if (IS_P3P_TYPE(vha->hw)) {
  8388. fcport->fcp_prio = priority & 0xf;
  8389. return QLA_SUCCESS;
  8390. }
  8391. ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
  8392. if (ret == QLA_SUCCESS) {
  8393. if (fcport->fcp_prio != priority)
  8394. ql_dbg(ql_dbg_user, vha, 0x709e,
  8395. "Updated FCP_CMND priority - value=%d loop_id=%d "
  8396. "port_id=%02x%02x%02x.\n", priority,
  8397. fcport->loop_id, fcport->d_id.b.domain,
  8398. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  8399. fcport->fcp_prio = priority & 0xf;
  8400. } else
  8401. ql_dbg(ql_dbg_user, vha, 0x704f,
  8402. "Unable to update FCP_CMND priority - ret=0x%x for "
  8403. "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
  8404. fcport->d_id.b.domain, fcport->d_id.b.area,
  8405. fcport->d_id.b.al_pa);
  8406. return ret;
  8407. }
  8408. /*
  8409. * qla24xx_update_all_fcp_prio
  8410. * Activates fcp priority for all the logged in ports
  8411. *
  8412. * Input:
  8413. * ha = adapter block pointer.
  8414. *
  8415. * Return:
  8416. * QLA_SUCCESS or QLA_FUNCTION_FAILED
  8417. *
  8418. * Context:
  8419. * Kernel context.
  8420. */
  8421. int
  8422. qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
  8423. {
  8424. int ret;
  8425. fc_port_t *fcport;
  8426. ret = QLA_FUNCTION_FAILED;
  8427. /* We need to set priority for all logged in ports */
  8428. list_for_each_entry(fcport, &vha->vp_fcports, list)
  8429. ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
  8430. return ret;
  8431. }
  8432. struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
  8433. int vp_idx, bool startqp)
  8434. {
  8435. int rsp_id = 0;
  8436. int req_id = 0;
  8437. int i;
  8438. struct qla_hw_data *ha = vha->hw;
  8439. uint16_t qpair_id = 0;
  8440. struct qla_qpair *qpair = NULL;
  8441. struct qla_msix_entry *msix;
  8442. if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
  8443. ql_log(ql_log_warn, vha, 0x00181,
  8444. "FW/Driver is not multi-queue capable.\n");
  8445. return NULL;
  8446. }
  8447. if (ql2xmqsupport || ql2xnvmeenable) {
  8448. qpair = kzalloc_obj(struct qla_qpair);
  8449. if (qpair == NULL) {
  8450. ql_log(ql_log_warn, vha, 0x0182,
  8451. "Failed to allocate memory for queue pair.\n");
  8452. return NULL;
  8453. }
  8454. qpair->hw = vha->hw;
  8455. qpair->vha = vha;
  8456. qpair->qp_lock_ptr = &qpair->qp_lock;
  8457. spin_lock_init(&qpair->qp_lock);
  8458. qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
  8459. /* Assign available que pair id */
  8460. mutex_lock(&ha->mq_lock);
  8461. qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
  8462. if (ha->num_qpairs >= ha->max_qpairs) {
  8463. mutex_unlock(&ha->mq_lock);
  8464. ql_log(ql_log_warn, vha, 0x0183,
  8465. "No resources to create additional q pair.\n");
  8466. goto fail_qid_map;
  8467. }
  8468. ha->num_qpairs++;
  8469. set_bit(qpair_id, ha->qpair_qid_map);
  8470. ha->queue_pair_map[qpair_id] = qpair;
  8471. qpair->id = qpair_id;
  8472. qpair->vp_idx = vp_idx;
  8473. qpair->fw_started = ha->flags.fw_started;
  8474. INIT_LIST_HEAD(&qpair->hints_list);
  8475. INIT_LIST_HEAD(&qpair->dsd_list);
  8476. qpair->chip_reset = ha->base_qpair->chip_reset;
  8477. qpair->enable_class_2 = ha->base_qpair->enable_class_2;
  8478. qpair->enable_explicit_conf =
  8479. ha->base_qpair->enable_explicit_conf;
  8480. for (i = 0; i < ha->msix_count; i++) {
  8481. msix = &ha->msix_entries[i];
  8482. if (msix->in_use)
  8483. continue;
  8484. qpair->msix = msix;
  8485. ql_dbg(ql_dbg_multiq, vha, 0xc00f,
  8486. "Vector %x selected for qpair\n", msix->vector);
  8487. break;
  8488. }
  8489. if (!qpair->msix) {
  8490. ql_log(ql_log_warn, vha, 0x0184,
  8491. "Out of MSI-X vectors!.\n");
  8492. goto fail_msix;
  8493. }
  8494. qpair->msix->in_use = 1;
  8495. list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
  8496. qpair->pdev = ha->pdev;
  8497. if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
  8498. qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
  8499. mutex_unlock(&ha->mq_lock);
  8500. /* Create response queue first */
  8501. rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
  8502. if (!rsp_id) {
  8503. ql_log(ql_log_warn, vha, 0x0185,
  8504. "Failed to create response queue.\n");
  8505. goto fail_rsp;
  8506. }
  8507. qpair->rsp = ha->rsp_q_map[rsp_id];
  8508. /* Create request queue */
  8509. req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
  8510. startqp);
  8511. if (!req_id) {
  8512. ql_log(ql_log_warn, vha, 0x0186,
  8513. "Failed to create request queue.\n");
  8514. goto fail_req;
  8515. }
  8516. qpair->req = ha->req_q_map[req_id];
  8517. qpair->rsp->req = qpair->req;
  8518. qpair->rsp->qpair = qpair;
  8519. if (!qpair->cpu_mapped)
  8520. qla_cpu_update(qpair, raw_smp_processor_id());
  8521. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  8522. if (ha->fw_attributes & BIT_4)
  8523. qpair->difdix_supported = 1;
  8524. }
  8525. qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  8526. if (!qpair->srb_mempool) {
  8527. ql_log(ql_log_warn, vha, 0xd036,
  8528. "Failed to create srb mempool for qpair %d\n",
  8529. qpair->id);
  8530. goto fail_mempool;
  8531. }
  8532. if (qla_create_buf_pool(vha, qpair)) {
  8533. ql_log(ql_log_warn, vha, 0xd036,
  8534. "Failed to initialize buf pool for qpair %d\n",
  8535. qpair->id);
  8536. goto fail_bufpool;
  8537. }
  8538. /* Mark as online */
  8539. qpair->online = 1;
  8540. if (!vha->flags.qpairs_available)
  8541. vha->flags.qpairs_available = 1;
  8542. ql_dbg(ql_dbg_multiq, vha, 0xc00d,
  8543. "Request/Response queue pair created, id %d\n",
  8544. qpair->id);
  8545. ql_dbg(ql_dbg_init, vha, 0x0187,
  8546. "Request/Response queue pair created, id %d\n",
  8547. qpair->id);
  8548. }
  8549. return qpair;
  8550. fail_bufpool:
  8551. mempool_destroy(qpair->srb_mempool);
  8552. fail_mempool:
  8553. qla25xx_delete_req_que(vha, qpair->req);
  8554. fail_req:
  8555. qla25xx_delete_rsp_que(vha, qpair->rsp);
  8556. fail_rsp:
  8557. mutex_lock(&ha->mq_lock);
  8558. qpair->msix->in_use = 0;
  8559. list_del(&qpair->qp_list_elem);
  8560. if (list_empty(&vha->qp_list))
  8561. vha->flags.qpairs_available = 0;
  8562. fail_msix:
  8563. ha->queue_pair_map[qpair_id] = NULL;
  8564. clear_bit(qpair_id, ha->qpair_qid_map);
  8565. ha->num_qpairs--;
  8566. mutex_unlock(&ha->mq_lock);
  8567. fail_qid_map:
  8568. kfree(qpair);
  8569. return NULL;
  8570. }
  8571. int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
  8572. {
  8573. int ret = QLA_FUNCTION_FAILED;
  8574. struct qla_hw_data *ha = qpair->hw;
  8575. qpair->delete_in_progress = 1;
  8576. qla_free_buf_pool(qpair);
  8577. ret = qla25xx_delete_req_que(vha, qpair->req);
  8578. if (ret != QLA_SUCCESS)
  8579. goto fail;
  8580. ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
  8581. if (ret != QLA_SUCCESS)
  8582. goto fail;
  8583. if (!list_empty(&qpair->dsd_list)) {
  8584. struct dsd_dma *dsd_ptr, *tdsd_ptr;
  8585. /* clean up allocated prev pool */
  8586. list_for_each_entry_safe(dsd_ptr, tdsd_ptr,
  8587. &qpair->dsd_list, list) {
  8588. dma_pool_free(ha->dl_dma_pool, dsd_ptr->dsd_addr,
  8589. dsd_ptr->dsd_list_dma);
  8590. list_del(&dsd_ptr->list);
  8591. kfree(dsd_ptr);
  8592. }
  8593. }
  8594. mutex_lock(&ha->mq_lock);
  8595. ha->queue_pair_map[qpair->id] = NULL;
  8596. clear_bit(qpair->id, ha->qpair_qid_map);
  8597. ha->num_qpairs--;
  8598. list_del(&qpair->qp_list_elem);
  8599. if (list_empty(&vha->qp_list)) {
  8600. vha->flags.qpairs_available = 0;
  8601. vha->flags.qpairs_req_created = 0;
  8602. vha->flags.qpairs_rsp_created = 0;
  8603. }
  8604. mempool_destroy(qpair->srb_mempool);
  8605. kfree(qpair);
  8606. mutex_unlock(&ha->mq_lock);
  8607. return QLA_SUCCESS;
  8608. fail:
  8609. return ret;
  8610. }
  8611. uint64_t
  8612. qla2x00_count_set_bits(uint32_t num)
  8613. {
  8614. /* Brian Kernighan's Algorithm */
  8615. u64 count = 0;
  8616. while (num) {
  8617. num &= (num - 1);
  8618. count++;
  8619. }
  8620. return count;
  8621. }
  8622. uint64_t
  8623. qla2x00_get_num_tgts(scsi_qla_host_t *vha)
  8624. {
  8625. fc_port_t *f, *tf;
  8626. u64 count = 0;
  8627. f = NULL;
  8628. tf = NULL;
  8629. list_for_each_entry_safe(f, tf, &vha->vp_fcports, list) {
  8630. if (f->port_type != FCT_TARGET)
  8631. continue;
  8632. count++;
  8633. }
  8634. return count;
  8635. }
  8636. int qla2xxx_reset_stats(struct Scsi_Host *host, u32 flags)
  8637. {
  8638. scsi_qla_host_t *vha = shost_priv(host);
  8639. fc_port_t *fcport = NULL;
  8640. unsigned long int_flags;
  8641. if (flags & QLA2XX_HW_ERROR)
  8642. vha->hw_err_cnt = 0;
  8643. if (flags & QLA2XX_SHT_LNK_DWN)
  8644. vha->short_link_down_cnt = 0;
  8645. if (flags & QLA2XX_INT_ERR)
  8646. vha->interface_err_cnt = 0;
  8647. if (flags & QLA2XX_CMD_TIMEOUT)
  8648. vha->cmd_timeout_cnt = 0;
  8649. if (flags & QLA2XX_RESET_CMD_ERR)
  8650. vha->reset_cmd_err_cnt = 0;
  8651. if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
  8652. spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
  8653. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  8654. fcport->tgt_short_link_down_cnt = 0;
  8655. fcport->tgt_link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
  8656. }
  8657. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
  8658. }
  8659. vha->link_down_time = QLA2XX_MAX_LINK_DOWN_TIME;
  8660. return 0;
  8661. }
  8662. int qla2xxx_start_stats(struct Scsi_Host *host, u32 flags)
  8663. {
  8664. return qla2xxx_reset_stats(host, flags);
  8665. }
  8666. int qla2xxx_stop_stats(struct Scsi_Host *host, u32 flags)
  8667. {
  8668. return qla2xxx_reset_stats(host, flags);
  8669. }
  8670. int qla2xxx_get_ini_stats(struct Scsi_Host *host, u32 flags,
  8671. void *data, u64 size)
  8672. {
  8673. scsi_qla_host_t *vha = shost_priv(host);
  8674. struct ql_vnd_host_stats_resp *resp = (struct ql_vnd_host_stats_resp *)data;
  8675. struct ql_vnd_stats *rsp_data = &resp->stats;
  8676. u64 ini_entry_count = 0;
  8677. u64 i = 0;
  8678. u64 entry_count = 0;
  8679. u64 num_tgt = 0;
  8680. u32 tmp_stat_type = 0;
  8681. fc_port_t *fcport = NULL;
  8682. unsigned long int_flags;
  8683. /* Copy stat type to work on it */
  8684. tmp_stat_type = flags;
  8685. if (tmp_stat_type & BIT_17) {
  8686. num_tgt = qla2x00_get_num_tgts(vha);
  8687. /* unset BIT_17 */
  8688. tmp_stat_type &= ~(1 << 17);
  8689. }
  8690. ini_entry_count = qla2x00_count_set_bits(tmp_stat_type);
  8691. entry_count = ini_entry_count + num_tgt;
  8692. rsp_data->entry_count = entry_count;
  8693. i = 0;
  8694. if (flags & QLA2XX_HW_ERROR) {
  8695. rsp_data->entry[i].stat_type = QLA2XX_HW_ERROR;
  8696. rsp_data->entry[i].tgt_num = 0x0;
  8697. rsp_data->entry[i].cnt = vha->hw_err_cnt;
  8698. i++;
  8699. }
  8700. if (flags & QLA2XX_SHT_LNK_DWN) {
  8701. rsp_data->entry[i].stat_type = QLA2XX_SHT_LNK_DWN;
  8702. rsp_data->entry[i].tgt_num = 0x0;
  8703. rsp_data->entry[i].cnt = vha->short_link_down_cnt;
  8704. i++;
  8705. }
  8706. if (flags & QLA2XX_INT_ERR) {
  8707. rsp_data->entry[i].stat_type = QLA2XX_INT_ERR;
  8708. rsp_data->entry[i].tgt_num = 0x0;
  8709. rsp_data->entry[i].cnt = vha->interface_err_cnt;
  8710. i++;
  8711. }
  8712. if (flags & QLA2XX_CMD_TIMEOUT) {
  8713. rsp_data->entry[i].stat_type = QLA2XX_CMD_TIMEOUT;
  8714. rsp_data->entry[i].tgt_num = 0x0;
  8715. rsp_data->entry[i].cnt = vha->cmd_timeout_cnt;
  8716. i++;
  8717. }
  8718. if (flags & QLA2XX_RESET_CMD_ERR) {
  8719. rsp_data->entry[i].stat_type = QLA2XX_RESET_CMD_ERR;
  8720. rsp_data->entry[i].tgt_num = 0x0;
  8721. rsp_data->entry[i].cnt = vha->reset_cmd_err_cnt;
  8722. i++;
  8723. }
  8724. /* i will continue from previous loop, as target
  8725. * entries are after initiator
  8726. */
  8727. if (flags & QLA2XX_TGT_SHT_LNK_DOWN) {
  8728. spin_lock_irqsave(&vha->hw->tgt.sess_lock, int_flags);
  8729. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  8730. if (fcport->port_type != FCT_TARGET)
  8731. continue;
  8732. if (!fcport->rport)
  8733. continue;
  8734. rsp_data->entry[i].stat_type = QLA2XX_TGT_SHT_LNK_DOWN;
  8735. rsp_data->entry[i].tgt_num = fcport->rport->number;
  8736. rsp_data->entry[i].cnt = fcport->tgt_short_link_down_cnt;
  8737. i++;
  8738. }
  8739. spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, int_flags);
  8740. }
  8741. resp->status = EXT_STATUS_OK;
  8742. return 0;
  8743. }
  8744. int qla2xxx_get_tgt_stats(struct Scsi_Host *host, u32 flags,
  8745. struct fc_rport *rport, void *data, u64 size)
  8746. {
  8747. struct ql_vnd_tgt_stats_resp *tgt_data = data;
  8748. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  8749. tgt_data->status = 0;
  8750. tgt_data->stats.entry_count = 1;
  8751. tgt_data->stats.entry[0].stat_type = flags;
  8752. tgt_data->stats.entry[0].tgt_num = rport->number;
  8753. tgt_data->stats.entry[0].cnt = fcport->tgt_short_link_down_cnt;
  8754. return 0;
  8755. }
  8756. int qla2xxx_disable_port(struct Scsi_Host *host)
  8757. {
  8758. scsi_qla_host_t *vha = shost_priv(host);
  8759. vha->hw->flags.port_isolated = 1;
  8760. if (qla2x00_isp_reg_stat(vha->hw)) {
  8761. ql_log(ql_log_info, vha, 0x9006,
  8762. "PCI/Register disconnect, exiting.\n");
  8763. qla_pci_set_eeh_busy(vha);
  8764. return FAILED;
  8765. }
  8766. if (qla2x00_chip_is_down(vha))
  8767. return 0;
  8768. if (vha->flags.online) {
  8769. qla2x00_abort_isp_cleanup(vha);
  8770. qla2x00_wait_for_sess_deletion(vha);
  8771. }
  8772. return 0;
  8773. }
  8774. int qla2xxx_enable_port(struct Scsi_Host *host)
  8775. {
  8776. scsi_qla_host_t *vha = shost_priv(host);
  8777. if (qla2x00_isp_reg_stat(vha->hw)) {
  8778. ql_log(ql_log_info, vha, 0x9001,
  8779. "PCI/Register disconnect, exiting.\n");
  8780. qla_pci_set_eeh_busy(vha);
  8781. return FAILED;
  8782. }
  8783. vha->hw->flags.port_isolated = 0;
  8784. /* Set the flag to 1, so that isp_abort can proceed */
  8785. vha->flags.online = 1;
  8786. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  8787. qla2xxx_wake_dpc(vha);
  8788. return 0;
  8789. }