lpfc_sli.c 680 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
  5. * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
  6. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  7. * EMULEX and SLI are trademarks of Emulex. *
  8. * www.broadcom.com *
  9. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  10. * *
  11. * This program is free software; you can redistribute it and/or *
  12. * modify it under the terms of version 2 of the GNU General *
  13. * Public License as published by the Free Software Foundation. *
  14. * This program is distributed in the hope that it will be useful. *
  15. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  16. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  17. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  18. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  19. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  20. * more details, a copy of which can be found in the file COPYING *
  21. * included with this package. *
  22. *******************************************************************/
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/lockdep.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_cmnd.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include <scsi/fc/fc_fs.h>
  35. #include <linux/aer.h>
  36. #include <linux/crash_dump.h>
  37. #ifdef CONFIG_X86
  38. #include <asm/set_memory.h>
  39. #endif
  40. #include "lpfc_hw4.h"
  41. #include "lpfc_hw.h"
  42. #include "lpfc_sli.h"
  43. #include "lpfc_sli4.h"
  44. #include "lpfc_nl.h"
  45. #include "lpfc_disc.h"
  46. #include "lpfc.h"
  47. #include "lpfc_scsi.h"
  48. #include "lpfc_nvme.h"
  49. #include "lpfc_crtn.h"
  50. #include "lpfc_logmsg.h"
  51. #include "lpfc_compat.h"
  52. #include "lpfc_debugfs.h"
  53. #include "lpfc_vport.h"
  54. #include "lpfc_version.h"
  55. /* There are only four IOCB completion types. */
  56. typedef enum _lpfc_iocb_type {
  57. LPFC_UNKNOWN_IOCB,
  58. LPFC_UNSOL_IOCB,
  59. LPFC_SOL_IOCB,
  60. LPFC_ABORT_IOCB
  61. } lpfc_iocb_type;
  62. /* Provide function prototypes local to this module. */
  63. static int lpfc_sli_issue_mbox_s4(struct lpfc_hba *, LPFC_MBOXQ_t *,
  64. uint32_t);
  65. static int lpfc_sli4_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *,
  66. uint8_t *, uint32_t *);
  67. static struct lpfc_iocbq *
  68. lpfc_sli4_els_preprocess_rspiocbq(struct lpfc_hba *phba,
  69. struct lpfc_iocbq *rspiocbq);
  70. static void lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *,
  71. struct hbq_dmabuf *);
  72. static void lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
  73. struct hbq_dmabuf *dmabuf);
  74. static bool lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba,
  75. struct lpfc_queue *cq, struct lpfc_cqe *cqe);
  76. static int lpfc_sli4_post_sgl_list(struct lpfc_hba *, struct list_head *,
  77. int);
  78. static void lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba,
  79. struct lpfc_queue *eq,
  80. struct lpfc_eqe *eqe);
  81. static bool lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba);
  82. static bool lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba);
  83. static struct lpfc_cqe *lpfc_sli4_cq_get(struct lpfc_queue *q);
  84. static void __lpfc_sli4_consume_cqe(struct lpfc_hba *phba,
  85. struct lpfc_queue *cq,
  86. struct lpfc_cqe *cqe);
  87. static uint16_t lpfc_wqe_bpl2sgl(struct lpfc_hba *phba,
  88. struct lpfc_iocbq *pwqeq,
  89. struct lpfc_sglq *sglq);
  90. union lpfc_wqe128 lpfc_iread_cmd_template;
  91. union lpfc_wqe128 lpfc_iwrite_cmd_template;
  92. union lpfc_wqe128 lpfc_icmnd_cmd_template;
  93. /* Setup WQE templates for IOs */
  94. void lpfc_wqe_cmd_template(void)
  95. {
  96. union lpfc_wqe128 *wqe;
  97. /* IREAD template */
  98. wqe = &lpfc_iread_cmd_template;
  99. memset(wqe, 0, sizeof(union lpfc_wqe128));
  100. /* Word 0, 1, 2 - BDE is variable */
  101. /* Word 3 - cmd_buff_len, payload_offset_len is zero */
  102. /* Word 4 - total_xfer_len is variable */
  103. /* Word 5 - is zero */
  104. /* Word 6 - ctxt_tag, xri_tag is variable */
  105. /* Word 7 */
  106. bf_set(wqe_cmnd, &wqe->fcp_iread.wqe_com, CMD_FCP_IREAD64_WQE);
  107. bf_set(wqe_pu, &wqe->fcp_iread.wqe_com, PARM_READ_CHECK);
  108. bf_set(wqe_class, &wqe->fcp_iread.wqe_com, CLASS3);
  109. bf_set(wqe_ct, &wqe->fcp_iread.wqe_com, SLI4_CT_RPI);
  110. /* Word 8 - abort_tag is variable */
  111. /* Word 9 - reqtag is variable */
  112. /* Word 10 - dbde, wqes is variable */
  113. bf_set(wqe_qosd, &wqe->fcp_iread.wqe_com, 0);
  114. bf_set(wqe_iod, &wqe->fcp_iread.wqe_com, LPFC_WQE_IOD_READ);
  115. bf_set(wqe_lenloc, &wqe->fcp_iread.wqe_com, LPFC_WQE_LENLOC_WORD4);
  116. bf_set(wqe_dbde, &wqe->fcp_iread.wqe_com, 0);
  117. bf_set(wqe_wqes, &wqe->fcp_iread.wqe_com, 1);
  118. /* Word 11 - pbde is variable */
  119. bf_set(wqe_cmd_type, &wqe->fcp_iread.wqe_com, COMMAND_DATA_IN);
  120. bf_set(wqe_cqid, &wqe->fcp_iread.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  121. bf_set(wqe_pbde, &wqe->fcp_iread.wqe_com, 0);
  122. /* Word 12 - is zero */
  123. /* Word 13, 14, 15 - PBDE is variable */
  124. /* IWRITE template */
  125. wqe = &lpfc_iwrite_cmd_template;
  126. memset(wqe, 0, sizeof(union lpfc_wqe128));
  127. /* Word 0, 1, 2 - BDE is variable */
  128. /* Word 3 - cmd_buff_len, payload_offset_len is zero */
  129. /* Word 4 - total_xfer_len is variable */
  130. /* Word 5 - initial_xfer_len is variable */
  131. /* Word 6 - ctxt_tag, xri_tag is variable */
  132. /* Word 7 */
  133. bf_set(wqe_cmnd, &wqe->fcp_iwrite.wqe_com, CMD_FCP_IWRITE64_WQE);
  134. bf_set(wqe_pu, &wqe->fcp_iwrite.wqe_com, PARM_READ_CHECK);
  135. bf_set(wqe_class, &wqe->fcp_iwrite.wqe_com, CLASS3);
  136. bf_set(wqe_ct, &wqe->fcp_iwrite.wqe_com, SLI4_CT_RPI);
  137. /* Word 8 - abort_tag is variable */
  138. /* Word 9 - reqtag is variable */
  139. /* Word 10 - dbde, wqes is variable */
  140. bf_set(wqe_qosd, &wqe->fcp_iwrite.wqe_com, 0);
  141. bf_set(wqe_iod, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_IOD_WRITE);
  142. bf_set(wqe_lenloc, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_LENLOC_WORD4);
  143. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
  144. bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
  145. /* Word 11 - pbde is variable */
  146. bf_set(wqe_cmd_type, &wqe->fcp_iwrite.wqe_com, COMMAND_DATA_OUT);
  147. bf_set(wqe_cqid, &wqe->fcp_iwrite.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  148. bf_set(wqe_pbde, &wqe->fcp_iwrite.wqe_com, 0);
  149. /* Word 12 - is zero */
  150. /* Word 13, 14, 15 - PBDE is variable */
  151. /* ICMND template */
  152. wqe = &lpfc_icmnd_cmd_template;
  153. memset(wqe, 0, sizeof(union lpfc_wqe128));
  154. /* Word 0, 1, 2 - BDE is variable */
  155. /* Word 3 - payload_offset_len is variable */
  156. /* Word 4, 5 - is zero */
  157. /* Word 6 - ctxt_tag, xri_tag is variable */
  158. /* Word 7 */
  159. bf_set(wqe_cmnd, &wqe->fcp_icmd.wqe_com, CMD_FCP_ICMND64_WQE);
  160. bf_set(wqe_pu, &wqe->fcp_icmd.wqe_com, 0);
  161. bf_set(wqe_class, &wqe->fcp_icmd.wqe_com, CLASS3);
  162. bf_set(wqe_ct, &wqe->fcp_icmd.wqe_com, SLI4_CT_RPI);
  163. /* Word 8 - abort_tag is variable */
  164. /* Word 9 - reqtag is variable */
  165. /* Word 10 - dbde, wqes is variable */
  166. bf_set(wqe_qosd, &wqe->fcp_icmd.wqe_com, 1);
  167. bf_set(wqe_iod, &wqe->fcp_icmd.wqe_com, LPFC_WQE_IOD_NONE);
  168. bf_set(wqe_lenloc, &wqe->fcp_icmd.wqe_com, LPFC_WQE_LENLOC_NONE);
  169. bf_set(wqe_dbde, &wqe->fcp_icmd.wqe_com, 0);
  170. bf_set(wqe_wqes, &wqe->fcp_icmd.wqe_com, 1);
  171. /* Word 11 */
  172. bf_set(wqe_cmd_type, &wqe->fcp_icmd.wqe_com, COMMAND_DATA_IN);
  173. bf_set(wqe_cqid, &wqe->fcp_icmd.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  174. bf_set(wqe_pbde, &wqe->fcp_icmd.wqe_com, 0);
  175. /* Word 12, 13, 14, 15 - is zero */
  176. }
  177. #if defined(CONFIG_64BIT) && defined(__LITTLE_ENDIAN)
  178. /**
  179. * lpfc_sli4_pcimem_bcopy - SLI4 memory copy function
  180. * @srcp: Source memory pointer.
  181. * @destp: Destination memory pointer.
  182. * @cnt: Number of words required to be copied.
  183. * Must be a multiple of sizeof(uint64_t)
  184. *
  185. * This function is used for copying data between driver memory
  186. * and the SLI WQ. This function also changes the endianness
  187. * of each word if native endianness is different from SLI
  188. * endianness. This function can be called with or without
  189. * lock.
  190. **/
  191. static void
  192. lpfc_sli4_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  193. {
  194. uint64_t *src = srcp;
  195. uint64_t *dest = destp;
  196. int i;
  197. for (i = 0; i < (int)cnt; i += sizeof(uint64_t))
  198. *dest++ = *src++;
  199. }
  200. #else
  201. #define lpfc_sli4_pcimem_bcopy(a, b, c) lpfc_sli_pcimem_bcopy(a, b, c)
  202. #endif
  203. /**
  204. * lpfc_sli4_wq_put - Put a Work Queue Entry on an Work Queue
  205. * @q: The Work Queue to operate on.
  206. * @wqe: The work Queue Entry to put on the Work queue.
  207. *
  208. * This routine will copy the contents of @wqe to the next available entry on
  209. * the @q. This function will then ring the Work Queue Doorbell to signal the
  210. * HBA to start processing the Work Queue Entry. This function returns 0 if
  211. * successful. If no entries are available on @q then this function will return
  212. * -ENOMEM.
  213. * The caller is expected to hold the hbalock when calling this routine.
  214. **/
  215. static int
  216. lpfc_sli4_wq_put(struct lpfc_queue *q, union lpfc_wqe128 *wqe)
  217. {
  218. union lpfc_wqe *temp_wqe;
  219. struct lpfc_register doorbell;
  220. uint32_t host_index;
  221. uint32_t idx;
  222. uint32_t i = 0;
  223. uint8_t *tmp;
  224. u32 if_type;
  225. /* sanity check on queue memory */
  226. if (unlikely(!q))
  227. return -ENOMEM;
  228. temp_wqe = lpfc_sli4_qe(q, q->host_index);
  229. /* If the host has not yet processed the next entry then we are done */
  230. idx = ((q->host_index + 1) % q->entry_count);
  231. if (idx == q->hba_index) {
  232. q->WQ_overflow++;
  233. return -EBUSY;
  234. }
  235. q->WQ_posted++;
  236. /* set consumption flag every once in a while */
  237. if (!((q->host_index + 1) % q->notify_interval))
  238. bf_set(wqe_wqec, &wqe->generic.wqe_com, 1);
  239. else
  240. bf_set(wqe_wqec, &wqe->generic.wqe_com, 0);
  241. if (q->phba->sli3_options & LPFC_SLI4_PHWQ_ENABLED)
  242. bf_set(wqe_wqid, &wqe->generic.wqe_com, q->queue_id);
  243. lpfc_sli4_pcimem_bcopy(wqe, temp_wqe, q->entry_size);
  244. if (q->dpp_enable && q->phba->cfg_enable_dpp) {
  245. /* write to DPP aperture taking advatage of Combined Writes */
  246. tmp = (uint8_t *)temp_wqe;
  247. #ifdef __raw_writeq
  248. for (i = 0; i < q->entry_size; i += sizeof(uint64_t))
  249. __raw_writeq(*((uint64_t *)(tmp + i)),
  250. q->dpp_regaddr + i);
  251. #else
  252. for (i = 0; i < q->entry_size; i += sizeof(uint32_t))
  253. __raw_writel(*((uint32_t *)(tmp + i)),
  254. q->dpp_regaddr + i);
  255. #endif
  256. }
  257. /* ensure WQE bcopy and DPP flushed before doorbell write */
  258. wmb();
  259. /* Update the host index before invoking device */
  260. host_index = q->host_index;
  261. q->host_index = idx;
  262. /* Ring Doorbell */
  263. doorbell.word0 = 0;
  264. if (q->db_format == LPFC_DB_LIST_FORMAT) {
  265. if (q->dpp_enable && q->phba->cfg_enable_dpp) {
  266. bf_set(lpfc_if6_wq_db_list_fm_num_posted, &doorbell, 1);
  267. bf_set(lpfc_if6_wq_db_list_fm_dpp, &doorbell, 1);
  268. bf_set(lpfc_if6_wq_db_list_fm_dpp_id, &doorbell,
  269. q->dpp_id);
  270. bf_set(lpfc_if6_wq_db_list_fm_id, &doorbell,
  271. q->queue_id);
  272. } else {
  273. bf_set(lpfc_wq_db_list_fm_num_posted, &doorbell, 1);
  274. bf_set(lpfc_wq_db_list_fm_id, &doorbell, q->queue_id);
  275. /* Leave bits <23:16> clear for if_type 6 dpp */
  276. if_type = bf_get(lpfc_sli_intf_if_type,
  277. &q->phba->sli4_hba.sli_intf);
  278. if (if_type != LPFC_SLI_INTF_IF_TYPE_6)
  279. bf_set(lpfc_wq_db_list_fm_index, &doorbell,
  280. host_index);
  281. }
  282. } else if (q->db_format == LPFC_DB_RING_FORMAT) {
  283. bf_set(lpfc_wq_db_ring_fm_num_posted, &doorbell, 1);
  284. bf_set(lpfc_wq_db_ring_fm_id, &doorbell, q->queue_id);
  285. } else {
  286. return -EINVAL;
  287. }
  288. writel(doorbell.word0, q->db_regaddr);
  289. return 0;
  290. }
  291. /**
  292. * lpfc_sli4_wq_release - Updates internal hba index for WQ
  293. * @q: The Work Queue to operate on.
  294. * @index: The index to advance the hba index to.
  295. *
  296. * This routine will update the HBA index of a queue to reflect consumption of
  297. * Work Queue Entries by the HBA. When the HBA indicates that it has consumed
  298. * an entry the host calls this function to update the queue's internal
  299. * pointers.
  300. **/
  301. static void
  302. lpfc_sli4_wq_release(struct lpfc_queue *q, uint32_t index)
  303. {
  304. /* sanity check on queue memory */
  305. if (unlikely(!q))
  306. return;
  307. q->hba_index = index;
  308. }
  309. /**
  310. * lpfc_sli4_mq_put - Put a Mailbox Queue Entry on an Mailbox Queue
  311. * @q: The Mailbox Queue to operate on.
  312. * @mqe: The Mailbox Queue Entry to put on the Work queue.
  313. *
  314. * This routine will copy the contents of @mqe to the next available entry on
  315. * the @q. This function will then ring the Work Queue Doorbell to signal the
  316. * HBA to start processing the Work Queue Entry. This function returns 0 if
  317. * successful. If no entries are available on @q then this function will return
  318. * -ENOMEM.
  319. * The caller is expected to hold the hbalock when calling this routine.
  320. **/
  321. static uint32_t
  322. lpfc_sli4_mq_put(struct lpfc_queue *q, struct lpfc_mqe *mqe)
  323. {
  324. struct lpfc_mqe *temp_mqe;
  325. struct lpfc_register doorbell;
  326. /* sanity check on queue memory */
  327. if (unlikely(!q))
  328. return -ENOMEM;
  329. temp_mqe = lpfc_sli4_qe(q, q->host_index);
  330. /* If the host has not yet processed the next entry then we are done */
  331. if (((q->host_index + 1) % q->entry_count) == q->hba_index)
  332. return -ENOMEM;
  333. lpfc_sli4_pcimem_bcopy(mqe, temp_mqe, q->entry_size);
  334. /* Save off the mailbox pointer for completion */
  335. q->phba->mbox = (MAILBOX_t *)temp_mqe;
  336. /* Update the host index before invoking device */
  337. q->host_index = ((q->host_index + 1) % q->entry_count);
  338. /* Ring Doorbell */
  339. doorbell.word0 = 0;
  340. bf_set(lpfc_mq_doorbell_num_posted, &doorbell, 1);
  341. bf_set(lpfc_mq_doorbell_id, &doorbell, q->queue_id);
  342. writel(doorbell.word0, q->phba->sli4_hba.MQDBregaddr);
  343. return 0;
  344. }
  345. /**
  346. * lpfc_sli4_mq_release - Updates internal hba index for MQ
  347. * @q: The Mailbox Queue to operate on.
  348. *
  349. * This routine will update the HBA index of a queue to reflect consumption of
  350. * a Mailbox Queue Entry by the HBA. When the HBA indicates that it has consumed
  351. * an entry the host calls this function to update the queue's internal
  352. * pointers. This routine returns the number of entries that were consumed by
  353. * the HBA.
  354. **/
  355. static uint32_t
  356. lpfc_sli4_mq_release(struct lpfc_queue *q)
  357. {
  358. /* sanity check on queue memory */
  359. if (unlikely(!q))
  360. return 0;
  361. /* Clear the mailbox pointer for completion */
  362. q->phba->mbox = NULL;
  363. q->hba_index = ((q->hba_index + 1) % q->entry_count);
  364. return 1;
  365. }
  366. /**
  367. * lpfc_sli4_eq_get - Gets the next valid EQE from a EQ
  368. * @q: The Event Queue to get the first valid EQE from
  369. *
  370. * This routine will get the first valid Event Queue Entry from @q, update
  371. * the queue's internal hba index, and return the EQE. If no valid EQEs are in
  372. * the Queue (no more work to do), or the Queue is full of EQEs that have been
  373. * processed, but not popped back to the HBA then this routine will return NULL.
  374. **/
  375. static struct lpfc_eqe *
  376. lpfc_sli4_eq_get(struct lpfc_queue *q)
  377. {
  378. struct lpfc_eqe *eqe;
  379. /* sanity check on queue memory */
  380. if (unlikely(!q))
  381. return NULL;
  382. eqe = lpfc_sli4_qe(q, q->host_index);
  383. /* If the next EQE is not valid then we are done */
  384. if (bf_get_le32(lpfc_eqe_valid, eqe) != q->qe_valid)
  385. return NULL;
  386. /*
  387. * insert barrier for instruction interlock : data from the hardware
  388. * must have the valid bit checked before it can be copied and acted
  389. * upon. Speculative instructions were allowing a bcopy at the start
  390. * of lpfc_sli4_fp_handle_wcqe(), which is called immediately
  391. * after our return, to copy data before the valid bit check above
  392. * was done. As such, some of the copied data was stale. The barrier
  393. * ensures the check is before any data is copied.
  394. */
  395. mb();
  396. return eqe;
  397. }
  398. /**
  399. * lpfc_sli4_eq_clr_intr - Turn off interrupts from this EQ
  400. * @q: The Event Queue to disable interrupts
  401. *
  402. **/
  403. void
  404. lpfc_sli4_eq_clr_intr(struct lpfc_queue *q)
  405. {
  406. struct lpfc_register doorbell;
  407. doorbell.word0 = 0;
  408. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  409. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  410. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  411. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  412. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  413. writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
  414. }
  415. /**
  416. * lpfc_sli4_if6_eq_clr_intr - Turn off interrupts from this EQ
  417. * @q: The Event Queue to disable interrupts
  418. *
  419. **/
  420. void
  421. lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q)
  422. {
  423. struct lpfc_register doorbell;
  424. doorbell.word0 = 0;
  425. bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
  426. writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
  427. }
  428. /**
  429. * lpfc_sli4_write_eq_db - write EQ DB for eqe's consumed or arm state
  430. * @phba: adapter with EQ
  431. * @q: The Event Queue that the host has completed processing for.
  432. * @count: Number of elements that have been consumed
  433. * @arm: Indicates whether the host wants to arms this CQ.
  434. *
  435. * This routine will notify the HBA, by ringing the doorbell, that count
  436. * number of EQEs have been processed. The @arm parameter indicates whether
  437. * the queue should be rearmed when ringing the doorbell.
  438. **/
  439. void
  440. lpfc_sli4_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
  441. uint32_t count, bool arm)
  442. {
  443. struct lpfc_register doorbell;
  444. /* sanity check on queue memory */
  445. if (unlikely(!q || (count == 0 && !arm)))
  446. return;
  447. /* ring doorbell for number popped */
  448. doorbell.word0 = 0;
  449. if (arm) {
  450. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  451. bf_set(lpfc_eqcq_doorbell_eqci, &doorbell, 1);
  452. }
  453. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
  454. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_EVENT);
  455. bf_set(lpfc_eqcq_doorbell_eqid_hi, &doorbell,
  456. (q->queue_id >> LPFC_EQID_HI_FIELD_SHIFT));
  457. bf_set(lpfc_eqcq_doorbell_eqid_lo, &doorbell, q->queue_id);
  458. writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
  459. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  460. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  461. readl(q->phba->sli4_hba.EQDBregaddr);
  462. }
  463. /**
  464. * lpfc_sli4_if6_write_eq_db - write EQ DB for eqe's consumed or arm state
  465. * @phba: adapter with EQ
  466. * @q: The Event Queue that the host has completed processing for.
  467. * @count: Number of elements that have been consumed
  468. * @arm: Indicates whether the host wants to arms this CQ.
  469. *
  470. * This routine will notify the HBA, by ringing the doorbell, that count
  471. * number of EQEs have been processed. The @arm parameter indicates whether
  472. * the queue should be rearmed when ringing the doorbell.
  473. **/
  474. void
  475. lpfc_sli4_if6_write_eq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
  476. uint32_t count, bool arm)
  477. {
  478. struct lpfc_register doorbell;
  479. /* sanity check on queue memory */
  480. if (unlikely(!q || (count == 0 && !arm)))
  481. return;
  482. /* ring doorbell for number popped */
  483. doorbell.word0 = 0;
  484. if (arm)
  485. bf_set(lpfc_if6_eq_doorbell_arm, &doorbell, 1);
  486. bf_set(lpfc_if6_eq_doorbell_num_released, &doorbell, count);
  487. bf_set(lpfc_if6_eq_doorbell_eqid, &doorbell, q->queue_id);
  488. writel(doorbell.word0, q->phba->sli4_hba.EQDBregaddr);
  489. /* PCI read to flush PCI pipeline on re-arming for INTx mode */
  490. if ((q->phba->intr_type == INTx) && (arm == LPFC_QUEUE_REARM))
  491. readl(q->phba->sli4_hba.EQDBregaddr);
  492. }
  493. static void
  494. __lpfc_sli4_consume_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
  495. struct lpfc_eqe *eqe)
  496. {
  497. if (!phba->sli4_hba.pc_sli4_params.eqav)
  498. bf_set_le32(lpfc_eqe_valid, eqe, 0);
  499. eq->host_index = ((eq->host_index + 1) % eq->entry_count);
  500. /* if the index wrapped around, toggle the valid bit */
  501. if (phba->sli4_hba.pc_sli4_params.eqav && !eq->host_index)
  502. eq->qe_valid = (eq->qe_valid) ? 0 : 1;
  503. }
  504. static void
  505. lpfc_sli4_eqcq_flush(struct lpfc_hba *phba, struct lpfc_queue *eq)
  506. {
  507. struct lpfc_eqe *eqe = NULL;
  508. u32 eq_count = 0, cq_count = 0;
  509. struct lpfc_cqe *cqe = NULL;
  510. struct lpfc_queue *cq = NULL, *childq = NULL;
  511. int cqid = 0;
  512. /* walk all the EQ entries and drop on the floor */
  513. eqe = lpfc_sli4_eq_get(eq);
  514. while (eqe) {
  515. /* Get the reference to the corresponding CQ */
  516. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  517. cq = NULL;
  518. list_for_each_entry(childq, &eq->child_list, list) {
  519. if (childq->queue_id == cqid) {
  520. cq = childq;
  521. break;
  522. }
  523. }
  524. /* If CQ is valid, iterate through it and drop all the CQEs */
  525. if (cq) {
  526. cqe = lpfc_sli4_cq_get(cq);
  527. while (cqe) {
  528. __lpfc_sli4_consume_cqe(phba, cq, cqe);
  529. cq_count++;
  530. cqe = lpfc_sli4_cq_get(cq);
  531. }
  532. /* Clear and re-arm the CQ */
  533. phba->sli4_hba.sli4_write_cq_db(phba, cq, cq_count,
  534. LPFC_QUEUE_REARM);
  535. cq_count = 0;
  536. }
  537. __lpfc_sli4_consume_eqe(phba, eq, eqe);
  538. eq_count++;
  539. eqe = lpfc_sli4_eq_get(eq);
  540. }
  541. /* Clear and re-arm the EQ */
  542. phba->sli4_hba.sli4_write_eq_db(phba, eq, eq_count, LPFC_QUEUE_REARM);
  543. }
  544. static int
  545. lpfc_sli4_process_eq(struct lpfc_hba *phba, struct lpfc_queue *eq,
  546. uint8_t rearm)
  547. {
  548. struct lpfc_eqe *eqe;
  549. int count = 0, consumed = 0;
  550. if (cmpxchg(&eq->queue_claimed, 0, 1) != 0)
  551. goto rearm_and_exit;
  552. eqe = lpfc_sli4_eq_get(eq);
  553. while (eqe) {
  554. lpfc_sli4_hba_handle_eqe(phba, eq, eqe);
  555. __lpfc_sli4_consume_eqe(phba, eq, eqe);
  556. consumed++;
  557. if (!(++count % eq->max_proc_limit))
  558. break;
  559. if (!(count % eq->notify_interval)) {
  560. phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed,
  561. LPFC_QUEUE_NOARM);
  562. consumed = 0;
  563. }
  564. eqe = lpfc_sli4_eq_get(eq);
  565. }
  566. eq->EQ_processed += count;
  567. /* Track the max number of EQEs processed in 1 intr */
  568. if (count > eq->EQ_max_eqe)
  569. eq->EQ_max_eqe = count;
  570. xchg(&eq->queue_claimed, 0);
  571. rearm_and_exit:
  572. /* Always clear the EQ. */
  573. phba->sli4_hba.sli4_write_eq_db(phba, eq, consumed, rearm);
  574. return count;
  575. }
  576. /**
  577. * lpfc_sli4_cq_get - Gets the next valid CQE from a CQ
  578. * @q: The Completion Queue to get the first valid CQE from
  579. *
  580. * This routine will get the first valid Completion Queue Entry from @q, update
  581. * the queue's internal hba index, and return the CQE. If no valid CQEs are in
  582. * the Queue (no more work to do), or the Queue is full of CQEs that have been
  583. * processed, but not popped back to the HBA then this routine will return NULL.
  584. **/
  585. static struct lpfc_cqe *
  586. lpfc_sli4_cq_get(struct lpfc_queue *q)
  587. {
  588. struct lpfc_cqe *cqe;
  589. /* sanity check on queue memory */
  590. if (unlikely(!q))
  591. return NULL;
  592. cqe = lpfc_sli4_qe(q, q->host_index);
  593. /* If the next CQE is not valid then we are done */
  594. if (bf_get_le32(lpfc_cqe_valid, cqe) != q->qe_valid)
  595. return NULL;
  596. /*
  597. * insert barrier for instruction interlock : data from the hardware
  598. * must have the valid bit checked before it can be copied and acted
  599. * upon. Given what was seen in lpfc_sli4_cq_get() of speculative
  600. * instructions allowing action on content before valid bit checked,
  601. * add barrier here as well. May not be needed as "content" is a
  602. * single 32-bit entity here (vs multi word structure for cq's).
  603. */
  604. mb();
  605. return cqe;
  606. }
  607. static void
  608. __lpfc_sli4_consume_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  609. struct lpfc_cqe *cqe)
  610. {
  611. if (!phba->sli4_hba.pc_sli4_params.cqav)
  612. bf_set_le32(lpfc_cqe_valid, cqe, 0);
  613. cq->host_index = ((cq->host_index + 1) % cq->entry_count);
  614. /* if the index wrapped around, toggle the valid bit */
  615. if (phba->sli4_hba.pc_sli4_params.cqav && !cq->host_index)
  616. cq->qe_valid = (cq->qe_valid) ? 0 : 1;
  617. }
  618. /**
  619. * lpfc_sli4_write_cq_db - write cq DB for entries consumed or arm state.
  620. * @phba: the adapter with the CQ
  621. * @q: The Completion Queue that the host has completed processing for.
  622. * @count: the number of elements that were consumed
  623. * @arm: Indicates whether the host wants to arms this CQ.
  624. *
  625. * This routine will notify the HBA, by ringing the doorbell, that the
  626. * CQEs have been processed. The @arm parameter specifies whether the
  627. * queue should be rearmed when ringing the doorbell.
  628. **/
  629. void
  630. lpfc_sli4_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
  631. uint32_t count, bool arm)
  632. {
  633. struct lpfc_register doorbell;
  634. /* sanity check on queue memory */
  635. if (unlikely(!q || (count == 0 && !arm)))
  636. return;
  637. /* ring doorbell for number popped */
  638. doorbell.word0 = 0;
  639. if (arm)
  640. bf_set(lpfc_eqcq_doorbell_arm, &doorbell, 1);
  641. bf_set(lpfc_eqcq_doorbell_num_released, &doorbell, count);
  642. bf_set(lpfc_eqcq_doorbell_qt, &doorbell, LPFC_QUEUE_TYPE_COMPLETION);
  643. bf_set(lpfc_eqcq_doorbell_cqid_hi, &doorbell,
  644. (q->queue_id >> LPFC_CQID_HI_FIELD_SHIFT));
  645. bf_set(lpfc_eqcq_doorbell_cqid_lo, &doorbell, q->queue_id);
  646. writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
  647. }
  648. /**
  649. * lpfc_sli4_if6_write_cq_db - write cq DB for entries consumed or arm state.
  650. * @phba: the adapter with the CQ
  651. * @q: The Completion Queue that the host has completed processing for.
  652. * @count: the number of elements that were consumed
  653. * @arm: Indicates whether the host wants to arms this CQ.
  654. *
  655. * This routine will notify the HBA, by ringing the doorbell, that the
  656. * CQEs have been processed. The @arm parameter specifies whether the
  657. * queue should be rearmed when ringing the doorbell.
  658. **/
  659. void
  660. lpfc_sli4_if6_write_cq_db(struct lpfc_hba *phba, struct lpfc_queue *q,
  661. uint32_t count, bool arm)
  662. {
  663. struct lpfc_register doorbell;
  664. /* sanity check on queue memory */
  665. if (unlikely(!q || (count == 0 && !arm)))
  666. return;
  667. /* ring doorbell for number popped */
  668. doorbell.word0 = 0;
  669. if (arm)
  670. bf_set(lpfc_if6_cq_doorbell_arm, &doorbell, 1);
  671. bf_set(lpfc_if6_cq_doorbell_num_released, &doorbell, count);
  672. bf_set(lpfc_if6_cq_doorbell_cqid, &doorbell, q->queue_id);
  673. writel(doorbell.word0, q->phba->sli4_hba.CQDBregaddr);
  674. }
  675. /*
  676. * lpfc_sli4_rq_put - Put a Receive Buffer Queue Entry on a Receive Queue
  677. *
  678. * This routine will copy the contents of @wqe to the next available entry on
  679. * the @q. This function will then ring the Receive Queue Doorbell to signal the
  680. * HBA to start processing the Receive Queue Entry. This function returns the
  681. * index that the rqe was copied to if successful. If no entries are available
  682. * on @q then this function will return -ENOMEM.
  683. * The caller is expected to hold the hbalock when calling this routine.
  684. **/
  685. int
  686. lpfc_sli4_rq_put(struct lpfc_queue *hq, struct lpfc_queue *dq,
  687. struct lpfc_rqe *hrqe, struct lpfc_rqe *drqe)
  688. {
  689. struct lpfc_rqe *temp_hrqe;
  690. struct lpfc_rqe *temp_drqe;
  691. struct lpfc_register doorbell;
  692. int hq_put_index;
  693. int dq_put_index;
  694. /* sanity check on queue memory */
  695. if (unlikely(!hq) || unlikely(!dq))
  696. return -ENOMEM;
  697. hq_put_index = hq->host_index;
  698. dq_put_index = dq->host_index;
  699. temp_hrqe = lpfc_sli4_qe(hq, hq_put_index);
  700. temp_drqe = lpfc_sli4_qe(dq, dq_put_index);
  701. if (hq->type != LPFC_HRQ || dq->type != LPFC_DRQ)
  702. return -EINVAL;
  703. if (hq_put_index != dq_put_index)
  704. return -EINVAL;
  705. /* If the host has not yet processed the next entry then we are done */
  706. if (((hq_put_index + 1) % hq->entry_count) == hq->hba_index)
  707. return -EBUSY;
  708. lpfc_sli4_pcimem_bcopy(hrqe, temp_hrqe, hq->entry_size);
  709. lpfc_sli4_pcimem_bcopy(drqe, temp_drqe, dq->entry_size);
  710. /* Update the host index to point to the next slot */
  711. hq->host_index = ((hq_put_index + 1) % hq->entry_count);
  712. dq->host_index = ((dq_put_index + 1) % dq->entry_count);
  713. hq->RQ_buf_posted++;
  714. /* Ring The Header Receive Queue Doorbell */
  715. if (!(hq->host_index % hq->notify_interval)) {
  716. doorbell.word0 = 0;
  717. if (hq->db_format == LPFC_DB_RING_FORMAT) {
  718. bf_set(lpfc_rq_db_ring_fm_num_posted, &doorbell,
  719. hq->notify_interval);
  720. bf_set(lpfc_rq_db_ring_fm_id, &doorbell, hq->queue_id);
  721. } else if (hq->db_format == LPFC_DB_LIST_FORMAT) {
  722. bf_set(lpfc_rq_db_list_fm_num_posted, &doorbell,
  723. hq->notify_interval);
  724. bf_set(lpfc_rq_db_list_fm_index, &doorbell,
  725. hq->host_index);
  726. bf_set(lpfc_rq_db_list_fm_id, &doorbell, hq->queue_id);
  727. } else {
  728. return -EINVAL;
  729. }
  730. writel(doorbell.word0, hq->db_regaddr);
  731. }
  732. return hq_put_index;
  733. }
  734. /*
  735. * lpfc_sli4_rq_release - Updates internal hba index for RQ
  736. *
  737. * This routine will update the HBA index of a queue to reflect consumption of
  738. * one Receive Queue Entry by the HBA. When the HBA indicates that it has
  739. * consumed an entry the host calls this function to update the queue's
  740. * internal pointers. This routine returns the number of entries that were
  741. * consumed by the HBA.
  742. **/
  743. static uint32_t
  744. lpfc_sli4_rq_release(struct lpfc_queue *hq, struct lpfc_queue *dq)
  745. {
  746. /* sanity check on queue memory */
  747. if (unlikely(!hq) || unlikely(!dq))
  748. return 0;
  749. if ((hq->type != LPFC_HRQ) || (dq->type != LPFC_DRQ))
  750. return 0;
  751. hq->hba_index = ((hq->hba_index + 1) % hq->entry_count);
  752. dq->hba_index = ((dq->hba_index + 1) % dq->entry_count);
  753. return 1;
  754. }
  755. /**
  756. * lpfc_cmd_iocb - Get next command iocb entry in the ring
  757. * @phba: Pointer to HBA context object.
  758. * @pring: Pointer to driver SLI ring object.
  759. *
  760. * This function returns pointer to next command iocb entry
  761. * in the command ring. The caller must hold hbalock to prevent
  762. * other threads consume the next command iocb.
  763. * SLI-2/SLI-3 provide different sized iocbs.
  764. **/
  765. static inline IOCB_t *
  766. lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  767. {
  768. return (IOCB_t *) (((char *) pring->sli.sli3.cmdringaddr) +
  769. pring->sli.sli3.cmdidx * phba->iocb_cmd_size);
  770. }
  771. /**
  772. * lpfc_resp_iocb - Get next response iocb entry in the ring
  773. * @phba: Pointer to HBA context object.
  774. * @pring: Pointer to driver SLI ring object.
  775. *
  776. * This function returns pointer to next response iocb entry
  777. * in the response ring. The caller must hold hbalock to make sure
  778. * that no other thread consume the next response iocb.
  779. * SLI-2/SLI-3 provide different sized iocbs.
  780. **/
  781. static inline IOCB_t *
  782. lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  783. {
  784. return (IOCB_t *) (((char *) pring->sli.sli3.rspringaddr) +
  785. pring->sli.sli3.rspidx * phba->iocb_rsp_size);
  786. }
  787. /**
  788. * __lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  789. * @phba: Pointer to HBA context object.
  790. *
  791. * This function is called with hbalock held. This function
  792. * allocates a new driver iocb object from the iocb pool. If the
  793. * allocation is successful, it returns pointer to the newly
  794. * allocated iocb object else it returns NULL.
  795. **/
  796. struct lpfc_iocbq *
  797. __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  798. {
  799. struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
  800. struct lpfc_iocbq * iocbq = NULL;
  801. lockdep_assert_held(&phba->hbalock);
  802. list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
  803. if (iocbq)
  804. phba->iocb_cnt++;
  805. if (phba->iocb_cnt > phba->iocb_max)
  806. phba->iocb_max = phba->iocb_cnt;
  807. return iocbq;
  808. }
  809. /**
  810. * __lpfc_clear_active_sglq - Remove the active sglq for this XRI.
  811. * @phba: Pointer to HBA context object.
  812. * @xritag: XRI value.
  813. *
  814. * This function clears the sglq pointer from the array of active
  815. * sglq's. The xritag that is passed in is used to index into the
  816. * array. Before the xritag can be used it needs to be adjusted
  817. * by subtracting the xribase.
  818. *
  819. * Returns sglq ponter = success, NULL = Failure.
  820. **/
  821. struct lpfc_sglq *
  822. __lpfc_clear_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  823. {
  824. struct lpfc_sglq *sglq;
  825. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  826. phba->sli4_hba.lpfc_sglq_active_list[xritag] = NULL;
  827. return sglq;
  828. }
  829. /**
  830. * __lpfc_get_active_sglq - Get the active sglq for this XRI.
  831. * @phba: Pointer to HBA context object.
  832. * @xritag: XRI value.
  833. *
  834. * This function returns the sglq pointer from the array of active
  835. * sglq's. The xritag that is passed in is used to index into the
  836. * array. Before the xritag can be used it needs to be adjusted
  837. * by subtracting the xribase.
  838. *
  839. * Returns sglq ponter = success, NULL = Failure.
  840. **/
  841. struct lpfc_sglq *
  842. __lpfc_get_active_sglq(struct lpfc_hba *phba, uint16_t xritag)
  843. {
  844. struct lpfc_sglq *sglq;
  845. sglq = phba->sli4_hba.lpfc_sglq_active_list[xritag];
  846. return sglq;
  847. }
  848. /**
  849. * lpfc_clr_rrq_active - Clears RRQ active bit in xri_bitmap.
  850. * @phba: Pointer to HBA context object.
  851. * @xritag: xri used in this exchange.
  852. * @rrq: The RRQ to be cleared.
  853. *
  854. **/
  855. void
  856. lpfc_clr_rrq_active(struct lpfc_hba *phba,
  857. uint16_t xritag,
  858. struct lpfc_node_rrq *rrq)
  859. {
  860. struct lpfc_nodelist *ndlp = NULL;
  861. /* Lookup did to verify if did is still active on this vport */
  862. if (rrq->vport)
  863. ndlp = lpfc_findnode_did(rrq->vport, rrq->nlp_DID);
  864. if (!ndlp)
  865. goto out;
  866. if (test_and_clear_bit(xritag, ndlp->active_rrqs_xri_bitmap)) {
  867. rrq->send_rrq = 0;
  868. rrq->xritag = 0;
  869. rrq->rrq_stop_time = 0;
  870. }
  871. out:
  872. mempool_free(rrq, phba->rrq_pool);
  873. }
  874. /**
  875. * lpfc_handle_rrq_active - Checks if RRQ has waithed RATOV.
  876. * @phba: Pointer to HBA context object.
  877. *
  878. * This function is called with hbalock held. This function
  879. * Checks if stop_time (ratov from setting rrq active) has
  880. * been reached, if it has and the send_rrq flag is set then
  881. * it will call lpfc_send_rrq. If the send_rrq flag is not set
  882. * then it will just call the routine to clear the rrq and
  883. * free the rrq resource.
  884. * The timer is set to the next rrq that is going to expire before
  885. * leaving the routine.
  886. *
  887. **/
  888. void
  889. lpfc_handle_rrq_active(struct lpfc_hba *phba)
  890. {
  891. struct lpfc_node_rrq *rrq;
  892. struct lpfc_node_rrq *nextrrq;
  893. unsigned long next_time;
  894. unsigned long iflags;
  895. LIST_HEAD(send_rrq);
  896. spin_lock_irqsave(&phba->hbalock, iflags);
  897. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  898. next_time = jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  899. list_for_each_entry_safe(rrq, nextrrq,
  900. &phba->active_rrq_list, list) {
  901. if (time_after(jiffies, rrq->rrq_stop_time))
  902. list_move(&rrq->list, &send_rrq);
  903. else if (time_before(rrq->rrq_stop_time, next_time))
  904. next_time = rrq->rrq_stop_time;
  905. }
  906. spin_unlock_irqrestore(&phba->hbalock, iflags);
  907. if ((!list_empty(&phba->active_rrq_list)) &&
  908. (!(phba->pport->load_flag & FC_UNLOADING)))
  909. mod_timer(&phba->rrq_tmr, next_time);
  910. list_for_each_entry_safe(rrq, nextrrq, &send_rrq, list) {
  911. list_del(&rrq->list);
  912. if (!rrq->send_rrq) {
  913. /* this call will free the rrq */
  914. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  915. } else if (lpfc_send_rrq(phba, rrq)) {
  916. /* if we send the rrq then the completion handler
  917. * will clear the bit in the xribitmap.
  918. */
  919. lpfc_clr_rrq_active(phba, rrq->xritag,
  920. rrq);
  921. }
  922. }
  923. }
  924. /**
  925. * lpfc_get_active_rrq - Get the active RRQ for this exchange.
  926. * @vport: Pointer to vport context object.
  927. * @xri: The xri used in the exchange.
  928. * @did: The targets DID for this exchange.
  929. *
  930. * returns NULL = rrq not found in the phba->active_rrq_list.
  931. * rrq = rrq for this xri and target.
  932. **/
  933. struct lpfc_node_rrq *
  934. lpfc_get_active_rrq(struct lpfc_vport *vport, uint16_t xri, uint32_t did)
  935. {
  936. struct lpfc_hba *phba = vport->phba;
  937. struct lpfc_node_rrq *rrq;
  938. struct lpfc_node_rrq *nextrrq;
  939. unsigned long iflags;
  940. if (phba->sli_rev != LPFC_SLI_REV4)
  941. return NULL;
  942. spin_lock_irqsave(&phba->hbalock, iflags);
  943. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  944. if (rrq->vport == vport && rrq->xritag == xri &&
  945. rrq->nlp_DID == did){
  946. list_del(&rrq->list);
  947. spin_unlock_irqrestore(&phba->hbalock, iflags);
  948. return rrq;
  949. }
  950. }
  951. spin_unlock_irqrestore(&phba->hbalock, iflags);
  952. return NULL;
  953. }
  954. /**
  955. * lpfc_cleanup_vports_rrqs - Remove and clear the active RRQ for this vport.
  956. * @vport: Pointer to vport context object.
  957. * @ndlp: Pointer to the lpfc_node_list structure.
  958. * If ndlp is NULL Remove all active RRQs for this vport from the
  959. * phba->active_rrq_list and clear the rrq.
  960. * If ndlp is not NULL then only remove rrqs for this vport & this ndlp.
  961. **/
  962. void
  963. lpfc_cleanup_vports_rrqs(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  964. {
  965. struct lpfc_hba *phba = vport->phba;
  966. struct lpfc_node_rrq *rrq;
  967. struct lpfc_node_rrq *nextrrq;
  968. unsigned long iflags;
  969. LIST_HEAD(rrq_list);
  970. if (phba->sli_rev != LPFC_SLI_REV4)
  971. return;
  972. if (!ndlp) {
  973. lpfc_sli4_vport_delete_els_xri_aborted(vport);
  974. lpfc_sli4_vport_delete_fcp_xri_aborted(vport);
  975. }
  976. spin_lock_irqsave(&phba->hbalock, iflags);
  977. list_for_each_entry_safe(rrq, nextrrq, &phba->active_rrq_list, list) {
  978. if (rrq->vport != vport)
  979. continue;
  980. if (!ndlp || ndlp == lpfc_findnode_did(vport, rrq->nlp_DID))
  981. list_move(&rrq->list, &rrq_list);
  982. }
  983. spin_unlock_irqrestore(&phba->hbalock, iflags);
  984. list_for_each_entry_safe(rrq, nextrrq, &rrq_list, list) {
  985. list_del(&rrq->list);
  986. lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
  987. }
  988. }
  989. /**
  990. * lpfc_test_rrq_active - Test RRQ bit in xri_bitmap.
  991. * @phba: Pointer to HBA context object.
  992. * @ndlp: Targets nodelist pointer for this exchange.
  993. * @xritag: the xri in the bitmap to test.
  994. *
  995. * This function returns:
  996. * 0 = rrq not active for this xri
  997. * 1 = rrq is valid for this xri.
  998. **/
  999. int
  1000. lpfc_test_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  1001. uint16_t xritag)
  1002. {
  1003. if (!ndlp)
  1004. return 0;
  1005. if (!ndlp->active_rrqs_xri_bitmap)
  1006. return 0;
  1007. if (test_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  1008. return 1;
  1009. else
  1010. return 0;
  1011. }
  1012. /**
  1013. * lpfc_set_rrq_active - set RRQ active bit in xri_bitmap.
  1014. * @phba: Pointer to HBA context object.
  1015. * @ndlp: nodelist pointer for this target.
  1016. * @xritag: xri used in this exchange.
  1017. * @rxid: Remote Exchange ID.
  1018. * @send_rrq: Flag used to determine if we should send rrq els cmd.
  1019. *
  1020. * This function takes the hbalock.
  1021. * The active bit is always set in the active rrq xri_bitmap even
  1022. * if there is no slot avaiable for the other rrq information.
  1023. *
  1024. * returns 0 rrq actived for this xri
  1025. * < 0 No memory or invalid ndlp.
  1026. **/
  1027. int
  1028. lpfc_set_rrq_active(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
  1029. uint16_t xritag, uint16_t rxid, uint16_t send_rrq)
  1030. {
  1031. unsigned long iflags;
  1032. struct lpfc_node_rrq *rrq;
  1033. int empty;
  1034. if (!ndlp)
  1035. return -EINVAL;
  1036. if (!phba->cfg_enable_rrq)
  1037. return -EINVAL;
  1038. spin_lock_irqsave(&phba->hbalock, iflags);
  1039. if (phba->pport->load_flag & FC_UNLOADING) {
  1040. phba->hba_flag &= ~HBA_RRQ_ACTIVE;
  1041. goto out;
  1042. }
  1043. if (ndlp->vport && (ndlp->vport->load_flag & FC_UNLOADING))
  1044. goto out;
  1045. if (!ndlp->active_rrqs_xri_bitmap)
  1046. goto out;
  1047. if (test_and_set_bit(xritag, ndlp->active_rrqs_xri_bitmap))
  1048. goto out;
  1049. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1050. rrq = mempool_alloc(phba->rrq_pool, GFP_ATOMIC);
  1051. if (!rrq) {
  1052. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1053. "3155 Unable to allocate RRQ xri:0x%x rxid:0x%x"
  1054. " DID:0x%x Send:%d\n",
  1055. xritag, rxid, ndlp->nlp_DID, send_rrq);
  1056. return -EINVAL;
  1057. }
  1058. if (phba->cfg_enable_rrq == 1)
  1059. rrq->send_rrq = send_rrq;
  1060. else
  1061. rrq->send_rrq = 0;
  1062. rrq->xritag = xritag;
  1063. rrq->rrq_stop_time = jiffies +
  1064. msecs_to_jiffies(1000 * (phba->fc_ratov + 1));
  1065. rrq->nlp_DID = ndlp->nlp_DID;
  1066. rrq->vport = ndlp->vport;
  1067. rrq->rxid = rxid;
  1068. spin_lock_irqsave(&phba->hbalock, iflags);
  1069. empty = list_empty(&phba->active_rrq_list);
  1070. list_add_tail(&rrq->list, &phba->active_rrq_list);
  1071. phba->hba_flag |= HBA_RRQ_ACTIVE;
  1072. if (empty)
  1073. lpfc_worker_wake_up(phba);
  1074. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1075. return 0;
  1076. out:
  1077. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1078. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  1079. "2921 Can't set rrq active xri:0x%x rxid:0x%x"
  1080. " DID:0x%x Send:%d\n",
  1081. xritag, rxid, ndlp->nlp_DID, send_rrq);
  1082. return -EINVAL;
  1083. }
  1084. /**
  1085. * __lpfc_sli_get_els_sglq - Allocates an iocb object from sgl pool
  1086. * @phba: Pointer to HBA context object.
  1087. * @piocbq: Pointer to the iocbq.
  1088. *
  1089. * The driver calls this function with either the nvme ls ring lock
  1090. * or the fc els ring lock held depending on the iocb usage. This function
  1091. * gets a new driver sglq object from the sglq list. If the list is not empty
  1092. * then it is successful, it returns pointer to the newly allocated sglq
  1093. * object else it returns NULL.
  1094. **/
  1095. static struct lpfc_sglq *
  1096. __lpfc_sli_get_els_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  1097. {
  1098. struct list_head *lpfc_els_sgl_list = &phba->sli4_hba.lpfc_els_sgl_list;
  1099. struct lpfc_sglq *sglq = NULL;
  1100. struct lpfc_sglq *start_sglq = NULL;
  1101. struct lpfc_io_buf *lpfc_cmd;
  1102. struct lpfc_nodelist *ndlp;
  1103. int found = 0;
  1104. u8 cmnd;
  1105. cmnd = get_job_cmnd(phba, piocbq);
  1106. if (piocbq->cmd_flag & LPFC_IO_FCP) {
  1107. lpfc_cmd = piocbq->io_buf;
  1108. ndlp = lpfc_cmd->rdata->pnode;
  1109. } else if ((cmnd == CMD_GEN_REQUEST64_CR) &&
  1110. !(piocbq->cmd_flag & LPFC_IO_LIBDFC)) {
  1111. ndlp = piocbq->ndlp;
  1112. } else if (piocbq->cmd_flag & LPFC_IO_LIBDFC) {
  1113. if (piocbq->cmd_flag & LPFC_IO_LOOPBACK)
  1114. ndlp = NULL;
  1115. else
  1116. ndlp = piocbq->ndlp;
  1117. } else {
  1118. ndlp = piocbq->ndlp;
  1119. }
  1120. spin_lock(&phba->sli4_hba.sgl_list_lock);
  1121. list_remove_head(lpfc_els_sgl_list, sglq, struct lpfc_sglq, list);
  1122. start_sglq = sglq;
  1123. while (!found) {
  1124. if (!sglq)
  1125. break;
  1126. if (ndlp && ndlp->active_rrqs_xri_bitmap &&
  1127. test_bit(sglq->sli4_lxritag,
  1128. ndlp->active_rrqs_xri_bitmap)) {
  1129. /* This xri has an rrq outstanding for this DID.
  1130. * put it back in the list and get another xri.
  1131. */
  1132. list_add_tail(&sglq->list, lpfc_els_sgl_list);
  1133. sglq = NULL;
  1134. list_remove_head(lpfc_els_sgl_list, sglq,
  1135. struct lpfc_sglq, list);
  1136. if (sglq == start_sglq) {
  1137. list_add_tail(&sglq->list, lpfc_els_sgl_list);
  1138. sglq = NULL;
  1139. break;
  1140. } else
  1141. continue;
  1142. }
  1143. sglq->ndlp = ndlp;
  1144. found = 1;
  1145. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  1146. sglq->state = SGL_ALLOCATED;
  1147. }
  1148. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  1149. return sglq;
  1150. }
  1151. /**
  1152. * __lpfc_sli_get_nvmet_sglq - Allocates an iocb object from sgl pool
  1153. * @phba: Pointer to HBA context object.
  1154. * @piocbq: Pointer to the iocbq.
  1155. *
  1156. * This function is called with the sgl_list lock held. This function
  1157. * gets a new driver sglq object from the sglq list. If the
  1158. * list is not empty then it is successful, it returns pointer to the newly
  1159. * allocated sglq object else it returns NULL.
  1160. **/
  1161. struct lpfc_sglq *
  1162. __lpfc_sli_get_nvmet_sglq(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq)
  1163. {
  1164. struct list_head *lpfc_nvmet_sgl_list;
  1165. struct lpfc_sglq *sglq = NULL;
  1166. lpfc_nvmet_sgl_list = &phba->sli4_hba.lpfc_nvmet_sgl_list;
  1167. lockdep_assert_held(&phba->sli4_hba.sgl_list_lock);
  1168. list_remove_head(lpfc_nvmet_sgl_list, sglq, struct lpfc_sglq, list);
  1169. if (!sglq)
  1170. return NULL;
  1171. phba->sli4_hba.lpfc_sglq_active_list[sglq->sli4_lxritag] = sglq;
  1172. sglq->state = SGL_ALLOCATED;
  1173. return sglq;
  1174. }
  1175. /**
  1176. * lpfc_sli_get_iocbq - Allocates an iocb object from iocb pool
  1177. * @phba: Pointer to HBA context object.
  1178. *
  1179. * This function is called with no lock held. This function
  1180. * allocates a new driver iocb object from the iocb pool. If the
  1181. * allocation is successful, it returns pointer to the newly
  1182. * allocated iocb object else it returns NULL.
  1183. **/
  1184. struct lpfc_iocbq *
  1185. lpfc_sli_get_iocbq(struct lpfc_hba *phba)
  1186. {
  1187. struct lpfc_iocbq * iocbq = NULL;
  1188. unsigned long iflags;
  1189. spin_lock_irqsave(&phba->hbalock, iflags);
  1190. iocbq = __lpfc_sli_get_iocbq(phba);
  1191. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1192. return iocbq;
  1193. }
  1194. /**
  1195. * __lpfc_sli_release_iocbq_s4 - Release iocb to the iocb pool
  1196. * @phba: Pointer to HBA context object.
  1197. * @iocbq: Pointer to driver iocb object.
  1198. *
  1199. * This function is called to release the driver iocb object
  1200. * to the iocb pool. The iotag in the iocb object
  1201. * does not change for each use of the iocb object. This function
  1202. * clears all other fields of the iocb object when it is freed.
  1203. * The sqlq structure that holds the xritag and phys and virtual
  1204. * mappings for the scatter gather list is retrieved from the
  1205. * active array of sglq. The get of the sglq pointer also clears
  1206. * the entry in the array. If the status of the IO indiactes that
  1207. * this IO was aborted then the sglq entry it put on the
  1208. * lpfc_abts_els_sgl_list until the CQ_ABORTED_XRI is received. If the
  1209. * IO has good status or fails for any other reason then the sglq
  1210. * entry is added to the free list (lpfc_els_sgl_list). The hbalock is
  1211. * asserted held in the code path calling this routine.
  1212. **/
  1213. static void
  1214. __lpfc_sli_release_iocbq_s4(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1215. {
  1216. struct lpfc_sglq *sglq;
  1217. size_t start_clean = offsetof(struct lpfc_iocbq, wqe);
  1218. unsigned long iflag = 0;
  1219. struct lpfc_sli_ring *pring;
  1220. if (iocbq->sli4_xritag == NO_XRI)
  1221. sglq = NULL;
  1222. else
  1223. sglq = __lpfc_clear_active_sglq(phba, iocbq->sli4_lxritag);
  1224. if (sglq) {
  1225. if (iocbq->cmd_flag & LPFC_IO_NVMET) {
  1226. spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
  1227. iflag);
  1228. sglq->state = SGL_FREED;
  1229. sglq->ndlp = NULL;
  1230. list_add_tail(&sglq->list,
  1231. &phba->sli4_hba.lpfc_nvmet_sgl_list);
  1232. spin_unlock_irqrestore(
  1233. &phba->sli4_hba.sgl_list_lock, iflag);
  1234. goto out;
  1235. }
  1236. if ((iocbq->cmd_flag & LPFC_EXCHANGE_BUSY) &&
  1237. (!(unlikely(pci_channel_offline(phba->pcidev)))) &&
  1238. sglq->state != SGL_XRI_ABORTED) {
  1239. spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
  1240. iflag);
  1241. /* Check if we can get a reference on ndlp */
  1242. if (sglq->ndlp && !lpfc_nlp_get(sglq->ndlp))
  1243. sglq->ndlp = NULL;
  1244. list_add(&sglq->list,
  1245. &phba->sli4_hba.lpfc_abts_els_sgl_list);
  1246. spin_unlock_irqrestore(
  1247. &phba->sli4_hba.sgl_list_lock, iflag);
  1248. } else {
  1249. spin_lock_irqsave(&phba->sli4_hba.sgl_list_lock,
  1250. iflag);
  1251. sglq->state = SGL_FREED;
  1252. sglq->ndlp = NULL;
  1253. list_add_tail(&sglq->list,
  1254. &phba->sli4_hba.lpfc_els_sgl_list);
  1255. spin_unlock_irqrestore(
  1256. &phba->sli4_hba.sgl_list_lock, iflag);
  1257. pring = lpfc_phba_elsring(phba);
  1258. /* Check if TXQ queue needs to be serviced */
  1259. if (pring && (!list_empty(&pring->txq)))
  1260. lpfc_worker_wake_up(phba);
  1261. }
  1262. }
  1263. out:
  1264. /*
  1265. * Clean all volatile data fields, preserve iotag and node struct.
  1266. */
  1267. memset((char *)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  1268. iocbq->sli4_lxritag = NO_XRI;
  1269. iocbq->sli4_xritag = NO_XRI;
  1270. iocbq->cmd_flag &= ~(LPFC_IO_NVME | LPFC_IO_NVMET | LPFC_IO_CMF |
  1271. LPFC_IO_NVME_LS);
  1272. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  1273. }
  1274. /**
  1275. * __lpfc_sli_release_iocbq_s3 - Release iocb to the iocb pool
  1276. * @phba: Pointer to HBA context object.
  1277. * @iocbq: Pointer to driver iocb object.
  1278. *
  1279. * This function is called to release the driver iocb object to the
  1280. * iocb pool. The iotag in the iocb object does not change for each
  1281. * use of the iocb object. This function clears all other fields of
  1282. * the iocb object when it is freed. The hbalock is asserted held in
  1283. * the code path calling this routine.
  1284. **/
  1285. static void
  1286. __lpfc_sli_release_iocbq_s3(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1287. {
  1288. size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
  1289. /*
  1290. * Clean all volatile data fields, preserve iotag and node struct.
  1291. */
  1292. memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
  1293. iocbq->sli4_xritag = NO_XRI;
  1294. list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
  1295. }
  1296. /**
  1297. * __lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1298. * @phba: Pointer to HBA context object.
  1299. * @iocbq: Pointer to driver iocb object.
  1300. *
  1301. * This function is called with hbalock held to release driver
  1302. * iocb object to the iocb pool. The iotag in the iocb object
  1303. * does not change for each use of the iocb object. This function
  1304. * clears all other fields of the iocb object when it is freed.
  1305. **/
  1306. static void
  1307. __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1308. {
  1309. lockdep_assert_held(&phba->hbalock);
  1310. phba->__lpfc_sli_release_iocbq(phba, iocbq);
  1311. phba->iocb_cnt--;
  1312. }
  1313. /**
  1314. * lpfc_sli_release_iocbq - Release iocb to the iocb pool
  1315. * @phba: Pointer to HBA context object.
  1316. * @iocbq: Pointer to driver iocb object.
  1317. *
  1318. * This function is called with no lock held to release the iocb to
  1319. * iocb pool.
  1320. **/
  1321. void
  1322. lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1323. {
  1324. unsigned long iflags;
  1325. /*
  1326. * Clean all volatile data fields, preserve iotag and node struct.
  1327. */
  1328. spin_lock_irqsave(&phba->hbalock, iflags);
  1329. __lpfc_sli_release_iocbq(phba, iocbq);
  1330. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1331. }
  1332. /**
  1333. * lpfc_sli_cancel_iocbs - Cancel all iocbs from a list.
  1334. * @phba: Pointer to HBA context object.
  1335. * @iocblist: List of IOCBs.
  1336. * @ulpstatus: ULP status in IOCB command field.
  1337. * @ulpWord4: ULP word-4 in IOCB command field.
  1338. *
  1339. * This function is called with a list of IOCBs to cancel. It cancels the IOCB
  1340. * on the list by invoking the complete callback function associated with the
  1341. * IOCB with the provided @ulpstatus and @ulpword4 set to the IOCB commond
  1342. * fields.
  1343. **/
  1344. void
  1345. lpfc_sli_cancel_iocbs(struct lpfc_hba *phba, struct list_head *iocblist,
  1346. uint32_t ulpstatus, uint32_t ulpWord4)
  1347. {
  1348. struct lpfc_iocbq *piocb;
  1349. while (!list_empty(iocblist)) {
  1350. list_remove_head(iocblist, piocb, struct lpfc_iocbq, list);
  1351. if (piocb->cmd_cmpl) {
  1352. if (piocb->cmd_flag & LPFC_IO_NVME) {
  1353. lpfc_nvme_cancel_iocb(phba, piocb,
  1354. ulpstatus, ulpWord4);
  1355. } else {
  1356. if (phba->sli_rev == LPFC_SLI_REV4) {
  1357. bf_set(lpfc_wcqe_c_status,
  1358. &piocb->wcqe_cmpl, ulpstatus);
  1359. piocb->wcqe_cmpl.parameter = ulpWord4;
  1360. } else {
  1361. piocb->iocb.ulpStatus = ulpstatus;
  1362. piocb->iocb.un.ulpWord[4] = ulpWord4;
  1363. }
  1364. (piocb->cmd_cmpl) (phba, piocb, piocb);
  1365. }
  1366. } else {
  1367. lpfc_sli_release_iocbq(phba, piocb);
  1368. }
  1369. }
  1370. return;
  1371. }
  1372. /**
  1373. * lpfc_sli_iocb_cmd_type - Get the iocb type
  1374. * @iocb_cmnd: iocb command code.
  1375. *
  1376. * This function is called by ring event handler function to get the iocb type.
  1377. * This function translates the iocb command to an iocb command type used to
  1378. * decide the final disposition of each completed IOCB.
  1379. * The function returns
  1380. * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
  1381. * LPFC_SOL_IOCB if it is a solicited iocb completion
  1382. * LPFC_ABORT_IOCB if it is an abort iocb
  1383. * LPFC_UNSOL_IOCB if it is an unsolicited iocb
  1384. *
  1385. * The caller is not required to hold any lock.
  1386. **/
  1387. static lpfc_iocb_type
  1388. lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
  1389. {
  1390. lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
  1391. if (iocb_cmnd > CMD_MAX_IOCB_CMD)
  1392. return 0;
  1393. switch (iocb_cmnd) {
  1394. case CMD_XMIT_SEQUENCE_CR:
  1395. case CMD_XMIT_SEQUENCE_CX:
  1396. case CMD_XMIT_BCAST_CN:
  1397. case CMD_XMIT_BCAST_CX:
  1398. case CMD_ELS_REQUEST_CR:
  1399. case CMD_ELS_REQUEST_CX:
  1400. case CMD_CREATE_XRI_CR:
  1401. case CMD_CREATE_XRI_CX:
  1402. case CMD_GET_RPI_CN:
  1403. case CMD_XMIT_ELS_RSP_CX:
  1404. case CMD_GET_RPI_CR:
  1405. case CMD_FCP_IWRITE_CR:
  1406. case CMD_FCP_IWRITE_CX:
  1407. case CMD_FCP_IREAD_CR:
  1408. case CMD_FCP_IREAD_CX:
  1409. case CMD_FCP_ICMND_CR:
  1410. case CMD_FCP_ICMND_CX:
  1411. case CMD_FCP_TSEND_CX:
  1412. case CMD_FCP_TRSP_CX:
  1413. case CMD_FCP_TRECEIVE_CX:
  1414. case CMD_FCP_AUTO_TRSP_CX:
  1415. case CMD_ADAPTER_MSG:
  1416. case CMD_ADAPTER_DUMP:
  1417. case CMD_XMIT_SEQUENCE64_CR:
  1418. case CMD_XMIT_SEQUENCE64_CX:
  1419. case CMD_XMIT_BCAST64_CN:
  1420. case CMD_XMIT_BCAST64_CX:
  1421. case CMD_ELS_REQUEST64_CR:
  1422. case CMD_ELS_REQUEST64_CX:
  1423. case CMD_FCP_IWRITE64_CR:
  1424. case CMD_FCP_IWRITE64_CX:
  1425. case CMD_FCP_IREAD64_CR:
  1426. case CMD_FCP_IREAD64_CX:
  1427. case CMD_FCP_ICMND64_CR:
  1428. case CMD_FCP_ICMND64_CX:
  1429. case CMD_FCP_TSEND64_CX:
  1430. case CMD_FCP_TRSP64_CX:
  1431. case CMD_FCP_TRECEIVE64_CX:
  1432. case CMD_GEN_REQUEST64_CR:
  1433. case CMD_GEN_REQUEST64_CX:
  1434. case CMD_XMIT_ELS_RSP64_CX:
  1435. case DSSCMD_IWRITE64_CR:
  1436. case DSSCMD_IWRITE64_CX:
  1437. case DSSCMD_IREAD64_CR:
  1438. case DSSCMD_IREAD64_CX:
  1439. case CMD_SEND_FRAME:
  1440. type = LPFC_SOL_IOCB;
  1441. break;
  1442. case CMD_ABORT_XRI_CN:
  1443. case CMD_ABORT_XRI_CX:
  1444. case CMD_CLOSE_XRI_CN:
  1445. case CMD_CLOSE_XRI_CX:
  1446. case CMD_XRI_ABORTED_CX:
  1447. case CMD_ABORT_MXRI64_CN:
  1448. case CMD_XMIT_BLS_RSP64_CX:
  1449. type = LPFC_ABORT_IOCB;
  1450. break;
  1451. case CMD_RCV_SEQUENCE_CX:
  1452. case CMD_RCV_ELS_REQ_CX:
  1453. case CMD_RCV_SEQUENCE64_CX:
  1454. case CMD_RCV_ELS_REQ64_CX:
  1455. case CMD_ASYNC_STATUS:
  1456. case CMD_IOCB_RCV_SEQ64_CX:
  1457. case CMD_IOCB_RCV_ELS64_CX:
  1458. case CMD_IOCB_RCV_CONT64_CX:
  1459. case CMD_IOCB_RET_XRI64_CX:
  1460. type = LPFC_UNSOL_IOCB;
  1461. break;
  1462. case CMD_IOCB_XMIT_MSEQ64_CR:
  1463. case CMD_IOCB_XMIT_MSEQ64_CX:
  1464. case CMD_IOCB_RCV_SEQ_LIST64_CX:
  1465. case CMD_IOCB_RCV_ELS_LIST64_CX:
  1466. case CMD_IOCB_CLOSE_EXTENDED_CN:
  1467. case CMD_IOCB_ABORT_EXTENDED_CN:
  1468. case CMD_IOCB_RET_HBQE64_CN:
  1469. case CMD_IOCB_FCP_IBIDIR64_CR:
  1470. case CMD_IOCB_FCP_IBIDIR64_CX:
  1471. case CMD_IOCB_FCP_ITASKMGT64_CX:
  1472. case CMD_IOCB_LOGENTRY_CN:
  1473. case CMD_IOCB_LOGENTRY_ASYNC_CN:
  1474. printk("%s - Unhandled SLI-3 Command x%x\n",
  1475. __func__, iocb_cmnd);
  1476. type = LPFC_UNKNOWN_IOCB;
  1477. break;
  1478. default:
  1479. type = LPFC_UNKNOWN_IOCB;
  1480. break;
  1481. }
  1482. return type;
  1483. }
  1484. /**
  1485. * lpfc_sli_ring_map - Issue config_ring mbox for all rings
  1486. * @phba: Pointer to HBA context object.
  1487. *
  1488. * This function is called from SLI initialization code
  1489. * to configure every ring of the HBA's SLI interface. The
  1490. * caller is not required to hold any lock. This function issues
  1491. * a config_ring mailbox command for each ring.
  1492. * This function returns zero if successful else returns a negative
  1493. * error code.
  1494. **/
  1495. static int
  1496. lpfc_sli_ring_map(struct lpfc_hba *phba)
  1497. {
  1498. struct lpfc_sli *psli = &phba->sli;
  1499. LPFC_MBOXQ_t *pmb;
  1500. MAILBOX_t *pmbox;
  1501. int i, rc, ret = 0;
  1502. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1503. if (!pmb)
  1504. return -ENOMEM;
  1505. pmbox = &pmb->u.mb;
  1506. phba->link_state = LPFC_INIT_MBX_CMDS;
  1507. for (i = 0; i < psli->num_rings; i++) {
  1508. lpfc_config_ring(phba, i, pmb);
  1509. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  1510. if (rc != MBX_SUCCESS) {
  1511. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1512. "0446 Adapter failed to init (%d), "
  1513. "mbxCmd x%x CFG_RING, mbxStatus x%x, "
  1514. "ring %d\n",
  1515. rc, pmbox->mbxCommand,
  1516. pmbox->mbxStatus, i);
  1517. phba->link_state = LPFC_HBA_ERROR;
  1518. ret = -ENXIO;
  1519. break;
  1520. }
  1521. }
  1522. mempool_free(pmb, phba->mbox_mem_pool);
  1523. return ret;
  1524. }
  1525. /**
  1526. * lpfc_sli_ringtxcmpl_put - Adds new iocb to the txcmplq
  1527. * @phba: Pointer to HBA context object.
  1528. * @pring: Pointer to driver SLI ring object.
  1529. * @piocb: Pointer to the driver iocb object.
  1530. *
  1531. * The driver calls this function with the hbalock held for SLI3 ports or
  1532. * the ring lock held for SLI4 ports. The function adds the
  1533. * new iocb to txcmplq of the given ring. This function always returns
  1534. * 0. If this function is called for ELS ring, this function checks if
  1535. * there is a vport associated with the ELS command. This function also
  1536. * starts els_tmofunc timer if this is an ELS command.
  1537. **/
  1538. static int
  1539. lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1540. struct lpfc_iocbq *piocb)
  1541. {
  1542. u32 ulp_command = 0;
  1543. BUG_ON(!piocb);
  1544. ulp_command = get_job_cmnd(phba, piocb);
  1545. list_add_tail(&piocb->list, &pring->txcmplq);
  1546. piocb->cmd_flag |= LPFC_IO_ON_TXCMPLQ;
  1547. pring->txcmplq_cnt++;
  1548. if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
  1549. (ulp_command != CMD_ABORT_XRI_WQE) &&
  1550. (ulp_command != CMD_ABORT_XRI_CN) &&
  1551. (ulp_command != CMD_CLOSE_XRI_CN)) {
  1552. BUG_ON(!piocb->vport);
  1553. if (!(piocb->vport->load_flag & FC_UNLOADING))
  1554. mod_timer(&piocb->vport->els_tmofunc,
  1555. jiffies +
  1556. msecs_to_jiffies(1000 * (phba->fc_ratov << 1)));
  1557. }
  1558. return 0;
  1559. }
  1560. /**
  1561. * lpfc_sli_ringtx_get - Get first element of the txq
  1562. * @phba: Pointer to HBA context object.
  1563. * @pring: Pointer to driver SLI ring object.
  1564. *
  1565. * This function is called with hbalock held to get next
  1566. * iocb in txq of the given ring. If there is any iocb in
  1567. * the txq, the function returns first iocb in the list after
  1568. * removing the iocb from the list, else it returns NULL.
  1569. **/
  1570. struct lpfc_iocbq *
  1571. lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1572. {
  1573. struct lpfc_iocbq *cmd_iocb;
  1574. lockdep_assert_held(&phba->hbalock);
  1575. list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
  1576. return cmd_iocb;
  1577. }
  1578. /**
  1579. * lpfc_cmf_sync_cmpl - Process a CMF_SYNC_WQE cmpl
  1580. * @phba: Pointer to HBA context object.
  1581. * @cmdiocb: Pointer to driver command iocb object.
  1582. * @rspiocb: Pointer to driver response iocb object.
  1583. *
  1584. * This routine will inform the driver of any BW adjustments we need
  1585. * to make. These changes will be picked up during the next CMF
  1586. * timer interrupt. In addition, any BW changes will be logged
  1587. * with LOG_CGN_MGMT.
  1588. **/
  1589. static void
  1590. lpfc_cmf_sync_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1591. struct lpfc_iocbq *rspiocb)
  1592. {
  1593. union lpfc_wqe128 *wqe;
  1594. uint32_t status, info;
  1595. struct lpfc_wcqe_complete *wcqe = &rspiocb->wcqe_cmpl;
  1596. uint64_t bw, bwdif, slop;
  1597. uint64_t pcent, bwpcent;
  1598. int asig, afpin, sigcnt, fpincnt;
  1599. int wsigmax, wfpinmax, cg, tdp;
  1600. char *s;
  1601. /* First check for error */
  1602. status = bf_get(lpfc_wcqe_c_status, wcqe);
  1603. if (status) {
  1604. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1605. "6211 CMF_SYNC_WQE Error "
  1606. "req_tag x%x status x%x hwstatus x%x "
  1607. "tdatap x%x parm x%x\n",
  1608. bf_get(lpfc_wcqe_c_request_tag, wcqe),
  1609. bf_get(lpfc_wcqe_c_status, wcqe),
  1610. bf_get(lpfc_wcqe_c_hw_status, wcqe),
  1611. wcqe->total_data_placed,
  1612. wcqe->parameter);
  1613. goto out;
  1614. }
  1615. /* Gather congestion information on a successful cmpl */
  1616. info = wcqe->parameter;
  1617. phba->cmf_active_info = info;
  1618. /* See if firmware info count is valid or has changed */
  1619. if (info > LPFC_MAX_CMF_INFO || phba->cmf_info_per_interval == info)
  1620. info = 0;
  1621. else
  1622. phba->cmf_info_per_interval = info;
  1623. tdp = bf_get(lpfc_wcqe_c_cmf_bw, wcqe);
  1624. cg = bf_get(lpfc_wcqe_c_cmf_cg, wcqe);
  1625. /* Get BW requirement from firmware */
  1626. bw = (uint64_t)tdp * LPFC_CMF_BLK_SIZE;
  1627. if (!bw) {
  1628. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1629. "6212 CMF_SYNC_WQE x%x: NULL bw\n",
  1630. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  1631. goto out;
  1632. }
  1633. /* Gather information needed for logging if a BW change is required */
  1634. wqe = &cmdiocb->wqe;
  1635. asig = bf_get(cmf_sync_asig, &wqe->cmf_sync);
  1636. afpin = bf_get(cmf_sync_afpin, &wqe->cmf_sync);
  1637. fpincnt = bf_get(cmf_sync_wfpincnt, &wqe->cmf_sync);
  1638. sigcnt = bf_get(cmf_sync_wsigcnt, &wqe->cmf_sync);
  1639. if (phba->cmf_max_bytes_per_interval != bw ||
  1640. (asig || afpin || sigcnt || fpincnt)) {
  1641. /* Are we increasing or decreasing BW */
  1642. if (phba->cmf_max_bytes_per_interval < bw) {
  1643. bwdif = bw - phba->cmf_max_bytes_per_interval;
  1644. s = "Increase";
  1645. } else {
  1646. bwdif = phba->cmf_max_bytes_per_interval - bw;
  1647. s = "Decrease";
  1648. }
  1649. /* What is the change percentage */
  1650. slop = div_u64(phba->cmf_link_byte_count, 200); /*For rounding*/
  1651. pcent = div64_u64(bwdif * 100 + slop,
  1652. phba->cmf_link_byte_count);
  1653. bwpcent = div64_u64(bw * 100 + slop,
  1654. phba->cmf_link_byte_count);
  1655. if (asig) {
  1656. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1657. "6237 BW Threshold %lld%% (%lld): "
  1658. "%lld%% %s: Signal Alarm: cg:%d "
  1659. "Info:%u\n",
  1660. bwpcent, bw, pcent, s, cg,
  1661. phba->cmf_active_info);
  1662. } else if (afpin) {
  1663. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1664. "6238 BW Threshold %lld%% (%lld): "
  1665. "%lld%% %s: FPIN Alarm: cg:%d "
  1666. "Info:%u\n",
  1667. bwpcent, bw, pcent, s, cg,
  1668. phba->cmf_active_info);
  1669. } else if (sigcnt) {
  1670. wsigmax = bf_get(cmf_sync_wsigmax, &wqe->cmf_sync);
  1671. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1672. "6239 BW Threshold %lld%% (%lld): "
  1673. "%lld%% %s: Signal Warning: "
  1674. "Cnt %d Max %d: cg:%d Info:%u\n",
  1675. bwpcent, bw, pcent, s, sigcnt,
  1676. wsigmax, cg, phba->cmf_active_info);
  1677. } else if (fpincnt) {
  1678. wfpinmax = bf_get(cmf_sync_wfpinmax, &wqe->cmf_sync);
  1679. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1680. "6240 BW Threshold %lld%% (%lld): "
  1681. "%lld%% %s: FPIN Warning: "
  1682. "Cnt %d Max %d: cg:%d Info:%u\n",
  1683. bwpcent, bw, pcent, s, fpincnt,
  1684. wfpinmax, cg, phba->cmf_active_info);
  1685. } else {
  1686. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1687. "6241 BW Threshold %lld%% (%lld): "
  1688. "CMF %lld%% %s: cg:%d Info:%u\n",
  1689. bwpcent, bw, pcent, s, cg,
  1690. phba->cmf_active_info);
  1691. }
  1692. } else if (info) {
  1693. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1694. "6246 Info Threshold %u\n", info);
  1695. }
  1696. /* Save BW change to be picked up during next timer interrupt */
  1697. phba->cmf_last_sync_bw = bw;
  1698. out:
  1699. lpfc_sli_release_iocbq(phba, cmdiocb);
  1700. }
  1701. /**
  1702. * lpfc_issue_cmf_sync_wqe - Issue a CMF_SYNC_WQE
  1703. * @phba: Pointer to HBA context object.
  1704. * @ms: ms to set in WQE interval, 0 means use init op
  1705. * @total: Total rcv bytes for this interval
  1706. *
  1707. * This routine is called every CMF timer interrupt. Its purpose is
  1708. * to issue a CMF_SYNC_WQE to the firmware to inform it of any events
  1709. * that may indicate we have congestion (FPINs or Signals). Upon
  1710. * completion, the firmware will indicate any BW restrictions the
  1711. * driver may need to take.
  1712. **/
  1713. int
  1714. lpfc_issue_cmf_sync_wqe(struct lpfc_hba *phba, u32 ms, u64 total)
  1715. {
  1716. union lpfc_wqe128 *wqe;
  1717. struct lpfc_iocbq *sync_buf;
  1718. unsigned long iflags;
  1719. u32 ret_val;
  1720. u32 atot, wtot, max;
  1721. u16 warn_sync_period = 0;
  1722. /* First address any alarm / warning activity */
  1723. atot = atomic_xchg(&phba->cgn_sync_alarm_cnt, 0);
  1724. wtot = atomic_xchg(&phba->cgn_sync_warn_cnt, 0);
  1725. /* ONLY Managed mode will send the CMF_SYNC_WQE to the HBA */
  1726. if (phba->cmf_active_mode != LPFC_CFG_MANAGED ||
  1727. phba->link_state == LPFC_LINK_DOWN)
  1728. return 0;
  1729. spin_lock_irqsave(&phba->hbalock, iflags);
  1730. sync_buf = __lpfc_sli_get_iocbq(phba);
  1731. if (!sync_buf) {
  1732. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT,
  1733. "6244 No available WQEs for CMF_SYNC_WQE\n");
  1734. ret_val = ENOMEM;
  1735. goto out_unlock;
  1736. }
  1737. wqe = &sync_buf->wqe;
  1738. /* WQEs are reused. Clear stale data and set key fields to zero */
  1739. memset(wqe, 0, sizeof(*wqe));
  1740. /* If this is the very first CMF_SYNC_WQE, issue an init operation */
  1741. if (!ms) {
  1742. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1743. "6441 CMF Init %d - CMF_SYNC_WQE\n",
  1744. phba->fc_eventTag);
  1745. bf_set(cmf_sync_op, &wqe->cmf_sync, 1); /* 1=init */
  1746. bf_set(cmf_sync_interval, &wqe->cmf_sync, LPFC_CMF_INTERVAL);
  1747. goto initpath;
  1748. }
  1749. bf_set(cmf_sync_op, &wqe->cmf_sync, 0); /* 0=recalc */
  1750. bf_set(cmf_sync_interval, &wqe->cmf_sync, ms);
  1751. /* Check for alarms / warnings */
  1752. if (atot) {
  1753. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
  1754. /* We hit an Signal alarm condition */
  1755. bf_set(cmf_sync_asig, &wqe->cmf_sync, 1);
  1756. } else {
  1757. /* We hit a FPIN alarm condition */
  1758. bf_set(cmf_sync_afpin, &wqe->cmf_sync, 1);
  1759. }
  1760. } else if (wtot) {
  1761. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY ||
  1762. phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
  1763. /* We hit an Signal warning condition */
  1764. max = LPFC_SEC_TO_MSEC / lpfc_fabric_cgn_frequency *
  1765. lpfc_acqe_cgn_frequency;
  1766. bf_set(cmf_sync_wsigmax, &wqe->cmf_sync, max);
  1767. bf_set(cmf_sync_wsigcnt, &wqe->cmf_sync, wtot);
  1768. warn_sync_period = lpfc_acqe_cgn_frequency;
  1769. } else {
  1770. /* We hit a FPIN warning condition */
  1771. bf_set(cmf_sync_wfpinmax, &wqe->cmf_sync, 1);
  1772. bf_set(cmf_sync_wfpincnt, &wqe->cmf_sync, 1);
  1773. if (phba->cgn_fpin_frequency != LPFC_FPIN_INIT_FREQ)
  1774. warn_sync_period =
  1775. LPFC_MSECS_TO_SECS(phba->cgn_fpin_frequency);
  1776. }
  1777. }
  1778. /* Update total read blocks during previous timer interval */
  1779. wqe->cmf_sync.read_bytes = (u32)(total / LPFC_CMF_BLK_SIZE);
  1780. initpath:
  1781. bf_set(cmf_sync_ver, &wqe->cmf_sync, LPFC_CMF_SYNC_VER);
  1782. wqe->cmf_sync.event_tag = phba->fc_eventTag;
  1783. bf_set(cmf_sync_cmnd, &wqe->cmf_sync, CMD_CMF_SYNC_WQE);
  1784. /* Setup reqtag to match the wqe completion. */
  1785. bf_set(cmf_sync_reqtag, &wqe->cmf_sync, sync_buf->iotag);
  1786. bf_set(cmf_sync_qosd, &wqe->cmf_sync, 1);
  1787. bf_set(cmf_sync_period, &wqe->cmf_sync, warn_sync_period);
  1788. bf_set(cmf_sync_cmd_type, &wqe->cmf_sync, CMF_SYNC_COMMAND);
  1789. bf_set(cmf_sync_wqec, &wqe->cmf_sync, 1);
  1790. bf_set(cmf_sync_cqid, &wqe->cmf_sync, LPFC_WQE_CQ_ID_DEFAULT);
  1791. sync_buf->vport = phba->pport;
  1792. sync_buf->cmd_cmpl = lpfc_cmf_sync_cmpl;
  1793. sync_buf->cmd_dmabuf = NULL;
  1794. sync_buf->rsp_dmabuf = NULL;
  1795. sync_buf->bpl_dmabuf = NULL;
  1796. sync_buf->sli4_xritag = NO_XRI;
  1797. sync_buf->cmd_flag |= LPFC_IO_CMF;
  1798. ret_val = lpfc_sli4_issue_wqe(phba, &phba->sli4_hba.hdwq[0], sync_buf);
  1799. if (ret_val) {
  1800. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  1801. "6214 Cannot issue CMF_SYNC_WQE: x%x\n",
  1802. ret_val);
  1803. __lpfc_sli_release_iocbq(phba, sync_buf);
  1804. }
  1805. out_unlock:
  1806. spin_unlock_irqrestore(&phba->hbalock, iflags);
  1807. return ret_val;
  1808. }
  1809. /**
  1810. * lpfc_sli_next_iocb_slot - Get next iocb slot in the ring
  1811. * @phba: Pointer to HBA context object.
  1812. * @pring: Pointer to driver SLI ring object.
  1813. *
  1814. * This function is called with hbalock held and the caller must post the
  1815. * iocb without releasing the lock. If the caller releases the lock,
  1816. * iocb slot returned by the function is not guaranteed to be available.
  1817. * The function returns pointer to the next available iocb slot if there
  1818. * is available slot in the ring, else it returns NULL.
  1819. * If the get index of the ring is ahead of the put index, the function
  1820. * will post an error attention event to the worker thread to take the
  1821. * HBA to offline state.
  1822. **/
  1823. static IOCB_t *
  1824. lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1825. {
  1826. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  1827. uint32_t max_cmd_idx = pring->sli.sli3.numCiocb;
  1828. lockdep_assert_held(&phba->hbalock);
  1829. if ((pring->sli.sli3.next_cmdidx == pring->sli.sli3.cmdidx) &&
  1830. (++pring->sli.sli3.next_cmdidx >= max_cmd_idx))
  1831. pring->sli.sli3.next_cmdidx = 0;
  1832. if (unlikely(pring->sli.sli3.local_getidx ==
  1833. pring->sli.sli3.next_cmdidx)) {
  1834. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  1835. if (unlikely(pring->sli.sli3.local_getidx >= max_cmd_idx)) {
  1836. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  1837. "0315 Ring %d issue: portCmdGet %d "
  1838. "is bigger than cmd ring %d\n",
  1839. pring->ringno,
  1840. pring->sli.sli3.local_getidx,
  1841. max_cmd_idx);
  1842. phba->link_state = LPFC_HBA_ERROR;
  1843. /*
  1844. * All error attention handlers are posted to
  1845. * worker thread
  1846. */
  1847. phba->work_ha |= HA_ERATT;
  1848. phba->work_hs = HS_FFER3;
  1849. lpfc_worker_wake_up(phba);
  1850. return NULL;
  1851. }
  1852. if (pring->sli.sli3.local_getidx == pring->sli.sli3.next_cmdidx)
  1853. return NULL;
  1854. }
  1855. return lpfc_cmd_iocb(phba, pring);
  1856. }
  1857. /**
  1858. * lpfc_sli_next_iotag - Get an iotag for the iocb
  1859. * @phba: Pointer to HBA context object.
  1860. * @iocbq: Pointer to driver iocb object.
  1861. *
  1862. * This function gets an iotag for the iocb. If there is no unused iotag and
  1863. * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
  1864. * array and assigns a new iotag.
  1865. * The function returns the allocated iotag if successful, else returns zero.
  1866. * Zero is not a valid iotag.
  1867. * The caller is not required to hold any lock.
  1868. **/
  1869. uint16_t
  1870. lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
  1871. {
  1872. struct lpfc_iocbq **new_arr;
  1873. struct lpfc_iocbq **old_arr;
  1874. size_t new_len;
  1875. struct lpfc_sli *psli = &phba->sli;
  1876. uint16_t iotag;
  1877. spin_lock_irq(&phba->hbalock);
  1878. iotag = psli->last_iotag;
  1879. if(++iotag < psli->iocbq_lookup_len) {
  1880. psli->last_iotag = iotag;
  1881. psli->iocbq_lookup[iotag] = iocbq;
  1882. spin_unlock_irq(&phba->hbalock);
  1883. iocbq->iotag = iotag;
  1884. return iotag;
  1885. } else if (psli->iocbq_lookup_len < (0xffff
  1886. - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
  1887. new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
  1888. spin_unlock_irq(&phba->hbalock);
  1889. new_arr = kcalloc(new_len, sizeof(struct lpfc_iocbq *),
  1890. GFP_KERNEL);
  1891. if (new_arr) {
  1892. spin_lock_irq(&phba->hbalock);
  1893. old_arr = psli->iocbq_lookup;
  1894. if (new_len <= psli->iocbq_lookup_len) {
  1895. /* highly unprobable case */
  1896. kfree(new_arr);
  1897. iotag = psli->last_iotag;
  1898. if(++iotag < psli->iocbq_lookup_len) {
  1899. psli->last_iotag = iotag;
  1900. psli->iocbq_lookup[iotag] = iocbq;
  1901. spin_unlock_irq(&phba->hbalock);
  1902. iocbq->iotag = iotag;
  1903. return iotag;
  1904. }
  1905. spin_unlock_irq(&phba->hbalock);
  1906. return 0;
  1907. }
  1908. if (psli->iocbq_lookup)
  1909. memcpy(new_arr, old_arr,
  1910. ((psli->last_iotag + 1) *
  1911. sizeof (struct lpfc_iocbq *)));
  1912. psli->iocbq_lookup = new_arr;
  1913. psli->iocbq_lookup_len = new_len;
  1914. psli->last_iotag = iotag;
  1915. psli->iocbq_lookup[iotag] = iocbq;
  1916. spin_unlock_irq(&phba->hbalock);
  1917. iocbq->iotag = iotag;
  1918. kfree(old_arr);
  1919. return iotag;
  1920. }
  1921. } else
  1922. spin_unlock_irq(&phba->hbalock);
  1923. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  1924. "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
  1925. psli->last_iotag);
  1926. return 0;
  1927. }
  1928. /**
  1929. * lpfc_sli_submit_iocb - Submit an iocb to the firmware
  1930. * @phba: Pointer to HBA context object.
  1931. * @pring: Pointer to driver SLI ring object.
  1932. * @iocb: Pointer to iocb slot in the ring.
  1933. * @nextiocb: Pointer to driver iocb object which need to be
  1934. * posted to firmware.
  1935. *
  1936. * This function is called to post a new iocb to the firmware. This
  1937. * function copies the new iocb to ring iocb slot and updates the
  1938. * ring pointers. It adds the new iocb to txcmplq if there is
  1939. * a completion call back for this iocb else the function will free the
  1940. * iocb object. The hbalock is asserted held in the code path calling
  1941. * this routine.
  1942. **/
  1943. static void
  1944. lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  1945. IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
  1946. {
  1947. /*
  1948. * Set up an iotag
  1949. */
  1950. nextiocb->iocb.ulpIoTag = (nextiocb->cmd_cmpl) ? nextiocb->iotag : 0;
  1951. if (pring->ringno == LPFC_ELS_RING) {
  1952. lpfc_debugfs_slow_ring_trc(phba,
  1953. "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  1954. *(((uint32_t *) &nextiocb->iocb) + 4),
  1955. *(((uint32_t *) &nextiocb->iocb) + 6),
  1956. *(((uint32_t *) &nextiocb->iocb) + 7));
  1957. }
  1958. /*
  1959. * Issue iocb command to adapter
  1960. */
  1961. lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
  1962. wmb();
  1963. pring->stats.iocb_cmd++;
  1964. /*
  1965. * If there is no completion routine to call, we can release the
  1966. * IOCB buffer back right now. For IOCBs, like QUE_RING_BUF,
  1967. * that have no rsp ring completion, cmd_cmpl MUST be NULL.
  1968. */
  1969. if (nextiocb->cmd_cmpl)
  1970. lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
  1971. else
  1972. __lpfc_sli_release_iocbq(phba, nextiocb);
  1973. /*
  1974. * Let the HBA know what IOCB slot will be the next one the
  1975. * driver will put a command into.
  1976. */
  1977. pring->sli.sli3.cmdidx = pring->sli.sli3.next_cmdidx;
  1978. writel(pring->sli.sli3.cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
  1979. }
  1980. /**
  1981. * lpfc_sli_update_full_ring - Update the chip attention register
  1982. * @phba: Pointer to HBA context object.
  1983. * @pring: Pointer to driver SLI ring object.
  1984. *
  1985. * The caller is not required to hold any lock for calling this function.
  1986. * This function updates the chip attention bits for the ring to inform firmware
  1987. * that there are pending work to be done for this ring and requests an
  1988. * interrupt when there is space available in the ring. This function is
  1989. * called when the driver is unable to post more iocbs to the ring due
  1990. * to unavailability of space in the ring.
  1991. **/
  1992. static void
  1993. lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  1994. {
  1995. int ringno = pring->ringno;
  1996. pring->flag |= LPFC_CALL_RING_AVAILABLE;
  1997. wmb();
  1998. /*
  1999. * Set ring 'ringno' to SET R0CE_REQ in Chip Att register.
  2000. * The HBA will tell us when an IOCB entry is available.
  2001. */
  2002. writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
  2003. readl(phba->CAregaddr); /* flush */
  2004. pring->stats.iocb_cmd_full++;
  2005. }
  2006. /**
  2007. * lpfc_sli_update_ring - Update chip attention register
  2008. * @phba: Pointer to HBA context object.
  2009. * @pring: Pointer to driver SLI ring object.
  2010. *
  2011. * This function updates the chip attention register bit for the
  2012. * given ring to inform HBA that there is more work to be done
  2013. * in this ring. The caller is not required to hold any lock.
  2014. **/
  2015. static void
  2016. lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2017. {
  2018. int ringno = pring->ringno;
  2019. /*
  2020. * Tell the HBA that there is work to do in this ring.
  2021. */
  2022. if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
  2023. wmb();
  2024. writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
  2025. readl(phba->CAregaddr); /* flush */
  2026. }
  2027. }
  2028. /**
  2029. * lpfc_sli_resume_iocb - Process iocbs in the txq
  2030. * @phba: Pointer to HBA context object.
  2031. * @pring: Pointer to driver SLI ring object.
  2032. *
  2033. * This function is called with hbalock held to post pending iocbs
  2034. * in the txq to the firmware. This function is called when driver
  2035. * detects space available in the ring.
  2036. **/
  2037. static void
  2038. lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  2039. {
  2040. IOCB_t *iocb;
  2041. struct lpfc_iocbq *nextiocb;
  2042. lockdep_assert_held(&phba->hbalock);
  2043. /*
  2044. * Check to see if:
  2045. * (a) there is anything on the txq to send
  2046. * (b) link is up
  2047. * (c) link attention events can be processed (fcp ring only)
  2048. * (d) IOCB processing is not blocked by the outstanding mbox command.
  2049. */
  2050. if (lpfc_is_link_up(phba) &&
  2051. (!list_empty(&pring->txq)) &&
  2052. (pring->ringno != LPFC_FCP_RING ||
  2053. phba->sli.sli_flag & LPFC_PROCESS_LA)) {
  2054. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  2055. (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
  2056. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  2057. if (iocb)
  2058. lpfc_sli_update_ring(phba, pring);
  2059. else
  2060. lpfc_sli_update_full_ring(phba, pring);
  2061. }
  2062. return;
  2063. }
  2064. /**
  2065. * lpfc_sli_next_hbq_slot - Get next hbq entry for the HBQ
  2066. * @phba: Pointer to HBA context object.
  2067. * @hbqno: HBQ number.
  2068. *
  2069. * This function is called with hbalock held to get the next
  2070. * available slot for the given HBQ. If there is free slot
  2071. * available for the HBQ it will return pointer to the next available
  2072. * HBQ entry else it will return NULL.
  2073. **/
  2074. static struct lpfc_hbq_entry *
  2075. lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
  2076. {
  2077. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  2078. lockdep_assert_held(&phba->hbalock);
  2079. if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
  2080. ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
  2081. hbqp->next_hbqPutIdx = 0;
  2082. if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
  2083. uint32_t raw_index = phba->hbq_get[hbqno];
  2084. uint32_t getidx = le32_to_cpu(raw_index);
  2085. hbqp->local_hbqGetIdx = getidx;
  2086. if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
  2087. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2088. "1802 HBQ %d: local_hbqGetIdx "
  2089. "%u is > than hbqp->entry_count %u\n",
  2090. hbqno, hbqp->local_hbqGetIdx,
  2091. hbqp->entry_count);
  2092. phba->link_state = LPFC_HBA_ERROR;
  2093. return NULL;
  2094. }
  2095. if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
  2096. return NULL;
  2097. }
  2098. return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
  2099. hbqp->hbqPutIdx;
  2100. }
  2101. /**
  2102. * lpfc_sli_hbqbuf_free_all - Free all the hbq buffers
  2103. * @phba: Pointer to HBA context object.
  2104. *
  2105. * This function is called with no lock held to free all the
  2106. * hbq buffers while uninitializing the SLI interface. It also
  2107. * frees the HBQ buffers returned by the firmware but not yet
  2108. * processed by the upper layers.
  2109. **/
  2110. void
  2111. lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
  2112. {
  2113. struct lpfc_dmabuf *dmabuf, *next_dmabuf;
  2114. struct hbq_dmabuf *hbq_buf;
  2115. unsigned long flags;
  2116. int i, hbq_count;
  2117. hbq_count = lpfc_sli_hbq_count();
  2118. /* Return all memory used by all HBQs */
  2119. spin_lock_irqsave(&phba->hbalock, flags);
  2120. for (i = 0; i < hbq_count; ++i) {
  2121. list_for_each_entry_safe(dmabuf, next_dmabuf,
  2122. &phba->hbqs[i].hbq_buffer_list, list) {
  2123. hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
  2124. list_del(&hbq_buf->dbuf.list);
  2125. (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
  2126. }
  2127. phba->hbqs[i].buffer_count = 0;
  2128. }
  2129. /* Mark the HBQs not in use */
  2130. phba->hbq_in_use = 0;
  2131. spin_unlock_irqrestore(&phba->hbalock, flags);
  2132. }
  2133. /**
  2134. * lpfc_sli_hbq_to_firmware - Post the hbq buffer to firmware
  2135. * @phba: Pointer to HBA context object.
  2136. * @hbqno: HBQ number.
  2137. * @hbq_buf: Pointer to HBQ buffer.
  2138. *
  2139. * This function is called with the hbalock held to post a
  2140. * hbq buffer to the firmware. If the function finds an empty
  2141. * slot in the HBQ, it will post the buffer. The function will return
  2142. * pointer to the hbq entry if it successfully post the buffer
  2143. * else it will return NULL.
  2144. **/
  2145. static int
  2146. lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
  2147. struct hbq_dmabuf *hbq_buf)
  2148. {
  2149. lockdep_assert_held(&phba->hbalock);
  2150. return phba->lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf);
  2151. }
  2152. /**
  2153. * lpfc_sli_hbq_to_firmware_s3 - Post the hbq buffer to SLI3 firmware
  2154. * @phba: Pointer to HBA context object.
  2155. * @hbqno: HBQ number.
  2156. * @hbq_buf: Pointer to HBQ buffer.
  2157. *
  2158. * This function is called with the hbalock held to post a hbq buffer to the
  2159. * firmware. If the function finds an empty slot in the HBQ, it will post the
  2160. * buffer and place it on the hbq_buffer_list. The function will return zero if
  2161. * it successfully post the buffer else it will return an error.
  2162. **/
  2163. static int
  2164. lpfc_sli_hbq_to_firmware_s3(struct lpfc_hba *phba, uint32_t hbqno,
  2165. struct hbq_dmabuf *hbq_buf)
  2166. {
  2167. struct lpfc_hbq_entry *hbqe;
  2168. dma_addr_t physaddr = hbq_buf->dbuf.phys;
  2169. lockdep_assert_held(&phba->hbalock);
  2170. /* Get next HBQ entry slot to use */
  2171. hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
  2172. if (hbqe) {
  2173. struct hbq_s *hbqp = &phba->hbqs[hbqno];
  2174. hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
  2175. hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
  2176. hbqe->bde.tus.f.bdeSize = hbq_buf->total_size;
  2177. hbqe->bde.tus.f.bdeFlags = 0;
  2178. hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
  2179. hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
  2180. /* Sync SLIM */
  2181. hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
  2182. writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
  2183. /* flush */
  2184. readl(phba->hbq_put + hbqno);
  2185. list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
  2186. return 0;
  2187. } else
  2188. return -ENOMEM;
  2189. }
  2190. /**
  2191. * lpfc_sli_hbq_to_firmware_s4 - Post the hbq buffer to SLI4 firmware
  2192. * @phba: Pointer to HBA context object.
  2193. * @hbqno: HBQ number.
  2194. * @hbq_buf: Pointer to HBQ buffer.
  2195. *
  2196. * This function is called with the hbalock held to post an RQE to the SLI4
  2197. * firmware. If able to post the RQE to the RQ it will queue the hbq entry to
  2198. * the hbq_buffer_list and return zero, otherwise it will return an error.
  2199. **/
  2200. static int
  2201. lpfc_sli_hbq_to_firmware_s4(struct lpfc_hba *phba, uint32_t hbqno,
  2202. struct hbq_dmabuf *hbq_buf)
  2203. {
  2204. int rc;
  2205. struct lpfc_rqe hrqe;
  2206. struct lpfc_rqe drqe;
  2207. struct lpfc_queue *hrq;
  2208. struct lpfc_queue *drq;
  2209. if (hbqno != LPFC_ELS_HBQ)
  2210. return 1;
  2211. hrq = phba->sli4_hba.hdr_rq;
  2212. drq = phba->sli4_hba.dat_rq;
  2213. lockdep_assert_held(&phba->hbalock);
  2214. hrqe.address_lo = putPaddrLow(hbq_buf->hbuf.phys);
  2215. hrqe.address_hi = putPaddrHigh(hbq_buf->hbuf.phys);
  2216. drqe.address_lo = putPaddrLow(hbq_buf->dbuf.phys);
  2217. drqe.address_hi = putPaddrHigh(hbq_buf->dbuf.phys);
  2218. rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
  2219. if (rc < 0)
  2220. return rc;
  2221. hbq_buf->tag = (rc | (hbqno << 16));
  2222. list_add_tail(&hbq_buf->dbuf.list, &phba->hbqs[hbqno].hbq_buffer_list);
  2223. return 0;
  2224. }
  2225. /* HBQ for ELS and CT traffic. */
  2226. static struct lpfc_hbq_init lpfc_els_hbq = {
  2227. .rn = 1,
  2228. .entry_count = 256,
  2229. .mask_count = 0,
  2230. .profile = 0,
  2231. .ring_mask = (1 << LPFC_ELS_RING),
  2232. .buffer_count = 0,
  2233. .init_count = 40,
  2234. .add_count = 40,
  2235. };
  2236. /* Array of HBQs */
  2237. struct lpfc_hbq_init *lpfc_hbq_defs[] = {
  2238. &lpfc_els_hbq,
  2239. };
  2240. /**
  2241. * lpfc_sli_hbqbuf_fill_hbqs - Post more hbq buffers to HBQ
  2242. * @phba: Pointer to HBA context object.
  2243. * @hbqno: HBQ number.
  2244. * @count: Number of HBQ buffers to be posted.
  2245. *
  2246. * This function is called with no lock held to post more hbq buffers to the
  2247. * given HBQ. The function returns the number of HBQ buffers successfully
  2248. * posted.
  2249. **/
  2250. static int
  2251. lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
  2252. {
  2253. uint32_t i, posted = 0;
  2254. unsigned long flags;
  2255. struct hbq_dmabuf *hbq_buffer;
  2256. LIST_HEAD(hbq_buf_list);
  2257. if (!phba->hbqs[hbqno].hbq_alloc_buffer)
  2258. return 0;
  2259. if ((phba->hbqs[hbqno].buffer_count + count) >
  2260. lpfc_hbq_defs[hbqno]->entry_count)
  2261. count = lpfc_hbq_defs[hbqno]->entry_count -
  2262. phba->hbqs[hbqno].buffer_count;
  2263. if (!count)
  2264. return 0;
  2265. /* Allocate HBQ entries */
  2266. for (i = 0; i < count; i++) {
  2267. hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
  2268. if (!hbq_buffer)
  2269. break;
  2270. list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
  2271. }
  2272. /* Check whether HBQ is still in use */
  2273. spin_lock_irqsave(&phba->hbalock, flags);
  2274. if (!phba->hbq_in_use)
  2275. goto err;
  2276. while (!list_empty(&hbq_buf_list)) {
  2277. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  2278. dbuf.list);
  2279. hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
  2280. (hbqno << 16));
  2281. if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
  2282. phba->hbqs[hbqno].buffer_count++;
  2283. posted++;
  2284. } else
  2285. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  2286. }
  2287. spin_unlock_irqrestore(&phba->hbalock, flags);
  2288. return posted;
  2289. err:
  2290. spin_unlock_irqrestore(&phba->hbalock, flags);
  2291. while (!list_empty(&hbq_buf_list)) {
  2292. list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
  2293. dbuf.list);
  2294. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  2295. }
  2296. return 0;
  2297. }
  2298. /**
  2299. * lpfc_sli_hbqbuf_add_hbqs - Post more HBQ buffers to firmware
  2300. * @phba: Pointer to HBA context object.
  2301. * @qno: HBQ number.
  2302. *
  2303. * This function posts more buffers to the HBQ. This function
  2304. * is called with no lock held. The function returns the number of HBQ entries
  2305. * successfully allocated.
  2306. **/
  2307. int
  2308. lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
  2309. {
  2310. if (phba->sli_rev == LPFC_SLI_REV4)
  2311. return 0;
  2312. else
  2313. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  2314. lpfc_hbq_defs[qno]->add_count);
  2315. }
  2316. /**
  2317. * lpfc_sli_hbqbuf_init_hbqs - Post initial buffers to the HBQ
  2318. * @phba: Pointer to HBA context object.
  2319. * @qno: HBQ queue number.
  2320. *
  2321. * This function is called from SLI initialization code path with
  2322. * no lock held to post initial HBQ buffers to firmware. The
  2323. * function returns the number of HBQ entries successfully allocated.
  2324. **/
  2325. static int
  2326. lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
  2327. {
  2328. if (phba->sli_rev == LPFC_SLI_REV4)
  2329. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  2330. lpfc_hbq_defs[qno]->entry_count);
  2331. else
  2332. return lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
  2333. lpfc_hbq_defs[qno]->init_count);
  2334. }
  2335. /*
  2336. * lpfc_sli_hbqbuf_get - Remove the first hbq off of an hbq list
  2337. *
  2338. * This function removes the first hbq buffer on an hbq list and returns a
  2339. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  2340. **/
  2341. static struct hbq_dmabuf *
  2342. lpfc_sli_hbqbuf_get(struct list_head *rb_list)
  2343. {
  2344. struct lpfc_dmabuf *d_buf;
  2345. list_remove_head(rb_list, d_buf, struct lpfc_dmabuf, list);
  2346. if (!d_buf)
  2347. return NULL;
  2348. return container_of(d_buf, struct hbq_dmabuf, dbuf);
  2349. }
  2350. /**
  2351. * lpfc_sli_rqbuf_get - Remove the first dma buffer off of an RQ list
  2352. * @phba: Pointer to HBA context object.
  2353. * @hrq: HBQ number.
  2354. *
  2355. * This function removes the first RQ buffer on an RQ buffer list and returns a
  2356. * pointer to that buffer. If it finds no buffers on the list it returns NULL.
  2357. **/
  2358. static struct rqb_dmabuf *
  2359. lpfc_sli_rqbuf_get(struct lpfc_hba *phba, struct lpfc_queue *hrq)
  2360. {
  2361. struct lpfc_dmabuf *h_buf;
  2362. struct lpfc_rqb *rqbp;
  2363. rqbp = hrq->rqbp;
  2364. list_remove_head(&rqbp->rqb_buffer_list, h_buf,
  2365. struct lpfc_dmabuf, list);
  2366. if (!h_buf)
  2367. return NULL;
  2368. rqbp->buffer_count--;
  2369. return container_of(h_buf, struct rqb_dmabuf, hbuf);
  2370. }
  2371. /**
  2372. * lpfc_sli_hbqbuf_find - Find the hbq buffer associated with a tag
  2373. * @phba: Pointer to HBA context object.
  2374. * @tag: Tag of the hbq buffer.
  2375. *
  2376. * This function searches for the hbq buffer associated with the given tag in
  2377. * the hbq buffer list. If it finds the hbq buffer, it returns the hbq_buffer
  2378. * otherwise it returns NULL.
  2379. **/
  2380. static struct hbq_dmabuf *
  2381. lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
  2382. {
  2383. struct lpfc_dmabuf *d_buf;
  2384. struct hbq_dmabuf *hbq_buf;
  2385. uint32_t hbqno;
  2386. hbqno = tag >> 16;
  2387. if (hbqno >= LPFC_MAX_HBQS)
  2388. return NULL;
  2389. spin_lock_irq(&phba->hbalock);
  2390. list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
  2391. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  2392. if (hbq_buf->tag == tag) {
  2393. spin_unlock_irq(&phba->hbalock);
  2394. return hbq_buf;
  2395. }
  2396. }
  2397. spin_unlock_irq(&phba->hbalock);
  2398. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2399. "1803 Bad hbq tag. Data: x%x x%x\n",
  2400. tag, phba->hbqs[tag >> 16].buffer_count);
  2401. return NULL;
  2402. }
  2403. /**
  2404. * lpfc_sli_free_hbq - Give back the hbq buffer to firmware
  2405. * @phba: Pointer to HBA context object.
  2406. * @hbq_buffer: Pointer to HBQ buffer.
  2407. *
  2408. * This function is called with hbalock. This function gives back
  2409. * the hbq buffer to firmware. If the HBQ does not have space to
  2410. * post the buffer, it will free the buffer.
  2411. **/
  2412. void
  2413. lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
  2414. {
  2415. uint32_t hbqno;
  2416. if (hbq_buffer) {
  2417. hbqno = hbq_buffer->tag >> 16;
  2418. if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
  2419. (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
  2420. }
  2421. }
  2422. /**
  2423. * lpfc_sli_chk_mbx_command - Check if the mailbox is a legitimate mailbox
  2424. * @mbxCommand: mailbox command code.
  2425. *
  2426. * This function is called by the mailbox event handler function to verify
  2427. * that the completed mailbox command is a legitimate mailbox command. If the
  2428. * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
  2429. * and the mailbox event handler will take the HBA offline.
  2430. **/
  2431. static int
  2432. lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
  2433. {
  2434. uint8_t ret;
  2435. switch (mbxCommand) {
  2436. case MBX_LOAD_SM:
  2437. case MBX_READ_NV:
  2438. case MBX_WRITE_NV:
  2439. case MBX_WRITE_VPARMS:
  2440. case MBX_RUN_BIU_DIAG:
  2441. case MBX_INIT_LINK:
  2442. case MBX_DOWN_LINK:
  2443. case MBX_CONFIG_LINK:
  2444. case MBX_CONFIG_RING:
  2445. case MBX_RESET_RING:
  2446. case MBX_READ_CONFIG:
  2447. case MBX_READ_RCONFIG:
  2448. case MBX_READ_SPARM:
  2449. case MBX_READ_STATUS:
  2450. case MBX_READ_RPI:
  2451. case MBX_READ_XRI:
  2452. case MBX_READ_REV:
  2453. case MBX_READ_LNK_STAT:
  2454. case MBX_REG_LOGIN:
  2455. case MBX_UNREG_LOGIN:
  2456. case MBX_CLEAR_LA:
  2457. case MBX_DUMP_MEMORY:
  2458. case MBX_DUMP_CONTEXT:
  2459. case MBX_RUN_DIAGS:
  2460. case MBX_RESTART:
  2461. case MBX_UPDATE_CFG:
  2462. case MBX_DOWN_LOAD:
  2463. case MBX_DEL_LD_ENTRY:
  2464. case MBX_RUN_PROGRAM:
  2465. case MBX_SET_MASK:
  2466. case MBX_SET_VARIABLE:
  2467. case MBX_UNREG_D_ID:
  2468. case MBX_KILL_BOARD:
  2469. case MBX_CONFIG_FARP:
  2470. case MBX_BEACON:
  2471. case MBX_LOAD_AREA:
  2472. case MBX_RUN_BIU_DIAG64:
  2473. case MBX_CONFIG_PORT:
  2474. case MBX_READ_SPARM64:
  2475. case MBX_READ_RPI64:
  2476. case MBX_REG_LOGIN64:
  2477. case MBX_READ_TOPOLOGY:
  2478. case MBX_WRITE_WWN:
  2479. case MBX_SET_DEBUG:
  2480. case MBX_LOAD_EXP_ROM:
  2481. case MBX_ASYNCEVT_ENABLE:
  2482. case MBX_REG_VPI:
  2483. case MBX_UNREG_VPI:
  2484. case MBX_HEARTBEAT:
  2485. case MBX_PORT_CAPABILITIES:
  2486. case MBX_PORT_IOV_CONTROL:
  2487. case MBX_SLI4_CONFIG:
  2488. case MBX_SLI4_REQ_FTRS:
  2489. case MBX_REG_FCFI:
  2490. case MBX_UNREG_FCFI:
  2491. case MBX_REG_VFI:
  2492. case MBX_UNREG_VFI:
  2493. case MBX_INIT_VPI:
  2494. case MBX_INIT_VFI:
  2495. case MBX_RESUME_RPI:
  2496. case MBX_READ_EVENT_LOG_STATUS:
  2497. case MBX_READ_EVENT_LOG:
  2498. case MBX_SECURITY_MGMT:
  2499. case MBX_AUTH_PORT:
  2500. case MBX_ACCESS_VDATA:
  2501. ret = mbxCommand;
  2502. break;
  2503. default:
  2504. ret = MBX_SHUTDOWN;
  2505. break;
  2506. }
  2507. return ret;
  2508. }
  2509. /**
  2510. * lpfc_sli_wake_mbox_wait - lpfc_sli_issue_mbox_wait mbox completion handler
  2511. * @phba: Pointer to HBA context object.
  2512. * @pmboxq: Pointer to mailbox command.
  2513. *
  2514. * This is completion handler function for mailbox commands issued from
  2515. * lpfc_sli_issue_mbox_wait function. This function is called by the
  2516. * mailbox event handler function with no lock held. This function
  2517. * will wake up thread waiting on the wait queue pointed by context1
  2518. * of the mailbox.
  2519. **/
  2520. void
  2521. lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
  2522. {
  2523. unsigned long drvr_flag;
  2524. struct completion *pmbox_done;
  2525. /*
  2526. * If pmbox_done is empty, the driver thread gave up waiting and
  2527. * continued running.
  2528. */
  2529. pmboxq->mbox_flag |= LPFC_MBX_WAKE;
  2530. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  2531. pmbox_done = (struct completion *)pmboxq->context3;
  2532. if (pmbox_done)
  2533. complete(pmbox_done);
  2534. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  2535. return;
  2536. }
  2537. static void
  2538. __lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2539. {
  2540. unsigned long iflags;
  2541. if (ndlp->nlp_flag & NLP_RELEASE_RPI) {
  2542. lpfc_sli4_free_rpi(vport->phba, ndlp->nlp_rpi);
  2543. spin_lock_irqsave(&ndlp->lock, iflags);
  2544. ndlp->nlp_flag &= ~NLP_RELEASE_RPI;
  2545. ndlp->nlp_rpi = LPFC_RPI_ALLOC_ERROR;
  2546. spin_unlock_irqrestore(&ndlp->lock, iflags);
  2547. }
  2548. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  2549. }
  2550. void
  2551. lpfc_sli_rpi_release(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
  2552. {
  2553. __lpfc_sli_rpi_release(vport, ndlp);
  2554. }
  2555. /**
  2556. * lpfc_sli_def_mbox_cmpl - Default mailbox completion handler
  2557. * @phba: Pointer to HBA context object.
  2558. * @pmb: Pointer to mailbox object.
  2559. *
  2560. * This function is the default mailbox completion handler. It
  2561. * frees the memory resources associated with the completed mailbox
  2562. * command. If the completed command is a REG_LOGIN mailbox command,
  2563. * this function will issue a UREG_LOGIN to re-claim the RPI.
  2564. **/
  2565. void
  2566. lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2567. {
  2568. struct lpfc_vport *vport = pmb->vport;
  2569. struct lpfc_dmabuf *mp;
  2570. struct lpfc_nodelist *ndlp;
  2571. struct Scsi_Host *shost;
  2572. uint16_t rpi, vpi;
  2573. int rc;
  2574. /*
  2575. * If a REG_LOGIN succeeded after node is destroyed or node
  2576. * is in re-discovery driver need to cleanup the RPI.
  2577. */
  2578. if (!(phba->pport->load_flag & FC_UNLOADING) &&
  2579. pmb->u.mb.mbxCommand == MBX_REG_LOGIN64 &&
  2580. !pmb->u.mb.mbxStatus) {
  2581. mp = (struct lpfc_dmabuf *)pmb->ctx_buf;
  2582. if (mp) {
  2583. pmb->ctx_buf = NULL;
  2584. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2585. kfree(mp);
  2586. }
  2587. rpi = pmb->u.mb.un.varWords[0];
  2588. vpi = pmb->u.mb.un.varRegLogin.vpi;
  2589. if (phba->sli_rev == LPFC_SLI_REV4)
  2590. vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
  2591. lpfc_unreg_login(phba, vpi, rpi, pmb);
  2592. pmb->vport = vport;
  2593. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  2594. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2595. if (rc != MBX_NOT_FINISHED)
  2596. return;
  2597. }
  2598. if ((pmb->u.mb.mbxCommand == MBX_REG_VPI) &&
  2599. !(phba->pport->load_flag & FC_UNLOADING) &&
  2600. !pmb->u.mb.mbxStatus) {
  2601. shost = lpfc_shost_from_vport(vport);
  2602. spin_lock_irq(shost->host_lock);
  2603. vport->vpi_state |= LPFC_VPI_REGISTERED;
  2604. vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
  2605. spin_unlock_irq(shost->host_lock);
  2606. }
  2607. if (pmb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  2608. ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  2609. lpfc_nlp_put(ndlp);
  2610. }
  2611. if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
  2612. ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  2613. /* Check to see if there are any deferred events to process */
  2614. if (ndlp) {
  2615. lpfc_printf_vlog(
  2616. vport,
  2617. KERN_INFO, LOG_MBOX | LOG_DISCOVERY,
  2618. "1438 UNREG cmpl deferred mbox x%x "
  2619. "on NPort x%x Data: x%x x%x x%px x%x x%x\n",
  2620. ndlp->nlp_rpi, ndlp->nlp_DID,
  2621. ndlp->nlp_flag, ndlp->nlp_defer_did,
  2622. ndlp, vport->load_flag, kref_read(&ndlp->kref));
  2623. if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
  2624. (ndlp->nlp_defer_did != NLP_EVT_NOTHING_PENDING)) {
  2625. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  2626. ndlp->nlp_defer_did = NLP_EVT_NOTHING_PENDING;
  2627. lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
  2628. } else {
  2629. __lpfc_sli_rpi_release(vport, ndlp);
  2630. }
  2631. /* The unreg_login mailbox is complete and had a
  2632. * reference that has to be released. The PLOGI
  2633. * got its own ref.
  2634. */
  2635. lpfc_nlp_put(ndlp);
  2636. pmb->ctx_ndlp = NULL;
  2637. }
  2638. }
  2639. /* This nlp_put pairs with lpfc_sli4_resume_rpi */
  2640. if (pmb->u.mb.mbxCommand == MBX_RESUME_RPI) {
  2641. ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  2642. lpfc_nlp_put(ndlp);
  2643. }
  2644. /* Check security permission status on INIT_LINK mailbox command */
  2645. if ((pmb->u.mb.mbxCommand == MBX_INIT_LINK) &&
  2646. (pmb->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION))
  2647. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2648. "2860 SLI authentication is required "
  2649. "for INIT_LINK but has not done yet\n");
  2650. if (bf_get(lpfc_mqe_command, &pmb->u.mqe) == MBX_SLI4_CONFIG)
  2651. lpfc_sli4_mbox_cmd_free(phba, pmb);
  2652. else
  2653. lpfc_mbox_rsrc_cleanup(phba, pmb, MBOX_THD_UNLOCKED);
  2654. }
  2655. /**
  2656. * lpfc_sli4_unreg_rpi_cmpl_clr - mailbox completion handler
  2657. * @phba: Pointer to HBA context object.
  2658. * @pmb: Pointer to mailbox object.
  2659. *
  2660. * This function is the unreg rpi mailbox completion handler. It
  2661. * frees the memory resources associated with the completed mailbox
  2662. * command. An additional reference is put on the ndlp to prevent
  2663. * lpfc_nlp_release from freeing the rpi bit in the bitmask before
  2664. * the unreg mailbox command completes, this routine puts the
  2665. * reference back.
  2666. *
  2667. **/
  2668. void
  2669. lpfc_sli4_unreg_rpi_cmpl_clr(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  2670. {
  2671. struct lpfc_vport *vport = pmb->vport;
  2672. struct lpfc_nodelist *ndlp;
  2673. ndlp = pmb->ctx_ndlp;
  2674. if (pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) {
  2675. if (phba->sli_rev == LPFC_SLI_REV4 &&
  2676. (bf_get(lpfc_sli_intf_if_type,
  2677. &phba->sli4_hba.sli_intf) >=
  2678. LPFC_SLI_INTF_IF_TYPE_2)) {
  2679. if (ndlp) {
  2680. lpfc_printf_vlog(
  2681. vport, KERN_INFO, LOG_MBOX | LOG_SLI,
  2682. "0010 UNREG_LOGIN vpi:%x "
  2683. "rpi:%x DID:%x defer x%x flg x%x "
  2684. "x%px\n",
  2685. vport->vpi, ndlp->nlp_rpi,
  2686. ndlp->nlp_DID, ndlp->nlp_defer_did,
  2687. ndlp->nlp_flag,
  2688. ndlp);
  2689. ndlp->nlp_flag &= ~NLP_LOGO_ACC;
  2690. /* Check to see if there are any deferred
  2691. * events to process
  2692. */
  2693. if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
  2694. (ndlp->nlp_defer_did !=
  2695. NLP_EVT_NOTHING_PENDING)) {
  2696. lpfc_printf_vlog(
  2697. vport, KERN_INFO, LOG_DISCOVERY,
  2698. "4111 UNREG cmpl deferred "
  2699. "clr x%x on "
  2700. "NPort x%x Data: x%x x%px\n",
  2701. ndlp->nlp_rpi, ndlp->nlp_DID,
  2702. ndlp->nlp_defer_did, ndlp);
  2703. ndlp->nlp_flag &= ~NLP_UNREG_INP;
  2704. ndlp->nlp_defer_did =
  2705. NLP_EVT_NOTHING_PENDING;
  2706. lpfc_issue_els_plogi(
  2707. vport, ndlp->nlp_DID, 0);
  2708. } else {
  2709. __lpfc_sli_rpi_release(vport, ndlp);
  2710. }
  2711. lpfc_nlp_put(ndlp);
  2712. }
  2713. }
  2714. }
  2715. mempool_free(pmb, phba->mbox_mem_pool);
  2716. }
  2717. /**
  2718. * lpfc_sli_handle_mb_event - Handle mailbox completions from firmware
  2719. * @phba: Pointer to HBA context object.
  2720. *
  2721. * This function is called with no lock held. This function processes all
  2722. * the completed mailbox commands and gives it to upper layers. The interrupt
  2723. * service routine processes mailbox completion interrupt and adds completed
  2724. * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
  2725. * Worker thread call lpfc_sli_handle_mb_event, which will return the
  2726. * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
  2727. * function returns the mailbox commands to the upper layer by calling the
  2728. * completion handler function of each mailbox.
  2729. **/
  2730. int
  2731. lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
  2732. {
  2733. MAILBOX_t *pmbox;
  2734. LPFC_MBOXQ_t *pmb;
  2735. int rc;
  2736. LIST_HEAD(cmplq);
  2737. phba->sli.slistat.mbox_event++;
  2738. /* Get all completed mailboxe buffers into the cmplq */
  2739. spin_lock_irq(&phba->hbalock);
  2740. list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
  2741. spin_unlock_irq(&phba->hbalock);
  2742. /* Get a Mailbox buffer to setup mailbox commands for callback */
  2743. do {
  2744. list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
  2745. if (pmb == NULL)
  2746. break;
  2747. pmbox = &pmb->u.mb;
  2748. if (pmbox->mbxCommand != MBX_HEARTBEAT) {
  2749. if (pmb->vport) {
  2750. lpfc_debugfs_disc_trc(pmb->vport,
  2751. LPFC_DISC_TRC_MBOX_VPORT,
  2752. "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
  2753. (uint32_t)pmbox->mbxCommand,
  2754. pmbox->un.varWords[0],
  2755. pmbox->un.varWords[1]);
  2756. }
  2757. else {
  2758. lpfc_debugfs_disc_trc(phba->pport,
  2759. LPFC_DISC_TRC_MBOX,
  2760. "MBOX cmpl: cmd:x%x mb:x%x x%x",
  2761. (uint32_t)pmbox->mbxCommand,
  2762. pmbox->un.varWords[0],
  2763. pmbox->un.varWords[1]);
  2764. }
  2765. }
  2766. /*
  2767. * It is a fatal error if unknown mbox command completion.
  2768. */
  2769. if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
  2770. MBX_SHUTDOWN) {
  2771. /* Unknown mailbox command compl */
  2772. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2773. "(%d):0323 Unknown Mailbox command "
  2774. "x%x (x%x/x%x) Cmpl\n",
  2775. pmb->vport ? pmb->vport->vpi :
  2776. LPFC_VPORT_UNKNOWN,
  2777. pmbox->mbxCommand,
  2778. lpfc_sli_config_mbox_subsys_get(phba,
  2779. pmb),
  2780. lpfc_sli_config_mbox_opcode_get(phba,
  2781. pmb));
  2782. phba->link_state = LPFC_HBA_ERROR;
  2783. phba->work_hs = HS_FFER3;
  2784. lpfc_handle_eratt(phba);
  2785. continue;
  2786. }
  2787. if (pmbox->mbxStatus) {
  2788. phba->sli.slistat.mbox_stat_err++;
  2789. if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
  2790. /* Mbox cmd cmpl error - RETRYing */
  2791. lpfc_printf_log(phba, KERN_INFO,
  2792. LOG_MBOX | LOG_SLI,
  2793. "(%d):0305 Mbox cmd cmpl "
  2794. "error - RETRYing Data: x%x "
  2795. "(x%x/x%x) x%x x%x x%x\n",
  2796. pmb->vport ? pmb->vport->vpi :
  2797. LPFC_VPORT_UNKNOWN,
  2798. pmbox->mbxCommand,
  2799. lpfc_sli_config_mbox_subsys_get(phba,
  2800. pmb),
  2801. lpfc_sli_config_mbox_opcode_get(phba,
  2802. pmb),
  2803. pmbox->mbxStatus,
  2804. pmbox->un.varWords[0],
  2805. pmb->vport ? pmb->vport->port_state :
  2806. LPFC_VPORT_UNKNOWN);
  2807. pmbox->mbxStatus = 0;
  2808. pmbox->mbxOwner = OWN_HOST;
  2809. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  2810. if (rc != MBX_NOT_FINISHED)
  2811. continue;
  2812. }
  2813. }
  2814. /* Mailbox cmd <cmd> Cmpl <cmpl> */
  2815. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  2816. "(%d):0307 Mailbox cmd x%x (x%x/x%x) Cmpl %ps "
  2817. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  2818. "x%x x%x x%x\n",
  2819. pmb->vport ? pmb->vport->vpi : 0,
  2820. pmbox->mbxCommand,
  2821. lpfc_sli_config_mbox_subsys_get(phba, pmb),
  2822. lpfc_sli_config_mbox_opcode_get(phba, pmb),
  2823. pmb->mbox_cmpl,
  2824. *((uint32_t *) pmbox),
  2825. pmbox->un.varWords[0],
  2826. pmbox->un.varWords[1],
  2827. pmbox->un.varWords[2],
  2828. pmbox->un.varWords[3],
  2829. pmbox->un.varWords[4],
  2830. pmbox->un.varWords[5],
  2831. pmbox->un.varWords[6],
  2832. pmbox->un.varWords[7],
  2833. pmbox->un.varWords[8],
  2834. pmbox->un.varWords[9],
  2835. pmbox->un.varWords[10]);
  2836. if (pmb->mbox_cmpl)
  2837. pmb->mbox_cmpl(phba,pmb);
  2838. } while (1);
  2839. return 0;
  2840. }
  2841. /**
  2842. * lpfc_sli_get_buff - Get the buffer associated with the buffer tag
  2843. * @phba: Pointer to HBA context object.
  2844. * @pring: Pointer to driver SLI ring object.
  2845. * @tag: buffer tag.
  2846. *
  2847. * This function is called with no lock held. When QUE_BUFTAG_BIT bit
  2848. * is set in the tag the buffer is posted for a particular exchange,
  2849. * the function will return the buffer without replacing the buffer.
  2850. * If the buffer is for unsolicited ELS or CT traffic, this function
  2851. * returns the buffer and also posts another buffer to the firmware.
  2852. **/
  2853. static struct lpfc_dmabuf *
  2854. lpfc_sli_get_buff(struct lpfc_hba *phba,
  2855. struct lpfc_sli_ring *pring,
  2856. uint32_t tag)
  2857. {
  2858. struct hbq_dmabuf *hbq_entry;
  2859. if (tag & QUE_BUFTAG_BIT)
  2860. return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
  2861. hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
  2862. if (!hbq_entry)
  2863. return NULL;
  2864. return &hbq_entry->dbuf;
  2865. }
  2866. /**
  2867. * lpfc_nvme_unsol_ls_handler - Process an unsolicited event data buffer
  2868. * containing a NVME LS request.
  2869. * @phba: pointer to lpfc hba data structure.
  2870. * @piocb: pointer to the iocbq struct representing the sequence starting
  2871. * frame.
  2872. *
  2873. * This routine initially validates the NVME LS, validates there is a login
  2874. * with the port that sent the LS, and then calls the appropriate nvme host
  2875. * or target LS request handler.
  2876. **/
  2877. static void
  2878. lpfc_nvme_unsol_ls_handler(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  2879. {
  2880. struct lpfc_nodelist *ndlp;
  2881. struct lpfc_dmabuf *d_buf;
  2882. struct hbq_dmabuf *nvmebuf;
  2883. struct fc_frame_header *fc_hdr;
  2884. struct lpfc_async_xchg_ctx *axchg = NULL;
  2885. char *failwhy = NULL;
  2886. uint32_t oxid, sid, did, fctl, size;
  2887. int ret = 1;
  2888. d_buf = piocb->cmd_dmabuf;
  2889. nvmebuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  2890. fc_hdr = nvmebuf->hbuf.virt;
  2891. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  2892. sid = sli4_sid_from_fc_hdr(fc_hdr);
  2893. did = sli4_did_from_fc_hdr(fc_hdr);
  2894. fctl = (fc_hdr->fh_f_ctl[0] << 16 |
  2895. fc_hdr->fh_f_ctl[1] << 8 |
  2896. fc_hdr->fh_f_ctl[2]);
  2897. size = bf_get(lpfc_rcqe_length, &nvmebuf->cq_event.cqe.rcqe_cmpl);
  2898. lpfc_nvmeio_data(phba, "NVME LS RCV: xri x%x sz %d from %06x\n",
  2899. oxid, size, sid);
  2900. if (phba->pport->load_flag & FC_UNLOADING) {
  2901. failwhy = "Driver Unloading";
  2902. } else if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) {
  2903. failwhy = "NVME FC4 Disabled";
  2904. } else if (!phba->nvmet_support && !phba->pport->localport) {
  2905. failwhy = "No Localport";
  2906. } else if (phba->nvmet_support && !phba->targetport) {
  2907. failwhy = "No Targetport";
  2908. } else if (unlikely(fc_hdr->fh_r_ctl != FC_RCTL_ELS4_REQ)) {
  2909. failwhy = "Bad NVME LS R_CTL";
  2910. } else if (unlikely((fctl & 0x00FF0000) !=
  2911. (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT))) {
  2912. failwhy = "Bad NVME LS F_CTL";
  2913. } else {
  2914. axchg = kzalloc(sizeof(*axchg), GFP_ATOMIC);
  2915. if (!axchg)
  2916. failwhy = "No CTX memory";
  2917. }
  2918. if (unlikely(failwhy)) {
  2919. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2920. "6154 Drop NVME LS: SID %06X OXID x%X: %s\n",
  2921. sid, oxid, failwhy);
  2922. goto out_fail;
  2923. }
  2924. /* validate the source of the LS is logged in */
  2925. ndlp = lpfc_findnode_did(phba->pport, sid);
  2926. if (!ndlp ||
  2927. ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
  2928. (ndlp->nlp_state != NLP_STE_MAPPED_NODE))) {
  2929. lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC,
  2930. "6216 NVME Unsol rcv: No ndlp: "
  2931. "NPort_ID x%x oxid x%x\n",
  2932. sid, oxid);
  2933. goto out_fail;
  2934. }
  2935. axchg->phba = phba;
  2936. axchg->ndlp = ndlp;
  2937. axchg->size = size;
  2938. axchg->oxid = oxid;
  2939. axchg->sid = sid;
  2940. axchg->wqeq = NULL;
  2941. axchg->state = LPFC_NVME_STE_LS_RCV;
  2942. axchg->entry_cnt = 1;
  2943. axchg->rqb_buffer = (void *)nvmebuf;
  2944. axchg->hdwq = &phba->sli4_hba.hdwq[0];
  2945. axchg->payload = nvmebuf->dbuf.virt;
  2946. INIT_LIST_HEAD(&axchg->list);
  2947. if (phba->nvmet_support) {
  2948. ret = lpfc_nvmet_handle_lsreq(phba, axchg);
  2949. spin_lock_irq(&ndlp->lock);
  2950. if (!ret && !(ndlp->fc4_xpt_flags & NLP_XPT_HAS_HH)) {
  2951. ndlp->fc4_xpt_flags |= NLP_XPT_HAS_HH;
  2952. spin_unlock_irq(&ndlp->lock);
  2953. /* This reference is a single occurrence to hold the
  2954. * node valid until the nvmet transport calls
  2955. * host_release.
  2956. */
  2957. if (!lpfc_nlp_get(ndlp))
  2958. goto out_fail;
  2959. lpfc_printf_log(phba, KERN_ERR, LOG_NODE,
  2960. "6206 NVMET unsol ls_req ndlp x%px "
  2961. "DID x%x xflags x%x refcnt %d\n",
  2962. ndlp, ndlp->nlp_DID,
  2963. ndlp->fc4_xpt_flags,
  2964. kref_read(&ndlp->kref));
  2965. } else {
  2966. spin_unlock_irq(&ndlp->lock);
  2967. }
  2968. } else {
  2969. ret = lpfc_nvme_handle_lsreq(phba, axchg);
  2970. }
  2971. /* if zero, LS was successfully handled. If non-zero, LS not handled */
  2972. if (!ret)
  2973. return;
  2974. out_fail:
  2975. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  2976. "6155 Drop NVME LS from DID %06X: SID %06X OXID x%X "
  2977. "NVMe%s handler failed %d\n",
  2978. did, sid, oxid,
  2979. (phba->nvmet_support) ? "T" : "I", ret);
  2980. /* recycle receive buffer */
  2981. lpfc_in_buf_free(phba, &nvmebuf->dbuf);
  2982. /* If start of new exchange, abort it */
  2983. if (axchg && (fctl & FC_FC_FIRST_SEQ && !(fctl & FC_FC_EX_CTX)))
  2984. ret = lpfc_nvme_unsol_ls_issue_abort(phba, axchg, sid, oxid);
  2985. if (ret)
  2986. kfree(axchg);
  2987. }
  2988. /**
  2989. * lpfc_complete_unsol_iocb - Complete an unsolicited sequence
  2990. * @phba: Pointer to HBA context object.
  2991. * @pring: Pointer to driver SLI ring object.
  2992. * @saveq: Pointer to the iocbq struct representing the sequence starting frame.
  2993. * @fch_r_ctl: the r_ctl for the first frame of the sequence.
  2994. * @fch_type: the type for the first frame of the sequence.
  2995. *
  2996. * This function is called with no lock held. This function uses the r_ctl and
  2997. * type of the received sequence to find the correct callback function to call
  2998. * to process the sequence.
  2999. **/
  3000. static int
  3001. lpfc_complete_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3002. struct lpfc_iocbq *saveq, uint32_t fch_r_ctl,
  3003. uint32_t fch_type)
  3004. {
  3005. int i;
  3006. switch (fch_type) {
  3007. case FC_TYPE_NVME:
  3008. lpfc_nvme_unsol_ls_handler(phba, saveq);
  3009. return 1;
  3010. default:
  3011. break;
  3012. }
  3013. /* unSolicited Responses */
  3014. if (pring->prt[0].profile) {
  3015. if (pring->prt[0].lpfc_sli_rcv_unsol_event)
  3016. (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
  3017. saveq);
  3018. return 1;
  3019. }
  3020. /* We must search, based on rctl / type
  3021. for the right routine */
  3022. for (i = 0; i < pring->num_mask; i++) {
  3023. if ((pring->prt[i].rctl == fch_r_ctl) &&
  3024. (pring->prt[i].type == fch_type)) {
  3025. if (pring->prt[i].lpfc_sli_rcv_unsol_event)
  3026. (pring->prt[i].lpfc_sli_rcv_unsol_event)
  3027. (phba, pring, saveq);
  3028. return 1;
  3029. }
  3030. }
  3031. return 0;
  3032. }
  3033. static void
  3034. lpfc_sli_prep_unsol_wqe(struct lpfc_hba *phba,
  3035. struct lpfc_iocbq *saveq)
  3036. {
  3037. IOCB_t *irsp;
  3038. union lpfc_wqe128 *wqe;
  3039. u16 i = 0;
  3040. irsp = &saveq->iocb;
  3041. wqe = &saveq->wqe;
  3042. /* Fill wcqe with the IOCB status fields */
  3043. bf_set(lpfc_wcqe_c_status, &saveq->wcqe_cmpl, irsp->ulpStatus);
  3044. saveq->wcqe_cmpl.word3 = irsp->ulpBdeCount;
  3045. saveq->wcqe_cmpl.parameter = irsp->un.ulpWord[4];
  3046. saveq->wcqe_cmpl.total_data_placed = irsp->unsli3.rcvsli3.acc_len;
  3047. /* Source ID */
  3048. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp, irsp->un.rcvels.parmRo);
  3049. /* rx-id of the response frame */
  3050. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com, irsp->ulpContext);
  3051. /* ox-id of the frame */
  3052. bf_set(wqe_rcvoxid, &wqe->xmit_els_rsp.wqe_com,
  3053. irsp->unsli3.rcvsli3.ox_id);
  3054. /* DID */
  3055. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest,
  3056. irsp->un.rcvels.remoteID);
  3057. /* unsol data len */
  3058. for (i = 0; i < irsp->ulpBdeCount; i++) {
  3059. struct lpfc_hbq_entry *hbqe = NULL;
  3060. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3061. if (i == 0) {
  3062. hbqe = (struct lpfc_hbq_entry *)
  3063. &irsp->un.ulpWord[0];
  3064. saveq->wqe.gen_req.bde.tus.f.bdeSize =
  3065. hbqe->bde.tus.f.bdeSize;
  3066. } else if (i == 1) {
  3067. hbqe = (struct lpfc_hbq_entry *)
  3068. &irsp->unsli3.sli3Words[4];
  3069. saveq->unsol_rcv_len = hbqe->bde.tus.f.bdeSize;
  3070. }
  3071. }
  3072. }
  3073. }
  3074. /**
  3075. * lpfc_sli_process_unsol_iocb - Unsolicited iocb handler
  3076. * @phba: Pointer to HBA context object.
  3077. * @pring: Pointer to driver SLI ring object.
  3078. * @saveq: Pointer to the unsolicited iocb.
  3079. *
  3080. * This function is called with no lock held by the ring event handler
  3081. * when there is an unsolicited iocb posted to the response ring by the
  3082. * firmware. This function gets the buffer associated with the iocbs
  3083. * and calls the event handler for the ring. This function handles both
  3084. * qring buffers and hbq buffers.
  3085. * When the function returns 1 the caller can free the iocb object otherwise
  3086. * upper layer functions will free the iocb objects.
  3087. **/
  3088. static int
  3089. lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3090. struct lpfc_iocbq *saveq)
  3091. {
  3092. IOCB_t * irsp;
  3093. WORD5 * w5p;
  3094. dma_addr_t paddr;
  3095. uint32_t Rctl, Type;
  3096. struct lpfc_iocbq *iocbq;
  3097. struct lpfc_dmabuf *dmzbuf;
  3098. irsp = &saveq->iocb;
  3099. saveq->vport = phba->pport;
  3100. if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
  3101. if (pring->lpfc_sli_rcv_async_status)
  3102. pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
  3103. else
  3104. lpfc_printf_log(phba,
  3105. KERN_WARNING,
  3106. LOG_SLI,
  3107. "0316 Ring %d handler: unexpected "
  3108. "ASYNC_STATUS iocb received evt_code "
  3109. "0x%x\n",
  3110. pring->ringno,
  3111. irsp->un.asyncstat.evt_code);
  3112. return 1;
  3113. }
  3114. if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
  3115. (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
  3116. if (irsp->ulpBdeCount > 0) {
  3117. dmzbuf = lpfc_sli_get_buff(phba, pring,
  3118. irsp->un.ulpWord[3]);
  3119. lpfc_in_buf_free(phba, dmzbuf);
  3120. }
  3121. if (irsp->ulpBdeCount > 1) {
  3122. dmzbuf = lpfc_sli_get_buff(phba, pring,
  3123. irsp->unsli3.sli3Words[3]);
  3124. lpfc_in_buf_free(phba, dmzbuf);
  3125. }
  3126. if (irsp->ulpBdeCount > 2) {
  3127. dmzbuf = lpfc_sli_get_buff(phba, pring,
  3128. irsp->unsli3.sli3Words[7]);
  3129. lpfc_in_buf_free(phba, dmzbuf);
  3130. }
  3131. return 1;
  3132. }
  3133. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  3134. if (irsp->ulpBdeCount != 0) {
  3135. saveq->cmd_dmabuf = lpfc_sli_get_buff(phba, pring,
  3136. irsp->un.ulpWord[3]);
  3137. if (!saveq->cmd_dmabuf)
  3138. lpfc_printf_log(phba,
  3139. KERN_ERR,
  3140. LOG_SLI,
  3141. "0341 Ring %d Cannot find buffer for "
  3142. "an unsolicited iocb. tag 0x%x\n",
  3143. pring->ringno,
  3144. irsp->un.ulpWord[3]);
  3145. }
  3146. if (irsp->ulpBdeCount == 2) {
  3147. saveq->bpl_dmabuf = lpfc_sli_get_buff(phba, pring,
  3148. irsp->unsli3.sli3Words[7]);
  3149. if (!saveq->bpl_dmabuf)
  3150. lpfc_printf_log(phba,
  3151. KERN_ERR,
  3152. LOG_SLI,
  3153. "0342 Ring %d Cannot find buffer for an"
  3154. " unsolicited iocb. tag 0x%x\n",
  3155. pring->ringno,
  3156. irsp->unsli3.sli3Words[7]);
  3157. }
  3158. list_for_each_entry(iocbq, &saveq->list, list) {
  3159. irsp = &iocbq->iocb;
  3160. if (irsp->ulpBdeCount != 0) {
  3161. iocbq->cmd_dmabuf = lpfc_sli_get_buff(phba,
  3162. pring,
  3163. irsp->un.ulpWord[3]);
  3164. if (!iocbq->cmd_dmabuf)
  3165. lpfc_printf_log(phba,
  3166. KERN_ERR,
  3167. LOG_SLI,
  3168. "0343 Ring %d Cannot find "
  3169. "buffer for an unsolicited iocb"
  3170. ". tag 0x%x\n", pring->ringno,
  3171. irsp->un.ulpWord[3]);
  3172. }
  3173. if (irsp->ulpBdeCount == 2) {
  3174. iocbq->bpl_dmabuf = lpfc_sli_get_buff(phba,
  3175. pring,
  3176. irsp->unsli3.sli3Words[7]);
  3177. if (!iocbq->bpl_dmabuf)
  3178. lpfc_printf_log(phba,
  3179. KERN_ERR,
  3180. LOG_SLI,
  3181. "0344 Ring %d Cannot find "
  3182. "buffer for an unsolicited "
  3183. "iocb. tag 0x%x\n",
  3184. pring->ringno,
  3185. irsp->unsli3.sli3Words[7]);
  3186. }
  3187. }
  3188. } else {
  3189. paddr = getPaddr(irsp->un.cont64[0].addrHigh,
  3190. irsp->un.cont64[0].addrLow);
  3191. saveq->cmd_dmabuf = lpfc_sli_ringpostbuf_get(phba, pring,
  3192. paddr);
  3193. if (irsp->ulpBdeCount == 2) {
  3194. paddr = getPaddr(irsp->un.cont64[1].addrHigh,
  3195. irsp->un.cont64[1].addrLow);
  3196. saveq->bpl_dmabuf = lpfc_sli_ringpostbuf_get(phba,
  3197. pring,
  3198. paddr);
  3199. }
  3200. }
  3201. if (irsp->ulpBdeCount != 0 &&
  3202. (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
  3203. irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
  3204. int found = 0;
  3205. /* search continue save q for same XRI */
  3206. list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
  3207. if (iocbq->iocb.unsli3.rcvsli3.ox_id ==
  3208. saveq->iocb.unsli3.rcvsli3.ox_id) {
  3209. list_add_tail(&saveq->list, &iocbq->list);
  3210. found = 1;
  3211. break;
  3212. }
  3213. }
  3214. if (!found)
  3215. list_add_tail(&saveq->clist,
  3216. &pring->iocb_continue_saveq);
  3217. if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
  3218. list_del_init(&iocbq->clist);
  3219. saveq = iocbq;
  3220. irsp = &saveq->iocb;
  3221. } else {
  3222. return 0;
  3223. }
  3224. }
  3225. if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
  3226. (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
  3227. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
  3228. Rctl = FC_RCTL_ELS_REQ;
  3229. Type = FC_TYPE_ELS;
  3230. } else {
  3231. w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
  3232. Rctl = w5p->hcsw.Rctl;
  3233. Type = w5p->hcsw.Type;
  3234. /* Firmware Workaround */
  3235. if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
  3236. (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
  3237. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3238. Rctl = FC_RCTL_ELS_REQ;
  3239. Type = FC_TYPE_ELS;
  3240. w5p->hcsw.Rctl = Rctl;
  3241. w5p->hcsw.Type = Type;
  3242. }
  3243. }
  3244. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
  3245. (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
  3246. irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
  3247. if (irsp->unsli3.rcvsli3.vpi == 0xffff)
  3248. saveq->vport = phba->pport;
  3249. else
  3250. saveq->vport = lpfc_find_vport_by_vpid(phba,
  3251. irsp->unsli3.rcvsli3.vpi);
  3252. }
  3253. /* Prepare WQE with Unsol frame */
  3254. lpfc_sli_prep_unsol_wqe(phba, saveq);
  3255. if (!lpfc_complete_unsol_iocb(phba, pring, saveq, Rctl, Type))
  3256. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  3257. "0313 Ring %d handler: unexpected Rctl x%x "
  3258. "Type x%x received\n",
  3259. pring->ringno, Rctl, Type);
  3260. return 1;
  3261. }
  3262. /**
  3263. * lpfc_sli_iocbq_lookup - Find command iocb for the given response iocb
  3264. * @phba: Pointer to HBA context object.
  3265. * @pring: Pointer to driver SLI ring object.
  3266. * @prspiocb: Pointer to response iocb object.
  3267. *
  3268. * This function looks up the iocb_lookup table to get the command iocb
  3269. * corresponding to the given response iocb using the iotag of the
  3270. * response iocb. The driver calls this function with the hbalock held
  3271. * for SLI3 ports or the ring lock held for SLI4 ports.
  3272. * This function returns the command iocb object if it finds the command
  3273. * iocb else returns NULL.
  3274. **/
  3275. static struct lpfc_iocbq *
  3276. lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
  3277. struct lpfc_sli_ring *pring,
  3278. struct lpfc_iocbq *prspiocb)
  3279. {
  3280. struct lpfc_iocbq *cmd_iocb = NULL;
  3281. u16 iotag;
  3282. if (phba->sli_rev == LPFC_SLI_REV4)
  3283. iotag = get_wqe_reqtag(prspiocb);
  3284. else
  3285. iotag = prspiocb->iocb.ulpIoTag;
  3286. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  3287. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  3288. if (cmd_iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ) {
  3289. /* remove from txcmpl queue list */
  3290. list_del_init(&cmd_iocb->list);
  3291. cmd_iocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
  3292. pring->txcmplq_cnt--;
  3293. return cmd_iocb;
  3294. }
  3295. }
  3296. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3297. "0317 iotag x%x is out of "
  3298. "range: max iotag x%x\n",
  3299. iotag, phba->sli.last_iotag);
  3300. return NULL;
  3301. }
  3302. /**
  3303. * lpfc_sli_iocbq_lookup_by_tag - Find command iocb for the iotag
  3304. * @phba: Pointer to HBA context object.
  3305. * @pring: Pointer to driver SLI ring object.
  3306. * @iotag: IOCB tag.
  3307. *
  3308. * This function looks up the iocb_lookup table to get the command iocb
  3309. * corresponding to the given iotag. The driver calls this function with
  3310. * the ring lock held because this function is an SLI4 port only helper.
  3311. * This function returns the command iocb object if it finds the command
  3312. * iocb else returns NULL.
  3313. **/
  3314. static struct lpfc_iocbq *
  3315. lpfc_sli_iocbq_lookup_by_tag(struct lpfc_hba *phba,
  3316. struct lpfc_sli_ring *pring, uint16_t iotag)
  3317. {
  3318. struct lpfc_iocbq *cmd_iocb = NULL;
  3319. if (iotag != 0 && iotag <= phba->sli.last_iotag) {
  3320. cmd_iocb = phba->sli.iocbq_lookup[iotag];
  3321. if (cmd_iocb->cmd_flag & LPFC_IO_ON_TXCMPLQ) {
  3322. /* remove from txcmpl queue list */
  3323. list_del_init(&cmd_iocb->list);
  3324. cmd_iocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
  3325. pring->txcmplq_cnt--;
  3326. return cmd_iocb;
  3327. }
  3328. }
  3329. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3330. "0372 iotag x%x lookup error: max iotag (x%x) "
  3331. "cmd_flag x%x\n",
  3332. iotag, phba->sli.last_iotag,
  3333. cmd_iocb ? cmd_iocb->cmd_flag : 0xffff);
  3334. return NULL;
  3335. }
  3336. /**
  3337. * lpfc_sli_process_sol_iocb - process solicited iocb completion
  3338. * @phba: Pointer to HBA context object.
  3339. * @pring: Pointer to driver SLI ring object.
  3340. * @saveq: Pointer to the response iocb to be processed.
  3341. *
  3342. * This function is called by the ring event handler for non-fcp
  3343. * rings when there is a new response iocb in the response ring.
  3344. * The caller is not required to hold any locks. This function
  3345. * gets the command iocb associated with the response iocb and
  3346. * calls the completion handler for the command iocb. If there
  3347. * is no completion handler, the function will free the resources
  3348. * associated with command iocb. If the response iocb is for
  3349. * an already aborted command iocb, the status of the completion
  3350. * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
  3351. * This function always returns 1.
  3352. **/
  3353. static int
  3354. lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3355. struct lpfc_iocbq *saveq)
  3356. {
  3357. struct lpfc_iocbq *cmdiocbp;
  3358. unsigned long iflag;
  3359. u32 ulp_command, ulp_status, ulp_word4, ulp_context, iotag;
  3360. if (phba->sli_rev == LPFC_SLI_REV4)
  3361. spin_lock_irqsave(&pring->ring_lock, iflag);
  3362. else
  3363. spin_lock_irqsave(&phba->hbalock, iflag);
  3364. cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
  3365. if (phba->sli_rev == LPFC_SLI_REV4)
  3366. spin_unlock_irqrestore(&pring->ring_lock, iflag);
  3367. else
  3368. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3369. ulp_command = get_job_cmnd(phba, saveq);
  3370. ulp_status = get_job_ulpstatus(phba, saveq);
  3371. ulp_word4 = get_job_word4(phba, saveq);
  3372. ulp_context = get_job_ulpcontext(phba, saveq);
  3373. if (phba->sli_rev == LPFC_SLI_REV4)
  3374. iotag = get_wqe_reqtag(saveq);
  3375. else
  3376. iotag = saveq->iocb.ulpIoTag;
  3377. if (cmdiocbp) {
  3378. ulp_command = get_job_cmnd(phba, cmdiocbp);
  3379. if (cmdiocbp->cmd_cmpl) {
  3380. /*
  3381. * If an ELS command failed send an event to mgmt
  3382. * application.
  3383. */
  3384. if (ulp_status &&
  3385. (pring->ringno == LPFC_ELS_RING) &&
  3386. (ulp_command == CMD_ELS_REQUEST64_CR))
  3387. lpfc_send_els_failure_event(phba,
  3388. cmdiocbp, saveq);
  3389. /*
  3390. * Post all ELS completions to the worker thread.
  3391. * All other are passed to the completion callback.
  3392. */
  3393. if (pring->ringno == LPFC_ELS_RING) {
  3394. if ((phba->sli_rev < LPFC_SLI_REV4) &&
  3395. (cmdiocbp->cmd_flag &
  3396. LPFC_DRIVER_ABORTED)) {
  3397. spin_lock_irqsave(&phba->hbalock,
  3398. iflag);
  3399. cmdiocbp->cmd_flag &=
  3400. ~LPFC_DRIVER_ABORTED;
  3401. spin_unlock_irqrestore(&phba->hbalock,
  3402. iflag);
  3403. saveq->iocb.ulpStatus =
  3404. IOSTAT_LOCAL_REJECT;
  3405. saveq->iocb.un.ulpWord[4] =
  3406. IOERR_SLI_ABORTED;
  3407. /* Firmware could still be in progress
  3408. * of DMAing payload, so don't free data
  3409. * buffer till after a hbeat.
  3410. */
  3411. spin_lock_irqsave(&phba->hbalock,
  3412. iflag);
  3413. saveq->cmd_flag |= LPFC_DELAY_MEM_FREE;
  3414. spin_unlock_irqrestore(&phba->hbalock,
  3415. iflag);
  3416. }
  3417. if (phba->sli_rev == LPFC_SLI_REV4) {
  3418. if (saveq->cmd_flag &
  3419. LPFC_EXCHANGE_BUSY) {
  3420. /* Set cmdiocb flag for the
  3421. * exchange busy so sgl (xri)
  3422. * will not be released until
  3423. * the abort xri is received
  3424. * from hba.
  3425. */
  3426. spin_lock_irqsave(
  3427. &phba->hbalock, iflag);
  3428. cmdiocbp->cmd_flag |=
  3429. LPFC_EXCHANGE_BUSY;
  3430. spin_unlock_irqrestore(
  3431. &phba->hbalock, iflag);
  3432. }
  3433. if (cmdiocbp->cmd_flag &
  3434. LPFC_DRIVER_ABORTED) {
  3435. /*
  3436. * Clear LPFC_DRIVER_ABORTED
  3437. * bit in case it was driver
  3438. * initiated abort.
  3439. */
  3440. spin_lock_irqsave(
  3441. &phba->hbalock, iflag);
  3442. cmdiocbp->cmd_flag &=
  3443. ~LPFC_DRIVER_ABORTED;
  3444. spin_unlock_irqrestore(
  3445. &phba->hbalock, iflag);
  3446. set_job_ulpstatus(cmdiocbp,
  3447. IOSTAT_LOCAL_REJECT);
  3448. set_job_ulpword4(cmdiocbp,
  3449. IOERR_ABORT_REQUESTED);
  3450. /*
  3451. * For SLI4, irspiocb contains
  3452. * NO_XRI in sli_xritag, it
  3453. * shall not affect releasing
  3454. * sgl (xri) process.
  3455. */
  3456. set_job_ulpstatus(saveq,
  3457. IOSTAT_LOCAL_REJECT);
  3458. set_job_ulpword4(saveq,
  3459. IOERR_SLI_ABORTED);
  3460. spin_lock_irqsave(
  3461. &phba->hbalock, iflag);
  3462. saveq->cmd_flag |=
  3463. LPFC_DELAY_MEM_FREE;
  3464. spin_unlock_irqrestore(
  3465. &phba->hbalock, iflag);
  3466. }
  3467. }
  3468. }
  3469. cmdiocbp->cmd_cmpl(phba, cmdiocbp, saveq);
  3470. } else
  3471. lpfc_sli_release_iocbq(phba, cmdiocbp);
  3472. } else {
  3473. /*
  3474. * Unknown initiating command based on the response iotag.
  3475. * This could be the case on the ELS ring because of
  3476. * lpfc_els_abort().
  3477. */
  3478. if (pring->ringno != LPFC_ELS_RING) {
  3479. /*
  3480. * Ring <ringno> handler: unexpected completion IoTag
  3481. * <IoTag>
  3482. */
  3483. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  3484. "0322 Ring %d handler: "
  3485. "unexpected completion IoTag x%x "
  3486. "Data: x%x x%x x%x x%x\n",
  3487. pring->ringno, iotag, ulp_status,
  3488. ulp_word4, ulp_command, ulp_context);
  3489. }
  3490. }
  3491. return 1;
  3492. }
  3493. /**
  3494. * lpfc_sli_rsp_pointers_error - Response ring pointer error handler
  3495. * @phba: Pointer to HBA context object.
  3496. * @pring: Pointer to driver SLI ring object.
  3497. *
  3498. * This function is called from the iocb ring event handlers when
  3499. * put pointer is ahead of the get pointer for a ring. This function signal
  3500. * an error attention condition to the worker thread and the worker
  3501. * thread will transition the HBA to offline state.
  3502. **/
  3503. static void
  3504. lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  3505. {
  3506. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  3507. /*
  3508. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3509. * rsp ring <portRspMax>
  3510. */
  3511. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3512. "0312 Ring %d handler: portRspPut %d "
  3513. "is bigger than rsp ring %d\n",
  3514. pring->ringno, le32_to_cpu(pgp->rspPutInx),
  3515. pring->sli.sli3.numRiocb);
  3516. phba->link_state = LPFC_HBA_ERROR;
  3517. /*
  3518. * All error attention handlers are posted to
  3519. * worker thread
  3520. */
  3521. phba->work_ha |= HA_ERATT;
  3522. phba->work_hs = HS_FFER3;
  3523. lpfc_worker_wake_up(phba);
  3524. return;
  3525. }
  3526. /**
  3527. * lpfc_poll_eratt - Error attention polling timer timeout handler
  3528. * @t: Context to fetch pointer to address of HBA context object from.
  3529. *
  3530. * This function is invoked by the Error Attention polling timer when the
  3531. * timer times out. It will check the SLI Error Attention register for
  3532. * possible attention events. If so, it will post an Error Attention event
  3533. * and wake up worker thread to process it. Otherwise, it will set up the
  3534. * Error Attention polling timer for the next poll.
  3535. **/
  3536. void lpfc_poll_eratt(struct timer_list *t)
  3537. {
  3538. struct lpfc_hba *phba;
  3539. uint32_t eratt = 0;
  3540. uint64_t sli_intr, cnt;
  3541. phba = from_timer(phba, t, eratt_poll);
  3542. if (!(phba->hba_flag & HBA_SETUP))
  3543. return;
  3544. /* Here we will also keep track of interrupts per sec of the hba */
  3545. sli_intr = phba->sli.slistat.sli_intr;
  3546. if (phba->sli.slistat.sli_prev_intr > sli_intr)
  3547. cnt = (((uint64_t)(-1) - phba->sli.slistat.sli_prev_intr) +
  3548. sli_intr);
  3549. else
  3550. cnt = (sli_intr - phba->sli.slistat.sli_prev_intr);
  3551. /* 64-bit integer division not supported on 32-bit x86 - use do_div */
  3552. do_div(cnt, phba->eratt_poll_interval);
  3553. phba->sli.slistat.sli_ips = cnt;
  3554. phba->sli.slistat.sli_prev_intr = sli_intr;
  3555. /* Check chip HA register for error event */
  3556. eratt = lpfc_sli_check_eratt(phba);
  3557. if (eratt)
  3558. /* Tell the worker thread there is work to do */
  3559. lpfc_worker_wake_up(phba);
  3560. else
  3561. /* Restart the timer for next eratt poll */
  3562. mod_timer(&phba->eratt_poll,
  3563. jiffies +
  3564. msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  3565. return;
  3566. }
  3567. /**
  3568. * lpfc_sli_handle_fast_ring_event - Handle ring events on FCP ring
  3569. * @phba: Pointer to HBA context object.
  3570. * @pring: Pointer to driver SLI ring object.
  3571. * @mask: Host attention register mask for this ring.
  3572. *
  3573. * This function is called from the interrupt context when there is a ring
  3574. * event for the fcp ring. The caller does not hold any lock.
  3575. * The function processes each response iocb in the response ring until it
  3576. * finds an iocb with LE bit set and chains all the iocbs up to the iocb with
  3577. * LE bit set. The function will call the completion handler of the command iocb
  3578. * if the response iocb indicates a completion for a command iocb or it is
  3579. * an abort completion. The function will call lpfc_sli_process_unsol_iocb
  3580. * function if this is an unsolicited iocb.
  3581. * This routine presumes LPFC_FCP_RING handling and doesn't bother
  3582. * to check it explicitly.
  3583. */
  3584. int
  3585. lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
  3586. struct lpfc_sli_ring *pring, uint32_t mask)
  3587. {
  3588. struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
  3589. IOCB_t *irsp = NULL;
  3590. IOCB_t *entry = NULL;
  3591. struct lpfc_iocbq *cmdiocbq = NULL;
  3592. struct lpfc_iocbq rspiocbq;
  3593. uint32_t status;
  3594. uint32_t portRspPut, portRspMax;
  3595. int rc = 1;
  3596. lpfc_iocb_type type;
  3597. unsigned long iflag;
  3598. uint32_t rsp_cmpl = 0;
  3599. spin_lock_irqsave(&phba->hbalock, iflag);
  3600. pring->stats.iocb_event++;
  3601. /*
  3602. * The next available response entry should never exceed the maximum
  3603. * entries. If it does, treat it as an adapter hardware error.
  3604. */
  3605. portRspMax = pring->sli.sli3.numRiocb;
  3606. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3607. if (unlikely(portRspPut >= portRspMax)) {
  3608. lpfc_sli_rsp_pointers_error(phba, pring);
  3609. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3610. return 1;
  3611. }
  3612. if (phba->fcp_ring_in_use) {
  3613. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3614. return 1;
  3615. } else
  3616. phba->fcp_ring_in_use = 1;
  3617. rmb();
  3618. while (pring->sli.sli3.rspidx != portRspPut) {
  3619. /*
  3620. * Fetch an entry off the ring and copy it into a local data
  3621. * structure. The copy involves a byte-swap since the
  3622. * network byte order and pci byte orders are different.
  3623. */
  3624. entry = lpfc_resp_iocb(phba, pring);
  3625. phba->last_completion_time = jiffies;
  3626. if (++pring->sli.sli3.rspidx >= portRspMax)
  3627. pring->sli.sli3.rspidx = 0;
  3628. lpfc_sli_pcimem_bcopy((uint32_t *) entry,
  3629. (uint32_t *) &rspiocbq.iocb,
  3630. phba->iocb_rsp_size);
  3631. INIT_LIST_HEAD(&(rspiocbq.list));
  3632. irsp = &rspiocbq.iocb;
  3633. type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
  3634. pring->stats.iocb_rsp++;
  3635. rsp_cmpl++;
  3636. if (unlikely(irsp->ulpStatus)) {
  3637. /*
  3638. * If resource errors reported from HBA, reduce
  3639. * queuedepths of the SCSI device.
  3640. */
  3641. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  3642. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  3643. IOERR_NO_RESOURCES)) {
  3644. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3645. phba->lpfc_rampdown_queue_depth(phba);
  3646. spin_lock_irqsave(&phba->hbalock, iflag);
  3647. }
  3648. /* Rsp ring <ringno> error: IOCB */
  3649. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  3650. "0336 Rsp Ring %d error: IOCB Data: "
  3651. "x%x x%x x%x x%x x%x x%x x%x x%x\n",
  3652. pring->ringno,
  3653. irsp->un.ulpWord[0],
  3654. irsp->un.ulpWord[1],
  3655. irsp->un.ulpWord[2],
  3656. irsp->un.ulpWord[3],
  3657. irsp->un.ulpWord[4],
  3658. irsp->un.ulpWord[5],
  3659. *(uint32_t *)&irsp->un1,
  3660. *((uint32_t *)&irsp->un1 + 1));
  3661. }
  3662. switch (type) {
  3663. case LPFC_ABORT_IOCB:
  3664. case LPFC_SOL_IOCB:
  3665. /*
  3666. * Idle exchange closed via ABTS from port. No iocb
  3667. * resources need to be recovered.
  3668. */
  3669. if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
  3670. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  3671. "0333 IOCB cmd 0x%x"
  3672. " processed. Skipping"
  3673. " completion\n",
  3674. irsp->ulpCommand);
  3675. break;
  3676. }
  3677. cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
  3678. &rspiocbq);
  3679. if (unlikely(!cmdiocbq))
  3680. break;
  3681. if (cmdiocbq->cmd_flag & LPFC_DRIVER_ABORTED)
  3682. cmdiocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
  3683. if (cmdiocbq->cmd_cmpl) {
  3684. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3685. cmdiocbq->cmd_cmpl(phba, cmdiocbq, &rspiocbq);
  3686. spin_lock_irqsave(&phba->hbalock, iflag);
  3687. }
  3688. break;
  3689. case LPFC_UNSOL_IOCB:
  3690. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3691. lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
  3692. spin_lock_irqsave(&phba->hbalock, iflag);
  3693. break;
  3694. default:
  3695. if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
  3696. char adaptermsg[LPFC_MAX_ADPTMSG];
  3697. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  3698. memcpy(&adaptermsg[0], (uint8_t *) irsp,
  3699. MAX_MSG_DATA);
  3700. dev_warn(&((phba->pcidev)->dev),
  3701. "lpfc%d: %s\n",
  3702. phba->brd_no, adaptermsg);
  3703. } else {
  3704. /* Unknown IOCB command */
  3705. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3706. "0334 Unknown IOCB command "
  3707. "Data: x%x, x%x x%x x%x x%x\n",
  3708. type, irsp->ulpCommand,
  3709. irsp->ulpStatus,
  3710. irsp->ulpIoTag,
  3711. irsp->ulpContext);
  3712. }
  3713. break;
  3714. }
  3715. /*
  3716. * The response IOCB has been processed. Update the ring
  3717. * pointer in SLIM. If the port response put pointer has not
  3718. * been updated, sync the pgp->rspPutInx and fetch the new port
  3719. * response put pointer.
  3720. */
  3721. writel(pring->sli.sli3.rspidx,
  3722. &phba->host_gp[pring->ringno].rspGetInx);
  3723. if (pring->sli.sli3.rspidx == portRspPut)
  3724. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3725. }
  3726. if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
  3727. pring->stats.iocb_rsp_full++;
  3728. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  3729. writel(status, phba->CAregaddr);
  3730. readl(phba->CAregaddr);
  3731. }
  3732. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  3733. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  3734. pring->stats.iocb_cmd_empty++;
  3735. /* Force update of the local copy of cmdGetInx */
  3736. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  3737. lpfc_sli_resume_iocb(phba, pring);
  3738. if ((pring->lpfc_sli_cmd_available))
  3739. (pring->lpfc_sli_cmd_available) (phba, pring);
  3740. }
  3741. phba->fcp_ring_in_use = 0;
  3742. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3743. return rc;
  3744. }
  3745. /**
  3746. * lpfc_sli_sp_handle_rspiocb - Handle slow-path response iocb
  3747. * @phba: Pointer to HBA context object.
  3748. * @pring: Pointer to driver SLI ring object.
  3749. * @rspiocbp: Pointer to driver response IOCB object.
  3750. *
  3751. * This function is called from the worker thread when there is a slow-path
  3752. * response IOCB to process. This function chains all the response iocbs until
  3753. * seeing the iocb with the LE bit set. The function will call
  3754. * lpfc_sli_process_sol_iocb function if the response iocb indicates a
  3755. * completion of a command iocb. The function will call the
  3756. * lpfc_sli_process_unsol_iocb function if this is an unsolicited iocb.
  3757. * The function frees the resources or calls the completion handler if this
  3758. * iocb is an abort completion. The function returns NULL when the response
  3759. * iocb has the LE bit set and all the chained iocbs are processed, otherwise
  3760. * this function shall chain the iocb on to the iocb_continueq and return the
  3761. * response iocb passed in.
  3762. **/
  3763. static struct lpfc_iocbq *
  3764. lpfc_sli_sp_handle_rspiocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  3765. struct lpfc_iocbq *rspiocbp)
  3766. {
  3767. struct lpfc_iocbq *saveq;
  3768. struct lpfc_iocbq *cmdiocb;
  3769. struct lpfc_iocbq *next_iocb;
  3770. IOCB_t *irsp;
  3771. uint32_t free_saveq;
  3772. u8 cmd_type;
  3773. lpfc_iocb_type type;
  3774. unsigned long iflag;
  3775. u32 ulp_status = get_job_ulpstatus(phba, rspiocbp);
  3776. u32 ulp_word4 = get_job_word4(phba, rspiocbp);
  3777. u32 ulp_command = get_job_cmnd(phba, rspiocbp);
  3778. int rc;
  3779. spin_lock_irqsave(&phba->hbalock, iflag);
  3780. /* First add the response iocb to the countinueq list */
  3781. list_add_tail(&rspiocbp->list, &pring->iocb_continueq);
  3782. pring->iocb_continueq_cnt++;
  3783. /*
  3784. * By default, the driver expects to free all resources
  3785. * associated with this iocb completion.
  3786. */
  3787. free_saveq = 1;
  3788. saveq = list_get_first(&pring->iocb_continueq,
  3789. struct lpfc_iocbq, list);
  3790. list_del_init(&pring->iocb_continueq);
  3791. pring->iocb_continueq_cnt = 0;
  3792. pring->stats.iocb_rsp++;
  3793. /*
  3794. * If resource errors reported from HBA, reduce
  3795. * queuedepths of the SCSI device.
  3796. */
  3797. if (ulp_status == IOSTAT_LOCAL_REJECT &&
  3798. ((ulp_word4 & IOERR_PARAM_MASK) ==
  3799. IOERR_NO_RESOURCES)) {
  3800. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3801. phba->lpfc_rampdown_queue_depth(phba);
  3802. spin_lock_irqsave(&phba->hbalock, iflag);
  3803. }
  3804. if (ulp_status) {
  3805. /* Rsp ring <ringno> error: IOCB */
  3806. if (phba->sli_rev < LPFC_SLI_REV4) {
  3807. irsp = &rspiocbp->iocb;
  3808. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  3809. "0328 Rsp Ring %d error: ulp_status x%x "
  3810. "IOCB Data: "
  3811. "x%08x x%08x x%08x x%08x "
  3812. "x%08x x%08x x%08x x%08x "
  3813. "x%08x x%08x x%08x x%08x "
  3814. "x%08x x%08x x%08x x%08x\n",
  3815. pring->ringno, ulp_status,
  3816. get_job_ulpword(rspiocbp, 0),
  3817. get_job_ulpword(rspiocbp, 1),
  3818. get_job_ulpword(rspiocbp, 2),
  3819. get_job_ulpword(rspiocbp, 3),
  3820. get_job_ulpword(rspiocbp, 4),
  3821. get_job_ulpword(rspiocbp, 5),
  3822. *(((uint32_t *)irsp) + 6),
  3823. *(((uint32_t *)irsp) + 7),
  3824. *(((uint32_t *)irsp) + 8),
  3825. *(((uint32_t *)irsp) + 9),
  3826. *(((uint32_t *)irsp) + 10),
  3827. *(((uint32_t *)irsp) + 11),
  3828. *(((uint32_t *)irsp) + 12),
  3829. *(((uint32_t *)irsp) + 13),
  3830. *(((uint32_t *)irsp) + 14),
  3831. *(((uint32_t *)irsp) + 15));
  3832. } else {
  3833. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  3834. "0321 Rsp Ring %d error: "
  3835. "IOCB Data: "
  3836. "x%x x%x x%x x%x\n",
  3837. pring->ringno,
  3838. rspiocbp->wcqe_cmpl.word0,
  3839. rspiocbp->wcqe_cmpl.total_data_placed,
  3840. rspiocbp->wcqe_cmpl.parameter,
  3841. rspiocbp->wcqe_cmpl.word3);
  3842. }
  3843. }
  3844. /*
  3845. * Fetch the iocb command type and call the correct completion
  3846. * routine. Solicited and Unsolicited IOCBs on the ELS ring
  3847. * get freed back to the lpfc_iocb_list by the discovery
  3848. * kernel thread.
  3849. */
  3850. cmd_type = ulp_command & CMD_IOCB_MASK;
  3851. type = lpfc_sli_iocb_cmd_type(cmd_type);
  3852. switch (type) {
  3853. case LPFC_SOL_IOCB:
  3854. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3855. rc = lpfc_sli_process_sol_iocb(phba, pring, saveq);
  3856. spin_lock_irqsave(&phba->hbalock, iflag);
  3857. break;
  3858. case LPFC_UNSOL_IOCB:
  3859. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3860. rc = lpfc_sli_process_unsol_iocb(phba, pring, saveq);
  3861. spin_lock_irqsave(&phba->hbalock, iflag);
  3862. if (!rc)
  3863. free_saveq = 0;
  3864. break;
  3865. case LPFC_ABORT_IOCB:
  3866. cmdiocb = NULL;
  3867. if (ulp_command != CMD_XRI_ABORTED_CX)
  3868. cmdiocb = lpfc_sli_iocbq_lookup(phba, pring,
  3869. saveq);
  3870. if (cmdiocb) {
  3871. /* Call the specified completion routine */
  3872. if (cmdiocb->cmd_cmpl) {
  3873. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3874. cmdiocb->cmd_cmpl(phba, cmdiocb, saveq);
  3875. spin_lock_irqsave(&phba->hbalock, iflag);
  3876. } else {
  3877. __lpfc_sli_release_iocbq(phba, cmdiocb);
  3878. }
  3879. }
  3880. break;
  3881. case LPFC_UNKNOWN_IOCB:
  3882. if (ulp_command == CMD_ADAPTER_MSG) {
  3883. char adaptermsg[LPFC_MAX_ADPTMSG];
  3884. memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
  3885. memcpy(&adaptermsg[0], (uint8_t *)&rspiocbp->wqe,
  3886. MAX_MSG_DATA);
  3887. dev_warn(&((phba->pcidev)->dev),
  3888. "lpfc%d: %s\n",
  3889. phba->brd_no, adaptermsg);
  3890. } else {
  3891. /* Unknown command */
  3892. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3893. "0335 Unknown IOCB "
  3894. "command Data: x%x "
  3895. "x%x x%x x%x\n",
  3896. ulp_command,
  3897. ulp_status,
  3898. get_wqe_reqtag(rspiocbp),
  3899. get_job_ulpcontext(phba, rspiocbp));
  3900. }
  3901. break;
  3902. }
  3903. if (free_saveq) {
  3904. list_for_each_entry_safe(rspiocbp, next_iocb,
  3905. &saveq->list, list) {
  3906. list_del_init(&rspiocbp->list);
  3907. __lpfc_sli_release_iocbq(phba, rspiocbp);
  3908. }
  3909. __lpfc_sli_release_iocbq(phba, saveq);
  3910. }
  3911. rspiocbp = NULL;
  3912. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3913. return rspiocbp;
  3914. }
  3915. /**
  3916. * lpfc_sli_handle_slow_ring_event - Wrapper func for handling slow-path iocbs
  3917. * @phba: Pointer to HBA context object.
  3918. * @pring: Pointer to driver SLI ring object.
  3919. * @mask: Host attention register mask for this ring.
  3920. *
  3921. * This routine wraps the actual slow_ring event process routine from the
  3922. * API jump table function pointer from the lpfc_hba struct.
  3923. **/
  3924. void
  3925. lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
  3926. struct lpfc_sli_ring *pring, uint32_t mask)
  3927. {
  3928. phba->lpfc_sli_handle_slow_ring_event(phba, pring, mask);
  3929. }
  3930. /**
  3931. * lpfc_sli_handle_slow_ring_event_s3 - Handle SLI3 ring event for non-FCP rings
  3932. * @phba: Pointer to HBA context object.
  3933. * @pring: Pointer to driver SLI ring object.
  3934. * @mask: Host attention register mask for this ring.
  3935. *
  3936. * This function is called from the worker thread when there is a ring event
  3937. * for non-fcp rings. The caller does not hold any lock. The function will
  3938. * remove each response iocb in the response ring and calls the handle
  3939. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  3940. **/
  3941. static void
  3942. lpfc_sli_handle_slow_ring_event_s3(struct lpfc_hba *phba,
  3943. struct lpfc_sli_ring *pring, uint32_t mask)
  3944. {
  3945. struct lpfc_pgp *pgp;
  3946. IOCB_t *entry;
  3947. IOCB_t *irsp = NULL;
  3948. struct lpfc_iocbq *rspiocbp = NULL;
  3949. uint32_t portRspPut, portRspMax;
  3950. unsigned long iflag;
  3951. uint32_t status;
  3952. pgp = &phba->port_gp[pring->ringno];
  3953. spin_lock_irqsave(&phba->hbalock, iflag);
  3954. pring->stats.iocb_event++;
  3955. /*
  3956. * The next available response entry should never exceed the maximum
  3957. * entries. If it does, treat it as an adapter hardware error.
  3958. */
  3959. portRspMax = pring->sli.sli3.numRiocb;
  3960. portRspPut = le32_to_cpu(pgp->rspPutInx);
  3961. if (portRspPut >= portRspMax) {
  3962. /*
  3963. * Ring <ringno> handler: portRspPut <portRspPut> is bigger than
  3964. * rsp ring <portRspMax>
  3965. */
  3966. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  3967. "0303 Ring %d handler: portRspPut %d "
  3968. "is bigger than rsp ring %d\n",
  3969. pring->ringno, portRspPut, portRspMax);
  3970. phba->link_state = LPFC_HBA_ERROR;
  3971. spin_unlock_irqrestore(&phba->hbalock, iflag);
  3972. phba->work_hs = HS_FFER3;
  3973. lpfc_handle_eratt(phba);
  3974. return;
  3975. }
  3976. rmb();
  3977. while (pring->sli.sli3.rspidx != portRspPut) {
  3978. /*
  3979. * Build a completion list and call the appropriate handler.
  3980. * The process is to get the next available response iocb, get
  3981. * a free iocb from the list, copy the response data into the
  3982. * free iocb, insert to the continuation list, and update the
  3983. * next response index to slim. This process makes response
  3984. * iocb's in the ring available to DMA as fast as possible but
  3985. * pays a penalty for a copy operation. Since the iocb is
  3986. * only 32 bytes, this penalty is considered small relative to
  3987. * the PCI reads for register values and a slim write. When
  3988. * the ulpLe field is set, the entire Command has been
  3989. * received.
  3990. */
  3991. entry = lpfc_resp_iocb(phba, pring);
  3992. phba->last_completion_time = jiffies;
  3993. rspiocbp = __lpfc_sli_get_iocbq(phba);
  3994. if (rspiocbp == NULL) {
  3995. printk(KERN_ERR "%s: out of buffers! Failing "
  3996. "completion.\n", __func__);
  3997. break;
  3998. }
  3999. lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
  4000. phba->iocb_rsp_size);
  4001. irsp = &rspiocbp->iocb;
  4002. if (++pring->sli.sli3.rspidx >= portRspMax)
  4003. pring->sli.sli3.rspidx = 0;
  4004. if (pring->ringno == LPFC_ELS_RING) {
  4005. lpfc_debugfs_slow_ring_trc(phba,
  4006. "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
  4007. *(((uint32_t *) irsp) + 4),
  4008. *(((uint32_t *) irsp) + 6),
  4009. *(((uint32_t *) irsp) + 7));
  4010. }
  4011. writel(pring->sli.sli3.rspidx,
  4012. &phba->host_gp[pring->ringno].rspGetInx);
  4013. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4014. /* Handle the response IOCB */
  4015. rspiocbp = lpfc_sli_sp_handle_rspiocb(phba, pring, rspiocbp);
  4016. spin_lock_irqsave(&phba->hbalock, iflag);
  4017. /*
  4018. * If the port response put pointer has not been updated, sync
  4019. * the pgp->rspPutInx in the MAILBOX_tand fetch the new port
  4020. * response put pointer.
  4021. */
  4022. if (pring->sli.sli3.rspidx == portRspPut) {
  4023. portRspPut = le32_to_cpu(pgp->rspPutInx);
  4024. }
  4025. } /* while (pring->sli.sli3.rspidx != portRspPut) */
  4026. if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
  4027. /* At least one response entry has been freed */
  4028. pring->stats.iocb_rsp_full++;
  4029. /* SET RxRE_RSP in Chip Att register */
  4030. status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
  4031. writel(status, phba->CAregaddr);
  4032. readl(phba->CAregaddr); /* flush */
  4033. }
  4034. if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
  4035. pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
  4036. pring->stats.iocb_cmd_empty++;
  4037. /* Force update of the local copy of cmdGetInx */
  4038. pring->sli.sli3.local_getidx = le32_to_cpu(pgp->cmdGetInx);
  4039. lpfc_sli_resume_iocb(phba, pring);
  4040. if ((pring->lpfc_sli_cmd_available))
  4041. (pring->lpfc_sli_cmd_available) (phba, pring);
  4042. }
  4043. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4044. return;
  4045. }
  4046. /**
  4047. * lpfc_sli_handle_slow_ring_event_s4 - Handle SLI4 slow-path els events
  4048. * @phba: Pointer to HBA context object.
  4049. * @pring: Pointer to driver SLI ring object.
  4050. * @mask: Host attention register mask for this ring.
  4051. *
  4052. * This function is called from the worker thread when there is a pending
  4053. * ELS response iocb on the driver internal slow-path response iocb worker
  4054. * queue. The caller does not hold any lock. The function will remove each
  4055. * response iocb from the response worker queue and calls the handle
  4056. * response iocb routine (lpfc_sli_sp_handle_rspiocb) to process it.
  4057. **/
  4058. static void
  4059. lpfc_sli_handle_slow_ring_event_s4(struct lpfc_hba *phba,
  4060. struct lpfc_sli_ring *pring, uint32_t mask)
  4061. {
  4062. struct lpfc_iocbq *irspiocbq;
  4063. struct hbq_dmabuf *dmabuf;
  4064. struct lpfc_cq_event *cq_event;
  4065. unsigned long iflag;
  4066. int count = 0;
  4067. spin_lock_irqsave(&phba->hbalock, iflag);
  4068. phba->hba_flag &= ~HBA_SP_QUEUE_EVT;
  4069. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4070. while (!list_empty(&phba->sli4_hba.sp_queue_event)) {
  4071. /* Get the response iocb from the head of work queue */
  4072. spin_lock_irqsave(&phba->hbalock, iflag);
  4073. list_remove_head(&phba->sli4_hba.sp_queue_event,
  4074. cq_event, struct lpfc_cq_event, list);
  4075. spin_unlock_irqrestore(&phba->hbalock, iflag);
  4076. switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) {
  4077. case CQE_CODE_COMPL_WQE:
  4078. irspiocbq = container_of(cq_event, struct lpfc_iocbq,
  4079. cq_event);
  4080. /* Translate ELS WCQE to response IOCBQ */
  4081. irspiocbq = lpfc_sli4_els_preprocess_rspiocbq(phba,
  4082. irspiocbq);
  4083. if (irspiocbq)
  4084. lpfc_sli_sp_handle_rspiocb(phba, pring,
  4085. irspiocbq);
  4086. count++;
  4087. break;
  4088. case CQE_CODE_RECEIVE:
  4089. case CQE_CODE_RECEIVE_V1:
  4090. dmabuf = container_of(cq_event, struct hbq_dmabuf,
  4091. cq_event);
  4092. lpfc_sli4_handle_received_buffer(phba, dmabuf);
  4093. count++;
  4094. break;
  4095. default:
  4096. break;
  4097. }
  4098. /* Limit the number of events to 64 to avoid soft lockups */
  4099. if (count == 64)
  4100. break;
  4101. }
  4102. }
  4103. /**
  4104. * lpfc_sli_abort_iocb_ring - Abort all iocbs in the ring
  4105. * @phba: Pointer to HBA context object.
  4106. * @pring: Pointer to driver SLI ring object.
  4107. *
  4108. * This function aborts all iocbs in the given ring and frees all the iocb
  4109. * objects in txq. This function issues an abort iocb for all the iocb commands
  4110. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  4111. * the return of this function. The caller is not required to hold any locks.
  4112. **/
  4113. void
  4114. lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
  4115. {
  4116. LIST_HEAD(tx_completions);
  4117. LIST_HEAD(txcmplq_completions);
  4118. struct lpfc_iocbq *iocb, *next_iocb;
  4119. int offline;
  4120. if (pring->ringno == LPFC_ELS_RING) {
  4121. lpfc_fabric_abort_hba(phba);
  4122. }
  4123. offline = pci_channel_offline(phba->pcidev);
  4124. /* Error everything on txq and txcmplq
  4125. * First do the txq.
  4126. */
  4127. if (phba->sli_rev >= LPFC_SLI_REV4) {
  4128. spin_lock_irq(&pring->ring_lock);
  4129. list_splice_init(&pring->txq, &tx_completions);
  4130. pring->txq_cnt = 0;
  4131. if (offline) {
  4132. list_splice_init(&pring->txcmplq,
  4133. &txcmplq_completions);
  4134. } else {
  4135. /* Next issue ABTS for everything on the txcmplq */
  4136. list_for_each_entry_safe(iocb, next_iocb,
  4137. &pring->txcmplq, list)
  4138. lpfc_sli_issue_abort_iotag(phba, pring,
  4139. iocb, NULL);
  4140. }
  4141. spin_unlock_irq(&pring->ring_lock);
  4142. } else {
  4143. spin_lock_irq(&phba->hbalock);
  4144. list_splice_init(&pring->txq, &tx_completions);
  4145. pring->txq_cnt = 0;
  4146. if (offline) {
  4147. list_splice_init(&pring->txcmplq, &txcmplq_completions);
  4148. } else {
  4149. /* Next issue ABTS for everything on the txcmplq */
  4150. list_for_each_entry_safe(iocb, next_iocb,
  4151. &pring->txcmplq, list)
  4152. lpfc_sli_issue_abort_iotag(phba, pring,
  4153. iocb, NULL);
  4154. }
  4155. spin_unlock_irq(&phba->hbalock);
  4156. }
  4157. if (offline) {
  4158. /* Cancel all the IOCBs from the completions list */
  4159. lpfc_sli_cancel_iocbs(phba, &txcmplq_completions,
  4160. IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
  4161. } else {
  4162. /* Make sure HBA is alive */
  4163. lpfc_issue_hb_tmo(phba);
  4164. }
  4165. /* Cancel all the IOCBs from the completions list */
  4166. lpfc_sli_cancel_iocbs(phba, &tx_completions, IOSTAT_LOCAL_REJECT,
  4167. IOERR_SLI_ABORTED);
  4168. }
  4169. /**
  4170. * lpfc_sli_abort_fcp_rings - Abort all iocbs in all FCP rings
  4171. * @phba: Pointer to HBA context object.
  4172. *
  4173. * This function aborts all iocbs in FCP rings and frees all the iocb
  4174. * objects in txq. This function issues an abort iocb for all the iocb commands
  4175. * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
  4176. * the return of this function. The caller is not required to hold any locks.
  4177. **/
  4178. void
  4179. lpfc_sli_abort_fcp_rings(struct lpfc_hba *phba)
  4180. {
  4181. struct lpfc_sli *psli = &phba->sli;
  4182. struct lpfc_sli_ring *pring;
  4183. uint32_t i;
  4184. /* Look on all the FCP Rings for the iotag */
  4185. if (phba->sli_rev >= LPFC_SLI_REV4) {
  4186. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  4187. pring = phba->sli4_hba.hdwq[i].io_wq->pring;
  4188. lpfc_sli_abort_iocb_ring(phba, pring);
  4189. }
  4190. } else {
  4191. pring = &psli->sli3_ring[LPFC_FCP_RING];
  4192. lpfc_sli_abort_iocb_ring(phba, pring);
  4193. }
  4194. }
  4195. /**
  4196. * lpfc_sli_flush_io_rings - flush all iocbs in the IO ring
  4197. * @phba: Pointer to HBA context object.
  4198. *
  4199. * This function flushes all iocbs in the IO ring and frees all the iocb
  4200. * objects in txq and txcmplq. This function will not issue abort iocbs
  4201. * for all the iocb commands in txcmplq, they will just be returned with
  4202. * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
  4203. * slot has been permanently disabled.
  4204. **/
  4205. void
  4206. lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
  4207. {
  4208. LIST_HEAD(txq);
  4209. LIST_HEAD(txcmplq);
  4210. struct lpfc_sli *psli = &phba->sli;
  4211. struct lpfc_sli_ring *pring;
  4212. uint32_t i;
  4213. struct lpfc_iocbq *piocb, *next_iocb;
  4214. spin_lock_irq(&phba->hbalock);
  4215. /* Indicate the I/O queues are flushed */
  4216. phba->hba_flag |= HBA_IOQ_FLUSH;
  4217. spin_unlock_irq(&phba->hbalock);
  4218. /* Look on all the FCP Rings for the iotag */
  4219. if (phba->sli_rev >= LPFC_SLI_REV4) {
  4220. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  4221. pring = phba->sli4_hba.hdwq[i].io_wq->pring;
  4222. spin_lock_irq(&pring->ring_lock);
  4223. /* Retrieve everything on txq */
  4224. list_splice_init(&pring->txq, &txq);
  4225. list_for_each_entry_safe(piocb, next_iocb,
  4226. &pring->txcmplq, list)
  4227. piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
  4228. /* Retrieve everything on the txcmplq */
  4229. list_splice_init(&pring->txcmplq, &txcmplq);
  4230. pring->txq_cnt = 0;
  4231. pring->txcmplq_cnt = 0;
  4232. spin_unlock_irq(&pring->ring_lock);
  4233. /* Flush the txq */
  4234. lpfc_sli_cancel_iocbs(phba, &txq,
  4235. IOSTAT_LOCAL_REJECT,
  4236. IOERR_SLI_DOWN);
  4237. /* Flush the txcmplq */
  4238. lpfc_sli_cancel_iocbs(phba, &txcmplq,
  4239. IOSTAT_LOCAL_REJECT,
  4240. IOERR_SLI_DOWN);
  4241. if (unlikely(pci_channel_offline(phba->pcidev)))
  4242. lpfc_sli4_io_xri_aborted(phba, NULL, 0);
  4243. }
  4244. } else {
  4245. pring = &psli->sli3_ring[LPFC_FCP_RING];
  4246. spin_lock_irq(&phba->hbalock);
  4247. /* Retrieve everything on txq */
  4248. list_splice_init(&pring->txq, &txq);
  4249. list_for_each_entry_safe(piocb, next_iocb,
  4250. &pring->txcmplq, list)
  4251. piocb->cmd_flag &= ~LPFC_IO_ON_TXCMPLQ;
  4252. /* Retrieve everything on the txcmplq */
  4253. list_splice_init(&pring->txcmplq, &txcmplq);
  4254. pring->txq_cnt = 0;
  4255. pring->txcmplq_cnt = 0;
  4256. spin_unlock_irq(&phba->hbalock);
  4257. /* Flush the txq */
  4258. lpfc_sli_cancel_iocbs(phba, &txq, IOSTAT_LOCAL_REJECT,
  4259. IOERR_SLI_DOWN);
  4260. /* Flush the txcmpq */
  4261. lpfc_sli_cancel_iocbs(phba, &txcmplq, IOSTAT_LOCAL_REJECT,
  4262. IOERR_SLI_DOWN);
  4263. }
  4264. }
  4265. /**
  4266. * lpfc_sli_brdready_s3 - Check for sli3 host ready status
  4267. * @phba: Pointer to HBA context object.
  4268. * @mask: Bit mask to be checked.
  4269. *
  4270. * This function reads the host status register and compares
  4271. * with the provided bit mask to check if HBA completed
  4272. * the restart. This function will wait in a loop for the
  4273. * HBA to complete restart. If the HBA does not restart within
  4274. * 15 iterations, the function will reset the HBA again. The
  4275. * function returns 1 when HBA fail to restart otherwise returns
  4276. * zero.
  4277. **/
  4278. static int
  4279. lpfc_sli_brdready_s3(struct lpfc_hba *phba, uint32_t mask)
  4280. {
  4281. uint32_t status;
  4282. int i = 0;
  4283. int retval = 0;
  4284. /* Read the HBA Host Status Register */
  4285. if (lpfc_readl(phba->HSregaddr, &status))
  4286. return 1;
  4287. phba->hba_flag |= HBA_NEEDS_CFG_PORT;
  4288. /*
  4289. * Check status register every 100ms for 5 retries, then every
  4290. * 500ms for 5, then every 2.5 sec for 5, then reset board and
  4291. * every 2.5 sec for 4.
  4292. * Break our of the loop if errors occurred during init.
  4293. */
  4294. while (((status & mask) != mask) &&
  4295. !(status & HS_FFERM) &&
  4296. i++ < 20) {
  4297. if (i <= 5)
  4298. msleep(10);
  4299. else if (i <= 10)
  4300. msleep(500);
  4301. else
  4302. msleep(2500);
  4303. if (i == 15) {
  4304. /* Do post */
  4305. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4306. lpfc_sli_brdrestart(phba);
  4307. }
  4308. /* Read the HBA Host Status Register */
  4309. if (lpfc_readl(phba->HSregaddr, &status)) {
  4310. retval = 1;
  4311. break;
  4312. }
  4313. }
  4314. /* Check to see if any errors occurred during init */
  4315. if ((status & HS_FFERM) || (i >= 20)) {
  4316. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4317. "2751 Adapter failed to restart, "
  4318. "status reg x%x, FW Data: A8 x%x AC x%x\n",
  4319. status,
  4320. readl(phba->MBslimaddr + 0xa8),
  4321. readl(phba->MBslimaddr + 0xac));
  4322. phba->link_state = LPFC_HBA_ERROR;
  4323. retval = 1;
  4324. }
  4325. return retval;
  4326. }
  4327. /**
  4328. * lpfc_sli_brdready_s4 - Check for sli4 host ready status
  4329. * @phba: Pointer to HBA context object.
  4330. * @mask: Bit mask to be checked.
  4331. *
  4332. * This function checks the host status register to check if HBA is
  4333. * ready. This function will wait in a loop for the HBA to be ready
  4334. * If the HBA is not ready , the function will will reset the HBA PCI
  4335. * function again. The function returns 1 when HBA fail to be ready
  4336. * otherwise returns zero.
  4337. **/
  4338. static int
  4339. lpfc_sli_brdready_s4(struct lpfc_hba *phba, uint32_t mask)
  4340. {
  4341. uint32_t status;
  4342. int retval = 0;
  4343. /* Read the HBA Host Status Register */
  4344. status = lpfc_sli4_post_status_check(phba);
  4345. if (status) {
  4346. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4347. lpfc_sli_brdrestart(phba);
  4348. status = lpfc_sli4_post_status_check(phba);
  4349. }
  4350. /* Check to see if any errors occurred during init */
  4351. if (status) {
  4352. phba->link_state = LPFC_HBA_ERROR;
  4353. retval = 1;
  4354. } else
  4355. phba->sli4_hba.intr_enable = 0;
  4356. phba->hba_flag &= ~HBA_SETUP;
  4357. return retval;
  4358. }
  4359. /**
  4360. * lpfc_sli_brdready - Wrapper func for checking the hba readyness
  4361. * @phba: Pointer to HBA context object.
  4362. * @mask: Bit mask to be checked.
  4363. *
  4364. * This routine wraps the actual SLI3 or SLI4 hba readyness check routine
  4365. * from the API jump table function pointer from the lpfc_hba struct.
  4366. **/
  4367. int
  4368. lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
  4369. {
  4370. return phba->lpfc_sli_brdready(phba, mask);
  4371. }
  4372. #define BARRIER_TEST_PATTERN (0xdeadbeef)
  4373. /**
  4374. * lpfc_reset_barrier - Make HBA ready for HBA reset
  4375. * @phba: Pointer to HBA context object.
  4376. *
  4377. * This function is called before resetting an HBA. This function is called
  4378. * with hbalock held and requests HBA to quiesce DMAs before a reset.
  4379. **/
  4380. void lpfc_reset_barrier(struct lpfc_hba *phba)
  4381. {
  4382. uint32_t __iomem *resp_buf;
  4383. uint32_t __iomem *mbox_buf;
  4384. volatile struct MAILBOX_word0 mbox;
  4385. uint32_t hc_copy, ha_copy, resp_data;
  4386. int i;
  4387. uint8_t hdrtype;
  4388. lockdep_assert_held(&phba->hbalock);
  4389. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  4390. if (hdrtype != 0x80 ||
  4391. (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
  4392. FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
  4393. return;
  4394. /*
  4395. * Tell the other part of the chip to suspend temporarily all
  4396. * its DMA activity.
  4397. */
  4398. resp_buf = phba->MBslimaddr;
  4399. /* Disable the error attention */
  4400. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  4401. return;
  4402. writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
  4403. readl(phba->HCregaddr); /* flush */
  4404. phba->link_flag |= LS_IGNORE_ERATT;
  4405. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  4406. return;
  4407. if (ha_copy & HA_ERATT) {
  4408. /* Clear Chip error bit */
  4409. writel(HA_ERATT, phba->HAregaddr);
  4410. phba->pport->stopped = 1;
  4411. }
  4412. mbox.word0 = 0;
  4413. mbox.mbxCommand = MBX_KILL_BOARD;
  4414. mbox.mbxOwner = OWN_CHIP;
  4415. writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
  4416. mbox_buf = phba->MBslimaddr;
  4417. writel(mbox.word0, mbox_buf);
  4418. for (i = 0; i < 50; i++) {
  4419. if (lpfc_readl((resp_buf + 1), &resp_data))
  4420. return;
  4421. if (resp_data != ~(BARRIER_TEST_PATTERN))
  4422. mdelay(1);
  4423. else
  4424. break;
  4425. }
  4426. resp_data = 0;
  4427. if (lpfc_readl((resp_buf + 1), &resp_data))
  4428. return;
  4429. if (resp_data != ~(BARRIER_TEST_PATTERN)) {
  4430. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE ||
  4431. phba->pport->stopped)
  4432. goto restore_hc;
  4433. else
  4434. goto clear_errat;
  4435. }
  4436. mbox.mbxOwner = OWN_HOST;
  4437. resp_data = 0;
  4438. for (i = 0; i < 500; i++) {
  4439. if (lpfc_readl(resp_buf, &resp_data))
  4440. return;
  4441. if (resp_data != mbox.word0)
  4442. mdelay(1);
  4443. else
  4444. break;
  4445. }
  4446. clear_errat:
  4447. while (++i < 500) {
  4448. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  4449. return;
  4450. if (!(ha_copy & HA_ERATT))
  4451. mdelay(1);
  4452. else
  4453. break;
  4454. }
  4455. if (readl(phba->HAregaddr) & HA_ERATT) {
  4456. writel(HA_ERATT, phba->HAregaddr);
  4457. phba->pport->stopped = 1;
  4458. }
  4459. restore_hc:
  4460. phba->link_flag &= ~LS_IGNORE_ERATT;
  4461. writel(hc_copy, phba->HCregaddr);
  4462. readl(phba->HCregaddr); /* flush */
  4463. }
  4464. /**
  4465. * lpfc_sli_brdkill - Issue a kill_board mailbox command
  4466. * @phba: Pointer to HBA context object.
  4467. *
  4468. * This function issues a kill_board mailbox command and waits for
  4469. * the error attention interrupt. This function is called for stopping
  4470. * the firmware processing. The caller is not required to hold any
  4471. * locks. This function calls lpfc_hba_down_post function to free
  4472. * any pending commands after the kill. The function will return 1 when it
  4473. * fails to kill the board else will return 0.
  4474. **/
  4475. int
  4476. lpfc_sli_brdkill(struct lpfc_hba *phba)
  4477. {
  4478. struct lpfc_sli *psli;
  4479. LPFC_MBOXQ_t *pmb;
  4480. uint32_t status;
  4481. uint32_t ha_copy;
  4482. int retval;
  4483. int i = 0;
  4484. psli = &phba->sli;
  4485. /* Kill HBA */
  4486. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4487. "0329 Kill HBA Data: x%x x%x\n",
  4488. phba->pport->port_state, psli->sli_flag);
  4489. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4490. if (!pmb)
  4491. return 1;
  4492. /* Disable the error attention */
  4493. spin_lock_irq(&phba->hbalock);
  4494. if (lpfc_readl(phba->HCregaddr, &status)) {
  4495. spin_unlock_irq(&phba->hbalock);
  4496. mempool_free(pmb, phba->mbox_mem_pool);
  4497. return 1;
  4498. }
  4499. status &= ~HC_ERINT_ENA;
  4500. writel(status, phba->HCregaddr);
  4501. readl(phba->HCregaddr); /* flush */
  4502. phba->link_flag |= LS_IGNORE_ERATT;
  4503. spin_unlock_irq(&phba->hbalock);
  4504. lpfc_kill_board(phba, pmb);
  4505. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  4506. retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  4507. if (retval != MBX_SUCCESS) {
  4508. if (retval != MBX_BUSY)
  4509. mempool_free(pmb, phba->mbox_mem_pool);
  4510. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4511. "2752 KILL_BOARD command failed retval %d\n",
  4512. retval);
  4513. spin_lock_irq(&phba->hbalock);
  4514. phba->link_flag &= ~LS_IGNORE_ERATT;
  4515. spin_unlock_irq(&phba->hbalock);
  4516. return 1;
  4517. }
  4518. spin_lock_irq(&phba->hbalock);
  4519. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  4520. spin_unlock_irq(&phba->hbalock);
  4521. mempool_free(pmb, phba->mbox_mem_pool);
  4522. /* There is no completion for a KILL_BOARD mbox cmd. Check for an error
  4523. * attention every 100ms for 3 seconds. If we don't get ERATT after
  4524. * 3 seconds we still set HBA_ERROR state because the status of the
  4525. * board is now undefined.
  4526. */
  4527. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  4528. return 1;
  4529. while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
  4530. mdelay(100);
  4531. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  4532. return 1;
  4533. }
  4534. del_timer_sync(&psli->mbox_tmo);
  4535. if (ha_copy & HA_ERATT) {
  4536. writel(HA_ERATT, phba->HAregaddr);
  4537. phba->pport->stopped = 1;
  4538. }
  4539. spin_lock_irq(&phba->hbalock);
  4540. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  4541. psli->mbox_active = NULL;
  4542. phba->link_flag &= ~LS_IGNORE_ERATT;
  4543. spin_unlock_irq(&phba->hbalock);
  4544. lpfc_hba_down_post(phba);
  4545. phba->link_state = LPFC_HBA_ERROR;
  4546. return ha_copy & HA_ERATT ? 0 : 1;
  4547. }
  4548. /**
  4549. * lpfc_sli_brdreset - Reset a sli-2 or sli-3 HBA
  4550. * @phba: Pointer to HBA context object.
  4551. *
  4552. * This function resets the HBA by writing HC_INITFF to the control
  4553. * register. After the HBA resets, this function resets all the iocb ring
  4554. * indices. This function disables PCI layer parity checking during
  4555. * the reset.
  4556. * This function returns 0 always.
  4557. * The caller is not required to hold any locks.
  4558. **/
  4559. int
  4560. lpfc_sli_brdreset(struct lpfc_hba *phba)
  4561. {
  4562. struct lpfc_sli *psli;
  4563. struct lpfc_sli_ring *pring;
  4564. uint16_t cfg_value;
  4565. int i;
  4566. psli = &phba->sli;
  4567. /* Reset HBA */
  4568. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4569. "0325 Reset HBA Data: x%x x%x\n",
  4570. (phba->pport) ? phba->pport->port_state : 0,
  4571. psli->sli_flag);
  4572. /* perform board reset */
  4573. phba->fc_eventTag = 0;
  4574. phba->link_events = 0;
  4575. phba->hba_flag |= HBA_NEEDS_CFG_PORT;
  4576. if (phba->pport) {
  4577. phba->pport->fc_myDID = 0;
  4578. phba->pport->fc_prevDID = 0;
  4579. }
  4580. /* Turn off parity checking and serr during the physical reset */
  4581. if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value))
  4582. return -EIO;
  4583. pci_write_config_word(phba->pcidev, PCI_COMMAND,
  4584. (cfg_value &
  4585. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  4586. psli->sli_flag &= ~(LPFC_SLI_ACTIVE | LPFC_PROCESS_LA);
  4587. /* Now toggle INITFF bit in the Host Control Register */
  4588. writel(HC_INITFF, phba->HCregaddr);
  4589. mdelay(1);
  4590. readl(phba->HCregaddr); /* flush */
  4591. writel(0, phba->HCregaddr);
  4592. readl(phba->HCregaddr); /* flush */
  4593. /* Restore PCI cmd register */
  4594. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  4595. /* Initialize relevant SLI info */
  4596. for (i = 0; i < psli->num_rings; i++) {
  4597. pring = &psli->sli3_ring[i];
  4598. pring->flag = 0;
  4599. pring->sli.sli3.rspidx = 0;
  4600. pring->sli.sli3.next_cmdidx = 0;
  4601. pring->sli.sli3.local_getidx = 0;
  4602. pring->sli.sli3.cmdidx = 0;
  4603. pring->missbufcnt = 0;
  4604. }
  4605. phba->link_state = LPFC_WARM_START;
  4606. return 0;
  4607. }
  4608. /**
  4609. * lpfc_sli4_brdreset - Reset a sli-4 HBA
  4610. * @phba: Pointer to HBA context object.
  4611. *
  4612. * This function resets a SLI4 HBA. This function disables PCI layer parity
  4613. * checking during resets the device. The caller is not required to hold
  4614. * any locks.
  4615. *
  4616. * This function returns 0 on success else returns negative error code.
  4617. **/
  4618. int
  4619. lpfc_sli4_brdreset(struct lpfc_hba *phba)
  4620. {
  4621. struct lpfc_sli *psli = &phba->sli;
  4622. uint16_t cfg_value;
  4623. int rc = 0;
  4624. /* Reset HBA */
  4625. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4626. "0295 Reset HBA Data: x%x x%x x%x\n",
  4627. phba->pport->port_state, psli->sli_flag,
  4628. phba->hba_flag);
  4629. /* perform board reset */
  4630. phba->fc_eventTag = 0;
  4631. phba->link_events = 0;
  4632. phba->pport->fc_myDID = 0;
  4633. phba->pport->fc_prevDID = 0;
  4634. phba->hba_flag &= ~HBA_SETUP;
  4635. spin_lock_irq(&phba->hbalock);
  4636. psli->sli_flag &= ~(LPFC_PROCESS_LA);
  4637. phba->fcf.fcf_flag = 0;
  4638. spin_unlock_irq(&phba->hbalock);
  4639. /* Now physically reset the device */
  4640. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4641. "0389 Performing PCI function reset!\n");
  4642. /* Turn off parity checking and serr during the physical reset */
  4643. if (pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value)) {
  4644. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  4645. "3205 PCI read Config failed\n");
  4646. return -EIO;
  4647. }
  4648. pci_write_config_word(phba->pcidev, PCI_COMMAND, (cfg_value &
  4649. ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
  4650. /* Perform FCoE PCI function reset before freeing queue memory */
  4651. rc = lpfc_pci_function_reset(phba);
  4652. /* Restore PCI cmd register */
  4653. pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
  4654. return rc;
  4655. }
  4656. /**
  4657. * lpfc_sli_brdrestart_s3 - Restart a sli-3 hba
  4658. * @phba: Pointer to HBA context object.
  4659. *
  4660. * This function is called in the SLI initialization code path to
  4661. * restart the HBA. The caller is not required to hold any lock.
  4662. * This function writes MBX_RESTART mailbox command to the SLIM and
  4663. * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
  4664. * function to free any pending commands. The function enables
  4665. * POST only during the first initialization. The function returns zero.
  4666. * The function does not guarantee completion of MBX_RESTART mailbox
  4667. * command before the return of this function.
  4668. **/
  4669. static int
  4670. lpfc_sli_brdrestart_s3(struct lpfc_hba *phba)
  4671. {
  4672. volatile struct MAILBOX_word0 mb;
  4673. struct lpfc_sli *psli;
  4674. void __iomem *to_slim;
  4675. uint32_t hba_aer_enabled;
  4676. spin_lock_irq(&phba->hbalock);
  4677. /* Take PCIe device Advanced Error Reporting (AER) state */
  4678. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  4679. psli = &phba->sli;
  4680. /* Restart HBA */
  4681. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4682. "0337 Restart HBA Data: x%x x%x\n",
  4683. (phba->pport) ? phba->pport->port_state : 0,
  4684. psli->sli_flag);
  4685. mb.word0 = 0;
  4686. mb.mbxCommand = MBX_RESTART;
  4687. mb.mbxHc = 1;
  4688. lpfc_reset_barrier(phba);
  4689. to_slim = phba->MBslimaddr;
  4690. writel(mb.word0, to_slim);
  4691. readl(to_slim); /* flush */
  4692. /* Only skip post after fc_ffinit is completed */
  4693. if (phba->pport && phba->pport->port_state)
  4694. mb.word0 = 1; /* This is really setting up word1 */
  4695. else
  4696. mb.word0 = 0; /* This is really setting up word1 */
  4697. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  4698. writel(mb.word0, to_slim);
  4699. readl(to_slim); /* flush */
  4700. lpfc_sli_brdreset(phba);
  4701. if (phba->pport)
  4702. phba->pport->stopped = 0;
  4703. phba->link_state = LPFC_INIT_START;
  4704. phba->hba_flag = 0;
  4705. spin_unlock_irq(&phba->hbalock);
  4706. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  4707. psli->stats_start = ktime_get_seconds();
  4708. /* Give the INITFF and Post time to settle. */
  4709. mdelay(100);
  4710. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  4711. if (hba_aer_enabled)
  4712. pci_disable_pcie_error_reporting(phba->pcidev);
  4713. lpfc_hba_down_post(phba);
  4714. return 0;
  4715. }
  4716. /**
  4717. * lpfc_sli_brdrestart_s4 - Restart the sli-4 hba
  4718. * @phba: Pointer to HBA context object.
  4719. *
  4720. * This function is called in the SLI initialization code path to restart
  4721. * a SLI4 HBA. The caller is not required to hold any lock.
  4722. * At the end of the function, it calls lpfc_hba_down_post function to
  4723. * free any pending commands.
  4724. **/
  4725. static int
  4726. lpfc_sli_brdrestart_s4(struct lpfc_hba *phba)
  4727. {
  4728. struct lpfc_sli *psli = &phba->sli;
  4729. uint32_t hba_aer_enabled;
  4730. int rc;
  4731. /* Restart HBA */
  4732. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  4733. "0296 Restart HBA Data: x%x x%x\n",
  4734. phba->pport->port_state, psli->sli_flag);
  4735. /* Take PCIe device Advanced Error Reporting (AER) state */
  4736. hba_aer_enabled = phba->hba_flag & HBA_AER_ENABLED;
  4737. rc = lpfc_sli4_brdreset(phba);
  4738. if (rc) {
  4739. phba->link_state = LPFC_HBA_ERROR;
  4740. goto hba_down_queue;
  4741. }
  4742. spin_lock_irq(&phba->hbalock);
  4743. phba->pport->stopped = 0;
  4744. phba->link_state = LPFC_INIT_START;
  4745. phba->hba_flag = 0;
  4746. /* Preserve FA-PWWN expectation */
  4747. phba->sli4_hba.fawwpn_flag &= LPFC_FAWWPN_FABRIC;
  4748. spin_unlock_irq(&phba->hbalock);
  4749. memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
  4750. psli->stats_start = ktime_get_seconds();
  4751. /* Reset HBA AER if it was enabled, note hba_flag was reset above */
  4752. if (hba_aer_enabled)
  4753. pci_disable_pcie_error_reporting(phba->pcidev);
  4754. hba_down_queue:
  4755. lpfc_hba_down_post(phba);
  4756. lpfc_sli4_queue_destroy(phba);
  4757. return rc;
  4758. }
  4759. /**
  4760. * lpfc_sli_brdrestart - Wrapper func for restarting hba
  4761. * @phba: Pointer to HBA context object.
  4762. *
  4763. * This routine wraps the actual SLI3 or SLI4 hba restart routine from the
  4764. * API jump table function pointer from the lpfc_hba struct.
  4765. **/
  4766. int
  4767. lpfc_sli_brdrestart(struct lpfc_hba *phba)
  4768. {
  4769. return phba->lpfc_sli_brdrestart(phba);
  4770. }
  4771. /**
  4772. * lpfc_sli_chipset_init - Wait for the restart of the HBA after a restart
  4773. * @phba: Pointer to HBA context object.
  4774. *
  4775. * This function is called after a HBA restart to wait for successful
  4776. * restart of the HBA. Successful restart of the HBA is indicated by
  4777. * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
  4778. * iteration, the function will restart the HBA again. The function returns
  4779. * zero if HBA successfully restarted else returns negative error code.
  4780. **/
  4781. int
  4782. lpfc_sli_chipset_init(struct lpfc_hba *phba)
  4783. {
  4784. uint32_t status, i = 0;
  4785. /* Read the HBA Host Status Register */
  4786. if (lpfc_readl(phba->HSregaddr, &status))
  4787. return -EIO;
  4788. /* Check status register to see what current state is */
  4789. i = 0;
  4790. while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
  4791. /* Check every 10ms for 10 retries, then every 100ms for 90
  4792. * retries, then every 1 sec for 50 retires for a total of
  4793. * ~60 seconds before reset the board again and check every
  4794. * 1 sec for 50 retries. The up to 60 seconds before the
  4795. * board ready is required by the Falcon FIPS zeroization
  4796. * complete, and any reset the board in between shall cause
  4797. * restart of zeroization, further delay the board ready.
  4798. */
  4799. if (i++ >= 200) {
  4800. /* Adapter failed to init, timeout, status reg
  4801. <status> */
  4802. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4803. "0436 Adapter failed to init, "
  4804. "timeout, status reg x%x, "
  4805. "FW Data: A8 x%x AC x%x\n", status,
  4806. readl(phba->MBslimaddr + 0xa8),
  4807. readl(phba->MBslimaddr + 0xac));
  4808. phba->link_state = LPFC_HBA_ERROR;
  4809. return -ETIMEDOUT;
  4810. }
  4811. /* Check to see if any errors occurred during init */
  4812. if (status & HS_FFERM) {
  4813. /* ERROR: During chipset initialization */
  4814. /* Adapter failed to init, chipset, status reg
  4815. <status> */
  4816. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4817. "0437 Adapter failed to init, "
  4818. "chipset, status reg x%x, "
  4819. "FW Data: A8 x%x AC x%x\n", status,
  4820. readl(phba->MBslimaddr + 0xa8),
  4821. readl(phba->MBslimaddr + 0xac));
  4822. phba->link_state = LPFC_HBA_ERROR;
  4823. return -EIO;
  4824. }
  4825. if (i <= 10)
  4826. msleep(10);
  4827. else if (i <= 100)
  4828. msleep(100);
  4829. else
  4830. msleep(1000);
  4831. if (i == 150) {
  4832. /* Do post */
  4833. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  4834. lpfc_sli_brdrestart(phba);
  4835. }
  4836. /* Read the HBA Host Status Register */
  4837. if (lpfc_readl(phba->HSregaddr, &status))
  4838. return -EIO;
  4839. }
  4840. /* Check to see if any errors occurred during init */
  4841. if (status & HS_FFERM) {
  4842. /* ERROR: During chipset initialization */
  4843. /* Adapter failed to init, chipset, status reg <status> */
  4844. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  4845. "0438 Adapter failed to init, chipset, "
  4846. "status reg x%x, "
  4847. "FW Data: A8 x%x AC x%x\n", status,
  4848. readl(phba->MBslimaddr + 0xa8),
  4849. readl(phba->MBslimaddr + 0xac));
  4850. phba->link_state = LPFC_HBA_ERROR;
  4851. return -EIO;
  4852. }
  4853. phba->hba_flag |= HBA_NEEDS_CFG_PORT;
  4854. /* Clear all interrupt enable conditions */
  4855. writel(0, phba->HCregaddr);
  4856. readl(phba->HCregaddr); /* flush */
  4857. /* setup host attn register */
  4858. writel(0xffffffff, phba->HAregaddr);
  4859. readl(phba->HAregaddr); /* flush */
  4860. return 0;
  4861. }
  4862. /**
  4863. * lpfc_sli_hbq_count - Get the number of HBQs to be configured
  4864. *
  4865. * This function calculates and returns the number of HBQs required to be
  4866. * configured.
  4867. **/
  4868. int
  4869. lpfc_sli_hbq_count(void)
  4870. {
  4871. return ARRAY_SIZE(lpfc_hbq_defs);
  4872. }
  4873. /**
  4874. * lpfc_sli_hbq_entry_count - Calculate total number of hbq entries
  4875. *
  4876. * This function adds the number of hbq entries in every HBQ to get
  4877. * the total number of hbq entries required for the HBA and returns
  4878. * the total count.
  4879. **/
  4880. static int
  4881. lpfc_sli_hbq_entry_count(void)
  4882. {
  4883. int hbq_count = lpfc_sli_hbq_count();
  4884. int count = 0;
  4885. int i;
  4886. for (i = 0; i < hbq_count; ++i)
  4887. count += lpfc_hbq_defs[i]->entry_count;
  4888. return count;
  4889. }
  4890. /**
  4891. * lpfc_sli_hbq_size - Calculate memory required for all hbq entries
  4892. *
  4893. * This function calculates amount of memory required for all hbq entries
  4894. * to be configured and returns the total memory required.
  4895. **/
  4896. int
  4897. lpfc_sli_hbq_size(void)
  4898. {
  4899. return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
  4900. }
  4901. /**
  4902. * lpfc_sli_hbq_setup - configure and initialize HBQs
  4903. * @phba: Pointer to HBA context object.
  4904. *
  4905. * This function is called during the SLI initialization to configure
  4906. * all the HBQs and post buffers to the HBQ. The caller is not
  4907. * required to hold any locks. This function will return zero if successful
  4908. * else it will return negative error code.
  4909. **/
  4910. static int
  4911. lpfc_sli_hbq_setup(struct lpfc_hba *phba)
  4912. {
  4913. int hbq_count = lpfc_sli_hbq_count();
  4914. LPFC_MBOXQ_t *pmb;
  4915. MAILBOX_t *pmbox;
  4916. uint32_t hbqno;
  4917. uint32_t hbq_entry_index;
  4918. /* Get a Mailbox buffer to setup mailbox
  4919. * commands for HBA initialization
  4920. */
  4921. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  4922. if (!pmb)
  4923. return -ENOMEM;
  4924. pmbox = &pmb->u.mb;
  4925. /* Initialize the struct lpfc_sli_hbq structure for each hbq */
  4926. phba->link_state = LPFC_INIT_MBX_CMDS;
  4927. phba->hbq_in_use = 1;
  4928. hbq_entry_index = 0;
  4929. for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
  4930. phba->hbqs[hbqno].next_hbqPutIdx = 0;
  4931. phba->hbqs[hbqno].hbqPutIdx = 0;
  4932. phba->hbqs[hbqno].local_hbqGetIdx = 0;
  4933. phba->hbqs[hbqno].entry_count =
  4934. lpfc_hbq_defs[hbqno]->entry_count;
  4935. lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
  4936. hbq_entry_index, pmb);
  4937. hbq_entry_index += phba->hbqs[hbqno].entry_count;
  4938. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  4939. /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
  4940. mbxStatus <status>, ring <num> */
  4941. lpfc_printf_log(phba, KERN_ERR,
  4942. LOG_SLI | LOG_VPORT,
  4943. "1805 Adapter failed to init. "
  4944. "Data: x%x x%x x%x\n",
  4945. pmbox->mbxCommand,
  4946. pmbox->mbxStatus, hbqno);
  4947. phba->link_state = LPFC_HBA_ERROR;
  4948. mempool_free(pmb, phba->mbox_mem_pool);
  4949. return -ENXIO;
  4950. }
  4951. }
  4952. phba->hbq_count = hbq_count;
  4953. mempool_free(pmb, phba->mbox_mem_pool);
  4954. /* Initially populate or replenish the HBQs */
  4955. for (hbqno = 0; hbqno < hbq_count; ++hbqno)
  4956. lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
  4957. return 0;
  4958. }
  4959. /**
  4960. * lpfc_sli4_rb_setup - Initialize and post RBs to HBA
  4961. * @phba: Pointer to HBA context object.
  4962. *
  4963. * This function is called during the SLI initialization to configure
  4964. * all the HBQs and post buffers to the HBQ. The caller is not
  4965. * required to hold any locks. This function will return zero if successful
  4966. * else it will return negative error code.
  4967. **/
  4968. static int
  4969. lpfc_sli4_rb_setup(struct lpfc_hba *phba)
  4970. {
  4971. phba->hbq_in_use = 1;
  4972. /**
  4973. * Specific case when the MDS diagnostics is enabled and supported.
  4974. * The receive buffer count is truncated to manage the incoming
  4975. * traffic.
  4976. **/
  4977. if (phba->cfg_enable_mds_diags && phba->mds_diags_support)
  4978. phba->hbqs[LPFC_ELS_HBQ].entry_count =
  4979. lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count >> 1;
  4980. else
  4981. phba->hbqs[LPFC_ELS_HBQ].entry_count =
  4982. lpfc_hbq_defs[LPFC_ELS_HBQ]->entry_count;
  4983. phba->hbq_count = 1;
  4984. lpfc_sli_hbqbuf_init_hbqs(phba, LPFC_ELS_HBQ);
  4985. /* Initially populate or replenish the HBQs */
  4986. return 0;
  4987. }
  4988. /**
  4989. * lpfc_sli_config_port - Issue config port mailbox command
  4990. * @phba: Pointer to HBA context object.
  4991. * @sli_mode: sli mode - 2/3
  4992. *
  4993. * This function is called by the sli initialization code path
  4994. * to issue config_port mailbox command. This function restarts the
  4995. * HBA firmware and issues a config_port mailbox command to configure
  4996. * the SLI interface in the sli mode specified by sli_mode
  4997. * variable. The caller is not required to hold any locks.
  4998. * The function returns 0 if successful, else returns negative error
  4999. * code.
  5000. **/
  5001. int
  5002. lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
  5003. {
  5004. LPFC_MBOXQ_t *pmb;
  5005. uint32_t resetcount = 0, rc = 0, done = 0;
  5006. pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5007. if (!pmb) {
  5008. phba->link_state = LPFC_HBA_ERROR;
  5009. return -ENOMEM;
  5010. }
  5011. phba->sli_rev = sli_mode;
  5012. while (resetcount < 2 && !done) {
  5013. spin_lock_irq(&phba->hbalock);
  5014. phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  5015. spin_unlock_irq(&phba->hbalock);
  5016. phba->pport->port_state = LPFC_VPORT_UNKNOWN;
  5017. lpfc_sli_brdrestart(phba);
  5018. rc = lpfc_sli_chipset_init(phba);
  5019. if (rc)
  5020. break;
  5021. spin_lock_irq(&phba->hbalock);
  5022. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  5023. spin_unlock_irq(&phba->hbalock);
  5024. resetcount++;
  5025. /* Call pre CONFIG_PORT mailbox command initialization. A
  5026. * value of 0 means the call was successful. Any other
  5027. * nonzero value is a failure, but if ERESTART is returned,
  5028. * the driver may reset the HBA and try again.
  5029. */
  5030. rc = lpfc_config_port_prep(phba);
  5031. if (rc == -ERESTART) {
  5032. phba->link_state = LPFC_LINK_UNKNOWN;
  5033. continue;
  5034. } else if (rc)
  5035. break;
  5036. phba->link_state = LPFC_INIT_MBX_CMDS;
  5037. lpfc_config_port(phba, pmb);
  5038. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  5039. phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
  5040. LPFC_SLI3_HBQ_ENABLED |
  5041. LPFC_SLI3_CRP_ENABLED |
  5042. LPFC_SLI3_DSS_ENABLED);
  5043. if (rc != MBX_SUCCESS) {
  5044. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5045. "0442 Adapter failed to init, mbxCmd x%x "
  5046. "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
  5047. pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus, 0);
  5048. spin_lock_irq(&phba->hbalock);
  5049. phba->sli.sli_flag &= ~LPFC_SLI_ACTIVE;
  5050. spin_unlock_irq(&phba->hbalock);
  5051. rc = -ENXIO;
  5052. } else {
  5053. /* Allow asynchronous mailbox command to go through */
  5054. spin_lock_irq(&phba->hbalock);
  5055. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  5056. spin_unlock_irq(&phba->hbalock);
  5057. done = 1;
  5058. if ((pmb->u.mb.un.varCfgPort.casabt == 1) &&
  5059. (pmb->u.mb.un.varCfgPort.gasabt == 0))
  5060. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  5061. "3110 Port did not grant ASABT\n");
  5062. }
  5063. }
  5064. if (!done) {
  5065. rc = -EINVAL;
  5066. goto do_prep_failed;
  5067. }
  5068. if (pmb->u.mb.un.varCfgPort.sli_mode == 3) {
  5069. if (!pmb->u.mb.un.varCfgPort.cMA) {
  5070. rc = -ENXIO;
  5071. goto do_prep_failed;
  5072. }
  5073. if (phba->max_vpi && pmb->u.mb.un.varCfgPort.gmv) {
  5074. phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
  5075. phba->max_vpi = pmb->u.mb.un.varCfgPort.max_vpi;
  5076. phba->max_vports = (phba->max_vpi > phba->max_vports) ?
  5077. phba->max_vpi : phba->max_vports;
  5078. } else
  5079. phba->max_vpi = 0;
  5080. if (pmb->u.mb.un.varCfgPort.gerbm)
  5081. phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
  5082. if (pmb->u.mb.un.varCfgPort.gcrp)
  5083. phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
  5084. phba->hbq_get = phba->mbox->us.s3_pgp.hbq_get;
  5085. phba->port_gp = phba->mbox->us.s3_pgp.port;
  5086. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
  5087. if (pmb->u.mb.un.varCfgPort.gbg == 0) {
  5088. phba->cfg_enable_bg = 0;
  5089. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  5090. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5091. "0443 Adapter did not grant "
  5092. "BlockGuard\n");
  5093. }
  5094. }
  5095. } else {
  5096. phba->hbq_get = NULL;
  5097. phba->port_gp = phba->mbox->us.s2.port;
  5098. phba->max_vpi = 0;
  5099. }
  5100. do_prep_failed:
  5101. mempool_free(pmb, phba->mbox_mem_pool);
  5102. return rc;
  5103. }
  5104. /**
  5105. * lpfc_sli_hba_setup - SLI initialization function
  5106. * @phba: Pointer to HBA context object.
  5107. *
  5108. * This function is the main SLI initialization function. This function
  5109. * is called by the HBA initialization code, HBA reset code and HBA
  5110. * error attention handler code. Caller is not required to hold any
  5111. * locks. This function issues config_port mailbox command to configure
  5112. * the SLI, setup iocb rings and HBQ rings. In the end the function
  5113. * calls the config_port_post function to issue init_link mailbox
  5114. * command and to start the discovery. The function will return zero
  5115. * if successful, else it will return negative error code.
  5116. **/
  5117. int
  5118. lpfc_sli_hba_setup(struct lpfc_hba *phba)
  5119. {
  5120. uint32_t rc;
  5121. int i;
  5122. int longs;
  5123. /* Enable ISR already does config_port because of config_msi mbx */
  5124. if (phba->hba_flag & HBA_NEEDS_CFG_PORT) {
  5125. rc = lpfc_sli_config_port(phba, LPFC_SLI_REV3);
  5126. if (rc)
  5127. return -EIO;
  5128. phba->hba_flag &= ~HBA_NEEDS_CFG_PORT;
  5129. }
  5130. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  5131. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  5132. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  5133. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  5134. if (!rc) {
  5135. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5136. "2709 This device supports "
  5137. "Advanced Error Reporting (AER)\n");
  5138. spin_lock_irq(&phba->hbalock);
  5139. phba->hba_flag |= HBA_AER_ENABLED;
  5140. spin_unlock_irq(&phba->hbalock);
  5141. } else {
  5142. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5143. "2708 This device does not support "
  5144. "Advanced Error Reporting (AER): %d\n",
  5145. rc);
  5146. phba->cfg_aer_support = 0;
  5147. }
  5148. }
  5149. if (phba->sli_rev == 3) {
  5150. phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
  5151. phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
  5152. } else {
  5153. phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
  5154. phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
  5155. phba->sli3_options = 0;
  5156. }
  5157. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  5158. "0444 Firmware in SLI %x mode. Max_vpi %d\n",
  5159. phba->sli_rev, phba->max_vpi);
  5160. rc = lpfc_sli_ring_map(phba);
  5161. if (rc)
  5162. goto lpfc_sli_hba_setup_error;
  5163. /* Initialize VPIs. */
  5164. if (phba->sli_rev == LPFC_SLI_REV3) {
  5165. /*
  5166. * The VPI bitmask and physical ID array are allocated
  5167. * and initialized once only - at driver load. A port
  5168. * reset doesn't need to reinitialize this memory.
  5169. */
  5170. if ((phba->vpi_bmask == NULL) && (phba->vpi_ids == NULL)) {
  5171. longs = (phba->max_vpi + BITS_PER_LONG) / BITS_PER_LONG;
  5172. phba->vpi_bmask = kcalloc(longs,
  5173. sizeof(unsigned long),
  5174. GFP_KERNEL);
  5175. if (!phba->vpi_bmask) {
  5176. rc = -ENOMEM;
  5177. goto lpfc_sli_hba_setup_error;
  5178. }
  5179. phba->vpi_ids = kcalloc(phba->max_vpi + 1,
  5180. sizeof(uint16_t),
  5181. GFP_KERNEL);
  5182. if (!phba->vpi_ids) {
  5183. kfree(phba->vpi_bmask);
  5184. rc = -ENOMEM;
  5185. goto lpfc_sli_hba_setup_error;
  5186. }
  5187. for (i = 0; i < phba->max_vpi; i++)
  5188. phba->vpi_ids[i] = i;
  5189. }
  5190. }
  5191. /* Init HBQs */
  5192. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  5193. rc = lpfc_sli_hbq_setup(phba);
  5194. if (rc)
  5195. goto lpfc_sli_hba_setup_error;
  5196. }
  5197. spin_lock_irq(&phba->hbalock);
  5198. phba->sli.sli_flag |= LPFC_PROCESS_LA;
  5199. spin_unlock_irq(&phba->hbalock);
  5200. rc = lpfc_config_port_post(phba);
  5201. if (rc)
  5202. goto lpfc_sli_hba_setup_error;
  5203. return rc;
  5204. lpfc_sli_hba_setup_error:
  5205. phba->link_state = LPFC_HBA_ERROR;
  5206. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5207. "0445 Firmware initialization failed\n");
  5208. return rc;
  5209. }
  5210. /**
  5211. * lpfc_sli4_read_fcoe_params - Read fcoe params from conf region
  5212. * @phba: Pointer to HBA context object.
  5213. *
  5214. * This function issue a dump mailbox command to read config region
  5215. * 23 and parse the records in the region and populate driver
  5216. * data structure.
  5217. **/
  5218. static int
  5219. lpfc_sli4_read_fcoe_params(struct lpfc_hba *phba)
  5220. {
  5221. LPFC_MBOXQ_t *mboxq;
  5222. struct lpfc_dmabuf *mp;
  5223. struct lpfc_mqe *mqe;
  5224. uint32_t data_length;
  5225. int rc;
  5226. /* Program the default value of vlan_id and fc_map */
  5227. phba->valid_vlan = 0;
  5228. phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
  5229. phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
  5230. phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
  5231. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5232. if (!mboxq)
  5233. return -ENOMEM;
  5234. mqe = &mboxq->u.mqe;
  5235. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq)) {
  5236. rc = -ENOMEM;
  5237. goto out_free_mboxq;
  5238. }
  5239. mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
  5240. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5241. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  5242. "(%d):2571 Mailbox cmd x%x Status x%x "
  5243. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  5244. "x%x x%x x%x x%x x%x x%x x%x x%x x%x "
  5245. "CQ: x%x x%x x%x x%x\n",
  5246. mboxq->vport ? mboxq->vport->vpi : 0,
  5247. bf_get(lpfc_mqe_command, mqe),
  5248. bf_get(lpfc_mqe_status, mqe),
  5249. mqe->un.mb_words[0], mqe->un.mb_words[1],
  5250. mqe->un.mb_words[2], mqe->un.mb_words[3],
  5251. mqe->un.mb_words[4], mqe->un.mb_words[5],
  5252. mqe->un.mb_words[6], mqe->un.mb_words[7],
  5253. mqe->un.mb_words[8], mqe->un.mb_words[9],
  5254. mqe->un.mb_words[10], mqe->un.mb_words[11],
  5255. mqe->un.mb_words[12], mqe->un.mb_words[13],
  5256. mqe->un.mb_words[14], mqe->un.mb_words[15],
  5257. mqe->un.mb_words[16], mqe->un.mb_words[50],
  5258. mboxq->mcqe.word0,
  5259. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  5260. mboxq->mcqe.trailer);
  5261. if (rc) {
  5262. rc = -EIO;
  5263. goto out_free_mboxq;
  5264. }
  5265. data_length = mqe->un.mb_words[5];
  5266. if (data_length > DMP_RGN23_SIZE) {
  5267. rc = -EIO;
  5268. goto out_free_mboxq;
  5269. }
  5270. lpfc_parse_fcoe_conf(phba, mp->virt, data_length);
  5271. rc = 0;
  5272. out_free_mboxq:
  5273. lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
  5274. return rc;
  5275. }
  5276. /**
  5277. * lpfc_sli4_read_rev - Issue READ_REV and collect vpd data
  5278. * @phba: pointer to lpfc hba data structure.
  5279. * @mboxq: pointer to the LPFC_MBOXQ_t structure.
  5280. * @vpd: pointer to the memory to hold resulting port vpd data.
  5281. * @vpd_size: On input, the number of bytes allocated to @vpd.
  5282. * On output, the number of data bytes in @vpd.
  5283. *
  5284. * This routine executes a READ_REV SLI4 mailbox command. In
  5285. * addition, this routine gets the port vpd data.
  5286. *
  5287. * Return codes
  5288. * 0 - successful
  5289. * -ENOMEM - could not allocated memory.
  5290. **/
  5291. static int
  5292. lpfc_sli4_read_rev(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  5293. uint8_t *vpd, uint32_t *vpd_size)
  5294. {
  5295. int rc = 0;
  5296. uint32_t dma_size;
  5297. struct lpfc_dmabuf *dmabuf;
  5298. struct lpfc_mqe *mqe;
  5299. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  5300. if (!dmabuf)
  5301. return -ENOMEM;
  5302. /*
  5303. * Get a DMA buffer for the vpd data resulting from the READ_REV
  5304. * mailbox command.
  5305. */
  5306. dma_size = *vpd_size;
  5307. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, dma_size,
  5308. &dmabuf->phys, GFP_KERNEL);
  5309. if (!dmabuf->virt) {
  5310. kfree(dmabuf);
  5311. return -ENOMEM;
  5312. }
  5313. /*
  5314. * The SLI4 implementation of READ_REV conflicts at word1,
  5315. * bits 31:16 and SLI4 adds vpd functionality not present
  5316. * in SLI3. This code corrects the conflicts.
  5317. */
  5318. lpfc_read_rev(phba, mboxq);
  5319. mqe = &mboxq->u.mqe;
  5320. mqe->un.read_rev.vpd_paddr_high = putPaddrHigh(dmabuf->phys);
  5321. mqe->un.read_rev.vpd_paddr_low = putPaddrLow(dmabuf->phys);
  5322. mqe->un.read_rev.word1 &= 0x0000FFFF;
  5323. bf_set(lpfc_mbx_rd_rev_vpd, &mqe->un.read_rev, 1);
  5324. bf_set(lpfc_mbx_rd_rev_avail_len, &mqe->un.read_rev, dma_size);
  5325. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5326. if (rc) {
  5327. dma_free_coherent(&phba->pcidev->dev, dma_size,
  5328. dmabuf->virt, dmabuf->phys);
  5329. kfree(dmabuf);
  5330. return -EIO;
  5331. }
  5332. /*
  5333. * The available vpd length cannot be bigger than the
  5334. * DMA buffer passed to the port. Catch the less than
  5335. * case and update the caller's size.
  5336. */
  5337. if (mqe->un.read_rev.avail_vpd_len < *vpd_size)
  5338. *vpd_size = mqe->un.read_rev.avail_vpd_len;
  5339. memcpy(vpd, dmabuf->virt, *vpd_size);
  5340. dma_free_coherent(&phba->pcidev->dev, dma_size,
  5341. dmabuf->virt, dmabuf->phys);
  5342. kfree(dmabuf);
  5343. return 0;
  5344. }
  5345. /**
  5346. * lpfc_sli4_get_ctl_attr - Retrieve SLI4 device controller attributes
  5347. * @phba: pointer to lpfc hba data structure.
  5348. *
  5349. * This routine retrieves SLI4 device physical port name this PCI function
  5350. * is attached to.
  5351. *
  5352. * Return codes
  5353. * 0 - successful
  5354. * otherwise - failed to retrieve controller attributes
  5355. **/
  5356. static int
  5357. lpfc_sli4_get_ctl_attr(struct lpfc_hba *phba)
  5358. {
  5359. LPFC_MBOXQ_t *mboxq;
  5360. struct lpfc_mbx_get_cntl_attributes *mbx_cntl_attr;
  5361. struct lpfc_controller_attribute *cntl_attr;
  5362. void *virtaddr = NULL;
  5363. uint32_t alloclen, reqlen;
  5364. uint32_t shdr_status, shdr_add_status;
  5365. union lpfc_sli4_cfg_shdr *shdr;
  5366. int rc;
  5367. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5368. if (!mboxq)
  5369. return -ENOMEM;
  5370. /* Send COMMON_GET_CNTL_ATTRIBUTES mbox cmd */
  5371. reqlen = sizeof(struct lpfc_mbx_get_cntl_attributes);
  5372. alloclen = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5373. LPFC_MBOX_OPCODE_GET_CNTL_ATTRIBUTES, reqlen,
  5374. LPFC_SLI4_MBX_NEMBED);
  5375. if (alloclen < reqlen) {
  5376. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5377. "3084 Allocated DMA memory size (%d) is "
  5378. "less than the requested DMA memory size "
  5379. "(%d)\n", alloclen, reqlen);
  5380. rc = -ENOMEM;
  5381. goto out_free_mboxq;
  5382. }
  5383. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5384. virtaddr = mboxq->sge_array->addr[0];
  5385. mbx_cntl_attr = (struct lpfc_mbx_get_cntl_attributes *)virtaddr;
  5386. shdr = &mbx_cntl_attr->cfg_shdr;
  5387. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5388. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5389. if (shdr_status || shdr_add_status || rc) {
  5390. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5391. "3085 Mailbox x%x (x%x/x%x) failed, "
  5392. "rc:x%x, status:x%x, add_status:x%x\n",
  5393. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5394. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  5395. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  5396. rc, shdr_status, shdr_add_status);
  5397. rc = -ENXIO;
  5398. goto out_free_mboxq;
  5399. }
  5400. cntl_attr = &mbx_cntl_attr->cntl_attr;
  5401. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL;
  5402. phba->sli4_hba.lnk_info.lnk_tp =
  5403. bf_get(lpfc_cntl_attr_lnk_type, cntl_attr);
  5404. phba->sli4_hba.lnk_info.lnk_no =
  5405. bf_get(lpfc_cntl_attr_lnk_numb, cntl_attr);
  5406. phba->sli4_hba.flash_id = bf_get(lpfc_cntl_attr_flash_id, cntl_attr);
  5407. phba->sli4_hba.asic_rev = bf_get(lpfc_cntl_attr_asic_rev, cntl_attr);
  5408. memset(phba->BIOSVersion, 0, sizeof(phba->BIOSVersion));
  5409. strlcat(phba->BIOSVersion, (char *)cntl_attr->bios_ver_str,
  5410. sizeof(phba->BIOSVersion));
  5411. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5412. "3086 lnk_type:%d, lnk_numb:%d, bios_ver:%s, "
  5413. "flash_id: x%02x, asic_rev: x%02x\n",
  5414. phba->sli4_hba.lnk_info.lnk_tp,
  5415. phba->sli4_hba.lnk_info.lnk_no,
  5416. phba->BIOSVersion, phba->sli4_hba.flash_id,
  5417. phba->sli4_hba.asic_rev);
  5418. out_free_mboxq:
  5419. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  5420. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  5421. else
  5422. mempool_free(mboxq, phba->mbox_mem_pool);
  5423. return rc;
  5424. }
  5425. /**
  5426. * lpfc_sli4_retrieve_pport_name - Retrieve SLI4 device physical port name
  5427. * @phba: pointer to lpfc hba data structure.
  5428. *
  5429. * This routine retrieves SLI4 device physical port name this PCI function
  5430. * is attached to.
  5431. *
  5432. * Return codes
  5433. * 0 - successful
  5434. * otherwise - failed to retrieve physical port name
  5435. **/
  5436. static int
  5437. lpfc_sli4_retrieve_pport_name(struct lpfc_hba *phba)
  5438. {
  5439. LPFC_MBOXQ_t *mboxq;
  5440. struct lpfc_mbx_get_port_name *get_port_name;
  5441. uint32_t shdr_status, shdr_add_status;
  5442. union lpfc_sli4_cfg_shdr *shdr;
  5443. char cport_name = 0;
  5444. int rc;
  5445. /* We assume nothing at this point */
  5446. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  5447. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_NON;
  5448. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5449. if (!mboxq)
  5450. return -ENOMEM;
  5451. /* obtain link type and link number via READ_CONFIG */
  5452. phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_INVAL;
  5453. lpfc_sli4_read_config(phba);
  5454. if (phba->sli4_hba.fawwpn_flag & LPFC_FAWWPN_CONFIG)
  5455. phba->sli4_hba.fawwpn_flag |= LPFC_FAWWPN_FABRIC;
  5456. if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL)
  5457. goto retrieve_ppname;
  5458. /* obtain link type and link number via COMMON_GET_CNTL_ATTRIBUTES */
  5459. rc = lpfc_sli4_get_ctl_attr(phba);
  5460. if (rc)
  5461. goto out_free_mboxq;
  5462. retrieve_ppname:
  5463. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  5464. LPFC_MBOX_OPCODE_GET_PORT_NAME,
  5465. sizeof(struct lpfc_mbx_get_port_name) -
  5466. sizeof(struct lpfc_sli4_cfg_mhdr),
  5467. LPFC_SLI4_MBX_EMBED);
  5468. get_port_name = &mboxq->u.mqe.un.get_port_name;
  5469. shdr = (union lpfc_sli4_cfg_shdr *)&get_port_name->header.cfg_shdr;
  5470. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_OPCODE_VERSION_1);
  5471. bf_set(lpfc_mbx_get_port_name_lnk_type, &get_port_name->u.request,
  5472. phba->sli4_hba.lnk_info.lnk_tp);
  5473. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  5474. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  5475. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  5476. if (shdr_status || shdr_add_status || rc) {
  5477. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  5478. "3087 Mailbox x%x (x%x/x%x) failed: "
  5479. "rc:x%x, status:x%x, add_status:x%x\n",
  5480. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  5481. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  5482. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  5483. rc, shdr_status, shdr_add_status);
  5484. rc = -ENXIO;
  5485. goto out_free_mboxq;
  5486. }
  5487. switch (phba->sli4_hba.lnk_info.lnk_no) {
  5488. case LPFC_LINK_NUMBER_0:
  5489. cport_name = bf_get(lpfc_mbx_get_port_name_name0,
  5490. &get_port_name->u.response);
  5491. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  5492. break;
  5493. case LPFC_LINK_NUMBER_1:
  5494. cport_name = bf_get(lpfc_mbx_get_port_name_name1,
  5495. &get_port_name->u.response);
  5496. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  5497. break;
  5498. case LPFC_LINK_NUMBER_2:
  5499. cport_name = bf_get(lpfc_mbx_get_port_name_name2,
  5500. &get_port_name->u.response);
  5501. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  5502. break;
  5503. case LPFC_LINK_NUMBER_3:
  5504. cport_name = bf_get(lpfc_mbx_get_port_name_name3,
  5505. &get_port_name->u.response);
  5506. phba->sli4_hba.pport_name_sta = LPFC_SLI4_PPNAME_GET;
  5507. break;
  5508. default:
  5509. break;
  5510. }
  5511. if (phba->sli4_hba.pport_name_sta == LPFC_SLI4_PPNAME_GET) {
  5512. phba->Port[0] = cport_name;
  5513. phba->Port[1] = '\0';
  5514. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5515. "3091 SLI get port name: %s\n", phba->Port);
  5516. }
  5517. out_free_mboxq:
  5518. if (bf_get(lpfc_mqe_command, &mboxq->u.mqe) == MBX_SLI4_CONFIG)
  5519. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  5520. else
  5521. mempool_free(mboxq, phba->mbox_mem_pool);
  5522. return rc;
  5523. }
  5524. /**
  5525. * lpfc_sli4_arm_cqeq_intr - Arm sli-4 device completion and event queues
  5526. * @phba: pointer to lpfc hba data structure.
  5527. *
  5528. * This routine is called to explicitly arm the SLI4 device's completion and
  5529. * event queues
  5530. **/
  5531. static void
  5532. lpfc_sli4_arm_cqeq_intr(struct lpfc_hba *phba)
  5533. {
  5534. int qidx;
  5535. struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
  5536. struct lpfc_sli4_hdw_queue *qp;
  5537. struct lpfc_queue *eq;
  5538. sli4_hba->sli4_write_cq_db(phba, sli4_hba->mbx_cq, 0, LPFC_QUEUE_REARM);
  5539. sli4_hba->sli4_write_cq_db(phba, sli4_hba->els_cq, 0, LPFC_QUEUE_REARM);
  5540. if (sli4_hba->nvmels_cq)
  5541. sli4_hba->sli4_write_cq_db(phba, sli4_hba->nvmels_cq, 0,
  5542. LPFC_QUEUE_REARM);
  5543. if (sli4_hba->hdwq) {
  5544. /* Loop thru all Hardware Queues */
  5545. for (qidx = 0; qidx < phba->cfg_hdw_queue; qidx++) {
  5546. qp = &sli4_hba->hdwq[qidx];
  5547. /* ARM the corresponding CQ */
  5548. sli4_hba->sli4_write_cq_db(phba, qp->io_cq, 0,
  5549. LPFC_QUEUE_REARM);
  5550. }
  5551. /* Loop thru all IRQ vectors */
  5552. for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
  5553. eq = sli4_hba->hba_eq_hdl[qidx].eq;
  5554. /* ARM the corresponding EQ */
  5555. sli4_hba->sli4_write_eq_db(phba, eq,
  5556. 0, LPFC_QUEUE_REARM);
  5557. }
  5558. }
  5559. if (phba->nvmet_support) {
  5560. for (qidx = 0; qidx < phba->cfg_nvmet_mrq; qidx++) {
  5561. sli4_hba->sli4_write_cq_db(phba,
  5562. sli4_hba->nvmet_cqset[qidx], 0,
  5563. LPFC_QUEUE_REARM);
  5564. }
  5565. }
  5566. }
  5567. /**
  5568. * lpfc_sli4_get_avail_extnt_rsrc - Get available resource extent count.
  5569. * @phba: Pointer to HBA context object.
  5570. * @type: The resource extent type.
  5571. * @extnt_count: buffer to hold port available extent count.
  5572. * @extnt_size: buffer to hold element count per extent.
  5573. *
  5574. * This function calls the port and retrievs the number of available
  5575. * extents and their size for a particular extent type.
  5576. *
  5577. * Returns: 0 if successful. Nonzero otherwise.
  5578. **/
  5579. int
  5580. lpfc_sli4_get_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type,
  5581. uint16_t *extnt_count, uint16_t *extnt_size)
  5582. {
  5583. int rc = 0;
  5584. uint32_t length;
  5585. uint32_t mbox_tmo;
  5586. struct lpfc_mbx_get_rsrc_extent_info *rsrc_info;
  5587. LPFC_MBOXQ_t *mbox;
  5588. *extnt_count = 0;
  5589. *extnt_size = 0;
  5590. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5591. if (!mbox)
  5592. return -ENOMEM;
  5593. /* Find out how many extents are available for this resource type */
  5594. length = (sizeof(struct lpfc_mbx_get_rsrc_extent_info) -
  5595. sizeof(struct lpfc_sli4_cfg_mhdr));
  5596. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5597. LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO,
  5598. length, LPFC_SLI4_MBX_EMBED);
  5599. /* Send an extents count of 0 - the GET doesn't use it. */
  5600. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  5601. LPFC_SLI4_MBX_EMBED);
  5602. if (unlikely(rc)) {
  5603. rc = -EIO;
  5604. goto err_exit;
  5605. }
  5606. if (!phba->sli4_hba.intr_enable)
  5607. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5608. else {
  5609. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5610. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5611. }
  5612. if (unlikely(rc)) {
  5613. rc = -EIO;
  5614. goto err_exit;
  5615. }
  5616. rsrc_info = &mbox->u.mqe.un.rsrc_extent_info;
  5617. if (bf_get(lpfc_mbox_hdr_status,
  5618. &rsrc_info->header.cfg_shdr.response)) {
  5619. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5620. "2930 Failed to get resource extents "
  5621. "Status 0x%x Add'l Status 0x%x\n",
  5622. bf_get(lpfc_mbox_hdr_status,
  5623. &rsrc_info->header.cfg_shdr.response),
  5624. bf_get(lpfc_mbox_hdr_add_status,
  5625. &rsrc_info->header.cfg_shdr.response));
  5626. rc = -EIO;
  5627. goto err_exit;
  5628. }
  5629. *extnt_count = bf_get(lpfc_mbx_get_rsrc_extent_info_cnt,
  5630. &rsrc_info->u.rsp);
  5631. *extnt_size = bf_get(lpfc_mbx_get_rsrc_extent_info_size,
  5632. &rsrc_info->u.rsp);
  5633. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  5634. "3162 Retrieved extents type-%d from port: count:%d, "
  5635. "size:%d\n", type, *extnt_count, *extnt_size);
  5636. err_exit:
  5637. mempool_free(mbox, phba->mbox_mem_pool);
  5638. return rc;
  5639. }
  5640. /**
  5641. * lpfc_sli4_chk_avail_extnt_rsrc - Check for available SLI4 resource extents.
  5642. * @phba: Pointer to HBA context object.
  5643. * @type: The extent type to check.
  5644. *
  5645. * This function reads the current available extents from the port and checks
  5646. * if the extent count or extent size has changed since the last access.
  5647. * Callers use this routine post port reset to understand if there is a
  5648. * extent reprovisioning requirement.
  5649. *
  5650. * Returns:
  5651. * -Error: error indicates problem.
  5652. * 1: Extent count or size has changed.
  5653. * 0: No changes.
  5654. **/
  5655. static int
  5656. lpfc_sli4_chk_avail_extnt_rsrc(struct lpfc_hba *phba, uint16_t type)
  5657. {
  5658. uint16_t curr_ext_cnt, rsrc_ext_cnt;
  5659. uint16_t size_diff, rsrc_ext_size;
  5660. int rc = 0;
  5661. struct lpfc_rsrc_blks *rsrc_entry;
  5662. struct list_head *rsrc_blk_list = NULL;
  5663. size_diff = 0;
  5664. curr_ext_cnt = 0;
  5665. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  5666. &rsrc_ext_cnt,
  5667. &rsrc_ext_size);
  5668. if (unlikely(rc))
  5669. return -EIO;
  5670. switch (type) {
  5671. case LPFC_RSC_TYPE_FCOE_RPI:
  5672. rsrc_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  5673. break;
  5674. case LPFC_RSC_TYPE_FCOE_VPI:
  5675. rsrc_blk_list = &phba->lpfc_vpi_blk_list;
  5676. break;
  5677. case LPFC_RSC_TYPE_FCOE_XRI:
  5678. rsrc_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  5679. break;
  5680. case LPFC_RSC_TYPE_FCOE_VFI:
  5681. rsrc_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  5682. break;
  5683. default:
  5684. break;
  5685. }
  5686. list_for_each_entry(rsrc_entry, rsrc_blk_list, list) {
  5687. curr_ext_cnt++;
  5688. if (rsrc_entry->rsrc_size != rsrc_ext_size)
  5689. size_diff++;
  5690. }
  5691. if (curr_ext_cnt != rsrc_ext_cnt || size_diff != 0)
  5692. rc = 1;
  5693. return rc;
  5694. }
  5695. /**
  5696. * lpfc_sli4_cfg_post_extnts -
  5697. * @phba: Pointer to HBA context object.
  5698. * @extnt_cnt: number of available extents.
  5699. * @type: the extent type (rpi, xri, vfi, vpi).
  5700. * @emb: buffer to hold either MBX_EMBED or MBX_NEMBED operation.
  5701. * @mbox: pointer to the caller's allocated mailbox structure.
  5702. *
  5703. * This function executes the extents allocation request. It also
  5704. * takes care of the amount of memory needed to allocate or get the
  5705. * allocated extents. It is the caller's responsibility to evaluate
  5706. * the response.
  5707. *
  5708. * Returns:
  5709. * -Error: Error value describes the condition found.
  5710. * 0: if successful
  5711. **/
  5712. static int
  5713. lpfc_sli4_cfg_post_extnts(struct lpfc_hba *phba, uint16_t extnt_cnt,
  5714. uint16_t type, bool *emb, LPFC_MBOXQ_t *mbox)
  5715. {
  5716. int rc = 0;
  5717. uint32_t req_len;
  5718. uint32_t emb_len;
  5719. uint32_t alloc_len, mbox_tmo;
  5720. /* Calculate the total requested length of the dma memory */
  5721. req_len = extnt_cnt * sizeof(uint16_t);
  5722. /*
  5723. * Calculate the size of an embedded mailbox. The uint32_t
  5724. * accounts for extents-specific word.
  5725. */
  5726. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  5727. sizeof(uint32_t);
  5728. /*
  5729. * Presume the allocation and response will fit into an embedded
  5730. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  5731. */
  5732. *emb = LPFC_SLI4_MBX_EMBED;
  5733. if (req_len > emb_len) {
  5734. req_len = extnt_cnt * sizeof(uint16_t) +
  5735. sizeof(union lpfc_sli4_cfg_shdr) +
  5736. sizeof(uint32_t);
  5737. *emb = LPFC_SLI4_MBX_NEMBED;
  5738. }
  5739. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  5740. LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT,
  5741. req_len, *emb);
  5742. if (alloc_len < req_len) {
  5743. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5744. "2982 Allocated DMA memory size (x%x) is "
  5745. "less than the requested DMA memory "
  5746. "size (x%x)\n", alloc_len, req_len);
  5747. return -ENOMEM;
  5748. }
  5749. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, extnt_cnt, type, *emb);
  5750. if (unlikely(rc))
  5751. return -EIO;
  5752. if (!phba->sli4_hba.intr_enable)
  5753. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  5754. else {
  5755. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  5756. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  5757. }
  5758. if (unlikely(rc))
  5759. rc = -EIO;
  5760. return rc;
  5761. }
  5762. /**
  5763. * lpfc_sli4_alloc_extent - Allocate an SLI4 resource extent.
  5764. * @phba: Pointer to HBA context object.
  5765. * @type: The resource extent type to allocate.
  5766. *
  5767. * This function allocates the number of elements for the specified
  5768. * resource type.
  5769. **/
  5770. static int
  5771. lpfc_sli4_alloc_extent(struct lpfc_hba *phba, uint16_t type)
  5772. {
  5773. bool emb = false;
  5774. uint16_t rsrc_id_cnt, rsrc_cnt, rsrc_size;
  5775. uint16_t rsrc_id, rsrc_start, j, k;
  5776. uint16_t *ids;
  5777. int i, rc;
  5778. unsigned long longs;
  5779. unsigned long *bmask;
  5780. struct lpfc_rsrc_blks *rsrc_blks;
  5781. LPFC_MBOXQ_t *mbox;
  5782. uint32_t length;
  5783. struct lpfc_id_range *id_array = NULL;
  5784. void *virtaddr = NULL;
  5785. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  5786. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  5787. struct list_head *ext_blk_list;
  5788. rc = lpfc_sli4_get_avail_extnt_rsrc(phba, type,
  5789. &rsrc_cnt,
  5790. &rsrc_size);
  5791. if (unlikely(rc))
  5792. return -EIO;
  5793. if ((rsrc_cnt == 0) || (rsrc_size == 0)) {
  5794. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  5795. "3009 No available Resource Extents "
  5796. "for resource type 0x%x: Count: 0x%x, "
  5797. "Size 0x%x\n", type, rsrc_cnt,
  5798. rsrc_size);
  5799. return -ENOMEM;
  5800. }
  5801. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_INIT | LOG_SLI,
  5802. "2903 Post resource extents type-0x%x: "
  5803. "count:%d, size %d\n", type, rsrc_cnt, rsrc_size);
  5804. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5805. if (!mbox)
  5806. return -ENOMEM;
  5807. rc = lpfc_sli4_cfg_post_extnts(phba, rsrc_cnt, type, &emb, mbox);
  5808. if (unlikely(rc)) {
  5809. rc = -EIO;
  5810. goto err_exit;
  5811. }
  5812. /*
  5813. * Figure out where the response is located. Then get local pointers
  5814. * to the response data. The port does not guarantee to respond to
  5815. * all extents counts request so update the local variable with the
  5816. * allocated count from the port.
  5817. */
  5818. if (emb == LPFC_SLI4_MBX_EMBED) {
  5819. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  5820. id_array = &rsrc_ext->u.rsp.id[0];
  5821. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  5822. } else {
  5823. virtaddr = mbox->sge_array->addr[0];
  5824. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  5825. rsrc_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  5826. id_array = &n_rsrc->id;
  5827. }
  5828. longs = ((rsrc_cnt * rsrc_size) + BITS_PER_LONG - 1) / BITS_PER_LONG;
  5829. rsrc_id_cnt = rsrc_cnt * rsrc_size;
  5830. /*
  5831. * Based on the resource size and count, correct the base and max
  5832. * resource values.
  5833. */
  5834. length = sizeof(struct lpfc_rsrc_blks);
  5835. switch (type) {
  5836. case LPFC_RSC_TYPE_FCOE_RPI:
  5837. phba->sli4_hba.rpi_bmask = kcalloc(longs,
  5838. sizeof(unsigned long),
  5839. GFP_KERNEL);
  5840. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  5841. rc = -ENOMEM;
  5842. goto err_exit;
  5843. }
  5844. phba->sli4_hba.rpi_ids = kcalloc(rsrc_id_cnt,
  5845. sizeof(uint16_t),
  5846. GFP_KERNEL);
  5847. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  5848. kfree(phba->sli4_hba.rpi_bmask);
  5849. rc = -ENOMEM;
  5850. goto err_exit;
  5851. }
  5852. /*
  5853. * The next_rpi was initialized with the maximum available
  5854. * count but the port may allocate a smaller number. Catch
  5855. * that case and update the next_rpi.
  5856. */
  5857. phba->sli4_hba.next_rpi = rsrc_id_cnt;
  5858. /* Initialize local ptrs for common extent processing later. */
  5859. bmask = phba->sli4_hba.rpi_bmask;
  5860. ids = phba->sli4_hba.rpi_ids;
  5861. ext_blk_list = &phba->sli4_hba.lpfc_rpi_blk_list;
  5862. break;
  5863. case LPFC_RSC_TYPE_FCOE_VPI:
  5864. phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
  5865. GFP_KERNEL);
  5866. if (unlikely(!phba->vpi_bmask)) {
  5867. rc = -ENOMEM;
  5868. goto err_exit;
  5869. }
  5870. phba->vpi_ids = kcalloc(rsrc_id_cnt, sizeof(uint16_t),
  5871. GFP_KERNEL);
  5872. if (unlikely(!phba->vpi_ids)) {
  5873. kfree(phba->vpi_bmask);
  5874. rc = -ENOMEM;
  5875. goto err_exit;
  5876. }
  5877. /* Initialize local ptrs for common extent processing later. */
  5878. bmask = phba->vpi_bmask;
  5879. ids = phba->vpi_ids;
  5880. ext_blk_list = &phba->lpfc_vpi_blk_list;
  5881. break;
  5882. case LPFC_RSC_TYPE_FCOE_XRI:
  5883. phba->sli4_hba.xri_bmask = kcalloc(longs,
  5884. sizeof(unsigned long),
  5885. GFP_KERNEL);
  5886. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  5887. rc = -ENOMEM;
  5888. goto err_exit;
  5889. }
  5890. phba->sli4_hba.max_cfg_param.xri_used = 0;
  5891. phba->sli4_hba.xri_ids = kcalloc(rsrc_id_cnt,
  5892. sizeof(uint16_t),
  5893. GFP_KERNEL);
  5894. if (unlikely(!phba->sli4_hba.xri_ids)) {
  5895. kfree(phba->sli4_hba.xri_bmask);
  5896. rc = -ENOMEM;
  5897. goto err_exit;
  5898. }
  5899. /* Initialize local ptrs for common extent processing later. */
  5900. bmask = phba->sli4_hba.xri_bmask;
  5901. ids = phba->sli4_hba.xri_ids;
  5902. ext_blk_list = &phba->sli4_hba.lpfc_xri_blk_list;
  5903. break;
  5904. case LPFC_RSC_TYPE_FCOE_VFI:
  5905. phba->sli4_hba.vfi_bmask = kcalloc(longs,
  5906. sizeof(unsigned long),
  5907. GFP_KERNEL);
  5908. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  5909. rc = -ENOMEM;
  5910. goto err_exit;
  5911. }
  5912. phba->sli4_hba.vfi_ids = kcalloc(rsrc_id_cnt,
  5913. sizeof(uint16_t),
  5914. GFP_KERNEL);
  5915. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  5916. kfree(phba->sli4_hba.vfi_bmask);
  5917. rc = -ENOMEM;
  5918. goto err_exit;
  5919. }
  5920. /* Initialize local ptrs for common extent processing later. */
  5921. bmask = phba->sli4_hba.vfi_bmask;
  5922. ids = phba->sli4_hba.vfi_ids;
  5923. ext_blk_list = &phba->sli4_hba.lpfc_vfi_blk_list;
  5924. break;
  5925. default:
  5926. /* Unsupported Opcode. Fail call. */
  5927. id_array = NULL;
  5928. bmask = NULL;
  5929. ids = NULL;
  5930. ext_blk_list = NULL;
  5931. goto err_exit;
  5932. }
  5933. /*
  5934. * Complete initializing the extent configuration with the
  5935. * allocated ids assigned to this function. The bitmask serves
  5936. * as an index into the array and manages the available ids. The
  5937. * array just stores the ids communicated to the port via the wqes.
  5938. */
  5939. for (i = 0, j = 0, k = 0; i < rsrc_cnt; i++) {
  5940. if ((i % 2) == 0)
  5941. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_0,
  5942. &id_array[k]);
  5943. else
  5944. rsrc_id = bf_get(lpfc_mbx_rsrc_id_word4_1,
  5945. &id_array[k]);
  5946. rsrc_blks = kzalloc(length, GFP_KERNEL);
  5947. if (unlikely(!rsrc_blks)) {
  5948. rc = -ENOMEM;
  5949. kfree(bmask);
  5950. kfree(ids);
  5951. goto err_exit;
  5952. }
  5953. rsrc_blks->rsrc_start = rsrc_id;
  5954. rsrc_blks->rsrc_size = rsrc_size;
  5955. list_add_tail(&rsrc_blks->list, ext_blk_list);
  5956. rsrc_start = rsrc_id;
  5957. if ((type == LPFC_RSC_TYPE_FCOE_XRI) && (j == 0)) {
  5958. phba->sli4_hba.io_xri_start = rsrc_start +
  5959. lpfc_sli4_get_iocb_cnt(phba);
  5960. }
  5961. while (rsrc_id < (rsrc_start + rsrc_size)) {
  5962. ids[j] = rsrc_id;
  5963. rsrc_id++;
  5964. j++;
  5965. }
  5966. /* Entire word processed. Get next word.*/
  5967. if ((i % 2) == 1)
  5968. k++;
  5969. }
  5970. err_exit:
  5971. lpfc_sli4_mbox_cmd_free(phba, mbox);
  5972. return rc;
  5973. }
  5974. /**
  5975. * lpfc_sli4_dealloc_extent - Deallocate an SLI4 resource extent.
  5976. * @phba: Pointer to HBA context object.
  5977. * @type: the extent's type.
  5978. *
  5979. * This function deallocates all extents of a particular resource type.
  5980. * SLI4 does not allow for deallocating a particular extent range. It
  5981. * is the caller's responsibility to release all kernel memory resources.
  5982. **/
  5983. static int
  5984. lpfc_sli4_dealloc_extent(struct lpfc_hba *phba, uint16_t type)
  5985. {
  5986. int rc;
  5987. uint32_t length, mbox_tmo = 0;
  5988. LPFC_MBOXQ_t *mbox;
  5989. struct lpfc_mbx_dealloc_rsrc_extents *dealloc_rsrc;
  5990. struct lpfc_rsrc_blks *rsrc_blk, *rsrc_blk_next;
  5991. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  5992. if (!mbox)
  5993. return -ENOMEM;
  5994. /*
  5995. * This function sends an embedded mailbox because it only sends the
  5996. * the resource type. All extents of this type are released by the
  5997. * port.
  5998. */
  5999. length = (sizeof(struct lpfc_mbx_dealloc_rsrc_extents) -
  6000. sizeof(struct lpfc_sli4_cfg_mhdr));
  6001. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  6002. LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT,
  6003. length, LPFC_SLI4_MBX_EMBED);
  6004. /* Send an extents count of 0 - the dealloc doesn't use it. */
  6005. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, 0, type,
  6006. LPFC_SLI4_MBX_EMBED);
  6007. if (unlikely(rc)) {
  6008. rc = -EIO;
  6009. goto out_free_mbox;
  6010. }
  6011. if (!phba->sli4_hba.intr_enable)
  6012. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  6013. else {
  6014. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  6015. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  6016. }
  6017. if (unlikely(rc)) {
  6018. rc = -EIO;
  6019. goto out_free_mbox;
  6020. }
  6021. dealloc_rsrc = &mbox->u.mqe.un.dealloc_rsrc_extents;
  6022. if (bf_get(lpfc_mbox_hdr_status,
  6023. &dealloc_rsrc->header.cfg_shdr.response)) {
  6024. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6025. "2919 Failed to release resource extents "
  6026. "for type %d - Status 0x%x Add'l Status 0x%x. "
  6027. "Resource memory not released.\n",
  6028. type,
  6029. bf_get(lpfc_mbox_hdr_status,
  6030. &dealloc_rsrc->header.cfg_shdr.response),
  6031. bf_get(lpfc_mbox_hdr_add_status,
  6032. &dealloc_rsrc->header.cfg_shdr.response));
  6033. rc = -EIO;
  6034. goto out_free_mbox;
  6035. }
  6036. /* Release kernel memory resources for the specific type. */
  6037. switch (type) {
  6038. case LPFC_RSC_TYPE_FCOE_VPI:
  6039. kfree(phba->vpi_bmask);
  6040. kfree(phba->vpi_ids);
  6041. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6042. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  6043. &phba->lpfc_vpi_blk_list, list) {
  6044. list_del_init(&rsrc_blk->list);
  6045. kfree(rsrc_blk);
  6046. }
  6047. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  6048. break;
  6049. case LPFC_RSC_TYPE_FCOE_XRI:
  6050. kfree(phba->sli4_hba.xri_bmask);
  6051. kfree(phba->sli4_hba.xri_ids);
  6052. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  6053. &phba->sli4_hba.lpfc_xri_blk_list, list) {
  6054. list_del_init(&rsrc_blk->list);
  6055. kfree(rsrc_blk);
  6056. }
  6057. break;
  6058. case LPFC_RSC_TYPE_FCOE_VFI:
  6059. kfree(phba->sli4_hba.vfi_bmask);
  6060. kfree(phba->sli4_hba.vfi_ids);
  6061. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6062. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  6063. &phba->sli4_hba.lpfc_vfi_blk_list, list) {
  6064. list_del_init(&rsrc_blk->list);
  6065. kfree(rsrc_blk);
  6066. }
  6067. break;
  6068. case LPFC_RSC_TYPE_FCOE_RPI:
  6069. /* RPI bitmask and physical id array are cleaned up earlier. */
  6070. list_for_each_entry_safe(rsrc_blk, rsrc_blk_next,
  6071. &phba->sli4_hba.lpfc_rpi_blk_list, list) {
  6072. list_del_init(&rsrc_blk->list);
  6073. kfree(rsrc_blk);
  6074. }
  6075. break;
  6076. default:
  6077. break;
  6078. }
  6079. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6080. out_free_mbox:
  6081. mempool_free(mbox, phba->mbox_mem_pool);
  6082. return rc;
  6083. }
  6084. static void
  6085. lpfc_set_features(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
  6086. uint32_t feature)
  6087. {
  6088. uint32_t len;
  6089. u32 sig_freq = 0;
  6090. len = sizeof(struct lpfc_mbx_set_feature) -
  6091. sizeof(struct lpfc_sli4_cfg_mhdr);
  6092. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  6093. LPFC_MBOX_OPCODE_SET_FEATURES, len,
  6094. LPFC_SLI4_MBX_EMBED);
  6095. switch (feature) {
  6096. case LPFC_SET_UE_RECOVERY:
  6097. bf_set(lpfc_mbx_set_feature_UER,
  6098. &mbox->u.mqe.un.set_feature, 1);
  6099. mbox->u.mqe.un.set_feature.feature = LPFC_SET_UE_RECOVERY;
  6100. mbox->u.mqe.un.set_feature.param_len = 8;
  6101. break;
  6102. case LPFC_SET_MDS_DIAGS:
  6103. bf_set(lpfc_mbx_set_feature_mds,
  6104. &mbox->u.mqe.un.set_feature, 1);
  6105. bf_set(lpfc_mbx_set_feature_mds_deep_loopbk,
  6106. &mbox->u.mqe.un.set_feature, 1);
  6107. mbox->u.mqe.un.set_feature.feature = LPFC_SET_MDS_DIAGS;
  6108. mbox->u.mqe.un.set_feature.param_len = 8;
  6109. break;
  6110. case LPFC_SET_CGN_SIGNAL:
  6111. if (phba->cmf_active_mode == LPFC_CFG_OFF)
  6112. sig_freq = 0;
  6113. else
  6114. sig_freq = phba->cgn_sig_freq;
  6115. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ALARM) {
  6116. bf_set(lpfc_mbx_set_feature_CGN_alarm_freq,
  6117. &mbox->u.mqe.un.set_feature, sig_freq);
  6118. bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
  6119. &mbox->u.mqe.un.set_feature, sig_freq);
  6120. }
  6121. if (phba->cgn_reg_signal == EDC_CG_SIG_WARN_ONLY)
  6122. bf_set(lpfc_mbx_set_feature_CGN_warn_freq,
  6123. &mbox->u.mqe.un.set_feature, sig_freq);
  6124. if (phba->cmf_active_mode == LPFC_CFG_OFF ||
  6125. phba->cgn_reg_signal == EDC_CG_SIG_NOTSUPPORTED)
  6126. sig_freq = 0;
  6127. else
  6128. sig_freq = lpfc_acqe_cgn_frequency;
  6129. bf_set(lpfc_mbx_set_feature_CGN_acqe_freq,
  6130. &mbox->u.mqe.un.set_feature, sig_freq);
  6131. mbox->u.mqe.un.set_feature.feature = LPFC_SET_CGN_SIGNAL;
  6132. mbox->u.mqe.un.set_feature.param_len = 12;
  6133. break;
  6134. case LPFC_SET_DUAL_DUMP:
  6135. bf_set(lpfc_mbx_set_feature_dd,
  6136. &mbox->u.mqe.un.set_feature, LPFC_ENABLE_DUAL_DUMP);
  6137. bf_set(lpfc_mbx_set_feature_ddquery,
  6138. &mbox->u.mqe.un.set_feature, 0);
  6139. mbox->u.mqe.un.set_feature.feature = LPFC_SET_DUAL_DUMP;
  6140. mbox->u.mqe.un.set_feature.param_len = 4;
  6141. break;
  6142. case LPFC_SET_ENABLE_MI:
  6143. mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_MI;
  6144. mbox->u.mqe.un.set_feature.param_len = 4;
  6145. bf_set(lpfc_mbx_set_feature_milunq, &mbox->u.mqe.un.set_feature,
  6146. phba->pport->cfg_lun_queue_depth);
  6147. bf_set(lpfc_mbx_set_feature_mi, &mbox->u.mqe.un.set_feature,
  6148. phba->sli4_hba.pc_sli4_params.mi_ver);
  6149. break;
  6150. case LPFC_SET_LD_SIGNAL:
  6151. mbox->u.mqe.un.set_feature.feature = LPFC_SET_LD_SIGNAL;
  6152. mbox->u.mqe.un.set_feature.param_len = 16;
  6153. bf_set(lpfc_mbx_set_feature_lds_qry,
  6154. &mbox->u.mqe.un.set_feature, LPFC_QUERY_LDS_OP);
  6155. break;
  6156. case LPFC_SET_ENABLE_CMF:
  6157. mbox->u.mqe.un.set_feature.feature = LPFC_SET_ENABLE_CMF;
  6158. mbox->u.mqe.un.set_feature.param_len = 4;
  6159. bf_set(lpfc_mbx_set_feature_cmf,
  6160. &mbox->u.mqe.un.set_feature, 1);
  6161. break;
  6162. }
  6163. return;
  6164. }
  6165. /**
  6166. * lpfc_ras_stop_fwlog: Disable FW logging by the adapter
  6167. * @phba: Pointer to HBA context object.
  6168. *
  6169. * Disable FW logging into host memory on the adapter. To
  6170. * be done before reading logs from the host memory.
  6171. **/
  6172. void
  6173. lpfc_ras_stop_fwlog(struct lpfc_hba *phba)
  6174. {
  6175. struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
  6176. spin_lock_irq(&phba->hbalock);
  6177. ras_fwlog->state = INACTIVE;
  6178. spin_unlock_irq(&phba->hbalock);
  6179. /* Disable FW logging to host memory */
  6180. writel(LPFC_CTL_PDEV_CTL_DDL_RAS,
  6181. phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET);
  6182. /* Wait 10ms for firmware to stop using DMA buffer */
  6183. usleep_range(10 * 1000, 20 * 1000);
  6184. }
  6185. /**
  6186. * lpfc_sli4_ras_dma_free - Free memory allocated for FW logging.
  6187. * @phba: Pointer to HBA context object.
  6188. *
  6189. * This function is called to free memory allocated for RAS FW logging
  6190. * support in the driver.
  6191. **/
  6192. void
  6193. lpfc_sli4_ras_dma_free(struct lpfc_hba *phba)
  6194. {
  6195. struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
  6196. struct lpfc_dmabuf *dmabuf, *next;
  6197. if (!list_empty(&ras_fwlog->fwlog_buff_list)) {
  6198. list_for_each_entry_safe(dmabuf, next,
  6199. &ras_fwlog->fwlog_buff_list,
  6200. list) {
  6201. list_del(&dmabuf->list);
  6202. dma_free_coherent(&phba->pcidev->dev,
  6203. LPFC_RAS_MAX_ENTRY_SIZE,
  6204. dmabuf->virt, dmabuf->phys);
  6205. kfree(dmabuf);
  6206. }
  6207. }
  6208. if (ras_fwlog->lwpd.virt) {
  6209. dma_free_coherent(&phba->pcidev->dev,
  6210. sizeof(uint32_t) * 2,
  6211. ras_fwlog->lwpd.virt,
  6212. ras_fwlog->lwpd.phys);
  6213. ras_fwlog->lwpd.virt = NULL;
  6214. }
  6215. spin_lock_irq(&phba->hbalock);
  6216. ras_fwlog->state = INACTIVE;
  6217. spin_unlock_irq(&phba->hbalock);
  6218. }
  6219. /**
  6220. * lpfc_sli4_ras_dma_alloc: Allocate memory for FW support
  6221. * @phba: Pointer to HBA context object.
  6222. * @fwlog_buff_count: Count of buffers to be created.
  6223. *
  6224. * This routine DMA memory for Log Write Position Data[LPWD] and buffer
  6225. * to update FW log is posted to the adapter.
  6226. * Buffer count is calculated based on module param ras_fwlog_buffsize
  6227. * Size of each buffer posted to FW is 64K.
  6228. **/
  6229. static int
  6230. lpfc_sli4_ras_dma_alloc(struct lpfc_hba *phba,
  6231. uint32_t fwlog_buff_count)
  6232. {
  6233. struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
  6234. struct lpfc_dmabuf *dmabuf;
  6235. int rc = 0, i = 0;
  6236. /* Initialize List */
  6237. INIT_LIST_HEAD(&ras_fwlog->fwlog_buff_list);
  6238. /* Allocate memory for the LWPD */
  6239. ras_fwlog->lwpd.virt = dma_alloc_coherent(&phba->pcidev->dev,
  6240. sizeof(uint32_t) * 2,
  6241. &ras_fwlog->lwpd.phys,
  6242. GFP_KERNEL);
  6243. if (!ras_fwlog->lwpd.virt) {
  6244. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6245. "6185 LWPD Memory Alloc Failed\n");
  6246. return -ENOMEM;
  6247. }
  6248. ras_fwlog->fw_buffcount = fwlog_buff_count;
  6249. for (i = 0; i < ras_fwlog->fw_buffcount; i++) {
  6250. dmabuf = kzalloc(sizeof(struct lpfc_dmabuf),
  6251. GFP_KERNEL);
  6252. if (!dmabuf) {
  6253. rc = -ENOMEM;
  6254. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6255. "6186 Memory Alloc failed FW logging");
  6256. goto free_mem;
  6257. }
  6258. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  6259. LPFC_RAS_MAX_ENTRY_SIZE,
  6260. &dmabuf->phys, GFP_KERNEL);
  6261. if (!dmabuf->virt) {
  6262. kfree(dmabuf);
  6263. rc = -ENOMEM;
  6264. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6265. "6187 DMA Alloc Failed FW logging");
  6266. goto free_mem;
  6267. }
  6268. dmabuf->buffer_tag = i;
  6269. list_add_tail(&dmabuf->list, &ras_fwlog->fwlog_buff_list);
  6270. }
  6271. free_mem:
  6272. if (rc)
  6273. lpfc_sli4_ras_dma_free(phba);
  6274. return rc;
  6275. }
  6276. /**
  6277. * lpfc_sli4_ras_mbox_cmpl: Completion handler for RAS MBX command
  6278. * @phba: pointer to lpfc hba data structure.
  6279. * @pmb: pointer to the driver internal queue element for mailbox command.
  6280. *
  6281. * Completion handler for driver's RAS MBX command to the device.
  6282. **/
  6283. static void
  6284. lpfc_sli4_ras_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  6285. {
  6286. MAILBOX_t *mb;
  6287. union lpfc_sli4_cfg_shdr *shdr;
  6288. uint32_t shdr_status, shdr_add_status;
  6289. struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
  6290. mb = &pmb->u.mb;
  6291. shdr = (union lpfc_sli4_cfg_shdr *)
  6292. &pmb->u.mqe.un.ras_fwlog.header.cfg_shdr;
  6293. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  6294. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  6295. if (mb->mbxStatus != MBX_SUCCESS || shdr_status) {
  6296. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6297. "6188 FW LOG mailbox "
  6298. "completed with status x%x add_status x%x,"
  6299. " mbx status x%x\n",
  6300. shdr_status, shdr_add_status, mb->mbxStatus);
  6301. ras_fwlog->ras_hwsupport = false;
  6302. goto disable_ras;
  6303. }
  6304. spin_lock_irq(&phba->hbalock);
  6305. ras_fwlog->state = ACTIVE;
  6306. spin_unlock_irq(&phba->hbalock);
  6307. mempool_free(pmb, phba->mbox_mem_pool);
  6308. return;
  6309. disable_ras:
  6310. /* Free RAS DMA memory */
  6311. lpfc_sli4_ras_dma_free(phba);
  6312. mempool_free(pmb, phba->mbox_mem_pool);
  6313. }
  6314. /**
  6315. * lpfc_sli4_ras_fwlog_init: Initialize memory and post RAS MBX command
  6316. * @phba: pointer to lpfc hba data structure.
  6317. * @fwlog_level: Logging verbosity level.
  6318. * @fwlog_enable: Enable/Disable logging.
  6319. *
  6320. * Initialize memory and post mailbox command to enable FW logging in host
  6321. * memory.
  6322. **/
  6323. int
  6324. lpfc_sli4_ras_fwlog_init(struct lpfc_hba *phba,
  6325. uint32_t fwlog_level,
  6326. uint32_t fwlog_enable)
  6327. {
  6328. struct lpfc_ras_fwlog *ras_fwlog = &phba->ras_fwlog;
  6329. struct lpfc_mbx_set_ras_fwlog *mbx_fwlog = NULL;
  6330. struct lpfc_dmabuf *dmabuf;
  6331. LPFC_MBOXQ_t *mbox;
  6332. uint32_t len = 0, fwlog_buffsize, fwlog_entry_count;
  6333. int rc = 0;
  6334. spin_lock_irq(&phba->hbalock);
  6335. ras_fwlog->state = INACTIVE;
  6336. spin_unlock_irq(&phba->hbalock);
  6337. fwlog_buffsize = (LPFC_RAS_MIN_BUFF_POST_SIZE *
  6338. phba->cfg_ras_fwlog_buffsize);
  6339. fwlog_entry_count = (fwlog_buffsize/LPFC_RAS_MAX_ENTRY_SIZE);
  6340. /*
  6341. * If re-enabling FW logging support use earlier allocated
  6342. * DMA buffers while posting MBX command.
  6343. **/
  6344. if (!ras_fwlog->lwpd.virt) {
  6345. rc = lpfc_sli4_ras_dma_alloc(phba, fwlog_entry_count);
  6346. if (rc) {
  6347. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  6348. "6189 FW Log Memory Allocation Failed");
  6349. return rc;
  6350. }
  6351. }
  6352. /* Setup Mailbox command */
  6353. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6354. if (!mbox) {
  6355. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6356. "6190 RAS MBX Alloc Failed");
  6357. rc = -ENOMEM;
  6358. goto mem_free;
  6359. }
  6360. ras_fwlog->fw_loglevel = fwlog_level;
  6361. len = (sizeof(struct lpfc_mbx_set_ras_fwlog) -
  6362. sizeof(struct lpfc_sli4_cfg_mhdr));
  6363. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_LOWLEVEL,
  6364. LPFC_MBOX_OPCODE_SET_DIAG_LOG_OPTION,
  6365. len, LPFC_SLI4_MBX_EMBED);
  6366. mbx_fwlog = (struct lpfc_mbx_set_ras_fwlog *)&mbox->u.mqe.un.ras_fwlog;
  6367. bf_set(lpfc_fwlog_enable, &mbx_fwlog->u.request,
  6368. fwlog_enable);
  6369. bf_set(lpfc_fwlog_loglvl, &mbx_fwlog->u.request,
  6370. ras_fwlog->fw_loglevel);
  6371. bf_set(lpfc_fwlog_buffcnt, &mbx_fwlog->u.request,
  6372. ras_fwlog->fw_buffcount);
  6373. bf_set(lpfc_fwlog_buffsz, &mbx_fwlog->u.request,
  6374. LPFC_RAS_MAX_ENTRY_SIZE/SLI4_PAGE_SIZE);
  6375. /* Update DMA buffer address */
  6376. list_for_each_entry(dmabuf, &ras_fwlog->fwlog_buff_list, list) {
  6377. memset(dmabuf->virt, 0, LPFC_RAS_MAX_ENTRY_SIZE);
  6378. mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_lo =
  6379. putPaddrLow(dmabuf->phys);
  6380. mbx_fwlog->u.request.buff_fwlog[dmabuf->buffer_tag].addr_hi =
  6381. putPaddrHigh(dmabuf->phys);
  6382. }
  6383. /* Update LPWD address */
  6384. mbx_fwlog->u.request.lwpd.addr_lo = putPaddrLow(ras_fwlog->lwpd.phys);
  6385. mbx_fwlog->u.request.lwpd.addr_hi = putPaddrHigh(ras_fwlog->lwpd.phys);
  6386. spin_lock_irq(&phba->hbalock);
  6387. ras_fwlog->state = REG_INPROGRESS;
  6388. spin_unlock_irq(&phba->hbalock);
  6389. mbox->vport = phba->pport;
  6390. mbox->mbox_cmpl = lpfc_sli4_ras_mbox_cmpl;
  6391. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  6392. if (rc == MBX_NOT_FINISHED) {
  6393. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6394. "6191 FW-Log Mailbox failed. "
  6395. "status %d mbxStatus : x%x", rc,
  6396. bf_get(lpfc_mqe_status, &mbox->u.mqe));
  6397. mempool_free(mbox, phba->mbox_mem_pool);
  6398. rc = -EIO;
  6399. goto mem_free;
  6400. } else
  6401. rc = 0;
  6402. mem_free:
  6403. if (rc)
  6404. lpfc_sli4_ras_dma_free(phba);
  6405. return rc;
  6406. }
  6407. /**
  6408. * lpfc_sli4_ras_setup - Check if RAS supported on the adapter
  6409. * @phba: Pointer to HBA context object.
  6410. *
  6411. * Check if RAS is supported on the adapter and initialize it.
  6412. **/
  6413. void
  6414. lpfc_sli4_ras_setup(struct lpfc_hba *phba)
  6415. {
  6416. /* Check RAS FW Log needs to be enabled or not */
  6417. if (lpfc_check_fwlog_support(phba))
  6418. return;
  6419. lpfc_sli4_ras_fwlog_init(phba, phba->cfg_ras_fwlog_level,
  6420. LPFC_RAS_ENABLE_LOGGING);
  6421. }
  6422. /**
  6423. * lpfc_sli4_alloc_resource_identifiers - Allocate all SLI4 resource extents.
  6424. * @phba: Pointer to HBA context object.
  6425. *
  6426. * This function allocates all SLI4 resource identifiers.
  6427. **/
  6428. int
  6429. lpfc_sli4_alloc_resource_identifiers(struct lpfc_hba *phba)
  6430. {
  6431. int i, rc, error = 0;
  6432. uint16_t count, base;
  6433. unsigned long longs;
  6434. if (!phba->sli4_hba.rpi_hdrs_in_use)
  6435. phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  6436. if (phba->sli4_hba.extents_in_use) {
  6437. /*
  6438. * The port supports resource extents. The XRI, VPI, VFI, RPI
  6439. * resource extent count must be read and allocated before
  6440. * provisioning the resource id arrays.
  6441. */
  6442. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  6443. LPFC_IDX_RSRC_RDY) {
  6444. /*
  6445. * Extent-based resources are set - the driver could
  6446. * be in a port reset. Figure out if any corrective
  6447. * actions need to be taken.
  6448. */
  6449. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  6450. LPFC_RSC_TYPE_FCOE_VFI);
  6451. if (rc != 0)
  6452. error++;
  6453. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  6454. LPFC_RSC_TYPE_FCOE_VPI);
  6455. if (rc != 0)
  6456. error++;
  6457. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  6458. LPFC_RSC_TYPE_FCOE_XRI);
  6459. if (rc != 0)
  6460. error++;
  6461. rc = lpfc_sli4_chk_avail_extnt_rsrc(phba,
  6462. LPFC_RSC_TYPE_FCOE_RPI);
  6463. if (rc != 0)
  6464. error++;
  6465. /*
  6466. * It's possible that the number of resources
  6467. * provided to this port instance changed between
  6468. * resets. Detect this condition and reallocate
  6469. * resources. Otherwise, there is no action.
  6470. */
  6471. if (error) {
  6472. lpfc_printf_log(phba, KERN_INFO,
  6473. LOG_MBOX | LOG_INIT,
  6474. "2931 Detected extent resource "
  6475. "change. Reallocating all "
  6476. "extents.\n");
  6477. rc = lpfc_sli4_dealloc_extent(phba,
  6478. LPFC_RSC_TYPE_FCOE_VFI);
  6479. rc = lpfc_sli4_dealloc_extent(phba,
  6480. LPFC_RSC_TYPE_FCOE_VPI);
  6481. rc = lpfc_sli4_dealloc_extent(phba,
  6482. LPFC_RSC_TYPE_FCOE_XRI);
  6483. rc = lpfc_sli4_dealloc_extent(phba,
  6484. LPFC_RSC_TYPE_FCOE_RPI);
  6485. } else
  6486. return 0;
  6487. }
  6488. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  6489. if (unlikely(rc))
  6490. goto err_exit;
  6491. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  6492. if (unlikely(rc))
  6493. goto err_exit;
  6494. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  6495. if (unlikely(rc))
  6496. goto err_exit;
  6497. rc = lpfc_sli4_alloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  6498. if (unlikely(rc))
  6499. goto err_exit;
  6500. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  6501. LPFC_IDX_RSRC_RDY);
  6502. return rc;
  6503. } else {
  6504. /*
  6505. * The port does not support resource extents. The XRI, VPI,
  6506. * VFI, RPI resource ids were determined from READ_CONFIG.
  6507. * Just allocate the bitmasks and provision the resource id
  6508. * arrays. If a port reset is active, the resources don't
  6509. * need any action - just exit.
  6510. */
  6511. if (bf_get(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags) ==
  6512. LPFC_IDX_RSRC_RDY) {
  6513. lpfc_sli4_dealloc_resource_identifiers(phba);
  6514. lpfc_sli4_remove_rpis(phba);
  6515. }
  6516. /* RPIs. */
  6517. count = phba->sli4_hba.max_cfg_param.max_rpi;
  6518. if (count <= 0) {
  6519. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6520. "3279 Invalid provisioning of "
  6521. "rpi:%d\n", count);
  6522. rc = -EINVAL;
  6523. goto err_exit;
  6524. }
  6525. base = phba->sli4_hba.max_cfg_param.rpi_base;
  6526. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  6527. phba->sli4_hba.rpi_bmask = kcalloc(longs,
  6528. sizeof(unsigned long),
  6529. GFP_KERNEL);
  6530. if (unlikely(!phba->sli4_hba.rpi_bmask)) {
  6531. rc = -ENOMEM;
  6532. goto err_exit;
  6533. }
  6534. phba->sli4_hba.rpi_ids = kcalloc(count, sizeof(uint16_t),
  6535. GFP_KERNEL);
  6536. if (unlikely(!phba->sli4_hba.rpi_ids)) {
  6537. rc = -ENOMEM;
  6538. goto free_rpi_bmask;
  6539. }
  6540. for (i = 0; i < count; i++)
  6541. phba->sli4_hba.rpi_ids[i] = base + i;
  6542. /* VPIs. */
  6543. count = phba->sli4_hba.max_cfg_param.max_vpi;
  6544. if (count <= 0) {
  6545. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6546. "3280 Invalid provisioning of "
  6547. "vpi:%d\n", count);
  6548. rc = -EINVAL;
  6549. goto free_rpi_ids;
  6550. }
  6551. base = phba->sli4_hba.max_cfg_param.vpi_base;
  6552. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  6553. phba->vpi_bmask = kcalloc(longs, sizeof(unsigned long),
  6554. GFP_KERNEL);
  6555. if (unlikely(!phba->vpi_bmask)) {
  6556. rc = -ENOMEM;
  6557. goto free_rpi_ids;
  6558. }
  6559. phba->vpi_ids = kcalloc(count, sizeof(uint16_t),
  6560. GFP_KERNEL);
  6561. if (unlikely(!phba->vpi_ids)) {
  6562. rc = -ENOMEM;
  6563. goto free_vpi_bmask;
  6564. }
  6565. for (i = 0; i < count; i++)
  6566. phba->vpi_ids[i] = base + i;
  6567. /* XRIs. */
  6568. count = phba->sli4_hba.max_cfg_param.max_xri;
  6569. if (count <= 0) {
  6570. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6571. "3281 Invalid provisioning of "
  6572. "xri:%d\n", count);
  6573. rc = -EINVAL;
  6574. goto free_vpi_ids;
  6575. }
  6576. base = phba->sli4_hba.max_cfg_param.xri_base;
  6577. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  6578. phba->sli4_hba.xri_bmask = kcalloc(longs,
  6579. sizeof(unsigned long),
  6580. GFP_KERNEL);
  6581. if (unlikely(!phba->sli4_hba.xri_bmask)) {
  6582. rc = -ENOMEM;
  6583. goto free_vpi_ids;
  6584. }
  6585. phba->sli4_hba.max_cfg_param.xri_used = 0;
  6586. phba->sli4_hba.xri_ids = kcalloc(count, sizeof(uint16_t),
  6587. GFP_KERNEL);
  6588. if (unlikely(!phba->sli4_hba.xri_ids)) {
  6589. rc = -ENOMEM;
  6590. goto free_xri_bmask;
  6591. }
  6592. for (i = 0; i < count; i++)
  6593. phba->sli4_hba.xri_ids[i] = base + i;
  6594. /* VFIs. */
  6595. count = phba->sli4_hba.max_cfg_param.max_vfi;
  6596. if (count <= 0) {
  6597. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6598. "3282 Invalid provisioning of "
  6599. "vfi:%d\n", count);
  6600. rc = -EINVAL;
  6601. goto free_xri_ids;
  6602. }
  6603. base = phba->sli4_hba.max_cfg_param.vfi_base;
  6604. longs = (count + BITS_PER_LONG - 1) / BITS_PER_LONG;
  6605. phba->sli4_hba.vfi_bmask = kcalloc(longs,
  6606. sizeof(unsigned long),
  6607. GFP_KERNEL);
  6608. if (unlikely(!phba->sli4_hba.vfi_bmask)) {
  6609. rc = -ENOMEM;
  6610. goto free_xri_ids;
  6611. }
  6612. phba->sli4_hba.vfi_ids = kcalloc(count, sizeof(uint16_t),
  6613. GFP_KERNEL);
  6614. if (unlikely(!phba->sli4_hba.vfi_ids)) {
  6615. rc = -ENOMEM;
  6616. goto free_vfi_bmask;
  6617. }
  6618. for (i = 0; i < count; i++)
  6619. phba->sli4_hba.vfi_ids[i] = base + i;
  6620. /*
  6621. * Mark all resources ready. An HBA reset doesn't need
  6622. * to reset the initialization.
  6623. */
  6624. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  6625. LPFC_IDX_RSRC_RDY);
  6626. return 0;
  6627. }
  6628. free_vfi_bmask:
  6629. kfree(phba->sli4_hba.vfi_bmask);
  6630. phba->sli4_hba.vfi_bmask = NULL;
  6631. free_xri_ids:
  6632. kfree(phba->sli4_hba.xri_ids);
  6633. phba->sli4_hba.xri_ids = NULL;
  6634. free_xri_bmask:
  6635. kfree(phba->sli4_hba.xri_bmask);
  6636. phba->sli4_hba.xri_bmask = NULL;
  6637. free_vpi_ids:
  6638. kfree(phba->vpi_ids);
  6639. phba->vpi_ids = NULL;
  6640. free_vpi_bmask:
  6641. kfree(phba->vpi_bmask);
  6642. phba->vpi_bmask = NULL;
  6643. free_rpi_ids:
  6644. kfree(phba->sli4_hba.rpi_ids);
  6645. phba->sli4_hba.rpi_ids = NULL;
  6646. free_rpi_bmask:
  6647. kfree(phba->sli4_hba.rpi_bmask);
  6648. phba->sli4_hba.rpi_bmask = NULL;
  6649. err_exit:
  6650. return rc;
  6651. }
  6652. /**
  6653. * lpfc_sli4_dealloc_resource_identifiers - Deallocate all SLI4 resource extents.
  6654. * @phba: Pointer to HBA context object.
  6655. *
  6656. * This function allocates the number of elements for the specified
  6657. * resource type.
  6658. **/
  6659. int
  6660. lpfc_sli4_dealloc_resource_identifiers(struct lpfc_hba *phba)
  6661. {
  6662. if (phba->sli4_hba.extents_in_use) {
  6663. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VPI);
  6664. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_RPI);
  6665. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_XRI);
  6666. lpfc_sli4_dealloc_extent(phba, LPFC_RSC_TYPE_FCOE_VFI);
  6667. } else {
  6668. kfree(phba->vpi_bmask);
  6669. phba->sli4_hba.max_cfg_param.vpi_used = 0;
  6670. kfree(phba->vpi_ids);
  6671. bf_set(lpfc_vpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6672. kfree(phba->sli4_hba.xri_bmask);
  6673. kfree(phba->sli4_hba.xri_ids);
  6674. kfree(phba->sli4_hba.vfi_bmask);
  6675. kfree(phba->sli4_hba.vfi_ids);
  6676. bf_set(lpfc_vfi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6677. bf_set(lpfc_idx_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  6678. }
  6679. return 0;
  6680. }
  6681. /**
  6682. * lpfc_sli4_get_allocated_extnts - Get the port's allocated extents.
  6683. * @phba: Pointer to HBA context object.
  6684. * @type: The resource extent type.
  6685. * @extnt_cnt: buffer to hold port extent count response
  6686. * @extnt_size: buffer to hold port extent size response.
  6687. *
  6688. * This function calls the port to read the host allocated extents
  6689. * for a particular type.
  6690. **/
  6691. int
  6692. lpfc_sli4_get_allocated_extnts(struct lpfc_hba *phba, uint16_t type,
  6693. uint16_t *extnt_cnt, uint16_t *extnt_size)
  6694. {
  6695. bool emb;
  6696. int rc = 0;
  6697. uint16_t curr_blks = 0;
  6698. uint32_t req_len, emb_len;
  6699. uint32_t alloc_len, mbox_tmo;
  6700. struct list_head *blk_list_head;
  6701. struct lpfc_rsrc_blks *rsrc_blk;
  6702. LPFC_MBOXQ_t *mbox;
  6703. void *virtaddr = NULL;
  6704. struct lpfc_mbx_nembed_rsrc_extent *n_rsrc;
  6705. struct lpfc_mbx_alloc_rsrc_extents *rsrc_ext;
  6706. union lpfc_sli4_cfg_shdr *shdr;
  6707. switch (type) {
  6708. case LPFC_RSC_TYPE_FCOE_VPI:
  6709. blk_list_head = &phba->lpfc_vpi_blk_list;
  6710. break;
  6711. case LPFC_RSC_TYPE_FCOE_XRI:
  6712. blk_list_head = &phba->sli4_hba.lpfc_xri_blk_list;
  6713. break;
  6714. case LPFC_RSC_TYPE_FCOE_VFI:
  6715. blk_list_head = &phba->sli4_hba.lpfc_vfi_blk_list;
  6716. break;
  6717. case LPFC_RSC_TYPE_FCOE_RPI:
  6718. blk_list_head = &phba->sli4_hba.lpfc_rpi_blk_list;
  6719. break;
  6720. default:
  6721. return -EIO;
  6722. }
  6723. /* Count the number of extents currently allocatd for this type. */
  6724. list_for_each_entry(rsrc_blk, blk_list_head, list) {
  6725. if (curr_blks == 0) {
  6726. /*
  6727. * The GET_ALLOCATED mailbox does not return the size,
  6728. * just the count. The size should be just the size
  6729. * stored in the current allocated block and all sizes
  6730. * for an extent type are the same so set the return
  6731. * value now.
  6732. */
  6733. *extnt_size = rsrc_blk->rsrc_size;
  6734. }
  6735. curr_blks++;
  6736. }
  6737. /*
  6738. * Calculate the size of an embedded mailbox. The uint32_t
  6739. * accounts for extents-specific word.
  6740. */
  6741. emb_len = sizeof(MAILBOX_t) - sizeof(struct mbox_header) -
  6742. sizeof(uint32_t);
  6743. /*
  6744. * Presume the allocation and response will fit into an embedded
  6745. * mailbox. If not true, reconfigure to a non-embedded mailbox.
  6746. */
  6747. emb = LPFC_SLI4_MBX_EMBED;
  6748. req_len = emb_len;
  6749. if (req_len > emb_len) {
  6750. req_len = curr_blks * sizeof(uint16_t) +
  6751. sizeof(union lpfc_sli4_cfg_shdr) +
  6752. sizeof(uint32_t);
  6753. emb = LPFC_SLI4_MBX_NEMBED;
  6754. }
  6755. mbox = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  6756. if (!mbox)
  6757. return -ENOMEM;
  6758. memset(mbox, 0, sizeof(LPFC_MBOXQ_t));
  6759. alloc_len = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  6760. LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT,
  6761. req_len, emb);
  6762. if (alloc_len < req_len) {
  6763. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6764. "2983 Allocated DMA memory size (x%x) is "
  6765. "less than the requested DMA memory "
  6766. "size (x%x)\n", alloc_len, req_len);
  6767. rc = -ENOMEM;
  6768. goto err_exit;
  6769. }
  6770. rc = lpfc_sli4_mbox_rsrc_extent(phba, mbox, curr_blks, type, emb);
  6771. if (unlikely(rc)) {
  6772. rc = -EIO;
  6773. goto err_exit;
  6774. }
  6775. if (!phba->sli4_hba.intr_enable)
  6776. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  6777. else {
  6778. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  6779. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  6780. }
  6781. if (unlikely(rc)) {
  6782. rc = -EIO;
  6783. goto err_exit;
  6784. }
  6785. /*
  6786. * Figure out where the response is located. Then get local pointers
  6787. * to the response data. The port does not guarantee to respond to
  6788. * all extents counts request so update the local variable with the
  6789. * allocated count from the port.
  6790. */
  6791. if (emb == LPFC_SLI4_MBX_EMBED) {
  6792. rsrc_ext = &mbox->u.mqe.un.alloc_rsrc_extents;
  6793. shdr = &rsrc_ext->header.cfg_shdr;
  6794. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, &rsrc_ext->u.rsp);
  6795. } else {
  6796. virtaddr = mbox->sge_array->addr[0];
  6797. n_rsrc = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
  6798. shdr = &n_rsrc->cfg_shdr;
  6799. *extnt_cnt = bf_get(lpfc_mbx_rsrc_cnt, n_rsrc);
  6800. }
  6801. if (bf_get(lpfc_mbox_hdr_status, &shdr->response)) {
  6802. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6803. "2984 Failed to read allocated resources "
  6804. "for type %d - Status 0x%x Add'l Status 0x%x.\n",
  6805. type,
  6806. bf_get(lpfc_mbox_hdr_status, &shdr->response),
  6807. bf_get(lpfc_mbox_hdr_add_status, &shdr->response));
  6808. rc = -EIO;
  6809. goto err_exit;
  6810. }
  6811. err_exit:
  6812. lpfc_sli4_mbox_cmd_free(phba, mbox);
  6813. return rc;
  6814. }
  6815. /**
  6816. * lpfc_sli4_repost_sgl_list - Repost the buffers sgl pages as block
  6817. * @phba: pointer to lpfc hba data structure.
  6818. * @sgl_list: linked link of sgl buffers to post
  6819. * @cnt: number of linked list buffers
  6820. *
  6821. * This routine walks the list of buffers that have been allocated and
  6822. * repost them to the port by using SGL block post. This is needed after a
  6823. * pci_function_reset/warm_start or start. It attempts to construct blocks
  6824. * of buffer sgls which contains contiguous xris and uses the non-embedded
  6825. * SGL block post mailbox commands to post them to the port. For single
  6826. * buffer sgl with non-contiguous xri, if any, it shall use embedded SGL post
  6827. * mailbox command for posting.
  6828. *
  6829. * Returns: 0 = success, non-zero failure.
  6830. **/
  6831. static int
  6832. lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,
  6833. struct list_head *sgl_list, int cnt)
  6834. {
  6835. struct lpfc_sglq *sglq_entry = NULL;
  6836. struct lpfc_sglq *sglq_entry_next = NULL;
  6837. struct lpfc_sglq *sglq_entry_first = NULL;
  6838. int status, total_cnt;
  6839. int post_cnt = 0, num_posted = 0, block_cnt = 0;
  6840. int last_xritag = NO_XRI;
  6841. LIST_HEAD(prep_sgl_list);
  6842. LIST_HEAD(blck_sgl_list);
  6843. LIST_HEAD(allc_sgl_list);
  6844. LIST_HEAD(post_sgl_list);
  6845. LIST_HEAD(free_sgl_list);
  6846. spin_lock_irq(&phba->hbalock);
  6847. spin_lock(&phba->sli4_hba.sgl_list_lock);
  6848. list_splice_init(sgl_list, &allc_sgl_list);
  6849. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  6850. spin_unlock_irq(&phba->hbalock);
  6851. total_cnt = cnt;
  6852. list_for_each_entry_safe(sglq_entry, sglq_entry_next,
  6853. &allc_sgl_list, list) {
  6854. list_del_init(&sglq_entry->list);
  6855. block_cnt++;
  6856. if ((last_xritag != NO_XRI) &&
  6857. (sglq_entry->sli4_xritag != last_xritag + 1)) {
  6858. /* a hole in xri block, form a sgl posting block */
  6859. list_splice_init(&prep_sgl_list, &blck_sgl_list);
  6860. post_cnt = block_cnt - 1;
  6861. /* prepare list for next posting block */
  6862. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  6863. block_cnt = 1;
  6864. } else {
  6865. /* prepare list for next posting block */
  6866. list_add_tail(&sglq_entry->list, &prep_sgl_list);
  6867. /* enough sgls for non-embed sgl mbox command */
  6868. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  6869. list_splice_init(&prep_sgl_list,
  6870. &blck_sgl_list);
  6871. post_cnt = block_cnt;
  6872. block_cnt = 0;
  6873. }
  6874. }
  6875. num_posted++;
  6876. /* keep track of last sgl's xritag */
  6877. last_xritag = sglq_entry->sli4_xritag;
  6878. /* end of repost sgl list condition for buffers */
  6879. if (num_posted == total_cnt) {
  6880. if (post_cnt == 0) {
  6881. list_splice_init(&prep_sgl_list,
  6882. &blck_sgl_list);
  6883. post_cnt = block_cnt;
  6884. } else if (block_cnt == 1) {
  6885. status = lpfc_sli4_post_sgl(phba,
  6886. sglq_entry->phys, 0,
  6887. sglq_entry->sli4_xritag);
  6888. if (!status) {
  6889. /* successful, put sgl to posted list */
  6890. list_add_tail(&sglq_entry->list,
  6891. &post_sgl_list);
  6892. } else {
  6893. /* Failure, put sgl to free list */
  6894. lpfc_printf_log(phba, KERN_WARNING,
  6895. LOG_SLI,
  6896. "3159 Failed to post "
  6897. "sgl, xritag:x%x\n",
  6898. sglq_entry->sli4_xritag);
  6899. list_add_tail(&sglq_entry->list,
  6900. &free_sgl_list);
  6901. total_cnt--;
  6902. }
  6903. }
  6904. }
  6905. /* continue until a nembed page worth of sgls */
  6906. if (post_cnt == 0)
  6907. continue;
  6908. /* post the buffer list sgls as a block */
  6909. status = lpfc_sli4_post_sgl_list(phba, &blck_sgl_list,
  6910. post_cnt);
  6911. if (!status) {
  6912. /* success, put sgl list to posted sgl list */
  6913. list_splice_init(&blck_sgl_list, &post_sgl_list);
  6914. } else {
  6915. /* Failure, put sgl list to free sgl list */
  6916. sglq_entry_first = list_first_entry(&blck_sgl_list,
  6917. struct lpfc_sglq,
  6918. list);
  6919. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  6920. "3160 Failed to post sgl-list, "
  6921. "xritag:x%x-x%x\n",
  6922. sglq_entry_first->sli4_xritag,
  6923. (sglq_entry_first->sli4_xritag +
  6924. post_cnt - 1));
  6925. list_splice_init(&blck_sgl_list, &free_sgl_list);
  6926. total_cnt -= post_cnt;
  6927. }
  6928. /* don't reset xirtag due to hole in xri block */
  6929. if (block_cnt == 0)
  6930. last_xritag = NO_XRI;
  6931. /* reset sgl post count for next round of posting */
  6932. post_cnt = 0;
  6933. }
  6934. /* free the sgls failed to post */
  6935. lpfc_free_sgl_list(phba, &free_sgl_list);
  6936. /* push sgls posted to the available list */
  6937. if (!list_empty(&post_sgl_list)) {
  6938. spin_lock_irq(&phba->hbalock);
  6939. spin_lock(&phba->sli4_hba.sgl_list_lock);
  6940. list_splice_init(&post_sgl_list, sgl_list);
  6941. spin_unlock(&phba->sli4_hba.sgl_list_lock);
  6942. spin_unlock_irq(&phba->hbalock);
  6943. } else {
  6944. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  6945. "3161 Failure to post sgl to port,status %x "
  6946. "blkcnt %d totalcnt %d postcnt %d\n",
  6947. status, block_cnt, total_cnt, post_cnt);
  6948. return -EIO;
  6949. }
  6950. /* return the number of XRIs actually posted */
  6951. return total_cnt;
  6952. }
  6953. /**
  6954. * lpfc_sli4_repost_io_sgl_list - Repost all the allocated nvme buffer sgls
  6955. * @phba: pointer to lpfc hba data structure.
  6956. *
  6957. * This routine walks the list of nvme buffers that have been allocated and
  6958. * repost them to the port by using SGL block post. This is needed after a
  6959. * pci_function_reset/warm_start or start. The lpfc_hba_down_post_s4 routine
  6960. * is responsible for moving all nvme buffers on the lpfc_abts_nvme_sgl_list
  6961. * to the lpfc_io_buf_list. If the repost fails, reject all nvme buffers.
  6962. *
  6963. * Returns: 0 = success, non-zero failure.
  6964. **/
  6965. static int
  6966. lpfc_sli4_repost_io_sgl_list(struct lpfc_hba *phba)
  6967. {
  6968. LIST_HEAD(post_nblist);
  6969. int num_posted, rc = 0;
  6970. /* get all NVME buffers need to repost to a local list */
  6971. lpfc_io_buf_flush(phba, &post_nblist);
  6972. /* post the list of nvme buffer sgls to port if available */
  6973. if (!list_empty(&post_nblist)) {
  6974. num_posted = lpfc_sli4_post_io_sgl_list(
  6975. phba, &post_nblist, phba->sli4_hba.io_xri_cnt);
  6976. /* failed to post any nvme buffer, return error */
  6977. if (num_posted == 0)
  6978. rc = -EIO;
  6979. }
  6980. return rc;
  6981. }
  6982. static void
  6983. lpfc_set_host_data(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  6984. {
  6985. uint32_t len;
  6986. len = sizeof(struct lpfc_mbx_set_host_data) -
  6987. sizeof(struct lpfc_sli4_cfg_mhdr);
  6988. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  6989. LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
  6990. LPFC_SLI4_MBX_EMBED);
  6991. mbox->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_OS_DRIVER_VERSION;
  6992. mbox->u.mqe.un.set_host_data.param_len =
  6993. LPFC_HOST_OS_DRIVER_VERSION_SIZE;
  6994. snprintf(mbox->u.mqe.un.set_host_data.un.data,
  6995. LPFC_HOST_OS_DRIVER_VERSION_SIZE,
  6996. "Linux %s v"LPFC_DRIVER_VERSION,
  6997. (phba->hba_flag & HBA_FCOE_MODE) ? "FCoE" : "FC");
  6998. }
  6999. int
  7000. lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  7001. struct lpfc_queue *drq, int count, int idx)
  7002. {
  7003. int rc, i;
  7004. struct lpfc_rqe hrqe;
  7005. struct lpfc_rqe drqe;
  7006. struct lpfc_rqb *rqbp;
  7007. unsigned long flags;
  7008. struct rqb_dmabuf *rqb_buffer;
  7009. LIST_HEAD(rqb_buf_list);
  7010. rqbp = hrq->rqbp;
  7011. for (i = 0; i < count; i++) {
  7012. spin_lock_irqsave(&phba->hbalock, flags);
  7013. /* IF RQ is already full, don't bother */
  7014. if (rqbp->buffer_count + i >= rqbp->entry_count - 1) {
  7015. spin_unlock_irqrestore(&phba->hbalock, flags);
  7016. break;
  7017. }
  7018. spin_unlock_irqrestore(&phba->hbalock, flags);
  7019. rqb_buffer = rqbp->rqb_alloc_buffer(phba);
  7020. if (!rqb_buffer)
  7021. break;
  7022. rqb_buffer->hrq = hrq;
  7023. rqb_buffer->drq = drq;
  7024. rqb_buffer->idx = idx;
  7025. list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list);
  7026. }
  7027. spin_lock_irqsave(&phba->hbalock, flags);
  7028. while (!list_empty(&rqb_buf_list)) {
  7029. list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf,
  7030. hbuf.list);
  7031. hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys);
  7032. hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys);
  7033. drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys);
  7034. drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys);
  7035. rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe);
  7036. if (rc < 0) {
  7037. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7038. "6421 Cannot post to HRQ %d: %x %x %x "
  7039. "DRQ %x %x\n",
  7040. hrq->queue_id,
  7041. hrq->host_index,
  7042. hrq->hba_index,
  7043. hrq->entry_count,
  7044. drq->host_index,
  7045. drq->hba_index);
  7046. rqbp->rqb_free_buffer(phba, rqb_buffer);
  7047. } else {
  7048. list_add_tail(&rqb_buffer->hbuf.list,
  7049. &rqbp->rqb_buffer_list);
  7050. rqbp->buffer_count++;
  7051. }
  7052. }
  7053. spin_unlock_irqrestore(&phba->hbalock, flags);
  7054. return 1;
  7055. }
  7056. static void
  7057. lpfc_mbx_cmpl_read_lds_params(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  7058. {
  7059. union lpfc_sli4_cfg_shdr *shdr;
  7060. u32 shdr_status, shdr_add_status;
  7061. shdr = (union lpfc_sli4_cfg_shdr *)
  7062. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  7063. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7064. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  7065. if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) {
  7066. lpfc_printf_log(phba, KERN_INFO, LOG_LDS_EVENT | LOG_MBOX,
  7067. "4622 SET_FEATURE (x%x) mbox failed, "
  7068. "status x%x add_status x%x, mbx status x%x\n",
  7069. LPFC_SET_LD_SIGNAL, shdr_status,
  7070. shdr_add_status, pmb->u.mb.mbxStatus);
  7071. phba->degrade_activate_threshold = 0;
  7072. phba->degrade_deactivate_threshold = 0;
  7073. phba->fec_degrade_interval = 0;
  7074. goto out;
  7075. }
  7076. phba->degrade_activate_threshold = pmb->u.mqe.un.set_feature.word7;
  7077. phba->degrade_deactivate_threshold = pmb->u.mqe.un.set_feature.word8;
  7078. phba->fec_degrade_interval = pmb->u.mqe.un.set_feature.word10;
  7079. lpfc_printf_log(phba, KERN_INFO, LOG_LDS_EVENT,
  7080. "4624 Success: da x%x dd x%x interval x%x\n",
  7081. phba->degrade_activate_threshold,
  7082. phba->degrade_deactivate_threshold,
  7083. phba->fec_degrade_interval);
  7084. out:
  7085. mempool_free(pmb, phba->mbox_mem_pool);
  7086. }
  7087. int
  7088. lpfc_read_lds_params(struct lpfc_hba *phba)
  7089. {
  7090. LPFC_MBOXQ_t *mboxq;
  7091. int rc;
  7092. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7093. if (!mboxq)
  7094. return -ENOMEM;
  7095. lpfc_set_features(phba, mboxq, LPFC_SET_LD_SIGNAL);
  7096. mboxq->vport = phba->pport;
  7097. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_lds_params;
  7098. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  7099. if (rc == MBX_NOT_FINISHED) {
  7100. mempool_free(mboxq, phba->mbox_mem_pool);
  7101. return -EIO;
  7102. }
  7103. return 0;
  7104. }
  7105. static void
  7106. lpfc_mbx_cmpl_cgn_set_ftrs(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
  7107. {
  7108. struct lpfc_vport *vport = pmb->vport;
  7109. union lpfc_sli4_cfg_shdr *shdr;
  7110. u32 shdr_status, shdr_add_status;
  7111. u32 sig, acqe;
  7112. /* Two outcomes. (1) Set featurs was successul and EDC negotiation
  7113. * is done. (2) Mailbox failed and send FPIN support only.
  7114. */
  7115. shdr = (union lpfc_sli4_cfg_shdr *)
  7116. &pmb->u.mqe.un.sli4_config.header.cfg_shdr;
  7117. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  7118. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  7119. if (shdr_status || shdr_add_status || pmb->u.mb.mbxStatus) {
  7120. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
  7121. "2516 CGN SET_FEATURE mbox failed with "
  7122. "status x%x add_status x%x, mbx status x%x "
  7123. "Reset Congestion to FPINs only\n",
  7124. shdr_status, shdr_add_status,
  7125. pmb->u.mb.mbxStatus);
  7126. /* If there is a mbox error, move on to RDF */
  7127. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  7128. phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
  7129. goto out;
  7130. }
  7131. /* Zero out Congestion Signal ACQE counter */
  7132. phba->cgn_acqe_cnt = 0;
  7133. acqe = bf_get(lpfc_mbx_set_feature_CGN_acqe_freq,
  7134. &pmb->u.mqe.un.set_feature);
  7135. sig = bf_get(lpfc_mbx_set_feature_CGN_warn_freq,
  7136. &pmb->u.mqe.un.set_feature);
  7137. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  7138. "4620 SET_FEATURES Success: Freq: %ds %dms "
  7139. " Reg: x%x x%x\n", acqe, sig,
  7140. phba->cgn_reg_signal, phba->cgn_reg_fpin);
  7141. out:
  7142. mempool_free(pmb, phba->mbox_mem_pool);
  7143. /* Register for FPIN events from the fabric now that the
  7144. * EDC common_set_features has completed.
  7145. */
  7146. lpfc_issue_els_rdf(vport, 0);
  7147. }
  7148. int
  7149. lpfc_config_cgn_signal(struct lpfc_hba *phba)
  7150. {
  7151. LPFC_MBOXQ_t *mboxq;
  7152. u32 rc;
  7153. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7154. if (!mboxq)
  7155. goto out_rdf;
  7156. lpfc_set_features(phba, mboxq, LPFC_SET_CGN_SIGNAL);
  7157. mboxq->vport = phba->pport;
  7158. mboxq->mbox_cmpl = lpfc_mbx_cmpl_cgn_set_ftrs;
  7159. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  7160. "4621 SET_FEATURES: FREQ sig x%x acqe x%x: "
  7161. "Reg: x%x x%x\n",
  7162. phba->cgn_sig_freq, lpfc_acqe_cgn_frequency,
  7163. phba->cgn_reg_signal, phba->cgn_reg_fpin);
  7164. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  7165. if (rc == MBX_NOT_FINISHED)
  7166. goto out;
  7167. return 0;
  7168. out:
  7169. mempool_free(mboxq, phba->mbox_mem_pool);
  7170. out_rdf:
  7171. /* If there is a mbox error, move on to RDF */
  7172. phba->cgn_reg_fpin = LPFC_CGN_FPIN_WARN | LPFC_CGN_FPIN_ALARM;
  7173. phba->cgn_reg_signal = EDC_CG_SIG_NOTSUPPORTED;
  7174. lpfc_issue_els_rdf(phba->pport, 0);
  7175. return -EIO;
  7176. }
  7177. /**
  7178. * lpfc_init_idle_stat_hb - Initialize idle_stat tracking
  7179. * @phba: pointer to lpfc hba data structure.
  7180. *
  7181. * This routine initializes the per-cq idle_stat to dynamically dictate
  7182. * polling decisions.
  7183. *
  7184. * Return codes:
  7185. * None
  7186. **/
  7187. static void lpfc_init_idle_stat_hb(struct lpfc_hba *phba)
  7188. {
  7189. int i;
  7190. struct lpfc_sli4_hdw_queue *hdwq;
  7191. struct lpfc_queue *cq;
  7192. struct lpfc_idle_stat *idle_stat;
  7193. u64 wall;
  7194. for_each_present_cpu(i) {
  7195. hdwq = &phba->sli4_hba.hdwq[phba->sli4_hba.cpu_map[i].hdwq];
  7196. cq = hdwq->io_cq;
  7197. /* Skip if we've already handled this cq's primary CPU */
  7198. if (cq->chann != i)
  7199. continue;
  7200. idle_stat = &phba->sli4_hba.idle_stat[i];
  7201. idle_stat->prev_idle = get_cpu_idle_time(i, &wall, 1);
  7202. idle_stat->prev_wall = wall;
  7203. if (phba->nvmet_support ||
  7204. phba->cmf_active_mode != LPFC_CFG_OFF)
  7205. cq->poll_mode = LPFC_QUEUE_WORK;
  7206. else
  7207. cq->poll_mode = LPFC_IRQ_POLL;
  7208. }
  7209. if (!phba->nvmet_support)
  7210. schedule_delayed_work(&phba->idle_stat_delay_work,
  7211. msecs_to_jiffies(LPFC_IDLE_STAT_DELAY));
  7212. }
  7213. static void lpfc_sli4_dip(struct lpfc_hba *phba)
  7214. {
  7215. uint32_t if_type;
  7216. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  7217. if (if_type == LPFC_SLI_INTF_IF_TYPE_2 ||
  7218. if_type == LPFC_SLI_INTF_IF_TYPE_6) {
  7219. struct lpfc_register reg_data;
  7220. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  7221. &reg_data.word0))
  7222. return;
  7223. if (bf_get(lpfc_sliport_status_dip, &reg_data))
  7224. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7225. "2904 Firmware Dump Image Present"
  7226. " on Adapter");
  7227. }
  7228. }
  7229. /**
  7230. * lpfc_rx_monitor_create_ring - Initialize ring buffer for rx_monitor
  7231. * @rx_monitor: Pointer to lpfc_rx_info_monitor object
  7232. * @entries: Number of rx_info_entry objects to allocate in ring
  7233. *
  7234. * Return:
  7235. * 0 - Success
  7236. * ENOMEM - Failure to kmalloc
  7237. **/
  7238. int lpfc_rx_monitor_create_ring(struct lpfc_rx_info_monitor *rx_monitor,
  7239. u32 entries)
  7240. {
  7241. rx_monitor->ring = kmalloc_array(entries, sizeof(struct rx_info_entry),
  7242. GFP_KERNEL);
  7243. if (!rx_monitor->ring)
  7244. return -ENOMEM;
  7245. rx_monitor->head_idx = 0;
  7246. rx_monitor->tail_idx = 0;
  7247. spin_lock_init(&rx_monitor->lock);
  7248. rx_monitor->entries = entries;
  7249. return 0;
  7250. }
  7251. /**
  7252. * lpfc_rx_monitor_destroy_ring - Free ring buffer for rx_monitor
  7253. * @rx_monitor: Pointer to lpfc_rx_info_monitor object
  7254. **/
  7255. void lpfc_rx_monitor_destroy_ring(struct lpfc_rx_info_monitor *rx_monitor)
  7256. {
  7257. spin_lock(&rx_monitor->lock);
  7258. kfree(rx_monitor->ring);
  7259. rx_monitor->ring = NULL;
  7260. rx_monitor->entries = 0;
  7261. rx_monitor->head_idx = 0;
  7262. rx_monitor->tail_idx = 0;
  7263. spin_unlock(&rx_monitor->lock);
  7264. }
  7265. /**
  7266. * lpfc_rx_monitor_record - Insert an entry into rx_monitor's ring
  7267. * @rx_monitor: Pointer to lpfc_rx_info_monitor object
  7268. * @entry: Pointer to rx_info_entry
  7269. *
  7270. * Used to insert an rx_info_entry into rx_monitor's ring. Note that this is a
  7271. * deep copy of rx_info_entry not a shallow copy of the rx_info_entry ptr.
  7272. *
  7273. * This is called from lpfc_cmf_timer, which is in timer/softirq context.
  7274. *
  7275. * In cases of old data overflow, we do a best effort of FIFO order.
  7276. **/
  7277. void lpfc_rx_monitor_record(struct lpfc_rx_info_monitor *rx_monitor,
  7278. struct rx_info_entry *entry)
  7279. {
  7280. struct rx_info_entry *ring = rx_monitor->ring;
  7281. u32 *head_idx = &rx_monitor->head_idx;
  7282. u32 *tail_idx = &rx_monitor->tail_idx;
  7283. spinlock_t *ring_lock = &rx_monitor->lock;
  7284. u32 ring_size = rx_monitor->entries;
  7285. spin_lock(ring_lock);
  7286. memcpy(&ring[*tail_idx], entry, sizeof(*entry));
  7287. *tail_idx = (*tail_idx + 1) % ring_size;
  7288. /* Best effort of FIFO saved data */
  7289. if (*tail_idx == *head_idx)
  7290. *head_idx = (*head_idx + 1) % ring_size;
  7291. spin_unlock(ring_lock);
  7292. }
  7293. /**
  7294. * lpfc_rx_monitor_report - Read out rx_monitor's ring
  7295. * @phba: Pointer to lpfc_hba object
  7296. * @rx_monitor: Pointer to lpfc_rx_info_monitor object
  7297. * @buf: Pointer to char buffer that will contain rx monitor info data
  7298. * @buf_len: Length buf including null char
  7299. * @max_read_entries: Maximum number of entries to read out of ring
  7300. *
  7301. * Used to dump/read what's in rx_monitor's ring buffer.
  7302. *
  7303. * If buf is NULL || buf_len == 0, then it is implied that we want to log the
  7304. * information to kmsg instead of filling out buf.
  7305. *
  7306. * Return:
  7307. * Number of entries read out of the ring
  7308. **/
  7309. u32 lpfc_rx_monitor_report(struct lpfc_hba *phba,
  7310. struct lpfc_rx_info_monitor *rx_monitor, char *buf,
  7311. u32 buf_len, u32 max_read_entries)
  7312. {
  7313. struct rx_info_entry *ring = rx_monitor->ring;
  7314. struct rx_info_entry *entry;
  7315. u32 *head_idx = &rx_monitor->head_idx;
  7316. u32 *tail_idx = &rx_monitor->tail_idx;
  7317. spinlock_t *ring_lock = &rx_monitor->lock;
  7318. u32 ring_size = rx_monitor->entries;
  7319. u32 cnt = 0;
  7320. char tmp[DBG_LOG_STR_SZ] = {0};
  7321. bool log_to_kmsg = (!buf || !buf_len) ? true : false;
  7322. if (!log_to_kmsg) {
  7323. /* clear the buffer to be sure */
  7324. memset(buf, 0, buf_len);
  7325. scnprintf(buf, buf_len, "\t%-16s%-16s%-16s%-16s%-8s%-8s%-8s"
  7326. "%-8s%-8s%-8s%-16s\n",
  7327. "MaxBPI", "Tot_Data_CMF",
  7328. "Tot_Data_Cmd", "Tot_Data_Cmpl",
  7329. "Lat(us)", "Avg_IO", "Max_IO", "Bsy",
  7330. "IO_cnt", "Info", "BWutil(ms)");
  7331. }
  7332. /* Needs to be _irq because record is called from timer interrupt
  7333. * context
  7334. */
  7335. spin_lock_irq(ring_lock);
  7336. while (*head_idx != *tail_idx) {
  7337. entry = &ring[*head_idx];
  7338. /* Read out this entry's data. */
  7339. if (!log_to_kmsg) {
  7340. /* If !log_to_kmsg, then store to buf. */
  7341. scnprintf(tmp, sizeof(tmp),
  7342. "%03d:\t%-16llu%-16llu%-16llu%-16llu%-8llu"
  7343. "%-8llu%-8llu%-8u%-8u%-8u%u(%u)\n",
  7344. *head_idx, entry->max_bytes_per_interval,
  7345. entry->cmf_bytes, entry->total_bytes,
  7346. entry->rcv_bytes, entry->avg_io_latency,
  7347. entry->avg_io_size, entry->max_read_cnt,
  7348. entry->cmf_busy, entry->io_cnt,
  7349. entry->cmf_info, entry->timer_utilization,
  7350. entry->timer_interval);
  7351. /* Check for buffer overflow */
  7352. if ((strlen(buf) + strlen(tmp)) >= buf_len)
  7353. break;
  7354. /* Append entry's data to buffer */
  7355. strlcat(buf, tmp, buf_len);
  7356. } else {
  7357. lpfc_printf_log(phba, KERN_INFO, LOG_CGN_MGMT,
  7358. "4410 %02u: MBPI %llu Xmit %llu "
  7359. "Cmpl %llu Lat %llu ASz %llu Info %02u "
  7360. "BWUtil %u Int %u slot %u\n",
  7361. cnt, entry->max_bytes_per_interval,
  7362. entry->total_bytes, entry->rcv_bytes,
  7363. entry->avg_io_latency,
  7364. entry->avg_io_size, entry->cmf_info,
  7365. entry->timer_utilization,
  7366. entry->timer_interval, *head_idx);
  7367. }
  7368. *head_idx = (*head_idx + 1) % ring_size;
  7369. /* Don't feed more than max_read_entries */
  7370. cnt++;
  7371. if (cnt >= max_read_entries)
  7372. break;
  7373. }
  7374. spin_unlock_irq(ring_lock);
  7375. return cnt;
  7376. }
  7377. /**
  7378. * lpfc_cmf_setup - Initialize idle_stat tracking
  7379. * @phba: Pointer to HBA context object.
  7380. *
  7381. * This is called from HBA setup during driver load or when the HBA
  7382. * comes online. this does all the initialization to support CMF and MI.
  7383. **/
  7384. static int
  7385. lpfc_cmf_setup(struct lpfc_hba *phba)
  7386. {
  7387. LPFC_MBOXQ_t *mboxq;
  7388. struct lpfc_dmabuf *mp;
  7389. struct lpfc_pc_sli4_params *sli4_params;
  7390. int rc, cmf, mi_ver;
  7391. rc = lpfc_sli4_refresh_params(phba);
  7392. if (unlikely(rc))
  7393. return rc;
  7394. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7395. if (!mboxq)
  7396. return -ENOMEM;
  7397. sli4_params = &phba->sli4_hba.pc_sli4_params;
  7398. /* Always try to enable MI feature if we can */
  7399. if (sli4_params->mi_ver) {
  7400. lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_MI);
  7401. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7402. mi_ver = bf_get(lpfc_mbx_set_feature_mi,
  7403. &mboxq->u.mqe.un.set_feature);
  7404. if (rc == MBX_SUCCESS) {
  7405. if (mi_ver) {
  7406. lpfc_printf_log(phba,
  7407. KERN_WARNING, LOG_CGN_MGMT,
  7408. "6215 MI is enabled\n");
  7409. sli4_params->mi_ver = mi_ver;
  7410. } else {
  7411. lpfc_printf_log(phba,
  7412. KERN_WARNING, LOG_CGN_MGMT,
  7413. "6338 MI is disabled\n");
  7414. sli4_params->mi_ver = 0;
  7415. }
  7416. } else {
  7417. /* mi_ver is already set from GET_SLI4_PARAMETERS */
  7418. lpfc_printf_log(phba, KERN_INFO,
  7419. LOG_CGN_MGMT | LOG_INIT,
  7420. "6245 Enable MI Mailbox x%x (x%x/x%x) "
  7421. "failed, rc:x%x mi:x%x\n",
  7422. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7423. lpfc_sli_config_mbox_subsys_get
  7424. (phba, mboxq),
  7425. lpfc_sli_config_mbox_opcode_get
  7426. (phba, mboxq),
  7427. rc, sli4_params->mi_ver);
  7428. }
  7429. } else {
  7430. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  7431. "6217 MI is disabled\n");
  7432. }
  7433. /* Ensure FDMI is enabled for MI if enable_mi is set */
  7434. if (sli4_params->mi_ver)
  7435. phba->cfg_fdmi_on = LPFC_FDMI_SUPPORT;
  7436. /* Always try to enable CMF feature if we can */
  7437. if (sli4_params->cmf) {
  7438. lpfc_set_features(phba, mboxq, LPFC_SET_ENABLE_CMF);
  7439. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7440. cmf = bf_get(lpfc_mbx_set_feature_cmf,
  7441. &mboxq->u.mqe.un.set_feature);
  7442. if (rc == MBX_SUCCESS && cmf) {
  7443. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  7444. "6218 CMF is enabled: mode %d\n",
  7445. phba->cmf_active_mode);
  7446. } else {
  7447. lpfc_printf_log(phba, KERN_WARNING,
  7448. LOG_CGN_MGMT | LOG_INIT,
  7449. "6219 Enable CMF Mailbox x%x (x%x/x%x) "
  7450. "failed, rc:x%x dd:x%x\n",
  7451. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7452. lpfc_sli_config_mbox_subsys_get
  7453. (phba, mboxq),
  7454. lpfc_sli_config_mbox_opcode_get
  7455. (phba, mboxq),
  7456. rc, cmf);
  7457. sli4_params->cmf = 0;
  7458. phba->cmf_active_mode = LPFC_CFG_OFF;
  7459. goto no_cmf;
  7460. }
  7461. /* Allocate Congestion Information Buffer */
  7462. if (!phba->cgn_i) {
  7463. mp = kmalloc(sizeof(*mp), GFP_KERNEL);
  7464. if (mp)
  7465. mp->virt = dma_alloc_coherent
  7466. (&phba->pcidev->dev,
  7467. sizeof(struct lpfc_cgn_info),
  7468. &mp->phys, GFP_KERNEL);
  7469. if (!mp || !mp->virt) {
  7470. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7471. "2640 Failed to alloc memory "
  7472. "for Congestion Info\n");
  7473. kfree(mp);
  7474. sli4_params->cmf = 0;
  7475. phba->cmf_active_mode = LPFC_CFG_OFF;
  7476. goto no_cmf;
  7477. }
  7478. phba->cgn_i = mp;
  7479. /* initialize congestion buffer info */
  7480. lpfc_init_congestion_buf(phba);
  7481. lpfc_init_congestion_stat(phba);
  7482. /* Zero out Congestion Signal counters */
  7483. atomic64_set(&phba->cgn_acqe_stat.alarm, 0);
  7484. atomic64_set(&phba->cgn_acqe_stat.warn, 0);
  7485. }
  7486. rc = lpfc_sli4_cgn_params_read(phba);
  7487. if (rc < 0) {
  7488. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  7489. "6242 Error reading Cgn Params (%d)\n",
  7490. rc);
  7491. /* Ensure CGN Mode is off */
  7492. sli4_params->cmf = 0;
  7493. } else if (!rc) {
  7494. lpfc_printf_log(phba, KERN_ERR, LOG_CGN_MGMT | LOG_INIT,
  7495. "6243 CGN Event empty object.\n");
  7496. /* Ensure CGN Mode is off */
  7497. sli4_params->cmf = 0;
  7498. }
  7499. } else {
  7500. no_cmf:
  7501. lpfc_printf_log(phba, KERN_WARNING, LOG_CGN_MGMT,
  7502. "6220 CMF is disabled\n");
  7503. }
  7504. /* Only register congestion buffer with firmware if BOTH
  7505. * CMF and E2E are enabled.
  7506. */
  7507. if (sli4_params->cmf && sli4_params->mi_ver) {
  7508. rc = lpfc_reg_congestion_buf(phba);
  7509. if (rc) {
  7510. dma_free_coherent(&phba->pcidev->dev,
  7511. sizeof(struct lpfc_cgn_info),
  7512. phba->cgn_i->virt, phba->cgn_i->phys);
  7513. kfree(phba->cgn_i);
  7514. phba->cgn_i = NULL;
  7515. /* Ensure CGN Mode is off */
  7516. phba->cmf_active_mode = LPFC_CFG_OFF;
  7517. return 0;
  7518. }
  7519. }
  7520. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  7521. "6470 Setup MI version %d CMF %d mode %d\n",
  7522. sli4_params->mi_ver, sli4_params->cmf,
  7523. phba->cmf_active_mode);
  7524. mempool_free(mboxq, phba->mbox_mem_pool);
  7525. /* Initialize atomic counters */
  7526. atomic_set(&phba->cgn_fabric_warn_cnt, 0);
  7527. atomic_set(&phba->cgn_fabric_alarm_cnt, 0);
  7528. atomic_set(&phba->cgn_sync_alarm_cnt, 0);
  7529. atomic_set(&phba->cgn_sync_warn_cnt, 0);
  7530. atomic_set(&phba->cgn_driver_evt_cnt, 0);
  7531. atomic_set(&phba->cgn_latency_evt_cnt, 0);
  7532. atomic64_set(&phba->cgn_latency_evt, 0);
  7533. phba->cmf_interval_rate = LPFC_CMF_INTERVAL;
  7534. /* Allocate RX Monitor Buffer */
  7535. if (!phba->rx_monitor) {
  7536. phba->rx_monitor = kzalloc(sizeof(*phba->rx_monitor),
  7537. GFP_KERNEL);
  7538. if (!phba->rx_monitor) {
  7539. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7540. "2644 Failed to alloc memory "
  7541. "for RX Monitor Buffer\n");
  7542. return -ENOMEM;
  7543. }
  7544. /* Instruct the rx_monitor object to instantiate its ring */
  7545. if (lpfc_rx_monitor_create_ring(phba->rx_monitor,
  7546. LPFC_MAX_RXMONITOR_ENTRY)) {
  7547. kfree(phba->rx_monitor);
  7548. phba->rx_monitor = NULL;
  7549. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  7550. "2645 Failed to alloc memory "
  7551. "for RX Monitor's Ring\n");
  7552. return -ENOMEM;
  7553. }
  7554. }
  7555. return 0;
  7556. }
  7557. static int
  7558. lpfc_set_host_tm(struct lpfc_hba *phba)
  7559. {
  7560. LPFC_MBOXQ_t *mboxq;
  7561. uint32_t len, rc;
  7562. struct timespec64 cur_time;
  7563. struct tm broken;
  7564. uint32_t month, day, year;
  7565. uint32_t hour, minute, second;
  7566. struct lpfc_mbx_set_host_date_time *tm;
  7567. mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7568. if (!mboxq)
  7569. return -ENOMEM;
  7570. len = sizeof(struct lpfc_mbx_set_host_data) -
  7571. sizeof(struct lpfc_sli4_cfg_mhdr);
  7572. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
  7573. LPFC_MBOX_OPCODE_SET_HOST_DATA, len,
  7574. LPFC_SLI4_MBX_EMBED);
  7575. mboxq->u.mqe.un.set_host_data.param_id = LPFC_SET_HOST_DATE_TIME;
  7576. mboxq->u.mqe.un.set_host_data.param_len =
  7577. sizeof(struct lpfc_mbx_set_host_date_time);
  7578. tm = &mboxq->u.mqe.un.set_host_data.un.tm;
  7579. ktime_get_real_ts64(&cur_time);
  7580. time64_to_tm(cur_time.tv_sec, 0, &broken);
  7581. month = broken.tm_mon + 1;
  7582. day = broken.tm_mday;
  7583. year = broken.tm_year - 100;
  7584. hour = broken.tm_hour;
  7585. minute = broken.tm_min;
  7586. second = broken.tm_sec;
  7587. bf_set(lpfc_mbx_set_host_month, tm, month);
  7588. bf_set(lpfc_mbx_set_host_day, tm, day);
  7589. bf_set(lpfc_mbx_set_host_year, tm, year);
  7590. bf_set(lpfc_mbx_set_host_hour, tm, hour);
  7591. bf_set(lpfc_mbx_set_host_min, tm, minute);
  7592. bf_set(lpfc_mbx_set_host_sec, tm, second);
  7593. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7594. mempool_free(mboxq, phba->mbox_mem_pool);
  7595. return rc;
  7596. }
  7597. /**
  7598. * lpfc_sli4_hba_setup - SLI4 device initialization PCI function
  7599. * @phba: Pointer to HBA context object.
  7600. *
  7601. * This function is the main SLI4 device initialization PCI function. This
  7602. * function is called by the HBA initialization code, HBA reset code and
  7603. * HBA error attention handler code. Caller is not required to hold any
  7604. * locks.
  7605. **/
  7606. int
  7607. lpfc_sli4_hba_setup(struct lpfc_hba *phba)
  7608. {
  7609. int rc, i, cnt, len, dd;
  7610. LPFC_MBOXQ_t *mboxq;
  7611. struct lpfc_mqe *mqe;
  7612. uint8_t *vpd;
  7613. uint32_t vpd_size;
  7614. uint32_t ftr_rsp = 0;
  7615. struct Scsi_Host *shost = lpfc_shost_from_vport(phba->pport);
  7616. struct lpfc_vport *vport = phba->pport;
  7617. struct lpfc_dmabuf *mp;
  7618. struct lpfc_rqb *rqbp;
  7619. u32 flg;
  7620. /* Perform a PCI function reset to start from clean */
  7621. rc = lpfc_pci_function_reset(phba);
  7622. if (unlikely(rc))
  7623. return -ENODEV;
  7624. /* Check the HBA Host Status Register for readyness */
  7625. rc = lpfc_sli4_post_status_check(phba);
  7626. if (unlikely(rc))
  7627. return -ENODEV;
  7628. else {
  7629. spin_lock_irq(&phba->hbalock);
  7630. phba->sli.sli_flag |= LPFC_SLI_ACTIVE;
  7631. flg = phba->sli.sli_flag;
  7632. spin_unlock_irq(&phba->hbalock);
  7633. /* Allow a little time after setting SLI_ACTIVE for any polled
  7634. * MBX commands to complete via BSG.
  7635. */
  7636. for (i = 0; i < 50 && (flg & LPFC_SLI_MBOX_ACTIVE); i++) {
  7637. msleep(20);
  7638. spin_lock_irq(&phba->hbalock);
  7639. flg = phba->sli.sli_flag;
  7640. spin_unlock_irq(&phba->hbalock);
  7641. }
  7642. }
  7643. phba->hba_flag &= ~HBA_SETUP;
  7644. lpfc_sli4_dip(phba);
  7645. /*
  7646. * Allocate a single mailbox container for initializing the
  7647. * port.
  7648. */
  7649. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  7650. if (!mboxq)
  7651. return -ENOMEM;
  7652. /* Issue READ_REV to collect vpd and FW information. */
  7653. vpd_size = SLI4_PAGE_SIZE;
  7654. vpd = kzalloc(vpd_size, GFP_KERNEL);
  7655. if (!vpd) {
  7656. rc = -ENOMEM;
  7657. goto out_free_mbox;
  7658. }
  7659. rc = lpfc_sli4_read_rev(phba, mboxq, vpd, &vpd_size);
  7660. if (unlikely(rc)) {
  7661. kfree(vpd);
  7662. goto out_free_mbox;
  7663. }
  7664. mqe = &mboxq->u.mqe;
  7665. phba->sli_rev = bf_get(lpfc_mbx_rd_rev_sli_lvl, &mqe->un.read_rev);
  7666. if (bf_get(lpfc_mbx_rd_rev_fcoe, &mqe->un.read_rev)) {
  7667. phba->hba_flag |= HBA_FCOE_MODE;
  7668. phba->fcp_embed_io = 0; /* SLI4 FC support only */
  7669. } else {
  7670. phba->hba_flag &= ~HBA_FCOE_MODE;
  7671. }
  7672. if (bf_get(lpfc_mbx_rd_rev_cee_ver, &mqe->un.read_rev) ==
  7673. LPFC_DCBX_CEE_MODE)
  7674. phba->hba_flag |= HBA_FIP_SUPPORT;
  7675. else
  7676. phba->hba_flag &= ~HBA_FIP_SUPPORT;
  7677. phba->hba_flag &= ~HBA_IOQ_FLUSH;
  7678. if (phba->sli_rev != LPFC_SLI_REV4) {
  7679. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7680. "0376 READ_REV Error. SLI Level %d "
  7681. "FCoE enabled %d\n",
  7682. phba->sli_rev, phba->hba_flag & HBA_FCOE_MODE);
  7683. rc = -EIO;
  7684. kfree(vpd);
  7685. goto out_free_mbox;
  7686. }
  7687. rc = lpfc_set_host_tm(phba);
  7688. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_INIT,
  7689. "6468 Set host date / time: Status x%x:\n", rc);
  7690. /*
  7691. * Continue initialization with default values even if driver failed
  7692. * to read FCoE param config regions, only read parameters if the
  7693. * board is FCoE
  7694. */
  7695. if (phba->hba_flag & HBA_FCOE_MODE &&
  7696. lpfc_sli4_read_fcoe_params(phba))
  7697. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_INIT,
  7698. "2570 Failed to read FCoE parameters\n");
  7699. /*
  7700. * Retrieve sli4 device physical port name, failure of doing it
  7701. * is considered as non-fatal.
  7702. */
  7703. rc = lpfc_sli4_retrieve_pport_name(phba);
  7704. if (!rc)
  7705. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7706. "3080 Successful retrieving SLI4 device "
  7707. "physical port name: %s.\n", phba->Port);
  7708. rc = lpfc_sli4_get_ctl_attr(phba);
  7709. if (!rc)
  7710. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7711. "8351 Successful retrieving SLI4 device "
  7712. "CTL ATTR\n");
  7713. /*
  7714. * Evaluate the read rev and vpd data. Populate the driver
  7715. * state with the results. If this routine fails, the failure
  7716. * is not fatal as the driver will use generic values.
  7717. */
  7718. rc = lpfc_parse_vpd(phba, vpd, vpd_size);
  7719. if (unlikely(!rc)) {
  7720. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7721. "0377 Error %d parsing vpd. "
  7722. "Using defaults.\n", rc);
  7723. rc = 0;
  7724. }
  7725. kfree(vpd);
  7726. /* Save information as VPD data */
  7727. phba->vpd.rev.biuRev = mqe->un.read_rev.first_hw_rev;
  7728. phba->vpd.rev.smRev = mqe->un.read_rev.second_hw_rev;
  7729. /*
  7730. * This is because first G7 ASIC doesn't support the standard
  7731. * 0x5a NVME cmd descriptor type/subtype
  7732. */
  7733. if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  7734. LPFC_SLI_INTF_IF_TYPE_6) &&
  7735. (phba->vpd.rev.biuRev == LPFC_G7_ASIC_1) &&
  7736. (phba->vpd.rev.smRev == 0) &&
  7737. (phba->cfg_nvme_embed_cmd == 1))
  7738. phba->cfg_nvme_embed_cmd = 0;
  7739. phba->vpd.rev.endecRev = mqe->un.read_rev.third_hw_rev;
  7740. phba->vpd.rev.fcphHigh = bf_get(lpfc_mbx_rd_rev_fcph_high,
  7741. &mqe->un.read_rev);
  7742. phba->vpd.rev.fcphLow = bf_get(lpfc_mbx_rd_rev_fcph_low,
  7743. &mqe->un.read_rev);
  7744. phba->vpd.rev.feaLevelHigh = bf_get(lpfc_mbx_rd_rev_ftr_lvl_high,
  7745. &mqe->un.read_rev);
  7746. phba->vpd.rev.feaLevelLow = bf_get(lpfc_mbx_rd_rev_ftr_lvl_low,
  7747. &mqe->un.read_rev);
  7748. phba->vpd.rev.sli1FwRev = mqe->un.read_rev.fw_id_rev;
  7749. memcpy(phba->vpd.rev.sli1FwName, mqe->un.read_rev.fw_name, 16);
  7750. phba->vpd.rev.sli2FwRev = mqe->un.read_rev.ulp_fw_id_rev;
  7751. memcpy(phba->vpd.rev.sli2FwName, mqe->un.read_rev.ulp_fw_name, 16);
  7752. phba->vpd.rev.opFwRev = mqe->un.read_rev.fw_id_rev;
  7753. memcpy(phba->vpd.rev.opFwName, mqe->un.read_rev.fw_name, 16);
  7754. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  7755. "(%d):0380 READ_REV Status x%x "
  7756. "fw_rev:%s fcphHi:%x fcphLo:%x flHi:%x flLo:%x\n",
  7757. mboxq->vport ? mboxq->vport->vpi : 0,
  7758. bf_get(lpfc_mqe_status, mqe),
  7759. phba->vpd.rev.opFwName,
  7760. phba->vpd.rev.fcphHigh, phba->vpd.rev.fcphLow,
  7761. phba->vpd.rev.feaLevelHigh, phba->vpd.rev.feaLevelLow);
  7762. if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
  7763. LPFC_SLI_INTF_IF_TYPE_0) {
  7764. lpfc_set_features(phba, mboxq, LPFC_SET_UE_RECOVERY);
  7765. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7766. if (rc == MBX_SUCCESS) {
  7767. phba->hba_flag |= HBA_RECOVERABLE_UE;
  7768. /* Set 1Sec interval to detect UE */
  7769. phba->eratt_poll_interval = 1;
  7770. phba->sli4_hba.ue_to_sr = bf_get(
  7771. lpfc_mbx_set_feature_UESR,
  7772. &mboxq->u.mqe.un.set_feature);
  7773. phba->sli4_hba.ue_to_rp = bf_get(
  7774. lpfc_mbx_set_feature_UERP,
  7775. &mboxq->u.mqe.un.set_feature);
  7776. }
  7777. }
  7778. if (phba->cfg_enable_mds_diags && phba->mds_diags_support) {
  7779. /* Enable MDS Diagnostics only if the SLI Port supports it */
  7780. lpfc_set_features(phba, mboxq, LPFC_SET_MDS_DIAGS);
  7781. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7782. if (rc != MBX_SUCCESS)
  7783. phba->mds_diags_support = 0;
  7784. }
  7785. /*
  7786. * Discover the port's supported feature set and match it against the
  7787. * hosts requests.
  7788. */
  7789. lpfc_request_features(phba, mboxq);
  7790. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7791. if (unlikely(rc)) {
  7792. rc = -EIO;
  7793. goto out_free_mbox;
  7794. }
  7795. /* Disable VMID if app header is not supported */
  7796. if (phba->cfg_vmid_app_header && !(bf_get(lpfc_mbx_rq_ftr_rsp_ashdr,
  7797. &mqe->un.req_ftrs))) {
  7798. bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 0);
  7799. phba->cfg_vmid_app_header = 0;
  7800. lpfc_printf_log(phba, KERN_DEBUG, LOG_SLI,
  7801. "1242 vmid feature not supported\n");
  7802. }
  7803. /*
  7804. * The port must support FCP initiator mode as this is the
  7805. * only mode running in the host.
  7806. */
  7807. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_fcpi, &mqe->un.req_ftrs))) {
  7808. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  7809. "0378 No support for fcpi mode.\n");
  7810. ftr_rsp++;
  7811. }
  7812. /* Performance Hints are ONLY for FCoE */
  7813. if (phba->hba_flag & HBA_FCOE_MODE) {
  7814. if (bf_get(lpfc_mbx_rq_ftr_rsp_perfh, &mqe->un.req_ftrs))
  7815. phba->sli3_options |= LPFC_SLI4_PERFH_ENABLED;
  7816. else
  7817. phba->sli3_options &= ~LPFC_SLI4_PERFH_ENABLED;
  7818. }
  7819. /*
  7820. * If the port cannot support the host's requested features
  7821. * then turn off the global config parameters to disable the
  7822. * feature in the driver. This is not a fatal error.
  7823. */
  7824. if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) {
  7825. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs))) {
  7826. phba->cfg_enable_bg = 0;
  7827. phba->sli3_options &= ~LPFC_SLI3_BG_ENABLED;
  7828. ftr_rsp++;
  7829. }
  7830. }
  7831. if (phba->max_vpi && phba->cfg_enable_npiv &&
  7832. !(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  7833. ftr_rsp++;
  7834. if (ftr_rsp) {
  7835. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  7836. "0379 Feature Mismatch Data: x%08x %08x "
  7837. "x%x x%x x%x\n", mqe->un.req_ftrs.word2,
  7838. mqe->un.req_ftrs.word3, phba->cfg_enable_bg,
  7839. phba->cfg_enable_npiv, phba->max_vpi);
  7840. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_dif, &mqe->un.req_ftrs)))
  7841. phba->cfg_enable_bg = 0;
  7842. if (!(bf_get(lpfc_mbx_rq_ftr_rsp_npiv, &mqe->un.req_ftrs)))
  7843. phba->cfg_enable_npiv = 0;
  7844. }
  7845. /* These SLI3 features are assumed in SLI4 */
  7846. spin_lock_irq(&phba->hbalock);
  7847. phba->sli3_options |= (LPFC_SLI3_NPIV_ENABLED | LPFC_SLI3_HBQ_ENABLED);
  7848. spin_unlock_irq(&phba->hbalock);
  7849. /* Always try to enable dual dump feature if we can */
  7850. lpfc_set_features(phba, mboxq, LPFC_SET_DUAL_DUMP);
  7851. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7852. dd = bf_get(lpfc_mbx_set_feature_dd, &mboxq->u.mqe.un.set_feature);
  7853. if ((rc == MBX_SUCCESS) && (dd == LPFC_ENABLE_DUAL_DUMP))
  7854. lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
  7855. "6448 Dual Dump is enabled\n");
  7856. else
  7857. lpfc_printf_log(phba, KERN_INFO, LOG_SLI | LOG_INIT,
  7858. "6447 Dual Dump Mailbox x%x (x%x/x%x) failed, "
  7859. "rc:x%x dd:x%x\n",
  7860. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  7861. lpfc_sli_config_mbox_subsys_get(
  7862. phba, mboxq),
  7863. lpfc_sli_config_mbox_opcode_get(
  7864. phba, mboxq),
  7865. rc, dd);
  7866. /*
  7867. * Allocate all resources (xri,rpi,vpi,vfi) now. Subsequent
  7868. * calls depends on these resources to complete port setup.
  7869. */
  7870. rc = lpfc_sli4_alloc_resource_identifiers(phba);
  7871. if (rc) {
  7872. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7873. "2920 Failed to alloc Resource IDs "
  7874. "rc = x%x\n", rc);
  7875. goto out_free_mbox;
  7876. }
  7877. lpfc_set_host_data(phba, mboxq);
  7878. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7879. if (rc) {
  7880. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  7881. "2134 Failed to set host os driver version %x",
  7882. rc);
  7883. }
  7884. /* Read the port's service parameters. */
  7885. rc = lpfc_read_sparam(phba, mboxq, vport->vpi);
  7886. if (rc) {
  7887. phba->link_state = LPFC_HBA_ERROR;
  7888. rc = -ENOMEM;
  7889. goto out_free_mbox;
  7890. }
  7891. mboxq->vport = vport;
  7892. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  7893. mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
  7894. if (rc == MBX_SUCCESS) {
  7895. memcpy(&vport->fc_sparam, mp->virt, sizeof(struct serv_parm));
  7896. rc = 0;
  7897. }
  7898. /*
  7899. * This memory was allocated by the lpfc_read_sparam routine but is
  7900. * no longer needed. It is released and ctx_buf NULLed to prevent
  7901. * unintended pointer access as the mbox is reused.
  7902. */
  7903. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  7904. kfree(mp);
  7905. mboxq->ctx_buf = NULL;
  7906. if (unlikely(rc)) {
  7907. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7908. "0382 READ_SPARAM command failed "
  7909. "status %d, mbxStatus x%x\n",
  7910. rc, bf_get(lpfc_mqe_status, mqe));
  7911. phba->link_state = LPFC_HBA_ERROR;
  7912. rc = -EIO;
  7913. goto out_free_mbox;
  7914. }
  7915. lpfc_update_vport_wwn(vport);
  7916. /* Update the fc_host data structures with new wwn. */
  7917. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  7918. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  7919. /* Create all the SLI4 queues */
  7920. rc = lpfc_sli4_queue_create(phba);
  7921. if (rc) {
  7922. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7923. "3089 Failed to allocate queues\n");
  7924. rc = -ENODEV;
  7925. goto out_free_mbox;
  7926. }
  7927. /* Set up all the queues to the device */
  7928. rc = lpfc_sli4_queue_setup(phba);
  7929. if (unlikely(rc)) {
  7930. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7931. "0381 Error %d during queue setup.\n ", rc);
  7932. goto out_stop_timers;
  7933. }
  7934. /* Initialize the driver internal SLI layer lists. */
  7935. lpfc_sli4_setup(phba);
  7936. lpfc_sli4_queue_init(phba);
  7937. /* update host els xri-sgl sizes and mappings */
  7938. rc = lpfc_sli4_els_sgl_update(phba);
  7939. if (unlikely(rc)) {
  7940. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7941. "1400 Failed to update xri-sgl size and "
  7942. "mapping: %d\n", rc);
  7943. goto out_destroy_queue;
  7944. }
  7945. /* register the els sgl pool to the port */
  7946. rc = lpfc_sli4_repost_sgl_list(phba, &phba->sli4_hba.lpfc_els_sgl_list,
  7947. phba->sli4_hba.els_xri_cnt);
  7948. if (unlikely(rc < 0)) {
  7949. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7950. "0582 Error %d during els sgl post "
  7951. "operation\n", rc);
  7952. rc = -ENODEV;
  7953. goto out_destroy_queue;
  7954. }
  7955. phba->sli4_hba.els_xri_cnt = rc;
  7956. if (phba->nvmet_support) {
  7957. /* update host nvmet xri-sgl sizes and mappings */
  7958. rc = lpfc_sli4_nvmet_sgl_update(phba);
  7959. if (unlikely(rc)) {
  7960. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7961. "6308 Failed to update nvmet-sgl size "
  7962. "and mapping: %d\n", rc);
  7963. goto out_destroy_queue;
  7964. }
  7965. /* register the nvmet sgl pool to the port */
  7966. rc = lpfc_sli4_repost_sgl_list(
  7967. phba,
  7968. &phba->sli4_hba.lpfc_nvmet_sgl_list,
  7969. phba->sli4_hba.nvmet_xri_cnt);
  7970. if (unlikely(rc < 0)) {
  7971. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7972. "3117 Error %d during nvmet "
  7973. "sgl post\n", rc);
  7974. rc = -ENODEV;
  7975. goto out_destroy_queue;
  7976. }
  7977. phba->sli4_hba.nvmet_xri_cnt = rc;
  7978. /* We allocate an iocbq for every receive context SGL.
  7979. * The additional allocation is for abort and ls handling.
  7980. */
  7981. cnt = phba->sli4_hba.nvmet_xri_cnt +
  7982. phba->sli4_hba.max_cfg_param.max_xri;
  7983. } else {
  7984. /* update host common xri-sgl sizes and mappings */
  7985. rc = lpfc_sli4_io_sgl_update(phba);
  7986. if (unlikely(rc)) {
  7987. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7988. "6082 Failed to update nvme-sgl size "
  7989. "and mapping: %d\n", rc);
  7990. goto out_destroy_queue;
  7991. }
  7992. /* register the allocated common sgl pool to the port */
  7993. rc = lpfc_sli4_repost_io_sgl_list(phba);
  7994. if (unlikely(rc)) {
  7995. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  7996. "6116 Error %d during nvme sgl post "
  7997. "operation\n", rc);
  7998. /* Some NVME buffers were moved to abort nvme list */
  7999. /* A pci function reset will repost them */
  8000. rc = -ENODEV;
  8001. goto out_destroy_queue;
  8002. }
  8003. /* Each lpfc_io_buf job structure has an iocbq element.
  8004. * This cnt provides for abort, els, ct and ls requests.
  8005. */
  8006. cnt = phba->sli4_hba.max_cfg_param.max_xri;
  8007. }
  8008. if (!phba->sli.iocbq_lookup) {
  8009. /* Initialize and populate the iocb list per host */
  8010. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8011. "2821 initialize iocb list with %d entries\n",
  8012. cnt);
  8013. rc = lpfc_init_iocb_list(phba, cnt);
  8014. if (rc) {
  8015. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8016. "1413 Failed to init iocb list.\n");
  8017. goto out_destroy_queue;
  8018. }
  8019. }
  8020. if (phba->nvmet_support)
  8021. lpfc_nvmet_create_targetport(phba);
  8022. if (phba->nvmet_support && phba->cfg_nvmet_mrq) {
  8023. /* Post initial buffers to all RQs created */
  8024. for (i = 0; i < phba->cfg_nvmet_mrq; i++) {
  8025. rqbp = phba->sli4_hba.nvmet_mrq_hdr[i]->rqbp;
  8026. INIT_LIST_HEAD(&rqbp->rqb_buffer_list);
  8027. rqbp->rqb_alloc_buffer = lpfc_sli4_nvmet_alloc;
  8028. rqbp->rqb_free_buffer = lpfc_sli4_nvmet_free;
  8029. rqbp->entry_count = LPFC_NVMET_RQE_DEF_COUNT;
  8030. rqbp->buffer_count = 0;
  8031. lpfc_post_rq_buffer(
  8032. phba, phba->sli4_hba.nvmet_mrq_hdr[i],
  8033. phba->sli4_hba.nvmet_mrq_data[i],
  8034. phba->cfg_nvmet_mrq_post, i);
  8035. }
  8036. }
  8037. /* Post the rpi header region to the device. */
  8038. rc = lpfc_sli4_post_all_rpi_hdrs(phba);
  8039. if (unlikely(rc)) {
  8040. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8041. "0393 Error %d during rpi post operation\n",
  8042. rc);
  8043. rc = -ENODEV;
  8044. goto out_free_iocblist;
  8045. }
  8046. lpfc_sli4_node_prep(phba);
  8047. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  8048. if ((phba->nvmet_support == 0) || (phba->cfg_nvmet_mrq == 1)) {
  8049. /*
  8050. * The FC Port needs to register FCFI (index 0)
  8051. */
  8052. lpfc_reg_fcfi(phba, mboxq);
  8053. mboxq->vport = phba->pport;
  8054. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8055. if (rc != MBX_SUCCESS)
  8056. goto out_unset_queue;
  8057. rc = 0;
  8058. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi,
  8059. &mboxq->u.mqe.un.reg_fcfi);
  8060. } else {
  8061. /* We are a NVME Target mode with MRQ > 1 */
  8062. /* First register the FCFI */
  8063. lpfc_reg_fcfi_mrq(phba, mboxq, 0);
  8064. mboxq->vport = phba->pport;
  8065. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8066. if (rc != MBX_SUCCESS)
  8067. goto out_unset_queue;
  8068. rc = 0;
  8069. phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_mrq_fcfi,
  8070. &mboxq->u.mqe.un.reg_fcfi_mrq);
  8071. /* Next register the MRQs */
  8072. lpfc_reg_fcfi_mrq(phba, mboxq, 1);
  8073. mboxq->vport = phba->pport;
  8074. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8075. if (rc != MBX_SUCCESS)
  8076. goto out_unset_queue;
  8077. rc = 0;
  8078. }
  8079. /* Check if the port is configured to be disabled */
  8080. lpfc_sli_read_link_ste(phba);
  8081. }
  8082. /* Don't post more new bufs if repost already recovered
  8083. * the nvme sgls.
  8084. */
  8085. if (phba->nvmet_support == 0) {
  8086. if (phba->sli4_hba.io_xri_cnt == 0) {
  8087. len = lpfc_new_io_buf(
  8088. phba, phba->sli4_hba.io_xri_max);
  8089. if (len == 0) {
  8090. rc = -ENOMEM;
  8091. goto out_unset_queue;
  8092. }
  8093. if (phba->cfg_xri_rebalancing)
  8094. lpfc_create_multixri_pools(phba);
  8095. }
  8096. } else {
  8097. phba->cfg_xri_rebalancing = 0;
  8098. }
  8099. /* Allow asynchronous mailbox command to go through */
  8100. spin_lock_irq(&phba->hbalock);
  8101. phba->sli.sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  8102. spin_unlock_irq(&phba->hbalock);
  8103. /* Post receive buffers to the device */
  8104. lpfc_sli4_rb_setup(phba);
  8105. /* Reset HBA FCF states after HBA reset */
  8106. phba->fcf.fcf_flag = 0;
  8107. phba->fcf.current_rec.flag = 0;
  8108. /* Start the ELS watchdog timer */
  8109. mod_timer(&vport->els_tmofunc,
  8110. jiffies + msecs_to_jiffies(1000 * (phba->fc_ratov * 2)));
  8111. /* Start heart beat timer */
  8112. mod_timer(&phba->hb_tmofunc,
  8113. jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL));
  8114. phba->hba_flag &= ~(HBA_HBEAT_INP | HBA_HBEAT_TMO);
  8115. phba->last_completion_time = jiffies;
  8116. /* start eq_delay heartbeat */
  8117. if (phba->cfg_auto_imax)
  8118. queue_delayed_work(phba->wq, &phba->eq_delay_work,
  8119. msecs_to_jiffies(LPFC_EQ_DELAY_MSECS));
  8120. /* start per phba idle_stat_delay heartbeat */
  8121. lpfc_init_idle_stat_hb(phba);
  8122. /* Start error attention (ERATT) polling timer */
  8123. mod_timer(&phba->eratt_poll,
  8124. jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval));
  8125. /* Enable PCIe device Advanced Error Reporting (AER) if configured */
  8126. if (phba->cfg_aer_support == 1 && !(phba->hba_flag & HBA_AER_ENABLED)) {
  8127. rc = pci_enable_pcie_error_reporting(phba->pcidev);
  8128. if (!rc) {
  8129. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8130. "2829 This device supports "
  8131. "Advanced Error Reporting (AER)\n");
  8132. spin_lock_irq(&phba->hbalock);
  8133. phba->hba_flag |= HBA_AER_ENABLED;
  8134. spin_unlock_irq(&phba->hbalock);
  8135. } else {
  8136. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  8137. "2830 This device does not support "
  8138. "Advanced Error Reporting (AER)\n");
  8139. phba->cfg_aer_support = 0;
  8140. }
  8141. rc = 0;
  8142. }
  8143. /*
  8144. * The port is ready, set the host's link state to LINK_DOWN
  8145. * in preparation for link interrupts.
  8146. */
  8147. spin_lock_irq(&phba->hbalock);
  8148. phba->link_state = LPFC_LINK_DOWN;
  8149. /* Check if physical ports are trunked */
  8150. if (bf_get(lpfc_conf_trunk_port0, &phba->sli4_hba))
  8151. phba->trunk_link.link0.state = LPFC_LINK_DOWN;
  8152. if (bf_get(lpfc_conf_trunk_port1, &phba->sli4_hba))
  8153. phba->trunk_link.link1.state = LPFC_LINK_DOWN;
  8154. if (bf_get(lpfc_conf_trunk_port2, &phba->sli4_hba))
  8155. phba->trunk_link.link2.state = LPFC_LINK_DOWN;
  8156. if (bf_get(lpfc_conf_trunk_port3, &phba->sli4_hba))
  8157. phba->trunk_link.link3.state = LPFC_LINK_DOWN;
  8158. spin_unlock_irq(&phba->hbalock);
  8159. /* Arm the CQs and then EQs on device */
  8160. lpfc_sli4_arm_cqeq_intr(phba);
  8161. /* Indicate device interrupt mode */
  8162. phba->sli4_hba.intr_enable = 1;
  8163. /* Setup CMF after HBA is initialized */
  8164. lpfc_cmf_setup(phba);
  8165. if (!(phba->hba_flag & HBA_FCOE_MODE) &&
  8166. (phba->hba_flag & LINK_DISABLED)) {
  8167. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8168. "3103 Adapter Link is disabled.\n");
  8169. lpfc_down_link(phba, mboxq);
  8170. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  8171. if (rc != MBX_SUCCESS) {
  8172. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8173. "3104 Adapter failed to issue "
  8174. "DOWN_LINK mbox cmd, rc:x%x\n", rc);
  8175. goto out_io_buff_free;
  8176. }
  8177. } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) {
  8178. /* don't perform init_link on SLI4 FC port loopback test */
  8179. if (!(phba->link_flag & LS_LOOPBACK_MODE)) {
  8180. rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT);
  8181. if (rc)
  8182. goto out_io_buff_free;
  8183. }
  8184. }
  8185. mempool_free(mboxq, phba->mbox_mem_pool);
  8186. /* Enable RAS FW log support */
  8187. lpfc_sli4_ras_setup(phba);
  8188. phba->hba_flag |= HBA_SETUP;
  8189. return rc;
  8190. out_io_buff_free:
  8191. /* Free allocated IO Buffers */
  8192. lpfc_io_free(phba);
  8193. out_unset_queue:
  8194. /* Unset all the queues set up in this routine when error out */
  8195. lpfc_sli4_queue_unset(phba);
  8196. out_free_iocblist:
  8197. lpfc_free_iocb_list(phba);
  8198. out_destroy_queue:
  8199. lpfc_sli4_queue_destroy(phba);
  8200. out_stop_timers:
  8201. lpfc_stop_hba_timers(phba);
  8202. out_free_mbox:
  8203. mempool_free(mboxq, phba->mbox_mem_pool);
  8204. return rc;
  8205. }
  8206. /**
  8207. * lpfc_mbox_timeout - Timeout call back function for mbox timer
  8208. * @t: Context to fetch pointer to hba structure from.
  8209. *
  8210. * This is the callback function for mailbox timer. The mailbox
  8211. * timer is armed when a new mailbox command is issued and the timer
  8212. * is deleted when the mailbox complete. The function is called by
  8213. * the kernel timer code when a mailbox does not complete within
  8214. * expected time. This function wakes up the worker thread to
  8215. * process the mailbox timeout and returns. All the processing is
  8216. * done by the worker thread function lpfc_mbox_timeout_handler.
  8217. **/
  8218. void
  8219. lpfc_mbox_timeout(struct timer_list *t)
  8220. {
  8221. struct lpfc_hba *phba = from_timer(phba, t, sli.mbox_tmo);
  8222. unsigned long iflag;
  8223. uint32_t tmo_posted;
  8224. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  8225. tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
  8226. if (!tmo_posted)
  8227. phba->pport->work_port_events |= WORKER_MBOX_TMO;
  8228. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  8229. if (!tmo_posted)
  8230. lpfc_worker_wake_up(phba);
  8231. return;
  8232. }
  8233. /**
  8234. * lpfc_sli4_mbox_completions_pending - check to see if any mailbox completions
  8235. * are pending
  8236. * @phba: Pointer to HBA context object.
  8237. *
  8238. * This function checks if any mailbox completions are present on the mailbox
  8239. * completion queue.
  8240. **/
  8241. static bool
  8242. lpfc_sli4_mbox_completions_pending(struct lpfc_hba *phba)
  8243. {
  8244. uint32_t idx;
  8245. struct lpfc_queue *mcq;
  8246. struct lpfc_mcqe *mcqe;
  8247. bool pending_completions = false;
  8248. uint8_t qe_valid;
  8249. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  8250. return false;
  8251. /* Check for completions on mailbox completion queue */
  8252. mcq = phba->sli4_hba.mbx_cq;
  8253. idx = mcq->hba_index;
  8254. qe_valid = mcq->qe_valid;
  8255. while (bf_get_le32(lpfc_cqe_valid,
  8256. (struct lpfc_cqe *)lpfc_sli4_qe(mcq, idx)) == qe_valid) {
  8257. mcqe = (struct lpfc_mcqe *)(lpfc_sli4_qe(mcq, idx));
  8258. if (bf_get_le32(lpfc_trailer_completed, mcqe) &&
  8259. (!bf_get_le32(lpfc_trailer_async, mcqe))) {
  8260. pending_completions = true;
  8261. break;
  8262. }
  8263. idx = (idx + 1) % mcq->entry_count;
  8264. if (mcq->hba_index == idx)
  8265. break;
  8266. /* if the index wrapped around, toggle the valid bit */
  8267. if (phba->sli4_hba.pc_sli4_params.cqav && !idx)
  8268. qe_valid = (qe_valid) ? 0 : 1;
  8269. }
  8270. return pending_completions;
  8271. }
  8272. /**
  8273. * lpfc_sli4_process_missed_mbox_completions - process mbox completions
  8274. * that were missed.
  8275. * @phba: Pointer to HBA context object.
  8276. *
  8277. * For sli4, it is possible to miss an interrupt. As such mbox completions
  8278. * maybe missed causing erroneous mailbox timeouts to occur. This function
  8279. * checks to see if mbox completions are on the mailbox completion queue
  8280. * and will process all the completions associated with the eq for the
  8281. * mailbox completion queue.
  8282. **/
  8283. static bool
  8284. lpfc_sli4_process_missed_mbox_completions(struct lpfc_hba *phba)
  8285. {
  8286. struct lpfc_sli4_hba *sli4_hba = &phba->sli4_hba;
  8287. uint32_t eqidx;
  8288. struct lpfc_queue *fpeq = NULL;
  8289. struct lpfc_queue *eq;
  8290. bool mbox_pending;
  8291. if (unlikely(!phba) || (phba->sli_rev != LPFC_SLI_REV4))
  8292. return false;
  8293. /* Find the EQ associated with the mbox CQ */
  8294. if (sli4_hba->hdwq) {
  8295. for (eqidx = 0; eqidx < phba->cfg_irq_chann; eqidx++) {
  8296. eq = phba->sli4_hba.hba_eq_hdl[eqidx].eq;
  8297. if (eq && eq->queue_id == sli4_hba->mbx_cq->assoc_qid) {
  8298. fpeq = eq;
  8299. break;
  8300. }
  8301. }
  8302. }
  8303. if (!fpeq)
  8304. return false;
  8305. /* Turn off interrupts from this EQ */
  8306. sli4_hba->sli4_eq_clr_intr(fpeq);
  8307. /* Check to see if a mbox completion is pending */
  8308. mbox_pending = lpfc_sli4_mbox_completions_pending(phba);
  8309. /*
  8310. * If a mbox completion is pending, process all the events on EQ
  8311. * associated with the mbox completion queue (this could include
  8312. * mailbox commands, async events, els commands, receive queue data
  8313. * and fcp commands)
  8314. */
  8315. if (mbox_pending)
  8316. /* process and rearm the EQ */
  8317. lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
  8318. else
  8319. /* Always clear and re-arm the EQ */
  8320. sli4_hba->sli4_write_eq_db(phba, fpeq, 0, LPFC_QUEUE_REARM);
  8321. return mbox_pending;
  8322. }
  8323. /**
  8324. * lpfc_mbox_timeout_handler - Worker thread function to handle mailbox timeout
  8325. * @phba: Pointer to HBA context object.
  8326. *
  8327. * This function is called from worker thread when a mailbox command times out.
  8328. * The caller is not required to hold any locks. This function will reset the
  8329. * HBA and recover all the pending commands.
  8330. **/
  8331. void
  8332. lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
  8333. {
  8334. LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
  8335. MAILBOX_t *mb = NULL;
  8336. struct lpfc_sli *psli = &phba->sli;
  8337. /* If the mailbox completed, process the completion */
  8338. lpfc_sli4_process_missed_mbox_completions(phba);
  8339. if (!(psli->sli_flag & LPFC_SLI_ACTIVE))
  8340. return;
  8341. if (pmbox != NULL)
  8342. mb = &pmbox->u.mb;
  8343. /* Check the pmbox pointer first. There is a race condition
  8344. * between the mbox timeout handler getting executed in the
  8345. * worklist and the mailbox actually completing. When this
  8346. * race condition occurs, the mbox_active will be NULL.
  8347. */
  8348. spin_lock_irq(&phba->hbalock);
  8349. if (pmbox == NULL) {
  8350. lpfc_printf_log(phba, KERN_WARNING,
  8351. LOG_MBOX | LOG_SLI,
  8352. "0353 Active Mailbox cleared - mailbox timeout "
  8353. "exiting\n");
  8354. spin_unlock_irq(&phba->hbalock);
  8355. return;
  8356. }
  8357. /* Mbox cmd <mbxCommand> timeout */
  8358. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8359. "0310 Mailbox command x%x timeout Data: x%x x%x x%px\n",
  8360. mb->mbxCommand,
  8361. phba->pport->port_state,
  8362. phba->sli.sli_flag,
  8363. phba->sli.mbox_active);
  8364. spin_unlock_irq(&phba->hbalock);
  8365. /* Setting state unknown so lpfc_sli_abort_iocb_ring
  8366. * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
  8367. * it to fail all outstanding SCSI IO.
  8368. */
  8369. set_bit(MBX_TMO_ERR, &phba->bit_flags);
  8370. spin_lock_irq(&phba->pport->work_port_lock);
  8371. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  8372. spin_unlock_irq(&phba->pport->work_port_lock);
  8373. spin_lock_irq(&phba->hbalock);
  8374. phba->link_state = LPFC_LINK_UNKNOWN;
  8375. psli->sli_flag &= ~LPFC_SLI_ACTIVE;
  8376. spin_unlock_irq(&phba->hbalock);
  8377. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8378. "0345 Resetting board due to mailbox timeout\n");
  8379. /* Reset the HBA device */
  8380. lpfc_reset_hba(phba);
  8381. }
  8382. /**
  8383. * lpfc_sli_issue_mbox_s3 - Issue an SLI3 mailbox command to firmware
  8384. * @phba: Pointer to HBA context object.
  8385. * @pmbox: Pointer to mailbox object.
  8386. * @flag: Flag indicating how the mailbox need to be processed.
  8387. *
  8388. * This function is called by discovery code and HBA management code
  8389. * to submit a mailbox command to firmware with SLI-3 interface spec. This
  8390. * function gets the hbalock to protect the data structures.
  8391. * The mailbox command can be submitted in polling mode, in which case
  8392. * this function will wait in a polling loop for the completion of the
  8393. * mailbox.
  8394. * If the mailbox is submitted in no_wait mode (not polling) the
  8395. * function will submit the command and returns immediately without waiting
  8396. * for the mailbox completion. The no_wait is supported only when HBA
  8397. * is in SLI2/SLI3 mode - interrupts are enabled.
  8398. * The SLI interface allows only one mailbox pending at a time. If the
  8399. * mailbox is issued in polling mode and there is already a mailbox
  8400. * pending, then the function will return an error. If the mailbox is issued
  8401. * in NO_WAIT mode and there is a mailbox pending already, the function
  8402. * will return MBX_BUSY after queuing the mailbox into mailbox queue.
  8403. * The sli layer owns the mailbox object until the completion of mailbox
  8404. * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
  8405. * return codes the caller owns the mailbox command after the return of
  8406. * the function.
  8407. **/
  8408. static int
  8409. lpfc_sli_issue_mbox_s3(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox,
  8410. uint32_t flag)
  8411. {
  8412. MAILBOX_t *mbx;
  8413. struct lpfc_sli *psli = &phba->sli;
  8414. uint32_t status, evtctr;
  8415. uint32_t ha_copy, hc_copy;
  8416. int i;
  8417. unsigned long timeout;
  8418. unsigned long drvr_flag = 0;
  8419. uint32_t word0, ldata;
  8420. void __iomem *to_slim;
  8421. int processing_queue = 0;
  8422. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  8423. if (!pmbox) {
  8424. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8425. /* processing mbox queue from intr_handler */
  8426. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  8427. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8428. return MBX_SUCCESS;
  8429. }
  8430. processing_queue = 1;
  8431. pmbox = lpfc_mbox_get(phba);
  8432. if (!pmbox) {
  8433. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8434. return MBX_SUCCESS;
  8435. }
  8436. }
  8437. if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
  8438. pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
  8439. if(!pmbox->vport) {
  8440. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8441. lpfc_printf_log(phba, KERN_ERR,
  8442. LOG_MBOX | LOG_VPORT,
  8443. "1806 Mbox x%x failed. No vport\n",
  8444. pmbox->u.mb.mbxCommand);
  8445. dump_stack();
  8446. goto out_not_finished;
  8447. }
  8448. }
  8449. /* If the PCI channel is in offline state, do not post mbox. */
  8450. if (unlikely(pci_channel_offline(phba->pcidev))) {
  8451. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8452. goto out_not_finished;
  8453. }
  8454. /* If HBA has a deferred error attention, fail the iocb. */
  8455. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  8456. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8457. goto out_not_finished;
  8458. }
  8459. psli = &phba->sli;
  8460. mbx = &pmbox->u.mb;
  8461. status = MBX_SUCCESS;
  8462. if (phba->link_state == LPFC_HBA_ERROR) {
  8463. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8464. /* Mbox command <mbxCommand> cannot issue */
  8465. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8466. "(%d):0311 Mailbox command x%x cannot "
  8467. "issue Data: x%x x%x\n",
  8468. pmbox->vport ? pmbox->vport->vpi : 0,
  8469. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  8470. goto out_not_finished;
  8471. }
  8472. if (mbx->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT) {
  8473. if (lpfc_readl(phba->HCregaddr, &hc_copy) ||
  8474. !(hc_copy & HC_MBINT_ENA)) {
  8475. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8476. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8477. "(%d):2528 Mailbox command x%x cannot "
  8478. "issue Data: x%x x%x\n",
  8479. pmbox->vport ? pmbox->vport->vpi : 0,
  8480. pmbox->u.mb.mbxCommand, psli->sli_flag, flag);
  8481. goto out_not_finished;
  8482. }
  8483. }
  8484. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8485. /* Polling for a mbox command when another one is already active
  8486. * is not allowed in SLI. Also, the driver must have established
  8487. * SLI2 mode to queue and process multiple mbox commands.
  8488. */
  8489. if (flag & MBX_POLL) {
  8490. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8491. /* Mbox command <mbxCommand> cannot issue */
  8492. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8493. "(%d):2529 Mailbox command x%x "
  8494. "cannot issue Data: x%x x%x\n",
  8495. pmbox->vport ? pmbox->vport->vpi : 0,
  8496. pmbox->u.mb.mbxCommand,
  8497. psli->sli_flag, flag);
  8498. goto out_not_finished;
  8499. }
  8500. if (!(psli->sli_flag & LPFC_SLI_ACTIVE)) {
  8501. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8502. /* Mbox command <mbxCommand> cannot issue */
  8503. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8504. "(%d):2530 Mailbox command x%x "
  8505. "cannot issue Data: x%x x%x\n",
  8506. pmbox->vport ? pmbox->vport->vpi : 0,
  8507. pmbox->u.mb.mbxCommand,
  8508. psli->sli_flag, flag);
  8509. goto out_not_finished;
  8510. }
  8511. /* Another mailbox command is still being processed, queue this
  8512. * command to be processed later.
  8513. */
  8514. lpfc_mbox_put(phba, pmbox);
  8515. /* Mbox cmd issue - BUSY */
  8516. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  8517. "(%d):0308 Mbox cmd issue - BUSY Data: "
  8518. "x%x x%x x%x x%x\n",
  8519. pmbox->vport ? pmbox->vport->vpi : 0xffffff,
  8520. mbx->mbxCommand,
  8521. phba->pport ? phba->pport->port_state : 0xff,
  8522. psli->sli_flag, flag);
  8523. psli->slistat.mbox_busy++;
  8524. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8525. if (pmbox->vport) {
  8526. lpfc_debugfs_disc_trc(pmbox->vport,
  8527. LPFC_DISC_TRC_MBOX_VPORT,
  8528. "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
  8529. (uint32_t)mbx->mbxCommand,
  8530. mbx->un.varWords[0], mbx->un.varWords[1]);
  8531. }
  8532. else {
  8533. lpfc_debugfs_disc_trc(phba->pport,
  8534. LPFC_DISC_TRC_MBOX,
  8535. "MBOX Bsy: cmd:x%x mb:x%x x%x",
  8536. (uint32_t)mbx->mbxCommand,
  8537. mbx->un.varWords[0], mbx->un.varWords[1]);
  8538. }
  8539. return MBX_BUSY;
  8540. }
  8541. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  8542. /* If we are not polling, we MUST be in SLI2 mode */
  8543. if (flag != MBX_POLL) {
  8544. if (!(psli->sli_flag & LPFC_SLI_ACTIVE) &&
  8545. (mbx->mbxCommand != MBX_KILL_BOARD)) {
  8546. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8547. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8548. /* Mbox command <mbxCommand> cannot issue */
  8549. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8550. "(%d):2531 Mailbox command x%x "
  8551. "cannot issue Data: x%x x%x\n",
  8552. pmbox->vport ? pmbox->vport->vpi : 0,
  8553. pmbox->u.mb.mbxCommand,
  8554. psli->sli_flag, flag);
  8555. goto out_not_finished;
  8556. }
  8557. /* timeout active mbox command */
  8558. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  8559. 1000);
  8560. mod_timer(&psli->mbox_tmo, jiffies + timeout);
  8561. }
  8562. /* Mailbox cmd <cmd> issue */
  8563. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  8564. "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
  8565. "x%x\n",
  8566. pmbox->vport ? pmbox->vport->vpi : 0,
  8567. mbx->mbxCommand,
  8568. phba->pport ? phba->pport->port_state : 0xff,
  8569. psli->sli_flag, flag);
  8570. if (mbx->mbxCommand != MBX_HEARTBEAT) {
  8571. if (pmbox->vport) {
  8572. lpfc_debugfs_disc_trc(pmbox->vport,
  8573. LPFC_DISC_TRC_MBOX_VPORT,
  8574. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  8575. (uint32_t)mbx->mbxCommand,
  8576. mbx->un.varWords[0], mbx->un.varWords[1]);
  8577. }
  8578. else {
  8579. lpfc_debugfs_disc_trc(phba->pport,
  8580. LPFC_DISC_TRC_MBOX,
  8581. "MBOX Send: cmd:x%x mb:x%x x%x",
  8582. (uint32_t)mbx->mbxCommand,
  8583. mbx->un.varWords[0], mbx->un.varWords[1]);
  8584. }
  8585. }
  8586. psli->slistat.mbox_cmd++;
  8587. evtctr = psli->slistat.mbox_event;
  8588. /* next set own bit for the adapter and copy over command word */
  8589. mbx->mbxOwner = OWN_CHIP;
  8590. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8591. /* Populate mbox extension offset word. */
  8592. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len) {
  8593. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  8594. = (uint8_t *)phba->mbox_ext
  8595. - (uint8_t *)phba->mbox;
  8596. }
  8597. /* Copy the mailbox extension data */
  8598. if (pmbox->in_ext_byte_len && pmbox->ctx_buf) {
  8599. lpfc_sli_pcimem_bcopy(pmbox->ctx_buf,
  8600. (uint8_t *)phba->mbox_ext,
  8601. pmbox->in_ext_byte_len);
  8602. }
  8603. /* Copy command data to host SLIM area */
  8604. lpfc_sli_pcimem_bcopy(mbx, phba->mbox, MAILBOX_CMD_SIZE);
  8605. } else {
  8606. /* Populate mbox extension offset word. */
  8607. if (pmbox->in_ext_byte_len || pmbox->out_ext_byte_len)
  8608. *(((uint32_t *)mbx) + pmbox->mbox_offset_word)
  8609. = MAILBOX_HBA_EXT_OFFSET;
  8610. /* Copy the mailbox extension data */
  8611. if (pmbox->in_ext_byte_len && pmbox->ctx_buf)
  8612. lpfc_memcpy_to_slim(phba->MBslimaddr +
  8613. MAILBOX_HBA_EXT_OFFSET,
  8614. pmbox->ctx_buf, pmbox->in_ext_byte_len);
  8615. if (mbx->mbxCommand == MBX_CONFIG_PORT)
  8616. /* copy command data into host mbox for cmpl */
  8617. lpfc_sli_pcimem_bcopy(mbx, phba->mbox,
  8618. MAILBOX_CMD_SIZE);
  8619. /* First copy mbox command data to HBA SLIM, skip past first
  8620. word */
  8621. to_slim = phba->MBslimaddr + sizeof (uint32_t);
  8622. lpfc_memcpy_to_slim(to_slim, &mbx->un.varWords[0],
  8623. MAILBOX_CMD_SIZE - sizeof (uint32_t));
  8624. /* Next copy over first word, with mbxOwner set */
  8625. ldata = *((uint32_t *)mbx);
  8626. to_slim = phba->MBslimaddr;
  8627. writel(ldata, to_slim);
  8628. readl(to_slim); /* flush */
  8629. if (mbx->mbxCommand == MBX_CONFIG_PORT)
  8630. /* switch over to host mailbox */
  8631. psli->sli_flag |= LPFC_SLI_ACTIVE;
  8632. }
  8633. wmb();
  8634. switch (flag) {
  8635. case MBX_NOWAIT:
  8636. /* Set up reference to mailbox command */
  8637. psli->mbox_active = pmbox;
  8638. /* Interrupt board to do it */
  8639. writel(CA_MBATT, phba->CAregaddr);
  8640. readl(phba->CAregaddr); /* flush */
  8641. /* Don't wait for it to finish, just return */
  8642. break;
  8643. case MBX_POLL:
  8644. /* Set up null reference to mailbox command */
  8645. psli->mbox_active = NULL;
  8646. /* Interrupt board to do it */
  8647. writel(CA_MBATT, phba->CAregaddr);
  8648. readl(phba->CAregaddr); /* flush */
  8649. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8650. /* First read mbox status word */
  8651. word0 = *((uint32_t *)phba->mbox);
  8652. word0 = le32_to_cpu(word0);
  8653. } else {
  8654. /* First read mbox status word */
  8655. if (lpfc_readl(phba->MBslimaddr, &word0)) {
  8656. spin_unlock_irqrestore(&phba->hbalock,
  8657. drvr_flag);
  8658. goto out_not_finished;
  8659. }
  8660. }
  8661. /* Read the HBA Host Attention Register */
  8662. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  8663. spin_unlock_irqrestore(&phba->hbalock,
  8664. drvr_flag);
  8665. goto out_not_finished;
  8666. }
  8667. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, pmbox) *
  8668. 1000) + jiffies;
  8669. i = 0;
  8670. /* Wait for command to complete */
  8671. while (((word0 & OWN_CHIP) == OWN_CHIP) ||
  8672. (!(ha_copy & HA_MBATT) &&
  8673. (phba->link_state > LPFC_WARM_START))) {
  8674. if (time_after(jiffies, timeout)) {
  8675. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8676. spin_unlock_irqrestore(&phba->hbalock,
  8677. drvr_flag);
  8678. goto out_not_finished;
  8679. }
  8680. /* Check if we took a mbox interrupt while we were
  8681. polling */
  8682. if (((word0 & OWN_CHIP) != OWN_CHIP)
  8683. && (evtctr != psli->slistat.mbox_event))
  8684. break;
  8685. if (i++ > 10) {
  8686. spin_unlock_irqrestore(&phba->hbalock,
  8687. drvr_flag);
  8688. msleep(1);
  8689. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  8690. }
  8691. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8692. /* First copy command data */
  8693. word0 = *((uint32_t *)phba->mbox);
  8694. word0 = le32_to_cpu(word0);
  8695. if (mbx->mbxCommand == MBX_CONFIG_PORT) {
  8696. MAILBOX_t *slimmb;
  8697. uint32_t slimword0;
  8698. /* Check real SLIM for any errors */
  8699. slimword0 = readl(phba->MBslimaddr);
  8700. slimmb = (MAILBOX_t *) & slimword0;
  8701. if (((slimword0 & OWN_CHIP) != OWN_CHIP)
  8702. && slimmb->mbxStatus) {
  8703. psli->sli_flag &=
  8704. ~LPFC_SLI_ACTIVE;
  8705. word0 = slimword0;
  8706. }
  8707. }
  8708. } else {
  8709. /* First copy command data */
  8710. word0 = readl(phba->MBslimaddr);
  8711. }
  8712. /* Read the HBA Host Attention Register */
  8713. if (lpfc_readl(phba->HAregaddr, &ha_copy)) {
  8714. spin_unlock_irqrestore(&phba->hbalock,
  8715. drvr_flag);
  8716. goto out_not_finished;
  8717. }
  8718. }
  8719. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  8720. /* copy results back to user */
  8721. lpfc_sli_pcimem_bcopy(phba->mbox, mbx,
  8722. MAILBOX_CMD_SIZE);
  8723. /* Copy the mailbox extension data */
  8724. if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
  8725. lpfc_sli_pcimem_bcopy(phba->mbox_ext,
  8726. pmbox->ctx_buf,
  8727. pmbox->out_ext_byte_len);
  8728. }
  8729. } else {
  8730. /* First copy command data */
  8731. lpfc_memcpy_from_slim(mbx, phba->MBslimaddr,
  8732. MAILBOX_CMD_SIZE);
  8733. /* Copy the mailbox extension data */
  8734. if (pmbox->out_ext_byte_len && pmbox->ctx_buf) {
  8735. lpfc_memcpy_from_slim(
  8736. pmbox->ctx_buf,
  8737. phba->MBslimaddr +
  8738. MAILBOX_HBA_EXT_OFFSET,
  8739. pmbox->out_ext_byte_len);
  8740. }
  8741. }
  8742. writel(HA_MBATT, phba->HAregaddr);
  8743. readl(phba->HAregaddr); /* flush */
  8744. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  8745. status = mbx->mbxStatus;
  8746. }
  8747. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  8748. return status;
  8749. out_not_finished:
  8750. if (processing_queue) {
  8751. pmbox->u.mb.mbxStatus = MBX_NOT_FINISHED;
  8752. lpfc_mbox_cmpl_put(phba, pmbox);
  8753. }
  8754. return MBX_NOT_FINISHED;
  8755. }
  8756. /**
  8757. * lpfc_sli4_async_mbox_block - Block posting SLI4 asynchronous mailbox command
  8758. * @phba: Pointer to HBA context object.
  8759. *
  8760. * The function blocks the posting of SLI4 asynchronous mailbox commands from
  8761. * the driver internal pending mailbox queue. It will then try to wait out the
  8762. * possible outstanding mailbox command before return.
  8763. *
  8764. * Returns:
  8765. * 0 - the outstanding mailbox command completed; otherwise, the wait for
  8766. * the outstanding mailbox command timed out.
  8767. **/
  8768. static int
  8769. lpfc_sli4_async_mbox_block(struct lpfc_hba *phba)
  8770. {
  8771. struct lpfc_sli *psli = &phba->sli;
  8772. LPFC_MBOXQ_t *mboxq;
  8773. int rc = 0;
  8774. unsigned long timeout = 0;
  8775. u32 sli_flag;
  8776. u8 cmd, subsys, opcode;
  8777. /* Mark the asynchronous mailbox command posting as blocked */
  8778. spin_lock_irq(&phba->hbalock);
  8779. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  8780. /* Determine how long we might wait for the active mailbox
  8781. * command to be gracefully completed by firmware.
  8782. */
  8783. if (phba->sli.mbox_active)
  8784. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  8785. phba->sli.mbox_active) *
  8786. 1000) + jiffies;
  8787. spin_unlock_irq(&phba->hbalock);
  8788. /* Make sure the mailbox is really active */
  8789. if (timeout)
  8790. lpfc_sli4_process_missed_mbox_completions(phba);
  8791. /* Wait for the outstanding mailbox command to complete */
  8792. while (phba->sli.mbox_active) {
  8793. /* Check active mailbox complete status every 2ms */
  8794. msleep(2);
  8795. if (time_after(jiffies, timeout)) {
  8796. /* Timeout, mark the outstanding cmd not complete */
  8797. /* Sanity check sli.mbox_active has not completed or
  8798. * cancelled from another context during last 2ms sleep,
  8799. * so take hbalock to be sure before logging.
  8800. */
  8801. spin_lock_irq(&phba->hbalock);
  8802. if (phba->sli.mbox_active) {
  8803. mboxq = phba->sli.mbox_active;
  8804. cmd = mboxq->u.mb.mbxCommand;
  8805. subsys = lpfc_sli_config_mbox_subsys_get(phba,
  8806. mboxq);
  8807. opcode = lpfc_sli_config_mbox_opcode_get(phba,
  8808. mboxq);
  8809. sli_flag = psli->sli_flag;
  8810. spin_unlock_irq(&phba->hbalock);
  8811. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8812. "2352 Mailbox command x%x "
  8813. "(x%x/x%x) sli_flag x%x could "
  8814. "not complete\n",
  8815. cmd, subsys, opcode,
  8816. sli_flag);
  8817. } else {
  8818. spin_unlock_irq(&phba->hbalock);
  8819. }
  8820. rc = 1;
  8821. break;
  8822. }
  8823. }
  8824. /* Can not cleanly block async mailbox command, fails it */
  8825. if (rc) {
  8826. spin_lock_irq(&phba->hbalock);
  8827. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  8828. spin_unlock_irq(&phba->hbalock);
  8829. }
  8830. return rc;
  8831. }
  8832. /**
  8833. * lpfc_sli4_async_mbox_unblock - Block posting SLI4 async mailbox command
  8834. * @phba: Pointer to HBA context object.
  8835. *
  8836. * The function unblocks and resume posting of SLI4 asynchronous mailbox
  8837. * commands from the driver internal pending mailbox queue. It makes sure
  8838. * that there is no outstanding mailbox command before resuming posting
  8839. * asynchronous mailbox commands. If, for any reason, there is outstanding
  8840. * mailbox command, it will try to wait it out before resuming asynchronous
  8841. * mailbox command posting.
  8842. **/
  8843. static void
  8844. lpfc_sli4_async_mbox_unblock(struct lpfc_hba *phba)
  8845. {
  8846. struct lpfc_sli *psli = &phba->sli;
  8847. spin_lock_irq(&phba->hbalock);
  8848. if (!(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  8849. /* Asynchronous mailbox posting is not blocked, do nothing */
  8850. spin_unlock_irq(&phba->hbalock);
  8851. return;
  8852. }
  8853. /* Outstanding synchronous mailbox command is guaranteed to be done,
  8854. * successful or timeout, after timing-out the outstanding mailbox
  8855. * command shall always be removed, so just unblock posting async
  8856. * mailbox command and resume
  8857. */
  8858. psli->sli_flag &= ~LPFC_SLI_ASYNC_MBX_BLK;
  8859. spin_unlock_irq(&phba->hbalock);
  8860. /* wake up worker thread to post asynchronous mailbox command */
  8861. lpfc_worker_wake_up(phba);
  8862. }
  8863. /**
  8864. * lpfc_sli4_wait_bmbx_ready - Wait for bootstrap mailbox register ready
  8865. * @phba: Pointer to HBA context object.
  8866. * @mboxq: Pointer to mailbox object.
  8867. *
  8868. * The function waits for the bootstrap mailbox register ready bit from
  8869. * port for twice the regular mailbox command timeout value.
  8870. *
  8871. * 0 - no timeout on waiting for bootstrap mailbox register ready.
  8872. * MBXERR_ERROR - wait for bootstrap mailbox register timed out.
  8873. **/
  8874. static int
  8875. lpfc_sli4_wait_bmbx_ready(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8876. {
  8877. uint32_t db_ready;
  8878. unsigned long timeout;
  8879. struct lpfc_register bmbx_reg;
  8880. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, mboxq)
  8881. * 1000) + jiffies;
  8882. do {
  8883. bmbx_reg.word0 = readl(phba->sli4_hba.BMBXregaddr);
  8884. db_ready = bf_get(lpfc_bmbx_rdy, &bmbx_reg);
  8885. if (!db_ready)
  8886. mdelay(2);
  8887. if (time_after(jiffies, timeout))
  8888. return MBXERR_ERROR;
  8889. } while (!db_ready);
  8890. return 0;
  8891. }
  8892. /**
  8893. * lpfc_sli4_post_sync_mbox - Post an SLI4 mailbox to the bootstrap mailbox
  8894. * @phba: Pointer to HBA context object.
  8895. * @mboxq: Pointer to mailbox object.
  8896. *
  8897. * The function posts a mailbox to the port. The mailbox is expected
  8898. * to be comletely filled in and ready for the port to operate on it.
  8899. * This routine executes a synchronous completion operation on the
  8900. * mailbox by polling for its completion.
  8901. *
  8902. * The caller must not be holding any locks when calling this routine.
  8903. *
  8904. * Returns:
  8905. * MBX_SUCCESS - mailbox posted successfully
  8906. * Any of the MBX error values.
  8907. **/
  8908. static int
  8909. lpfc_sli4_post_sync_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  8910. {
  8911. int rc = MBX_SUCCESS;
  8912. unsigned long iflag;
  8913. uint32_t mcqe_status;
  8914. uint32_t mbx_cmnd;
  8915. struct lpfc_sli *psli = &phba->sli;
  8916. struct lpfc_mqe *mb = &mboxq->u.mqe;
  8917. struct lpfc_bmbx_create *mbox_rgn;
  8918. struct dma_address *dma_address;
  8919. /*
  8920. * Only one mailbox can be active to the bootstrap mailbox region
  8921. * at a time and there is no queueing provided.
  8922. */
  8923. spin_lock_irqsave(&phba->hbalock, iflag);
  8924. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  8925. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8926. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  8927. "(%d):2532 Mailbox command x%x (x%x/x%x) "
  8928. "cannot issue Data: x%x x%x\n",
  8929. mboxq->vport ? mboxq->vport->vpi : 0,
  8930. mboxq->u.mb.mbxCommand,
  8931. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  8932. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  8933. psli->sli_flag, MBX_POLL);
  8934. return MBXERR_ERROR;
  8935. }
  8936. /* The server grabs the token and owns it until release */
  8937. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  8938. phba->sli.mbox_active = mboxq;
  8939. spin_unlock_irqrestore(&phba->hbalock, iflag);
  8940. /* wait for bootstrap mbox register for readyness */
  8941. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  8942. if (rc)
  8943. goto exit;
  8944. /*
  8945. * Initialize the bootstrap memory region to avoid stale data areas
  8946. * in the mailbox post. Then copy the caller's mailbox contents to
  8947. * the bmbx mailbox region.
  8948. */
  8949. mbx_cmnd = bf_get(lpfc_mqe_command, mb);
  8950. memset(phba->sli4_hba.bmbx.avirt, 0, sizeof(struct lpfc_bmbx_create));
  8951. lpfc_sli4_pcimem_bcopy(mb, phba->sli4_hba.bmbx.avirt,
  8952. sizeof(struct lpfc_mqe));
  8953. /* Post the high mailbox dma address to the port and wait for ready. */
  8954. dma_address = &phba->sli4_hba.bmbx.dma_address;
  8955. writel(dma_address->addr_hi, phba->sli4_hba.BMBXregaddr);
  8956. /* wait for bootstrap mbox register for hi-address write done */
  8957. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  8958. if (rc)
  8959. goto exit;
  8960. /* Post the low mailbox dma address to the port. */
  8961. writel(dma_address->addr_lo, phba->sli4_hba.BMBXregaddr);
  8962. /* wait for bootstrap mbox register for low address write done */
  8963. rc = lpfc_sli4_wait_bmbx_ready(phba, mboxq);
  8964. if (rc)
  8965. goto exit;
  8966. /*
  8967. * Read the CQ to ensure the mailbox has completed.
  8968. * If so, update the mailbox status so that the upper layers
  8969. * can complete the request normally.
  8970. */
  8971. lpfc_sli4_pcimem_bcopy(phba->sli4_hba.bmbx.avirt, mb,
  8972. sizeof(struct lpfc_mqe));
  8973. mbox_rgn = (struct lpfc_bmbx_create *) phba->sli4_hba.bmbx.avirt;
  8974. lpfc_sli4_pcimem_bcopy(&mbox_rgn->mcqe, &mboxq->mcqe,
  8975. sizeof(struct lpfc_mcqe));
  8976. mcqe_status = bf_get(lpfc_mcqe_status, &mbox_rgn->mcqe);
  8977. /*
  8978. * When the CQE status indicates a failure and the mailbox status
  8979. * indicates success then copy the CQE status into the mailbox status
  8980. * (and prefix it with x4000).
  8981. */
  8982. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  8983. if (bf_get(lpfc_mqe_status, mb) == MBX_SUCCESS)
  8984. bf_set(lpfc_mqe_status, mb,
  8985. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  8986. rc = MBXERR_ERROR;
  8987. } else
  8988. lpfc_sli4_swap_str(phba, mboxq);
  8989. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  8990. "(%d):0356 Mailbox cmd x%x (x%x/x%x) Status x%x "
  8991. "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x x%x"
  8992. " x%x x%x CQ: x%x x%x x%x x%x\n",
  8993. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  8994. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  8995. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  8996. bf_get(lpfc_mqe_status, mb),
  8997. mb->un.mb_words[0], mb->un.mb_words[1],
  8998. mb->un.mb_words[2], mb->un.mb_words[3],
  8999. mb->un.mb_words[4], mb->un.mb_words[5],
  9000. mb->un.mb_words[6], mb->un.mb_words[7],
  9001. mb->un.mb_words[8], mb->un.mb_words[9],
  9002. mb->un.mb_words[10], mb->un.mb_words[11],
  9003. mb->un.mb_words[12], mboxq->mcqe.word0,
  9004. mboxq->mcqe.mcqe_tag0, mboxq->mcqe.mcqe_tag1,
  9005. mboxq->mcqe.trailer);
  9006. exit:
  9007. /* We are holding the token, no needed for lock when release */
  9008. spin_lock_irqsave(&phba->hbalock, iflag);
  9009. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  9010. phba->sli.mbox_active = NULL;
  9011. spin_unlock_irqrestore(&phba->hbalock, iflag);
  9012. return rc;
  9013. }
  9014. /**
  9015. * lpfc_sli_issue_mbox_s4 - Issue an SLI4 mailbox command to firmware
  9016. * @phba: Pointer to HBA context object.
  9017. * @mboxq: Pointer to mailbox object.
  9018. * @flag: Flag indicating how the mailbox need to be processed.
  9019. *
  9020. * This function is called by discovery code and HBA management code to submit
  9021. * a mailbox command to firmware with SLI-4 interface spec.
  9022. *
  9023. * Return codes the caller owns the mailbox command after the return of the
  9024. * function.
  9025. **/
  9026. static int
  9027. lpfc_sli_issue_mbox_s4(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
  9028. uint32_t flag)
  9029. {
  9030. struct lpfc_sli *psli = &phba->sli;
  9031. unsigned long iflags;
  9032. int rc;
  9033. /* dump from issue mailbox command if setup */
  9034. lpfc_idiag_mbxacc_dump_issue_mbox(phba, &mboxq->u.mb);
  9035. rc = lpfc_mbox_dev_check(phba);
  9036. if (unlikely(rc)) {
  9037. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9038. "(%d):2544 Mailbox command x%x (x%x/x%x) "
  9039. "cannot issue Data: x%x x%x\n",
  9040. mboxq->vport ? mboxq->vport->vpi : 0,
  9041. mboxq->u.mb.mbxCommand,
  9042. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9043. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9044. psli->sli_flag, flag);
  9045. goto out_not_finished;
  9046. }
  9047. /* Detect polling mode and jump to a handler */
  9048. if (!phba->sli4_hba.intr_enable) {
  9049. if (flag == MBX_POLL)
  9050. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  9051. else
  9052. rc = -EIO;
  9053. if (rc != MBX_SUCCESS)
  9054. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  9055. "(%d):2541 Mailbox command x%x "
  9056. "(x%x/x%x) failure: "
  9057. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  9058. "Data: x%x x%x\n",
  9059. mboxq->vport ? mboxq->vport->vpi : 0,
  9060. mboxq->u.mb.mbxCommand,
  9061. lpfc_sli_config_mbox_subsys_get(phba,
  9062. mboxq),
  9063. lpfc_sli_config_mbox_opcode_get(phba,
  9064. mboxq),
  9065. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  9066. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  9067. bf_get(lpfc_mcqe_ext_status,
  9068. &mboxq->mcqe),
  9069. psli->sli_flag, flag);
  9070. return rc;
  9071. } else if (flag == MBX_POLL) {
  9072. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  9073. "(%d):2542 Try to issue mailbox command "
  9074. "x%x (x%x/x%x) synchronously ahead of async "
  9075. "mailbox command queue: x%x x%x\n",
  9076. mboxq->vport ? mboxq->vport->vpi : 0,
  9077. mboxq->u.mb.mbxCommand,
  9078. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9079. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9080. psli->sli_flag, flag);
  9081. /* Try to block the asynchronous mailbox posting */
  9082. rc = lpfc_sli4_async_mbox_block(phba);
  9083. if (!rc) {
  9084. /* Successfully blocked, now issue sync mbox cmd */
  9085. rc = lpfc_sli4_post_sync_mbox(phba, mboxq);
  9086. if (rc != MBX_SUCCESS)
  9087. lpfc_printf_log(phba, KERN_WARNING,
  9088. LOG_MBOX | LOG_SLI,
  9089. "(%d):2597 Sync Mailbox command "
  9090. "x%x (x%x/x%x) failure: "
  9091. "mqe_sta: x%x mcqe_sta: x%x/x%x "
  9092. "Data: x%x x%x\n",
  9093. mboxq->vport ? mboxq->vport->vpi : 0,
  9094. mboxq->u.mb.mbxCommand,
  9095. lpfc_sli_config_mbox_subsys_get(phba,
  9096. mboxq),
  9097. lpfc_sli_config_mbox_opcode_get(phba,
  9098. mboxq),
  9099. bf_get(lpfc_mqe_status, &mboxq->u.mqe),
  9100. bf_get(lpfc_mcqe_status, &mboxq->mcqe),
  9101. bf_get(lpfc_mcqe_ext_status,
  9102. &mboxq->mcqe),
  9103. psli->sli_flag, flag);
  9104. /* Unblock the async mailbox posting afterward */
  9105. lpfc_sli4_async_mbox_unblock(phba);
  9106. }
  9107. return rc;
  9108. }
  9109. /* Now, interrupt mode asynchronous mailbox command */
  9110. rc = lpfc_mbox_cmd_check(phba, mboxq);
  9111. if (rc) {
  9112. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9113. "(%d):2543 Mailbox command x%x (x%x/x%x) "
  9114. "cannot issue Data: x%x x%x\n",
  9115. mboxq->vport ? mboxq->vport->vpi : 0,
  9116. mboxq->u.mb.mbxCommand,
  9117. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9118. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9119. psli->sli_flag, flag);
  9120. goto out_not_finished;
  9121. }
  9122. /* Put the mailbox command to the driver internal FIFO */
  9123. psli->slistat.mbox_busy++;
  9124. spin_lock_irqsave(&phba->hbalock, iflags);
  9125. lpfc_mbox_put(phba, mboxq);
  9126. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9127. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  9128. "(%d):0354 Mbox cmd issue - Enqueue Data: "
  9129. "x%x (x%x/x%x) x%x x%x x%x\n",
  9130. mboxq->vport ? mboxq->vport->vpi : 0xffffff,
  9131. bf_get(lpfc_mqe_command, &mboxq->u.mqe),
  9132. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9133. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9134. phba->pport->port_state,
  9135. psli->sli_flag, MBX_NOWAIT);
  9136. /* Wake up worker thread to transport mailbox command from head */
  9137. lpfc_worker_wake_up(phba);
  9138. return MBX_BUSY;
  9139. out_not_finished:
  9140. return MBX_NOT_FINISHED;
  9141. }
  9142. /**
  9143. * lpfc_sli4_post_async_mbox - Post an SLI4 mailbox command to device
  9144. * @phba: Pointer to HBA context object.
  9145. *
  9146. * This function is called by worker thread to send a mailbox command to
  9147. * SLI4 HBA firmware.
  9148. *
  9149. **/
  9150. int
  9151. lpfc_sli4_post_async_mbox(struct lpfc_hba *phba)
  9152. {
  9153. struct lpfc_sli *psli = &phba->sli;
  9154. LPFC_MBOXQ_t *mboxq;
  9155. int rc = MBX_SUCCESS;
  9156. unsigned long iflags;
  9157. struct lpfc_mqe *mqe;
  9158. uint32_t mbx_cmnd;
  9159. /* Check interrupt mode before post async mailbox command */
  9160. if (unlikely(!phba->sli4_hba.intr_enable))
  9161. return MBX_NOT_FINISHED;
  9162. /* Check for mailbox command service token */
  9163. spin_lock_irqsave(&phba->hbalock, iflags);
  9164. if (unlikely(psli->sli_flag & LPFC_SLI_ASYNC_MBX_BLK)) {
  9165. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9166. return MBX_NOT_FINISHED;
  9167. }
  9168. if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
  9169. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9170. return MBX_NOT_FINISHED;
  9171. }
  9172. if (unlikely(phba->sli.mbox_active)) {
  9173. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9174. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9175. "0384 There is pending active mailbox cmd\n");
  9176. return MBX_NOT_FINISHED;
  9177. }
  9178. /* Take the mailbox command service token */
  9179. psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
  9180. /* Get the next mailbox command from head of queue */
  9181. mboxq = lpfc_mbox_get(phba);
  9182. /* If no more mailbox command waiting for post, we're done */
  9183. if (!mboxq) {
  9184. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  9185. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9186. return MBX_SUCCESS;
  9187. }
  9188. phba->sli.mbox_active = mboxq;
  9189. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9190. /* Check device readiness for posting mailbox command */
  9191. rc = lpfc_mbox_dev_check(phba);
  9192. if (unlikely(rc))
  9193. /* Driver clean routine will clean up pending mailbox */
  9194. goto out_not_finished;
  9195. /* Prepare the mbox command to be posted */
  9196. mqe = &mboxq->u.mqe;
  9197. mbx_cmnd = bf_get(lpfc_mqe_command, mqe);
  9198. /* Start timer for the mbox_tmo and log some mailbox post messages */
  9199. mod_timer(&psli->mbox_tmo, (jiffies +
  9200. msecs_to_jiffies(1000 * lpfc_mbox_tmo_val(phba, mboxq))));
  9201. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  9202. "(%d):0355 Mailbox cmd x%x (x%x/x%x) issue Data: "
  9203. "x%x x%x\n",
  9204. mboxq->vport ? mboxq->vport->vpi : 0, mbx_cmnd,
  9205. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9206. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9207. phba->pport->port_state, psli->sli_flag);
  9208. if (mbx_cmnd != MBX_HEARTBEAT) {
  9209. if (mboxq->vport) {
  9210. lpfc_debugfs_disc_trc(mboxq->vport,
  9211. LPFC_DISC_TRC_MBOX_VPORT,
  9212. "MBOX Send vport: cmd:x%x mb:x%x x%x",
  9213. mbx_cmnd, mqe->un.mb_words[0],
  9214. mqe->un.mb_words[1]);
  9215. } else {
  9216. lpfc_debugfs_disc_trc(phba->pport,
  9217. LPFC_DISC_TRC_MBOX,
  9218. "MBOX Send: cmd:x%x mb:x%x x%x",
  9219. mbx_cmnd, mqe->un.mb_words[0],
  9220. mqe->un.mb_words[1]);
  9221. }
  9222. }
  9223. psli->slistat.mbox_cmd++;
  9224. /* Post the mailbox command to the port */
  9225. rc = lpfc_sli4_mq_put(phba->sli4_hba.mbx_wq, mqe);
  9226. if (rc != MBX_SUCCESS) {
  9227. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9228. "(%d):2533 Mailbox command x%x (x%x/x%x) "
  9229. "cannot issue Data: x%x x%x\n",
  9230. mboxq->vport ? mboxq->vport->vpi : 0,
  9231. mboxq->u.mb.mbxCommand,
  9232. lpfc_sli_config_mbox_subsys_get(phba, mboxq),
  9233. lpfc_sli_config_mbox_opcode_get(phba, mboxq),
  9234. psli->sli_flag, MBX_NOWAIT);
  9235. goto out_not_finished;
  9236. }
  9237. return rc;
  9238. out_not_finished:
  9239. spin_lock_irqsave(&phba->hbalock, iflags);
  9240. if (phba->sli.mbox_active) {
  9241. mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
  9242. __lpfc_mbox_cmpl_put(phba, mboxq);
  9243. /* Release the token */
  9244. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  9245. phba->sli.mbox_active = NULL;
  9246. }
  9247. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9248. return MBX_NOT_FINISHED;
  9249. }
  9250. /**
  9251. * lpfc_sli_issue_mbox - Wrapper func for issuing mailbox command
  9252. * @phba: Pointer to HBA context object.
  9253. * @pmbox: Pointer to mailbox object.
  9254. * @flag: Flag indicating how the mailbox need to be processed.
  9255. *
  9256. * This routine wraps the actual SLI3 or SLI4 mailbox issuing routine from
  9257. * the API jump table function pointer from the lpfc_hba struct.
  9258. *
  9259. * Return codes the caller owns the mailbox command after the return of the
  9260. * function.
  9261. **/
  9262. int
  9263. lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
  9264. {
  9265. return phba->lpfc_sli_issue_mbox(phba, pmbox, flag);
  9266. }
  9267. /**
  9268. * lpfc_mbox_api_table_setup - Set up mbox api function jump table
  9269. * @phba: The hba struct for which this call is being executed.
  9270. * @dev_grp: The HBA PCI-Device group number.
  9271. *
  9272. * This routine sets up the mbox interface API function jump table in @phba
  9273. * struct.
  9274. * Returns: 0 - success, -ENODEV - failure.
  9275. **/
  9276. int
  9277. lpfc_mbox_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  9278. {
  9279. switch (dev_grp) {
  9280. case LPFC_PCI_DEV_LP:
  9281. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s3;
  9282. phba->lpfc_sli_handle_slow_ring_event =
  9283. lpfc_sli_handle_slow_ring_event_s3;
  9284. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s3;
  9285. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s3;
  9286. phba->lpfc_sli_brdready = lpfc_sli_brdready_s3;
  9287. break;
  9288. case LPFC_PCI_DEV_OC:
  9289. phba->lpfc_sli_issue_mbox = lpfc_sli_issue_mbox_s4;
  9290. phba->lpfc_sli_handle_slow_ring_event =
  9291. lpfc_sli_handle_slow_ring_event_s4;
  9292. phba->lpfc_sli_hbq_to_firmware = lpfc_sli_hbq_to_firmware_s4;
  9293. phba->lpfc_sli_brdrestart = lpfc_sli_brdrestart_s4;
  9294. phba->lpfc_sli_brdready = lpfc_sli_brdready_s4;
  9295. break;
  9296. default:
  9297. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  9298. "1420 Invalid HBA PCI-device group: 0x%x\n",
  9299. dev_grp);
  9300. return -ENODEV;
  9301. }
  9302. return 0;
  9303. }
  9304. /**
  9305. * __lpfc_sli_ringtx_put - Add an iocb to the txq
  9306. * @phba: Pointer to HBA context object.
  9307. * @pring: Pointer to driver SLI ring object.
  9308. * @piocb: Pointer to address of newly added command iocb.
  9309. *
  9310. * This function is called with hbalock held for SLI3 ports or
  9311. * the ring lock held for SLI4 ports to add a command
  9312. * iocb to the txq when SLI layer cannot submit the command iocb
  9313. * to the ring.
  9314. **/
  9315. void
  9316. __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9317. struct lpfc_iocbq *piocb)
  9318. {
  9319. if (phba->sli_rev == LPFC_SLI_REV4)
  9320. lockdep_assert_held(&pring->ring_lock);
  9321. else
  9322. lockdep_assert_held(&phba->hbalock);
  9323. /* Insert the caller's iocb in the txq tail for later processing. */
  9324. list_add_tail(&piocb->list, &pring->txq);
  9325. }
  9326. /**
  9327. * lpfc_sli_next_iocb - Get the next iocb in the txq
  9328. * @phba: Pointer to HBA context object.
  9329. * @pring: Pointer to driver SLI ring object.
  9330. * @piocb: Pointer to address of newly added command iocb.
  9331. *
  9332. * This function is called with hbalock held before a new
  9333. * iocb is submitted to the firmware. This function checks
  9334. * txq to flush the iocbs in txq to Firmware before
  9335. * submitting new iocbs to the Firmware.
  9336. * If there are iocbs in the txq which need to be submitted
  9337. * to firmware, lpfc_sli_next_iocb returns the first element
  9338. * of the txq after dequeuing it from txq.
  9339. * If there is no iocb in the txq then the function will return
  9340. * *piocb and *piocb is set to NULL. Caller needs to check
  9341. * *piocb to find if there are more commands in the txq.
  9342. **/
  9343. static struct lpfc_iocbq *
  9344. lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  9345. struct lpfc_iocbq **piocb)
  9346. {
  9347. struct lpfc_iocbq * nextiocb;
  9348. lockdep_assert_held(&phba->hbalock);
  9349. nextiocb = lpfc_sli_ringtx_get(phba, pring);
  9350. if (!nextiocb) {
  9351. nextiocb = *piocb;
  9352. *piocb = NULL;
  9353. }
  9354. return nextiocb;
  9355. }
  9356. /**
  9357. * __lpfc_sli_issue_iocb_s3 - SLI3 device lockless ver of lpfc_sli_issue_iocb
  9358. * @phba: Pointer to HBA context object.
  9359. * @ring_number: SLI ring number to issue iocb on.
  9360. * @piocb: Pointer to command iocb.
  9361. * @flag: Flag indicating if this command can be put into txq.
  9362. *
  9363. * __lpfc_sli_issue_iocb_s3 is used by other functions in the driver to issue
  9364. * an iocb command to an HBA with SLI-3 interface spec. If the PCI slot is
  9365. * recovering from error state, if HBA is resetting or if LPFC_STOP_IOCB_EVENT
  9366. * flag is turned on, the function returns IOCB_ERROR. When the link is down,
  9367. * this function allows only iocbs for posting buffers. This function finds
  9368. * next available slot in the command ring and posts the command to the
  9369. * available slot and writes the port attention register to request HBA start
  9370. * processing new iocb. If there is no slot available in the ring and
  9371. * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the txq, otherwise
  9372. * the function returns IOCB_BUSY.
  9373. *
  9374. * This function is called with hbalock held. The function will return success
  9375. * after it successfully submit the iocb to firmware or after adding to the
  9376. * txq.
  9377. **/
  9378. static int
  9379. __lpfc_sli_issue_iocb_s3(struct lpfc_hba *phba, uint32_t ring_number,
  9380. struct lpfc_iocbq *piocb, uint32_t flag)
  9381. {
  9382. struct lpfc_iocbq *nextiocb;
  9383. IOCB_t *iocb;
  9384. struct lpfc_sli_ring *pring = &phba->sli.sli3_ring[ring_number];
  9385. lockdep_assert_held(&phba->hbalock);
  9386. if (piocb->cmd_cmpl && (!piocb->vport) &&
  9387. (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
  9388. (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
  9389. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  9390. "1807 IOCB x%x failed. No vport\n",
  9391. piocb->iocb.ulpCommand);
  9392. dump_stack();
  9393. return IOCB_ERROR;
  9394. }
  9395. /* If the PCI channel is in offline state, do not post iocbs. */
  9396. if (unlikely(pci_channel_offline(phba->pcidev)))
  9397. return IOCB_ERROR;
  9398. /* If HBA has a deferred error attention, fail the iocb. */
  9399. if (unlikely(phba->hba_flag & DEFER_ERATT))
  9400. return IOCB_ERROR;
  9401. /*
  9402. * We should never get an IOCB if we are in a < LINK_DOWN state
  9403. */
  9404. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  9405. return IOCB_ERROR;
  9406. /*
  9407. * Check to see if we are blocking IOCB processing because of a
  9408. * outstanding event.
  9409. */
  9410. if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
  9411. goto iocb_busy;
  9412. if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
  9413. /*
  9414. * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
  9415. * can be issued if the link is not up.
  9416. */
  9417. switch (piocb->iocb.ulpCommand) {
  9418. case CMD_QUE_RING_BUF_CN:
  9419. case CMD_QUE_RING_BUF64_CN:
  9420. /*
  9421. * For IOCBs, like QUE_RING_BUF, that have no rsp ring
  9422. * completion, cmd_cmpl MUST be 0.
  9423. */
  9424. if (piocb->cmd_cmpl)
  9425. piocb->cmd_cmpl = NULL;
  9426. fallthrough;
  9427. case CMD_CREATE_XRI_CR:
  9428. case CMD_CLOSE_XRI_CN:
  9429. case CMD_CLOSE_XRI_CX:
  9430. break;
  9431. default:
  9432. goto iocb_busy;
  9433. }
  9434. /*
  9435. * For FCP commands, we must be in a state where we can process link
  9436. * attention events.
  9437. */
  9438. } else if (unlikely(pring->ringno == LPFC_FCP_RING &&
  9439. !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
  9440. goto iocb_busy;
  9441. }
  9442. while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
  9443. (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
  9444. lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
  9445. if (iocb)
  9446. lpfc_sli_update_ring(phba, pring);
  9447. else
  9448. lpfc_sli_update_full_ring(phba, pring);
  9449. if (!piocb)
  9450. return IOCB_SUCCESS;
  9451. goto out_busy;
  9452. iocb_busy:
  9453. pring->stats.iocb_cmd_delay++;
  9454. out_busy:
  9455. if (!(flag & SLI_IOCB_RET_IOCB)) {
  9456. __lpfc_sli_ringtx_put(phba, pring, piocb);
  9457. return IOCB_SUCCESS;
  9458. }
  9459. return IOCB_BUSY;
  9460. }
  9461. /**
  9462. * __lpfc_sli_issue_fcp_io_s3 - SLI3 device for sending fcp io iocb
  9463. * @phba: Pointer to HBA context object.
  9464. * @ring_number: SLI ring number to issue wqe on.
  9465. * @piocb: Pointer to command iocb.
  9466. * @flag: Flag indicating if this command can be put into txq.
  9467. *
  9468. * __lpfc_sli_issue_fcp_io_s3 is wrapper function to invoke lockless func to
  9469. * send an iocb command to an HBA with SLI-3 interface spec.
  9470. *
  9471. * This function takes the hbalock before invoking the lockless version.
  9472. * The function will return success after it successfully submit the wqe to
  9473. * firmware or after adding to the txq.
  9474. **/
  9475. static int
  9476. __lpfc_sli_issue_fcp_io_s3(struct lpfc_hba *phba, uint32_t ring_number,
  9477. struct lpfc_iocbq *piocb, uint32_t flag)
  9478. {
  9479. unsigned long iflags;
  9480. int rc;
  9481. spin_lock_irqsave(&phba->hbalock, iflags);
  9482. rc = __lpfc_sli_issue_iocb_s3(phba, ring_number, piocb, flag);
  9483. spin_unlock_irqrestore(&phba->hbalock, iflags);
  9484. return rc;
  9485. }
  9486. /**
  9487. * __lpfc_sli_issue_fcp_io_s4 - SLI4 device for sending fcp io wqe
  9488. * @phba: Pointer to HBA context object.
  9489. * @ring_number: SLI ring number to issue wqe on.
  9490. * @piocb: Pointer to command iocb.
  9491. * @flag: Flag indicating if this command can be put into txq.
  9492. *
  9493. * __lpfc_sli_issue_fcp_io_s4 is used by other functions in the driver to issue
  9494. * an wqe command to an HBA with SLI-4 interface spec.
  9495. *
  9496. * This function is a lockless version. The function will return success
  9497. * after it successfully submit the wqe to firmware or after adding to the
  9498. * txq.
  9499. **/
  9500. static int
  9501. __lpfc_sli_issue_fcp_io_s4(struct lpfc_hba *phba, uint32_t ring_number,
  9502. struct lpfc_iocbq *piocb, uint32_t flag)
  9503. {
  9504. struct lpfc_io_buf *lpfc_cmd = piocb->io_buf;
  9505. lpfc_prep_embed_io(phba, lpfc_cmd);
  9506. return lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, piocb);
  9507. }
  9508. void
  9509. lpfc_prep_embed_io(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
  9510. {
  9511. struct lpfc_iocbq *piocb = &lpfc_cmd->cur_iocbq;
  9512. union lpfc_wqe128 *wqe = &lpfc_cmd->cur_iocbq.wqe;
  9513. struct sli4_sge *sgl;
  9514. /* 128 byte wqe support here */
  9515. sgl = (struct sli4_sge *)lpfc_cmd->dma_sgl;
  9516. if (phba->fcp_embed_io) {
  9517. struct fcp_cmnd *fcp_cmnd;
  9518. u32 *ptr;
  9519. fcp_cmnd = lpfc_cmd->fcp_cmnd;
  9520. /* Word 0-2 - FCP_CMND */
  9521. wqe->generic.bde.tus.f.bdeFlags =
  9522. BUFF_TYPE_BDE_IMMED;
  9523. wqe->generic.bde.tus.f.bdeSize = sgl->sge_len;
  9524. wqe->generic.bde.addrHigh = 0;
  9525. wqe->generic.bde.addrLow = 88; /* Word 22 */
  9526. bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
  9527. bf_set(wqe_dbde, &wqe->fcp_iwrite.wqe_com, 0);
  9528. /* Word 22-29 FCP CMND Payload */
  9529. ptr = &wqe->words[22];
  9530. memcpy(ptr, fcp_cmnd, sizeof(struct fcp_cmnd));
  9531. } else {
  9532. /* Word 0-2 - Inline BDE */
  9533. wqe->generic.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  9534. wqe->generic.bde.tus.f.bdeSize = sizeof(struct fcp_cmnd);
  9535. wqe->generic.bde.addrHigh = sgl->addr_hi;
  9536. wqe->generic.bde.addrLow = sgl->addr_lo;
  9537. /* Word 10 */
  9538. bf_set(wqe_dbde, &wqe->generic.wqe_com, 1);
  9539. bf_set(wqe_wqes, &wqe->generic.wqe_com, 0);
  9540. }
  9541. /* add the VMID tags as per switch response */
  9542. if (unlikely(piocb->cmd_flag & LPFC_IO_VMID)) {
  9543. if (phba->pport->vmid_flag & LPFC_VMID_TYPE_PRIO) {
  9544. bf_set(wqe_ccpe, &wqe->fcp_iwrite.wqe_com, 1);
  9545. bf_set(wqe_ccp, &wqe->fcp_iwrite.wqe_com,
  9546. (piocb->vmid_tag.cs_ctl_vmid));
  9547. } else if (phba->cfg_vmid_app_header) {
  9548. bf_set(wqe_appid, &wqe->fcp_iwrite.wqe_com, 1);
  9549. bf_set(wqe_wqes, &wqe->fcp_iwrite.wqe_com, 1);
  9550. wqe->words[31] = piocb->vmid_tag.app_id;
  9551. }
  9552. }
  9553. }
  9554. /**
  9555. * __lpfc_sli_issue_iocb_s4 - SLI4 device lockless ver of lpfc_sli_issue_iocb
  9556. * @phba: Pointer to HBA context object.
  9557. * @ring_number: SLI ring number to issue iocb on.
  9558. * @piocb: Pointer to command iocb.
  9559. * @flag: Flag indicating if this command can be put into txq.
  9560. *
  9561. * __lpfc_sli_issue_iocb_s4 is used by other functions in the driver to issue
  9562. * an iocb command to an HBA with SLI-4 interface spec.
  9563. *
  9564. * This function is called with ringlock held. The function will return success
  9565. * after it successfully submit the iocb to firmware or after adding to the
  9566. * txq.
  9567. **/
  9568. static int
  9569. __lpfc_sli_issue_iocb_s4(struct lpfc_hba *phba, uint32_t ring_number,
  9570. struct lpfc_iocbq *piocb, uint32_t flag)
  9571. {
  9572. struct lpfc_sglq *sglq;
  9573. union lpfc_wqe128 *wqe;
  9574. struct lpfc_queue *wq;
  9575. struct lpfc_sli_ring *pring;
  9576. u32 ulp_command = get_job_cmnd(phba, piocb);
  9577. /* Get the WQ */
  9578. if ((piocb->cmd_flag & LPFC_IO_FCP) ||
  9579. (piocb->cmd_flag & LPFC_USE_FCPWQIDX)) {
  9580. wq = phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq;
  9581. } else {
  9582. wq = phba->sli4_hba.els_wq;
  9583. }
  9584. /* Get corresponding ring */
  9585. pring = wq->pring;
  9586. /*
  9587. * The WQE can be either 64 or 128 bytes,
  9588. */
  9589. lockdep_assert_held(&pring->ring_lock);
  9590. wqe = &piocb->wqe;
  9591. if (piocb->sli4_xritag == NO_XRI) {
  9592. if (ulp_command == CMD_ABORT_XRI_CX)
  9593. sglq = NULL;
  9594. else {
  9595. sglq = __lpfc_sli_get_els_sglq(phba, piocb);
  9596. if (!sglq) {
  9597. if (!(flag & SLI_IOCB_RET_IOCB)) {
  9598. __lpfc_sli_ringtx_put(phba,
  9599. pring,
  9600. piocb);
  9601. return IOCB_SUCCESS;
  9602. } else {
  9603. return IOCB_BUSY;
  9604. }
  9605. }
  9606. }
  9607. } else if (piocb->cmd_flag & LPFC_IO_FCP) {
  9608. /* These IO's already have an XRI and a mapped sgl. */
  9609. sglq = NULL;
  9610. }
  9611. else {
  9612. /*
  9613. * This is a continuation of a commandi,(CX) so this
  9614. * sglq is on the active list
  9615. */
  9616. sglq = __lpfc_get_active_sglq(phba, piocb->sli4_lxritag);
  9617. if (!sglq)
  9618. return IOCB_ERROR;
  9619. }
  9620. if (sglq) {
  9621. piocb->sli4_lxritag = sglq->sli4_lxritag;
  9622. piocb->sli4_xritag = sglq->sli4_xritag;
  9623. /* ABTS sent by initiator to CT exchange, the
  9624. * RX_ID field will be filled with the newly
  9625. * allocated responder XRI.
  9626. */
  9627. if (ulp_command == CMD_XMIT_BLS_RSP64_CX &&
  9628. piocb->abort_bls == LPFC_ABTS_UNSOL_INT)
  9629. bf_set(xmit_bls_rsp64_rxid, &wqe->xmit_bls_rsp,
  9630. piocb->sli4_xritag);
  9631. bf_set(wqe_xri_tag, &wqe->generic.wqe_com,
  9632. piocb->sli4_xritag);
  9633. if (lpfc_wqe_bpl2sgl(phba, piocb, sglq) == NO_XRI)
  9634. return IOCB_ERROR;
  9635. }
  9636. if (lpfc_sli4_wq_put(wq, wqe))
  9637. return IOCB_ERROR;
  9638. lpfc_sli_ringtxcmpl_put(phba, pring, piocb);
  9639. return 0;
  9640. }
  9641. /*
  9642. * lpfc_sli_issue_fcp_io - Wrapper func for issuing fcp i/o
  9643. *
  9644. * This routine wraps the actual fcp i/o function for issusing WQE for sli-4
  9645. * or IOCB for sli-3 function.
  9646. * pointer from the lpfc_hba struct.
  9647. *
  9648. * Return codes:
  9649. * IOCB_ERROR - Error
  9650. * IOCB_SUCCESS - Success
  9651. * IOCB_BUSY - Busy
  9652. **/
  9653. int
  9654. lpfc_sli_issue_fcp_io(struct lpfc_hba *phba, uint32_t ring_number,
  9655. struct lpfc_iocbq *piocb, uint32_t flag)
  9656. {
  9657. return phba->__lpfc_sli_issue_fcp_io(phba, ring_number, piocb, flag);
  9658. }
  9659. /*
  9660. * __lpfc_sli_issue_iocb - Wrapper func of lockless version for issuing iocb
  9661. *
  9662. * This routine wraps the actual lockless version for issusing IOCB function
  9663. * pointer from the lpfc_hba struct.
  9664. *
  9665. * Return codes:
  9666. * IOCB_ERROR - Error
  9667. * IOCB_SUCCESS - Success
  9668. * IOCB_BUSY - Busy
  9669. **/
  9670. int
  9671. __lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  9672. struct lpfc_iocbq *piocb, uint32_t flag)
  9673. {
  9674. return phba->__lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  9675. }
  9676. static void
  9677. __lpfc_sli_prep_els_req_rsp_s3(struct lpfc_iocbq *cmdiocbq,
  9678. struct lpfc_vport *vport,
  9679. struct lpfc_dmabuf *bmp, u16 cmd_size, u32 did,
  9680. u32 elscmd, u8 tmo, u8 expect_rsp)
  9681. {
  9682. struct lpfc_hba *phba = vport->phba;
  9683. IOCB_t *cmd;
  9684. cmd = &cmdiocbq->iocb;
  9685. memset(cmd, 0, sizeof(*cmd));
  9686. cmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  9687. cmd->un.elsreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  9688. cmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  9689. if (expect_rsp) {
  9690. cmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
  9691. cmd->un.elsreq64.remoteID = did; /* DID */
  9692. cmd->ulpCommand = CMD_ELS_REQUEST64_CR;
  9693. cmd->ulpTimeout = tmo;
  9694. } else {
  9695. cmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
  9696. cmd->un.genreq64.xmit_els_remoteID = did; /* DID */
  9697. cmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
  9698. cmd->ulpPU = PARM_NPIV_DID;
  9699. }
  9700. cmd->ulpBdeCount = 1;
  9701. cmd->ulpLe = 1;
  9702. cmd->ulpClass = CLASS3;
  9703. /* If we have NPIV enabled, we want to send ELS traffic by VPI. */
  9704. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  9705. if (expect_rsp) {
  9706. cmd->un.elsreq64.myID = vport->fc_myDID;
  9707. /* For ELS_REQUEST64_CR, use the VPI by default */
  9708. cmd->ulpContext = phba->vpi_ids[vport->vpi];
  9709. }
  9710. cmd->ulpCt_h = 0;
  9711. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  9712. if (elscmd == ELS_CMD_ECHO)
  9713. cmd->ulpCt_l = 0; /* context = invalid RPI */
  9714. else
  9715. cmd->ulpCt_l = 1; /* context = VPI */
  9716. }
  9717. }
  9718. static void
  9719. __lpfc_sli_prep_els_req_rsp_s4(struct lpfc_iocbq *cmdiocbq,
  9720. struct lpfc_vport *vport,
  9721. struct lpfc_dmabuf *bmp, u16 cmd_size, u32 did,
  9722. u32 elscmd, u8 tmo, u8 expect_rsp)
  9723. {
  9724. struct lpfc_hba *phba = vport->phba;
  9725. union lpfc_wqe128 *wqe;
  9726. struct ulp_bde64_le *bde;
  9727. u8 els_id;
  9728. wqe = &cmdiocbq->wqe;
  9729. memset(wqe, 0, sizeof(*wqe));
  9730. /* Word 0 - 2 BDE */
  9731. bde = (struct ulp_bde64_le *)&wqe->generic.bde;
  9732. bde->addr_low = cpu_to_le32(putPaddrLow(bmp->phys));
  9733. bde->addr_high = cpu_to_le32(putPaddrHigh(bmp->phys));
  9734. bde->type_size = cpu_to_le32(cmd_size);
  9735. bde->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
  9736. if (expect_rsp) {
  9737. bf_set(wqe_cmnd, &wqe->els_req.wqe_com, CMD_ELS_REQUEST64_WQE);
  9738. /* Transfer length */
  9739. wqe->els_req.payload_len = cmd_size;
  9740. wqe->els_req.max_response_payload_len = FCELSSIZE;
  9741. /* DID */
  9742. bf_set(wqe_els_did, &wqe->els_req.wqe_dest, did);
  9743. /* Word 11 - ELS_ID */
  9744. switch (elscmd) {
  9745. case ELS_CMD_PLOGI:
  9746. els_id = LPFC_ELS_ID_PLOGI;
  9747. break;
  9748. case ELS_CMD_FLOGI:
  9749. els_id = LPFC_ELS_ID_FLOGI;
  9750. break;
  9751. case ELS_CMD_LOGO:
  9752. els_id = LPFC_ELS_ID_LOGO;
  9753. break;
  9754. case ELS_CMD_FDISC:
  9755. if (!vport->fc_myDID) {
  9756. els_id = LPFC_ELS_ID_FDISC;
  9757. break;
  9758. }
  9759. fallthrough;
  9760. default:
  9761. els_id = LPFC_ELS_ID_DEFAULT;
  9762. break;
  9763. }
  9764. bf_set(wqe_els_id, &wqe->els_req.wqe_com, els_id);
  9765. } else {
  9766. /* DID */
  9767. bf_set(wqe_els_did, &wqe->xmit_els_rsp.wqe_dest, did);
  9768. /* Transfer length */
  9769. wqe->xmit_els_rsp.response_payload_len = cmd_size;
  9770. bf_set(wqe_cmnd, &wqe->xmit_els_rsp.wqe_com,
  9771. CMD_XMIT_ELS_RSP64_WQE);
  9772. }
  9773. bf_set(wqe_tmo, &wqe->generic.wqe_com, tmo);
  9774. bf_set(wqe_reqtag, &wqe->generic.wqe_com, cmdiocbq->iotag);
  9775. bf_set(wqe_class, &wqe->generic.wqe_com, CLASS3);
  9776. /* If we have NPIV enabled, we want to send ELS traffic by VPI.
  9777. * For SLI4, since the driver controls VPIs we also want to include
  9778. * all ELS pt2pt protocol traffic as well.
  9779. */
  9780. if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
  9781. (vport->fc_flag & FC_PT2PT)) {
  9782. if (expect_rsp) {
  9783. bf_set(els_req64_sid, &wqe->els_req, vport->fc_myDID);
  9784. /* For ELS_REQUEST64_WQE, use the VPI by default */
  9785. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  9786. phba->vpi_ids[vport->vpi]);
  9787. }
  9788. /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
  9789. if (elscmd == ELS_CMD_ECHO)
  9790. bf_set(wqe_ct, &wqe->generic.wqe_com, 0);
  9791. else
  9792. bf_set(wqe_ct, &wqe->generic.wqe_com, 1);
  9793. }
  9794. }
  9795. void
  9796. lpfc_sli_prep_els_req_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
  9797. struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  9798. u16 cmd_size, u32 did, u32 elscmd, u8 tmo,
  9799. u8 expect_rsp)
  9800. {
  9801. phba->__lpfc_sli_prep_els_req_rsp(cmdiocbq, vport, bmp, cmd_size, did,
  9802. elscmd, tmo, expect_rsp);
  9803. }
  9804. static void
  9805. __lpfc_sli_prep_gen_req_s3(struct lpfc_iocbq *cmdiocbq, struct lpfc_dmabuf *bmp,
  9806. u16 rpi, u32 num_entry, u8 tmo)
  9807. {
  9808. IOCB_t *cmd;
  9809. cmd = &cmdiocbq->iocb;
  9810. memset(cmd, 0, sizeof(*cmd));
  9811. cmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  9812. cmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  9813. cmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  9814. cmd->un.genreq64.bdl.bdeSize = num_entry * sizeof(struct ulp_bde64);
  9815. cmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
  9816. cmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
  9817. cmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  9818. cmd->ulpContext = rpi;
  9819. cmd->ulpClass = CLASS3;
  9820. cmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  9821. cmd->ulpBdeCount = 1;
  9822. cmd->ulpLe = 1;
  9823. cmd->ulpOwner = OWN_CHIP;
  9824. cmd->ulpTimeout = tmo;
  9825. }
  9826. static void
  9827. __lpfc_sli_prep_gen_req_s4(struct lpfc_iocbq *cmdiocbq, struct lpfc_dmabuf *bmp,
  9828. u16 rpi, u32 num_entry, u8 tmo)
  9829. {
  9830. union lpfc_wqe128 *cmdwqe;
  9831. struct ulp_bde64_le *bde, *bpl;
  9832. u32 xmit_len = 0, total_len = 0, size, type, i;
  9833. cmdwqe = &cmdiocbq->wqe;
  9834. memset(cmdwqe, 0, sizeof(*cmdwqe));
  9835. /* Calculate total_len and xmit_len */
  9836. bpl = (struct ulp_bde64_le *)bmp->virt;
  9837. for (i = 0; i < num_entry; i++) {
  9838. size = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_SIZE_MASK;
  9839. total_len += size;
  9840. }
  9841. for (i = 0; i < num_entry; i++) {
  9842. size = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_SIZE_MASK;
  9843. type = le32_to_cpu(bpl[i].type_size) & ULP_BDE64_TYPE_MASK;
  9844. if (type != ULP_BDE64_TYPE_BDE_64)
  9845. break;
  9846. xmit_len += size;
  9847. }
  9848. /* Words 0 - 2 */
  9849. bde = (struct ulp_bde64_le *)&cmdwqe->generic.bde;
  9850. bde->addr_low = bpl->addr_low;
  9851. bde->addr_high = bpl->addr_high;
  9852. bde->type_size = cpu_to_le32(xmit_len);
  9853. bde->type_size |= cpu_to_le32(ULP_BDE64_TYPE_BDE_64);
  9854. /* Word 3 */
  9855. cmdwqe->gen_req.request_payload_len = xmit_len;
  9856. /* Word 5 */
  9857. bf_set(wqe_type, &cmdwqe->gen_req.wge_ctl, FC_TYPE_CT);
  9858. bf_set(wqe_rctl, &cmdwqe->gen_req.wge_ctl, FC_RCTL_DD_UNSOL_CTL);
  9859. bf_set(wqe_si, &cmdwqe->gen_req.wge_ctl, 1);
  9860. bf_set(wqe_la, &cmdwqe->gen_req.wge_ctl, 1);
  9861. /* Word 6 */
  9862. bf_set(wqe_ctxt_tag, &cmdwqe->gen_req.wqe_com, rpi);
  9863. /* Word 7 */
  9864. bf_set(wqe_tmo, &cmdwqe->gen_req.wqe_com, tmo);
  9865. bf_set(wqe_class, &cmdwqe->gen_req.wqe_com, CLASS3);
  9866. bf_set(wqe_cmnd, &cmdwqe->gen_req.wqe_com, CMD_GEN_REQUEST64_CR);
  9867. bf_set(wqe_ct, &cmdwqe->gen_req.wqe_com, SLI4_CT_RPI);
  9868. /* Word 12 */
  9869. cmdwqe->gen_req.max_response_payload_len = total_len - xmit_len;
  9870. }
  9871. void
  9872. lpfc_sli_prep_gen_req(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
  9873. struct lpfc_dmabuf *bmp, u16 rpi, u32 num_entry, u8 tmo)
  9874. {
  9875. phba->__lpfc_sli_prep_gen_req(cmdiocbq, bmp, rpi, num_entry, tmo);
  9876. }
  9877. static void
  9878. __lpfc_sli_prep_xmit_seq64_s3(struct lpfc_iocbq *cmdiocbq,
  9879. struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
  9880. u32 num_entry, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
  9881. {
  9882. IOCB_t *icmd;
  9883. icmd = &cmdiocbq->iocb;
  9884. memset(icmd, 0, sizeof(*icmd));
  9885. icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  9886. icmd->un.xseq64.bdl.addrLow = putPaddrLow(bmp->phys);
  9887. icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  9888. icmd->un.xseq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
  9889. icmd->un.xseq64.w5.hcsw.Fctl = LA;
  9890. if (last_seq)
  9891. icmd->un.xseq64.w5.hcsw.Fctl |= LS;
  9892. icmd->un.xseq64.w5.hcsw.Dfctl = 0;
  9893. icmd->un.xseq64.w5.hcsw.Rctl = rctl;
  9894. icmd->un.xseq64.w5.hcsw.Type = FC_TYPE_CT;
  9895. icmd->ulpBdeCount = 1;
  9896. icmd->ulpLe = 1;
  9897. icmd->ulpClass = CLASS3;
  9898. switch (cr_cx_cmd) {
  9899. case CMD_XMIT_SEQUENCE64_CR:
  9900. icmd->ulpContext = rpi;
  9901. icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CR;
  9902. break;
  9903. case CMD_XMIT_SEQUENCE64_CX:
  9904. icmd->ulpContext = ox_id;
  9905. icmd->ulpCommand = CMD_XMIT_SEQUENCE64_CX;
  9906. break;
  9907. default:
  9908. break;
  9909. }
  9910. }
  9911. static void
  9912. __lpfc_sli_prep_xmit_seq64_s4(struct lpfc_iocbq *cmdiocbq,
  9913. struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
  9914. u32 full_size, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
  9915. {
  9916. union lpfc_wqe128 *wqe;
  9917. struct ulp_bde64 *bpl;
  9918. wqe = &cmdiocbq->wqe;
  9919. memset(wqe, 0, sizeof(*wqe));
  9920. /* Words 0 - 2 */
  9921. bpl = (struct ulp_bde64 *)bmp->virt;
  9922. wqe->xmit_sequence.bde.addrHigh = bpl->addrHigh;
  9923. wqe->xmit_sequence.bde.addrLow = bpl->addrLow;
  9924. wqe->xmit_sequence.bde.tus.w = bpl->tus.w;
  9925. /* Word 5 */
  9926. bf_set(wqe_ls, &wqe->xmit_sequence.wge_ctl, last_seq);
  9927. bf_set(wqe_la, &wqe->xmit_sequence.wge_ctl, 1);
  9928. bf_set(wqe_dfctl, &wqe->xmit_sequence.wge_ctl, 0);
  9929. bf_set(wqe_rctl, &wqe->xmit_sequence.wge_ctl, rctl);
  9930. bf_set(wqe_type, &wqe->xmit_sequence.wge_ctl, FC_TYPE_CT);
  9931. /* Word 6 */
  9932. bf_set(wqe_ctxt_tag, &wqe->xmit_sequence.wqe_com, rpi);
  9933. bf_set(wqe_cmnd, &wqe->xmit_sequence.wqe_com,
  9934. CMD_XMIT_SEQUENCE64_WQE);
  9935. /* Word 7 */
  9936. bf_set(wqe_class, &wqe->xmit_sequence.wqe_com, CLASS3);
  9937. /* Word 9 */
  9938. bf_set(wqe_rcvoxid, &wqe->xmit_sequence.wqe_com, ox_id);
  9939. /* Word 12 */
  9940. if (cmdiocbq->cmd_flag & (LPFC_IO_LIBDFC | LPFC_IO_LOOPBACK))
  9941. wqe->xmit_sequence.xmit_len = full_size;
  9942. else
  9943. wqe->xmit_sequence.xmit_len =
  9944. wqe->xmit_sequence.bde.tus.f.bdeSize;
  9945. }
  9946. void
  9947. lpfc_sli_prep_xmit_seq64(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
  9948. struct lpfc_dmabuf *bmp, u16 rpi, u16 ox_id,
  9949. u32 num_entry, u8 rctl, u8 last_seq, u8 cr_cx_cmd)
  9950. {
  9951. phba->__lpfc_sli_prep_xmit_seq64(cmdiocbq, bmp, rpi, ox_id, num_entry,
  9952. rctl, last_seq, cr_cx_cmd);
  9953. }
  9954. static void
  9955. __lpfc_sli_prep_abort_xri_s3(struct lpfc_iocbq *cmdiocbq, u16 ulp_context,
  9956. u16 iotag, u8 ulp_class, u16 cqid, bool ia,
  9957. bool wqec)
  9958. {
  9959. IOCB_t *icmd = NULL;
  9960. icmd = &cmdiocbq->iocb;
  9961. memset(icmd, 0, sizeof(*icmd));
  9962. /* Word 5 */
  9963. icmd->un.acxri.abortContextTag = ulp_context;
  9964. icmd->un.acxri.abortIoTag = iotag;
  9965. if (ia) {
  9966. /* Word 7 */
  9967. icmd->ulpCommand = CMD_CLOSE_XRI_CN;
  9968. } else {
  9969. /* Word 3 */
  9970. icmd->un.acxri.abortType = ABORT_TYPE_ABTS;
  9971. /* Word 7 */
  9972. icmd->ulpClass = ulp_class;
  9973. icmd->ulpCommand = CMD_ABORT_XRI_CN;
  9974. }
  9975. /* Word 7 */
  9976. icmd->ulpLe = 1;
  9977. }
  9978. static void
  9979. __lpfc_sli_prep_abort_xri_s4(struct lpfc_iocbq *cmdiocbq, u16 ulp_context,
  9980. u16 iotag, u8 ulp_class, u16 cqid, bool ia,
  9981. bool wqec)
  9982. {
  9983. union lpfc_wqe128 *wqe;
  9984. wqe = &cmdiocbq->wqe;
  9985. memset(wqe, 0, sizeof(*wqe));
  9986. /* Word 3 */
  9987. bf_set(abort_cmd_criteria, &wqe->abort_cmd, T_XRI_TAG);
  9988. if (ia)
  9989. bf_set(abort_cmd_ia, &wqe->abort_cmd, 1);
  9990. else
  9991. bf_set(abort_cmd_ia, &wqe->abort_cmd, 0);
  9992. /* Word 7 */
  9993. bf_set(wqe_cmnd, &wqe->abort_cmd.wqe_com, CMD_ABORT_XRI_WQE);
  9994. /* Word 8 */
  9995. wqe->abort_cmd.wqe_com.abort_tag = ulp_context;
  9996. /* Word 9 */
  9997. bf_set(wqe_reqtag, &wqe->abort_cmd.wqe_com, iotag);
  9998. /* Word 10 */
  9999. bf_set(wqe_qosd, &wqe->abort_cmd.wqe_com, 1);
  10000. /* Word 11 */
  10001. if (wqec)
  10002. bf_set(wqe_wqec, &wqe->abort_cmd.wqe_com, 1);
  10003. bf_set(wqe_cqid, &wqe->abort_cmd.wqe_com, cqid);
  10004. bf_set(wqe_cmd_type, &wqe->abort_cmd.wqe_com, OTHER_COMMAND);
  10005. }
  10006. void
  10007. lpfc_sli_prep_abort_xri(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocbq,
  10008. u16 ulp_context, u16 iotag, u8 ulp_class, u16 cqid,
  10009. bool ia, bool wqec)
  10010. {
  10011. phba->__lpfc_sli_prep_abort_xri(cmdiocbq, ulp_context, iotag, ulp_class,
  10012. cqid, ia, wqec);
  10013. }
  10014. /**
  10015. * lpfc_sli_api_table_setup - Set up sli api function jump table
  10016. * @phba: The hba struct for which this call is being executed.
  10017. * @dev_grp: The HBA PCI-Device group number.
  10018. *
  10019. * This routine sets up the SLI interface API function jump table in @phba
  10020. * struct.
  10021. * Returns: 0 - success, -ENODEV - failure.
  10022. **/
  10023. int
  10024. lpfc_sli_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
  10025. {
  10026. switch (dev_grp) {
  10027. case LPFC_PCI_DEV_LP:
  10028. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s3;
  10029. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s3;
  10030. phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s3;
  10031. phba->__lpfc_sli_prep_els_req_rsp = __lpfc_sli_prep_els_req_rsp_s3;
  10032. phba->__lpfc_sli_prep_gen_req = __lpfc_sli_prep_gen_req_s3;
  10033. phba->__lpfc_sli_prep_xmit_seq64 = __lpfc_sli_prep_xmit_seq64_s3;
  10034. phba->__lpfc_sli_prep_abort_xri = __lpfc_sli_prep_abort_xri_s3;
  10035. break;
  10036. case LPFC_PCI_DEV_OC:
  10037. phba->__lpfc_sli_issue_iocb = __lpfc_sli_issue_iocb_s4;
  10038. phba->__lpfc_sli_release_iocbq = __lpfc_sli_release_iocbq_s4;
  10039. phba->__lpfc_sli_issue_fcp_io = __lpfc_sli_issue_fcp_io_s4;
  10040. phba->__lpfc_sli_prep_els_req_rsp = __lpfc_sli_prep_els_req_rsp_s4;
  10041. phba->__lpfc_sli_prep_gen_req = __lpfc_sli_prep_gen_req_s4;
  10042. phba->__lpfc_sli_prep_xmit_seq64 = __lpfc_sli_prep_xmit_seq64_s4;
  10043. phba->__lpfc_sli_prep_abort_xri = __lpfc_sli_prep_abort_xri_s4;
  10044. break;
  10045. default:
  10046. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  10047. "1419 Invalid HBA PCI-device group: 0x%x\n",
  10048. dev_grp);
  10049. return -ENODEV;
  10050. }
  10051. return 0;
  10052. }
  10053. /**
  10054. * lpfc_sli4_calc_ring - Calculates which ring to use
  10055. * @phba: Pointer to HBA context object.
  10056. * @piocb: Pointer to command iocb.
  10057. *
  10058. * For SLI4 only, FCP IO can deferred to one fo many WQs, based on
  10059. * hba_wqidx, thus we need to calculate the corresponding ring.
  10060. * Since ABORTS must go on the same WQ of the command they are
  10061. * aborting, we use command's hba_wqidx.
  10062. */
  10063. struct lpfc_sli_ring *
  10064. lpfc_sli4_calc_ring(struct lpfc_hba *phba, struct lpfc_iocbq *piocb)
  10065. {
  10066. struct lpfc_io_buf *lpfc_cmd;
  10067. if (piocb->cmd_flag & (LPFC_IO_FCP | LPFC_USE_FCPWQIDX)) {
  10068. if (unlikely(!phba->sli4_hba.hdwq))
  10069. return NULL;
  10070. /*
  10071. * for abort iocb hba_wqidx should already
  10072. * be setup based on what work queue we used.
  10073. */
  10074. if (!(piocb->cmd_flag & LPFC_USE_FCPWQIDX)) {
  10075. lpfc_cmd = piocb->io_buf;
  10076. piocb->hba_wqidx = lpfc_cmd->hdwq_no;
  10077. }
  10078. return phba->sli4_hba.hdwq[piocb->hba_wqidx].io_wq->pring;
  10079. } else {
  10080. if (unlikely(!phba->sli4_hba.els_wq))
  10081. return NULL;
  10082. piocb->hba_wqidx = 0;
  10083. return phba->sli4_hba.els_wq->pring;
  10084. }
  10085. }
  10086. /**
  10087. * lpfc_sli_issue_iocb - Wrapper function for __lpfc_sli_issue_iocb
  10088. * @phba: Pointer to HBA context object.
  10089. * @ring_number: Ring number
  10090. * @piocb: Pointer to command iocb.
  10091. * @flag: Flag indicating if this command can be put into txq.
  10092. *
  10093. * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
  10094. * function. This function gets the hbalock and calls
  10095. * __lpfc_sli_issue_iocb function and will return the error returned
  10096. * by __lpfc_sli_issue_iocb function. This wrapper is used by
  10097. * functions which do not hold hbalock.
  10098. **/
  10099. int
  10100. lpfc_sli_issue_iocb(struct lpfc_hba *phba, uint32_t ring_number,
  10101. struct lpfc_iocbq *piocb, uint32_t flag)
  10102. {
  10103. struct lpfc_sli_ring *pring;
  10104. struct lpfc_queue *eq;
  10105. unsigned long iflags;
  10106. int rc;
  10107. /* If the PCI channel is in offline state, do not post iocbs. */
  10108. if (unlikely(pci_channel_offline(phba->pcidev)))
  10109. return IOCB_ERROR;
  10110. if (phba->sli_rev == LPFC_SLI_REV4) {
  10111. lpfc_sli_prep_wqe(phba, piocb);
  10112. eq = phba->sli4_hba.hdwq[piocb->hba_wqidx].hba_eq;
  10113. pring = lpfc_sli4_calc_ring(phba, piocb);
  10114. if (unlikely(pring == NULL))
  10115. return IOCB_ERROR;
  10116. spin_lock_irqsave(&pring->ring_lock, iflags);
  10117. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  10118. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  10119. lpfc_sli4_poll_eq(eq, LPFC_POLL_FASTPATH);
  10120. } else {
  10121. /* For now, SLI2/3 will still use hbalock */
  10122. spin_lock_irqsave(&phba->hbalock, iflags);
  10123. rc = __lpfc_sli_issue_iocb(phba, ring_number, piocb, flag);
  10124. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10125. }
  10126. return rc;
  10127. }
  10128. /**
  10129. * lpfc_extra_ring_setup - Extra ring setup function
  10130. * @phba: Pointer to HBA context object.
  10131. *
  10132. * This function is called while driver attaches with the
  10133. * HBA to setup the extra ring. The extra ring is used
  10134. * only when driver needs to support target mode functionality
  10135. * or IP over FC functionalities.
  10136. *
  10137. * This function is called with no lock held. SLI3 only.
  10138. **/
  10139. static int
  10140. lpfc_extra_ring_setup( struct lpfc_hba *phba)
  10141. {
  10142. struct lpfc_sli *psli;
  10143. struct lpfc_sli_ring *pring;
  10144. psli = &phba->sli;
  10145. /* Adjust cmd/rsp ring iocb entries more evenly */
  10146. /* Take some away from the FCP ring */
  10147. pring = &psli->sli3_ring[LPFC_FCP_RING];
  10148. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  10149. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  10150. pring->sli.sli3.numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  10151. pring->sli.sli3.numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  10152. /* and give them to the extra ring */
  10153. pring = &psli->sli3_ring[LPFC_EXTRA_RING];
  10154. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  10155. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  10156. pring->sli.sli3.numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  10157. pring->sli.sli3.numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  10158. /* Setup default profile for this ring */
  10159. pring->iotag_max = 4096;
  10160. pring->num_mask = 1;
  10161. pring->prt[0].profile = 0; /* Mask 0 */
  10162. pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
  10163. pring->prt[0].type = phba->cfg_multi_ring_type;
  10164. pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
  10165. return 0;
  10166. }
  10167. static void
  10168. lpfc_sli_post_recovery_event(struct lpfc_hba *phba,
  10169. struct lpfc_nodelist *ndlp)
  10170. {
  10171. unsigned long iflags;
  10172. struct lpfc_work_evt *evtp = &ndlp->recovery_evt;
  10173. spin_lock_irqsave(&phba->hbalock, iflags);
  10174. if (!list_empty(&evtp->evt_listp)) {
  10175. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10176. return;
  10177. }
  10178. /* Incrementing the reference count until the queued work is done. */
  10179. evtp->evt_arg1 = lpfc_nlp_get(ndlp);
  10180. if (!evtp->evt_arg1) {
  10181. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10182. return;
  10183. }
  10184. evtp->evt = LPFC_EVT_RECOVER_PORT;
  10185. list_add_tail(&evtp->evt_listp, &phba->work_list);
  10186. spin_unlock_irqrestore(&phba->hbalock, iflags);
  10187. lpfc_worker_wake_up(phba);
  10188. }
  10189. /* lpfc_sli_abts_err_handler - handle a failed ABTS request from an SLI3 port.
  10190. * @phba: Pointer to HBA context object.
  10191. * @iocbq: Pointer to iocb object.
  10192. *
  10193. * The async_event handler calls this routine when it receives
  10194. * an ASYNC_STATUS_CN event from the port. The port generates
  10195. * this event when an Abort Sequence request to an rport fails
  10196. * twice in succession. The abort could be originated by the
  10197. * driver or by the port. The ABTS could have been for an ELS
  10198. * or FCP IO. The port only generates this event when an ABTS
  10199. * fails to complete after one retry.
  10200. */
  10201. static void
  10202. lpfc_sli_abts_err_handler(struct lpfc_hba *phba,
  10203. struct lpfc_iocbq *iocbq)
  10204. {
  10205. struct lpfc_nodelist *ndlp = NULL;
  10206. uint16_t rpi = 0, vpi = 0;
  10207. struct lpfc_vport *vport = NULL;
  10208. /* The rpi in the ulpContext is vport-sensitive. */
  10209. vpi = iocbq->iocb.un.asyncstat.sub_ctxt_tag;
  10210. rpi = iocbq->iocb.ulpContext;
  10211. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10212. "3092 Port generated ABTS async event "
  10213. "on vpi %d rpi %d status 0x%x\n",
  10214. vpi, rpi, iocbq->iocb.ulpStatus);
  10215. vport = lpfc_find_vport_by_vpid(phba, vpi);
  10216. if (!vport)
  10217. goto err_exit;
  10218. ndlp = lpfc_findnode_rpi(vport, rpi);
  10219. if (!ndlp)
  10220. goto err_exit;
  10221. if (iocbq->iocb.ulpStatus == IOSTAT_LOCAL_REJECT)
  10222. lpfc_sli_abts_recover_port(vport, ndlp);
  10223. return;
  10224. err_exit:
  10225. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10226. "3095 Event Context not found, no "
  10227. "action on vpi %d rpi %d status 0x%x, reason 0x%x\n",
  10228. vpi, rpi, iocbq->iocb.ulpStatus,
  10229. iocbq->iocb.ulpContext);
  10230. }
  10231. /* lpfc_sli4_abts_err_handler - handle a failed ABTS request from an SLI4 port.
  10232. * @phba: pointer to HBA context object.
  10233. * @ndlp: nodelist pointer for the impacted rport.
  10234. * @axri: pointer to the wcqe containing the failed exchange.
  10235. *
  10236. * The driver calls this routine when it receives an ABORT_XRI_FCP CQE from the
  10237. * port. The port generates this event when an abort exchange request to an
  10238. * rport fails twice in succession with no reply. The abort could be originated
  10239. * by the driver or by the port. The ABTS could have been for an ELS or FCP IO.
  10240. */
  10241. void
  10242. lpfc_sli4_abts_err_handler(struct lpfc_hba *phba,
  10243. struct lpfc_nodelist *ndlp,
  10244. struct sli4_wcqe_xri_aborted *axri)
  10245. {
  10246. uint32_t ext_status = 0;
  10247. if (!ndlp) {
  10248. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  10249. "3115 Node Context not found, driver "
  10250. "ignoring abts err event\n");
  10251. return;
  10252. }
  10253. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  10254. "3116 Port generated FCP XRI ABORT event on "
  10255. "vpi %d rpi %d xri x%x status 0x%x parameter x%x\n",
  10256. ndlp->vport->vpi, phba->sli4_hba.rpi_ids[ndlp->nlp_rpi],
  10257. bf_get(lpfc_wcqe_xa_xri, axri),
  10258. bf_get(lpfc_wcqe_xa_status, axri),
  10259. axri->parameter);
  10260. /*
  10261. * Catch the ABTS protocol failure case. Older OCe FW releases returned
  10262. * LOCAL_REJECT and 0 for a failed ABTS exchange and later OCe and
  10263. * LPe FW releases returned LOCAL_REJECT and SEQUENCE_TIMEOUT.
  10264. */
  10265. ext_status = axri->parameter & IOERR_PARAM_MASK;
  10266. if ((bf_get(lpfc_wcqe_xa_status, axri) == IOSTAT_LOCAL_REJECT) &&
  10267. ((ext_status == IOERR_SEQUENCE_TIMEOUT) || (ext_status == 0)))
  10268. lpfc_sli_post_recovery_event(phba, ndlp);
  10269. }
  10270. /**
  10271. * lpfc_sli_async_event_handler - ASYNC iocb handler function
  10272. * @phba: Pointer to HBA context object.
  10273. * @pring: Pointer to driver SLI ring object.
  10274. * @iocbq: Pointer to iocb object.
  10275. *
  10276. * This function is called by the slow ring event handler
  10277. * function when there is an ASYNC event iocb in the ring.
  10278. * This function is called with no lock held.
  10279. * Currently this function handles only temperature related
  10280. * ASYNC events. The function decodes the temperature sensor
  10281. * event message and posts events for the management applications.
  10282. **/
  10283. static void
  10284. lpfc_sli_async_event_handler(struct lpfc_hba * phba,
  10285. struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
  10286. {
  10287. IOCB_t *icmd;
  10288. uint16_t evt_code;
  10289. struct temp_event temp_event_data;
  10290. struct Scsi_Host *shost;
  10291. uint32_t *iocb_w;
  10292. icmd = &iocbq->iocb;
  10293. evt_code = icmd->un.asyncstat.evt_code;
  10294. switch (evt_code) {
  10295. case ASYNC_TEMP_WARN:
  10296. case ASYNC_TEMP_SAFE:
  10297. temp_event_data.data = (uint32_t) icmd->ulpContext;
  10298. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  10299. if (evt_code == ASYNC_TEMP_WARN) {
  10300. temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
  10301. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10302. "0347 Adapter is very hot, please take "
  10303. "corrective action. temperature : %d Celsius\n",
  10304. (uint32_t) icmd->ulpContext);
  10305. } else {
  10306. temp_event_data.event_code = LPFC_NORMAL_TEMP;
  10307. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10308. "0340 Adapter temperature is OK now. "
  10309. "temperature : %d Celsius\n",
  10310. (uint32_t) icmd->ulpContext);
  10311. }
  10312. /* Send temperature change event to applications */
  10313. shost = lpfc_shost_from_vport(phba->pport);
  10314. fc_host_post_vendor_event(shost, fc_get_event_number(),
  10315. sizeof(temp_event_data), (char *) &temp_event_data,
  10316. LPFC_NL_VENDOR_ID);
  10317. break;
  10318. case ASYNC_STATUS_CN:
  10319. lpfc_sli_abts_err_handler(phba, iocbq);
  10320. break;
  10321. default:
  10322. iocb_w = (uint32_t *) icmd;
  10323. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10324. "0346 Ring %d handler: unexpected ASYNC_STATUS"
  10325. " evt_code 0x%x\n"
  10326. "W0 0x%08x W1 0x%08x W2 0x%08x W3 0x%08x\n"
  10327. "W4 0x%08x W5 0x%08x W6 0x%08x W7 0x%08x\n"
  10328. "W8 0x%08x W9 0x%08x W10 0x%08x W11 0x%08x\n"
  10329. "W12 0x%08x W13 0x%08x W14 0x%08x W15 0x%08x\n",
  10330. pring->ringno, icmd->un.asyncstat.evt_code,
  10331. iocb_w[0], iocb_w[1], iocb_w[2], iocb_w[3],
  10332. iocb_w[4], iocb_w[5], iocb_w[6], iocb_w[7],
  10333. iocb_w[8], iocb_w[9], iocb_w[10], iocb_w[11],
  10334. iocb_w[12], iocb_w[13], iocb_w[14], iocb_w[15]);
  10335. break;
  10336. }
  10337. }
  10338. /**
  10339. * lpfc_sli4_setup - SLI ring setup function
  10340. * @phba: Pointer to HBA context object.
  10341. *
  10342. * lpfc_sli_setup sets up rings of the SLI interface with
  10343. * number of iocbs per ring and iotags. This function is
  10344. * called while driver attach to the HBA and before the
  10345. * interrupts are enabled. So there is no need for locking.
  10346. *
  10347. * This function always returns 0.
  10348. **/
  10349. int
  10350. lpfc_sli4_setup(struct lpfc_hba *phba)
  10351. {
  10352. struct lpfc_sli_ring *pring;
  10353. pring = phba->sli4_hba.els_wq->pring;
  10354. pring->num_mask = LPFC_MAX_RING_MASK;
  10355. pring->prt[0].profile = 0; /* Mask 0 */
  10356. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  10357. pring->prt[0].type = FC_TYPE_ELS;
  10358. pring->prt[0].lpfc_sli_rcv_unsol_event =
  10359. lpfc_els_unsol_event;
  10360. pring->prt[1].profile = 0; /* Mask 1 */
  10361. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  10362. pring->prt[1].type = FC_TYPE_ELS;
  10363. pring->prt[1].lpfc_sli_rcv_unsol_event =
  10364. lpfc_els_unsol_event;
  10365. pring->prt[2].profile = 0; /* Mask 2 */
  10366. /* NameServer Inquiry */
  10367. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  10368. /* NameServer */
  10369. pring->prt[2].type = FC_TYPE_CT;
  10370. pring->prt[2].lpfc_sli_rcv_unsol_event =
  10371. lpfc_ct_unsol_event;
  10372. pring->prt[3].profile = 0; /* Mask 3 */
  10373. /* NameServer response */
  10374. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  10375. /* NameServer */
  10376. pring->prt[3].type = FC_TYPE_CT;
  10377. pring->prt[3].lpfc_sli_rcv_unsol_event =
  10378. lpfc_ct_unsol_event;
  10379. return 0;
  10380. }
  10381. /**
  10382. * lpfc_sli_setup - SLI ring setup function
  10383. * @phba: Pointer to HBA context object.
  10384. *
  10385. * lpfc_sli_setup sets up rings of the SLI interface with
  10386. * number of iocbs per ring and iotags. This function is
  10387. * called while driver attach to the HBA and before the
  10388. * interrupts are enabled. So there is no need for locking.
  10389. *
  10390. * This function always returns 0. SLI3 only.
  10391. **/
  10392. int
  10393. lpfc_sli_setup(struct lpfc_hba *phba)
  10394. {
  10395. int i, totiocbsize = 0;
  10396. struct lpfc_sli *psli = &phba->sli;
  10397. struct lpfc_sli_ring *pring;
  10398. psli->num_rings = MAX_SLI3_CONFIGURED_RINGS;
  10399. psli->sli_flag = 0;
  10400. psli->iocbq_lookup = NULL;
  10401. psli->iocbq_lookup_len = 0;
  10402. psli->last_iotag = 0;
  10403. for (i = 0; i < psli->num_rings; i++) {
  10404. pring = &psli->sli3_ring[i];
  10405. switch (i) {
  10406. case LPFC_FCP_RING: /* ring 0 - FCP */
  10407. /* numCiocb and numRiocb are used in config_port */
  10408. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
  10409. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
  10410. pring->sli.sli3.numCiocb +=
  10411. SLI2_IOCB_CMD_R1XTRA_ENTRIES;
  10412. pring->sli.sli3.numRiocb +=
  10413. SLI2_IOCB_RSP_R1XTRA_ENTRIES;
  10414. pring->sli.sli3.numCiocb +=
  10415. SLI2_IOCB_CMD_R3XTRA_ENTRIES;
  10416. pring->sli.sli3.numRiocb +=
  10417. SLI2_IOCB_RSP_R3XTRA_ENTRIES;
  10418. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  10419. SLI3_IOCB_CMD_SIZE :
  10420. SLI2_IOCB_CMD_SIZE;
  10421. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  10422. SLI3_IOCB_RSP_SIZE :
  10423. SLI2_IOCB_RSP_SIZE;
  10424. pring->iotag_ctr = 0;
  10425. pring->iotag_max =
  10426. (phba->cfg_hba_queue_depth * 2);
  10427. pring->fast_iotag = pring->iotag_max;
  10428. pring->num_mask = 0;
  10429. break;
  10430. case LPFC_EXTRA_RING: /* ring 1 - EXTRA */
  10431. /* numCiocb and numRiocb are used in config_port */
  10432. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
  10433. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
  10434. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  10435. SLI3_IOCB_CMD_SIZE :
  10436. SLI2_IOCB_CMD_SIZE;
  10437. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  10438. SLI3_IOCB_RSP_SIZE :
  10439. SLI2_IOCB_RSP_SIZE;
  10440. pring->iotag_max = phba->cfg_hba_queue_depth;
  10441. pring->num_mask = 0;
  10442. break;
  10443. case LPFC_ELS_RING: /* ring 2 - ELS / CT */
  10444. /* numCiocb and numRiocb are used in config_port */
  10445. pring->sli.sli3.numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
  10446. pring->sli.sli3.numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
  10447. pring->sli.sli3.sizeCiocb = (phba->sli_rev == 3) ?
  10448. SLI3_IOCB_CMD_SIZE :
  10449. SLI2_IOCB_CMD_SIZE;
  10450. pring->sli.sli3.sizeRiocb = (phba->sli_rev == 3) ?
  10451. SLI3_IOCB_RSP_SIZE :
  10452. SLI2_IOCB_RSP_SIZE;
  10453. pring->fast_iotag = 0;
  10454. pring->iotag_ctr = 0;
  10455. pring->iotag_max = 4096;
  10456. pring->lpfc_sli_rcv_async_status =
  10457. lpfc_sli_async_event_handler;
  10458. pring->num_mask = LPFC_MAX_RING_MASK;
  10459. pring->prt[0].profile = 0; /* Mask 0 */
  10460. pring->prt[0].rctl = FC_RCTL_ELS_REQ;
  10461. pring->prt[0].type = FC_TYPE_ELS;
  10462. pring->prt[0].lpfc_sli_rcv_unsol_event =
  10463. lpfc_els_unsol_event;
  10464. pring->prt[1].profile = 0; /* Mask 1 */
  10465. pring->prt[1].rctl = FC_RCTL_ELS_REP;
  10466. pring->prt[1].type = FC_TYPE_ELS;
  10467. pring->prt[1].lpfc_sli_rcv_unsol_event =
  10468. lpfc_els_unsol_event;
  10469. pring->prt[2].profile = 0; /* Mask 2 */
  10470. /* NameServer Inquiry */
  10471. pring->prt[2].rctl = FC_RCTL_DD_UNSOL_CTL;
  10472. /* NameServer */
  10473. pring->prt[2].type = FC_TYPE_CT;
  10474. pring->prt[2].lpfc_sli_rcv_unsol_event =
  10475. lpfc_ct_unsol_event;
  10476. pring->prt[3].profile = 0; /* Mask 3 */
  10477. /* NameServer response */
  10478. pring->prt[3].rctl = FC_RCTL_DD_SOL_CTL;
  10479. /* NameServer */
  10480. pring->prt[3].type = FC_TYPE_CT;
  10481. pring->prt[3].lpfc_sli_rcv_unsol_event =
  10482. lpfc_ct_unsol_event;
  10483. break;
  10484. }
  10485. totiocbsize += (pring->sli.sli3.numCiocb *
  10486. pring->sli.sli3.sizeCiocb) +
  10487. (pring->sli.sli3.numRiocb * pring->sli.sli3.sizeRiocb);
  10488. }
  10489. if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
  10490. /* Too many cmd / rsp ring entries in SLI2 SLIM */
  10491. printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
  10492. "SLI2 SLIM Data: x%x x%lx\n",
  10493. phba->brd_no, totiocbsize,
  10494. (unsigned long) MAX_SLIM_IOCB_SIZE);
  10495. }
  10496. if (phba->cfg_multi_ring_support == 2)
  10497. lpfc_extra_ring_setup(phba);
  10498. return 0;
  10499. }
  10500. /**
  10501. * lpfc_sli4_queue_init - Queue initialization function
  10502. * @phba: Pointer to HBA context object.
  10503. *
  10504. * lpfc_sli4_queue_init sets up mailbox queues and iocb queues for each
  10505. * ring. This function also initializes ring indices of each ring.
  10506. * This function is called during the initialization of the SLI
  10507. * interface of an HBA.
  10508. * This function is called with no lock held and always returns
  10509. * 1.
  10510. **/
  10511. void
  10512. lpfc_sli4_queue_init(struct lpfc_hba *phba)
  10513. {
  10514. struct lpfc_sli *psli;
  10515. struct lpfc_sli_ring *pring;
  10516. int i;
  10517. psli = &phba->sli;
  10518. spin_lock_irq(&phba->hbalock);
  10519. INIT_LIST_HEAD(&psli->mboxq);
  10520. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  10521. /* Initialize list headers for txq and txcmplq as double linked lists */
  10522. for (i = 0; i < phba->cfg_hdw_queue; i++) {
  10523. pring = phba->sli4_hba.hdwq[i].io_wq->pring;
  10524. pring->flag = 0;
  10525. pring->ringno = LPFC_FCP_RING;
  10526. pring->txcmplq_cnt = 0;
  10527. INIT_LIST_HEAD(&pring->txq);
  10528. INIT_LIST_HEAD(&pring->txcmplq);
  10529. INIT_LIST_HEAD(&pring->iocb_continueq);
  10530. spin_lock_init(&pring->ring_lock);
  10531. }
  10532. pring = phba->sli4_hba.els_wq->pring;
  10533. pring->flag = 0;
  10534. pring->ringno = LPFC_ELS_RING;
  10535. pring->txcmplq_cnt = 0;
  10536. INIT_LIST_HEAD(&pring->txq);
  10537. INIT_LIST_HEAD(&pring->txcmplq);
  10538. INIT_LIST_HEAD(&pring->iocb_continueq);
  10539. spin_lock_init(&pring->ring_lock);
  10540. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  10541. pring = phba->sli4_hba.nvmels_wq->pring;
  10542. pring->flag = 0;
  10543. pring->ringno = LPFC_ELS_RING;
  10544. pring->txcmplq_cnt = 0;
  10545. INIT_LIST_HEAD(&pring->txq);
  10546. INIT_LIST_HEAD(&pring->txcmplq);
  10547. INIT_LIST_HEAD(&pring->iocb_continueq);
  10548. spin_lock_init(&pring->ring_lock);
  10549. }
  10550. spin_unlock_irq(&phba->hbalock);
  10551. }
  10552. /**
  10553. * lpfc_sli_queue_init - Queue initialization function
  10554. * @phba: Pointer to HBA context object.
  10555. *
  10556. * lpfc_sli_queue_init sets up mailbox queues and iocb queues for each
  10557. * ring. This function also initializes ring indices of each ring.
  10558. * This function is called during the initialization of the SLI
  10559. * interface of an HBA.
  10560. * This function is called with no lock held and always returns
  10561. * 1.
  10562. **/
  10563. void
  10564. lpfc_sli_queue_init(struct lpfc_hba *phba)
  10565. {
  10566. struct lpfc_sli *psli;
  10567. struct lpfc_sli_ring *pring;
  10568. int i;
  10569. psli = &phba->sli;
  10570. spin_lock_irq(&phba->hbalock);
  10571. INIT_LIST_HEAD(&psli->mboxq);
  10572. INIT_LIST_HEAD(&psli->mboxq_cmpl);
  10573. /* Initialize list headers for txq and txcmplq as double linked lists */
  10574. for (i = 0; i < psli->num_rings; i++) {
  10575. pring = &psli->sli3_ring[i];
  10576. pring->ringno = i;
  10577. pring->sli.sli3.next_cmdidx = 0;
  10578. pring->sli.sli3.local_getidx = 0;
  10579. pring->sli.sli3.cmdidx = 0;
  10580. INIT_LIST_HEAD(&pring->iocb_continueq);
  10581. INIT_LIST_HEAD(&pring->iocb_continue_saveq);
  10582. INIT_LIST_HEAD(&pring->postbufq);
  10583. pring->flag = 0;
  10584. INIT_LIST_HEAD(&pring->txq);
  10585. INIT_LIST_HEAD(&pring->txcmplq);
  10586. spin_lock_init(&pring->ring_lock);
  10587. }
  10588. spin_unlock_irq(&phba->hbalock);
  10589. }
  10590. /**
  10591. * lpfc_sli_mbox_sys_flush - Flush mailbox command sub-system
  10592. * @phba: Pointer to HBA context object.
  10593. *
  10594. * This routine flushes the mailbox command subsystem. It will unconditionally
  10595. * flush all the mailbox commands in the three possible stages in the mailbox
  10596. * command sub-system: pending mailbox command queue; the outstanding mailbox
  10597. * command; and completed mailbox command queue. It is caller's responsibility
  10598. * to make sure that the driver is in the proper state to flush the mailbox
  10599. * command sub-system. Namely, the posting of mailbox commands into the
  10600. * pending mailbox command queue from the various clients must be stopped;
  10601. * either the HBA is in a state that it will never works on the outstanding
  10602. * mailbox command (such as in EEH or ERATT conditions) or the outstanding
  10603. * mailbox command has been completed.
  10604. **/
  10605. static void
  10606. lpfc_sli_mbox_sys_flush(struct lpfc_hba *phba)
  10607. {
  10608. LIST_HEAD(completions);
  10609. struct lpfc_sli *psli = &phba->sli;
  10610. LPFC_MBOXQ_t *pmb;
  10611. unsigned long iflag;
  10612. /* Disable softirqs, including timers from obtaining phba->hbalock */
  10613. local_bh_disable();
  10614. /* Flush all the mailbox commands in the mbox system */
  10615. spin_lock_irqsave(&phba->hbalock, iflag);
  10616. /* The pending mailbox command queue */
  10617. list_splice_init(&phba->sli.mboxq, &completions);
  10618. /* The outstanding active mailbox command */
  10619. if (psli->mbox_active) {
  10620. list_add_tail(&psli->mbox_active->list, &completions);
  10621. psli->mbox_active = NULL;
  10622. psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  10623. }
  10624. /* The completed mailbox command queue */
  10625. list_splice_init(&phba->sli.mboxq_cmpl, &completions);
  10626. spin_unlock_irqrestore(&phba->hbalock, iflag);
  10627. /* Enable softirqs again, done with phba->hbalock */
  10628. local_bh_enable();
  10629. /* Return all flushed mailbox commands with MBX_NOT_FINISHED status */
  10630. while (!list_empty(&completions)) {
  10631. list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
  10632. pmb->u.mb.mbxStatus = MBX_NOT_FINISHED;
  10633. if (pmb->mbox_cmpl)
  10634. pmb->mbox_cmpl(phba, pmb);
  10635. }
  10636. }
  10637. /**
  10638. * lpfc_sli_host_down - Vport cleanup function
  10639. * @vport: Pointer to virtual port object.
  10640. *
  10641. * lpfc_sli_host_down is called to clean up the resources
  10642. * associated with a vport before destroying virtual
  10643. * port data structures.
  10644. * This function does following operations:
  10645. * - Free discovery resources associated with this virtual
  10646. * port.
  10647. * - Free iocbs associated with this virtual port in
  10648. * the txq.
  10649. * - Send abort for all iocb commands associated with this
  10650. * vport in txcmplq.
  10651. *
  10652. * This function is called with no lock held and always returns 1.
  10653. **/
  10654. int
  10655. lpfc_sli_host_down(struct lpfc_vport *vport)
  10656. {
  10657. LIST_HEAD(completions);
  10658. struct lpfc_hba *phba = vport->phba;
  10659. struct lpfc_sli *psli = &phba->sli;
  10660. struct lpfc_queue *qp = NULL;
  10661. struct lpfc_sli_ring *pring;
  10662. struct lpfc_iocbq *iocb, *next_iocb;
  10663. int i;
  10664. unsigned long flags = 0;
  10665. uint16_t prev_pring_flag;
  10666. lpfc_cleanup_discovery_resources(vport);
  10667. spin_lock_irqsave(&phba->hbalock, flags);
  10668. /*
  10669. * Error everything on the txq since these iocbs
  10670. * have not been given to the FW yet.
  10671. * Also issue ABTS for everything on the txcmplq
  10672. */
  10673. if (phba->sli_rev != LPFC_SLI_REV4) {
  10674. for (i = 0; i < psli->num_rings; i++) {
  10675. pring = &psli->sli3_ring[i];
  10676. prev_pring_flag = pring->flag;
  10677. /* Only slow rings */
  10678. if (pring->ringno == LPFC_ELS_RING) {
  10679. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  10680. /* Set the lpfc data pending flag */
  10681. set_bit(LPFC_DATA_READY, &phba->data_flags);
  10682. }
  10683. list_for_each_entry_safe(iocb, next_iocb,
  10684. &pring->txq, list) {
  10685. if (iocb->vport != vport)
  10686. continue;
  10687. list_move_tail(&iocb->list, &completions);
  10688. }
  10689. list_for_each_entry_safe(iocb, next_iocb,
  10690. &pring->txcmplq, list) {
  10691. if (iocb->vport != vport)
  10692. continue;
  10693. lpfc_sli_issue_abort_iotag(phba, pring, iocb,
  10694. NULL);
  10695. }
  10696. pring->flag = prev_pring_flag;
  10697. }
  10698. } else {
  10699. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  10700. pring = qp->pring;
  10701. if (!pring)
  10702. continue;
  10703. if (pring == phba->sli4_hba.els_wq->pring) {
  10704. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  10705. /* Set the lpfc data pending flag */
  10706. set_bit(LPFC_DATA_READY, &phba->data_flags);
  10707. }
  10708. prev_pring_flag = pring->flag;
  10709. spin_lock(&pring->ring_lock);
  10710. list_for_each_entry_safe(iocb, next_iocb,
  10711. &pring->txq, list) {
  10712. if (iocb->vport != vport)
  10713. continue;
  10714. list_move_tail(&iocb->list, &completions);
  10715. }
  10716. spin_unlock(&pring->ring_lock);
  10717. list_for_each_entry_safe(iocb, next_iocb,
  10718. &pring->txcmplq, list) {
  10719. if (iocb->vport != vport)
  10720. continue;
  10721. lpfc_sli_issue_abort_iotag(phba, pring, iocb,
  10722. NULL);
  10723. }
  10724. pring->flag = prev_pring_flag;
  10725. }
  10726. }
  10727. spin_unlock_irqrestore(&phba->hbalock, flags);
  10728. /* Make sure HBA is alive */
  10729. lpfc_issue_hb_tmo(phba);
  10730. /* Cancel all the IOCBs from the completions list */
  10731. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  10732. IOERR_SLI_DOWN);
  10733. return 1;
  10734. }
  10735. /**
  10736. * lpfc_sli_hba_down - Resource cleanup function for the HBA
  10737. * @phba: Pointer to HBA context object.
  10738. *
  10739. * This function cleans up all iocb, buffers, mailbox commands
  10740. * while shutting down the HBA. This function is called with no
  10741. * lock held and always returns 1.
  10742. * This function does the following to cleanup driver resources:
  10743. * - Free discovery resources for each virtual port
  10744. * - Cleanup any pending fabric iocbs
  10745. * - Iterate through the iocb txq and free each entry
  10746. * in the list.
  10747. * - Free up any buffer posted to the HBA
  10748. * - Free mailbox commands in the mailbox queue.
  10749. **/
  10750. int
  10751. lpfc_sli_hba_down(struct lpfc_hba *phba)
  10752. {
  10753. LIST_HEAD(completions);
  10754. struct lpfc_sli *psli = &phba->sli;
  10755. struct lpfc_queue *qp = NULL;
  10756. struct lpfc_sli_ring *pring;
  10757. struct lpfc_dmabuf *buf_ptr;
  10758. unsigned long flags = 0;
  10759. int i;
  10760. /* Shutdown the mailbox command sub-system */
  10761. lpfc_sli_mbox_sys_shutdown(phba, LPFC_MBX_WAIT);
  10762. lpfc_hba_down_prep(phba);
  10763. /* Disable softirqs, including timers from obtaining phba->hbalock */
  10764. local_bh_disable();
  10765. lpfc_fabric_abort_hba(phba);
  10766. spin_lock_irqsave(&phba->hbalock, flags);
  10767. /*
  10768. * Error everything on the txq since these iocbs
  10769. * have not been given to the FW yet.
  10770. */
  10771. if (phba->sli_rev != LPFC_SLI_REV4) {
  10772. for (i = 0; i < psli->num_rings; i++) {
  10773. pring = &psli->sli3_ring[i];
  10774. /* Only slow rings */
  10775. if (pring->ringno == LPFC_ELS_RING) {
  10776. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  10777. /* Set the lpfc data pending flag */
  10778. set_bit(LPFC_DATA_READY, &phba->data_flags);
  10779. }
  10780. list_splice_init(&pring->txq, &completions);
  10781. }
  10782. } else {
  10783. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  10784. pring = qp->pring;
  10785. if (!pring)
  10786. continue;
  10787. spin_lock(&pring->ring_lock);
  10788. list_splice_init(&pring->txq, &completions);
  10789. spin_unlock(&pring->ring_lock);
  10790. if (pring == phba->sli4_hba.els_wq->pring) {
  10791. pring->flag |= LPFC_DEFERRED_RING_EVENT;
  10792. /* Set the lpfc data pending flag */
  10793. set_bit(LPFC_DATA_READY, &phba->data_flags);
  10794. }
  10795. }
  10796. }
  10797. spin_unlock_irqrestore(&phba->hbalock, flags);
  10798. /* Cancel all the IOCBs from the completions list */
  10799. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  10800. IOERR_SLI_DOWN);
  10801. spin_lock_irqsave(&phba->hbalock, flags);
  10802. list_splice_init(&phba->elsbuf, &completions);
  10803. phba->elsbuf_cnt = 0;
  10804. phba->elsbuf_prev_cnt = 0;
  10805. spin_unlock_irqrestore(&phba->hbalock, flags);
  10806. while (!list_empty(&completions)) {
  10807. list_remove_head(&completions, buf_ptr,
  10808. struct lpfc_dmabuf, list);
  10809. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  10810. kfree(buf_ptr);
  10811. }
  10812. /* Enable softirqs again, done with phba->hbalock */
  10813. local_bh_enable();
  10814. /* Return any active mbox cmds */
  10815. del_timer_sync(&psli->mbox_tmo);
  10816. spin_lock_irqsave(&phba->pport->work_port_lock, flags);
  10817. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  10818. spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
  10819. return 1;
  10820. }
  10821. /**
  10822. * lpfc_sli_pcimem_bcopy - SLI memory copy function
  10823. * @srcp: Source memory pointer.
  10824. * @destp: Destination memory pointer.
  10825. * @cnt: Number of words required to be copied.
  10826. *
  10827. * This function is used for copying data between driver memory
  10828. * and the SLI memory. This function also changes the endianness
  10829. * of each word if native endianness is different from SLI
  10830. * endianness. This function can be called with or without
  10831. * lock.
  10832. **/
  10833. void
  10834. lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
  10835. {
  10836. uint32_t *src = srcp;
  10837. uint32_t *dest = destp;
  10838. uint32_t ldata;
  10839. int i;
  10840. for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
  10841. ldata = *src;
  10842. ldata = le32_to_cpu(ldata);
  10843. *dest = ldata;
  10844. src++;
  10845. dest++;
  10846. }
  10847. }
  10848. /**
  10849. * lpfc_sli_bemem_bcopy - SLI memory copy function
  10850. * @srcp: Source memory pointer.
  10851. * @destp: Destination memory pointer.
  10852. * @cnt: Number of words required to be copied.
  10853. *
  10854. * This function is used for copying data between a data structure
  10855. * with big endian representation to local endianness.
  10856. * This function can be called with or without lock.
  10857. **/
  10858. void
  10859. lpfc_sli_bemem_bcopy(void *srcp, void *destp, uint32_t cnt)
  10860. {
  10861. uint32_t *src = srcp;
  10862. uint32_t *dest = destp;
  10863. uint32_t ldata;
  10864. int i;
  10865. for (i = 0; i < (int)cnt; i += sizeof(uint32_t)) {
  10866. ldata = *src;
  10867. ldata = be32_to_cpu(ldata);
  10868. *dest = ldata;
  10869. src++;
  10870. dest++;
  10871. }
  10872. }
  10873. /**
  10874. * lpfc_sli_ringpostbuf_put - Function to add a buffer to postbufq
  10875. * @phba: Pointer to HBA context object.
  10876. * @pring: Pointer to driver SLI ring object.
  10877. * @mp: Pointer to driver buffer object.
  10878. *
  10879. * This function is called with no lock held.
  10880. * It always return zero after adding the buffer to the postbufq
  10881. * buffer list.
  10882. **/
  10883. int
  10884. lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  10885. struct lpfc_dmabuf *mp)
  10886. {
  10887. /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
  10888. later */
  10889. spin_lock_irq(&phba->hbalock);
  10890. list_add_tail(&mp->list, &pring->postbufq);
  10891. pring->postbufq_cnt++;
  10892. spin_unlock_irq(&phba->hbalock);
  10893. return 0;
  10894. }
  10895. /**
  10896. * lpfc_sli_get_buffer_tag - allocates a tag for a CMD_QUE_XRI64_CX buffer
  10897. * @phba: Pointer to HBA context object.
  10898. *
  10899. * When HBQ is enabled, buffers are searched based on tags. This function
  10900. * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
  10901. * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
  10902. * does not conflict with tags of buffer posted for unsolicited events.
  10903. * The function returns the allocated tag. The function is called with
  10904. * no locks held.
  10905. **/
  10906. uint32_t
  10907. lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
  10908. {
  10909. spin_lock_irq(&phba->hbalock);
  10910. phba->buffer_tag_count++;
  10911. /*
  10912. * Always set the QUE_BUFTAG_BIT to distiguish between
  10913. * a tag assigned by HBQ.
  10914. */
  10915. phba->buffer_tag_count |= QUE_BUFTAG_BIT;
  10916. spin_unlock_irq(&phba->hbalock);
  10917. return phba->buffer_tag_count;
  10918. }
  10919. /**
  10920. * lpfc_sli_ring_taggedbuf_get - find HBQ buffer associated with given tag
  10921. * @phba: Pointer to HBA context object.
  10922. * @pring: Pointer to driver SLI ring object.
  10923. * @tag: Buffer tag.
  10924. *
  10925. * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
  10926. * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
  10927. * iocb is posted to the response ring with the tag of the buffer.
  10928. * This function searches the pring->postbufq list using the tag
  10929. * to find buffer associated with CMD_IOCB_RET_XRI64_CX
  10930. * iocb. If the buffer is found then lpfc_dmabuf object of the
  10931. * buffer is returned to the caller else NULL is returned.
  10932. * This function is called with no lock held.
  10933. **/
  10934. struct lpfc_dmabuf *
  10935. lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  10936. uint32_t tag)
  10937. {
  10938. struct lpfc_dmabuf *mp, *next_mp;
  10939. struct list_head *slp = &pring->postbufq;
  10940. /* Search postbufq, from the beginning, looking for a match on tag */
  10941. spin_lock_irq(&phba->hbalock);
  10942. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  10943. if (mp->buffer_tag == tag) {
  10944. list_del_init(&mp->list);
  10945. pring->postbufq_cnt--;
  10946. spin_unlock_irq(&phba->hbalock);
  10947. return mp;
  10948. }
  10949. }
  10950. spin_unlock_irq(&phba->hbalock);
  10951. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10952. "0402 Cannot find virtual addr for buffer tag on "
  10953. "ring %d Data x%lx x%px x%px x%x\n",
  10954. pring->ringno, (unsigned long) tag,
  10955. slp->next, slp->prev, pring->postbufq_cnt);
  10956. return NULL;
  10957. }
  10958. /**
  10959. * lpfc_sli_ringpostbuf_get - search buffers for unsolicited CT and ELS events
  10960. * @phba: Pointer to HBA context object.
  10961. * @pring: Pointer to driver SLI ring object.
  10962. * @phys: DMA address of the buffer.
  10963. *
  10964. * This function searches the buffer list using the dma_address
  10965. * of unsolicited event to find the driver's lpfc_dmabuf object
  10966. * corresponding to the dma_address. The function returns the
  10967. * lpfc_dmabuf object if a buffer is found else it returns NULL.
  10968. * This function is called by the ct and els unsolicited event
  10969. * handlers to get the buffer associated with the unsolicited
  10970. * event.
  10971. *
  10972. * This function is called with no lock held.
  10973. **/
  10974. struct lpfc_dmabuf *
  10975. lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  10976. dma_addr_t phys)
  10977. {
  10978. struct lpfc_dmabuf *mp, *next_mp;
  10979. struct list_head *slp = &pring->postbufq;
  10980. /* Search postbufq, from the beginning, looking for a match on phys */
  10981. spin_lock_irq(&phba->hbalock);
  10982. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  10983. if (mp->phys == phys) {
  10984. list_del_init(&mp->list);
  10985. pring->postbufq_cnt--;
  10986. spin_unlock_irq(&phba->hbalock);
  10987. return mp;
  10988. }
  10989. }
  10990. spin_unlock_irq(&phba->hbalock);
  10991. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  10992. "0410 Cannot find virtual addr for mapped buf on "
  10993. "ring %d Data x%llx x%px x%px x%x\n",
  10994. pring->ringno, (unsigned long long)phys,
  10995. slp->next, slp->prev, pring->postbufq_cnt);
  10996. return NULL;
  10997. }
  10998. /**
  10999. * lpfc_sli_abort_els_cmpl - Completion handler for the els abort iocbs
  11000. * @phba: Pointer to HBA context object.
  11001. * @cmdiocb: Pointer to driver command iocb object.
  11002. * @rspiocb: Pointer to driver response iocb object.
  11003. *
  11004. * This function is the completion handler for the abort iocbs for
  11005. * ELS commands. This function is called from the ELS ring event
  11006. * handler with no lock held. This function frees memory resources
  11007. * associated with the abort iocb.
  11008. **/
  11009. static void
  11010. lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  11011. struct lpfc_iocbq *rspiocb)
  11012. {
  11013. u32 ulp_status = get_job_ulpstatus(phba, rspiocb);
  11014. u32 ulp_word4 = get_job_word4(phba, rspiocb);
  11015. u8 cmnd = get_job_cmnd(phba, cmdiocb);
  11016. if (ulp_status) {
  11017. /*
  11018. * Assume that the port already completed and returned, or
  11019. * will return the iocb. Just Log the message.
  11020. */
  11021. if (phba->sli_rev < LPFC_SLI_REV4) {
  11022. if (cmnd == CMD_ABORT_XRI_CX &&
  11023. ulp_status == IOSTAT_LOCAL_REJECT &&
  11024. ulp_word4 == IOERR_ABORT_REQUESTED) {
  11025. goto release_iocb;
  11026. }
  11027. }
  11028. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_SLI,
  11029. "0327 Cannot abort els iocb x%px "
  11030. "with io cmd xri %x abort tag : x%x, "
  11031. "abort status %x abort code %x\n",
  11032. cmdiocb, get_job_abtsiotag(phba, cmdiocb),
  11033. (phba->sli_rev == LPFC_SLI_REV4) ?
  11034. get_wqe_reqtag(cmdiocb) :
  11035. cmdiocb->iocb.un.acxri.abortContextTag,
  11036. ulp_status, ulp_word4);
  11037. }
  11038. release_iocb:
  11039. lpfc_sli_release_iocbq(phba, cmdiocb);
  11040. return;
  11041. }
  11042. /**
  11043. * lpfc_ignore_els_cmpl - Completion handler for aborted ELS command
  11044. * @phba: Pointer to HBA context object.
  11045. * @cmdiocb: Pointer to driver command iocb object.
  11046. * @rspiocb: Pointer to driver response iocb object.
  11047. *
  11048. * The function is called from SLI ring event handler with no
  11049. * lock held. This function is the completion handler for ELS commands
  11050. * which are aborted. The function frees memory resources used for
  11051. * the aborted ELS commands.
  11052. **/
  11053. void
  11054. lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  11055. struct lpfc_iocbq *rspiocb)
  11056. {
  11057. struct lpfc_nodelist *ndlp = cmdiocb->ndlp;
  11058. IOCB_t *irsp;
  11059. LPFC_MBOXQ_t *mbox;
  11060. u32 ulp_command, ulp_status, ulp_word4, iotag;
  11061. ulp_command = get_job_cmnd(phba, cmdiocb);
  11062. ulp_status = get_job_ulpstatus(phba, rspiocb);
  11063. ulp_word4 = get_job_word4(phba, rspiocb);
  11064. if (phba->sli_rev == LPFC_SLI_REV4) {
  11065. iotag = get_wqe_reqtag(cmdiocb);
  11066. } else {
  11067. irsp = &rspiocb->iocb;
  11068. iotag = irsp->ulpIoTag;
  11069. /* It is possible a PLOGI_RJT for NPIV ports to get aborted.
  11070. * The MBX_REG_LOGIN64 mbox command is freed back to the
  11071. * mbox_mem_pool here.
  11072. */
  11073. if (cmdiocb->context_un.mbox) {
  11074. mbox = cmdiocb->context_un.mbox;
  11075. lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
  11076. cmdiocb->context_un.mbox = NULL;
  11077. }
  11078. }
  11079. /* ELS cmd tag <ulpIoTag> completes */
  11080. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  11081. "0139 Ignoring ELS cmd code x%x completion Data: "
  11082. "x%x x%x x%x x%px\n",
  11083. ulp_command, ulp_status, ulp_word4, iotag,
  11084. cmdiocb->ndlp);
  11085. /*
  11086. * Deref the ndlp after free_iocb. sli_release_iocb will access the ndlp
  11087. * if exchange is busy.
  11088. */
  11089. if (ulp_command == CMD_GEN_REQUEST64_CR)
  11090. lpfc_ct_free_iocb(phba, cmdiocb);
  11091. else
  11092. lpfc_els_free_iocb(phba, cmdiocb);
  11093. lpfc_nlp_put(ndlp);
  11094. }
  11095. /**
  11096. * lpfc_sli_issue_abort_iotag - Abort function for a command iocb
  11097. * @phba: Pointer to HBA context object.
  11098. * @pring: Pointer to driver SLI ring object.
  11099. * @cmdiocb: Pointer to driver command iocb object.
  11100. * @cmpl: completion function.
  11101. *
  11102. * This function issues an abort iocb for the provided command iocb. In case
  11103. * of unloading, the abort iocb will not be issued to commands on the ELS
  11104. * ring. Instead, the callback function shall be changed to those commands
  11105. * so that nothing happens when them finishes. This function is called with
  11106. * hbalock held andno ring_lock held (SLI4). The function returns IOCB_SUCCESS
  11107. * when the command iocb is an abort request.
  11108. *
  11109. **/
  11110. int
  11111. lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  11112. struct lpfc_iocbq *cmdiocb, void *cmpl)
  11113. {
  11114. struct lpfc_vport *vport = cmdiocb->vport;
  11115. struct lpfc_iocbq *abtsiocbp;
  11116. int retval = IOCB_ERROR;
  11117. unsigned long iflags;
  11118. struct lpfc_nodelist *ndlp = NULL;
  11119. u32 ulp_command = get_job_cmnd(phba, cmdiocb);
  11120. u16 ulp_context, iotag;
  11121. bool ia;
  11122. /*
  11123. * There are certain command types we don't want to abort. And we
  11124. * don't want to abort commands that are already in the process of
  11125. * being aborted.
  11126. */
  11127. if (ulp_command == CMD_ABORT_XRI_WQE ||
  11128. ulp_command == CMD_ABORT_XRI_CN ||
  11129. ulp_command == CMD_CLOSE_XRI_CN ||
  11130. cmdiocb->cmd_flag & LPFC_DRIVER_ABORTED)
  11131. return IOCB_ABORTING;
  11132. if (!pring) {
  11133. if (cmdiocb->cmd_flag & LPFC_IO_FABRIC)
  11134. cmdiocb->fabric_cmd_cmpl = lpfc_ignore_els_cmpl;
  11135. else
  11136. cmdiocb->cmd_cmpl = lpfc_ignore_els_cmpl;
  11137. return retval;
  11138. }
  11139. /*
  11140. * If we're unloading, don't abort iocb on the ELS ring, but change
  11141. * the callback so that nothing happens when it finishes.
  11142. */
  11143. if ((vport->load_flag & FC_UNLOADING) &&
  11144. pring->ringno == LPFC_ELS_RING) {
  11145. if (cmdiocb->cmd_flag & LPFC_IO_FABRIC)
  11146. cmdiocb->fabric_cmd_cmpl = lpfc_ignore_els_cmpl;
  11147. else
  11148. cmdiocb->cmd_cmpl = lpfc_ignore_els_cmpl;
  11149. return retval;
  11150. }
  11151. /* issue ABTS for this IOCB based on iotag */
  11152. abtsiocbp = __lpfc_sli_get_iocbq(phba);
  11153. if (abtsiocbp == NULL)
  11154. return IOCB_NORESOURCE;
  11155. /* This signals the response to set the correct status
  11156. * before calling the completion handler
  11157. */
  11158. cmdiocb->cmd_flag |= LPFC_DRIVER_ABORTED;
  11159. if (phba->sli_rev == LPFC_SLI_REV4) {
  11160. ulp_context = cmdiocb->sli4_xritag;
  11161. iotag = abtsiocbp->iotag;
  11162. } else {
  11163. iotag = cmdiocb->iocb.ulpIoTag;
  11164. if (pring->ringno == LPFC_ELS_RING) {
  11165. ndlp = cmdiocb->ndlp;
  11166. ulp_context = ndlp->nlp_rpi;
  11167. } else {
  11168. ulp_context = cmdiocb->iocb.ulpContext;
  11169. }
  11170. }
  11171. if (phba->link_state < LPFC_LINK_UP ||
  11172. (phba->sli_rev == LPFC_SLI_REV4 &&
  11173. phba->sli4_hba.link_state.status == LPFC_FC_LA_TYPE_LINK_DOWN) ||
  11174. (phba->link_flag & LS_EXTERNAL_LOOPBACK))
  11175. ia = true;
  11176. else
  11177. ia = false;
  11178. lpfc_sli_prep_abort_xri(phba, abtsiocbp, ulp_context, iotag,
  11179. cmdiocb->iocb.ulpClass,
  11180. LPFC_WQE_CQ_ID_DEFAULT, ia, false);
  11181. abtsiocbp->vport = vport;
  11182. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  11183. abtsiocbp->hba_wqidx = cmdiocb->hba_wqidx;
  11184. if (cmdiocb->cmd_flag & LPFC_IO_FCP)
  11185. abtsiocbp->cmd_flag |= (LPFC_IO_FCP | LPFC_USE_FCPWQIDX);
  11186. if (cmdiocb->cmd_flag & LPFC_IO_FOF)
  11187. abtsiocbp->cmd_flag |= LPFC_IO_FOF;
  11188. if (cmpl)
  11189. abtsiocbp->cmd_cmpl = cmpl;
  11190. else
  11191. abtsiocbp->cmd_cmpl = lpfc_sli_abort_els_cmpl;
  11192. abtsiocbp->vport = vport;
  11193. if (phba->sli_rev == LPFC_SLI_REV4) {
  11194. pring = lpfc_sli4_calc_ring(phba, abtsiocbp);
  11195. if (unlikely(pring == NULL))
  11196. goto abort_iotag_exit;
  11197. /* Note: both hbalock and ring_lock need to be set here */
  11198. spin_lock_irqsave(&pring->ring_lock, iflags);
  11199. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  11200. abtsiocbp, 0);
  11201. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  11202. } else {
  11203. retval = __lpfc_sli_issue_iocb(phba, pring->ringno,
  11204. abtsiocbp, 0);
  11205. }
  11206. abort_iotag_exit:
  11207. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
  11208. "0339 Abort IO XRI x%x, Original iotag x%x, "
  11209. "abort tag x%x Cmdjob : x%px Abortjob : x%px "
  11210. "retval x%x\n",
  11211. ulp_context, (phba->sli_rev == LPFC_SLI_REV4) ?
  11212. cmdiocb->iotag : iotag, iotag, cmdiocb, abtsiocbp,
  11213. retval);
  11214. if (retval) {
  11215. cmdiocb->cmd_flag &= ~LPFC_DRIVER_ABORTED;
  11216. __lpfc_sli_release_iocbq(phba, abtsiocbp);
  11217. }
  11218. /*
  11219. * Caller to this routine should check for IOCB_ERROR
  11220. * and handle it properly. This routine no longer removes
  11221. * iocb off txcmplq and call compl in case of IOCB_ERROR.
  11222. */
  11223. return retval;
  11224. }
  11225. /**
  11226. * lpfc_sli_hba_iocb_abort - Abort all iocbs to an hba.
  11227. * @phba: pointer to lpfc HBA data structure.
  11228. *
  11229. * This routine will abort all pending and outstanding iocbs to an HBA.
  11230. **/
  11231. void
  11232. lpfc_sli_hba_iocb_abort(struct lpfc_hba *phba)
  11233. {
  11234. struct lpfc_sli *psli = &phba->sli;
  11235. struct lpfc_sli_ring *pring;
  11236. struct lpfc_queue *qp = NULL;
  11237. int i;
  11238. if (phba->sli_rev != LPFC_SLI_REV4) {
  11239. for (i = 0; i < psli->num_rings; i++) {
  11240. pring = &psli->sli3_ring[i];
  11241. lpfc_sli_abort_iocb_ring(phba, pring);
  11242. }
  11243. return;
  11244. }
  11245. list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) {
  11246. pring = qp->pring;
  11247. if (!pring)
  11248. continue;
  11249. lpfc_sli_abort_iocb_ring(phba, pring);
  11250. }
  11251. }
  11252. /**
  11253. * lpfc_sli_validate_fcp_iocb_for_abort - filter iocbs appropriate for FCP aborts
  11254. * @iocbq: Pointer to iocb object.
  11255. * @vport: Pointer to driver virtual port object.
  11256. *
  11257. * This function acts as an iocb filter for functions which abort FCP iocbs.
  11258. *
  11259. * Return values
  11260. * -ENODEV, if a null iocb or vport ptr is encountered
  11261. * -EINVAL, if the iocb is not an FCP I/O, not on the TX cmpl queue, premarked as
  11262. * driver already started the abort process, or is an abort iocb itself
  11263. * 0, passes criteria for aborting the FCP I/O iocb
  11264. **/
  11265. static int
  11266. lpfc_sli_validate_fcp_iocb_for_abort(struct lpfc_iocbq *iocbq,
  11267. struct lpfc_vport *vport)
  11268. {
  11269. u8 ulp_command;
  11270. /* No null ptr vports */
  11271. if (!iocbq || iocbq->vport != vport)
  11272. return -ENODEV;
  11273. /* iocb must be for FCP IO, already exists on the TX cmpl queue,
  11274. * can't be premarked as driver aborted, nor be an ABORT iocb itself
  11275. */
  11276. ulp_command = get_job_cmnd(vport->phba, iocbq);
  11277. if (!(iocbq->cmd_flag & LPFC_IO_FCP) ||
  11278. !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ) ||
  11279. (iocbq->cmd_flag & LPFC_DRIVER_ABORTED) ||
  11280. (ulp_command == CMD_ABORT_XRI_CN ||
  11281. ulp_command == CMD_CLOSE_XRI_CN ||
  11282. ulp_command == CMD_ABORT_XRI_WQE))
  11283. return -EINVAL;
  11284. return 0;
  11285. }
  11286. /**
  11287. * lpfc_sli_validate_fcp_iocb - validate commands associated with a SCSI target
  11288. * @iocbq: Pointer to driver iocb object.
  11289. * @vport: Pointer to driver virtual port object.
  11290. * @tgt_id: SCSI ID of the target.
  11291. * @lun_id: LUN ID of the scsi device.
  11292. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
  11293. *
  11294. * This function acts as an iocb filter for validating a lun/SCSI target/SCSI
  11295. * host.
  11296. *
  11297. * It will return
  11298. * 0 if the filtering criteria is met for the given iocb and will return
  11299. * 1 if the filtering criteria is not met.
  11300. * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
  11301. * given iocb is for the SCSI device specified by vport, tgt_id and
  11302. * lun_id parameter.
  11303. * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
  11304. * given iocb is for the SCSI target specified by vport and tgt_id
  11305. * parameters.
  11306. * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
  11307. * given iocb is for the SCSI host associated with the given vport.
  11308. * This function is called with no locks held.
  11309. **/
  11310. static int
  11311. lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
  11312. uint16_t tgt_id, uint64_t lun_id,
  11313. lpfc_ctx_cmd ctx_cmd)
  11314. {
  11315. struct lpfc_io_buf *lpfc_cmd;
  11316. int rc = 1;
  11317. lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
  11318. if (lpfc_cmd->pCmd == NULL)
  11319. return rc;
  11320. switch (ctx_cmd) {
  11321. case LPFC_CTX_LUN:
  11322. if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
  11323. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
  11324. (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
  11325. rc = 0;
  11326. break;
  11327. case LPFC_CTX_TGT:
  11328. if ((lpfc_cmd->rdata) && (lpfc_cmd->rdata->pnode) &&
  11329. (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
  11330. rc = 0;
  11331. break;
  11332. case LPFC_CTX_HOST:
  11333. rc = 0;
  11334. break;
  11335. default:
  11336. printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
  11337. __func__, ctx_cmd);
  11338. break;
  11339. }
  11340. return rc;
  11341. }
  11342. /**
  11343. * lpfc_sli_sum_iocb - Function to count the number of FCP iocbs pending
  11344. * @vport: Pointer to virtual port.
  11345. * @tgt_id: SCSI ID of the target.
  11346. * @lun_id: LUN ID of the scsi device.
  11347. * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  11348. *
  11349. * This function returns number of FCP commands pending for the vport.
  11350. * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
  11351. * commands pending on the vport associated with SCSI device specified
  11352. * by tgt_id and lun_id parameters.
  11353. * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
  11354. * commands pending on the vport associated with SCSI target specified
  11355. * by tgt_id parameter.
  11356. * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
  11357. * commands pending on the vport.
  11358. * This function returns the number of iocbs which satisfy the filter.
  11359. * This function is called without any lock held.
  11360. **/
  11361. int
  11362. lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
  11363. lpfc_ctx_cmd ctx_cmd)
  11364. {
  11365. struct lpfc_hba *phba = vport->phba;
  11366. struct lpfc_iocbq *iocbq;
  11367. int sum, i;
  11368. unsigned long iflags;
  11369. u8 ulp_command;
  11370. spin_lock_irqsave(&phba->hbalock, iflags);
  11371. for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
  11372. iocbq = phba->sli.iocbq_lookup[i];
  11373. if (!iocbq || iocbq->vport != vport)
  11374. continue;
  11375. if (!(iocbq->cmd_flag & LPFC_IO_FCP) ||
  11376. !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ))
  11377. continue;
  11378. /* Include counting outstanding aborts */
  11379. ulp_command = get_job_cmnd(phba, iocbq);
  11380. if (ulp_command == CMD_ABORT_XRI_CN ||
  11381. ulp_command == CMD_CLOSE_XRI_CN ||
  11382. ulp_command == CMD_ABORT_XRI_WQE) {
  11383. sum++;
  11384. continue;
  11385. }
  11386. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  11387. ctx_cmd) == 0)
  11388. sum++;
  11389. }
  11390. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11391. return sum;
  11392. }
  11393. /**
  11394. * lpfc_sli_abort_fcp_cmpl - Completion handler function for aborted FCP IOCBs
  11395. * @phba: Pointer to HBA context object
  11396. * @cmdiocb: Pointer to command iocb object.
  11397. * @rspiocb: Pointer to response iocb object.
  11398. *
  11399. * This function is called when an aborted FCP iocb completes. This
  11400. * function is called by the ring event handler with no lock held.
  11401. * This function frees the iocb.
  11402. **/
  11403. void
  11404. lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  11405. struct lpfc_iocbq *rspiocb)
  11406. {
  11407. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  11408. "3096 ABORT_XRI_CX completing on rpi x%x "
  11409. "original iotag x%x, abort cmd iotag x%x "
  11410. "status 0x%x, reason 0x%x\n",
  11411. (phba->sli_rev == LPFC_SLI_REV4) ?
  11412. cmdiocb->sli4_xritag :
  11413. cmdiocb->iocb.un.acxri.abortContextTag,
  11414. get_job_abtsiotag(phba, cmdiocb),
  11415. cmdiocb->iotag, get_job_ulpstatus(phba, rspiocb),
  11416. get_job_word4(phba, rspiocb));
  11417. lpfc_sli_release_iocbq(phba, cmdiocb);
  11418. return;
  11419. }
  11420. /**
  11421. * lpfc_sli_abort_iocb - issue abort for all commands on a host/target/LUN
  11422. * @vport: Pointer to virtual port.
  11423. * @tgt_id: SCSI ID of the target.
  11424. * @lun_id: LUN ID of the scsi device.
  11425. * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  11426. *
  11427. * This function sends an abort command for every SCSI command
  11428. * associated with the given virtual port pending on the ring
  11429. * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
  11430. * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
  11431. * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
  11432. * followed by lpfc_sli_validate_fcp_iocb.
  11433. *
  11434. * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
  11435. * FCP iocbs associated with lun specified by tgt_id and lun_id
  11436. * parameters
  11437. * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
  11438. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  11439. * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
  11440. * FCP iocbs associated with virtual port.
  11441. * The pring used for SLI3 is sli3_ring[LPFC_FCP_RING], for SLI4
  11442. * lpfc_sli4_calc_ring is used.
  11443. * This function returns number of iocbs it failed to abort.
  11444. * This function is called with no locks held.
  11445. **/
  11446. int
  11447. lpfc_sli_abort_iocb(struct lpfc_vport *vport, u16 tgt_id, u64 lun_id,
  11448. lpfc_ctx_cmd abort_cmd)
  11449. {
  11450. struct lpfc_hba *phba = vport->phba;
  11451. struct lpfc_sli_ring *pring = NULL;
  11452. struct lpfc_iocbq *iocbq;
  11453. int errcnt = 0, ret_val = 0;
  11454. unsigned long iflags;
  11455. int i;
  11456. /* all I/Os are in process of being flushed */
  11457. if (phba->hba_flag & HBA_IOQ_FLUSH)
  11458. return errcnt;
  11459. for (i = 1; i <= phba->sli.last_iotag; i++) {
  11460. iocbq = phba->sli.iocbq_lookup[i];
  11461. if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
  11462. continue;
  11463. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  11464. abort_cmd) != 0)
  11465. continue;
  11466. spin_lock_irqsave(&phba->hbalock, iflags);
  11467. if (phba->sli_rev == LPFC_SLI_REV3) {
  11468. pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
  11469. } else if (phba->sli_rev == LPFC_SLI_REV4) {
  11470. pring = lpfc_sli4_calc_ring(phba, iocbq);
  11471. }
  11472. ret_val = lpfc_sli_issue_abort_iotag(phba, pring, iocbq,
  11473. lpfc_sli_abort_fcp_cmpl);
  11474. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11475. if (ret_val != IOCB_SUCCESS)
  11476. errcnt++;
  11477. }
  11478. return errcnt;
  11479. }
  11480. /**
  11481. * lpfc_sli_abort_taskmgmt - issue abort for all commands on a host/target/LUN
  11482. * @vport: Pointer to virtual port.
  11483. * @pring: Pointer to driver SLI ring object.
  11484. * @tgt_id: SCSI ID of the target.
  11485. * @lun_id: LUN ID of the scsi device.
  11486. * @cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
  11487. *
  11488. * This function sends an abort command for every SCSI command
  11489. * associated with the given virtual port pending on the ring
  11490. * filtered by lpfc_sli_validate_fcp_iocb_for_abort and then
  11491. * lpfc_sli_validate_fcp_iocb function. The ordering for validation before
  11492. * submitting abort iocbs must be lpfc_sli_validate_fcp_iocb_for_abort
  11493. * followed by lpfc_sli_validate_fcp_iocb.
  11494. *
  11495. * When taskmgmt_cmd == LPFC_CTX_LUN, the function sends abort only to the
  11496. * FCP iocbs associated with lun specified by tgt_id and lun_id
  11497. * parameters
  11498. * When taskmgmt_cmd == LPFC_CTX_TGT, the function sends abort only to the
  11499. * FCP iocbs associated with SCSI target specified by tgt_id parameter.
  11500. * When taskmgmt_cmd == LPFC_CTX_HOST, the function sends abort to all
  11501. * FCP iocbs associated with virtual port.
  11502. * This function returns number of iocbs it aborted .
  11503. * This function is called with no locks held right after a taskmgmt
  11504. * command is sent.
  11505. **/
  11506. int
  11507. lpfc_sli_abort_taskmgmt(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
  11508. uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd cmd)
  11509. {
  11510. struct lpfc_hba *phba = vport->phba;
  11511. struct lpfc_io_buf *lpfc_cmd;
  11512. struct lpfc_iocbq *abtsiocbq;
  11513. struct lpfc_nodelist *ndlp = NULL;
  11514. struct lpfc_iocbq *iocbq;
  11515. int sum, i, ret_val;
  11516. unsigned long iflags;
  11517. struct lpfc_sli_ring *pring_s4 = NULL;
  11518. u16 ulp_context, iotag, cqid = LPFC_WQE_CQ_ID_DEFAULT;
  11519. bool ia;
  11520. spin_lock_irqsave(&phba->hbalock, iflags);
  11521. /* all I/Os are in process of being flushed */
  11522. if (phba->hba_flag & HBA_IOQ_FLUSH) {
  11523. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11524. return 0;
  11525. }
  11526. sum = 0;
  11527. for (i = 1; i <= phba->sli.last_iotag; i++) {
  11528. iocbq = phba->sli.iocbq_lookup[i];
  11529. if (lpfc_sli_validate_fcp_iocb_for_abort(iocbq, vport))
  11530. continue;
  11531. if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
  11532. cmd) != 0)
  11533. continue;
  11534. /* Guard against IO completion being called at same time */
  11535. lpfc_cmd = container_of(iocbq, struct lpfc_io_buf, cur_iocbq);
  11536. spin_lock(&lpfc_cmd->buf_lock);
  11537. if (!lpfc_cmd->pCmd) {
  11538. spin_unlock(&lpfc_cmd->buf_lock);
  11539. continue;
  11540. }
  11541. if (phba->sli_rev == LPFC_SLI_REV4) {
  11542. pring_s4 =
  11543. phba->sli4_hba.hdwq[iocbq->hba_wqidx].io_wq->pring;
  11544. if (!pring_s4) {
  11545. spin_unlock(&lpfc_cmd->buf_lock);
  11546. continue;
  11547. }
  11548. /* Note: both hbalock and ring_lock must be set here */
  11549. spin_lock(&pring_s4->ring_lock);
  11550. }
  11551. /*
  11552. * If the iocbq is already being aborted, don't take a second
  11553. * action, but do count it.
  11554. */
  11555. if ((iocbq->cmd_flag & LPFC_DRIVER_ABORTED) ||
  11556. !(iocbq->cmd_flag & LPFC_IO_ON_TXCMPLQ)) {
  11557. if (phba->sli_rev == LPFC_SLI_REV4)
  11558. spin_unlock(&pring_s4->ring_lock);
  11559. spin_unlock(&lpfc_cmd->buf_lock);
  11560. continue;
  11561. }
  11562. /* issue ABTS for this IOCB based on iotag */
  11563. abtsiocbq = __lpfc_sli_get_iocbq(phba);
  11564. if (!abtsiocbq) {
  11565. if (phba->sli_rev == LPFC_SLI_REV4)
  11566. spin_unlock(&pring_s4->ring_lock);
  11567. spin_unlock(&lpfc_cmd->buf_lock);
  11568. continue;
  11569. }
  11570. if (phba->sli_rev == LPFC_SLI_REV4) {
  11571. iotag = abtsiocbq->iotag;
  11572. ulp_context = iocbq->sli4_xritag;
  11573. cqid = lpfc_cmd->hdwq->io_cq_map;
  11574. } else {
  11575. iotag = iocbq->iocb.ulpIoTag;
  11576. if (pring->ringno == LPFC_ELS_RING) {
  11577. ndlp = iocbq->ndlp;
  11578. ulp_context = ndlp->nlp_rpi;
  11579. } else {
  11580. ulp_context = iocbq->iocb.ulpContext;
  11581. }
  11582. }
  11583. ndlp = lpfc_cmd->rdata->pnode;
  11584. if (lpfc_is_link_up(phba) &&
  11585. (ndlp && ndlp->nlp_state == NLP_STE_MAPPED_NODE) &&
  11586. !(phba->link_flag & LS_EXTERNAL_LOOPBACK))
  11587. ia = false;
  11588. else
  11589. ia = true;
  11590. lpfc_sli_prep_abort_xri(phba, abtsiocbq, ulp_context, iotag,
  11591. iocbq->iocb.ulpClass, cqid,
  11592. ia, false);
  11593. abtsiocbq->vport = vport;
  11594. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  11595. abtsiocbq->hba_wqidx = iocbq->hba_wqidx;
  11596. if (iocbq->cmd_flag & LPFC_IO_FCP)
  11597. abtsiocbq->cmd_flag |= LPFC_USE_FCPWQIDX;
  11598. if (iocbq->cmd_flag & LPFC_IO_FOF)
  11599. abtsiocbq->cmd_flag |= LPFC_IO_FOF;
  11600. /* Setup callback routine and issue the command. */
  11601. abtsiocbq->cmd_cmpl = lpfc_sli_abort_fcp_cmpl;
  11602. /*
  11603. * Indicate the IO is being aborted by the driver and set
  11604. * the caller's flag into the aborted IO.
  11605. */
  11606. iocbq->cmd_flag |= LPFC_DRIVER_ABORTED;
  11607. if (phba->sli_rev == LPFC_SLI_REV4) {
  11608. ret_val = __lpfc_sli_issue_iocb(phba, pring_s4->ringno,
  11609. abtsiocbq, 0);
  11610. spin_unlock(&pring_s4->ring_lock);
  11611. } else {
  11612. ret_val = __lpfc_sli_issue_iocb(phba, pring->ringno,
  11613. abtsiocbq, 0);
  11614. }
  11615. spin_unlock(&lpfc_cmd->buf_lock);
  11616. if (ret_val == IOCB_ERROR)
  11617. __lpfc_sli_release_iocbq(phba, abtsiocbq);
  11618. else
  11619. sum++;
  11620. }
  11621. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11622. return sum;
  11623. }
  11624. /**
  11625. * lpfc_sli_wake_iocb_wait - lpfc_sli_issue_iocb_wait's completion handler
  11626. * @phba: Pointer to HBA context object.
  11627. * @cmdiocbq: Pointer to command iocb.
  11628. * @rspiocbq: Pointer to response iocb.
  11629. *
  11630. * This function is the completion handler for iocbs issued using
  11631. * lpfc_sli_issue_iocb_wait function. This function is called by the
  11632. * ring event handler function without any lock held. This function
  11633. * can be called from both worker thread context and interrupt
  11634. * context. This function also can be called from other thread which
  11635. * cleans up the SLI layer objects.
  11636. * This function copy the contents of the response iocb to the
  11637. * response iocb memory object provided by the caller of
  11638. * lpfc_sli_issue_iocb_wait and then wakes up the thread which
  11639. * sleeps for the iocb completion.
  11640. **/
  11641. static void
  11642. lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
  11643. struct lpfc_iocbq *cmdiocbq,
  11644. struct lpfc_iocbq *rspiocbq)
  11645. {
  11646. wait_queue_head_t *pdone_q;
  11647. unsigned long iflags;
  11648. struct lpfc_io_buf *lpfc_cmd;
  11649. size_t offset = offsetof(struct lpfc_iocbq, wqe);
  11650. spin_lock_irqsave(&phba->hbalock, iflags);
  11651. if (cmdiocbq->cmd_flag & LPFC_IO_WAKE_TMO) {
  11652. /*
  11653. * A time out has occurred for the iocb. If a time out
  11654. * completion handler has been supplied, call it. Otherwise,
  11655. * just free the iocbq.
  11656. */
  11657. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11658. cmdiocbq->cmd_cmpl = cmdiocbq->wait_cmd_cmpl;
  11659. cmdiocbq->wait_cmd_cmpl = NULL;
  11660. if (cmdiocbq->cmd_cmpl)
  11661. cmdiocbq->cmd_cmpl(phba, cmdiocbq, NULL);
  11662. else
  11663. lpfc_sli_release_iocbq(phba, cmdiocbq);
  11664. return;
  11665. }
  11666. /* Copy the contents of the local rspiocb into the caller's buffer. */
  11667. cmdiocbq->cmd_flag |= LPFC_IO_WAKE;
  11668. if (cmdiocbq->rsp_iocb && rspiocbq)
  11669. memcpy((char *)cmdiocbq->rsp_iocb + offset,
  11670. (char *)rspiocbq + offset, sizeof(*rspiocbq) - offset);
  11671. /* Set the exchange busy flag for task management commands */
  11672. if ((cmdiocbq->cmd_flag & LPFC_IO_FCP) &&
  11673. !(cmdiocbq->cmd_flag & LPFC_IO_LIBDFC)) {
  11674. lpfc_cmd = container_of(cmdiocbq, struct lpfc_io_buf,
  11675. cur_iocbq);
  11676. if (rspiocbq && (rspiocbq->cmd_flag & LPFC_EXCHANGE_BUSY))
  11677. lpfc_cmd->flags |= LPFC_SBUF_XBUSY;
  11678. else
  11679. lpfc_cmd->flags &= ~LPFC_SBUF_XBUSY;
  11680. }
  11681. pdone_q = cmdiocbq->context_un.wait_queue;
  11682. if (pdone_q)
  11683. wake_up(pdone_q);
  11684. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11685. return;
  11686. }
  11687. /**
  11688. * lpfc_chk_iocb_flg - Test IOCB flag with lock held.
  11689. * @phba: Pointer to HBA context object..
  11690. * @piocbq: Pointer to command iocb.
  11691. * @flag: Flag to test.
  11692. *
  11693. * This routine grabs the hbalock and then test the cmd_flag to
  11694. * see if the passed in flag is set.
  11695. * Returns:
  11696. * 1 if flag is set.
  11697. * 0 if flag is not set.
  11698. **/
  11699. static int
  11700. lpfc_chk_iocb_flg(struct lpfc_hba *phba,
  11701. struct lpfc_iocbq *piocbq, uint32_t flag)
  11702. {
  11703. unsigned long iflags;
  11704. int ret;
  11705. spin_lock_irqsave(&phba->hbalock, iflags);
  11706. ret = piocbq->cmd_flag & flag;
  11707. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11708. return ret;
  11709. }
  11710. /**
  11711. * lpfc_sli_issue_iocb_wait - Synchronous function to issue iocb commands
  11712. * @phba: Pointer to HBA context object..
  11713. * @ring_number: Ring number
  11714. * @piocb: Pointer to command iocb.
  11715. * @prspiocbq: Pointer to response iocb.
  11716. * @timeout: Timeout in number of seconds.
  11717. *
  11718. * This function issues the iocb to firmware and waits for the
  11719. * iocb to complete. The cmd_cmpl field of the shall be used
  11720. * to handle iocbs which time out. If the field is NULL, the
  11721. * function shall free the iocbq structure. If more clean up is
  11722. * needed, the caller is expected to provide a completion function
  11723. * that will provide the needed clean up. If the iocb command is
  11724. * not completed within timeout seconds, the function will either
  11725. * free the iocbq structure (if cmd_cmpl == NULL) or execute the
  11726. * completion function set in the cmd_cmpl field and then return
  11727. * a status of IOCB_TIMEDOUT. The caller should not free the iocb
  11728. * resources if this function returns IOCB_TIMEDOUT.
  11729. * The function waits for the iocb completion using an
  11730. * non-interruptible wait.
  11731. * This function will sleep while waiting for iocb completion.
  11732. * So, this function should not be called from any context which
  11733. * does not allow sleeping. Due to the same reason, this function
  11734. * cannot be called with interrupt disabled.
  11735. * This function assumes that the iocb completions occur while
  11736. * this function sleep. So, this function cannot be called from
  11737. * the thread which process iocb completion for this ring.
  11738. * This function clears the cmd_flag of the iocb object before
  11739. * issuing the iocb and the iocb completion handler sets this
  11740. * flag and wakes this thread when the iocb completes.
  11741. * The contents of the response iocb will be copied to prspiocbq
  11742. * by the completion handler when the command completes.
  11743. * This function returns IOCB_SUCCESS when success.
  11744. * This function is called with no lock held.
  11745. **/
  11746. int
  11747. lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
  11748. uint32_t ring_number,
  11749. struct lpfc_iocbq *piocb,
  11750. struct lpfc_iocbq *prspiocbq,
  11751. uint32_t timeout)
  11752. {
  11753. DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
  11754. long timeleft, timeout_req = 0;
  11755. int retval = IOCB_SUCCESS;
  11756. uint32_t creg_val;
  11757. struct lpfc_iocbq *iocb;
  11758. int txq_cnt = 0;
  11759. int txcmplq_cnt = 0;
  11760. struct lpfc_sli_ring *pring;
  11761. unsigned long iflags;
  11762. bool iocb_completed = true;
  11763. if (phba->sli_rev >= LPFC_SLI_REV4) {
  11764. lpfc_sli_prep_wqe(phba, piocb);
  11765. pring = lpfc_sli4_calc_ring(phba, piocb);
  11766. } else
  11767. pring = &phba->sli.sli3_ring[ring_number];
  11768. /*
  11769. * If the caller has provided a response iocbq buffer, then rsp_iocb
  11770. * is NULL or its an error.
  11771. */
  11772. if (prspiocbq) {
  11773. if (piocb->rsp_iocb)
  11774. return IOCB_ERROR;
  11775. piocb->rsp_iocb = prspiocbq;
  11776. }
  11777. piocb->wait_cmd_cmpl = piocb->cmd_cmpl;
  11778. piocb->cmd_cmpl = lpfc_sli_wake_iocb_wait;
  11779. piocb->context_un.wait_queue = &done_q;
  11780. piocb->cmd_flag &= ~(LPFC_IO_WAKE | LPFC_IO_WAKE_TMO);
  11781. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  11782. if (lpfc_readl(phba->HCregaddr, &creg_val))
  11783. return IOCB_ERROR;
  11784. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  11785. writel(creg_val, phba->HCregaddr);
  11786. readl(phba->HCregaddr); /* flush */
  11787. }
  11788. retval = lpfc_sli_issue_iocb(phba, ring_number, piocb,
  11789. SLI_IOCB_RET_IOCB);
  11790. if (retval == IOCB_SUCCESS) {
  11791. timeout_req = msecs_to_jiffies(timeout * 1000);
  11792. timeleft = wait_event_timeout(done_q,
  11793. lpfc_chk_iocb_flg(phba, piocb, LPFC_IO_WAKE),
  11794. timeout_req);
  11795. spin_lock_irqsave(&phba->hbalock, iflags);
  11796. if (!(piocb->cmd_flag & LPFC_IO_WAKE)) {
  11797. /*
  11798. * IOCB timed out. Inform the wake iocb wait
  11799. * completion function and set local status
  11800. */
  11801. iocb_completed = false;
  11802. piocb->cmd_flag |= LPFC_IO_WAKE_TMO;
  11803. }
  11804. spin_unlock_irqrestore(&phba->hbalock, iflags);
  11805. if (iocb_completed) {
  11806. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  11807. "0331 IOCB wake signaled\n");
  11808. /* Note: we are not indicating if the IOCB has a success
  11809. * status or not - that's for the caller to check.
  11810. * IOCB_SUCCESS means just that the command was sent and
  11811. * completed. Not that it completed successfully.
  11812. * */
  11813. } else if (timeleft == 0) {
  11814. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  11815. "0338 IOCB wait timeout error - no "
  11816. "wake response Data x%x\n", timeout);
  11817. retval = IOCB_TIMEDOUT;
  11818. } else {
  11819. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  11820. "0330 IOCB wake NOT set, "
  11821. "Data x%x x%lx\n",
  11822. timeout, (timeleft / jiffies));
  11823. retval = IOCB_TIMEDOUT;
  11824. }
  11825. } else if (retval == IOCB_BUSY) {
  11826. if (phba->cfg_log_verbose & LOG_SLI) {
  11827. list_for_each_entry(iocb, &pring->txq, list) {
  11828. txq_cnt++;
  11829. }
  11830. list_for_each_entry(iocb, &pring->txcmplq, list) {
  11831. txcmplq_cnt++;
  11832. }
  11833. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  11834. "2818 Max IOCBs %d txq cnt %d txcmplq cnt %d\n",
  11835. phba->iocb_cnt, txq_cnt, txcmplq_cnt);
  11836. }
  11837. return retval;
  11838. } else {
  11839. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  11840. "0332 IOCB wait issue failed, Data x%x\n",
  11841. retval);
  11842. retval = IOCB_ERROR;
  11843. }
  11844. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  11845. if (lpfc_readl(phba->HCregaddr, &creg_val))
  11846. return IOCB_ERROR;
  11847. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  11848. writel(creg_val, phba->HCregaddr);
  11849. readl(phba->HCregaddr); /* flush */
  11850. }
  11851. if (prspiocbq)
  11852. piocb->rsp_iocb = NULL;
  11853. piocb->context_un.wait_queue = NULL;
  11854. piocb->cmd_cmpl = NULL;
  11855. return retval;
  11856. }
  11857. /**
  11858. * lpfc_sli_issue_mbox_wait - Synchronous function to issue mailbox
  11859. * @phba: Pointer to HBA context object.
  11860. * @pmboxq: Pointer to driver mailbox object.
  11861. * @timeout: Timeout in number of seconds.
  11862. *
  11863. * This function issues the mailbox to firmware and waits for the
  11864. * mailbox command to complete. If the mailbox command is not
  11865. * completed within timeout seconds, it returns MBX_TIMEOUT.
  11866. * The function waits for the mailbox completion using an
  11867. * interruptible wait. If the thread is woken up due to a
  11868. * signal, MBX_TIMEOUT error is returned to the caller. Caller
  11869. * should not free the mailbox resources, if this function returns
  11870. * MBX_TIMEOUT.
  11871. * This function will sleep while waiting for mailbox completion.
  11872. * So, this function should not be called from any context which
  11873. * does not allow sleeping. Due to the same reason, this function
  11874. * cannot be called with interrupt disabled.
  11875. * This function assumes that the mailbox completion occurs while
  11876. * this function sleep. So, this function cannot be called from
  11877. * the worker thread which processes mailbox completion.
  11878. * This function is called in the context of HBA management
  11879. * applications.
  11880. * This function returns MBX_SUCCESS when successful.
  11881. * This function is called with no lock held.
  11882. **/
  11883. int
  11884. lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
  11885. uint32_t timeout)
  11886. {
  11887. struct completion mbox_done;
  11888. int retval;
  11889. unsigned long flag;
  11890. pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
  11891. /* setup wake call as IOCB callback */
  11892. pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
  11893. /* setup context3 field to pass wait_queue pointer to wake function */
  11894. init_completion(&mbox_done);
  11895. pmboxq->context3 = &mbox_done;
  11896. /* now issue the command */
  11897. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  11898. if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
  11899. wait_for_completion_timeout(&mbox_done,
  11900. msecs_to_jiffies(timeout * 1000));
  11901. spin_lock_irqsave(&phba->hbalock, flag);
  11902. pmboxq->context3 = NULL;
  11903. /*
  11904. * if LPFC_MBX_WAKE flag is set the mailbox is completed
  11905. * else do not free the resources.
  11906. */
  11907. if (pmboxq->mbox_flag & LPFC_MBX_WAKE) {
  11908. retval = MBX_SUCCESS;
  11909. } else {
  11910. retval = MBX_TIMEOUT;
  11911. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  11912. }
  11913. spin_unlock_irqrestore(&phba->hbalock, flag);
  11914. }
  11915. return retval;
  11916. }
  11917. /**
  11918. * lpfc_sli_mbox_sys_shutdown - shutdown mailbox command sub-system
  11919. * @phba: Pointer to HBA context.
  11920. * @mbx_action: Mailbox shutdown options.
  11921. *
  11922. * This function is called to shutdown the driver's mailbox sub-system.
  11923. * It first marks the mailbox sub-system is in a block state to prevent
  11924. * the asynchronous mailbox command from issued off the pending mailbox
  11925. * command queue. If the mailbox command sub-system shutdown is due to
  11926. * HBA error conditions such as EEH or ERATT, this routine shall invoke
  11927. * the mailbox sub-system flush routine to forcefully bring down the
  11928. * mailbox sub-system. Otherwise, if it is due to normal condition (such
  11929. * as with offline or HBA function reset), this routine will wait for the
  11930. * outstanding mailbox command to complete before invoking the mailbox
  11931. * sub-system flush routine to gracefully bring down mailbox sub-system.
  11932. **/
  11933. void
  11934. lpfc_sli_mbox_sys_shutdown(struct lpfc_hba *phba, int mbx_action)
  11935. {
  11936. struct lpfc_sli *psli = &phba->sli;
  11937. unsigned long timeout;
  11938. if (mbx_action == LPFC_MBX_NO_WAIT) {
  11939. /* delay 100ms for port state */
  11940. msleep(100);
  11941. lpfc_sli_mbox_sys_flush(phba);
  11942. return;
  11943. }
  11944. timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies;
  11945. /* Disable softirqs, including timers from obtaining phba->hbalock */
  11946. local_bh_disable();
  11947. spin_lock_irq(&phba->hbalock);
  11948. psli->sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
  11949. if (psli->sli_flag & LPFC_SLI_ACTIVE) {
  11950. /* Determine how long we might wait for the active mailbox
  11951. * command to be gracefully completed by firmware.
  11952. */
  11953. if (phba->sli.mbox_active)
  11954. timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
  11955. phba->sli.mbox_active) *
  11956. 1000) + jiffies;
  11957. spin_unlock_irq(&phba->hbalock);
  11958. /* Enable softirqs again, done with phba->hbalock */
  11959. local_bh_enable();
  11960. while (phba->sli.mbox_active) {
  11961. /* Check active mailbox complete status every 2ms */
  11962. msleep(2);
  11963. if (time_after(jiffies, timeout))
  11964. /* Timeout, let the mailbox flush routine to
  11965. * forcefully release active mailbox command
  11966. */
  11967. break;
  11968. }
  11969. } else {
  11970. spin_unlock_irq(&phba->hbalock);
  11971. /* Enable softirqs again, done with phba->hbalock */
  11972. local_bh_enable();
  11973. }
  11974. lpfc_sli_mbox_sys_flush(phba);
  11975. }
  11976. /**
  11977. * lpfc_sli_eratt_read - read sli-3 error attention events
  11978. * @phba: Pointer to HBA context.
  11979. *
  11980. * This function is called to read the SLI3 device error attention registers
  11981. * for possible error attention events. The caller must hold the hostlock
  11982. * with spin_lock_irq().
  11983. *
  11984. * This function returns 1 when there is Error Attention in the Host Attention
  11985. * Register and returns 0 otherwise.
  11986. **/
  11987. static int
  11988. lpfc_sli_eratt_read(struct lpfc_hba *phba)
  11989. {
  11990. uint32_t ha_copy;
  11991. /* Read chip Host Attention (HA) register */
  11992. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  11993. goto unplug_err;
  11994. if (ha_copy & HA_ERATT) {
  11995. /* Read host status register to retrieve error event */
  11996. if (lpfc_sli_read_hs(phba))
  11997. goto unplug_err;
  11998. /* Check if there is a deferred error condition is active */
  11999. if ((HS_FFER1 & phba->work_hs) &&
  12000. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  12001. HS_FFER6 | HS_FFER7 | HS_FFER8) & phba->work_hs)) {
  12002. phba->hba_flag |= DEFER_ERATT;
  12003. /* Clear all interrupt enable conditions */
  12004. writel(0, phba->HCregaddr);
  12005. readl(phba->HCregaddr);
  12006. }
  12007. /* Set the driver HA work bitmap */
  12008. phba->work_ha |= HA_ERATT;
  12009. /* Indicate polling handles this ERATT */
  12010. phba->hba_flag |= HBA_ERATT_HANDLED;
  12011. return 1;
  12012. }
  12013. return 0;
  12014. unplug_err:
  12015. /* Set the driver HS work bitmap */
  12016. phba->work_hs |= UNPLUG_ERR;
  12017. /* Set the driver HA work bitmap */
  12018. phba->work_ha |= HA_ERATT;
  12019. /* Indicate polling handles this ERATT */
  12020. phba->hba_flag |= HBA_ERATT_HANDLED;
  12021. return 1;
  12022. }
  12023. /**
  12024. * lpfc_sli4_eratt_read - read sli-4 error attention events
  12025. * @phba: Pointer to HBA context.
  12026. *
  12027. * This function is called to read the SLI4 device error attention registers
  12028. * for possible error attention events. The caller must hold the hostlock
  12029. * with spin_lock_irq().
  12030. *
  12031. * This function returns 1 when there is Error Attention in the Host Attention
  12032. * Register and returns 0 otherwise.
  12033. **/
  12034. static int
  12035. lpfc_sli4_eratt_read(struct lpfc_hba *phba)
  12036. {
  12037. uint32_t uerr_sta_hi, uerr_sta_lo;
  12038. uint32_t if_type, portsmphr;
  12039. struct lpfc_register portstat_reg;
  12040. u32 logmask;
  12041. /*
  12042. * For now, use the SLI4 device internal unrecoverable error
  12043. * registers for error attention. This can be changed later.
  12044. */
  12045. if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf);
  12046. switch (if_type) {
  12047. case LPFC_SLI_INTF_IF_TYPE_0:
  12048. if (lpfc_readl(phba->sli4_hba.u.if_type0.UERRLOregaddr,
  12049. &uerr_sta_lo) ||
  12050. lpfc_readl(phba->sli4_hba.u.if_type0.UERRHIregaddr,
  12051. &uerr_sta_hi)) {
  12052. phba->work_hs |= UNPLUG_ERR;
  12053. phba->work_ha |= HA_ERATT;
  12054. phba->hba_flag |= HBA_ERATT_HANDLED;
  12055. return 1;
  12056. }
  12057. if ((~phba->sli4_hba.ue_mask_lo & uerr_sta_lo) ||
  12058. (~phba->sli4_hba.ue_mask_hi & uerr_sta_hi)) {
  12059. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12060. "1423 HBA Unrecoverable error: "
  12061. "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
  12062. "ue_mask_lo_reg=0x%x, "
  12063. "ue_mask_hi_reg=0x%x\n",
  12064. uerr_sta_lo, uerr_sta_hi,
  12065. phba->sli4_hba.ue_mask_lo,
  12066. phba->sli4_hba.ue_mask_hi);
  12067. phba->work_status[0] = uerr_sta_lo;
  12068. phba->work_status[1] = uerr_sta_hi;
  12069. phba->work_ha |= HA_ERATT;
  12070. phba->hba_flag |= HBA_ERATT_HANDLED;
  12071. return 1;
  12072. }
  12073. break;
  12074. case LPFC_SLI_INTF_IF_TYPE_2:
  12075. case LPFC_SLI_INTF_IF_TYPE_6:
  12076. if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr,
  12077. &portstat_reg.word0) ||
  12078. lpfc_readl(phba->sli4_hba.PSMPHRregaddr,
  12079. &portsmphr)){
  12080. phba->work_hs |= UNPLUG_ERR;
  12081. phba->work_ha |= HA_ERATT;
  12082. phba->hba_flag |= HBA_ERATT_HANDLED;
  12083. return 1;
  12084. }
  12085. if (bf_get(lpfc_sliport_status_err, &portstat_reg)) {
  12086. phba->work_status[0] =
  12087. readl(phba->sli4_hba.u.if_type2.ERR1regaddr);
  12088. phba->work_status[1] =
  12089. readl(phba->sli4_hba.u.if_type2.ERR2regaddr);
  12090. logmask = LOG_TRACE_EVENT;
  12091. if (phba->work_status[0] ==
  12092. SLIPORT_ERR1_REG_ERR_CODE_2 &&
  12093. phba->work_status[1] == SLIPORT_ERR2_REG_FW_RESTART)
  12094. logmask = LOG_SLI;
  12095. lpfc_printf_log(phba, KERN_ERR, logmask,
  12096. "2885 Port Status Event: "
  12097. "port status reg 0x%x, "
  12098. "port smphr reg 0x%x, "
  12099. "error 1=0x%x, error 2=0x%x\n",
  12100. portstat_reg.word0,
  12101. portsmphr,
  12102. phba->work_status[0],
  12103. phba->work_status[1]);
  12104. phba->work_ha |= HA_ERATT;
  12105. phba->hba_flag |= HBA_ERATT_HANDLED;
  12106. return 1;
  12107. }
  12108. break;
  12109. case LPFC_SLI_INTF_IF_TYPE_1:
  12110. default:
  12111. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12112. "2886 HBA Error Attention on unsupported "
  12113. "if type %d.", if_type);
  12114. return 1;
  12115. }
  12116. return 0;
  12117. }
  12118. /**
  12119. * lpfc_sli_check_eratt - check error attention events
  12120. * @phba: Pointer to HBA context.
  12121. *
  12122. * This function is called from timer soft interrupt context to check HBA's
  12123. * error attention register bit for error attention events.
  12124. *
  12125. * This function returns 1 when there is Error Attention in the Host Attention
  12126. * Register and returns 0 otherwise.
  12127. **/
  12128. int
  12129. lpfc_sli_check_eratt(struct lpfc_hba *phba)
  12130. {
  12131. uint32_t ha_copy;
  12132. /* If somebody is waiting to handle an eratt, don't process it
  12133. * here. The brdkill function will do this.
  12134. */
  12135. if (phba->link_flag & LS_IGNORE_ERATT)
  12136. return 0;
  12137. /* Check if interrupt handler handles this ERATT */
  12138. spin_lock_irq(&phba->hbalock);
  12139. if (phba->hba_flag & HBA_ERATT_HANDLED) {
  12140. /* Interrupt handler has handled ERATT */
  12141. spin_unlock_irq(&phba->hbalock);
  12142. return 0;
  12143. }
  12144. /*
  12145. * If there is deferred error attention, do not check for error
  12146. * attention
  12147. */
  12148. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  12149. spin_unlock_irq(&phba->hbalock);
  12150. return 0;
  12151. }
  12152. /* If PCI channel is offline, don't process it */
  12153. if (unlikely(pci_channel_offline(phba->pcidev))) {
  12154. spin_unlock_irq(&phba->hbalock);
  12155. return 0;
  12156. }
  12157. switch (phba->sli_rev) {
  12158. case LPFC_SLI_REV2:
  12159. case LPFC_SLI_REV3:
  12160. /* Read chip Host Attention (HA) register */
  12161. ha_copy = lpfc_sli_eratt_read(phba);
  12162. break;
  12163. case LPFC_SLI_REV4:
  12164. /* Read device Uncoverable Error (UERR) registers */
  12165. ha_copy = lpfc_sli4_eratt_read(phba);
  12166. break;
  12167. default:
  12168. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12169. "0299 Invalid SLI revision (%d)\n",
  12170. phba->sli_rev);
  12171. ha_copy = 0;
  12172. break;
  12173. }
  12174. spin_unlock_irq(&phba->hbalock);
  12175. return ha_copy;
  12176. }
  12177. /**
  12178. * lpfc_intr_state_check - Check device state for interrupt handling
  12179. * @phba: Pointer to HBA context.
  12180. *
  12181. * This inline routine checks whether a device or its PCI slot is in a state
  12182. * that the interrupt should be handled.
  12183. *
  12184. * This function returns 0 if the device or the PCI slot is in a state that
  12185. * interrupt should be handled, otherwise -EIO.
  12186. */
  12187. static inline int
  12188. lpfc_intr_state_check(struct lpfc_hba *phba)
  12189. {
  12190. /* If the pci channel is offline, ignore all the interrupts */
  12191. if (unlikely(pci_channel_offline(phba->pcidev)))
  12192. return -EIO;
  12193. /* Update device level interrupt statistics */
  12194. phba->sli.slistat.sli_intr++;
  12195. /* Ignore all interrupts during initialization. */
  12196. if (unlikely(phba->link_state < LPFC_LINK_DOWN))
  12197. return -EIO;
  12198. return 0;
  12199. }
  12200. /**
  12201. * lpfc_sli_sp_intr_handler - Slow-path interrupt handler to SLI-3 device
  12202. * @irq: Interrupt number.
  12203. * @dev_id: The device context pointer.
  12204. *
  12205. * This function is directly called from the PCI layer as an interrupt
  12206. * service routine when device with SLI-3 interface spec is enabled with
  12207. * MSI-X multi-message interrupt mode and there are slow-path events in
  12208. * the HBA. However, when the device is enabled with either MSI or Pin-IRQ
  12209. * interrupt mode, this function is called as part of the device-level
  12210. * interrupt handler. When the PCI slot is in error recovery or the HBA
  12211. * is undergoing initialization, the interrupt handler will not process
  12212. * the interrupt. The link attention and ELS ring attention events are
  12213. * handled by the worker thread. The interrupt handler signals the worker
  12214. * thread and returns for these events. This function is called without
  12215. * any lock held. It gets the hbalock to access and update SLI data
  12216. * structures.
  12217. *
  12218. * This function returns IRQ_HANDLED when interrupt is handled else it
  12219. * returns IRQ_NONE.
  12220. **/
  12221. irqreturn_t
  12222. lpfc_sli_sp_intr_handler(int irq, void *dev_id)
  12223. {
  12224. struct lpfc_hba *phba;
  12225. uint32_t ha_copy, hc_copy;
  12226. uint32_t work_ha_copy;
  12227. unsigned long status;
  12228. unsigned long iflag;
  12229. uint32_t control;
  12230. MAILBOX_t *mbox, *pmbox;
  12231. struct lpfc_vport *vport;
  12232. struct lpfc_nodelist *ndlp;
  12233. struct lpfc_dmabuf *mp;
  12234. LPFC_MBOXQ_t *pmb;
  12235. int rc;
  12236. /*
  12237. * Get the driver's phba structure from the dev_id and
  12238. * assume the HBA is not interrupting.
  12239. */
  12240. phba = (struct lpfc_hba *)dev_id;
  12241. if (unlikely(!phba))
  12242. return IRQ_NONE;
  12243. /*
  12244. * Stuff needs to be attented to when this function is invoked as an
  12245. * individual interrupt handler in MSI-X multi-message interrupt mode
  12246. */
  12247. if (phba->intr_type == MSIX) {
  12248. /* Check device state for handling interrupt */
  12249. if (lpfc_intr_state_check(phba))
  12250. return IRQ_NONE;
  12251. /* Need to read HA REG for slow-path events */
  12252. spin_lock_irqsave(&phba->hbalock, iflag);
  12253. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  12254. goto unplug_error;
  12255. /* If somebody is waiting to handle an eratt don't process it
  12256. * here. The brdkill function will do this.
  12257. */
  12258. if (phba->link_flag & LS_IGNORE_ERATT)
  12259. ha_copy &= ~HA_ERATT;
  12260. /* Check the need for handling ERATT in interrupt handler */
  12261. if (ha_copy & HA_ERATT) {
  12262. if (phba->hba_flag & HBA_ERATT_HANDLED)
  12263. /* ERATT polling has handled ERATT */
  12264. ha_copy &= ~HA_ERATT;
  12265. else
  12266. /* Indicate interrupt handler handles ERATT */
  12267. phba->hba_flag |= HBA_ERATT_HANDLED;
  12268. }
  12269. /*
  12270. * If there is deferred error attention, do not check for any
  12271. * interrupt.
  12272. */
  12273. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  12274. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12275. return IRQ_NONE;
  12276. }
  12277. /* Clear up only attention source related to slow-path */
  12278. if (lpfc_readl(phba->HCregaddr, &hc_copy))
  12279. goto unplug_error;
  12280. writel(hc_copy & ~(HC_MBINT_ENA | HC_R2INT_ENA |
  12281. HC_LAINT_ENA | HC_ERINT_ENA),
  12282. phba->HCregaddr);
  12283. writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
  12284. phba->HAregaddr);
  12285. writel(hc_copy, phba->HCregaddr);
  12286. readl(phba->HAregaddr); /* flush */
  12287. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12288. } else
  12289. ha_copy = phba->ha_copy;
  12290. work_ha_copy = ha_copy & phba->work_ha_mask;
  12291. if (work_ha_copy) {
  12292. if (work_ha_copy & HA_LATT) {
  12293. if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
  12294. /*
  12295. * Turn off Link Attention interrupts
  12296. * until CLEAR_LA done
  12297. */
  12298. spin_lock_irqsave(&phba->hbalock, iflag);
  12299. phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
  12300. if (lpfc_readl(phba->HCregaddr, &control))
  12301. goto unplug_error;
  12302. control &= ~HC_LAINT_ENA;
  12303. writel(control, phba->HCregaddr);
  12304. readl(phba->HCregaddr); /* flush */
  12305. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12306. }
  12307. else
  12308. work_ha_copy &= ~HA_LATT;
  12309. }
  12310. if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
  12311. /*
  12312. * Turn off Slow Rings interrupts, LPFC_ELS_RING is
  12313. * the only slow ring.
  12314. */
  12315. status = (work_ha_copy &
  12316. (HA_RXMASK << (4*LPFC_ELS_RING)));
  12317. status >>= (4*LPFC_ELS_RING);
  12318. if (status & HA_RXMASK) {
  12319. spin_lock_irqsave(&phba->hbalock, iflag);
  12320. if (lpfc_readl(phba->HCregaddr, &control))
  12321. goto unplug_error;
  12322. lpfc_debugfs_slow_ring_trc(phba,
  12323. "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
  12324. control, status,
  12325. (uint32_t)phba->sli.slistat.sli_intr);
  12326. if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
  12327. lpfc_debugfs_slow_ring_trc(phba,
  12328. "ISR Disable ring:"
  12329. "pwork:x%x hawork:x%x wait:x%x",
  12330. phba->work_ha, work_ha_copy,
  12331. (uint32_t)((unsigned long)
  12332. &phba->work_waitq));
  12333. control &=
  12334. ~(HC_R0INT_ENA << LPFC_ELS_RING);
  12335. writel(control, phba->HCregaddr);
  12336. readl(phba->HCregaddr); /* flush */
  12337. }
  12338. else {
  12339. lpfc_debugfs_slow_ring_trc(phba,
  12340. "ISR slow ring: pwork:"
  12341. "x%x hawork:x%x wait:x%x",
  12342. phba->work_ha, work_ha_copy,
  12343. (uint32_t)((unsigned long)
  12344. &phba->work_waitq));
  12345. }
  12346. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12347. }
  12348. }
  12349. spin_lock_irqsave(&phba->hbalock, iflag);
  12350. if (work_ha_copy & HA_ERATT) {
  12351. if (lpfc_sli_read_hs(phba))
  12352. goto unplug_error;
  12353. /*
  12354. * Check if there is a deferred error condition
  12355. * is active
  12356. */
  12357. if ((HS_FFER1 & phba->work_hs) &&
  12358. ((HS_FFER2 | HS_FFER3 | HS_FFER4 | HS_FFER5 |
  12359. HS_FFER6 | HS_FFER7 | HS_FFER8) &
  12360. phba->work_hs)) {
  12361. phba->hba_flag |= DEFER_ERATT;
  12362. /* Clear all interrupt enable conditions */
  12363. writel(0, phba->HCregaddr);
  12364. readl(phba->HCregaddr);
  12365. }
  12366. }
  12367. if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
  12368. pmb = phba->sli.mbox_active;
  12369. pmbox = &pmb->u.mb;
  12370. mbox = phba->mbox;
  12371. vport = pmb->vport;
  12372. /* First check out the status word */
  12373. lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
  12374. if (pmbox->mbxOwner != OWN_HOST) {
  12375. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12376. /*
  12377. * Stray Mailbox Interrupt, mbxCommand <cmd>
  12378. * mbxStatus <status>
  12379. */
  12380. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12381. "(%d):0304 Stray Mailbox "
  12382. "Interrupt mbxCommand x%x "
  12383. "mbxStatus x%x\n",
  12384. (vport ? vport->vpi : 0),
  12385. pmbox->mbxCommand,
  12386. pmbox->mbxStatus);
  12387. /* clear mailbox attention bit */
  12388. work_ha_copy &= ~HA_MBATT;
  12389. } else {
  12390. phba->sli.mbox_active = NULL;
  12391. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12392. phba->last_completion_time = jiffies;
  12393. del_timer(&phba->sli.mbox_tmo);
  12394. if (pmb->mbox_cmpl) {
  12395. lpfc_sli_pcimem_bcopy(mbox, pmbox,
  12396. MAILBOX_CMD_SIZE);
  12397. if (pmb->out_ext_byte_len &&
  12398. pmb->ctx_buf)
  12399. lpfc_sli_pcimem_bcopy(
  12400. phba->mbox_ext,
  12401. pmb->ctx_buf,
  12402. pmb->out_ext_byte_len);
  12403. }
  12404. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  12405. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  12406. lpfc_debugfs_disc_trc(vport,
  12407. LPFC_DISC_TRC_MBOX_VPORT,
  12408. "MBOX dflt rpi: : "
  12409. "status:x%x rpi:x%x",
  12410. (uint32_t)pmbox->mbxStatus,
  12411. pmbox->un.varWords[0], 0);
  12412. if (!pmbox->mbxStatus) {
  12413. mp = (struct lpfc_dmabuf *)
  12414. (pmb->ctx_buf);
  12415. ndlp = (struct lpfc_nodelist *)
  12416. pmb->ctx_ndlp;
  12417. /* Reg_LOGIN of dflt RPI was
  12418. * successful. new lets get
  12419. * rid of the RPI using the
  12420. * same mbox buffer.
  12421. */
  12422. lpfc_unreg_login(phba,
  12423. vport->vpi,
  12424. pmbox->un.varWords[0],
  12425. pmb);
  12426. pmb->mbox_cmpl =
  12427. lpfc_mbx_cmpl_dflt_rpi;
  12428. pmb->ctx_buf = mp;
  12429. pmb->ctx_ndlp = ndlp;
  12430. pmb->vport = vport;
  12431. rc = lpfc_sli_issue_mbox(phba,
  12432. pmb,
  12433. MBX_NOWAIT);
  12434. if (rc != MBX_BUSY)
  12435. lpfc_printf_log(phba,
  12436. KERN_ERR,
  12437. LOG_TRACE_EVENT,
  12438. "0350 rc should have"
  12439. "been MBX_BUSY\n");
  12440. if (rc != MBX_NOT_FINISHED)
  12441. goto send_current_mbox;
  12442. }
  12443. }
  12444. spin_lock_irqsave(
  12445. &phba->pport->work_port_lock,
  12446. iflag);
  12447. phba->pport->work_port_events &=
  12448. ~WORKER_MBOX_TMO;
  12449. spin_unlock_irqrestore(
  12450. &phba->pport->work_port_lock,
  12451. iflag);
  12452. /* Do NOT queue MBX_HEARTBEAT to the worker
  12453. * thread for processing.
  12454. */
  12455. if (pmbox->mbxCommand == MBX_HEARTBEAT) {
  12456. /* Process mbox now */
  12457. phba->sli.mbox_active = NULL;
  12458. phba->sli.sli_flag &=
  12459. ~LPFC_SLI_MBOX_ACTIVE;
  12460. if (pmb->mbox_cmpl)
  12461. pmb->mbox_cmpl(phba, pmb);
  12462. } else {
  12463. /* Queue to worker thread to process */
  12464. lpfc_mbox_cmpl_put(phba, pmb);
  12465. }
  12466. }
  12467. } else
  12468. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12469. if ((work_ha_copy & HA_MBATT) &&
  12470. (phba->sli.mbox_active == NULL)) {
  12471. send_current_mbox:
  12472. /* Process next mailbox command if there is one */
  12473. do {
  12474. rc = lpfc_sli_issue_mbox(phba, NULL,
  12475. MBX_NOWAIT);
  12476. } while (rc == MBX_NOT_FINISHED);
  12477. if (rc != MBX_SUCCESS)
  12478. lpfc_printf_log(phba, KERN_ERR,
  12479. LOG_TRACE_EVENT,
  12480. "0349 rc should be "
  12481. "MBX_SUCCESS\n");
  12482. }
  12483. spin_lock_irqsave(&phba->hbalock, iflag);
  12484. phba->work_ha |= work_ha_copy;
  12485. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12486. lpfc_worker_wake_up(phba);
  12487. }
  12488. return IRQ_HANDLED;
  12489. unplug_error:
  12490. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12491. return IRQ_HANDLED;
  12492. } /* lpfc_sli_sp_intr_handler */
  12493. /**
  12494. * lpfc_sli_fp_intr_handler - Fast-path interrupt handler to SLI-3 device.
  12495. * @irq: Interrupt number.
  12496. * @dev_id: The device context pointer.
  12497. *
  12498. * This function is directly called from the PCI layer as an interrupt
  12499. * service routine when device with SLI-3 interface spec is enabled with
  12500. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  12501. * ring event in the HBA. However, when the device is enabled with either
  12502. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  12503. * device-level interrupt handler. When the PCI slot is in error recovery
  12504. * or the HBA is undergoing initialization, the interrupt handler will not
  12505. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  12506. * the intrrupt context. This function is called without any lock held.
  12507. * It gets the hbalock to access and update SLI data structures.
  12508. *
  12509. * This function returns IRQ_HANDLED when interrupt is handled else it
  12510. * returns IRQ_NONE.
  12511. **/
  12512. irqreturn_t
  12513. lpfc_sli_fp_intr_handler(int irq, void *dev_id)
  12514. {
  12515. struct lpfc_hba *phba;
  12516. uint32_t ha_copy;
  12517. unsigned long status;
  12518. unsigned long iflag;
  12519. struct lpfc_sli_ring *pring;
  12520. /* Get the driver's phba structure from the dev_id and
  12521. * assume the HBA is not interrupting.
  12522. */
  12523. phba = (struct lpfc_hba *) dev_id;
  12524. if (unlikely(!phba))
  12525. return IRQ_NONE;
  12526. /*
  12527. * Stuff needs to be attented to when this function is invoked as an
  12528. * individual interrupt handler in MSI-X multi-message interrupt mode
  12529. */
  12530. if (phba->intr_type == MSIX) {
  12531. /* Check device state for handling interrupt */
  12532. if (lpfc_intr_state_check(phba))
  12533. return IRQ_NONE;
  12534. /* Need to read HA REG for FCP ring and other ring events */
  12535. if (lpfc_readl(phba->HAregaddr, &ha_copy))
  12536. return IRQ_HANDLED;
  12537. /* Clear up only attention source related to fast-path */
  12538. spin_lock_irqsave(&phba->hbalock, iflag);
  12539. /*
  12540. * If there is deferred error attention, do not check for
  12541. * any interrupt.
  12542. */
  12543. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  12544. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12545. return IRQ_NONE;
  12546. }
  12547. writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
  12548. phba->HAregaddr);
  12549. readl(phba->HAregaddr); /* flush */
  12550. spin_unlock_irqrestore(&phba->hbalock, iflag);
  12551. } else
  12552. ha_copy = phba->ha_copy;
  12553. /*
  12554. * Process all events on FCP ring. Take the optimized path for FCP IO.
  12555. */
  12556. ha_copy &= ~(phba->work_ha_mask);
  12557. status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  12558. status >>= (4*LPFC_FCP_RING);
  12559. pring = &phba->sli.sli3_ring[LPFC_FCP_RING];
  12560. if (status & HA_RXMASK)
  12561. lpfc_sli_handle_fast_ring_event(phba, pring, status);
  12562. if (phba->cfg_multi_ring_support == 2) {
  12563. /*
  12564. * Process all events on extra ring. Take the optimized path
  12565. * for extra ring IO.
  12566. */
  12567. status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  12568. status >>= (4*LPFC_EXTRA_RING);
  12569. if (status & HA_RXMASK) {
  12570. lpfc_sli_handle_fast_ring_event(phba,
  12571. &phba->sli.sli3_ring[LPFC_EXTRA_RING],
  12572. status);
  12573. }
  12574. }
  12575. return IRQ_HANDLED;
  12576. } /* lpfc_sli_fp_intr_handler */
  12577. /**
  12578. * lpfc_sli_intr_handler - Device-level interrupt handler to SLI-3 device
  12579. * @irq: Interrupt number.
  12580. * @dev_id: The device context pointer.
  12581. *
  12582. * This function is the HBA device-level interrupt handler to device with
  12583. * SLI-3 interface spec, called from the PCI layer when either MSI or
  12584. * Pin-IRQ interrupt mode is enabled and there is an event in the HBA which
  12585. * requires driver attention. This function invokes the slow-path interrupt
  12586. * attention handling function and fast-path interrupt attention handling
  12587. * function in turn to process the relevant HBA attention events. This
  12588. * function is called without any lock held. It gets the hbalock to access
  12589. * and update SLI data structures.
  12590. *
  12591. * This function returns IRQ_HANDLED when interrupt is handled, else it
  12592. * returns IRQ_NONE.
  12593. **/
  12594. irqreturn_t
  12595. lpfc_sli_intr_handler(int irq, void *dev_id)
  12596. {
  12597. struct lpfc_hba *phba;
  12598. irqreturn_t sp_irq_rc, fp_irq_rc;
  12599. unsigned long status1, status2;
  12600. uint32_t hc_copy;
  12601. /*
  12602. * Get the driver's phba structure from the dev_id and
  12603. * assume the HBA is not interrupting.
  12604. */
  12605. phba = (struct lpfc_hba *) dev_id;
  12606. if (unlikely(!phba))
  12607. return IRQ_NONE;
  12608. /* Check device state for handling interrupt */
  12609. if (lpfc_intr_state_check(phba))
  12610. return IRQ_NONE;
  12611. spin_lock(&phba->hbalock);
  12612. if (lpfc_readl(phba->HAregaddr, &phba->ha_copy)) {
  12613. spin_unlock(&phba->hbalock);
  12614. return IRQ_HANDLED;
  12615. }
  12616. if (unlikely(!phba->ha_copy)) {
  12617. spin_unlock(&phba->hbalock);
  12618. return IRQ_NONE;
  12619. } else if (phba->ha_copy & HA_ERATT) {
  12620. if (phba->hba_flag & HBA_ERATT_HANDLED)
  12621. /* ERATT polling has handled ERATT */
  12622. phba->ha_copy &= ~HA_ERATT;
  12623. else
  12624. /* Indicate interrupt handler handles ERATT */
  12625. phba->hba_flag |= HBA_ERATT_HANDLED;
  12626. }
  12627. /*
  12628. * If there is deferred error attention, do not check for any interrupt.
  12629. */
  12630. if (unlikely(phba->hba_flag & DEFER_ERATT)) {
  12631. spin_unlock(&phba->hbalock);
  12632. return IRQ_NONE;
  12633. }
  12634. /* Clear attention sources except link and error attentions */
  12635. if (lpfc_readl(phba->HCregaddr, &hc_copy)) {
  12636. spin_unlock(&phba->hbalock);
  12637. return IRQ_HANDLED;
  12638. }
  12639. writel(hc_copy & ~(HC_MBINT_ENA | HC_R0INT_ENA | HC_R1INT_ENA
  12640. | HC_R2INT_ENA | HC_LAINT_ENA | HC_ERINT_ENA),
  12641. phba->HCregaddr);
  12642. writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
  12643. writel(hc_copy, phba->HCregaddr);
  12644. readl(phba->HAregaddr); /* flush */
  12645. spin_unlock(&phba->hbalock);
  12646. /*
  12647. * Invokes slow-path host attention interrupt handling as appropriate.
  12648. */
  12649. /* status of events with mailbox and link attention */
  12650. status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
  12651. /* status of events with ELS ring */
  12652. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
  12653. status2 >>= (4*LPFC_ELS_RING);
  12654. if (status1 || (status2 & HA_RXMASK))
  12655. sp_irq_rc = lpfc_sli_sp_intr_handler(irq, dev_id);
  12656. else
  12657. sp_irq_rc = IRQ_NONE;
  12658. /*
  12659. * Invoke fast-path host attention interrupt handling as appropriate.
  12660. */
  12661. /* status of events with FCP ring */
  12662. status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
  12663. status1 >>= (4*LPFC_FCP_RING);
  12664. /* status of events with extra ring */
  12665. if (phba->cfg_multi_ring_support == 2) {
  12666. status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
  12667. status2 >>= (4*LPFC_EXTRA_RING);
  12668. } else
  12669. status2 = 0;
  12670. if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
  12671. fp_irq_rc = lpfc_sli_fp_intr_handler(irq, dev_id);
  12672. else
  12673. fp_irq_rc = IRQ_NONE;
  12674. /* Return device-level interrupt handling status */
  12675. return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
  12676. } /* lpfc_sli_intr_handler */
  12677. /**
  12678. * lpfc_sli4_els_xri_abort_event_proc - Process els xri abort event
  12679. * @phba: pointer to lpfc hba data structure.
  12680. *
  12681. * This routine is invoked by the worker thread to process all the pending
  12682. * SLI4 els abort xri events.
  12683. **/
  12684. void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *phba)
  12685. {
  12686. struct lpfc_cq_event *cq_event;
  12687. unsigned long iflags;
  12688. /* First, declare the els xri abort event has been handled */
  12689. spin_lock_irqsave(&phba->hbalock, iflags);
  12690. phba->hba_flag &= ~ELS_XRI_ABORT_EVENT;
  12691. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12692. /* Now, handle all the els xri abort events */
  12693. spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
  12694. while (!list_empty(&phba->sli4_hba.sp_els_xri_aborted_work_queue)) {
  12695. /* Get the first event from the head of the event queue */
  12696. list_remove_head(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
  12697. cq_event, struct lpfc_cq_event, list);
  12698. spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
  12699. iflags);
  12700. /* Notify aborted XRI for ELS work queue */
  12701. lpfc_sli4_els_xri_aborted(phba, &cq_event->cqe.wcqe_axri);
  12702. /* Free the event processed back to the free pool */
  12703. lpfc_sli4_cq_event_release(phba, cq_event);
  12704. spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
  12705. iflags);
  12706. }
  12707. spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock, iflags);
  12708. }
  12709. /**
  12710. * lpfc_sli4_els_preprocess_rspiocbq - Get response iocbq from els wcqe
  12711. * @phba: Pointer to HBA context object.
  12712. * @irspiocbq: Pointer to work-queue completion queue entry.
  12713. *
  12714. * This routine handles an ELS work-queue completion event and construct
  12715. * a pseudo response ELS IOCBQ from the SLI4 ELS WCQE for the common
  12716. * discovery engine to handle.
  12717. *
  12718. * Return: Pointer to the receive IOCBQ, NULL otherwise.
  12719. **/
  12720. static struct lpfc_iocbq *
  12721. lpfc_sli4_els_preprocess_rspiocbq(struct lpfc_hba *phba,
  12722. struct lpfc_iocbq *irspiocbq)
  12723. {
  12724. struct lpfc_sli_ring *pring;
  12725. struct lpfc_iocbq *cmdiocbq;
  12726. struct lpfc_wcqe_complete *wcqe;
  12727. unsigned long iflags;
  12728. pring = lpfc_phba_elsring(phba);
  12729. if (unlikely(!pring))
  12730. return NULL;
  12731. wcqe = &irspiocbq->cq_event.cqe.wcqe_cmpl;
  12732. spin_lock_irqsave(&pring->ring_lock, iflags);
  12733. pring->stats.iocb_event++;
  12734. /* Look up the ELS command IOCB and create pseudo response IOCB */
  12735. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  12736. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  12737. if (unlikely(!cmdiocbq)) {
  12738. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  12739. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  12740. "0386 ELS complete with no corresponding "
  12741. "cmdiocb: 0x%x 0x%x 0x%x 0x%x\n",
  12742. wcqe->word0, wcqe->total_data_placed,
  12743. wcqe->parameter, wcqe->word3);
  12744. lpfc_sli_release_iocbq(phba, irspiocbq);
  12745. return NULL;
  12746. }
  12747. memcpy(&irspiocbq->wqe, &cmdiocbq->wqe, sizeof(union lpfc_wqe128));
  12748. memcpy(&irspiocbq->wcqe_cmpl, wcqe, sizeof(*wcqe));
  12749. /* Put the iocb back on the txcmplq */
  12750. lpfc_sli_ringtxcmpl_put(phba, pring, cmdiocbq);
  12751. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  12752. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  12753. spin_lock_irqsave(&phba->hbalock, iflags);
  12754. irspiocbq->cmd_flag |= LPFC_EXCHANGE_BUSY;
  12755. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12756. }
  12757. return irspiocbq;
  12758. }
  12759. inline struct lpfc_cq_event *
  12760. lpfc_cq_event_setup(struct lpfc_hba *phba, void *entry, int size)
  12761. {
  12762. struct lpfc_cq_event *cq_event;
  12763. /* Allocate a new internal CQ_EVENT entry */
  12764. cq_event = lpfc_sli4_cq_event_alloc(phba);
  12765. if (!cq_event) {
  12766. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12767. "0602 Failed to alloc CQ_EVENT entry\n");
  12768. return NULL;
  12769. }
  12770. /* Move the CQE into the event */
  12771. memcpy(&cq_event->cqe, entry, size);
  12772. return cq_event;
  12773. }
  12774. /**
  12775. * lpfc_sli4_sp_handle_async_event - Handle an asynchronous event
  12776. * @phba: Pointer to HBA context object.
  12777. * @mcqe: Pointer to mailbox completion queue entry.
  12778. *
  12779. * This routine process a mailbox completion queue entry with asynchronous
  12780. * event.
  12781. *
  12782. * Return: true if work posted to worker thread, otherwise false.
  12783. **/
  12784. static bool
  12785. lpfc_sli4_sp_handle_async_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  12786. {
  12787. struct lpfc_cq_event *cq_event;
  12788. unsigned long iflags;
  12789. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  12790. "0392 Async Event: word0:x%x, word1:x%x, "
  12791. "word2:x%x, word3:x%x\n", mcqe->word0,
  12792. mcqe->mcqe_tag0, mcqe->mcqe_tag1, mcqe->trailer);
  12793. cq_event = lpfc_cq_event_setup(phba, mcqe, sizeof(struct lpfc_mcqe));
  12794. if (!cq_event)
  12795. return false;
  12796. spin_lock_irqsave(&phba->sli4_hba.asynce_list_lock, iflags);
  12797. list_add_tail(&cq_event->list, &phba->sli4_hba.sp_asynce_work_queue);
  12798. spin_unlock_irqrestore(&phba->sli4_hba.asynce_list_lock, iflags);
  12799. /* Set the async event flag */
  12800. spin_lock_irqsave(&phba->hbalock, iflags);
  12801. phba->hba_flag |= ASYNC_EVENT;
  12802. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12803. return true;
  12804. }
  12805. /**
  12806. * lpfc_sli4_sp_handle_mbox_event - Handle a mailbox completion event
  12807. * @phba: Pointer to HBA context object.
  12808. * @mcqe: Pointer to mailbox completion queue entry.
  12809. *
  12810. * This routine process a mailbox completion queue entry with mailbox
  12811. * completion event.
  12812. *
  12813. * Return: true if work posted to worker thread, otherwise false.
  12814. **/
  12815. static bool
  12816. lpfc_sli4_sp_handle_mbox_event(struct lpfc_hba *phba, struct lpfc_mcqe *mcqe)
  12817. {
  12818. uint32_t mcqe_status;
  12819. MAILBOX_t *mbox, *pmbox;
  12820. struct lpfc_mqe *mqe;
  12821. struct lpfc_vport *vport;
  12822. struct lpfc_nodelist *ndlp;
  12823. struct lpfc_dmabuf *mp;
  12824. unsigned long iflags;
  12825. LPFC_MBOXQ_t *pmb;
  12826. bool workposted = false;
  12827. int rc;
  12828. /* If not a mailbox complete MCQE, out by checking mailbox consume */
  12829. if (!bf_get(lpfc_trailer_completed, mcqe))
  12830. goto out_no_mqe_complete;
  12831. /* Get the reference to the active mbox command */
  12832. spin_lock_irqsave(&phba->hbalock, iflags);
  12833. pmb = phba->sli.mbox_active;
  12834. if (unlikely(!pmb)) {
  12835. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  12836. "1832 No pending MBOX command to handle\n");
  12837. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12838. goto out_no_mqe_complete;
  12839. }
  12840. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12841. mqe = &pmb->u.mqe;
  12842. pmbox = (MAILBOX_t *)&pmb->u.mqe;
  12843. mbox = phba->mbox;
  12844. vport = pmb->vport;
  12845. /* Reset heartbeat timer */
  12846. phba->last_completion_time = jiffies;
  12847. del_timer(&phba->sli.mbox_tmo);
  12848. /* Move mbox data to caller's mailbox region, do endian swapping */
  12849. if (pmb->mbox_cmpl && mbox)
  12850. lpfc_sli4_pcimem_bcopy(mbox, mqe, sizeof(struct lpfc_mqe));
  12851. /*
  12852. * For mcqe errors, conditionally move a modified error code to
  12853. * the mbox so that the error will not be missed.
  12854. */
  12855. mcqe_status = bf_get(lpfc_mcqe_status, mcqe);
  12856. if (mcqe_status != MB_CQE_STATUS_SUCCESS) {
  12857. if (bf_get(lpfc_mqe_status, mqe) == MBX_SUCCESS)
  12858. bf_set(lpfc_mqe_status, mqe,
  12859. (LPFC_MBX_ERROR_RANGE | mcqe_status));
  12860. }
  12861. if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
  12862. pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
  12863. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_MBOX_VPORT,
  12864. "MBOX dflt rpi: status:x%x rpi:x%x",
  12865. mcqe_status,
  12866. pmbox->un.varWords[0], 0);
  12867. if (mcqe_status == MB_CQE_STATUS_SUCCESS) {
  12868. mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
  12869. ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
  12870. /* Reg_LOGIN of dflt RPI was successful. Mark the
  12871. * node as having an UNREG_LOGIN in progress to stop
  12872. * an unsolicited PLOGI from the same NPortId from
  12873. * starting another mailbox transaction.
  12874. */
  12875. spin_lock_irqsave(&ndlp->lock, iflags);
  12876. ndlp->nlp_flag |= NLP_UNREG_INP;
  12877. spin_unlock_irqrestore(&ndlp->lock, iflags);
  12878. lpfc_unreg_login(phba, vport->vpi,
  12879. pmbox->un.varWords[0], pmb);
  12880. pmb->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
  12881. pmb->ctx_buf = mp;
  12882. /* No reference taken here. This is a default
  12883. * RPI reg/immediate unreg cycle. The reference was
  12884. * taken in the reg rpi path and is released when
  12885. * this mailbox completes.
  12886. */
  12887. pmb->ctx_ndlp = ndlp;
  12888. pmb->vport = vport;
  12889. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  12890. if (rc != MBX_BUSY)
  12891. lpfc_printf_log(phba, KERN_ERR,
  12892. LOG_TRACE_EVENT,
  12893. "0385 rc should "
  12894. "have been MBX_BUSY\n");
  12895. if (rc != MBX_NOT_FINISHED)
  12896. goto send_current_mbox;
  12897. }
  12898. }
  12899. spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
  12900. phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
  12901. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
  12902. /* Do NOT queue MBX_HEARTBEAT to the worker thread for processing. */
  12903. if (pmbox->mbxCommand == MBX_HEARTBEAT) {
  12904. spin_lock_irqsave(&phba->hbalock, iflags);
  12905. /* Release the mailbox command posting token */
  12906. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  12907. phba->sli.mbox_active = NULL;
  12908. if (bf_get(lpfc_trailer_consumed, mcqe))
  12909. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  12910. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12911. /* Post the next mbox command, if there is one */
  12912. lpfc_sli4_post_async_mbox(phba);
  12913. /* Process cmpl now */
  12914. if (pmb->mbox_cmpl)
  12915. pmb->mbox_cmpl(phba, pmb);
  12916. return false;
  12917. }
  12918. /* There is mailbox completion work to queue to the worker thread */
  12919. spin_lock_irqsave(&phba->hbalock, iflags);
  12920. __lpfc_mbox_cmpl_put(phba, pmb);
  12921. phba->work_ha |= HA_MBATT;
  12922. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12923. workposted = true;
  12924. send_current_mbox:
  12925. spin_lock_irqsave(&phba->hbalock, iflags);
  12926. /* Release the mailbox command posting token */
  12927. phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
  12928. /* Setting active mailbox pointer need to be in sync to flag clear */
  12929. phba->sli.mbox_active = NULL;
  12930. if (bf_get(lpfc_trailer_consumed, mcqe))
  12931. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  12932. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12933. /* Wake up worker thread to post the next pending mailbox command */
  12934. lpfc_worker_wake_up(phba);
  12935. return workposted;
  12936. out_no_mqe_complete:
  12937. spin_lock_irqsave(&phba->hbalock, iflags);
  12938. if (bf_get(lpfc_trailer_consumed, mcqe))
  12939. lpfc_sli4_mq_release(phba->sli4_hba.mbx_wq);
  12940. spin_unlock_irqrestore(&phba->hbalock, iflags);
  12941. return false;
  12942. }
  12943. /**
  12944. * lpfc_sli4_sp_handle_mcqe - Process a mailbox completion queue entry
  12945. * @phba: Pointer to HBA context object.
  12946. * @cq: Pointer to associated CQ
  12947. * @cqe: Pointer to mailbox completion queue entry.
  12948. *
  12949. * This routine process a mailbox completion queue entry, it invokes the
  12950. * proper mailbox complete handling or asynchronous event handling routine
  12951. * according to the MCQE's async bit.
  12952. *
  12953. * Return: true if work posted to worker thread, otherwise false.
  12954. **/
  12955. static bool
  12956. lpfc_sli4_sp_handle_mcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  12957. struct lpfc_cqe *cqe)
  12958. {
  12959. struct lpfc_mcqe mcqe;
  12960. bool workposted;
  12961. cq->CQ_mbox++;
  12962. /* Copy the mailbox MCQE and convert endian order as needed */
  12963. lpfc_sli4_pcimem_bcopy(cqe, &mcqe, sizeof(struct lpfc_mcqe));
  12964. /* Invoke the proper event handling routine */
  12965. if (!bf_get(lpfc_trailer_async, &mcqe))
  12966. workposted = lpfc_sli4_sp_handle_mbox_event(phba, &mcqe);
  12967. else
  12968. workposted = lpfc_sli4_sp_handle_async_event(phba, &mcqe);
  12969. return workposted;
  12970. }
  12971. /**
  12972. * lpfc_sli4_sp_handle_els_wcqe - Handle els work-queue completion event
  12973. * @phba: Pointer to HBA context object.
  12974. * @cq: Pointer to associated CQ
  12975. * @wcqe: Pointer to work-queue completion queue entry.
  12976. *
  12977. * This routine handles an ELS work-queue completion event.
  12978. *
  12979. * Return: true if work posted to worker thread, otherwise false.
  12980. **/
  12981. static bool
  12982. lpfc_sli4_sp_handle_els_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  12983. struct lpfc_wcqe_complete *wcqe)
  12984. {
  12985. struct lpfc_iocbq *irspiocbq;
  12986. unsigned long iflags;
  12987. struct lpfc_sli_ring *pring = cq->pring;
  12988. int txq_cnt = 0;
  12989. int txcmplq_cnt = 0;
  12990. /* Check for response status */
  12991. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  12992. /* Log the error status */
  12993. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  12994. "0357 ELS CQE error: status=x%x: "
  12995. "CQE: %08x %08x %08x %08x\n",
  12996. bf_get(lpfc_wcqe_c_status, wcqe),
  12997. wcqe->word0, wcqe->total_data_placed,
  12998. wcqe->parameter, wcqe->word3);
  12999. }
  13000. /* Get an irspiocbq for later ELS response processing use */
  13001. irspiocbq = lpfc_sli_get_iocbq(phba);
  13002. if (!irspiocbq) {
  13003. if (!list_empty(&pring->txq))
  13004. txq_cnt++;
  13005. if (!list_empty(&pring->txcmplq))
  13006. txcmplq_cnt++;
  13007. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13008. "0387 NO IOCBQ data: txq_cnt=%d iocb_cnt=%d "
  13009. "els_txcmplq_cnt=%d\n",
  13010. txq_cnt, phba->iocb_cnt,
  13011. txcmplq_cnt);
  13012. return false;
  13013. }
  13014. /* Save off the slow-path queue event for work thread to process */
  13015. memcpy(&irspiocbq->cq_event.cqe.wcqe_cmpl, wcqe, sizeof(*wcqe));
  13016. spin_lock_irqsave(&phba->hbalock, iflags);
  13017. list_add_tail(&irspiocbq->cq_event.list,
  13018. &phba->sli4_hba.sp_queue_event);
  13019. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  13020. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13021. return true;
  13022. }
  13023. /**
  13024. * lpfc_sli4_sp_handle_rel_wcqe - Handle slow-path WQ entry consumed event
  13025. * @phba: Pointer to HBA context object.
  13026. * @wcqe: Pointer to work-queue completion queue entry.
  13027. *
  13028. * This routine handles slow-path WQ entry consumed event by invoking the
  13029. * proper WQ release routine to the slow-path WQ.
  13030. **/
  13031. static void
  13032. lpfc_sli4_sp_handle_rel_wcqe(struct lpfc_hba *phba,
  13033. struct lpfc_wcqe_release *wcqe)
  13034. {
  13035. /* sanity check on queue memory */
  13036. if (unlikely(!phba->sli4_hba.els_wq))
  13037. return;
  13038. /* Check for the slow-path ELS work queue */
  13039. if (bf_get(lpfc_wcqe_r_wq_id, wcqe) == phba->sli4_hba.els_wq->queue_id)
  13040. lpfc_sli4_wq_release(phba->sli4_hba.els_wq,
  13041. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  13042. else
  13043. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13044. "2579 Slow-path wqe consume event carries "
  13045. "miss-matched qid: wcqe-qid=x%x, sp-qid=x%x\n",
  13046. bf_get(lpfc_wcqe_r_wqe_index, wcqe),
  13047. phba->sli4_hba.els_wq->queue_id);
  13048. }
  13049. /**
  13050. * lpfc_sli4_sp_handle_abort_xri_wcqe - Handle a xri abort event
  13051. * @phba: Pointer to HBA context object.
  13052. * @cq: Pointer to a WQ completion queue.
  13053. * @wcqe: Pointer to work-queue completion queue entry.
  13054. *
  13055. * This routine handles an XRI abort event.
  13056. *
  13057. * Return: true if work posted to worker thread, otherwise false.
  13058. **/
  13059. static bool
  13060. lpfc_sli4_sp_handle_abort_xri_wcqe(struct lpfc_hba *phba,
  13061. struct lpfc_queue *cq,
  13062. struct sli4_wcqe_xri_aborted *wcqe)
  13063. {
  13064. bool workposted = false;
  13065. struct lpfc_cq_event *cq_event;
  13066. unsigned long iflags;
  13067. switch (cq->subtype) {
  13068. case LPFC_IO:
  13069. lpfc_sli4_io_xri_aborted(phba, wcqe, cq->hdwq);
  13070. if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) {
  13071. /* Notify aborted XRI for NVME work queue */
  13072. if (phba->nvmet_support)
  13073. lpfc_sli4_nvmet_xri_aborted(phba, wcqe);
  13074. }
  13075. workposted = false;
  13076. break;
  13077. case LPFC_NVME_LS: /* NVME LS uses ELS resources */
  13078. case LPFC_ELS:
  13079. cq_event = lpfc_cq_event_setup(phba, wcqe, sizeof(*wcqe));
  13080. if (!cq_event) {
  13081. workposted = false;
  13082. break;
  13083. }
  13084. cq_event->hdwq = cq->hdwq;
  13085. spin_lock_irqsave(&phba->sli4_hba.els_xri_abrt_list_lock,
  13086. iflags);
  13087. list_add_tail(&cq_event->list,
  13088. &phba->sli4_hba.sp_els_xri_aborted_work_queue);
  13089. /* Set the els xri abort event flag */
  13090. phba->hba_flag |= ELS_XRI_ABORT_EVENT;
  13091. spin_unlock_irqrestore(&phba->sli4_hba.els_xri_abrt_list_lock,
  13092. iflags);
  13093. workposted = true;
  13094. break;
  13095. default:
  13096. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13097. "0603 Invalid CQ subtype %d: "
  13098. "%08x %08x %08x %08x\n",
  13099. cq->subtype, wcqe->word0, wcqe->parameter,
  13100. wcqe->word2, wcqe->word3);
  13101. workposted = false;
  13102. break;
  13103. }
  13104. return workposted;
  13105. }
  13106. #define FC_RCTL_MDS_DIAGS 0xF4
  13107. /**
  13108. * lpfc_sli4_sp_handle_rcqe - Process a receive-queue completion queue entry
  13109. * @phba: Pointer to HBA context object.
  13110. * @rcqe: Pointer to receive-queue completion queue entry.
  13111. *
  13112. * This routine process a receive-queue completion queue entry.
  13113. *
  13114. * Return: true if work posted to worker thread, otherwise false.
  13115. **/
  13116. static bool
  13117. lpfc_sli4_sp_handle_rcqe(struct lpfc_hba *phba, struct lpfc_rcqe *rcqe)
  13118. {
  13119. bool workposted = false;
  13120. struct fc_frame_header *fc_hdr;
  13121. struct lpfc_queue *hrq = phba->sli4_hba.hdr_rq;
  13122. struct lpfc_queue *drq = phba->sli4_hba.dat_rq;
  13123. struct lpfc_nvmet_tgtport *tgtp;
  13124. struct hbq_dmabuf *dma_buf;
  13125. uint32_t status, rq_id;
  13126. unsigned long iflags;
  13127. /* sanity check on queue memory */
  13128. if (unlikely(!hrq) || unlikely(!drq))
  13129. return workposted;
  13130. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  13131. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  13132. else
  13133. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  13134. if (rq_id != hrq->queue_id)
  13135. goto out;
  13136. status = bf_get(lpfc_rcqe_status, rcqe);
  13137. switch (status) {
  13138. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  13139. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13140. "2537 Receive Frame Truncated!!\n");
  13141. fallthrough;
  13142. case FC_STATUS_RQ_SUCCESS:
  13143. spin_lock_irqsave(&phba->hbalock, iflags);
  13144. lpfc_sli4_rq_release(hrq, drq);
  13145. dma_buf = lpfc_sli_hbqbuf_get(&phba->hbqs[0].hbq_buffer_list);
  13146. if (!dma_buf) {
  13147. hrq->RQ_no_buf_found++;
  13148. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13149. goto out;
  13150. }
  13151. hrq->RQ_rcv_buf++;
  13152. hrq->RQ_buf_posted--;
  13153. memcpy(&dma_buf->cq_event.cqe.rcqe_cmpl, rcqe, sizeof(*rcqe));
  13154. fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
  13155. if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
  13156. fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
  13157. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13158. /* Handle MDS Loopback frames */
  13159. if (!(phba->pport->load_flag & FC_UNLOADING))
  13160. lpfc_sli4_handle_mds_loopback(phba->pport,
  13161. dma_buf);
  13162. else
  13163. lpfc_in_buf_free(phba, &dma_buf->dbuf);
  13164. break;
  13165. }
  13166. /* save off the frame for the work thread to process */
  13167. list_add_tail(&dma_buf->cq_event.list,
  13168. &phba->sli4_hba.sp_queue_event);
  13169. /* Frame received */
  13170. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  13171. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13172. workposted = true;
  13173. break;
  13174. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  13175. if (phba->nvmet_support) {
  13176. tgtp = phba->targetport->private;
  13177. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13178. "6402 RQE Error x%x, posted %d err_cnt "
  13179. "%d: %x %x %x\n",
  13180. status, hrq->RQ_buf_posted,
  13181. hrq->RQ_no_posted_buf,
  13182. atomic_read(&tgtp->rcv_fcp_cmd_in),
  13183. atomic_read(&tgtp->rcv_fcp_cmd_out),
  13184. atomic_read(&tgtp->xmt_fcp_release));
  13185. }
  13186. fallthrough;
  13187. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  13188. hrq->RQ_no_posted_buf++;
  13189. /* Post more buffers if possible */
  13190. spin_lock_irqsave(&phba->hbalock, iflags);
  13191. phba->hba_flag |= HBA_POST_RECEIVE_BUFFER;
  13192. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13193. workposted = true;
  13194. break;
  13195. }
  13196. out:
  13197. return workposted;
  13198. }
  13199. /**
  13200. * lpfc_sli4_sp_handle_cqe - Process a slow path completion queue entry
  13201. * @phba: Pointer to HBA context object.
  13202. * @cq: Pointer to the completion queue.
  13203. * @cqe: Pointer to a completion queue entry.
  13204. *
  13205. * This routine process a slow-path work-queue or receive queue completion queue
  13206. * entry.
  13207. *
  13208. * Return: true if work posted to worker thread, otherwise false.
  13209. **/
  13210. static bool
  13211. lpfc_sli4_sp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13212. struct lpfc_cqe *cqe)
  13213. {
  13214. struct lpfc_cqe cqevt;
  13215. bool workposted = false;
  13216. /* Copy the work queue CQE and convert endian order if needed */
  13217. lpfc_sli4_pcimem_bcopy(cqe, &cqevt, sizeof(struct lpfc_cqe));
  13218. /* Check and process for different type of WCQE and dispatch */
  13219. switch (bf_get(lpfc_cqe_code, &cqevt)) {
  13220. case CQE_CODE_COMPL_WQE:
  13221. /* Process the WQ/RQ complete event */
  13222. phba->last_completion_time = jiffies;
  13223. workposted = lpfc_sli4_sp_handle_els_wcqe(phba, cq,
  13224. (struct lpfc_wcqe_complete *)&cqevt);
  13225. break;
  13226. case CQE_CODE_RELEASE_WQE:
  13227. /* Process the WQ release event */
  13228. lpfc_sli4_sp_handle_rel_wcqe(phba,
  13229. (struct lpfc_wcqe_release *)&cqevt);
  13230. break;
  13231. case CQE_CODE_XRI_ABORTED:
  13232. /* Process the WQ XRI abort event */
  13233. phba->last_completion_time = jiffies;
  13234. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  13235. (struct sli4_wcqe_xri_aborted *)&cqevt);
  13236. break;
  13237. case CQE_CODE_RECEIVE:
  13238. case CQE_CODE_RECEIVE_V1:
  13239. /* Process the RQ event */
  13240. phba->last_completion_time = jiffies;
  13241. workposted = lpfc_sli4_sp_handle_rcqe(phba,
  13242. (struct lpfc_rcqe *)&cqevt);
  13243. break;
  13244. default:
  13245. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13246. "0388 Not a valid WCQE code: x%x\n",
  13247. bf_get(lpfc_cqe_code, &cqevt));
  13248. break;
  13249. }
  13250. return workposted;
  13251. }
  13252. /**
  13253. * lpfc_sli4_sp_handle_eqe - Process a slow-path event queue entry
  13254. * @phba: Pointer to HBA context object.
  13255. * @eqe: Pointer to fast-path event queue entry.
  13256. * @speq: Pointer to slow-path event queue.
  13257. *
  13258. * This routine process a event queue entry from the slow-path event queue.
  13259. * It will check the MajorCode and MinorCode to determine this is for a
  13260. * completion event on a completion queue, if not, an error shall be logged
  13261. * and just return. Otherwise, it will get to the corresponding completion
  13262. * queue and process all the entries on that completion queue, rearm the
  13263. * completion queue, and then return.
  13264. *
  13265. **/
  13266. static void
  13267. lpfc_sli4_sp_handle_eqe(struct lpfc_hba *phba, struct lpfc_eqe *eqe,
  13268. struct lpfc_queue *speq)
  13269. {
  13270. struct lpfc_queue *cq = NULL, *childq;
  13271. uint16_t cqid;
  13272. int ret = 0;
  13273. /* Get the reference to the corresponding CQ */
  13274. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  13275. list_for_each_entry(childq, &speq->child_list, list) {
  13276. if (childq->queue_id == cqid) {
  13277. cq = childq;
  13278. break;
  13279. }
  13280. }
  13281. if (unlikely(!cq)) {
  13282. if (phba->sli.sli_flag & LPFC_SLI_ACTIVE)
  13283. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13284. "0365 Slow-path CQ identifier "
  13285. "(%d) does not exist\n", cqid);
  13286. return;
  13287. }
  13288. /* Save EQ associated with this CQ */
  13289. cq->assoc_qp = speq;
  13290. if (is_kdump_kernel())
  13291. ret = queue_work(phba->wq, &cq->spwork);
  13292. else
  13293. ret = queue_work_on(cq->chann, phba->wq, &cq->spwork);
  13294. if (!ret)
  13295. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13296. "0390 Cannot schedule queue work "
  13297. "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
  13298. cqid, cq->queue_id, raw_smp_processor_id());
  13299. }
  13300. /**
  13301. * __lpfc_sli4_process_cq - Process elements of a CQ
  13302. * @phba: Pointer to HBA context object.
  13303. * @cq: Pointer to CQ to be processed
  13304. * @handler: Routine to process each cqe
  13305. * @delay: Pointer to usdelay to set in case of rescheduling of the handler
  13306. * @poll_mode: Polling mode we were called from
  13307. *
  13308. * This routine processes completion queue entries in a CQ. While a valid
  13309. * queue element is found, the handler is called. During processing checks
  13310. * are made for periodic doorbell writes to let the hardware know of
  13311. * element consumption.
  13312. *
  13313. * If the max limit on cqes to process is hit, or there are no more valid
  13314. * entries, the loop stops. If we processed a sufficient number of elements,
  13315. * meaning there is sufficient load, rather than rearming and generating
  13316. * another interrupt, a cq rescheduling delay will be set. A delay of 0
  13317. * indicates no rescheduling.
  13318. *
  13319. * Returns True if work scheduled, False otherwise.
  13320. **/
  13321. static bool
  13322. __lpfc_sli4_process_cq(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13323. bool (*handler)(struct lpfc_hba *, struct lpfc_queue *,
  13324. struct lpfc_cqe *), unsigned long *delay,
  13325. enum lpfc_poll_mode poll_mode)
  13326. {
  13327. struct lpfc_cqe *cqe;
  13328. bool workposted = false;
  13329. int count = 0, consumed = 0;
  13330. bool arm = true;
  13331. /* default - no reschedule */
  13332. *delay = 0;
  13333. if (cmpxchg(&cq->queue_claimed, 0, 1) != 0)
  13334. goto rearm_and_exit;
  13335. /* Process all the entries to the CQ */
  13336. cq->q_flag = 0;
  13337. cqe = lpfc_sli4_cq_get(cq);
  13338. while (cqe) {
  13339. workposted |= handler(phba, cq, cqe);
  13340. __lpfc_sli4_consume_cqe(phba, cq, cqe);
  13341. consumed++;
  13342. if (!(++count % cq->max_proc_limit))
  13343. break;
  13344. if (!(count % cq->notify_interval)) {
  13345. phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
  13346. LPFC_QUEUE_NOARM);
  13347. consumed = 0;
  13348. cq->assoc_qp->q_flag |= HBA_EQ_DELAY_CHK;
  13349. }
  13350. if (count == LPFC_NVMET_CQ_NOTIFY)
  13351. cq->q_flag |= HBA_NVMET_CQ_NOTIFY;
  13352. cqe = lpfc_sli4_cq_get(cq);
  13353. }
  13354. if (count >= phba->cfg_cq_poll_threshold) {
  13355. *delay = 1;
  13356. arm = false;
  13357. }
  13358. /* Note: complete the irq_poll softirq before rearming CQ */
  13359. if (poll_mode == LPFC_IRQ_POLL)
  13360. irq_poll_complete(&cq->iop);
  13361. /* Track the max number of CQEs processed in 1 EQ */
  13362. if (count > cq->CQ_max_cqe)
  13363. cq->CQ_max_cqe = count;
  13364. cq->assoc_qp->EQ_cqe_cnt += count;
  13365. /* Catch the no cq entry condition */
  13366. if (unlikely(count == 0))
  13367. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  13368. "0369 No entry from completion queue "
  13369. "qid=%d\n", cq->queue_id);
  13370. xchg(&cq->queue_claimed, 0);
  13371. rearm_and_exit:
  13372. phba->sli4_hba.sli4_write_cq_db(phba, cq, consumed,
  13373. arm ? LPFC_QUEUE_REARM : LPFC_QUEUE_NOARM);
  13374. return workposted;
  13375. }
  13376. /**
  13377. * __lpfc_sli4_sp_process_cq - Process a slow-path event queue entry
  13378. * @cq: pointer to CQ to process
  13379. *
  13380. * This routine calls the cq processing routine with a handler specific
  13381. * to the type of queue bound to it.
  13382. *
  13383. * The CQ routine returns two values: the first is the calling status,
  13384. * which indicates whether work was queued to the background discovery
  13385. * thread. If true, the routine should wakeup the discovery thread;
  13386. * the second is the delay parameter. If non-zero, rather than rearming
  13387. * the CQ and yet another interrupt, the CQ handler should be queued so
  13388. * that it is processed in a subsequent polling action. The value of
  13389. * the delay indicates when to reschedule it.
  13390. **/
  13391. static void
  13392. __lpfc_sli4_sp_process_cq(struct lpfc_queue *cq)
  13393. {
  13394. struct lpfc_hba *phba = cq->phba;
  13395. unsigned long delay;
  13396. bool workposted = false;
  13397. int ret = 0;
  13398. /* Process and rearm the CQ */
  13399. switch (cq->type) {
  13400. case LPFC_MCQ:
  13401. workposted |= __lpfc_sli4_process_cq(phba, cq,
  13402. lpfc_sli4_sp_handle_mcqe,
  13403. &delay, LPFC_QUEUE_WORK);
  13404. break;
  13405. case LPFC_WCQ:
  13406. if (cq->subtype == LPFC_IO)
  13407. workposted |= __lpfc_sli4_process_cq(phba, cq,
  13408. lpfc_sli4_fp_handle_cqe,
  13409. &delay, LPFC_QUEUE_WORK);
  13410. else
  13411. workposted |= __lpfc_sli4_process_cq(phba, cq,
  13412. lpfc_sli4_sp_handle_cqe,
  13413. &delay, LPFC_QUEUE_WORK);
  13414. break;
  13415. default:
  13416. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13417. "0370 Invalid completion queue type (%d)\n",
  13418. cq->type);
  13419. return;
  13420. }
  13421. if (delay) {
  13422. if (is_kdump_kernel())
  13423. ret = queue_delayed_work(phba->wq, &cq->sched_spwork,
  13424. delay);
  13425. else
  13426. ret = queue_delayed_work_on(cq->chann, phba->wq,
  13427. &cq->sched_spwork, delay);
  13428. if (!ret)
  13429. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13430. "0394 Cannot schedule queue work "
  13431. "for cqid=%d on CPU %d\n",
  13432. cq->queue_id, cq->chann);
  13433. }
  13434. /* wake up worker thread if there are works to be done */
  13435. if (workposted)
  13436. lpfc_worker_wake_up(phba);
  13437. }
  13438. /**
  13439. * lpfc_sli4_sp_process_cq - slow-path work handler when started by
  13440. * interrupt
  13441. * @work: pointer to work element
  13442. *
  13443. * translates from the work handler and calls the slow-path handler.
  13444. **/
  13445. static void
  13446. lpfc_sli4_sp_process_cq(struct work_struct *work)
  13447. {
  13448. struct lpfc_queue *cq = container_of(work, struct lpfc_queue, spwork);
  13449. __lpfc_sli4_sp_process_cq(cq);
  13450. }
  13451. /**
  13452. * lpfc_sli4_dly_sp_process_cq - slow-path work handler when started by timer
  13453. * @work: pointer to work element
  13454. *
  13455. * translates from the work handler and calls the slow-path handler.
  13456. **/
  13457. static void
  13458. lpfc_sli4_dly_sp_process_cq(struct work_struct *work)
  13459. {
  13460. struct lpfc_queue *cq = container_of(to_delayed_work(work),
  13461. struct lpfc_queue, sched_spwork);
  13462. __lpfc_sli4_sp_process_cq(cq);
  13463. }
  13464. /**
  13465. * lpfc_sli4_fp_handle_fcp_wcqe - Process fast-path work queue completion entry
  13466. * @phba: Pointer to HBA context object.
  13467. * @cq: Pointer to associated CQ
  13468. * @wcqe: Pointer to work-queue completion queue entry.
  13469. *
  13470. * This routine process a fast-path work queue completion entry from fast-path
  13471. * event queue for FCP command response completion.
  13472. **/
  13473. static void
  13474. lpfc_sli4_fp_handle_fcp_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13475. struct lpfc_wcqe_complete *wcqe)
  13476. {
  13477. struct lpfc_sli_ring *pring = cq->pring;
  13478. struct lpfc_iocbq *cmdiocbq;
  13479. unsigned long iflags;
  13480. /* Check for response status */
  13481. if (unlikely(bf_get(lpfc_wcqe_c_status, wcqe))) {
  13482. /* If resource errors reported from HBA, reduce queue
  13483. * depth of the SCSI device.
  13484. */
  13485. if (((bf_get(lpfc_wcqe_c_status, wcqe) ==
  13486. IOSTAT_LOCAL_REJECT)) &&
  13487. ((wcqe->parameter & IOERR_PARAM_MASK) ==
  13488. IOERR_NO_RESOURCES))
  13489. phba->lpfc_rampdown_queue_depth(phba);
  13490. /* Log the cmpl status */
  13491. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  13492. "0373 FCP CQE cmpl: status=x%x: "
  13493. "CQE: %08x %08x %08x %08x\n",
  13494. bf_get(lpfc_wcqe_c_status, wcqe),
  13495. wcqe->word0, wcqe->total_data_placed,
  13496. wcqe->parameter, wcqe->word3);
  13497. }
  13498. /* Look up the FCP command IOCB and create pseudo response IOCB */
  13499. spin_lock_irqsave(&pring->ring_lock, iflags);
  13500. pring->stats.iocb_event++;
  13501. cmdiocbq = lpfc_sli_iocbq_lookup_by_tag(phba, pring,
  13502. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  13503. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  13504. if (unlikely(!cmdiocbq)) {
  13505. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13506. "0374 FCP complete with no corresponding "
  13507. "cmdiocb: iotag (%d)\n",
  13508. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  13509. return;
  13510. }
  13511. #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
  13512. cmdiocbq->isr_timestamp = cq->isr_timestamp;
  13513. #endif
  13514. if (bf_get(lpfc_wcqe_c_xb, wcqe)) {
  13515. spin_lock_irqsave(&phba->hbalock, iflags);
  13516. cmdiocbq->cmd_flag |= LPFC_EXCHANGE_BUSY;
  13517. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13518. }
  13519. if (cmdiocbq->cmd_cmpl) {
  13520. /* For FCP the flag is cleared in cmd_cmpl */
  13521. if (!(cmdiocbq->cmd_flag & LPFC_IO_FCP) &&
  13522. cmdiocbq->cmd_flag & LPFC_DRIVER_ABORTED) {
  13523. spin_lock_irqsave(&phba->hbalock, iflags);
  13524. cmdiocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
  13525. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13526. }
  13527. /* Pass the cmd_iocb and the wcqe to the upper layer */
  13528. memcpy(&cmdiocbq->wcqe_cmpl, wcqe,
  13529. sizeof(struct lpfc_wcqe_complete));
  13530. cmdiocbq->cmd_cmpl(phba, cmdiocbq, cmdiocbq);
  13531. } else {
  13532. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13533. "0375 FCP cmdiocb not callback function "
  13534. "iotag: (%d)\n",
  13535. bf_get(lpfc_wcqe_c_request_tag, wcqe));
  13536. }
  13537. }
  13538. /**
  13539. * lpfc_sli4_fp_handle_rel_wcqe - Handle fast-path WQ entry consumed event
  13540. * @phba: Pointer to HBA context object.
  13541. * @cq: Pointer to completion queue.
  13542. * @wcqe: Pointer to work-queue completion queue entry.
  13543. *
  13544. * This routine handles an fast-path WQ entry consumed event by invoking the
  13545. * proper WQ release routine to the slow-path WQ.
  13546. **/
  13547. static void
  13548. lpfc_sli4_fp_handle_rel_wcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13549. struct lpfc_wcqe_release *wcqe)
  13550. {
  13551. struct lpfc_queue *childwq;
  13552. bool wqid_matched = false;
  13553. uint16_t hba_wqid;
  13554. /* Check for fast-path FCP work queue release */
  13555. hba_wqid = bf_get(lpfc_wcqe_r_wq_id, wcqe);
  13556. list_for_each_entry(childwq, &cq->child_list, list) {
  13557. if (childwq->queue_id == hba_wqid) {
  13558. lpfc_sli4_wq_release(childwq,
  13559. bf_get(lpfc_wcqe_r_wqe_index, wcqe));
  13560. if (childwq->q_flag & HBA_NVMET_WQFULL)
  13561. lpfc_nvmet_wqfull_process(phba, childwq);
  13562. wqid_matched = true;
  13563. break;
  13564. }
  13565. }
  13566. /* Report warning log message if no match found */
  13567. if (wqid_matched != true)
  13568. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13569. "2580 Fast-path wqe consume event carries "
  13570. "miss-matched qid: wcqe-qid=x%x\n", hba_wqid);
  13571. }
  13572. /**
  13573. * lpfc_sli4_nvmet_handle_rcqe - Process a receive-queue completion queue entry
  13574. * @phba: Pointer to HBA context object.
  13575. * @cq: Pointer to completion queue.
  13576. * @rcqe: Pointer to receive-queue completion queue entry.
  13577. *
  13578. * This routine process a receive-queue completion queue entry.
  13579. *
  13580. * Return: true if work posted to worker thread, otherwise false.
  13581. **/
  13582. static bool
  13583. lpfc_sli4_nvmet_handle_rcqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13584. struct lpfc_rcqe *rcqe)
  13585. {
  13586. bool workposted = false;
  13587. struct lpfc_queue *hrq;
  13588. struct lpfc_queue *drq;
  13589. struct rqb_dmabuf *dma_buf;
  13590. struct fc_frame_header *fc_hdr;
  13591. struct lpfc_nvmet_tgtport *tgtp;
  13592. uint32_t status, rq_id;
  13593. unsigned long iflags;
  13594. uint32_t fctl, idx;
  13595. if ((phba->nvmet_support == 0) ||
  13596. (phba->sli4_hba.nvmet_cqset == NULL))
  13597. return workposted;
  13598. idx = cq->queue_id - phba->sli4_hba.nvmet_cqset[0]->queue_id;
  13599. hrq = phba->sli4_hba.nvmet_mrq_hdr[idx];
  13600. drq = phba->sli4_hba.nvmet_mrq_data[idx];
  13601. /* sanity check on queue memory */
  13602. if (unlikely(!hrq) || unlikely(!drq))
  13603. return workposted;
  13604. if (bf_get(lpfc_cqe_code, rcqe) == CQE_CODE_RECEIVE_V1)
  13605. rq_id = bf_get(lpfc_rcqe_rq_id_v1, rcqe);
  13606. else
  13607. rq_id = bf_get(lpfc_rcqe_rq_id, rcqe);
  13608. if ((phba->nvmet_support == 0) ||
  13609. (rq_id != hrq->queue_id))
  13610. return workposted;
  13611. status = bf_get(lpfc_rcqe_status, rcqe);
  13612. switch (status) {
  13613. case FC_STATUS_RQ_BUF_LEN_EXCEEDED:
  13614. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13615. "6126 Receive Frame Truncated!!\n");
  13616. fallthrough;
  13617. case FC_STATUS_RQ_SUCCESS:
  13618. spin_lock_irqsave(&phba->hbalock, iflags);
  13619. lpfc_sli4_rq_release(hrq, drq);
  13620. dma_buf = lpfc_sli_rqbuf_get(phba, hrq);
  13621. if (!dma_buf) {
  13622. hrq->RQ_no_buf_found++;
  13623. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13624. goto out;
  13625. }
  13626. spin_unlock_irqrestore(&phba->hbalock, iflags);
  13627. hrq->RQ_rcv_buf++;
  13628. hrq->RQ_buf_posted--;
  13629. fc_hdr = (struct fc_frame_header *)dma_buf->hbuf.virt;
  13630. /* Just some basic sanity checks on FCP Command frame */
  13631. fctl = (fc_hdr->fh_f_ctl[0] << 16 |
  13632. fc_hdr->fh_f_ctl[1] << 8 |
  13633. fc_hdr->fh_f_ctl[2]);
  13634. if (((fctl &
  13635. (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) !=
  13636. (FC_FC_FIRST_SEQ | FC_FC_END_SEQ | FC_FC_SEQ_INIT)) ||
  13637. (fc_hdr->fh_seq_cnt != 0)) /* 0 byte swapped is still 0 */
  13638. goto drop;
  13639. if (fc_hdr->fh_type == FC_TYPE_FCP) {
  13640. dma_buf->bytes_recv = bf_get(lpfc_rcqe_length, rcqe);
  13641. lpfc_nvmet_unsol_fcp_event(
  13642. phba, idx, dma_buf, cq->isr_timestamp,
  13643. cq->q_flag & HBA_NVMET_CQ_NOTIFY);
  13644. return false;
  13645. }
  13646. drop:
  13647. lpfc_rq_buf_free(phba, &dma_buf->hbuf);
  13648. break;
  13649. case FC_STATUS_INSUFF_BUF_FRM_DISC:
  13650. if (phba->nvmet_support) {
  13651. tgtp = phba->targetport->private;
  13652. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13653. "6401 RQE Error x%x, posted %d err_cnt "
  13654. "%d: %x %x %x\n",
  13655. status, hrq->RQ_buf_posted,
  13656. hrq->RQ_no_posted_buf,
  13657. atomic_read(&tgtp->rcv_fcp_cmd_in),
  13658. atomic_read(&tgtp->rcv_fcp_cmd_out),
  13659. atomic_read(&tgtp->xmt_fcp_release));
  13660. }
  13661. fallthrough;
  13662. case FC_STATUS_INSUFF_BUF_NEED_BUF:
  13663. hrq->RQ_no_posted_buf++;
  13664. /* Post more buffers if possible */
  13665. break;
  13666. }
  13667. out:
  13668. return workposted;
  13669. }
  13670. /**
  13671. * lpfc_sli4_fp_handle_cqe - Process fast-path work queue completion entry
  13672. * @phba: adapter with cq
  13673. * @cq: Pointer to the completion queue.
  13674. * @cqe: Pointer to fast-path completion queue entry.
  13675. *
  13676. * This routine process a fast-path work queue completion entry from fast-path
  13677. * event queue for FCP command response completion.
  13678. *
  13679. * Return: true if work posted to worker thread, otherwise false.
  13680. **/
  13681. static bool
  13682. lpfc_sli4_fp_handle_cqe(struct lpfc_hba *phba, struct lpfc_queue *cq,
  13683. struct lpfc_cqe *cqe)
  13684. {
  13685. struct lpfc_wcqe_release wcqe;
  13686. bool workposted = false;
  13687. /* Copy the work queue CQE and convert endian order if needed */
  13688. lpfc_sli4_pcimem_bcopy(cqe, &wcqe, sizeof(struct lpfc_cqe));
  13689. /* Check and process for different type of WCQE and dispatch */
  13690. switch (bf_get(lpfc_wcqe_c_code, &wcqe)) {
  13691. case CQE_CODE_COMPL_WQE:
  13692. case CQE_CODE_NVME_ERSP:
  13693. cq->CQ_wq++;
  13694. /* Process the WQ complete event */
  13695. phba->last_completion_time = jiffies;
  13696. if (cq->subtype == LPFC_IO || cq->subtype == LPFC_NVME_LS)
  13697. lpfc_sli4_fp_handle_fcp_wcqe(phba, cq,
  13698. (struct lpfc_wcqe_complete *)&wcqe);
  13699. break;
  13700. case CQE_CODE_RELEASE_WQE:
  13701. cq->CQ_release_wqe++;
  13702. /* Process the WQ release event */
  13703. lpfc_sli4_fp_handle_rel_wcqe(phba, cq,
  13704. (struct lpfc_wcqe_release *)&wcqe);
  13705. break;
  13706. case CQE_CODE_XRI_ABORTED:
  13707. cq->CQ_xri_aborted++;
  13708. /* Process the WQ XRI abort event */
  13709. phba->last_completion_time = jiffies;
  13710. workposted = lpfc_sli4_sp_handle_abort_xri_wcqe(phba, cq,
  13711. (struct sli4_wcqe_xri_aborted *)&wcqe);
  13712. break;
  13713. case CQE_CODE_RECEIVE_V1:
  13714. case CQE_CODE_RECEIVE:
  13715. phba->last_completion_time = jiffies;
  13716. if (cq->subtype == LPFC_NVMET) {
  13717. workposted = lpfc_sli4_nvmet_handle_rcqe(
  13718. phba, cq, (struct lpfc_rcqe *)&wcqe);
  13719. }
  13720. break;
  13721. default:
  13722. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13723. "0144 Not a valid CQE code: x%x\n",
  13724. bf_get(lpfc_wcqe_c_code, &wcqe));
  13725. break;
  13726. }
  13727. return workposted;
  13728. }
  13729. /**
  13730. * lpfc_sli4_sched_cq_work - Schedules cq work
  13731. * @phba: Pointer to HBA context object.
  13732. * @cq: Pointer to CQ
  13733. * @cqid: CQ ID
  13734. *
  13735. * This routine checks the poll mode of the CQ corresponding to
  13736. * cq->chann, then either schedules a softirq or queue_work to complete
  13737. * cq work.
  13738. *
  13739. * queue_work path is taken if in NVMET mode, or if poll_mode is in
  13740. * LPFC_QUEUE_WORK mode. Otherwise, softirq path is taken.
  13741. *
  13742. **/
  13743. static void lpfc_sli4_sched_cq_work(struct lpfc_hba *phba,
  13744. struct lpfc_queue *cq, uint16_t cqid)
  13745. {
  13746. int ret = 0;
  13747. switch (cq->poll_mode) {
  13748. case LPFC_IRQ_POLL:
  13749. /* CGN mgmt is mutually exclusive from softirq processing */
  13750. if (phba->cmf_active_mode == LPFC_CFG_OFF) {
  13751. irq_poll_sched(&cq->iop);
  13752. break;
  13753. }
  13754. fallthrough;
  13755. case LPFC_QUEUE_WORK:
  13756. default:
  13757. if (is_kdump_kernel())
  13758. ret = queue_work(phba->wq, &cq->irqwork);
  13759. else
  13760. ret = queue_work_on(cq->chann, phba->wq, &cq->irqwork);
  13761. if (!ret)
  13762. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13763. "0383 Cannot schedule queue work "
  13764. "for CQ eqcqid=%d, cqid=%d on CPU %d\n",
  13765. cqid, cq->queue_id,
  13766. raw_smp_processor_id());
  13767. }
  13768. }
  13769. /**
  13770. * lpfc_sli4_hba_handle_eqe - Process a fast-path event queue entry
  13771. * @phba: Pointer to HBA context object.
  13772. * @eq: Pointer to the queue structure.
  13773. * @eqe: Pointer to fast-path event queue entry.
  13774. *
  13775. * This routine process a event queue entry from the fast-path event queue.
  13776. * It will check the MajorCode and MinorCode to determine this is for a
  13777. * completion event on a completion queue, if not, an error shall be logged
  13778. * and just return. Otherwise, it will get to the corresponding completion
  13779. * queue and process all the entries on the completion queue, rearm the
  13780. * completion queue, and then return.
  13781. **/
  13782. static void
  13783. lpfc_sli4_hba_handle_eqe(struct lpfc_hba *phba, struct lpfc_queue *eq,
  13784. struct lpfc_eqe *eqe)
  13785. {
  13786. struct lpfc_queue *cq = NULL;
  13787. uint32_t qidx = eq->hdwq;
  13788. uint16_t cqid, id;
  13789. if (unlikely(bf_get_le32(lpfc_eqe_major_code, eqe) != 0)) {
  13790. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13791. "0366 Not a valid completion "
  13792. "event: majorcode=x%x, minorcode=x%x\n",
  13793. bf_get_le32(lpfc_eqe_major_code, eqe),
  13794. bf_get_le32(lpfc_eqe_minor_code, eqe));
  13795. return;
  13796. }
  13797. /* Get the reference to the corresponding CQ */
  13798. cqid = bf_get_le32(lpfc_eqe_resource_id, eqe);
  13799. /* Use the fast lookup method first */
  13800. if (cqid <= phba->sli4_hba.cq_max) {
  13801. cq = phba->sli4_hba.cq_lookup[cqid];
  13802. if (cq)
  13803. goto work_cq;
  13804. }
  13805. /* Next check for NVMET completion */
  13806. if (phba->cfg_nvmet_mrq && phba->sli4_hba.nvmet_cqset) {
  13807. id = phba->sli4_hba.nvmet_cqset[0]->queue_id;
  13808. if ((cqid >= id) && (cqid < (id + phba->cfg_nvmet_mrq))) {
  13809. /* Process NVMET unsol rcv */
  13810. cq = phba->sli4_hba.nvmet_cqset[cqid - id];
  13811. goto process_cq;
  13812. }
  13813. }
  13814. if (phba->sli4_hba.nvmels_cq &&
  13815. (cqid == phba->sli4_hba.nvmels_cq->queue_id)) {
  13816. /* Process NVME unsol rcv */
  13817. cq = phba->sli4_hba.nvmels_cq;
  13818. }
  13819. /* Otherwise this is a Slow path event */
  13820. if (cq == NULL) {
  13821. lpfc_sli4_sp_handle_eqe(phba, eqe,
  13822. phba->sli4_hba.hdwq[qidx].hba_eq);
  13823. return;
  13824. }
  13825. process_cq:
  13826. if (unlikely(cqid != cq->queue_id)) {
  13827. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13828. "0368 Miss-matched fast-path completion "
  13829. "queue identifier: eqcqid=%d, fcpcqid=%d\n",
  13830. cqid, cq->queue_id);
  13831. return;
  13832. }
  13833. work_cq:
  13834. #if defined(CONFIG_SCSI_LPFC_DEBUG_FS)
  13835. if (phba->ktime_on)
  13836. cq->isr_timestamp = ktime_get_ns();
  13837. else
  13838. cq->isr_timestamp = 0;
  13839. #endif
  13840. lpfc_sli4_sched_cq_work(phba, cq, cqid);
  13841. }
  13842. /**
  13843. * __lpfc_sli4_hba_process_cq - Process a fast-path event queue entry
  13844. * @cq: Pointer to CQ to be processed
  13845. * @poll_mode: Enum lpfc_poll_state to determine poll mode
  13846. *
  13847. * This routine calls the cq processing routine with the handler for
  13848. * fast path CQEs.
  13849. *
  13850. * The CQ routine returns two values: the first is the calling status,
  13851. * which indicates whether work was queued to the background discovery
  13852. * thread. If true, the routine should wakeup the discovery thread;
  13853. * the second is the delay parameter. If non-zero, rather than rearming
  13854. * the CQ and yet another interrupt, the CQ handler should be queued so
  13855. * that it is processed in a subsequent polling action. The value of
  13856. * the delay indicates when to reschedule it.
  13857. **/
  13858. static void
  13859. __lpfc_sli4_hba_process_cq(struct lpfc_queue *cq,
  13860. enum lpfc_poll_mode poll_mode)
  13861. {
  13862. struct lpfc_hba *phba = cq->phba;
  13863. unsigned long delay;
  13864. bool workposted = false;
  13865. int ret = 0;
  13866. /* process and rearm the CQ */
  13867. workposted |= __lpfc_sli4_process_cq(phba, cq, lpfc_sli4_fp_handle_cqe,
  13868. &delay, poll_mode);
  13869. if (delay) {
  13870. if (is_kdump_kernel())
  13871. ret = queue_delayed_work(phba->wq, &cq->sched_irqwork,
  13872. delay);
  13873. else
  13874. ret = queue_delayed_work_on(cq->chann, phba->wq,
  13875. &cq->sched_irqwork, delay);
  13876. if (!ret)
  13877. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  13878. "0367 Cannot schedule queue work "
  13879. "for cqid=%d on CPU %d\n",
  13880. cq->queue_id, cq->chann);
  13881. }
  13882. /* wake up worker thread if there are works to be done */
  13883. if (workposted)
  13884. lpfc_worker_wake_up(phba);
  13885. }
  13886. /**
  13887. * lpfc_sli4_hba_process_cq - fast-path work handler when started by
  13888. * interrupt
  13889. * @work: pointer to work element
  13890. *
  13891. * translates from the work handler and calls the fast-path handler.
  13892. **/
  13893. static void
  13894. lpfc_sli4_hba_process_cq(struct work_struct *work)
  13895. {
  13896. struct lpfc_queue *cq = container_of(work, struct lpfc_queue, irqwork);
  13897. __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
  13898. }
  13899. /**
  13900. * lpfc_sli4_dly_hba_process_cq - fast-path work handler when started by timer
  13901. * @work: pointer to work element
  13902. *
  13903. * translates from the work handler and calls the fast-path handler.
  13904. **/
  13905. static void
  13906. lpfc_sli4_dly_hba_process_cq(struct work_struct *work)
  13907. {
  13908. struct lpfc_queue *cq = container_of(to_delayed_work(work),
  13909. struct lpfc_queue, sched_irqwork);
  13910. __lpfc_sli4_hba_process_cq(cq, LPFC_QUEUE_WORK);
  13911. }
  13912. /**
  13913. * lpfc_sli4_hba_intr_handler - HBA interrupt handler to SLI-4 device
  13914. * @irq: Interrupt number.
  13915. * @dev_id: The device context pointer.
  13916. *
  13917. * This function is directly called from the PCI layer as an interrupt
  13918. * service routine when device with SLI-4 interface spec is enabled with
  13919. * MSI-X multi-message interrupt mode and there is a fast-path FCP IOCB
  13920. * ring event in the HBA. However, when the device is enabled with either
  13921. * MSI or Pin-IRQ interrupt mode, this function is called as part of the
  13922. * device-level interrupt handler. When the PCI slot is in error recovery
  13923. * or the HBA is undergoing initialization, the interrupt handler will not
  13924. * process the interrupt. The SCSI FCP fast-path ring event are handled in
  13925. * the intrrupt context. This function is called without any lock held.
  13926. * It gets the hbalock to access and update SLI data structures. Note that,
  13927. * the FCP EQ to FCP CQ are one-to-one map such that the FCP EQ index is
  13928. * equal to that of FCP CQ index.
  13929. *
  13930. * The link attention and ELS ring attention events are handled
  13931. * by the worker thread. The interrupt handler signals the worker thread
  13932. * and returns for these events. This function is called without any lock
  13933. * held. It gets the hbalock to access and update SLI data structures.
  13934. *
  13935. * This function returns IRQ_HANDLED when interrupt is handled else it
  13936. * returns IRQ_NONE.
  13937. **/
  13938. irqreturn_t
  13939. lpfc_sli4_hba_intr_handler(int irq, void *dev_id)
  13940. {
  13941. struct lpfc_hba *phba;
  13942. struct lpfc_hba_eq_hdl *hba_eq_hdl;
  13943. struct lpfc_queue *fpeq;
  13944. unsigned long iflag;
  13945. int ecount = 0;
  13946. int hba_eqidx;
  13947. struct lpfc_eq_intr_info *eqi;
  13948. /* Get the driver's phba structure from the dev_id */
  13949. hba_eq_hdl = (struct lpfc_hba_eq_hdl *)dev_id;
  13950. phba = hba_eq_hdl->phba;
  13951. hba_eqidx = hba_eq_hdl->idx;
  13952. if (unlikely(!phba))
  13953. return IRQ_NONE;
  13954. if (unlikely(!phba->sli4_hba.hdwq))
  13955. return IRQ_NONE;
  13956. /* Get to the EQ struct associated with this vector */
  13957. fpeq = phba->sli4_hba.hba_eq_hdl[hba_eqidx].eq;
  13958. if (unlikely(!fpeq))
  13959. return IRQ_NONE;
  13960. /* Check device state for handling interrupt */
  13961. if (unlikely(lpfc_intr_state_check(phba))) {
  13962. /* Check again for link_state with lock held */
  13963. spin_lock_irqsave(&phba->hbalock, iflag);
  13964. if (phba->link_state < LPFC_LINK_DOWN)
  13965. /* Flush, clear interrupt, and rearm the EQ */
  13966. lpfc_sli4_eqcq_flush(phba, fpeq);
  13967. spin_unlock_irqrestore(&phba->hbalock, iflag);
  13968. return IRQ_NONE;
  13969. }
  13970. eqi = this_cpu_ptr(phba->sli4_hba.eq_info);
  13971. eqi->icnt++;
  13972. fpeq->last_cpu = raw_smp_processor_id();
  13973. if (eqi->icnt > LPFC_EQD_ISR_TRIGGER &&
  13974. fpeq->q_flag & HBA_EQ_DELAY_CHK &&
  13975. phba->cfg_auto_imax &&
  13976. fpeq->q_mode != LPFC_MAX_AUTO_EQ_DELAY &&
  13977. phba->sli.sli_flag & LPFC_SLI_USE_EQDR)
  13978. lpfc_sli4_mod_hba_eq_delay(phba, fpeq, LPFC_MAX_AUTO_EQ_DELAY);
  13979. /* process and rearm the EQ */
  13980. ecount = lpfc_sli4_process_eq(phba, fpeq, LPFC_QUEUE_REARM);
  13981. if (unlikely(ecount == 0)) {
  13982. fpeq->EQ_no_entry++;
  13983. if (phba->intr_type == MSIX)
  13984. /* MSI-X treated interrupt served as no EQ share INT */
  13985. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  13986. "0358 MSI-X interrupt with no EQE\n");
  13987. else
  13988. /* Non MSI-X treated on interrupt as EQ share INT */
  13989. return IRQ_NONE;
  13990. }
  13991. return IRQ_HANDLED;
  13992. } /* lpfc_sli4_hba_intr_handler */
  13993. /**
  13994. * lpfc_sli4_intr_handler - Device-level interrupt handler for SLI-4 device
  13995. * @irq: Interrupt number.
  13996. * @dev_id: The device context pointer.
  13997. *
  13998. * This function is the device-level interrupt handler to device with SLI-4
  13999. * interface spec, called from the PCI layer when either MSI or Pin-IRQ
  14000. * interrupt mode is enabled and there is an event in the HBA which requires
  14001. * driver attention. This function invokes the slow-path interrupt attention
  14002. * handling function and fast-path interrupt attention handling function in
  14003. * turn to process the relevant HBA attention events. This function is called
  14004. * without any lock held. It gets the hbalock to access and update SLI data
  14005. * structures.
  14006. *
  14007. * This function returns IRQ_HANDLED when interrupt is handled, else it
  14008. * returns IRQ_NONE.
  14009. **/
  14010. irqreturn_t
  14011. lpfc_sli4_intr_handler(int irq, void *dev_id)
  14012. {
  14013. struct lpfc_hba *phba;
  14014. irqreturn_t hba_irq_rc;
  14015. bool hba_handled = false;
  14016. int qidx;
  14017. /* Get the driver's phba structure from the dev_id */
  14018. phba = (struct lpfc_hba *)dev_id;
  14019. if (unlikely(!phba))
  14020. return IRQ_NONE;
  14021. /*
  14022. * Invoke fast-path host attention interrupt handling as appropriate.
  14023. */
  14024. for (qidx = 0; qidx < phba->cfg_irq_chann; qidx++) {
  14025. hba_irq_rc = lpfc_sli4_hba_intr_handler(irq,
  14026. &phba->sli4_hba.hba_eq_hdl[qidx]);
  14027. if (hba_irq_rc == IRQ_HANDLED)
  14028. hba_handled |= true;
  14029. }
  14030. return (hba_handled == true) ? IRQ_HANDLED : IRQ_NONE;
  14031. } /* lpfc_sli4_intr_handler */
  14032. void lpfc_sli4_poll_hbtimer(struct timer_list *t)
  14033. {
  14034. struct lpfc_hba *phba = from_timer(phba, t, cpuhp_poll_timer);
  14035. struct lpfc_queue *eq;
  14036. int i = 0;
  14037. rcu_read_lock();
  14038. list_for_each_entry_rcu(eq, &phba->poll_list, _poll_list)
  14039. i += lpfc_sli4_poll_eq(eq, LPFC_POLL_SLOWPATH);
  14040. if (!list_empty(&phba->poll_list))
  14041. mod_timer(&phba->cpuhp_poll_timer,
  14042. jiffies + msecs_to_jiffies(LPFC_POLL_HB));
  14043. rcu_read_unlock();
  14044. }
  14045. inline int lpfc_sli4_poll_eq(struct lpfc_queue *eq, uint8_t path)
  14046. {
  14047. struct lpfc_hba *phba = eq->phba;
  14048. int i = 0;
  14049. /*
  14050. * Unlocking an irq is one of the entry point to check
  14051. * for re-schedule, but we are good for io submission
  14052. * path as midlayer does a get_cpu to glue us in. Flush
  14053. * out the invalidate queue so we can see the updated
  14054. * value for flag.
  14055. */
  14056. smp_rmb();
  14057. if (READ_ONCE(eq->mode) == LPFC_EQ_POLL)
  14058. /* We will not likely get the completion for the caller
  14059. * during this iteration but i guess that's fine.
  14060. * Future io's coming on this eq should be able to
  14061. * pick it up. As for the case of single io's, they
  14062. * will be handled through a sched from polling timer
  14063. * function which is currently triggered every 1msec.
  14064. */
  14065. i = lpfc_sli4_process_eq(phba, eq, LPFC_QUEUE_NOARM);
  14066. return i;
  14067. }
  14068. static inline void lpfc_sli4_add_to_poll_list(struct lpfc_queue *eq)
  14069. {
  14070. struct lpfc_hba *phba = eq->phba;
  14071. /* kickstart slowpath processing if needed */
  14072. if (list_empty(&phba->poll_list))
  14073. mod_timer(&phba->cpuhp_poll_timer,
  14074. jiffies + msecs_to_jiffies(LPFC_POLL_HB));
  14075. list_add_rcu(&eq->_poll_list, &phba->poll_list);
  14076. synchronize_rcu();
  14077. }
  14078. static inline void lpfc_sli4_remove_from_poll_list(struct lpfc_queue *eq)
  14079. {
  14080. struct lpfc_hba *phba = eq->phba;
  14081. /* Disable slowpath processing for this eq. Kick start the eq
  14082. * by RE-ARMING the eq's ASAP
  14083. */
  14084. list_del_rcu(&eq->_poll_list);
  14085. synchronize_rcu();
  14086. if (list_empty(&phba->poll_list))
  14087. del_timer_sync(&phba->cpuhp_poll_timer);
  14088. }
  14089. void lpfc_sli4_cleanup_poll_list(struct lpfc_hba *phba)
  14090. {
  14091. struct lpfc_queue *eq, *next;
  14092. list_for_each_entry_safe(eq, next, &phba->poll_list, _poll_list)
  14093. list_del(&eq->_poll_list);
  14094. INIT_LIST_HEAD(&phba->poll_list);
  14095. synchronize_rcu();
  14096. }
  14097. static inline void
  14098. __lpfc_sli4_switch_eqmode(struct lpfc_queue *eq, uint8_t mode)
  14099. {
  14100. if (mode == eq->mode)
  14101. return;
  14102. /*
  14103. * currently this function is only called during a hotplug
  14104. * event and the cpu on which this function is executing
  14105. * is going offline. By now the hotplug has instructed
  14106. * the scheduler to remove this cpu from cpu active mask.
  14107. * So we don't need to work about being put aside by the
  14108. * scheduler for a high priority process. Yes, the inte-
  14109. * rrupts could come but they are known to retire ASAP.
  14110. */
  14111. /* Disable polling in the fastpath */
  14112. WRITE_ONCE(eq->mode, mode);
  14113. /* flush out the store buffer */
  14114. smp_wmb();
  14115. /*
  14116. * Add this eq to the polling list and start polling. For
  14117. * a grace period both interrupt handler and poller will
  14118. * try to process the eq _but_ that's fine. We have a
  14119. * synchronization mechanism in place (queue_claimed) to
  14120. * deal with it. This is just a draining phase for int-
  14121. * errupt handler (not eq's) as we have guranteed through
  14122. * barrier that all the CPUs have seen the new CQ_POLLED
  14123. * state. which will effectively disable the REARMING of
  14124. * the EQ. The whole idea is eq's die off eventually as
  14125. * we are not rearming EQ's anymore.
  14126. */
  14127. mode ? lpfc_sli4_add_to_poll_list(eq) :
  14128. lpfc_sli4_remove_from_poll_list(eq);
  14129. }
  14130. void lpfc_sli4_start_polling(struct lpfc_queue *eq)
  14131. {
  14132. __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_POLL);
  14133. }
  14134. void lpfc_sli4_stop_polling(struct lpfc_queue *eq)
  14135. {
  14136. struct lpfc_hba *phba = eq->phba;
  14137. __lpfc_sli4_switch_eqmode(eq, LPFC_EQ_INTERRUPT);
  14138. /* Kick start for the pending io's in h/w.
  14139. * Once we switch back to interrupt processing on a eq
  14140. * the io path completion will only arm eq's when it
  14141. * receives a completion. But since eq's are in disa-
  14142. * rmed state it doesn't receive a completion. This
  14143. * creates a deadlock scenaro.
  14144. */
  14145. phba->sli4_hba.sli4_write_eq_db(phba, eq, 0, LPFC_QUEUE_REARM);
  14146. }
  14147. /**
  14148. * lpfc_sli4_queue_free - free a queue structure and associated memory
  14149. * @queue: The queue structure to free.
  14150. *
  14151. * This function frees a queue structure and the DMAable memory used for
  14152. * the host resident queue. This function must be called after destroying the
  14153. * queue on the HBA.
  14154. **/
  14155. void
  14156. lpfc_sli4_queue_free(struct lpfc_queue *queue)
  14157. {
  14158. struct lpfc_dmabuf *dmabuf;
  14159. if (!queue)
  14160. return;
  14161. if (!list_empty(&queue->wq_list))
  14162. list_del(&queue->wq_list);
  14163. while (!list_empty(&queue->page_list)) {
  14164. list_remove_head(&queue->page_list, dmabuf, struct lpfc_dmabuf,
  14165. list);
  14166. dma_free_coherent(&queue->phba->pcidev->dev, queue->page_size,
  14167. dmabuf->virt, dmabuf->phys);
  14168. kfree(dmabuf);
  14169. }
  14170. if (queue->rqbp) {
  14171. lpfc_free_rq_buffer(queue->phba, queue);
  14172. kfree(queue->rqbp);
  14173. }
  14174. if (!list_empty(&queue->cpu_list))
  14175. list_del(&queue->cpu_list);
  14176. kfree(queue);
  14177. return;
  14178. }
  14179. /**
  14180. * lpfc_sli4_queue_alloc - Allocate and initialize a queue structure
  14181. * @phba: The HBA that this queue is being created on.
  14182. * @page_size: The size of a queue page
  14183. * @entry_size: The size of each queue entry for this queue.
  14184. * @entry_count: The number of entries that this queue will handle.
  14185. * @cpu: The cpu that will primarily utilize this queue.
  14186. *
  14187. * This function allocates a queue structure and the DMAable memory used for
  14188. * the host resident queue. This function must be called before creating the
  14189. * queue on the HBA.
  14190. **/
  14191. struct lpfc_queue *
  14192. lpfc_sli4_queue_alloc(struct lpfc_hba *phba, uint32_t page_size,
  14193. uint32_t entry_size, uint32_t entry_count, int cpu)
  14194. {
  14195. struct lpfc_queue *queue;
  14196. struct lpfc_dmabuf *dmabuf;
  14197. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  14198. uint16_t x, pgcnt;
  14199. if (!phba->sli4_hba.pc_sli4_params.supported)
  14200. hw_page_size = page_size;
  14201. pgcnt = ALIGN(entry_size * entry_count, hw_page_size) / hw_page_size;
  14202. /* If needed, Adjust page count to match the max the adapter supports */
  14203. if (pgcnt > phba->sli4_hba.pc_sli4_params.wqpcnt)
  14204. pgcnt = phba->sli4_hba.pc_sli4_params.wqpcnt;
  14205. queue = kzalloc_node(sizeof(*queue) + (sizeof(void *) * pgcnt),
  14206. GFP_KERNEL, cpu_to_node(cpu));
  14207. if (!queue)
  14208. return NULL;
  14209. INIT_LIST_HEAD(&queue->list);
  14210. INIT_LIST_HEAD(&queue->_poll_list);
  14211. INIT_LIST_HEAD(&queue->wq_list);
  14212. INIT_LIST_HEAD(&queue->wqfull_list);
  14213. INIT_LIST_HEAD(&queue->page_list);
  14214. INIT_LIST_HEAD(&queue->child_list);
  14215. INIT_LIST_HEAD(&queue->cpu_list);
  14216. /* Set queue parameters now. If the system cannot provide memory
  14217. * resources, the free routine needs to know what was allocated.
  14218. */
  14219. queue->page_count = pgcnt;
  14220. queue->q_pgs = (void **)&queue[1];
  14221. queue->entry_cnt_per_pg = hw_page_size / entry_size;
  14222. queue->entry_size = entry_size;
  14223. queue->entry_count = entry_count;
  14224. queue->page_size = hw_page_size;
  14225. queue->phba = phba;
  14226. for (x = 0; x < queue->page_count; x++) {
  14227. dmabuf = kzalloc_node(sizeof(*dmabuf), GFP_KERNEL,
  14228. dev_to_node(&phba->pcidev->dev));
  14229. if (!dmabuf)
  14230. goto out_fail;
  14231. dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
  14232. hw_page_size, &dmabuf->phys,
  14233. GFP_KERNEL);
  14234. if (!dmabuf->virt) {
  14235. kfree(dmabuf);
  14236. goto out_fail;
  14237. }
  14238. dmabuf->buffer_tag = x;
  14239. list_add_tail(&dmabuf->list, &queue->page_list);
  14240. /* use lpfc_sli4_qe to index a paritcular entry in this page */
  14241. queue->q_pgs[x] = dmabuf->virt;
  14242. }
  14243. INIT_WORK(&queue->irqwork, lpfc_sli4_hba_process_cq);
  14244. INIT_WORK(&queue->spwork, lpfc_sli4_sp_process_cq);
  14245. INIT_DELAYED_WORK(&queue->sched_irqwork, lpfc_sli4_dly_hba_process_cq);
  14246. INIT_DELAYED_WORK(&queue->sched_spwork, lpfc_sli4_dly_sp_process_cq);
  14247. /* notify_interval will be set during q creation */
  14248. return queue;
  14249. out_fail:
  14250. lpfc_sli4_queue_free(queue);
  14251. return NULL;
  14252. }
  14253. /**
  14254. * lpfc_dual_chute_pci_bar_map - Map pci base address register to host memory
  14255. * @phba: HBA structure that indicates port to create a queue on.
  14256. * @pci_barset: PCI BAR set flag.
  14257. *
  14258. * This function shall perform iomap of the specified PCI BAR address to host
  14259. * memory address if not already done so and return it. The returned host
  14260. * memory address can be NULL.
  14261. */
  14262. static void __iomem *
  14263. lpfc_dual_chute_pci_bar_map(struct lpfc_hba *phba, uint16_t pci_barset)
  14264. {
  14265. if (!phba->pcidev)
  14266. return NULL;
  14267. switch (pci_barset) {
  14268. case WQ_PCI_BAR_0_AND_1:
  14269. return phba->pci_bar0_memmap_p;
  14270. case WQ_PCI_BAR_2_AND_3:
  14271. return phba->pci_bar2_memmap_p;
  14272. case WQ_PCI_BAR_4_AND_5:
  14273. return phba->pci_bar4_memmap_p;
  14274. default:
  14275. break;
  14276. }
  14277. return NULL;
  14278. }
  14279. /**
  14280. * lpfc_modify_hba_eq_delay - Modify Delay Multiplier on EQs
  14281. * @phba: HBA structure that EQs are on.
  14282. * @startq: The starting EQ index to modify
  14283. * @numq: The number of EQs (consecutive indexes) to modify
  14284. * @usdelay: amount of delay
  14285. *
  14286. * This function revises the EQ delay on 1 or more EQs. The EQ delay
  14287. * is set either by writing to a register (if supported by the SLI Port)
  14288. * or by mailbox command. The mailbox command allows several EQs to be
  14289. * updated at once.
  14290. *
  14291. * The @phba struct is used to send a mailbox command to HBA. The @startq
  14292. * is used to get the starting EQ index to change. The @numq value is
  14293. * used to specify how many consecutive EQ indexes, starting at EQ index,
  14294. * are to be changed. This function is asynchronous and will wait for any
  14295. * mailbox commands to finish before returning.
  14296. *
  14297. * On success this function will return a zero. If unable to allocate
  14298. * enough memory this function will return -ENOMEM. If a mailbox command
  14299. * fails this function will return -ENXIO. Note: on ENXIO, some EQs may
  14300. * have had their delay multipler changed.
  14301. **/
  14302. void
  14303. lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
  14304. uint32_t numq, uint32_t usdelay)
  14305. {
  14306. struct lpfc_mbx_modify_eq_delay *eq_delay;
  14307. LPFC_MBOXQ_t *mbox;
  14308. struct lpfc_queue *eq;
  14309. int cnt = 0, rc, length;
  14310. uint32_t shdr_status, shdr_add_status;
  14311. uint32_t dmult;
  14312. int qidx;
  14313. union lpfc_sli4_cfg_shdr *shdr;
  14314. if (startq >= phba->cfg_irq_chann)
  14315. return;
  14316. if (usdelay > 0xFFFF) {
  14317. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP | LOG_NVME,
  14318. "6429 usdelay %d too large. Scaled down to "
  14319. "0xFFFF.\n", usdelay);
  14320. usdelay = 0xFFFF;
  14321. }
  14322. /* set values by EQ_DELAY register if supported */
  14323. if (phba->sli.sli_flag & LPFC_SLI_USE_EQDR) {
  14324. for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
  14325. eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
  14326. if (!eq)
  14327. continue;
  14328. lpfc_sli4_mod_hba_eq_delay(phba, eq, usdelay);
  14329. if (++cnt >= numq)
  14330. break;
  14331. }
  14332. return;
  14333. }
  14334. /* Otherwise, set values by mailbox cmd */
  14335. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14336. if (!mbox) {
  14337. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14338. "6428 Failed allocating mailbox cmd buffer."
  14339. " EQ delay was not set.\n");
  14340. return;
  14341. }
  14342. length = (sizeof(struct lpfc_mbx_modify_eq_delay) -
  14343. sizeof(struct lpfc_sli4_cfg_mhdr));
  14344. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14345. LPFC_MBOX_OPCODE_MODIFY_EQ_DELAY,
  14346. length, LPFC_SLI4_MBX_EMBED);
  14347. eq_delay = &mbox->u.mqe.un.eq_delay;
  14348. /* Calculate delay multiper from maximum interrupt per second */
  14349. dmult = (usdelay * LPFC_DMULT_CONST) / LPFC_SEC_TO_USEC;
  14350. if (dmult)
  14351. dmult--;
  14352. if (dmult > LPFC_DMULT_MAX)
  14353. dmult = LPFC_DMULT_MAX;
  14354. for (qidx = startq; qidx < phba->cfg_irq_chann; qidx++) {
  14355. eq = phba->sli4_hba.hba_eq_hdl[qidx].eq;
  14356. if (!eq)
  14357. continue;
  14358. eq->q_mode = usdelay;
  14359. eq_delay->u.request.eq[cnt].eq_id = eq->queue_id;
  14360. eq_delay->u.request.eq[cnt].phase = 0;
  14361. eq_delay->u.request.eq[cnt].delay_multi = dmult;
  14362. if (++cnt >= numq)
  14363. break;
  14364. }
  14365. eq_delay->u.request.num_eq = cnt;
  14366. mbox->vport = phba->pport;
  14367. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14368. mbox->ctx_ndlp = NULL;
  14369. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14370. shdr = (union lpfc_sli4_cfg_shdr *) &eq_delay->header.cfg_shdr;
  14371. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14372. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14373. if (shdr_status || shdr_add_status || rc) {
  14374. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14375. "2512 MODIFY_EQ_DELAY mailbox failed with "
  14376. "status x%x add_status x%x, mbx status x%x\n",
  14377. shdr_status, shdr_add_status, rc);
  14378. }
  14379. mempool_free(mbox, phba->mbox_mem_pool);
  14380. return;
  14381. }
  14382. /**
  14383. * lpfc_eq_create - Create an Event Queue on the HBA
  14384. * @phba: HBA structure that indicates port to create a queue on.
  14385. * @eq: The queue structure to use to create the event queue.
  14386. * @imax: The maximum interrupt per second limit.
  14387. *
  14388. * This function creates an event queue, as detailed in @eq, on a port,
  14389. * described by @phba by sending an EQ_CREATE mailbox command to the HBA.
  14390. *
  14391. * The @phba struct is used to send mailbox command to HBA. The @eq struct
  14392. * is used to get the entry count and entry size that are necessary to
  14393. * determine the number of pages to allocate and use for this queue. This
  14394. * function will send the EQ_CREATE mailbox command to the HBA to setup the
  14395. * event queue. This function is asynchronous and will wait for the mailbox
  14396. * command to finish before continuing.
  14397. *
  14398. * On success this function will return a zero. If unable to allocate enough
  14399. * memory this function will return -ENOMEM. If the queue create mailbox command
  14400. * fails this function will return -ENXIO.
  14401. **/
  14402. int
  14403. lpfc_eq_create(struct lpfc_hba *phba, struct lpfc_queue *eq, uint32_t imax)
  14404. {
  14405. struct lpfc_mbx_eq_create *eq_create;
  14406. LPFC_MBOXQ_t *mbox;
  14407. int rc, length, status = 0;
  14408. struct lpfc_dmabuf *dmabuf;
  14409. uint32_t shdr_status, shdr_add_status;
  14410. union lpfc_sli4_cfg_shdr *shdr;
  14411. uint16_t dmult;
  14412. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  14413. /* sanity check on queue memory */
  14414. if (!eq)
  14415. return -ENODEV;
  14416. if (!phba->sli4_hba.pc_sli4_params.supported)
  14417. hw_page_size = SLI4_PAGE_SIZE;
  14418. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14419. if (!mbox)
  14420. return -ENOMEM;
  14421. length = (sizeof(struct lpfc_mbx_eq_create) -
  14422. sizeof(struct lpfc_sli4_cfg_mhdr));
  14423. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14424. LPFC_MBOX_OPCODE_EQ_CREATE,
  14425. length, LPFC_SLI4_MBX_EMBED);
  14426. eq_create = &mbox->u.mqe.un.eq_create;
  14427. shdr = (union lpfc_sli4_cfg_shdr *) &eq_create->header.cfg_shdr;
  14428. bf_set(lpfc_mbx_eq_create_num_pages, &eq_create->u.request,
  14429. eq->page_count);
  14430. bf_set(lpfc_eq_context_size, &eq_create->u.request.context,
  14431. LPFC_EQE_SIZE);
  14432. bf_set(lpfc_eq_context_valid, &eq_create->u.request.context, 1);
  14433. /* Use version 2 of CREATE_EQ if eqav is set */
  14434. if (phba->sli4_hba.pc_sli4_params.eqav) {
  14435. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  14436. LPFC_Q_CREATE_VERSION_2);
  14437. bf_set(lpfc_eq_context_autovalid, &eq_create->u.request.context,
  14438. phba->sli4_hba.pc_sli4_params.eqav);
  14439. }
  14440. /* don't setup delay multiplier using EQ_CREATE */
  14441. dmult = 0;
  14442. bf_set(lpfc_eq_context_delay_multi, &eq_create->u.request.context,
  14443. dmult);
  14444. switch (eq->entry_count) {
  14445. default:
  14446. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14447. "0360 Unsupported EQ count. (%d)\n",
  14448. eq->entry_count);
  14449. if (eq->entry_count < 256) {
  14450. status = -EINVAL;
  14451. goto out;
  14452. }
  14453. fallthrough; /* otherwise default to smallest count */
  14454. case 256:
  14455. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  14456. LPFC_EQ_CNT_256);
  14457. break;
  14458. case 512:
  14459. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  14460. LPFC_EQ_CNT_512);
  14461. break;
  14462. case 1024:
  14463. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  14464. LPFC_EQ_CNT_1024);
  14465. break;
  14466. case 2048:
  14467. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  14468. LPFC_EQ_CNT_2048);
  14469. break;
  14470. case 4096:
  14471. bf_set(lpfc_eq_context_count, &eq_create->u.request.context,
  14472. LPFC_EQ_CNT_4096);
  14473. break;
  14474. }
  14475. list_for_each_entry(dmabuf, &eq->page_list, list) {
  14476. memset(dmabuf->virt, 0, hw_page_size);
  14477. eq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  14478. putPaddrLow(dmabuf->phys);
  14479. eq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  14480. putPaddrHigh(dmabuf->phys);
  14481. }
  14482. mbox->vport = phba->pport;
  14483. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  14484. mbox->ctx_buf = NULL;
  14485. mbox->ctx_ndlp = NULL;
  14486. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14487. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14488. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14489. if (shdr_status || shdr_add_status || rc) {
  14490. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14491. "2500 EQ_CREATE mailbox failed with "
  14492. "status x%x add_status x%x, mbx status x%x\n",
  14493. shdr_status, shdr_add_status, rc);
  14494. status = -ENXIO;
  14495. }
  14496. eq->type = LPFC_EQ;
  14497. eq->subtype = LPFC_NONE;
  14498. eq->queue_id = bf_get(lpfc_mbx_eq_create_q_id, &eq_create->u.response);
  14499. if (eq->queue_id == 0xFFFF)
  14500. status = -ENXIO;
  14501. eq->host_index = 0;
  14502. eq->notify_interval = LPFC_EQ_NOTIFY_INTRVL;
  14503. eq->max_proc_limit = LPFC_EQ_MAX_PROC_LIMIT;
  14504. out:
  14505. mempool_free(mbox, phba->mbox_mem_pool);
  14506. return status;
  14507. }
  14508. static int lpfc_cq_poll_hdler(struct irq_poll *iop, int budget)
  14509. {
  14510. struct lpfc_queue *cq = container_of(iop, struct lpfc_queue, iop);
  14511. __lpfc_sli4_hba_process_cq(cq, LPFC_IRQ_POLL);
  14512. return 1;
  14513. }
  14514. /**
  14515. * lpfc_cq_create - Create a Completion Queue on the HBA
  14516. * @phba: HBA structure that indicates port to create a queue on.
  14517. * @cq: The queue structure to use to create the completion queue.
  14518. * @eq: The event queue to bind this completion queue to.
  14519. * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
  14520. * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
  14521. *
  14522. * This function creates a completion queue, as detailed in @wq, on a port,
  14523. * described by @phba by sending a CQ_CREATE mailbox command to the HBA.
  14524. *
  14525. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  14526. * is used to get the entry count and entry size that are necessary to
  14527. * determine the number of pages to allocate and use for this queue. The @eq
  14528. * is used to indicate which event queue to bind this completion queue to. This
  14529. * function will send the CQ_CREATE mailbox command to the HBA to setup the
  14530. * completion queue. This function is asynchronous and will wait for the mailbox
  14531. * command to finish before continuing.
  14532. *
  14533. * On success this function will return a zero. If unable to allocate enough
  14534. * memory this function will return -ENOMEM. If the queue create mailbox command
  14535. * fails this function will return -ENXIO.
  14536. **/
  14537. int
  14538. lpfc_cq_create(struct lpfc_hba *phba, struct lpfc_queue *cq,
  14539. struct lpfc_queue *eq, uint32_t type, uint32_t subtype)
  14540. {
  14541. struct lpfc_mbx_cq_create *cq_create;
  14542. struct lpfc_dmabuf *dmabuf;
  14543. LPFC_MBOXQ_t *mbox;
  14544. int rc, length, status = 0;
  14545. uint32_t shdr_status, shdr_add_status;
  14546. union lpfc_sli4_cfg_shdr *shdr;
  14547. /* sanity check on queue memory */
  14548. if (!cq || !eq)
  14549. return -ENODEV;
  14550. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14551. if (!mbox)
  14552. return -ENOMEM;
  14553. length = (sizeof(struct lpfc_mbx_cq_create) -
  14554. sizeof(struct lpfc_sli4_cfg_mhdr));
  14555. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14556. LPFC_MBOX_OPCODE_CQ_CREATE,
  14557. length, LPFC_SLI4_MBX_EMBED);
  14558. cq_create = &mbox->u.mqe.un.cq_create;
  14559. shdr = (union lpfc_sli4_cfg_shdr *) &cq_create->header.cfg_shdr;
  14560. bf_set(lpfc_mbx_cq_create_num_pages, &cq_create->u.request,
  14561. cq->page_count);
  14562. bf_set(lpfc_cq_context_event, &cq_create->u.request.context, 1);
  14563. bf_set(lpfc_cq_context_valid, &cq_create->u.request.context, 1);
  14564. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  14565. phba->sli4_hba.pc_sli4_params.cqv);
  14566. if (phba->sli4_hba.pc_sli4_params.cqv == LPFC_Q_CREATE_VERSION_2) {
  14567. bf_set(lpfc_mbx_cq_create_page_size, &cq_create->u.request,
  14568. (cq->page_size / SLI4_PAGE_SIZE));
  14569. bf_set(lpfc_cq_eq_id_2, &cq_create->u.request.context,
  14570. eq->queue_id);
  14571. bf_set(lpfc_cq_context_autovalid, &cq_create->u.request.context,
  14572. phba->sli4_hba.pc_sli4_params.cqav);
  14573. } else {
  14574. bf_set(lpfc_cq_eq_id, &cq_create->u.request.context,
  14575. eq->queue_id);
  14576. }
  14577. switch (cq->entry_count) {
  14578. case 2048:
  14579. case 4096:
  14580. if (phba->sli4_hba.pc_sli4_params.cqv ==
  14581. LPFC_Q_CREATE_VERSION_2) {
  14582. cq_create->u.request.context.lpfc_cq_context_count =
  14583. cq->entry_count;
  14584. bf_set(lpfc_cq_context_count,
  14585. &cq_create->u.request.context,
  14586. LPFC_CQ_CNT_WORD7);
  14587. break;
  14588. }
  14589. fallthrough;
  14590. default:
  14591. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14592. "0361 Unsupported CQ count: "
  14593. "entry cnt %d sz %d pg cnt %d\n",
  14594. cq->entry_count, cq->entry_size,
  14595. cq->page_count);
  14596. if (cq->entry_count < 256) {
  14597. status = -EINVAL;
  14598. goto out;
  14599. }
  14600. fallthrough; /* otherwise default to smallest count */
  14601. case 256:
  14602. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  14603. LPFC_CQ_CNT_256);
  14604. break;
  14605. case 512:
  14606. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  14607. LPFC_CQ_CNT_512);
  14608. break;
  14609. case 1024:
  14610. bf_set(lpfc_cq_context_count, &cq_create->u.request.context,
  14611. LPFC_CQ_CNT_1024);
  14612. break;
  14613. }
  14614. list_for_each_entry(dmabuf, &cq->page_list, list) {
  14615. memset(dmabuf->virt, 0, cq->page_size);
  14616. cq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  14617. putPaddrLow(dmabuf->phys);
  14618. cq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  14619. putPaddrHigh(dmabuf->phys);
  14620. }
  14621. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14622. /* The IOCTL status is embedded in the mailbox subheader. */
  14623. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14624. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14625. if (shdr_status || shdr_add_status || rc) {
  14626. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14627. "2501 CQ_CREATE mailbox failed with "
  14628. "status x%x add_status x%x, mbx status x%x\n",
  14629. shdr_status, shdr_add_status, rc);
  14630. status = -ENXIO;
  14631. goto out;
  14632. }
  14633. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  14634. if (cq->queue_id == 0xFFFF) {
  14635. status = -ENXIO;
  14636. goto out;
  14637. }
  14638. /* link the cq onto the parent eq child list */
  14639. list_add_tail(&cq->list, &eq->child_list);
  14640. /* Set up completion queue's type and subtype */
  14641. cq->type = type;
  14642. cq->subtype = subtype;
  14643. cq->queue_id = bf_get(lpfc_mbx_cq_create_q_id, &cq_create->u.response);
  14644. cq->assoc_qid = eq->queue_id;
  14645. cq->assoc_qp = eq;
  14646. cq->host_index = 0;
  14647. cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
  14648. cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit, cq->entry_count);
  14649. if (cq->queue_id > phba->sli4_hba.cq_max)
  14650. phba->sli4_hba.cq_max = cq->queue_id;
  14651. irq_poll_init(&cq->iop, LPFC_IRQ_POLL_WEIGHT, lpfc_cq_poll_hdler);
  14652. out:
  14653. mempool_free(mbox, phba->mbox_mem_pool);
  14654. return status;
  14655. }
  14656. /**
  14657. * lpfc_cq_create_set - Create a set of Completion Queues on the HBA for MRQ
  14658. * @phba: HBA structure that indicates port to create a queue on.
  14659. * @cqp: The queue structure array to use to create the completion queues.
  14660. * @hdwq: The hardware queue array with the EQ to bind completion queues to.
  14661. * @type: Type of queue (EQ, GCQ, MCQ, WCQ, etc).
  14662. * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
  14663. *
  14664. * This function creates a set of completion queue, s to support MRQ
  14665. * as detailed in @cqp, on a port,
  14666. * described by @phba by sending a CREATE_CQ_SET mailbox command to the HBA.
  14667. *
  14668. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  14669. * is used to get the entry count and entry size that are necessary to
  14670. * determine the number of pages to allocate and use for this queue. The @eq
  14671. * is used to indicate which event queue to bind this completion queue to. This
  14672. * function will send the CREATE_CQ_SET mailbox command to the HBA to setup the
  14673. * completion queue. This function is asynchronous and will wait for the mailbox
  14674. * command to finish before continuing.
  14675. *
  14676. * On success this function will return a zero. If unable to allocate enough
  14677. * memory this function will return -ENOMEM. If the queue create mailbox command
  14678. * fails this function will return -ENXIO.
  14679. **/
  14680. int
  14681. lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
  14682. struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
  14683. uint32_t subtype)
  14684. {
  14685. struct lpfc_queue *cq;
  14686. struct lpfc_queue *eq;
  14687. struct lpfc_mbx_cq_create_set *cq_set;
  14688. struct lpfc_dmabuf *dmabuf;
  14689. LPFC_MBOXQ_t *mbox;
  14690. int rc, length, alloclen, status = 0;
  14691. int cnt, idx, numcq, page_idx = 0;
  14692. uint32_t shdr_status, shdr_add_status;
  14693. union lpfc_sli4_cfg_shdr *shdr;
  14694. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  14695. /* sanity check on queue memory */
  14696. numcq = phba->cfg_nvmet_mrq;
  14697. if (!cqp || !hdwq || !numcq)
  14698. return -ENODEV;
  14699. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14700. if (!mbox)
  14701. return -ENOMEM;
  14702. length = sizeof(struct lpfc_mbx_cq_create_set);
  14703. length += ((numcq * cqp[0]->page_count) *
  14704. sizeof(struct dma_address));
  14705. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  14706. LPFC_MBOX_OPCODE_FCOE_CQ_CREATE_SET, length,
  14707. LPFC_SLI4_MBX_NEMBED);
  14708. if (alloclen < length) {
  14709. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14710. "3098 Allocated DMA memory size (%d) is "
  14711. "less than the requested DMA memory size "
  14712. "(%d)\n", alloclen, length);
  14713. status = -ENOMEM;
  14714. goto out;
  14715. }
  14716. cq_set = mbox->sge_array->addr[0];
  14717. shdr = (union lpfc_sli4_cfg_shdr *)&cq_set->cfg_shdr;
  14718. bf_set(lpfc_mbox_hdr_version, &shdr->request, 0);
  14719. for (idx = 0; idx < numcq; idx++) {
  14720. cq = cqp[idx];
  14721. eq = hdwq[idx].hba_eq;
  14722. if (!cq || !eq) {
  14723. status = -ENOMEM;
  14724. goto out;
  14725. }
  14726. if (!phba->sli4_hba.pc_sli4_params.supported)
  14727. hw_page_size = cq->page_size;
  14728. switch (idx) {
  14729. case 0:
  14730. bf_set(lpfc_mbx_cq_create_set_page_size,
  14731. &cq_set->u.request,
  14732. (hw_page_size / SLI4_PAGE_SIZE));
  14733. bf_set(lpfc_mbx_cq_create_set_num_pages,
  14734. &cq_set->u.request, cq->page_count);
  14735. bf_set(lpfc_mbx_cq_create_set_evt,
  14736. &cq_set->u.request, 1);
  14737. bf_set(lpfc_mbx_cq_create_set_valid,
  14738. &cq_set->u.request, 1);
  14739. bf_set(lpfc_mbx_cq_create_set_cqe_size,
  14740. &cq_set->u.request, 0);
  14741. bf_set(lpfc_mbx_cq_create_set_num_cq,
  14742. &cq_set->u.request, numcq);
  14743. bf_set(lpfc_mbx_cq_create_set_autovalid,
  14744. &cq_set->u.request,
  14745. phba->sli4_hba.pc_sli4_params.cqav);
  14746. switch (cq->entry_count) {
  14747. case 2048:
  14748. case 4096:
  14749. if (phba->sli4_hba.pc_sli4_params.cqv ==
  14750. LPFC_Q_CREATE_VERSION_2) {
  14751. bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
  14752. &cq_set->u.request,
  14753. cq->entry_count);
  14754. bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
  14755. &cq_set->u.request,
  14756. LPFC_CQ_CNT_WORD7);
  14757. break;
  14758. }
  14759. fallthrough;
  14760. default:
  14761. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14762. "3118 Bad CQ count. (%d)\n",
  14763. cq->entry_count);
  14764. if (cq->entry_count < 256) {
  14765. status = -EINVAL;
  14766. goto out;
  14767. }
  14768. fallthrough; /* otherwise default to smallest */
  14769. case 256:
  14770. bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
  14771. &cq_set->u.request, LPFC_CQ_CNT_256);
  14772. break;
  14773. case 512:
  14774. bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
  14775. &cq_set->u.request, LPFC_CQ_CNT_512);
  14776. break;
  14777. case 1024:
  14778. bf_set(lpfc_mbx_cq_create_set_cqe_cnt,
  14779. &cq_set->u.request, LPFC_CQ_CNT_1024);
  14780. break;
  14781. }
  14782. bf_set(lpfc_mbx_cq_create_set_eq_id0,
  14783. &cq_set->u.request, eq->queue_id);
  14784. break;
  14785. case 1:
  14786. bf_set(lpfc_mbx_cq_create_set_eq_id1,
  14787. &cq_set->u.request, eq->queue_id);
  14788. break;
  14789. case 2:
  14790. bf_set(lpfc_mbx_cq_create_set_eq_id2,
  14791. &cq_set->u.request, eq->queue_id);
  14792. break;
  14793. case 3:
  14794. bf_set(lpfc_mbx_cq_create_set_eq_id3,
  14795. &cq_set->u.request, eq->queue_id);
  14796. break;
  14797. case 4:
  14798. bf_set(lpfc_mbx_cq_create_set_eq_id4,
  14799. &cq_set->u.request, eq->queue_id);
  14800. break;
  14801. case 5:
  14802. bf_set(lpfc_mbx_cq_create_set_eq_id5,
  14803. &cq_set->u.request, eq->queue_id);
  14804. break;
  14805. case 6:
  14806. bf_set(lpfc_mbx_cq_create_set_eq_id6,
  14807. &cq_set->u.request, eq->queue_id);
  14808. break;
  14809. case 7:
  14810. bf_set(lpfc_mbx_cq_create_set_eq_id7,
  14811. &cq_set->u.request, eq->queue_id);
  14812. break;
  14813. case 8:
  14814. bf_set(lpfc_mbx_cq_create_set_eq_id8,
  14815. &cq_set->u.request, eq->queue_id);
  14816. break;
  14817. case 9:
  14818. bf_set(lpfc_mbx_cq_create_set_eq_id9,
  14819. &cq_set->u.request, eq->queue_id);
  14820. break;
  14821. case 10:
  14822. bf_set(lpfc_mbx_cq_create_set_eq_id10,
  14823. &cq_set->u.request, eq->queue_id);
  14824. break;
  14825. case 11:
  14826. bf_set(lpfc_mbx_cq_create_set_eq_id11,
  14827. &cq_set->u.request, eq->queue_id);
  14828. break;
  14829. case 12:
  14830. bf_set(lpfc_mbx_cq_create_set_eq_id12,
  14831. &cq_set->u.request, eq->queue_id);
  14832. break;
  14833. case 13:
  14834. bf_set(lpfc_mbx_cq_create_set_eq_id13,
  14835. &cq_set->u.request, eq->queue_id);
  14836. break;
  14837. case 14:
  14838. bf_set(lpfc_mbx_cq_create_set_eq_id14,
  14839. &cq_set->u.request, eq->queue_id);
  14840. break;
  14841. case 15:
  14842. bf_set(lpfc_mbx_cq_create_set_eq_id15,
  14843. &cq_set->u.request, eq->queue_id);
  14844. break;
  14845. }
  14846. /* link the cq onto the parent eq child list */
  14847. list_add_tail(&cq->list, &eq->child_list);
  14848. /* Set up completion queue's type and subtype */
  14849. cq->type = type;
  14850. cq->subtype = subtype;
  14851. cq->assoc_qid = eq->queue_id;
  14852. cq->assoc_qp = eq;
  14853. cq->host_index = 0;
  14854. cq->notify_interval = LPFC_CQ_NOTIFY_INTRVL;
  14855. cq->max_proc_limit = min(phba->cfg_cq_max_proc_limit,
  14856. cq->entry_count);
  14857. cq->chann = idx;
  14858. rc = 0;
  14859. list_for_each_entry(dmabuf, &cq->page_list, list) {
  14860. memset(dmabuf->virt, 0, hw_page_size);
  14861. cnt = page_idx + dmabuf->buffer_tag;
  14862. cq_set->u.request.page[cnt].addr_lo =
  14863. putPaddrLow(dmabuf->phys);
  14864. cq_set->u.request.page[cnt].addr_hi =
  14865. putPaddrHigh(dmabuf->phys);
  14866. rc++;
  14867. }
  14868. page_idx += rc;
  14869. }
  14870. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  14871. /* The IOCTL status is embedded in the mailbox subheader. */
  14872. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  14873. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  14874. if (shdr_status || shdr_add_status || rc) {
  14875. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  14876. "3119 CQ_CREATE_SET mailbox failed with "
  14877. "status x%x add_status x%x, mbx status x%x\n",
  14878. shdr_status, shdr_add_status, rc);
  14879. status = -ENXIO;
  14880. goto out;
  14881. }
  14882. rc = bf_get(lpfc_mbx_cq_create_set_base_id, &cq_set->u.response);
  14883. if (rc == 0xFFFF) {
  14884. status = -ENXIO;
  14885. goto out;
  14886. }
  14887. for (idx = 0; idx < numcq; idx++) {
  14888. cq = cqp[idx];
  14889. cq->queue_id = rc + idx;
  14890. if (cq->queue_id > phba->sli4_hba.cq_max)
  14891. phba->sli4_hba.cq_max = cq->queue_id;
  14892. }
  14893. out:
  14894. lpfc_sli4_mbox_cmd_free(phba, mbox);
  14895. return status;
  14896. }
  14897. /**
  14898. * lpfc_mq_create_fb_init - Send MCC_CREATE without async events registration
  14899. * @phba: HBA structure that indicates port to create a queue on.
  14900. * @mq: The queue structure to use to create the mailbox queue.
  14901. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  14902. * @cq: The completion queue to associate with this cq.
  14903. *
  14904. * This function provides failback (fb) functionality when the
  14905. * mq_create_ext fails on older FW generations. It's purpose is identical
  14906. * to mq_create_ext otherwise.
  14907. *
  14908. * This routine cannot fail as all attributes were previously accessed and
  14909. * initialized in mq_create_ext.
  14910. **/
  14911. static void
  14912. lpfc_mq_create_fb_init(struct lpfc_hba *phba, struct lpfc_queue *mq,
  14913. LPFC_MBOXQ_t *mbox, struct lpfc_queue *cq)
  14914. {
  14915. struct lpfc_mbx_mq_create *mq_create;
  14916. struct lpfc_dmabuf *dmabuf;
  14917. int length;
  14918. length = (sizeof(struct lpfc_mbx_mq_create) -
  14919. sizeof(struct lpfc_sli4_cfg_mhdr));
  14920. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14921. LPFC_MBOX_OPCODE_MQ_CREATE,
  14922. length, LPFC_SLI4_MBX_EMBED);
  14923. mq_create = &mbox->u.mqe.un.mq_create;
  14924. bf_set(lpfc_mbx_mq_create_num_pages, &mq_create->u.request,
  14925. mq->page_count);
  14926. bf_set(lpfc_mq_context_cq_id, &mq_create->u.request.context,
  14927. cq->queue_id);
  14928. bf_set(lpfc_mq_context_valid, &mq_create->u.request.context, 1);
  14929. switch (mq->entry_count) {
  14930. case 16:
  14931. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  14932. LPFC_MQ_RING_SIZE_16);
  14933. break;
  14934. case 32:
  14935. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  14936. LPFC_MQ_RING_SIZE_32);
  14937. break;
  14938. case 64:
  14939. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  14940. LPFC_MQ_RING_SIZE_64);
  14941. break;
  14942. case 128:
  14943. bf_set(lpfc_mq_context_ring_size, &mq_create->u.request.context,
  14944. LPFC_MQ_RING_SIZE_128);
  14945. break;
  14946. }
  14947. list_for_each_entry(dmabuf, &mq->page_list, list) {
  14948. mq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  14949. putPaddrLow(dmabuf->phys);
  14950. mq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  14951. putPaddrHigh(dmabuf->phys);
  14952. }
  14953. }
  14954. /**
  14955. * lpfc_mq_create - Create a mailbox Queue on the HBA
  14956. * @phba: HBA structure that indicates port to create a queue on.
  14957. * @mq: The queue structure to use to create the mailbox queue.
  14958. * @cq: The completion queue to associate with this cq.
  14959. * @subtype: The queue's subtype.
  14960. *
  14961. * This function creates a mailbox queue, as detailed in @mq, on a port,
  14962. * described by @phba by sending a MQ_CREATE mailbox command to the HBA.
  14963. *
  14964. * The @phba struct is used to send mailbox command to HBA. The @cq struct
  14965. * is used to get the entry count and entry size that are necessary to
  14966. * determine the number of pages to allocate and use for this queue. This
  14967. * function will send the MQ_CREATE mailbox command to the HBA to setup the
  14968. * mailbox queue. This function is asynchronous and will wait for the mailbox
  14969. * command to finish before continuing.
  14970. *
  14971. * On success this function will return a zero. If unable to allocate enough
  14972. * memory this function will return -ENOMEM. If the queue create mailbox command
  14973. * fails this function will return -ENXIO.
  14974. **/
  14975. int32_t
  14976. lpfc_mq_create(struct lpfc_hba *phba, struct lpfc_queue *mq,
  14977. struct lpfc_queue *cq, uint32_t subtype)
  14978. {
  14979. struct lpfc_mbx_mq_create *mq_create;
  14980. struct lpfc_mbx_mq_create_ext *mq_create_ext;
  14981. struct lpfc_dmabuf *dmabuf;
  14982. LPFC_MBOXQ_t *mbox;
  14983. int rc, length, status = 0;
  14984. uint32_t shdr_status, shdr_add_status;
  14985. union lpfc_sli4_cfg_shdr *shdr;
  14986. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  14987. /* sanity check on queue memory */
  14988. if (!mq || !cq)
  14989. return -ENODEV;
  14990. if (!phba->sli4_hba.pc_sli4_params.supported)
  14991. hw_page_size = SLI4_PAGE_SIZE;
  14992. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  14993. if (!mbox)
  14994. return -ENOMEM;
  14995. length = (sizeof(struct lpfc_mbx_mq_create_ext) -
  14996. sizeof(struct lpfc_sli4_cfg_mhdr));
  14997. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  14998. LPFC_MBOX_OPCODE_MQ_CREATE_EXT,
  14999. length, LPFC_SLI4_MBX_EMBED);
  15000. mq_create_ext = &mbox->u.mqe.un.mq_create_ext;
  15001. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create_ext->header.cfg_shdr;
  15002. bf_set(lpfc_mbx_mq_create_ext_num_pages,
  15003. &mq_create_ext->u.request, mq->page_count);
  15004. bf_set(lpfc_mbx_mq_create_ext_async_evt_link,
  15005. &mq_create_ext->u.request, 1);
  15006. bf_set(lpfc_mbx_mq_create_ext_async_evt_fip,
  15007. &mq_create_ext->u.request, 1);
  15008. bf_set(lpfc_mbx_mq_create_ext_async_evt_group5,
  15009. &mq_create_ext->u.request, 1);
  15010. bf_set(lpfc_mbx_mq_create_ext_async_evt_fc,
  15011. &mq_create_ext->u.request, 1);
  15012. bf_set(lpfc_mbx_mq_create_ext_async_evt_sli,
  15013. &mq_create_ext->u.request, 1);
  15014. bf_set(lpfc_mq_context_valid, &mq_create_ext->u.request.context, 1);
  15015. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  15016. phba->sli4_hba.pc_sli4_params.mqv);
  15017. if (phba->sli4_hba.pc_sli4_params.mqv == LPFC_Q_CREATE_VERSION_1)
  15018. bf_set(lpfc_mbx_mq_create_ext_cq_id, &mq_create_ext->u.request,
  15019. cq->queue_id);
  15020. else
  15021. bf_set(lpfc_mq_context_cq_id, &mq_create_ext->u.request.context,
  15022. cq->queue_id);
  15023. switch (mq->entry_count) {
  15024. default:
  15025. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15026. "0362 Unsupported MQ count. (%d)\n",
  15027. mq->entry_count);
  15028. if (mq->entry_count < 16) {
  15029. status = -EINVAL;
  15030. goto out;
  15031. }
  15032. fallthrough; /* otherwise default to smallest count */
  15033. case 16:
  15034. bf_set(lpfc_mq_context_ring_size,
  15035. &mq_create_ext->u.request.context,
  15036. LPFC_MQ_RING_SIZE_16);
  15037. break;
  15038. case 32:
  15039. bf_set(lpfc_mq_context_ring_size,
  15040. &mq_create_ext->u.request.context,
  15041. LPFC_MQ_RING_SIZE_32);
  15042. break;
  15043. case 64:
  15044. bf_set(lpfc_mq_context_ring_size,
  15045. &mq_create_ext->u.request.context,
  15046. LPFC_MQ_RING_SIZE_64);
  15047. break;
  15048. case 128:
  15049. bf_set(lpfc_mq_context_ring_size,
  15050. &mq_create_ext->u.request.context,
  15051. LPFC_MQ_RING_SIZE_128);
  15052. break;
  15053. }
  15054. list_for_each_entry(dmabuf, &mq->page_list, list) {
  15055. memset(dmabuf->virt, 0, hw_page_size);
  15056. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_lo =
  15057. putPaddrLow(dmabuf->phys);
  15058. mq_create_ext->u.request.page[dmabuf->buffer_tag].addr_hi =
  15059. putPaddrHigh(dmabuf->phys);
  15060. }
  15061. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15062. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  15063. &mq_create_ext->u.response);
  15064. if (rc != MBX_SUCCESS) {
  15065. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15066. "2795 MQ_CREATE_EXT failed with "
  15067. "status x%x. Failback to MQ_CREATE.\n",
  15068. rc);
  15069. lpfc_mq_create_fb_init(phba, mq, mbox, cq);
  15070. mq_create = &mbox->u.mqe.un.mq_create;
  15071. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15072. shdr = (union lpfc_sli4_cfg_shdr *) &mq_create->header.cfg_shdr;
  15073. mq->queue_id = bf_get(lpfc_mbx_mq_create_q_id,
  15074. &mq_create->u.response);
  15075. }
  15076. /* The IOCTL status is embedded in the mailbox subheader. */
  15077. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15078. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15079. if (shdr_status || shdr_add_status || rc) {
  15080. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15081. "2502 MQ_CREATE mailbox failed with "
  15082. "status x%x add_status x%x, mbx status x%x\n",
  15083. shdr_status, shdr_add_status, rc);
  15084. status = -ENXIO;
  15085. goto out;
  15086. }
  15087. if (mq->queue_id == 0xFFFF) {
  15088. status = -ENXIO;
  15089. goto out;
  15090. }
  15091. mq->type = LPFC_MQ;
  15092. mq->assoc_qid = cq->queue_id;
  15093. mq->subtype = subtype;
  15094. mq->host_index = 0;
  15095. mq->hba_index = 0;
  15096. /* link the mq onto the parent cq child list */
  15097. list_add_tail(&mq->list, &cq->child_list);
  15098. out:
  15099. mempool_free(mbox, phba->mbox_mem_pool);
  15100. return status;
  15101. }
  15102. /**
  15103. * lpfc_wq_create - Create a Work Queue on the HBA
  15104. * @phba: HBA structure that indicates port to create a queue on.
  15105. * @wq: The queue structure to use to create the work queue.
  15106. * @cq: The completion queue to bind this work queue to.
  15107. * @subtype: The subtype of the work queue indicating its functionality.
  15108. *
  15109. * This function creates a work queue, as detailed in @wq, on a port, described
  15110. * by @phba by sending a WQ_CREATE mailbox command to the HBA.
  15111. *
  15112. * The @phba struct is used to send mailbox command to HBA. The @wq struct
  15113. * is used to get the entry count and entry size that are necessary to
  15114. * determine the number of pages to allocate and use for this queue. The @cq
  15115. * is used to indicate which completion queue to bind this work queue to. This
  15116. * function will send the WQ_CREATE mailbox command to the HBA to setup the
  15117. * work queue. This function is asynchronous and will wait for the mailbox
  15118. * command to finish before continuing.
  15119. *
  15120. * On success this function will return a zero. If unable to allocate enough
  15121. * memory this function will return -ENOMEM. If the queue create mailbox command
  15122. * fails this function will return -ENXIO.
  15123. **/
  15124. int
  15125. lpfc_wq_create(struct lpfc_hba *phba, struct lpfc_queue *wq,
  15126. struct lpfc_queue *cq, uint32_t subtype)
  15127. {
  15128. struct lpfc_mbx_wq_create *wq_create;
  15129. struct lpfc_dmabuf *dmabuf;
  15130. LPFC_MBOXQ_t *mbox;
  15131. int rc, length, status = 0;
  15132. uint32_t shdr_status, shdr_add_status;
  15133. union lpfc_sli4_cfg_shdr *shdr;
  15134. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  15135. struct dma_address *page;
  15136. void __iomem *bar_memmap_p;
  15137. uint32_t db_offset;
  15138. uint16_t pci_barset;
  15139. uint8_t dpp_barset;
  15140. uint32_t dpp_offset;
  15141. uint8_t wq_create_version;
  15142. #ifdef CONFIG_X86
  15143. unsigned long pg_addr;
  15144. #endif
  15145. /* sanity check on queue memory */
  15146. if (!wq || !cq)
  15147. return -ENODEV;
  15148. if (!phba->sli4_hba.pc_sli4_params.supported)
  15149. hw_page_size = wq->page_size;
  15150. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15151. if (!mbox)
  15152. return -ENOMEM;
  15153. length = (sizeof(struct lpfc_mbx_wq_create) -
  15154. sizeof(struct lpfc_sli4_cfg_mhdr));
  15155. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15156. LPFC_MBOX_OPCODE_FCOE_WQ_CREATE,
  15157. length, LPFC_SLI4_MBX_EMBED);
  15158. wq_create = &mbox->u.mqe.un.wq_create;
  15159. shdr = (union lpfc_sli4_cfg_shdr *) &wq_create->header.cfg_shdr;
  15160. bf_set(lpfc_mbx_wq_create_num_pages, &wq_create->u.request,
  15161. wq->page_count);
  15162. bf_set(lpfc_mbx_wq_create_cq_id, &wq_create->u.request,
  15163. cq->queue_id);
  15164. /* wqv is the earliest version supported, NOT the latest */
  15165. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  15166. phba->sli4_hba.pc_sli4_params.wqv);
  15167. if ((phba->sli4_hba.pc_sli4_params.wqsize & LPFC_WQ_SZ128_SUPPORT) ||
  15168. (wq->page_size > SLI4_PAGE_SIZE))
  15169. wq_create_version = LPFC_Q_CREATE_VERSION_1;
  15170. else
  15171. wq_create_version = LPFC_Q_CREATE_VERSION_0;
  15172. switch (wq_create_version) {
  15173. case LPFC_Q_CREATE_VERSION_1:
  15174. bf_set(lpfc_mbx_wq_create_wqe_count, &wq_create->u.request_1,
  15175. wq->entry_count);
  15176. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  15177. LPFC_Q_CREATE_VERSION_1);
  15178. switch (wq->entry_size) {
  15179. default:
  15180. case 64:
  15181. bf_set(lpfc_mbx_wq_create_wqe_size,
  15182. &wq_create->u.request_1,
  15183. LPFC_WQ_WQE_SIZE_64);
  15184. break;
  15185. case 128:
  15186. bf_set(lpfc_mbx_wq_create_wqe_size,
  15187. &wq_create->u.request_1,
  15188. LPFC_WQ_WQE_SIZE_128);
  15189. break;
  15190. }
  15191. /* Request DPP by default */
  15192. bf_set(lpfc_mbx_wq_create_dpp_req, &wq_create->u.request_1, 1);
  15193. bf_set(lpfc_mbx_wq_create_page_size,
  15194. &wq_create->u.request_1,
  15195. (wq->page_size / SLI4_PAGE_SIZE));
  15196. page = wq_create->u.request_1.page;
  15197. break;
  15198. default:
  15199. page = wq_create->u.request.page;
  15200. break;
  15201. }
  15202. list_for_each_entry(dmabuf, &wq->page_list, list) {
  15203. memset(dmabuf->virt, 0, hw_page_size);
  15204. page[dmabuf->buffer_tag].addr_lo = putPaddrLow(dmabuf->phys);
  15205. page[dmabuf->buffer_tag].addr_hi = putPaddrHigh(dmabuf->phys);
  15206. }
  15207. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  15208. bf_set(lpfc_mbx_wq_create_dua, &wq_create->u.request, 1);
  15209. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15210. /* The IOCTL status is embedded in the mailbox subheader. */
  15211. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15212. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15213. if (shdr_status || shdr_add_status || rc) {
  15214. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15215. "2503 WQ_CREATE mailbox failed with "
  15216. "status x%x add_status x%x, mbx status x%x\n",
  15217. shdr_status, shdr_add_status, rc);
  15218. status = -ENXIO;
  15219. goto out;
  15220. }
  15221. if (wq_create_version == LPFC_Q_CREATE_VERSION_0)
  15222. wq->queue_id = bf_get(lpfc_mbx_wq_create_q_id,
  15223. &wq_create->u.response);
  15224. else
  15225. wq->queue_id = bf_get(lpfc_mbx_wq_create_v1_q_id,
  15226. &wq_create->u.response_1);
  15227. if (wq->queue_id == 0xFFFF) {
  15228. status = -ENXIO;
  15229. goto out;
  15230. }
  15231. wq->db_format = LPFC_DB_LIST_FORMAT;
  15232. if (wq_create_version == LPFC_Q_CREATE_VERSION_0) {
  15233. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  15234. wq->db_format = bf_get(lpfc_mbx_wq_create_db_format,
  15235. &wq_create->u.response);
  15236. if ((wq->db_format != LPFC_DB_LIST_FORMAT) &&
  15237. (wq->db_format != LPFC_DB_RING_FORMAT)) {
  15238. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15239. "3265 WQ[%d] doorbell format "
  15240. "not supported: x%x\n",
  15241. wq->queue_id, wq->db_format);
  15242. status = -EINVAL;
  15243. goto out;
  15244. }
  15245. pci_barset = bf_get(lpfc_mbx_wq_create_bar_set,
  15246. &wq_create->u.response);
  15247. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
  15248. pci_barset);
  15249. if (!bar_memmap_p) {
  15250. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15251. "3263 WQ[%d] failed to memmap "
  15252. "pci barset:x%x\n",
  15253. wq->queue_id, pci_barset);
  15254. status = -ENOMEM;
  15255. goto out;
  15256. }
  15257. db_offset = wq_create->u.response.doorbell_offset;
  15258. if ((db_offset != LPFC_ULP0_WQ_DOORBELL) &&
  15259. (db_offset != LPFC_ULP1_WQ_DOORBELL)) {
  15260. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15261. "3252 WQ[%d] doorbell offset "
  15262. "not supported: x%x\n",
  15263. wq->queue_id, db_offset);
  15264. status = -EINVAL;
  15265. goto out;
  15266. }
  15267. wq->db_regaddr = bar_memmap_p + db_offset;
  15268. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15269. "3264 WQ[%d]: barset:x%x, offset:x%x, "
  15270. "format:x%x\n", wq->queue_id,
  15271. pci_barset, db_offset, wq->db_format);
  15272. } else
  15273. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  15274. } else {
  15275. /* Check if DPP was honored by the firmware */
  15276. wq->dpp_enable = bf_get(lpfc_mbx_wq_create_dpp_rsp,
  15277. &wq_create->u.response_1);
  15278. if (wq->dpp_enable) {
  15279. pci_barset = bf_get(lpfc_mbx_wq_create_v1_bar_set,
  15280. &wq_create->u.response_1);
  15281. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
  15282. pci_barset);
  15283. if (!bar_memmap_p) {
  15284. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15285. "3267 WQ[%d] failed to memmap "
  15286. "pci barset:x%x\n",
  15287. wq->queue_id, pci_barset);
  15288. status = -ENOMEM;
  15289. goto out;
  15290. }
  15291. db_offset = wq_create->u.response_1.doorbell_offset;
  15292. wq->db_regaddr = bar_memmap_p + db_offset;
  15293. wq->dpp_id = bf_get(lpfc_mbx_wq_create_dpp_id,
  15294. &wq_create->u.response_1);
  15295. dpp_barset = bf_get(lpfc_mbx_wq_create_dpp_bar,
  15296. &wq_create->u.response_1);
  15297. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba,
  15298. dpp_barset);
  15299. if (!bar_memmap_p) {
  15300. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15301. "3268 WQ[%d] failed to memmap "
  15302. "pci barset:x%x\n",
  15303. wq->queue_id, dpp_barset);
  15304. status = -ENOMEM;
  15305. goto out;
  15306. }
  15307. dpp_offset = wq_create->u.response_1.dpp_offset;
  15308. wq->dpp_regaddr = bar_memmap_p + dpp_offset;
  15309. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15310. "3271 WQ[%d]: barset:x%x, offset:x%x, "
  15311. "dpp_id:x%x dpp_barset:x%x "
  15312. "dpp_offset:x%x\n",
  15313. wq->queue_id, pci_barset, db_offset,
  15314. wq->dpp_id, dpp_barset, dpp_offset);
  15315. #ifdef CONFIG_X86
  15316. /* Enable combined writes for DPP aperture */
  15317. pg_addr = (unsigned long)(wq->dpp_regaddr) & PAGE_MASK;
  15318. rc = set_memory_wc(pg_addr, 1);
  15319. if (rc) {
  15320. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  15321. "3272 Cannot setup Combined "
  15322. "Write on WQ[%d] - disable DPP\n",
  15323. wq->queue_id);
  15324. phba->cfg_enable_dpp = 0;
  15325. }
  15326. #else
  15327. phba->cfg_enable_dpp = 0;
  15328. #endif
  15329. } else
  15330. wq->db_regaddr = phba->sli4_hba.WQDBregaddr;
  15331. }
  15332. wq->pring = kzalloc(sizeof(struct lpfc_sli_ring), GFP_KERNEL);
  15333. if (wq->pring == NULL) {
  15334. status = -ENOMEM;
  15335. goto out;
  15336. }
  15337. wq->type = LPFC_WQ;
  15338. wq->assoc_qid = cq->queue_id;
  15339. wq->subtype = subtype;
  15340. wq->host_index = 0;
  15341. wq->hba_index = 0;
  15342. wq->notify_interval = LPFC_WQ_NOTIFY_INTRVL;
  15343. /* link the wq onto the parent cq child list */
  15344. list_add_tail(&wq->list, &cq->child_list);
  15345. out:
  15346. mempool_free(mbox, phba->mbox_mem_pool);
  15347. return status;
  15348. }
  15349. /**
  15350. * lpfc_rq_create - Create a Receive Queue on the HBA
  15351. * @phba: HBA structure that indicates port to create a queue on.
  15352. * @hrq: The queue structure to use to create the header receive queue.
  15353. * @drq: The queue structure to use to create the data receive queue.
  15354. * @cq: The completion queue to bind this work queue to.
  15355. * @subtype: The subtype of the work queue indicating its functionality.
  15356. *
  15357. * This function creates a receive buffer queue pair , as detailed in @hrq and
  15358. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  15359. * to the HBA.
  15360. *
  15361. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  15362. * struct is used to get the entry count that is necessary to determine the
  15363. * number of pages to use for this queue. The @cq is used to indicate which
  15364. * completion queue to bind received buffers that are posted to these queues to.
  15365. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  15366. * receive queue pair. This function is asynchronous and will wait for the
  15367. * mailbox command to finish before continuing.
  15368. *
  15369. * On success this function will return a zero. If unable to allocate enough
  15370. * memory this function will return -ENOMEM. If the queue create mailbox command
  15371. * fails this function will return -ENXIO.
  15372. **/
  15373. int
  15374. lpfc_rq_create(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  15375. struct lpfc_queue *drq, struct lpfc_queue *cq, uint32_t subtype)
  15376. {
  15377. struct lpfc_mbx_rq_create *rq_create;
  15378. struct lpfc_dmabuf *dmabuf;
  15379. LPFC_MBOXQ_t *mbox;
  15380. int rc, length, status = 0;
  15381. uint32_t shdr_status, shdr_add_status;
  15382. union lpfc_sli4_cfg_shdr *shdr;
  15383. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  15384. void __iomem *bar_memmap_p;
  15385. uint32_t db_offset;
  15386. uint16_t pci_barset;
  15387. /* sanity check on queue memory */
  15388. if (!hrq || !drq || !cq)
  15389. return -ENODEV;
  15390. if (!phba->sli4_hba.pc_sli4_params.supported)
  15391. hw_page_size = SLI4_PAGE_SIZE;
  15392. if (hrq->entry_count != drq->entry_count)
  15393. return -EINVAL;
  15394. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15395. if (!mbox)
  15396. return -ENOMEM;
  15397. length = (sizeof(struct lpfc_mbx_rq_create) -
  15398. sizeof(struct lpfc_sli4_cfg_mhdr));
  15399. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15400. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  15401. length, LPFC_SLI4_MBX_EMBED);
  15402. rq_create = &mbox->u.mqe.un.rq_create;
  15403. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  15404. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  15405. phba->sli4_hba.pc_sli4_params.rqv);
  15406. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  15407. bf_set(lpfc_rq_context_rqe_count_1,
  15408. &rq_create->u.request.context,
  15409. hrq->entry_count);
  15410. rq_create->u.request.context.buffer_size = LPFC_HDR_BUF_SIZE;
  15411. bf_set(lpfc_rq_context_rqe_size,
  15412. &rq_create->u.request.context,
  15413. LPFC_RQE_SIZE_8);
  15414. bf_set(lpfc_rq_context_page_size,
  15415. &rq_create->u.request.context,
  15416. LPFC_RQ_PAGE_SIZE_4096);
  15417. } else {
  15418. switch (hrq->entry_count) {
  15419. default:
  15420. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15421. "2535 Unsupported RQ count. (%d)\n",
  15422. hrq->entry_count);
  15423. if (hrq->entry_count < 512) {
  15424. status = -EINVAL;
  15425. goto out;
  15426. }
  15427. fallthrough; /* otherwise default to smallest count */
  15428. case 512:
  15429. bf_set(lpfc_rq_context_rqe_count,
  15430. &rq_create->u.request.context,
  15431. LPFC_RQ_RING_SIZE_512);
  15432. break;
  15433. case 1024:
  15434. bf_set(lpfc_rq_context_rqe_count,
  15435. &rq_create->u.request.context,
  15436. LPFC_RQ_RING_SIZE_1024);
  15437. break;
  15438. case 2048:
  15439. bf_set(lpfc_rq_context_rqe_count,
  15440. &rq_create->u.request.context,
  15441. LPFC_RQ_RING_SIZE_2048);
  15442. break;
  15443. case 4096:
  15444. bf_set(lpfc_rq_context_rqe_count,
  15445. &rq_create->u.request.context,
  15446. LPFC_RQ_RING_SIZE_4096);
  15447. break;
  15448. }
  15449. bf_set(lpfc_rq_context_buf_size, &rq_create->u.request.context,
  15450. LPFC_HDR_BUF_SIZE);
  15451. }
  15452. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  15453. cq->queue_id);
  15454. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  15455. hrq->page_count);
  15456. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  15457. memset(dmabuf->virt, 0, hw_page_size);
  15458. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  15459. putPaddrLow(dmabuf->phys);
  15460. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  15461. putPaddrHigh(dmabuf->phys);
  15462. }
  15463. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  15464. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  15465. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15466. /* The IOCTL status is embedded in the mailbox subheader. */
  15467. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15468. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15469. if (shdr_status || shdr_add_status || rc) {
  15470. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15471. "2504 RQ_CREATE mailbox failed with "
  15472. "status x%x add_status x%x, mbx status x%x\n",
  15473. shdr_status, shdr_add_status, rc);
  15474. status = -ENXIO;
  15475. goto out;
  15476. }
  15477. hrq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  15478. if (hrq->queue_id == 0xFFFF) {
  15479. status = -ENXIO;
  15480. goto out;
  15481. }
  15482. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE) {
  15483. hrq->db_format = bf_get(lpfc_mbx_rq_create_db_format,
  15484. &rq_create->u.response);
  15485. if ((hrq->db_format != LPFC_DB_LIST_FORMAT) &&
  15486. (hrq->db_format != LPFC_DB_RING_FORMAT)) {
  15487. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15488. "3262 RQ [%d] doorbell format not "
  15489. "supported: x%x\n", hrq->queue_id,
  15490. hrq->db_format);
  15491. status = -EINVAL;
  15492. goto out;
  15493. }
  15494. pci_barset = bf_get(lpfc_mbx_rq_create_bar_set,
  15495. &rq_create->u.response);
  15496. bar_memmap_p = lpfc_dual_chute_pci_bar_map(phba, pci_barset);
  15497. if (!bar_memmap_p) {
  15498. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15499. "3269 RQ[%d] failed to memmap pci "
  15500. "barset:x%x\n", hrq->queue_id,
  15501. pci_barset);
  15502. status = -ENOMEM;
  15503. goto out;
  15504. }
  15505. db_offset = rq_create->u.response.doorbell_offset;
  15506. if ((db_offset != LPFC_ULP0_RQ_DOORBELL) &&
  15507. (db_offset != LPFC_ULP1_RQ_DOORBELL)) {
  15508. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15509. "3270 RQ[%d] doorbell offset not "
  15510. "supported: x%x\n", hrq->queue_id,
  15511. db_offset);
  15512. status = -EINVAL;
  15513. goto out;
  15514. }
  15515. hrq->db_regaddr = bar_memmap_p + db_offset;
  15516. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  15517. "3266 RQ[qid:%d]: barset:x%x, offset:x%x, "
  15518. "format:x%x\n", hrq->queue_id, pci_barset,
  15519. db_offset, hrq->db_format);
  15520. } else {
  15521. hrq->db_format = LPFC_DB_RING_FORMAT;
  15522. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  15523. }
  15524. hrq->type = LPFC_HRQ;
  15525. hrq->assoc_qid = cq->queue_id;
  15526. hrq->subtype = subtype;
  15527. hrq->host_index = 0;
  15528. hrq->hba_index = 0;
  15529. hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
  15530. /* now create the data queue */
  15531. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15532. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE,
  15533. length, LPFC_SLI4_MBX_EMBED);
  15534. bf_set(lpfc_mbox_hdr_version, &shdr->request,
  15535. phba->sli4_hba.pc_sli4_params.rqv);
  15536. if (phba->sli4_hba.pc_sli4_params.rqv == LPFC_Q_CREATE_VERSION_1) {
  15537. bf_set(lpfc_rq_context_rqe_count_1,
  15538. &rq_create->u.request.context, hrq->entry_count);
  15539. if (subtype == LPFC_NVMET)
  15540. rq_create->u.request.context.buffer_size =
  15541. LPFC_NVMET_DATA_BUF_SIZE;
  15542. else
  15543. rq_create->u.request.context.buffer_size =
  15544. LPFC_DATA_BUF_SIZE;
  15545. bf_set(lpfc_rq_context_rqe_size, &rq_create->u.request.context,
  15546. LPFC_RQE_SIZE_8);
  15547. bf_set(lpfc_rq_context_page_size, &rq_create->u.request.context,
  15548. (PAGE_SIZE/SLI4_PAGE_SIZE));
  15549. } else {
  15550. switch (drq->entry_count) {
  15551. default:
  15552. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15553. "2536 Unsupported RQ count. (%d)\n",
  15554. drq->entry_count);
  15555. if (drq->entry_count < 512) {
  15556. status = -EINVAL;
  15557. goto out;
  15558. }
  15559. fallthrough; /* otherwise default to smallest count */
  15560. case 512:
  15561. bf_set(lpfc_rq_context_rqe_count,
  15562. &rq_create->u.request.context,
  15563. LPFC_RQ_RING_SIZE_512);
  15564. break;
  15565. case 1024:
  15566. bf_set(lpfc_rq_context_rqe_count,
  15567. &rq_create->u.request.context,
  15568. LPFC_RQ_RING_SIZE_1024);
  15569. break;
  15570. case 2048:
  15571. bf_set(lpfc_rq_context_rqe_count,
  15572. &rq_create->u.request.context,
  15573. LPFC_RQ_RING_SIZE_2048);
  15574. break;
  15575. case 4096:
  15576. bf_set(lpfc_rq_context_rqe_count,
  15577. &rq_create->u.request.context,
  15578. LPFC_RQ_RING_SIZE_4096);
  15579. break;
  15580. }
  15581. if (subtype == LPFC_NVMET)
  15582. bf_set(lpfc_rq_context_buf_size,
  15583. &rq_create->u.request.context,
  15584. LPFC_NVMET_DATA_BUF_SIZE);
  15585. else
  15586. bf_set(lpfc_rq_context_buf_size,
  15587. &rq_create->u.request.context,
  15588. LPFC_DATA_BUF_SIZE);
  15589. }
  15590. bf_set(lpfc_rq_context_cq_id, &rq_create->u.request.context,
  15591. cq->queue_id);
  15592. bf_set(lpfc_mbx_rq_create_num_pages, &rq_create->u.request,
  15593. drq->page_count);
  15594. list_for_each_entry(dmabuf, &drq->page_list, list) {
  15595. rq_create->u.request.page[dmabuf->buffer_tag].addr_lo =
  15596. putPaddrLow(dmabuf->phys);
  15597. rq_create->u.request.page[dmabuf->buffer_tag].addr_hi =
  15598. putPaddrHigh(dmabuf->phys);
  15599. }
  15600. if (phba->sli4_hba.fw_func_mode & LPFC_DUA_MODE)
  15601. bf_set(lpfc_mbx_rq_create_dua, &rq_create->u.request, 1);
  15602. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15603. /* The IOCTL status is embedded in the mailbox subheader. */
  15604. shdr = (union lpfc_sli4_cfg_shdr *) &rq_create->header.cfg_shdr;
  15605. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15606. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15607. if (shdr_status || shdr_add_status || rc) {
  15608. status = -ENXIO;
  15609. goto out;
  15610. }
  15611. drq->queue_id = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  15612. if (drq->queue_id == 0xFFFF) {
  15613. status = -ENXIO;
  15614. goto out;
  15615. }
  15616. drq->type = LPFC_DRQ;
  15617. drq->assoc_qid = cq->queue_id;
  15618. drq->subtype = subtype;
  15619. drq->host_index = 0;
  15620. drq->hba_index = 0;
  15621. drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
  15622. /* link the header and data RQs onto the parent cq child list */
  15623. list_add_tail(&hrq->list, &cq->child_list);
  15624. list_add_tail(&drq->list, &cq->child_list);
  15625. out:
  15626. mempool_free(mbox, phba->mbox_mem_pool);
  15627. return status;
  15628. }
  15629. /**
  15630. * lpfc_mrq_create - Create MRQ Receive Queues on the HBA
  15631. * @phba: HBA structure that indicates port to create a queue on.
  15632. * @hrqp: The queue structure array to use to create the header receive queues.
  15633. * @drqp: The queue structure array to use to create the data receive queues.
  15634. * @cqp: The completion queue array to bind these receive queues to.
  15635. * @subtype: Functional purpose of the queue (MBOX, IO, ELS, NVMET, etc).
  15636. *
  15637. * This function creates a receive buffer queue pair , as detailed in @hrq and
  15638. * @drq, on a port, described by @phba by sending a RQ_CREATE mailbox command
  15639. * to the HBA.
  15640. *
  15641. * The @phba struct is used to send mailbox command to HBA. The @drq and @hrq
  15642. * struct is used to get the entry count that is necessary to determine the
  15643. * number of pages to use for this queue. The @cq is used to indicate which
  15644. * completion queue to bind received buffers that are posted to these queues to.
  15645. * This function will send the RQ_CREATE mailbox command to the HBA to setup the
  15646. * receive queue pair. This function is asynchronous and will wait for the
  15647. * mailbox command to finish before continuing.
  15648. *
  15649. * On success this function will return a zero. If unable to allocate enough
  15650. * memory this function will return -ENOMEM. If the queue create mailbox command
  15651. * fails this function will return -ENXIO.
  15652. **/
  15653. int
  15654. lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
  15655. struct lpfc_queue **drqp, struct lpfc_queue **cqp,
  15656. uint32_t subtype)
  15657. {
  15658. struct lpfc_queue *hrq, *drq, *cq;
  15659. struct lpfc_mbx_rq_create_v2 *rq_create;
  15660. struct lpfc_dmabuf *dmabuf;
  15661. LPFC_MBOXQ_t *mbox;
  15662. int rc, length, alloclen, status = 0;
  15663. int cnt, idx, numrq, page_idx = 0;
  15664. uint32_t shdr_status, shdr_add_status;
  15665. union lpfc_sli4_cfg_shdr *shdr;
  15666. uint32_t hw_page_size = phba->sli4_hba.pc_sli4_params.if_page_sz;
  15667. numrq = phba->cfg_nvmet_mrq;
  15668. /* sanity check on array memory */
  15669. if (!hrqp || !drqp || !cqp || !numrq)
  15670. return -ENODEV;
  15671. if (!phba->sli4_hba.pc_sli4_params.supported)
  15672. hw_page_size = SLI4_PAGE_SIZE;
  15673. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  15674. if (!mbox)
  15675. return -ENOMEM;
  15676. length = sizeof(struct lpfc_mbx_rq_create_v2);
  15677. length += ((2 * numrq * hrqp[0]->page_count) *
  15678. sizeof(struct dma_address));
  15679. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15680. LPFC_MBOX_OPCODE_FCOE_RQ_CREATE, length,
  15681. LPFC_SLI4_MBX_NEMBED);
  15682. if (alloclen < length) {
  15683. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15684. "3099 Allocated DMA memory size (%d) is "
  15685. "less than the requested DMA memory size "
  15686. "(%d)\n", alloclen, length);
  15687. status = -ENOMEM;
  15688. goto out;
  15689. }
  15690. rq_create = mbox->sge_array->addr[0];
  15691. shdr = (union lpfc_sli4_cfg_shdr *)&rq_create->cfg_shdr;
  15692. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_2);
  15693. cnt = 0;
  15694. for (idx = 0; idx < numrq; idx++) {
  15695. hrq = hrqp[idx];
  15696. drq = drqp[idx];
  15697. cq = cqp[idx];
  15698. /* sanity check on queue memory */
  15699. if (!hrq || !drq || !cq) {
  15700. status = -ENODEV;
  15701. goto out;
  15702. }
  15703. if (hrq->entry_count != drq->entry_count) {
  15704. status = -EINVAL;
  15705. goto out;
  15706. }
  15707. if (idx == 0) {
  15708. bf_set(lpfc_mbx_rq_create_num_pages,
  15709. &rq_create->u.request,
  15710. hrq->page_count);
  15711. bf_set(lpfc_mbx_rq_create_rq_cnt,
  15712. &rq_create->u.request, (numrq * 2));
  15713. bf_set(lpfc_mbx_rq_create_dnb, &rq_create->u.request,
  15714. 1);
  15715. bf_set(lpfc_rq_context_base_cq,
  15716. &rq_create->u.request.context,
  15717. cq->queue_id);
  15718. bf_set(lpfc_rq_context_data_size,
  15719. &rq_create->u.request.context,
  15720. LPFC_NVMET_DATA_BUF_SIZE);
  15721. bf_set(lpfc_rq_context_hdr_size,
  15722. &rq_create->u.request.context,
  15723. LPFC_HDR_BUF_SIZE);
  15724. bf_set(lpfc_rq_context_rqe_count_1,
  15725. &rq_create->u.request.context,
  15726. hrq->entry_count);
  15727. bf_set(lpfc_rq_context_rqe_size,
  15728. &rq_create->u.request.context,
  15729. LPFC_RQE_SIZE_8);
  15730. bf_set(lpfc_rq_context_page_size,
  15731. &rq_create->u.request.context,
  15732. (PAGE_SIZE/SLI4_PAGE_SIZE));
  15733. }
  15734. rc = 0;
  15735. list_for_each_entry(dmabuf, &hrq->page_list, list) {
  15736. memset(dmabuf->virt, 0, hw_page_size);
  15737. cnt = page_idx + dmabuf->buffer_tag;
  15738. rq_create->u.request.page[cnt].addr_lo =
  15739. putPaddrLow(dmabuf->phys);
  15740. rq_create->u.request.page[cnt].addr_hi =
  15741. putPaddrHigh(dmabuf->phys);
  15742. rc++;
  15743. }
  15744. page_idx += rc;
  15745. rc = 0;
  15746. list_for_each_entry(dmabuf, &drq->page_list, list) {
  15747. memset(dmabuf->virt, 0, hw_page_size);
  15748. cnt = page_idx + dmabuf->buffer_tag;
  15749. rq_create->u.request.page[cnt].addr_lo =
  15750. putPaddrLow(dmabuf->phys);
  15751. rq_create->u.request.page[cnt].addr_hi =
  15752. putPaddrHigh(dmabuf->phys);
  15753. rc++;
  15754. }
  15755. page_idx += rc;
  15756. hrq->db_format = LPFC_DB_RING_FORMAT;
  15757. hrq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  15758. hrq->type = LPFC_HRQ;
  15759. hrq->assoc_qid = cq->queue_id;
  15760. hrq->subtype = subtype;
  15761. hrq->host_index = 0;
  15762. hrq->hba_index = 0;
  15763. hrq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
  15764. drq->db_format = LPFC_DB_RING_FORMAT;
  15765. drq->db_regaddr = phba->sli4_hba.RQDBregaddr;
  15766. drq->type = LPFC_DRQ;
  15767. drq->assoc_qid = cq->queue_id;
  15768. drq->subtype = subtype;
  15769. drq->host_index = 0;
  15770. drq->hba_index = 0;
  15771. drq->notify_interval = LPFC_RQ_NOTIFY_INTRVL;
  15772. list_add_tail(&hrq->list, &cq->child_list);
  15773. list_add_tail(&drq->list, &cq->child_list);
  15774. }
  15775. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  15776. /* The IOCTL status is embedded in the mailbox subheader. */
  15777. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15778. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15779. if (shdr_status || shdr_add_status || rc) {
  15780. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15781. "3120 RQ_CREATE mailbox failed with "
  15782. "status x%x add_status x%x, mbx status x%x\n",
  15783. shdr_status, shdr_add_status, rc);
  15784. status = -ENXIO;
  15785. goto out;
  15786. }
  15787. rc = bf_get(lpfc_mbx_rq_create_q_id, &rq_create->u.response);
  15788. if (rc == 0xFFFF) {
  15789. status = -ENXIO;
  15790. goto out;
  15791. }
  15792. /* Initialize all RQs with associated queue id */
  15793. for (idx = 0; idx < numrq; idx++) {
  15794. hrq = hrqp[idx];
  15795. hrq->queue_id = rc + (2 * idx);
  15796. drq = drqp[idx];
  15797. drq->queue_id = rc + (2 * idx) + 1;
  15798. }
  15799. out:
  15800. lpfc_sli4_mbox_cmd_free(phba, mbox);
  15801. return status;
  15802. }
  15803. /**
  15804. * lpfc_eq_destroy - Destroy an event Queue on the HBA
  15805. * @phba: HBA structure that indicates port to destroy a queue on.
  15806. * @eq: The queue structure associated with the queue to destroy.
  15807. *
  15808. * This function destroys a queue, as detailed in @eq by sending an mailbox
  15809. * command, specific to the type of queue, to the HBA.
  15810. *
  15811. * The @eq struct is used to get the queue ID of the queue to destroy.
  15812. *
  15813. * On success this function will return a zero. If the queue destroy mailbox
  15814. * command fails this function will return -ENXIO.
  15815. **/
  15816. int
  15817. lpfc_eq_destroy(struct lpfc_hba *phba, struct lpfc_queue *eq)
  15818. {
  15819. LPFC_MBOXQ_t *mbox;
  15820. int rc, length, status = 0;
  15821. uint32_t shdr_status, shdr_add_status;
  15822. union lpfc_sli4_cfg_shdr *shdr;
  15823. /* sanity check on queue memory */
  15824. if (!eq)
  15825. return -ENODEV;
  15826. mbox = mempool_alloc(eq->phba->mbox_mem_pool, GFP_KERNEL);
  15827. if (!mbox)
  15828. return -ENOMEM;
  15829. length = (sizeof(struct lpfc_mbx_eq_destroy) -
  15830. sizeof(struct lpfc_sli4_cfg_mhdr));
  15831. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15832. LPFC_MBOX_OPCODE_EQ_DESTROY,
  15833. length, LPFC_SLI4_MBX_EMBED);
  15834. bf_set(lpfc_mbx_eq_destroy_q_id, &mbox->u.mqe.un.eq_destroy.u.request,
  15835. eq->queue_id);
  15836. mbox->vport = eq->phba->pport;
  15837. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15838. rc = lpfc_sli_issue_mbox(eq->phba, mbox, MBX_POLL);
  15839. /* The IOCTL status is embedded in the mailbox subheader. */
  15840. shdr = (union lpfc_sli4_cfg_shdr *)
  15841. &mbox->u.mqe.un.eq_destroy.header.cfg_shdr;
  15842. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15843. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15844. if (shdr_status || shdr_add_status || rc) {
  15845. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15846. "2505 EQ_DESTROY mailbox failed with "
  15847. "status x%x add_status x%x, mbx status x%x\n",
  15848. shdr_status, shdr_add_status, rc);
  15849. status = -ENXIO;
  15850. }
  15851. /* Remove eq from any list */
  15852. list_del_init(&eq->list);
  15853. mempool_free(mbox, eq->phba->mbox_mem_pool);
  15854. return status;
  15855. }
  15856. /**
  15857. * lpfc_cq_destroy - Destroy a Completion Queue on the HBA
  15858. * @phba: HBA structure that indicates port to destroy a queue on.
  15859. * @cq: The queue structure associated with the queue to destroy.
  15860. *
  15861. * This function destroys a queue, as detailed in @cq by sending an mailbox
  15862. * command, specific to the type of queue, to the HBA.
  15863. *
  15864. * The @cq struct is used to get the queue ID of the queue to destroy.
  15865. *
  15866. * On success this function will return a zero. If the queue destroy mailbox
  15867. * command fails this function will return -ENXIO.
  15868. **/
  15869. int
  15870. lpfc_cq_destroy(struct lpfc_hba *phba, struct lpfc_queue *cq)
  15871. {
  15872. LPFC_MBOXQ_t *mbox;
  15873. int rc, length, status = 0;
  15874. uint32_t shdr_status, shdr_add_status;
  15875. union lpfc_sli4_cfg_shdr *shdr;
  15876. /* sanity check on queue memory */
  15877. if (!cq)
  15878. return -ENODEV;
  15879. mbox = mempool_alloc(cq->phba->mbox_mem_pool, GFP_KERNEL);
  15880. if (!mbox)
  15881. return -ENOMEM;
  15882. length = (sizeof(struct lpfc_mbx_cq_destroy) -
  15883. sizeof(struct lpfc_sli4_cfg_mhdr));
  15884. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15885. LPFC_MBOX_OPCODE_CQ_DESTROY,
  15886. length, LPFC_SLI4_MBX_EMBED);
  15887. bf_set(lpfc_mbx_cq_destroy_q_id, &mbox->u.mqe.un.cq_destroy.u.request,
  15888. cq->queue_id);
  15889. mbox->vport = cq->phba->pport;
  15890. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15891. rc = lpfc_sli_issue_mbox(cq->phba, mbox, MBX_POLL);
  15892. /* The IOCTL status is embedded in the mailbox subheader. */
  15893. shdr = (union lpfc_sli4_cfg_shdr *)
  15894. &mbox->u.mqe.un.wq_create.header.cfg_shdr;
  15895. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15896. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15897. if (shdr_status || shdr_add_status || rc) {
  15898. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15899. "2506 CQ_DESTROY mailbox failed with "
  15900. "status x%x add_status x%x, mbx status x%x\n",
  15901. shdr_status, shdr_add_status, rc);
  15902. status = -ENXIO;
  15903. }
  15904. /* Remove cq from any list */
  15905. list_del_init(&cq->list);
  15906. mempool_free(mbox, cq->phba->mbox_mem_pool);
  15907. return status;
  15908. }
  15909. /**
  15910. * lpfc_mq_destroy - Destroy a Mailbox Queue on the HBA
  15911. * @phba: HBA structure that indicates port to destroy a queue on.
  15912. * @mq: The queue structure associated with the queue to destroy.
  15913. *
  15914. * This function destroys a queue, as detailed in @mq by sending an mailbox
  15915. * command, specific to the type of queue, to the HBA.
  15916. *
  15917. * The @mq struct is used to get the queue ID of the queue to destroy.
  15918. *
  15919. * On success this function will return a zero. If the queue destroy mailbox
  15920. * command fails this function will return -ENXIO.
  15921. **/
  15922. int
  15923. lpfc_mq_destroy(struct lpfc_hba *phba, struct lpfc_queue *mq)
  15924. {
  15925. LPFC_MBOXQ_t *mbox;
  15926. int rc, length, status = 0;
  15927. uint32_t shdr_status, shdr_add_status;
  15928. union lpfc_sli4_cfg_shdr *shdr;
  15929. /* sanity check on queue memory */
  15930. if (!mq)
  15931. return -ENODEV;
  15932. mbox = mempool_alloc(mq->phba->mbox_mem_pool, GFP_KERNEL);
  15933. if (!mbox)
  15934. return -ENOMEM;
  15935. length = (sizeof(struct lpfc_mbx_mq_destroy) -
  15936. sizeof(struct lpfc_sli4_cfg_mhdr));
  15937. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  15938. LPFC_MBOX_OPCODE_MQ_DESTROY,
  15939. length, LPFC_SLI4_MBX_EMBED);
  15940. bf_set(lpfc_mbx_mq_destroy_q_id, &mbox->u.mqe.un.mq_destroy.u.request,
  15941. mq->queue_id);
  15942. mbox->vport = mq->phba->pport;
  15943. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15944. rc = lpfc_sli_issue_mbox(mq->phba, mbox, MBX_POLL);
  15945. /* The IOCTL status is embedded in the mailbox subheader. */
  15946. shdr = (union lpfc_sli4_cfg_shdr *)
  15947. &mbox->u.mqe.un.mq_destroy.header.cfg_shdr;
  15948. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  15949. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  15950. if (shdr_status || shdr_add_status || rc) {
  15951. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  15952. "2507 MQ_DESTROY mailbox failed with "
  15953. "status x%x add_status x%x, mbx status x%x\n",
  15954. shdr_status, shdr_add_status, rc);
  15955. status = -ENXIO;
  15956. }
  15957. /* Remove mq from any list */
  15958. list_del_init(&mq->list);
  15959. mempool_free(mbox, mq->phba->mbox_mem_pool);
  15960. return status;
  15961. }
  15962. /**
  15963. * lpfc_wq_destroy - Destroy a Work Queue on the HBA
  15964. * @phba: HBA structure that indicates port to destroy a queue on.
  15965. * @wq: The queue structure associated with the queue to destroy.
  15966. *
  15967. * This function destroys a queue, as detailed in @wq by sending an mailbox
  15968. * command, specific to the type of queue, to the HBA.
  15969. *
  15970. * The @wq struct is used to get the queue ID of the queue to destroy.
  15971. *
  15972. * On success this function will return a zero. If the queue destroy mailbox
  15973. * command fails this function will return -ENXIO.
  15974. **/
  15975. int
  15976. lpfc_wq_destroy(struct lpfc_hba *phba, struct lpfc_queue *wq)
  15977. {
  15978. LPFC_MBOXQ_t *mbox;
  15979. int rc, length, status = 0;
  15980. uint32_t shdr_status, shdr_add_status;
  15981. union lpfc_sli4_cfg_shdr *shdr;
  15982. /* sanity check on queue memory */
  15983. if (!wq)
  15984. return -ENODEV;
  15985. mbox = mempool_alloc(wq->phba->mbox_mem_pool, GFP_KERNEL);
  15986. if (!mbox)
  15987. return -ENOMEM;
  15988. length = (sizeof(struct lpfc_mbx_wq_destroy) -
  15989. sizeof(struct lpfc_sli4_cfg_mhdr));
  15990. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  15991. LPFC_MBOX_OPCODE_FCOE_WQ_DESTROY,
  15992. length, LPFC_SLI4_MBX_EMBED);
  15993. bf_set(lpfc_mbx_wq_destroy_q_id, &mbox->u.mqe.un.wq_destroy.u.request,
  15994. wq->queue_id);
  15995. mbox->vport = wq->phba->pport;
  15996. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  15997. rc = lpfc_sli_issue_mbox(wq->phba, mbox, MBX_POLL);
  15998. shdr = (union lpfc_sli4_cfg_shdr *)
  15999. &mbox->u.mqe.un.wq_destroy.header.cfg_shdr;
  16000. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16001. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16002. if (shdr_status || shdr_add_status || rc) {
  16003. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16004. "2508 WQ_DESTROY mailbox failed with "
  16005. "status x%x add_status x%x, mbx status x%x\n",
  16006. shdr_status, shdr_add_status, rc);
  16007. status = -ENXIO;
  16008. }
  16009. /* Remove wq from any list */
  16010. list_del_init(&wq->list);
  16011. kfree(wq->pring);
  16012. wq->pring = NULL;
  16013. mempool_free(mbox, wq->phba->mbox_mem_pool);
  16014. return status;
  16015. }
  16016. /**
  16017. * lpfc_rq_destroy - Destroy a Receive Queue on the HBA
  16018. * @phba: HBA structure that indicates port to destroy a queue on.
  16019. * @hrq: The queue structure associated with the queue to destroy.
  16020. * @drq: The queue structure associated with the queue to destroy.
  16021. *
  16022. * This function destroys a queue, as detailed in @rq by sending an mailbox
  16023. * command, specific to the type of queue, to the HBA.
  16024. *
  16025. * The @rq struct is used to get the queue ID of the queue to destroy.
  16026. *
  16027. * On success this function will return a zero. If the queue destroy mailbox
  16028. * command fails this function will return -ENXIO.
  16029. **/
  16030. int
  16031. lpfc_rq_destroy(struct lpfc_hba *phba, struct lpfc_queue *hrq,
  16032. struct lpfc_queue *drq)
  16033. {
  16034. LPFC_MBOXQ_t *mbox;
  16035. int rc, length, status = 0;
  16036. uint32_t shdr_status, shdr_add_status;
  16037. union lpfc_sli4_cfg_shdr *shdr;
  16038. /* sanity check on queue memory */
  16039. if (!hrq || !drq)
  16040. return -ENODEV;
  16041. mbox = mempool_alloc(hrq->phba->mbox_mem_pool, GFP_KERNEL);
  16042. if (!mbox)
  16043. return -ENOMEM;
  16044. length = (sizeof(struct lpfc_mbx_rq_destroy) -
  16045. sizeof(struct lpfc_sli4_cfg_mhdr));
  16046. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  16047. LPFC_MBOX_OPCODE_FCOE_RQ_DESTROY,
  16048. length, LPFC_SLI4_MBX_EMBED);
  16049. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  16050. hrq->queue_id);
  16051. mbox->vport = hrq->phba->pport;
  16052. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  16053. rc = lpfc_sli_issue_mbox(hrq->phba, mbox, MBX_POLL);
  16054. /* The IOCTL status is embedded in the mailbox subheader. */
  16055. shdr = (union lpfc_sli4_cfg_shdr *)
  16056. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  16057. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16058. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16059. if (shdr_status || shdr_add_status || rc) {
  16060. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16061. "2509 RQ_DESTROY mailbox failed with "
  16062. "status x%x add_status x%x, mbx status x%x\n",
  16063. shdr_status, shdr_add_status, rc);
  16064. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  16065. return -ENXIO;
  16066. }
  16067. bf_set(lpfc_mbx_rq_destroy_q_id, &mbox->u.mqe.un.rq_destroy.u.request,
  16068. drq->queue_id);
  16069. rc = lpfc_sli_issue_mbox(drq->phba, mbox, MBX_POLL);
  16070. shdr = (union lpfc_sli4_cfg_shdr *)
  16071. &mbox->u.mqe.un.rq_destroy.header.cfg_shdr;
  16072. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16073. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16074. if (shdr_status || shdr_add_status || rc) {
  16075. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16076. "2510 RQ_DESTROY mailbox failed with "
  16077. "status x%x add_status x%x, mbx status x%x\n",
  16078. shdr_status, shdr_add_status, rc);
  16079. status = -ENXIO;
  16080. }
  16081. list_del_init(&hrq->list);
  16082. list_del_init(&drq->list);
  16083. mempool_free(mbox, hrq->phba->mbox_mem_pool);
  16084. return status;
  16085. }
  16086. /**
  16087. * lpfc_sli4_post_sgl - Post scatter gather list for an XRI to HBA
  16088. * @phba: The virtual port for which this call being executed.
  16089. * @pdma_phys_addr0: Physical address of the 1st SGL page.
  16090. * @pdma_phys_addr1: Physical address of the 2nd SGL page.
  16091. * @xritag: the xritag that ties this io to the SGL pages.
  16092. *
  16093. * This routine will post the sgl pages for the IO that has the xritag
  16094. * that is in the iocbq structure. The xritag is assigned during iocbq
  16095. * creation and persists for as long as the driver is loaded.
  16096. * if the caller has fewer than 256 scatter gather segments to map then
  16097. * pdma_phys_addr1 should be 0.
  16098. * If the caller needs to map more than 256 scatter gather segment then
  16099. * pdma_phys_addr1 should be a valid physical address.
  16100. * physical address for SGLs must be 64 byte aligned.
  16101. * If you are going to map 2 SGL's then the first one must have 256 entries
  16102. * the second sgl can have between 1 and 256 entries.
  16103. *
  16104. * Return codes:
  16105. * 0 - Success
  16106. * -ENXIO, -ENOMEM - Failure
  16107. **/
  16108. int
  16109. lpfc_sli4_post_sgl(struct lpfc_hba *phba,
  16110. dma_addr_t pdma_phys_addr0,
  16111. dma_addr_t pdma_phys_addr1,
  16112. uint16_t xritag)
  16113. {
  16114. struct lpfc_mbx_post_sgl_pages *post_sgl_pages;
  16115. LPFC_MBOXQ_t *mbox;
  16116. int rc;
  16117. uint32_t shdr_status, shdr_add_status;
  16118. uint32_t mbox_tmo;
  16119. union lpfc_sli4_cfg_shdr *shdr;
  16120. if (xritag == NO_XRI) {
  16121. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16122. "0364 Invalid param:\n");
  16123. return -EINVAL;
  16124. }
  16125. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  16126. if (!mbox)
  16127. return -ENOMEM;
  16128. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  16129. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  16130. sizeof(struct lpfc_mbx_post_sgl_pages) -
  16131. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  16132. post_sgl_pages = (struct lpfc_mbx_post_sgl_pages *)
  16133. &mbox->u.mqe.un.post_sgl_pages;
  16134. bf_set(lpfc_post_sgl_pages_xri, post_sgl_pages, xritag);
  16135. bf_set(lpfc_post_sgl_pages_xricnt, post_sgl_pages, 1);
  16136. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_lo =
  16137. cpu_to_le32(putPaddrLow(pdma_phys_addr0));
  16138. post_sgl_pages->sgl_pg_pairs[0].sgl_pg0_addr_hi =
  16139. cpu_to_le32(putPaddrHigh(pdma_phys_addr0));
  16140. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_lo =
  16141. cpu_to_le32(putPaddrLow(pdma_phys_addr1));
  16142. post_sgl_pages->sgl_pg_pairs[0].sgl_pg1_addr_hi =
  16143. cpu_to_le32(putPaddrHigh(pdma_phys_addr1));
  16144. if (!phba->sli4_hba.intr_enable)
  16145. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  16146. else {
  16147. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  16148. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  16149. }
  16150. /* The IOCTL status is embedded in the mailbox subheader. */
  16151. shdr = (union lpfc_sli4_cfg_shdr *) &post_sgl_pages->header.cfg_shdr;
  16152. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16153. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16154. if (!phba->sli4_hba.intr_enable)
  16155. mempool_free(mbox, phba->mbox_mem_pool);
  16156. else if (rc != MBX_TIMEOUT)
  16157. mempool_free(mbox, phba->mbox_mem_pool);
  16158. if (shdr_status || shdr_add_status || rc) {
  16159. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16160. "2511 POST_SGL mailbox failed with "
  16161. "status x%x add_status x%x, mbx status x%x\n",
  16162. shdr_status, shdr_add_status, rc);
  16163. }
  16164. return 0;
  16165. }
  16166. /**
  16167. * lpfc_sli4_alloc_xri - Get an available rpi in the device's range
  16168. * @phba: pointer to lpfc hba data structure.
  16169. *
  16170. * This routine is invoked to post rpi header templates to the
  16171. * HBA consistent with the SLI-4 interface spec. This routine
  16172. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  16173. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  16174. *
  16175. * Returns
  16176. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  16177. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  16178. **/
  16179. static uint16_t
  16180. lpfc_sli4_alloc_xri(struct lpfc_hba *phba)
  16181. {
  16182. unsigned long xri;
  16183. /*
  16184. * Fetch the next logical xri. Because this index is logical,
  16185. * the driver starts at 0 each time.
  16186. */
  16187. spin_lock_irq(&phba->hbalock);
  16188. xri = find_first_zero_bit(phba->sli4_hba.xri_bmask,
  16189. phba->sli4_hba.max_cfg_param.max_xri);
  16190. if (xri >= phba->sli4_hba.max_cfg_param.max_xri) {
  16191. spin_unlock_irq(&phba->hbalock);
  16192. return NO_XRI;
  16193. } else {
  16194. set_bit(xri, phba->sli4_hba.xri_bmask);
  16195. phba->sli4_hba.max_cfg_param.xri_used++;
  16196. }
  16197. spin_unlock_irq(&phba->hbalock);
  16198. return xri;
  16199. }
  16200. /**
  16201. * __lpfc_sli4_free_xri - Release an xri for reuse.
  16202. * @phba: pointer to lpfc hba data structure.
  16203. * @xri: xri to release.
  16204. *
  16205. * This routine is invoked to release an xri to the pool of
  16206. * available rpis maintained by the driver.
  16207. **/
  16208. static void
  16209. __lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  16210. {
  16211. if (test_and_clear_bit(xri, phba->sli4_hba.xri_bmask)) {
  16212. phba->sli4_hba.max_cfg_param.xri_used--;
  16213. }
  16214. }
  16215. /**
  16216. * lpfc_sli4_free_xri - Release an xri for reuse.
  16217. * @phba: pointer to lpfc hba data structure.
  16218. * @xri: xri to release.
  16219. *
  16220. * This routine is invoked to release an xri to the pool of
  16221. * available rpis maintained by the driver.
  16222. **/
  16223. void
  16224. lpfc_sli4_free_xri(struct lpfc_hba *phba, int xri)
  16225. {
  16226. spin_lock_irq(&phba->hbalock);
  16227. __lpfc_sli4_free_xri(phba, xri);
  16228. spin_unlock_irq(&phba->hbalock);
  16229. }
  16230. /**
  16231. * lpfc_sli4_next_xritag - Get an xritag for the io
  16232. * @phba: Pointer to HBA context object.
  16233. *
  16234. * This function gets an xritag for the iocb. If there is no unused xritag
  16235. * it will return 0xffff.
  16236. * The function returns the allocated xritag if successful, else returns zero.
  16237. * Zero is not a valid xritag.
  16238. * The caller is not required to hold any lock.
  16239. **/
  16240. uint16_t
  16241. lpfc_sli4_next_xritag(struct lpfc_hba *phba)
  16242. {
  16243. uint16_t xri_index;
  16244. xri_index = lpfc_sli4_alloc_xri(phba);
  16245. if (xri_index == NO_XRI)
  16246. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  16247. "2004 Failed to allocate XRI.last XRITAG is %d"
  16248. " Max XRI is %d, Used XRI is %d\n",
  16249. xri_index,
  16250. phba->sli4_hba.max_cfg_param.max_xri,
  16251. phba->sli4_hba.max_cfg_param.xri_used);
  16252. return xri_index;
  16253. }
  16254. /**
  16255. * lpfc_sli4_post_sgl_list - post a block of ELS sgls to the port.
  16256. * @phba: pointer to lpfc hba data structure.
  16257. * @post_sgl_list: pointer to els sgl entry list.
  16258. * @post_cnt: number of els sgl entries on the list.
  16259. *
  16260. * This routine is invoked to post a block of driver's sgl pages to the
  16261. * HBA using non-embedded mailbox command. No Lock is held. This routine
  16262. * is only called when the driver is loading and after all IO has been
  16263. * stopped.
  16264. **/
  16265. static int
  16266. lpfc_sli4_post_sgl_list(struct lpfc_hba *phba,
  16267. struct list_head *post_sgl_list,
  16268. int post_cnt)
  16269. {
  16270. struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
  16271. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  16272. struct sgl_page_pairs *sgl_pg_pairs;
  16273. void *viraddr;
  16274. LPFC_MBOXQ_t *mbox;
  16275. uint32_t reqlen, alloclen, pg_pairs;
  16276. uint32_t mbox_tmo;
  16277. uint16_t xritag_start = 0;
  16278. int rc = 0;
  16279. uint32_t shdr_status, shdr_add_status;
  16280. union lpfc_sli4_cfg_shdr *shdr;
  16281. reqlen = post_cnt * sizeof(struct sgl_page_pairs) +
  16282. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  16283. if (reqlen > SLI4_PAGE_SIZE) {
  16284. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16285. "2559 Block sgl registration required DMA "
  16286. "size (%d) great than a page\n", reqlen);
  16287. return -ENOMEM;
  16288. }
  16289. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  16290. if (!mbox)
  16291. return -ENOMEM;
  16292. /* Allocate DMA memory and set up the non-embedded mailbox command */
  16293. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  16294. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES, reqlen,
  16295. LPFC_SLI4_MBX_NEMBED);
  16296. if (alloclen < reqlen) {
  16297. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16298. "0285 Allocated DMA memory size (%d) is "
  16299. "less than the requested DMA memory "
  16300. "size (%d)\n", alloclen, reqlen);
  16301. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16302. return -ENOMEM;
  16303. }
  16304. /* Set up the SGL pages in the non-embedded DMA pages */
  16305. viraddr = mbox->sge_array->addr[0];
  16306. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  16307. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  16308. pg_pairs = 0;
  16309. list_for_each_entry_safe(sglq_entry, sglq_next, post_sgl_list, list) {
  16310. /* Set up the sge entry */
  16311. sgl_pg_pairs->sgl_pg0_addr_lo =
  16312. cpu_to_le32(putPaddrLow(sglq_entry->phys));
  16313. sgl_pg_pairs->sgl_pg0_addr_hi =
  16314. cpu_to_le32(putPaddrHigh(sglq_entry->phys));
  16315. sgl_pg_pairs->sgl_pg1_addr_lo =
  16316. cpu_to_le32(putPaddrLow(0));
  16317. sgl_pg_pairs->sgl_pg1_addr_hi =
  16318. cpu_to_le32(putPaddrHigh(0));
  16319. /* Keep the first xritag on the list */
  16320. if (pg_pairs == 0)
  16321. xritag_start = sglq_entry->sli4_xritag;
  16322. sgl_pg_pairs++;
  16323. pg_pairs++;
  16324. }
  16325. /* Complete initialization and perform endian conversion. */
  16326. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  16327. bf_set(lpfc_post_sgl_pages_xricnt, sgl, post_cnt);
  16328. sgl->word0 = cpu_to_le32(sgl->word0);
  16329. if (!phba->sli4_hba.intr_enable)
  16330. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  16331. else {
  16332. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  16333. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  16334. }
  16335. shdr = (union lpfc_sli4_cfg_shdr *) &sgl->cfg_shdr;
  16336. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16337. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16338. if (!phba->sli4_hba.intr_enable)
  16339. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16340. else if (rc != MBX_TIMEOUT)
  16341. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16342. if (shdr_status || shdr_add_status || rc) {
  16343. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16344. "2513 POST_SGL_BLOCK mailbox command failed "
  16345. "status x%x add_status x%x mbx status x%x\n",
  16346. shdr_status, shdr_add_status, rc);
  16347. rc = -ENXIO;
  16348. }
  16349. return rc;
  16350. }
  16351. /**
  16352. * lpfc_sli4_post_io_sgl_block - post a block of nvme sgl list to firmware
  16353. * @phba: pointer to lpfc hba data structure.
  16354. * @nblist: pointer to nvme buffer list.
  16355. * @count: number of scsi buffers on the list.
  16356. *
  16357. * This routine is invoked to post a block of @count scsi sgl pages from a
  16358. * SCSI buffer list @nblist to the HBA using non-embedded mailbox command.
  16359. * No Lock is held.
  16360. *
  16361. **/
  16362. static int
  16363. lpfc_sli4_post_io_sgl_block(struct lpfc_hba *phba, struct list_head *nblist,
  16364. int count)
  16365. {
  16366. struct lpfc_io_buf *lpfc_ncmd;
  16367. struct lpfc_mbx_post_uembed_sgl_page1 *sgl;
  16368. struct sgl_page_pairs *sgl_pg_pairs;
  16369. void *viraddr;
  16370. LPFC_MBOXQ_t *mbox;
  16371. uint32_t reqlen, alloclen, pg_pairs;
  16372. uint32_t mbox_tmo;
  16373. uint16_t xritag_start = 0;
  16374. int rc = 0;
  16375. uint32_t shdr_status, shdr_add_status;
  16376. dma_addr_t pdma_phys_bpl1;
  16377. union lpfc_sli4_cfg_shdr *shdr;
  16378. /* Calculate the requested length of the dma memory */
  16379. reqlen = count * sizeof(struct sgl_page_pairs) +
  16380. sizeof(union lpfc_sli4_cfg_shdr) + sizeof(uint32_t);
  16381. if (reqlen > SLI4_PAGE_SIZE) {
  16382. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  16383. "6118 Block sgl registration required DMA "
  16384. "size (%d) great than a page\n", reqlen);
  16385. return -ENOMEM;
  16386. }
  16387. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  16388. if (!mbox) {
  16389. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16390. "6119 Failed to allocate mbox cmd memory\n");
  16391. return -ENOMEM;
  16392. }
  16393. /* Allocate DMA memory and set up the non-embedded mailbox command */
  16394. alloclen = lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  16395. LPFC_MBOX_OPCODE_FCOE_POST_SGL_PAGES,
  16396. reqlen, LPFC_SLI4_MBX_NEMBED);
  16397. if (alloclen < reqlen) {
  16398. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16399. "6120 Allocated DMA memory size (%d) is "
  16400. "less than the requested DMA memory "
  16401. "size (%d)\n", alloclen, reqlen);
  16402. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16403. return -ENOMEM;
  16404. }
  16405. /* Get the first SGE entry from the non-embedded DMA memory */
  16406. viraddr = mbox->sge_array->addr[0];
  16407. /* Set up the SGL pages in the non-embedded DMA pages */
  16408. sgl = (struct lpfc_mbx_post_uembed_sgl_page1 *)viraddr;
  16409. sgl_pg_pairs = &sgl->sgl_pg_pairs;
  16410. pg_pairs = 0;
  16411. list_for_each_entry(lpfc_ncmd, nblist, list) {
  16412. /* Set up the sge entry */
  16413. sgl_pg_pairs->sgl_pg0_addr_lo =
  16414. cpu_to_le32(putPaddrLow(lpfc_ncmd->dma_phys_sgl));
  16415. sgl_pg_pairs->sgl_pg0_addr_hi =
  16416. cpu_to_le32(putPaddrHigh(lpfc_ncmd->dma_phys_sgl));
  16417. if (phba->cfg_sg_dma_buf_size > SGL_PAGE_SIZE)
  16418. pdma_phys_bpl1 = lpfc_ncmd->dma_phys_sgl +
  16419. SGL_PAGE_SIZE;
  16420. else
  16421. pdma_phys_bpl1 = 0;
  16422. sgl_pg_pairs->sgl_pg1_addr_lo =
  16423. cpu_to_le32(putPaddrLow(pdma_phys_bpl1));
  16424. sgl_pg_pairs->sgl_pg1_addr_hi =
  16425. cpu_to_le32(putPaddrHigh(pdma_phys_bpl1));
  16426. /* Keep the first xritag on the list */
  16427. if (pg_pairs == 0)
  16428. xritag_start = lpfc_ncmd->cur_iocbq.sli4_xritag;
  16429. sgl_pg_pairs++;
  16430. pg_pairs++;
  16431. }
  16432. bf_set(lpfc_post_sgl_pages_xri, sgl, xritag_start);
  16433. bf_set(lpfc_post_sgl_pages_xricnt, sgl, pg_pairs);
  16434. /* Perform endian conversion if necessary */
  16435. sgl->word0 = cpu_to_le32(sgl->word0);
  16436. if (!phba->sli4_hba.intr_enable) {
  16437. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  16438. } else {
  16439. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  16440. rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  16441. }
  16442. shdr = (union lpfc_sli4_cfg_shdr *)&sgl->cfg_shdr;
  16443. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  16444. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  16445. if (!phba->sli4_hba.intr_enable)
  16446. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16447. else if (rc != MBX_TIMEOUT)
  16448. lpfc_sli4_mbox_cmd_free(phba, mbox);
  16449. if (shdr_status || shdr_add_status || rc) {
  16450. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16451. "6125 POST_SGL_BLOCK mailbox command failed "
  16452. "status x%x add_status x%x mbx status x%x\n",
  16453. shdr_status, shdr_add_status, rc);
  16454. rc = -ENXIO;
  16455. }
  16456. return rc;
  16457. }
  16458. /**
  16459. * lpfc_sli4_post_io_sgl_list - Post blocks of nvme buffer sgls from a list
  16460. * @phba: pointer to lpfc hba data structure.
  16461. * @post_nblist: pointer to the nvme buffer list.
  16462. * @sb_count: number of nvme buffers.
  16463. *
  16464. * This routine walks a list of nvme buffers that was passed in. It attempts
  16465. * to construct blocks of nvme buffer sgls which contains contiguous xris and
  16466. * uses the non-embedded SGL block post mailbox commands to post to the port.
  16467. * For single NVME buffer sgl with non-contiguous xri, if any, it shall use
  16468. * embedded SGL post mailbox command for posting. The @post_nblist passed in
  16469. * must be local list, thus no lock is needed when manipulate the list.
  16470. *
  16471. * Returns: 0 = failure, non-zero number of successfully posted buffers.
  16472. **/
  16473. int
  16474. lpfc_sli4_post_io_sgl_list(struct lpfc_hba *phba,
  16475. struct list_head *post_nblist, int sb_count)
  16476. {
  16477. struct lpfc_io_buf *lpfc_ncmd, *lpfc_ncmd_next;
  16478. int status, sgl_size;
  16479. int post_cnt = 0, block_cnt = 0, num_posting = 0, num_posted = 0;
  16480. dma_addr_t pdma_phys_sgl1;
  16481. int last_xritag = NO_XRI;
  16482. int cur_xritag;
  16483. LIST_HEAD(prep_nblist);
  16484. LIST_HEAD(blck_nblist);
  16485. LIST_HEAD(nvme_nblist);
  16486. /* sanity check */
  16487. if (sb_count <= 0)
  16488. return -EINVAL;
  16489. sgl_size = phba->cfg_sg_dma_buf_size;
  16490. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, post_nblist, list) {
  16491. list_del_init(&lpfc_ncmd->list);
  16492. block_cnt++;
  16493. if ((last_xritag != NO_XRI) &&
  16494. (lpfc_ncmd->cur_iocbq.sli4_xritag != last_xritag + 1)) {
  16495. /* a hole in xri block, form a sgl posting block */
  16496. list_splice_init(&prep_nblist, &blck_nblist);
  16497. post_cnt = block_cnt - 1;
  16498. /* prepare list for next posting block */
  16499. list_add_tail(&lpfc_ncmd->list, &prep_nblist);
  16500. block_cnt = 1;
  16501. } else {
  16502. /* prepare list for next posting block */
  16503. list_add_tail(&lpfc_ncmd->list, &prep_nblist);
  16504. /* enough sgls for non-embed sgl mbox command */
  16505. if (block_cnt == LPFC_NEMBED_MBOX_SGL_CNT) {
  16506. list_splice_init(&prep_nblist, &blck_nblist);
  16507. post_cnt = block_cnt;
  16508. block_cnt = 0;
  16509. }
  16510. }
  16511. num_posting++;
  16512. last_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
  16513. /* end of repost sgl list condition for NVME buffers */
  16514. if (num_posting == sb_count) {
  16515. if (post_cnt == 0) {
  16516. /* last sgl posting block */
  16517. list_splice_init(&prep_nblist, &blck_nblist);
  16518. post_cnt = block_cnt;
  16519. } else if (block_cnt == 1) {
  16520. /* last single sgl with non-contiguous xri */
  16521. if (sgl_size > SGL_PAGE_SIZE)
  16522. pdma_phys_sgl1 =
  16523. lpfc_ncmd->dma_phys_sgl +
  16524. SGL_PAGE_SIZE;
  16525. else
  16526. pdma_phys_sgl1 = 0;
  16527. cur_xritag = lpfc_ncmd->cur_iocbq.sli4_xritag;
  16528. status = lpfc_sli4_post_sgl(
  16529. phba, lpfc_ncmd->dma_phys_sgl,
  16530. pdma_phys_sgl1, cur_xritag);
  16531. if (status) {
  16532. /* Post error. Buffer unavailable. */
  16533. lpfc_ncmd->flags |=
  16534. LPFC_SBUF_NOT_POSTED;
  16535. } else {
  16536. /* Post success. Bffer available. */
  16537. lpfc_ncmd->flags &=
  16538. ~LPFC_SBUF_NOT_POSTED;
  16539. lpfc_ncmd->status = IOSTAT_SUCCESS;
  16540. num_posted++;
  16541. }
  16542. /* success, put on NVME buffer sgl list */
  16543. list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
  16544. }
  16545. }
  16546. /* continue until a nembed page worth of sgls */
  16547. if (post_cnt == 0)
  16548. continue;
  16549. /* post block of NVME buffer list sgls */
  16550. status = lpfc_sli4_post_io_sgl_block(phba, &blck_nblist,
  16551. post_cnt);
  16552. /* don't reset xirtag due to hole in xri block */
  16553. if (block_cnt == 0)
  16554. last_xritag = NO_XRI;
  16555. /* reset NVME buffer post count for next round of posting */
  16556. post_cnt = 0;
  16557. /* put posted NVME buffer-sgl posted on NVME buffer sgl list */
  16558. while (!list_empty(&blck_nblist)) {
  16559. list_remove_head(&blck_nblist, lpfc_ncmd,
  16560. struct lpfc_io_buf, list);
  16561. if (status) {
  16562. /* Post error. Mark buffer unavailable. */
  16563. lpfc_ncmd->flags |= LPFC_SBUF_NOT_POSTED;
  16564. } else {
  16565. /* Post success, Mark buffer available. */
  16566. lpfc_ncmd->flags &= ~LPFC_SBUF_NOT_POSTED;
  16567. lpfc_ncmd->status = IOSTAT_SUCCESS;
  16568. num_posted++;
  16569. }
  16570. list_add_tail(&lpfc_ncmd->list, &nvme_nblist);
  16571. }
  16572. }
  16573. /* Push NVME buffers with sgl posted to the available list */
  16574. lpfc_io_buf_replenish(phba, &nvme_nblist);
  16575. return num_posted;
  16576. }
  16577. /**
  16578. * lpfc_fc_frame_check - Check that this frame is a valid frame to handle
  16579. * @phba: pointer to lpfc_hba struct that the frame was received on
  16580. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  16581. *
  16582. * This function checks the fields in the @fc_hdr to see if the FC frame is a
  16583. * valid type of frame that the LPFC driver will handle. This function will
  16584. * return a zero if the frame is a valid frame or a non zero value when the
  16585. * frame does not pass the check.
  16586. **/
  16587. static int
  16588. lpfc_fc_frame_check(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr)
  16589. {
  16590. /* make rctl_names static to save stack space */
  16591. struct fc_vft_header *fc_vft_hdr;
  16592. uint32_t *header = (uint32_t *) fc_hdr;
  16593. #define FC_RCTL_MDS_DIAGS 0xF4
  16594. switch (fc_hdr->fh_r_ctl) {
  16595. case FC_RCTL_DD_UNCAT: /* uncategorized information */
  16596. case FC_RCTL_DD_SOL_DATA: /* solicited data */
  16597. case FC_RCTL_DD_UNSOL_CTL: /* unsolicited control */
  16598. case FC_RCTL_DD_SOL_CTL: /* solicited control or reply */
  16599. case FC_RCTL_DD_UNSOL_DATA: /* unsolicited data */
  16600. case FC_RCTL_DD_DATA_DESC: /* data descriptor */
  16601. case FC_RCTL_DD_UNSOL_CMD: /* unsolicited command */
  16602. case FC_RCTL_DD_CMD_STATUS: /* command status */
  16603. case FC_RCTL_ELS_REQ: /* extended link services request */
  16604. case FC_RCTL_ELS_REP: /* extended link services reply */
  16605. case FC_RCTL_ELS4_REQ: /* FC-4 ELS request */
  16606. case FC_RCTL_ELS4_REP: /* FC-4 ELS reply */
  16607. case FC_RCTL_BA_ABTS: /* basic link service abort */
  16608. case FC_RCTL_BA_RMC: /* remove connection */
  16609. case FC_RCTL_BA_ACC: /* basic accept */
  16610. case FC_RCTL_BA_RJT: /* basic reject */
  16611. case FC_RCTL_BA_PRMT:
  16612. case FC_RCTL_ACK_1: /* acknowledge_1 */
  16613. case FC_RCTL_ACK_0: /* acknowledge_0 */
  16614. case FC_RCTL_P_RJT: /* port reject */
  16615. case FC_RCTL_F_RJT: /* fabric reject */
  16616. case FC_RCTL_P_BSY: /* port busy */
  16617. case FC_RCTL_F_BSY: /* fabric busy to data frame */
  16618. case FC_RCTL_F_BSYL: /* fabric busy to link control frame */
  16619. case FC_RCTL_LCR: /* link credit reset */
  16620. case FC_RCTL_MDS_DIAGS: /* MDS Diagnostics */
  16621. case FC_RCTL_END: /* end */
  16622. break;
  16623. case FC_RCTL_VFTH: /* Virtual Fabric tagging Header */
  16624. fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  16625. fc_hdr = &((struct fc_frame_header *)fc_vft_hdr)[1];
  16626. return lpfc_fc_frame_check(phba, fc_hdr);
  16627. case FC_RCTL_BA_NOP: /* basic link service NOP */
  16628. default:
  16629. goto drop;
  16630. }
  16631. switch (fc_hdr->fh_type) {
  16632. case FC_TYPE_BLS:
  16633. case FC_TYPE_ELS:
  16634. case FC_TYPE_FCP:
  16635. case FC_TYPE_CT:
  16636. case FC_TYPE_NVME:
  16637. break;
  16638. case FC_TYPE_IP:
  16639. case FC_TYPE_ILS:
  16640. default:
  16641. goto drop;
  16642. }
  16643. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  16644. "2538 Received frame rctl:x%x, type:x%x, "
  16645. "frame Data:%08x %08x %08x %08x %08x %08x %08x\n",
  16646. fc_hdr->fh_r_ctl, fc_hdr->fh_type,
  16647. be32_to_cpu(header[0]), be32_to_cpu(header[1]),
  16648. be32_to_cpu(header[2]), be32_to_cpu(header[3]),
  16649. be32_to_cpu(header[4]), be32_to_cpu(header[5]),
  16650. be32_to_cpu(header[6]));
  16651. return 0;
  16652. drop:
  16653. lpfc_printf_log(phba, KERN_WARNING, LOG_ELS,
  16654. "2539 Dropped frame rctl:x%x type:x%x\n",
  16655. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  16656. return 1;
  16657. }
  16658. /**
  16659. * lpfc_fc_hdr_get_vfi - Get the VFI from an FC frame
  16660. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  16661. *
  16662. * This function processes the FC header to retrieve the VFI from the VF
  16663. * header, if one exists. This function will return the VFI if one exists
  16664. * or 0 if no VSAN Header exists.
  16665. **/
  16666. static uint32_t
  16667. lpfc_fc_hdr_get_vfi(struct fc_frame_header *fc_hdr)
  16668. {
  16669. struct fc_vft_header *fc_vft_hdr = (struct fc_vft_header *)fc_hdr;
  16670. if (fc_hdr->fh_r_ctl != FC_RCTL_VFTH)
  16671. return 0;
  16672. return bf_get(fc_vft_hdr_vf_id, fc_vft_hdr);
  16673. }
  16674. /**
  16675. * lpfc_fc_frame_to_vport - Finds the vport that a frame is destined to
  16676. * @phba: Pointer to the HBA structure to search for the vport on
  16677. * @fc_hdr: A pointer to the FC Header data (In Big Endian Format)
  16678. * @fcfi: The FC Fabric ID that the frame came from
  16679. * @did: Destination ID to match against
  16680. *
  16681. * This function searches the @phba for a vport that matches the content of the
  16682. * @fc_hdr passed in and the @fcfi. This function uses the @fc_hdr to fetch the
  16683. * VFI, if the Virtual Fabric Tagging Header exists, and the DID. This function
  16684. * returns the matching vport pointer or NULL if unable to match frame to a
  16685. * vport.
  16686. **/
  16687. static struct lpfc_vport *
  16688. lpfc_fc_frame_to_vport(struct lpfc_hba *phba, struct fc_frame_header *fc_hdr,
  16689. uint16_t fcfi, uint32_t did)
  16690. {
  16691. struct lpfc_vport **vports;
  16692. struct lpfc_vport *vport = NULL;
  16693. int i;
  16694. if (did == Fabric_DID)
  16695. return phba->pport;
  16696. if ((phba->pport->fc_flag & FC_PT2PT) &&
  16697. !(phba->link_state == LPFC_HBA_READY))
  16698. return phba->pport;
  16699. vports = lpfc_create_vport_work_array(phba);
  16700. if (vports != NULL) {
  16701. for (i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  16702. if (phba->fcf.fcfi == fcfi &&
  16703. vports[i]->vfi == lpfc_fc_hdr_get_vfi(fc_hdr) &&
  16704. vports[i]->fc_myDID == did) {
  16705. vport = vports[i];
  16706. break;
  16707. }
  16708. }
  16709. }
  16710. lpfc_destroy_vport_work_array(phba, vports);
  16711. return vport;
  16712. }
  16713. /**
  16714. * lpfc_update_rcv_time_stamp - Update vport's rcv seq time stamp
  16715. * @vport: The vport to work on.
  16716. *
  16717. * This function updates the receive sequence time stamp for this vport. The
  16718. * receive sequence time stamp indicates the time that the last frame of the
  16719. * the sequence that has been idle for the longest amount of time was received.
  16720. * the driver uses this time stamp to indicate if any received sequences have
  16721. * timed out.
  16722. **/
  16723. static void
  16724. lpfc_update_rcv_time_stamp(struct lpfc_vport *vport)
  16725. {
  16726. struct lpfc_dmabuf *h_buf;
  16727. struct hbq_dmabuf *dmabuf = NULL;
  16728. /* get the oldest sequence on the rcv list */
  16729. h_buf = list_get_first(&vport->rcv_buffer_list,
  16730. struct lpfc_dmabuf, list);
  16731. if (!h_buf)
  16732. return;
  16733. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  16734. vport->rcv_buffer_time_stamp = dmabuf->time_stamp;
  16735. }
  16736. /**
  16737. * lpfc_cleanup_rcv_buffers - Cleans up all outstanding receive sequences.
  16738. * @vport: The vport that the received sequences were sent to.
  16739. *
  16740. * This function cleans up all outstanding received sequences. This is called
  16741. * by the driver when a link event or user action invalidates all the received
  16742. * sequences.
  16743. **/
  16744. void
  16745. lpfc_cleanup_rcv_buffers(struct lpfc_vport *vport)
  16746. {
  16747. struct lpfc_dmabuf *h_buf, *hnext;
  16748. struct lpfc_dmabuf *d_buf, *dnext;
  16749. struct hbq_dmabuf *dmabuf = NULL;
  16750. /* start with the oldest sequence on the rcv list */
  16751. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  16752. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  16753. list_del_init(&dmabuf->hbuf.list);
  16754. list_for_each_entry_safe(d_buf, dnext,
  16755. &dmabuf->dbuf.list, list) {
  16756. list_del_init(&d_buf->list);
  16757. lpfc_in_buf_free(vport->phba, d_buf);
  16758. }
  16759. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  16760. }
  16761. }
  16762. /**
  16763. * lpfc_rcv_seq_check_edtov - Cleans up timed out receive sequences.
  16764. * @vport: The vport that the received sequences were sent to.
  16765. *
  16766. * This function determines whether any received sequences have timed out by
  16767. * first checking the vport's rcv_buffer_time_stamp. If this time_stamp
  16768. * indicates that there is at least one timed out sequence this routine will
  16769. * go through the received sequences one at a time from most inactive to most
  16770. * active to determine which ones need to be cleaned up. Once it has determined
  16771. * that a sequence needs to be cleaned up it will simply free up the resources
  16772. * without sending an abort.
  16773. **/
  16774. void
  16775. lpfc_rcv_seq_check_edtov(struct lpfc_vport *vport)
  16776. {
  16777. struct lpfc_dmabuf *h_buf, *hnext;
  16778. struct lpfc_dmabuf *d_buf, *dnext;
  16779. struct hbq_dmabuf *dmabuf = NULL;
  16780. unsigned long timeout;
  16781. int abort_count = 0;
  16782. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  16783. vport->rcv_buffer_time_stamp);
  16784. if (list_empty(&vport->rcv_buffer_list) ||
  16785. time_before(jiffies, timeout))
  16786. return;
  16787. /* start with the oldest sequence on the rcv list */
  16788. list_for_each_entry_safe(h_buf, hnext, &vport->rcv_buffer_list, list) {
  16789. dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  16790. timeout = (msecs_to_jiffies(vport->phba->fc_edtov) +
  16791. dmabuf->time_stamp);
  16792. if (time_before(jiffies, timeout))
  16793. break;
  16794. abort_count++;
  16795. list_del_init(&dmabuf->hbuf.list);
  16796. list_for_each_entry_safe(d_buf, dnext,
  16797. &dmabuf->dbuf.list, list) {
  16798. list_del_init(&d_buf->list);
  16799. lpfc_in_buf_free(vport->phba, d_buf);
  16800. }
  16801. lpfc_in_buf_free(vport->phba, &dmabuf->dbuf);
  16802. }
  16803. if (abort_count)
  16804. lpfc_update_rcv_time_stamp(vport);
  16805. }
  16806. /**
  16807. * lpfc_fc_frame_add - Adds a frame to the vport's list of received sequences
  16808. * @vport: pointer to a vitural port
  16809. * @dmabuf: pointer to a dmabuf that describes the hdr and data of the FC frame
  16810. *
  16811. * This function searches through the existing incomplete sequences that have
  16812. * been sent to this @vport. If the frame matches one of the incomplete
  16813. * sequences then the dbuf in the @dmabuf is added to the list of frames that
  16814. * make up that sequence. If no sequence is found that matches this frame then
  16815. * the function will add the hbuf in the @dmabuf to the @vport's rcv_buffer_list
  16816. * This function returns a pointer to the first dmabuf in the sequence list that
  16817. * the frame was linked to.
  16818. **/
  16819. static struct hbq_dmabuf *
  16820. lpfc_fc_frame_add(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  16821. {
  16822. struct fc_frame_header *new_hdr;
  16823. struct fc_frame_header *temp_hdr;
  16824. struct lpfc_dmabuf *d_buf;
  16825. struct lpfc_dmabuf *h_buf;
  16826. struct hbq_dmabuf *seq_dmabuf = NULL;
  16827. struct hbq_dmabuf *temp_dmabuf = NULL;
  16828. uint8_t found = 0;
  16829. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  16830. dmabuf->time_stamp = jiffies;
  16831. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  16832. /* Use the hdr_buf to find the sequence that this frame belongs to */
  16833. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  16834. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  16835. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  16836. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  16837. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  16838. continue;
  16839. /* found a pending sequence that matches this frame */
  16840. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  16841. break;
  16842. }
  16843. if (!seq_dmabuf) {
  16844. /*
  16845. * This indicates first frame received for this sequence.
  16846. * Queue the buffer on the vport's rcv_buffer_list.
  16847. */
  16848. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  16849. lpfc_update_rcv_time_stamp(vport);
  16850. return dmabuf;
  16851. }
  16852. temp_hdr = seq_dmabuf->hbuf.virt;
  16853. if (be16_to_cpu(new_hdr->fh_seq_cnt) <
  16854. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  16855. list_del_init(&seq_dmabuf->hbuf.list);
  16856. list_add_tail(&dmabuf->hbuf.list, &vport->rcv_buffer_list);
  16857. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  16858. lpfc_update_rcv_time_stamp(vport);
  16859. return dmabuf;
  16860. }
  16861. /* move this sequence to the tail to indicate a young sequence */
  16862. list_move_tail(&seq_dmabuf->hbuf.list, &vport->rcv_buffer_list);
  16863. seq_dmabuf->time_stamp = jiffies;
  16864. lpfc_update_rcv_time_stamp(vport);
  16865. if (list_empty(&seq_dmabuf->dbuf.list)) {
  16866. list_add_tail(&dmabuf->dbuf.list, &seq_dmabuf->dbuf.list);
  16867. return seq_dmabuf;
  16868. }
  16869. /* find the correct place in the sequence to insert this frame */
  16870. d_buf = list_entry(seq_dmabuf->dbuf.list.prev, typeof(*d_buf), list);
  16871. while (!found) {
  16872. temp_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  16873. temp_hdr = (struct fc_frame_header *)temp_dmabuf->hbuf.virt;
  16874. /*
  16875. * If the frame's sequence count is greater than the frame on
  16876. * the list then insert the frame right after this frame
  16877. */
  16878. if (be16_to_cpu(new_hdr->fh_seq_cnt) >
  16879. be16_to_cpu(temp_hdr->fh_seq_cnt)) {
  16880. list_add(&dmabuf->dbuf.list, &temp_dmabuf->dbuf.list);
  16881. found = 1;
  16882. break;
  16883. }
  16884. if (&d_buf->list == &seq_dmabuf->dbuf.list)
  16885. break;
  16886. d_buf = list_entry(d_buf->list.prev, typeof(*d_buf), list);
  16887. }
  16888. if (found)
  16889. return seq_dmabuf;
  16890. return NULL;
  16891. }
  16892. /**
  16893. * lpfc_sli4_abort_partial_seq - Abort partially assembled unsol sequence
  16894. * @vport: pointer to a vitural port
  16895. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  16896. *
  16897. * This function tries to abort from the partially assembed sequence, described
  16898. * by the information from basic abbort @dmabuf. It checks to see whether such
  16899. * partially assembled sequence held by the driver. If so, it shall free up all
  16900. * the frames from the partially assembled sequence.
  16901. *
  16902. * Return
  16903. * true -- if there is matching partially assembled sequence present and all
  16904. * the frames freed with the sequence;
  16905. * false -- if there is no matching partially assembled sequence present so
  16906. * nothing got aborted in the lower layer driver
  16907. **/
  16908. static bool
  16909. lpfc_sli4_abort_partial_seq(struct lpfc_vport *vport,
  16910. struct hbq_dmabuf *dmabuf)
  16911. {
  16912. struct fc_frame_header *new_hdr;
  16913. struct fc_frame_header *temp_hdr;
  16914. struct lpfc_dmabuf *d_buf, *n_buf, *h_buf;
  16915. struct hbq_dmabuf *seq_dmabuf = NULL;
  16916. /* Use the hdr_buf to find the sequence that matches this frame */
  16917. INIT_LIST_HEAD(&dmabuf->dbuf.list);
  16918. INIT_LIST_HEAD(&dmabuf->hbuf.list);
  16919. new_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  16920. list_for_each_entry(h_buf, &vport->rcv_buffer_list, list) {
  16921. temp_hdr = (struct fc_frame_header *)h_buf->virt;
  16922. if ((temp_hdr->fh_seq_id != new_hdr->fh_seq_id) ||
  16923. (temp_hdr->fh_ox_id != new_hdr->fh_ox_id) ||
  16924. (memcmp(&temp_hdr->fh_s_id, &new_hdr->fh_s_id, 3)))
  16925. continue;
  16926. /* found a pending sequence that matches this frame */
  16927. seq_dmabuf = container_of(h_buf, struct hbq_dmabuf, hbuf);
  16928. break;
  16929. }
  16930. /* Free up all the frames from the partially assembled sequence */
  16931. if (seq_dmabuf) {
  16932. list_for_each_entry_safe(d_buf, n_buf,
  16933. &seq_dmabuf->dbuf.list, list) {
  16934. list_del_init(&d_buf->list);
  16935. lpfc_in_buf_free(vport->phba, d_buf);
  16936. }
  16937. return true;
  16938. }
  16939. return false;
  16940. }
  16941. /**
  16942. * lpfc_sli4_abort_ulp_seq - Abort assembled unsol sequence from ulp
  16943. * @vport: pointer to a vitural port
  16944. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  16945. *
  16946. * This function tries to abort from the assembed sequence from upper level
  16947. * protocol, described by the information from basic abbort @dmabuf. It
  16948. * checks to see whether such pending context exists at upper level protocol.
  16949. * If so, it shall clean up the pending context.
  16950. *
  16951. * Return
  16952. * true -- if there is matching pending context of the sequence cleaned
  16953. * at ulp;
  16954. * false -- if there is no matching pending context of the sequence present
  16955. * at ulp.
  16956. **/
  16957. static bool
  16958. lpfc_sli4_abort_ulp_seq(struct lpfc_vport *vport, struct hbq_dmabuf *dmabuf)
  16959. {
  16960. struct lpfc_hba *phba = vport->phba;
  16961. int handled;
  16962. /* Accepting abort at ulp with SLI4 only */
  16963. if (phba->sli_rev < LPFC_SLI_REV4)
  16964. return false;
  16965. /* Register all caring upper level protocols to attend abort */
  16966. handled = lpfc_ct_handle_unsol_abort(phba, dmabuf);
  16967. if (handled)
  16968. return true;
  16969. return false;
  16970. }
  16971. /**
  16972. * lpfc_sli4_seq_abort_rsp_cmpl - BLS ABORT RSP seq abort iocb complete handler
  16973. * @phba: Pointer to HBA context object.
  16974. * @cmd_iocbq: pointer to the command iocbq structure.
  16975. * @rsp_iocbq: pointer to the response iocbq structure.
  16976. *
  16977. * This function handles the sequence abort response iocb command complete
  16978. * event. It properly releases the memory allocated to the sequence abort
  16979. * accept iocb.
  16980. **/
  16981. static void
  16982. lpfc_sli4_seq_abort_rsp_cmpl(struct lpfc_hba *phba,
  16983. struct lpfc_iocbq *cmd_iocbq,
  16984. struct lpfc_iocbq *rsp_iocbq)
  16985. {
  16986. if (cmd_iocbq) {
  16987. lpfc_nlp_put(cmd_iocbq->ndlp);
  16988. lpfc_sli_release_iocbq(phba, cmd_iocbq);
  16989. }
  16990. /* Failure means BLS ABORT RSP did not get delivered to remote node*/
  16991. if (rsp_iocbq && rsp_iocbq->iocb.ulpStatus)
  16992. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  16993. "3154 BLS ABORT RSP failed, data: x%x/x%x\n",
  16994. get_job_ulpstatus(phba, rsp_iocbq),
  16995. get_job_word4(phba, rsp_iocbq));
  16996. }
  16997. /**
  16998. * lpfc_sli4_xri_inrange - check xri is in range of xris owned by driver.
  16999. * @phba: Pointer to HBA context object.
  17000. * @xri: xri id in transaction.
  17001. *
  17002. * This function validates the xri maps to the known range of XRIs allocated an
  17003. * used by the driver.
  17004. **/
  17005. uint16_t
  17006. lpfc_sli4_xri_inrange(struct lpfc_hba *phba,
  17007. uint16_t xri)
  17008. {
  17009. uint16_t i;
  17010. for (i = 0; i < phba->sli4_hba.max_cfg_param.max_xri; i++) {
  17011. if (xri == phba->sli4_hba.xri_ids[i])
  17012. return i;
  17013. }
  17014. return NO_XRI;
  17015. }
  17016. /**
  17017. * lpfc_sli4_seq_abort_rsp - bls rsp to sequence abort
  17018. * @vport: pointer to a virtual port.
  17019. * @fc_hdr: pointer to a FC frame header.
  17020. * @aborted: was the partially assembled receive sequence successfully aborted
  17021. *
  17022. * This function sends a basic response to a previous unsol sequence abort
  17023. * event after aborting the sequence handling.
  17024. **/
  17025. void
  17026. lpfc_sli4_seq_abort_rsp(struct lpfc_vport *vport,
  17027. struct fc_frame_header *fc_hdr, bool aborted)
  17028. {
  17029. struct lpfc_hba *phba = vport->phba;
  17030. struct lpfc_iocbq *ctiocb = NULL;
  17031. struct lpfc_nodelist *ndlp;
  17032. uint16_t oxid, rxid, xri, lxri;
  17033. uint32_t sid, fctl;
  17034. union lpfc_wqe128 *icmd;
  17035. int rc;
  17036. if (!lpfc_is_link_up(phba))
  17037. return;
  17038. sid = sli4_sid_from_fc_hdr(fc_hdr);
  17039. oxid = be16_to_cpu(fc_hdr->fh_ox_id);
  17040. rxid = be16_to_cpu(fc_hdr->fh_rx_id);
  17041. ndlp = lpfc_findnode_did(vport, sid);
  17042. if (!ndlp) {
  17043. ndlp = lpfc_nlp_init(vport, sid);
  17044. if (!ndlp) {
  17045. lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
  17046. "1268 Failed to allocate ndlp for "
  17047. "oxid:x%x SID:x%x\n", oxid, sid);
  17048. return;
  17049. }
  17050. /* Put ndlp onto pport node list */
  17051. lpfc_enqueue_node(vport, ndlp);
  17052. }
  17053. /* Allocate buffer for rsp iocb */
  17054. ctiocb = lpfc_sli_get_iocbq(phba);
  17055. if (!ctiocb)
  17056. return;
  17057. icmd = &ctiocb->wqe;
  17058. /* Extract the F_CTL field from FC_HDR */
  17059. fctl = sli4_fctl_from_fc_hdr(fc_hdr);
  17060. ctiocb->ndlp = lpfc_nlp_get(ndlp);
  17061. if (!ctiocb->ndlp) {
  17062. lpfc_sli_release_iocbq(phba, ctiocb);
  17063. return;
  17064. }
  17065. ctiocb->vport = phba->pport;
  17066. ctiocb->cmd_cmpl = lpfc_sli4_seq_abort_rsp_cmpl;
  17067. ctiocb->sli4_lxritag = NO_XRI;
  17068. ctiocb->sli4_xritag = NO_XRI;
  17069. ctiocb->abort_rctl = FC_RCTL_BA_ACC;
  17070. if (fctl & FC_FC_EX_CTX)
  17071. /* Exchange responder sent the abort so we
  17072. * own the oxid.
  17073. */
  17074. xri = oxid;
  17075. else
  17076. xri = rxid;
  17077. lxri = lpfc_sli4_xri_inrange(phba, xri);
  17078. if (lxri != NO_XRI)
  17079. lpfc_set_rrq_active(phba, ndlp, lxri,
  17080. (xri == oxid) ? rxid : oxid, 0);
  17081. /* For BA_ABTS from exchange responder, if the logical xri with
  17082. * the oxid maps to the FCP XRI range, the port no longer has
  17083. * that exchange context, send a BLS_RJT. Override the IOCB for
  17084. * a BA_RJT.
  17085. */
  17086. if ((fctl & FC_FC_EX_CTX) &&
  17087. (lxri > lpfc_sli4_get_iocb_cnt(phba))) {
  17088. ctiocb->abort_rctl = FC_RCTL_BA_RJT;
  17089. bf_set(xmit_bls_rsp64_rjt_vspec, &icmd->xmit_bls_rsp, 0);
  17090. bf_set(xmit_bls_rsp64_rjt_expc, &icmd->xmit_bls_rsp,
  17091. FC_BA_RJT_INV_XID);
  17092. bf_set(xmit_bls_rsp64_rjt_rsnc, &icmd->xmit_bls_rsp,
  17093. FC_BA_RJT_UNABLE);
  17094. }
  17095. /* If BA_ABTS failed to abort a partially assembled receive sequence,
  17096. * the driver no longer has that exchange, send a BLS_RJT. Override
  17097. * the IOCB for a BA_RJT.
  17098. */
  17099. if (aborted == false) {
  17100. ctiocb->abort_rctl = FC_RCTL_BA_RJT;
  17101. bf_set(xmit_bls_rsp64_rjt_vspec, &icmd->xmit_bls_rsp, 0);
  17102. bf_set(xmit_bls_rsp64_rjt_expc, &icmd->xmit_bls_rsp,
  17103. FC_BA_RJT_INV_XID);
  17104. bf_set(xmit_bls_rsp64_rjt_rsnc, &icmd->xmit_bls_rsp,
  17105. FC_BA_RJT_UNABLE);
  17106. }
  17107. if (fctl & FC_FC_EX_CTX) {
  17108. /* ABTS sent by responder to CT exchange, construction
  17109. * of BA_ACC will use OX_ID from ABTS for the XRI_TAG
  17110. * field and RX_ID from ABTS for RX_ID field.
  17111. */
  17112. ctiocb->abort_bls = LPFC_ABTS_UNSOL_RSP;
  17113. bf_set(xmit_bls_rsp64_rxid, &icmd->xmit_bls_rsp, rxid);
  17114. } else {
  17115. /* ABTS sent by initiator to CT exchange, construction
  17116. * of BA_ACC will need to allocate a new XRI as for the
  17117. * XRI_TAG field.
  17118. */
  17119. ctiocb->abort_bls = LPFC_ABTS_UNSOL_INT;
  17120. }
  17121. /* OX_ID is invariable to who sent ABTS to CT exchange */
  17122. bf_set(xmit_bls_rsp64_oxid, &icmd->xmit_bls_rsp, oxid);
  17123. bf_set(xmit_bls_rsp64_oxid, &icmd->xmit_bls_rsp, rxid);
  17124. /* Use CT=VPI */
  17125. bf_set(wqe_els_did, &icmd->xmit_bls_rsp.wqe_dest,
  17126. ndlp->nlp_DID);
  17127. bf_set(xmit_bls_rsp64_temprpi, &icmd->xmit_bls_rsp,
  17128. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  17129. bf_set(wqe_cmnd, &icmd->generic.wqe_com, CMD_XMIT_BLS_RSP64_CX);
  17130. /* Xmit CT abts response on exchange <xid> */
  17131. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  17132. "1200 Send BLS cmd x%x on oxid x%x Data: x%x\n",
  17133. ctiocb->abort_rctl, oxid, phba->link_state);
  17134. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, ctiocb, 0);
  17135. if (rc == IOCB_ERROR) {
  17136. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  17137. "2925 Failed to issue CT ABTS RSP x%x on "
  17138. "xri x%x, Data x%x\n",
  17139. ctiocb->abort_rctl, oxid,
  17140. phba->link_state);
  17141. lpfc_nlp_put(ndlp);
  17142. ctiocb->ndlp = NULL;
  17143. lpfc_sli_release_iocbq(phba, ctiocb);
  17144. }
  17145. }
  17146. /**
  17147. * lpfc_sli4_handle_unsol_abort - Handle sli-4 unsolicited abort event
  17148. * @vport: Pointer to the vport on which this sequence was received
  17149. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  17150. *
  17151. * This function handles an SLI-4 unsolicited abort event. If the unsolicited
  17152. * receive sequence is only partially assembed by the driver, it shall abort
  17153. * the partially assembled frames for the sequence. Otherwise, if the
  17154. * unsolicited receive sequence has been completely assembled and passed to
  17155. * the Upper Layer Protocol (ULP), it then mark the per oxid status for the
  17156. * unsolicited sequence has been aborted. After that, it will issue a basic
  17157. * accept to accept the abort.
  17158. **/
  17159. static void
  17160. lpfc_sli4_handle_unsol_abort(struct lpfc_vport *vport,
  17161. struct hbq_dmabuf *dmabuf)
  17162. {
  17163. struct lpfc_hba *phba = vport->phba;
  17164. struct fc_frame_header fc_hdr;
  17165. uint32_t fctl;
  17166. bool aborted;
  17167. /* Make a copy of fc_hdr before the dmabuf being released */
  17168. memcpy(&fc_hdr, dmabuf->hbuf.virt, sizeof(struct fc_frame_header));
  17169. fctl = sli4_fctl_from_fc_hdr(&fc_hdr);
  17170. if (fctl & FC_FC_EX_CTX) {
  17171. /* ABTS by responder to exchange, no cleanup needed */
  17172. aborted = true;
  17173. } else {
  17174. /* ABTS by initiator to exchange, need to do cleanup */
  17175. aborted = lpfc_sli4_abort_partial_seq(vport, dmabuf);
  17176. if (aborted == false)
  17177. aborted = lpfc_sli4_abort_ulp_seq(vport, dmabuf);
  17178. }
  17179. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17180. if (phba->nvmet_support) {
  17181. lpfc_nvmet_rcv_unsol_abort(vport, &fc_hdr);
  17182. return;
  17183. }
  17184. /* Respond with BA_ACC or BA_RJT accordingly */
  17185. lpfc_sli4_seq_abort_rsp(vport, &fc_hdr, aborted);
  17186. }
  17187. /**
  17188. * lpfc_seq_complete - Indicates if a sequence is complete
  17189. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  17190. *
  17191. * This function checks the sequence, starting with the frame described by
  17192. * @dmabuf, to see if all the frames associated with this sequence are present.
  17193. * the frames associated with this sequence are linked to the @dmabuf using the
  17194. * dbuf list. This function looks for two major things. 1) That the first frame
  17195. * has a sequence count of zero. 2) There is a frame with last frame of sequence
  17196. * set. 3) That there are no holes in the sequence count. The function will
  17197. * return 1 when the sequence is complete, otherwise it will return 0.
  17198. **/
  17199. static int
  17200. lpfc_seq_complete(struct hbq_dmabuf *dmabuf)
  17201. {
  17202. struct fc_frame_header *hdr;
  17203. struct lpfc_dmabuf *d_buf;
  17204. struct hbq_dmabuf *seq_dmabuf;
  17205. uint32_t fctl;
  17206. int seq_count = 0;
  17207. hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  17208. /* make sure first fame of sequence has a sequence count of zero */
  17209. if (hdr->fh_seq_cnt != seq_count)
  17210. return 0;
  17211. fctl = (hdr->fh_f_ctl[0] << 16 |
  17212. hdr->fh_f_ctl[1] << 8 |
  17213. hdr->fh_f_ctl[2]);
  17214. /* If last frame of sequence we can return success. */
  17215. if (fctl & FC_FC_END_SEQ)
  17216. return 1;
  17217. list_for_each_entry(d_buf, &dmabuf->dbuf.list, list) {
  17218. seq_dmabuf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  17219. hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  17220. /* If there is a hole in the sequence count then fail. */
  17221. if (++seq_count != be16_to_cpu(hdr->fh_seq_cnt))
  17222. return 0;
  17223. fctl = (hdr->fh_f_ctl[0] << 16 |
  17224. hdr->fh_f_ctl[1] << 8 |
  17225. hdr->fh_f_ctl[2]);
  17226. /* If last frame of sequence we can return success. */
  17227. if (fctl & FC_FC_END_SEQ)
  17228. return 1;
  17229. }
  17230. return 0;
  17231. }
  17232. /**
  17233. * lpfc_prep_seq - Prep sequence for ULP processing
  17234. * @vport: Pointer to the vport on which this sequence was received
  17235. * @seq_dmabuf: pointer to a dmabuf that describes the FC sequence
  17236. *
  17237. * This function takes a sequence, described by a list of frames, and creates
  17238. * a list of iocbq structures to describe the sequence. This iocbq list will be
  17239. * used to issue to the generic unsolicited sequence handler. This routine
  17240. * returns a pointer to the first iocbq in the list. If the function is unable
  17241. * to allocate an iocbq then it throw out the received frames that were not
  17242. * able to be described and return a pointer to the first iocbq. If unable to
  17243. * allocate any iocbqs (including the first) this function will return NULL.
  17244. **/
  17245. static struct lpfc_iocbq *
  17246. lpfc_prep_seq(struct lpfc_vport *vport, struct hbq_dmabuf *seq_dmabuf)
  17247. {
  17248. struct hbq_dmabuf *hbq_buf;
  17249. struct lpfc_dmabuf *d_buf, *n_buf;
  17250. struct lpfc_iocbq *first_iocbq, *iocbq;
  17251. struct fc_frame_header *fc_hdr;
  17252. uint32_t sid;
  17253. uint32_t len, tot_len;
  17254. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  17255. /* remove from receive buffer list */
  17256. list_del_init(&seq_dmabuf->hbuf.list);
  17257. lpfc_update_rcv_time_stamp(vport);
  17258. /* get the Remote Port's SID */
  17259. sid = sli4_sid_from_fc_hdr(fc_hdr);
  17260. tot_len = 0;
  17261. /* Get an iocbq struct to fill in. */
  17262. first_iocbq = lpfc_sli_get_iocbq(vport->phba);
  17263. if (first_iocbq) {
  17264. /* Initialize the first IOCB. */
  17265. first_iocbq->wcqe_cmpl.total_data_placed = 0;
  17266. bf_set(lpfc_wcqe_c_status, &first_iocbq->wcqe_cmpl,
  17267. IOSTAT_SUCCESS);
  17268. first_iocbq->vport = vport;
  17269. /* Check FC Header to see what TYPE of frame we are rcv'ing */
  17270. if (sli4_type_from_fc_hdr(fc_hdr) == FC_TYPE_ELS) {
  17271. bf_set(els_rsp64_sid, &first_iocbq->wqe.xmit_els_rsp,
  17272. sli4_did_from_fc_hdr(fc_hdr));
  17273. }
  17274. bf_set(wqe_ctxt_tag, &first_iocbq->wqe.xmit_els_rsp.wqe_com,
  17275. NO_XRI);
  17276. bf_set(wqe_rcvoxid, &first_iocbq->wqe.xmit_els_rsp.wqe_com,
  17277. be16_to_cpu(fc_hdr->fh_ox_id));
  17278. /* put the first buffer into the first iocb */
  17279. tot_len = bf_get(lpfc_rcqe_length,
  17280. &seq_dmabuf->cq_event.cqe.rcqe_cmpl);
  17281. first_iocbq->cmd_dmabuf = &seq_dmabuf->dbuf;
  17282. first_iocbq->bpl_dmabuf = NULL;
  17283. /* Keep track of the BDE count */
  17284. first_iocbq->wcqe_cmpl.word3 = 1;
  17285. if (tot_len > LPFC_DATA_BUF_SIZE)
  17286. first_iocbq->wqe.gen_req.bde.tus.f.bdeSize =
  17287. LPFC_DATA_BUF_SIZE;
  17288. else
  17289. first_iocbq->wqe.gen_req.bde.tus.f.bdeSize = tot_len;
  17290. first_iocbq->wcqe_cmpl.total_data_placed = tot_len;
  17291. bf_set(wqe_els_did, &first_iocbq->wqe.xmit_els_rsp.wqe_dest,
  17292. sid);
  17293. }
  17294. iocbq = first_iocbq;
  17295. /*
  17296. * Each IOCBq can have two Buffers assigned, so go through the list
  17297. * of buffers for this sequence and save two buffers in each IOCBq
  17298. */
  17299. list_for_each_entry_safe(d_buf, n_buf, &seq_dmabuf->dbuf.list, list) {
  17300. if (!iocbq) {
  17301. lpfc_in_buf_free(vport->phba, d_buf);
  17302. continue;
  17303. }
  17304. if (!iocbq->bpl_dmabuf) {
  17305. iocbq->bpl_dmabuf = d_buf;
  17306. iocbq->wcqe_cmpl.word3++;
  17307. /* We need to get the size out of the right CQE */
  17308. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  17309. len = bf_get(lpfc_rcqe_length,
  17310. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  17311. iocbq->unsol_rcv_len = len;
  17312. iocbq->wcqe_cmpl.total_data_placed += len;
  17313. tot_len += len;
  17314. } else {
  17315. iocbq = lpfc_sli_get_iocbq(vport->phba);
  17316. if (!iocbq) {
  17317. if (first_iocbq) {
  17318. bf_set(lpfc_wcqe_c_status,
  17319. &first_iocbq->wcqe_cmpl,
  17320. IOSTAT_SUCCESS);
  17321. first_iocbq->wcqe_cmpl.parameter =
  17322. IOERR_NO_RESOURCES;
  17323. }
  17324. lpfc_in_buf_free(vport->phba, d_buf);
  17325. continue;
  17326. }
  17327. /* We need to get the size out of the right CQE */
  17328. hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
  17329. len = bf_get(lpfc_rcqe_length,
  17330. &hbq_buf->cq_event.cqe.rcqe_cmpl);
  17331. iocbq->cmd_dmabuf = d_buf;
  17332. iocbq->bpl_dmabuf = NULL;
  17333. iocbq->wcqe_cmpl.word3 = 1;
  17334. if (len > LPFC_DATA_BUF_SIZE)
  17335. iocbq->wqe.xmit_els_rsp.bde.tus.f.bdeSize =
  17336. LPFC_DATA_BUF_SIZE;
  17337. else
  17338. iocbq->wqe.xmit_els_rsp.bde.tus.f.bdeSize =
  17339. len;
  17340. tot_len += len;
  17341. iocbq->wcqe_cmpl.total_data_placed = tot_len;
  17342. bf_set(wqe_els_did, &iocbq->wqe.xmit_els_rsp.wqe_dest,
  17343. sid);
  17344. list_add_tail(&iocbq->list, &first_iocbq->list);
  17345. }
  17346. }
  17347. /* Free the sequence's header buffer */
  17348. if (!first_iocbq)
  17349. lpfc_in_buf_free(vport->phba, &seq_dmabuf->dbuf);
  17350. return first_iocbq;
  17351. }
  17352. static void
  17353. lpfc_sli4_send_seq_to_ulp(struct lpfc_vport *vport,
  17354. struct hbq_dmabuf *seq_dmabuf)
  17355. {
  17356. struct fc_frame_header *fc_hdr;
  17357. struct lpfc_iocbq *iocbq, *curr_iocb, *next_iocb;
  17358. struct lpfc_hba *phba = vport->phba;
  17359. fc_hdr = (struct fc_frame_header *)seq_dmabuf->hbuf.virt;
  17360. iocbq = lpfc_prep_seq(vport, seq_dmabuf);
  17361. if (!iocbq) {
  17362. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17363. "2707 Ring %d handler: Failed to allocate "
  17364. "iocb Rctl x%x Type x%x received\n",
  17365. LPFC_ELS_RING,
  17366. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  17367. return;
  17368. }
  17369. if (!lpfc_complete_unsol_iocb(phba,
  17370. phba->sli4_hba.els_wq->pring,
  17371. iocbq, fc_hdr->fh_r_ctl,
  17372. fc_hdr->fh_type)) {
  17373. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17374. "2540 Ring %d handler: unexpected Rctl "
  17375. "x%x Type x%x received\n",
  17376. LPFC_ELS_RING,
  17377. fc_hdr->fh_r_ctl, fc_hdr->fh_type);
  17378. lpfc_in_buf_free(phba, &seq_dmabuf->dbuf);
  17379. }
  17380. /* Free iocb created in lpfc_prep_seq */
  17381. list_for_each_entry_safe(curr_iocb, next_iocb,
  17382. &iocbq->list, list) {
  17383. list_del_init(&curr_iocb->list);
  17384. lpfc_sli_release_iocbq(phba, curr_iocb);
  17385. }
  17386. lpfc_sli_release_iocbq(phba, iocbq);
  17387. }
  17388. static void
  17389. lpfc_sli4_mds_loopback_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  17390. struct lpfc_iocbq *rspiocb)
  17391. {
  17392. struct lpfc_dmabuf *pcmd = cmdiocb->cmd_dmabuf;
  17393. if (pcmd && pcmd->virt)
  17394. dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
  17395. kfree(pcmd);
  17396. lpfc_sli_release_iocbq(phba, cmdiocb);
  17397. lpfc_drain_txq(phba);
  17398. }
  17399. static void
  17400. lpfc_sli4_handle_mds_loopback(struct lpfc_vport *vport,
  17401. struct hbq_dmabuf *dmabuf)
  17402. {
  17403. struct fc_frame_header *fc_hdr;
  17404. struct lpfc_hba *phba = vport->phba;
  17405. struct lpfc_iocbq *iocbq = NULL;
  17406. union lpfc_wqe128 *pwqe;
  17407. struct lpfc_dmabuf *pcmd = NULL;
  17408. uint32_t frame_len;
  17409. int rc;
  17410. unsigned long iflags;
  17411. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  17412. frame_len = bf_get(lpfc_rcqe_length, &dmabuf->cq_event.cqe.rcqe_cmpl);
  17413. /* Send the received frame back */
  17414. iocbq = lpfc_sli_get_iocbq(phba);
  17415. if (!iocbq) {
  17416. /* Queue cq event and wakeup worker thread to process it */
  17417. spin_lock_irqsave(&phba->hbalock, iflags);
  17418. list_add_tail(&dmabuf->cq_event.list,
  17419. &phba->sli4_hba.sp_queue_event);
  17420. phba->hba_flag |= HBA_SP_QUEUE_EVT;
  17421. spin_unlock_irqrestore(&phba->hbalock, iflags);
  17422. lpfc_worker_wake_up(phba);
  17423. return;
  17424. }
  17425. /* Allocate buffer for command payload */
  17426. pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  17427. if (pcmd)
  17428. pcmd->virt = dma_pool_alloc(phba->lpfc_drb_pool, GFP_KERNEL,
  17429. &pcmd->phys);
  17430. if (!pcmd || !pcmd->virt)
  17431. goto exit;
  17432. INIT_LIST_HEAD(&pcmd->list);
  17433. /* copyin the payload */
  17434. memcpy(pcmd->virt, dmabuf->dbuf.virt, frame_len);
  17435. iocbq->cmd_dmabuf = pcmd;
  17436. iocbq->vport = vport;
  17437. iocbq->cmd_flag &= ~LPFC_FIP_ELS_ID_MASK;
  17438. iocbq->cmd_flag |= LPFC_USE_FCPWQIDX;
  17439. iocbq->num_bdes = 0;
  17440. pwqe = &iocbq->wqe;
  17441. /* fill in BDE's for command */
  17442. pwqe->gen_req.bde.addrHigh = putPaddrHigh(pcmd->phys);
  17443. pwqe->gen_req.bde.addrLow = putPaddrLow(pcmd->phys);
  17444. pwqe->gen_req.bde.tus.f.bdeSize = frame_len;
  17445. pwqe->gen_req.bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
  17446. pwqe->send_frame.frame_len = frame_len;
  17447. pwqe->send_frame.fc_hdr_wd0 = be32_to_cpu(*((__be32 *)fc_hdr));
  17448. pwqe->send_frame.fc_hdr_wd1 = be32_to_cpu(*((__be32 *)fc_hdr + 1));
  17449. pwqe->send_frame.fc_hdr_wd2 = be32_to_cpu(*((__be32 *)fc_hdr + 2));
  17450. pwqe->send_frame.fc_hdr_wd3 = be32_to_cpu(*((__be32 *)fc_hdr + 3));
  17451. pwqe->send_frame.fc_hdr_wd4 = be32_to_cpu(*((__be32 *)fc_hdr + 4));
  17452. pwqe->send_frame.fc_hdr_wd5 = be32_to_cpu(*((__be32 *)fc_hdr + 5));
  17453. pwqe->generic.wqe_com.word7 = 0;
  17454. pwqe->generic.wqe_com.word10 = 0;
  17455. bf_set(wqe_cmnd, &pwqe->generic.wqe_com, CMD_SEND_FRAME);
  17456. bf_set(wqe_sof, &pwqe->generic.wqe_com, 0x2E); /* SOF byte */
  17457. bf_set(wqe_eof, &pwqe->generic.wqe_com, 0x41); /* EOF byte */
  17458. bf_set(wqe_lenloc, &pwqe->generic.wqe_com, 1);
  17459. bf_set(wqe_xbl, &pwqe->generic.wqe_com, 1);
  17460. bf_set(wqe_dbde, &pwqe->generic.wqe_com, 1);
  17461. bf_set(wqe_xc, &pwqe->generic.wqe_com, 1);
  17462. bf_set(wqe_cmd_type, &pwqe->generic.wqe_com, 0xA);
  17463. bf_set(wqe_cqid, &pwqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  17464. bf_set(wqe_xri_tag, &pwqe->generic.wqe_com, iocbq->sli4_xritag);
  17465. bf_set(wqe_reqtag, &pwqe->generic.wqe_com, iocbq->iotag);
  17466. bf_set(wqe_class, &pwqe->generic.wqe_com, CLASS3);
  17467. pwqe->generic.wqe_com.abort_tag = iocbq->iotag;
  17468. iocbq->cmd_cmpl = lpfc_sli4_mds_loopback_cmpl;
  17469. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocbq, 0);
  17470. if (rc == IOCB_ERROR)
  17471. goto exit;
  17472. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17473. return;
  17474. exit:
  17475. lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
  17476. "2023 Unable to process MDS loopback frame\n");
  17477. if (pcmd && pcmd->virt)
  17478. dma_pool_free(phba->lpfc_drb_pool, pcmd->virt, pcmd->phys);
  17479. kfree(pcmd);
  17480. if (iocbq)
  17481. lpfc_sli_release_iocbq(phba, iocbq);
  17482. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17483. }
  17484. /**
  17485. * lpfc_sli4_handle_received_buffer - Handle received buffers from firmware
  17486. * @phba: Pointer to HBA context object.
  17487. * @dmabuf: Pointer to a dmabuf that describes the FC sequence.
  17488. *
  17489. * This function is called with no lock held. This function processes all
  17490. * the received buffers and gives it to upper layers when a received buffer
  17491. * indicates that it is the final frame in the sequence. The interrupt
  17492. * service routine processes received buffers at interrupt contexts.
  17493. * Worker thread calls lpfc_sli4_handle_received_buffer, which will call the
  17494. * appropriate receive function when the final frame in a sequence is received.
  17495. **/
  17496. void
  17497. lpfc_sli4_handle_received_buffer(struct lpfc_hba *phba,
  17498. struct hbq_dmabuf *dmabuf)
  17499. {
  17500. struct hbq_dmabuf *seq_dmabuf;
  17501. struct fc_frame_header *fc_hdr;
  17502. struct lpfc_vport *vport;
  17503. uint32_t fcfi;
  17504. uint32_t did;
  17505. /* Process each received buffer */
  17506. fc_hdr = (struct fc_frame_header *)dmabuf->hbuf.virt;
  17507. if (fc_hdr->fh_r_ctl == FC_RCTL_MDS_DIAGS ||
  17508. fc_hdr->fh_r_ctl == FC_RCTL_DD_UNSOL_DATA) {
  17509. vport = phba->pport;
  17510. /* Handle MDS Loopback frames */
  17511. if (!(phba->pport->load_flag & FC_UNLOADING))
  17512. lpfc_sli4_handle_mds_loopback(vport, dmabuf);
  17513. else
  17514. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17515. return;
  17516. }
  17517. /* check to see if this a valid type of frame */
  17518. if (lpfc_fc_frame_check(phba, fc_hdr)) {
  17519. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17520. return;
  17521. }
  17522. if ((bf_get(lpfc_cqe_code,
  17523. &dmabuf->cq_event.cqe.rcqe_cmpl) == CQE_CODE_RECEIVE_V1))
  17524. fcfi = bf_get(lpfc_rcqe_fcf_id_v1,
  17525. &dmabuf->cq_event.cqe.rcqe_cmpl);
  17526. else
  17527. fcfi = bf_get(lpfc_rcqe_fcf_id,
  17528. &dmabuf->cq_event.cqe.rcqe_cmpl);
  17529. if (fc_hdr->fh_r_ctl == 0xF4 && fc_hdr->fh_type == 0xFF) {
  17530. vport = phba->pport;
  17531. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  17532. "2023 MDS Loopback %d bytes\n",
  17533. bf_get(lpfc_rcqe_length,
  17534. &dmabuf->cq_event.cqe.rcqe_cmpl));
  17535. /* Handle MDS Loopback frames */
  17536. lpfc_sli4_handle_mds_loopback(vport, dmabuf);
  17537. return;
  17538. }
  17539. /* d_id this frame is directed to */
  17540. did = sli4_did_from_fc_hdr(fc_hdr);
  17541. vport = lpfc_fc_frame_to_vport(phba, fc_hdr, fcfi, did);
  17542. if (!vport) {
  17543. /* throw out the frame */
  17544. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17545. return;
  17546. }
  17547. /* vport is registered unless we rcv a FLOGI directed to Fabric_DID */
  17548. if (!(vport->vpi_state & LPFC_VPI_REGISTERED) &&
  17549. (did != Fabric_DID)) {
  17550. /*
  17551. * Throw out the frame if we are not pt2pt.
  17552. * The pt2pt protocol allows for discovery frames
  17553. * to be received without a registered VPI.
  17554. */
  17555. if (!(vport->fc_flag & FC_PT2PT) ||
  17556. (phba->link_state == LPFC_HBA_READY)) {
  17557. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17558. return;
  17559. }
  17560. }
  17561. /* Handle the basic abort sequence (BA_ABTS) event */
  17562. if (fc_hdr->fh_r_ctl == FC_RCTL_BA_ABTS) {
  17563. lpfc_sli4_handle_unsol_abort(vport, dmabuf);
  17564. return;
  17565. }
  17566. /* Link this frame */
  17567. seq_dmabuf = lpfc_fc_frame_add(vport, dmabuf);
  17568. if (!seq_dmabuf) {
  17569. /* unable to add frame to vport - throw it out */
  17570. lpfc_in_buf_free(phba, &dmabuf->dbuf);
  17571. return;
  17572. }
  17573. /* If not last frame in sequence continue processing frames. */
  17574. if (!lpfc_seq_complete(seq_dmabuf))
  17575. return;
  17576. /* Send the complete sequence to the upper layer protocol */
  17577. lpfc_sli4_send_seq_to_ulp(vport, seq_dmabuf);
  17578. }
  17579. /**
  17580. * lpfc_sli4_post_all_rpi_hdrs - Post the rpi header memory region to the port
  17581. * @phba: pointer to lpfc hba data structure.
  17582. *
  17583. * This routine is invoked to post rpi header templates to the
  17584. * HBA consistent with the SLI-4 interface spec. This routine
  17585. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  17586. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  17587. *
  17588. * This routine does not require any locks. It's usage is expected
  17589. * to be driver load or reset recovery when the driver is
  17590. * sequential.
  17591. *
  17592. * Return codes
  17593. * 0 - successful
  17594. * -EIO - The mailbox failed to complete successfully.
  17595. * When this error occurs, the driver is not guaranteed
  17596. * to have any rpi regions posted to the device and
  17597. * must either attempt to repost the regions or take a
  17598. * fatal error.
  17599. **/
  17600. int
  17601. lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *phba)
  17602. {
  17603. struct lpfc_rpi_hdr *rpi_page;
  17604. uint32_t rc = 0;
  17605. uint16_t lrpi = 0;
  17606. /* SLI4 ports that support extents do not require RPI headers. */
  17607. if (!phba->sli4_hba.rpi_hdrs_in_use)
  17608. goto exit;
  17609. if (phba->sli4_hba.extents_in_use)
  17610. return -EIO;
  17611. list_for_each_entry(rpi_page, &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
  17612. /*
  17613. * Assign the rpi headers a physical rpi only if the driver
  17614. * has not initialized those resources. A port reset only
  17615. * needs the headers posted.
  17616. */
  17617. if (bf_get(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags) !=
  17618. LPFC_RPI_RSRC_RDY)
  17619. rpi_page->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  17620. rc = lpfc_sli4_post_rpi_hdr(phba, rpi_page);
  17621. if (rc != MBX_SUCCESS) {
  17622. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17623. "2008 Error %d posting all rpi "
  17624. "headers\n", rc);
  17625. rc = -EIO;
  17626. break;
  17627. }
  17628. }
  17629. exit:
  17630. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags,
  17631. LPFC_RPI_RSRC_RDY);
  17632. return rc;
  17633. }
  17634. /**
  17635. * lpfc_sli4_post_rpi_hdr - Post an rpi header memory region to the port
  17636. * @phba: pointer to lpfc hba data structure.
  17637. * @rpi_page: pointer to the rpi memory region.
  17638. *
  17639. * This routine is invoked to post a single rpi header to the
  17640. * HBA consistent with the SLI-4 interface spec. This memory region
  17641. * maps up to 64 rpi context regions.
  17642. *
  17643. * Return codes
  17644. * 0 - successful
  17645. * -ENOMEM - No available memory
  17646. * -EIO - The mailbox failed to complete successfully.
  17647. **/
  17648. int
  17649. lpfc_sli4_post_rpi_hdr(struct lpfc_hba *phba, struct lpfc_rpi_hdr *rpi_page)
  17650. {
  17651. LPFC_MBOXQ_t *mboxq;
  17652. struct lpfc_mbx_post_hdr_tmpl *hdr_tmpl;
  17653. uint32_t rc = 0;
  17654. uint32_t shdr_status, shdr_add_status;
  17655. union lpfc_sli4_cfg_shdr *shdr;
  17656. /* SLI4 ports that support extents do not require RPI headers. */
  17657. if (!phba->sli4_hba.rpi_hdrs_in_use)
  17658. return rc;
  17659. if (phba->sli4_hba.extents_in_use)
  17660. return -EIO;
  17661. /* The port is notified of the header region via a mailbox command. */
  17662. mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  17663. if (!mboxq) {
  17664. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17665. "2001 Unable to allocate memory for issuing "
  17666. "SLI_CONFIG_SPECIAL mailbox command\n");
  17667. return -ENOMEM;
  17668. }
  17669. /* Post all rpi memory regions to the port. */
  17670. hdr_tmpl = &mboxq->u.mqe.un.hdr_tmpl;
  17671. lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  17672. LPFC_MBOX_OPCODE_FCOE_POST_HDR_TEMPLATE,
  17673. sizeof(struct lpfc_mbx_post_hdr_tmpl) -
  17674. sizeof(struct lpfc_sli4_cfg_mhdr),
  17675. LPFC_SLI4_MBX_EMBED);
  17676. /* Post the physical rpi to the port for this rpi header. */
  17677. bf_set(lpfc_mbx_post_hdr_tmpl_rpi_offset, hdr_tmpl,
  17678. rpi_page->start_rpi);
  17679. bf_set(lpfc_mbx_post_hdr_tmpl_page_cnt,
  17680. hdr_tmpl, rpi_page->page_count);
  17681. hdr_tmpl->rpi_paddr_lo = putPaddrLow(rpi_page->dmabuf->phys);
  17682. hdr_tmpl->rpi_paddr_hi = putPaddrHigh(rpi_page->dmabuf->phys);
  17683. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  17684. shdr = (union lpfc_sli4_cfg_shdr *) &hdr_tmpl->header.cfg_shdr;
  17685. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  17686. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  17687. mempool_free(mboxq, phba->mbox_mem_pool);
  17688. if (shdr_status || shdr_add_status || rc) {
  17689. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17690. "2514 POST_RPI_HDR mailbox failed with "
  17691. "status x%x add_status x%x, mbx status x%x\n",
  17692. shdr_status, shdr_add_status, rc);
  17693. rc = -ENXIO;
  17694. } else {
  17695. /*
  17696. * The next_rpi stores the next logical module-64 rpi value used
  17697. * to post physical rpis in subsequent rpi postings.
  17698. */
  17699. spin_lock_irq(&phba->hbalock);
  17700. phba->sli4_hba.next_rpi = rpi_page->next_rpi;
  17701. spin_unlock_irq(&phba->hbalock);
  17702. }
  17703. return rc;
  17704. }
  17705. /**
  17706. * lpfc_sli4_alloc_rpi - Get an available rpi in the device's range
  17707. * @phba: pointer to lpfc hba data structure.
  17708. *
  17709. * This routine is invoked to post rpi header templates to the
  17710. * HBA consistent with the SLI-4 interface spec. This routine
  17711. * posts a SLI4_PAGE_SIZE memory region to the port to hold up to
  17712. * SLI4_PAGE_SIZE modulo 64 rpi context headers.
  17713. *
  17714. * Returns
  17715. * A nonzero rpi defined as rpi_base <= rpi < max_rpi if successful
  17716. * LPFC_RPI_ALLOC_ERROR if no rpis are available.
  17717. **/
  17718. int
  17719. lpfc_sli4_alloc_rpi(struct lpfc_hba *phba)
  17720. {
  17721. unsigned long rpi;
  17722. uint16_t max_rpi, rpi_limit;
  17723. uint16_t rpi_remaining, lrpi = 0;
  17724. struct lpfc_rpi_hdr *rpi_hdr;
  17725. unsigned long iflag;
  17726. /*
  17727. * Fetch the next logical rpi. Because this index is logical,
  17728. * the driver starts at 0 each time.
  17729. */
  17730. spin_lock_irqsave(&phba->hbalock, iflag);
  17731. max_rpi = phba->sli4_hba.max_cfg_param.max_rpi;
  17732. rpi_limit = phba->sli4_hba.next_rpi;
  17733. rpi = find_first_zero_bit(phba->sli4_hba.rpi_bmask, rpi_limit);
  17734. if (rpi >= rpi_limit)
  17735. rpi = LPFC_RPI_ALLOC_ERROR;
  17736. else {
  17737. set_bit(rpi, phba->sli4_hba.rpi_bmask);
  17738. phba->sli4_hba.max_cfg_param.rpi_used++;
  17739. phba->sli4_hba.rpi_count++;
  17740. }
  17741. lpfc_printf_log(phba, KERN_INFO,
  17742. LOG_NODE | LOG_DISCOVERY,
  17743. "0001 Allocated rpi:x%x max:x%x lim:x%x\n",
  17744. (int) rpi, max_rpi, rpi_limit);
  17745. /*
  17746. * Don't try to allocate more rpi header regions if the device limit
  17747. * has been exhausted.
  17748. */
  17749. if ((rpi == LPFC_RPI_ALLOC_ERROR) &&
  17750. (phba->sli4_hba.rpi_count >= max_rpi)) {
  17751. spin_unlock_irqrestore(&phba->hbalock, iflag);
  17752. return rpi;
  17753. }
  17754. /*
  17755. * RPI header postings are not required for SLI4 ports capable of
  17756. * extents.
  17757. */
  17758. if (!phba->sli4_hba.rpi_hdrs_in_use) {
  17759. spin_unlock_irqrestore(&phba->hbalock, iflag);
  17760. return rpi;
  17761. }
  17762. /*
  17763. * If the driver is running low on rpi resources, allocate another
  17764. * page now. Note that the next_rpi value is used because
  17765. * it represents how many are actually in use whereas max_rpi notes
  17766. * how many are supported max by the device.
  17767. */
  17768. rpi_remaining = phba->sli4_hba.next_rpi - phba->sli4_hba.rpi_count;
  17769. spin_unlock_irqrestore(&phba->hbalock, iflag);
  17770. if (rpi_remaining < LPFC_RPI_LOW_WATER_MARK) {
  17771. rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
  17772. if (!rpi_hdr) {
  17773. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17774. "2002 Error Could not grow rpi "
  17775. "count\n");
  17776. } else {
  17777. lrpi = rpi_hdr->start_rpi;
  17778. rpi_hdr->start_rpi = phba->sli4_hba.rpi_ids[lrpi];
  17779. lpfc_sli4_post_rpi_hdr(phba, rpi_hdr);
  17780. }
  17781. }
  17782. return rpi;
  17783. }
  17784. /**
  17785. * __lpfc_sli4_free_rpi - Release an rpi for reuse.
  17786. * @phba: pointer to lpfc hba data structure.
  17787. * @rpi: rpi to free
  17788. *
  17789. * This routine is invoked to release an rpi to the pool of
  17790. * available rpis maintained by the driver.
  17791. **/
  17792. static void
  17793. __lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  17794. {
  17795. /*
  17796. * if the rpi value indicates a prior unreg has already
  17797. * been done, skip the unreg.
  17798. */
  17799. if (rpi == LPFC_RPI_ALLOC_ERROR)
  17800. return;
  17801. if (test_and_clear_bit(rpi, phba->sli4_hba.rpi_bmask)) {
  17802. phba->sli4_hba.rpi_count--;
  17803. phba->sli4_hba.max_cfg_param.rpi_used--;
  17804. } else {
  17805. lpfc_printf_log(phba, KERN_INFO,
  17806. LOG_NODE | LOG_DISCOVERY,
  17807. "2016 rpi %x not inuse\n",
  17808. rpi);
  17809. }
  17810. }
  17811. /**
  17812. * lpfc_sli4_free_rpi - Release an rpi for reuse.
  17813. * @phba: pointer to lpfc hba data structure.
  17814. * @rpi: rpi to free
  17815. *
  17816. * This routine is invoked to release an rpi to the pool of
  17817. * available rpis maintained by the driver.
  17818. **/
  17819. void
  17820. lpfc_sli4_free_rpi(struct lpfc_hba *phba, int rpi)
  17821. {
  17822. spin_lock_irq(&phba->hbalock);
  17823. __lpfc_sli4_free_rpi(phba, rpi);
  17824. spin_unlock_irq(&phba->hbalock);
  17825. }
  17826. /**
  17827. * lpfc_sli4_remove_rpis - Remove the rpi bitmask region
  17828. * @phba: pointer to lpfc hba data structure.
  17829. *
  17830. * This routine is invoked to remove the memory region that
  17831. * provided rpi via a bitmask.
  17832. **/
  17833. void
  17834. lpfc_sli4_remove_rpis(struct lpfc_hba *phba)
  17835. {
  17836. kfree(phba->sli4_hba.rpi_bmask);
  17837. kfree(phba->sli4_hba.rpi_ids);
  17838. bf_set(lpfc_rpi_rsrc_rdy, &phba->sli4_hba.sli4_flags, 0);
  17839. }
  17840. /**
  17841. * lpfc_sli4_resume_rpi - Remove the rpi bitmask region
  17842. * @ndlp: pointer to lpfc nodelist data structure.
  17843. * @cmpl: completion call-back.
  17844. * @arg: data to load as MBox 'caller buffer information'
  17845. *
  17846. * This routine is invoked to remove the memory region that
  17847. * provided rpi via a bitmask.
  17848. **/
  17849. int
  17850. lpfc_sli4_resume_rpi(struct lpfc_nodelist *ndlp,
  17851. void (*cmpl)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *arg)
  17852. {
  17853. LPFC_MBOXQ_t *mboxq;
  17854. struct lpfc_hba *phba = ndlp->phba;
  17855. int rc;
  17856. /* The port is notified of the header region via a mailbox command. */
  17857. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  17858. if (!mboxq)
  17859. return -ENOMEM;
  17860. /* If cmpl assigned, then this nlp_get pairs with
  17861. * lpfc_mbx_cmpl_resume_rpi.
  17862. *
  17863. * Else cmpl is NULL, then this nlp_get pairs with
  17864. * lpfc_sli_def_mbox_cmpl.
  17865. */
  17866. if (!lpfc_nlp_get(ndlp)) {
  17867. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17868. "2122 %s: Failed to get nlp ref\n",
  17869. __func__);
  17870. mempool_free(mboxq, phba->mbox_mem_pool);
  17871. return -EIO;
  17872. }
  17873. /* Post all rpi memory regions to the port. */
  17874. lpfc_resume_rpi(mboxq, ndlp);
  17875. if (cmpl) {
  17876. mboxq->mbox_cmpl = cmpl;
  17877. mboxq->ctx_buf = arg;
  17878. } else
  17879. mboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  17880. mboxq->ctx_ndlp = ndlp;
  17881. mboxq->vport = ndlp->vport;
  17882. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  17883. if (rc == MBX_NOT_FINISHED) {
  17884. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17885. "2010 Resume RPI Mailbox failed "
  17886. "status %d, mbxStatus x%x\n", rc,
  17887. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  17888. lpfc_nlp_put(ndlp);
  17889. mempool_free(mboxq, phba->mbox_mem_pool);
  17890. return -EIO;
  17891. }
  17892. return 0;
  17893. }
  17894. /**
  17895. * lpfc_sli4_init_vpi - Initialize a vpi with the port
  17896. * @vport: Pointer to the vport for which the vpi is being initialized
  17897. *
  17898. * This routine is invoked to activate a vpi with the port.
  17899. *
  17900. * Returns:
  17901. * 0 success
  17902. * -Evalue otherwise
  17903. **/
  17904. int
  17905. lpfc_sli4_init_vpi(struct lpfc_vport *vport)
  17906. {
  17907. LPFC_MBOXQ_t *mboxq;
  17908. int rc = 0;
  17909. int retval = MBX_SUCCESS;
  17910. uint32_t mbox_tmo;
  17911. struct lpfc_hba *phba = vport->phba;
  17912. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  17913. if (!mboxq)
  17914. return -ENOMEM;
  17915. lpfc_init_vpi(phba, mboxq, vport->vpi);
  17916. mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq);
  17917. rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
  17918. if (rc != MBX_SUCCESS) {
  17919. lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
  17920. "2022 INIT VPI Mailbox failed "
  17921. "status %d, mbxStatus x%x\n", rc,
  17922. bf_get(lpfc_mqe_status, &mboxq->u.mqe));
  17923. retval = -EIO;
  17924. }
  17925. if (rc != MBX_TIMEOUT)
  17926. mempool_free(mboxq, vport->phba->mbox_mem_pool);
  17927. return retval;
  17928. }
  17929. /**
  17930. * lpfc_mbx_cmpl_add_fcf_record - add fcf mbox completion handler.
  17931. * @phba: pointer to lpfc hba data structure.
  17932. * @mboxq: Pointer to mailbox object.
  17933. *
  17934. * This routine is invoked to manually add a single FCF record. The caller
  17935. * must pass a completely initialized FCF_Record. This routine takes
  17936. * care of the nonembedded mailbox operations.
  17937. **/
  17938. static void
  17939. lpfc_mbx_cmpl_add_fcf_record(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
  17940. {
  17941. void *virt_addr;
  17942. union lpfc_sli4_cfg_shdr *shdr;
  17943. uint32_t shdr_status, shdr_add_status;
  17944. virt_addr = mboxq->sge_array->addr[0];
  17945. /* The IOCTL status is embedded in the mailbox subheader. */
  17946. shdr = (union lpfc_sli4_cfg_shdr *) virt_addr;
  17947. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  17948. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  17949. if ((shdr_status || shdr_add_status) &&
  17950. (shdr_status != STATUS_FCF_IN_USE))
  17951. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17952. "2558 ADD_FCF_RECORD mailbox failed with "
  17953. "status x%x add_status x%x\n",
  17954. shdr_status, shdr_add_status);
  17955. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  17956. }
  17957. /**
  17958. * lpfc_sli4_add_fcf_record - Manually add an FCF Record.
  17959. * @phba: pointer to lpfc hba data structure.
  17960. * @fcf_record: pointer to the initialized fcf record to add.
  17961. *
  17962. * This routine is invoked to manually add a single FCF record. The caller
  17963. * must pass a completely initialized FCF_Record. This routine takes
  17964. * care of the nonembedded mailbox operations.
  17965. **/
  17966. int
  17967. lpfc_sli4_add_fcf_record(struct lpfc_hba *phba, struct fcf_record *fcf_record)
  17968. {
  17969. int rc = 0;
  17970. LPFC_MBOXQ_t *mboxq;
  17971. uint8_t *bytep;
  17972. void *virt_addr;
  17973. struct lpfc_mbx_sge sge;
  17974. uint32_t alloc_len, req_len;
  17975. uint32_t fcfindex;
  17976. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  17977. if (!mboxq) {
  17978. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17979. "2009 Failed to allocate mbox for ADD_FCF cmd\n");
  17980. return -ENOMEM;
  17981. }
  17982. req_len = sizeof(struct fcf_record) + sizeof(union lpfc_sli4_cfg_shdr) +
  17983. sizeof(uint32_t);
  17984. /* Allocate DMA memory and set up the non-embedded mailbox command */
  17985. alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
  17986. LPFC_MBOX_OPCODE_FCOE_ADD_FCF,
  17987. req_len, LPFC_SLI4_MBX_NEMBED);
  17988. if (alloc_len < req_len) {
  17989. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  17990. "2523 Allocated DMA memory size (x%x) is "
  17991. "less than the requested DMA memory "
  17992. "size (x%x)\n", alloc_len, req_len);
  17993. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  17994. return -ENOMEM;
  17995. }
  17996. /*
  17997. * Get the first SGE entry from the non-embedded DMA memory. This
  17998. * routine only uses a single SGE.
  17999. */
  18000. lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
  18001. virt_addr = mboxq->sge_array->addr[0];
  18002. /*
  18003. * Configure the FCF record for FCFI 0. This is the driver's
  18004. * hardcoded default and gets used in nonFIP mode.
  18005. */
  18006. fcfindex = bf_get(lpfc_fcf_record_fcf_index, fcf_record);
  18007. bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
  18008. lpfc_sli_pcimem_bcopy(&fcfindex, bytep, sizeof(uint32_t));
  18009. /*
  18010. * Copy the fcf_index and the FCF Record Data. The data starts after
  18011. * the FCoE header plus word10. The data copy needs to be endian
  18012. * correct.
  18013. */
  18014. bytep += sizeof(uint32_t);
  18015. lpfc_sli_pcimem_bcopy(fcf_record, bytep, sizeof(struct fcf_record));
  18016. mboxq->vport = phba->pport;
  18017. mboxq->mbox_cmpl = lpfc_mbx_cmpl_add_fcf_record;
  18018. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  18019. if (rc == MBX_NOT_FINISHED) {
  18020. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18021. "2515 ADD_FCF_RECORD mailbox failed with "
  18022. "status 0x%x\n", rc);
  18023. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  18024. rc = -EIO;
  18025. } else
  18026. rc = 0;
  18027. return rc;
  18028. }
  18029. /**
  18030. * lpfc_sli4_build_dflt_fcf_record - Build the driver's default FCF Record.
  18031. * @phba: pointer to lpfc hba data structure.
  18032. * @fcf_record: pointer to the fcf record to write the default data.
  18033. * @fcf_index: FCF table entry index.
  18034. *
  18035. * This routine is invoked to build the driver's default FCF record. The
  18036. * values used are hardcoded. This routine handles memory initialization.
  18037. *
  18038. **/
  18039. void
  18040. lpfc_sli4_build_dflt_fcf_record(struct lpfc_hba *phba,
  18041. struct fcf_record *fcf_record,
  18042. uint16_t fcf_index)
  18043. {
  18044. memset(fcf_record, 0, sizeof(struct fcf_record));
  18045. fcf_record->max_rcv_size = LPFC_FCOE_MAX_RCV_SIZE;
  18046. fcf_record->fka_adv_period = LPFC_FCOE_FKA_ADV_PER;
  18047. fcf_record->fip_priority = LPFC_FCOE_FIP_PRIORITY;
  18048. bf_set(lpfc_fcf_record_mac_0, fcf_record, phba->fc_map[0]);
  18049. bf_set(lpfc_fcf_record_mac_1, fcf_record, phba->fc_map[1]);
  18050. bf_set(lpfc_fcf_record_mac_2, fcf_record, phba->fc_map[2]);
  18051. bf_set(lpfc_fcf_record_mac_3, fcf_record, LPFC_FCOE_FCF_MAC3);
  18052. bf_set(lpfc_fcf_record_mac_4, fcf_record, LPFC_FCOE_FCF_MAC4);
  18053. bf_set(lpfc_fcf_record_mac_5, fcf_record, LPFC_FCOE_FCF_MAC5);
  18054. bf_set(lpfc_fcf_record_fc_map_0, fcf_record, phba->fc_map[0]);
  18055. bf_set(lpfc_fcf_record_fc_map_1, fcf_record, phba->fc_map[1]);
  18056. bf_set(lpfc_fcf_record_fc_map_2, fcf_record, phba->fc_map[2]);
  18057. bf_set(lpfc_fcf_record_fcf_valid, fcf_record, 1);
  18058. bf_set(lpfc_fcf_record_fcf_avail, fcf_record, 1);
  18059. bf_set(lpfc_fcf_record_fcf_index, fcf_record, fcf_index);
  18060. bf_set(lpfc_fcf_record_mac_addr_prov, fcf_record,
  18061. LPFC_FCF_FPMA | LPFC_FCF_SPMA);
  18062. /* Set the VLAN bit map */
  18063. if (phba->valid_vlan) {
  18064. fcf_record->vlan_bitmap[phba->vlan_id / 8]
  18065. = 1 << (phba->vlan_id % 8);
  18066. }
  18067. }
  18068. /**
  18069. * lpfc_sli4_fcf_scan_read_fcf_rec - Read hba fcf record for fcf scan.
  18070. * @phba: pointer to lpfc hba data structure.
  18071. * @fcf_index: FCF table entry offset.
  18072. *
  18073. * This routine is invoked to scan the entire FCF table by reading FCF
  18074. * record and processing it one at a time starting from the @fcf_index
  18075. * for initial FCF discovery or fast FCF failover rediscovery.
  18076. *
  18077. * Return 0 if the mailbox command is submitted successfully, none 0
  18078. * otherwise.
  18079. **/
  18080. int
  18081. lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  18082. {
  18083. int rc = 0, error;
  18084. LPFC_MBOXQ_t *mboxq;
  18085. phba->fcoe_eventtag_at_fcf_scan = phba->fcoe_eventtag;
  18086. phba->fcoe_cvl_eventtag_attn = phba->fcoe_cvl_eventtag;
  18087. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18088. if (!mboxq) {
  18089. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18090. "2000 Failed to allocate mbox for "
  18091. "READ_FCF cmd\n");
  18092. error = -ENOMEM;
  18093. goto fail_fcf_scan;
  18094. }
  18095. /* Construct the read FCF record mailbox command */
  18096. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  18097. if (rc) {
  18098. error = -EINVAL;
  18099. goto fail_fcf_scan;
  18100. }
  18101. /* Issue the mailbox command asynchronously */
  18102. mboxq->vport = phba->pport;
  18103. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_scan_read_fcf_rec;
  18104. spin_lock_irq(&phba->hbalock);
  18105. phba->hba_flag |= FCF_TS_INPROG;
  18106. spin_unlock_irq(&phba->hbalock);
  18107. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  18108. if (rc == MBX_NOT_FINISHED)
  18109. error = -EIO;
  18110. else {
  18111. /* Reset eligible FCF count for new scan */
  18112. if (fcf_index == LPFC_FCOE_FCF_GET_FIRST)
  18113. phba->fcf.eligible_fcf_cnt = 0;
  18114. error = 0;
  18115. }
  18116. fail_fcf_scan:
  18117. if (error) {
  18118. if (mboxq)
  18119. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  18120. /* FCF scan failed, clear FCF_TS_INPROG flag */
  18121. spin_lock_irq(&phba->hbalock);
  18122. phba->hba_flag &= ~FCF_TS_INPROG;
  18123. spin_unlock_irq(&phba->hbalock);
  18124. }
  18125. return error;
  18126. }
  18127. /**
  18128. * lpfc_sli4_fcf_rr_read_fcf_rec - Read hba fcf record for roundrobin fcf.
  18129. * @phba: pointer to lpfc hba data structure.
  18130. * @fcf_index: FCF table entry offset.
  18131. *
  18132. * This routine is invoked to read an FCF record indicated by @fcf_index
  18133. * and to use it for FLOGI roundrobin FCF failover.
  18134. *
  18135. * Return 0 if the mailbox command is submitted successfully, none 0
  18136. * otherwise.
  18137. **/
  18138. int
  18139. lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  18140. {
  18141. int rc = 0, error;
  18142. LPFC_MBOXQ_t *mboxq;
  18143. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18144. if (!mboxq) {
  18145. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  18146. "2763 Failed to allocate mbox for "
  18147. "READ_FCF cmd\n");
  18148. error = -ENOMEM;
  18149. goto fail_fcf_read;
  18150. }
  18151. /* Construct the read FCF record mailbox command */
  18152. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  18153. if (rc) {
  18154. error = -EINVAL;
  18155. goto fail_fcf_read;
  18156. }
  18157. /* Issue the mailbox command asynchronously */
  18158. mboxq->vport = phba->pport;
  18159. mboxq->mbox_cmpl = lpfc_mbx_cmpl_fcf_rr_read_fcf_rec;
  18160. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  18161. if (rc == MBX_NOT_FINISHED)
  18162. error = -EIO;
  18163. else
  18164. error = 0;
  18165. fail_fcf_read:
  18166. if (error && mboxq)
  18167. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  18168. return error;
  18169. }
  18170. /**
  18171. * lpfc_sli4_read_fcf_rec - Read hba fcf record for update eligible fcf bmask.
  18172. * @phba: pointer to lpfc hba data structure.
  18173. * @fcf_index: FCF table entry offset.
  18174. *
  18175. * This routine is invoked to read an FCF record indicated by @fcf_index to
  18176. * determine whether it's eligible for FLOGI roundrobin failover list.
  18177. *
  18178. * Return 0 if the mailbox command is submitted successfully, none 0
  18179. * otherwise.
  18180. **/
  18181. int
  18182. lpfc_sli4_read_fcf_rec(struct lpfc_hba *phba, uint16_t fcf_index)
  18183. {
  18184. int rc = 0, error;
  18185. LPFC_MBOXQ_t *mboxq;
  18186. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18187. if (!mboxq) {
  18188. lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_INIT,
  18189. "2758 Failed to allocate mbox for "
  18190. "READ_FCF cmd\n");
  18191. error = -ENOMEM;
  18192. goto fail_fcf_read;
  18193. }
  18194. /* Construct the read FCF record mailbox command */
  18195. rc = lpfc_sli4_mbx_read_fcf_rec(phba, mboxq, fcf_index);
  18196. if (rc) {
  18197. error = -EINVAL;
  18198. goto fail_fcf_read;
  18199. }
  18200. /* Issue the mailbox command asynchronously */
  18201. mboxq->vport = phba->pport;
  18202. mboxq->mbox_cmpl = lpfc_mbx_cmpl_read_fcf_rec;
  18203. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
  18204. if (rc == MBX_NOT_FINISHED)
  18205. error = -EIO;
  18206. else
  18207. error = 0;
  18208. fail_fcf_read:
  18209. if (error && mboxq)
  18210. lpfc_sli4_mbox_cmd_free(phba, mboxq);
  18211. return error;
  18212. }
  18213. /**
  18214. * lpfc_check_next_fcf_pri_level
  18215. * @phba: pointer to the lpfc_hba struct for this port.
  18216. * This routine is called from the lpfc_sli4_fcf_rr_next_index_get
  18217. * routine when the rr_bmask is empty. The FCF indecies are put into the
  18218. * rr_bmask based on their priority level. Starting from the highest priority
  18219. * to the lowest. The most likely FCF candidate will be in the highest
  18220. * priority group. When this routine is called it searches the fcf_pri list for
  18221. * next lowest priority group and repopulates the rr_bmask with only those
  18222. * fcf_indexes.
  18223. * returns:
  18224. * 1=success 0=failure
  18225. **/
  18226. static int
  18227. lpfc_check_next_fcf_pri_level(struct lpfc_hba *phba)
  18228. {
  18229. uint16_t next_fcf_pri;
  18230. uint16_t last_index;
  18231. struct lpfc_fcf_pri *fcf_pri;
  18232. int rc;
  18233. int ret = 0;
  18234. last_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  18235. LPFC_SLI4_FCF_TBL_INDX_MAX);
  18236. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  18237. "3060 Last IDX %d\n", last_index);
  18238. /* Verify the priority list has 2 or more entries */
  18239. spin_lock_irq(&phba->hbalock);
  18240. if (list_empty(&phba->fcf.fcf_pri_list) ||
  18241. list_is_singular(&phba->fcf.fcf_pri_list)) {
  18242. spin_unlock_irq(&phba->hbalock);
  18243. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  18244. "3061 Last IDX %d\n", last_index);
  18245. return 0; /* Empty rr list */
  18246. }
  18247. spin_unlock_irq(&phba->hbalock);
  18248. next_fcf_pri = 0;
  18249. /*
  18250. * Clear the rr_bmask and set all of the bits that are at this
  18251. * priority.
  18252. */
  18253. memset(phba->fcf.fcf_rr_bmask, 0,
  18254. sizeof(*phba->fcf.fcf_rr_bmask));
  18255. spin_lock_irq(&phba->hbalock);
  18256. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  18257. if (fcf_pri->fcf_rec.flag & LPFC_FCF_FLOGI_FAILED)
  18258. continue;
  18259. /*
  18260. * the 1st priority that has not FLOGI failed
  18261. * will be the highest.
  18262. */
  18263. if (!next_fcf_pri)
  18264. next_fcf_pri = fcf_pri->fcf_rec.priority;
  18265. spin_unlock_irq(&phba->hbalock);
  18266. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  18267. rc = lpfc_sli4_fcf_rr_index_set(phba,
  18268. fcf_pri->fcf_rec.fcf_index);
  18269. if (rc)
  18270. return 0;
  18271. }
  18272. spin_lock_irq(&phba->hbalock);
  18273. }
  18274. /*
  18275. * if next_fcf_pri was not set above and the list is not empty then
  18276. * we have failed flogis on all of them. So reset flogi failed
  18277. * and start at the beginning.
  18278. */
  18279. if (!next_fcf_pri && !list_empty(&phba->fcf.fcf_pri_list)) {
  18280. list_for_each_entry(fcf_pri, &phba->fcf.fcf_pri_list, list) {
  18281. fcf_pri->fcf_rec.flag &= ~LPFC_FCF_FLOGI_FAILED;
  18282. /*
  18283. * the 1st priority that has not FLOGI failed
  18284. * will be the highest.
  18285. */
  18286. if (!next_fcf_pri)
  18287. next_fcf_pri = fcf_pri->fcf_rec.priority;
  18288. spin_unlock_irq(&phba->hbalock);
  18289. if (fcf_pri->fcf_rec.priority == next_fcf_pri) {
  18290. rc = lpfc_sli4_fcf_rr_index_set(phba,
  18291. fcf_pri->fcf_rec.fcf_index);
  18292. if (rc)
  18293. return 0;
  18294. }
  18295. spin_lock_irq(&phba->hbalock);
  18296. }
  18297. } else
  18298. ret = 1;
  18299. spin_unlock_irq(&phba->hbalock);
  18300. return ret;
  18301. }
  18302. /**
  18303. * lpfc_sli4_fcf_rr_next_index_get - Get next eligible fcf record index
  18304. * @phba: pointer to lpfc hba data structure.
  18305. *
  18306. * This routine is to get the next eligible FCF record index in a round
  18307. * robin fashion. If the next eligible FCF record index equals to the
  18308. * initial roundrobin FCF record index, LPFC_FCOE_FCF_NEXT_NONE (0xFFFF)
  18309. * shall be returned, otherwise, the next eligible FCF record's index
  18310. * shall be returned.
  18311. **/
  18312. uint16_t
  18313. lpfc_sli4_fcf_rr_next_index_get(struct lpfc_hba *phba)
  18314. {
  18315. uint16_t next_fcf_index;
  18316. initial_priority:
  18317. /* Search start from next bit of currently registered FCF index */
  18318. next_fcf_index = phba->fcf.current_rec.fcf_indx;
  18319. next_priority:
  18320. /* Determine the next fcf index to check */
  18321. next_fcf_index = (next_fcf_index + 1) % LPFC_SLI4_FCF_TBL_INDX_MAX;
  18322. next_fcf_index = find_next_bit(phba->fcf.fcf_rr_bmask,
  18323. LPFC_SLI4_FCF_TBL_INDX_MAX,
  18324. next_fcf_index);
  18325. /* Wrap around condition on phba->fcf.fcf_rr_bmask */
  18326. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  18327. /*
  18328. * If we have wrapped then we need to clear the bits that
  18329. * have been tested so that we can detect when we should
  18330. * change the priority level.
  18331. */
  18332. next_fcf_index = find_first_bit(phba->fcf.fcf_rr_bmask,
  18333. LPFC_SLI4_FCF_TBL_INDX_MAX);
  18334. }
  18335. /* Check roundrobin failover list empty condition */
  18336. if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX ||
  18337. next_fcf_index == phba->fcf.current_rec.fcf_indx) {
  18338. /*
  18339. * If next fcf index is not found check if there are lower
  18340. * Priority level fcf's in the fcf_priority list.
  18341. * Set up the rr_bmask with all of the avaiable fcf bits
  18342. * at that level and continue the selection process.
  18343. */
  18344. if (lpfc_check_next_fcf_pri_level(phba))
  18345. goto initial_priority;
  18346. lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
  18347. "2844 No roundrobin failover FCF available\n");
  18348. return LPFC_FCOE_FCF_NEXT_NONE;
  18349. }
  18350. if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
  18351. phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag &
  18352. LPFC_FCF_FLOGI_FAILED) {
  18353. if (list_is_singular(&phba->fcf.fcf_pri_list))
  18354. return LPFC_FCOE_FCF_NEXT_NONE;
  18355. goto next_priority;
  18356. }
  18357. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  18358. "2845 Get next roundrobin failover FCF (x%x)\n",
  18359. next_fcf_index);
  18360. return next_fcf_index;
  18361. }
  18362. /**
  18363. * lpfc_sli4_fcf_rr_index_set - Set bmask with eligible fcf record index
  18364. * @phba: pointer to lpfc hba data structure.
  18365. * @fcf_index: index into the FCF table to 'set'
  18366. *
  18367. * This routine sets the FCF record index in to the eligible bmask for
  18368. * roundrobin failover search. It checks to make sure that the index
  18369. * does not go beyond the range of the driver allocated bmask dimension
  18370. * before setting the bit.
  18371. *
  18372. * Returns 0 if the index bit successfully set, otherwise, it returns
  18373. * -EINVAL.
  18374. **/
  18375. int
  18376. lpfc_sli4_fcf_rr_index_set(struct lpfc_hba *phba, uint16_t fcf_index)
  18377. {
  18378. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  18379. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  18380. "2610 FCF (x%x) reached driver's book "
  18381. "keeping dimension:x%x\n",
  18382. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  18383. return -EINVAL;
  18384. }
  18385. /* Set the eligible FCF record index bmask */
  18386. set_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  18387. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  18388. "2790 Set FCF (x%x) to roundrobin FCF failover "
  18389. "bmask\n", fcf_index);
  18390. return 0;
  18391. }
  18392. /**
  18393. * lpfc_sli4_fcf_rr_index_clear - Clear bmask from eligible fcf record index
  18394. * @phba: pointer to lpfc hba data structure.
  18395. * @fcf_index: index into the FCF table to 'clear'
  18396. *
  18397. * This routine clears the FCF record index from the eligible bmask for
  18398. * roundrobin failover search. It checks to make sure that the index
  18399. * does not go beyond the range of the driver allocated bmask dimension
  18400. * before clearing the bit.
  18401. **/
  18402. void
  18403. lpfc_sli4_fcf_rr_index_clear(struct lpfc_hba *phba, uint16_t fcf_index)
  18404. {
  18405. struct lpfc_fcf_pri *fcf_pri, *fcf_pri_next;
  18406. if (fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX) {
  18407. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  18408. "2762 FCF (x%x) reached driver's book "
  18409. "keeping dimension:x%x\n",
  18410. fcf_index, LPFC_SLI4_FCF_TBL_INDX_MAX);
  18411. return;
  18412. }
  18413. /* Clear the eligible FCF record index bmask */
  18414. spin_lock_irq(&phba->hbalock);
  18415. list_for_each_entry_safe(fcf_pri, fcf_pri_next, &phba->fcf.fcf_pri_list,
  18416. list) {
  18417. if (fcf_pri->fcf_rec.fcf_index == fcf_index) {
  18418. list_del_init(&fcf_pri->list);
  18419. break;
  18420. }
  18421. }
  18422. spin_unlock_irq(&phba->hbalock);
  18423. clear_bit(fcf_index, phba->fcf.fcf_rr_bmask);
  18424. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  18425. "2791 Clear FCF (x%x) from roundrobin failover "
  18426. "bmask\n", fcf_index);
  18427. }
  18428. /**
  18429. * lpfc_mbx_cmpl_redisc_fcf_table - completion routine for rediscover FCF table
  18430. * @phba: pointer to lpfc hba data structure.
  18431. * @mbox: An allocated pointer to type LPFC_MBOXQ_t
  18432. *
  18433. * This routine is the completion routine for the rediscover FCF table mailbox
  18434. * command. If the mailbox command returned failure, it will try to stop the
  18435. * FCF rediscover wait timer.
  18436. **/
  18437. static void
  18438. lpfc_mbx_cmpl_redisc_fcf_table(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
  18439. {
  18440. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  18441. uint32_t shdr_status, shdr_add_status;
  18442. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  18443. shdr_status = bf_get(lpfc_mbox_hdr_status,
  18444. &redisc_fcf->header.cfg_shdr.response);
  18445. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  18446. &redisc_fcf->header.cfg_shdr.response);
  18447. if (shdr_status || shdr_add_status) {
  18448. lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
  18449. "2746 Requesting for FCF rediscovery failed "
  18450. "status x%x add_status x%x\n",
  18451. shdr_status, shdr_add_status);
  18452. if (phba->fcf.fcf_flag & FCF_ACVL_DISC) {
  18453. spin_lock_irq(&phba->hbalock);
  18454. phba->fcf.fcf_flag &= ~FCF_ACVL_DISC;
  18455. spin_unlock_irq(&phba->hbalock);
  18456. /*
  18457. * CVL event triggered FCF rediscover request failed,
  18458. * last resort to re-try current registered FCF entry.
  18459. */
  18460. lpfc_retry_pport_discovery(phba);
  18461. } else {
  18462. spin_lock_irq(&phba->hbalock);
  18463. phba->fcf.fcf_flag &= ~FCF_DEAD_DISC;
  18464. spin_unlock_irq(&phba->hbalock);
  18465. /*
  18466. * DEAD FCF event triggered FCF rediscover request
  18467. * failed, last resort to fail over as a link down
  18468. * to FCF registration.
  18469. */
  18470. lpfc_sli4_fcf_dead_failthrough(phba);
  18471. }
  18472. } else {
  18473. lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
  18474. "2775 Start FCF rediscover quiescent timer\n");
  18475. /*
  18476. * Start FCF rediscovery wait timer for pending FCF
  18477. * before rescan FCF record table.
  18478. */
  18479. lpfc_fcf_redisc_wait_start_timer(phba);
  18480. }
  18481. mempool_free(mbox, phba->mbox_mem_pool);
  18482. }
  18483. /**
  18484. * lpfc_sli4_redisc_fcf_table - Request to rediscover entire FCF table by port.
  18485. * @phba: pointer to lpfc hba data structure.
  18486. *
  18487. * This routine is invoked to request for rediscovery of the entire FCF table
  18488. * by the port.
  18489. **/
  18490. int
  18491. lpfc_sli4_redisc_fcf_table(struct lpfc_hba *phba)
  18492. {
  18493. LPFC_MBOXQ_t *mbox;
  18494. struct lpfc_mbx_redisc_fcf_tbl *redisc_fcf;
  18495. int rc, length;
  18496. /* Cancel retry delay timers to all vports before FCF rediscover */
  18497. lpfc_cancel_all_vport_retry_delay_timer(phba);
  18498. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18499. if (!mbox) {
  18500. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18501. "2745 Failed to allocate mbox for "
  18502. "requesting FCF rediscover.\n");
  18503. return -ENOMEM;
  18504. }
  18505. length = (sizeof(struct lpfc_mbx_redisc_fcf_tbl) -
  18506. sizeof(struct lpfc_sli4_cfg_mhdr));
  18507. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_FCOE,
  18508. LPFC_MBOX_OPCODE_FCOE_REDISCOVER_FCF,
  18509. length, LPFC_SLI4_MBX_EMBED);
  18510. redisc_fcf = &mbox->u.mqe.un.redisc_fcf_tbl;
  18511. /* Set count to 0 for invalidating the entire FCF database */
  18512. bf_set(lpfc_mbx_redisc_fcf_count, redisc_fcf, 0);
  18513. /* Issue the mailbox command asynchronously */
  18514. mbox->vport = phba->pport;
  18515. mbox->mbox_cmpl = lpfc_mbx_cmpl_redisc_fcf_table;
  18516. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
  18517. if (rc == MBX_NOT_FINISHED) {
  18518. mempool_free(mbox, phba->mbox_mem_pool);
  18519. return -EIO;
  18520. }
  18521. return 0;
  18522. }
  18523. /**
  18524. * lpfc_sli4_fcf_dead_failthrough - Failthrough routine to fcf dead event
  18525. * @phba: pointer to lpfc hba data structure.
  18526. *
  18527. * This function is the failover routine as a last resort to the FCF DEAD
  18528. * event when driver failed to perform fast FCF failover.
  18529. **/
  18530. void
  18531. lpfc_sli4_fcf_dead_failthrough(struct lpfc_hba *phba)
  18532. {
  18533. uint32_t link_state;
  18534. /*
  18535. * Last resort as FCF DEAD event failover will treat this as
  18536. * a link down, but save the link state because we don't want
  18537. * it to be changed to Link Down unless it is already down.
  18538. */
  18539. link_state = phba->link_state;
  18540. lpfc_linkdown(phba);
  18541. phba->link_state = link_state;
  18542. /* Unregister FCF if no devices connected to it */
  18543. lpfc_unregister_unused_fcf(phba);
  18544. }
  18545. /**
  18546. * lpfc_sli_get_config_region23 - Get sli3 port region 23 data.
  18547. * @phba: pointer to lpfc hba data structure.
  18548. * @rgn23_data: pointer to configure region 23 data.
  18549. *
  18550. * This function gets SLI3 port configure region 23 data through memory dump
  18551. * mailbox command. When it successfully retrieves data, the size of the data
  18552. * will be returned, otherwise, 0 will be returned.
  18553. **/
  18554. static uint32_t
  18555. lpfc_sli_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  18556. {
  18557. LPFC_MBOXQ_t *pmb = NULL;
  18558. MAILBOX_t *mb;
  18559. uint32_t offset = 0;
  18560. int rc;
  18561. if (!rgn23_data)
  18562. return 0;
  18563. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18564. if (!pmb) {
  18565. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18566. "2600 failed to allocate mailbox memory\n");
  18567. return 0;
  18568. }
  18569. mb = &pmb->u.mb;
  18570. do {
  18571. lpfc_dump_mem(phba, pmb, offset, DMP_REGION_23);
  18572. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  18573. if (rc != MBX_SUCCESS) {
  18574. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  18575. "2601 failed to read config "
  18576. "region 23, rc 0x%x Status 0x%x\n",
  18577. rc, mb->mbxStatus);
  18578. mb->un.varDmp.word_cnt = 0;
  18579. }
  18580. /*
  18581. * dump mem may return a zero when finished or we got a
  18582. * mailbox error, either way we are done.
  18583. */
  18584. if (mb->un.varDmp.word_cnt == 0)
  18585. break;
  18586. if (mb->un.varDmp.word_cnt > DMP_RGN23_SIZE - offset)
  18587. mb->un.varDmp.word_cnt = DMP_RGN23_SIZE - offset;
  18588. lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
  18589. rgn23_data + offset,
  18590. mb->un.varDmp.word_cnt);
  18591. offset += mb->un.varDmp.word_cnt;
  18592. } while (mb->un.varDmp.word_cnt && offset < DMP_RGN23_SIZE);
  18593. mempool_free(pmb, phba->mbox_mem_pool);
  18594. return offset;
  18595. }
  18596. /**
  18597. * lpfc_sli4_get_config_region23 - Get sli4 port region 23 data.
  18598. * @phba: pointer to lpfc hba data structure.
  18599. * @rgn23_data: pointer to configure region 23 data.
  18600. *
  18601. * This function gets SLI4 port configure region 23 data through memory dump
  18602. * mailbox command. When it successfully retrieves data, the size of the data
  18603. * will be returned, otherwise, 0 will be returned.
  18604. **/
  18605. static uint32_t
  18606. lpfc_sli4_get_config_region23(struct lpfc_hba *phba, char *rgn23_data)
  18607. {
  18608. LPFC_MBOXQ_t *mboxq = NULL;
  18609. struct lpfc_dmabuf *mp = NULL;
  18610. struct lpfc_mqe *mqe;
  18611. uint32_t data_length = 0;
  18612. int rc;
  18613. if (!rgn23_data)
  18614. return 0;
  18615. mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18616. if (!mboxq) {
  18617. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18618. "3105 failed to allocate mailbox memory\n");
  18619. return 0;
  18620. }
  18621. if (lpfc_sli4_dump_cfg_rg23(phba, mboxq))
  18622. goto out;
  18623. mqe = &mboxq->u.mqe;
  18624. mp = (struct lpfc_dmabuf *)mboxq->ctx_buf;
  18625. rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
  18626. if (rc)
  18627. goto out;
  18628. data_length = mqe->un.mb_words[5];
  18629. if (data_length == 0)
  18630. goto out;
  18631. if (data_length > DMP_RGN23_SIZE) {
  18632. data_length = 0;
  18633. goto out;
  18634. }
  18635. lpfc_sli_pcimem_bcopy((char *)mp->virt, rgn23_data, data_length);
  18636. out:
  18637. lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
  18638. return data_length;
  18639. }
  18640. /**
  18641. * lpfc_sli_read_link_ste - Read region 23 to decide if link is disabled.
  18642. * @phba: pointer to lpfc hba data structure.
  18643. *
  18644. * This function read region 23 and parse TLV for port status to
  18645. * decide if the user disaled the port. If the TLV indicates the
  18646. * port is disabled, the hba_flag is set accordingly.
  18647. **/
  18648. void
  18649. lpfc_sli_read_link_ste(struct lpfc_hba *phba)
  18650. {
  18651. uint8_t *rgn23_data = NULL;
  18652. uint32_t if_type, data_size, sub_tlv_len, tlv_offset;
  18653. uint32_t offset = 0;
  18654. /* Get adapter Region 23 data */
  18655. rgn23_data = kzalloc(DMP_RGN23_SIZE, GFP_KERNEL);
  18656. if (!rgn23_data)
  18657. goto out;
  18658. if (phba->sli_rev < LPFC_SLI_REV4)
  18659. data_size = lpfc_sli_get_config_region23(phba, rgn23_data);
  18660. else {
  18661. if_type = bf_get(lpfc_sli_intf_if_type,
  18662. &phba->sli4_hba.sli_intf);
  18663. if (if_type == LPFC_SLI_INTF_IF_TYPE_0)
  18664. goto out;
  18665. data_size = lpfc_sli4_get_config_region23(phba, rgn23_data);
  18666. }
  18667. if (!data_size)
  18668. goto out;
  18669. /* Check the region signature first */
  18670. if (memcmp(&rgn23_data[offset], LPFC_REGION23_SIGNATURE, 4)) {
  18671. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18672. "2619 Config region 23 has bad signature\n");
  18673. goto out;
  18674. }
  18675. offset += 4;
  18676. /* Check the data structure version */
  18677. if (rgn23_data[offset] != LPFC_REGION23_VERSION) {
  18678. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18679. "2620 Config region 23 has bad version\n");
  18680. goto out;
  18681. }
  18682. offset += 4;
  18683. /* Parse TLV entries in the region */
  18684. while (offset < data_size) {
  18685. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC)
  18686. break;
  18687. /*
  18688. * If the TLV is not driver specific TLV or driver id is
  18689. * not linux driver id, skip the record.
  18690. */
  18691. if ((rgn23_data[offset] != DRIVER_SPECIFIC_TYPE) ||
  18692. (rgn23_data[offset + 2] != LINUX_DRIVER_ID) ||
  18693. (rgn23_data[offset + 3] != 0)) {
  18694. offset += rgn23_data[offset + 1] * 4 + 4;
  18695. continue;
  18696. }
  18697. /* Driver found a driver specific TLV in the config region */
  18698. sub_tlv_len = rgn23_data[offset + 1] * 4;
  18699. offset += 4;
  18700. tlv_offset = 0;
  18701. /*
  18702. * Search for configured port state sub-TLV.
  18703. */
  18704. while ((offset < data_size) &&
  18705. (tlv_offset < sub_tlv_len)) {
  18706. if (rgn23_data[offset] == LPFC_REGION23_LAST_REC) {
  18707. offset += 4;
  18708. tlv_offset += 4;
  18709. break;
  18710. }
  18711. if (rgn23_data[offset] != PORT_STE_TYPE) {
  18712. offset += rgn23_data[offset + 1] * 4 + 4;
  18713. tlv_offset += rgn23_data[offset + 1] * 4 + 4;
  18714. continue;
  18715. }
  18716. /* This HBA contains PORT_STE configured */
  18717. if (!rgn23_data[offset + 2])
  18718. phba->hba_flag |= LINK_DISABLED;
  18719. goto out;
  18720. }
  18721. }
  18722. out:
  18723. kfree(rgn23_data);
  18724. return;
  18725. }
  18726. /**
  18727. * lpfc_log_fw_write_cmpl - logs firmware write completion status
  18728. * @phba: pointer to lpfc hba data structure
  18729. * @shdr_status: wr_object rsp's status field
  18730. * @shdr_add_status: wr_object rsp's add_status field
  18731. * @shdr_add_status_2: wr_object rsp's add_status_2 field
  18732. * @shdr_change_status: wr_object rsp's change_status field
  18733. * @shdr_csf: wr_object rsp's csf bit
  18734. *
  18735. * This routine is intended to be called after a firmware write completes.
  18736. * It will log next action items to be performed by the user to instantiate
  18737. * the newly downloaded firmware or reason for incompatibility.
  18738. **/
  18739. static void
  18740. lpfc_log_fw_write_cmpl(struct lpfc_hba *phba, u32 shdr_status,
  18741. u32 shdr_add_status, u32 shdr_add_status_2,
  18742. u32 shdr_change_status, u32 shdr_csf)
  18743. {
  18744. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  18745. "4198 %s: flash_id x%02x, asic_rev x%02x, "
  18746. "status x%02x, add_status x%02x, add_status_2 x%02x, "
  18747. "change_status x%02x, csf %01x\n", __func__,
  18748. phba->sli4_hba.flash_id, phba->sli4_hba.asic_rev,
  18749. shdr_status, shdr_add_status, shdr_add_status_2,
  18750. shdr_change_status, shdr_csf);
  18751. if (shdr_add_status == LPFC_ADD_STATUS_INCOMPAT_OBJ) {
  18752. switch (shdr_add_status_2) {
  18753. case LPFC_ADD_STATUS_2_INCOMPAT_FLASH:
  18754. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  18755. "4199 Firmware write failed: "
  18756. "image incompatible with flash x%02x\n",
  18757. phba->sli4_hba.flash_id);
  18758. break;
  18759. case LPFC_ADD_STATUS_2_INCORRECT_ASIC:
  18760. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  18761. "4200 Firmware write failed: "
  18762. "image incompatible with ASIC "
  18763. "architecture x%02x\n",
  18764. phba->sli4_hba.asic_rev);
  18765. break;
  18766. default:
  18767. lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_SLI,
  18768. "4210 Firmware write failed: "
  18769. "add_status_2 x%02x\n",
  18770. shdr_add_status_2);
  18771. break;
  18772. }
  18773. } else if (!shdr_status && !shdr_add_status) {
  18774. if (shdr_change_status == LPFC_CHANGE_STATUS_FW_RESET ||
  18775. shdr_change_status == LPFC_CHANGE_STATUS_PORT_MIGRATION) {
  18776. if (shdr_csf)
  18777. shdr_change_status =
  18778. LPFC_CHANGE_STATUS_PCI_RESET;
  18779. }
  18780. switch (shdr_change_status) {
  18781. case (LPFC_CHANGE_STATUS_PHYS_DEV_RESET):
  18782. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  18783. "3198 Firmware write complete: System "
  18784. "reboot required to instantiate\n");
  18785. break;
  18786. case (LPFC_CHANGE_STATUS_FW_RESET):
  18787. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  18788. "3199 Firmware write complete: "
  18789. "Firmware reset required to "
  18790. "instantiate\n");
  18791. break;
  18792. case (LPFC_CHANGE_STATUS_PORT_MIGRATION):
  18793. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  18794. "3200 Firmware write complete: Port "
  18795. "Migration or PCI Reset required to "
  18796. "instantiate\n");
  18797. break;
  18798. case (LPFC_CHANGE_STATUS_PCI_RESET):
  18799. lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
  18800. "3201 Firmware write complete: PCI "
  18801. "Reset required to instantiate\n");
  18802. break;
  18803. default:
  18804. break;
  18805. }
  18806. }
  18807. }
  18808. /**
  18809. * lpfc_wr_object - write an object to the firmware
  18810. * @phba: HBA structure that indicates port to create a queue on.
  18811. * @dmabuf_list: list of dmabufs to write to the port.
  18812. * @size: the total byte value of the objects to write to the port.
  18813. * @offset: the current offset to be used to start the transfer.
  18814. *
  18815. * This routine will create a wr_object mailbox command to send to the port.
  18816. * the mailbox command will be constructed using the dma buffers described in
  18817. * @dmabuf_list to create a list of BDEs. This routine will fill in as many
  18818. * BDEs that the imbedded mailbox can support. The @offset variable will be
  18819. * used to indicate the starting offset of the transfer and will also return
  18820. * the offset after the write object mailbox has completed. @size is used to
  18821. * determine the end of the object and whether the eof bit should be set.
  18822. *
  18823. * Return 0 is successful and offset will contain the the new offset to use
  18824. * for the next write.
  18825. * Return negative value for error cases.
  18826. **/
  18827. int
  18828. lpfc_wr_object(struct lpfc_hba *phba, struct list_head *dmabuf_list,
  18829. uint32_t size, uint32_t *offset)
  18830. {
  18831. struct lpfc_mbx_wr_object *wr_object;
  18832. LPFC_MBOXQ_t *mbox;
  18833. int rc = 0, i = 0;
  18834. int mbox_status = 0;
  18835. uint32_t shdr_status, shdr_add_status, shdr_add_status_2;
  18836. uint32_t shdr_change_status = 0, shdr_csf = 0;
  18837. uint32_t mbox_tmo;
  18838. struct lpfc_dmabuf *dmabuf;
  18839. uint32_t written = 0;
  18840. bool check_change_status = false;
  18841. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  18842. if (!mbox)
  18843. return -ENOMEM;
  18844. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  18845. LPFC_MBOX_OPCODE_WRITE_OBJECT,
  18846. sizeof(struct lpfc_mbx_wr_object) -
  18847. sizeof(struct lpfc_sli4_cfg_mhdr), LPFC_SLI4_MBX_EMBED);
  18848. wr_object = (struct lpfc_mbx_wr_object *)&mbox->u.mqe.un.wr_object;
  18849. wr_object->u.request.write_offset = *offset;
  18850. sprintf((uint8_t *)wr_object->u.request.object_name, "/");
  18851. wr_object->u.request.object_name[0] =
  18852. cpu_to_le32(wr_object->u.request.object_name[0]);
  18853. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 0);
  18854. list_for_each_entry(dmabuf, dmabuf_list, list) {
  18855. if (i >= LPFC_MBX_WR_CONFIG_MAX_BDE || written >= size)
  18856. break;
  18857. wr_object->u.request.bde[i].addrLow = putPaddrLow(dmabuf->phys);
  18858. wr_object->u.request.bde[i].addrHigh =
  18859. putPaddrHigh(dmabuf->phys);
  18860. if (written + SLI4_PAGE_SIZE >= size) {
  18861. wr_object->u.request.bde[i].tus.f.bdeSize =
  18862. (size - written);
  18863. written += (size - written);
  18864. bf_set(lpfc_wr_object_eof, &wr_object->u.request, 1);
  18865. bf_set(lpfc_wr_object_eas, &wr_object->u.request, 1);
  18866. check_change_status = true;
  18867. } else {
  18868. wr_object->u.request.bde[i].tus.f.bdeSize =
  18869. SLI4_PAGE_SIZE;
  18870. written += SLI4_PAGE_SIZE;
  18871. }
  18872. i++;
  18873. }
  18874. wr_object->u.request.bde_count = i;
  18875. bf_set(lpfc_wr_object_write_length, &wr_object->u.request, written);
  18876. if (!phba->sli4_hba.intr_enable)
  18877. mbox_status = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  18878. else {
  18879. mbox_tmo = lpfc_mbox_tmo_val(phba, mbox);
  18880. mbox_status = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
  18881. }
  18882. /* The mbox status needs to be maintained to detect MBOX_TIMEOUT. */
  18883. rc = mbox_status;
  18884. /* The IOCTL status is embedded in the mailbox subheader. */
  18885. shdr_status = bf_get(lpfc_mbox_hdr_status,
  18886. &wr_object->header.cfg_shdr.response);
  18887. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
  18888. &wr_object->header.cfg_shdr.response);
  18889. shdr_add_status_2 = bf_get(lpfc_mbox_hdr_add_status_2,
  18890. &wr_object->header.cfg_shdr.response);
  18891. if (check_change_status) {
  18892. shdr_change_status = bf_get(lpfc_wr_object_change_status,
  18893. &wr_object->u.response);
  18894. shdr_csf = bf_get(lpfc_wr_object_csf,
  18895. &wr_object->u.response);
  18896. }
  18897. if (shdr_status || shdr_add_status || shdr_add_status_2 || rc) {
  18898. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  18899. "3025 Write Object mailbox failed with "
  18900. "status x%x add_status x%x, add_status_2 x%x, "
  18901. "mbx status x%x\n",
  18902. shdr_status, shdr_add_status, shdr_add_status_2,
  18903. rc);
  18904. rc = -ENXIO;
  18905. *offset = shdr_add_status;
  18906. } else {
  18907. *offset += wr_object->u.response.actual_write_length;
  18908. }
  18909. if (rc || check_change_status)
  18910. lpfc_log_fw_write_cmpl(phba, shdr_status, shdr_add_status,
  18911. shdr_add_status_2, shdr_change_status,
  18912. shdr_csf);
  18913. if (!phba->sli4_hba.intr_enable)
  18914. mempool_free(mbox, phba->mbox_mem_pool);
  18915. else if (mbox_status != MBX_TIMEOUT)
  18916. mempool_free(mbox, phba->mbox_mem_pool);
  18917. return rc;
  18918. }
  18919. /**
  18920. * lpfc_cleanup_pending_mbox - Free up vport discovery mailbox commands.
  18921. * @vport: pointer to vport data structure.
  18922. *
  18923. * This function iterate through the mailboxq and clean up all REG_LOGIN
  18924. * and REG_VPI mailbox commands associated with the vport. This function
  18925. * is called when driver want to restart discovery of the vport due to
  18926. * a Clear Virtual Link event.
  18927. **/
  18928. void
  18929. lpfc_cleanup_pending_mbox(struct lpfc_vport *vport)
  18930. {
  18931. struct lpfc_hba *phba = vport->phba;
  18932. LPFC_MBOXQ_t *mb, *nextmb;
  18933. struct lpfc_nodelist *ndlp;
  18934. struct lpfc_nodelist *act_mbx_ndlp = NULL;
  18935. LIST_HEAD(mbox_cmd_list);
  18936. uint8_t restart_loop;
  18937. /* Clean up internally queued mailbox commands with the vport */
  18938. spin_lock_irq(&phba->hbalock);
  18939. list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
  18940. if (mb->vport != vport)
  18941. continue;
  18942. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  18943. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  18944. continue;
  18945. list_move_tail(&mb->list, &mbox_cmd_list);
  18946. }
  18947. /* Clean up active mailbox command with the vport */
  18948. mb = phba->sli.mbox_active;
  18949. if (mb && (mb->vport == vport)) {
  18950. if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) ||
  18951. (mb->u.mb.mbxCommand == MBX_REG_VPI))
  18952. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  18953. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  18954. act_mbx_ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
  18955. /* This reference is local to this routine. The
  18956. * reference is removed at routine exit.
  18957. */
  18958. act_mbx_ndlp = lpfc_nlp_get(act_mbx_ndlp);
  18959. /* Unregister the RPI when mailbox complete */
  18960. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  18961. }
  18962. }
  18963. /* Cleanup any mailbox completions which are not yet processed */
  18964. do {
  18965. restart_loop = 0;
  18966. list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
  18967. /*
  18968. * If this mailox is already processed or it is
  18969. * for another vport ignore it.
  18970. */
  18971. if ((mb->vport != vport) ||
  18972. (mb->mbox_flag & LPFC_MBX_IMED_UNREG))
  18973. continue;
  18974. if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) &&
  18975. (mb->u.mb.mbxCommand != MBX_REG_VPI))
  18976. continue;
  18977. mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  18978. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  18979. ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
  18980. /* Unregister the RPI when mailbox complete */
  18981. mb->mbox_flag |= LPFC_MBX_IMED_UNREG;
  18982. restart_loop = 1;
  18983. spin_unlock_irq(&phba->hbalock);
  18984. spin_lock(&ndlp->lock);
  18985. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  18986. spin_unlock(&ndlp->lock);
  18987. spin_lock_irq(&phba->hbalock);
  18988. break;
  18989. }
  18990. }
  18991. } while (restart_loop);
  18992. spin_unlock_irq(&phba->hbalock);
  18993. /* Release the cleaned-up mailbox commands */
  18994. while (!list_empty(&mbox_cmd_list)) {
  18995. list_remove_head(&mbox_cmd_list, mb, LPFC_MBOXQ_t, list);
  18996. if (mb->u.mb.mbxCommand == MBX_REG_LOGIN64) {
  18997. ndlp = (struct lpfc_nodelist *)mb->ctx_ndlp;
  18998. mb->ctx_ndlp = NULL;
  18999. if (ndlp) {
  19000. spin_lock(&ndlp->lock);
  19001. ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  19002. spin_unlock(&ndlp->lock);
  19003. lpfc_nlp_put(ndlp);
  19004. }
  19005. }
  19006. lpfc_mbox_rsrc_cleanup(phba, mb, MBOX_THD_UNLOCKED);
  19007. }
  19008. /* Release the ndlp with the cleaned-up active mailbox command */
  19009. if (act_mbx_ndlp) {
  19010. spin_lock(&act_mbx_ndlp->lock);
  19011. act_mbx_ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
  19012. spin_unlock(&act_mbx_ndlp->lock);
  19013. lpfc_nlp_put(act_mbx_ndlp);
  19014. }
  19015. }
  19016. /**
  19017. * lpfc_drain_txq - Drain the txq
  19018. * @phba: Pointer to HBA context object.
  19019. *
  19020. * This function attempt to submit IOCBs on the txq
  19021. * to the adapter. For SLI4 adapters, the txq contains
  19022. * ELS IOCBs that have been deferred because the there
  19023. * are no SGLs. This congestion can occur with large
  19024. * vport counts during node discovery.
  19025. **/
  19026. uint32_t
  19027. lpfc_drain_txq(struct lpfc_hba *phba)
  19028. {
  19029. LIST_HEAD(completions);
  19030. struct lpfc_sli_ring *pring;
  19031. struct lpfc_iocbq *piocbq = NULL;
  19032. unsigned long iflags = 0;
  19033. char *fail_msg = NULL;
  19034. uint32_t txq_cnt = 0;
  19035. struct lpfc_queue *wq;
  19036. int ret = 0;
  19037. if (phba->link_flag & LS_MDS_LOOPBACK) {
  19038. /* MDS WQE are posted only to first WQ*/
  19039. wq = phba->sli4_hba.hdwq[0].io_wq;
  19040. if (unlikely(!wq))
  19041. return 0;
  19042. pring = wq->pring;
  19043. } else {
  19044. wq = phba->sli4_hba.els_wq;
  19045. if (unlikely(!wq))
  19046. return 0;
  19047. pring = lpfc_phba_elsring(phba);
  19048. }
  19049. if (unlikely(!pring) || list_empty(&pring->txq))
  19050. return 0;
  19051. spin_lock_irqsave(&pring->ring_lock, iflags);
  19052. list_for_each_entry(piocbq, &pring->txq, list) {
  19053. txq_cnt++;
  19054. }
  19055. if (txq_cnt > pring->txq_max)
  19056. pring->txq_max = txq_cnt;
  19057. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19058. while (!list_empty(&pring->txq)) {
  19059. spin_lock_irqsave(&pring->ring_lock, iflags);
  19060. piocbq = lpfc_sli_ringtx_get(phba, pring);
  19061. if (!piocbq) {
  19062. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19063. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  19064. "2823 txq empty and txq_cnt is %d\n ",
  19065. txq_cnt);
  19066. break;
  19067. }
  19068. txq_cnt--;
  19069. ret = __lpfc_sli_issue_iocb(phba, pring->ringno, piocbq, 0);
  19070. if (ret && ret != IOCB_BUSY) {
  19071. fail_msg = " - Cannot send IO ";
  19072. piocbq->cmd_flag &= ~LPFC_DRIVER_ABORTED;
  19073. }
  19074. if (fail_msg) {
  19075. piocbq->cmd_flag |= LPFC_DRIVER_ABORTED;
  19076. /* Failed means we can't issue and need to cancel */
  19077. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  19078. "2822 IOCB failed %s iotag 0x%x "
  19079. "xri 0x%x %d flg x%x\n",
  19080. fail_msg, piocbq->iotag,
  19081. piocbq->sli4_xritag, ret,
  19082. piocbq->cmd_flag);
  19083. list_add_tail(&piocbq->list, &completions);
  19084. fail_msg = NULL;
  19085. }
  19086. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19087. if (txq_cnt == 0 || ret == IOCB_BUSY)
  19088. break;
  19089. }
  19090. /* Cancel all the IOCBs that cannot be issued */
  19091. lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
  19092. IOERR_SLI_ABORTED);
  19093. return txq_cnt;
  19094. }
  19095. /**
  19096. * lpfc_wqe_bpl2sgl - Convert the bpl/bde to a sgl.
  19097. * @phba: Pointer to HBA context object.
  19098. * @pwqeq: Pointer to command WQE.
  19099. * @sglq: Pointer to the scatter gather queue object.
  19100. *
  19101. * This routine converts the bpl or bde that is in the WQE
  19102. * to a sgl list for the sli4 hardware. The physical address
  19103. * of the bpl/bde is converted back to a virtual address.
  19104. * If the WQE contains a BPL then the list of BDE's is
  19105. * converted to sli4_sge's. If the WQE contains a single
  19106. * BDE then it is converted to a single sli_sge.
  19107. * The WQE is still in cpu endianness so the contents of
  19108. * the bpl can be used without byte swapping.
  19109. *
  19110. * Returns valid XRI = Success, NO_XRI = Failure.
  19111. */
  19112. static uint16_t
  19113. lpfc_wqe_bpl2sgl(struct lpfc_hba *phba, struct lpfc_iocbq *pwqeq,
  19114. struct lpfc_sglq *sglq)
  19115. {
  19116. uint16_t xritag = NO_XRI;
  19117. struct ulp_bde64 *bpl = NULL;
  19118. struct ulp_bde64 bde;
  19119. struct sli4_sge *sgl = NULL;
  19120. struct lpfc_dmabuf *dmabuf;
  19121. union lpfc_wqe128 *wqe;
  19122. int numBdes = 0;
  19123. int i = 0;
  19124. uint32_t offset = 0; /* accumulated offset in the sg request list */
  19125. int inbound = 0; /* number of sg reply entries inbound from firmware */
  19126. uint32_t cmd;
  19127. if (!pwqeq || !sglq)
  19128. return xritag;
  19129. sgl = (struct sli4_sge *)sglq->sgl;
  19130. wqe = &pwqeq->wqe;
  19131. pwqeq->iocb.ulpIoTag = pwqeq->iotag;
  19132. cmd = bf_get(wqe_cmnd, &wqe->generic.wqe_com);
  19133. if (cmd == CMD_XMIT_BLS_RSP64_WQE)
  19134. return sglq->sli4_xritag;
  19135. numBdes = pwqeq->num_bdes;
  19136. if (numBdes) {
  19137. /* The addrHigh and addrLow fields within the WQE
  19138. * have not been byteswapped yet so there is no
  19139. * need to swap them back.
  19140. */
  19141. if (pwqeq->bpl_dmabuf)
  19142. dmabuf = pwqeq->bpl_dmabuf;
  19143. else
  19144. return xritag;
  19145. bpl = (struct ulp_bde64 *)dmabuf->virt;
  19146. if (!bpl)
  19147. return xritag;
  19148. for (i = 0; i < numBdes; i++) {
  19149. /* Should already be byte swapped. */
  19150. sgl->addr_hi = bpl->addrHigh;
  19151. sgl->addr_lo = bpl->addrLow;
  19152. sgl->word2 = le32_to_cpu(sgl->word2);
  19153. if ((i+1) == numBdes)
  19154. bf_set(lpfc_sli4_sge_last, sgl, 1);
  19155. else
  19156. bf_set(lpfc_sli4_sge_last, sgl, 0);
  19157. /* swap the size field back to the cpu so we
  19158. * can assign it to the sgl.
  19159. */
  19160. bde.tus.w = le32_to_cpu(bpl->tus.w);
  19161. sgl->sge_len = cpu_to_le32(bde.tus.f.bdeSize);
  19162. /* The offsets in the sgl need to be accumulated
  19163. * separately for the request and reply lists.
  19164. * The request is always first, the reply follows.
  19165. */
  19166. switch (cmd) {
  19167. case CMD_GEN_REQUEST64_WQE:
  19168. /* add up the reply sg entries */
  19169. if (bpl->tus.f.bdeFlags == BUFF_TYPE_BDE_64I)
  19170. inbound++;
  19171. /* first inbound? reset the offset */
  19172. if (inbound == 1)
  19173. offset = 0;
  19174. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  19175. bf_set(lpfc_sli4_sge_type, sgl,
  19176. LPFC_SGE_TYPE_DATA);
  19177. offset += bde.tus.f.bdeSize;
  19178. break;
  19179. case CMD_FCP_TRSP64_WQE:
  19180. bf_set(lpfc_sli4_sge_offset, sgl, 0);
  19181. bf_set(lpfc_sli4_sge_type, sgl,
  19182. LPFC_SGE_TYPE_DATA);
  19183. break;
  19184. case CMD_FCP_TSEND64_WQE:
  19185. case CMD_FCP_TRECEIVE64_WQE:
  19186. bf_set(lpfc_sli4_sge_type, sgl,
  19187. bpl->tus.f.bdeFlags);
  19188. if (i < 3)
  19189. offset = 0;
  19190. else
  19191. offset += bde.tus.f.bdeSize;
  19192. bf_set(lpfc_sli4_sge_offset, sgl, offset);
  19193. break;
  19194. }
  19195. sgl->word2 = cpu_to_le32(sgl->word2);
  19196. bpl++;
  19197. sgl++;
  19198. }
  19199. } else if (wqe->gen_req.bde.tus.f.bdeFlags == BUFF_TYPE_BDE_64) {
  19200. /* The addrHigh and addrLow fields of the BDE have not
  19201. * been byteswapped yet so they need to be swapped
  19202. * before putting them in the sgl.
  19203. */
  19204. sgl->addr_hi = cpu_to_le32(wqe->gen_req.bde.addrHigh);
  19205. sgl->addr_lo = cpu_to_le32(wqe->gen_req.bde.addrLow);
  19206. sgl->word2 = le32_to_cpu(sgl->word2);
  19207. bf_set(lpfc_sli4_sge_last, sgl, 1);
  19208. sgl->word2 = cpu_to_le32(sgl->word2);
  19209. sgl->sge_len = cpu_to_le32(wqe->gen_req.bde.tus.f.bdeSize);
  19210. }
  19211. return sglq->sli4_xritag;
  19212. }
  19213. /**
  19214. * lpfc_sli4_issue_wqe - Issue an SLI4 Work Queue Entry (WQE)
  19215. * @phba: Pointer to HBA context object.
  19216. * @qp: Pointer to HDW queue.
  19217. * @pwqe: Pointer to command WQE.
  19218. **/
  19219. int
  19220. lpfc_sli4_issue_wqe(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
  19221. struct lpfc_iocbq *pwqe)
  19222. {
  19223. union lpfc_wqe128 *wqe = &pwqe->wqe;
  19224. struct lpfc_async_xchg_ctx *ctxp;
  19225. struct lpfc_queue *wq;
  19226. struct lpfc_sglq *sglq;
  19227. struct lpfc_sli_ring *pring;
  19228. unsigned long iflags;
  19229. uint32_t ret = 0;
  19230. /* NVME_LS and NVME_LS ABTS requests. */
  19231. if (pwqe->cmd_flag & LPFC_IO_NVME_LS) {
  19232. pring = phba->sli4_hba.nvmels_wq->pring;
  19233. lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
  19234. qp, wq_access);
  19235. sglq = __lpfc_sli_get_els_sglq(phba, pwqe);
  19236. if (!sglq) {
  19237. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19238. return WQE_BUSY;
  19239. }
  19240. pwqe->sli4_lxritag = sglq->sli4_lxritag;
  19241. pwqe->sli4_xritag = sglq->sli4_xritag;
  19242. if (lpfc_wqe_bpl2sgl(phba, pwqe, sglq) == NO_XRI) {
  19243. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19244. return WQE_ERROR;
  19245. }
  19246. bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
  19247. pwqe->sli4_xritag);
  19248. ret = lpfc_sli4_wq_put(phba->sli4_hba.nvmels_wq, wqe);
  19249. if (ret) {
  19250. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19251. return ret;
  19252. }
  19253. lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
  19254. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19255. lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
  19256. return 0;
  19257. }
  19258. /* NVME_FCREQ and NVME_ABTS requests */
  19259. if (pwqe->cmd_flag & (LPFC_IO_NVME | LPFC_IO_FCP | LPFC_IO_CMF)) {
  19260. /* Get the IO distribution (hba_wqidx) for WQ assignment. */
  19261. wq = qp->io_wq;
  19262. pring = wq->pring;
  19263. bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
  19264. lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
  19265. qp, wq_access);
  19266. ret = lpfc_sli4_wq_put(wq, wqe);
  19267. if (ret) {
  19268. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19269. return ret;
  19270. }
  19271. lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
  19272. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19273. lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
  19274. return 0;
  19275. }
  19276. /* NVMET requests */
  19277. if (pwqe->cmd_flag & LPFC_IO_NVMET) {
  19278. /* Get the IO distribution (hba_wqidx) for WQ assignment. */
  19279. wq = qp->io_wq;
  19280. pring = wq->pring;
  19281. ctxp = pwqe->context_un.axchg;
  19282. sglq = ctxp->ctxbuf->sglq;
  19283. if (pwqe->sli4_xritag == NO_XRI) {
  19284. pwqe->sli4_lxritag = sglq->sli4_lxritag;
  19285. pwqe->sli4_xritag = sglq->sli4_xritag;
  19286. }
  19287. bf_set(wqe_xri_tag, &pwqe->wqe.xmit_bls_rsp.wqe_com,
  19288. pwqe->sli4_xritag);
  19289. bf_set(wqe_cqid, &wqe->generic.wqe_com, qp->io_cq_map);
  19290. lpfc_qp_spin_lock_irqsave(&pring->ring_lock, iflags,
  19291. qp, wq_access);
  19292. ret = lpfc_sli4_wq_put(wq, wqe);
  19293. if (ret) {
  19294. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19295. return ret;
  19296. }
  19297. lpfc_sli_ringtxcmpl_put(phba, pring, pwqe);
  19298. spin_unlock_irqrestore(&pring->ring_lock, iflags);
  19299. lpfc_sli4_poll_eq(qp->hba_eq, LPFC_POLL_FASTPATH);
  19300. return 0;
  19301. }
  19302. return WQE_ERROR;
  19303. }
  19304. /**
  19305. * lpfc_sli4_issue_abort_iotag - SLI-4 WQE init & issue for the Abort
  19306. * @phba: Pointer to HBA context object.
  19307. * @cmdiocb: Pointer to driver command iocb object.
  19308. * @cmpl: completion function.
  19309. *
  19310. * Fill the appropriate fields for the abort WQE and call
  19311. * internal routine lpfc_sli4_issue_wqe to send the WQE
  19312. * This function is called with hbalock held and no ring_lock held.
  19313. *
  19314. * RETURNS 0 - SUCCESS
  19315. **/
  19316. int
  19317. lpfc_sli4_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  19318. void *cmpl)
  19319. {
  19320. struct lpfc_vport *vport = cmdiocb->vport;
  19321. struct lpfc_iocbq *abtsiocb = NULL;
  19322. union lpfc_wqe128 *abtswqe;
  19323. struct lpfc_io_buf *lpfc_cmd;
  19324. int retval = IOCB_ERROR;
  19325. u16 xritag = cmdiocb->sli4_xritag;
  19326. /*
  19327. * The scsi command can not be in txq and it is in flight because the
  19328. * pCmd is still pointing at the SCSI command we have to abort. There
  19329. * is no need to search the txcmplq. Just send an abort to the FW.
  19330. */
  19331. abtsiocb = __lpfc_sli_get_iocbq(phba);
  19332. if (!abtsiocb)
  19333. return WQE_NORESOURCE;
  19334. /* Indicate the IO is being aborted by the driver. */
  19335. cmdiocb->cmd_flag |= LPFC_DRIVER_ABORTED;
  19336. abtswqe = &abtsiocb->wqe;
  19337. memset(abtswqe, 0, sizeof(*abtswqe));
  19338. if (!lpfc_is_link_up(phba) || (phba->link_flag & LS_EXTERNAL_LOOPBACK))
  19339. bf_set(abort_cmd_ia, &abtswqe->abort_cmd, 1);
  19340. bf_set(abort_cmd_criteria, &abtswqe->abort_cmd, T_XRI_TAG);
  19341. abtswqe->abort_cmd.rsrvd5 = 0;
  19342. abtswqe->abort_cmd.wqe_com.abort_tag = xritag;
  19343. bf_set(wqe_reqtag, &abtswqe->abort_cmd.wqe_com, abtsiocb->iotag);
  19344. bf_set(wqe_cmnd, &abtswqe->abort_cmd.wqe_com, CMD_ABORT_XRI_CX);
  19345. bf_set(wqe_xri_tag, &abtswqe->generic.wqe_com, 0);
  19346. bf_set(wqe_qosd, &abtswqe->abort_cmd.wqe_com, 1);
  19347. bf_set(wqe_lenloc, &abtswqe->abort_cmd.wqe_com, LPFC_WQE_LENLOC_NONE);
  19348. bf_set(wqe_cmd_type, &abtswqe->abort_cmd.wqe_com, OTHER_COMMAND);
  19349. /* ABTS WQE must go to the same WQ as the WQE to be aborted */
  19350. abtsiocb->hba_wqidx = cmdiocb->hba_wqidx;
  19351. abtsiocb->cmd_flag |= LPFC_USE_FCPWQIDX;
  19352. if (cmdiocb->cmd_flag & LPFC_IO_FCP)
  19353. abtsiocb->cmd_flag |= LPFC_IO_FCP;
  19354. if (cmdiocb->cmd_flag & LPFC_IO_NVME)
  19355. abtsiocb->cmd_flag |= LPFC_IO_NVME;
  19356. if (cmdiocb->cmd_flag & LPFC_IO_FOF)
  19357. abtsiocb->cmd_flag |= LPFC_IO_FOF;
  19358. abtsiocb->vport = vport;
  19359. abtsiocb->cmd_cmpl = cmpl;
  19360. lpfc_cmd = container_of(cmdiocb, struct lpfc_io_buf, cur_iocbq);
  19361. retval = lpfc_sli4_issue_wqe(phba, lpfc_cmd->hdwq, abtsiocb);
  19362. lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
  19363. "0359 Abort xri x%x, original iotag x%x, "
  19364. "abort cmd iotag x%x retval x%x\n",
  19365. xritag, cmdiocb->iotag, abtsiocb->iotag, retval);
  19366. if (retval) {
  19367. cmdiocb->cmd_flag &= ~LPFC_DRIVER_ABORTED;
  19368. __lpfc_sli_release_iocbq(phba, abtsiocb);
  19369. }
  19370. return retval;
  19371. }
  19372. #ifdef LPFC_MXP_STAT
  19373. /**
  19374. * lpfc_snapshot_mxp - Snapshot pbl, pvt and busy count
  19375. * @phba: pointer to lpfc hba data structure.
  19376. * @hwqid: belong to which HWQ.
  19377. *
  19378. * The purpose of this routine is to take a snapshot of pbl, pvt and busy count
  19379. * 15 seconds after a test case is running.
  19380. *
  19381. * The user should call lpfc_debugfs_multixripools_write before running a test
  19382. * case to clear stat_snapshot_taken. Then the user starts a test case. During
  19383. * test case is running, stat_snapshot_taken is incremented by 1 every time when
  19384. * this routine is called from heartbeat timer. When stat_snapshot_taken is
  19385. * equal to LPFC_MXP_SNAPSHOT_TAKEN, a snapshot is taken.
  19386. **/
  19387. void lpfc_snapshot_mxp(struct lpfc_hba *phba, u32 hwqid)
  19388. {
  19389. struct lpfc_sli4_hdw_queue *qp;
  19390. struct lpfc_multixri_pool *multixri_pool;
  19391. struct lpfc_pvt_pool *pvt_pool;
  19392. struct lpfc_pbl_pool *pbl_pool;
  19393. u32 txcmplq_cnt;
  19394. qp = &phba->sli4_hba.hdwq[hwqid];
  19395. multixri_pool = qp->p_multixri_pool;
  19396. if (!multixri_pool)
  19397. return;
  19398. if (multixri_pool->stat_snapshot_taken == LPFC_MXP_SNAPSHOT_TAKEN) {
  19399. pvt_pool = &qp->p_multixri_pool->pvt_pool;
  19400. pbl_pool = &qp->p_multixri_pool->pbl_pool;
  19401. txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
  19402. multixri_pool->stat_pbl_count = pbl_pool->count;
  19403. multixri_pool->stat_pvt_count = pvt_pool->count;
  19404. multixri_pool->stat_busy_count = txcmplq_cnt;
  19405. }
  19406. multixri_pool->stat_snapshot_taken++;
  19407. }
  19408. #endif
  19409. /**
  19410. * lpfc_adjust_pvt_pool_count - Adjust private pool count
  19411. * @phba: pointer to lpfc hba data structure.
  19412. * @hwqid: belong to which HWQ.
  19413. *
  19414. * This routine moves some XRIs from private to public pool when private pool
  19415. * is not busy.
  19416. **/
  19417. void lpfc_adjust_pvt_pool_count(struct lpfc_hba *phba, u32 hwqid)
  19418. {
  19419. struct lpfc_multixri_pool *multixri_pool;
  19420. u32 io_req_count;
  19421. u32 prev_io_req_count;
  19422. multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
  19423. if (!multixri_pool)
  19424. return;
  19425. io_req_count = multixri_pool->io_req_count;
  19426. prev_io_req_count = multixri_pool->prev_io_req_count;
  19427. if (prev_io_req_count != io_req_count) {
  19428. /* Private pool is busy */
  19429. multixri_pool->prev_io_req_count = io_req_count;
  19430. } else {
  19431. /* Private pool is not busy.
  19432. * Move XRIs from private to public pool.
  19433. */
  19434. lpfc_move_xri_pvt_to_pbl(phba, hwqid);
  19435. }
  19436. }
  19437. /**
  19438. * lpfc_adjust_high_watermark - Adjust high watermark
  19439. * @phba: pointer to lpfc hba data structure.
  19440. * @hwqid: belong to which HWQ.
  19441. *
  19442. * This routine sets high watermark as number of outstanding XRIs,
  19443. * but make sure the new value is between xri_limit/2 and xri_limit.
  19444. **/
  19445. void lpfc_adjust_high_watermark(struct lpfc_hba *phba, u32 hwqid)
  19446. {
  19447. u32 new_watermark;
  19448. u32 watermark_max;
  19449. u32 watermark_min;
  19450. u32 xri_limit;
  19451. u32 txcmplq_cnt;
  19452. u32 abts_io_bufs;
  19453. struct lpfc_multixri_pool *multixri_pool;
  19454. struct lpfc_sli4_hdw_queue *qp;
  19455. qp = &phba->sli4_hba.hdwq[hwqid];
  19456. multixri_pool = qp->p_multixri_pool;
  19457. if (!multixri_pool)
  19458. return;
  19459. xri_limit = multixri_pool->xri_limit;
  19460. watermark_max = xri_limit;
  19461. watermark_min = xri_limit / 2;
  19462. txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
  19463. abts_io_bufs = qp->abts_scsi_io_bufs;
  19464. abts_io_bufs += qp->abts_nvme_io_bufs;
  19465. new_watermark = txcmplq_cnt + abts_io_bufs;
  19466. new_watermark = min(watermark_max, new_watermark);
  19467. new_watermark = max(watermark_min, new_watermark);
  19468. multixri_pool->pvt_pool.high_watermark = new_watermark;
  19469. #ifdef LPFC_MXP_STAT
  19470. multixri_pool->stat_max_hwm = max(multixri_pool->stat_max_hwm,
  19471. new_watermark);
  19472. #endif
  19473. }
  19474. /**
  19475. * lpfc_move_xri_pvt_to_pbl - Move some XRIs from private to public pool
  19476. * @phba: pointer to lpfc hba data structure.
  19477. * @hwqid: belong to which HWQ.
  19478. *
  19479. * This routine is called from hearbeat timer when pvt_pool is idle.
  19480. * All free XRIs are moved from private to public pool on hwqid with 2 steps.
  19481. * The first step moves (all - low_watermark) amount of XRIs.
  19482. * The second step moves the rest of XRIs.
  19483. **/
  19484. void lpfc_move_xri_pvt_to_pbl(struct lpfc_hba *phba, u32 hwqid)
  19485. {
  19486. struct lpfc_pbl_pool *pbl_pool;
  19487. struct lpfc_pvt_pool *pvt_pool;
  19488. struct lpfc_sli4_hdw_queue *qp;
  19489. struct lpfc_io_buf *lpfc_ncmd;
  19490. struct lpfc_io_buf *lpfc_ncmd_next;
  19491. unsigned long iflag;
  19492. struct list_head tmp_list;
  19493. u32 tmp_count;
  19494. qp = &phba->sli4_hba.hdwq[hwqid];
  19495. pbl_pool = &qp->p_multixri_pool->pbl_pool;
  19496. pvt_pool = &qp->p_multixri_pool->pvt_pool;
  19497. tmp_count = 0;
  19498. lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag, qp, mv_to_pub_pool);
  19499. lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_from_pvt_pool);
  19500. if (pvt_pool->count > pvt_pool->low_watermark) {
  19501. /* Step 1: move (all - low_watermark) from pvt_pool
  19502. * to pbl_pool
  19503. */
  19504. /* Move low watermark of bufs from pvt_pool to tmp_list */
  19505. INIT_LIST_HEAD(&tmp_list);
  19506. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  19507. &pvt_pool->list, list) {
  19508. list_move_tail(&lpfc_ncmd->list, &tmp_list);
  19509. tmp_count++;
  19510. if (tmp_count >= pvt_pool->low_watermark)
  19511. break;
  19512. }
  19513. /* Move all bufs from pvt_pool to pbl_pool */
  19514. list_splice_init(&pvt_pool->list, &pbl_pool->list);
  19515. /* Move all bufs from tmp_list to pvt_pool */
  19516. list_splice(&tmp_list, &pvt_pool->list);
  19517. pbl_pool->count += (pvt_pool->count - tmp_count);
  19518. pvt_pool->count = tmp_count;
  19519. } else {
  19520. /* Step 2: move the rest from pvt_pool to pbl_pool */
  19521. list_splice_init(&pvt_pool->list, &pbl_pool->list);
  19522. pbl_pool->count += pvt_pool->count;
  19523. pvt_pool->count = 0;
  19524. }
  19525. spin_unlock(&pvt_pool->lock);
  19526. spin_unlock_irqrestore(&pbl_pool->lock, iflag);
  19527. }
  19528. /**
  19529. * _lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
  19530. * @phba: pointer to lpfc hba data structure
  19531. * @qp: pointer to HDW queue
  19532. * @pbl_pool: specified public free XRI pool
  19533. * @pvt_pool: specified private free XRI pool
  19534. * @count: number of XRIs to move
  19535. *
  19536. * This routine tries to move some free common bufs from the specified pbl_pool
  19537. * to the specified pvt_pool. It might move less than count XRIs if there's not
  19538. * enough in public pool.
  19539. *
  19540. * Return:
  19541. * true - if XRIs are successfully moved from the specified pbl_pool to the
  19542. * specified pvt_pool
  19543. * false - if the specified pbl_pool is empty or locked by someone else
  19544. **/
  19545. static bool
  19546. _lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, struct lpfc_sli4_hdw_queue *qp,
  19547. struct lpfc_pbl_pool *pbl_pool,
  19548. struct lpfc_pvt_pool *pvt_pool, u32 count)
  19549. {
  19550. struct lpfc_io_buf *lpfc_ncmd;
  19551. struct lpfc_io_buf *lpfc_ncmd_next;
  19552. unsigned long iflag;
  19553. int ret;
  19554. ret = spin_trylock_irqsave(&pbl_pool->lock, iflag);
  19555. if (ret) {
  19556. if (pbl_pool->count) {
  19557. /* Move a batch of XRIs from public to private pool */
  19558. lpfc_qp_spin_lock(&pvt_pool->lock, qp, mv_to_pvt_pool);
  19559. list_for_each_entry_safe(lpfc_ncmd,
  19560. lpfc_ncmd_next,
  19561. &pbl_pool->list,
  19562. list) {
  19563. list_move_tail(&lpfc_ncmd->list,
  19564. &pvt_pool->list);
  19565. pvt_pool->count++;
  19566. pbl_pool->count--;
  19567. count--;
  19568. if (count == 0)
  19569. break;
  19570. }
  19571. spin_unlock(&pvt_pool->lock);
  19572. spin_unlock_irqrestore(&pbl_pool->lock, iflag);
  19573. return true;
  19574. }
  19575. spin_unlock_irqrestore(&pbl_pool->lock, iflag);
  19576. }
  19577. return false;
  19578. }
  19579. /**
  19580. * lpfc_move_xri_pbl_to_pvt - Move some XRIs from public to private pool
  19581. * @phba: pointer to lpfc hba data structure.
  19582. * @hwqid: belong to which HWQ.
  19583. * @count: number of XRIs to move
  19584. *
  19585. * This routine tries to find some free common bufs in one of public pools with
  19586. * Round Robin method. The search always starts from local hwqid, then the next
  19587. * HWQ which was found last time (rrb_next_hwqid). Once a public pool is found,
  19588. * a batch of free common bufs are moved to private pool on hwqid.
  19589. * It might move less than count XRIs if there's not enough in public pool.
  19590. **/
  19591. void lpfc_move_xri_pbl_to_pvt(struct lpfc_hba *phba, u32 hwqid, u32 count)
  19592. {
  19593. struct lpfc_multixri_pool *multixri_pool;
  19594. struct lpfc_multixri_pool *next_multixri_pool;
  19595. struct lpfc_pvt_pool *pvt_pool;
  19596. struct lpfc_pbl_pool *pbl_pool;
  19597. struct lpfc_sli4_hdw_queue *qp;
  19598. u32 next_hwqid;
  19599. u32 hwq_count;
  19600. int ret;
  19601. qp = &phba->sli4_hba.hdwq[hwqid];
  19602. multixri_pool = qp->p_multixri_pool;
  19603. pvt_pool = &multixri_pool->pvt_pool;
  19604. pbl_pool = &multixri_pool->pbl_pool;
  19605. /* Check if local pbl_pool is available */
  19606. ret = _lpfc_move_xri_pbl_to_pvt(phba, qp, pbl_pool, pvt_pool, count);
  19607. if (ret) {
  19608. #ifdef LPFC_MXP_STAT
  19609. multixri_pool->local_pbl_hit_count++;
  19610. #endif
  19611. return;
  19612. }
  19613. hwq_count = phba->cfg_hdw_queue;
  19614. /* Get the next hwqid which was found last time */
  19615. next_hwqid = multixri_pool->rrb_next_hwqid;
  19616. do {
  19617. /* Go to next hwq */
  19618. next_hwqid = (next_hwqid + 1) % hwq_count;
  19619. next_multixri_pool =
  19620. phba->sli4_hba.hdwq[next_hwqid].p_multixri_pool;
  19621. pbl_pool = &next_multixri_pool->pbl_pool;
  19622. /* Check if the public free xri pool is available */
  19623. ret = _lpfc_move_xri_pbl_to_pvt(
  19624. phba, qp, pbl_pool, pvt_pool, count);
  19625. /* Exit while-loop if success or all hwqid are checked */
  19626. } while (!ret && next_hwqid != multixri_pool->rrb_next_hwqid);
  19627. /* Starting point for the next time */
  19628. multixri_pool->rrb_next_hwqid = next_hwqid;
  19629. if (!ret) {
  19630. /* stats: all public pools are empty*/
  19631. multixri_pool->pbl_empty_count++;
  19632. }
  19633. #ifdef LPFC_MXP_STAT
  19634. if (ret) {
  19635. if (next_hwqid == hwqid)
  19636. multixri_pool->local_pbl_hit_count++;
  19637. else
  19638. multixri_pool->other_pbl_hit_count++;
  19639. }
  19640. #endif
  19641. }
  19642. /**
  19643. * lpfc_keep_pvt_pool_above_lowwm - Keep pvt_pool above low watermark
  19644. * @phba: pointer to lpfc hba data structure.
  19645. * @hwqid: belong to which HWQ.
  19646. *
  19647. * This routine get a batch of XRIs from pbl_pool if pvt_pool is less than
  19648. * low watermark.
  19649. **/
  19650. void lpfc_keep_pvt_pool_above_lowwm(struct lpfc_hba *phba, u32 hwqid)
  19651. {
  19652. struct lpfc_multixri_pool *multixri_pool;
  19653. struct lpfc_pvt_pool *pvt_pool;
  19654. multixri_pool = phba->sli4_hba.hdwq[hwqid].p_multixri_pool;
  19655. pvt_pool = &multixri_pool->pvt_pool;
  19656. if (pvt_pool->count < pvt_pool->low_watermark)
  19657. lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
  19658. }
  19659. /**
  19660. * lpfc_release_io_buf - Return one IO buf back to free pool
  19661. * @phba: pointer to lpfc hba data structure.
  19662. * @lpfc_ncmd: IO buf to be returned.
  19663. * @qp: belong to which HWQ.
  19664. *
  19665. * This routine returns one IO buf back to free pool. If this is an urgent IO,
  19666. * the IO buf is returned to expedite pool. If cfg_xri_rebalancing==1,
  19667. * the IO buf is returned to pbl_pool or pvt_pool based on watermark and
  19668. * xri_limit. If cfg_xri_rebalancing==0, the IO buf is returned to
  19669. * lpfc_io_buf_list_put.
  19670. **/
  19671. void lpfc_release_io_buf(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_ncmd,
  19672. struct lpfc_sli4_hdw_queue *qp)
  19673. {
  19674. unsigned long iflag;
  19675. struct lpfc_pbl_pool *pbl_pool;
  19676. struct lpfc_pvt_pool *pvt_pool;
  19677. struct lpfc_epd_pool *epd_pool;
  19678. u32 txcmplq_cnt;
  19679. u32 xri_owned;
  19680. u32 xri_limit;
  19681. u32 abts_io_bufs;
  19682. /* MUST zero fields if buffer is reused by another protocol */
  19683. lpfc_ncmd->nvmeCmd = NULL;
  19684. lpfc_ncmd->cur_iocbq.cmd_cmpl = NULL;
  19685. if (phba->cfg_xpsgl && !phba->nvmet_support &&
  19686. !list_empty(&lpfc_ncmd->dma_sgl_xtra_list))
  19687. lpfc_put_sgl_per_hdwq(phba, lpfc_ncmd);
  19688. if (!list_empty(&lpfc_ncmd->dma_cmd_rsp_list))
  19689. lpfc_put_cmd_rsp_buf_per_hdwq(phba, lpfc_ncmd);
  19690. if (phba->cfg_xri_rebalancing) {
  19691. if (lpfc_ncmd->expedite) {
  19692. /* Return to expedite pool */
  19693. epd_pool = &phba->epd_pool;
  19694. spin_lock_irqsave(&epd_pool->lock, iflag);
  19695. list_add_tail(&lpfc_ncmd->list, &epd_pool->list);
  19696. epd_pool->count++;
  19697. spin_unlock_irqrestore(&epd_pool->lock, iflag);
  19698. return;
  19699. }
  19700. /* Avoid invalid access if an IO sneaks in and is being rejected
  19701. * just _after_ xri pools are destroyed in lpfc_offline.
  19702. * Nothing much can be done at this point.
  19703. */
  19704. if (!qp->p_multixri_pool)
  19705. return;
  19706. pbl_pool = &qp->p_multixri_pool->pbl_pool;
  19707. pvt_pool = &qp->p_multixri_pool->pvt_pool;
  19708. txcmplq_cnt = qp->io_wq->pring->txcmplq_cnt;
  19709. abts_io_bufs = qp->abts_scsi_io_bufs;
  19710. abts_io_bufs += qp->abts_nvme_io_bufs;
  19711. xri_owned = pvt_pool->count + txcmplq_cnt + abts_io_bufs;
  19712. xri_limit = qp->p_multixri_pool->xri_limit;
  19713. #ifdef LPFC_MXP_STAT
  19714. if (xri_owned <= xri_limit)
  19715. qp->p_multixri_pool->below_limit_count++;
  19716. else
  19717. qp->p_multixri_pool->above_limit_count++;
  19718. #endif
  19719. /* XRI goes to either public or private free xri pool
  19720. * based on watermark and xri_limit
  19721. */
  19722. if ((pvt_pool->count < pvt_pool->low_watermark) ||
  19723. (xri_owned < xri_limit &&
  19724. pvt_pool->count < pvt_pool->high_watermark)) {
  19725. lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag,
  19726. qp, free_pvt_pool);
  19727. list_add_tail(&lpfc_ncmd->list,
  19728. &pvt_pool->list);
  19729. pvt_pool->count++;
  19730. spin_unlock_irqrestore(&pvt_pool->lock, iflag);
  19731. } else {
  19732. lpfc_qp_spin_lock_irqsave(&pbl_pool->lock, iflag,
  19733. qp, free_pub_pool);
  19734. list_add_tail(&lpfc_ncmd->list,
  19735. &pbl_pool->list);
  19736. pbl_pool->count++;
  19737. spin_unlock_irqrestore(&pbl_pool->lock, iflag);
  19738. }
  19739. } else {
  19740. lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_put_lock, iflag,
  19741. qp, free_xri);
  19742. list_add_tail(&lpfc_ncmd->list,
  19743. &qp->lpfc_io_buf_list_put);
  19744. qp->put_io_bufs++;
  19745. spin_unlock_irqrestore(&qp->io_buf_list_put_lock,
  19746. iflag);
  19747. }
  19748. }
  19749. /**
  19750. * lpfc_get_io_buf_from_private_pool - Get one free IO buf from private pool
  19751. * @phba: pointer to lpfc hba data structure.
  19752. * @qp: pointer to HDW queue
  19753. * @pvt_pool: pointer to private pool data structure.
  19754. * @ndlp: pointer to lpfc nodelist data structure.
  19755. *
  19756. * This routine tries to get one free IO buf from private pool.
  19757. *
  19758. * Return:
  19759. * pointer to one free IO buf - if private pool is not empty
  19760. * NULL - if private pool is empty
  19761. **/
  19762. static struct lpfc_io_buf *
  19763. lpfc_get_io_buf_from_private_pool(struct lpfc_hba *phba,
  19764. struct lpfc_sli4_hdw_queue *qp,
  19765. struct lpfc_pvt_pool *pvt_pool,
  19766. struct lpfc_nodelist *ndlp)
  19767. {
  19768. struct lpfc_io_buf *lpfc_ncmd;
  19769. struct lpfc_io_buf *lpfc_ncmd_next;
  19770. unsigned long iflag;
  19771. lpfc_qp_spin_lock_irqsave(&pvt_pool->lock, iflag, qp, alloc_pvt_pool);
  19772. list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next,
  19773. &pvt_pool->list, list) {
  19774. if (lpfc_test_rrq_active(
  19775. phba, ndlp, lpfc_ncmd->cur_iocbq.sli4_lxritag))
  19776. continue;
  19777. list_del(&lpfc_ncmd->list);
  19778. pvt_pool->count--;
  19779. spin_unlock_irqrestore(&pvt_pool->lock, iflag);
  19780. return lpfc_ncmd;
  19781. }
  19782. spin_unlock_irqrestore(&pvt_pool->lock, iflag);
  19783. return NULL;
  19784. }
  19785. /**
  19786. * lpfc_get_io_buf_from_expedite_pool - Get one free IO buf from expedite pool
  19787. * @phba: pointer to lpfc hba data structure.
  19788. *
  19789. * This routine tries to get one free IO buf from expedite pool.
  19790. *
  19791. * Return:
  19792. * pointer to one free IO buf - if expedite pool is not empty
  19793. * NULL - if expedite pool is empty
  19794. **/
  19795. static struct lpfc_io_buf *
  19796. lpfc_get_io_buf_from_expedite_pool(struct lpfc_hba *phba)
  19797. {
  19798. struct lpfc_io_buf *lpfc_ncmd = NULL, *iter;
  19799. struct lpfc_io_buf *lpfc_ncmd_next;
  19800. unsigned long iflag;
  19801. struct lpfc_epd_pool *epd_pool;
  19802. epd_pool = &phba->epd_pool;
  19803. spin_lock_irqsave(&epd_pool->lock, iflag);
  19804. if (epd_pool->count > 0) {
  19805. list_for_each_entry_safe(iter, lpfc_ncmd_next,
  19806. &epd_pool->list, list) {
  19807. list_del(&iter->list);
  19808. epd_pool->count--;
  19809. lpfc_ncmd = iter;
  19810. break;
  19811. }
  19812. }
  19813. spin_unlock_irqrestore(&epd_pool->lock, iflag);
  19814. return lpfc_ncmd;
  19815. }
  19816. /**
  19817. * lpfc_get_io_buf_from_multixri_pools - Get one free IO bufs
  19818. * @phba: pointer to lpfc hba data structure.
  19819. * @ndlp: pointer to lpfc nodelist data structure.
  19820. * @hwqid: belong to which HWQ
  19821. * @expedite: 1 means this request is urgent.
  19822. *
  19823. * This routine will do the following actions and then return a pointer to
  19824. * one free IO buf.
  19825. *
  19826. * 1. If private free xri count is empty, move some XRIs from public to
  19827. * private pool.
  19828. * 2. Get one XRI from private free xri pool.
  19829. * 3. If we fail to get one from pvt_pool and this is an expedite request,
  19830. * get one free xri from expedite pool.
  19831. *
  19832. * Note: ndlp is only used on SCSI side for RRQ testing.
  19833. * The caller should pass NULL for ndlp on NVME side.
  19834. *
  19835. * Return:
  19836. * pointer to one free IO buf - if private pool is not empty
  19837. * NULL - if private pool is empty
  19838. **/
  19839. static struct lpfc_io_buf *
  19840. lpfc_get_io_buf_from_multixri_pools(struct lpfc_hba *phba,
  19841. struct lpfc_nodelist *ndlp,
  19842. int hwqid, int expedite)
  19843. {
  19844. struct lpfc_sli4_hdw_queue *qp;
  19845. struct lpfc_multixri_pool *multixri_pool;
  19846. struct lpfc_pvt_pool *pvt_pool;
  19847. struct lpfc_io_buf *lpfc_ncmd;
  19848. qp = &phba->sli4_hba.hdwq[hwqid];
  19849. lpfc_ncmd = NULL;
  19850. if (!qp) {
  19851. lpfc_printf_log(phba, KERN_INFO,
  19852. LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
  19853. "5556 NULL qp for hwqid x%x\n", hwqid);
  19854. return lpfc_ncmd;
  19855. }
  19856. multixri_pool = qp->p_multixri_pool;
  19857. if (!multixri_pool) {
  19858. lpfc_printf_log(phba, KERN_INFO,
  19859. LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
  19860. "5557 NULL multixri for hwqid x%x\n", hwqid);
  19861. return lpfc_ncmd;
  19862. }
  19863. pvt_pool = &multixri_pool->pvt_pool;
  19864. if (!pvt_pool) {
  19865. lpfc_printf_log(phba, KERN_INFO,
  19866. LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
  19867. "5558 NULL pvt_pool for hwqid x%x\n", hwqid);
  19868. return lpfc_ncmd;
  19869. }
  19870. multixri_pool->io_req_count++;
  19871. /* If pvt_pool is empty, move some XRIs from public to private pool */
  19872. if (pvt_pool->count == 0)
  19873. lpfc_move_xri_pbl_to_pvt(phba, hwqid, XRI_BATCH);
  19874. /* Get one XRI from private free xri pool */
  19875. lpfc_ncmd = lpfc_get_io_buf_from_private_pool(phba, qp, pvt_pool, ndlp);
  19876. if (lpfc_ncmd) {
  19877. lpfc_ncmd->hdwq = qp;
  19878. lpfc_ncmd->hdwq_no = hwqid;
  19879. } else if (expedite) {
  19880. /* If we fail to get one from pvt_pool and this is an expedite
  19881. * request, get one free xri from expedite pool.
  19882. */
  19883. lpfc_ncmd = lpfc_get_io_buf_from_expedite_pool(phba);
  19884. }
  19885. return lpfc_ncmd;
  19886. }
  19887. static inline struct lpfc_io_buf *
  19888. lpfc_io_buf(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int idx)
  19889. {
  19890. struct lpfc_sli4_hdw_queue *qp;
  19891. struct lpfc_io_buf *lpfc_cmd, *lpfc_cmd_next;
  19892. qp = &phba->sli4_hba.hdwq[idx];
  19893. list_for_each_entry_safe(lpfc_cmd, lpfc_cmd_next,
  19894. &qp->lpfc_io_buf_list_get, list) {
  19895. if (lpfc_test_rrq_active(phba, ndlp,
  19896. lpfc_cmd->cur_iocbq.sli4_lxritag))
  19897. continue;
  19898. if (lpfc_cmd->flags & LPFC_SBUF_NOT_POSTED)
  19899. continue;
  19900. list_del_init(&lpfc_cmd->list);
  19901. qp->get_io_bufs--;
  19902. lpfc_cmd->hdwq = qp;
  19903. lpfc_cmd->hdwq_no = idx;
  19904. return lpfc_cmd;
  19905. }
  19906. return NULL;
  19907. }
  19908. /**
  19909. * lpfc_get_io_buf - Get one IO buffer from free pool
  19910. * @phba: The HBA for which this call is being executed.
  19911. * @ndlp: pointer to lpfc nodelist data structure.
  19912. * @hwqid: belong to which HWQ
  19913. * @expedite: 1 means this request is urgent.
  19914. *
  19915. * This routine gets one IO buffer from free pool. If cfg_xri_rebalancing==1,
  19916. * removes a IO buffer from multiXRI pools. If cfg_xri_rebalancing==0, removes
  19917. * a IO buffer from head of @hdwq io_buf_list and returns to caller.
  19918. *
  19919. * Note: ndlp is only used on SCSI side for RRQ testing.
  19920. * The caller should pass NULL for ndlp on NVME side.
  19921. *
  19922. * Return codes:
  19923. * NULL - Error
  19924. * Pointer to lpfc_io_buf - Success
  19925. **/
  19926. struct lpfc_io_buf *lpfc_get_io_buf(struct lpfc_hba *phba,
  19927. struct lpfc_nodelist *ndlp,
  19928. u32 hwqid, int expedite)
  19929. {
  19930. struct lpfc_sli4_hdw_queue *qp;
  19931. unsigned long iflag;
  19932. struct lpfc_io_buf *lpfc_cmd;
  19933. qp = &phba->sli4_hba.hdwq[hwqid];
  19934. lpfc_cmd = NULL;
  19935. if (!qp) {
  19936. lpfc_printf_log(phba, KERN_WARNING,
  19937. LOG_SLI | LOG_NVME_ABTS | LOG_FCP,
  19938. "5555 NULL qp for hwqid x%x\n", hwqid);
  19939. return lpfc_cmd;
  19940. }
  19941. if (phba->cfg_xri_rebalancing)
  19942. lpfc_cmd = lpfc_get_io_buf_from_multixri_pools(
  19943. phba, ndlp, hwqid, expedite);
  19944. else {
  19945. lpfc_qp_spin_lock_irqsave(&qp->io_buf_list_get_lock, iflag,
  19946. qp, alloc_xri_get);
  19947. if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT || expedite)
  19948. lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
  19949. if (!lpfc_cmd) {
  19950. lpfc_qp_spin_lock(&qp->io_buf_list_put_lock,
  19951. qp, alloc_xri_put);
  19952. list_splice(&qp->lpfc_io_buf_list_put,
  19953. &qp->lpfc_io_buf_list_get);
  19954. qp->get_io_bufs += qp->put_io_bufs;
  19955. INIT_LIST_HEAD(&qp->lpfc_io_buf_list_put);
  19956. qp->put_io_bufs = 0;
  19957. spin_unlock(&qp->io_buf_list_put_lock);
  19958. if (qp->get_io_bufs > LPFC_NVME_EXPEDITE_XRICNT ||
  19959. expedite)
  19960. lpfc_cmd = lpfc_io_buf(phba, ndlp, hwqid);
  19961. }
  19962. spin_unlock_irqrestore(&qp->io_buf_list_get_lock, iflag);
  19963. }
  19964. return lpfc_cmd;
  19965. }
  19966. /**
  19967. * lpfc_read_object - Retrieve object data from HBA
  19968. * @phba: The HBA for which this call is being executed.
  19969. * @rdobject: Pathname of object data we want to read.
  19970. * @datap: Pointer to where data will be copied to.
  19971. * @datasz: size of data area
  19972. *
  19973. * This routine is limited to object sizes of LPFC_BPL_SIZE (1024) or less.
  19974. * The data will be truncated if datasz is not large enough.
  19975. * Version 1 is not supported with Embedded mbox cmd, so we must use version 0.
  19976. * Returns the actual bytes read from the object.
  19977. */
  19978. int
  19979. lpfc_read_object(struct lpfc_hba *phba, char *rdobject, uint32_t *datap,
  19980. uint32_t datasz)
  19981. {
  19982. struct lpfc_mbx_read_object *read_object;
  19983. LPFC_MBOXQ_t *mbox;
  19984. int rc, length, eof, j, byte_cnt = 0;
  19985. uint32_t shdr_status, shdr_add_status;
  19986. union lpfc_sli4_cfg_shdr *shdr;
  19987. struct lpfc_dmabuf *pcmd;
  19988. u32 rd_object_name[LPFC_MBX_OBJECT_NAME_LEN_DW] = {0};
  19989. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  19990. if (!mbox)
  19991. return -ENOMEM;
  19992. length = (sizeof(struct lpfc_mbx_read_object) -
  19993. sizeof(struct lpfc_sli4_cfg_mhdr));
  19994. lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
  19995. LPFC_MBOX_OPCODE_READ_OBJECT,
  19996. length, LPFC_SLI4_MBX_EMBED);
  19997. read_object = &mbox->u.mqe.un.read_object;
  19998. shdr = (union lpfc_sli4_cfg_shdr *)&read_object->header.cfg_shdr;
  19999. bf_set(lpfc_mbox_hdr_version, &shdr->request, LPFC_Q_CREATE_VERSION_0);
  20000. bf_set(lpfc_mbx_rd_object_rlen, &read_object->u.request, datasz);
  20001. read_object->u.request.rd_object_offset = 0;
  20002. read_object->u.request.rd_object_cnt = 1;
  20003. memset((void *)read_object->u.request.rd_object_name, 0,
  20004. LPFC_OBJ_NAME_SZ);
  20005. scnprintf((char *)rd_object_name, sizeof(rd_object_name), rdobject);
  20006. for (j = 0; j < strlen(rdobject); j++)
  20007. read_object->u.request.rd_object_name[j] =
  20008. cpu_to_le32(rd_object_name[j]);
  20009. pcmd = kmalloc(sizeof(*pcmd), GFP_KERNEL);
  20010. if (pcmd)
  20011. pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
  20012. if (!pcmd || !pcmd->virt) {
  20013. kfree(pcmd);
  20014. mempool_free(mbox, phba->mbox_mem_pool);
  20015. return -ENOMEM;
  20016. }
  20017. memset((void *)pcmd->virt, 0, LPFC_BPL_SIZE);
  20018. read_object->u.request.rd_object_hbuf[0].pa_lo =
  20019. putPaddrLow(pcmd->phys);
  20020. read_object->u.request.rd_object_hbuf[0].pa_hi =
  20021. putPaddrHigh(pcmd->phys);
  20022. read_object->u.request.rd_object_hbuf[0].length = LPFC_BPL_SIZE;
  20023. mbox->vport = phba->pport;
  20024. mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  20025. mbox->ctx_ndlp = NULL;
  20026. rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
  20027. shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
  20028. shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
  20029. if (shdr_status == STATUS_FAILED &&
  20030. shdr_add_status == ADD_STATUS_INVALID_OBJECT_NAME) {
  20031. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
  20032. "4674 No port cfg file in FW.\n");
  20033. byte_cnt = -ENOENT;
  20034. } else if (shdr_status || shdr_add_status || rc) {
  20035. lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_CGN_MGMT,
  20036. "2625 READ_OBJECT mailbox failed with "
  20037. "status x%x add_status x%x, mbx status x%x\n",
  20038. shdr_status, shdr_add_status, rc);
  20039. byte_cnt = -ENXIO;
  20040. } else {
  20041. /* Success */
  20042. length = read_object->u.response.rd_object_actual_rlen;
  20043. eof = bf_get(lpfc_mbx_rd_object_eof, &read_object->u.response);
  20044. lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_CGN_MGMT,
  20045. "2626 READ_OBJECT Success len %d:%d, EOF %d\n",
  20046. length, datasz, eof);
  20047. /* Detect the port config file exists but is empty */
  20048. if (!length && eof) {
  20049. byte_cnt = 0;
  20050. goto exit;
  20051. }
  20052. byte_cnt = length;
  20053. lpfc_sli_pcimem_bcopy(pcmd->virt, datap, byte_cnt);
  20054. }
  20055. exit:
  20056. /* This is an embedded SLI4 mailbox with an external buffer allocated.
  20057. * Free the pcmd and then cleanup with the correct routine.
  20058. */
  20059. lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
  20060. kfree(pcmd);
  20061. lpfc_sli4_mbox_cmd_free(phba, mbox);
  20062. return byte_cnt;
  20063. }
  20064. /**
  20065. * lpfc_get_sgl_per_hdwq - Get one SGL chunk from hdwq's pool
  20066. * @phba: The HBA for which this call is being executed.
  20067. * @lpfc_buf: IO buf structure to append the SGL chunk
  20068. *
  20069. * This routine gets one SGL chunk buffer from hdwq's SGL chunk pool,
  20070. * and will allocate an SGL chunk if the pool is empty.
  20071. *
  20072. * Return codes:
  20073. * NULL - Error
  20074. * Pointer to sli4_hybrid_sgl - Success
  20075. **/
  20076. struct sli4_hybrid_sgl *
  20077. lpfc_get_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
  20078. {
  20079. struct sli4_hybrid_sgl *list_entry = NULL;
  20080. struct sli4_hybrid_sgl *tmp = NULL;
  20081. struct sli4_hybrid_sgl *allocated_sgl = NULL;
  20082. struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
  20083. struct list_head *buf_list = &hdwq->sgl_list;
  20084. unsigned long iflags;
  20085. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20086. if (likely(!list_empty(buf_list))) {
  20087. /* break off 1 chunk from the sgl_list */
  20088. list_for_each_entry_safe(list_entry, tmp,
  20089. buf_list, list_node) {
  20090. list_move_tail(&list_entry->list_node,
  20091. &lpfc_buf->dma_sgl_xtra_list);
  20092. break;
  20093. }
  20094. } else {
  20095. /* allocate more */
  20096. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20097. tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
  20098. cpu_to_node(hdwq->io_wq->chann));
  20099. if (!tmp) {
  20100. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  20101. "8353 error kmalloc memory for HDWQ "
  20102. "%d %s\n",
  20103. lpfc_buf->hdwq_no, __func__);
  20104. return NULL;
  20105. }
  20106. tmp->dma_sgl = dma_pool_alloc(phba->lpfc_sg_dma_buf_pool,
  20107. GFP_ATOMIC, &tmp->dma_phys_sgl);
  20108. if (!tmp->dma_sgl) {
  20109. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  20110. "8354 error pool_alloc memory for HDWQ "
  20111. "%d %s\n",
  20112. lpfc_buf->hdwq_no, __func__);
  20113. kfree(tmp);
  20114. return NULL;
  20115. }
  20116. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20117. list_add_tail(&tmp->list_node, &lpfc_buf->dma_sgl_xtra_list);
  20118. }
  20119. allocated_sgl = list_last_entry(&lpfc_buf->dma_sgl_xtra_list,
  20120. struct sli4_hybrid_sgl,
  20121. list_node);
  20122. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20123. return allocated_sgl;
  20124. }
  20125. /**
  20126. * lpfc_put_sgl_per_hdwq - Put one SGL chunk into hdwq pool
  20127. * @phba: The HBA for which this call is being executed.
  20128. * @lpfc_buf: IO buf structure with the SGL chunk
  20129. *
  20130. * This routine puts one SGL chunk buffer into hdwq's SGL chunk pool.
  20131. *
  20132. * Return codes:
  20133. * 0 - Success
  20134. * -EINVAL - Error
  20135. **/
  20136. int
  20137. lpfc_put_sgl_per_hdwq(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_buf)
  20138. {
  20139. int rc = 0;
  20140. struct sli4_hybrid_sgl *list_entry = NULL;
  20141. struct sli4_hybrid_sgl *tmp = NULL;
  20142. struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
  20143. struct list_head *buf_list = &hdwq->sgl_list;
  20144. unsigned long iflags;
  20145. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20146. if (likely(!list_empty(&lpfc_buf->dma_sgl_xtra_list))) {
  20147. list_for_each_entry_safe(list_entry, tmp,
  20148. &lpfc_buf->dma_sgl_xtra_list,
  20149. list_node) {
  20150. list_move_tail(&list_entry->list_node,
  20151. buf_list);
  20152. }
  20153. } else {
  20154. rc = -EINVAL;
  20155. }
  20156. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20157. return rc;
  20158. }
  20159. /**
  20160. * lpfc_free_sgl_per_hdwq - Free all SGL chunks of hdwq pool
  20161. * @phba: phba object
  20162. * @hdwq: hdwq to cleanup sgl buff resources on
  20163. *
  20164. * This routine frees all SGL chunks of hdwq SGL chunk pool.
  20165. *
  20166. * Return codes:
  20167. * None
  20168. **/
  20169. void
  20170. lpfc_free_sgl_per_hdwq(struct lpfc_hba *phba,
  20171. struct lpfc_sli4_hdw_queue *hdwq)
  20172. {
  20173. struct list_head *buf_list = &hdwq->sgl_list;
  20174. struct sli4_hybrid_sgl *list_entry = NULL;
  20175. struct sli4_hybrid_sgl *tmp = NULL;
  20176. unsigned long iflags;
  20177. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20178. /* Free sgl pool */
  20179. list_for_each_entry_safe(list_entry, tmp,
  20180. buf_list, list_node) {
  20181. dma_pool_free(phba->lpfc_sg_dma_buf_pool,
  20182. list_entry->dma_sgl,
  20183. list_entry->dma_phys_sgl);
  20184. list_del(&list_entry->list_node);
  20185. kfree(list_entry);
  20186. }
  20187. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20188. }
  20189. /**
  20190. * lpfc_get_cmd_rsp_buf_per_hdwq - Get one CMD/RSP buffer from hdwq
  20191. * @phba: The HBA for which this call is being executed.
  20192. * @lpfc_buf: IO buf structure to attach the CMD/RSP buffer
  20193. *
  20194. * This routine gets one CMD/RSP buffer from hdwq's CMD/RSP pool,
  20195. * and will allocate an CMD/RSP buffer if the pool is empty.
  20196. *
  20197. * Return codes:
  20198. * NULL - Error
  20199. * Pointer to fcp_cmd_rsp_buf - Success
  20200. **/
  20201. struct fcp_cmd_rsp_buf *
  20202. lpfc_get_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
  20203. struct lpfc_io_buf *lpfc_buf)
  20204. {
  20205. struct fcp_cmd_rsp_buf *list_entry = NULL;
  20206. struct fcp_cmd_rsp_buf *tmp = NULL;
  20207. struct fcp_cmd_rsp_buf *allocated_buf = NULL;
  20208. struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
  20209. struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
  20210. unsigned long iflags;
  20211. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20212. if (likely(!list_empty(buf_list))) {
  20213. /* break off 1 chunk from the list */
  20214. list_for_each_entry_safe(list_entry, tmp,
  20215. buf_list,
  20216. list_node) {
  20217. list_move_tail(&list_entry->list_node,
  20218. &lpfc_buf->dma_cmd_rsp_list);
  20219. break;
  20220. }
  20221. } else {
  20222. /* allocate more */
  20223. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20224. tmp = kmalloc_node(sizeof(*tmp), GFP_ATOMIC,
  20225. cpu_to_node(hdwq->io_wq->chann));
  20226. if (!tmp) {
  20227. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  20228. "8355 error kmalloc memory for HDWQ "
  20229. "%d %s\n",
  20230. lpfc_buf->hdwq_no, __func__);
  20231. return NULL;
  20232. }
  20233. tmp->fcp_cmnd = dma_pool_zalloc(phba->lpfc_cmd_rsp_buf_pool,
  20234. GFP_ATOMIC,
  20235. &tmp->fcp_cmd_rsp_dma_handle);
  20236. if (!tmp->fcp_cmnd) {
  20237. lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
  20238. "8356 error pool_alloc memory for HDWQ "
  20239. "%d %s\n",
  20240. lpfc_buf->hdwq_no, __func__);
  20241. kfree(tmp);
  20242. return NULL;
  20243. }
  20244. tmp->fcp_rsp = (struct fcp_rsp *)((uint8_t *)tmp->fcp_cmnd +
  20245. sizeof(struct fcp_cmnd));
  20246. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20247. list_add_tail(&tmp->list_node, &lpfc_buf->dma_cmd_rsp_list);
  20248. }
  20249. allocated_buf = list_last_entry(&lpfc_buf->dma_cmd_rsp_list,
  20250. struct fcp_cmd_rsp_buf,
  20251. list_node);
  20252. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20253. return allocated_buf;
  20254. }
  20255. /**
  20256. * lpfc_put_cmd_rsp_buf_per_hdwq - Put one CMD/RSP buffer into hdwq pool
  20257. * @phba: The HBA for which this call is being executed.
  20258. * @lpfc_buf: IO buf structure with the CMD/RSP buf
  20259. *
  20260. * This routine puts one CMD/RSP buffer into executing CPU's CMD/RSP pool.
  20261. *
  20262. * Return codes:
  20263. * 0 - Success
  20264. * -EINVAL - Error
  20265. **/
  20266. int
  20267. lpfc_put_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
  20268. struct lpfc_io_buf *lpfc_buf)
  20269. {
  20270. int rc = 0;
  20271. struct fcp_cmd_rsp_buf *list_entry = NULL;
  20272. struct fcp_cmd_rsp_buf *tmp = NULL;
  20273. struct lpfc_sli4_hdw_queue *hdwq = lpfc_buf->hdwq;
  20274. struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
  20275. unsigned long iflags;
  20276. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20277. if (likely(!list_empty(&lpfc_buf->dma_cmd_rsp_list))) {
  20278. list_for_each_entry_safe(list_entry, tmp,
  20279. &lpfc_buf->dma_cmd_rsp_list,
  20280. list_node) {
  20281. list_move_tail(&list_entry->list_node,
  20282. buf_list);
  20283. }
  20284. } else {
  20285. rc = -EINVAL;
  20286. }
  20287. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20288. return rc;
  20289. }
  20290. /**
  20291. * lpfc_free_cmd_rsp_buf_per_hdwq - Free all CMD/RSP chunks of hdwq pool
  20292. * @phba: phba object
  20293. * @hdwq: hdwq to cleanup cmd rsp buff resources on
  20294. *
  20295. * This routine frees all CMD/RSP buffers of hdwq's CMD/RSP buf pool.
  20296. *
  20297. * Return codes:
  20298. * None
  20299. **/
  20300. void
  20301. lpfc_free_cmd_rsp_buf_per_hdwq(struct lpfc_hba *phba,
  20302. struct lpfc_sli4_hdw_queue *hdwq)
  20303. {
  20304. struct list_head *buf_list = &hdwq->cmd_rsp_buf_list;
  20305. struct fcp_cmd_rsp_buf *list_entry = NULL;
  20306. struct fcp_cmd_rsp_buf *tmp = NULL;
  20307. unsigned long iflags;
  20308. spin_lock_irqsave(&hdwq->hdwq_lock, iflags);
  20309. /* Free cmd_rsp buf pool */
  20310. list_for_each_entry_safe(list_entry, tmp,
  20311. buf_list,
  20312. list_node) {
  20313. dma_pool_free(phba->lpfc_cmd_rsp_buf_pool,
  20314. list_entry->fcp_cmnd,
  20315. list_entry->fcp_cmd_rsp_dma_handle);
  20316. list_del(&list_entry->list_node);
  20317. kfree(list_entry);
  20318. }
  20319. spin_unlock_irqrestore(&hdwq->hdwq_lock, iflags);
  20320. }
  20321. /**
  20322. * lpfc_sli_prep_wqe - Prepare WQE for the command to be posted
  20323. * @phba: phba object
  20324. * @job: job entry of the command to be posted.
  20325. *
  20326. * Fill the common fields of the wqe for each of the command.
  20327. *
  20328. * Return codes:
  20329. * None
  20330. **/
  20331. void
  20332. lpfc_sli_prep_wqe(struct lpfc_hba *phba, struct lpfc_iocbq *job)
  20333. {
  20334. u8 cmnd;
  20335. u32 *pcmd;
  20336. u32 if_type = 0;
  20337. u32 fip, abort_tag;
  20338. struct lpfc_nodelist *ndlp = NULL;
  20339. union lpfc_wqe128 *wqe = &job->wqe;
  20340. u8 command_type = ELS_COMMAND_NON_FIP;
  20341. fip = phba->hba_flag & HBA_FIP_SUPPORT;
  20342. /* The fcp commands will set command type */
  20343. if (job->cmd_flag & LPFC_IO_FCP)
  20344. command_type = FCP_COMMAND;
  20345. else if (fip && (job->cmd_flag & LPFC_FIP_ELS_ID_MASK))
  20346. command_type = ELS_COMMAND_FIP;
  20347. else
  20348. command_type = ELS_COMMAND_NON_FIP;
  20349. abort_tag = job->iotag;
  20350. cmnd = bf_get(wqe_cmnd, &wqe->els_req.wqe_com);
  20351. switch (cmnd) {
  20352. case CMD_ELS_REQUEST64_WQE:
  20353. ndlp = job->ndlp;
  20354. if_type = bf_get(lpfc_sli_intf_if_type,
  20355. &phba->sli4_hba.sli_intf);
  20356. if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
  20357. pcmd = (u32 *)job->cmd_dmabuf->virt;
  20358. if (pcmd && (*pcmd == ELS_CMD_FLOGI ||
  20359. *pcmd == ELS_CMD_SCR ||
  20360. *pcmd == ELS_CMD_RDF ||
  20361. *pcmd == ELS_CMD_EDC ||
  20362. *pcmd == ELS_CMD_RSCN_XMT ||
  20363. *pcmd == ELS_CMD_FDISC ||
  20364. *pcmd == ELS_CMD_LOGO ||
  20365. *pcmd == ELS_CMD_QFPA ||
  20366. *pcmd == ELS_CMD_UVEM ||
  20367. *pcmd == ELS_CMD_PLOGI)) {
  20368. bf_set(els_req64_sp, &wqe->els_req, 1);
  20369. bf_set(els_req64_sid, &wqe->els_req,
  20370. job->vport->fc_myDID);
  20371. if ((*pcmd == ELS_CMD_FLOGI) &&
  20372. !(phba->fc_topology ==
  20373. LPFC_TOPOLOGY_LOOP))
  20374. bf_set(els_req64_sid, &wqe->els_req, 0);
  20375. bf_set(wqe_ct, &wqe->els_req.wqe_com, 1);
  20376. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  20377. phba->vpi_ids[job->vport->vpi]);
  20378. } else if (pcmd) {
  20379. bf_set(wqe_ct, &wqe->els_req.wqe_com, 0);
  20380. bf_set(wqe_ctxt_tag, &wqe->els_req.wqe_com,
  20381. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  20382. }
  20383. }
  20384. bf_set(wqe_temp_rpi, &wqe->els_req.wqe_com,
  20385. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  20386. bf_set(wqe_dbde, &wqe->els_req.wqe_com, 1);
  20387. bf_set(wqe_iod, &wqe->els_req.wqe_com, LPFC_WQE_IOD_READ);
  20388. bf_set(wqe_qosd, &wqe->els_req.wqe_com, 1);
  20389. bf_set(wqe_lenloc, &wqe->els_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  20390. bf_set(wqe_ebde_cnt, &wqe->els_req.wqe_com, 0);
  20391. break;
  20392. case CMD_XMIT_ELS_RSP64_WQE:
  20393. ndlp = job->ndlp;
  20394. /* word4 */
  20395. wqe->xmit_els_rsp.word4 = 0;
  20396. if_type = bf_get(lpfc_sli_intf_if_type,
  20397. &phba->sli4_hba.sli_intf);
  20398. if (if_type >= LPFC_SLI_INTF_IF_TYPE_2) {
  20399. if (job->vport->fc_flag & FC_PT2PT) {
  20400. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  20401. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  20402. job->vport->fc_myDID);
  20403. if (job->vport->fc_myDID == Fabric_DID) {
  20404. bf_set(wqe_els_did,
  20405. &wqe->xmit_els_rsp.wqe_dest, 0);
  20406. }
  20407. }
  20408. }
  20409. bf_set(wqe_dbde, &wqe->xmit_els_rsp.wqe_com, 1);
  20410. bf_set(wqe_iod, &wqe->xmit_els_rsp.wqe_com, LPFC_WQE_IOD_WRITE);
  20411. bf_set(wqe_qosd, &wqe->xmit_els_rsp.wqe_com, 1);
  20412. bf_set(wqe_lenloc, &wqe->xmit_els_rsp.wqe_com,
  20413. LPFC_WQE_LENLOC_WORD3);
  20414. bf_set(wqe_ebde_cnt, &wqe->xmit_els_rsp.wqe_com, 0);
  20415. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
  20416. bf_set(els_rsp64_sp, &wqe->xmit_els_rsp, 1);
  20417. bf_set(els_rsp64_sid, &wqe->xmit_els_rsp,
  20418. job->vport->fc_myDID);
  20419. bf_set(wqe_ct, &wqe->xmit_els_rsp.wqe_com, 1);
  20420. }
  20421. if (phba->sli_rev == LPFC_SLI_REV4) {
  20422. bf_set(wqe_rsp_temp_rpi, &wqe->xmit_els_rsp,
  20423. phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
  20424. if (bf_get(wqe_ct, &wqe->xmit_els_rsp.wqe_com))
  20425. bf_set(wqe_ctxt_tag, &wqe->xmit_els_rsp.wqe_com,
  20426. phba->vpi_ids[job->vport->vpi]);
  20427. }
  20428. command_type = OTHER_COMMAND;
  20429. break;
  20430. case CMD_GEN_REQUEST64_WQE:
  20431. /* Word 10 */
  20432. bf_set(wqe_dbde, &wqe->gen_req.wqe_com, 1);
  20433. bf_set(wqe_iod, &wqe->gen_req.wqe_com, LPFC_WQE_IOD_READ);
  20434. bf_set(wqe_qosd, &wqe->gen_req.wqe_com, 1);
  20435. bf_set(wqe_lenloc, &wqe->gen_req.wqe_com, LPFC_WQE_LENLOC_NONE);
  20436. bf_set(wqe_ebde_cnt, &wqe->gen_req.wqe_com, 0);
  20437. command_type = OTHER_COMMAND;
  20438. break;
  20439. case CMD_XMIT_SEQUENCE64_WQE:
  20440. if (phba->link_flag & LS_LOOPBACK_MODE)
  20441. bf_set(wqe_xo, &wqe->xmit_sequence.wge_ctl, 1);
  20442. wqe->xmit_sequence.rsvd3 = 0;
  20443. bf_set(wqe_pu, &wqe->xmit_sequence.wqe_com, 0);
  20444. bf_set(wqe_dbde, &wqe->xmit_sequence.wqe_com, 1);
  20445. bf_set(wqe_iod, &wqe->xmit_sequence.wqe_com,
  20446. LPFC_WQE_IOD_WRITE);
  20447. bf_set(wqe_lenloc, &wqe->xmit_sequence.wqe_com,
  20448. LPFC_WQE_LENLOC_WORD12);
  20449. bf_set(wqe_ebde_cnt, &wqe->xmit_sequence.wqe_com, 0);
  20450. command_type = OTHER_COMMAND;
  20451. break;
  20452. case CMD_XMIT_BLS_RSP64_WQE:
  20453. bf_set(xmit_bls_rsp64_seqcnthi, &wqe->xmit_bls_rsp, 0xffff);
  20454. bf_set(wqe_xmit_bls_pt, &wqe->xmit_bls_rsp.wqe_dest, 0x1);
  20455. bf_set(wqe_ct, &wqe->xmit_bls_rsp.wqe_com, 1);
  20456. bf_set(wqe_ctxt_tag, &wqe->xmit_bls_rsp.wqe_com,
  20457. phba->vpi_ids[phba->pport->vpi]);
  20458. bf_set(wqe_qosd, &wqe->xmit_bls_rsp.wqe_com, 1);
  20459. bf_set(wqe_lenloc, &wqe->xmit_bls_rsp.wqe_com,
  20460. LPFC_WQE_LENLOC_NONE);
  20461. /* Overwrite the pre-set comnd type with OTHER_COMMAND */
  20462. command_type = OTHER_COMMAND;
  20463. break;
  20464. case CMD_FCP_ICMND64_WQE: /* task mgmt commands */
  20465. case CMD_ABORT_XRI_WQE: /* abort iotag */
  20466. case CMD_SEND_FRAME: /* mds loopback */
  20467. /* cases already formatted for sli4 wqe - no chgs necessary */
  20468. return;
  20469. default:
  20470. dump_stack();
  20471. lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
  20472. "6207 Invalid command 0x%x\n",
  20473. cmnd);
  20474. break;
  20475. }
  20476. wqe->generic.wqe_com.abort_tag = abort_tag;
  20477. bf_set(wqe_reqtag, &wqe->generic.wqe_com, job->iotag);
  20478. bf_set(wqe_cmd_type, &wqe->generic.wqe_com, command_type);
  20479. bf_set(wqe_cqid, &wqe->generic.wqe_com, LPFC_WQE_CQ_ID_DEFAULT);
  20480. }